*/}}

la_widgets.c 128 KB

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