*/}}

la_widgets.c 132 KB

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