*/}}

la_widgets.c 132 KB

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