*/}}

la_widgets.c 129 KB

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