*/}}

la_widgets.c 149 KB

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