*/}}

la_widgets.c 156 KB

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