*/}}

la_widgets.c 128 KB

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