*/}}

la_widgets.c 128 KB

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