*/}}

la_widgets.c 132 KB

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