*/}}

la_widgets.c 126 KB

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