*/}}

la_widgets.c 128 KB

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