*/}}

la_widgets.c 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "../la_5.h"
  19. extern LA MAIN;
  20. extern tnsMain* T;
  21. laWidget _LA_WIDGET_FIXED_GROUP={0};
  22. laWidget _LA_WIDGET_TAB={0};
  23. laWidget _LA_WIDGET_COLLECTION={0};
  24. laWidget _LA_WIDGET_COLLECTION_ITEM={0};
  25. laWidget _LA_WIDGET_COLLECTION_SELECTOR={0};
  26. laWidget _LA_WIDGET_COLLECTION_SINGLE={0};
  27. laWidget _LA_WIDGET_CONDITION_TOGGLE={0};
  28. laWidget _LA_WIDGET_COLUMN_ADJUSTER={0,LA_UI_FLAGS_NO_HEIGHT};
  29. laWidget _LA_WIDGET_COLUMN_VIEWER={0};
  30. laWidget _LA_WIDGET_BUTTON={0};
  31. laWidget _LA_WIDGET_BUTTON_NO_CONFIRM={0};
  32. laWidget _LA_WIDGET_LABEL={0};
  33. laWidget _LA_WIDGET_INT={0};
  34. laWidget _LA_WIDGET_INT_PLAIN={0, LA_UI_FLAGS_PLAIN};
  35. laWidget _LA_WIDGET_INT_PLAIN_ICON={0, LA_UI_FLAGS_INT_ICON};
  36. laWidget _LA_WIDGET_METER_TYPE1={0,LA_TEXT_ALIGN_CENTER};
  37. laWidget _LA_WIDGET_METER_TYPE2={0,LA_TEXT_ALIGN_CENTER};
  38. laWidget _LA_WIDGET_VALUE_METER_2D={0,LA_TEXT_ALIGN_CENTER};
  39. laWidget _LA_WIDGET_FLOAT={0};
  40. laWidget _LA_WIDGET_FLOAT_PLAIN={0, LA_UI_FLAGS_PLAIN};
  41. laWidget _LA_WIDGET_FLOAT_COLOR={0};
  42. laWidget _LA_WIDGET_FLOAT_COLOR_HCY={0};
  43. laWidget _LA_WIDGET_ENUM_SELECTOR={0};
  44. laWidget _LA_WIDGET_ENUM_SELECTOR_ICON={0, LA_UI_FLAGS_ICON};
  45. laWidget _LA_WIDGET_ENUM_CYCLE={0, LA_UI_FLAGS_CYCLE};
  46. laWidget _LA_WIDGET_ENUM_CYCLE_ICON={0, LA_UI_FLAGS_CYCLE|LA_UI_FLAGS_ICON};
  47. laWidget _LA_WIDGET_ENUM_ICON_PLAIN={0, LA_UI_FLAGS_PLAIN|LA_UI_FLAGS_ICON};
  48. laWidget _LA_WIDGET_ENUM_HIGHLIGHT={0, LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_CYCLE|LA_TEXT_ALIGN_CENTER};
  49. laWidget _LA_WIDGET_STRING={0};
  50. laWidget _LA_WIDGET_STRING_PLAIN={0, LA_UI_FLAGS_PLAIN};
  51. laWidget _LA_WIDGET_STRING_MONO_PLAIN={0, LA_TEXT_MONO|LA_UI_FLAGS_PLAIN};
  52. laWidget _LA_WIDGET_STRING_MULTI={0, LA_TEXT_MONO};
  53. laWidget _LA_WIDGET_MENU_ROOT={0};
  54. laWidget _LA_WIDGET_ALIGN={0};
  55. laWidget _LA_WIDGET_3D_VIEW={0};
  56. laWidget _LA_WIDGET_2D_VIEW={0};
  57. laWidget _LA_WIDGET_SYMBOL={0};
  58. laWidget _LA_WIDGET_NODE_SOCKET={0};
  59. laWidget _LA_WIDGET_HEIGHT_ADJUSTER={0};
  60. laWidget _LA_WIDGET_RAW={0};
  61. laWidget _LA_WIDGET_MAPPER={0};
  62. laWidget _LA_WIDGET_IMAGE={0};
  63. laWidget _LA_WIDGET_SCOPE={0};
  64. laWidget _LA_WIDGET_KNOB={0,LA_UI_FLAGS_KNOB};
  65. laWidget *LA_WIDGET_FIXED_GROUP=&_LA_WIDGET_FIXED_GROUP;
  66. laWidget *LA_WIDGET_TAB=&_LA_WIDGET_TAB;
  67. laWidget *LA_WIDGET_COLLECTION=&_LA_WIDGET_COLLECTION;
  68. laWidget *LA_WIDGET_COLLECTION_ITEM=&_LA_WIDGET_COLLECTION_ITEM;
  69. laWidget *LA_WIDGET_COLLECTION_SELECTOR=&_LA_WIDGET_COLLECTION_SELECTOR;
  70. laWidget *LA_WIDGET_COLLECTION_SINGLE=&_LA_WIDGET_COLLECTION_SINGLE;
  71. laWidget *LA_WIDGET_CONDITION_TOGGLE=&_LA_WIDGET_CONDITION_TOGGLE;
  72. laWidget *LA_WIDGET_COLUMN_ADJUSTER=&_LA_WIDGET_COLUMN_ADJUSTER;
  73. laWidget *LA_WIDGET_COLUMN_VIEWER=&_LA_WIDGET_COLUMN_VIEWER;
  74. laWidget *LA_WIDGET_BUTTON=&_LA_WIDGET_BUTTON;
  75. laWidget *LA_WIDGET_BUTTON_NO_CONFIRM=&_LA_WIDGET_BUTTON_NO_CONFIRM;
  76. laWidget *LA_WIDGET_LABEL=&_LA_WIDGET_LABEL;
  77. laWidget *LA_WIDGET_INT=&_LA_WIDGET_INT;
  78. laWidget *LA_WIDGET_INT_PLAIN=&_LA_WIDGET_INT_PLAIN;
  79. laWidget *LA_WIDGET_INT_PLAIN_ICON=&_LA_WIDGET_INT_PLAIN_ICON;
  80. laWidget *LA_WIDGET_METER_TYPE1=&_LA_WIDGET_METER_TYPE1;
  81. laWidget *LA_WIDGET_METER_TYPE2=&_LA_WIDGET_METER_TYPE2;
  82. laWidget *LA_WIDGET_VALUE_METER_2D=&_LA_WIDGET_VALUE_METER_2D;
  83. laWidget *LA_WIDGET_FLOAT=&_LA_WIDGET_FLOAT;
  84. laWidget *LA_WIDGET_FLOAT_PLAIN=&_LA_WIDGET_FLOAT_PLAIN;
  85. laWidget *LA_WIDGET_FLOAT_COLOR=&_LA_WIDGET_FLOAT_COLOR;
  86. laWidget *LA_WIDGET_FLOAT_COLOR_HCY=&_LA_WIDGET_FLOAT_COLOR_HCY;
  87. laWidget *LA_WIDGET_ENUM_SELECTOR=&_LA_WIDGET_ENUM_SELECTOR;
  88. laWidget *LA_WIDGET_ENUM_SELECTOR_ICON=&_LA_WIDGET_ENUM_SELECTOR_ICON;
  89. laWidget *LA_WIDGET_ENUM_CYCLE=&_LA_WIDGET_ENUM_CYCLE;
  90. laWidget *LA_WIDGET_ENUM_CYCLE_ICON=&_LA_WIDGET_ENUM_CYCLE_ICON;
  91. laWidget *LA_WIDGET_ENUM_ICON_PLAIN=&_LA_WIDGET_ENUM_ICON_PLAIN;
  92. laWidget *LA_WIDGET_ENUM_HIGHLIGHT=&_LA_WIDGET_ENUM_HIGHLIGHT;
  93. laWidget *LA_WIDGET_STRING=&_LA_WIDGET_STRING;
  94. laWidget *LA_WIDGET_STRING_PLAIN=&_LA_WIDGET_STRING_PLAIN;
  95. laWidget *LA_WIDGET_STRING_MULTI=&_LA_WIDGET_STRING_MULTI;
  96. laWidget *LA_WIDGET_STRING_MONO_PLAIN=&_LA_WIDGET_STRING_MONO_PLAIN;
  97. laWidget *LA_WIDGET_MENU_ROOT=&_LA_WIDGET_MENU_ROOT;
  98. laWidget *LA_WIDGET_ALIGN=&_LA_WIDGET_ALIGN;
  99. laWidget *LA_WIDGET_3D_VIEW=&_LA_WIDGET_3D_VIEW;
  100. laWidget *LA_WIDGET_2D_VIEW=&_LA_WIDGET_2D_VIEW;
  101. laWidget *LA_WIDGET_SYMBOL=&_LA_WIDGET_SYMBOL;
  102. laWidget *LA_WIDGET_NODE_SOCKET=&_LA_WIDGET_NODE_SOCKET;
  103. laWidget *LA_WIDGET_HEIGHT_ADJUSTER=&_LA_WIDGET_HEIGHT_ADJUSTER;
  104. laWidget *LA_WIDGET_RAW=&_LA_WIDGET_RAW;
  105. laWidget *LA_WIDGET_MAPPER=&_LA_WIDGET_MAPPER;
  106. laWidget *LA_WIDGET_IMAGE=&_LA_WIDGET_IMAGE;
  107. laWidget *LA_WIDGET_SCOPE=&_LA_WIDGET_SCOPE;
  108. laWidget *LA_WIDGET_KNOB=&_LA_WIDGET_KNOB;
  109. //============================================== [Draw]
  110. int la_ArrayGetHeight(laUiItem *ui){
  111. return laGetArrayLength(&ui->PP);
  112. }
  113. int la_ValueGetHeight(laUiItem*ui){
  114. int rows = ui->Extra->HeightCoeff; TNS_CLAMP(rows,1,4);
  115. if(ui->Flags&LA_UI_FLAGS_TRANSPOSE){ return la_ArrayGetHeight(ui)*rows; }
  116. return rows;
  117. }
  118. int la_ValueMeterGetHeight(laUiItem*ui){
  119. if(ui->Flags&LA_UI_FLAGS_TRANSPOSE){ return ui->Extra->HeightCoeff?ui->Extra->HeightCoeff:6; }
  120. return laGetArrayLength(&ui->PP);
  121. }
  122. int la_ValueMeter2DGetHeight(laUiItem*ui){
  123. return ui->Extra->HeightCoeff?ui->Extra->HeightCoeff:(ui->Extra->HeightCoeff=(ui->TR-ui->TL)/LA_RH);
  124. }
  125. int la_CanvasGetHeight(laUiItem *ui){
  126. return ui->Expand;
  127. }
  128. int la_EnumGetHeight(laUiItem *ui){
  129. // norm e1
  130. // expand e1 e2 e3
  131. // expand vertical (vertical)
  132. // arr expand e1 e2 e3
  133. // e1 e2 e3
  134. // arr exp+vert e1 e1
  135. // e2 e2
  136. // e3 e3
  137. int IsVertical = ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  138. int IsExpand = ui->Flags&LA_UI_FLAGS_EXPAND;
  139. int IsCycle = ui->Flags&LA_UI_FLAGS_CYCLE;
  140. int ArrLen = laGetArrayLength(&ui->PP);
  141. if(ArrLen==1){ if(!IsExpand) IsVertical=0; }else{ IsExpand=1; }
  142. int EnumLen = (IsExpand&&(!IsCycle)) ? laGetEnumEntryLen(&ui->PP) : 1;
  143. if(ArrLen==1){
  144. if(IsVertical&&IsExpand) return laGetEnumEntryLen(&ui->PP);
  145. return 1;
  146. }else{
  147. if(IsVertical) return EnumLen;
  148. else return ArrLen;
  149. }
  150. }
  151. int la_ColorPickerGetHeight(laUiItem *ui){
  152. if(!ui->Extra->HeightCoeff) ui->Extra->HeightCoeff=7;
  153. return ui->Extra->HeightCoeff;
  154. }
  155. int la_SymbolGetHeight(laUiItem *ui){
  156. //if (!ui->State)
  157. //{
  158. // ui->State = (int)_ICON_SYMBOL_SIZE[ui->SymbolID - ICON_SYMBOL_START] * 1.4 + 1;
  159. //}
  160. return ui->State;
  161. }
  162. int la_GroupGetHeight(laUiItem *ui){
  163. if (ui->State == LA_UI_ACTIVE) return 0;
  164. return LA_RH;
  165. }
  166. int la_StringPropGetHeight(laUiItem *ui){
  167. laBoxedTheme *bt = *ui->Type->Theme;
  168. if(!(ui->Flags&LA_TEXT_LINE_WRAP)) return 1;
  169. char _buf[LA_RAW_CSTR_MAX_LEN]={0}; char* buf=_buf;
  170. laGetString(&ui->PP, _buf, &buf); int rows=0;
  171. int strw=tnsStringGetDimension(buf, 0, 0, ui->TR-ui->TL, &rows, ui->Flags&LA_TEXT_MONO);
  172. return rows;
  173. }
  174. int la_MultiStringHeight(laUiItem *ui){
  175. laGeneralUiExtraData *e = ui->Extra;
  176. return e->HeightCoeff;
  177. }
  178. int la_LabelHeight(laUiItem *ui){
  179. int Wrap=ui->Flags&(LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  180. if(!Wrap) return 1;
  181. int rows;
  182. tnsStringGetDimension(transLate(ui->Display->Ptr), 0, 0, ui->TR-ui->TL, &rows, ui->Flags&LA_TEXT_MONO);
  183. return rows;
  184. }
  185. int la_SocketGetHeight(laUiItem *ui){
  186. if(ui->Flags&(LA_UI_SOCKET_LABEL_N|LA_UI_SOCKET_LABEL_S))return 2; return 1;
  187. }
  188. int la_ImageGetHeight(laUiItem *ui){
  189. if(ui->Flags&LA_UI_IMAGE_FULL_W){
  190. tnsImage* im=ui->Extra;
  191. int W=im->Texture->Width, H=im->Texture->Height;
  192. real CW=MAIN.CurrentWindow->CW-LA_RH*4, CH=MAIN.CurrentWindow->CH-LA_RH*4;
  193. real ra=1;
  194. if(W>CW){ real r=W/CW; ra=TNS_MAX2(r,ra); }
  195. if(H>CH){ real r=H/CH; ra=TNS_MAX2(r,ra); }
  196. W/=ra; H/=ra;
  197. return H/LA_RH+1;
  198. }
  199. if(!ui->SymbolID) ui->SymbolID=3;
  200. return ui->SymbolID;
  201. }
  202. int la_ColorSelectorGetMinWidth(laUiItem *ui){
  203. if(ui->Flags&LA_UI_FLAGS_ICON) return LA_RH;
  204. return 5*LA_RH;
  205. }
  206. int la_ValueGetMinWidth(laUiItem *ui){
  207. int ExtraW=0;
  208. if(ui->Flags&LA_UI_FLAGS_NO_LABEL){ return LA_RH; }
  209. if(ui->Flags&LA_UI_FLAGS_KNOB){ return LA_RH*TNS_MAX2(1,ui->Extra->HeightCoeff); }
  210. if((ui->Flags&LA_UI_FLAGS_EXPAND)&&(!(ui->Flags&LA_UI_FLAGS_NO_LABEL))){
  211. ExtraW+=tnsStringGetWidth(transLate(ui->PP.LastPs->p->Name),0,0);
  212. }
  213. return LA_RH*4+ExtraW;
  214. }
  215. int la_LabelGetMinWidth(laUiItem *ui){
  216. laBoxedTheme *bt = *ui->Type->Theme;
  217. if(ui->Flags&LA_UI_MIN_WIDTH){ return LA_RH; }
  218. int strw=tnsStringGetWidth(transLate(ui->Display->Ptr), 0, ui->Flags&LA_TEXT_MONO);
  219. if(ui->Type==_LA_UI_MENU_ROOT && strw<LA_RH)strw=LA_RH;
  220. return (strw + bt->LM + bt->RM);
  221. }
  222. int la_StringPropGetMinWidth(laUiItem *ui){
  223. laBoxedTheme *bt = *ui->Type->Theme;
  224. if(ui->Flags&LA_UI_MIN_WIDTH){ return LA_RH; }
  225. char _buf[LA_RAW_CSTR_MAX_LEN]={0}; int ExtraW=0; char* buf=_buf;
  226. if(ui->Type == _LA_UI_STRING_MULTI){ExtraW=2*LA_RH+bt->LM;}
  227. laGetString(&ui->PP, _buf, &buf); int rows=0;
  228. int strw=tnsStringGetDimension(buf, 0, 0, 0, &rows, ui->Flags&LA_TEXT_MONO);
  229. int Plain = ui->Flags&LA_UI_FLAGS_PLAIN;
  230. if((!Plain)&&strw<LA_RH*4){strw=LA_RH*4;}
  231. return (strw + bt->LM + bt->RM+ExtraW);
  232. }
  233. int la_EnumGetMinWidth(laUiItem *ui){
  234. laBoxedTheme *bt = *ui->Type->Theme;
  235. laEnumProp *ep = ui->PP.LastPs->p;
  236. laEnumItem *i;
  237. int W = 0; int tW;
  238. int IsVertical = ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  239. int IsExpand = ui->Flags&LA_UI_FLAGS_EXPAND;
  240. int IsCycle = ui->Flags&LA_UI_FLAGS_CYCLE;
  241. int IsIcon = ui->Flags&LA_UI_FLAGS_ICON;
  242. int Highlight=ui->Flags&LA_UI_FLAGS_HIGHLIGHT;
  243. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  244. int SharedWidth;
  245. if(!IsIcon){
  246. SharedWidth = bt->LM + bt->RM + ((IsCycle||IsExpand||NoDecal)?0:LA_RH); int HasIcon=0;
  247. if(Highlight){ int ico=0;
  248. if (ui->ExtraInstructions){
  249. if (ui->Type->OperatorType->ParseArgs){
  250. char buf[256]; buf[0]=0;
  251. ui->Type->OperatorType->ParseArgs(ui->Instructions, &ico, buf);
  252. tW = tnsStringGetWidth(transLate(buf), 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
  253. }
  254. }else{
  255. for (i = ep->Items.pFirst; i; i = i->Item.pNext){ if (i->IconID){ HasIcon=1; } }
  256. tW = tnsStringGetWidth(transLate(ep->Base.Name), 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
  257. }
  258. if (tW > W) W = tW;
  259. if(HasIcon||ico) W+=bt->LM+LA_RH;
  260. }else{
  261. for (i = ep->Items.pFirst; i; i = i->Item.pNext){
  262. tW = tnsStringGetWidth(transLate(i->Name), 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
  263. if (i->IconID){ HasIcon=1; }
  264. if (tW > W) W = tW;
  265. }
  266. if(HasIcon) W+=bt->LM+LA_RH;
  267. }
  268. }else{
  269. W = LA_RH;
  270. }
  271. int ArrLen = laGetArrayLength(&ui->PP);
  272. if(ArrLen==1){ if(!IsExpand) IsVertical=0; }else{ IsExpand=1; }
  273. int EnumLen = (IsExpand&&(!IsCycle)) ? laGetEnumEntryLen(&ui->PP) : 1;
  274. if(ArrLen==1){
  275. if(!IsVertical) return W*EnumLen;
  276. return W;
  277. }else{
  278. if(IsVertical) return ArrLen*W;
  279. return EnumLen*W;
  280. }
  281. return W;
  282. }
  283. int la_ButtonGetMinWidth(laUiItem *ui){
  284. laBoxedTheme *bt = *ui->Type->Theme;
  285. uint32_t IconID;
  286. char buf[LA_RAW_CSTR_MAX_LEN]={0};
  287. char *label;
  288. laOperatorProp *ap;
  289. int IconOnly=ui->Flags&LA_UI_FLAGS_ICON;
  290. if(IconOnly) return LA_RH;
  291. if (ui->PP.LastPs && ui->PP.LastPs->p){
  292. ap = ui->PP.LastPs->p;
  293. label = transLate(ap->Base.Name);
  294. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  295. IconID = ap->Base.IconID ? ap->Base.IconID : ap->OperatorType->IconID;
  296. }else{
  297. label = transLate(ui->AT->Name);
  298. IconID = ui->AT->IconID;
  299. }
  300. if (ui->ExtraInstructions){
  301. if (ui->AT && ui->AT->ParseArgs){
  302. ui->AT->ParseArgs(ui->Instructions, &IconID, buf);
  303. if (buf[0]) label = transLate(buf);
  304. }else if (ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  305. laOperatorProp *ap = ui->PP.LastPs->p;
  306. if (ap->OperatorType && ap->OperatorType->ParseArgs){
  307. ap->OperatorType->ParseArgs(ui->Instructions, &IconID, buf);
  308. if (buf[0]) label = transLate(buf);
  309. }
  310. }
  311. }
  312. int strw=tnsStringGetWidth(label, 0, ui->Flags&LA_TEXT_MONO);
  313. if(strw){ strw+=bt->RM+bt->LM; }
  314. return ((IconID ? (LA_RH) : 0) + strw);
  315. }
  316. int la_CollectionSimpleGetMinWidth(laUiItem *ui){
  317. laBoxedTheme *bt = *ui->Type->Theme;
  318. int Simple=ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR;
  319. int Expand=ui->Expand||(ui->Flags&LA_UI_FLAGS_EXPAND);
  320. int w=LA_RH+((Simple&&Expand)?(tnsStringGetWidth("Select",0,0)+bt->RM+bt->LM):0);
  321. return w;
  322. }
  323. int la_ColumnViewerGetMinWidth(laUiItem *ui){
  324. return 350;
  325. }
  326. int la_ColorPickerGetMinWidth(laUiItem *ui){
  327. return LA_RH * 9;
  328. }
  329. int la_SocketGetMinWidth(laUiItem *ui){
  330. if(ui->Flags&(LA_UI_SOCKET_LABEL_W|LA_UI_SOCKET_LABEL_E))return LA_RH*3;
  331. if(ui->Flags&(LA_UI_SOCKET_LABEL_S|LA_UI_SOCKET_LABEL_N))return LA_RH*2;
  332. return LA_RH;
  333. }
  334. int la_ImageGetMinWidth(laUiItem *ui){
  335. tnsImage* im=ui->Extra;
  336. if(!im->Texture) return LA_RH;
  337. int W=im->Texture->Width, H=im->Texture->Height;
  338. int UseW=LA_RH;
  339. if(ui->Flags&LA_UI_IMAGE_FULL_W) UseW=W;
  340. else UseW=(int)((real)LA_RH*ui->SymbolID/H*W);
  341. real CW=MAIN.CurrentWindow->CW-LA_RH*4, CH=MAIN.CurrentWindow->CH-LA_RH*4;
  342. real ra=1;
  343. if(UseW>CW){ real r=UseW/CW; ra=TNS_MAX2(r,ra); }
  344. if(H>CH){ real r=H/CH; ra=TNS_MAX2(r,ra); }
  345. UseW/=ra; H/=ra;
  346. return UseW;
  347. }
  348. void la_SingleLineStringDrawSelection(laUiItem *ui, int Begin, int U, laBoxedTheme *bt, uint32_t *str, laStringEdit *se);
  349. void la_CollectionSelectorDraw(laUiItem *ui, int h){
  350. char temp[128] = {0};
  351. laBoxedTheme *bt = (*ui->Type->Theme);
  352. real Color[16] = {0};
  353. tnsVector4d Transp = {0};
  354. int CrossDraw = 0;
  355. int Simple=ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR;
  356. if(Simple){ CrossDraw=0; }
  357. if (!ui->State) ui->State = LA_UI_NORMAL;
  358. tnsUseNoTexture();
  359. tnsColor4dv(laThemeColor(bt,ui->State));
  360. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  361. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  362. tnsPackAs(GL_TRIANGLE_FAN);
  363. if(!Simple){
  364. CrossDraw = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance) ? 1 : 0;
  365. }
  366. if (CrossDraw){
  367. tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Transp);
  368. Transp[3] = 0;
  369. tnsMakeLinerGradient4dv(Color, 2, Transp, laThemeColor(bt,LA_BT_BORDER));
  370. tnsMakeLinerGradient4dv(&Color[8], 2, Transp, laThemeColor(bt,LA_BT_BORDER));
  371. //tnsMakeLinerGradient4dv(&Color[8], 2, laThemeColor(bt, LA_BT_BORDER), Transp);
  372. tnsVertex2d(ui->R - LA_RH, ui->U); tnsVertex2d(ui->R, ui->U);
  373. tnsVertex2d(ui->R - LA_RH, ui->B); tnsVertex2d(ui->R, ui->B);
  374. tnsColorArray4d(Color, 4);
  375. tnsPackAs(GL_TRIANGLE_STRIP);
  376. }
  377. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  378. tnsVertex2d(ui->L, ui->U);
  379. tnsVertex2d(ui->R, ui->U);
  380. tnsVertex2d(ui->R, ui->B);
  381. tnsVertex2d(ui->L, ui->B);
  382. tnsPackAs(GL_LINE_LOOP);
  383. if (CrossDraw){
  384. tnsDrawStringAuto("🧹", laThemeColor(bt,ui->State|LA_BT_TEXT), ui->R - LA_RH, ui->R, ui->U, 0);
  385. }
  386. if(Simple){
  387. int R=ui->R; if(ui->Expand || (ui->Flags&LA_UI_FLAGS_EXPAND)){
  388. R=ui->L+LA_RH; tnsDrawStringAuto(transLate("Select"), laThemeColor(bt,ui->State|LA_BT_TEXT), R+bt->LM, ui->R, ui->U, 0);
  389. }
  390. tnsDrawStringAuto("⯆", laThemeColor(bt,ui->State|LA_BT_TEXT), ui->L, R, ui->U, LA_TEXT_ALIGN_CENTER);
  391. }
  392. }
  393. void la_EmptyDraw(laUiItem *ui, int h){
  394. char temp[128] = {0};
  395. laBoxedTheme *bt = (*ui->Type->Theme);
  396. if (!ui->State) ui->State = LA_UI_NORMAL;
  397. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  398. if(!NoDecal){
  399. tnsUseNoTexture();
  400. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  401. tnsVertex2d(ui->L, ui->U);
  402. tnsVertex2d(ui->R, ui->U);
  403. tnsVertex2d(ui->R, ui->B);
  404. tnsVertex2d(ui->L, ui->B);
  405. tnsPackAs(GL_TRIANGLE_FAN);
  406. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  407. tnsVertex2d(ui->L, ui->U);
  408. tnsVertex2d(ui->R, ui->U);
  409. tnsVertex2d(ui->R, ui->B);
  410. tnsVertex2d(ui->L, ui->B);
  411. tnsPackAs(GL_LINE_LOOP);
  412. }
  413. }
  414. void la_GroupDraw(laUiItem *ui, int h){
  415. char temp[128] = {0};
  416. laBoxedTheme *bt = (*ui->Type->Theme);
  417. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  418. if(!NoDecal){
  419. tnsUseNoTexture();
  420. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  421. tnsVertex2d(ui->L, ui->U);
  422. tnsVertex2d(ui->R, ui->U);
  423. tnsVertex2d(ui->R, ui->B);
  424. tnsVertex2d(ui->L, ui->B);
  425. tnsPackAs(GL_TRIANGLE_FAN);
  426. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  427. tnsVertex2d(ui->L, ui->U);
  428. tnsVertex2d(ui->R, ui->U);
  429. tnsVertex2d(ui->R, ui->B);
  430. tnsVertex2d(ui->L, ui->B);
  431. tnsPackAs(GL_LINE_LOOP);
  432. }
  433. if (ui->State != LA_UI_ACTIVE){
  434. tnsDrawStringAuto(ui->Page ? transLate(ui->Page->TabName->Ptr) : transLate("No Page"),
  435. laThemeColor(bt,ui->State|LA_BT_TEXT), ui->L+bt->LM, ui->R+bt->RM, ui->U, LA_TEXT_ALIGN_CENTER);
  436. }
  437. }
  438. void la_TabDraw(laUiItem *ui, int h){
  439. char temp[128] = {0};
  440. laBoxedTheme *bt = (*ui->Type->Theme);
  441. laUiList *uil; int count = 0, page = 0;real w, l = ui->L;
  442. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){ count++; }
  443. w = (real)(ui->R - ui->L) / (count == 0 ? 1 : count);
  444. real* bkg=laThemeColor(bt,LA_BT_NORMAL);
  445. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  446. if(!NoDecal){
  447. tnsUseNoTexture();
  448. tnsColor4d(LA_COLOR3(bkg),bkg[3]*0.7);
  449. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  450. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  451. tnsPackAs(GL_TRIANGLE_FAN);
  452. real* bc=laThemeColor(bt,LA_BT_BORDER); real bcolor[24];
  453. tnsVectorCopy4d(bc,bcolor); tnsVectorSet4(&bcolor[4],bc[0],bc[1],bc[2],bc[3]*0.6);
  454. tnsVectorCopy4d(&bcolor[4],&bcolor[8]);
  455. tnsVectorCopy4d(&bcolor[4],&bcolor[12]);
  456. tnsVectorCopy4d(&bcolor[4],&bcolor[16]);
  457. tnsVectorCopy4d(bcolor,&bcolor[20]);
  458. tnsVertex2d(ui->L, ui->U + h); tnsVertex2d(ui->L, TNS_MIN2(ui->U+h*3,ui->B)); tnsVertex2d(ui->L, ui->B);
  459. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->R, TNS_MIN2(ui->U+h*3,ui->B)); tnsVertex2d(ui->R, ui->U + h);
  460. tnsColorArray4d(bcolor,6);
  461. tnsPackAs(GL_LINE_STRIP);
  462. }
  463. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  464. l = page*w; int IsThisPage=(uil==ui->Page);
  465. tnsUseNoTexture();
  466. if(!IsThisPage){
  467. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  468. tnsVertex2d(ui->L + l, ui->U); tnsVertex2d(ui->L + l + w, ui->U);
  469. tnsVertex2d(ui->L + l + w, ui->U + h); tnsVertex2d(ui->L + l, ui->U + h);
  470. tnsPackAs(GL_TRIANGLE_FAN);
  471. }
  472. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  473. tnsVertex2d(ui->L + l, ui->U + h); tnsVertex2d(ui->L + l, ui->U);
  474. tnsVertex2d(ui->L + l + w, ui->U); tnsVertex2d(ui->L + l + w, ui->U + h);
  475. tnsPackAs(IsThisPage?GL_LINE_STRIP:GL_LINE_LOOP);
  476. tnsDrawStringAuto(transLate(uil->TabName->Ptr), laThemeColor(bt,IsThisPage?LA_BT_BORDER:LA_BT_TEXT), ui->L+l+bt->LM, ui->L+l+w-bt->RM, ui->U, LA_TEXT_ALIGN_CENTER);
  477. page++;
  478. }
  479. tnsFlush();
  480. }
  481. void la_SymbolDraw(laUiItem *ui, int h){
  482. return;
  483. //char temp[128] = {0};
  484. //laBoxedTheme *bt = (*ui->Type->Theme);
  485. //tnsFontSingleCharacter *fsc = tfntFetchVectorGraphTextureIDW(ui->SymbolID);
  486. //int VOffset = (ui->B - ui->U - (fsc->height)) / 2;
  487. //int HOffset = (ui->R - ui->L - (fsc->width)) / 2;
  488. //
  489. //if (strArgumentMatch(ui->Instructions, "mode", "invert"))
  490. //{
  491. // tnsUseNoTexture();
  492. // //tnsColor4dv(laThemeColor(bt, ui->State));
  493. // //tnsVertex2d(ui->L, ui->U);
  494. // //tnsVertex2d(ui->R, ui->U);
  495. // //tnsVertex2d(ui->R, ui->B);
  496. // //tnsVertex2d(ui->L, ui->B);
  497. // //tnsPackAs(GL_TRIANGLE_FAN);
  498. //
  499. // tnsUseNoTexture();
  500. // tnsColor4dv(LA_THEME_GET(bt, LA_UI_NORMAL)->BorderColor->RGBA);
  501. // tnsVertex2d(ui->L, ui->U);
  502. // tnsVertex2d(ui->R, ui->U);
  503. // tnsVertex2d(ui->R, ui->B);
  504. // tnsVertex2d(ui->L, ui->B);
  505. // tnsPackAs(GL_TRIANGLE_FAN);
  506. //
  507. // // tnsDrawVectorGraphPackage(ui->SymbolID, LA_THEME_GET(bt, LA_THEME_INTERPOLATING), ui->L + HOffset, ui->R, ui->U + VOffset, ui->B, 0, 0);
  508. //}
  509. //else
  510. //{
  511. // //if (!ui->State) ui->State = LA_UI_NORMAL;
  512. //
  513. // /*tnsUseNoTexture();
  514. // tnsColor4dv(laThemeColor(bt, ui->State));
  515. // tnsVertex2d(ui->L, ui->U);
  516. // tnsVertex2d(ui->R, ui->U);
  517. // tnsVertex2d(ui->R, ui->B);
  518. // tnsVertex2d(ui->L, ui->B);
  519. // tnsPackAs(GL_TRIANGLE_FAN);*/
  520. //
  521. // //tnsUseNoTexture();
  522. //tnsColor4dv(LA_THEME_GET(bt, LA_UI_NORMAL)->BorderColor->RGBA);
  523. //tnsVertex2d(ui->L, ui->U);
  524. //tnsVertex2d(ui->R, ui->U);
  525. //tnsVertex2d(ui->R, ui->B);
  526. //tnsVertex2d(ui->L, ui->B);
  527. //tnsPackAs(GL_LINE_LOOP);
  528. //
  529. // // tnsDrawVectorGraphPackage(ui->SymbolID, LA_THEME_GET(bt, LA_UI_NORMAL), ui->L + HOffset, ui->R, ui->U + VOffset, ui->B, 0, 0);
  530. //}
  531. }
  532. void la_IntDraw(laUiItem *ui, int h){
  533. laBoxedTheme *bt = (*ui->Type->Theme);
  534. int Data[32];
  535. int Len, i, Seg, W;
  536. char buf[48] = {0};
  537. char buf2[48] = {0};
  538. char prefix[8][64] = {0};
  539. int Original;
  540. int Ranged;
  541. int min, max;
  542. int s, State;
  543. int IsVertical=ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  544. int IsIcon=ui->Flags&LA_UI_FLAGS_ICON;
  545. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  546. int NoLabel=ui->Flags&LA_UI_FLAGS_NO_LABEL;
  547. int IsDisabled=ui->Flags&LA_UI_FLAGS_DISABLED;
  548. int IsKnob = ui->Flags&LA_UI_FLAGS_NODE_CONTAINER;
  549. if (laIsPropertyReadOnly(&ui->PP) && !NoDecal) ui->State = LA_BT_DISABLED;
  550. laGetIntArray(&ui->PP, Data);
  551. Len = laGetArrayLength(&ui->PP);
  552. laGetPrefixP(&ui->PP, prefix);
  553. Ranged = laGetIntRange(&ui->PP, &min, &max);
  554. for (i = 0; i < Len; i++){
  555. int _L=ui->L, _R=ui->R, _U=ui->U, _B=ui->B;
  556. if(IsVertical){
  557. Seg = ui->R - ui->L;
  558. _U = ui->U + i * LA_RH; _B = _U+LA_RH;
  559. }else{
  560. Seg = (ui->R - ui->L) / Len;
  561. _L = ui->L + i * Seg; _R=_L+Seg;
  562. }
  563. if(IsIcon){
  564. sprintf(buf, "%lc", laGetInt(&ui->PP));
  565. }else{
  566. buf[0] = '\0'; buf2[0] = '\0';
  567. if(Len==1){ strcat(buf2, transLate(ui->PP.LastPs->p->Name)); }
  568. if(i<8)strcat(Len==1?buf:buf2,&prefix[i]);
  569. strPrintIntAfter(buf, 48, Data[i]);
  570. strAppend(buf, ui->PP.LastPs->p->Unit ? transLate(ui->PP.LastPs->p->Unit) : "");
  571. }
  572. if (ui->Extra && ui->Extra->On == i + 1){
  573. Original = ui->State;
  574. ui->State = LA_UI_ACTIVE;
  575. }
  576. if(IsKnob && !ui->Extra->Edit){
  577. real ctrx = (real)(_L+_R)/2.0f, ctry=(real)(_U+_B)/2.0f, radius=TNS_MIN2((_B-_U)/2.0f,(_R-_L)/2.0f);
  578. tnsUseNoTexture();
  579. real dgx=0,dgy=0;
  580. if(radius*2>(_B-_U)-LA_RH/5){ dgx = radius/1.5; }
  581. if(radius*2>(_R-_L)-LA_RH/5){ dgy = radius/1.5; }
  582. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  583. tnsVertex2d(_L, ctry-dgy); tnsVertex2d(_L, _U); tnsVertex2d(ctrx-dgx, _U); tnsPackAs(GL_LINE_STRIP);
  584. tnsVertex2d(_R, ctry-dgy); tnsVertex2d(_R, _U); tnsVertex2d(ctrx+dgx, _U); tnsPackAs(GL_LINE_STRIP);
  585. tnsVertex2d(_R, ctry+dgy); tnsVertex2d(_R, _B); tnsVertex2d(ctrx+dgx, _B); tnsPackAs(GL_LINE_STRIP);
  586. tnsVertex2d(_L, ctry+dgy); tnsVertex2d(_L, _B); tnsVertex2d(ctrx-dgx, _B); tnsPackAs(GL_LINE_STRIP);
  587. real verts[52];//24*2+ctr+overlap
  588. tnsMakeCircle2d(&verts[2],24,ctrx,ctry,radius,0);
  589. tnsVectorCopy2d(&verts[2],&verts[50]);
  590. verts[0]=ctrx; verts[1]=ctry;
  591. tnsColor4dv(laThemeColor(bt,ui->State));
  592. tnsVertexArray2d(verts,26); tnsPackAs(GL_TRIANGLE_FAN);
  593. tnsMakeCircle2d(verts,24,ctrx,ctry,radius,0);
  594. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  595. tnsVertexArray2d(verts,24); tnsPackAs(GL_LINE_LOOP);
  596. if(Ranged){
  597. real arc[52]; int arcindex[26]; // 12 slices 13 ends
  598. real range = (real)(Data[i] - min) / (real)(max - min) * TNS_PI * 1.5;
  599. tnsMakeArc2d(arc,12,ctrx,ctry,radius,TNS_PI*2.75, TNS_PI*2.75 + range);
  600. tnsMakeArc2d(&arc[26],12,ctrx,ctry,radius*0.6,TNS_PI*2.75, TNS_PI*2.75 + range);
  601. tnsMakeBridgedIndex(arcindex, 13, 0, 0);
  602. real *color = laThemeColor(bt,LA_BT_TEXT|ui->State); //tnsColor4d(LA_COLOR3(color),0.3);
  603. tnsColor4dv(color);
  604. tnsVertexArray2d(arc,26); tnsIndexArray(arcindex,26); tnsPackAs(GL_TRIANGLE_STRIP);
  605. tnsMakeArc2d(&arc[2],12,ctrx,ctry,radius*0.6,TNS_PI*2.75, TNS_PI*4.25);
  606. tnsVertexArray2d(&arc[2],13);
  607. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  608. tnsPackAs(GL_LINE_STRIP);
  609. }
  610. }else{
  611. if(!NoDecal){
  612. tnsUseNoTexture();
  613. tnsColor4dv(laThemeColor(bt,ui->State));
  614. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  615. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  616. tnsPackAs(GL_TRIANGLE_FAN);
  617. if (Ranged){
  618. int L1 = _L;
  619. int R1 = (real)(Data[i] - min) / (real)(max - min) * (real)(Seg) + L1;
  620. tnsUseNoTexture(); real* color=laThemeColor(bt,LA_BT_TEXT);
  621. tnsColor4d(LA_COLOR3(color),0.3);
  622. tnsVertex2d(L1, _U); tnsVertex2d(R1, _U);
  623. tnsVertex2d(R1, _B); tnsVertex2d(L1, _B);
  624. tnsPackAs(GL_TRIANGLE_FAN);
  625. }
  626. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  627. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  628. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  629. tnsPackAs(GL_LINE_LOOP);
  630. }
  631. if (ui->Extra->On == i + 1 && ui->Extra->Edit){
  632. uint32_t *buf = strGetCursorLine(ui->Extra->Edit, 0)->Buf;
  633. int LL = _L + (Seg - tnsStringGetWidthU(buf, 0, ui->Flags&LA_TEXT_MONO)) / 2;
  634. tnsColor4dv(laThemeColor(bt, LA_BT_TEXT));
  635. la_SingleLineStringDrawSelection(ui, _L, _U, bt, buf, ui->Extra->Edit);
  636. tnsDrawStringM(0, buf, laThemeColor(bt, LA_BT_TEXT_ACTIVE), _L + bt->LM, _R - bt->RM, _U, ui->Flags);
  637. }else{
  638. tnsDrawStringWithPriority(NoLabel?0:buf2, buf,
  639. IsDisabled?laThemeColor(bt, LA_BT_DISABLED):laThemeColor(bt, LA_BT_TEXT|ui->State), bt->TextAlign, _L + bt->LM, _R - bt->RM, _U, ui->Flags);//, ui->ExtraInstructions);
  640. }
  641. }
  642. if (ui->Extra && ui->Extra->On == i + 1) ui->State = Original;
  643. }
  644. tnsFlush();
  645. }
  646. void la_FloatDraw(laUiItem *ui, int h){
  647. laBoxedTheme *bt = (*ui->Type->Theme);
  648. real Data[32];
  649. int Len, i, W, Seg;
  650. char buf[48] = {0};
  651. char buf2[48] = {0};
  652. char prefix[8][64] = {0};
  653. int Original;
  654. int Ranged;
  655. real min, max;
  656. int s, State;
  657. int IsVertical=ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  658. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  659. int IsRad=ui->PP.LastPs->p->IsRadAngle;
  660. int NoLabel=ui->Flags&LA_UI_FLAGS_NO_LABEL;
  661. int IsDisabled=ui->Flags&LA_UI_FLAGS_DISABLED;
  662. int IsKnob = ui->Flags&LA_UI_FLAGS_NODE_CONTAINER;
  663. if (laIsPropertyReadOnly(&ui->PP) && !NoDecal) ui->State = LA_BT_DISABLED;
  664. laGetFloatArray(&ui->PP, Data);
  665. Len = laGetArrayLength(&ui->PP);
  666. laGetPrefixP(&ui->PP, prefix);
  667. Ranged = laGetFloatRange(&ui->PP, &min, &max);
  668. for (i = 0; i < Len; i++){
  669. int _L=ui->L, _R=ui->R, _U=ui->U, _B=ui->B;
  670. if(IsVertical){
  671. Seg = ui->R - ui->L;
  672. _U = ui->U + i * LA_RH; _B = _U+LA_RH;
  673. }else{
  674. Seg = (ui->R - ui->L) / Len;
  675. _L = ui->L + i * Seg; _R=_L+Seg;
  676. }
  677. buf[0] = '\0'; buf2[0] = '\0';
  678. if(Len==1){ strcat(buf2, transLate(ui->PP.LastPs->p->Name)); }
  679. if(i<8)strcat(Len==1?buf:buf2, &prefix[i]);
  680. strPrintFloatAfter(buf, 48, 3, IsRad?deg(Data[i]):Data[i]);
  681. strAppend(buf, ui->PP.LastPs->p->Unit ? transLate(ui->PP.LastPs->p->Unit) : "");
  682. if (ui->Extra && ui->Extra->On == i + 1){
  683. Original = ui->State;
  684. ui->State = LA_UI_ACTIVE;
  685. }
  686. if(IsKnob && !ui->Extra->Edit){
  687. real ctrx = (real)(_L+_R)/2.0f, ctry=(real)(_U+_B)/2.0f, radius=TNS_MIN2((_B-_U)/2.0f,(_R-_L)/2.0f);
  688. tnsUseNoTexture();
  689. real dgx=0,dgy=0;
  690. if(radius*2>(_B-_U)-LA_RH/5){ dgx = radius/1.5; }
  691. if(radius*2>(_R-_L)-LA_RH/5){ dgy = radius/1.5; }
  692. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  693. tnsVertex2d(_L, ctry-dgy); tnsVertex2d(_L, _U); tnsVertex2d(ctrx-dgx, _U); tnsPackAs(GL_LINE_STRIP);
  694. tnsVertex2d(_R, ctry-dgy); tnsVertex2d(_R, _U); tnsVertex2d(ctrx+dgx, _U); tnsPackAs(GL_LINE_STRIP);
  695. tnsVertex2d(_R, ctry+dgy); tnsVertex2d(_R, _B); tnsVertex2d(ctrx+dgx, _B); tnsPackAs(GL_LINE_STRIP);
  696. tnsVertex2d(_L, ctry+dgy); tnsVertex2d(_L, _B); tnsVertex2d(ctrx-dgx, _B); tnsPackAs(GL_LINE_STRIP);
  697. real verts[52];//24*2+ctr+overlap
  698. tnsMakeCircle2d(&verts[2],24,ctrx,ctry,radius,0);
  699. tnsVectorCopy2d(&verts[2],&verts[50]);
  700. verts[0]=ctrx; verts[1]=ctry;
  701. tnsColor4dv(laThemeColor(bt,ui->State));
  702. tnsVertexArray2d(verts,26); tnsPackAs(GL_TRIANGLE_FAN);
  703. tnsMakeCircle2d(verts,24,ctrx,ctry,radius,0);
  704. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  705. tnsVertexArray2d(verts,24); tnsPackAs(GL_LINE_LOOP);
  706. if(Ranged){
  707. real arc[52]; int arcindex[26]; // 12 slices 13 ends
  708. real range,rstart;
  709. if(min<0&&max>0){ rstart=TNS_PI*3.5; range = (real)(Data[i]) / (real)(max) * TNS_PI * 1.5 * max/(max-min);}
  710. else{ rstart=TNS_PI*2.75; range = (real)(Data[i] - min) / (real)(max - min) * TNS_PI * 1.5; }
  711. tnsMakeArc2d(arc,12,ctrx,ctry,radius,rstart, rstart + range);
  712. tnsMakeArc2d(&arc[26],12,ctrx,ctry,radius*0.6,rstart, rstart + range);
  713. tnsMakeBridgedIndex(arcindex, 13, 0, 0);
  714. real *color = laThemeColor(bt,LA_BT_TEXT|ui->State); //tnsColor4d(LA_COLOR3(color),0.3);
  715. tnsColor4dv(color);
  716. tnsVertexArray2d(arc,26); tnsIndexArray(arcindex,26); tnsPackAs(GL_TRIANGLE_STRIP);
  717. tnsMakeArc2d(&arc[2],12,ctrx,ctry,radius*0.6,TNS_PI*2.75, TNS_PI*4.25);
  718. arc[0] = ctrx + cos(TNS_PI*2.75) * radius; arc[1] = ctry + sin(TNS_PI*2.75) * radius;
  719. arc[28] =ctrx + cos(TNS_PI*4.25) * radius; arc[29] =ctry + sin(TNS_PI*4.25) * radius;
  720. tnsVertexArray2d(arc,15);
  721. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  722. tnsPackAs(GL_LINE_STRIP);
  723. }
  724. }else{
  725. if(!NoDecal){
  726. tnsUseNoTexture();
  727. tnsColor4dv(laThemeColor(bt,ui->State));
  728. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  729. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  730. tnsPackAs(GL_TRIANGLE_FAN);
  731. if (Ranged){
  732. int L1 = _L;
  733. int R1 = (real)(Data[i] - min) / (real)(max - min) * (real)(Seg) + L1;
  734. tnsUseNoTexture(); real* color=laThemeColor(bt,LA_BT_TEXT);
  735. tnsColor4d(LA_COLOR3(color),0.3);
  736. tnsVertex2d(L1, _U); tnsVertex2d(R1, _U);
  737. tnsVertex2d(R1, _B); tnsVertex2d(L1, _B);
  738. tnsPackAs(GL_TRIANGLE_FAN);
  739. }
  740. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  741. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  742. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  743. tnsPackAs(GL_LINE_LOOP);
  744. }
  745. if (ui->Extra->On == i + 1 && ui->Extra->Edit){
  746. uint32_t *buf = strGetCursorLine(ui->Extra->Edit,0)->Buf;
  747. int LL = _L + (Seg - tnsStringGetWidthU(buf, 0, ui->Flags&LA_TEXT_MONO)) / 2;
  748. tnsColor4dv(laThemeColor(bt, LA_BT_TEXT));
  749. la_SingleLineStringDrawSelection(ui, _L, _U, bt, buf, ui->Extra->Edit);
  750. tnsDrawStringM(0, buf, laThemeColor(bt, LA_BT_TEXT_ACTIVE), _L + bt->LM, _R - bt->RM, _U, ui->Flags);
  751. }else{
  752. tnsDrawStringWithPriority(NoLabel?0:buf2, buf,
  753. IsDisabled?laThemeColor(bt, LA_BT_DISABLED):laThemeColor(bt, LA_BT_TEXT|ui->State), bt->TextAlign, _L + bt->LM, _R - bt->RM, _U, ui->Flags);//, ui->ExtraInstructions);
  754. }
  755. }
  756. if (ui->Extra && ui->Extra->On == i + 1) ui->State = Original;
  757. }
  758. tnsFlush();
  759. }
  760. void la_FloatArrayColorDraw(laUiItem *ui, int h){
  761. laBoxedTheme *bt = (*ui->Type->Theme);
  762. real Data[32];
  763. int Len, i;
  764. int IsColorful=ui->Flags&LA_UI_FLAGS_COLORFUL;
  765. laGetFloatArray(&ui->PP, Data);
  766. Len = laGetArrayLength(&ui->PP);
  767. if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LogsRGB(Data); }
  768. tnsUseNoTexture();
  769. if(IsColorful){
  770. int sw=(ui->R-ui->L)/2;
  771. tnsColor4d(Data[0], Data[1], Data[2], 1);
  772. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->L+sw, ui->U);
  773. tnsVertex2d(ui->L+sw, ui->B); tnsVertex2d(ui->L, ui->B);
  774. tnsPackAs(GL_TRIANGLE_FAN);
  775. tnsColor4d(Data[0], Data[1], Data[2], Len>3?Data[3]:1);
  776. tnsVertex2d(ui->L+sw, ui->U); tnsVertex2d(ui->R, ui->U);
  777. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L+sw, ui->B);
  778. tnsUseHalftone(1.0); tnsPackAs(GL_TRIANGLE_FAN); tnsUseHalftone(0.0);
  779. }else{
  780. tnsColor4d(Data[0], Data[1], Data[2], 1);
  781. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  782. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  783. tnsPackAs(GL_TRIANGLE_FAN);
  784. }
  785. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  786. if(!NoDecal){
  787. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  788. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  789. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  790. tnsPackAs(GL_LINE_LOOP);
  791. }
  792. tnsFlush();
  793. }
  794. void la_EnumSelectorDraw(laUiItem *ui, int h){
  795. laEnumItem *Data[32], Len;
  796. laBoxedTheme *bt = (*ui->Type->Theme);
  797. char buf[48] = {0};
  798. char buf2[48] = {0};
  799. char prefix[8][64]= {0};
  800. laEnumProp *ep = ui->PP.LastPs->p;
  801. int HasIcon = laEnumHasIcon(&ui->PP);
  802. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  803. int IconOnly=ui->Flags&LA_UI_FLAGS_ICON;
  804. int NoEvent=ui->Flags&LA_UI_FLAGS_NO_EVENT;
  805. int Highlight=ui->Flags&LA_UI_FLAGS_HIGHLIGHT;
  806. // norm e1
  807. // expand e1 e2 e3
  808. // expand vertical (vertical)
  809. // arr expand e1 e1 e3
  810. // e2 e2 e3
  811. // arr exp+vert e1 e1
  812. // e2 e2
  813. // e3 e3
  814. tnsUseNoTexture();
  815. laGetEnumArray(&ui->PP,Data);
  816. laEnumItem* ei, *use_ei;
  817. int IsVertical = ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  818. int IsExpand = ui->Flags&LA_UI_FLAGS_EXPAND;
  819. int IsCycle = ui->Flags&LA_UI_FLAGS_CYCLE;
  820. int ArrLen = laGetArrayLength(&ui->PP);
  821. if(ArrLen==1){ if(!IsExpand) IsVertical=0; }else{ IsExpand=1; }
  822. int EnumLen = (IsExpand&&(!IsCycle)) ? laGetEnumEntryLen(&ui->PP) : 1;
  823. if(Highlight&&ArrLen!=1){laGetPrefixP(&ui->PP, prefix);}
  824. if (laIsPropertyReadOnly(&ui->PP) && !NoDecal) ui->State = LA_BT_DISABLED;
  825. int _L,_R,_U,_B, _W=ui->R - ui->L;
  826. if(IsVertical){
  827. if(IsExpand){ _W/=ArrLen; }
  828. }else{
  829. if(IsExpand){ _W/=EnumLen; }
  830. else{ _W/=ArrLen; }
  831. }
  832. int UseIco=0,ico=0; char buft[48]={0}; int HasText=0;
  833. if (ui->ExtraInstructions){
  834. if (ui->Type->OperatorType->ParseArgs){
  835. ui->Type->OperatorType->ParseArgs(ui->Instructions, &UseIco, buft);
  836. }
  837. sprintf(buf,"%s",transLate(buft)); HasText=1;
  838. }
  839. for(int i=0;i<ArrLen;i++){
  840. if(!Data[i]){ Data[i]=((laEnumProp*)ui->PP.LastPs->p)->Items.pFirst; }
  841. _L=ui->L; _R=ui->R; _U=ui->U; _B=ui->B; ei = ep->Items.pFirst;
  842. for(int j=0;j<EnumLen;j++){ if(!HasText)buf[0]=0;
  843. ico=UseIco;
  844. if(IsVertical){
  845. if(IsExpand){ _U=ui->U+j*LA_RH; _L=ui->L+i*_W; }
  846. else{ _U=ui->U+i*LA_RH; _L=ui->L; }
  847. }else{
  848. if(IsExpand){ _U=ui->U+i*LA_RH; _L=ui->L+j*_W; }
  849. else{ _U=ui->U; _L=ui->L+i*_W; }
  850. }
  851. _B=_U+LA_RH; _R=_L+_W;
  852. int ExtraState=ui->State;
  853. if(IsExpand&&!IsCycle){ use_ei = ei; ei=ei->Item.pNext; ExtraState=(use_ei==Data[i])?LA_BT_ACTIVE:0; }
  854. else{ use_ei = Data[i]; if(Highlight && Data[i]->Index!=0){ ExtraState=LA_BT_ACTIVE; } }
  855. if(!NoDecal){
  856. tnsUseNoTexture();
  857. tnsColor4dv(laThemeColor(bt, ExtraState));
  858. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  859. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  860. tnsPackAs(GL_TRIANGLE_FAN);
  861. tnsColor4dv(laThemeColor(bt, LA_BT_BORDER));
  862. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  863. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  864. tnsPackAs(GL_LINE_LOOP);
  865. }
  866. if(Highlight){ if(!HasText && ArrLen==1) strcpy(buf, transLate(ui->PP.LastPs->p->Name)); else{ if(i<8)strcat(buf, &prefix[i]); } }
  867. if((!HasText) && (!buf[0])) strcpy(buf, transLate(use_ei->Name));
  868. int iconR; if(IconOnly)iconR=TNS_MAX2(_L+LA_RH,_R);else{ iconR=TNS_MIN2(_L+LA_RH,_R); }
  869. if (use_ei->IconID && !ico){ ico=use_ei->IconID; }
  870. if (ico) tnsDrawIcon(ico, laThemeColor(bt, LA_BT_TEXT|ExtraState), _L,iconR, _U, LA_TEXT_ALIGN_CENTER);
  871. if(!IconOnly){
  872. int UseFlags=ui->Flags; if(!HasIcon && IsExpand){ if(!(UseFlags&LA_TEXT_ALIGN)); UseFlags|=LA_TEXT_ALIGN_CENTER; }
  873. tnsDrawStringAuto(buf, laThemeColor(bt, LA_BT_TEXT|ExtraState), _L+bt->LM+(HasIcon?LA_RH:0), _R-bt->RM, _U, UseFlags);
  874. }
  875. if (!IsExpand && !IsVertical && !IconOnly && !IsCycle && !NoEvent){
  876. tnsDrawIcon(U'🔻', laThemeColor(bt, LA_BT_TEXT|ExtraState), _R-LA_RH, _R, _U, ui->Flags);
  877. }
  878. }
  879. }
  880. tnsFlush();
  881. }
  882. void la_ButtonDraw(laUiItem *ui, int h){
  883. laBoxedTheme *bt = (*ui->Type->Theme);
  884. char buf[LA_RAW_CSTR_MAX_LEN] = {0};
  885. char *label = 0;
  886. uint32_t IconID=0;
  887. int L;
  888. char *Identifier;
  889. laOperatorProp *ap = 0;
  890. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  891. int IconOnly=ui->Flags&LA_UI_FLAGS_ICON;
  892. int IsHighlight=ui->Flags&LA_UI_FLAGS_HIGHLIGHT;
  893. if (ui->PP.LastPs && ui->PP.LastPs->p){
  894. ap = ui->PP.LastPs->p;
  895. label = transLate(ap->Base.Name);
  896. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  897. IconID = ap->Base.IconID ? ap->Base.IconID : ap->OperatorType->IconID;
  898. }else{
  899. label = transLate(ui->AT->Name);
  900. IconID = ui->AT->IconID;
  901. }
  902. if (ui->AT && (!laOperatorAvailableP(ui->AT, 0, ui->Instructions)))
  903. ui->State = LA_UI_DISABLED;
  904. elif (ap && ap->OperatorType && (!laOperatorAvailablePSafe(ap->OperatorType, ui->PP.RawThis, ui->PP.Go->UseInstance, ui->Instructions))) ui->State = LA_UI_DISABLED;
  905. else if (ui->State == LA_UI_DISABLED) ui->State = LA_UI_NORMAL;
  906. if(!NoDecal){
  907. tnsUseNoTexture();
  908. tnsColor4dv(ui->State==LA_UI_NORMAL?(IsHighlight?laAccentColor(LA_BT_NORMAL):laThemeColor(bt, ui->State)):laThemeColor(bt, ui->State));
  909. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  910. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  911. tnsPackAs(GL_TRIANGLE_FAN);
  912. tnsColor4dv(laThemeColor(bt, LA_BT_BORDER));
  913. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  914. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  915. tnsPackAs(GL_LINE_LOOP);
  916. }
  917. if (ui->ExtraInstructions){
  918. uint32_t tIconID=0;
  919. if (ui->AT && ui->AT->ParseArgs){
  920. ui->AT->ParseArgs(ui->Instructions, &tIconID, buf);
  921. if (buf[0]) label = transLate(buf);
  922. if (tIconID) IconID=tIconID;
  923. }else if (ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  924. laOperatorProp *ap = ui->PP.LastPs->p;
  925. if (ap->OperatorType && ap->OperatorType->ParseArgs){
  926. ap->OperatorType->ParseArgs(ui->Instructions, &tIconID, buf);
  927. if (buf[0]) label = transLate(buf);
  928. if (tIconID) IconID=tIconID;
  929. }
  930. }
  931. }
  932. if (IconID) L = ui->L + bt->LM + h;
  933. else L = ui->L + bt->LM;
  934. if (IconID) tnsDrawIcon(IconID, laThemeColor(bt, ui->State|LA_BT_TEXT), ui->L, IconOnly?(ui->R):(ui->L+LA_RH), ui->U, LA_TEXT_ALIGN_CENTER);
  935. if (!IconOnly) tnsDrawStringAuto(label, laThemeColor(bt, ui->State|LA_BT_TEXT), L, ui->R-bt->RM, ui->U, ui->Flags);
  936. }
  937. void la_LabelDraw(laUiItem *ui, int h){
  938. laBoxedTheme *bt = (*ui->Type->Theme);
  939. int IsDisabled=ui->Flags&LA_UI_FLAGS_DISABLED;
  940. int IsHighlight=ui->Flags&LA_UI_FLAGS_HIGHLIGHT;
  941. if (!ui->State) ui->State = LA_UI_NORMAL;
  942. if (ui->ExtraInstructions && !ui->Instructions){
  943. strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  944. }
  945. //int State = ui->Instructions ? (strArgumentMatch(ui->Instructions, "disabled", "true") ? LA_THEME_DISABLED : LA_UI_NORMAL) : LA_UI_NORMAL;
  946. tnsDrawStringAuto(transLate(ui->Display->Ptr),
  947. IsDisabled?laThemeColor(bt,LA_BT_TEXT|LA_UI_DISABLED):(IsHighlight?laAccentColor(LA_BT_TEXT):laThemeColor(bt,LA_BT_TEXT)),
  948. ui->L, ui->R, ui->U, ui->Flags);
  949. }
  950. void la_SingleLineStringDrawSelection(laUiItem *ui, int Begin, int U, laBoxedTheme *bt, uint32_t *str, laStringEdit *se){
  951. tnsUseNoTexture();
  952. if (!strHasSelection(se)){
  953. tnsColor4dv(laAccentColor(LA_BT_TEXT));
  954. int L = (se->CursorBefore ? tnsStringGetWidthU(str, se->CursorBefore, ui->Flags&LA_TEXT_MONO) : 0) + Begin + bt->LM;
  955. tnsVertex2d(L-1, U + LA_RH - bt->BM);
  956. tnsVertex2d(L-1, U + bt->TM);
  957. tnsVertex2d(L+2, U + bt->TM);
  958. tnsVertex2d(L+2, U + LA_RH - bt->BM);
  959. tnsPackAs(GL_TRIANGLE_FAN);
  960. }else{
  961. int L = (se->BeginBefore ? tnsStringGetWidthU(str, se->BeginBefore, ui->Flags&LA_TEXT_MONO) : 0) + Begin + bt->LM;
  962. int R = (se->EndBefore ? tnsStringGetWidthU(str, se->EndBefore, ui->Flags&LA_TEXT_MONO) : 0) + Begin + bt->LM;
  963. tnsColor4dv(laAccentColor(LA_BT_NORMAL));
  964. tnsVertex2d(L, U + bt->TM);
  965. tnsVertex2d(L, U + LA_RH - bt->BM);
  966. tnsVertex2d(R, U + LA_RH - bt->TM);
  967. tnsVertex2d(R, U + bt->BM);
  968. tnsPackAs(GL_TRIANGLE_FAN);
  969. }
  970. }
  971. void la_SingleLineStringDraw(laUiItem *ui, int h){
  972. laBoxedTheme *bt = (*ui->Type->Theme);
  973. char* _temp[LA_RAW_CSTR_MAX_LEN] = {0}; char* temp=_temp;
  974. uint32_t* line=0;
  975. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  976. int IsDisabled=ui->Flags&LA_UI_FLAGS_DISABLED;
  977. if (!ui->State) ui->State = LA_UI_NORMAL;
  978. if(!NoDecal){
  979. tnsUseNoTexture();
  980. tnsColor4dv(laThemeColor(bt, ui->State));
  981. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  982. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  983. tnsPackAs(GL_TRIANGLE_FAN);
  984. tnsColor4dv(laThemeColor(bt, LA_BT_BORDER));
  985. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  986. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  987. tnsPackAs(GL_LINE_LOOP);
  988. }
  989. if (ui->Extra && ui->Extra->Edit){
  990. line=strGetCursorLine(ui->Extra->Edit,0)->Buf;
  991. }else{
  992. laGetString(&ui->PP, _temp, &temp);
  993. }
  994. if (line) la_SingleLineStringDrawSelection(ui, ui->L+(NoDecal?0:bt->LM), ui->U, bt, line, ui->Extra->Edit);
  995. if(ui->PP.LastPs->p->CanTranslate){ temp=transLate(temp); }
  996. tnsDrawStringAutoM(line?0:temp, line, IsDisabled?laThemeColor(bt,LA_BT_TEXT|LA_UI_DISABLED):laThemeColor(bt,LA_BT_TEXT), ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), ui->U, ui->Flags);
  997. }
  998. void la_MultiStringDraw(laUiItem *ui, int h){
  999. laBoxedTheme *bt = (*ui->Type->Theme);
  1000. char _temp[LA_RAW_CSTR_MAX_LEN] = {0}; char* temp=_temp;
  1001. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  1002. if (!ui->State) ui->State = LA_UI_NORMAL;
  1003. int NumberWidth=bt->LM;
  1004. if((!ui->Extra->Edit) || (ui->Extra->Ptr1!=ui->PP.EndInstance)){
  1005. laGetString(&ui->PP, _temp, &temp);
  1006. strBeginEdit(&ui->Extra->Edit, temp);
  1007. ui->Extra->Ptr1=ui->PP.EndInstance;
  1008. }
  1009. laStringEdit* se=ui->Extra->Edit;
  1010. real MonoWidth=tnsGetMonoFontAdvance(); int Count=se->TotalLines;
  1011. while(Count){ Count/=10; NumberWidth+=MonoWidth; }
  1012. if (ui->State!=LA_UI_ACTIVE){
  1013. strSetEditViewRange(ui->Extra->Edit,
  1014. ui->Extra->HeightCoeff>0?ui->Extra->HeightCoeff:((ui->B-ui->U)/LA_RH),(ui->R-ui->L-NumberWidth-bt->LM*2-bt->RM)/MonoWidth);
  1015. }
  1016. if(!NoDecal){
  1017. tnsUseNoTexture();
  1018. tnsColor4dv(laThemeColor(bt, ui->State));
  1019. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  1020. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  1021. tnsPackAs(GL_TRIANGLE_FAN);
  1022. tnsColor4dv(laThemeColor(bt, LA_BT_BORDER));
  1023. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  1024. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  1025. tnsPackAs(GL_LINE_LOOP);
  1026. tnsColor4d(LA_COLOR3(laThemeColor(bt,LA_BT_BORDER)),0.8);
  1027. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->L+NumberWidth, ui->U);
  1028. tnsVertex2d(ui->L, ui->B); tnsVertex2d(ui->L+NumberWidth, ui->B);
  1029. tnsPackAs(GL_QUADS);
  1030. if(!(se->CursorLine<se->ViewStartLine||se->CursorLine>se->ViewStartLine+se->ViewHeight)){
  1031. int LineU=(se->CursorLine-se->ViewStartLine)*LA_RH+ui->U;
  1032. tnsColor4dv(ui->State==LA_UI_ACTIVE?laAccentColor(LA_BT_NORMAL):laThemeColor(bt,LA_BT_BORDER));
  1033. tnsVertex2d(ui->L, LineU); tnsVertex2d(ui->R, LineU);
  1034. tnsVertex2d(ui->L, LineU+LA_RH); tnsVertex2d(ui->R, LineU+LA_RH);
  1035. tnsPackAs(GL_LINES);
  1036. tnsColor4dv(ui->State==LA_UI_ACTIVE?laAccentColor(LA_BT_TEXT):laThemeColor(bt,LA_BT_TEXT_NORMAL));
  1037. tnsVertex2d(ui->L, LineU); tnsVertex2d(ui->L+NumberWidth, LineU);
  1038. tnsVertex2d(ui->L, LineU+LA_RH); tnsVertex2d(ui->L+NumberWidth, LineU+LA_RH);
  1039. tnsPackAs(GL_QUADS);
  1040. }
  1041. }else{
  1042. NumberWidth=bt->LM;
  1043. }
  1044. tnsColor4dv(laThemeColor(bt, LA_BT_TEXT));
  1045. int Line=0, Skip=0, _L=ui->L+NumberWidth+bt->LM; char num[10]={0};
  1046. for(laStringLine* sl=se->Lines.pFirst;sl;sl=sl->Item.pNext){
  1047. int UseLine=Line+Skip;
  1048. if(UseLine<se->ViewStartLine){ Skip++; continue; }
  1049. if(UseLine>=se->ViewHeight+se->ViewStartLine){ break; }
  1050. int slen=strlenU(sl->Buf);
  1051. sprintf(num,"%d", UseLine+1); int LineU=ui->U+Line*LA_RH;
  1052. tnsDrawStringM(num, 0, laThemeColor(bt, ((UseLine==se->CursorLine)?LA_BT_NORMAL:LA_BT_TEXT)),
  1053. _L-bt->LM -(tnsStringGetWidth(num, 0, ui->Flags&LA_TEXT_MONO)), ui->R, LineU, ui->Flags);
  1054. if(slen>=se->ViewStartCol){
  1055. tnsDrawStringM(0, &sl->Buf[se->ViewStartCol], laThemeColor(bt, ui->State|LA_BT_TEXT), _L, ui->R, LineU, ui->Flags|LA_TEXT_OVERFLOW_ARROW);
  1056. }
  1057. if(UseLine>=se->BeginLine&&UseLine<=se->EndLine){
  1058. int BeginC=UseLine==se->BeginLine?se->BeginBefore:0; int EndC=UseLine==se->EndLine?se->EndBefore:slen;
  1059. BeginC-=se->ViewStartCol; EndC-=se->ViewStartCol; if(EndC>se->ViewWidth)EndC=se->ViewWidth;
  1060. tnsUseNoTexture();
  1061. tnsVertex2d(BeginC*MonoWidth+_L, LineU); tnsVertex2d(EndC*MonoWidth+_L, LineU);
  1062. tnsVertex2d(EndC*MonoWidth+_L, LineU+LA_RH); tnsVertex2d(BeginC*MonoWidth+_L, LineU+LA_RH);
  1063. tnsColor4dv(laAccentColor(LA_BT_NORMAL));
  1064. tnsPackAs(GL_TRIANGLE_FAN);
  1065. }
  1066. int len=strlenU(sl->Buf);
  1067. if(UseLine==se->CursorLine){
  1068. int Dist=se->CursorBefore==0?0:tnsStringGetWidthU(sl->Buf,se->CursorBefore,ui->Flags&LA_TEXT_MONO);
  1069. tnsUseNoTexture(); int d=se->ViewStartCol*MonoWidth; real w2=LA_RH/12;
  1070. tnsColor4dv(ui->State==LA_UI_ACTIVE?laAccentColor(LA_BT_TEXT):laThemeColor(bt,LA_BT_TEXT_NORMAL));
  1071. tnsVertex2d(_L+Dist-w2-d, LineU); tnsVertex2d(_L+Dist+w2-d, LineU);
  1072. tnsVertex2d(_L+Dist-w2-d, LineU+LA_RH); tnsVertex2d(_L+Dist+w2-d, LineU+LA_RH);
  1073. tnsPackAs(GL_QUADS);
  1074. }
  1075. Line++;
  1076. tnsFlush();
  1077. }
  1078. if(ui->Extra->HeightCoeff>=0)
  1079. tnsDrawStringAuto("◿",laThemeColor(bt,LA_BT_BORDER),ui->R-LA_RH, ui->R, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  1080. if(!NoDecal){
  1081. char buf[100]={0}; sprintf(buf, "%d,%d | %d Lines", se->CursorLine+1, se->CursorBefore+1, se->TotalLines);
  1082. tnsDrawStringAuto(buf,laThemeColor(bt,LA_BT_BORDER),ui->L, ui->R-LA_RH, ui->B-bt->BM-LA_RH, LA_TEXT_MONO|LA_TEXT_ALIGN_RIGHT);
  1083. }
  1084. //if (ui->Extra && ui->Extra->Edit) la_SingleLineStringDrawSelection(ui, ui->L, ui->U, bt, temp, ui->Extra->Edit);
  1085. tnsFlush();
  1086. }
  1087. void la_UiSeperatorDraw(laUiItem *ui, int h){
  1088. laBoxedTheme *bt = (*ui->Type->Theme);
  1089. if (!bt) return;
  1090. if(ui->Flags&LA_UI_FLAGS_TRANSPOSE){
  1091. char str[]="🞄";
  1092. int strw=tnsStringGetWidth(str,0, 0);
  1093. tnsDrawStringM(str, 0, laThemeColor(bt,LA_BT_BORDER), ui->L+(ui->R-ui->L-strw)/2, ui->R, ui->U, 0);
  1094. }else{
  1095. tnsUseNoTexture();
  1096. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1097. real u=(ui->U+ui->B)/2; tnsVertex2d(ui->L, u); tnsVertex2d(ui->R, (ui->U+ui->B)/2);
  1098. tnsPackAs(GL_LINES);
  1099. }
  1100. }
  1101. void la_ColorCircleDrawHCY(laUiItem *ui, int h){
  1102. laBoxedTheme *bt = (*ui->Type->Theme);
  1103. real c = (real)((ui->R + ui->L) / 2) - h / 2; /*- bt->RM*/
  1104. ;
  1105. real r = (ui->B - ui->U - bt->TP - bt->BP) / 2;
  1106. int i = 0;
  1107. real colors[584]={0}; //4*72*2+4*2
  1108. real verts[292]={0}; //72*2*2+2*2
  1109. real hcy[3] = {0, 1, 1};
  1110. real step = 1.0 / 72.0f;
  1111. real RealColor[4] = {0,0,0,1};
  1112. real PickerPos[2];
  1113. real pi_4;
  1114. GLuint index[26];
  1115. real v, cv, sv;
  1116. laGetFloatArray(&ui->PP, RealColor);
  1117. if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LogsRGB(RealColor); }
  1118. tnsRGB2HCY(RealColor, hcy);
  1119. PickerPos[0] = c + cos(hcy[0] * TNS_PI * 2) * pow(hcy[1],1.0f/MAIN.ColorPickerGamma) * r;
  1120. PickerPos[1] = ui->U + r + sin(hcy[0] * TNS_PI * 2) * pow(hcy[1],1.0f/MAIN.ColorPickerGamma) * r;
  1121. hcy[0] = 0;
  1122. hcy[1] = 1;
  1123. for (i; i < 72; i += 1){
  1124. int beg = i * 8;
  1125. hcy[0]+=step; tnsVectorSet3v(&colors[beg],hcy); colors[beg+3]=1;
  1126. tnsVectorSet4v(&colors[beg+4],&colors[beg]); colors[beg+5]=0;
  1127. }
  1128. tnsFlush();
  1129. int IsClay=ui->Flags&LA_UI_FLAGS_COLOR_SPACE_CLAY;
  1130. int ShowInfo=0;
  1131. if(MAIN.CurrentWindow->OutputColorSpace!=TNS_COLOR_SPACE_SRGB && (!IsClay)){
  1132. tnsUniformShowColorOverflowStripes(T->immShader,1);
  1133. }
  1134. if(IsClay){
  1135. tnsUniformInputColorSpace(T->immShader,TNS_COLOR_SPACE_CLAY);
  1136. if(MAIN.CurrentWindow->OutputColorSpace!=TNS_COLOR_SPACE_CLAY) ShowInfo=1;
  1137. }else{
  1138. tnsUniformInputColorSpace(T->immShader,TNS_COLOR_SPACE_SRGB);
  1139. }
  1140. tnsUseNoTexture();
  1141. tnsVectorSet4(&colors[576],1,1,hcy[2],1);
  1142. tnsVectorSet4(&colors[580],1,0,hcy[2],1);
  1143. tnsColorArray4d(colors, 146);
  1144. tnsMakeCircle2d(verts, 72, c, ui->U + r, r, 1);
  1145. for(int i=0;i<73;i++){ tnsVectorSet2(&verts[2+i*4],c,ui->U + r); }
  1146. tnsVectorSet2v(&verts[288],&verts[0]);
  1147. tnsVectorSet2v(&verts[290],&verts[2]);
  1148. tnsVertexArray2d(verts, 146);
  1149. tnsPackAs(GL_TRIANGLE_STRIP);
  1150. tnsUniformColorMode(T->immShader,1); tnsUniformHCYGamma(T->immShader,MAIN.ColorPickerGamma);
  1151. tnsFlush();
  1152. tnsUniformColorMode(T->immShader,0);
  1153. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1154. tnsMakeCircle2d(verts, 72, c, ui->U + r, r, 0);
  1155. tnsVertexArray2d(verts, 72);
  1156. tnsPackAs(GL_LINE_LOOP);
  1157. pi_4 = TNS_PI / 4;
  1158. tnsMakeArc2d(&verts[26], 12, c, ui->U + r, r + bt->LM + h, pi_4, -pi_4);
  1159. tnsMakeArc2d(verts, 12, c, ui->U + r, r + bt->LM, pi_4, -pi_4);
  1160. tnsMakeLinerGradient4d(&colors[52], 13, 0, 0, 0, 1, 1, 1, 1, 1);
  1161. tnsMakeLinerGradient4d(colors, 13, 0, 0, 0, 1, 1, 1, 1, 1);
  1162. tnsMakeBridgedIndex(index, 13, 0, 0);
  1163. tnsColorArray4d(colors, 26);
  1164. tnsVertexArray2d(verts, 26);
  1165. tnsIndexArray(index, 26);
  1166. tnsPackAs(GL_QUAD_STRIP);
  1167. tnsMakeArc2d(&verts[26], 12, c, ui->U + r, r + bt->LM + h, -pi_4, pi_4);
  1168. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1169. tnsVertexArray2d(verts, 26);
  1170. tnsPackAs(GL_LINE_LOOP);
  1171. v = -hcy[2] + 0.5;
  1172. cv = cos(v / 2 * TNS_PI);
  1173. sv = sin(v / 2 * TNS_PI);
  1174. verts[0] = cv * r + c;
  1175. verts[1] = sv * r + ui->U + r;
  1176. verts[2] = cv * (r + h) + c;
  1177. verts[3] = sv * (r + h) + ui->U + r;
  1178. tnsColor4d(1, 1, 1, 1);
  1179. tnsVertexArray2d(verts, 2);
  1180. tnsPackAs(GL_LINES);
  1181. tnsColor4dv(RealColor);
  1182. tnsMakeCircle2d(verts, 16, PickerPos[0], PickerPos[1], 8,0);
  1183. tnsVertexArray2d(verts, 16);
  1184. tnsPackAs(GL_TRIANGLE_FAN);
  1185. tnsColor4d(1, 1, 1, 1);
  1186. tnsVertexArray2d(verts, 16);
  1187. tnsPackAs(GL_LINE_LOOP);
  1188. tnsMakeCircle2d(verts, 16, PickerPos[0], PickerPos[1], 7,0);
  1189. tnsColor4d(0.1, 0.1, 0.1, 1);
  1190. tnsVertexArray2d(verts, 16);
  1191. tnsPackAs(GL_LINE_LOOP);
  1192. if(ui->Extra->HeightCoeff>=0) tnsDrawStringAuto("◿",laThemeColor(bt,LA_BT_BORDER),ui->R-LA_RH, ui->R, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  1193. if(IsClay) tnsDrawStringAuto("Clay",laThemeColor(bt,LA_BT_BORDER),ui->L, c-r+LA_RH, ui->U+bt->TM, LA_TEXT_ALIGN_RIGHT|LA_TEXT_MONO);
  1194. if(ShowInfo) tnsDrawStringAuto("🛈",laThemeColor(bt,LA_BT_TEXT),c-r, ui->R, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_LEFT);
  1195. tnsFlush();
  1196. tnsUniformShowColorOverflowStripes(T->immShader,0);
  1197. tnsUniformInputColorSpace(T->immShader,0);
  1198. }
  1199. void la_MenuItemDraw(laUiItem *ui, int h){
  1200. laBoxedTheme *bt = (*ui->Type->Theme);
  1201. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  1202. if(!NoDecal){
  1203. tnsUseNoTexture();
  1204. tnsColor4dv(laThemeColor(bt, ui->State));
  1205. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  1206. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  1207. tnsPackAs(GL_TRIANGLE_FAN);
  1208. tnsColor4dv(laThemeColor(bt, LA_BT_BORDER));
  1209. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  1210. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  1211. tnsPackAs(GL_LINE_LOOP);
  1212. }
  1213. tnsDrawStringAuto(transLate(ui->Display->Ptr), laThemeColor(bt, LA_BT_TEXT|ui->State), ui->L+bt->LM, ui->R, ui->U, ui->Flags);
  1214. }
  1215. void la_ConditionToggleDraw(laUiItem *ui, int h){
  1216. laBoxedTheme *bt = (*ui->Type->Theme);
  1217. char temp[128] = {0};
  1218. char *buf[LA_RAW_CSTR_MAX_LEN];
  1219. uint32_t IconID;
  1220. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  1221. if (!ui->State) ui->State = LA_UI_NORMAL;
  1222. int UseState=ui->State;
  1223. if (!(ui->Flags&LA_TEXT_ALIGN)) ui->Flags|=LA_TEXT_ALIGN_CENTER;
  1224. if(!NoDecal){
  1225. tnsUseNoTexture();
  1226. tnsColor4dv(laThemeColor(bt, ui->State));
  1227. tnsVertex2d(ui->L, ui->U);
  1228. tnsVertex2d(ui->R, ui->U);
  1229. tnsVertex2d(ui->R, ui->B);
  1230. tnsVertex2d(ui->L, ui->B);
  1231. tnsPackAs(GL_TRIANGLE_FAN);
  1232. tnsColor4dv(laThemeColor(bt, LA_BT_BORDER));
  1233. tnsVertex2d(ui->L, ui->U);
  1234. tnsVertex2d(ui->R, ui->U);
  1235. tnsVertex2d(ui->R, ui->B);
  1236. tnsVertex2d(ui->L, ui->B);
  1237. tnsPackAs(GL_LINE_LOOP);
  1238. }else{
  1239. UseState=LA_UI_NORMAL;
  1240. }
  1241. buf[0] = 0;
  1242. if (ui->ExtraInstructions){
  1243. if (ui->Type->OperatorType->ParseArgs){
  1244. ui->Type->OperatorType->ParseArgs(ui->Instructions, &IconID, buf);
  1245. }
  1246. }
  1247. if (buf[0]) tnsDrawStringAuto(transLate(buf), laThemeColor(bt, LA_BT_TEXT|UseState), ui->L+bt->LM, ui->R-bt->RM, ui->U, ui->Flags);
  1248. else
  1249. tnsDrawStringAuto(ui->State == LA_UI_ACTIVE ? "⯆" : "⯈", laThemeColor(bt, LA_BT_TEXT|UseState), ui->L+bt->LM, ui->R-bt->RM, ui->U, ui->Flags);
  1250. }
  1251. void la_DrawColumnAdjusterRecursive(int U, int B, laColumn *c, int W, tnsVector3d color, int LeftMost){
  1252. if (c->LS){
  1253. la_DrawColumnAdjusterRecursive(U, B, c->LS, W, color, LeftMost);
  1254. la_DrawColumnAdjusterRecursive(U, B, c->RS, W, color, LeftMost);
  1255. }else{
  1256. if(c->IL==LeftMost) return;
  1257. tnsDrawStringAuto("❘", color, c->IL-LA_RH, c->IL+LA_RH, U, LA_TEXT_ALIGN_CENTER);
  1258. }
  1259. }
  1260. void la_ColumnAdjusterDraw(laUiItem *ui, int h){
  1261. laBoxedTheme *bt = (*ui->Type->Theme);
  1262. tnsUseNoTexture();
  1263. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1264. la_DrawColumnAdjusterRecursive(ui->U, ui->U + LA_RH, ui->C, (bt->LM+bt->RM)/2, laThemeColor(bt, LA_BT_BORDER), ui->C->IL);
  1265. }
  1266. void la_ColumnViewerDraw(laUiItem *ui, int h){
  1267. laBoxedTheme *bt = (*ui->Type->Theme);
  1268. laColumn *c = ui->PP.EndInstance;
  1269. int W = ui->R - ui->L - bt->LM - bt->RM;
  1270. //if (c->IR == c->IL)
  1271. // return;
  1272. int T = c->Top->IR - c->Top->IL;
  1273. int L = (int)((real)(c->IL - c->Top->IL) * W / T) + ui->L + bt->LM,
  1274. R = (int)((real)(c->IR - c->Top->IL) * W / T) + ui->L + bt->LM;
  1275. tnsUseNoTexture();
  1276. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1277. tnsVertex2d(L, ui->U + bt->TM);
  1278. tnsVertex2d(R, ui->U + bt->TM);
  1279. tnsVertex2d(R, ui->B - bt->BM);
  1280. tnsVertex2d(L, ui->B - bt->BM);
  1281. tnsPackAs(GL_TRIANGLE_FAN);
  1282. }
  1283. void la_NodeSocketDraw(laUiItem *ui, int h){
  1284. laBoxedTheme *bt = (*ui->Type->Theme);
  1285. char* label=0; char* icon;
  1286. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  1287. real* ColorBkg=0,*ColorSocket;
  1288. if(pc==LA_PC_SOCKET_IN) { laNodeInSocket*s=ui->PP.EndInstance; ColorSocket=laThemeColor(bt,LA_BT_TEXT); ColorBkg=laThemeColor(bt, LA_BT_NORMAL); label=s->Label?s->Label->Ptr:""; }
  1289. elif(pc==LA_PC_SOCKET_OUT){ laNodeOutSocket*s=ui->PP.EndInstance; ColorSocket=laThemeColor(bt,LA_BT_TEXT_ACTIVE); ColorBkg=laThemeColor(bt, LA_BT_ACTIVE); label=s->Label?s->Label->Ptr:""; }
  1290. int IsDisabled=ui->Flags&LA_UI_FLAGS_DISABLED;
  1291. tnsUseNoTexture();
  1292. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  1293. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  1294. tnsColor4dv(ColorBkg);
  1295. tnsPackAs(GL_TRIANGLE_FAN);
  1296. int tl,tr,tu,sl,sr,su;
  1297. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ tl=ui->L; tu=ui->U; tr=ui->R; sl=ui->L; sr=ui->R; su=ui->U+LA_RH; }
  1298. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ tl=ui->L; tu=ui->U+LA_RH; tr=ui->R; sl=ui->L; sr=ui->R; su=ui->U; }
  1299. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ tl=ui->L; tu=ui->U; tr=tl+LA_2RH; sl=ui->L+LA_2RH; sr=ui->R; su=ui->U; }
  1300. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ tu=ui->U; tr=ui->R; tl=tr-LA_2RH; sl=ui->L; sr=tl; su=ui->U; }
  1301. else{ sl=ui->L; su=ui->U; sr=ui->R; label=0; }
  1302. tnsDrawStringAuto("⭗", IsDisabled?laThemeColor(bt,LA_BT_TEXT|LA_UI_DISABLED):ColorSocket, sl, sr, su, LA_TEXT_ALIGN_CENTER);
  1303. if(label) tnsDrawStringAuto(label, IsDisabled?laThemeColor(bt,LA_BT_TEXT|LA_UI_DISABLED):ColorSocket, tl, tr, tu, LA_TEXT_ALIGN_CENTER|LA_TEXT_MONO);
  1304. }
  1305. void la_HeightAdjusterDraw(laUiItem *ui, int h){
  1306. laBoxedTheme *bt = (*ui->Type->Theme);
  1307. char* str="☰";
  1308. if(ui->State==LA_BT_ACTIVE){ str="🡙"; }
  1309. tnsDrawStringAuto(str, laThemeColor(bt,LA_BT_TEXT), ui->L-1000, ui->R+1000, ui->U, LA_TEXT_ALIGN_CENTER);
  1310. }
  1311. void la_RawPropDraw(laUiItem *ui, int h){
  1312. laBoxedTheme *bt = (*ui->Type->Theme);
  1313. int s=0;
  1314. //void* data=laGetRaw(&ui->PP, &s);
  1315. //char* buf[128]; sprintf(buf,"%d bytes of raw data at 0x%0x", s, data);
  1316. tnsDrawStringAuto("RAW DATA", laThemeColor(bt,LA_BT_TEXT), ui->L, ui->R, ui->U, ui->Flags|LA_TEXT_MONO);
  1317. }
  1318. void la_MapperDraw(laUiItem *ui, int h){
  1319. laBoxedTheme *bt = (*ui->Type->Theme);
  1320. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  1321. if(!NoDecal){
  1322. tnsUseNoTexture();
  1323. tnsColor4dv(laThemeColor(bt, LA_BT_NORMAL));
  1324. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  1325. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  1326. tnsPackAs(GL_TRIANGLE_FAN);
  1327. tnsColor4dv(laThemeColor(bt, LA_BT_BORDER));
  1328. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  1329. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  1330. tnsPackAs(GL_LINE_LOOP);
  1331. }
  1332. laPropContainer* pc=la_EnsureSubTarget(ui->PP.LastPs->p,ui->PP.EndInstance);
  1333. if(!pc || pc!=LA_PC_MAPPER || !ui->PP.EndInstance){
  1334. tnsDrawStringAuto("Property is not a la_value_mapper.",0,ui->L+bt->LM,ui->R-bt->RM,bt->TM,LA_TEXT_LINE_WRAP); return;
  1335. }
  1336. laValueMapper* vm=ui->PP.EndInstance; int any=0;
  1337. tnsColor4dv(laAccentColor(LA_BT_TEXT));
  1338. for(laValueMapperPoint* vmp=vm->Points.pFirst;vmp;vmp=vmp->Item.pNext){
  1339. tnsVertex2d(tnsInterpolate(ui->L,ui->R,vmp->x),tnsInterpolate(ui->B,ui->U,vmp->y)); any++;
  1340. } tnsPackAs(GL_LINE_STRIP);
  1341. for(laValueMapperPoint* vmp=vm->Points.pFirst;vmp;vmp=vmp->Item.pNext){
  1342. tnsVertex2d(tnsInterpolate(ui->L,ui->R,vmp->x),tnsInterpolate(ui->B,ui->U,vmp->y));
  1343. } tnsPackAs(GL_POINTS);
  1344. if(any){ glLineWidth(2); glPointSize(5); tnsFlush(); glPointSize(1); glLineWidth(1); }
  1345. }
  1346. void la_ImageDraw(laUiItem *ui, int h){
  1347. laBoxedTheme *bt = (*ui->Type->Theme);
  1348. tnsImage* im=ui->Extra;
  1349. if(!im->Texture) return;
  1350. int W=im->Texture->Width, H=im->Texture->Height;
  1351. int Full=ui->Flags&LA_UI_IMAGE_FULL_W;
  1352. real r=(real)(ui->R-ui->L)/W; if(r<1){W*=r;H*=r;}
  1353. real UseW=Full?(W):((real)LA_RH*ui->SymbolID/H*W);
  1354. real L=(ui->R-ui->L-UseW)/2,U=0,UseH=Full?H:(ui->B-ui->U);
  1355. if(Full){ U=(ui->B-ui->U-H)/2; }
  1356. if(ui->Flags&LA_TEXT_ALIGN_CENTER){ L=0; }
  1357. elif(ui->Flags&LA_TEXT_ALIGN_RIGHT){ L=ui->R-ui->L-UseW; }
  1358. tnsDraw2DTextureDirectly(im->Texture,ui->L+L,ui->U+U,UseW,UseH);
  1359. tnsFlush();
  1360. }
  1361. void la_ValueMeterType1Draw(laUiItem *ui, int h){
  1362. laBoxedTheme *bt = (*ui->Type->Theme);
  1363. int DataI[8]; real Data[8];
  1364. int Len, i, W; real Seg;
  1365. char buf[48] = {0};
  1366. char buf2[48] = {0};
  1367. char prefix[8][64] = {0};
  1368. int Original;
  1369. int Imin=-100, Imax=100;
  1370. real min=-100, max=100;
  1371. int s, State; int IsVertical=ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  1372. int NoLabel=ui->Flags&LA_UI_FLAGS_NO_LABEL;
  1373. int IsInt=(ui->PP.LastPs->p->PropertyType&LA_PROP_INT)?1:0;
  1374. Len = laGetArrayLength(&ui->PP);
  1375. laGetPrefixP(&ui->PP, prefix);
  1376. if(IsInt){
  1377. laGetIntArray(&ui->PP, DataI); for(int i=0;i<Len;i++){ Data[i]=DataI[i]; }
  1378. laGetIntRange(&ui->PP, &Imin, &Imax); min=Imin; max=Imax;
  1379. }else{
  1380. laGetFloatArray(&ui->PP, Data);
  1381. laGetFloatRange(&ui->PP,&min,&max);
  1382. }
  1383. for (i = 0; i < Len; i++){
  1384. int _L=ui->L, _R=ui->R, _U=ui->U, _B=ui->B;
  1385. if(IsVertical){
  1386. Seg = (real)(ui->R-ui->L)/Len;
  1387. _L = ui->L + i * Seg; _R=ui->L + (i+1) * Seg;
  1388. }else{
  1389. Seg = (real)(ui->B-ui->U)/Len;
  1390. _U = ui->U + i * Seg; _B=_U+Seg;
  1391. }
  1392. tnsUseNoTexture();
  1393. tnsColor4dv(laThemeColor(bt,ui->State));
  1394. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  1395. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  1396. tnsPackAs(GL_TRIANGLE_FAN);
  1397. int oflow=0,ofhigh=0;
  1398. if(Data[i]<min){ oflow=1; Data[i]=min; }
  1399. if(Data[i]>max){ ofhigh=1; Data[i]=max; }
  1400. int R1=_R,U1=_U;
  1401. if(IsVertical){ U1 = (real)(max - Data[i]) / (real)(max - min) * (real)(_B-_U) + _U; }
  1402. else{ R1 = (real)(Data[i] - min) / (real)(max - min) * (real)(_R-_L) + _L; }
  1403. tnsUseNoTexture(); real* color=laThemeColor(bt,LA_BT_TEXT);
  1404. tnsColor4d(LA_COLOR3(color),0.4);
  1405. tnsVertex2d(_L, U1); tnsVertex2d(R1, U1);
  1406. tnsVertex2d(R1, _B); tnsVertex2d(_L, _B);
  1407. tnsPackAs(GL_TRIANGLE_FAN);
  1408. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1409. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  1410. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  1411. tnsPackAs(GL_LINE_LOOP);
  1412. if(!NoLabel){
  1413. if(Len==1){ sprintf(buf,ui->PP.LastPs->p->Name); } else{ if(i<8)sprintf(buf,prefix[i]); }
  1414. if(buf[0]) tnsDrawStringAuto(buf, laThemeColor(bt, LA_BT_TEXT), _L + bt->LM, _R - bt->RM, _U, ui->Flags);//, ui->ExtraInstructions);
  1415. }
  1416. if(IsVertical){
  1417. if(oflow){ tnsDrawStringAuto("⯆",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _U, LA_TEXT_ALIGN_CENTER); }
  1418. elif(ofhigh){ tnsDrawStringAuto("⯅",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  1419. }else{
  1420. if(oflow){ tnsDrawStringAuto("⯇",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _U, LA_TEXT_ALIGN_LEFT); }
  1421. elif(ofhigh){ tnsDrawStringAuto("⯈",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _U, LA_TEXT_ALIGN_RIGHT); }
  1422. }
  1423. }
  1424. int trisize=LA_RH/3.0f;
  1425. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  1426. IsInt=(CPP->PP.LastPs->p->PropertyType&LA_PROP_INT)?1:0;
  1427. Len = laGetArrayLength(&CPP->PP);
  1428. laGetPrefixP(&CPP->PP, prefix);
  1429. if(IsInt){
  1430. laGetIntArray(&CPP->PP, DataI); for(int i=0;i<Len;i++){ Data[i]=DataI[i]; }
  1431. laGetIntRange(&CPP->PP, &Imin, &Imax); min=Imin; max=Imax;
  1432. }else{
  1433. laGetFloatArray(&CPP->PP, Data);
  1434. laGetFloatRange(&CPP->PP,&min,&max);
  1435. }
  1436. if(CPP->Slot <= LA_SLOT_MARKER_4){
  1437. for (i = 0; i < Len; i++){
  1438. int _L=ui->L, _R=ui->R, _U=ui->U, _B=ui->B;
  1439. if(IsVertical){
  1440. Seg = (real)(ui->R-ui->L)/Len;
  1441. _L = ui->L + i * Seg; _R=ui->L + (i+1) * Seg;
  1442. }else{
  1443. Seg = (real)(ui->B-ui->U)/Len;
  1444. _U = ui->U + i * Seg; _B=_U+Seg;
  1445. }
  1446. int R1=_R,U1=_U;
  1447. if(IsVertical){ U1 = (real)(max - Data[i]) / (real)(max - min) * (real)(_B-_U) + _U; }
  1448. else{ R1 = (real)(Data[i] - min) / (real)(max - min) * (real)(_R-_L) + _L; }
  1449. tnsUseNoTexture();
  1450. tnsColor4dv(laAccentColor(LA_BT_TEXT));
  1451. if(IsVertical){ tnsVertex2d(_L, U1); tnsVertex2d(R1, U1); }
  1452. else{ tnsVertex2d(R1, U1); tnsVertex2d(R1, _B); }
  1453. tnsPackAs(GL_LINES);
  1454. if(IsVertical){
  1455. if(! CPP->Slot % 2){ tnsVertex2d(_L, U1+trisize); tnsVertex2d(_L+trisize, U1); tnsVertex2d(_L, U1-trisize); }
  1456. else{ tnsVertex2d(_R, U1+trisize); tnsVertex2d(_R-trisize, U1); tnsVertex2d(_R, U1-trisize); }
  1457. }
  1458. else{
  1459. if(! CPP->Slot % 2){ tnsVertex2d(R1-trisize, _B); tnsVertex2d(R1, _B-trisize); tnsVertex2d(R1+trisize, _B); }
  1460. else{ tnsVertex2d(R1-trisize, U1); tnsVertex2d(R1, U1+trisize); tnsVertex2d(R1+trisize, U1); }
  1461. }
  1462. tnsPackAs(GL_TRIANGLES);
  1463. }
  1464. }
  1465. }
  1466. tnsFlush();
  1467. }
  1468. void la_ValueMeterType2Draw(laUiItem *ui, int h){
  1469. laBoxedTheme *bt = (*ui->Type->Theme);
  1470. int DataI[8]; real Data[8]; int SDataI[8]; real SData[8]; int Len, i, W; real Seg;
  1471. char buf[48] = {0}; char buf2[48] = {0};char prefix[16][64] = {0};char limits[2][64]={0};
  1472. int Original;
  1473. int Imin=-100, Imax=100; real min=-100, max=100;
  1474. int s, State; int IsVertical=ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  1475. int NoLabel=ui->Flags&LA_UI_FLAGS_NO_LABEL;
  1476. int IsInt=(ui->PP.LastPs->p->PropertyType&LA_PROP_INT)?1:0;
  1477. Len = laGetArrayLength(&ui->PP);
  1478. laGetPrefixP(&ui->PP, prefix);
  1479. if(IsInt){
  1480. laGetIntArray(&ui->PP, DataI); for(int i=0;i<Len;i++){ Data[i]=DataI[i]; }
  1481. laGetIntRange(&ui->PP, &Imin, &Imax); min=Imin; max=Imax;
  1482. sprintf(limits[0],"%d",Imin); sprintf(limits[1],"%d",Imax);
  1483. }else{
  1484. laGetFloatArray(&ui->PP, Data);
  1485. laGetFloatRange(&ui->PP,&min,&max);
  1486. sprintf(limits[0],"%lf",min); sprintf(limits[1],"%lf",max);
  1487. }
  1488. int sl = TNS_MAX2(abs(ui->SymbolID),5);
  1489. int ScaleLen = sl * LA_RH;
  1490. real seg = abs(ui->TemplateContext)/100;
  1491. int times=1,times10=0;
  1492. while((max-min)/seg > ScaleLen/10){
  1493. seg*=10;
  1494. }
  1495. if(seg>100){ int sseg=seg; while(sseg>=100){ sseg/=10; times*=10; times10++; } }
  1496. for (i = 0; i < Len; i++){
  1497. int _L=ui->L, _R=ui->R, _U=ui->U, _B=ui->B;
  1498. if(IsVertical){
  1499. Seg = (real)(ui->R-ui->L)/Len;
  1500. _L = ui->L + i * Seg; _R=ui->L + (i+1) * Seg;
  1501. }else{
  1502. Seg = (real)(ui->B-ui->U)/Len;
  1503. _U = ui->U + i * Seg; _B=_U+Seg;
  1504. }
  1505. real cx=(_L+_R)/2,cy=(_U+_B)/2,cw=(_R-_L),ch=(_B-_U);
  1506. tnsPushStringClip(_L,_R,_U,_B);
  1507. tnsUseNoTexture();
  1508. tnsColor4dv(laThemeColor(bt,ui->State));
  1509. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  1510. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  1511. tnsPackAs(GL_TRIANGLE_FAN);
  1512. int oflow=0,ofhigh=0;
  1513. if(Data[i]<min){ oflow=1; Data[i]=min; }
  1514. if(Data[i]>max){ ofhigh=1; Data[i]=max; }
  1515. real fac = (real)(Data[i]-min) / (real)(max - min);
  1516. int SL,SR,SU,SB,_SL,_SR,_SU,_SB,Move = fac*ScaleLen;
  1517. if(IsVertical){ SL=_L; SR=_R; SB=_SB=cy+Move; SU=_SU=SB-ScaleLen; TNS_CLAMP(SB,_U,_B); TNS_CLAMP(SU,_U,_B); }
  1518. else{ SL=_SL=cx-Move; SR=_SR=SL+ScaleLen; SB=_B; SU=_U; TNS_CLAMP(SL,_L,_R); TNS_CLAMP(SR,_L,_R); }
  1519. tnsUseNoTexture(); real* color=laThemeColor(bt,LA_BT_TEXT);
  1520. tnsColor4d(LA_COLOR3(color),0.3);
  1521. tnsVertex2d(SL, SU); tnsVertex2d(SR, SU);
  1522. tnsVertex2d(SR, SB); tnsVertex2d(SL, SB);
  1523. tnsPackAs(GL_TRIANGLE_FAN);
  1524. tnsColor4d(LA_COLOR3(color),0.7);
  1525. int scalelow=min/seg-1, scalehigh=max/seg+1;
  1526. for(int si=scalelow;si<=scalehigh;si++){
  1527. for(int ssi=0;ssi<10;ssi++){
  1528. real val=si*seg + ssi*0.1*seg; if(val<min) continue; if(val>max) break;
  1529. real sfac = (real)(val-min) / (max - min); int smove=Move-sfac*ScaleLen;
  1530. real lfac = ssi==0?(si==ssi?0.5:0.3):(ssi==5?0.2:0.1);
  1531. if(IsVertical){ int scaleb=cy+smove; if(scaleb>_B || scaleb<_U) continue;
  1532. tnsVertex2d(cx-cw*lfac,scaleb); tnsVertex2d(cx+cw*lfac,scaleb);
  1533. }else{ int scalel=cx-smove; if(scalel<_L || scalel>_R) continue;
  1534. tnsVertex2d(scalel,cy+ch*lfac); tnsVertex2d(scalel,cy-ch*lfac);
  1535. }
  1536. }
  1537. }
  1538. tnsPackAs(GL_LINES);
  1539. if(!NoLabel){
  1540. for(int si=scalelow;si<=scalehigh;si++){
  1541. real val=si*seg; if(val<min) continue; if(val>max) break;
  1542. real sfac = (real)(val-min) / (max - min); int smove=Move-sfac*ScaleLen;
  1543. if(IsInt) sprintf(buf,"%.0lf",val/times); else sprintf(buf,"%.2lf",val/times);
  1544. if(IsVertical){ int scaleb=cy+smove; if(scaleb>_B+LA_RH2 || scaleb<_U-LA_RH2) continue;
  1545. tnsDrawStringAuto(buf,laThemeColor(bt,LA_BT_TEXT),_L+bt->LM,_R-bt->RM,scaleb-LA_RH2,ui->Flags);
  1546. }else{ int scalel=cx-smove; if(scalel<_L-100 || scalel>_R+100) continue;
  1547. tnsDrawStringAuto(buf,laThemeColor(bt,LA_BT_TEXT),scalel-100,scalel+100,_U,ui->Flags);
  1548. }
  1549. }
  1550. if(IsVertical){
  1551. tnsDrawStringAuto(limits[0],laThemeColor(bt,LA_BT_TEXT|ui->State),_L+bt->LM,_R-bt->RM,_SB,ui->Flags);
  1552. tnsDrawStringAuto(limits[1],laThemeColor(bt,LA_BT_TEXT|ui->State),_L+bt->LM,_R-bt->RM,_SU-LA_RH,ui->Flags);
  1553. }else{
  1554. tnsDrawStringAuto(limits[0],laThemeColor(bt,LA_BT_TEXT|ui->State),_SL-100,_SL-bt->LM,_B-LA_RH,LA_TEXT_ALIGN_RIGHT);
  1555. tnsDrawStringAuto(limits[1],laThemeColor(bt,LA_BT_TEXT|ui->State),_SR+bt->RM,_SR+100,_B-LA_RH,LA_TEXT_ALIGN_LEFT);
  1556. }
  1557. }
  1558. tnsUseNoTexture();
  1559. tnsColor4dv(laAccentColor(LA_BT_BORDER));
  1560. if(IsVertical){tnsVertex2d(_L,cy); tnsVertex2d(_R,cy);}
  1561. else{tnsVertex2d(cx,_U); tnsVertex2d(cx,_B);}
  1562. tnsPackAs(GL_LINES);
  1563. if(times!=1){ sprintf(buf,"%d",times10);
  1564. if(IsVertical && cw>LA_RH) tnsDrawStringAuto(buf,laAccentColor(LA_BT_BORDER),_L+bt->LM,_R-bt->RM,cy,LA_TEXT_MONO|LA_TEXT_ALIGN_RIGHT);
  1565. elif(ch>LA_RH) tnsDrawStringAuto(buf,laAccentColor(LA_BT_BORDER),cx+bt->LM,cx+100,_U,LA_TEXT_MONO|LA_TEXT_ALIGN_LEFT);
  1566. }
  1567. tnsUseNoTexture();
  1568. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1569. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  1570. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  1571. tnsPackAs(GL_LINE_LOOP);
  1572. //if(IsVertical){
  1573. // if(oflow){ tnsDrawStringAuto("⯆",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _U, LA_TEXT_ALIGN_CENTER); }
  1574. // elif(ofhigh){ tnsDrawStringAuto("⯅",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  1575. //}else{
  1576. // if(oflow){ tnsDrawStringAuto("⯇",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _U, LA_TEXT_ALIGN_LEFT); }
  1577. // elif(ofhigh){ tnsDrawStringAuto("⯈",laThemeColor(bt, LA_BT_TEXT), _L+bt->LM,_R-bt->RM, _U, LA_TEXT_ALIGN_RIGHT); }
  1578. //}
  1579. tnsPopStringClip();
  1580. }
  1581. int trisize=LA_RH/3.0f;
  1582. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  1583. IsInt=(CPP->PP.LastPs->p->PropertyType&LA_PROP_INT)?1:0;
  1584. Len = laGetArrayLength(&CPP->PP);
  1585. laGetPrefixP(&CPP->PP, prefix);
  1586. if(IsInt){
  1587. laGetIntArray(&CPP->PP, SDataI); for(int i=0;i<Len;i++){ SData[i]=SDataI[i]; }
  1588. //laGetIntRange(&CPP->PP, &Imin, &Imax); min=Imin; max=Imax;
  1589. }else{
  1590. laGetFloatArray(&CPP->PP, SData);
  1591. //laGetFloatRange(&CPP->PP,&min,&max);
  1592. }
  1593. if(CPP->Slot <= LA_SLOT_MARKER_4){
  1594. for (i = 0; i < Len; i++){
  1595. int _L=ui->L, _R=ui->R, _U=ui->U, _B=ui->B;
  1596. if(IsVertical){
  1597. Seg = (real)(ui->R-ui->L)/Len;
  1598. _L = ui->L + i * Seg; _R=ui->L + (i+1) * Seg;
  1599. }else{
  1600. Seg = (real)(ui->B-ui->U)/Len;
  1601. _U = ui->U + i * Seg; _B=_U+Seg;
  1602. }
  1603. real cx=(_L+_R)/2,cy=(_U+_B)/2,cw=(_R-_L),ch=(_B-_U);
  1604. real sfac = (real)(SData[i]-min) / (real)(max - min);
  1605. real fac = (real)(Data[i]-min) / (real)(max - min);
  1606. int SL,SR,SU,SB,_SL,_SR,_SU,_SB, Move = fac*ScaleLen,SMove=sfac*ScaleLen;
  1607. if(IsVertical){ _SB=SB=cy+Move-SMove; TNS_CLAMP(SB,_U,_B); }
  1608. else{ SL=_SL=cx-Move+SMove; TNS_CLAMP(SL,_L,_R); }
  1609. tnsUseNoTexture();
  1610. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT|LA_BT_ACTIVE));
  1611. if(IsVertical){ tnsVertex2d(_L, SB); tnsVertex2d(_R, SB); }
  1612. else{ tnsVertex2d(SL, _U); tnsVertex2d(SL, _B); }
  1613. tnsPackAs(GL_LINES);
  1614. if(IsVertical){
  1615. if(! CPP->Slot % 2){ tnsVertex2d(_L, SB); tnsVertex2d(_L+trisize, SB); tnsVertex2d(_L, SB-trisize); }
  1616. else{ tnsVertex2d(_R, SB+trisize); tnsVertex2d(_R-trisize, SB); tnsVertex2d(_R, SB); }
  1617. if(SB==_SB){ tnsPackAs(GL_TRIANGLES); }else{ tnsPackAs(GL_LINE_LOOP); }
  1618. }
  1619. else{
  1620. if(! CPP->Slot % 2){ tnsVertex2d(SL, _B); tnsVertex2d(SL, _B-trisize); tnsVertex2d(SL+trisize, _B); }
  1621. else{ tnsVertex2d(SL-trisize, _U); tnsVertex2d(SL, _U+trisize); tnsVertex2d(SL, _U); }
  1622. if(SL==_SL){ tnsPackAs(GL_TRIANGLES); }else{ tnsPackAs(GL_LINE_LOOP); }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. tnsFlush();
  1628. }
  1629. void la_ValueMeter2DDraw(laUiItem *ui, int h){
  1630. laBoxedTheme *bt = (*ui->Type->Theme);
  1631. int DataI[8]; real Data[8];
  1632. int Len, i, W; real Seg;
  1633. char buf[48] = {0};
  1634. char buf2[48] = {0};
  1635. char prefix[8][64] = {0};
  1636. int Original;
  1637. int Imin=-100, Imax=100;
  1638. real min=-100, max=100;
  1639. int IsInt=(ui->PP.LastPs->p->PropertyType&LA_PROP_INT)?1:0;
  1640. Len = laGetArrayLength(&ui->PP);
  1641. laGetPrefixP(&ui->PP, prefix);
  1642. if(IsInt){
  1643. laGetIntArray(&ui->PP, DataI); for(int i=0;i<Len;i++){ Data[i]=DataI[i]; }
  1644. laGetIntRange(&ui->PP, &Imin, &Imax); min=Imin; max=Imax;
  1645. }else{
  1646. laGetFloatArray(&ui->PP, Data);
  1647. laGetFloatRange(&ui->PP,&min,&max);
  1648. }
  1649. int _L=ui->L, _R=ui->R, _U=ui->U, _B=ui->B;
  1650. tnsUseNoTexture();
  1651. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  1652. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  1653. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  1654. tnsPackAs(GL_TRIANGLE_FAN);
  1655. real CL=(real)(Data[0] - min) / (real)(max - min) * (real)(_R-_L) + _L;
  1656. real CU=(real)(max - Data[1]) / (real)(max - min) * (real)(_B-_U) + _U;
  1657. real HW=((real)_R-(real)_L)/4; real HH=((real)_B-(real)_U)/4;
  1658. real ML=((real)_R+(real)_L)/2; real MU=((real)_B+(real)_U)/2;
  1659. tnsUseNoTexture(); real* color=laThemeColor(bt,LA_BT_TEXT);
  1660. tnsColor4d(LA_COLOR3(color),0.4);
  1661. tnsVertex2d(ML+HW, MU+HH); tnsVertex2d(ML-HW, MU+HH);
  1662. tnsVertex2d(ML-HW, MU-HH); tnsVertex2d(ML+HW, MU-HH);
  1663. tnsPackAs(GL_LINE_LOOP);
  1664. tnsVertex2d(_L,_U); tnsVertex2d(_R,_B);
  1665. tnsVertex2d(_R,_U); tnsVertex2d(_L,_B);
  1666. tnsVertex2d(ML,_U); tnsVertex2d(ML,_B);
  1667. tnsVertex2d(_R,MU); tnsVertex2d(_L,MU);
  1668. tnsPackAs(GL_LINES);
  1669. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1670. tnsVertex2d(_L, _U); tnsVertex2d(_R, _U);
  1671. tnsVertex2d(_R, _B); tnsVertex2d(_L, _B);
  1672. tnsPackAs(GL_LINE_LOOP);
  1673. tnsFlush();
  1674. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  1675. tnsVertex2d(_L, CU); tnsVertex2d(_R, CU);
  1676. tnsVertex2d(CL, _U); tnsVertex2d(CL, _B);
  1677. tnsPackAs(GL_LINES);
  1678. real circle[48];
  1679. tnsMakeCircle2d(circle,24,CL,CU,LA_RH2,0);
  1680. tnsVertexArray2d(circle,24);
  1681. tnsPackAs(GL_LINE_LOOP);
  1682. glLineWidth(2);
  1683. tnsFlush();
  1684. glLineWidth(1);
  1685. }
  1686. void la_ScopeDraw(laUiItem *ui, int h){
  1687. laBoxedTheme *bt = (*ui->Type->Theme); laSynthNodeScope* s=ui->PP.EndInstance;
  1688. if(!s) return;
  1689. real* lcolor=laAccentColor(LA_BT_TEXT); int plen=LA_SYNTH_PLEN;
  1690. int cl=ui->L+2, cr=ui->R-2, cu=ui->U+2, cb=ui->B-2; real cc=(real)(cu+cb)/2;
  1691. real yfac1=(real)(1<<(s->Gain1+1))/4.0f, yfac2=(real)(1<<(s->Gain2+1))/4.0f; yfac1/=10; yfac2/=10;
  1692. real off1=s->Offset1/20*(cb-cu), off2=s->Offset2/20*(cb-cu);
  1693. real arrx[LA_SYNTH_PLEN];
  1694. real arru1[LA_SYNTH_PLEN],arrb1[LA_SYNTH_PLEN];
  1695. real arru2[LA_SYNTH_PLEN],arrb2[LA_SYNTH_PLEN];
  1696. tnsFlush(); tnsUseNoTexture();
  1697. tnsColor4d(0,0,0,0.8);
  1698. tnsVertex2d(ui->L,ui->U); tnsVertex2d(ui->R,ui->U);
  1699. tnsVertex2d(ui->R,ui->B); tnsVertex2d(ui->L,ui->B);
  1700. tnsPackAs(GL_TRIANGLE_FAN);
  1701. tnsFlush(); tnsLineWidth(3.0);
  1702. laSpinLock(&s->Lock);
  1703. real b1=s->Brightness1, b2=s->Brightness2; real hcy[3]; tnsRGB2HCY(lcolor,hcy); hcy[2]=0.75;
  1704. real c1[3]; tnsHCY2RGB(hcy,c1);
  1705. for(int i=0;i<plen;i++){
  1706. arrx[i]=tnsInterpolate(cl,cr,((real)i)/plen);
  1707. arru1[i]=tnsInterpolate(cc,cu,yfac1*s->Display1[i])-off1;
  1708. arrb1[i]=tnsInterpolate(cc,cu,yfac1*s->Display1[i+plen])-off1;
  1709. TNS_CLAMP(arru1[i],cu,cb); TNS_CLAMP(arrb1[i],cu,cb);
  1710. tnsVertex2d(arrx[i],arru1[i]); tnsVertex2d(arrx[i],arrb1[i]);
  1711. }
  1712. tnsColor4d(LA_COLOR3(c1),b1*0.4);
  1713. tnsPackAs(GL_TRIANGLE_STRIP); tnsFlush();
  1714. for(int i=0;i<plen;i++){
  1715. arru2[i]=tnsInterpolate(cc,cu,yfac2*s->Display2[i])-off2;
  1716. arrb2[i]=tnsInterpolate(cc,cu,yfac2*s->Display2[i+plen])-off2;
  1717. TNS_CLAMP(arru2[i],cu,cb); TNS_CLAMP(arrb2[i],cu,cb);
  1718. tnsVertex2d(arrx[i],arru2[i]); tnsVertex2d(arrx[i],arrb2[i]);
  1719. }
  1720. tnsColor4d(LA_COLOR3(c1),b2*0.6);
  1721. tnsPackAs(GL_TRIANGLE_STRIP); tnsFlush();
  1722. for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arru1[i]); }
  1723. tnsColor4d(LA_COLOR3(c1),b1);
  1724. tnsPackAs(GL_LINE_STRIP);
  1725. for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arrb1[i]); }
  1726. tnsColor4d(LA_COLOR3(c1),b1);
  1727. tnsPackAs(GL_LINE_STRIP);
  1728. for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arru2[i]); }
  1729. tnsColor4d(LA_COLOR3(c1),b2);
  1730. tnsPackAs(GL_LINE_STRIP);
  1731. for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arrb2[i]); }
  1732. tnsColor4d(LA_COLOR3(c1),b2);
  1733. tnsPackAs(GL_LINE_STRIP);
  1734. laSpinUnlock(&s->Lock);
  1735. tnsFlush(); tnsLineWidth(1.0);
  1736. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1737. tnsVertex2d(ui->L,ui->U); tnsVertex2d(ui->R,ui->U);
  1738. tnsVertex2d(ui->R,ui->B); tnsVertex2d(ui->L,ui->B);
  1739. tnsPackAs(GL_LINE_LOOP);
  1740. if(s->FromSynth && laget_SynthPlaying(s->FromSynth)){ laDeferredRedraw(MAIN.CurrentPanel); }
  1741. }
  1742. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn);
  1743. void la_GeneralUiInit(laUiItem *ui){
  1744. ui->Extra = memAcquireSimple(sizeof(laGeneralUiExtraData));
  1745. ui->Extra->ui=ui;
  1746. }
  1747. void la_GeneralUiDestroy(laUiItem *ui){
  1748. if(ui->Extra && ui->Extra->Edit){ strEndEdit(&ui->Extra->Edit, 1); }
  1749. memFree(ui->Extra);
  1750. }
  1751. void la_ConditionUiDestroy(laUiItem *ui){
  1752. laConditionUiExtraData *cued = ui->Extra;
  1753. la_ConditionNodeFreeRecursive(cued->Expression);
  1754. FreeMem(ui->Extra);
  1755. }
  1756. void la_MultiStringInit(laUiItem *ui){
  1757. laGeneralUiExtraData *e = ui->Extra;
  1758. if (!e) e = memAcquireSimple(sizeof(laGeneralUiExtraData));
  1759. ui->Extra = e;
  1760. e->HeightCoeff = 10;
  1761. }
  1762. void la_ImageUiInit(laUiItem *ui){
  1763. tnsImage* im=ui->Extra;
  1764. #ifdef LA_WITH_PNG
  1765. tnsUseImage(im);
  1766. #endif
  1767. }
  1768. void la_ImageUiDestroy(laUiItem *ui){
  1769. tnsImage* im=ui->Extra;
  1770. #ifdef LA_WITH_PNG
  1771. tnsStopUsingImage(im);
  1772. #endif
  1773. }
  1774. void la_MeterUiInit(laUiItem *ui){
  1775. la_GeneralUiInit(ui); ui->SymbolID = 20; ui->TemplateContext = 1000;
  1776. }
  1777. void la_RegisterUiTypesBasic(){
  1778. laKeyMapper* km;
  1779. laPropContainer* pc;
  1780. LA_WIDGET_INT->Type=LA_WIDGET_INT_PLAIN->Type=
  1781. _LA_UI_INT = la_RegisterUiType("LA_int_array_horizon", LA_PROP_INT | LA_PROP_ARRAY, "LA_int_array_h_operator",
  1782. &_LA_THEME_VALUATOR, la_IntDraw, la_ValueGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1783. _LA_UI_INT->GetMinWidth=la_ValueGetMinWidth;
  1784. LA_WIDGET_METER_TYPE1->Type=
  1785. _LA_UI_METER_TYPE1 = la_RegisterUiType("LA_meter_type1", 0, 0, &_LA_THEME_VALUATOR, la_ValueMeterType1Draw, la_ValueMeterGetHeight, la_MeterUiInit, la_GeneralUiDestroy);
  1786. _LA_UI_METER_TYPE1->GetMinWidth=la_ValueGetMinWidth;
  1787. LA_WIDGET_METER_TYPE2->Type=
  1788. _LA_UI_METER_TYPE2 = la_RegisterUiType("LA_meter_type2", 0, 0, &_LA_THEME_VALUATOR, la_ValueMeterType2Draw, la_ValueMeterGetHeight, la_MeterUiInit, la_GeneralUiDestroy);
  1789. _LA_UI_METER_TYPE2->GetMinWidth=la_ValueGetMinWidth;
  1790. LA_WIDGET_VALUE_METER_2D->Type=
  1791. _LA_UI_VALUE_METER_2D = la_RegisterUiType("LA_value_meter_2d", 0, 0, &_LA_THEME_VALUATOR, la_ValueMeter2DDraw, la_ValueMeter2DGetHeight, la_MeterUiInit, la_GeneralUiDestroy);
  1792. LA_WIDGET_FLOAT->Type=LA_WIDGET_FLOAT_PLAIN->Type=
  1793. _LA_UI_FLOAT = la_RegisterUiType("LA_real_array_horizon", LA_PROP_FLOAT | LA_PROP_ARRAY, "LA_real_array_h_operator",
  1794. &_LA_THEME_VALUATOR, la_FloatDraw, la_ValueGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1795. _LA_UI_FLOAT->GetMinWidth=la_ValueGetMinWidth;
  1796. LA_WIDGET_FLOAT_COLOR->Type=
  1797. _LA_UI_FLOAT_COLOR = la_RegisterUiType("LA_real_color", LA_PROP_FLOAT | LA_PROP_ARRAY, "LA_real_color_operator",
  1798. &_LA_THEME_VALUATOR, la_FloatArrayColorDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1799. _LA_UI_FLOAT_COLOR->GetMinWidth=la_ColorSelectorGetMinWidth;
  1800. LA_WIDGET_FLOAT_COLOR_HCY->Type=
  1801. _LA_UI_FLOAT_COLOR_HCY = la_RegisterUiType("LA_real_hcy", LA_PROP_FLOAT | LA_PROP_ARRAY, "LA_real_hcy_operator",
  1802. &_LA_THEME_VALUATOR, la_ColorCircleDrawHCY, la_ColorPickerGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1803. _LA_UI_FLOAT_COLOR_HCY->GetMinWidth = la_ColorPickerGetMinWidth;
  1804. LA_WIDGET_ENUM_SELECTOR->Type=LA_WIDGET_ENUM_SELECTOR_ICON->Type=LA_WIDGET_ENUM_CYCLE->Type=LA_WIDGET_ENUM_HIGHLIGHT->Type=
  1805. _LA_UI_ENUM_SELECTOR = la_RegisterUiType("LA_enum_selector", LA_PROP_ENUM, "LA_enum_selector_operator",
  1806. &_LA_THEME_SELECTOR, la_EnumSelectorDraw, la_EnumGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1807. _LA_UI_ENUM_SELECTOR->GetMinWidth = la_EnumGetMinWidth;
  1808. LA_WIDGET_FIXED_GROUP->Type=
  1809. _LA_UI_FIXED_GROUP = la_RegisterUiType("LA_group_default", 0, 0,
  1810. &_LA_THEME_COLLECTION_GROUP, la_GroupDraw, la_GroupGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1811. _LA_UI_FIXED_GROUP->Tag|=LA_UI_TAG_SCISSOR;
  1812. LA_WIDGET_COLLECTION->Type=
  1813. _LA_UI_COLLECTION = la_RegisterUiType("LA_collection_default", LA_PROP_SUB, "LA_collection_operator",
  1814. &_LA_THEME_COLLECTION_GROUP, la_EmptyDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1815. LA_WIDGET_COLLECTION_SELECTOR->Type=
  1816. _LA_UI_COLLECTION_SELECTOR = la_RegisterUiType("LA_collection_selector_default", LA_PROP_SUB, "LA_collection_selector_operator",
  1817. &_LA_THEME_COLLECTION_SELECTOR, la_CollectionSelectorDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1818. _LA_UI_COLLECTION_SELECTOR->GetMinWidth = la_CollectionSimpleGetMinWidth;
  1819. LA_WIDGET_COLLECTION_SINGLE->Type=
  1820. _LA_UI_COLLECTION_SINGLE = la_RegisterUiType("LA_collection_single", LA_PROP_SUB, "LA_collection_operator",
  1821. &_LA_THEME_COLLECTION_GROUP, la_EmptyDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1822. LA_WIDGET_TAB->Type=
  1823. _LA_UI_TAB = la_RegisterUiType("LA_tab_default", 0, "LA_tab_operator",
  1824. &_LA_THEME_TAB, la_TabDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1825. LA_WIDGET_BUTTON->Type=LA_WIDGET_BUTTON_NO_CONFIRM->Type=
  1826. _LA_UI_BUTTON = la_RegisterUiType("LA_button_default", LA_PROP_OPERATOR, "LA_button_operator",
  1827. &_LA_THEME_BUTTON, la_ButtonDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1828. _LA_UI_BUTTON->GetMinWidth = la_ButtonGetMinWidth;
  1829. LA_WIDGET_BUTTON_NO_CONFIRM->Flags|=LA_UI_FLAGS_NO_CONFIRM;
  1830. pc=laUiHasExtraProps(_LA_UI_BUTTON, sizeof(laGeneralUiExtraData),0);
  1831. LA_WIDGET_LABEL->Type=
  1832. _LA_UI_LABEL = la_RegisterUiType("LA_label_default", LA_PROP_OPERATOR, 0,
  1833. &_LA_THEME_LABEL, la_LabelDraw, la_LabelHeight, 0, 0);
  1834. _LA_UI_LABEL->GetMinWidth = la_LabelGetMinWidth;
  1835. LA_WIDGET_MENU_ROOT->Type=
  1836. _LA_UI_MENU_ROOT = la_RegisterUiType("LA_menu_default", LA_PROP_OPERATOR, "LA_menu_root_operator",
  1837. &_LA_THEME_BUTTON, la_MenuItemDraw, 0, 0, 0);
  1838. _LA_UI_MENU_ROOT->GetMinWidth=la_LabelGetMinWidth;
  1839. LA_WIDGET_CONDITION_TOGGLE->Type=
  1840. _LA_UI_CONDITION_TOGGLE = la_RegisterUiType("LA_condition_toggle_default", LA_PROP_SELF_CONDITION, "LA_condition_toggle_operator",
  1841. &_LA_THEME_BUTTON, la_ConditionToggleDraw, 0, 0, la_ConditionUiDestroy);
  1842. LA_WIDGET_STRING->Type=LA_WIDGET_STRING_PLAIN->Type=LA_WIDGET_STRING_MONO_PLAIN->Type=
  1843. _LA_UI_STRING = la_RegisterUiType("LA_string_default", LA_PROP_STRING, "LA_string_operator",
  1844. &_LA_THEME_STRING, la_SingleLineStringDraw, la_StringPropGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1845. _LA_UI_STRING->GetMinWidth = la_StringPropGetMinWidth;
  1846. km=&_LA_UI_STRING->KeyMapper;
  1847. laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'c', 0);
  1848. laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'x', "mode=CUT");
  1849. laAssignNewKey(km, 0, "LA_system_paste", 0, LA_KEY_CTRL, LA_KEY_DOWN, 'v', 0);
  1850. pc=laUiHasExtraProps(_LA_UI_STRING, sizeof(laGeneralUiExtraData), 0);{
  1851. laAddOperatorProperty(pc, "copy_selection", "Copy Selection", "Copy selected string into clipboard", "LA_edit_string_copy",0,0);
  1852. }
  1853. LA_WIDGET_STRING_MULTI->Type=
  1854. _LA_UI_STRING_MULTI = la_RegisterUiType("LA_string_multiline", LA_PROP_STRING, "LA_string_multi",
  1855. &_LA_THEME_STRING, la_MultiStringDraw, la_MultiStringHeight, la_MultiStringInit, la_GeneralUiDestroy);
  1856. _LA_UI_STRING_MULTI->GetMinWidth = la_StringPropGetMinWidth;
  1857. km=&_LA_UI_STRING_MULTI->KeyMapper;
  1858. laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'c', 0);
  1859. laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'x', "mode=CUT");
  1860. laAssignNewKey(km, 0, "LA_system_paste", 0, LA_KEY_CTRL, LA_KEY_DOWN, 'v', 0);
  1861. pc=laUiHasExtraProps(_LA_UI_STRING_MULTI, sizeof(laGeneralUiExtraData), 0);{
  1862. laAddOperatorProperty(pc, "copy_selection", "Copy Selection", "Copy selected string into clipboard", "LA_edit_string_copy",0,0);
  1863. }
  1864. LA_WIDGET_ALIGN->Type=
  1865. _LA_UI_ALIGN = la_RegisterUiType("LA_colum_align_default", 0, 0,
  1866. &_LA_THEME_BUTTON, la_UiSeperatorDraw, 0, 0, 0);
  1867. LA_WIDGET_COLUMN_ADJUSTER->Type=
  1868. _LA_UI_COLUMN_ADJUSTER = la_RegisterUiType("LA_column_adjuster_default", 0, "LA_column_adjuster",
  1869. &_LA_THEME_BUTTON, la_ColumnAdjusterDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1870. _LA_UI_COLUMN_ADJUSTER->TargetSub = "ui_column";
  1871. LA_WIDGET_COLUMN_VIEWER->Type=
  1872. _LA_UI_COLUMN_VIEWER = la_RegisterUiType("LA_column_viewer_default", 0, 0,
  1873. &_LA_THEME_BUTTON, la_ColumnViewerDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1874. _LA_UI_COLUMN_VIEWER->TargetSub = "ui_column";
  1875. _LA_UI_COLUMN_VIEWER->GetMinWidth = la_ColumnViewerGetMinWidth;
  1876. _LA_UI_CONDITION_ELSE.Theme = &_LA_THEME_BUTTON;
  1877. la_UDFAppendSharedTypePointer("LA_condition_else", &_LA_UI_CONDITION_ELSE);
  1878. _LA_UI_CONDITION.Destroy = _LA_UI_CONDITION_ELSE.Destroy = _LA_UI_CONDITION_END.Destroy =la_ConditionUiDestroy;
  1879. _LA_UI_CONDITION.Theme = &_LA_THEME_BUTTON;
  1880. la_UDFAppendSharedTypePointer("LA_condition", &_LA_UI_CONDITION);
  1881. _LA_UI_CONDITION_END.Theme = &_LA_THEME_BUTTON;
  1882. la_UDFAppendSharedTypePointer("LA_condition_end", &_LA_UI_CONDITION_END);
  1883. LA_WIDGET_SYMBOL->Type=
  1884. _LA_UI_SYMBOL = la_RegisterUiType("LA_symbol_default", 0, 0, &_LA_THEME_BUTTON, la_SymbolDraw, la_SymbolGetHeight, 0, 0);
  1885. LA_WIDGET_NODE_SOCKET->Type=
  1886. _LA_UI_NODE_SOCKET = la_RegisterUiType("LA_node_socket_default", 0, "LA_node_socket", &_LA_THEME_SOCKET, la_NodeSocketDraw, la_SocketGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1887. _LA_UI_NODE_SOCKET->GetMinWidth=la_SocketGetMinWidth;
  1888. LA_WIDGET_HEIGHT_ADJUSTER->Type=
  1889. _LA_UI_HEIGHT_ADJUSTER = la_RegisterUiType("LA_height_adjuster_default", 0, "LA_height_adjuster", &_LA_THEME_COLLECTION_GROUP, la_HeightAdjusterDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
  1890. _LA_UI_HEIGHT_ADJUSTER->ForType = LA_PROP_INT;
  1891. LA_WIDGET_RAW->Type=
  1892. _LA_UI_RAW = la_RegisterUiType("LA_raw_prop_default", 0, 0, &_LA_THEME_COLLECTION_GROUP, la_RawPropDraw, 0, 0, 0);
  1893. _LA_UI_RAW->ForType = LA_PROP_RAW;
  1894. LA_WIDGET_MAPPER->Type=
  1895. _LA_UI_MAPPER = la_RegisterUiType("LA_mapper_default", 0, "LA_value_mapper", &_LA_THEME_COLLECTION_GROUP, la_MapperDraw, la_ColorPickerGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1896. LA_WIDGET_IMAGE->Type=
  1897. _LA_UI_IMAGE = la_RegisterUiType("LA_image_default", 0, 0, &_LA_THEME_COLLECTION_GROUP, la_ImageDraw, la_ImageGetHeight, la_ImageUiInit, la_ImageUiDestroy);
  1898. _LA_UI_IMAGE->GetMinWidth=la_ImageGetMinWidth;
  1899. LA_WIDGET_SCOPE->Type=
  1900. _LA_UI_SCOPE = la_RegisterUiType("LA_scope_default", 0, "LA_synth_scope", &_LA_THEME_BUTTON, la_ScopeDraw, la_ColorPickerGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
  1901. _LA_UI_INVISIBLE.Theme=&_LA_THEME_BUTTON;
  1902. _LA_UI_ROW_BEGIN.Theme=&_LA_THEME_BUTTON;
  1903. _LA_UI_ROW_END.Theme=&_LA_THEME_BUTTON;
  1904. }
  1905. // ============================================================ [Operators]
  1906. void la_DefaultEnumPanel(laUiList *uil, laPropPack *This, laPropPack *OperatorProps, laColumn *UNUSED){
  1907. laColumn *c = laFirstColumn(uil);
  1908. laShowItem(uil, c, This, 0)->Flags=(LA_UI_FLAGS_TRANSPOSE|LA_UI_FLAGS_EXPAND);
  1909. }
  1910. int la_DetectRow(laUiItem *ui, int LocalY){
  1911. return (LocalY - ui->U) / LA_RH;
  1912. }
  1913. int la_DetectColumn(laUiItem *ui, int LocalX, int Total){
  1914. return (int)((real)(LocalX - ui->L) / (real)(ui->R - ui->L) * (real)Total);
  1915. }
  1916. laColumn *la_DetectSplit(laColumn *Root, int LocalX){
  1917. laColumn *result = 0;
  1918. if (!Root->LS) return 0;
  1919. if (LocalX - Root->LS->IR < LA_SCROLL_W && Root->LS->IR - LocalX < LA_SCROLL_W &&
  1920. !Root->LS->MaxW && !Root->RS->MaxW){
  1921. return Root;
  1922. }
  1923. result = la_DetectSplit(Root->LS, LocalX);
  1924. if (result) return result;
  1925. else
  1926. return la_DetectSplit(Root->RS, LocalX);
  1927. }
  1928. void la_AdjustColumnSplit(laColumn *c, int PxLeftPositive){
  1929. if (!c->LS || c->LS->MaxW || c->RS->MaxW) return;
  1930. if (PxLeftPositive < 0 && c->LS->IR - c->LS->IL <= LA_SCROLL_W*2) return;
  1931. if (PxLeftPositive > 0 && c->RS->IR - c->RS->IL <= LA_SCROLL_W*2) return;
  1932. c->LS->IR += PxLeftPositive;
  1933. c->RS->IL += PxLeftPositive;
  1934. c->LS->SP = (real)(c->LS->IR - c->LS->IL) / (real)(c->IR - c->IL);
  1935. c->RS->SP = c->LS->SP;
  1936. }
  1937. int OPCHK_EditStringCopySelection(laPropPack *This, laStringSplitor *Instructions){
  1938. laGeneralUiExtraData *uit = This->EndInstance; if(!uit) return 0;
  1939. if(!uit->Edit || !strHasSelection(uit->Edit)) return 0;
  1940. return 1;
  1941. }
  1942. int OPINV_EditStringCopySelection(laOperator *a, laEvent *e){
  1943. laGeneralUiExtraData *uit = a->This->EndInstance; if(!uit) return LA_FINISHED;
  1944. if(!uit->Edit || !strHasSelection(uit->Edit)) return LA_FINISHED;
  1945. char* mode=strGetArgumentString(a->ExtraInstructionsP,"mode");
  1946. char* str=strGetEditString(uit->Edit, 1);
  1947. laCopyToClipboard(str); free(str);
  1948. if(strSame(mode,"CUT")){ strClearSelection(&uit->Edit); }
  1949. return LA_FINISHED;
  1950. }
  1951. int la_ProcessTextEdit(laEvent *e, laStringEdit *se, laUiItem* ui){
  1952. int Select=e->SpecialKeyBit&LA_KEY_SHIFT;
  1953. real _L, MonoWidth;
  1954. switch (e->type){
  1955. case LA_INPUT:
  1956. switch (e->Input){
  1957. case 0x08: if(strHasSelection(se)) strClearSelection(se); else strBackspace(se); return 1;
  1958. case 0x7f: if(strHasSelection(se)) strClearSelection(se); else { strMoveCursor(se,0,0); strBackspace(se); } return 1;
  1959. case 0x09: strInsertChar(se, ' ');strInsertChar(se, ' ');strInsertChar(se, ' ');strInsertChar(se, ' '); return 1;
  1960. case 0x1B: case 0x0D: return 0;
  1961. default: strInsertChar(se, e->Input); return 1;
  1962. }
  1963. break;
  1964. case LA_KEY_DOWN:
  1965. switch (e->key){
  1966. case LA_KEY_ENTER: strInsertChar(se, '\n'); return 1;
  1967. case LA_KEY_ARRLEFT: strMoveCursor(se, 1, Select); return 1;
  1968. case LA_KEY_ARRRIGHT: strMoveCursor(se, 0, Select); return 1;
  1969. case LA_KEY_ARRUP: strMoveCursorLine(se, 1, Select); return 1;
  1970. case LA_KEY_ARRDOWN: strMoveCursorLine(se, 0, Select); return 1;
  1971. }
  1972. break;
  1973. case LA_L_MOUSE_DOWN:
  1974. case LA_MOUSEMOVE:
  1975. if(!ui) return 0;
  1976. MonoWidth=tnsGetMonoFontAdvance(); _L=(*ui->Type->Theme)->LM*2+ui->L;
  1977. int Count=se->TotalLines; while(Count){ Count/=10; _L+=MonoWidth; }
  1978. if(e->type==LA_L_MOUSE_DOWN){
  1979. strSetCursor(se, (e->y-ui->U)/LA_RH+se->ViewStartLine, (real)se->ViewStartCol+((real)e->x-_L)/MonoWidth+0.5); strCancelSelect(se); strLazySelect(se);
  1980. se->MouseSelecting=1; se->CursorPreferBefore=se->CursorBefore; return 1;
  1981. }else{
  1982. if(!se->MouseSelecting) return 0;
  1983. strSetCursor(se, (e->y-ui->U)/LA_RH+se->ViewStartLine, (real)se->ViewStartCol+((real)e->x-_L)/MonoWidth+0.5); strEndSelect(se);
  1984. se->CursorPreferBefore=se->CursorBefore; return 1;
  1985. }return 0;
  1986. case LA_L_MOUSE_UP:
  1987. se->MouseSelecting=0;
  1988. }
  1989. return 0;
  1990. }
  1991. int OPINV_UiItem(laOperator *a, laEvent *e){
  1992. laUiItem *ui = a->Instance;
  1993. a->CustomData = ui->Extra;
  1994. return LA_RUNNING;
  1995. }
  1996. int OPINV_Tab(laOperator *a, laEvent *e){
  1997. laUiList *uil;
  1998. laUiItem *ui = a->Instance;
  1999. laGeneralUiExtraData *uit;
  2000. int count = 0;
  2001. //if (e->Type == LA_L_MOUSE_DOWN) {
  2002. //}
  2003. a->CustomData = ui->Extra;
  2004. uit = a->CustomData;
  2005. uit->TargetIndexVali = count;
  2006. return LA_RUNNING;
  2007. }
  2008. int OPEXT_UiItem(laOperator *a, int ExitCode){
  2009. laUiItem *ui = a->Instance;
  2010. return 0;
  2011. }
  2012. int OPMOD_IntArrayHorizon(laOperator *a, laEvent *e){
  2013. laUiItem *ui = a->Instance;
  2014. laBoxedTheme *bt = (*ui->Type->Theme);
  2015. laGeneralUiExtraData *uit = a->CustomData;
  2016. laIntProp *ip = ui->PP.LastPs->p;
  2017. int Away = 0;
  2018. int TmpArr[32];
  2019. int Len = laGetArrayLength(&ui->PP);
  2020. int IsVertical=(ui->Flags&LA_UI_FLAGS_TRANSPOSE)!=0;
  2021. int NoEvent = ui->Flags&LA_UI_FLAGS_NO_EVENT;
  2022. int NoTooltip=ui->Flags&LA_UI_FLAGS_NO_TOOLTIP;
  2023. int IsKnob = ui->Flags&LA_UI_FLAGS_NODE_CONTAINER;
  2024. if (!laIsInUiItem(ui, e->x, e->y) && !ui->Extra->On){
  2025. ui->State = LA_UI_NORMAL;
  2026. if (ui->Extra) ui->Extra->On = 0;
  2027. laRedrawCurrentPanel();
  2028. return LA_FINISHED_PASS;
  2029. }
  2030. if (e->type == LA_TIME_IDLE && !uit->On && !uit->Edit && !NoTooltip){
  2031. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2032. laPanel *p = laEnableIdlePanel(a->ToPanel, a, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2033. return LA_RUNNING;
  2034. }
  2035. if(NoEvent){ return LA_RUNNING_PASS; }
  2036. if (e->type == LA_L_MOUSE_DOWN){
  2037. if (laIsPropertyReadOnly(&ui->PP)) return LA_RUNNING_PASS;
  2038. if (uit->Edit){
  2039. if (!laIsInUiItem(ui, e->x, e->y)){
  2040. strEndEdit(&uit->Edit, 1);
  2041. uit->On = 0;
  2042. laRedrawCurrentPanel();
  2043. return LA_FINISHED;
  2044. }
  2045. if (strHasSelection(uit->Edit)) strDeselectAll(uit->Edit);
  2046. else strSelectLineAll(uit->Edit);
  2047. return LA_RUNNING;
  2048. }
  2049. uit->LastX = e->x;
  2050. uit->LastY = e->y;
  2051. ui->Extra->On = (IsVertical ? la_DetectRow(ui, e->y) : la_DetectColumn(ui, e->x, Len)) + 1;
  2052. if (ui->Extra->On > Len) return LA_RUNNING;
  2053. laGetIntArray(&ui->PP, &TmpArr);
  2054. uit->TargetIndexValf = TmpArr[ui->Extra->On - 1];
  2055. laRedrawCurrentPanel();
  2056. return LA_RUNNING;
  2057. }
  2058. if (e->type == LA_MOUSEMOVE && ui->Extra->On){
  2059. if(ui->Extra->Edit){ return LA_RUNNING; }
  2060. int dist=abs(e->x - uit->LastX + uit->LastY - e->y);
  2061. if (dist > MAIN.ValuatorThreshold || uit->Dragging){
  2062. int min,max,Ranged = laGetIntRange(&ui->PP, &min, &max); real step=ip->Step; if(Ranged&&!IsKnob){ step=(real)(max-min)/(ui->R-ui->L); }
  2063. if(Ranged){ TNS_CLAMP(step,(max-min)/500,INT_MAX); }
  2064. //laGetIntArray(&ui->PP, &TmpArr);
  2065. //uit->TargetIndexVali = TmpArr[ui->Extra->On - 1];
  2066. int delta=e->x-uit->LastX; if(IsKnob){ int dy=uit->LastY-e->y; delta=delta+dy; } if(!uit->Dragging) delta=delta>0?1:-1;
  2067. uit->TargetIndexValf += delta*step;
  2068. laSetIntArraySingle(&ui->PP, ui->Extra->On - 1, uit->TargetIndexValf);
  2069. uit->LastX = e->x;
  2070. uit->LastY = e->y;
  2071. uit->Dragging = 1;
  2072. laRedrawCurrentPanel();
  2073. }
  2074. return LA_RUNNING;
  2075. }
  2076. if (e->type == LA_L_MOUSE_UP){
  2077. if (laIsPropertyReadOnly(&ui->PP)) return LA_RUNNING_PASS;
  2078. if (uit->Dragging){
  2079. if (ui->Extra->On){
  2080. ui->Extra->On = 0;
  2081. laConfirmInt(a, uit->TargetIndexVali, LA_CONFIRM_DATA);
  2082. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2083. }
  2084. }else if(ui->Extra->On){
  2085. int SelectOn=(IsVertical ? la_DetectRow(ui, e->y) : la_DetectColumn(ui, e->x, Len)) + 1;
  2086. if ((!uit->Edit) || (uit->Edit && (SelectOn != ui->Extra->On))){
  2087. char buf[32] = {0};
  2088. uit->On=SelectOn;
  2089. laGetIntArray(&ui->PP, &TmpArr);
  2090. uit->TargetIndexVali = TmpArr[ui->Extra->On - 1];
  2091. strPrintIntAfter(buf, 32, uit->TargetIndexVali);
  2092. strBeginEdit(&uit->Edit,buf);
  2093. strSelectLineAll(uit->Edit);
  2094. }
  2095. }
  2096. uit->Dragging = 0;
  2097. laRedrawCurrentPanel();
  2098. return LA_RUNNING;
  2099. }
  2100. if(e->type ==LA_KEY_DOWN){
  2101. if (e->key == LA_KEY_ENTER && uit->Edit){
  2102. char* buf=strEndEdit(&uit->Edit, 0);
  2103. int Result; sscanf(buf, "%d", &Result); free(buf);
  2104. laSetIntArraySingle(&ui->PP, ui->Extra->On - 1, Result);
  2105. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2106. ui->State = LA_UI_NORMAL;
  2107. uit->Dragging = 0;
  2108. uit->On = 0;
  2109. laRedrawCurrentPanel();
  2110. return LA_FINISHED_PASS;
  2111. }
  2112. }
  2113. if (e->type == LA_R_MOUSE_DOWN){
  2114. int GX = e->x, GY = e->y;
  2115. ui->PP.LastIndex = la_DetectColumn(ui, e->x, Len);
  2116. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2117. laPanel *p = laEnablePropertyPanel(a->ToPanel, a, 0, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2118. return LA_RUNNING;
  2119. }
  2120. if (uit->Edit){
  2121. if (la_ProcessTextEdit(e, uit->Edit, ui)) laRedrawCurrentPanel();
  2122. return LA_RUNNING;
  2123. }
  2124. return LA_RUNNING_PASS;
  2125. }
  2126. int OPMOD_FloatArrayHorizon(laOperator *a, laEvent *e){
  2127. laUiItem *ui = a->Instance;
  2128. laBoxedTheme *bt = (*ui->Type->Theme);
  2129. laGeneralUiExtraData *uit = a->CustomData;
  2130. laFloatProp *fp = ui->PP.LastPs->p;
  2131. int Away = 0;
  2132. real TmpArr[32];
  2133. int Len = laGetArrayLength(&ui->PP);
  2134. int IsVertical=(ui->Flags&LA_UI_FLAGS_TRANSPOSE)!=0;
  2135. int NoEvent = ui->Flags&LA_UI_FLAGS_NO_EVENT;
  2136. int IsRad=ui->PP.LastPs->p->IsRadAngle;
  2137. int NoTooltip=ui->Flags&LA_UI_FLAGS_NO_TOOLTIP;
  2138. int IsKnob = ui->Flags&LA_UI_FLAGS_NODE_CONTAINER;
  2139. if (!laIsInUiItem(ui, e->x, e->y) && !ui->Extra->On && !NoTooltip){
  2140. ui->State = LA_UI_NORMAL;
  2141. ui->Extra->On = 0;
  2142. laRedrawCurrentPanel();
  2143. return LA_FINISHED_PASS;
  2144. }
  2145. if (e->type == LA_TIME_IDLE && !uit->On && !uit->Edit){
  2146. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2147. laPanel *p = laEnableIdlePanel(a->ToPanel, a, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2148. return LA_RUNNING;
  2149. }
  2150. if(NoEvent){ return LA_RUNNING_PASS; }
  2151. if (e->type == LA_L_MOUSE_DOWN){
  2152. if (uit->Edit){
  2153. if (!laIsInUiItem(ui, e->x, e->y)){
  2154. strEndEdit(&uit->Edit, 1);
  2155. uit->On = 0;
  2156. laRedrawCurrentPanel();
  2157. return LA_FINISHED;
  2158. }
  2159. if (strHasSelection(uit->Edit)) strDeselectAll(uit->Edit);
  2160. else strSelectLineAll(uit->Edit);
  2161. return LA_RUNNING;
  2162. }
  2163. if (laIsPropertyReadOnly(&ui->PP)) return LA_RUNNING_PASS;
  2164. uit->LastX = e->x;
  2165. uit->LastY = e->y;
  2166. ui->Extra->On = (IsVertical ? la_DetectRow(ui, e->y) : la_DetectColumn(ui, e->x, Len)) + 1;
  2167. if (ui->Extra->On > Len) return LA_RUNNING;
  2168. laGetFloatArray(&ui->PP, &TmpArr);
  2169. uit->TargetIndexValf = TmpArr[ui->Extra->On - 1];
  2170. laRedrawCurrentPanel();
  2171. return LA_RUNNING;
  2172. }
  2173. if (e->type == LA_MOUSEMOVE && ui->Extra->On){
  2174. if(uit->Edit){ return LA_RUNNING; }
  2175. int dist=abs(e->x - uit->LastX - e->y + uit->LastY);
  2176. if (dist > MAIN.ValuatorThreshold || uit->Dragging){
  2177. real min,max; int Ranged = laGetFloatRange(&ui->PP, &min, &max); real step=fp->Step; if(Ranged&&!IsKnob){ step=(max-min)/(ui->R-ui->L); }
  2178. if(Ranged){ TNS_CLAMP(step,(max-min)/500,INT_MAX); }
  2179. laGetFloatArray(&ui->PP, &TmpArr);
  2180. uit->TargetIndexValf = TmpArr[ui->Extra->On - 1];
  2181. int delta=e->x-uit->LastX; if(IsKnob){ int dy=uit->LastY-e->y; delta=delta+dy; } if(!uit->Dragging) delta=delta>0?1:-1;
  2182. uit->TargetIndexValf += delta*step;
  2183. laSetFloatArraySingle(&ui->PP, ui->Extra->On - 1, uit->TargetIndexValf);
  2184. uit->LastX = e->x;
  2185. uit->LastY = e->y;
  2186. uit->Dragging = 1;
  2187. laRedrawCurrentPanel();
  2188. }
  2189. return LA_RUNNING;
  2190. }
  2191. if (e->type == LA_L_MOUSE_UP){
  2192. if (laIsPropertyReadOnly(&ui->PP)) return LA_RUNNING_PASS;
  2193. if (uit->Dragging){
  2194. if (ui->Extra->On){
  2195. ui->Extra->On = 0;
  2196. laConfirmFloat(a, uit->TargetIndexValf, LA_CONFIRM_DATA);
  2197. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2198. }
  2199. }else if(ui->Extra->On){
  2200. int SelectOn=(IsVertical ? la_DetectRow(ui, e->y) : la_DetectColumn(ui, e->x, Len)) + 1;
  2201. if ((!uit->Edit) || (uit->Edit && (SelectOn != ui->Extra->On))){
  2202. char buf[32] = {0};
  2203. uit->On=SelectOn;
  2204. laGetFloatArray(&ui->PP, &TmpArr);
  2205. uit->TargetIndexValf = TmpArr[ui->Extra->On - 1];
  2206. strPrintFloatAfter(buf, 32, 5, IsRad?deg(uit->TargetIndexValf):uit->TargetIndexValf);
  2207. strBeginEdit(&uit->Edit,buf);
  2208. strSelectLineAll(uit->Edit);
  2209. }
  2210. }
  2211. uit->Dragging = 0;
  2212. laRedrawCurrentPanel();
  2213. return LA_RUNNING;
  2214. }
  2215. if(e->type ==LA_KEY_DOWN){
  2216. if (e->key == LA_KEY_ENTER && uit->Edit){
  2217. char* buf=strEndEdit(&uit->Edit, 0);
  2218. real Result; sscanf(buf, "%lf", &Result); free(buf);
  2219. if(IsRad) Result=rad(Result);
  2220. laSetFloatArraySingle(&ui->PP, ui->Extra->On - 1, Result);
  2221. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2222. uit->Dragging = 0;
  2223. uit->On = 0;
  2224. laRedrawCurrentPanel();
  2225. return LA_FINISHED_PASS;
  2226. }
  2227. }
  2228. if (e->type == LA_R_MOUSE_DOWN){
  2229. int GX = e->x, GY = e->y;
  2230. ui->PP.LastIndex = la_DetectColumn(ui, e->x, laGetArrayLength(&ui->PP));
  2231. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2232. laPanel *p = laEnablePropertyPanel(a->ToPanel, a, 0, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2233. return LA_RUNNING;
  2234. }
  2235. if (uit->Edit){
  2236. if (la_ProcessTextEdit(e, uit->Edit, ui)) laRedrawCurrentPanel();
  2237. return LA_RUNNING;
  2238. }
  2239. return LA_RUNNING_PASS;
  2240. }
  2241. int OPMOD_FloatColor(laOperator *a, laEvent *e){
  2242. laUiItem *ui = a->Instance;
  2243. laBoxedTheme *bt = (*ui->Type->Theme);
  2244. laGeneralUiExtraData *uit = a->CustomData;
  2245. int Away = 0;
  2246. int NoEvent = ui->Flags&LA_UI_FLAGS_NO_EVENT;
  2247. int NoTooltip=ui->Flags&LA_UI_FLAGS_NO_TOOLTIP;
  2248. if (!laIsInUiItem(ui, e->x, e->y)){
  2249. return LA_FINISHED_PASS;
  2250. }
  2251. if (e->type == LA_TIME_IDLE && !NoTooltip){
  2252. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2253. laPanel *p = laEnableIdlePanel(a->ToPanel, a, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2254. return LA_RUNNING;
  2255. }
  2256. if(NoEvent){ return LA_RUNNING_PASS; }
  2257. if (e->type == LA_L_MOUSE_DOWN){
  2258. laUiList *uil;
  2259. laColumn *col;
  2260. laPanel *p;
  2261. int GX = ui->L, GY = ui->B;
  2262. ui->State = LA_UI_ACTIVE;
  2263. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2264. p = laEnableEmptyPropertyPanel(a->ToPanel, a, GX, GX + 150, GY, 500, e);{
  2265. uil = &p->UI;
  2266. col = laFirstColumn(uil);
  2267. laShowItemFull(uil, col, &ui->PP, 0, LA_WIDGET_FLOAT_COLOR_HCY, 0, 0, 0);
  2268. laShowItemFull(uil, col, &ui->PP, 0, LA_WIDGET_FLOAT, 0, 0, 0)->Flags=LA_UI_FLAGS_TRANSPOSE;
  2269. laEnclosePanelContent(p, uil);
  2270. }
  2271. return LA_RUNNING;
  2272. }
  2273. if (e->type == LA_R_MOUSE_DOWN){
  2274. int GX = e->x, GY = e->y;
  2275. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2276. laPanel *p = laEnablePropertyPanel(a->ToPanel, a, 0, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2277. return LA_RUNNING;
  2278. }
  2279. return LA_RUNNING_PASS;
  2280. }
  2281. int OPMOD_ColorHCY(laOperator *a, laEvent *e){
  2282. laUiItem *ui = a->Instance;
  2283. laBoxedTheme *bt = (*ui->Type->Theme);
  2284. laGeneralUiExtraData *es = a->CustomData;
  2285. int Away = 0;
  2286. int i = 0;
  2287. real hcy[3] = {0};
  2288. real Color[4] = {0};
  2289. real PickerPos[2];
  2290. real abso;
  2291. if (!laIsInUiItem(ui, e->x, e->y) && !es->Dragging){
  2292. return LA_FINISHED_PASS;
  2293. }
  2294. if(e->type == LA_L_MOUSE_DOWN && es->HeightCoeff>=0 && e->x>ui->R-bt->RM-LA_RH && e->y>ui->B-bt->BM-LA_RH){
  2295. es->Dragging=3; es->LastX=e->x; es->LastY=e->y; es->TargetIndexVali=es->HeightCoeff; return LA_RUNNING;
  2296. }
  2297. if(es->Dragging==3){
  2298. if(e->type==LA_MOUSEMOVE){ es->HeightCoeff=es->TargetIndexVali+((real)e->y-es->LastY+0.5)/LA_RH;
  2299. if(es->HeightCoeff<1)es->HeightCoeff=1; laRecalcCurrentPanel();}
  2300. elif(e->type==LA_L_MOUSE_UP){ es->Dragging=0; }
  2301. elif(e->type==LA_R_MOUSE_DOWN){
  2302. es->Dragging=0; es->HeightCoeff=es->TargetIndexVali; laRecalcCurrentPanel(); }
  2303. return LA_RUNNING;
  2304. }
  2305. real c = (real)((ui->R + ui->L) / 2) - LA_RH / 2; /*- bt->RM;*/
  2306. real r = (ui->B - ui->U - bt->TP - bt->BP) / 2;
  2307. real dx = e->x - c, dy = e->y - (ui->U + r + bt->TP);
  2308. real dist = sqrt(dx * dx + dy * dy);
  2309. if (e->type == LA_L_MOUSE_DOWN){ ui->State = LA_UI_ACTIVE; laRedrawCurrentPanel(); es->Dragging=(dist<=r)?1:2; }
  2310. if (e->type == LA_L_MOUSE_UP){
  2311. ui->State = LA_UI_NORMAL; es->Dragging=0; laRedrawCurrentPanel();
  2312. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2313. return LA_RUNNING_PASS;
  2314. }
  2315. if (e->type & LA_MOUSE_EVENT && es->Dragging){
  2316. laGetFloatArray(&ui->PP, Color);
  2317. if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LogsRGB(Color); }
  2318. tnsRGB2HCY(Color, hcy);
  2319. if (es->Dragging==1){
  2320. abso = fabs(atan((real)dy / (real)dx));
  2321. hcy[0] = abso / TNS_PI / 2;
  2322. if (dx > 0){
  2323. if (dy < 0) hcy[0] = 1 - hcy[0];
  2324. }else{
  2325. if (dy > 0){
  2326. hcy[0] = 0.5 - hcy[0];
  2327. }else{
  2328. hcy[0] += 0.5;
  2329. }
  2330. }
  2331. hcy[1] = dist / r; TNS_CLAMP(hcy[1],0,1);
  2332. hcy[1]=pow(hcy[1],MAIN.ColorPickerGamma);
  2333. }else if (dist < r + LA_RH * 2 && dx > 0){
  2334. abso = -atan((real)dy / (real)dx) / TNS_PI * 2 + 0.5;
  2335. hcy[2] = abso; TNS_CLAMP(hcy[2],0,1);
  2336. }
  2337. tnsHCY2RGB(hcy, Color);
  2338. if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LinearsRGB(Color); }
  2339. laSetFloatArrayAllArray(&ui->PP, Color);
  2340. laRedrawCurrentPanel();
  2341. return LA_RUNNING;
  2342. }
  2343. return LA_RUNNING_PASS;
  2344. }
  2345. int OPMOD_EnumSelector(laOperator *a, laEvent *e){
  2346. laUiItem *ui = a->Instance;
  2347. laBoxedTheme *bt = (*ui->Type->Theme);
  2348. laGeneralUiExtraData *uit = a->CustomData;
  2349. laEnumItem *ei;
  2350. laEnumProp *ep = ui->PP.LastPs->p;
  2351. int at = 0;
  2352. laEnumItem *Data[32];
  2353. int NoEvent = ui->Flags&LA_UI_FLAGS_NO_EVENT;
  2354. int NoTooltip=ui->Flags&LA_UI_FLAGS_NO_TOOLTIP;
  2355. int IsCycle = ui->Flags&LA_UI_FLAGS_CYCLE;
  2356. int IsMomentary = IsCycle && ui->Flags&LA_UI_FLAGS_NODE_CONTAINER;
  2357. // norm e1
  2358. // expand e1 e2 e3
  2359. // expand vertical (vertical)
  2360. // arr expand e1 e1 e3
  2361. // e2 e2 e3
  2362. // arr exp+vert e1 e1
  2363. // e2 e2
  2364. // e3 e3
  2365. if (a->ConfirmData /* && a->ConfirmData->Mode == LA_CONFIRM_DATA*/){
  2366. ui->State = LA_UI_NORMAL;
  2367. laRedrawCurrentPanel();
  2368. return LA_RUNNING;
  2369. }
  2370. if (!laIsInUiItem(ui, e->x, e->y) && !uit->On){ return LA_FINISHED_PASS; }
  2371. if (e->type == LA_TIME_IDLE && !NoTooltip && !uit->On){
  2372. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2373. laPanel *p = laEnableIdlePanel(a->ToPanel, a, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2374. return LA_RUNNING;
  2375. }
  2376. if(NoEvent){ return LA_RUNNING_PASS; }
  2377. if (e->type == LA_L_MOUSE_DOWN || (IsMomentary && e->type == LA_L_MOUSE_UP)){
  2378. if (laIsPropertyReadOnly(&ui->PP)) return LA_RUNNING_PASS;
  2379. int IsVertical = ui->Flags&LA_UI_FLAGS_TRANSPOSE;
  2380. int IsExpand = ui->Flags&LA_UI_FLAGS_EXPAND;
  2381. int ArrLen = laGetArrayLength(&ui->PP);
  2382. if(ArrLen==1){ if(!IsExpand) IsVertical=0; }else{ IsExpand=1; }
  2383. int EnumLen = (IsExpand&&(!IsCycle)) ? laGetEnumEntryLen(&ui->PP) : 1;
  2384. int _L,_R,_U,_B, _W=ui->R - ui->L, _Col=1;
  2385. if(IsVertical){
  2386. if(IsExpand){ _Col=ArrLen; }
  2387. }else{
  2388. if(IsExpand){ _Col=EnumLen; } else { _Col=ArrLen; }
  2389. }
  2390. int row = la_DetectRow(ui, e->y);
  2391. int col = la_DetectColumn(ui, e->x, _Col);
  2392. int ArrTarget=0, EnumTarget=0, ShowMenu=0;
  2393. if(IsVertical){
  2394. if(IsExpand){ EnumTarget=row; ArrTarget=col; } else { EnumTarget=col; }
  2395. }else{
  2396. if(IsExpand){ EnumTarget=col; ArrTarget=row; } else { if(!IsCycle) ShowMenu=1; }
  2397. }
  2398. if(ShowMenu){
  2399. int GX = ui->L, GY = ui->B, GR = ui->R, t = 0;
  2400. ui->State = LA_UI_ACTIVE;
  2401. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2402. laLocalToWindow(a, a->ToPanel, &GR, &t);
  2403. laEnablePropertyPanel(a->ToPanel, a, 0, la_DefaultEnumPanel, 0, &ui->PP, GX, GR, GY, MAIN.CurrentWindow->CH-LA_2RH, 0, e);
  2404. laRedrawCurrentPanel();
  2405. }elif(IsCycle){
  2406. laEnumItem* ei=laGetEnumArrayIndexed(&ui->PP, ArrTarget);
  2407. if(!ei){ ei=((laEnumProp*)ui->PP.LastPs->p)->Items.pFirst; }
  2408. ei = ei->Item.pNext?ei->Item.pNext:((laEnumProp*)ui->PP.LastPs->p)->Items.pFirst;
  2409. if(IsMomentary){ uit->On = 1; if(e->type==LA_L_MOUSE_UP){ ei = ei=((laEnumProp*)ui->PP.LastPs->p)->Items.pFirst; uit->On = 0;} }
  2410. laSetEnumArrayIndexed(&ui->PP, ArrTarget, ei->Index);
  2411. laConfirmInt(a,EnumTarget,LA_CONFIRM_DATA);
  2412. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2413. if(ui->Flags&LA_UI_FLAGS_EXIT_WHEN_TRIGGERED) return LA_FINISHED;
  2414. }else{
  2415. if(ArrTarget>=ArrLen){ArrTarget=ArrLen-1;}
  2416. if(EnumTarget>=EnumLen){EnumTarget=EnumLen-1;}
  2417. laSetEnumArrayIndexedExternal(&ui->PP, ArrTarget, EnumTarget);
  2418. laConfirmInt(a,EnumTarget,LA_CONFIRM_DATA);
  2419. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2420. return LA_RUNNING_PASS;
  2421. }
  2422. return LA_RUNNING;
  2423. }
  2424. if(e->type==LA_R_MOUSE_DOWN){
  2425. int GX = e->x, GY = e->y;
  2426. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2427. laPanel *p = laEnablePropertyPanel(a->ToPanel, a, 0, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2428. return LA_RUNNING;
  2429. }
  2430. return LA_RUNNING_PASS;
  2431. }
  2432. int OPMOD_Button(laOperator *a, laEvent *e){
  2433. laUiItem *ui = a->Instance;
  2434. laBoxedTheme *bt = (*ui->Type->Theme);
  2435. int lx, ly;
  2436. int Away = 0;
  2437. if (e->type == LA_TIME_IDLE && !ui->State){
  2438. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2439. laPanel *p = laEnableIdlePanel(a->ToPanel, a, &ui->ExtraPP, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2440. return LA_RUNNING;
  2441. }
  2442. if (laConfirmSameDataIfAny(a)) return LA_RUNNING_PASS;
  2443. if (e->type == LA_ESCAPE_DOWN || e->type == LA_INPUT) return LA_FINISHED; //debug
  2444. if (!laIsInUiItem(ui, e->x, e->y) /*&& ui->State!= LA_UI_ACTIVE*/){
  2445. ui->State = LA_UI_NORMAL;
  2446. laRedrawCurrentPanel();
  2447. return LA_FINISHED_PASS;
  2448. }
  2449. if (e->type == LA_L_MOUSE_DOWN){
  2450. ui->State = LA_UI_ACTIVE;
  2451. laRedrawCurrentPanel();
  2452. return LA_RUNNING;
  2453. }
  2454. char *str;
  2455. int call_ret=0;
  2456. if (e->type == LA_L_MOUSE_UP && ui->State!=LA_UI_NORMAL){
  2457. ui->State = LA_UI_NORMAL;
  2458. if (ui->AT){
  2459. if (!ui->Instructions){
  2460. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  2461. if (ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  2462. }
  2463. if (!laOperatorAvailableP(ui->AT, 0, ui->Instructions)) return LA_RUNNING;
  2464. lx = e->x;
  2465. ly = e->y;
  2466. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  2467. e->Localized = 0;
  2468. call_ret=laInvokeP(0, ui->AT, e, 0, ui->ExtraInstructions ? ui->ExtraInstructions->Ptr : 0, 0);
  2469. e->x = lx;
  2470. e->y = ly;
  2471. e->Localized = 1;
  2472. }else{
  2473. laOperatorProp *ap = ui->PP.LastPs->p;
  2474. if (ap->OperatorID){
  2475. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  2476. if (!ui->Instructions){
  2477. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  2478. if (ap->OperatorType) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  2479. }
  2480. if (!laOperatorAvailablePSafe(ap->OperatorType, ui->PP.RawThis, ui->PP.Go->UseInstance, ui->Instructions)) return LA_RUNNING;
  2481. lx = e->x;
  2482. ly = e->y;
  2483. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  2484. e->Localized = 0;
  2485. call_ret=laInvokePCreateThis(0, ap->OperatorType, e, ui->PP.RawThis, ui->PP.Go->UseInstance, ui->ExtraInstructions ? ui->ExtraInstructions->Ptr : 0, ap->Base.ExtraInstructions);
  2486. if(a->StopNow) return LA_FINISHED;
  2487. laRetriggerOperators();
  2488. e->x = lx;
  2489. e->y = ly;
  2490. e->Localized = 1;
  2491. }
  2492. }
  2493. if(MAIN.InvokeConfirmData){
  2494. a->ConfirmData=MAIN.InvokeConfirmData; laConfirmSameDataIfAny(a); a->ConfirmData=0;
  2495. }else{
  2496. if (str = strGetArgumentString(ui->Instructions, "feedback")){
  2497. if (strSame(str, "CONFIRM")) laConfirmInt(a, 0, LA_CONFIRM_OK);
  2498. elif (strSame(str, "CANCEL")) laConfirmInt(a, 0, LA_CONFIRM_CANCEL);
  2499. else { laConfirmString(a, str, LA_CONFIRM_CUSTOM_STRING); }
  2500. }elif(!(ui->Flags&LA_UI_FLAGS_NO_CONFIRM)){
  2501. laConfirmInt(a, 0, LA_CONFIRM_OK);
  2502. }
  2503. }
  2504. if(call_ret==LA_OPERATOR_CALLS_SHUTOFF) return LA_OPERATOR_CALLS_SHUTOFF;
  2505. laRedrawCurrentPanel();
  2506. if(ui->Flags&LA_UI_FLAGS_EXIT_WHEN_TRIGGERED) return LA_FINISHED_PASS;
  2507. return LA_RUNNING_PASS;
  2508. }
  2509. return LA_RUNNING_PASS;
  2510. }
  2511. int OPMOD_MenuItem(laOperator *a, laEvent *e){
  2512. laUiItem *ui = a->Instance;
  2513. laPanel *p;
  2514. laBoxedTheme *bt = (*ui->Type->Theme);
  2515. laGeneralUiExtraData *uit = a->CustomData;
  2516. int Away = 0;
  2517. if (a->ConfirmData){
  2518. ui->State = LA_UI_NORMAL;
  2519. laConfirmInt(a, a->ConfirmData->IData, a->ConfirmData->Mode);
  2520. laRedrawCurrentPanel();
  2521. return LA_RUNNING_PASS;
  2522. }
  2523. if (!laIsInUiItem(ui, e->x, e->y) && ui->State != LA_UI_ACTIVE){
  2524. ui->State = LA_UI_NORMAL;
  2525. laRedrawCurrentPanel();
  2526. return LA_FINISHED_PASS;
  2527. }
  2528. if (e->type == LA_L_MOUSE_DOWN){
  2529. int GX = ui->L, GY = ui->B;
  2530. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2531. ui->State = LA_UI_ACTIVE;
  2532. p = laEnableMenuPanel(a->ToPanel, a, ui->Subs.pFirst, &ui->PP, GX, GX + 300, GY, MAIN.CurrentWindow->CH-LA_2RH, 0, e);
  2533. laShowPanelWithDropDownEffect(p);
  2534. laRedrawCurrentPanel();
  2535. return LA_RUNNING;
  2536. }
  2537. return LA_RUNNING_PASS;
  2538. }
  2539. int OPMOD_ConditionToggle(laOperator *a, laEvent *e){
  2540. laUiItem *ui = a->Instance;
  2541. laBoxedTheme *bt = (*ui->Type->Theme);
  2542. laGeneralUiExtraData *uit = a->CustomData;
  2543. int Away = 0;
  2544. if (!laIsInUiItem(ui, e->x, e->y) /*&& ui->State!= LA_UI_ACTIVE*/){
  2545. return LA_FINISHED_PASS;
  2546. }
  2547. if (e->type == LA_L_MOUSE_DOWN){
  2548. ui->State = ui->State == LA_UI_ACTIVE ? LA_UI_NORMAL : LA_UI_ACTIVE;
  2549. laRecalcCurrentPanel();
  2550. return LA_RUNNING;
  2551. }
  2552. return LA_RUNNING_PASS;
  2553. }
  2554. int OPMOD_SingleLineString(laOperator *a, laEvent *e){
  2555. laUiItem *ui = a->Instance;
  2556. laBoxedTheme *bt = (*ui->Type->Theme);
  2557. laGeneralUiExtraData *uit = a->CustomData;
  2558. laStringEdit *se = uit->Edit;
  2559. int Away = 0;
  2560. char _buf[LA_RAW_CSTR_MAX_LEN] = {0}; char* buf=_buf;
  2561. int NoEvent = ui->Flags&LA_UI_FLAGS_NO_EVENT;
  2562. int NoTooltip=ui->Flags&LA_UI_FLAGS_NO_TOOLTIP;
  2563. int IsTerminal=ui->Flags&LA_UI_FLAGS_TERMINAL_INPUT;
  2564. int ImmediateInput=ui->Flags&LA_UI_FLAGS_IMMEDIATE_INPUT;
  2565. if (!laIsInUiItem(ui, e->x, e->y)){
  2566. if (ui->State != LA_UI_EDITING){
  2567. ui->State = LA_UI_NORMAL;
  2568. laRedrawCurrentPanel();
  2569. return LA_FINISHED_PASS;
  2570. }else{
  2571. if(IsTerminal && (e->type&LA_KEY_MOUSE_SCROLL)){ return LA_RUNNING_PASS; }
  2572. if ((e->type & LA_MOUSEDOWN) == LA_MOUSEDOWN){
  2573. buf=strEndEdit(&uit->Edit, 0);
  2574. laSetString(&ui->PP, buf); free(buf);
  2575. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2576. ui->State = LA_UI_NORMAL;
  2577. laRedrawCurrentPanel();
  2578. return LA_FINISHED_PASS;
  2579. }
  2580. }
  2581. }
  2582. if (e->type == LA_TIME_IDLE && !ui->State && !NoTooltip){
  2583. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2584. laPanel *p = laEnableIdlePanel(a->ToPanel, a, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2585. return LA_RUNNING;
  2586. }
  2587. if(NoEvent){ return LA_RUNNING_PASS; }
  2588. if(e->type ==LA_KEY_DOWN){
  2589. if (e->key == LA_KEY_ENTER){
  2590. buf=IsTerminal?strGetEditString(uit->Edit,0):strEndEdit(&uit->Edit, 0);
  2591. if(IsTerminal){ MAIN.IsTerminalEnter=1; }
  2592. laSetString(&ui->PP, buf); free(buf);
  2593. laRedrawCurrentPanel();
  2594. if(!IsTerminal){
  2595. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2596. ui->State = LA_UI_NORMAL;
  2597. return LA_FINISHED_PASS;
  2598. }else{
  2599. laGetString(&ui->PP, _buf, &buf);
  2600. strBeginEdit(&uit->Edit,buf);
  2601. MAIN.IsTerminalEnter=0;
  2602. return LA_RUNNING;
  2603. }
  2604. }else if (e->key == LA_KEY_ESCAPE && ui->State != LA_UI_NORMAL){
  2605. ui->State = LA_UI_NORMAL;
  2606. laRedrawCurrentPanel();
  2607. return LA_FINISHED;
  2608. }
  2609. }
  2610. if(laKeyMapExecuteEventEx(a, &ui->ExtraPP, &ui->Type->KeyMapper, e)) return LA_RUNNING;
  2611. if (e->type == LA_L_MOUSE_DOWN){
  2612. if (ui->State == LA_UI_NORMAL){
  2613. if(laIsPropertyReadOnly(&ui->PP)) return LA_RUNNING;
  2614. ui->State = LA_UI_EDITING;
  2615. laGetString(&ui->PP, _buf, &buf);
  2616. strBeginEdit(&uit->Edit,buf);
  2617. strSelectLineAll(uit->Edit);
  2618. }elif (ui->State == LA_UI_EDITING){
  2619. if (strHasSelection(uit->Edit)) strDeselectAll(uit->Edit);
  2620. else strSelectLineAll(uit->Edit);
  2621. }
  2622. laRedrawCurrentPanel();
  2623. return LA_RUNNING;
  2624. }
  2625. if (e->type == LA_R_MOUSE_DOWN){
  2626. int GX = e->x, GY = e->y;
  2627. ui->PP.LastIndex = la_DetectColumn(ui, e->x, laGetArrayLength(&ui->PP));
  2628. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2629. laPanel *p = laEnablePropertyPanel(a->ToPanel, a, ui->State==LA_UI_EDITING?&ui->ExtraPP:0, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2630. return LA_RUNNING;
  2631. }
  2632. if (ui->State == LA_UI_EDITING){
  2633. if (la_ProcessTextEdit(e, se, ui)){
  2634. laRedrawCurrentPanel();
  2635. if(ImmediateInput){
  2636. buf=strGetEditString(uit->Edit,0); laSetString(&ui->PP, buf); free(buf);
  2637. }
  2638. }
  2639. return LA_RUNNING;
  2640. }
  2641. if (ui->State != LA_UI_EDITING) return LA_RUNNING_PASS;
  2642. else return LA_RUNNING;
  2643. }
  2644. void la_SetMultistringViewRange(laUiItem* ui, laStringEdit* se, laBoxedTheme* bt){
  2645. int NumberWidth=0; int MonoWidth=tnsGetMonoFontAdvance(); int Count=se->TotalLines;
  2646. while(Count){ Count/=10; NumberWidth+=MonoWidth; }
  2647. strSetEditViewRange(ui->Extra->Edit,
  2648. ui->Extra->HeightCoeff>0?ui->Extra->HeightCoeff:((ui->B-ui->U)/LA_RH),(ui->R-ui->L-NumberWidth-bt->LM*2-bt->RM)/MonoWidth);
  2649. }
  2650. int OPMOD_MultiString(laOperator *a, laEvent *e){
  2651. laUiItem *ui = a->Instance;
  2652. laBoxedTheme *bt = (*ui->Type->Theme);
  2653. laGeneralUiExtraData *es = a->CustomData;
  2654. laStringEdit *se = es->Edit;
  2655. int Away = 0;
  2656. char _buf[LA_RAW_CSTR_MAX_LEN] = {0}; char* buf=&_buf;
  2657. int NoEvent = ui->Flags&LA_UI_FLAGS_NO_EVENT;
  2658. int NoTooltip=ui->Flags&LA_UI_FLAGS_NO_TOOLTIP;
  2659. if (!laIsInUiItem(ui, e->x, e->y) && !es->Dragging){
  2660. if ((e->type & LA_MOUSEDOWN) == LA_MOUSEDOWN){
  2661. buf=strGetEditString(es->Edit, 0); laSetString(&ui->PP, buf); free(buf);
  2662. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2663. ui->State = LA_UI_NORMAL;
  2664. laRedrawCurrentPanel();
  2665. return LA_FINISHED_PASS;
  2666. }
  2667. if(ui->State!=LA_UI_ACTIVE) return LA_FINISHED_PASS;
  2668. }
  2669. if (e->type == LA_TIME_IDLE && ui->State!=LA_UI_ACTIVE && !NoTooltip){
  2670. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2671. laPanel *p = laEnableIdlePanel(a->ToPanel, a, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2672. return LA_RUNNING;
  2673. }
  2674. if(NoEvent){ return LA_RUNNING_PASS; }
  2675. if(e->type ==LA_KEY_DOWN){
  2676. if (e->key == LA_KEY_ESCAPE){
  2677. if(ui->State != LA_UI_NORMAL){
  2678. buf=strGetEditString(es->Edit, 0); laSetString(&ui->PP, buf); free(buf);
  2679. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2680. ui->State = LA_UI_NORMAL; laRedrawCurrentPanel();la_SetMultistringViewRange(ui,es->Edit,bt);
  2681. }
  2682. if(es->Dragging){ es->Dragging=0; es->HeightCoeff=es->TargetIndexVali; laRecalcCurrentPanel();la_SetMultistringViewRange(ui,es->Edit,bt); }
  2683. return LA_FINISHED;
  2684. }
  2685. }
  2686. if(laKeyMapExecuteEventEx(a, &ui->ExtraPP, &ui->Type->KeyMapper, e)) return LA_RUNNING;
  2687. if(e->type == LA_L_MOUSE_DOWN && es->HeightCoeff>=0 && e->x>ui->R-bt->RM-LA_RH && e->y>ui->B-bt->BM-LA_RH){
  2688. es->Dragging=1; es->LastX=e->x; es->LastY=e->y; es->TargetIndexVali=es->HeightCoeff;
  2689. return LA_RUNNING;
  2690. }
  2691. if(es->Dragging){
  2692. if(e->type==LA_MOUSEMOVE){ es->HeightCoeff=es->TargetIndexVali+((real)e->y-es->LastY+0.5)/LA_RH;
  2693. if(es->HeightCoeff<1)es->HeightCoeff=1; laRecalcCurrentPanel(); la_SetMultistringViewRange(ui,es->Edit,bt);}
  2694. elif(e->type==LA_L_MOUSE_UP){ es->Dragging=0; }
  2695. elif(e->type==LA_R_MOUSE_DOWN){
  2696. es->Dragging=0; es->HeightCoeff=es->TargetIndexVali; laRecalcCurrentPanel();la_SetMultistringViewRange(ui,se,bt); }
  2697. return LA_RUNNING;
  2698. }
  2699. int NoInactiveScroll=ui->Flags&LA_UI_FLAGS_NO_SCROLL_INACTIVE;
  2700. if((!NoInactiveScroll) || (ui->State==LA_UI_ACTIVE)){
  2701. if(e->type==LA_MOUSE_WHEEL_DOWN){ strMoveView(se, MAIN.ScrollingSpeed, 0); laRedrawCurrentPanel(); return LA_RUNNING; }
  2702. elif(e->type==LA_MOUSE_WHEEL_UP){ strMoveView(se, -MAIN.ScrollingSpeed, 0); laRedrawCurrentPanel(); return LA_RUNNING; }
  2703. }
  2704. if (e->type == LA_L_MOUSE_DOWN){
  2705. if (ui->State == LA_UI_NORMAL){
  2706. ui->State = LA_UI_ACTIVE;
  2707. laGetString(&ui->PP, _buf, &buf);
  2708. strBeginEdit(&es->Edit,buf);la_SetMultistringViewRange(ui,es->Edit,bt);
  2709. laRedrawCurrentPanel();
  2710. return LA_RUNNING;
  2711. }
  2712. }
  2713. if (e->type == LA_R_MOUSE_DOWN){
  2714. int GX = e->x, GY = e->y;
  2715. ui->PP.LastIndex = la_DetectColumn(ui, e->x, laGetArrayLength(&ui->PP));
  2716. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2717. laPanel *p = laEnablePropertyPanel(a->ToPanel, a, ui->State==LA_UI_ACTIVE?&ui->ExtraPP:0, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2718. return LA_RUNNING;
  2719. }
  2720. if (ui->State == LA_UI_ACTIVE){
  2721. if (la_ProcessTextEdit(e, se, ui))laRedrawCurrentPanel();
  2722. return LA_RUNNING;
  2723. }
  2724. if (ui->State != LA_UI_ACTIVE) return LA_RUNNING_PASS;
  2725. else return LA_RUNNING;
  2726. }
  2727. int OPMOD_TabSelector(laOperator *a, laEvent *e){
  2728. laUiItem *ui = a->Instance;
  2729. laBoxedTheme *bt = (*ui->Type->Theme);
  2730. laGeneralUiExtraData *uit = a->CustomData;
  2731. laUiList *uil;
  2732. int Away = 0;
  2733. int count = 0;
  2734. int it = 0;
  2735. int page;
  2736. if (!laIsInBound(e->x, e->y, ui->L, ui->R, ui->U, ui->U+LA_RH)){ return LA_FINISHED; }
  2737. if (e->type == LA_L_MOUSE_DOWN){
  2738. if (ui->Page->HeightCoeff && ui->R - e->x < LA_RH + bt->RM) return LA_RUNNING_PASS;
  2739. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){ count++; }
  2740. page = la_DetectColumn(ui, e->x, count);
  2741. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  2742. if (it == page){
  2743. laRecalcCurrentPanel();
  2744. ui->Page = uil;
  2745. return LA_RUNNING;
  2746. }else
  2747. it++;
  2748. }
  2749. }
  2750. return LA_RUNNING_PASS;
  2751. }
  2752. int OPMOD_Collection(laOperator *a, laEvent *e) {
  2753. laUiItem *ui = a->Instance;
  2754. laGeneralUiExtraData *uit = a->CustomData;
  2755. laListHandle Locals = {0};
  2756. laUiList *uil;
  2757. int lx = e->x, ly = e->y;
  2758. int at = 0;
  2759. laUiList *ToUil =
  2760. a->ToPanel->MenuRefer ? a->ToPanel->MenuRefer : &a->ToPanel->UI;
  2761. if (!laIsInUiItem(ui, e->x, e->y) /* || e->y>(ui->Subs.pFirst?((laUiList*)ui->Subs.pFirst)->HeightCoeff:10000)*/){
  2762. return LA_FINISHED_PASS;
  2763. }
  2764. laLocalToPanel(a, &lx, &ly);
  2765. if (a->ToPanel && ui->U>=a->ToPanel->TitleBar.B && ly < a->ToPanel->TitleBar.B) {
  2766. return LA_FINISHED_PASS;
  2767. }
  2768. uil = la_DetectUiListRecursive(ToUil, lx, ly, 10000, 0, 0, 0, 0, 0);
  2769. if (uil != ((laUiListDrawItem *)a->LocalUiLists.pFirst)->Target) {
  2770. // printf("EXIT\n");
  2771. return LA_FINISHED;
  2772. }
  2773. if (e->type & LA_MOUSE_EVENT) {
  2774. laUiList *sub;
  2775. laUiItem *tui;
  2776. int LimHeight = 10000;
  2777. int UIB = ui->B, UIU = ui->U;
  2778. int t = 0;
  2779. void *Active = ui->PP.EndInstance;
  2780. if (ui->Subs.pFirst)
  2781. LimHeight = (int)((laUiList *)ui->Subs.pFirst)->HeightCoeff;
  2782. if (LimHeight > 0)
  2783. UIB = LimHeight;
  2784. laPanelToLocal(a, &t, &UIB);
  2785. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext) {
  2786. ui->PP.EndInstance = sub->Instance;
  2787. if ((tui = la_DetectUiItemRecursive(sub, e->x, e->y, UIB, &Locals, 0))) {
  2788. if (tui && !a->Child && tui->Type->OperatorType) {
  2789. // printf("invui %d\n", tui);
  2790. laSetOperatorLocalizer(a->ToPanel);
  2791. laInvokeUiP(a, tui->Type->OperatorType, e, tui, &Locals, 0);
  2792. }
  2793. }
  2794. lstClearPointer(&Locals);
  2795. }
  2796. ui->PP.EndInstance = Active;
  2797. }
  2798. if (e->type == LA_L_MOUSE_DOWN && (!laIsPropertyReadOnly(&ui->PP)) &&
  2799. ui->Type != _LA_UI_COLLECTION_SINGLE) {
  2800. laUiList *uil;
  2801. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext) {
  2802. if (a->ConfirmData)
  2803. return LA_RUNNING_PASS;
  2804. if (laIsInBound(e->x, e->y, uil->L, uil->R, uil->U, uil->B)) {
  2805. laRecalcCurrentPanel();
  2806. laPropPack PP = {0};
  2807. la_CopyPropPack(
  2808. &ui->PP,
  2809. &PP); // needed because layout can be switched after set active.
  2810. char *cmd;
  2811. if ((!(cmd = strGetArgumentString(ui->Instructions, "feedback"))) ||
  2812. (!strSame(cmd, "NONE"))) {
  2813. laConfirmPointer(a, uil->Instance, la_EnsureSubTarget(ui->PP.LastPs->p, uil->Instance), LA_CONFIRM_DATA);
  2814. }
  2815. laSetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance,
  2816. uil->Instance);
  2817. laRecordAndPushProp(&PP, 0);
  2818. laMarkPropChanged(&PP);
  2819. return LA_RUNNING_PASS;
  2820. }
  2821. }
  2822. return LA_RUNNING;
  2823. }
  2824. elif (e->type == LA_R_MOUSE_DOWN) {
  2825. laUiList *uil;
  2826. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext) {
  2827. if (laIsInBound(e->x, e->y, uil->L, uil->R, uil->U, uil->B)) {
  2828. ui->PP.EndInstance = uil->Instance;
  2829. lx = e->x, ly = e->y;
  2830. laLocalToWindow(a, a->ToPanel, &lx, &ly);
  2831. laEnablePropertyPanel(a->ToPanel, a, 0, 0, laui_PropOperatorUiDefine, &ui->PP,
  2832. lx, lx, ly, 0, 0, e);
  2833. }
  2834. }
  2835. return LA_RUNNING;
  2836. }
  2837. return LA_RUNNING_PASS;
  2838. }
  2839. int OPMOD_CollectionSelector(laOperator *a, laEvent *e){
  2840. laUiItem *ui = a->Instance;
  2841. laBoxedTheme *bt = (*ui->Type->Theme);
  2842. laGeneralUiExtraData *uit = a->CustomData;
  2843. int NoTooltip=ui->Flags&LA_UI_FLAGS_NO_TOOLTIP;
  2844. int at = 0;
  2845. int ReadOnly=laIsPropertyReadOnly(&ui->PP);
  2846. int Simple=ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR;
  2847. if (a->ConfirmData /* && a->ConfirmData->Mode == LA_CONFIRM_DATA*/){
  2848. ui->State = LA_UI_NORMAL;
  2849. laRecalcCurrentPanel();
  2850. return LA_RUNNING;
  2851. }
  2852. if (!laIsInUiItem(ui, e->x, e->y)){
  2853. return LA_FINISHED;
  2854. }
  2855. if (e->type == LA_TIME_IDLE && !ui->State && !NoTooltip){
  2856. int GX = e->x, GY = e->y; laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2857. laPanel *p = laEnableIdlePanel(a->ToPanel, a, 0, 0, &ui->PP, GX, GX + 150, GY, 600, 200, e);
  2858. return LA_RUNNING;
  2859. }
  2860. if (e->type == LA_L_MOUSE_DOWN){
  2861. laUiList *uil;
  2862. laColumn *col;
  2863. laPanel *p;
  2864. int GX = ui->L, GY = ui->B, GR = ui->R, t = 0;
  2865. if(ReadOnly){ return LA_FINISHED; }
  2866. if(!Simple){
  2867. if (e->x >= TNS_MAX2(ui->R - LA_RH,(ui->R+ui->L)/2) && e->x < ui->R){
  2868. laSetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, 0);
  2869. laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  2870. return LA_FINISHED;
  2871. }
  2872. }
  2873. laLocalToWindow(a, a->ToPanel, &GX, &GY);
  2874. laLocalToWindow(a, a->ToPanel, &GR, &t);
  2875. laRedrawCurrentPanel();
  2876. ui->State = LA_UI_ACTIVE;
  2877. p = laEnableEmptyPropertyPanel(a->ToPanel, a, GX, GR, GY, 500, e);{
  2878. int MinWidth;
  2879. uil = &p->UI;
  2880. col = laFirstColumn(uil);
  2881. laShowItemFull(uil, col, &ui->PP, 0, LA_WIDGET_COLLECTION, 0, ui->Template, 0)->SymbolID = ui->SymbolID;
  2882. laEnclosePanelContent(p, &p->UI);
  2883. }
  2884. return LA_RUNNING;
  2885. }
  2886. return LA_RUNNING_PASS;
  2887. }
  2888. int OPMOD_ColumnAdjuster(laOperator *a, laEvent *e){
  2889. laUiItem *ui = a->Instance;
  2890. laBoxedTheme *bt = (*ui->Type->Theme);
  2891. laGeneralUiExtraData *uit = a->CustomData;
  2892. laColumn *c = uit->Ptr1;
  2893. c = uit->Ptr1 ? uit->Ptr1 : la_DetectSplit(ui->C, e->x);
  2894. if(c){ laSetWindowCursor(LA_LEFT_AND_RIGHT); }else{ laSetWindowCursor(LA_ARROW); }
  2895. if ((!uit->Dragging) && (!laIsInUiItem(ui, e->x, e->y)||!c)){
  2896. //printf("done\n");
  2897. laSetWindowCursor(LA_ARROW);
  2898. return LA_FINISHED_PASS;
  2899. }
  2900. if (e->type == LA_L_MOUSE_DOWN){
  2901. uit->Ptr1 = c;
  2902. uit->LastX = e->x;
  2903. uit->Dragging=1;
  2904. return LA_RUNNING;
  2905. }
  2906. if (uit->Dragging && uit->Ptr1 && e->type == LA_MOUSEMOVE){
  2907. la_AdjustColumnSplit(c, e->x - uit->LastX);
  2908. uit->LastX = e->x;
  2909. laRecalcCurrentPanel();
  2910. return LA_RUNNING;
  2911. }
  2912. if (uit->Dragging && (e->type == LA_L_MOUSE_UP || e->type == LA_R_MOUSE_DOWN || e->key == LA_KEY_ESCAPE)){
  2913. uit->Ptr1 = 0; uit->Dragging=0;
  2914. return LA_RUNNING;
  2915. }
  2916. return LA_RUNNING;
  2917. }
  2918. void la_NodeSocketGetPositionDelta(laUiItem* ui, int ex,int ey,int* dx,int* dy){
  2919. int cx,cy;
  2920. if(ui->Flags&LA_UI_SOCKET_LABEL_E){ cy=(ui->U+ui->B)/2; cx=ui->L+(ui->B-ui->U)/2; }
  2921. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ cy=(ui->U+ui->B)/2; cx=ui->R-(ui->B-ui->U)/2; }
  2922. elif(ui->Flags&LA_UI_SOCKET_LABEL_N){ cx=(ui->L+ui->R)/2; cy=ui->U+(ui->R-ui->L)*0.75; }
  2923. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ cx=(ui->L+ui->R)/2; cy=ui->B-(ui->R-ui->L)*0.75; }
  2924. else{ cx=(ui->L+ui->R)/2; cy=(ui->U+ui->B)/2; }
  2925. *dx=cx-ex; *dy=cy-ey;
  2926. }
  2927. int OPMOD_NodeSocket(laOperator *a, laEvent *e){
  2928. laUiItem *ui = a->Instance;
  2929. laBoxedTheme *bt = (*ui->Type->Theme);
  2930. laGeneralUiExtraData *uit = a->CustomData;
  2931. int lx=e->x,ly=e->y;
  2932. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  2933. laPropContainer* PCFind;
  2934. if(pc==LA_PC_SOCKET_IN) { PCFind=LA_PC_SOCKET_OUT; }
  2935. elif(pc==LA_PC_SOCKET_OUT){ PCFind=LA_PC_SOCKET_IN; }
  2936. if ((!uit->Dragging) && (!laIsInUiItem(ui, e->x, e->y))){ return LA_FINISHED_PASS; }
  2937. if (e->type==LA_TIME_IDLE){ return LA_RUNNING_PASS; }
  2938. if (e->type == LA_L_MOUSE_DOWN){
  2939. uit->Dragging=1; MAIN.NextWireColor+=3;
  2940. if(pc==LA_PC_SOCKET_IN) {
  2941. laNodeInSocket* s=ui->PP.EndInstance;
  2942. uit->Ptr2 = s->Source;
  2943. if(!s->Source){
  2944. s->ColorId=MAIN.NextWireColor; s->Source=MAIN.tNodeOut; latouched_NodeInSocket(0,0);
  2945. MAIN.tNodeOut->RuntimeX=MAIN.tNodeOut->RuntimeY=MAIN.tNodeOut->RuntimePX=MAIN.tNodeOut->RuntimePY=0;
  2946. }else{
  2947. MAIN.tNodeIn->Source = s->Source;
  2948. MAIN.tNodeIn->RuntimeX=MAIN.tNodeIn->RuntimeY=MAIN.tNodeIn->RuntimePX=MAIN.tNodeIn->RuntimePY=0;
  2949. MAIN.tNodeIn->RuntimePX=-(s->Source->RuntimeX+s->Source->RuntimePX)+(s->RuntimeX+s->RuntimePX);
  2950. MAIN.tNodeIn->RuntimePY=-(s->Source->RuntimeY+s->Source->RuntimePY)+(s->RuntimeY+s->RuntimePY);
  2951. s->Source=0; MAIN.tNodeIn->ColorId=s->ColorId; latouched_NodeInSocket(0,0);
  2952. }
  2953. }
  2954. elif(pc==LA_PC_SOCKET_OUT){ MAIN.tNodeIn->Source=ui->PP.EndInstance; latouched_NodeInSocket(0,0);
  2955. MAIN.tNodeIn->RuntimeX=MAIN.tNodeIn->RuntimeY=MAIN.tNodeIn->RuntimePX=MAIN.tNodeIn->RuntimePY=0;
  2956. MAIN.tNodeIn->ColorId=MAIN.NextWireColor; }
  2957. int dx,dy; la_NodeSocketGetPositionDelta(ui,e->x,e->y,&dx,&dy); uit->LastX = e->x+dx; uit->LastY = e->y+dy;
  2958. laRedrawCurrentPanel();
  2959. return LA_RUNNING;
  2960. }
  2961. if (uit->Dragging && e->type == LA_MOUSEMOVE){
  2962. laPanel* p=MAIN.CurrentPanel;
  2963. laLocalToPanel(a, &lx, &ly);
  2964. laUiItem* tui=la_DetectSocketRecursive(&p->UI,lx,ly,100000,uit->Ptr2?LA_PC_SOCKET_IN:PCFind); uit->Ptr1=tui;
  2965. if(pc==LA_PC_SOCKET_IN){
  2966. if(!uit->Ptr2){MAIN.tNodeOut->RuntimeX=e->x-uit->LastX;MAIN.tNodeOut->RuntimeY=e->y-uit->LastY;}
  2967. else { MAIN.tNodeIn->RuntimeX=e->x-uit->LastX;MAIN.tNodeIn->RuntimeY=e->y-uit->LastY; } }
  2968. elif(pc==LA_PC_SOCKET_OUT){ MAIN.tNodeIn->RuntimeX=e->x-uit->LastX; MAIN.tNodeIn->RuntimeY=e->y-uit->LastY; }
  2969. laRedrawCurrentPanel();
  2970. return LA_RUNNING;
  2971. }
  2972. if (uit->Dragging && (e->type == LA_L_MOUSE_UP || e->type == LA_R_MOUSE_DOWN || e->key == LA_KEY_ESCAPE)){
  2973. uit->Dragging=0; MAIN.tNodeIn->Source=0;
  2974. laRecalcCurrentPanel();
  2975. laUiItem* tui=uit->Ptr1; void* soc=tui?tui->PP.EndInstance:0;
  2976. if(pc == LA_PC_SOCKET_IN){
  2977. if(!uit->Ptr2){ if(!tui){ laNodeInSocket* s=ui->PP.EndInstance; s->Source=0; return LA_RUNNING; }
  2978. laNodeInSocket* s=ui->PP.EndInstance; s->Source=0; memAssignRef(s,&s->Source,soc); latouched_NodeInSocket(0,0);
  2979. s->ColorId=MAIN.NextWireColor; laRecordAndPushProp(&ui->PP, 0); laMarkPropChanged(&ui->PP);
  2980. }else{
  2981. if(!tui){
  2982. laNodeInSocket* s=ui->PP.EndInstance; s->Source=uit->Ptr2; memAssignRef(s,&s->Source,0); latouched_NodeInSocket(0,0);
  2983. laRecordAndPushProp(&ui->PP, 0); laMarkPropChanged(&ui->PP);
  2984. }else{
  2985. laNodeInSocket* s=soc; if(s->Source){ uit->Ptr2=0; return LA_RUNNING; } latouched_NodeInSocket(0,0);
  2986. memAssignRef(s,&s->Source,uit->Ptr2); s->ColorId=((laNodeInSocket*)ui->PP.EndInstance)->ColorId;
  2987. laRecordDifferences(&ui->PP,0); laRecordDifferences(&tui->PP,0); laPushDifferences("Socket status changed", 0);
  2988. laMarkPropChanged(&tui->PP); laMarkPropChanged(&ui->PP);
  2989. }
  2990. }
  2991. }
  2992. else{
  2993. if(!tui){ return LA_RUNNING; }
  2994. laNodeInSocket* s=soc; s->Source=0; memAssignRef(s,&s->Source,ui->PP.EndInstance); latouched_NodeInSocket(0,0);
  2995. s->ColorId=MAIN.NextWireColor; laRecordAndPushProp(&tui->PP, 0); laMarkPropChanged(&tui->PP);
  2996. }
  2997. uit->Ptr2=0;
  2998. return LA_RUNNING;
  2999. }
  3000. return LA_RUNNING_PASS;
  3001. }
  3002. int OPMOD_HeightAdjuster(laOperator *a, laEvent *e){
  3003. laUiItem *ui = a->Instance;
  3004. laBoxedTheme *bt = (*ui->Type->Theme);
  3005. laGeneralUiExtraData *uit = a->CustomData;
  3006. int lx=e->x,ly=e->y;
  3007. int ClickedVal=0;
  3008. if ((!uit->Dragging) && (!laIsInUiItem(ui, e->x, e->y))){ return LA_FINISHED_PASS; }
  3009. if (e->type == LA_L_MOUSE_DOWN || e->type==LA_R_MOUSE_DOWN){
  3010. uit->Dragging=1; uit->LastY=e->y; uit->On=0; uit->TargetIndexVali=e->type==LA_L_MOUSE_DOWN?(ui->State==LA_BT_ACTIVE?2:1):2; uit->HeightCoeff=1;
  3011. return LA_RUNNING;
  3012. }
  3013. if(e->type==LA_L_MOUSE_UP && uit->HeightCoeff){ ui->State=(ui->State==LA_BT_ACTIVE)?LA_BT_NORMAL:LA_BT_ACTIVE; laRedrawCurrentPanel(); }
  3014. if (uit->Dragging && e->type == LA_MOUSEMOVE){
  3015. int diff=e->y-uit->LastY; diff=((real)diff+0.5)/(ui->B-ui->U); int delta=uit->TargetIndexVali;
  3016. if(diff!=uit->On){ uit->HeightCoeff=0; int d=diff-uit->On; uit->On=diff; while(d){ laSetInt(&ui->PP, d>0?delta:-delta); d-=(d>0?1:-1); }; laRecalcCurrentPanel(); }
  3017. return LA_RUNNING;
  3018. }
  3019. if (uit->Dragging && (e->type == LA_L_MOUSE_UP || e->type == LA_R_MOUSE_UP || e->key == LA_KEY_ESCAPE)){
  3020. uit->Dragging=0; return LA_RUNNING_PASS;
  3021. }
  3022. return LA_RUNNING_PASS;
  3023. }
  3024. void la_ValueMapperSortPoint(laValueMapper* vm){
  3025. laValueMapperPoint* vmp,*ivmp; laListHandle temp={0}; int Inserted=0;
  3026. while(vmp=lstPopItem(&vm->Points)){
  3027. Inserted=0;
  3028. for(ivmp=temp.pLast;ivmp;ivmp=ivmp->Item.pPrev){
  3029. if(ivmp->x<vmp->x){ lstInsertItemAfter(&temp,vmp,ivmp); Inserted=1; break; }
  3030. }
  3031. if(!Inserted){ lstPushItem(&temp,vmp); }
  3032. }
  3033. vm->Points.pFirst=temp.pFirst; vm->Points.pLast=temp.pLast;
  3034. }
  3035. laValueMapperPoint* la_ValueMapperCreatePoint(laValueMapper* vm, real x, real y){
  3036. laValueMapperPoint* vmp=memAcquire(sizeof(laValueMapperPoint));
  3037. vmp->x=x;vmp->y=y; lstAppendItem(&vm->Points,vmp);
  3038. la_ValueMapperSortPoint(vm);
  3039. return vmp;
  3040. }
  3041. laValueMapperPoint* la_ValueMapperGetPoint(laValueMapper* vm, real x, real y){
  3042. laValueMapperPoint* vmp=0,*ClosestVMP=0; real MinD=FLT_MAX;
  3043. if(x<0||x>1||y>1||y<0) return 0;
  3044. const real thres=0.1;
  3045. for(vmp=vm->Points.pFirst;vmp;vmp=vmp->Item.pNext){
  3046. if(vmp->x>x+thres || vmp->x<x-thres || vmp->y>y+thres || vmp->y<y-thres) continue;
  3047. real d=tnsDistIdv2(x,y,vmp->x,vmp->y);
  3048. if(d<MinD){ ClosestVMP=vmp; MinD=d; }
  3049. }
  3050. vmp=ClosestVMP;
  3051. if(!vmp){ vmp=la_ValueMapperCreatePoint(vm,x,y); }
  3052. return vmp;
  3053. }
  3054. void la_ValueMapperEnsureValidPoints(laValueMapper* vm){
  3055. if(!vm->Points.pFirst){ la_ValueMapperCreatePoint(vm,0,0); }
  3056. if(vm->Points.pFirst==vm->Points.pLast){ la_ValueMapperCreatePoint(vm,1,1); }
  3057. }
  3058. laValueMapper* laValueMapperInit(){
  3059. laValueMapper* vm=memAcquire(sizeof(laValueMapper));
  3060. vm->InRange[0]=0; vm->InRange[1]=1; vm->OutRange[0]=0; vm->OutRange[1]=1;
  3061. la_ValueMapperEnsureValidPoints(vm);
  3062. return vm;
  3063. }
  3064. laValueMapper* laValueMapperDestroy(laValueMapper* vm){
  3065. laValueMapperPoint* vmp;
  3066. while(vmp=lstPopItem(&vm->Points)){ memLeave(vmp); }
  3067. memLeave(vm);
  3068. }
  3069. laValueMapper* laValueMapperCopy(laValueMapper* new_optional, laValueMapper* vm){
  3070. laValueMapper* into=new_optional?new_optional:memAcquire(sizeof(laValueMapper)); laValueMapperPoint* vmp;
  3071. while(vmp=lstPopItem(&into->Points)){ memLeave(vmp); }
  3072. for(vmp=vm->Points.pFirst;vmp;vmp=vmp->Item.pNext){ la_ValueMapperCreatePoint(into, vmp->x, vmp->y); }
  3073. tnsVectorSet2v(into->InRange,vm->InRange); tnsVectorSet2v(into->OutRange,vm->OutRange);
  3074. return into;
  3075. }
  3076. real laValueMapperEvaluate(laValueMapper* vm, real x, real* force_InMin, real* force_InMax, real* force_OutMin, real* force_OutMax, int ClampIn, int ClampOut){
  3077. real InMin=vm->InRange[0], InMax=vm->InRange[1], OutMin=vm->OutRange[0], OutMax=vm->OutRange[1];
  3078. if(force_InMin) InMin=*force_InMin; if(force_InMax) InMax=*force_InMax; if(force_OutMin) OutMin=*force_OutMin; if(force_OutMax) OutMax=*force_OutMax;
  3079. if(fabs(InMax-InMin)<1e-7) return 0;
  3080. x=tnsGetRatiod(InMin,InMax,x); if(ClampIn) TNS_CLAMP(x,0,1);
  3081. laValueMapperPoint* vmp,*NextVMP;
  3082. real ey=0;
  3083. for(vmp=vm->Points.pFirst;vmp;vmp=vmp->Item.pNext){
  3084. NextVMP=vmp->Item.pNext;
  3085. if(NextVMP && (!(vmp->x<=x && NextVMP->x>x))) continue;
  3086. if(!NextVMP){ NextVMP=vmp; vmp=vmp->Item.pPrev; if(!vmp) return 0; }
  3087. if(fabs(vmp->x-NextVMP->x)<1e-7){ ey=vmp->y; break; }
  3088. real ratio=tnsGetRatiod(vmp->x,NextVMP->x,x);
  3089. ey=tnsInterpolate(vmp->y,NextVMP->y,ratio); break;
  3090. }
  3091. real Out=tnsInterpolate(OutMin,OutMax,ey);
  3092. if(ClampOut) TNS_CLAMP(Out,OutMin,OutMax);
  3093. return Out;
  3094. }
  3095. int OPMOD_ValueMapper(laOperator *a, laEvent *e){
  3096. laUiItem *ui = a->Instance;
  3097. laBoxedTheme *bt = (*ui->Type->Theme);
  3098. laGeneralUiExtraData *uit = a->CustomData;
  3099. int w=ui->R-ui->L, h=ui->B-ui->U;
  3100. real x=(real)(e->x-ui->L)/w,y=(real)(ui->B-e->y)/h;
  3101. int ClickedVal=0;
  3102. if ((!uit->Dragging) && (!laIsInUiItem(ui, e->x, e->y))){ return LA_FINISHED_PASS; }
  3103. laValueMapper* vm=ui->PP.EndInstance;
  3104. if (e->type == LA_L_MOUSE_DOWN){
  3105. uit->Dragging=1; uit->LastX=e->x; uit->LastY=e->y;
  3106. return LA_RUNNING;
  3107. }
  3108. if (uit->Dragging && e->type == LA_MOUSEMOVE){
  3109. laValueMapperPoint* vmp=uit->Ptr1;
  3110. if(uit->Dragging==1 && tnsDistIdv2(e->x,e->y,uit->LastX,uit->LastY)>LA_RH/2){
  3111. uit->Ptr1=la_ValueMapperGetPoint(vm,x,y); if(!uit->Ptr1){ uit->Dragging=0; return LA_RUNNING; }
  3112. uit->Dragging=2;
  3113. }
  3114. elif(uit->Dragging==2){
  3115. if(x<0&&x>-0.05){ x=0; } if(x>1&&x<1.05){ x=1; } TNS_CLAMP(y,0,1);
  3116. vmp->x=x; vmp->y=y; la_ValueMapperSortPoint(vm);
  3117. laNotifyUsersPP(&ui->PP); laRedrawCurrentPanel(); laMarkPropChanged(&ui->PP);
  3118. }
  3119. return LA_RUNNING;
  3120. }
  3121. if (uit->Dragging && (e->type == LA_L_MOUSE_UP || e->type == LA_R_MOUSE_UP || e->key == LA_KEY_ESCAPE)){
  3122. uit->Dragging=0; laValueMapperPoint* vmp=uit->Ptr1; if(!vmp) return LA_RUNNING_PASS;
  3123. if(vmp->x>1||vmp->x<0) {
  3124. lstRemoveItem(&vm->Points,vmp); la_ValueMapperEnsureValidPoints(vm);
  3125. laNotifyUsersPP(&ui->PP); laRedrawCurrentPanel(); laRecordAndPushProp(&ui->PP,0); laMarkPropChanged(&ui->PP);
  3126. }
  3127. return LA_RUNNING_PASS;
  3128. }
  3129. return LA_RUNNING_PASS;
  3130. }
  3131. void la_RegisterUiOperatorsBasic(){
  3132. laPropContainer *pc, *p;
  3133. laOperatorType *at;
  3134. laEnumProp *ep;
  3135. laCreateOperatorType("LA_edit_string_copy", "Copy Selection", "Copy selected string to clip board",
  3136. OPCHK_EditStringCopySelection, 0, 0, OPINV_EditStringCopySelection, 0, U'🗍', LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3137. laCreateOperatorType("LA_int_array_h_operator", "Int(Horizon) UiItem Operator", "Do Array Valuator Stuff",
  3138. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_IntArrayHorizon, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3139. laCreateOperatorType("LA_real_array_h_operator", "Float(Horizon) UiItem Operator", "Do Array Valuator Stuff",
  3140. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_FloatArrayHorizon, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3141. laCreateOperatorType("LA_real_color_operator", "Color(Float) Display UiItem Operator", "Color Display,Click To Set Color",
  3142. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_FloatColor, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3143. laCreateOperatorType("LA_real_hcy_operator", "HCY Color Picker UiItem Operator", "HCY Color Picker,Click To Set Color",
  3144. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_ColorHCY, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3145. laCreateOperatorType("LA_enum_selector_operator", "Enum Selector UiItem Operator", "Do Selector Stuff",
  3146. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_EnumSelector, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3147. laCreateOperatorType("LA_button_operator", "Button UiItem Operator", "Execute an Operator",
  3148. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_Button, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3149. laCreateOperatorType("LA_menu_root_operator", "Menu Root UiItem Operator", "Drop A Menu",
  3150. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_MenuItem, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3151. laCreateOperatorType("LA_condition_toggle_operator", "Condition +/- Button Operator", "Do Self Condition Function",
  3152. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_ConditionToggle, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3153. laCreateOperatorType("LA_string_operator", "Single Line String Operator", "Do String Modifying Function",
  3154. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_SingleLineString, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3155. laCreateOperatorType("LA_string_multi", "Multi Line String Operator", "Do String Modifying Function",
  3156. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_MultiString, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3157. laCreateOperatorType("LA_tab_operator", "Tab Switcher Operator", "Change The Page In The Tab Group",
  3158. 0, 0, OPEXT_UiItem, OPINV_Tab, OPMOD_TabSelector, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3159. laCreateOperatorType("LA_collection_operator", "Collection UiItem Operator", "Activate/Deactivate Collection Item(s)",
  3160. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_Collection, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3161. laCreateOperatorType("LA_collection_selector_operator", "Collection Dropdown Selector Operator", "Do Selector Stuff",
  3162. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_CollectionSelector, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3163. laCreateOperatorType("LA_column_adjuster", "Column Width Adjuster", "Drag To Set Width of Columns",
  3164. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_ColumnAdjuster, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3165. laCreateOperatorType("LA_node_socket", "Node Socket Operator", "Drag to connect node sockets",
  3166. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_NodeSocket, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3167. laCreateOperatorType("LA_height_adjuster", "Height Adjuster Operator", "Drag to adjust heights of an instance",
  3168. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_HeightAdjuster, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3169. laCreateOperatorType("LA_value_mapper", "Value mapper Operator", "Drag to set value mapping from input to output",
  3170. 0, 0, OPEXT_UiItem, OPINV_UiItem, OPMOD_ValueMapper, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  3171. }