*/}}

la_widgets.c 131 KB

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