*/}}

la_kernel.c 292 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824
  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. #ifdef LA_USE_GLES
  19. #define NANOVG_GLES3_IMPLEMENTATION
  20. #else
  21. #define NANOVG_GL3_IMPLEMENTATION
  22. #endif
  23. #include "la_5.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <time.h>
  28. #ifdef __linux__
  29. #include <execinfo.h>
  30. #include <signal.h>
  31. #include <sys/time.h>
  32. #include <X11/Xlib.h>
  33. #include <X11/Xutil.h>
  34. #include <X11/Xos.h>
  35. #include <X11/keysymdef.h>
  36. #include <X11/XKBlib.h>
  37. #include <X11/extensions/XInput.h>
  38. #include <X11/extensions/XInput2.h>
  39. #include <X11/extensions/Xfixes.h>
  40. #include <X11/extensions/Xrandr.h>
  41. #include <X11/Xcursor/Xcursor.h>
  42. #include <X11/cursorfont.h>
  43. #include <GL/glx.h>
  44. #endif
  45. #ifdef _WIN32
  46. #include <GL/wglew.h>
  47. #include <GL/wgl.h>
  48. #include <shellscalingapi.h>
  49. #endif
  50. LA MAIN;
  51. extern tnsMain *T;
  52. int deb = 0;
  53. laOperator *DEB;
  54. laColumn *DEBUG_C;
  55. #ifdef _WIN32
  56. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  57. #else
  58. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  59. #endif
  60. #ifdef __linux__
  61. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  62. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  63. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  64. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  65. #endif
  66. #ifdef __linux__
  67. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  68. int i;
  69. for (i = 0; i < num_classes; i++) {
  70. if (classes[i]->type == XIValuatorClass) {
  71. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  72. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  73. logPrint(" Range: %f - %f\n", v->min, v->max);
  74. logPrint(" Resolution: %d units/m\n", v->resolution);
  75. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  76. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  77. }
  78. }
  79. }
  80. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  81. XIDeviceInfo *info, *dev;
  82. int i, ndevices;
  83. dev = XIQueryDevice(display, deviceid, &ndevices);
  84. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  85. mask->deviceid = deviceid;
  86. mask->mask_len = XIMaskLen(XI_RawMotion);
  87. mask->mask=memAcquireSimple(mask->mask_len);
  88. memset(mask->mask, 0, mask->mask_len);
  89. XISetMask(mask->mask, XI_RawMotion);
  90. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  91. int FoundMax=0;
  92. for (i = 0; i < dev->num_classes; i++) {
  93. if (dev->classes[i]->type == XIValuatorClass) {
  94. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  95. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  96. }
  97. }
  98. if(!FoundMax){*max_pressure=65535;}
  99. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  100. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  101. XIFreeDeviceInfo(dev);
  102. }
  103. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  104. int axis=0;
  105. for (int i = 0; i < dev->num_classes; i++) {
  106. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  107. }
  108. return axis>=3;
  109. }
  110. #define LA_G_STYLUS(dev) \
  111. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  112. #define LA_G_ERASER \
  113. (!MAIN.WacomDeviceEraser)
  114. void la_ScanWacomDevices(Display *display, int deviceid){
  115. XIDeviceInfo *info, *dev;
  116. int ndevices;
  117. int i; char * word;
  118. int _event, _error;
  119. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  120. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  121. }
  122. info = XIQueryDevice(display, deviceid, &ndevices);
  123. for(i = 0; i < ndevices; i++) {
  124. dev = &info[i]; strToLower(dev->name);
  125. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  126. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  127. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  128. word = strtok (dev->name," ");
  129. while (1) {
  130. word = strtok (NULL, " "); if (!word) break;
  131. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  132. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  133. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  134. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  135. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  136. }
  137. }
  138. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  139. logPrintNew("Found wacom devices:\n");
  140. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  141. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  142. }else{
  143. logPrintNew("No wacom pen device connected.\n");
  144. }
  145. XIFreeDeviceInfo(info);
  146. }
  147. void laHideCursor(){
  148. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  149. }
  150. void laShowCursor(){
  151. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  152. }
  153. void la_XErrorHandler(Display *display, XErrorEvent *event){
  154. char buf[512];
  155. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  156. printf("X Error:\n%s\n",buf);
  157. }
  158. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  159. XSetWindowAttributes swa;
  160. XWindowAttributes wa;
  161. swa.event_mask =
  162. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  163. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  164. swa.colormap = MAIN.cmap;
  165. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  166. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  167. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  168. if(x>0||y>0){
  169. XSizeHints my_hints = {0};
  170. my_hints.flags = PPosition;
  171. my_hints.x = x; my_hints.y = y;
  172. XSetNormalHints(MAIN.dpy, win, &my_hints);
  173. }
  174. XStoreName(MAIN.dpy, win, title);
  175. #ifdef LA_USE_GLES
  176. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
  177. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  178. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  179. EGLSurface* surf=egl_surf;
  180. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  181. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  182. tnsContextMakeCurrent((*r_glc),win,(*surf));
  183. #else
  184. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  185. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  186. printf("\n\tcannot create gl context\n\n"); exit(0);
  187. }
  188. tnsContextMakeCurrent((*r_glc),win,0);
  189. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  190. #endif
  191. XSetLocaleModifiers("");
  192. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  193. if(!MAIN.im){
  194. XSetLocaleModifiers("@im=local");
  195. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  196. }
  197. if(!MAIN.im){
  198. XSetLocaleModifiers("@im=none");
  199. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  200. }
  201. if(!MAIN.im){
  202. XSetLocaleModifiers("@im=");
  203. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  204. }
  205. if(!MAIN.im){
  206. logPrint("Can't open a input method.\n");
  207. }
  208. if(MAIN.im){
  209. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  210. XSetICFocus(MAIN.ic);
  211. }
  212. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  213. XSetClassHint(MAIN.dpy, win, &ch);
  214. #define _NET_WM_STATE_ADD 1
  215. if(w<0&&h<0){
  216. XEvent xev;
  217. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  218. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  219. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  220. memset(&xev, 0, sizeof(xev));
  221. xev.type = ClientMessage;
  222. xev.xclient.window = win;
  223. xev.xclient.message_type = wm_state;
  224. xev.xclient.format = 32;
  225. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  226. xev.xclient.data.l[1] = max_horz;
  227. xev.xclient.data.l[2] = max_vert;
  228. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  229. }
  230. return win;
  231. };
  232. void la_DestroySystemWindowX11(laWindow* w) {
  233. tnsContextMakeCurrent(0,0,0);
  234. tnsDeleteContext(w->glc);
  235. #ifdef LA_USE_GLES
  236. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  237. #endif
  238. XDestroyWindow(MAIN.dpy, w->win);
  239. };
  240. #endif //linux
  241. #ifdef _WIN32
  242. #include <msgdef.h>
  243. #include <wintab.h>
  244. #include <wintab_utils.h>
  245. #define PACKETDATA (PK_X | PK_Y | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  246. #define PACKETMODE PK_BUTTONS
  247. #include <pktdef.h>
  248. void la_OpenWacomWinTab(HWND hwnd){
  249. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  250. static LOGCONTEXT glogContext = { 0 };
  251. HCTX hctx = NULL;
  252. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  253. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 };
  254. glogContext.lcOptions |= CXO_SYSTEM;
  255. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  256. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  257. assert(glogContext.lcOptions & CXO_SYSTEM);
  258. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  259. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  260. glogContext.lcPktData = PACKETDATA;
  261. glogContext.lcPktMode = PACKETMODE;
  262. glogContext.lcMoveMask = PACKETDATA;
  263. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  264. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  265. assert(wWTInfoRetVal == sizeof(AXIS));
  266. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  267. assert(wWTInfoRetVal == sizeof(AXIS));
  268. AXIS tabletPressure = { 0 };
  269. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  270. //glogContext.lcInOrgX = 0;
  271. //glogContext.lcInOrgY = 0;
  272. //glogContext.lcInExtX = TabletX.axMax;
  273. //glogContext.lcInExtY = TabletY.axMax;
  274. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  275. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  276. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  277. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  278. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  279. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  280. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  281. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  282. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  283. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  284. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  285. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  286. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  287. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  288. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  289. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  290. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  291. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  292. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  293. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  294. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  295. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  296. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  297. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  298. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  299. if (!hctx)return;
  300. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  301. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  302. }
  303. void laHideCursor() {
  304. if (!MAIN.CurrentWindow) return; //impl
  305. }
  306. void laShowCursor() {
  307. if (!MAIN.CurrentWindow) return; //impl
  308. }
  309. static PIXELFORMATDESCRIPTOR cpfd = {
  310. sizeof(PIXELFORMATDESCRIPTOR),1,
  311. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  312. PFD_TYPE_RGBA,
  313. 8,
  314. 0, 0, 0, 0, 0, 0,
  315. 0, 0, 0,
  316. 0, 0, 0, 0,
  317. 32,
  318. 8, 0,
  319. 0,
  320. 0, 0, 0, 0
  321. };
  322. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  323. int nBestMS = 0;
  324. int i;
  325. int iResults[9];
  326. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  327. WGL_ACCELERATION_ARB, // 1
  328. WGL_DRAW_TO_WINDOW_ARB, // 2
  329. WGL_DOUBLE_BUFFER_ARB, // 3
  330. WGL_PIXEL_TYPE_ARB, // 4
  331. WGL_DEPTH_BITS_ARB, // 5
  332. WGL_STENCIL_BITS_ARB, // 6
  333. WGL_SAMPLE_BUFFERS_ARB, // 7
  334. WGL_SAMPLES_ARB }; // 8
  335. // How many pixelformats are there?
  336. int nFormatCount[] = { 0 };
  337. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  338. if (!wglGetPixelFormatAttribivARB)
  339. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  340. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  341. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  342. for (i = 0; i < nFormatCount[0]; i++){
  343. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  344. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  345. if (iResults[3] == 1) // Double buffered
  346. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  347. if (iResults[5] >= 24) // Any Depth greater than 16
  348. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  349. }
  350. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  351. };
  352. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  353. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  354. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  355. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
  356. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  357. 0 };
  358. HGLRC hglrc = 0;
  359. HDC hdc = 0;
  360. int a, b;
  361. hdc = GetDC(hwnd);
  362. la_SetupPxlFormat(hdc, &a, &b);
  363. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  364. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  365. tnsContextMakeCurrent(hglrc, hdc,0);
  366. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  367. wglSwapIntervalEXT(-1);
  368. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  369. };
  370. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  371. HINSTANCE* inst = &MAIN.hinstance;
  372. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  373. x, y, w, h, 0, 0, *inst, 0);
  374. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  375. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  376. return hwnd;
  377. };
  378. void la_DestroySystemWindowWin32(laWindow* w) {
  379. tnsContextMakeCurrent(0,0,0);
  380. tnsDeleteContext(w->glc);
  381. ReleaseDC(w->win, w->hdc);
  382. DestroyWindow(w->win);
  383. };
  384. #endif
  385. #ifdef __linux__
  386. void la_HandlerSIGSEGV(int sig) {
  387. void *array[30];
  388. size_t sz;
  389. sz = backtrace(array, 30);
  390. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  391. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  392. exit(1);
  393. }
  394. #endif
  395. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  396. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  397. // ignore non-significant error/warning codes
  398. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076) return;
  399. logPrint("GL %d: %s\n", id, message);
  400. char* strsource="",*strtype="",*strseverity="";
  401. switch (source) {
  402. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  403. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  404. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  405. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  406. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  407. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  408. }
  409. switch (type) {
  410. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  411. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  412. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  413. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  414. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  415. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  416. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  417. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  418. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  419. }
  420. switch (severity) {
  421. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  422. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  423. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  424. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  425. }
  426. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  427. }
  428. void la_SetCurrentGLContextDebug(){
  429. int force=MAIN.InitArgs.GLDebug;
  430. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  431. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  432. glDebugMessageCallback(la_glDebugOutput, 0);
  433. int sev=GL_DONT_CARE;
  434. if(!force){
  435. switch(MAIN.GLDebugLevel){
  436. default: sev=GL_DONT_CARE; break;
  437. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  438. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  439. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  440. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  441. }
  442. }
  443. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  444. }
  445. void la_NotifyGLDebugChanges(){
  446. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  447. }
  448. void la_SetupWindowGLStates(laWindow* w){
  449. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  450. if(w->GLDebugNeedsUpdate){
  451. tnsContextMakeWindowCurrent(w);
  452. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  453. }
  454. }
  455. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  456. SYSGLCONTEXT glc;
  457. #ifdef __linux__
  458. void* egl_surf=0;
  459. #ifdef LA_USE_GLES
  460. egl_surf=&window->egl_surf;
  461. #endif
  462. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  463. #endif
  464. #ifdef _WIN32
  465. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  466. #endif
  467. window->win = hwnd;
  468. window->glc = glc;
  469. #ifdef _WIN32
  470. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  471. RECT rc; GetClientRect(window->win, &rc);
  472. window->CW = rc.right - rc.left;
  473. window->CH = rc.bottom - rc.top;
  474. #endif
  475. #ifdef __linux__
  476. XWindowAttributes attr;
  477. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  478. window->CW =attr.width;
  479. window->CH = attr.height;
  480. #endif
  481. la_SetCurrentGLContextDebug();
  482. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  483. la_SetupWindowGLStates(window);
  484. #ifdef LA_USE_GLES
  485. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  486. #else
  487. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  488. #endif
  489. window->OutputShowStripes=1; window->Redraw=1;
  490. window->GLDebugNeedsUpdate=1;
  491. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  492. return 1;
  493. };
  494. int la_DestroySystemWindow(laWindow* wnd){
  495. #ifdef LA_USE_GLES
  496. nvgDeleteGLES3(wnd->nvg);
  497. #else
  498. nvgDeleteGL3(wnd->nvg);
  499. #endif
  500. #ifdef __linux__
  501. la_DestroySystemWindowX11(wnd);
  502. #endif
  503. #ifdef _WIN32
  504. la_DestroySystemWindowWin32(wnd);
  505. #endif
  506. }
  507. void la_DestroyWindow(laWindow *wnd){
  508. laLayout *l; laPanel *p; if (!wnd) return;
  509. tnsSwitchToCurrentWindowContext(wnd);
  510. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  511. la_StopAllOperators();
  512. strSafeDestroy(&wnd->Title);
  513. //la_PrintUserList(wnd);
  514. //printf("----\n");
  515. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  516. while (l = lstPopItem(&wnd->Layouts)){
  517. laDestroyBlocksRecursive(l->FirstBlock);
  518. //la_PrintUserList(l);
  519. //printf("%x %s\n", l, l->ID->Ptr);
  520. strSafeDestroy(&l->ID);
  521. memFree(l);
  522. //la_PrintUserList(wnd);
  523. //printf("----\n");
  524. }
  525. //printf("----\n%x\n",wnd);
  526. //la_PrintUserList(wnd);
  527. la_DestroySystemWindow(wnd);
  528. lstRemoveItem(&MAIN.Windows, wnd);
  529. memFree(wnd);
  530. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  531. }
  532. void laRenameWindow(laWindow* wnd, char* name){
  533. if((!wnd)||MAIN.IsReadingUDF) return;
  534. strSafeSet(&wnd->Title, name);
  535. if(!wnd->win) return;
  536. #ifdef __linux__
  537. XStoreName(MAIN.dpy, wnd->win, name);
  538. #endif
  539. #ifdef _WIN32
  540. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  541. SetWindowTextW(wnd->win, name);
  542. #endif
  543. }
  544. #ifdef __linux__
  545. const char* la_ConvertCursorID(int id){
  546. switch (id) {
  547. case LA_ARROW: return "arrow";
  548. case LA_CROSS: return "cross";
  549. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  550. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  551. case LA_MOVE: return "diamond_cross";
  552. case LA_HAND: return "hand1";
  553. case LA_CORNER: return "bottom_right_corner";
  554. }
  555. return "arrow";
  556. }
  557. #endif
  558. #ifdef _WIN32
  559. HCURSOR la_ConvertCursorID(int id){
  560. switch (id){
  561. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  562. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  563. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  564. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  565. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  566. case LA_HAND: return LoadCursor(0, IDC_HAND);
  567. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  568. }
  569. return LoadCursor(0, IDC_ARROW);;
  570. }
  571. #endif
  572. void la_InitThreadEnviornment(){
  573. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  574. }
  575. laLogEntry* logEnsure(int Create){
  576. if(!MAIN.Logs.pFirst || Create){
  577. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  578. lstAppendItem(&MAIN.Logs, le);
  579. }
  580. return MAIN.Logs.pLast;
  581. }
  582. void logPrintTV(int Continued, char* format, va_list v){
  583. if(!format || !format[0]) return;
  584. laLogEntry* le=logEnsure(Continued);
  585. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  586. strSafePrintV(&le->Content, format, v);
  587. laNotifyUsers("la.logs");
  588. }
  589. void logPrintT(int Continued, char* format, ...){
  590. if(!format || !format[0]) return;
  591. laLogEntry* le=logEnsure(Continued);
  592. va_list aptr; va_start(aptr, format);
  593. strSafePrint(&le->Content, format, aptr);
  594. va_end(aptr);
  595. laNotifyUsers("la.logs");
  596. }
  597. void logPrint(char* format, ...){
  598. va_list aptr; va_start(aptr, format);
  599. logPrintTV(0, format, aptr);
  600. va_end(aptr);
  601. }
  602. void logPrintNew(char* format, ...){
  603. logEnsure(1);
  604. va_list aptr; va_start(aptr, format);
  605. logPrintTV(0, format, aptr);
  606. va_end(aptr);
  607. }
  608. void logClear(){
  609. laLogEntry*l;
  610. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  611. laNotifyUsers("la.logs");
  612. }
  613. laScreen* la_EnsureScreen(char* Name, int mmw, int mmh, int x, int y, int w, int h,int dpi){ if(!Name || !Name[0]) return 0;
  614. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  615. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  616. }
  617. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  618. strSafeSet(&s->Name,Name);
  619. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  620. s->x=x;s->y=y;s->w=w;s->h=h;
  621. return s;
  622. }
  623. void la_RemoveScreen(laScreen*s){
  624. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  625. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  626. }
  627. void la_RemoveDuplicatedScreenConf(){
  628. laScreen* NextS;
  629. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  630. NextS = s->Item.pNext;
  631. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  632. if(strSame(SSTR(fs->Name),SSTR(s->Name))){ fs->x=s->x;fs->y=s->y;fs->w=s->w;fs->h=s->h; la_RemoveScreen(s); break; }
  633. }
  634. }
  635. }
  636. laScreen* laGetWindowScreen(laWindow* w){
  637. int l,r,u,b; int area=-1; laScreen* maxs=0;
  638. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  639. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  640. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  641. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  642. int a=w*h; if(a>area){ maxs = s; area = a; }
  643. }
  644. return maxs;
  645. }
  646. #ifdef __linux__
  647. int la_GetDPI(Window* root_win){
  648. XRRScreenResources *screen;
  649. XRROutputInfo *info;
  650. XRRCrtcInfo *crtc_info;
  651. XRRCrtcInfo *crtc;
  652. int iscres, icrtc, dpi=0;
  653. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  654. for(iscres=0;iscres<screen->noutput;iscres++){
  655. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  656. if(!info->mm_width || !info->mm_height){ continue; }
  657. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  658. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  659. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  660. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  661. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  662. XRRFreeCrtcInfo(crtc);
  663. //if(info->connection==RR_Connected){
  664. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  665. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  666. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  667. // XRRFreeCrtcInfo(crtc_info);
  668. // }
  669. //}
  670. XRRFreeOutputInfo(info);
  671. }
  672. XRRFreeScreenResources(screen);
  673. return dpi;
  674. }
  675. #endif
  676. #ifdef _WIN32
  677. int la_GetDPI(HWND win){
  678. return GetDpiForWindow(win);
  679. return 144;
  680. }
  681. #endif
  682. #define PROGRESSW (LA_RH*15)
  683. void laShowProgress(real p1, real p2){
  684. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  685. if(!MAIN.Progress.Called){
  686. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  687. }else{
  688. laTimeRecorder tm; laRecordTime(&tm);
  689. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1) return;
  690. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  691. if(!MAIN.Progress.Shown){
  692. int ww=PROGRESSW+LA_RH*2;
  693. #ifdef __linux__
  694. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  695. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  696. long a=LA_COLOR3_TO_HEX(bg);
  697. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  698. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  699. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  700. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  701. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  702. #endif
  703. #ifdef _WIN32
  704. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  705. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  706. ShowWindow(MAIN.Progress.w,SW_SHOW);
  707. #endif
  708. MAIN.Progress.Shown = 1;
  709. }
  710. }
  711. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  712. #ifdef __linux__
  713. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  714. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  715. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  716. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  717. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  718. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  719. #endif
  720. #ifdef _WIN32
  721. InvalidateRect(MAIN.Progress.w,0,1);
  722. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  723. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  724. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  725. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  726. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  727. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  728. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  729. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  730. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  731. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  732. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  733. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  734. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  735. EndPaint(MAIN.Progress.w,&ps);
  736. MSG msg;
  737. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  738. #endif
  739. }
  740. void laHideProgress(){
  741. if(!MAIN.Progress.Shown){
  742. MAIN.Progress.Called=0; return;
  743. }
  744. laTimeRecorder tm; laRecordTime(&tm);
  745. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  746. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  747. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  748. #ifdef __linux__
  749. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  750. #endif
  751. #ifdef _WIN32
  752. ShowWindow(MAIN.Progress.w,SW_HIDE);
  753. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  754. #endif
  755. }
  756. //=======================
  757. void la_InitProgressWindow(){
  758. #ifdef __linux__
  759. MAIN.Progress.w=XCreateSimpleWindow(MAIN.dpy, RootWindow(MAIN.dpy, 0), 0, 0, PROGRESSW+LA_RH*2, LA_RH*2, 0, BlackPixel(MAIN.dpy, 0), WhitePixel(MAIN.dpy, 0));
  760. if(!MAIN.Progress.w) return;
  761. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  762. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  763. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  764. if(MAIN.Progress.gc<0) return;
  765. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  766. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  767. XSync(MAIN.dpy,0);
  768. #endif
  769. #ifdef _WIN32
  770. WNDCLASSW wc;
  771. wc.hInstance = MAIN.hinstance;
  772. wc.lpfnWndProc = LA_ProgressWindowProc;
  773. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  774. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  775. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  776. wc.cbWndExtra = 0;
  777. wc.cbClsExtra = 0;
  778. wc.lpszClassName = L"_LAGUIPROGRESS";
  779. wc.lpszMenuName = NULL;
  780. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  781. if (!RegisterClassW(&wc)){ return; }
  782. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  783. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  784. #endif
  785. }
  786. void laSetFontFolderPath(char* absolute){
  787. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  788. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  789. }
  790. void laSetDefaultInitArguments(laInitArguments* ia){
  791. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  792. ia->UseColorManagement=0;
  793. ia->HasWorldObjects=0;
  794. ia->HasAction=0;
  795. ia->HasTextureInspector=0;
  796. ia->HasHistories=0;
  797. ia->HasTerminal=1;
  798. ia->HasAudio=0;
  799. }
  800. void laSetCompleteInitArguments(laInitArguments* ia){
  801. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  802. ia->UseColorManagement=1;
  803. ia->HasWorldObjects=1;
  804. ia->HasAction=1;
  805. ia->HasTextureInspector=1;
  806. ia->HasHistories=1;
  807. ia->HasTerminal=1;
  808. ia->HasAudio=1;
  809. }
  810. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  811. MAIN.GLMajor=MAIN.GLMinor=-1;
  812. char* arg = 0;
  813. printf("Initializing LaGUI...\n",argc);
  814. for(int i=0;i<argc;i++){
  815. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  816. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  817. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  818. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  819. }
  820. continue;
  821. }
  822. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  823. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  824. }
  825. }
  826. int laGetReadyWith(laInitArguments* ia){
  827. #ifdef __linux__
  828. //signal(SIGSEGV,la_HandlerSIGSEGV);
  829. #endif
  830. laSpinInit(&MAIN.MemLock);
  831. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  832. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  833. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  834. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  835. tnsInit();
  836. #ifdef __linux__
  837. SYSWINDOW root, win;
  838. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  839. XSetWindowAttributes swa={0};
  840. XWindowAttributes wa={0};
  841. XEvent xev;
  842. logPrintNew("Initializing LaGUI...\n");
  843. setlocale(LC_CTYPE, "zh_CN.utf8");
  844. XSetErrorHandler(la_XErrorHandler);
  845. int i;
  846. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  847. printf("\n\tcannot connect to x server\n\n");
  848. exit(0);
  849. }
  850. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  851. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  852. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  853. #ifdef LA_USE_GLES
  854. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  855. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  856. EGLint egl_major, egl_minor;
  857. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  858. printf("Error: eglInitialize() failed\n"); return -1;
  859. }
  860. int scrnum;
  861. XSetWindowAttributes attr;
  862. XVisualInfo *visInfo, visTemplate;
  863. int num_visuals;
  864. EGLContext ctx;
  865. EGLint num_configs;
  866. EGLint vid;
  867. static const EGLint attribs[] = {
  868. EGL_RED_SIZE, 8,
  869. EGL_GREEN_SIZE, 8,
  870. EGL_BLUE_SIZE, 8,
  871. EGL_DEPTH_SIZE, 1,
  872. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  873. EGL_NONE
  874. };
  875. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  876. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  877. }
  878. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  879. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  880. }
  881. visTemplate.visualid = vid;
  882. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  883. if (!visInfo) {
  884. printf("Error: couldn't get X visual\n"); exit(1);
  885. }
  886. MAIN.xvi=visInfo;
  887. root = DefaultRootWindow(MAIN.dpy);
  888. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  889. printf("\n\tcannot create colormap\n\n"); exit(1);
  890. }
  891. eglBindAPI(EGL_OPENGL_ES_API);
  892. static const EGLint ctx_attribs[] = {
  893. EGL_CONTEXT_CLIENT_VERSION, 2,
  894. EGL_NONE
  895. };
  896. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  897. if (!MAIN.glc) {
  898. printf("Error: eglCreateContext failed\n"); exit(1);
  899. }
  900. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  901. #else
  902. int visual_attribs[] = {
  903. GLX_X_RENDERABLE , True,
  904. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  905. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  906. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  907. GLX_RED_SIZE , 8,
  908. GLX_GREEN_SIZE , 8,
  909. GLX_BLUE_SIZE , 8,
  910. GLX_ALPHA_SIZE , 8,
  911. GLX_DEPTH_SIZE , 24,
  912. //GLX_STENCIL_SIZE , 8,
  913. GLX_DOUBLEBUFFER , True,
  914. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  915. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  916. None
  917. };
  918. int fbcount = -1;
  919. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  920. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  921. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  922. MAIN.BestFBC = fbconfig[0];
  923. int sample_buf,samples;
  924. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  925. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  926. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  927. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  928. free(fbconfig);
  929. root = DefaultRootWindow(MAIN.dpy);
  930. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  931. printf("\n\tcannot create colormap\n\n"); exit(0);
  932. }
  933. swa.colormap = MAIN.cmap;
  934. root = DefaultRootWindow(MAIN.dpy);
  935. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  936. MAIN.win=win;
  937. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  938. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  939. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  940. printf("\n\tcannot create gl context\n\n"); exit(0);
  941. }
  942. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  943. tnsContextMakeCurrent(MAIN.glc,win,0);
  944. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  945. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  946. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  947. int err=0;
  948. if((err=glewInit())!=GLEW_OK){
  949. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  950. };
  951. #endif /* gles or glx */
  952. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  953. la_SetCurrentGLContextDebug();
  954. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  955. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  956. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  957. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  958. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  959. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  960. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  961. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  962. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  963. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  964. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  965. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  966. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  967. #endif //linux
  968. #ifdef _WIN32
  969. logPrintNew("Initializing LaGUI...\n");
  970. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  971. setlocale(LC_ALL, "zh_CN.utf8");
  972. MAIN.hinstance = GetModuleHandle(NULL);
  973. HINSTANCE* hInst = &MAIN.hinstance;
  974. WNDCLASSEXW wt;
  975. wt.cbSize = sizeof(WNDCLASSEXW);
  976. wt.cbClsExtra = 0;
  977. wt.cbWndExtra = 0;
  978. wt.hbrBackground = 0;
  979. wt.hCursor = LoadCursor(0, IDC_ARROW);
  980. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  981. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  982. wt.hInstance = *hInst;
  983. wt.lpfnWndProc = LA_WindowProc;
  984. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  985. wt.lpszMenuName = 0;
  986. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  987. if (!RegisterClassExW(&wt)) return 0;
  988. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  989. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  990. SetProcessDPIAware();
  991. GLenum err;
  992. PIXELFORMATDESCRIPTOR pfd;
  993. HINSTANCE* hinst = &MAIN.hinstance;
  994. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  995. "Temp Window For Accessing GLEW!",
  996. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  997. 0, 0, *hinst, 0);
  998. HDC hdc = GetDC(hwnd);
  999. HGLRC hglrc = 0;
  1000. SetPixelFormat(hdc, 1, &cpfd);
  1001. hglrc = wglCreateContext(hdc);
  1002. tnsContextMakeCurrent(hglrc, hdc,0);
  1003. //MAIN.hdc = hdc;
  1004. // MAIN.tWND = hwnd;
  1005. MAIN.glc = hglrc;
  1006. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1007. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1008. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1009. if (err = glewInit()) {
  1010. printf("Init Glew Failed\n");
  1011. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1012. return 0;
  1013. }
  1014. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1015. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1016. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1017. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1018. #endif
  1019. la_GetWorkingDirectoryInternal();
  1020. MAIN.SavePreferenceOnExit=1;
  1021. MAIN.FontSize = 0.6;
  1022. #ifdef _WIN32
  1023. int dpi=la_GetDPI(hwnd);
  1024. #endif
  1025. #ifdef __linux__
  1026. int dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1027. #endif
  1028. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1029. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1030. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1031. MAIN.UiScale=1;
  1032. MAIN.MarginSize = 1;
  1033. MAIN.ColorPickerGamma=1.5;
  1034. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1035. MAIN.ViewportHalftoneFactor=0.5;
  1036. MAIN.ViewportHalftoneSize=3.7;
  1037. tnsInitRenderKernel(64);
  1038. tnsInitBuiltinShaders();
  1039. tnsSetuptnsFontManager();
  1040. #define LOAD_FONT(font) \
  1041. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1042. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1043. LOAD_FONT("NotoEmoji-Regular.ttf");
  1044. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1045. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1046. //LOAD_FONT("NotoMusic-Regular.ttf");
  1047. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1048. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) printf("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1049. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1050. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1051. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1052. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1053. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1054. MAIN.Audio=memAcquire(sizeof(laAudio));
  1055. #ifdef LA_WITH_LUAJIT
  1056. // starting lua
  1057. logPrint("Starting luajit...\n");
  1058. MAIN.L = lua_open();
  1059. la_luaLoadLibs(MAIN.L);
  1060. la_luaPrintStatus(MAIN.L);
  1061. tnsLuaInit(MAIN.L);
  1062. #endif
  1063. //interactions:
  1064. MAIN.TopFramerate = 60;
  1065. MAIN.ValuatorThreshold = 8;
  1066. MAIN.ScrollingSpeed = 3;
  1067. MAIN.AnimationSpeed = 0.4;
  1068. MAIN.PanelAnimationSpeed = 0.4;
  1069. MAIN.ZoomSpeed2D = 0.01;
  1070. MAIN.IdleTime = 0.75;
  1071. MAIN.TooltipCloseDistance = 30;
  1072. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1073. //display:
  1074. MAIN.FloatingAlpha = 0.35;
  1075. MAIN.SolidShadowLength = 20;
  1076. MAIN.WireColorSlices = 16;
  1077. MAIN.WireThickness = 5;
  1078. MAIN.WireSaggyness = 0.5;
  1079. laAddResourceFolder(".");
  1080. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1081. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0);
  1082. la_InitProgressWindow();
  1083. la_MakeTranslations();
  1084. //tns_RegisterResourcesForSoftwareRender();
  1085. la_RegisterDefaultSignals();
  1086. la_RegisterGeneralProps();
  1087. la_RegisterBuiltinTemplates();
  1088. la_RegisterMainThemes();
  1089. la_RegisterMainOperators();
  1090. la_RegisterMainUiTypes();
  1091. la_RegisterModellingOperators();
  1092. la_RegisterShapeOperators();
  1093. la_RegisterInternalProps();
  1094. la_RegisterAnimationResources();
  1095. la_RegisterWindowKeys();
  1096. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1097. laFinalizeUiTemplates();
  1098. laFinalizeOperators();
  1099. la_RegisterControllerProps();
  1100. la_RefreshControllers();
  1101. la_RegisterBasicNodes();
  1102. tns_RegisterNodes();
  1103. la_InitThreadEnviornment();
  1104. laSetRootInstance(&MAIN);
  1105. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1106. laPushDifferences(0, 0);
  1107. la_MakeDummyManagedUDF();
  1108. la_RegenerateWireColors();
  1109. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1110. logPrintNew("Initialization Completed\n");
  1111. MAIN.InitDone=1;
  1112. return 1;
  1113. }
  1114. int laGetReady(){
  1115. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1116. return laGetReadyWith(&ia);
  1117. }
  1118. void la_DestroyUiType(laUiType* uit);
  1119. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1120. void laShutoff(int SavePrefereces){
  1121. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1122. transDumpMissMatchRecord("TranslationDump.txt");
  1123. if(MAIN.Cleanup) MAIN.Cleanup();
  1124. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1125. strSafeDestroy(&MAIN.WorkingDirectory);
  1126. strSafeDestroy(&MAIN.example_string);
  1127. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1128. // (Must undo/redo to desired position or delete from back/front without moving target head. This can be done but this is of lower priority. )
  1129. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1130. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1131. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1132. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1133. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1134. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1135. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1136. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1137. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1138. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1139. strSafeDestroy(&MAIN.CopyPending);
  1140. la_ClearUDFRegistryAndFolders();
  1141. laClearManagedUDF();
  1142. laClearSaveProp();
  1143. logClear();
  1144. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1145. #ifdef __linux__
  1146. tnsContextMakeCurrent(0,0,0);
  1147. tnsDeleteContext(MAIN.glc);
  1148. #ifdef LA_USE_GLES
  1149. eglTerminate(MAIN.egl_dpy);
  1150. #endif
  1151. #endif
  1152. #ifdef _WIN32
  1153. tnsContextMakeCurrent(0,0,0);
  1154. tnsDeleteContext(MAIN.glc);
  1155. UnloadWintab();
  1156. #endif
  1157. tnsQuit();
  1158. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1159. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1160. strSafeDump();
  1161. hshFree(&MAIN.DBInstMemLeft);
  1162. memNoLonger();
  1163. #ifdef LA_WITH_LUAJIT
  1164. lua_close(MAIN.L);
  1165. #endif
  1166. printf("LaGUI has cleaned up.\n");
  1167. }
  1168. int laRestoreFactorySettings(){
  1169. char path[1024]; sprintf(path, "%s%s", MAIN.WorkingDirectory->Ptr, "preferences.udf");
  1170. if(remove(path)){ return 0; }
  1171. return 1;
  1172. }
  1173. void laSaveUserPreferences(){
  1174. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  1175. laUDF* udf=laPrepareUDF(path);
  1176. laWriteProp(udf,"la.windows");
  1177. laWriteProp(udf,"la.user_preferences");
  1178. laWriteProp(udf,"la.input_mapping");
  1179. laWriteProp(udf,"la.controllers");
  1180. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1181. laWriteProp(udf,lip->p);
  1182. }
  1183. laPackUDF(udf,0,0);
  1184. }
  1185. void laEnsureUserPreferences(){
  1186. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  1187. laUDFRegistry* r=laFindUDFRegistry(path);
  1188. if(!r){ laSaveUserPreferences(); return; }
  1189. laUDF* udf=laOpenUDF(r->Path->Ptr,1,0,0); if(!udf){ logPrint("Can't read preferences. Using default settings."); return; }
  1190. laClearUDFRegistries();
  1191. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1192. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1193. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1194. laCloseUDF(udf);
  1195. la_RemoveDuplicatedScreenConf();
  1196. la_RemoveDuplicatedControllers();
  1197. laRefreshUDFRegistries();
  1198. //restore forced settings
  1199. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1200. }
  1201. void laAddExtraExtension(int FileType, ...){
  1202. va_list list; va_start(list,FileType);
  1203. char* ext;
  1204. while(ext=va_arg(list,char*)){ if(!ext) break;
  1205. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1206. et->FileType=FileType; et->Extension=ext;
  1207. lstAppendItem(&MAIN.ExtraExtensions, et);
  1208. }
  1209. va_end(list);
  1210. }
  1211. void laAddExtraPreferencePath(const char* path){
  1212. if(!path) return;
  1213. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1214. }
  1215. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1216. if(!name || !Func) return;
  1217. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1218. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1219. }
  1220. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1221. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1222. }
  1223. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1224. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1225. }
  1226. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1227. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1228. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1229. }
  1230. laCustomSignal* laFindSignal(char* Name){
  1231. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1232. return 0;
  1233. }
  1234. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1235. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key); if(str&&str[0]){ int adv; ime->KeyValue=laToUnicode(str,&adv); }else{ ime->KeyValue=0; } }
  1236. if(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1237. char* signal = SSTR(ime->Signal);
  1238. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1239. }
  1240. laInputMapping* laNewInputMapping(char* Name){
  1241. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1242. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1243. strSafeSet(&im->Name,Name);
  1244. return im;
  1245. }
  1246. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1247. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1248. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1249. memAssignRef(e,&e->Parent,im);
  1250. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1251. laInputMappingUpdateSignal(e);
  1252. }
  1253. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1254. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1255. }
  1256. void laRemoveInputMapping(laInputMapping* im){
  1257. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1258. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1259. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1260. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1261. }
  1262. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1263. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1264. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1265. return cs;
  1266. }
  1267. void laRemoveCustomSignal(laCustomSignal* cs){
  1268. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1269. }
  1270. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1271. void la_SendSignalsFromEvent(laEvent* e){
  1272. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1273. if(!im){return;}
  1274. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1275. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1276. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1277. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1278. }
  1279. }
  1280. }
  1281. }
  1282. //MSG====================================================
  1283. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1284. if (wnd->win == hwnd) return 1;
  1285. else return 0;
  1286. };
  1287. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1288. if (p->SL){ int s=p->SL<0?0:p->SL;
  1289. if (p->TX != s) laRecalcPanel(p);
  1290. p->TX = s;
  1291. }
  1292. if (p->SR){ int s=p->SR<0?0:p->SR;
  1293. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1294. p->TW = CW - p->TX - s;
  1295. }
  1296. if (p->ST){ int s=p->ST<0?0:p->ST;
  1297. if (p->TY != s) laRecalcPanel(p);
  1298. p->TY = s;
  1299. }
  1300. if (p->SB){ int s=p->SB<0?0:p->SB;
  1301. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1302. p->TH = CH - p->TY - s;
  1303. }
  1304. }
  1305. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1306. laPanel *p = 0;
  1307. b->X = X;
  1308. b->Y = Y;
  1309. b->W = W;
  1310. b->H = H;
  1311. if (b->B1){
  1312. int SplitWidth;
  1313. if (b->Vertical){
  1314. SplitWidth = H * b->SplitRatio;
  1315. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1316. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1317. }else{
  1318. SplitWidth = W * b->SplitRatio;
  1319. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1320. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1321. }
  1322. }
  1323. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1324. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1325. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1326. }
  1327. if (p = b->CurrentPanel){
  1328. int TitleGap=b->Folded?0:LA_RH;
  1329. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1330. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1331. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1332. laRecalcPanel(p);
  1333. }
  1334. }
  1335. void la_UpdateUiPlacement(laWindow *w){
  1336. laLayout *l;
  1337. laPanel *p;
  1338. int CW = w->CW;
  1339. int CH = w->CH;
  1340. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1341. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1342. if(w->MaximizedUi && w->MaximizedUiPanel){
  1343. laRecalcPanel(w->MaximizedUiPanel);
  1344. }elif(w->MaximizedBlock){
  1345. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1346. }else{
  1347. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1348. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1349. }
  1350. }
  1351. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1352. if(p->IsMenuPanel){
  1353. p->TH=p->H=MenuHeight;
  1354. }
  1355. la_EnsurePanelSnapping(p, CW, CH);
  1356. laRecalcPanel(p);
  1357. }
  1358. }
  1359. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1360. laWindow *window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1361. if (!window) return;
  1362. #ifdef _WIN32
  1363. RECT rcc; GetClientRect(window->win, &rcc);
  1364. RECT rcw; GetWindowRect(window->win, &rcw);
  1365. window->CW = rcc.right - rcc.left;
  1366. window->CH = rcc.bottom - rcc.top;
  1367. window->W = rcw.right - rcw.left;
  1368. window->H = rcw.bottom - rcw.top;
  1369. window->X = rcw.left; window->Y = rcw.top;
  1370. #endif
  1371. #ifdef __linux__
  1372. XWindowAttributes attr;
  1373. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1374. window->CW = w; window->CH = h;
  1375. window->W = w; window->H = h;
  1376. window->X = x; window->Y = y;
  1377. if(MAIN.AutoSwitchColorSpace){
  1378. laScreen* s = laGetWindowScreen(window);
  1379. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1380. }
  1381. #endif
  1382. la_UpdateUiPlacement(window);
  1383. }
  1384. int la_OnWindowDestroy(SYSWINDOW wnd){
  1385. laListHandle *hlst = &MAIN.Windows;
  1386. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1387. if (!w) return 0;
  1388. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1389. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1390. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1391. laShutoff(1);
  1392. return 1;
  1393. }
  1394. laListHandle h={0};laLayout*l=0;
  1395. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1396. la_DestroyWindow(w);
  1397. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1398. #ifdef __linux__
  1399. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1400. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1401. #endif
  1402. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1403. }
  1404. return 0;
  1405. }
  1406. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1407. laListHandle *el = &wnd->EventList;
  1408. laEvent* last_e=el->pLast;
  1409. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1410. #ifdef __linux__
  1411. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1412. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1413. #endif
  1414. #ifdef _WIN32
  1415. e->SpecialKeyBit = ((GetKeyState(VK_SHIFT)&0x8000)?LA_KEY_SHIFT:0)|((GetKeyState(VK_CONTROL)&0x8000)?LA_KEY_CTRL:0)|((GetKeyState(VK_MENU)&0x8000)?LA_KEY_ALT:0);
  1416. #endif
  1417. }
  1418. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1419. laListHandle *wl = &MAIN.Windows;
  1420. laWindow* wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1421. if (!wnd){ memFree(e); return; }
  1422. laListHandle *el = &wnd->EventList;
  1423. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1424. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1425. e->window = wnd;
  1426. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1427. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1428. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1429. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1430. e->IsEraser=MAIN.PointerIsEraser;
  1431. e->GoodPressure=MAIN.IsPen;
  1432. lstAppendItem(el, (laListItem *)e);
  1433. laMappingRequestEval();
  1434. };
  1435. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1436. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1437. la_SaveEvent(hwnd, e, 1);
  1438. };
  1439. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1440. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1441. e->type = LA_INPUT; e->Input=Input;
  1442. la_SaveEvent(hwnd, e, 1);
  1443. }
  1444. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1445. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1446. e->type = LA_EMPTY;
  1447. la_SaveEvent(hwnd, e, 1);
  1448. }
  1449. void laSendOperatorTriggerEvent(){
  1450. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1451. MAIN.ReTriggerOperators = 0;
  1452. }
  1453. int la_TranslateSpecialKey(int keysym){
  1454. #ifdef __linux__
  1455. switch(keysym){
  1456. case XK_Return: return LA_KEY_ENTER;
  1457. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1458. case XK_Delete: return LA_KEY_DELETE;
  1459. case XK_Escape: return LA_KEY_ESCAPE;
  1460. case XK_Tab: return LA_KEY_TAB;
  1461. case XK_Left: return LA_KEY_ARRLEFT;
  1462. case XK_Right: return LA_KEY_ARRRIGHT;
  1463. case XK_Up: return LA_KEY_ARRUP;
  1464. case XK_Down: return LA_KEY_ARRDOWN;
  1465. case XK_Control_L: return LA_KEY_CTRL;
  1466. case XK_Control_R: return LA_KEY_CTRL;
  1467. case XK_Shift_L: return LA_KEY_SHIFT;
  1468. case XK_Shift_R: return LA_KEY_SHIFT;
  1469. case XK_Alt_L: return LA_KEY_ALT;
  1470. case XK_Alt_R: return LA_KEY_ALT;
  1471. default: return keysym;
  1472. }
  1473. #endif
  1474. #ifdef _WIN32
  1475. switch (keysym) {
  1476. case VK_RETURN: return LA_KEY_ENTER;
  1477. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1478. case VK_TAB: return LA_KEY_TAB;
  1479. case VK_LEFT: return LA_KEY_ARRLEFT;
  1480. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1481. case VK_UP: return LA_KEY_ARRUP;
  1482. case VK_DOWN: return LA_KEY_ARRDOWN;
  1483. case VK_CONTROL: return LA_KEY_CTRL;
  1484. case VK_SHIFT: return LA_KEY_SHIFT;
  1485. case VK_MENU: return LA_KEY_ALT;
  1486. case VK_OEM_1: return ';';
  1487. case VK_OEM_2: return '/';
  1488. case VK_OEM_3: return '`';
  1489. case VK_OEM_4: return '[';
  1490. case VK_OEM_5: return '\\';
  1491. case VK_OEM_6: return ']';
  1492. case VK_OEM_7: return '\'';
  1493. default: return keysym;
  1494. }
  1495. #endif
  1496. }
  1497. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1498. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1499. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1500. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1501. // la_SaveEvent(hwnd, e, 0);
  1502. //}
  1503. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1504. e->type = type; e->x = x; e->y = y;
  1505. la_SaveEvent(hwnd, e, 0);
  1506. MAIN.evLastX=x; MAIN.evLastY=y;
  1507. };
  1508. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1509. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1510. e->type = type;
  1511. la_SaveEvent(hwnd, e, 1);
  1512. };
  1513. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1514. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1515. e->type = LA_SIGNAL_EVENT;
  1516. e->key = signal;
  1517. la_SaveEvent(hwnd, e, 1);
  1518. };
  1519. void laRetriggerOperators(){
  1520. MAIN.ReTriggerOperators = 1;
  1521. }
  1522. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1523. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1524. }
  1525. void laSetCleanupCallback(laCleanupF Cleanup){
  1526. MAIN.Cleanup=Cleanup;
  1527. }
  1528. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1529. MAIN.InputProcess=InputProcess;
  1530. }
  1531. //====================================================================================================
  1532. void la_DestroyTheme(laTheme* t){
  1533. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1534. strSafeDestroy(&t->Name);
  1535. strSafeDestroy(&t->Author);
  1536. }
  1537. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1538. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1539. strSafeSet(&t->Name, Name);
  1540. strSafeSet(&t->Author, AuthorName);
  1541. lstAppendItem(&MAIN.Themes, t);
  1542. MAIN.CurrentTheme = t;
  1543. return t;
  1544. }
  1545. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1546. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1547. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1548. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1549. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1550. strSafeSet(&bt->Name, Name);
  1551. bt->NormalY=NormalY;
  1552. bt->ActiveY=ActiveY;
  1553. bt->BorderY=BorderY;
  1554. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1555. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1556. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1557. bt->BackRef = BackRef;
  1558. lstAppendItem(&t->BoxedThemes, bt);
  1559. return bt;
  1560. }
  1561. laTheme *laGetTheme(const char *ThemeName){
  1562. laTheme *t = MAIN.Themes.pFirst;
  1563. for (t; t; t = t->Item.pNext){
  1564. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1565. }
  1566. return 0;
  1567. }
  1568. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1569. laTheme *t = MAIN.Themes.pFirst;
  1570. for (t; t; t = t->Item.pNext){
  1571. laBoxedTheme *bt;
  1572. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1573. bt = t->BoxedThemes.pFirst;
  1574. for (bt; bt; bt = bt->Item.pNext){
  1575. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1576. }
  1577. }
  1578. return 0;
  1579. }
  1580. real* laThemeColor(laBoxedTheme* bt, int which){
  1581. switch(which){
  1582. default:
  1583. case LA_BT_NORMAL: return bt->Normal;
  1584. case LA_UI_EDITING:
  1585. case LA_BT_ACTIVE: return bt->Active;
  1586. case LA_BT_BORDER: return bt->Border;
  1587. case LA_BT_TEXT: return bt->Text; break;
  1588. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1589. case LA_BT_DISABLED: return bt->Inactive; break;
  1590. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1591. }
  1592. return bt->Normal;
  1593. }
  1594. real* laAccentColor(int which){
  1595. switch(which){
  1596. default:
  1597. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1598. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1599. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1600. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1601. case LA_BT_FACE:
  1602. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1603. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1604. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1605. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1606. }
  1607. return MAIN.CurrentTheme->SelectionColor;
  1608. }
  1609. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1610. real hcy[3];
  1611. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1612. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1613. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1614. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1615. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1616. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1617. int *tm=&bt->LM,*tp=&bt->LP;
  1618. for(int i=0;i<4;i++){
  1619. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1620. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1621. }
  1622. }
  1623. void la_RefreshThemeColorSelf(laTheme* th){
  1624. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1625. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1626. real hcy[3], usehcy[3];
  1627. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1628. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1629. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1630. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1631. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1632. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1633. }
  1634. void la_RefreshThemeColor(laTheme* th){
  1635. real hcy[3], usehcy[3], normalhcy[3];
  1636. tnsRGB2HCY(th->Color,hcy);
  1637. la_RefreshThemeColorSelf(th);
  1638. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1639. la_RefreshBoxedThemeColor(bt);
  1640. (*bt->BackRef) = bt;
  1641. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1642. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1643. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1644. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1645. }
  1646. }
  1647. //I FUCKING HATE THIS STUPID FUNCTION
  1648. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1649. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1650. laUiListDrawItem *last = uild->Items.pFirst;
  1651. int LimW=_R-_L;
  1652. int SL, SR, SU, SB;
  1653. int Target__B = Target->B;
  1654. int Target__R = Target->R;
  1655. uildi->Target = Target;
  1656. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1657. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1658. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1659. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1660. uildi->L = last ? Target->L - last->XP : Target->L;
  1661. uildi->R = last ? Target__R - last->XP : Target__R;
  1662. uildi->U = last ? Target->U - last->YP : Target->U;
  1663. uildi->B = last ? Target__B - last->YP : Target__B;
  1664. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1665. uildi->L -= GlobalX;
  1666. uildi->R -= GlobalX;
  1667. uildi->U -= GlobalY;
  1668. uildi->B -= GlobalY;
  1669. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1670. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1671. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1672. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1673. uildi->DifX = SL - uildi->L;
  1674. uildi->DifY = SU - uildi->U;
  1675. uildi->L = SL;
  1676. uildi->R = SR+uildi->DifX;
  1677. uildi->U = SU;
  1678. uildi->B = SB;//+uildi->DifY;
  1679. if(uildi->R>_R){ uildi->R=_R; }
  1680. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1681. //printf("py %f %d lb %d b %d limh %d sb%d\n",Target->PanY,uildi->U,last?last->B:0,uildi->B,LimH,SB);
  1682. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1683. memFree(uildi);
  1684. return 0;
  1685. }
  1686. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  1687. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  1688. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  1689. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  1690. Target->U + Target->PanY + uildi->DifY+1,
  1691. -100, 100);
  1692. lstPushItem(&uild->Items, uildi);
  1693. return 1;
  1694. }
  1695. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1696. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1697. laUiListDrawItem *last = uild->Items.pFirst;
  1698. int SL, SR, SU, SB;
  1699. if (B - U > LimH) B = U + LimH;
  1700. uildi->XP = last ? last->XP + PanX : PanX;
  1701. uildi->YP = last ? last->YP + PanY : PanY;
  1702. uildi->L = last ? L - last->XP : L;
  1703. uildi->R = last ? R - last->XP : R;
  1704. uildi->U = last ? U - last->YP : U;
  1705. uildi->B = last ? B - last->YP : B;
  1706. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1707. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1708. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1709. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1710. uildi->DifX = SL - uildi->L;
  1711. uildi->DifY = SU - uildi->U;
  1712. uildi->L = SL;
  1713. uildi->R = SR;
  1714. uildi->U = SU;
  1715. uildi->B = SB;
  1716. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1717. tnsOrtho(L + PanX + uildi->DifX,
  1718. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  1719. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  1720. U + PanY + uildi->DifY,
  1721. -100, 100);
  1722. lstPushItem(&uild->Items, uildi);
  1723. }
  1724. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  1725. int* savel, int* saver, int* saveu, int* saveb){
  1726. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  1727. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  1728. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  1729. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  1730. real x,y,w,h;
  1731. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  1732. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  1733. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  1734. }
  1735. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  1736. laUiListDrawItem *uildi = uild->Items.pFirst;
  1737. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  1738. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  1739. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  1740. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  1741. Target->U + Target->PanY + uildi->DifY -1,
  1742. -100, 100);
  1743. }
  1744. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  1745. laUiListDrawItem *uildi = lstPopItem(uild);
  1746. laUiList *Target;
  1747. memFree(uildi);
  1748. uildi = uild->Items.pFirst;
  1749. if (!uildi || !uildi->Target){
  1750. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  1751. return;
  1752. }
  1753. Target = uildi->Target;
  1754. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  1755. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  1756. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  1757. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  1758. Target->U + Target->PanY + uildi->DifY -1,
  1759. -100, 100);
  1760. }
  1761. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  1762. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1763. uildi->L = L;
  1764. uildi->R = R;
  1765. uildi->U = U;
  1766. uildi->B = B;
  1767. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1768. tnsOrtho(L, R, B, U, -100, 100);
  1769. lstPushItem(&uild->Items, uildi);
  1770. }
  1771. void la_ClearUiListMatrix(laUiListDraw *uild){
  1772. laUiListDrawItem *uildi;
  1773. while (uildi = lstPopItem(uild)){
  1774. memFree(uildi);
  1775. }
  1776. }
  1777. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  1778. int la_DrawUiListRecursive(laUiListDraw *uild, laUiList *uil, int L, int R, int U, int B, int LimH, int ConditionStackLevel, int GlobalX, int GlobalY, int RegisterNodes);
  1779. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  1780. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  1781. int la_TestUiListMinumWidth(laUiList *uil);
  1782. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  1783. if (ui){
  1784. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  1785. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  1786. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  1787. p->X = p->TX; p->Y = p->TY;
  1788. p->W = p->TW;
  1789. }
  1790. }
  1791. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  1792. int cw = MAIN.CurrentWindow->CW;
  1793. int ch = MAIN.CurrentWindow->CH;
  1794. int PH = p->TH;
  1795. laBoxedTheme*bt = *p->BT;
  1796. int uih=uil->B + bt->BM;
  1797. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  1798. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  1799. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  1800. else p->TH = PH;
  1801. p->H = p->TH;
  1802. if(p->BoundUi){
  1803. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  1804. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  1805. if (p->X < 0) p->X = 0;
  1806. if (p->Y < 0) p->Y = 0;
  1807. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  1808. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  1809. }else{
  1810. if (p->Y < 0) p->Y = 0;
  1811. if ((!p->Block)&&(!p->IsMenuPanel)){
  1812. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  1813. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  1814. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  1815. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  1816. }
  1817. }
  1818. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  1819. if(p->W<LA_RH*4) p->W=LA_RH*4;
  1820. if(p->H<LA_RH*2) p->H=LA_RH*2;
  1821. }
  1822. if (p->ST) p->TY = p->ST;
  1823. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  1824. if (p->SB) p->TH = ch - p->TY - p->SB;
  1825. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  1826. p->TX = p->X; p->TY = p->Y;
  1827. p->TW = p->W; p->TH = p->H;
  1828. }
  1829. void laPlacePanelForCreation(laPanel *p){
  1830. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  1831. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  1832. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  1833. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  1834. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  1835. p->TX=p->X; p->TY=p->Y;
  1836. }
  1837. }
  1838. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  1839. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1840. tnsViewportWithScissor(0, 0, p->W, p->H);
  1841. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  1842. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1843. }
  1844. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  1845. tnsDrawToScreen();
  1846. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  1847. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1848. }
  1849. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  1850. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  1851. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  1852. }
  1853. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  1854. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  1855. tnsClearAll();
  1856. }
  1857. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  1858. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  1859. real Color[] = {1, 1, 1, 1};
  1860. real L, W, U, H;
  1861. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  1862. if(MAIN.EnableColorManagement){
  1863. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  1864. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  1865. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  1866. }else{
  1867. tnsUniformOutputColorSpace(T->immShader,0);
  1868. tnsUniformShowColorOverflowStripes(T->immShader,0);
  1869. tnsUniformColorComposing(T->immShader,0,0,0);
  1870. }
  1871. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99))){
  1872. tnsUseNoTexture();
  1873. if (!p->IsMenuPanel){
  1874. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  1875. }
  1876. tnsFlush();
  1877. }
  1878. switch (p->AnimationMode){
  1879. case 0:
  1880. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  1881. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  1882. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  1883. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  1884. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  1885. tnsPackAs(GL_TRIANGLES);
  1886. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  1887. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  1888. }
  1889. break;
  1890. case LA_PANEL_ANIMATION_DROP_DOWN:
  1891. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1892. tnsDraw2DTextureArg(
  1893. p->OffScr->pColor[0],
  1894. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  1895. Color,
  1896. 0, 0, 1 - p->AnimationRatio, 0);
  1897. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1898. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  1899. break;
  1900. case LA_PANEL_ANIMATION_EXPAND:
  1901. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1902. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1903. W = tnsLinearItp(0, p->W, 0.4);
  1904. H = tnsLinearItp(0, p->H, 0.4);
  1905. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1906. tnsDraw2DTextureArg(
  1907. p->OffScr->pColor[0],
  1908. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1909. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1910. Color,
  1911. 0, 0, 0, 0);
  1912. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1913. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  1914. break;
  1915. case LA_PANEL_ANIMATION_DISSOVE:
  1916. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  1917. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  1918. W = tnsLinearItp(0, p->W, 1.4);
  1919. H = tnsLinearItp(0, p->H, 1.4);
  1920. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  1921. if (p->OffScr) tnsDraw2DTextureArg(
  1922. p->OffScr->pColor[0],
  1923. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1924. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1925. Color,
  1926. 0, 0, 0, 0);
  1927. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1928. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1929. break;
  1930. case LA_PANEL_ANIMATION_COLLAPSE:
  1931. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1932. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1933. W = tnsLinearItp(0, p->W, 0.4);
  1934. H = tnsLinearItp(0, p->H, 0.4);
  1935. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1936. if (p->OffScr) tnsDraw2DTextureArg(
  1937. p->OffScr->pColor[0],
  1938. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1939. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1940. Color,
  1941. 0, 0, 0, 0);
  1942. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1943. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1944. break;
  1945. case LA_PANEL_ANIMATION_MINIMIZE:
  1946. L = tnsLinearItp(0, p->X, 0.3);
  1947. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  1948. W = tnsLinearItp(0, p->W, 0.4);
  1949. H = tnsLinearItp(0, p->H, 0.4);
  1950. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1951. tnsDraw2DTextureArg(
  1952. p->OffScr->pColor[0],
  1953. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1954. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1955. Color,
  1956. 0, 0, 0, 0);
  1957. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1958. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1959. break;
  1960. }
  1961. tnsFlush();
  1962. tnsUniformOutputColorSpace(T->immShader,0);
  1963. tnsUniformShowColorOverflowStripes(T->immShader,0);
  1964. tnsUniformColorComposing(T->immShader,0,0,0);
  1965. }
  1966. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  1967. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  1968. else{
  1969. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:GL_RGBA8;
  1970. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  1971. }
  1972. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1973. }
  1974. void la_PanelRefreshDetachedProp(laPanel *panel){
  1975. laProp *p;
  1976. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  1977. la_StepPropPack(&p->DetachedPP);
  1978. la_UsePropPack(&p->DetachedPP, 0);
  1979. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  1980. // laUseDataBlock(
  1981. // p->DetachedPP.LastPs->UseInstance,
  1982. // p->DetachedPP.LastPs->p,
  1983. // MAIN.PropMatcherContextP->FrameDistinguish,
  1984. // MAIN.PropMatcherContextP,
  1985. // la_PropPanelUserRemover, 0);
  1986. //}
  1987. }
  1988. }
  1989. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  1990. real* color=laThemeColor(bt,LA_BT_BORDER);
  1991. tnsColor4d(0,0,0,Alpha);
  1992. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  1993. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  1994. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  1995. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  1996. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  1997. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  1998. tnsPackAs(GL_TRIANGLE_STRIP);
  1999. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2000. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2001. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2002. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2003. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2004. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2005. }
  2006. int la_AnimateUiListRecursive(laUiList *uil);
  2007. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2008. int DrawState_ = 0;
  2009. laUiListDraw uild = {0};
  2010. if (p->Show){
  2011. la_SetPropMathcerContext(p);
  2012. MAIN.CurrentPanel = p;
  2013. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2014. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2015. //}
  2016. if (p->Refresh & LA_TAG_RECALC){
  2017. laRecalcPanelImmediate(p);
  2018. }
  2019. if (!p->MenuRefer){
  2020. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2021. if (p->Refresh || !p->OffScr){
  2022. la_PanelDrawToOffsceen(p, &p->UI);
  2023. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2024. la_PanelBackgroundInit(p, bt);
  2025. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2026. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2027. tnsFlush();
  2028. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2029. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2030. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2031. DrawState_++;
  2032. }
  2033. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2034. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2035. if(p->UI.PanY<0){p->UI.PanY=0;}
  2036. DrawState_++;
  2037. }
  2038. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2039. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2040. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2041. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2042. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2043. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2044. if(p!=w->MaximizedUiPanel){
  2045. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2046. }else{
  2047. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2048. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2049. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2050. tnsFlush();
  2051. }
  2052. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2053. }
  2054. }else{
  2055. if (p->Refresh || !p->OffScr){
  2056. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2057. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2058. la_PanelBackgroundInit(p, bt);
  2059. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2060. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2061. tnsFlush();
  2062. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2063. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2064. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2065. DrawState_++;
  2066. }
  2067. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2068. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2069. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2070. DrawState_++;
  2071. }
  2072. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2073. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2074. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2075. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2076. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2077. }
  2078. }
  2079. tnsDrawToScreen();
  2080. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2081. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2082. la_PanelDrawToWindow(p, w);
  2083. }elif (p->AnimationMode){
  2084. la_PanelDrawToWindow(p, w);
  2085. }
  2086. }
  2087. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2088. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2089. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2090. laPanel *pi, *PrevPI;
  2091. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2092. PrevPI = pi->Item.pPrev;
  2093. if (pi->AnimationMode && pi->LaterDestroy){
  2094. lstRemoveItem(&p->SubPanels, pi);
  2095. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2096. continue;
  2097. }
  2098. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2099. la_AttachedPanelDefDraw(w,pi,bt);
  2100. }
  2101. }
  2102. }
  2103. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2104. real PanelSquare[] = {
  2105. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2106. b->X + 2, CH - (b->Y + b->H - 4),
  2107. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2108. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2109. real Center[] = {
  2110. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2111. real DraggingPlot[] = {
  2112. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2113. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2114. PanelSquare[0],
  2115. PanelSquare[1],
  2116. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2117. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2118. PanelSquare[2],
  2119. PanelSquare[3],
  2120. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2121. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2122. PanelSquare[4],
  2123. PanelSquare[5],
  2124. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2125. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2126. PanelSquare[6],
  2127. PanelSquare[7],
  2128. };
  2129. real Square[] = {
  2130. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2131. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2132. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2133. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2134. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2135. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2136. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2137. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2138. };
  2139. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2140. LA_COLOR3(BorderColor4dV), 0,
  2141. LA_COLOR3(BorderColor4dV), 0.8,
  2142. LA_COLOR3(BorderColor4dV), 0,
  2143. LA_COLOR3(BorderColor4dV), 0.8,
  2144. LA_COLOR3(BorderColor4dV), 0,
  2145. LA_COLOR3(BorderColor4dV), 0.8,
  2146. LA_COLOR3(BorderColor4dV), 0,
  2147. };
  2148. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2149. LA_COLOR3(FillColor4dv), 0,
  2150. LA_COLOR3(FillColor4dv), 0.8,
  2151. LA_COLOR3(FillColor4dv), 0,
  2152. LA_COLOR3(FillColor4dv), 0.8,
  2153. LA_COLOR3(FillColor4dv), 0,
  2154. LA_COLOR3(FillColor4dv), 0.8,
  2155. LA_COLOR3(FillColor4dv), 0,
  2156. };
  2157. tnsUseNoTexture();
  2158. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2159. int Index[4];
  2160. tnsVertexArray2d(DraggingPlot, 8);
  2161. tnsColorArray4d(FillColor, 8);
  2162. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2163. case 0:
  2164. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2165. break;
  2166. case LA_BLOCK_DROP_LOCATION_L:
  2167. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2168. break;
  2169. case LA_BLOCK_DROP_LOCATION_R:
  2170. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2171. break;
  2172. case LA_BLOCK_DROP_LOCATION_U:
  2173. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2174. break;
  2175. case LA_BLOCK_DROP_LOCATION_B:
  2176. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2177. break;
  2178. }
  2179. //glDisable(GL_CULL_FACE);
  2180. tnsIndexArray(Index, 4);
  2181. tnsPackAs(GL_TRIANGLE_FAN);
  2182. //tnsFlush();
  2183. }
  2184. tnsVertexArray2d(DraggingPlot, 8);
  2185. tnsColorArray4d(PlotColor, 8);
  2186. tnsPackAs(GL_LINES);
  2187. tnsVertexArray2d(Square, 4);
  2188. tnsColor4dv(BorderColor4dV);
  2189. tnsPackAs(GL_LINE_LOOP);
  2190. glLineWidth(LA_SEAM_W);
  2191. tnsFlush();
  2192. glLineWidth(1);
  2193. }
  2194. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2195. laBoxedTheme *bt = _LA_THEME_TAB;
  2196. laPanel *p;
  2197. real v[] = {
  2198. b->X, CH - b->Y,
  2199. b->X + LA_SEAM_W, CH - b->Y ,
  2200. b->X, CH - (b->Y + b->H),
  2201. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2202. b->X + b->W, CH - (b->Y + b->H),
  2203. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2204. b->X + b->W, CH - b->Y,
  2205. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2206. real tv[8];
  2207. real ratio = 1.0001f;
  2208. int tw = 0;
  2209. int L = LA_RH+LA_SEAM_W;
  2210. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2211. if(MAIN.EnableColorManagement){
  2212. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2213. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2214. }else{
  2215. tnsUniformOutputColorSpace(T->immShader,0);
  2216. tnsUniformColorComposing(T->immShader,0,0,0);
  2217. }
  2218. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2219. tw += p->TitleWidth + LA_SEAM_W*2;
  2220. }
  2221. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2222. tnsUseNoTexture();
  2223. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2224. tnsVertexArray2d(v, 8);
  2225. tnsPackAs(GL_TRIANGLE_STRIP);
  2226. int TitleGap=b->Folded?0:LA_RH;
  2227. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2228. b->X + b->W, (CH - b->Y),
  2229. b->X + b->W, (CH - b->Y - TitleGap),
  2230. b->X, (CH - b->Y - TitleGap));
  2231. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2232. tnsVertexArray2d(tv, 4);
  2233. tnsPackAs(GL_TRIANGLE_FAN);
  2234. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2235. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2236. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2237. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2238. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2239. tnsVertexArray2d(tv, 4);
  2240. tnsPackAs(GL_TRIANGLE_FAN);
  2241. if(b->Folded){
  2242. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2243. tnsDrawStringAuto("⯆",Color, b->X+LA_SEAM_W,b->X+LA_SEAM_W+LA_RH, CH-b->Y, LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  2244. tnsDrawStringAuto("⮼",Color, b->X+LA_SEAM_W+LA_RH,b->X+LA_SEAM_W+LA_2RH, CH-b->Y, LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  2245. tnsFlush(); return;
  2246. }
  2247. int LT=0,RT=0;
  2248. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2249. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2250. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2251. b->X + L+RT * ratio, (CH - b->Y),
  2252. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2253. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2254. if (p == b->CurrentPanel){
  2255. tnsUseNoTexture();
  2256. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2257. tnsVertexArray2d(tv, 4);
  2258. tnsPackAs(GL_TRIANGLE_FAN);
  2259. tnsDrawStringAuto(transLate(p->Title->Ptr), laThemeColor(bt,LA_BT_TEXT_ACTIVE), b->X + L +LT* ratio + LA_SEAM_W, b->X + L +RT* ratio, CH - b->Y, LA_TEXT_REVERT_Y);
  2260. }else{
  2261. tnsDrawStringAuto(transLate(p->Title->Ptr), laThemeColor(bt,LA_BT_TEXT), b->X + L +LT* ratio + LA_SEAM_W, b->X + L +RT* ratio, CH - b->Y, LA_TEXT_REVERT_Y);
  2262. }
  2263. LT =RT;
  2264. }
  2265. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2266. tnsFlush();
  2267. tnsUniformOutputColorSpace(T->immShader,0);
  2268. tnsUniformColorComposing(T->immShader,0,0,0);
  2269. }
  2270. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2271. laBoxedTheme *bt = _LA_THEME_PANEL;
  2272. real tv[8];
  2273. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2274. if(MAIN.EnableColorManagement){
  2275. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2276. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2277. }else{
  2278. tnsUniformOutputColorSpace(T->immShader,0);
  2279. tnsUniformColorComposing(T->immShader,0,0,0);
  2280. }
  2281. tnsUseNoTexture();
  2282. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2283. b->X + b->W, (CH - b->Y),
  2284. b->X + b->W, (CH - b->Y-b->H),
  2285. b->X, (CH - b->Y-b->H));
  2286. tnsVertexArray2d(tv, 4);
  2287. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2288. tnsPackAs(GL_TRIANGLE_FAN);
  2289. tnsDrawStringAuto(transLate("Dock some panels here."), laThemeColor(bt,LA_BT_TEXT), b->X+LA_SEAM_W,b->X+b->W-LA_SEAM_W, CH-b->Y-b->H/2+LA_RH2,
  2290. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2291. tnsFlush();
  2292. tnsUniformOutputColorSpace(T->immShader,0);
  2293. tnsUniformColorComposing(T->immShader,0,0,0);
  2294. }
  2295. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2296. if (b->B1){
  2297. la_BlockDefDrawRecursive(w, bt, b->B1);
  2298. la_BlockDefDrawRecursive(w, bt, b->B2);
  2299. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2300. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2301. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2302. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2303. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2304. la_BlockDefDrawSelf(b, w->CH);
  2305. }else{
  2306. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2307. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2308. la_BlockDefDrawSelfEmpty(b, w->CH);
  2309. }
  2310. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2311. tnsUseNoTexture();
  2312. int at; real tv[8];
  2313. if (b->Vertical){
  2314. at = b->H * b->SplitRatio + b->Y;
  2315. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2316. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2317. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2318. b->X, (w->CH - at - LA_SEAM_W));
  2319. }else{
  2320. at = b->X + b->W * b->SplitRatio;
  2321. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2322. at- LA_SEAM_W, (w->CH - b->Y),
  2323. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2324. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2325. }
  2326. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2327. tnsVertexArray2d(tv, 4);
  2328. tnsPackAs(GL_TRIANGLE_FAN);
  2329. }
  2330. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2331. tnsFlush();
  2332. }
  2333. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2334. if (b->B1){
  2335. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2336. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2337. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2338. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2339. }
  2340. tnsFlush();
  2341. }
  2342. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2343. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2344. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2345. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2346. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2347. if(p->OffScr){
  2348. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2349. }
  2350. }
  2351. }
  2352. void la_ClearUnusedFramebuffers(laWindow* w){
  2353. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2354. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2355. }
  2356. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2357. if(p->Show || p->AnimationMode) continue;
  2358. if(p->OffScr){
  2359. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2360. }
  2361. }
  2362. }
  2363. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2364. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2365. laPanel *p, *NextP;
  2366. laLayout *l = w->CurrentLayout;
  2367. la_ClearUnusedFramebuffers(w);
  2368. tnsDrawToScreen();
  2369. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2370. glClearColor(0.2, 0.2, 0.3, 1.0);
  2371. tnsClearAll();
  2372. tnsUseNoTexture();
  2373. if (l->Draw) l->Draw(w, l);
  2374. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2375. glEnable(GL_BLEND);
  2376. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2377. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2378. laUiItem* ui;
  2379. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2380. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2381. la_SetPropMathcerContext(p);
  2382. if(p->Refresh){
  2383. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2384. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2385. if(MAIN.EnableColorManagement){
  2386. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2387. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2388. }else{
  2389. tnsUniformOutputColorSpace(T->immShader,0);
  2390. tnsUniformColorComposing(T->immShader,0,0,0);
  2391. }
  2392. if(p->Refresh&LA_TAG_RECALC){
  2393. laRecalcPanelImmediate(p);
  2394. }
  2395. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2396. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2397. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2398. }
  2399. tnsDrawToScreen();
  2400. tnsResetViewMatrix();
  2401. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2402. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2403. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2404. tnsFlush();
  2405. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2406. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2407. tnsFlush();
  2408. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2409. }
  2410. }
  2411. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2412. la_AttachedPanelDefDraw(w,p,*p->BT);
  2413. }else{
  2414. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2415. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2416. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2417. }
  2418. for (p = w->Panels.pLast; p; p = NextP){
  2419. NextP = p->Item.pPrev;
  2420. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2421. if (p->AnimationMode && p->LaterDestroy){
  2422. lstRemoveItem(&w->Panels, p);
  2423. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2424. continue;
  2425. }
  2426. la_PanelDefDraw(w, p, *p->BT);
  2427. }
  2428. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2429. la_AttachedPanelDefDraw(w,p,*p->BT);
  2430. }
  2431. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2432. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2433. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2434. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2435. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2436. tnsFlush();
  2437. }
  2438. for (p = w->FadingPanels.pLast; p; p = NextP){
  2439. NextP = p->Item.pPrev;
  2440. if (!p->AnimationMode){
  2441. lstRemoveItem(&w->FadingPanels, p);
  2442. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2443. laDeferredDestroyPanel(p, 0);
  2444. }else
  2445. la_PanelDrawToWindow(p, w);
  2446. }
  2447. }
  2448. int laStartWindow(laWindow *w){
  2449. #ifdef __linux__
  2450. XMapWindow(MAIN.dpy,w->win);
  2451. tnsContextMakeWindowCurrent(w);
  2452. #endif
  2453. #ifdef _WIN32
  2454. ShowWindow(w->win, SW_SHOWNORMAL);
  2455. #endif
  2456. MAIN.CurrentWindow = w;
  2457. if(!w->CurrentLayout){
  2458. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2459. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2460. }
  2461. laRedrawCurrentWindow();
  2462. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2463. w->Shown = 1;
  2464. }
  2465. void la_AssignWindowPP(laWindow* w){
  2466. w->PP.EndInstance = w;
  2467. w->PP.LastPs = &w->FakePS;
  2468. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2469. w->PP.LastPs->UseInstance = w;
  2470. w->PP.LastPs->Type = U'.';
  2471. }
  2472. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2473. laWindow *n = memAcquire(sizeof(laWindow));
  2474. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2475. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2476. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2477. lstAppendItem(&MAIN.Windows, n);
  2478. MAIN.CurrentWindow = n;
  2479. la_AssignWindowPP(n);
  2480. laui_DefaultMenuBar(n);
  2481. return n;
  2482. }
  2483. void laSetWindowCursor(int id){
  2484. MAIN.CurrentCursor = id;
  2485. #ifdef __linux__
  2486. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2487. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2488. #endif
  2489. #ifdef _WIN32
  2490. SetCursor(la_ConvertCursorID(id));
  2491. #endif
  2492. };
  2493. void la_AssignBlockPP(laBlock* b){
  2494. b->PP.EndInstance = b;
  2495. b->PP.LastPs = &b->FakePS;
  2496. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2497. b->PP.LastPs->UseInstance = b;
  2498. b->PP.LastPs->Type = U'.';
  2499. }
  2500. void laDestroyLayout(laWindow *w, laLayout* l){
  2501. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2502. laDestroyBlocksRecursive(l->FirstBlock);
  2503. strSafeDestroy(&l->ID);
  2504. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2505. lstRemoveItem(&w->Layouts,l); memFree(l);
  2506. }
  2507. laLayout *laDesignLayout(laWindow *w, char *Title){
  2508. laLayout *l = memAcquire(sizeof(laLayout));
  2509. l->FirstBlock = memAcquire(sizeof(laBlock));
  2510. la_AssignBlockPP(l->FirstBlock);
  2511. lstAppendItem(&w->Layouts, l);
  2512. strSafeSet(&l->ID, Title);
  2513. memAssignRef(w, &w->CurrentLayout, l);
  2514. laRenameWindow(w, Title);
  2515. return l;
  2516. }
  2517. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2518. void laUnfoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=0; b->OnButton=0; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2519. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2520. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2521. laNotifyUsers("la.windows.maximized_block"); }
  2522. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2523. laNotifyUsers("la.windows.maximized_block"); }
  2524. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2525. laRestoreCanvasUI();
  2526. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2527. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2528. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2529. UiParentPanel->Show=0;
  2530. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2531. }
  2532. void laRestoreCanvasUI(){
  2533. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2534. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2535. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2536. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2537. }
  2538. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2539. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2540. }
  2541. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2542. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2543. laPanel *p;
  2544. b->SplitRatio = Percentage;
  2545. b->Vertical = 0;
  2546. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2547. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2548. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2549. p->Block = b->B1;
  2550. }
  2551. b->B1->Panels.pFirst = b->Panels.pFirst;
  2552. b->B1->Panels.pLast = b->Panels.pLast;
  2553. b->B1->CurrentPanel = b->CurrentPanel;
  2554. b->B1->parent = b->B2->parent=b;
  2555. b->Panels.pFirst = 0;
  2556. b->Panels.pLast = 0;
  2557. b->CurrentPanel = 0;
  2558. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2559. }
  2560. void laSplitBlockVertical(laBlock *b, real Percentage){
  2561. laPanel *p;
  2562. b->SplitRatio = Percentage;
  2563. b->Vertical = 1;
  2564. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2565. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2566. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2567. p->Block = b->B1;
  2568. }
  2569. b->B1->Panels.pFirst = b->Panels.pFirst;
  2570. b->B1->Panels.pLast = b->Panels.pLast;
  2571. b->B1->CurrentPanel = b->CurrentPanel;
  2572. b->B1->parent = b->B2->parent=b;
  2573. b->Panels.pFirst = 0;
  2574. b->Panels.pLast = 0;
  2575. b->CurrentPanel = 0;
  2576. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2577. }
  2578. void laCombineChildBlocks(laBlock *b){
  2579. laPanel *p; if(!b) return;
  2580. if (!b->B1->B1 && !b->B2->B1){
  2581. lstCombineLists(&b->Panels, &b->B1->Panels);
  2582. lstCombineLists(&b->Panels, &b->B2->Panels);
  2583. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2584. p->Block = b;
  2585. }
  2586. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2587. memFree(b->B1);
  2588. memFree(b->B2);
  2589. b->B1 = 0;
  2590. b->B2 = 0;
  2591. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2592. }elif(!b->B1->B1){
  2593. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2594. b->Vertical = b->B2->Vertical;
  2595. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2596. p->Block = b1;
  2597. }
  2598. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2599. memFree(b->B1); memFree(b->B2);
  2600. b->B1 = b1; b->B2 = b2;
  2601. b1->parent = b; b2->parent = b;
  2602. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2603. }elif(!b->B2->B1){
  2604. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2605. b->Vertical = b->B1->Vertical;
  2606. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2607. p->Block = b1;
  2608. }
  2609. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2610. memFree(b->B1); memFree(b->B2);
  2611. b->B1 = b1; b->B2 = b2;
  2612. b1->parent = b; b2->parent = b;
  2613. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2614. }
  2615. }
  2616. laBlock *laBlock1(laBlock *b){
  2617. return b->B1;
  2618. }
  2619. laBlock *laBlock2(laBlock *b){
  2620. return b->B2;
  2621. }
  2622. laBlock *laSwapSubBlocks(laBlock *b){
  2623. laBlock *tB;
  2624. tB = b->B2;
  2625. b->B2 = b->B1;
  2626. b->B1 = tB;
  2627. b->SplitRatio = 1 - b->SplitRatio;
  2628. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2629. }
  2630. void laDestroyBlocksRecursive(laBlock *Root){
  2631. laPanel *p;
  2632. if (Root->B1){
  2633. laDestroyBlocksRecursive(Root->B1);
  2634. laDestroyBlocksRecursive(Root->B2);
  2635. }else{
  2636. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2637. }
  2638. memFree(Root);
  2639. }
  2640. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2641. if(!b->CurrentPanel ) return 0;
  2642. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2643. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2644. lstRemoveItem(&b->Panels, p);
  2645. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  2646. if(!p->TitleBar.UiItems.pFirst){
  2647. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2648. }
  2649. p->Mode = LA_PANEL_FLOATING_TOP;
  2650. p->TY-=LA_RH; p->TH+=LA_RH;
  2651. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  2652. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  2653. p->Block = 0;
  2654. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  2655. laRecalcPanel(p);
  2656. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2657. p->BT = &_LA_THEME_FLOATING_PANEL;
  2658. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2659. laNotifyUsers("la.windows.panels");
  2660. return b->CurrentPanel;
  2661. }
  2662. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2663. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2664. lstRemoveItem(&from->Panels, p);
  2665. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2666. p->Mode = LA_PANEL_NORMAL;
  2667. p->Block=b;
  2668. b->CurrentPanel = p;
  2669. lstPushItem(&b->Panels, p);
  2670. laRecalcPanel(p);
  2671. p->BT = &_LA_THEME_PANEL;
  2672. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2673. tnsFlush();
  2674. laNotifyUsers("la.windows.panels");
  2675. }
  2676. void laPopPanel(laPanel *p){
  2677. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2678. lstRemoveItem(&p->Parent->SubPanels, p);
  2679. lstPushItem(&p->Parent->SubPanels, p);
  2680. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2681. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2682. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2683. laNotifyUsers("la.windows.panels");
  2684. }
  2685. }
  2686. void la_EnsurePanelExtras(laPanel *p){
  2687. laUiTemplate* uit=p->PanelTemplate;
  2688. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  2689. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  2690. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  2691. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  2692. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  2693. p->PropLinkFakeProp->Base.Offset = 0;
  2694. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  2695. p->PropLinkPP.EndInstance = p;
  2696. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  2697. p->PropLinkPP.LastPs->Type = U'.';
  2698. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  2699. }
  2700. laPanel* la_GivePanelNode(){
  2701. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  2702. return memAcquire(sizeof(laPanel));
  2703. }
  2704. void la_ReturnPanelNode(laPanel* p){
  2705. memset(p,0,sizeof(laPanel));
  2706. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  2707. lstAppendItem(&MAIN.WastedPanels, p);
  2708. }
  2709. laPanel *la_NewPanel(laUiTemplate* uit, int X, int Y, int W, int H, int MaxW, int MaxH, int MinW, int MinH, int SnapL, int SnapR, int SnapT, int SnapB){
  2710. laPanel *p = la_GivePanelNode();
  2711. int CW = MAIN.CurrentWindow->CW;
  2712. int CH = MAIN.CurrentWindow->CH;
  2713. p->PanelTemplate = uit;
  2714. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  2715. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  2716. if (!MaxW) MaxW = 10000;
  2717. if (!MaxH) MaxH = 10000;
  2718. if (W > MaxW) W = MaxW;
  2719. if (H > MaxH) H = MaxH;
  2720. if (W < MinW) W = MinW;
  2721. if (H < MinH) H = MinH;
  2722. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  2723. p->X = p->TX = (X < 0 ? 0 : X);
  2724. p->Y = p->TY = (Y < 0 ? 0 : Y);
  2725. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  2726. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  2727. p->MaxW = MaxW; p->MaxH = MaxH;
  2728. p->MinW = MinW; p->MinH = MinH;
  2729. p->SL = SnapL; p->ST = SnapT;
  2730. p->SR = SnapR; p->SB = SnapB;
  2731. if (p->SR) p->X = CW - p->W - p->SR;
  2732. if (p->SB) p->Y = CH - p->H - p->SB;
  2733. la_EnsurePanelSnapping(p, CW, CH);
  2734. p->Show = 1;
  2735. p->PP.EndInstance = p;
  2736. p->PP.LastPs = &p->FakePS;
  2737. p->PP.LastPs->p = _LA_PROP_PANEL;
  2738. p->PP.LastPs->UseInstance = p;
  2739. p->PP.LastPs->Type = U'.';
  2740. la_EnsurePanelExtras(p);
  2741. laRecalcPanel(p);
  2742. p->FrameDistinguish = 100; //greater than 1 is ok
  2743. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  2744. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  2745. return p;
  2746. }
  2747. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  2748. if(!uit) return 0;
  2749. laPanel *p = memAcquireHyper(sizeof(laPanel));
  2750. strSafeSet(&p->Title, uit->Title->Ptr);
  2751. p->PanelTemplate = uit;
  2752. p->Show = 1;
  2753. p->PP.EndInstance = p;
  2754. p->PP.LastPs = &p->FakePS;
  2755. p->PP.LastPs->p = _LA_PROP_PANEL;
  2756. p->PP.LastPs->UseInstance = p;
  2757. p->PP.LastPs->Type = U'.';
  2758. la_EnsurePanelExtras(p);
  2759. laRecalcPanel(p);
  2760. p->FrameDistinguish = 100; //greater than 1 is ok
  2761. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  2762. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  2763. p->Block = b; b->CurrentPanel = p;
  2764. if(uit->PropFunc){ uit->PropFunc(p); }
  2765. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  2766. laNotifyUsers("la.windows.panels");
  2767. return p;
  2768. }
  2769. laPanel *laCreatePanel(laBlock *b, char *template_id){
  2770. laUiTemplate* uit=laFindUiTemplate(template_id);
  2771. return laCreatePanelT(b, uit);
  2772. }
  2773. laPanel *laCreateTopPanel(laWindow *w, char *template_id, int X, int Y, int W, int H, int MaxW, int MaxH, int MinW, int MinH, int SnapL, int SnapR, int SnapT, int SnapB){
  2774. laUiTemplate* uit=0;
  2775. if(template_id) uit=laFindUiTemplate(template_id);
  2776. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  2777. p->Mode = LA_PANEL_FLOATING_TOP;
  2778. laPlacePanelForCreation(p);
  2779. if(uit){
  2780. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  2781. }
  2782. if (w) lstPushItem(&w->Panels, p);
  2783. return p;
  2784. }
  2785. void laShowPanel(laPanel *p){
  2786. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  2787. }
  2788. void laShowPanelWithDropDownEffect(laPanel *p){
  2789. laShowPanel(p);
  2790. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  2791. p->AnimationRatio = 0;
  2792. }
  2793. void laShowPanelWithExpandEffect(laPanel *p){
  2794. laShowPanel(p);
  2795. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  2796. p->AnimationRatio = 0;
  2797. }
  2798. void laHidePanel(laPanel *p){
  2799. if (!p->Mode) return;
  2800. p->Show = 0;
  2801. laNotifyUsers("la.windows.panels_hidden");
  2802. }
  2803. void laHidePanelWithDissoveEffect(laPanel *p){
  2804. if (!p->Mode) return;
  2805. laHidePanel(p);
  2806. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  2807. p->AnimationRatio = 1;
  2808. }
  2809. void laHidePanelWithCollapseEffect(laPanel *p){
  2810. if (!p->Mode) return;
  2811. laHidePanel(p);
  2812. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  2813. p->AnimationRatio = 1;
  2814. }
  2815. void laHidePanelWithMinimizeEffect(laPanel *p){
  2816. if (!p->Mode) return;
  2817. laHidePanel(p);
  2818. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  2819. p->AnimationRatio = 1;
  2820. }
  2821. void laActivatePanel(char* TemplateID, int x, int y){
  2822. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  2823. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  2824. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  2825. laShowPanelWithExpandEffect(p); laPopPanel(p);
  2826. }
  2827. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  2828. p->UI.PanX += DeltaX;
  2829. p->UI.PanY += DeltaY;
  2830. }
  2831. int laPanUiListFree(laUiList *uil, int X, int Y){
  2832. uil->PanX+=X; uil->PanY+=Y;
  2833. }
  2834. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  2835. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  2836. if(Y){X+=Y;Y=0;}
  2837. }
  2838. if (Y > 0){
  2839. if (uil->B - uil->PanY <= B) return 0;
  2840. else{
  2841. uil->PanY += Y;
  2842. if (uil->B - uil->PanY <= B){
  2843. uil->PanY = uil->B - B;
  2844. return 1;
  2845. }
  2846. }
  2847. }
  2848. if (Y < 0){
  2849. if (uil->U - uil->PanY >= U) return 0;
  2850. else{
  2851. uil->PanY += Y;
  2852. if (uil->U - uil->PanY >= U){
  2853. uil->PanY = uil->U - U;
  2854. return 1;
  2855. }
  2856. }
  2857. }
  2858. if(uil->AllowScale){
  2859. laPanUiListFree(uil, X, 0);
  2860. }else{
  2861. if (X > 0){
  2862. if (uil->R - uil->PanX <= R) return 0;
  2863. else{
  2864. uil->PanX += X;
  2865. if (uil->R - uil->PanX <= R){
  2866. uil->PanX = uil->R - R;
  2867. return 1;
  2868. }
  2869. }
  2870. }
  2871. if (X < 0){
  2872. if (uil->L - uil->PanX >= L) return 0;
  2873. else{
  2874. uil->PanX += X;
  2875. if (uil->L - uil->PanX >= L){
  2876. uil->PanX = uil->L - L;
  2877. return 1;
  2878. }
  2879. }
  2880. }
  2881. }
  2882. return 1;
  2883. }
  2884. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  2885. int ret=1;
  2886. if(!uil->AllowScale){ return 0; }
  2887. real NewScale=uil->Scale*factor;
  2888. if(NewScale<0.2){NewScale=0.2; ret=0;}
  2889. if(NewScale>5) {NewScale=5; ret=0;}
  2890. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  2891. factor=NewScale/uil->Scale;
  2892. uil->Scale=NewScale;
  2893. real mx=(L+R)/2,my=(U+B)/2;
  2894. real dx= (mx+uil->PanX)*factor;
  2895. real dy= (my+uil->PanY)*factor;
  2896. uil->PanX=dx-mx;
  2897. uil->PanY=dy-my;
  2898. MAIN.CurrentPanel->FrameDistinguish=100;
  2899. return ret;
  2900. }
  2901. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  2902. if(uil->AllowScale) return 0;
  2903. return laPanUiList(uil,X,Y,L,R,U,B);
  2904. }
  2905. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  2906. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2907. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  2908. strSafeSet(&p->Title, Title);
  2909. if (Define){
  2910. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2911. }
  2912. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2913. p->BT= &_LA_THEME_FLOATING_PANEL;
  2914. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  2915. p->BoundUi = 1;
  2916. return p;
  2917. }
  2918. laPanel *laDesignOperatorPanel(char *Title, int X, int Y, int W, int H, int MaxW, int MaxH, int MinW, int MinH, int SnapL, int SnapR, int SnapT, int SnapB,
  2919. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2920. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  2921. strSafeSet(&p->Title, Title);
  2922. if (Define){
  2923. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2924. }
  2925. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2926. p->BT= &_LA_THEME_FLOATING_PANEL;
  2927. p->Mode = LA_PANEL_FLOATING_TOP;
  2928. p->BoundUi = 1;
  2929. return p;
  2930. }
  2931. void laDeferredDestroyPanel(laPanel *p, int immediate){
  2932. laPanel *ip;
  2933. tnsDelete2DOffscreen(p->OffScr);
  2934. p->OffScr = 0;
  2935. strSafeDestroy(&p->Title);
  2936. if (!p->AnimationMode){
  2937. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  2938. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2939. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2940. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  2941. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2942. }else if (p->Block){
  2943. lstRemoveItem(&p->Block->Panels, p);
  2944. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  2945. }
  2946. laNotifyUsers("la.windows.panels");
  2947. }
  2948. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  2949. //lstRemoveItem(&p->SubPanels, ip);
  2950. laDestroySinglePanel(ip, immediate);
  2951. laNotifyUsers("la.windows.panels");
  2952. }
  2953. la_ClearDetachedProp(p);
  2954. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  2955. la_ReturnPanelNode(p);
  2956. }
  2957. void laDestroySinglePanel(laPanel *p, int immediate){
  2958. la_SetPropMathcerContext(p);
  2959. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  2960. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  2961. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  2962. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  2963. }
  2964. }
  2965. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  2966. la_DestroyUiList(&p->UI, 1, 1, 0);
  2967. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2968. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  2969. if (p->Mode){
  2970. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  2971. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  2972. }
  2973. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  2974. if (la_UiStillInService(p)){
  2975. la_StopUiOperatorService(p);
  2976. }
  2977. if ((!p->AnimationMode) || immediate){
  2978. laDeferredDestroyPanel(p, immediate);
  2979. }else{
  2980. p->LaterDestroy = 1;
  2981. }
  2982. }
  2983. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  2984. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2985. int MinW,MinWt=0;
  2986. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  2987. int CW = MAIN.CurrentWindow->CW;
  2988. if(p->SL && p->SR){return 0;}
  2989. la_SetPropMathcerContext(p);
  2990. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  2991. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  2992. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  2993. MinW = la_TestUiListMinumWidth(uil);
  2994. if (MinW<MinWt){MinW=MinWt;}
  2995. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  2996. if (MinW > 20){
  2997. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  2998. }
  2999. la_PanelValidateWidth(p,uil);
  3000. laEnsurePanelInBound(p,uil);
  3001. if(p->TW>CW){ p->TW=CW; }
  3002. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3003. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3004. laRedrawPanel(p);
  3005. return 1;
  3006. }
  3007. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3008. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3009. laOperator *ai = a;
  3010. laPanel *p;
  3011. int GX, GY, GW, t = 0;
  3012. int b;
  3013. laUiDefineFunc def = ReplaceUiDefine;
  3014. int MinW;
  3015. if (!def){ def=laui_DefaultPropDetails; }
  3016. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3017. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3018. laEnclosePanelContent(p, &p->UI);
  3019. laSetOperatorLocalizer(p);
  3020. p->CloseWhenMovedOut=1;
  3021. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3022. //laShowPanelWithDropDownEffect(p);
  3023. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3024. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3025. return p;
  3026. }
  3027. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3028. laPanel *p;
  3029. int GX, GY, GW, t = 0;
  3030. int b;
  3031. laUiDefineFunc def = ReplaceUiDefine;
  3032. int MinW;
  3033. if (!def) return 0;
  3034. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3035. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3036. p->Mode = LA_PANEL_FLOATING_TOP;
  3037. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3038. laEnclosePanelContent(p, &p->UI);
  3039. if(MAIN.CurrentWindow->Operators.pFirst){
  3040. laSetOperatorLocalizer(MAIN.PendingSplash);
  3041. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3042. MAIN.PendingSplash=0;
  3043. }
  3044. //laShowPanelWithExpandEffect(p);
  3045. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3046. return p;
  3047. }
  3048. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3049. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3050. laOperator *ai = a;
  3051. laPanel *p; laPropContainer* sub;
  3052. int GX, GY, GW, t = 0;
  3053. int b;
  3054. laUiDefineFunc def = ReplaceUiDefine;
  3055. int MinW;
  3056. if (!def){
  3057. if (This && This->LastPs->p){
  3058. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3059. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3060. }
  3061. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3062. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3063. }
  3064. GX = L; GY = B;
  3065. GW = (R - L) > MaxW ? MaxW : (R - L);
  3066. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3067. laEnclosePanelContent(p, &p->UI);
  3068. laSetOperatorLocalizer(p);
  3069. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3070. laShowPanelWithDropDownEffect(p);
  3071. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3072. if(Attachment){
  3073. p->Parent = Attachment;
  3074. lstAppendItem(&Attachment->SubPanels, p);
  3075. }
  3076. return p;
  3077. }
  3078. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3079. laPanel *p;
  3080. int t = 0;
  3081. int b;
  3082. //laLocalToWindow(0, Attachment, &L, &t);
  3083. //laLocalToWindow(0, Attachment, &R, &U);
  3084. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3085. laSetOperatorLocalizer(p);
  3086. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3087. laShowPanelWithDropDownEffect(p);
  3088. p->Parent = Attachment;
  3089. lstPushItem(&Attachment->SubPanels, p);
  3090. return p;
  3091. }
  3092. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3093. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3094. laOperator *ai = a;
  3095. laPanel *p;
  3096. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3097. int GX, GY, GW, t = 0;
  3098. int b;
  3099. int MinW;
  3100. //laLocalToWindow(0,Attachment, &L, &t);
  3101. //laLocalToWindow(0,Attachment, &R, &B);
  3102. GX = L;
  3103. GY = B;
  3104. GW = (R - L) > MaxW ? MaxW : (R - L);
  3105. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3106. p->MenuRefer = MenuRefer;
  3107. laEnclosePanelContent(p, MenuRefer);
  3108. laSetOperatorLocalizer(p);
  3109. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3110. laShowPanelWithDropDownEffect(p);
  3111. p->Parent = Attachment;
  3112. lstPushItem(&Attachment->SubPanels, p);
  3113. return p;
  3114. }
  3115. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3116. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3117. laOperator *ai = a;
  3118. laPanel *p;
  3119. int GX, GY, GW, t = 0;
  3120. int b;
  3121. GX = L;
  3122. GY = B;
  3123. GW = MaxW;
  3124. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3125. p->MenuRefer = &p->UI;
  3126. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3127. laSetOperatorLocalizer(p);
  3128. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3129. laShowPanelWithDropDownEffect(p);
  3130. if (Attachment){
  3131. p->Parent = Attachment;
  3132. lstPushItem(&Attachment->SubPanels, p);
  3133. }else{
  3134. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3135. }
  3136. return p;
  3137. }
  3138. laPanel *laEnableOperatorPanel(laOperator *For, laPropPack *This, int X, int Y, int W, int H, int MaxW, int MaxH, int MinW, int MinH, int SnapL, int SnapR, int SnapT, int SnapB, laEvent *e){
  3139. laOperator *ai = For;
  3140. laPanel *p;
  3141. int b;
  3142. laUiDefineFunc def = 0;
  3143. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3144. else def = laui_DefaultPropUiDefine;
  3145. For->PP.EndInstance = For->CustomData;
  3146. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3147. laEnclosePanelContent(p, &p->UI);
  3148. MAIN.ToPanel = p;
  3149. laShowPanelWithExpandEffect(p);
  3150. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3151. ai->OperatorPanel = p;
  3152. p->ParentOperator = For;
  3153. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3154. return p;
  3155. }
  3156. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3157. laPanel *p; int b; laUiList *uil; laColumn* col;
  3158. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3159. strSafeSet(&p->Title, Title);
  3160. p->BoundUi = 1;
  3161. p->Mode = LA_PANEL_FLOATING_TOP;
  3162. p->BT = &_LA_THEME_FLOATING_PANEL;
  3163. MAIN.ToPanel = p;
  3164. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3165. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3166. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3167. laUiItem* r=laBeginRow(uil,col,0,0);
  3168. laShowSeparator(uil,col)->Expand=1;
  3169. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3170. laEndRow(uil,r);
  3171. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3172. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3173. laSetOperatorLocalizer(p);
  3174. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3175. return p;
  3176. }
  3177. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3178. laPanel *p; int b; laUiList *uil; laColumn* col;
  3179. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3180. strSafeSet(&p->Title, Title);
  3181. p->BoundUi = 1;
  3182. p->Mode = LA_PANEL_FLOATING_TOP;
  3183. p->BT = &_LA_THEME_FLOATING_PANEL;
  3184. MAIN.ToPanel = p;
  3185. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3186. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3187. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3188. laUiItem* r = laBeginRow(uil,col,0,0);
  3189. laShowSeparator(uil,col)->Expand=1;
  3190. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3191. laEndRow(uil, r);
  3192. laEnclosePanelContent(p,uil);
  3193. laShowPanelWithExpandEffect(p);
  3194. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3195. laSetOperatorLocalizer(p);
  3196. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3197. return p;
  3198. }
  3199. void laOperatorModalOver(laOperator* For){
  3200. For->ModalOver = 1;
  3201. }
  3202. void laDeferredRedraw(laPanel* p){
  3203. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3204. if(lip->p==p) return;
  3205. }
  3206. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3207. }
  3208. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3209. laWindow* cur=MAIN.CurrentWindow;
  3210. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3211. MAIN.CurrentWindow=w;
  3212. la_UpdateUiPlacement(w);
  3213. }
  3214. MAIN.CurrentWindow=cur;
  3215. }
  3216. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3217. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3218. }
  3219. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3220. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3221. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3222. void laRedrawCurrentPanel(){
  3223. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3224. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3225. }
  3226. void laRecalcCurrentPanel(){
  3227. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3228. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3229. }
  3230. void laRecalcPanelImmediate(laPanel* p){
  3231. p->FrameDistinguish++;
  3232. laBoxedTheme* bt = (*p->BT);
  3233. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3234. la_PanelRefreshDetachedProp(p);
  3235. int enclosed=0;
  3236. if(p->BoundUi || p->MenuRefer){
  3237. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3238. else enclosed=laEnclosePanelContent(p, &p->UI);
  3239. }
  3240. if(!enclosed){
  3241. la_PanelValidateWidth(p,&p->UI);
  3242. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3243. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3244. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3245. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3246. }
  3247. laWindow* w=MAIN.CurrentWindow;
  3248. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3249. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3250. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3251. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3252. }
  3253. }
  3254. void laRecalcCurrentPanelImmediate(){
  3255. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3256. }
  3257. int laNonFixedPanelExists(laPanel *p){
  3258. laPanel *ip;
  3259. if (!p) return 0;
  3260. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3261. // if (ip == p) return 1;
  3262. //}
  3263. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3264. if (ip == p) return 1;
  3265. }
  3266. return 0;
  3267. }
  3268. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3269. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3270. return 1;
  3271. }
  3272. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3273. int tt=MAIN.TooltipCloseDistance;
  3274. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3275. return 1;
  3276. }
  3277. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3278. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3279. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3280. return 0;
  3281. return 1;
  3282. }
  3283. void laUnlinkSharedPanel(laPanel *p){
  3284. laWindow *w;
  3285. laPanel *ip;
  3286. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3287. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3288. if (ip == p){
  3289. lstRemoveItem(&w->Panels, ip);
  3290. return;
  3291. }
  3292. }
  3293. }
  3294. }
  3295. int laIsPanelCovered(laPanel *p){
  3296. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3297. laPanel *ip;
  3298. laPanel *resp;
  3299. int in1 = 0, in2 = 0, in3 = 0;
  3300. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3301. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3302. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3303. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3304. //}
  3305. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3306. if (ip == p){
  3307. in3 = 1;
  3308. d3 = 0;
  3309. continue;
  3310. }
  3311. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3312. }
  3313. if (!in2 && !in3) in1 = 1;
  3314. if (in1){
  3315. if (d1 || d2 || d3) return 1;
  3316. }else{
  3317. if (in2){
  3318. if (d2 || d3) return 1;
  3319. }else if (in3)
  3320. if (d3) return 1;
  3321. }
  3322. return 0;
  3323. }
  3324. int laIsTopPanel(laPanel *p){
  3325. //if (!p->Item.pPrev) return 1;
  3326. //else {
  3327. if (!laIsPanelCovered(p)){
  3328. //laPopPanel(p);
  3329. return 1;
  3330. }
  3331. return 0;
  3332. //}
  3333. return 0;
  3334. }
  3335. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3336. if(!p) return;
  3337. int ix = *x, iy = *y;
  3338. laListItemPointer *lip;
  3339. laOperator *ai = a;
  3340. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3341. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3342. if (a){
  3343. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3344. laUiList *uil = lip->p;
  3345. (*x) += uil->PanX;
  3346. (*y) += uil->PanY;
  3347. }
  3348. }
  3349. }
  3350. void laPanelToLocal(laOperator *a, int *x, int *y){
  3351. int ix = *x, iy = *y;
  3352. laListItemPointer *lip;
  3353. if (a){
  3354. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3355. laUiList *uil = lip->p;
  3356. (*x) += uil->PanX;
  3357. (*y) += uil->PanY;
  3358. }
  3359. }
  3360. }
  3361. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3362. if(!p) return;
  3363. int ix = *x, iy = *y;
  3364. laListItemPointer *lip;
  3365. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3366. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3367. if (a){
  3368. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3369. laUiList *uil = lip->p;
  3370. (*x) -= uil->PanX;
  3371. (*y) -= uil->PanY;
  3372. }
  3373. }
  3374. }
  3375. void laPanelToWindow(laPanel *p, int *x, int *y){
  3376. int ix = *x, iy = *y;
  3377. laListItemPointer *lip;
  3378. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3379. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3380. }
  3381. void laLocalToPanel(laOperator *a, int *x, int *y){
  3382. int ix = *x, iy = *y;
  3383. laListItemPointer *lip;
  3384. if (a){
  3385. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3386. laUiList *uil = lip->p;
  3387. (*x) -= uil->PanX;
  3388. (*y) -= uil->PanY;
  3389. }
  3390. }
  3391. }
  3392. void laSetNextMenuPos(int X, int Y, int W, int H){
  3393. MAIN.NextX = X;
  3394. MAIN.NextY = Y;
  3395. MAIN.NextW = W;
  3396. MAIN.NextH = H;
  3397. }
  3398. int laIsInBlock(laBlock *b, int X, int Y){
  3399. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3400. return 0;
  3401. }
  3402. int laIsInBlockHeader(laBlock *b, int X, int Y){ if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + LA_RH) return 1; return 0; }
  3403. int laIsInBlockBotton1(laBlock *b, int X, int Y){ if (X >= b->X && X <= b->X + LA_RH && Y >= b->Y && Y <= b->Y + LA_RH) return 1; return 0; }
  3404. int laIsInBlockBotton2(laBlock *b, int X, int Y){ if (X >= b->X+LA_RH && X <= b->X+LA_2RH && Y >= b->Y && Y <= b->Y + LA_RH) return 1; return 0; }
  3405. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3406. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3407. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3408. if (!b->B1 && !b->B2){
  3409. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3410. }
  3411. }
  3412. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3413. laPanel *p;
  3414. laBlock *sb = 0;
  3415. if (!laIsInBlock(b, X, Y)) return 0;
  3416. if (!b->B1 && !b->B2) return b;
  3417. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3418. return laDetectBlockRecursive(b->B2, X, Y);
  3419. }
  3420. laPanel *laDetectPanel(int X, int Y){
  3421. laPanel *p; laBlock *b;
  3422. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3423. int x = X, y = Y;
  3424. laWindowToLocal(0, p, &x, &y);
  3425. if (p->Show && laIsInPanel(p, x, y)){
  3426. return p;
  3427. }
  3428. }
  3429. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3430. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3431. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3432. return 0;
  3433. }
  3434. laUiList *laPrepareUi(laPanel *p){
  3435. return &p->UI;
  3436. }
  3437. laColumn *laFirstColumn(laUiList *uil){
  3438. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3439. else{
  3440. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3441. c->SP = 1;
  3442. c->PreWidth = 1;
  3443. lstAppendItem(&uil->Columns, c);
  3444. c->Top = c;
  3445. return uil->Columns.pFirst;
  3446. }
  3447. }
  3448. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3449. laColumn *lc, *rc;
  3450. if (c->LS || c->RS) return c;
  3451. lc = memAcquireSimple(sizeof(laColumn));
  3452. rc = memAcquireSimple(sizeof(laColumn));
  3453. c->LS = lc;
  3454. c->RS = rc;
  3455. c->LS->SP = Percent;
  3456. c->RS->SP = Percent;
  3457. c->LS->Top = c->Top;
  3458. c->RS->Top = c->Top;
  3459. if (uil){
  3460. lstAppendItem(&uil->Columns, lc);
  3461. lstAppendItem(&uil->Columns, rc);
  3462. }
  3463. if (c->LS && c->RS->MaxW == 0){
  3464. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3465. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3466. }else if (c->RS && c->LS->MaxW == 0){
  3467. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3468. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3469. }
  3470. return c;
  3471. }
  3472. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3473. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3474. return c->LS;
  3475. }
  3476. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3477. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3478. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3479. return c->RS;
  3480. }
  3481. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3482. lstRemoveItem(List, c);
  3483. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3484. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3485. memFree(c);
  3486. }
  3487. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3488. laUiList *uil = TopUil;
  3489. laUiList *sub;
  3490. laUiItem *ui;
  3491. laColumn *cc, *NextCC = 0;
  3492. int Occupied = 0;
  3493. int Removed = 0;
  3494. if (!c->LS) return 0;
  3495. else{
  3496. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3497. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3498. }
  3499. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3500. if (ui->C == c->LS || ui->C == c->RS){
  3501. if (DoMerge){
  3502. ui->C = c;
  3503. Occupied = 1;
  3504. }else
  3505. return 1;
  3506. }
  3507. if (ui->Subs.pFirst){
  3508. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3509. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3510. }
  3511. }
  3512. }
  3513. if (!Removed){
  3514. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3515. if (cc == c){
  3516. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3517. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3518. c->LS = 0;
  3519. c->RS = 0;
  3520. Removed = 1;
  3521. break;
  3522. }
  3523. }
  3524. }
  3525. return Occupied;
  3526. }
  3527. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3528. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3529. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3530. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3531. ut->FakeProp->Base.Identifier = ut->Identifier;
  3532. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3533. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3534. ut->FakeProp->Base.OffsetIsPointer = 1;
  3535. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3536. return ut->ExtraProps;
  3537. }
  3538. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3539. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3540. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3541. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3542. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3543. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3544. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3545. ct->FakeProp->Base.OffsetIsPointer = 1;
  3546. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3547. return ct->ExtraProps;
  3548. }
  3549. void la_DestroyUiType(laUiType* uit){
  3550. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3551. memFree(uit);
  3552. }
  3553. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3554. laUiType *ut = memAcquire(sizeof(laUiType));
  3555. ut->Identifier = Identifer;
  3556. ut->OperatorID = UseOperator;
  3557. ut->Draw = Draw;
  3558. ut->Theme = bt;
  3559. ut->ForType = ForType;
  3560. ut->OperatorType = laGetOperatorType(UseOperator);
  3561. ut->GetHeight = GetHeight;
  3562. ut->Init = Init;
  3563. ut->Destroy = Destroy;
  3564. la_UDFAppendSharedTypePointer(Identifer, ut);
  3565. lstAppendItem(&MAIN.UiTypes, ut);
  3566. return ut;
  3567. }
  3568. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3569. laUiType *ut = MAIN.UiTypes.pFirst;
  3570. if (!P) return 0;
  3571. if (P->DefaultUiType) return P->DefaultUiType;
  3572. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3573. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3574. for (ut; ut; ut = ut->Item.pNext){
  3575. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3576. return ut;
  3577. }
  3578. }
  3579. return 0;
  3580. }
  3581. laUiType *la_GetUiButtonType(){
  3582. laUiType *ut = MAIN.UiTypes.pFirst;
  3583. for (ut; ut; ut = ut->Item.pNext){
  3584. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3585. }
  3586. return 0;
  3587. }
  3588. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3589. laCanvasTemplate *vdt;
  3590. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3591. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3592. }
  3593. return 0;
  3594. }
  3595. void la_AssignPropExtras(laUiItem* ui){
  3596. if(!ui->Type || !ui->Type->FakeProp) return;
  3597. ui->FakePs.p = ui->Type->FakeProp;
  3598. ui->FakePs.Type = U'.';
  3599. ui->FakePs.UseInstance = ui;
  3600. ui->ExtraPP.LastPs = &ui->FakePs;
  3601. }
  3602. void la_AssignCanvasPropExtras(laUiItem* ui){
  3603. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3604. laCanvasTemplate*ct=ui->CanvasTemplate;
  3605. ui->FakePs.p = ct->FakeProp;
  3606. ui->FakePs.Type = U'.';
  3607. ui->FakePs.UseInstance = ui;
  3608. ui->ExtraPP.EndInstance = ui->Extra;
  3609. ui->ExtraPP.LastPs = &ui->FakePs;
  3610. }
  3611. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3612. int result;
  3613. if (!ui) return 0;
  3614. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3615. if (Path){
  3616. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3617. if (!result){
  3618. ui->AT = laGetOperatorType(Path);
  3619. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3620. ui->Type = la_GetUiButtonType();
  3621. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3622. }else{
  3623. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3624. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3625. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3626. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3627. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3628. }
  3629. if (Base){
  3630. ui->PP.RawThis = Base;
  3631. }
  3632. }else if (Base){
  3633. ui->PP.LastPs = Base->LastPs;
  3634. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3635. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3636. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3637. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3638. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3639. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3640. }
  3641. la_AssignPropExtras(ui);
  3642. if(Widget){ ui->Flags|= Widget->Flags; }
  3643. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3644. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3645. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3646. return ui;
  3647. }
  3648. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3649. ui->Type = _LA_UI_LABEL;
  3650. ui->Template = Template;
  3651. ui->State = LA_UI_NORMAL;
  3652. strSafeSet(&ui->Display, Content);
  3653. la_AssignPropExtras(ui);
  3654. return ui;
  3655. }
  3656. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3657. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3658. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3659. ui->State = LA_UI_NORMAL;
  3660. la_AssignPropExtras(ui);
  3661. return ui;
  3662. }
  3663. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3664. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3665. transLate(Content);
  3666. la_UpdateLabelDisplay(ui, Template, Content);
  3667. ui->C = c;
  3668. if (ui->Type->Init) ui->Type->Init(ui);
  3669. ui->ExtraPP.EndInstance = ui->Extra;
  3670. lstAppendItem(&uil->UiItems, ui);
  3671. return ui;
  3672. }
  3673. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3674. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3675. la_UpdateLabelDisplay(ui, Template, Content);
  3676. ui->C = c;
  3677. if (ui->Type->Init) ui->Type->Init(ui);
  3678. ui->ExtraPP.EndInstance = ui->Extra;
  3679. lstAppendItem(&uil->UiItems, ui);
  3680. return ui;
  3681. }
  3682. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3683. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3684. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3685. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3686. ui->C = c;
  3687. if (ui->Type->Init) ui->Type->Init(ui);
  3688. ui->ExtraPP.EndInstance = ui->Extra;
  3689. lstAppendItem(&uil->UiItems, ui);
  3690. return ui;
  3691. }
  3692. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3693. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  3694. }
  3695. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3696. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  3697. }
  3698. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  3699. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3700. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  3701. ui->C = c;
  3702. ui->TemplateContext = TemplateContext;
  3703. if (ui->Type->Init) ui->Type->Init(ui);
  3704. ui->ExtraPP.EndInstance = ui->Extra;
  3705. lstAppendItem(&uil->UiItems, ui);
  3706. return ui;
  3707. }
  3708. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  3709. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3710. ui->C = c; ui->Extra=Image;
  3711. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  3712. ui->SymbolID=Height;
  3713. lstAppendItem(&uil->UiItems, ui);
  3714. return ui;
  3715. }
  3716. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3717. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  3718. }
  3719. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3720. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  3721. }
  3722. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  3723. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3724. ui->Type = _LA_UI_CANVAS;
  3725. ui->State = LA_UI_NORMAL;
  3726. ui->C = c;
  3727. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3728. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  3729. else{
  3730. if(!ui->PP.LastPs || ui->PP.LastPs->p->PropertyType!=LA_PROP_SUB){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  3731. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  3732. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  3733. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  3734. }
  3735. if (ui->Type->Init) ui->Type->Init(ui);
  3736. la_AssignCanvasPropExtras(ui);
  3737. if (Height) ui->Expand=Height; else ui->Expand=6;
  3738. lstAppendItem(&uil->UiItems, ui);
  3739. return ui;
  3740. }
  3741. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  3742. laUiItem* ui=0;
  3743. #define ADD_CANVAS \
  3744. laUiItem* b=laBeginRow(uil,cr,0,0);\
  3745. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  3746. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  3747. }laEndCondition(uil,b3);\
  3748. laEndRow(uil,b);
  3749. if(Detached){
  3750. laColumn* cl,*cll,*clr,*cr;
  3751. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  3752. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  3753. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  3754. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  3755. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  3756. ADD_CANVAS
  3757. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  3758. }laElse(uil,b2);{
  3759. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  3760. ADD_CANVAS
  3761. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  3762. }laEndCondition(uil,b2);
  3763. }else{
  3764. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  3765. }
  3766. #undef ADD_CANVAS
  3767. }
  3768. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  3769. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3770. laCanvasExtra *e;
  3771. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  3772. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  3773. ui->C = c;
  3774. if (ui->Type->Init) ui->Type->Init(ui);
  3775. ui->ExtraPP.EndInstance = ui->Extra;
  3776. lstAppendItem(&uil->UiItems, ui);
  3777. return ui;
  3778. }
  3779. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  3780. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3781. ui->Type = _LA_UI_SYMBOL;
  3782. ui->SymbolID = SymbolID;
  3783. if (Height) ui->State = Height;
  3784. ui->C = c;
  3785. if (ui->Type->Init) ui->Type->Init(ui);
  3786. ui->ExtraPP.EndInstance = ui->Extra;
  3787. lstAppendItem(&uil->UiItems, ui);
  3788. return ui;
  3789. }
  3790. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  3791. laPropPack PP={0}; int result;
  3792. if (Path){
  3793. result = la_GetPropFromPath(&PP, Base, Path, 0);
  3794. if (!result){ return 0; }
  3795. if (Base){ PP.RawThis = Base; }
  3796. }else if (Base){
  3797. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3798. }
  3799. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  3800. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  3801. lstAppendItem(&ui->CompoundPPs,CPP);
  3802. return &CPP->PP;
  3803. }
  3804. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  3805. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3806. ui->Type = &_LA_UI_ROW_BEGIN;
  3807. ui->State=Expand;
  3808. ui->Flags=Even;
  3809. ui->C = c;
  3810. if (ui->Type->Init) ui->Type->Init(ui);
  3811. ui->ExtraPP.EndInstance = ui->Extra;
  3812. lstAppendItem(&uil->UiItems, ui);
  3813. return ui;
  3814. }
  3815. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  3816. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3817. ui->Type = &_LA_UI_ROW_END;
  3818. ui->C = Begin->C;
  3819. ui->Page = (laUiList*)Begin;
  3820. if (ui->Type->Init) ui->Type->Init(ui);
  3821. ui->ExtraPP.EndInstance = ui->Extra;
  3822. lstAppendItem(&uil->UiItems, ui);
  3823. return ui;
  3824. }
  3825. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  3826. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  3827. e->Expression = Expression;
  3828. ui->Extra = e;
  3829. la_AssignPropExtras(ui);
  3830. }
  3831. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3832. laUiItem *ui = la_CreateGroupHandle(Widget);
  3833. laUiList *nuil;
  3834. ui->C = c;
  3835. lstAppendItem(&uil->UiItems, ui);
  3836. nuil = memAcquireSimple(sizeof(laUiList));
  3837. strSafeSet(&nuil->TabName, Name);
  3838. ui->Page = nuil;
  3839. lstAppendItem(&ui->Subs, nuil);
  3840. if (ui->Type->Init) ui->Type->Init(ui);
  3841. ui->ExtraPP.EndInstance = ui->Extra;
  3842. return ui;
  3843. }
  3844. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  3845. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  3846. laUiList *sub = SubUi->Page;
  3847. laColumn *s = laFirstColumn(sub);
  3848. SubUi->State = LA_UI_ACTIVE;
  3849. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  3850. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  3851. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  3852. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  3853. laShowSeparator(sub, s);
  3854. return SubUi;
  3855. }
  3856. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3857. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  3858. laUiList *sub = SubUi->Page;
  3859. laColumn *s = laFirstColumn(sub);
  3860. SubUi->State = LA_UI_ACTIVE;
  3861. return SubUi;
  3862. }
  3863. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  3864. laEndCondition(sub, sub->UiItems.pFirst);
  3865. }
  3866. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  3867. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  3868. laUiList *nuil;
  3869. ui->C = c;
  3870. lstAppendItem(&uil->UiItems, ui);
  3871. if (ui->Type->Init) ui->Type->Init(ui);
  3872. ui->ExtraPP.EndInstance = ui->Extra;
  3873. return ui;
  3874. }
  3875. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  3876. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3877. if (!ui->Page) ui->Page = uil;
  3878. lstAppendItem(&ui->Subs, uil);
  3879. strSafeSet(&uil->TabName, Name);
  3880. laFirstColumn(uil);
  3881. //laFirstColumn(uil);
  3882. return uil;
  3883. }
  3884. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  3885. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3886. /*if (!ui->Page) */ ui->Page = uil;
  3887. lstAppendItem(&ui->Subs, uil);
  3888. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  3889. return uil;
  3890. }
  3891. laUiConditionNode *laTrue(){
  3892. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3893. ucn->Type = LA_CONDITION_TRUE;
  3894. return ucn;
  3895. }
  3896. laUiConditionNode *laFalse(){
  3897. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3898. ucn->Type = LA_CONDITION_FALSE;
  3899. return ucn;
  3900. }
  3901. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  3902. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3903. ucn->Type = LA_CONDITION_PROP;
  3904. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  3905. strSafeSet(&ucn->String, Prop);
  3906. return ucn;
  3907. }
  3908. laUiConditionNode *laIntExpression(int Value){
  3909. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3910. ucn->Type = LA_CONDITION_INT;
  3911. ucn->IntValue = Value;
  3912. return ucn;
  3913. }
  3914. laUiConditionNode *laFloatExpression(real Value){
  3915. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3916. ucn->Type = LA_CONDITION_FLOAT;
  3917. ucn->FloatValue = Value;
  3918. return ucn;
  3919. }
  3920. laUiConditionNode *laStringExpression(char *Content){
  3921. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3922. ucn->Type = LA_CONDITION_STRING;
  3923. strSafeSet(&ucn->String, Content);
  3924. return ucn;
  3925. }
  3926. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3927. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3928. ucn->Type = LA_CONDITION_AND;
  3929. ucn->Expression1 = Expression1;
  3930. ucn->Expression2 = Expression2;
  3931. return ucn;
  3932. }
  3933. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3934. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3935. ucn->Type = LA_CONDITION_OR;
  3936. ucn->Expression1 = Expression1;
  3937. ucn->Expression2 = Expression2;
  3938. return ucn;
  3939. }
  3940. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  3941. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3942. ucn->Type = LA_CONDITION_NOT;
  3943. ucn->Expression1 = Expression1;
  3944. return ucn;
  3945. }
  3946. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3947. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3948. ucn->Type = LA_CONDITION_EQ;
  3949. ucn->Expression1 = Expression1;
  3950. ucn->Expression2 = Expression2;
  3951. return ucn;
  3952. }
  3953. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3954. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3955. ucn->Type = LA_CONDITION_GT;
  3956. ucn->Expression1 = Expression1;
  3957. ucn->Expression2 = Expression2;
  3958. return ucn;
  3959. }
  3960. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3961. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3962. ucn->Type = LA_CONDITION_LT;
  3963. ucn->Expression1 = Expression1;
  3964. ucn->Expression2 = Expression2;
  3965. return ucn;
  3966. }
  3967. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3968. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3969. ucn->Type = LA_CONDITION_GE;
  3970. ucn->Expression1 = Expression1;
  3971. ucn->Expression2 = Expression2;
  3972. return ucn;
  3973. }
  3974. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3975. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3976. ucn->Type = LA_CONDITION_LE;
  3977. ucn->Expression1 = Expression1;
  3978. ucn->Expression2 = Expression2;
  3979. return ucn;
  3980. }
  3981. int la_GetIntConditionValue(laUiConditionNode *Expression){
  3982. if (Expression->Type != LA_CONDITION_INT) return 0;
  3983. return Expression->IntValue;
  3984. }
  3985. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  3986. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  3987. return Expression->FloatValue;
  3988. }
  3989. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  3990. return Expression->String->Ptr;
  3991. }
  3992. int la_DoCompare(int CompMode, int Mode1, int i1, real f1, char *s1, void *p1, int Mode2, int i2, real f2, char *s2, void *p2){
  3993. switch (Mode1){
  3994. case LA_PROP_ENUM:
  3995. case LA_PROP_INT:
  3996. case LA_CONDITION_INT:
  3997. switch (Mode2){
  3998. case LA_PROP_ENUM:
  3999. case LA_PROP_INT:
  4000. case LA_CONDITION_INT:
  4001. switch (CompMode){
  4002. case LA_CONDITION_GE:
  4003. return (i1 >= i2);
  4004. case LA_CONDITION_GT:
  4005. return (i1 > i2);
  4006. case LA_CONDITION_EQ:
  4007. return (i1 == i2);
  4008. case LA_CONDITION_LT:
  4009. return (i1 < i2);
  4010. case LA_CONDITION_LE:
  4011. return (i1 <= i2);
  4012. }
  4013. case LA_PROP_FLOAT:
  4014. case LA_CONDITION_FLOAT:
  4015. switch (CompMode){
  4016. case LA_CONDITION_GE:
  4017. return ((real)i1 >= f2);
  4018. case LA_CONDITION_GT:
  4019. return ((real)i1 > f2);
  4020. case LA_CONDITION_EQ:
  4021. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4022. case LA_CONDITION_LT:
  4023. return ((real)i1 < f2);
  4024. case LA_CONDITION_LE:
  4025. return ((real)i1 <= f2);
  4026. }
  4027. case LA_PROP_SUB:
  4028. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4029. default:
  4030. return 0;
  4031. }
  4032. case LA_PROP_FLOAT:
  4033. case LA_CONDITION_FLOAT:
  4034. switch (Mode2){
  4035. case LA_PROP_INT:
  4036. case LA_PROP_ENUM:
  4037. case LA_CONDITION_INT:
  4038. switch (CompMode){
  4039. case LA_CONDITION_GE:
  4040. return (f1 >= (real)i2);
  4041. case LA_CONDITION_GT:
  4042. return (f1 > (real)i2);
  4043. case LA_CONDITION_EQ:
  4044. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4045. case LA_CONDITION_LT:
  4046. return (f1 < (real)i2);
  4047. case LA_CONDITION_LE:
  4048. return (f1 <= (real)i2);
  4049. }
  4050. case LA_PROP_FLOAT:
  4051. case LA_CONDITION_FLOAT:
  4052. switch (CompMode){
  4053. case LA_CONDITION_GE:
  4054. return (f1 >= f2);
  4055. case LA_CONDITION_GT:
  4056. return (f1 > f2);
  4057. case LA_CONDITION_EQ:
  4058. return (f1 == f2);
  4059. case LA_CONDITION_LT:
  4060. return (f1 < f2);
  4061. case LA_CONDITION_LE:
  4062. return (f1 <= f2);
  4063. }
  4064. default:
  4065. return 0;
  4066. }
  4067. case LA_PROP_STRING:
  4068. case LA_CONDITION_STRING:
  4069. switch (Mode2){
  4070. case LA_PROP_STRING:
  4071. case LA_CONDITION_STRING:
  4072. return strSame(s1, s2);
  4073. default:
  4074. return 0;
  4075. }
  4076. case LA_PROP_SUB:
  4077. switch (Mode2){
  4078. case LA_PROP_SUB:
  4079. return p1 == p2;
  4080. case LA_CONDITION_INT:
  4081. case LA_PROP_INT:
  4082. case LA_PROP_ENUM:
  4083. return (int)p1 == i2;
  4084. default:
  4085. return 0;
  4086. }
  4087. default:
  4088. switch (CompMode){
  4089. case LA_CONDITION_GE:
  4090. return (i1 >= i2);
  4091. case LA_CONDITION_GT:
  4092. return (i1 > i2);
  4093. case LA_CONDITION_EQ:
  4094. return (i1 == i2);
  4095. case LA_CONDITION_LT:
  4096. return (i1 < i2);
  4097. case LA_CONDITION_LE:
  4098. return (i1 <= i2);
  4099. }
  4100. }
  4101. }
  4102. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4103. void *Instance = 0;
  4104. int IValue1 = 0, IValue2 = 0;
  4105. real FValue1 = 0, FValue2 = 0;
  4106. void *Ptr1 = 0, *Ptr2 = 0;
  4107. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4108. int Result1, Result2;
  4109. laEnumItem *ei; laSubProp*sp;
  4110. if (!Expression) return 0;
  4111. Str1[0] = 0;
  4112. Str2[0] = 0;
  4113. laPropIterator pi = {0};
  4114. switch (Expression->Type){
  4115. case LA_CONDITION_PROP:
  4116. if (!Expression->PP.LastPs){
  4117. (*IResult) = 0;
  4118. return 0;
  4119. }
  4120. switch (Expression->PP.LastPs->p->PropertyType){
  4121. case LA_PROP_INT:
  4122. *IResult = laGetInt(&Expression->PP);
  4123. if (*IResult) return LA_CONDITION_INT;
  4124. else return 0;
  4125. case LA_PROP_FLOAT:
  4126. *FResult = laGetFloat(&Expression->PP);
  4127. if (*FResult) return 1;
  4128. else return 0;
  4129. break;
  4130. case LA_PROP_STRING:
  4131. laGetString(&Expression->PP, _StrResult, &StrResult);
  4132. if (StrResult[0]) return 1;
  4133. else return 0;
  4134. break;
  4135. case LA_PROP_ENUM:
  4136. ei = laGetEnum(&Expression->PP);
  4137. if (!ei) return 0;
  4138. /*if(ei) */ *IResult = ei->Index;
  4139. if (*IResult) return LA_CONDITION_INT;
  4140. else return 0;
  4141. break;
  4142. case LA_PROP_SUB:
  4143. sp=Expression->PP.LastPs->p;
  4144. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4145. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4146. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4147. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4148. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4149. }
  4150. }
  4151. *PtrResult = Instance;
  4152. if (Instance) return 1;
  4153. break;
  4154. default:
  4155. return 0;
  4156. }
  4157. break;
  4158. case LA_CONDITION_INT:
  4159. *IResult = Expression->IntValue;
  4160. if (*IResult) return 1;
  4161. else
  4162. return 0;
  4163. case LA_CONDITION_FLOAT:
  4164. *FResult = Expression->FloatValue;
  4165. if (*FResult) return 1;
  4166. else
  4167. return 0;
  4168. case LA_CONDITION_STRING:
  4169. if (Expression->String){
  4170. strCopyFull(StrResult, Expression->String->Ptr);
  4171. return 1;
  4172. }else
  4173. return 0;
  4174. case LA_CONDITION_TRUE:
  4175. if (*IResult) *IResult = 1;
  4176. return 1;
  4177. case LA_CONDITION_FALSE:
  4178. if (*IResult) *IResult = 0;
  4179. return 0;
  4180. default:
  4181. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4182. switch (Expression->Type){
  4183. case LA_CONDITION_AND:
  4184. if (Result1){
  4185. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4186. if (Result2) *IResult = 1;
  4187. return (Result2);
  4188. }else
  4189. return 0;
  4190. case LA_CONDITION_OR:
  4191. if (!Result1){
  4192. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4193. if (Result2) *IResult = 1;
  4194. return (Result2);
  4195. }else
  4196. return 1;
  4197. case LA_CONDITION_NOT:
  4198. return !Result1;
  4199. default:
  4200. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4201. return la_DoCompare(Expression->Type,
  4202. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4203. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4204. }
  4205. break;
  4206. }
  4207. return 0;
  4208. }
  4209. int la_DoSingleExpression(laUiConditionNode *Expression){
  4210. int a;
  4211. real b;
  4212. char c[128]={0};
  4213. void *p;
  4214. if (!Expression) return 1;
  4215. c[0] = 0;
  4216. return la_DoExpression(Expression, &a, &b, c, &p);
  4217. }
  4218. void la_StepExpression(laUiConditionNode *e){
  4219. if (!e) return;
  4220. switch (e->Type){
  4221. case LA_CONDITION_AND:
  4222. case LA_CONDITION_OR:
  4223. case LA_CONDITION_GE:
  4224. case LA_CONDITION_GT:
  4225. case LA_CONDITION_EQ:
  4226. case LA_CONDITION_LT:
  4227. case LA_CONDITION_LE:
  4228. la_StepExpression(e->Expression1);
  4229. la_StepExpression(e->Expression2);
  4230. break;
  4231. case LA_CONDITION_NOT:
  4232. la_StepExpression(e->Expression1);
  4233. break;
  4234. case LA_CONDITION_PROP:
  4235. la_StepPropPack(&e->PP);
  4236. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4237. la_UsePropPack(&e->PP, 1);
  4238. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4239. //}
  4240. break;
  4241. default:
  4242. break;
  4243. }
  4244. }
  4245. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4246. if (!ucn) return;
  4247. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4248. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4249. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4250. if (ucn->String) strSafeDestroy(&ucn->String);
  4251. if (ucn) memFree(ucn);
  4252. }
  4253. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4254. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4255. ui->C = c;
  4256. ui->Type = &_LA_UI_CONDITION;
  4257. la_ConditionerInit(ui, Expression);
  4258. lstAppendItem(&uil->UiItems, ui);
  4259. return ui;
  4260. }
  4261. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4262. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4263. laConditionUiExtraData *cued;
  4264. ui->Type = &_LA_UI_CONDITION_ELSE;
  4265. la_ConditionerInit(ui, 0);
  4266. cued = ui->Extra;
  4267. cued->EndUi = Beginner;
  4268. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4269. ui->C = Beginner->C;
  4270. lstAppendItem(&uil->UiItems, ui);
  4271. return ui;
  4272. }
  4273. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4274. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4275. laConditionUiExtraData *cued;
  4276. ui->Template = define;
  4277. ui->C = col;
  4278. ui->PP.RawThis = ExtraBase;
  4279. ui->Page = ExtraThis;
  4280. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4281. la_ConditionerInit(ui, 0);
  4282. cued = ui->Extra;
  4283. //cued->Remove = Remove;
  4284. ui->State = LA_UI_NORMAL;
  4285. lstAppendItem(&uil->UiItems, ui);
  4286. return ui;
  4287. }
  4288. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4289. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4290. laConditionUiExtraData *cued;
  4291. ui->Type = &_LA_UI_CONDITION_END;
  4292. la_ConditionerInit(ui, 0);
  4293. cued = ui->Extra;
  4294. cued->EndUi = Beginner;
  4295. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4296. ui->C = Beginner->C;
  4297. lstAppendItem(&uil->UiItems, ui);
  4298. return ui;
  4299. }
  4300. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4301. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4302. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4303. ui->Type = _LA_UI_MENU_ROOT;
  4304. strSafeSet(&ui->Display, Title);
  4305. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4306. ui->C = c;
  4307. lstAppendItem(&uil->UiItems, ui);
  4308. lstAppendItem(&ui->Subs, muil);
  4309. return muil;
  4310. }
  4311. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4312. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4313. ui->Type = _LA_UI_ALIGN;
  4314. ui->C = widest;
  4315. lstAppendItem(&uil->UiItems, ui);
  4316. return ui;
  4317. }
  4318. void laFixHeight(laUiList *uil, short Rows){
  4319. if (!uil) return;
  4320. uil->HeightCoeff = Rows;
  4321. }
  4322. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4323. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4324. if (!ExtraColumns) return;
  4325. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4326. }
  4327. laUiTemplate *laFindUiTemplate(char *Identifier){
  4328. laUiTemplate *uit;
  4329. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4330. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4331. }
  4332. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4333. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4334. }
  4335. return 0;
  4336. }
  4337. void la_DestroyUiTemplate(laUiTemplate* uit){
  4338. strSafeDestroy(&uit->Identifier);
  4339. strSafeDestroy(&uit->Title);
  4340. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4341. memFree(uit);
  4342. }
  4343. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4344. strSafeDestroy(&uit->Identifier);
  4345. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4346. memFree(uit);
  4347. }
  4348. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4349. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4350. strSafeSet(&uit->Identifier, Identifier);
  4351. strSafeSet(&uit->Title, Title);
  4352. strSafeSet(&uit->CategoryName, NewCategory);
  4353. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4354. uit->DefaultGLFormat=DefaultGLFormat;
  4355. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4356. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4357. la_UDFAppendSharedTypePointer(Identifier, uit);
  4358. return uit;
  4359. }
  4360. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4361. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4362. strSafeSet(&t->Identifier, Identifier);
  4363. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4364. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4365. lstAppendItem(&MAIN.View2DTemplates, t);
  4366. la_UDFAppendSharedTypePointer(Identifier, t);
  4367. return t;
  4368. }
  4369. void laFinalizeUiTemplates(){
  4370. laUiTemplate *uit;
  4371. laCanvasTemplate *u2d;
  4372. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4373. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4374. }
  4375. }
  4376. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4377. laPanel *p;
  4378. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4379. if (p->PanelTemplate==uit){
  4380. return p;
  4381. }
  4382. }
  4383. return 0;
  4384. }
  4385. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4386. laUiList *uil, *NextUil;
  4387. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4388. NextUil = uil->Item.pNext;
  4389. lstRemoveItem(&ui->Subs, uil);
  4390. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4391. }
  4392. la_StopUiOperatorService(ui);
  4393. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4394. strSafeDestroy(&ui->Display);
  4395. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4396. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4397. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4398. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4399. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4400. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4401. }
  4402. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4403. memFree(ui);
  4404. }
  4405. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4406. laUiItem *ui, *NextUi;
  4407. laColumn *col, *NextCol;
  4408. if (!uil) return;
  4409. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4410. NextUi = ui->Item.pNext;
  4411. if(OnlyRemoveUser && RemoveUsers){
  4412. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4413. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4414. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4415. continue;
  4416. }
  4417. lstRemoveItem(&uil->UiItems, ui);
  4418. la_DestroyUiItem(ui, RemoveUsers);
  4419. }
  4420. if(OnlyRemoveUser){ return; }
  4421. for (col = uil->Columns.pFirst; col; col = NextCol){
  4422. NextCol = col->Item.pNext;
  4423. lstRemoveItem(&uil->Columns, col);
  4424. memFree(col);
  4425. }
  4426. strSafeDestroy(&uil->TabName);
  4427. if (!NoFree) memFree(uil);
  4428. }
  4429. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4430. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4431. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4432. }
  4433. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4434. laUiItem *Next = after->Item.pNext;
  4435. laUiItem *Last = uil->UiItems.pLast;
  4436. after->Item.pNext = 0;
  4437. uil->UiItems.pLast = after;
  4438. Define(uil, Base, This, ExtraColums, 0);
  4439. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4440. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4441. if (Next != Last) uil->UiItems.pLast = Last;
  4442. }
  4443. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4444. // int i = 0;
  4445. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4446. // if (!ui->ExtraColums) return;
  4447. // for (i; ui->ExtraColums[i]; i++) {
  4448. // laColumn* c = ui->ExtraColums[i];
  4449. // c->B = B;
  4450. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4451. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4452. // }
  4453. //}
  4454. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4455. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4456. }
  4457. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4458. laColumn *c = ui->C;
  4459. laColumn *ic = lst->pFirst;
  4460. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4461. for (ic; ic; ic = ic->Item.pNext){
  4462. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4463. ic->B = ic->B < c->B ? c->B : ic->B;
  4464. }
  4465. }
  4466. ic = ui->C;
  4467. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4468. ;
  4469. for (ic; ic; ic = ic->Item.pNext){
  4470. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4471. ic->B = ic->B < c->B ? c->B : ic->B;
  4472. }
  4473. }
  4474. }
  4475. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4476. laColumn *c = ui->C;
  4477. laColumn *ic = lst->pFirst;
  4478. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4479. for (ic; ic; ic = ic->Item.pNext){
  4480. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4481. ic->B = ic->B < c->B ? c->B : ic->B;
  4482. }
  4483. }
  4484. ic = ui->C;
  4485. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4486. ;
  4487. for (ic; ic; ic = ic->Item.pNext){
  4488. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4489. ic->B = ic->B < c->B ? c->B : ic->B;
  4490. }
  4491. }
  4492. }
  4493. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4494. int rep;
  4495. int sp;
  4496. int rev;
  4497. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4498. if (!c) return 0;
  4499. sp = (c->SP * (R - L)) + L;
  4500. rev = sp;
  4501. /*if (U)*/ c->B = U;
  4502. if (LR == 1){
  4503. c->IL = L;
  4504. c->IR = sp;
  4505. if (repos){
  4506. c->IR = repos;
  4507. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4508. c->IR = c->IL + c->MaxW*LA_RH+M;
  4509. rev = c->IR;
  4510. }
  4511. }else if (LR == 2){
  4512. c->IL = sp;
  4513. c->IR = R;
  4514. if (repos){
  4515. c->IL = repos;
  4516. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4517. c->IL = c->IR - c->MaxW*LA_RH-M;
  4518. rev = c->IL;
  4519. }
  4520. }else if (LR == 0){
  4521. c->IL = L;
  4522. c->IR = R;
  4523. }
  4524. if (c->LS && c->RS->MaxW == 0){
  4525. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4526. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4527. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4528. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4529. }else if (c->RS && c->LS->MaxW == 0){
  4530. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4531. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4532. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4533. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4534. }
  4535. return rev;
  4536. }
  4537. STRUCTURE(laRowInfo){
  4538. int MaxW;
  4539. int MinW;
  4540. int UnitMinW;
  4541. int NonExpandW;
  4542. int TotalPadding;
  4543. int Expand, Even;
  4544. int ExpandAccum;
  4545. int CountElements;
  4546. int U,MaxB,L;
  4547. laListHandle Elements;
  4548. int LastNoHeight;
  4549. };
  4550. STRUCTURE(laRowNode){
  4551. laListItem Item;
  4552. laUiItem* ui;
  4553. int GotW, LP, RP, H;
  4554. int Expand;
  4555. int UseLast;
  4556. };
  4557. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4558. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4559. ri->UnitMinW=LA_RH;
  4560. ri->Expand=ui->State?1:0;
  4561. ri->Even=ui->Flags?1:0;
  4562. ri->U=ui->TU; ri->L=ui->TL;
  4563. ri->MaxB=ui->TU;
  4564. }
  4565. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H){
  4566. laRowNode* rn=CreateNew(laRowNode);
  4567. rn->LP=bt->LP;rn->RP=bt->RP;
  4568. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4569. rn->ui=ui;
  4570. rn->H=H;
  4571. rn->Expand=ui->Expand;
  4572. lstAppendItem(&ri->Elements, rn);
  4573. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4574. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4575. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4576. ri->TotalPadding += (bt->LP+bt->RP);
  4577. ri->MinW+=ri->UnitMinW;
  4578. ri->NonExpandW+=rn->GotW;
  4579. ri->ExpandAccum+=ui->Expand;
  4580. ri->CountElements++;
  4581. if(ui->Expand){ri->Expand=1;}
  4582. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4583. }
  4584. int la_ShrinkableRowElements(laRowInfo* ri){
  4585. int count=0;
  4586. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4587. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4588. count++;
  4589. }
  4590. return count;
  4591. }
  4592. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4593. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end, int WaitAnimation){
  4594. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4595. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4596. if(Available<0){
  4597. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4598. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4599. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4600. }else{
  4601. if(!ri->Expand && Available>0){Available=0;}
  4602. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4603. }
  4604. if(!ShareCount) return 0;
  4605. int PerNode = Available/ShareCount;
  4606. int Remaining = Available-PerNode*ShareCount;
  4607. int L = ri->L; int i=0; laRowNode* rn;
  4608. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4609. laUiItem* ui=rn->ui;
  4610. int NodeAdd, Node=rn->GotW;
  4611. if(rn->UseLast){
  4612. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4613. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4614. continue;
  4615. }
  4616. if(Available>=0){
  4617. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4618. NodeAdd+=(i<Remaining?1:0);i++;
  4619. }else{
  4620. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4621. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4622. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4623. }else{ Node=ri->UnitMinW;
  4624. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4625. }
  4626. }
  4627. ui->TL = L + rn->LP;
  4628. ui->TR = ui->TL + Node+NodeAdd;
  4629. ui->TB = ui->TU + rn->H;
  4630. L=ui->TR+rn->RP;
  4631. if (!WaitAnimation){
  4632. ui->L = ui->TL; ui->R = ui->TR;
  4633. ui->U = ui->TU; ui->B = ui->TB;
  4634. }
  4635. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4636. }
  4637. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  4638. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  4639. memset(ri, 0, sizeof(laRowInfo));
  4640. }
  4641. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4642. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4643. int sl,sr,su,sb;
  4644. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4645. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4646. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4647. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4648. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4649. if(pc==LA_PC_SOCKET_OUT){
  4650. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4651. }else{
  4652. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4653. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4654. }
  4655. }
  4656. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4657. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4658. }
  4659. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4660. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4661. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4662. laBoxedTheme *bt;
  4663. int Lowest = 0;
  4664. int HyperValue = 0;
  4665. int WaitAnimation;
  4666. int RowMode=0; laRowInfo ri={0};
  4667. laBoxedTheme* pt=*(ParentPanel->BT);
  4668. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4669. int MaxR=0;
  4670. if(!uil->Scale){uil->Scale=1;}
  4671. uil->SaveScale=MAIN.UiScale;
  4672. MAIN.UiScale*=uil->Scale;
  4673. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4674. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4675. WaitAnimation = 0;
  4676. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4677. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4678. for (ui = uil->UiItems.pFirst; ui;){
  4679. int SubB = 0;
  4680. int H;
  4681. WaitAnimation = 0;
  4682. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4683. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4684. //if (Fast && ui->C->B > B) {
  4685. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4686. // ui = ui->Item.pNext;
  4687. // continue;
  4688. //}
  4689. if (!ui->Instructions){
  4690. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4691. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4692. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4693. laOperatorProp *ap = ui->PP.LastPs->p;
  4694. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  4695. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  4696. }
  4697. }
  4698. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  4699. la_UsePropPack(&ui->PP, 0);
  4700. if (ui->CompoundPPs.pFirst){
  4701. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  4702. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  4703. }
  4704. }
  4705. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  4706. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  4707. // laUseDataBlock(ui->PP.Go ? ui->PP.LastPs->UseInstance : ui->PP.RawThis->LastPs->UseInstance, ui->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4708. //}
  4709. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  4710. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  4711. WaitAnimation = 1;
  4712. }
  4713. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  4714. bt = (*ui->Type->Theme);
  4715. if (ui->Type == &_LA_UI_CONDITION){
  4716. laConditionUiExtraData *cued = ui->Extra;
  4717. la_StepExpression(cued->Expression);
  4718. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4719. if (!cued->IsTrue){
  4720. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4721. }else{
  4722. ui = ui->Item.pNext;
  4723. }
  4724. continue;
  4725. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4726. ui = ui->Item.pNext;
  4727. continue;
  4728. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4729. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4730. if (cued->IsTrue) ui = cued->EndUi;
  4731. else
  4732. ui = ui->Item.pNext;
  4733. continue;
  4734. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4735. laConditionUiExtraData *cued = ui->Extra;
  4736. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  4737. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  4738. if (!WaitAnimation){
  4739. ui->L = ui->TL; ui->R = ui->TR;
  4740. ui->U = ui->TU; ui->B = ui->TB;
  4741. }
  4742. if(!RowMode){
  4743. la_CalcUiItemInfluence(&uil->Columns, ui);
  4744. }else{
  4745. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4746. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4747. }
  4748. if (ui->State == LA_UI_NORMAL){
  4749. cued->IsTrue = 0;
  4750. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  4751. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  4752. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4753. }else{
  4754. cued->IsTrue = 1;
  4755. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  4756. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  4757. //}
  4758. ui = ui->Item.pNext;
  4759. }
  4760. continue;
  4761. }
  4762. if (ui->Type == _LA_UI_ALIGN){
  4763. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  4764. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4765. if (ui->TB > Lowest) Lowest = ui->TB;
  4766. if (!WaitAnimation){
  4767. ui->L = ui->TL; ui->R = ui->TR;
  4768. ui->U = ui->TU; ui->B = ui->TB;
  4769. }
  4770. if(!RowMode){
  4771. la_CalcUiItemInfluence(&uil->Columns, ui);
  4772. }else{
  4773. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  4774. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4775. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4776. }
  4777. ui = ui->Item.pNext; continue;
  4778. }
  4779. if (ui->Type == &_LA_UI_ROW_BEGIN){
  4780. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4781. la_InitRowNode(&ri, ui, bt);
  4782. RowMode=1; ui=ui->Item.pNext; continue;
  4783. }
  4784. if (ui->Type == &_LA_UI_ROW_END){
  4785. la_CalculateRowExpand(&ri, ui, WaitAnimation);
  4786. la_CalcUiItemInfluence(&uil->Columns, ui);
  4787. RowMode=0; ui=ui->Item.pNext; continue;
  4788. }
  4789. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  4790. int GB=0;
  4791. if (ui->Type == _LA_UI_FIXED_GROUP && ui->Page->HeightCoeff < 0 && ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM){ GB=ui->Page->TB-ui->Page->PanY; }
  4792. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4793. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  4794. if (H < 0){
  4795. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  4796. else{ H=LA_RH; }
  4797. }
  4798. else H *= LA_RH;
  4799. ui->TB = ui->TU;
  4800. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4801. if (ui->Type->ForType == LA_PROP_SUB && ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS){ //DynamicCreation
  4802. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  4803. if (ui->Type == _LA_UI_COLLECTION){
  4804. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  4805. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4806. ui->PP.EndInstance = TInstance;
  4807. laUiList *iuil = ui->Subs.pFirst;
  4808. laUiList *puil = iuil;
  4809. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  4810. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  4811. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4812. int Begin = ui->TB;
  4813. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  4814. int ElementB = ui->TU;
  4815. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  4816. int MaxB = ElementB;
  4817. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4818. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  4819. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  4820. if (!ElementLimit) RowPriority = 0;
  4821. if (!TInstance){
  4822. while (iuil){
  4823. puil = iuil->Item.pNext;
  4824. la_DestroyTabPage(ui, iuil, 0);
  4825. iuil = puil;
  4826. }
  4827. }
  4828. while (TInstance){
  4829. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  4830. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4831. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4832. ui->PP.EndInstance = TInstance; continue;
  4833. }
  4834. if(CanGetTheme){
  4835. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4836. la_SwitchThemeQuick(t, OriginalTheme);
  4837. }
  4838. if(CanGetGap){
  4839. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  4840. Gap=g*LA_RH;
  4841. }else Gap=0;
  4842. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  4843. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  4844. }else GotCategory=0;
  4845. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  4846. if (RowPriority){
  4847. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  4848. }
  4849. }
  4850. FirstIn=0;
  4851. if (ElementLimit){
  4852. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  4853. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  4854. }
  4855. while (iuil && iuil->Instance != TInstance){
  4856. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  4857. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  4858. }else{
  4859. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  4860. }
  4861. iuil = puil;
  4862. }
  4863. if(!iuil){
  4864. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  4865. }
  4866. if (!iuil){
  4867. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  4868. la_CalcUiTopInfluence(&uil->Columns, ui);
  4869. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4870. SubB = la_UpdateUiListRecursive(ui->Page, Gap+Begin+(NoDecal?0:bt->TM), EL+(NoDecal?0:bt->LM), ER-(NoDecal?0:bt->RM), B, Fast, ParentPanel) +(NoDecal?0:bt->TM);
  4871. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4872. iuil = ui->Page->Item.pNext;
  4873. }else{
  4874. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  4875. SubB = la_UpdateUiListRecursive(iuil, Gap+Begin+(NoDecal?0:bt->TM), EL+(NoDecal?0:bt->LM), ER-(NoDecal?0:bt->RM), B, Fast, ParentPanel) + (NoDecal?0:bt->TM);
  4876. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4877. la_CalcUiItemInfluence(&uil->Columns, ui);
  4878. iuil = iuil->Item.pNext;
  4879. }
  4880. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4881. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4882. ui->PP.EndInstance = TInstance;
  4883. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4884. if (RowPriority){
  4885. Col += 1;
  4886. if (Col >= ElementLimit){
  4887. Col = 0;
  4888. Row += 1;
  4889. Begin = ElementB + bt->TM;
  4890. }
  4891. }elif(Spread){
  4892. EL+=Spread*LA_RH;
  4893. ER+=Spread*LA_RH;
  4894. }else{
  4895. Row += 1;
  4896. Begin = ElementB + bt->TM;
  4897. if (ElementLimit && Row >= ElementLimit){
  4898. Row = 0;
  4899. Col += 1;
  4900. Begin = ui->TU + bt->TM;
  4901. }
  4902. }
  4903. ui->TB = ElementB;
  4904. MaxB = MaxB < ElementB ? ElementB : MaxB;
  4905. }
  4906. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  4907. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  4908. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4909. ui->TB = MaxB;
  4910. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  4911. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  4912. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  4913. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  4914. ui->TB=ui->TU+LA_RH;
  4915. }else{
  4916. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4917. ui->PP.EndInstance = TInstance;
  4918. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4919. if(!Template) Template=laui_SubPropInfoDefault;
  4920. //ui->Template = Template;
  4921. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  4922. if (!ui->Subs.pFirst && TInstance){
  4923. la_AddInstancePage(ui, TInstance, 0);
  4924. la_CalcUiTopInfluence(&uil->Columns, ui);
  4925. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4926. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  4927. ui->TB = SubB + (NoDecal?0:bt->BM);
  4928. }else if (ui->Subs.pFirst){
  4929. if (!TInstance || TInstance != ui->Page->Instance){
  4930. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  4931. ui->Page = 0;
  4932. if (TInstance){
  4933. la_AddInstancePage(ui, TInstance, 0);
  4934. la_CalcUiTopInfluence(&uil->Columns, ui);
  4935. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4936. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  4937. ui->TB = SubB + (NoDecal?0:bt->TM);
  4938. }else
  4939. ui->TB = ui->TU + LA_RH + bt->BM;
  4940. }else{
  4941. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  4942. ui->TB = SubB + (NoDecal?0:bt->BM);
  4943. }
  4944. }
  4945. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  4946. ui->TB=ui->TU+LA_RH;
  4947. }
  4948. }
  4949. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  4950. if (!WaitAnimation){
  4951. ui->L = ui->TL;
  4952. ui->R = ui->TR;
  4953. ui->U = ui->TU;
  4954. ui->B = ui->TB;
  4955. }
  4956. }
  4957. }else{
  4958. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4959. if (ui->Type != _LA_UI_CANVAS){
  4960. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  4961. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  4962. SubB = la_UpdateUiListRecursive(ui->Page,
  4963. ui->TB + (ui->State == LA_UI_ACTIVE ? 0 : LA_RH)+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-scrollw, B, Fast, ParentPanel);
  4964. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  4965. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  4966. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  4967. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  4968. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  4969. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  4970. }
  4971. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  4972. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  4973. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  4974. if(ui->Page->HeightCoeff){
  4975. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  4976. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  4977. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  4978. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  4979. }
  4980. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  4981. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  4982. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  4983. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  4984. }
  4985. }
  4986. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  4987. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  4988. }else{
  4989. laUiList *suil;
  4990. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  4991. la_CalcUiTopInfluence(&uil->Columns, ui);
  4992. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4993. SubB = la_UpdateUiListRecursive(suil, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), ui->TU+H, Fast, ParentPanel);
  4994. }
  4995. }
  4996. ui->TB = ui->TU + H;
  4997. }
  4998. }else ui->TB = ui->TU + H;
  4999. }
  5000. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5001. if(!RowMode){
  5002. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5003. }else{
  5004. la_AddRowNode(&ri, ui, bt, H);
  5005. }
  5006. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5007. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5008. ui = ui->Item.pNext;
  5009. }
  5010. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5011. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5012. else uil->TB = Lowest;
  5013. if (!WaitAnimation){
  5014. uil->L = uil->TL;
  5015. uil->R = uil->TR;
  5016. uil->U = uil->TU;
  5017. uil->B = uil->TB;
  5018. }
  5019. MAIN.UiScale=uil->SaveScale;
  5020. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5021. return uil->TB;
  5022. }
  5023. int la_AnimateSingleUiSize(int To, int *Now){
  5024. int Delta;
  5025. if (To != *Now){
  5026. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5027. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5028. *Now += Delta;
  5029. return 1;
  5030. }else
  5031. return 0;
  5032. }
  5033. int la_AnimateUiListRecursive(laUiList *uil){
  5034. laUiItem *ui;
  5035. int Again = 0;
  5036. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5037. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5038. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5039. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5040. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5041. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5042. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5043. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5044. laUiList *suil;
  5045. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5046. Again += la_AnimateUiListRecursive(suil);
  5047. }
  5048. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5049. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5050. Again += la_AnimateUiListRecursive(ui->Page);
  5051. }
  5052. }
  5053. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5054. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5055. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5056. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5057. return Again;
  5058. }
  5059. int la_DrawUiItem(laUiItem *ui){
  5060. tnsUseNoTexture();
  5061. tnsColor4d(1, 1, 1, 1);
  5062. tnsVertex2d(ui->L, ui->U);
  5063. tnsVertex2d(ui->R, ui->U);
  5064. tnsVertex2d(ui->R, ui->B);
  5065. tnsVertex2d(ui->L, ui->B);
  5066. tnsPackAs(GL_LINE_LOOP);
  5067. }
  5068. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5069. tnsUseNoTexture();
  5070. tnsColor4d(1, 1, 1, 1);
  5071. tnsVertex2d(ui->L - 1, ui->U - 1);
  5072. tnsVertex2d(ui->R + 1, ui->U - 1);
  5073. tnsVertex2d(ui->R + 1, ui->B + 1);
  5074. tnsVertex2d(ui->L - 1, ui->B + 1);
  5075. tnsPackAs(GL_LINE_LOOP);
  5076. }
  5077. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5078. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5079. return 1;
  5080. }
  5081. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5082. laUiListDrawItem *uildi = uild->Items.pFirst;
  5083. laUiList *Target = uildi->Target;
  5084. int L, R, U, B;
  5085. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5086. L = Target->L + Target->PanX + uildi->DifX;
  5087. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5088. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5089. U = Target->U + Target->PanY + uildi->DifY;
  5090. return la_UiInBound(ui, L, R, U, B);
  5091. }
  5092. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5093. laUiListDrawItem *uildi = uild->Items.pFirst;
  5094. laUiList *Target = uildi->Target;
  5095. int L, R, U, B;
  5096. if (Target){
  5097. L = Target->L + Target->PanX + uildi->DifX;
  5098. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5099. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5100. U = Target->U + Target->PanY + uildi->DifY;
  5101. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5102. return 1;
  5103. }else{
  5104. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5105. return 1;
  5106. }
  5107. }
  5108. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5109. laUiItem *ui = uil->UiItems.pFirst;
  5110. while (!strGetArgument(ui->Instructions, mark))
  5111. ui = ui->Item.pNext;
  5112. return ui;
  5113. }
  5114. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5115. laUiList *uil;
  5116. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5117. if (uil->Instance == Instance) return uil;
  5118. }
  5119. return uil;
  5120. }
  5121. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5122. int mx=(L+R)/2; int my=(U+B)/2;
  5123. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5124. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5125. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5126. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5127. tnsFlush();
  5128. }
  5129. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5130. if(!uil->ScrollerShownV) return;
  5131. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5132. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5133. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5134. int U = uil->U + Offset;
  5135. int B = U + Len;
  5136. int L = UiR - RM*2 - W;
  5137. int R = L + W;
  5138. if (B > U + DisplayH) B = U + DisplayH;
  5139. if (U < uil->U) U = uil->U;
  5140. if (B <= uil->U || U >= uil->B) return;
  5141. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5142. if (U < uil->U) U = uil->U;
  5143. tnsUseNoTexture();
  5144. laBoxedTheme* bt=_LA_THEME_PANEL;
  5145. real* color=laThemeColor(bt, LA_BT_TEXT);
  5146. tnsColor4d(LA_COLOR3(color), 0.2);
  5147. tnsVertex2d(R-RM, uil->U);
  5148. tnsVertex2d(L+RM, uil->U);
  5149. tnsVertex2d(L+RM, uil->U + DisplayH);
  5150. tnsVertex2d(R-RM, uil->U + DisplayH);
  5151. tnsPackAs(GL_TRIANGLE_FAN);
  5152. tnsColor4d(LA_COLOR3(color), 0.5);
  5153. tnsVertex2d(R-RM, uil->U);
  5154. tnsVertex2d(L+RM, uil->U);
  5155. tnsVertex2d(L+RM, uil->U + DisplayH);
  5156. tnsVertex2d(R-RM, uil->U + DisplayH);
  5157. tnsPackAs(GL_LINE_LOOP);
  5158. tnsColor4d(LA_COLOR3(color), 1);
  5159. tnsVertex2d(R, U);
  5160. tnsVertex2d(L, U);
  5161. tnsVertex2d(L, B);
  5162. tnsVertex2d(R, B);
  5163. tnsPackAs(GL_TRIANGLE_FAN);
  5164. int HU=(U+B)/2+LA_RH2;
  5165. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5166. tnsFlush();
  5167. }
  5168. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5169. if(!uil->ScrollerShownH) return;
  5170. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5171. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5172. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5173. int L = uil->L + Offset;
  5174. int R = L + Len;
  5175. int U = UiB - RM - W;
  5176. int B = U + W;
  5177. if (B > U + DisplayW) B = U + DisplayW;
  5178. if (U < uil->U) U = uil->U;
  5179. if (R <= uil->L || L >= uil->R) return;
  5180. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5181. if (L < uil->L) L = uil->L;
  5182. tnsUseNoTexture();
  5183. laBoxedTheme* bt=_LA_THEME_PANEL;
  5184. real* color=laThemeColor(bt, LA_BT_TEXT);
  5185. tnsColor4d(LA_COLOR3(color), 0.2);
  5186. tnsVertex2d(uil->L,U+RM);
  5187. tnsVertex2d(uil->L,B-RM);
  5188. tnsVertex2d(uil->L + DisplayW,B-RM);
  5189. tnsVertex2d(uil->L + DisplayW,U+RM);
  5190. tnsPackAs(GL_TRIANGLE_FAN);
  5191. tnsColor4d(LA_COLOR3(color), 0.5);
  5192. tnsVertex2d(uil->L,U+RM);
  5193. tnsVertex2d(uil->L,B-RM);
  5194. tnsVertex2d(uil->L + DisplayW,B-RM);
  5195. tnsVertex2d(uil->L + DisplayW,U+RM);
  5196. tnsPackAs(GL_LINE_LOOP);
  5197. tnsColor4d(LA_COLOR3(color), 1);
  5198. tnsVertex2d(R, U);
  5199. tnsVertex2d(L, U);
  5200. tnsVertex2d(L, B);
  5201. tnsVertex2d(R, B);
  5202. tnsPackAs(GL_TRIANGLE_FAN);
  5203. int HU=(U+B)/2+LA_RH2;
  5204. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5205. tnsFlush();
  5206. }
  5207. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5208. tnsUseNoTexture();
  5209. tnsColor4dv(color);
  5210. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5211. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5212. tnsPackAs(GL_TRIANGLE_FAN);
  5213. }
  5214. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5215. laSocketRecord* sr;
  5216. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5217. uild->WiresContainer=container;
  5218. }
  5219. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5220. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5221. if(lip->Target==uild->WiresContainer) break;
  5222. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5223. }
  5224. }
  5225. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5226. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5227. int PanX, PanY;
  5228. if(pc==LA_PC_SOCKET_OUT){
  5229. laNodeOutSocket* s=ui->PP.EndInstance;
  5230. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5231. }else{
  5232. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5233. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5234. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5235. }
  5236. }
  5237. void la_RegenerateWireColors(){
  5238. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5239. laTheme* t=MAIN.CurrentTheme;
  5240. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5241. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5242. for(int i=0;i<MAIN.WireColorSlices;i++){
  5243. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5244. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5245. }
  5246. }
  5247. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5248. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5249. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5250. tnsInterpolate2dv(v1,v2,0.5,vi);
  5251. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5252. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5253. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5254. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5255. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5256. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5257. tnsVertex2d(v1[0],v1[1]);
  5258. for(int i=1;i<=steps;i++){
  5259. real ratio=i==steps?1.0f:step*i;
  5260. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5261. tnsVertex2d(v1s[0],v1s[1]);
  5262. }
  5263. }
  5264. void la_DrawNodeWires(laUiListDraw* uild){
  5265. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5266. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5267. tnsUseNoTexture();
  5268. #define _RSLICES 16
  5269. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5270. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5271. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5272. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5273. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5274. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5275. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5276. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5277. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5278. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5279. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5280. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5281. }
  5282. if(MAIN.tNodeIn->Source){
  5283. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5284. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5285. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5286. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5287. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5288. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5289. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5290. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5291. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5292. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5293. }
  5294. #undef _RSLICES
  5295. tnsFlush();
  5296. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5297. glLineWidth(ww);
  5298. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5299. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5300. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5301. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5302. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5303. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5304. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5305. }
  5306. if(MAIN.tNodeIn->Source){
  5307. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5308. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5309. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5310. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5311. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5312. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5313. }
  5314. tnsFlush();
  5315. glLineWidth(1);
  5316. la_InitSocketRecord(uild,0);
  5317. }
  5318. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5319. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5320. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5321. }
  5322. int la_DrawUiListRecursive(laUiListDraw *uild, laUiList *uil, int L, int R, int U, int B, int LimH, int ConditionStackLevel, int GlobalX, int GlobalY, int RegisterNodes){
  5323. laUiItem *ui;
  5324. laBoxedTheme *bt;
  5325. laUiList *sub;
  5326. laUiListDrawItem *uildi;
  5327. int Ret = 0;
  5328. if (!uil) return 0;
  5329. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5330. ui = uil->UiItems.pFirst;
  5331. if(uil->PanY<0){uil->PanY=0;}
  5332. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5333. uil->SaveScale=MAIN.UiScale;
  5334. MAIN.UiScale*=uil->Scale;
  5335. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5336. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5337. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5338. if (ui->Type == &_LA_UI_CONDITION){
  5339. laConditionUiExtraData *cued = ui->Extra;
  5340. la_StepExpression(cued->Expression);
  5341. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5342. if (!cued->IsTrue){
  5343. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5344. }else{
  5345. ui = ui->Item.pNext;
  5346. }
  5347. continue;
  5348. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5349. ui = ui->Item.pNext;
  5350. continue;
  5351. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5352. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5353. if (cued->IsTrue) ui = cued->EndUi;
  5354. else
  5355. ui = ui->Item.pNext;
  5356. continue;
  5357. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5358. laConditionUiExtraData *cued = ui->Extra;
  5359. ui->Type->Draw(ui, LA_RH);
  5360. if (ui->State == LA_UI_NORMAL){
  5361. cued->IsTrue = 0;
  5362. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5363. }else{
  5364. cued->IsTrue = 1;
  5365. ui = ui->Item.pNext;
  5366. }
  5367. continue;
  5368. }
  5369. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5370. int NeedDraw=0;
  5371. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5372. if(NeedDraw){
  5373. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5374. }else{ ui->Type->Draw(ui, LA_RH); }
  5375. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5376. tnsFlush();
  5377. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5378. tnsResetViewMatrix();
  5379. }
  5380. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5381. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5382. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5383. tnsFlush();
  5384. }
  5385. }
  5386. if(NeedDraw || RegisterNodes){
  5387. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5388. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5389. ui->Type == _LA_UI_TAB ||
  5390. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5391. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5392. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5393. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5394. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5395. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5396. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5397. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5398. ui->Page->R-ui->Page->L-bt->RM-bt->LM, ui->R-ui->Page->L-bt->RM-bt->LM-(ui->Page->ScrollerShownV?LA_SCROLL_W:0),ui->B); }
  5399. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5400. ui->Page->B-ui->Page->U-(NoDecal?0:bt->TM-bt->BM), ui->B-ui->Page->U-(NoDecal?0:bt->TM-bt->BM)-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->RM:0),ui->R);
  5401. if (ui->Page->AllowScale){ la_DrawUiListArrows(ui->Page,ui->L, ui->R, ui->Page->U, ui->B-LA_SCROLL_W-bt->BM*2, laThemeColor(bt, LA_BT_BORDER)); }
  5402. }elif (ui->Type == _LA_UI_COLLECTION){
  5403. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5404. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5405. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5406. void* SaveInstance = ui->PP.EndInstance;
  5407. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5408. int State;
  5409. ui->PP.EndInstance = sub->Instance;
  5410. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5411. if(NeedDraw){ int drawn=0;
  5412. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5413. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5414. }
  5415. if (CanGetState && !drawn){
  5416. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5417. if(State >= 0){
  5418. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5419. }
  5420. }
  5421. }
  5422. if(sub->TabName && sub->TabName->Ptr){
  5423. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5424. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5425. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5426. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5427. tnsFlush();
  5428. }
  5429. if(CanGetTheme){
  5430. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5431. la_SwitchThemeQuick(t, OriginalTheme);
  5432. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5433. }
  5434. tnsFlush();
  5435. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5436. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5437. }
  5438. //ui->PP.EndInstance = Active;
  5439. ui->PP.EndInstance = SaveInstance;
  5440. }elif (ui->Type == _LA_UI_CANVAS){
  5441. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5442. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5443. tnsFlush();
  5444. Ret += la_DrawUiListRecursive(uild, sub, L-1, R+1, U-1, B+1, ui->B-bt->TP-bt->BP-bt->BM-bt->TM, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5445. }
  5446. }
  5447. }
  5448. ui = ui->Item.pNext;
  5449. }else{
  5450. ui = ui->Item.pNext;
  5451. }
  5452. }
  5453. tnsFlush();
  5454. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5455. la_RestoreLastUiListMatrix(uild, B - U);
  5456. MAIN.UiScale=uil->SaveScale;
  5457. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5458. return Ret;
  5459. }
  5460. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5461. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5462. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5463. tnsUseNoTexture();
  5464. tnsColor4d(1, 1, 1, 1);
  5465. tnsVertex2d(L, U);
  5466. tnsVertex2d(R, U);
  5467. tnsVertex2d(R, B);
  5468. tnsVertex2d(L, B);
  5469. tnsPackAs(GL_LINE_LOOP);
  5470. tnsVertex2d(L + 3, Begin);
  5471. tnsVertex2d(R - 3, Begin);
  5472. tnsVertex2d(R - 3, End);
  5473. tnsVertex2d(L + 3, End);
  5474. tnsPackAs(GL_LINE_LOOP);
  5475. }
  5476. int laIsInUiItem(laUiItem *ui, int x, int y){
  5477. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5478. return 1;
  5479. }
  5480. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5481. if (x < l || x > r || y < u || y > b) return 0;
  5482. return 1;
  5483. }
  5484. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5485. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5486. laUiItem *ui, *tui;
  5487. laBoxedTheme *bt;
  5488. laUiList *sub;
  5489. int CPB = 0;
  5490. if (!uil || (LimB && y > LimB)) return 0;
  5491. x += uil->PanX;
  5492. y += uil->PanY;
  5493. for (ui = uil->UiItems.pFirst; ui;){
  5494. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5495. if (ui->Type == &_LA_UI_CONDITION){
  5496. laConditionUiExtraData *cued = ui->Extra;
  5497. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5498. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5499. if (!cued->IsTrue){
  5500. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5501. }else{
  5502. ui = ui->Item.pNext;
  5503. }
  5504. continue;
  5505. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5506. ui = ui->Item.pNext;
  5507. continue;
  5508. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5509. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5510. if (cued->IsTrue) ui = cued->EndUi;
  5511. else
  5512. ui = ui->Item.pNext;
  5513. continue;
  5514. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5515. laConditionUiExtraData *cued = ui->Extra;
  5516. if (laIsInUiItem(ui, x, y)){
  5517. lstAppendPointer(LocalBuf, uil);
  5518. return ui;
  5519. }
  5520. if (ui->State == LA_UI_NORMAL){
  5521. cued->IsTrue = 0;
  5522. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5523. }else{
  5524. cued->IsTrue = 1;
  5525. ui = ui->Item.pNext;
  5526. }
  5527. continue;
  5528. }
  5529. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5530. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5531. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5532. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5533. if(!la_DetectSplit(ui->C, x)) Add=0;
  5534. }
  5535. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5536. }
  5537. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5538. if (ui->Page->HeightCoeff) CPB = ui->B;
  5539. else CPB = ui->Page->B;
  5540. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5541. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5542. lstAppendPointer(LocalBuf, uil);
  5543. return tui;
  5544. }
  5545. }else if (laIsInUiItem(ui, x, y)){
  5546. lstAppendPointer(LocalBuf, uil);return ui;
  5547. }
  5548. }
  5549. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5550. if (laIsInUiItem(ui, x, y)){
  5551. lstAppendPointer(LocalBuf, uil);
  5552. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5553. if(Deep){
  5554. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5555. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5556. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5557. lstAppendPointer(LocalBuf, iuil);
  5558. return tui;
  5559. }
  5560. }
  5561. }
  5562. }
  5563. return ui;
  5564. }
  5565. }
  5566. if (ui->Type == _LA_UI_CANVAS){
  5567. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5568. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5569. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5570. lstAppendPointer(LocalBuf, uil);
  5571. return tui;
  5572. }
  5573. }
  5574. }
  5575. if (laIsInUiItem(ui, x, y)){
  5576. lstAppendPointer(LocalBuf, uil);
  5577. return ui;
  5578. }
  5579. }
  5580. ui = ui->Item.pNext;
  5581. }
  5582. return 0;
  5583. }
  5584. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5585. laListHandle Locals={0};
  5586. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5587. while(lstPopPointer(&Locals));
  5588. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5589. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5590. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5591. if(pc==PCInOrOut) return ui;
  5592. }
  5593. return 0;
  5594. }
  5595. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5596. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5597. laUiItem *ui = uil->UiItems.pFirst;
  5598. laBoxedTheme *bt;
  5599. laUiList *tuil;
  5600. laUiList *sub;
  5601. int CPB = 0;
  5602. x += uil->PanX;
  5603. y += uil->PanY;
  5604. if (y > LimH) return uil;
  5605. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5606. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5607. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5608. return uil;
  5609. }
  5610. for (ui = uil->UiItems.pFirst; ui;){
  5611. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5612. if (ui->Type == &_LA_UI_CONDITION){
  5613. laConditionUiExtraData *cued = ui->Extra;
  5614. //la_StepExpression(cued->Expression);
  5615. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5616. if (!cued->IsTrue){
  5617. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5618. }else{
  5619. ui = ui->Item.pNext;
  5620. }
  5621. continue;
  5622. }
  5623. if (ui->Type == &_LA_UI_CONDITION_END){
  5624. ui = ui->Item.pNext;
  5625. continue;
  5626. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5627. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5628. if (cued->IsTrue) ui = cued->EndUi;
  5629. else
  5630. ui = ui->Item.pNext;
  5631. continue;
  5632. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5633. laConditionUiExtraData *cued = ui->Extra;
  5634. if (ui->State == LA_UI_NORMAL){
  5635. cued->IsTrue = 0;
  5636. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5637. }else{
  5638. cued->IsTrue = 1;
  5639. ui = ui->Item.pNext;
  5640. }
  5641. continue;
  5642. }
  5643. if (InToContainerUI && ui != Exception){
  5644. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5645. if (ContainerParent) (*ContainerParent) = uil;
  5646. if (ParentUi) *ParentUi = ui;
  5647. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5648. //if (y > LimH) return uil;
  5649. if (laIsInBound(x, y, sub->L, sub->R, sub->U, sub->B) && (tuil = la_DetectUiListRecursive(sub, x, y, ui->B, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception))){
  5650. return tuil;
  5651. }
  5652. }
  5653. }
  5654. }
  5655. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5656. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  5657. else CPB = ui->Page->B+ui->Page->PanY;
  5658. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5659. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5660. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5661. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5662. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5663. if (ParentUi) *ParentUi = ui;
  5664. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5665. }
  5666. }
  5667. ui = ui->Item.pNext;
  5668. }
  5669. return uil;
  5670. }
  5671. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5672. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5673. laUiItem *ui = uil->UiItems.pFirst;
  5674. laBoxedTheme *bt;
  5675. laUiList *tuil;
  5676. laUiList *sub;
  5677. int CPB = 0;
  5678. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5679. x += uil->PanX;
  5680. y += uil->PanY;
  5681. if (y > LimH) return uil;
  5682. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5683. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5684. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5685. return uil;
  5686. }
  5687. for (ui = uil->UiItems.pFirst; ui;){
  5688. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5689. if (ui->Type == &_LA_UI_CONDITION){
  5690. laConditionUiExtraData *cued = ui->Extra;
  5691. //la_StepExpression(cued->Expression);
  5692. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5693. if (!cued->IsTrue){
  5694. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5695. }else{
  5696. ui = ui->Item.pNext;
  5697. }
  5698. continue;
  5699. }
  5700. if (ui->Type == &_LA_UI_CONDITION_END){
  5701. ui = ui->Item.pNext;
  5702. continue;
  5703. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5704. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5705. if (cued->IsTrue) ui = cued->EndUi;
  5706. else
  5707. ui = ui->Item.pNext;
  5708. continue;
  5709. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5710. laConditionUiExtraData *cued = ui->Extra;
  5711. if (ui->State == LA_UI_NORMAL){
  5712. cued->IsTrue = 0;
  5713. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5714. }else{
  5715. cued->IsTrue = 1;
  5716. ui = ui->Item.pNext;
  5717. }
  5718. continue;
  5719. }
  5720. if (InToContainerUI && ui != Exception){
  5721. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5722. if (ContainerParent) (*ContainerParent) = uil;
  5723. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5724. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5725. //if (y > LimH) return uil;
  5726. if (laIsInBound(x, y, sub->L, sub->R, sub->U, sub->B) && (tuil = la_DetectUiListRecursiveDeep(sub, x, y, ui->B, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels))){
  5727. return tuil;
  5728. }
  5729. }
  5730. }
  5731. }
  5732. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5733. if (ui->Page->HeightCoeff) CPB = ui->B;
  5734. else CPB = ui->Page->B;
  5735. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5736. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5737. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5738. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5739. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5740. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5741. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5742. }
  5743. }
  5744. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  5745. if (ui->Page->HeightCoeff) CPB = ui->B;
  5746. else
  5747. CPB = ui->Page->B;
  5748. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  5749. if (ScrollUil) *ScrollUil = ui->Page;
  5750. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5751. }
  5752. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5753. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5754. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5755. }
  5756. }
  5757. ui = ui->Item.pNext;
  5758. }
  5759. return uil;
  5760. }
  5761. int la_TestUiListMinumWidth(laUiList *uil){
  5762. laUiItem *ui, *tui;
  5763. laBoxedTheme *bt;
  5764. laUiList *sub;
  5765. int CPB = 0;
  5766. int W = 0;
  5767. int tW, sW, RowMode=0, rW;
  5768. void *Restore;
  5769. for (ui = uil->UiItems.pFirst; ui;){
  5770. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5771. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5772. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  5773. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5774. if (W < tW) W = tW;
  5775. }elif (ui->Type == _LA_UI_COLLECTION){
  5776. Restore = ui->PP.EndInstance;
  5777. tW = 0; sW = 0;
  5778. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5779. ui->PP.EndInstance = sub->Instance;
  5780. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  5781. if (sW > tW) tW = sW;
  5782. }
  5783. ui->PP.EndInstance = Restore;
  5784. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5785. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  5786. if (W < tW) W = tW;
  5787. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  5788. RowMode=1; rW=0;
  5789. }elif (ui->Type==&_LA_UI_ROW_END){
  5790. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  5791. }elif (ui->Type->GetMinWidth){
  5792. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  5793. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  5794. }
  5795. ui = ui->Item.pNext;
  5796. }
  5797. return W;
  5798. }
  5799. void la_InitLLVM(){
  5800. //LLVMLinkInMCJIT();
  5801. //LLVMInitializeNativeTarget();
  5802. //LLVMInitializeNativeAsmPrinter();
  5803. //LLVMInitializeNativeAsmParser();
  5804. // MAIN.llvmContext = LLVMGetGlobalContext();
  5805. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  5806. }
  5807. //==================================================================================================
  5808. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  5809. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  5810. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  5811. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  5812. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  5813. memFree(kmi);
  5814. }
  5815. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  5816. laKeyMapItem *kmi;
  5817. if (!km) return 0;
  5818. kmi = memAcquire(sizeof(laKeyMapItem));
  5819. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  5820. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  5821. }else{
  5822. strSafeSet(&kmi->Operation, Operation);
  5823. }
  5824. strSafeSet(&kmi->Instructions, ExtraInstructions);
  5825. kmi->SpecialKeyBits = SpecialKeyBits;
  5826. kmi->EventType = EventType;
  5827. kmi->Key = tolowerGuarded(Key);
  5828. kmi->SelectBase = SelectBase;
  5829. lstAppendItem(&km->Items, kmi);
  5830. return kmi;
  5831. }
  5832. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  5833. laKeyMapItem *kmi; int inv=0;
  5834. char *instructions;
  5835. if(e->type==LA_MOUSEMOVE) return 0;
  5836. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5837. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5838. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5839. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5840. if (kmi->Operation)
  5841. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5842. else
  5843. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5844. inv = 1;
  5845. }
  5846. }
  5847. return inv;
  5848. }
  5849. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  5850. laKeyMapItem *kmi;
  5851. char *instructions;
  5852. int inv = 0; int lx = -1, ly = -1;
  5853. if(e->type==LA_MOUSEMOVE) return 0;
  5854. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5855. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5856. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5857. if (e->Localized){
  5858. lx = e->x;
  5859. ly = e->y;
  5860. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  5861. e->Localized = 0;
  5862. }
  5863. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5864. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  5865. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  5866. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  5867. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  5868. }elif (kmi->Operation){
  5869. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5870. }else{
  5871. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5872. }
  5873. inv = 1;
  5874. if (lx >= 0){
  5875. e->x = lx;
  5876. e->y = ly;
  5877. e->Localized = 1;
  5878. }
  5879. }
  5880. }
  5881. return inv;
  5882. }
  5883. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  5884. void la_DestroyOperatorType(laOperatorType* at){
  5885. //if(at->PC) la_FreePropertyContainer(at->PC);
  5886. memFree(at);
  5887. }
  5888. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  5889. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  5890. uint32_t IconID, int ExtraMark){
  5891. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  5892. at->Identifier = ID;
  5893. at->Name = Name;
  5894. at->Description = Description;
  5895. at->Check = Check;
  5896. at->Invoke = Invoke;
  5897. at->Init = Init;
  5898. at->Exit = Exit;
  5899. at->Modal = Modal;
  5900. at->IconID = IconID;
  5901. at->ExtraMark = ExtraMark;
  5902. at->ParseArgs = la_DefaultOperatorParser;
  5903. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  5904. return at;
  5905. }
  5906. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  5907. ot->PC = memAcquire(sizeof(laPropContainer));
  5908. ot->PC->Identifier = ot->Identifier;
  5909. ot->PC->Hyper = HyperLevel;
  5910. return ot->PC;
  5911. }
  5912. laOperator *la_CreateOperator(laOperatorType *at){
  5913. laOperator *a = CreateNew(laOperator);
  5914. a->Type = at;
  5915. if (at->PC && at->PC->Props.pFirst){
  5916. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  5917. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  5918. a->PP.LastPs->p->SubProp = at->PC;
  5919. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  5920. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  5921. a->PP.LastPs->Type = U'.';
  5922. }
  5923. return a;
  5924. }
  5925. int la_OperatorTypeByID(laOperatorType *a, char *id){
  5926. return (!strcmp(a->Identifier, id));
  5927. }
  5928. laOperatorType *laGetOperatorType(const char *ID){
  5929. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5930. }
  5931. int laOperatorExistsT(laOperatorType* at){
  5932. if (!at) return 0;
  5933. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  5934. return 0;
  5935. }
  5936. int laOperatorExists(const char* ID){
  5937. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  5938. return laOperatorExistsT(at);
  5939. }
  5940. int la_OperatorExists(laOperator *ac){
  5941. if (!ac) return 0;
  5942. laOperator *a;
  5943. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  5944. return 0;
  5945. }
  5946. int la_UiOperatorExists(void *inst){
  5947. laOperator *a;
  5948. if (!inst) return 0;
  5949. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  5950. if (((laUiItem *)a->Instance) == inst){
  5951. return 1;
  5952. }
  5953. }
  5954. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5955. if (a->Instance == inst){
  5956. return 1;
  5957. }
  5958. }
  5959. return 0;
  5960. }
  5961. int la_OperatorPending(laOperator *target){
  5962. laOperator *a;
  5963. if (!target) return 0;
  5964. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5965. if (a == target){
  5966. return 1;
  5967. }
  5968. }
  5969. return 0;
  5970. }
  5971. void laSetOperatorLocalizer(void *ToPanel){
  5972. MAIN.ToPanel = ToPanel;
  5973. }
  5974. void la_DestroyConfirmData(laConfirmData **cd);
  5975. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  5976. laOperator *ai = (*a);
  5977. laOperator *ac = ((*a)->Child);
  5978. void *Ret = 0;
  5979. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  5980. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  5981. }
  5982. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  5983. if ((*a)->PP.LastPs){
  5984. memFree((*a)->PP.LastPs->p);
  5985. memFree((*a)->PP.LastPs);
  5986. }
  5987. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  5988. la_SetPropMathcerContext((*a)->OperatorPanel);
  5989. MAIN.CurrentPanel = (*a)->OperatorPanel;
  5990. laDestroySinglePanel((*a)->OperatorPanel,0);
  5991. }
  5992. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  5993. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  5994. lstClearPointer(&(*a)->LocalUiLists);
  5995. if (Operators){
  5996. Ret = ai->Item.pNext;
  5997. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  5998. else
  5999. lstRemoveItem(Operators, *a);
  6000. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6001. if (ai->Child == (*a)) ai->Child = 0;
  6002. }
  6003. }
  6004. strSafeDestroy(&(*a)->RuntimeHint);
  6005. free(*a);
  6006. return Ret;
  6007. }
  6008. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6009. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6010. if (!at) return 0;
  6011. if (!at->Check) return 1;
  6012. return (at->Check(This, Instructions));
  6013. }
  6014. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6015. if (!at) return 0;
  6016. if (!at->Check) return 1;
  6017. return (at->Check(This, Instructions));
  6018. }
  6019. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6020. laPropPack FakePP = {0};
  6021. laPropStep FakePs = {0};
  6022. if (!at) return 0;
  6023. if (!at->Check) return 1;
  6024. FakePP.LastPs = &FakePs;
  6025. FakePP.Go = FakePP.LastPs;
  6026. FakePP.LastPs->p = This->LastPs->p;
  6027. FakePP.LastPs->UseInstance = This->EndInstance;
  6028. FakePP.EndInstance = Real_FromInstance;
  6029. FakePP.LastIndex = This->LastIndex;
  6030. return (at->Check(&FakePP, Instructions));
  6031. }
  6032. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6033. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6034. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6035. }
  6036. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6037. laOperator *a, *f = From;
  6038. int rev;
  6039. if (!f && e&&e->Localized) return -1;
  6040. a = la_CreateOperator(at);
  6041. a->ToPanel = MAIN.ToPanel;
  6042. a->This = This;
  6043. a->ExtraInstructions = args;
  6044. strMakeInstructions(&a->ExtraInstructionsP, args);
  6045. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6046. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6047. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6048. la_DestroyOperator(&a, 0, 0);
  6049. return LA_CANCELED;
  6050. }
  6051. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6052. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6053. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6054. e->Localized = 1;
  6055. }
  6056. if (e&&e->Localized){
  6057. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6058. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6059. e->Localized = 0;
  6060. }else{
  6061. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6062. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6063. }
  6064. }
  6065. if (From) f->Child = a;
  6066. a->Using = 1;
  6067. if (at->Init) at->Init(a);
  6068. rev = at->Invoke(a, e);
  6069. a->Using = 0;
  6070. if (rev & LA_FINISH){
  6071. a->StopNow = 1; if(From)From->Child=0;
  6072. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6073. }
  6074. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6075. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6076. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6077. a->State = rev;
  6078. a->PP.EndInstance = a->CustomData;
  6079. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6080. }else
  6081. la_DestroyOperator(&a, 0, 0);
  6082. return rev;
  6083. }
  6084. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6085. laOperatorType *at; laOperator *a, *f = From;
  6086. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6087. if (!at) return -1;
  6088. return laInvokeP(From,at,e,This,args,args2);
  6089. }
  6090. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6091. laOperator *a, *f = From;
  6092. int rev;
  6093. laPropPack *created;
  6094. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6095. created = memAcquireSimple(sizeof(laPropPack));
  6096. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6097. created->Go = created->LastPs;
  6098. created->LastPs->p = OrigionalThis->LastPs->p;
  6099. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6100. created->EndInstance = FromInstance;
  6101. created->LastIndex = OrigionalThis->LastIndex;
  6102. a = la_CreateOperator(at);
  6103. a->ToPanel = MAIN.ToPanel;
  6104. a->This = created;
  6105. a->CreatedThis = created;
  6106. a->ExtraInstructions = args;
  6107. strMakeInstructions(&a->ExtraInstructionsP, args);
  6108. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6109. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6110. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6111. la_DestroyOperator(&a, 0, 0);
  6112. return LA_CANCELED;
  6113. }
  6114. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6115. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6116. if (From) f->Child = a;
  6117. a->Using = 1;
  6118. if (at->Init) at->Init(a);
  6119. rev = at->Invoke(a, e);
  6120. a->Using = 0;
  6121. if (rev & LA_FINISH){
  6122. a->StopNow = 1; if(From)From->Child=0;
  6123. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6124. }
  6125. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6126. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6127. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6128. a->State = rev;
  6129. a->PP.EndInstance = a->CustomData;
  6130. }else
  6131. la_DestroyOperator(&a, 0, 0);
  6132. return rev;
  6133. }
  6134. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6135. laOperator *a, *f = From;
  6136. int rev;
  6137. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6138. a = la_CreateOperator(at);
  6139. a->Instance = inst;
  6140. a->ToPanel = MAIN.ToPanel;
  6141. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6142. if (From) f->Child = a;
  6143. a->Using = 1;
  6144. if (at->Init) at->Init(a);
  6145. rev = at->Invoke(a, e);
  6146. a->Using = 0;
  6147. if (rev & LA_FINISH){
  6148. a->StopNow = 1; if(From)From->Child=0;
  6149. }
  6150. if (rev & LA_BLOCK){
  6151. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6152. a->State = rev;
  6153. }else la_DestroyOperator(&a, 0, 0);
  6154. DEB = a;
  6155. return rev;
  6156. }
  6157. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6158. laOperatorType *at;
  6159. laOperator *a, *f = From;
  6160. if (la_UiOperatorExists(inst)) return -1;
  6161. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6162. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6163. }
  6164. void laRequestDelayEvent(real Seconds){
  6165. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6166. int la_UiStillInService(void *UiInstance){
  6167. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6168. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6169. if (ai->Instance == UiInstance) return 1;
  6170. }
  6171. return 0;
  6172. }
  6173. void la_StopUiOperatorService(void *UiInstance){
  6174. laOperator *ai, *dai, *NextAi;
  6175. if (!MAIN.CurrentWindow) return;
  6176. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6177. NextAi = ai->Item.pNext;
  6178. if (ai->Instance == UiInstance){
  6179. if (ai->Child){
  6180. la_StopUiOperatorService(ai->Child->Instance);
  6181. ai->Child = 0;
  6182. }
  6183. laOperator *dai = ai;
  6184. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6185. continue;
  6186. }
  6187. }
  6188. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6189. NextAi = ai->Item.pNext;
  6190. if (ai->Instance == UiInstance){
  6191. if (ai->Instance == ai->ToPanel){
  6192. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6193. //ai->ToPanel->LaterDestroy = 1;
  6194. }
  6195. if (ai->Child && la_OperatorExists(ai->Child)){
  6196. la_StopUiOperatorService(ai->Child->Instance);
  6197. //ai->Child = 0;
  6198. }
  6199. if (!ai->Using){
  6200. laOperator *dai = ai;
  6201. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6202. }else
  6203. ai->StopNow = 1;
  6204. }
  6205. }
  6206. }
  6207. void la_StopAllOperators(){
  6208. laOperator *ai, *dai, *NextAi;
  6209. if (!MAIN.CurrentWindow) return;
  6210. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6211. NextAi = ai->Item.pNext;
  6212. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6213. continue;
  6214. }
  6215. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6216. NextAi = ai->Item.pNext;
  6217. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6218. laHidePanelWithDissoveEffect(ai->ToPanel);
  6219. ai->ToPanel->LaterDestroy = 1;
  6220. }
  6221. if (!ai->Using){
  6222. laOperator *dai = ai;
  6223. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6224. }else ai->StopNow = 1;
  6225. }
  6226. }
  6227. void la_DestroyConfirmData(laConfirmData **cd){
  6228. if((!cd)||!(*cd)) return;
  6229. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6230. if ((*cd)->StrData) free((*cd)->StrData);
  6231. FreeMem((*cd));
  6232. (*cd) = 0;
  6233. }
  6234. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6235. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6236. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6237. ai->NextConfirmData = cd; laRetriggerOperators();
  6238. }
  6239. void laConfirmInt(laOperator *a, int Data, int mode){
  6240. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6241. cd->IData = Data; cd->Mode = mode;
  6242. ai->NextConfirmData = cd; laRetriggerOperators();
  6243. }
  6244. void laConfirmFloat(laOperator *a, real Data, int mode){
  6245. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6246. cd->FData = Data; cd->Mode = mode;
  6247. ai->NextConfirmData = cd; laRetriggerOperators();
  6248. }
  6249. void laConfirmString(laOperator *a, char *Str, int mode){
  6250. laOperator *ai = a;
  6251. laConfirmData *cd = CreateNew(laConfirmData);
  6252. int len = strlen(Str);
  6253. char *buf = calloc(len + 1, sizeof(char));
  6254. strcpy(buf, Str);
  6255. cd->StrData = buf;
  6256. cd->Mode = mode;
  6257. cd->Destroy = free;
  6258. ai->NextConfirmData = cd;
  6259. laRetriggerOperators();
  6260. }
  6261. int laConfirmSameDataIfAny(laOperator *a){
  6262. laOperator *ai = a;
  6263. laConfirmData *cd;
  6264. char *buf = 0;
  6265. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6266. cd = CreateNew(laConfirmData);
  6267. if (ai->ConfirmData->StrData){
  6268. int len = strlen(ai->ConfirmData->StrData);
  6269. buf = calloc(len + 1, sizeof(char));
  6270. strcpy(buf, ai->ConfirmData->StrData);
  6271. }
  6272. //cd->CustomData = cd->CustomData;
  6273. cd->IData = ai->ConfirmData->IData;
  6274. cd->FData = ai->ConfirmData->FData;
  6275. cd->PointerData = ai->ConfirmData->PointerData;
  6276. cd->PointerType = a->ConfirmData->PointerType;
  6277. cd->StrData = buf;
  6278. cd->Mode = ai->ConfirmData->Mode;
  6279. cd->Destroy = ai->ConfirmData->Destroy;
  6280. ai->NextConfirmData = cd;
  6281. laRetriggerOperators();
  6282. return 1;
  6283. }
  6284. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6285. laOperator *ai = a;
  6286. laConfirmData *cd = CreateNew(laConfirmData);
  6287. cd->CustomData = UserData;
  6288. cd->Mode = mode;
  6289. cd->Destroy = Destroy;
  6290. ai->NextConfirmData = cd;
  6291. laRetriggerOperators();
  6292. }
  6293. int laGetConfirmMode(laOperator *a){
  6294. return ((laOperator *)a)->ConfirmData->Mode;
  6295. }
  6296. int laGetConfirmInt(laOperator *a){
  6297. laOperator *ai = a;
  6298. int rev = ai->ConfirmData->IData;
  6299. la_DestroyConfirmData(&ai->ConfirmData);
  6300. ai->ConfirmData = 0;
  6301. return rev;
  6302. }
  6303. real laGetConfirmFloat(laOperator *a){
  6304. laOperator *ai = a;
  6305. real rev = ai->ConfirmData->FData;
  6306. la_DestroyConfirmData(&ai->ConfirmData);
  6307. ai->ConfirmData = 0;
  6308. return rev;
  6309. }
  6310. void laGetConfirmString(laOperator *a, char *buf){
  6311. laOperator *ai = a;
  6312. strcpy(buf, ai->ConfirmData->StrData);
  6313. la_DestroyConfirmData(&ai->ConfirmData);
  6314. ai->ConfirmData = 0;
  6315. }
  6316. void *laGetConfirmUserData(laOperator *a){
  6317. laOperator *ai = a;
  6318. return ai->ConfirmData->CustomData;
  6319. }
  6320. void laFinalizeOperators(){
  6321. laOperatorType *at;
  6322. laListHandle *lst;
  6323. int i;
  6324. for (i = 0; i < 256; i++){
  6325. lst = &MAIN.OperatorTypeHash.Entries[i];
  6326. for (at = lst->pFirst; at; at = at->Item.pNext){
  6327. if (at->PC && at->PC->Props.pFirst){
  6328. lstAppendItem(&MAIN.PropContainers, at->PC);
  6329. }
  6330. }
  6331. }
  6332. }
  6333. //=================
  6334. #ifdef __linux__
  6335. static void la_RecordWacomMotions(XIRawEvent *event)
  6336. {
  6337. double *valuator = event->valuators.values;
  6338. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6339. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6340. //SYSWINDOW root_return, child_return;
  6341. //int root_x_return, root_y_return;
  6342. //int win_x_return, win_y_return;
  6343. //unsigned int mask_return;
  6344. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6345. // &root_x_return, &root_y_return,
  6346. // &win_x_return, &win_y_return,
  6347. // &mask_return);
  6348. //
  6349. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6350. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6351. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6352. real x=valuator[3],y=valuator[4];
  6353. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6354. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6355. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6356. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6357. if(XIMaskIsSet(event->valuators.mask, 5)){
  6358. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6359. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6360. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6361. MAIN.IsPen=1;
  6362. }
  6363. #endif
  6364. #ifdef _WIN32
  6365. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6366. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6367. static uint32_t ch = 0; static int lead = 0;
  6368. static wchar_t buf[10] = { 0 }; int adv;
  6369. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6370. short wheelmark = 0;
  6371. int WheelDir = 0;
  6372. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6373. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6374. POINT point;
  6375. PACKET pkt;
  6376. static POINT ptOld, ptNew;
  6377. static UINT prsOld, prsNew, vkey;
  6378. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6379. switch (message) {
  6380. case WM_PAINT:
  6381. //SwapBuffers(GetDC(hwnd));
  6382. break;
  6383. case WM_MOUSEMOVE:
  6384. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6385. MAIN.IsPen = 0;
  6386. break;
  6387. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6388. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6389. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6390. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6391. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6392. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6393. case WM_MOUSEWHEEL:
  6394. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6395. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6396. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6397. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6398. break;
  6399. case WT_PACKET:
  6400. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6401. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6402. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6403. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6404. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6405. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6406. MAIN.StylusTwist = tw;
  6407. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6408. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6409. MAIN.EraserPressure = MAIN.StylusPressure;
  6410. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6411. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6412. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6413. }
  6414. return 0; break;
  6415. case WM_SYSCOMMAND:
  6416. switch (wparam) {
  6417. case SC_MAXIMIZE:
  6418. case SC_RESTORE:
  6419. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6420. break;
  6421. case SC_KEYMENU:
  6422. return 0;
  6423. }
  6424. break;
  6425. case WM_SIZE:
  6426. if (wparam == SIZE_MINIMIZED) break;
  6427. case WM_MOVE: /* And size */
  6428. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6429. break;
  6430. case WM_SETCURSOR:
  6431. if(MAIN.CurrentCursor) return 1;
  6432. break;
  6433. case WM_POINTERDOWN:
  6434. case WM_POINTERUP:
  6435. case WM_POINTERUPDATE:
  6436. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6437. pointerId = GET_POINTERID_WPARAM(wparam);
  6438. pointerType = PT_POINTER;
  6439. if(!GetPointerType(pointerId, &pointerType)){
  6440. pointerType = PT_POINTER;
  6441. }
  6442. if(pointerType == PT_PEN){
  6443. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6444. for (int i = peninfonum-1; i>=0; i--) {
  6445. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6446. ScreenToClient(hwnd, &point);
  6447. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6448. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6449. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6450. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6451. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6452. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6453. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6454. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6455. }
  6456. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6457. }
  6458. }
  6459. SkipPointerFrameMessages(pointerId);
  6460. return 0;
  6461. }
  6462. else if (pointerType == PT_TOUCH){
  6463. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6464. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6465. ScreenToClient(hwnd, &point);
  6466. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6467. }
  6468. }
  6469. break;
  6470. case WM_SYSKEYDOWN:
  6471. if (lparam & 0x40000000) break;
  6472. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6473. break;
  6474. case WM_KEYDOWN:
  6475. if (lparam & 0x40000000) break;
  6476. vkey = wparam;
  6477. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6478. break;
  6479. case WM_KEYUP:
  6480. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6481. break;
  6482. case WM_SYSKEYUP:
  6483. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6484. break;
  6485. case WM_UNICHAR:
  6486. la_SendInputEvent(hwnd, wparam);
  6487. break;
  6488. case WM_IME_CHAR:
  6489. la_SendInputEvent(hwnd, wparam);
  6490. return 0;
  6491. case WM_CHAR:
  6492. la_SendInputEvent(hwnd, wparam);
  6493. break;
  6494. case WM_SHOWWINDOW:
  6495. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6496. break;
  6497. case WM_CLOSE:
  6498. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6499. break;
  6500. default:
  6501. return DefWindowProc(hwnd, message, wparam, lparam);
  6502. }
  6503. return DefWindowProc(hwnd, message, wparam, lparam);
  6504. }
  6505. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6506. return DefWindowProc(hwnd, message, wparam, lparam);
  6507. }
  6508. #endif
  6509. int la_UpdateOperatorHints(laWindow* w){
  6510. laSafeString* ss=0;
  6511. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6512. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6513. }
  6514. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6515. }else{
  6516. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6517. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6518. }
  6519. strSafeDestroy(&ss);
  6520. }
  6521. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6522. laOperator *a, *NextA = 0;
  6523. int Result = 0;
  6524. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6525. la_SendSignalsFromEvent(e);
  6526. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6527. a = Operators->pFirst;
  6528. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6529. while (1){
  6530. if (!a) break;
  6531. if (a->StopNow){
  6532. NextA = a->Item.pNext;
  6533. if (a->Type->Exit) a->Type->Exit(a, Result);
  6534. ConfirmData = a->NextConfirmData;
  6535. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6536. NextConfirmData = ConfirmData;
  6537. a->ConfirmData = 0;
  6538. a->NextConfirmData = 0;
  6539. la_DestroyOperator(&a, Operators, 0);
  6540. a = NextA;
  6541. if (a){
  6542. a->ConfirmData = NextConfirmData;
  6543. }
  6544. continue;
  6545. }
  6546. a->Using = 1;
  6547. la_SetPropMathcerContext(a->ToPanel);
  6548. laSetOperatorLocalizer(a->ToPanel);
  6549. MAIN.CurrentPanel = a->ToPanel;
  6550. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6551. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6552. e->Localized = 1;
  6553. }
  6554. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6555. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6556. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6557. e->Localized = 0;
  6558. }
  6559. la_SetPropMathcerContext(0);
  6560. laSetOperatorLocalizer(0);
  6561. MAIN.CurrentPanel = 0;
  6562. a->Using = 0;
  6563. if (Result & LA_PASS_ON){
  6564. laConfirmSameDataIfAny(a);
  6565. NextA = a->Item.pNext;
  6566. }else{
  6567. NextA = 0;
  6568. if (a->NextConfirmData){
  6569. la_DestroyConfirmData(&a->NextConfirmData);
  6570. }
  6571. }
  6572. ConfirmData = a->NextConfirmData;
  6573. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6574. NextConfirmData = ConfirmData;
  6575. a->ConfirmData = 0;
  6576. a->NextConfirmData = 0;
  6577. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6578. if (a->Type->Exit) a->Type->Exit(a, Result);
  6579. la_DestroyOperator(&a, Operators, 0);
  6580. int found=0;
  6581. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6582. if(!found){ NextA=0; }
  6583. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6584. }
  6585. a = NextA;
  6586. if (a){
  6587. a->ConfirmData = NextConfirmData;
  6588. }
  6589. }
  6590. return 1;
  6591. }
  6592. int la_HandleEvents(laWindow *w){
  6593. laEvent *e, *NextE;
  6594. laOperator *a;
  6595. laThreadNotifier *tn;
  6596. MAIN.CurrentWindow=w;
  6597. //laSpinLock(&MAIN.csNotifier);
  6598. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6599. //laSpinUnlock(&MAIN.csNotifier);
  6600. laNotifyUsers(tn->Path);
  6601. FreeMem(tn);
  6602. //if (MAIN.ThreadNotifiers.pFirst)
  6603. //laSpinLock(&MAIN.csNotifier);
  6604. }
  6605. //laSpinUnlock(&MAIN.csNotifier);
  6606. while (1){
  6607. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6608. while (w->EventList.pFirst){
  6609. while (w->PendingOperators.pLast){
  6610. a = w->PendingOperators.pLast;
  6611. if (a->OperatorPanel){
  6612. laSetOperatorLocalizer(a->OperatorPanel);
  6613. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6614. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6615. }
  6616. lstRemoveItem(&w->PendingOperators, a);
  6617. lstPushItem(&w->Operators, a);
  6618. }
  6619. e = lstPopItem(&w->EventList);
  6620. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6621. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6622. memFree(e);
  6623. }
  6624. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  6625. if (!MAIN.ReTriggerOperators) break;
  6626. }
  6627. la_UpdateOperatorHints(w);
  6628. return 1;
  6629. }
  6630. int la_AllowInput(uint32_t ch){
  6631. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6632. return 0;
  6633. }
  6634. int laCopyToClipboard(unsigned char * text){
  6635. #ifdef __linux__
  6636. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6637. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6638. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6639. strSafeSet(&MAIN.CopyPending, text);
  6640. #endif
  6641. }
  6642. int la_ProcessSysMessage(){
  6643. int SendDelay = 0, SendIdle = 0;
  6644. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6645. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6646. #ifdef __linux__
  6647. XEvent e;
  6648. int type;
  6649. int InputCount = 0, CharCount=0;
  6650. KeySym InputKeysym = 0;
  6651. Status InputStatus = 0;
  6652. laWindow* wnd ;
  6653. while(XPending(MAIN.dpy)){
  6654. XGenericEventCookie *cookie = &e.xcookie;
  6655. XNextEvent(MAIN.dpy, &e);
  6656. if (XFilterEvent(&e, None)) continue;
  6657. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6658. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6659. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6660. XFreeEventData(MAIN.dpy, cookie); continue;
  6661. }
  6662. switch(e.type){
  6663. case ConfigureNotify:
  6664. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6665. break;
  6666. case Expose:
  6667. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6668. if(!wnd) break;
  6669. laRefreshWindow(wnd);
  6670. break;
  6671. case MotionNotify:
  6672. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6673. MAIN.IsPen=0;
  6674. break;
  6675. case ButtonPress:
  6676. type=LA_MOUSEDOWN;
  6677. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6678. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6679. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6680. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  6681. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  6682. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6683. MAIN.IsPen=0;
  6684. break;
  6685. case ButtonRelease:
  6686. type=LA_MOUSEUP;
  6687. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6688. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6689. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6690. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6691. MAIN.IsPen=0;
  6692. break;
  6693. case KeyPress:
  6694. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  6695. MAIN.InputBuf[InputCount]=0;
  6696. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  6697. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  6698. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  6699. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6700. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6701. #ifdef DEBUG
  6702. printf("pressed KEY: %d\n", (int)InputKeysym);
  6703. #endif
  6704. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  6705. }
  6706. break;
  6707. case KeyRelease:
  6708. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6709. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  6710. }
  6711. case ClientMessage:
  6712. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  6713. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  6714. }
  6715. break;
  6716. case SelectionNotify:
  6717. if(e.xselection.selection != MAIN.bufid) continue;
  6718. if (e.xselection.property){
  6719. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  6720. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  6721. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  6722. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  6723. else if(result) {
  6724. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  6725. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  6726. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6727. }
  6728. XFree(result);
  6729. return True;
  6730. }
  6731. case SelectionRequest:
  6732. if(!MAIN.CopyPending){ break; }
  6733. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  6734. if (e.xselectionrequest.selection != MAIN.selection) break;
  6735. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  6736. XSelectionEvent ev = {0};
  6737. int R = 0;
  6738. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  6739. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  6740. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  6741. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  6742. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  6743. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  6744. else if (ev.target == MAIN.UTF8)
  6745. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  6746. else ev.property = None;
  6747. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  6748. break;
  6749. case SelectionClear:
  6750. break;
  6751. default:
  6752. break;
  6753. }
  6754. }
  6755. #endif //linux
  6756. #ifdef _WIN32
  6757. MSG msg; int Processed = 0;
  6758. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  6759. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  6760. if (msg.wParam == VK_PROCESSKEY) {
  6761. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  6762. }
  6763. TranslateMessage(&msg); DispatchMessage(&msg);
  6764. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  6765. };
  6766. if(!MAIN.Windows.pFirst){ return 0; }
  6767. #endif
  6768. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6769. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  6770. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  6771. }
  6772. return 1;
  6773. };
  6774. void la_PrintOperatorStack(){
  6775. laWindow *w = MAIN.CurrentWindow;
  6776. laOperator *a;
  6777. printf("\n");
  6778. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  6779. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  6780. a->Type->Identifier, a->Instance,
  6781. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  6782. }
  6783. }
  6784. void la_DrawWindow(laWindow *w){
  6785. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  6786. MAIN.CurrentWindow = w;
  6787. la_WindowDefDraw(w, 0);
  6788. }
  6789. int laFinalize(){
  6790. if(!laValidateProperties()){ laShutoff(0); return 0; }
  6791. laUiTemplate* uit;
  6792. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  6793. return 1;
  6794. }
  6795. void la_PreFrame(){
  6796. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  6797. la_AnimationPreFrame();
  6798. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  6799. }
  6800. void la_PostFrame(){
  6801. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  6802. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  6803. }
  6804. void laMainLoop(){
  6805. laWindow *w = MAIN.Windows.pFirst, *NextW;
  6806. laTimeRecorder FrameStartTime, FrameEndTime;
  6807. time_t t1, t2;
  6808. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  6809. static int a = 0;
  6810. if(!laFinalize()) return;
  6811. laSetWindowCursor(LA_ARROW);
  6812. MAIN.DelayTriggered=1;
  6813. while (1){
  6814. laRecordTime(&FrameStartTime);
  6815. la_PreFrame();
  6816. if(!la_ProcessSysMessage()){ return; }
  6817. la_UpdateControllerStatus();
  6818. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  6819. for (w=MAIN.Windows.pFirst;w;w = NextW){
  6820. NextW = w->Item.pNext;
  6821. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  6822. }
  6823. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  6824. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6825. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  6826. if(MAIN.GLDebugNeedsUpdate){
  6827. la_SetCurrentGLContextDebug();
  6828. }
  6829. la_DrawWindow(w);
  6830. }
  6831. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6832. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  6833. #ifdef __linux__
  6834. #ifdef LA_USE_GLES
  6835. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  6836. #else
  6837. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  6838. #endif
  6839. #endif
  6840. #ifdef _WIN32
  6841. SwapBuffers(w->hdc);
  6842. #endif
  6843. }
  6844. MAIN.GLDebugNeedsUpdate=0;
  6845. la_PostFrame();
  6846. //t2 = clock();
  6847. laRecordTime(&FrameEndTime);
  6848. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  6849. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  6850. if (Pause > 0){
  6851. int us = Pause * 1000000.0;
  6852. usleep(us);
  6853. }
  6854. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  6855. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  6856. la_AnimationPostFrame();
  6857. }
  6858. }
  6859. #ifdef LA_ANDROID
  6860. void android_main(struct android_app *app){
  6861. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  6862. CORE.Android.app = app;
  6863. // NOTE: Return from main is ignored
  6864. (void)main(1, (char *[]) { arg0, NULL });
  6865. // Request to end the native activity
  6866. ANativeActivity_finish(app->activity);
  6867. // Android ALooper_pollAll() variables
  6868. int pollResult = 0;
  6869. int pollEvents = 0;
  6870. // Waiting for application events before complete finishing
  6871. while (!app->destroyRequested)
  6872. {
  6873. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&CORE.Android.source)) >= 0)
  6874. {
  6875. if (CORE.Android.source != NULL) CORE.Android.source->process(app, CORE.Android.source);
  6876. }
  6877. }
  6878. }
  6879. #endif //android