*/}}

la_kernel.c 238 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <math.h>
  22. #include <time.h>
  23. #include <sys/time.h>
  24. #include <X11/Xlib.h>
  25. #include <X11/Xutil.h>
  26. #include <X11/Xos.h>
  27. #include <X11/keysymdef.h>
  28. #include <X11/XKBlib.h>
  29. #include <X11/extensions/XInput2.h>
  30. #include <X11/extensions/Xfixes.h>
  31. #include <GL/glx.h>
  32. //#include <GL/glext.h>
  33. //#include <GL/glu.h>
  34. LA MAIN;
  35. extern tnsMain *T;
  36. int deb = 0;
  37. laOperator *DEB;
  38. laColumn *DEBUG_C;
  39. Atom XA_ATOM = 4, XA_STRING = 31;
  40. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  41. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
  42. typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
  43. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  44. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  45. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  46. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  47. int i;
  48. for (i = 0; i < num_classes; i++) {
  49. if (classes[i]->type == XIValuatorClass) {
  50. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  51. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  52. logPrint(" Range: %f - %f\n", v->min, v->max);
  53. logPrint(" Resolution: %d units/m\n", v->resolution);
  54. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  55. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  56. }
  57. }
  58. }
  59. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure)
  60. {
  61. XIDeviceInfo *info, *dev;
  62. int i, ndevices;
  63. dev = XIQueryDevice(display, deviceid, &ndevices);
  64. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  65. mask->deviceid = deviceid;
  66. mask->mask_len = XIMaskLen(XI_RawMotion);
  67. mask->mask=memAcquireSimple(mask->mask_len);
  68. memset(mask->mask, 0, mask->mask_len);
  69. XISetMask(mask->mask, XI_RawMotion);
  70. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  71. int FoundMax=0;
  72. for (i = 0; i < dev->num_classes; i++) {
  73. if (dev->classes[i]->type == XIValuatorClass) {
  74. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  75. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  76. }
  77. }
  78. if(!FoundMax){*max_pressure=65535;}
  79. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  80. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  81. }
  82. void la_ScanWacomDevices(Display *display, int deviceid){
  83. XIDeviceInfo *info, *dev;
  84. int ndevices;
  85. int i; char * word;
  86. int _event, _error;
  87. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  88. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  89. }
  90. info = XIQueryDevice(display, deviceid, &ndevices);
  91. for(i = 0; i < ndevices; i++) {
  92. dev = &info[i];
  93. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  94. word = strtok (dev->name," ");
  95. while (1) {
  96. word = strtok (NULL, " "); if (!word) break;
  97. if (strcmp("stylus", word) == 0) MAIN.WacomDeviceStylus = dev->deviceid; // wacom
  98. elif (strcmp("eraser", word) == 0) MAIN.WacomDeviceEraser = dev->deviceid; // wacom
  99. elif (is_ipts && strcmp("Pen", word) == 0) MAIN.WacomDeviceStylus = dev->deviceid; // surface ipts
  100. elif (is_ipts && strcmp("Eraser", word) == 0) MAIN.WacomDeviceEraser = dev->deviceid; // surface ipts
  101. }
  102. }
  103. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  104. logPrintNew("Found wacom devices:\n");
  105. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  106. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  107. }else{
  108. logPrintNew("No wacom pen device connected.\n");
  109. }
  110. }
  111. void laHideCursor(){
  112. //if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  113. }
  114. void laShowCursor(){
  115. //if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  116. }
  117. Window la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc){
  118. XSetWindowAttributes swa;
  119. XWindowAttributes wa;
  120. swa.event_mask =
  121. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  122. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  123. swa.colormap = MAIN.cmap;
  124. Window root = DefaultRootWindow(MAIN.dpy);
  125. Window win = XCreateWindow(MAIN.dpy, root, x, y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  126. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  127. if(x>0||y>0){
  128. XSizeHints my_hints = {0};
  129. my_hints.flags = PPosition;
  130. my_hints.x = x; my_hints.y = y;
  131. XSetNormalHints(MAIN.dpy, win, &my_hints);
  132. }
  133. //int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 3, 0};
  134. //if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  135. // printf("\n\tcannot create gl context\n\n"); exit(0);
  136. //}
  137. XStoreName(MAIN.dpy, win, title);
  138. XMapWindow(MAIN.dpy, win);
  139. glXMakeContextCurrent(MAIN.dpy, win, win, MAIN.glc);
  140. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  141. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  142. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  143. XSetICFocus(MAIN.ic);
  144. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  145. XSetClassHint(MAIN.dpy, win, &ch);
  146. #define _NET_WM_STATE_ADD 1
  147. if(w<0&&h<0){
  148. XEvent xev;
  149. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  150. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  151. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  152. memset(&xev, 0, sizeof(xev));
  153. xev.type = ClientMessage;
  154. xev.xclient.window = win;
  155. xev.xclient.message_type = wm_state;
  156. xev.xclient.format = 32;
  157. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  158. xev.xclient.data.l[1] = max_horz;
  159. xev.xclient.data.l[2] = max_vert;
  160. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  161. }
  162. return win;
  163. };
  164. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  165. GLXContext glc;
  166. Window hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  167. window->win = hwnd;
  168. //if (!hwnd)
  169. //{
  170. // MessageBox(0, "Error Creating Window!", "Error", 0);
  171. // return 0;
  172. //};
  173. //ImmAssociateContext(hwnd,0);
  174. //la_SetupGLEnviornment(window, hwnd);
  175. //GetClientRect(window->win, &rc);
  176. //window->CW = rc.right - rc.left;
  177. //window->CH = rc.bottom - rc.top;
  178. XWindowAttributes attr;
  179. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  180. window->CW =attr.width;
  181. window->CH = attr.height;
  182. window->glc = glc;
  183. return 1;
  184. };
  185. void la_DestroySystemWindowX11(laWindow* w){
  186. glXMakeCurrent(MAIN.dpy, None, NULL);
  187. //glXDestroyContext(MAIN.dpy, w->glc);
  188. XDestroyWindow(MAIN.dpy, w->win);
  189. };
  190. int la_DestroySystemWindow(laWindow* wnd){
  191. la_DestroySystemWindowX11(wnd);
  192. }
  193. void la_DestroyWindow(laWindow *wnd){
  194. laLayout *l; laPanel *p;
  195. if (!wnd) return;
  196. la_StopAllOperators();
  197. strSafeDestroy(&wnd->Title);
  198. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  199. while (l = lstPopItem(&wnd->Layouts)){
  200. laDestroyBlocksRecursive(l->FirstBlock);
  201. strSafeDestroy(&l->ID);
  202. memFree(l);
  203. }
  204. la_DestroySystemWindow(wnd);
  205. lstRemoveItem(&MAIN.Windows, wnd);
  206. memFree(wnd);
  207. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  208. }
  209. void laRenameWindow(laWindow* wnd, char* name){
  210. strSafeSet(&wnd->Title, name);
  211. XStoreName(MAIN.dpy, wnd->win, name);
  212. }
  213. int la_ConvertCursorID(int id){
  214. return 0;
  215. //switch (id)
  216. //{
  217. //case LA_ARROW:
  218. // return IDC_ARROW;
  219. //case LA_CROSS:
  220. // return IDC_CROSS;
  221. //case LA_LEFT_RIGHT:
  222. // return IDC_SIZEWE;
  223. //case LA_UP_AND_DOWN:
  224. // return IDC_SIZENS;
  225. //case LA_MOVE:
  226. // return IDC_SIZEALL;
  227. //case LA_HAND:
  228. // return IDC_HAND;
  229. //}
  230. }
  231. void la_MakePanelTitleBar(laPanel *p, laUiDefineFunc ReplaceDefine);
  232. void la_InitThreadEnviornment(){
  233. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  234. }
  235. laLogEntry* logEnsure(int Create){
  236. if(!MAIN.Logs.pFirst || Create){
  237. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  238. lstAppendItem(&MAIN.Logs, le);
  239. }
  240. return MAIN.Logs.pLast;
  241. }
  242. void logPrintTV(int Continued, char* format, va_list v){
  243. if(!format || !format[0]) return;
  244. laLogEntry* le=logEnsure(Continued);
  245. strSafePrintV(&le->Content, format, v);
  246. laNotifyUsers("la.logs");
  247. }
  248. void logPrintT(int Continued, char* format, ...){
  249. if(!format || !format[0]) return;
  250. laLogEntry* le=logEnsure(Continued);
  251. va_list aptr; va_start(aptr, format);
  252. strSafePrint(&le->Content, format, aptr);
  253. va_end(aptr);
  254. laNotifyUsers("la.logs");
  255. }
  256. void logPrint(char* format, ...){
  257. va_list aptr; va_start(aptr, format);
  258. logPrintTV(0, format, aptr);
  259. va_end(aptr);
  260. }
  261. void logPrintNew(char* format, ...){
  262. logEnsure(1);
  263. va_list aptr; va_start(aptr, format);
  264. logPrintTV(0, format, aptr);
  265. va_end(aptr);
  266. }
  267. void logClear(){
  268. laLogEntry*l;
  269. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  270. }
  271. #define PROGRESSW (LA_RH*15)
  272. void laShowProgressV(real p1, real p2, char* format, va_list v){
  273. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  274. if(!MAIN.Progress.Called){
  275. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  276. }else{
  277. laTimeRecorder tm; laRecordTime(&tm);
  278. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1) return;
  279. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  280. if(!MAIN.Progress.Shown){
  281. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  282. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-PROGRESSW/2,h/2-LA_RH*2/2,PROGRESSW,LA_RH*2);
  283. long a=LA_COLOR3_TO_HEX(bg);
  284. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  285. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  286. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  287. XMapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 0); XFlush(MAIN.dpy);
  288. MAIN.Progress.Shown=1;
  289. }
  290. }
  291. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  292. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  293. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  294. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  295. tnsDrawLCD7_ProgressX11(LA_RH*1.5,0,MAIN.Progress.p1);
  296. tnsDrawLCD7_ProgressX11(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  297. XFlush(MAIN.dpy); XSync(MAIN.dpy, 0);
  298. }
  299. void laShowProgress(real p1, real p2, char* format, ...){
  300. va_list aptr; va_start(aptr, format);
  301. laShowProgressV(p1,p2,format,aptr);
  302. va_end(aptr);
  303. }
  304. void laHideProgress(){
  305. if(!MAIN.Progress.Shown){
  306. MAIN.Progress.Called=0; return;
  307. }
  308. laTimeRecorder tm; laRecordTime(&tm);
  309. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  310. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  311. XUnmapWindow(MAIN.dpy,MAIN.Progress.w);
  312. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  313. }
  314. //=======================
  315. void laInitProgressWindow(){
  316. 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));
  317. if(!MAIN.Progress.w) return;
  318. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  319. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  320. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  321. if(MAIN.Progress.gc<0) return;
  322. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  323. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  324. XSync(MAIN.dpy,0);
  325. }
  326. void laSetFontFolderPath(char* absolute){
  327. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  328. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  329. }
  330. int laGetReady(){
  331. Window root, win;
  332. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  333. XSetWindowAttributes swa={0};
  334. XWindowAttributes wa={0};
  335. XEvent xev;
  336. logPrintNew("Initializing LaGUI...\n");
  337. setlocale(LC_CTYPE, "zh_CN.utf8");
  338. XSetLocaleModifiers("");
  339. int i;
  340. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  341. printf("\n\tcannot connect to x server\n\n");
  342. exit(0);
  343. }
  344. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  345. static int visual_attribs[] =
  346. {
  347. GLX_X_RENDERABLE , True,
  348. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  349. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  350. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  351. GLX_RED_SIZE , 8,
  352. GLX_GREEN_SIZE , 8,
  353. GLX_BLUE_SIZE , 8,
  354. GLX_ALPHA_SIZE , 8,
  355. GLX_DEPTH_SIZE , 24,
  356. //GLX_STENCIL_SIZE , 8,
  357. GLX_DOUBLEBUFFER , True,
  358. GLX_SAMPLE_BUFFERS , 1,
  359. GLX_SAMPLES , 4,
  360. None
  361. };
  362. int fbcount = -1;
  363. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  364. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  365. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  366. MAIN.BestFBC = fbconfig[0];
  367. int sample_buf,samples;
  368. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  369. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  370. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  371. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  372. free(fbconfig);
  373. root = DefaultRootWindow(MAIN.dpy);
  374. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  375. printf("\n\tcannot create colormap\n\n"); exit(0);
  376. }
  377. swa.colormap = MAIN.cmap;
  378. root = DefaultRootWindow(MAIN.dpy);
  379. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  380. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 4, GLX_CONTEXT_MINOR_VERSION_ARB, 6, 0};
  381. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  382. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  383. printf("\n\tcannot create gl context\n\n"); exit(0);
  384. }
  385. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  386. glXMakeContextCurrent(MAIN.dpy, win,win, MAIN.glc);
  387. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  388. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  389. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  390. int err=0;
  391. if((err=glewInit())!=GLEW_OK){
  392. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  393. };
  394. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  395. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  396. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  397. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  398. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  399. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  400. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  401. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  402. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  403. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  404. la_GetWorkingDirectoryInternal();
  405. //laSetAuthorInfo("YimingWu", "(C)Nick'sBest");
  406. //transInitTranslation_zh_cn();
  407. //transState(0, 1); //enable translation
  408. MAIN.FontSize = 0.6;
  409. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =24;
  410. MAIN.UiScale=1;
  411. MAIN.MarginSize = 1;
  412. tnsInitRenderKernel(64);
  413. tnsInitBuiltinShaders();
  414. tnsSetuptnsFontManager();
  415. #define LOAD_FONT(font)\
  416. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  417. LOAD_FONT("NotoSansCJK-Regular.ttc");
  418. LOAD_FONT("NotoEmoji-Regular.ttf");
  419. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  420. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  421. //LOAD_FONT("NotoMusic-Regular.ttf");
  422. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  423. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) printf("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  424. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  425. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  426. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  427. MAIN.InputMapping=memAcquire(sizeof(laRackPageCollection));
  428. MAIN.Drivers=memAcquire(sizeof(laRackPageCollection));
  429. //interactions:
  430. MAIN.TopFramerate = 60;
  431. MAIN.ValuatorThreshold = 8;
  432. MAIN.ScrollingSpeed = 3;
  433. MAIN.AnimationSpeed = 0.4;
  434. MAIN.PanelAnimationSpeed = 0.4;
  435. MAIN.ZoomSpeed2D = 0.01;
  436. MAIN.IdleTime = 0.75;
  437. MAIN.TooltipCloseDistance = 30;
  438. //display:
  439. MAIN.FloatingAlpha = 0.7;
  440. MAIN.SolidShadowLength = 20;
  441. MAIN.WireColorSlices = 16;
  442. MAIN.WireThickness = 5;
  443. MAIN.WireSaggyness = 5;
  444. //timeline:
  445. MAIN.Animation.FrameBegin = 1;
  446. MAIN.Animation.FrameEnd = 250;
  447. MAIN.Animation.Frame = 1;
  448. MAIN.Animation.FrameRate = 25;
  449. MAIN.Animation.FrameStep = 1;
  450. laAddResourceFolder(".");
  451. laAddResourceFolder("/home/yiming/Documents/sync/Projects/2022/nul5/build");
  452. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  453. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0);
  454. laInitProgressWindow();
  455. //tns_RegisterResourcesForSoftwareRender();
  456. la_RegisterGeneralProps();
  457. la_RegisterBuiltinTemplates();
  458. la_RegisterMainThemes();
  459. la_RegisterMainOperators();
  460. la_RegisterMainUiTypes();
  461. la_RegisterModellingOperators();
  462. la_RegisterInternalProps();
  463. la_RegisterWindowKeys();
  464. laFinalizeUiTemplates();
  465. laFinalizeOperators();
  466. la_InitControllers();
  467. la_RegisterControllerProps();
  468. la_RegisterInputMapperOperators();
  469. tns_RegisterNodes();
  470. la_InitThreadEnviornment();
  471. laSetRootInstance(&MAIN);
  472. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  473. laPushDifferences(0, 0);
  474. la_MakeDummyManagedUDF();
  475. la_RegenerateWireColors();
  476. logPrint("Initialization Completed\n");
  477. MAIN.InitDone=1;
  478. }
  479. void laShutoff(){
  480. if(MAIN.Cleanup) MAIN.Cleanup();
  481. strSafeDestroy(&MAIN.WorkingDirectory);
  482. strSafeDestroy(&MAIN.example_string);
  483. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  484. // (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. )
  485. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  486. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  487. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  488. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  489. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  490. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  491. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  492. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  493. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  494. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  495. strSafeDestroy(&MAIN.CopyPending);
  496. la_ClearUDFRegistryAndFolders();
  497. laClearManagedUDF();
  498. laClearSaveProp();
  499. logClear();
  500. tnsQuit();
  501. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  502. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  503. strSafeDump();
  504. hshFree(&MAIN.DBInstMemLeft);
  505. memNoLonger();
  506. glXDestroyContext(MAIN.dpy,MAIN.glc);
  507. }
  508. void laSaveUserPreferences(){
  509. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  510. laUDF* udf=laPrepareUDF(path);
  511. laWriteProp(udf,"la.user_preferences");
  512. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  513. laWriteProp(udf,lip->p);
  514. }
  515. laPackUDF(udf,0);
  516. }
  517. void laEnsureUserPreferences(){
  518. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  519. laUDFRegistry* r=laFindUDFRegistry(path);
  520. if(!r){ laSaveUserPreferences(); return; }
  521. laUDF* udf=laOpenUDF(r->Path->Ptr,1,0,0); if(!udf){ logPrint("Can't read preferences. Using default settings."); return; }
  522. laClearUDFRegistries(); while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  523. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE,0);
  524. laCloseUDF(udf);
  525. }
  526. void laAddExtraExtension(int FileType, ...){
  527. va_list list; va_start(list,FileType);
  528. char* ext;
  529. while(ext=va_arg(list,char*)){ if(!ext) break;
  530. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  531. et->FileType=FileType; et->Extension=ext;
  532. lstAppendItem(&MAIN.ExtraExtensions, et);
  533. }
  534. va_end(list);
  535. }
  536. void laAddExtraPreferencePath(const char* path){
  537. if(!path) return;
  538. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  539. }
  540. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  541. if(!name || !Func) return;
  542. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  543. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  544. }
  545. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  546. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  547. }
  548. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  549. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  550. }
  551. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  552. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  553. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  554. }
  555. //MSG====================================================
  556. int la_IsThisSysWindow(laWindow *wnd, Window hwnd){
  557. if (wnd->win == hwnd) return 1;
  558. else return 0;
  559. };
  560. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  561. if (p->SL){ int s=p->SL<0?0:p->SL;
  562. if (p->TX != s) p->Refresh |= LA_TAG_RECALC;
  563. p->TX = s;
  564. }
  565. if (p->SR){ int s=p->SR<0?0:p->SR;
  566. if (p->TW != CW - p->TX - s) p->Refresh |= LA_TAG_RECALC;
  567. p->TW = CW - p->TX - s;
  568. }
  569. if (p->ST){ int s=p->ST<0?0:p->ST;
  570. if (p->TY != s) p->Refresh |= LA_TAG_RECALC;
  571. p->TY = s;
  572. }
  573. if (p->SB){ int s=p->SB<0?0:p->SB;
  574. if (p->TH != CH - p->TY - s) p->Refresh |= LA_TAG_RECALC;
  575. p->TH = CH - p->TY - s;
  576. }
  577. }
  578. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  579. laPanel *p = 0;
  580. b->X = X;
  581. b->Y = Y;
  582. b->W = W;
  583. b->H = H;
  584. if (b->B1){
  585. int SplitWidth;
  586. if (b->Vertical){
  587. SplitWidth = H * b->SplitRatio;
  588. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  589. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  590. }else{
  591. SplitWidth = W * b->SplitRatio;
  592. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  593. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  594. }
  595. }
  596. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  597. if (p = b->CurrentPanel){
  598. int TitleGap=b->Folded?0:LA_RH;
  599. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  600. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  601. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  602. p->Refresh |= LA_TAG_RECALC;
  603. p->TitleWidth = tnsStringGetWidth(p->Title->Ptr, 0, 0);
  604. }
  605. }
  606. void la_UpdateUiPlacement(laWindow *w){
  607. laLayout *l;
  608. laPanel *p;
  609. int CW = w->CW;
  610. int CH = w->CH;
  611. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  612. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  613. if(w->MaximizedUi && w->MaximizedUiPanel){
  614. w->MaximizedUiPanel->Refresh|=LA_TAG_RECALC;
  615. }elif(w->MaximizedBlock){
  616. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  617. }else{
  618. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  619. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  620. }
  621. }
  622. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  623. if(p->IsMenuPanel){
  624. p->TH=p->H=MenuHeight;
  625. }
  626. la_EnsurePanelSnapping(p, CW, CH);
  627. p->Refresh |= LA_TAG_RECALC;
  628. }
  629. }
  630. void la_CommandResizeWindow(Window hwnd, int x, int y, int w, int h){
  631. laWindow *window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  632. if (!window) return;
  633. XWindowAttributes attr;
  634. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  635. window->CW = w; window->CH = h;
  636. window->W = w; window->H = h;
  637. window->X = x; window->Y = y;
  638. la_UpdateUiPlacement(window);
  639. }
  640. int la_OnWindowDestroy(Window wnd){
  641. laListHandle *hlst = &MAIN.Windows;
  642. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  643. if (!w) return;
  644. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  645. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  646. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  647. laShutoff();
  648. return 1;
  649. }
  650. laListHandle h={0};laLayout*l=0;
  651. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  652. la_DestroyWindow(w);
  653. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  654. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  655. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done=1; while(l=lstPopItem(&h)){ lstAppendItem(&w->Layouts, l); } }
  656. }
  657. return 0;
  658. }
  659. void la_MakeSpecialKeyBit(Window*hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  660. laListHandle *el = &wnd->EventList;
  661. laEvent* last_e=el->pLast;
  662. Window root_ret, win_ret; int rrx,rry,rx,ry,rmask;
  663. XQueryPointer(MAIN.dpy, hwnd, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  664. if(use_last_pos){ if(last_e){ e->x= last_e->x; e->y= last_e->y; }else{ e->x = rx; e->y = ry; } }
  665. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  666. }
  667. void la_SaveEvent(Window hwnd, laEvent *e, int use_last_pos){
  668. laListHandle *wl = &MAIN.Windows;
  669. laWindow* wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  670. if (!wnd){ FreeMem(e); return; }
  671. laListHandle *el = &wnd->EventList;
  672. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  673. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  674. e->AngleX=MAIN.PointerIsEraser?MAIN.EraserAngleX:MAIN.StylusAngleX;
  675. e->AngleY=MAIN.PointerIsEraser?MAIN.EraserAngleY:MAIN.StylusAngleY;
  676. e->IsEraser=MAIN.PointerIsEraser;
  677. lstAppendItem(el, (laListItem *)e);
  678. laMappingRequestEval();
  679. };
  680. void la_SendKeyboardEvent(Window hwnd, int type, int key){
  681. laEvent *e = CreateNew(laEvent); e->Type = type; e->key = key;
  682. la_SaveEvent(hwnd, e, 1);
  683. };
  684. void la_SendInputEvent(Window hwnd, uint32_t Input){
  685. laEvent *e = CreateNew(laEvent);
  686. e->Type = LA_INPUT; e->Input=Input;
  687. la_SaveEvent(hwnd, e, 1);
  688. }
  689. void la_SendEmptyEvent(Window hwnd){
  690. laEvent *e = CreateNew(laEvent);
  691. e->Type = LA_EMPTY;
  692. la_SaveEvent(hwnd, e, 1);
  693. }
  694. void laSendOperatorTriggerEvent(){
  695. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  696. MAIN.ReTriggerOperators = 0;
  697. }
  698. int la_TranslateSpecialKey(int keysym){
  699. switch(keysym){
  700. case XK_Return: return LA_KEY_ENTER;
  701. case XK_BackSpace: return LA_KEY_BACKSPACE;
  702. case XK_Delete: return LA_KEY_DELETE;
  703. case XK_Escape: return LA_KEY_ESCAPE;
  704. case XK_Tab: return LA_KEY_TAB;
  705. case XK_Left: return LA_KEY_ARRLEFT;
  706. case XK_Right: return LA_KEY_ARRRIGHT;
  707. case XK_Up: return LA_KEY_ARRUP;
  708. case XK_Down: return LA_KEY_ARRDOWN;
  709. case XK_Control_L: return LA_KEY_CTRL;
  710. case XK_Control_R: return LA_KEY_CTRL;
  711. case XK_Shift_L: return LA_KEY_SHIFT;
  712. case XK_Shift_R: return LA_KEY_SHIFT;
  713. case XK_Alt_L: return LA_KEY_ALT;
  714. case XK_Alt_R: return LA_KEY_ALT;
  715. default: return keysym;
  716. }
  717. }
  718. void la_SendMouseEvent(Window hwnd, int type, int x, int y){
  719. laEvent *e = CreateNew(laEvent);
  720. e->Type = type;
  721. e->x = x;
  722. e->y = y;
  723. la_SaveEvent(hwnd, e, 0);
  724. //printf("mouse %d %d\n", e->x, e->y);
  725. //if (e->Type == LA_R_MOUSE_DOWN)
  726. // la_PrintOperatorStack();
  727. };
  728. void la_SendTimerEvent(Window hwnd, int type){
  729. laEvent *e = CreateNew(laEvent);
  730. e->Type = type;
  731. la_SaveEvent(hwnd, e, 1);
  732. };
  733. void laRetriggerOperators(){
  734. MAIN.ReTriggerOperators = 1;
  735. }
  736. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  737. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  738. }
  739. void laSetCleanupCallback(laCleanupF Cleanup){
  740. MAIN.Cleanup=Cleanup;
  741. }
  742. //====================================================================================================
  743. void la_DestroyTheme(laTheme* t){
  744. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  745. strSafeDestroy(&t->Name);
  746. strSafeDestroy(&t->Author);
  747. }
  748. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  749. laTheme *t = memAcquireHyper(sizeof(laTheme));
  750. strSafeSet(&t->Name, Name);
  751. strSafeSet(&t->Author, AuthorName);
  752. lstAppendItem(&MAIN.Themes, t);
  753. MAIN.CurrentTheme = t;
  754. return t;
  755. }
  756. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  757. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  758. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  759. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  760. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  761. strSafeSet(&bt->Name, Name);
  762. bt->NormalY=NormalY;
  763. bt->ActiveY=ActiveY;
  764. bt->BorderY=BorderY;
  765. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  766. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  767. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  768. bt->BackRef = BackRef;
  769. lstAppendItem(&t->BoxedThemes, bt);
  770. return bt;
  771. }
  772. laBoxedTheme *laGetTheme(const char *ThemeName){
  773. laTheme *t = MAIN.Themes.pFirst;
  774. for (t; t; t = t->Item.pNext){
  775. laBoxedTheme *bt;
  776. if (strSame(t->Name->Ptr, ThemeName)) return t;
  777. }
  778. return 0;
  779. }
  780. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  781. laTheme *t = MAIN.Themes.pFirst;
  782. for (t; t; t = t->Item.pNext){
  783. laBoxedTheme *bt;
  784. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  785. bt = t->BoxedThemes.pFirst;
  786. for (bt; bt; bt = bt->Item.pNext){
  787. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  788. }
  789. }
  790. return 0;
  791. }
  792. real* laThemeColor(laBoxedTheme* bt, int which){
  793. switch(which){
  794. default:
  795. case LA_BT_NORMAL: return bt->Normal;
  796. case LA_UI_EDITING:
  797. case LA_BT_ACTIVE: return bt->Active;
  798. case LA_BT_BORDER: return bt->Border;
  799. case LA_BT_TEXT: return bt->Text; break;
  800. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  801. case LA_BT_DISABLED: return bt->Inactive; break;
  802. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  803. }
  804. return bt->Normal;
  805. }
  806. real* laAccentColor(int which){
  807. switch(which){
  808. default:
  809. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  810. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  811. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  812. case LA_BT_FACE:
  813. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  814. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  815. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  816. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  817. }
  818. return MAIN.CurrentTheme->SelectionColor;
  819. }
  820. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  821. real hcy[3];
  822. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  823. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  824. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  825. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  826. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  827. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  828. int *tm=&bt->LM,*tp=&bt->LP;
  829. for(int i=0;i<4;i++){
  830. tm[i]=bt->Margins[i]*LA_RH*MAIN.MarginSize;
  831. tp[i]=bt->Paddings[i]*LA_RH*MAIN.MarginSize;
  832. }
  833. }
  834. void la_RefreshThemeColorSelf(laTheme* th){
  835. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  836. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha;
  837. real hcy[3], usehcy[3];
  838. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  839. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  840. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  841. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  842. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  843. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  844. }
  845. void la_RefreshThemeColor(laTheme* th){
  846. real hcy[3], usehcy[3], normalhcy[3];
  847. tnsRGB2HCY(th->Color,hcy);
  848. la_RefreshThemeColorSelf(th);
  849. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  850. la_RefreshBoxedThemeColor(bt);
  851. (*bt->BackRef) = bt;
  852. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  853. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  854. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  855. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  856. }
  857. }
  858. //I FUCKING HATE THIS STUPID FUNCTION
  859. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  860. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  861. laUiListDrawItem *last = uild->Items.pFirst;
  862. int LimW=_R-_L;
  863. int SL, SR, SU, SB;
  864. int Target__B = Target->B;
  865. int Target__R = Target->R;
  866. uildi->Target = Target;
  867. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  868. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  869. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  870. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  871. uildi->L = last ? Target->L - last->XP : Target->L;
  872. uildi->R = last ? Target__R - last->XP : Target__R;
  873. uildi->U = last ? Target->U - last->YP : Target->U;
  874. uildi->B = last ? Target__B - last->YP : Target__B;
  875. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  876. uildi->L -= GlobalX;
  877. uildi->R -= GlobalX;
  878. uildi->U -= GlobalY;
  879. uildi->B -= GlobalY;
  880. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  881. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  882. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  883. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  884. uildi->DifX = SL - uildi->L;
  885. uildi->DifY = SU - uildi->U;
  886. uildi->L = SL;
  887. uildi->R = SR+uildi->DifX;
  888. uildi->U = SU;
  889. uildi->B = SB;//+uildi->DifY;
  890. if(uildi->R>_R){ uildi->R=_R; }
  891. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  892. //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);
  893. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  894. memFree(uildi);
  895. return 0;
  896. }
  897. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  898. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  899. Target->L + Target->PanX + uildi->DifX +1+ (uildi->R - uildi->L),
  900. Target->U + Target->PanY + uildi->DifY +1+ (uildi->B - uildi->U),
  901. Target->U + Target->PanY + uildi->DifY -1,
  902. -100, 100);
  903. lstPushItem(&uild->Items, uildi);
  904. return 1;
  905. }
  906. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  907. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  908. laUiListDrawItem *last = uild->Items.pFirst;
  909. int SL, SR, SU, SB;
  910. if (B - U > LimH) B = U + LimH;
  911. uildi->XP = last ? last->XP + PanX : PanX;
  912. uildi->YP = last ? last->YP + PanY : PanY;
  913. uildi->L = last ? L - last->XP : L;
  914. uildi->R = last ? R - last->XP : R;
  915. uildi->U = last ? U - last->YP : U;
  916. uildi->B = last ? B - last->YP : B;
  917. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  918. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  919. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  920. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  921. uildi->DifX = SL - uildi->L;
  922. uildi->DifY = SU - uildi->U;
  923. uildi->L = SL;
  924. uildi->R = SR;
  925. uildi->U = SU;
  926. uildi->B = SB;
  927. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  928. tnsOrtho(L + PanX + uildi->DifX,
  929. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  930. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  931. U + PanY + uildi->DifY,
  932. -100, 100);
  933. lstPushItem(&uild->Items, uildi);
  934. }
  935. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  936. laUiListDrawItem *uildi = uild->Items.pFirst;
  937. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  938. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  939. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  940. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  941. Target->U + Target->PanY + uildi->DifY -1,
  942. -100, 100);
  943. }
  944. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  945. laUiListDrawItem *uildi = lstPopItem(uild);
  946. laUiList *Target;
  947. memFree(uildi);
  948. uildi = uild->Items.pFirst;
  949. if (!uildi || !uildi->Target){
  950. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  951. return;
  952. }
  953. Target = uildi->Target;
  954. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  955. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  956. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  957. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  958. Target->U + Target->PanY + uildi->DifY -1,
  959. -100, 100);
  960. }
  961. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  962. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  963. uildi->L = L;
  964. uildi->R = R;
  965. uildi->U = U;
  966. uildi->B = B;
  967. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  968. tnsOrtho(L, R, B, U, -100, 100);
  969. lstPushItem(&uild->Items, uildi);
  970. }
  971. void la_ClearUiListMatrix(laUiListDraw *uild){
  972. laUiListDrawItem *uildi;
  973. while (uildi = lstPopItem(uild)){
  974. memFree(uildi);
  975. }
  976. }
  977. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  978. 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);
  979. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  980. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  981. int la_TestUiListMinumWidth(laUiList *uil);
  982. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  983. if (ui){
  984. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  985. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  986. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  987. p->X = p->TX; p->Y = p->TY;
  988. p->W = p->TW;
  989. }
  990. }
  991. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  992. int cw = MAIN.CurrentWindow->CW;
  993. int ch = MAIN.CurrentWindow->CH;
  994. int PH = p->TH;
  995. laBoxedTheme*bt = *p->BT;
  996. int uih=uil->B + bt->TM+bt->BM;
  997. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  998. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  999. else if (p->MinH && PH < p->MinH)
  1000. p->TH = p->MinH;
  1001. else
  1002. p->TH = PH;
  1003. p->H = p->TH;
  1004. if ((p->X + p->W) > cw){
  1005. p->X -= (p->X + p->W - cw);
  1006. }
  1007. if ((p->Y + p->H) > ch){
  1008. p->Y -= (p->Y + p->H - ch);
  1009. }
  1010. if (p->X < 0) p->X = 0;
  1011. if (p->Y < 0) p->Y = 0;
  1012. if ((p->X + p->W) > cw){
  1013. p->W -= (p->X + p->W - cw);
  1014. }
  1015. if ((p->Y + p->H) > ch){
  1016. p->H -= (p->Y + p->H - ch);
  1017. }
  1018. if (p->ST) p->TY = p->ST;
  1019. if (p->SB && p->TH != ch - p->TY - p->SB) p->Refresh = LA_TAG_RECALC;
  1020. if (p->SB) p->TH = ch - p->TY - p->SB;
  1021. p->TX = p->X; p->TY = p->Y;
  1022. p->TW = p->W; p->TH = p->H;
  1023. if (p->OffScr &&
  1024. (p->W != p->OffScr->pColor[0]->Width ||
  1025. p->H != p->OffScr->pColor[0]->Height)){
  1026. tnsConfigureOffscreen(p->OffScr, p->W,p->H);
  1027. }
  1028. }
  1029. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  1030. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1031. tnsViewportWithScissor(0, 0, p->W, p->H);
  1032. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  1033. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1034. }
  1035. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  1036. tnsDrawToScreen();
  1037. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  1038. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1039. }
  1040. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  1041. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  1042. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  1043. }
  1044. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  1045. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  1046. tnsClearAll();
  1047. }
  1048. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  1049. real Color[] = {1, 1, 1, 1};
  1050. real L, W, U, H;
  1051. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  1052. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  1053. switch (p->AnimationMode){
  1054. case 0:
  1055. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  1056. //if(p->Mode==LA_PANEL_FLOATING_TOP)
  1057. // tnsDrawStringAuto("◿",laThemeColor(*p->BT,LA_BT_BORDER),p->X+p->W-LA_RH, p->X+p->W, p->H+p->Y-LA_RH, LA_TEXT_ALIGN_CENTER);
  1058. break;
  1059. case LA_PANEL_ANIMATION_DROP_DOWN:
  1060. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1061. tnsDraw2DTextureArg(
  1062. p->OffScr->pColor[0],
  1063. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  1064. Color,
  1065. 0, 0, 1 - p->AnimationRatio, 0);
  1066. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1067. if (p->AnimationRatio > 0.99) p->AnimationMode = 0;
  1068. break;
  1069. case LA_PANEL_ANIMATION_EXPAND:
  1070. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1071. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1072. W = tnsLinearItp(0, p->W, 0.4);
  1073. H = tnsLinearItp(0, p->H, 0.4);
  1074. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1075. tnsDraw2DTextureArg(
  1076. p->OffScr->pColor[0],
  1077. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1078. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1079. Color,
  1080. 0, 0, 0, 0);
  1081. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1082. if (p->AnimationRatio > 0.99) p->AnimationMode = 0;
  1083. break;
  1084. case LA_PANEL_ANIMATION_DISSOVE:
  1085. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  1086. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  1087. W = tnsLinearItp(0, p->W, 1.4);
  1088. H = tnsLinearItp(0, p->H, 1.4);
  1089. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  1090. if (p->OffScr) tnsDraw2DTextureArg(
  1091. p->OffScr->pColor[0],
  1092. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1093. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1094. Color,
  1095. 0, 0, 0, 0);
  1096. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1097. if (p->AnimationRatio < 0.01) p->AnimationMode = 0;
  1098. break;
  1099. case LA_PANEL_ANIMATION_COLLAPSE:
  1100. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1101. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1102. W = tnsLinearItp(0, p->W, 0.4);
  1103. H = tnsLinearItp(0, p->H, 0.4);
  1104. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1105. if (p->OffScr) tnsDraw2DTextureArg(
  1106. p->OffScr->pColor[0],
  1107. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1108. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1109. Color,
  1110. 0, 0, 0, 0);
  1111. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1112. if (p->AnimationRatio < 0.01) p->AnimationMode = 0;
  1113. break;
  1114. case LA_PANEL_ANIMATION_MINIMIZE:
  1115. L = tnsLinearItp(0, p->X, 0.3);
  1116. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  1117. W = tnsLinearItp(0, p->W, 0.4);
  1118. H = tnsLinearItp(0, p->H, 0.4);
  1119. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1120. tnsDraw2DTextureArg(
  1121. p->OffScr->pColor[0],
  1122. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1123. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1124. Color,
  1125. 0, 0, 0, 0);
  1126. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1127. if (p->AnimationRatio < 0.01) p->AnimationMode = 0;
  1128. break;
  1129. }
  1130. tnsFlush();
  1131. tnsUniformOutputColorSpace(T->immShader,0);
  1132. tnsUniformShowColorOverflowStripes(T->immShader,0);
  1133. }
  1134. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  1135. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  1136. if (!p->OffScr){
  1137. p->OffScr = tnsCreate2DOffscreen(p->DefaultGLFormat?p->DefaultGLFormat:GL_RGBA8, p->W, p->H, MAIN.PanelMultisample, 0);
  1138. }
  1139. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1140. }
  1141. void la_PanelRefreshDetachedProp(laPanel *panel){
  1142. laProp *p;
  1143. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  1144. la_StepPropPack(&p->DetachedPP);
  1145. la_UsePropPack(&p->DetachedPP, 0);
  1146. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  1147. // laUseDataBlock(
  1148. // p->DetachedPP.LastPs->UseInstance,
  1149. // p->DetachedPP.LastPs->p,
  1150. // MAIN.PropMatcherContextP->FrameDistinguish,
  1151. // MAIN.PropMatcherContextP,
  1152. // la_PropPanelUserRemover, 0);
  1153. //}
  1154. }
  1155. }
  1156. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  1157. real* color=laThemeColor(bt,LA_BT_NORMAL);
  1158. tnsColor4d(LA_COLOR3(color),Alpha);
  1159. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  1160. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  1161. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  1162. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  1163. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  1164. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  1165. tnsPackAs(GL_TRIANGLE_STRIP);
  1166. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1167. tnsVertex2d(Panel->X, Panel->Y);
  1168. tnsVertex2d(Panel->X, Panel->Y + Panel->H);
  1169. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  1170. tnsVertex2d(Panel->X + Panel->W, Panel->Y);
  1171. tnsPackAs(GL_LINE_LOOP);
  1172. }
  1173. int la_AnimateUiListRecursive(laUiList *uil);
  1174. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  1175. int DrawState_ = 0;
  1176. laUiListDraw uild = {0};
  1177. if (p->Show){
  1178. la_SetPropMathcerContext(p);
  1179. MAIN.CurrentPanel = p;
  1180. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  1181. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  1182. //}
  1183. if (p->Refresh & LA_TAG_RECALC){
  1184. laRecalcPanelImmediate(p);
  1185. }
  1186. if (!p->MenuRefer){
  1187. if(!p->OffScr){la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW;}
  1188. if (p->Refresh || !p->OffScr){
  1189. la_PanelDrawToOffsceen(p, &p->UI);
  1190. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  1191. la_PanelBackgroundInit(p, bt);
  1192. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U-bt->TM-bt->BM, p->H-p->TitleBar.B-bt->TM-bt->BM*2, p->W);
  1193. tnsFlush();
  1194. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  1195. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  1196. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  1197. DrawState_++;
  1198. }
  1199. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  1200. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  1201. if(p->UI.PanY<0){p->UI.PanY=0;}
  1202. DrawState_++;
  1203. }
  1204. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  1205. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  1206. else p->Refresh = LA_TAG_ANIMATION;
  1207. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = p->Refresh;
  1208. else p->Refresh = LA_TAG_ANIMATION;
  1209. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1210. if(p!=w->MaximizedUiPanel){
  1211. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1212. }else{
  1213. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  1214. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  1215. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  1216. tnsFlush();
  1217. }
  1218. if (DrawState_) p->Refresh = LA_TAG_RECALC;
  1219. }
  1220. }else{
  1221. if (p->Refresh || !p->OffScr){
  1222. la_PanelDrawToOffsceen(p, p->MenuRefer);
  1223. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  1224. la_PanelBackgroundInit(p, bt);
  1225. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  1226. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  1227. tnsFlush();
  1228. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  1229. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  1230. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  1231. DrawState_++;
  1232. }
  1233. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  1234. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  1235. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  1236. DrawState_++;
  1237. }
  1238. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  1239. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  1240. else p->Refresh = LA_TAG_ANIMATION;
  1241. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1242. if (DrawState_) p->Refresh = LA_TAG_RECALC;
  1243. }
  1244. }
  1245. tnsDrawToScreen();
  1246. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1247. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  1248. la_PanelDrawToWindow(p, w);
  1249. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99))){
  1250. tnsUseNoTexture();
  1251. if (!p->IsMenuPanel){
  1252. la_PanelDrawDescendBorder(p, bt, MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  1253. }
  1254. tnsFlush();
  1255. }
  1256. }elif (p->AnimationMode){
  1257. la_PanelDrawToWindow(p, w);
  1258. }
  1259. }
  1260. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  1261. if(!p->Show && p!=w->MaximizedUiPanel) return;
  1262. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  1263. laPanel *pi, *PrevPI;
  1264. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  1265. PrevPI = pi->Item.pPrev;
  1266. if (pi->AnimationMode && pi->LaterDestroy){
  1267. lstRemoveItem(&p->SubPanels, pi);
  1268. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  1269. continue;
  1270. }
  1271. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  1272. la_AttachedPanelDefDraw(w,pi,bt);
  1273. }
  1274. }
  1275. }
  1276. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  1277. real PanelSquare[] = {
  1278. b->X + 2, CH - (b->Y + 2 + LA_RH),
  1279. b->X + 2, CH - (b->Y + b->H - 4),
  1280. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  1281. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  1282. real Center[] = {
  1283. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  1284. real DraggingPlot[] = {
  1285. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  1286. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  1287. PanelSquare[0],
  1288. PanelSquare[1],
  1289. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  1290. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  1291. PanelSquare[2],
  1292. PanelSquare[3],
  1293. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  1294. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  1295. PanelSquare[4],
  1296. PanelSquare[5],
  1297. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  1298. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  1299. PanelSquare[6],
  1300. PanelSquare[7],
  1301. };
  1302. real Square[] = {
  1303. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  1304. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  1305. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  1306. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  1307. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  1308. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  1309. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  1310. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  1311. };
  1312. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  1313. LA_COLOR3(BorderColor4dV), 0,
  1314. LA_COLOR3(BorderColor4dV), 0.8,
  1315. LA_COLOR3(BorderColor4dV), 0,
  1316. LA_COLOR3(BorderColor4dV), 0.8,
  1317. LA_COLOR3(BorderColor4dV), 0,
  1318. LA_COLOR3(BorderColor4dV), 0.8,
  1319. LA_COLOR3(BorderColor4dV), 0,
  1320. };
  1321. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  1322. LA_COLOR3(FillColor4dv), 0,
  1323. LA_COLOR3(FillColor4dv), 0.8,
  1324. LA_COLOR3(FillColor4dv), 0,
  1325. LA_COLOR3(FillColor4dv), 0.8,
  1326. LA_COLOR3(FillColor4dv), 0,
  1327. LA_COLOR3(FillColor4dv), 0.8,
  1328. LA_COLOR3(FillColor4dv), 0,
  1329. };
  1330. tnsUseNoTexture();
  1331. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  1332. int Index[4];
  1333. tnsVertexArray2d(DraggingPlot, 8);
  1334. tnsColorArray4d(FillColor, 8);
  1335. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  1336. case 0:
  1337. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  1338. break;
  1339. case LA_BLOCK_DROP_LOCATION_L:
  1340. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  1341. break;
  1342. case LA_BLOCK_DROP_LOCATION_R:
  1343. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  1344. break;
  1345. case LA_BLOCK_DROP_LOCATION_U:
  1346. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  1347. break;
  1348. case LA_BLOCK_DROP_LOCATION_B:
  1349. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  1350. break;
  1351. }
  1352. //glDisable(GL_CULL_FACE);
  1353. tnsIndexArray(Index, 4);
  1354. tnsPackAs(GL_TRIANGLE_FAN);
  1355. //tnsFlush();
  1356. }
  1357. tnsVertexArray2d(DraggingPlot, 8);
  1358. tnsColorArray4d(PlotColor, 8);
  1359. tnsPackAs(GL_LINES);
  1360. tnsVertexArray2d(Square, 4);
  1361. tnsColor4dv(BorderColor4dV);
  1362. tnsPackAs(GL_LINE_LOOP);
  1363. glLineWidth(LA_SEAM_W);
  1364. tnsFlush();
  1365. glLineWidth(1);
  1366. }
  1367. void la_BlockDefDrawSelf(laBlock *b, int CH){
  1368. laBoxedTheme *bt = _LA_THEME_TAB;
  1369. laPanel *p;
  1370. real v[] = {
  1371. b->X, CH - b->Y,
  1372. b->X + LA_SEAM_W, CH - b->Y ,
  1373. b->X, CH - (b->Y + b->H),
  1374. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  1375. b->X + b->W, CH - (b->Y + b->H),
  1376. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  1377. b->X + b->W, CH - b->Y,
  1378. b->X + b->W - LA_SEAM_W, CH - b->Y};
  1379. real tv[8];
  1380. real ratio = 1.0001f;
  1381. int tw = 0;
  1382. int L = LA_RH+LA_SEAM_W;
  1383. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  1384. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1385. tw += p->TitleWidth + LA_SEAM_W*2;
  1386. }
  1387. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  1388. tnsUseNoTexture();
  1389. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  1390. tnsVertexArray2d(v, 8);
  1391. tnsPackAs(GL_TRIANGLE_STRIP);
  1392. int TitleGap=b->Folded?0:LA_RH;
  1393. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  1394. b->X + b->W, (CH - b->Y),
  1395. b->X + b->W, (CH - b->Y - TitleGap),
  1396. b->X, (CH - b->Y - TitleGap));
  1397. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  1398. tnsVertexArray2d(tv, 4);
  1399. tnsPackAs(GL_TRIANGLE_FAN);
  1400. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  1401. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  1402. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  1403. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  1404. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1405. tnsVertexArray2d(tv, 4);
  1406. tnsPackAs(GL_TRIANGLE_FAN);
  1407. if(b->Folded){
  1408. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  1409. 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);
  1410. 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);
  1411. tnsFlush(); return;
  1412. }
  1413. int LT=0,RT=0;
  1414. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1415. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  1416. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  1417. b->X + L+RT * ratio, (CH - b->Y),
  1418. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  1419. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  1420. if (p == b->CurrentPanel){
  1421. tnsUseNoTexture();
  1422. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1423. tnsVertexArray2d(tv, 4);
  1424. tnsPackAs(GL_TRIANGLE_FAN);
  1425. tnsDrawStringAuto(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);
  1426. }else{
  1427. tnsDrawStringAuto(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);
  1428. }
  1429. LT =RT;
  1430. }
  1431. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  1432. tnsFlush();
  1433. tnsUniformOutputColorSpace(T->immShader,0);
  1434. }
  1435. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  1436. laBoxedTheme *bt = _LA_THEME_PANEL;
  1437. real tv[8];
  1438. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  1439. tnsUseNoTexture();
  1440. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  1441. b->X + b->W, (CH - b->Y),
  1442. b->X + b->W, (CH - b->Y-b->H),
  1443. b->X, (CH - b->Y-b->H));
  1444. tnsVertexArray2d(tv, 4);
  1445. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  1446. tnsPackAs(GL_TRIANGLE_FAN);
  1447. tnsDrawStringAuto("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,
  1448. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  1449. tnsFlush();
  1450. tnsUniformOutputColorSpace(T->immShader,0);
  1451. }
  1452. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  1453. if (b->B1){
  1454. la_BlockDefDrawRecursive(w, bt, b->B1);
  1455. la_BlockDefDrawRecursive(w, bt, b->B2);
  1456. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  1457. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  1458. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  1459. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1460. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1461. la_BlockDefDrawSelf(b, w->CH);
  1462. }else{
  1463. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1464. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1465. la_BlockDefDrawSelfEmpty(b, w->CH);
  1466. }
  1467. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  1468. tnsUseNoTexture();
  1469. int at; real tv[8];
  1470. if (b->Vertical){
  1471. at = b->H * b->SplitRatio + b->Y;
  1472. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  1473. b->X + b->W, (w->CH - at + LA_SEAM_W),
  1474. b->X + b->W, (w->CH - at - LA_SEAM_W),
  1475. b->X, (w->CH - at - LA_SEAM_W));
  1476. }else{
  1477. at = b->X + b->W * b->SplitRatio;
  1478. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  1479. at- LA_SEAM_W, (w->CH - b->Y),
  1480. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  1481. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  1482. }
  1483. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  1484. tnsVertexArray2d(tv, 4);
  1485. tnsPackAs(GL_TRIANGLE_FAN);
  1486. }
  1487. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  1488. tnsFlush();
  1489. }
  1490. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  1491. if (b->B1){
  1492. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  1493. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  1494. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  1495. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  1496. }
  1497. tnsFlush();
  1498. }
  1499. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  1500. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  1501. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  1502. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  1503. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  1504. if(p->OffScr){
  1505. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  1506. }
  1507. }
  1508. }
  1509. void la_ClearUnusedFramebuffers(laWindow* w){
  1510. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  1511. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  1512. }
  1513. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  1514. if(p->Show || p->AnimationMode) continue;
  1515. if(p->OffScr){
  1516. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  1517. }
  1518. }
  1519. }
  1520. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  1521. laPanel *p, *NextP;
  1522. laLayout *l = w->CurrentLayout;
  1523. la_ClearUnusedFramebuffers(w);
  1524. tnsDrawToScreen();
  1525. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1526. glClearColor(0.2, 0.2, 0.3, 1.0);
  1527. tnsClearAll();
  1528. tnsUseNoTexture();
  1529. if (l->Draw) l->Draw(w, l);
  1530. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  1531. //tnsShadeMode(GL_SMOOTH);
  1532. glEnable(GL_BLEND);
  1533. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1534. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  1535. laUiItem* ui;
  1536. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  1537. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  1538. if(p->Refresh){
  1539. if(p->Refresh&LA_TAG_RECALC){
  1540. la_SetPropMathcerContext(p);
  1541. laRecalcPanelImmediate(p);
  1542. }
  1543. ui->Type->Draw(ui, LA_RH); tnsFlush();
  1544. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  1545. else p->Refresh|=LA_TAG_ANIMATION;
  1546. }
  1547. tnsDrawToScreen();
  1548. tnsResetViewMatrix();
  1549. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1550. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  1551. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  1552. tnsFlush();
  1553. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  1554. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  1555. tnsFlush();
  1556. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  1557. }
  1558. }
  1559. if (DrawState_) p->Refresh = LA_TAG_RECALC;
  1560. }else{
  1561. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  1562. la_BlockDefDrawRecursive(w, bt, RootBlock);
  1563. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  1564. }
  1565. for (p = w->Panels.pLast; p; p = NextP){
  1566. NextP = p->Item.pPrev;
  1567. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  1568. if (p->AnimationMode && p->LaterDestroy){
  1569. lstRemoveItem(&w->Panels, p);
  1570. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  1571. continue;
  1572. }
  1573. la_PanelDefDraw(w, p, *p->BT);
  1574. }
  1575. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  1576. la_AttachedPanelDefDraw(w,p,*p->BT);
  1577. }
  1578. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  1579. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  1580. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1581. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  1582. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  1583. tnsFlush();
  1584. }
  1585. for (p = w->FadingPanels.pLast; p; p = NextP){
  1586. NextP = p->Item.pPrev;
  1587. if (!p->AnimationMode){
  1588. lstRemoveItem(&w->FadingPanels, p);
  1589. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY;
  1590. laDeferredDestroyPanel(p, 0);
  1591. }else
  1592. la_PanelDrawToWindow(p, w);
  1593. }
  1594. }
  1595. int laStartWindow(laWindow *w){
  1596. //ShowWindow(w->win, SW_SHOWNORMAL);
  1597. glXMakeContextCurrent(MAIN.dpy, w->win,w->win, MAIN.glc);
  1598. MAIN.CurrentWindow = w;
  1599. if(!w->CurrentLayout){
  1600. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  1601. w->CurrentLayout=w->Layouts.pFirst;
  1602. }
  1603. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  1604. w->Shown = 1;
  1605. }
  1606. void la_AssignWindowPP(laWindow* w){
  1607. w->PP.EndInstance = w;
  1608. w->PP.LastPs = &w->FakePS;
  1609. w->PP.LastPs->p = _LA_PROP_WINDOW;
  1610. w->PP.LastPs->UseInstance = w;
  1611. w->PP.LastPs->Type = L'.';
  1612. }
  1613. laWindow *laDesignWindow(int X, int Y, int W, int H){
  1614. laWindow *n = memAcquireHyper(sizeof(laWindow));
  1615. strSafeSet(&n->Title, "Empty Window");
  1616. n->X = X; n->Y = Y; n->W = W; n->H = H;
  1617. n->OutputShowStripes=1;
  1618. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  1619. lstAppendItem(&MAIN.Windows, n);
  1620. MAIN.CurrentWindow = n;
  1621. la_AssignWindowPP(n);
  1622. laui_DefaultMenuBar(n);
  1623. return n;
  1624. }
  1625. void laSetWindowCursor(int id){
  1626. //SetClassLongPtr(MAIN.CurrentWindow->win,
  1627. // GCLP_HCURSOR, LoadCursor(NULL, la_ConvertCursorID(id)));
  1628. };
  1629. void la_AssignBlockPP(laBlock* b){
  1630. b->PP.EndInstance = b;
  1631. b->PP.LastPs = &b->FakePS;
  1632. b->PP.LastPs->p = _LA_PROP_BLOCK;
  1633. b->PP.LastPs->UseInstance = b;
  1634. b->PP.LastPs->Type = L'.';
  1635. }
  1636. laLayout *laDesignLayout(laWindow *w, char *Title){
  1637. laLayout *l = memAcquireHyper(sizeof(laLayout));
  1638. l->FirstBlock = memAcquire(sizeof(laBlock));
  1639. la_AssignBlockPP(l->FirstBlock);
  1640. lstAppendItem(&w->Layouts, l);
  1641. strSafeSet(&l->ID, Title);
  1642. w->CurrentLayout = l;
  1643. laRenameWindow(w, Title);
  1644. return l;
  1645. }
  1646. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  1647. 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); }
  1648. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  1649. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  1650. laNotifyUsers("la.windows.maximized_block"); }
  1651. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  1652. laNotifyUsers("la.windows.maximized_block"); }
  1653. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  1654. laRestoreCanvasUI();
  1655. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  1656. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  1657. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; UiParentPanel->Refresh |= LA_TAG_RECALC;
  1658. UiParentPanel->Show=0;
  1659. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  1660. }
  1661. void laRestoreCanvasUI(){
  1662. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  1663. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  1664. w->MaximizedUiPanel->Refresh |= LA_TAG_RECALC; w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  1665. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  1666. }
  1667. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  1668. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; break; } }
  1669. }
  1670. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; break; } } }
  1671. void laSplitBlockHorizon(laBlock *b, real Percentage){
  1672. laPanel *p;
  1673. b->SplitRatio = Percentage;
  1674. b->Vertical = 0;
  1675. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  1676. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  1677. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1678. p->Block = b->B1;
  1679. }
  1680. b->B1->Panels.pFirst = b->Panels.pFirst;
  1681. b->B1->Panels.pLast = b->Panels.pLast;
  1682. b->B1->CurrentPanel = b->CurrentPanel;
  1683. b->B1->parent = b->B2->parent=b;
  1684. b->Panels.pFirst = 0;
  1685. b->Panels.pLast = 0;
  1686. b->CurrentPanel = 0;
  1687. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1688. }
  1689. void laSplitBlockVertical(laBlock *b, real Percentage){
  1690. laPanel *p;
  1691. b->SplitRatio = Percentage;
  1692. b->Vertical = 1;
  1693. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  1694. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  1695. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1696. p->Block = b->B1;
  1697. }
  1698. b->B1->Panels.pFirst = b->Panels.pFirst;
  1699. b->B1->Panels.pLast = b->Panels.pLast;
  1700. b->B1->CurrentPanel = b->CurrentPanel;
  1701. b->B1->parent = b->B2->parent=b;
  1702. b->Panels.pFirst = 0;
  1703. b->Panels.pLast = 0;
  1704. b->CurrentPanel = 0;
  1705. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1706. }
  1707. void laCombineChildBlocks(laBlock *b){
  1708. laPanel *p; if(!b) return;
  1709. if (!b->B1->B1 && !b->B2->B1){
  1710. lstCombineLists(&b->Panels, &b->B1->Panels);
  1711. lstCombineLists(&b->Panels, &b->B2->Panels);
  1712. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1713. p->Block = b;
  1714. }
  1715. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  1716. memFree(b->B1);
  1717. memFree(b->B2);
  1718. b->B1 = 0;
  1719. b->B2 = 0;
  1720. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1721. }elif(!b->B1->B1){
  1722. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  1723. b->Vertical = b->B2->Vertical;
  1724. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  1725. p->Block = b1;
  1726. }
  1727. lstCombineLists(&b1->Panels, &b->B1->Panels);
  1728. memFree(b->B1); memFree(b->B2);
  1729. b->B1 = b1; b->B2 = b2;
  1730. b1->parent = b; b2->parent = b;
  1731. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1732. }elif(!b->B2->B1){
  1733. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  1734. b->Vertical = b->B1->Vertical;
  1735. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  1736. p->Block = b1;
  1737. }
  1738. lstCombineLists(&b1->Panels, &b->B2->Panels);
  1739. memFree(b->B1); memFree(b->B2);
  1740. b->B1 = b1; b->B2 = b2;
  1741. b1->parent = b; b2->parent = b;
  1742. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1743. }
  1744. }
  1745. laBlock *laBlock1(laBlock *b){
  1746. return b->B1;
  1747. }
  1748. laBlock *laBlock2(laBlock *b){
  1749. return b->B2;
  1750. }
  1751. laBlock *laSwapSubBlocks(laBlock *b){
  1752. laBlock *tB;
  1753. tB = b->B2;
  1754. b->B2 = b->B1;
  1755. b->B1 = tB;
  1756. b->SplitRatio = 1 - b->SplitRatio;
  1757. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1758. }
  1759. void laDestroyBlocksRecursive(laBlock *Root){
  1760. laPanel *p;
  1761. if (Root->B1){
  1762. laDestroyBlocksRecursive(Root->B1);
  1763. laDestroyBlocksRecursive(Root->B2);
  1764. }else{
  1765. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  1766. }
  1767. memFree(Root);
  1768. }
  1769. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  1770. if(!b->CurrentPanel ) return 0;
  1771. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  1772. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  1773. lstRemoveItem(&b->Panels, p);
  1774. if(!b->CurrentPanel && b->parent){
  1775. b=b->parent;
  1776. laCombineChildBlocks(b);
  1777. }
  1778. if(!p->TitleBar.UiItems.pFirst){
  1779. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  1780. }
  1781. p->Mode = LA_PANEL_FLOATING_TOP;
  1782. p->TY-=LA_RH;
  1783. p->TH+=LA_RH;
  1784. p->Refresh=LA_TAG_RECALC;
  1785. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  1786. p->BT = &_LA_THEME_FLOATING_PANEL;
  1787. p->Block = 0;
  1788. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  1789. laNotifyUsers("la.windows.panels");
  1790. return b->CurrentPanel;
  1791. }
  1792. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  1793. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  1794. lstRemoveItem(&from->Panels, p);
  1795. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  1796. p->Mode = LA_PANEL_NORMAL;
  1797. p->Block=b;
  1798. b->CurrentPanel = p;
  1799. lstPushItem(&b->Panels, p);
  1800. p->Refresh=LA_TAG_RECALC;
  1801. p->BT = &_LA_THEME_PANEL;
  1802. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  1803. tnsFlush();
  1804. laNotifyUsers("la.windows.panels");
  1805. }
  1806. void laPopPanel(laPanel *p){
  1807. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  1808. lstRemoveItem(&p->Parent->SubPanels, p);
  1809. lstPushItem(&p->Parent->SubPanels, p);
  1810. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  1811. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  1812. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  1813. laNotifyUsers("la.windows.panels");
  1814. }
  1815. }
  1816. void la_EnsurePanelExtras(laPanel *p){
  1817. laUiTemplate* uit=p->PanelTemplate;
  1818. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  1819. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  1820. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  1821. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  1822. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  1823. p->PropLinkFakeProp->Base.Offset = 0;
  1824. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  1825. p->PropLinkPP.EndInstance = p;
  1826. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  1827. p->PropLinkPP.LastPs->Type = L'.';
  1828. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  1829. }
  1830. laPanel* la_GivePanelNode(){
  1831. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  1832. return memAcquire(sizeof(laPanel));
  1833. }
  1834. void la_ReturnPanelNode(laPanel* p){
  1835. memset(p,0,sizeof(laPanel));
  1836. lstAppendItem(&MAIN.WastedPanels, p);
  1837. }
  1838. 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){
  1839. laPanel *p = la_GivePanelNode();
  1840. int CW = MAIN.CurrentWindow->CW;
  1841. int CH = MAIN.CurrentWindow->CH;
  1842. p->PanelTemplate = uit;
  1843. if (!MaxW) MaxW = 10000;
  1844. if (!MaxH) MaxH = 10000;
  1845. if (W > MaxW) W = MaxW;
  1846. if (H > MaxH) H = MaxH;
  1847. if (W < MinW) W = MinW;
  1848. if (H < MinH) H = MinH;
  1849. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  1850. p->X = p->TX = (X < 0 ? 0 : X);
  1851. p->Y = p->TY = (Y < 0 ? 0 : Y);
  1852. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  1853. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  1854. p->MaxW = MaxW;
  1855. p->MaxH = MaxH;
  1856. p->MinW = MinW;
  1857. p->MinH = MinH;
  1858. p->SL = SnapL;
  1859. p->ST = SnapT;
  1860. p->SR = SnapR;
  1861. p->SB = SnapB;
  1862. if (p->SR) p->X = CW - p->W - p->SR;
  1863. if (p->SB) p->Y = CH - p->H - p->SB;
  1864. la_EnsurePanelSnapping(p, CW, CH);
  1865. p->Show = 1;
  1866. p->PP.EndInstance = p;
  1867. p->PP.LastPs = &p->FakePS;
  1868. p->PP.LastPs->p = _LA_PROP_PANEL;
  1869. p->PP.LastPs->UseInstance = p;
  1870. p->PP.LastPs->Type = L'.';
  1871. la_EnsurePanelExtras(p);
  1872. p->Refresh = LA_TAG_RECALC;
  1873. p->FrameDistinguish = 100; //greater than 1 is ok
  1874. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  1875. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  1876. return p;
  1877. }
  1878. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  1879. if(!uit) return 0;
  1880. laPanel *p = memAcquireHyper(sizeof(laPanel));
  1881. strSafeSet(&p->Title, uit->Title->Ptr);
  1882. p->PanelTemplate = uit;
  1883. p->DefaultGLFormat=uit->DefaultGLFormat?uit->DefaultGLFormat:GL_RGBA8;
  1884. p->Show = 1;
  1885. p->PP.EndInstance = p;
  1886. p->PP.LastPs = &p->FakePS;
  1887. p->PP.LastPs->p = _LA_PROP_PANEL;
  1888. p->PP.LastPs->UseInstance = p;
  1889. p->PP.LastPs->Type = L'.';
  1890. la_EnsurePanelExtras(p);
  1891. p->Refresh = LA_TAG_RECALC;
  1892. p->FrameDistinguish = 100; //greater than 1 is ok
  1893. p->TitleWidth = tnsStringGetWidth(p->Title->Ptr, 0, 0);
  1894. while (b->B1){
  1895. b = b->B1;
  1896. }
  1897. lstPushItem(&b->Panels, p);
  1898. p->Block = b;
  1899. b->CurrentPanel = p;
  1900. if(uit->PropFunc){ uit->PropFunc(p); }
  1901. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  1902. laNotifyUsers("la.windows.panels");
  1903. return p;
  1904. }
  1905. laPanel *laCreatePanel(laBlock *b, char *template_id){
  1906. laUiTemplate* uit=laFindUiTemplate(template_id);
  1907. return laCreatePanelT(b, uit);
  1908. }
  1909. 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){
  1910. laUiTemplate* uit=0;
  1911. if(template_id) uit=laFindUiTemplate(template_id);
  1912. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  1913. p->Mode = LA_PANEL_FLOATING_TOP;
  1914. if(uit){
  1915. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  1916. }
  1917. if (w) lstPushItem(&w->Panels, p);
  1918. return p;
  1919. }
  1920. void laShowPanel(laPanel *p){
  1921. p->Show = 1;
  1922. laNotifyUsers("la.windows.panels_hidden");
  1923. }
  1924. void laShowPanelWithDropDownEffect(laPanel *p){
  1925. laShowPanel(p);
  1926. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN;
  1927. p->AnimationRatio = 0;
  1928. }
  1929. void laShowPanelWithExpandEffect(laPanel *p){
  1930. laShowPanel(p);
  1931. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND;
  1932. p->AnimationRatio = 0;
  1933. }
  1934. void laHidePanel(laPanel *p){
  1935. if (!p->Mode) return;
  1936. p->Show = 0;
  1937. laNotifyUsers("la.windows.panels_hidden");
  1938. }
  1939. void laHidePanelWithDissoveEffect(laPanel *p){
  1940. if (!p->Mode) return;
  1941. laHidePanel(p);
  1942. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE;
  1943. p->AnimationRatio = 1;
  1944. }
  1945. void laHidePanelWithCollapseEffect(laPanel *p){
  1946. if (!p->Mode) return;
  1947. laHidePanel(p);
  1948. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE;
  1949. p->AnimationRatio = 1;
  1950. }
  1951. void laHidePanelWithMinimizeEffect(laPanel *p){
  1952. if (!p->Mode) return;
  1953. laHidePanel(p);
  1954. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE;
  1955. p->AnimationRatio = 1;
  1956. }
  1957. void laActivatePanel(char* TemplateID, int x, int y){
  1958. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  1959. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  1960. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 400,400, 0, 0, 0, 0, 0, 0, 0, 0); }
  1961. laShowPanelWithExpandEffect(p); laPopPanel(p);
  1962. }
  1963. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  1964. p->UI.PanX += DeltaX;
  1965. p->UI.PanY += DeltaY;
  1966. }
  1967. int laPanUiListFree(laUiList *uil, int X, int Y){
  1968. uil->PanX+=X; uil->PanY+=Y;
  1969. }
  1970. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  1971. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  1972. if(Y){X+=Y;Y=0;}
  1973. }
  1974. if (Y > 0){
  1975. if (uil->B - uil->PanY <= B) return 0;
  1976. else{
  1977. uil->PanY += Y;
  1978. if (uil->B - uil->PanY <= B){
  1979. uil->PanY = uil->B - B;
  1980. return 1;
  1981. }
  1982. }
  1983. }
  1984. if (Y < 0){
  1985. if (uil->U - uil->PanY >= U) return 0;
  1986. else{
  1987. uil->PanY += Y;
  1988. if (uil->U - uil->PanY >= U){
  1989. uil->PanY = uil->U - U;
  1990. return 1;
  1991. }
  1992. }
  1993. }
  1994. if(uil->AllowScale){
  1995. laPanUiListFree(uil, X, 0);
  1996. }else{
  1997. if (X > 0){
  1998. if (uil->R - uil->PanX <= R) return 0;
  1999. else{
  2000. uil->PanX += X;
  2001. if (uil->R - uil->PanX <= R){
  2002. uil->PanX = uil->R - R;
  2003. return 1;
  2004. }
  2005. }
  2006. }
  2007. if (X < 0){
  2008. if (uil->L - uil->PanX >= L) return 0;
  2009. else{
  2010. uil->PanX += X;
  2011. if (uil->L - uil->PanX >= L){
  2012. uil->PanX = uil->L - L;
  2013. return 1;
  2014. }
  2015. }
  2016. }
  2017. }
  2018. return 1;
  2019. }
  2020. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  2021. int ret=1;
  2022. if(!uil->AllowScale){ return 0; }
  2023. real NewScale=uil->Scale*factor;
  2024. if(NewScale<0.2){NewScale=0.2; ret=0;}
  2025. if(NewScale>5) {NewScale=5; ret=0;}
  2026. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  2027. factor=NewScale/uil->Scale;
  2028. uil->Scale=NewScale;
  2029. real mx=(L+R)/2,my=(U+B)/2;
  2030. real dx= (mx+uil->PanX)*factor;
  2031. real dy= (my+uil->PanY)*factor;
  2032. uil->PanX=dx-mx;
  2033. uil->PanY=dy-my;
  2034. MAIN.CurrentPanel->FrameDistinguish=100;
  2035. return ret;
  2036. }
  2037. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  2038. if(uil->AllowScale) return 0;
  2039. return laPanUiList(uil,X,Y,L,R,U,B);
  2040. }
  2041. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  2042. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2043. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  2044. strSafeSet(&p->Title, Title);
  2045. if (Define){
  2046. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2047. }
  2048. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2049. p->BT= &_LA_THEME_FLOATING_PANEL;
  2050. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  2051. p->BoundUi = 1;
  2052. return p;
  2053. }
  2054. 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,
  2055. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2056. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  2057. strSafeSet(&p->Title, Title);
  2058. if (Define){
  2059. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2060. }
  2061. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2062. p->BT= &_LA_THEME_FLOATING_PANEL;
  2063. p->Mode = LA_PANEL_FLOATING_TOP;
  2064. p->BoundUi = 1;
  2065. return p;
  2066. }
  2067. void laDeferredDestroyPanel(laPanel *p, int immediate){
  2068. laPanel *ip;
  2069. tnsDelete2DOffscreen(p->OffScr);
  2070. p->OffScr = 0;
  2071. strSafeDestroy(&p->Title);
  2072. if (!p->AnimationMode){
  2073. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  2074. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2075. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2076. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  2077. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2078. }else if (p->Block){
  2079. lstRemoveItem(&p->Block->Panels, p);
  2080. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  2081. }
  2082. laNotifyUsers("la.windows.panels");
  2083. }
  2084. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  2085. //lstRemoveItem(&p->SubPanels, ip);
  2086. laDestroySinglePanel(ip, immediate);
  2087. laNotifyUsers("la.windows.panels");
  2088. }
  2089. la_ClearDetachedProp(p);
  2090. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  2091. la_ReturnPanelNode(p);
  2092. }
  2093. void laDestroySinglePanel(laPanel *p, int immediate){
  2094. la_SetPropMathcerContext(p);
  2095. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  2096. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  2097. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  2098. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  2099. }
  2100. }
  2101. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  2102. la_DestroyUiList(&p->UI, 1, 1, 0);
  2103. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2104. la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  2105. if (p->Mode){
  2106. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE;
  2107. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  2108. }
  2109. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  2110. if (la_UiStillInService(p)){
  2111. la_StopUiOperatorService(p);
  2112. }
  2113. if ((!p->AnimationMode) || immediate){
  2114. laDeferredDestroyPanel(p, immediate);
  2115. }else{
  2116. p->LaterDestroy = 1;
  2117. }
  2118. }
  2119. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  2120. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2121. int MinW,MinWt=0;
  2122. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  2123. int CW = MAIN.CurrentWindow->CW;
  2124. if(p->SL && p->SR){return 0;}
  2125. la_SetPropMathcerContext(p);
  2126. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  2127. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  2128. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  2129. MinW = la_TestUiListMinumWidth(uil);
  2130. if (MinW<MinWt){MinW=MinWt;}
  2131. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  2132. if (MinW > 20){
  2133. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  2134. }
  2135. la_PanelValidateWidth(p,uil);
  2136. laEnsurePanelInBound(p,uil);
  2137. if(p->TW>CW){ p->TW=CW; }
  2138. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  2139. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  2140. p->Refresh=LA_TAG_REDRAW;
  2141. return 1;
  2142. }
  2143. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  2144. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2145. laOperator *ai = a;
  2146. laPanel *p;
  2147. int GX, GY, GW, t = 0;
  2148. int b;
  2149. laUiDefineFunc def = ReplaceUiDefine;
  2150. int MinW;
  2151. if (!def){ def=laui_DefaultPropDetails; }
  2152. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  2153. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  2154. laEnclosePanelContent(p, &p->UI);
  2155. laSetOperatorLocalizer(p);
  2156. p->CloseWhenMovedOut=1;
  2157. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2158. //laShowPanelWithDropDownEffect(p);
  2159. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  2160. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  2161. return p;
  2162. }
  2163. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  2164. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2165. laOperator *ai = a;
  2166. laPanel *p; laPropContainer* sub;
  2167. int GX, GY, GW, t = 0;
  2168. int b;
  2169. laUiDefineFunc def = ReplaceUiDefine;
  2170. int MinW;
  2171. if (!def){
  2172. if (This && This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  2173. if ((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  2174. else def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  2175. }
  2176. GX = L; GY = B;
  2177. GW = (R - L) > MaxW ? MaxW : (R - L);
  2178. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  2179. laEnclosePanelContent(p, &p->UI);
  2180. laSetOperatorLocalizer(p);
  2181. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2182. laShowPanelWithDropDownEffect(p);
  2183. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  2184. if(Attachment){
  2185. p->Parent = Attachment;
  2186. lstAppendItem(&Attachment->SubPanels, p);
  2187. }
  2188. return p;
  2189. }
  2190. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  2191. laPanel *p;
  2192. int t = 0;
  2193. int b;
  2194. //laLocalToWindow(0, Attachment, &L, &t);
  2195. //laLocalToWindow(0, Attachment, &R, &U);
  2196. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  2197. laSetOperatorLocalizer(p);
  2198. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2199. laShowPanelWithDropDownEffect(p);
  2200. p->Parent = Attachment;
  2201. lstPushItem(&Attachment->SubPanels, p);
  2202. return p;
  2203. }
  2204. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  2205. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2206. laOperator *ai = a;
  2207. laPanel *p;
  2208. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2209. int GX, GY, GW, t = 0;
  2210. int b;
  2211. int MinW;
  2212. //laLocalToWindow(0,Attachment, &L, &t);
  2213. //laLocalToWindow(0,Attachment, &R, &B);
  2214. GX = L;
  2215. GY = B;
  2216. GW = (R - L) > MaxW ? MaxW : (R - L);
  2217. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2218. p->MenuRefer = MenuRefer;
  2219. laEnclosePanelContent(p, MenuRefer);
  2220. laSetOperatorLocalizer(p);
  2221. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2222. laShowPanelWithDropDownEffect(p);
  2223. p->Parent = Attachment;
  2224. lstPushItem(&Attachment->SubPanels, p);
  2225. return p;
  2226. }
  2227. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  2228. int L, int B, int MaxGH, int MaxW, laEvent *e){
  2229. laOperator *ai = a;
  2230. laPanel *p;
  2231. int GX, GY, GW, t = 0;
  2232. int b;
  2233. GX = L;
  2234. GY = B;
  2235. GW = MaxW;
  2236. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2237. p->MenuRefer = &p->UI;
  2238. p->Mode = LA_PANEL_NO_PARENT_MENU;
  2239. laSetOperatorLocalizer(p);
  2240. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2241. laShowPanelWithDropDownEffect(p);
  2242. if (Attachment){
  2243. p->Parent = Attachment;
  2244. lstPushItem(&Attachment->SubPanels, p);
  2245. }else{
  2246. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2247. }
  2248. return p;
  2249. }
  2250. 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){
  2251. laOperator *ai = For;
  2252. laPanel *p;
  2253. int b;
  2254. laUiDefineFunc def = 0;
  2255. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  2256. else def = laui_DefaultPropUiDefine;
  2257. For->PP.EndInstance = For->CustomData;
  2258. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  2259. laEnclosePanelContent(p, &p->UI);
  2260. MAIN.ToPanel = p;
  2261. laShowPanelWithExpandEffect(p);
  2262. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2263. ai->OperatorPanel = p;
  2264. p->ParentOperator = For;
  2265. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  2266. return p;
  2267. }
  2268. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2269. laPanel *p;
  2270. int b;
  2271. laUiList *uil;
  2272. laColumn *col, *cor, *corl, *corr;
  2273. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  2274. strSafeSet(&p->Title, Title);
  2275. p->BoundUi = 1;
  2276. p->Mode = LA_PANEL_FLOATING_TOP;
  2277. p->BT = &_LA_THEME_FLOATING_PANEL;
  2278. MAIN.ToPanel = p;
  2279. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2280. uil = laPrepareUi(p);
  2281. col = laFirstColumn(uil);
  2282. laSplitColumn(uil, col, 0.5);
  2283. cor = laRightColumn(col, 600);
  2284. laShowLabel(uil, col, Message, 0, 0);
  2285. laShowItem(uil, cor, 0, "LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  2286. laEnclosePanelContent(p,uil);
  2287. laShowPanelWithExpandEffect(p);
  2288. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2289. laSetOperatorLocalizer(p);
  2290. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2291. return p;
  2292. }
  2293. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2294. laPanel *p;
  2295. int b;
  2296. laUiList *uil;
  2297. laColumn *col, *cor, *corl, *corr;
  2298. p = la_NewPanel(0, X, Y, W, 0, 1000, 90, 100, 0, 0, 0, 0, 0);
  2299. strSafeSet(&p->Title, Title);
  2300. p->BoundUi = 1;
  2301. p->Mode = LA_PANEL_FLOATING_TOP;
  2302. p->BT = &_LA_THEME_FLOATING_PANEL;
  2303. MAIN.ToPanel = p;
  2304. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2305. uil = laPrepareUi(p);
  2306. col = laFirstColumn(uil);
  2307. laSplitColumn(uil, col, 0.35);
  2308. cor = laRightColumn(col, 200);
  2309. laShowLabel(uil, col, Message, 0, 0);
  2310. laShowItemFull(uil, cor, 0, "LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  2311. laEnclosePanelContent(p,uil);
  2312. laShowPanelWithExpandEffect(p);
  2313. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2314. laSetOperatorLocalizer(p);
  2315. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2316. return p;
  2317. }
  2318. laPanel *laEnableMultiMessagePanel(laOperator *a, laPanel *Attachment, char *Title, laPanelMessageList *pml, int X, int Y, int W, laEvent *e){
  2319. laPanel *p;
  2320. int b;
  2321. laUiList *uil;
  2322. laColumn *col, *cor, *corl, *corr;
  2323. laPanelMessage *pm;
  2324. p = la_NewPanel(0, X, Y, W, 0, 1000, 1000, 100, 0, 0, 0, 0, 0);
  2325. strSafeSet(&p->Title, Title);
  2326. p->BoundUi = 1;
  2327. p->Mode = LA_PANEL_FLOATING_TOP;
  2328. p->BT = &_LA_THEME_FLOATING_PANEL;
  2329. MAIN.ToPanel = p;
  2330. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2331. uil = laPrepareUi(p);
  2332. col = laFirstColumn(uil);
  2333. laSplitColumn(uil, col, 0.35);
  2334. cor = laRightColumn(col, 200);
  2335. while (pm = lstPopItem(pml)){
  2336. laShowLabel(uil, col, pm->Message->Ptr, 0, 0);
  2337. strSafeDestroy(&pm->Message);
  2338. FreeMem(pm);
  2339. }
  2340. laShowItemFull(uil, cor, 0, "LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  2341. laShowPanelWithExpandEffect(p);
  2342. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2343. laSetOperatorLocalizer(p);
  2344. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2345. return p;
  2346. }
  2347. void laAddPanelMessage(laPanelMessageList *pml, char *Message){
  2348. if (!Message || !Message[0]) return;
  2349. laPanelMessage *pm = CreateNew(laPanelMessage);
  2350. strSafeSet(&pm->Message, Message);
  2351. lstAppendItem(&pml->Msg, pm);
  2352. }
  2353. void laRedrawAllWindows(){
  2354. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext) la_UpdateUiPlacement(w);
  2355. }
  2356. void laRedrawCurrentWindow(){
  2357. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  2358. }
  2359. void laRedrawCurrentPanel(){
  2360. if (MAIN.CurrentPanel) MAIN.CurrentPanel->Refresh |= LA_TAG_REDRAW;
  2361. elif (MAIN.CurrentWindow->MaximizedUiPanel) MAIN.CurrentWindow->MaximizedUiPanel->Refresh |= LA_TAG_REDRAW;
  2362. }
  2363. void laRecalcCurrentPanel(){
  2364. if (MAIN.CurrentPanel) MAIN.CurrentPanel->Refresh |= LA_TAG_RECALC;
  2365. elif (MAIN.CurrentWindow->MaximizedUiPanel) MAIN.CurrentWindow->MaximizedUiPanel->Refresh |= LA_TAG_RECALC;
  2366. }
  2367. void laRecalcPanelImmediate(laPanel* p){
  2368. p->FrameDistinguish++;
  2369. laBoxedTheme* bt = (*p->BT);
  2370. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  2371. la_PanelRefreshDetachedProp(p);
  2372. int enclosed=0;
  2373. if(p->BoundUi || p->MenuRefer){
  2374. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  2375. else enclosed=laEnclosePanelContent(p, &p->UI);
  2376. }
  2377. if(!enclosed){
  2378. la_PanelValidateWidth(p,&p->UI);
  2379. //laEnsurePanelInBound(p,&p->UI);
  2380. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->TM-bt->BM, 0, p);
  2381. la_UpdateUiListRecursive(&p->UI, bt->TM+p->TitleBar.TB, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->TM-bt->BM, 0, p);
  2382. }
  2383. laWindow* w=MAIN.CurrentWindow;
  2384. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  2385. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  2386. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  2387. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  2388. }
  2389. }
  2390. void laRecalcCurrentPanelImmediate(){
  2391. laRecalcPanelImmediate(MAIN.CurrentPanel);
  2392. }
  2393. int laNonFixedPanelExists(laPanel *p){
  2394. laPanel *ip;
  2395. if (!p) return 0;
  2396. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2397. // if (ip == p) return 1;
  2398. //}
  2399. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2400. if (ip == p) return 1;
  2401. }
  2402. return 0;
  2403. }
  2404. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  2405. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  2406. return 1;
  2407. }
  2408. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  2409. int tt=MAIN.TooltipCloseDistance;
  2410. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  2411. return 1;
  2412. }
  2413. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  2414. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  2415. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  2416. return 0;
  2417. return 1;
  2418. }
  2419. void laUnlinkSharedPanel(laPanel *p){
  2420. laWindow *w;
  2421. laPanel *ip;
  2422. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  2423. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  2424. if (ip == p){
  2425. lstRemoveItem(&w->Panels, ip);
  2426. return;
  2427. }
  2428. }
  2429. }
  2430. }
  2431. int laIsPanelCovered(laPanel *p){
  2432. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  2433. laPanel *ip;
  2434. laPanel *resp;
  2435. int in1 = 0, in2 = 0, in3 = 0;
  2436. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  2437. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2438. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  2439. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  2440. //}
  2441. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2442. if (ip == p){
  2443. in3 = 1;
  2444. d3 = 0;
  2445. continue;
  2446. }
  2447. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  2448. }
  2449. if (!in2 && !in3) in1 = 1;
  2450. if (in1){
  2451. if (d1 || d2 || d3) return 1;
  2452. }else{
  2453. if (in2){
  2454. if (d2 || d3) return 1;
  2455. }else if (in3)
  2456. if (d3) return 1;
  2457. }
  2458. return 0;
  2459. }
  2460. int laIsTopPanel(laPanel *p){
  2461. //if (!p->Item.pPrev) return 1;
  2462. //else {
  2463. if (!laIsPanelCovered(p)){
  2464. //laPopPanel(p);
  2465. return 1;
  2466. }
  2467. return 0;
  2468. //}
  2469. return 0;
  2470. }
  2471. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  2472. if(!p) return;
  2473. int ix = *x, iy = *y;
  2474. laListItemPointer *lip;
  2475. laOperator *ai = a;
  2476. (*x) = ix - p->X;
  2477. (*y) = iy - p->Y;
  2478. if (a){
  2479. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2480. laUiList *uil = lip->p;
  2481. (*x) += uil->PanX;
  2482. (*y) += uil->PanY;
  2483. }
  2484. }
  2485. }
  2486. void laPanelToLocal(laOperator *a, int *x, int *y){
  2487. int ix = *x, iy = *y;
  2488. laListItemPointer *lip;
  2489. if (a){
  2490. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2491. laUiList *uil = lip->p;
  2492. (*x) += uil->PanX;
  2493. (*y) += uil->PanY;
  2494. }
  2495. }
  2496. }
  2497. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  2498. if(!p) return;
  2499. int ix = *x, iy = *y;
  2500. laListItemPointer *lip;
  2501. (*x) = ix + p->X;
  2502. (*y) = iy + p->Y;
  2503. if (a){
  2504. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2505. laUiList *uil = lip->p;
  2506. (*x) -= uil->PanX;
  2507. (*y) -= uil->PanY;
  2508. }
  2509. }
  2510. }
  2511. void laPanelToWindow(laPanel *p, int *x, int *y){
  2512. int ix = *x, iy = *y;
  2513. laListItemPointer *lip;
  2514. (*x) = ix + p->X;
  2515. (*y) = iy + p->Y;
  2516. }
  2517. void laLocalToPanel(laOperator *a, int *x, int *y){
  2518. int ix = *x, iy = *y;
  2519. laListItemPointer *lip;
  2520. if (a){
  2521. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2522. laUiList *uil = lip->p;
  2523. (*x) -= uil->PanX;
  2524. (*y) -= uil->PanY;
  2525. }
  2526. }
  2527. }
  2528. void laSetNextMenuPos(int X, int Y, int W, int H){
  2529. MAIN.NextX = X;
  2530. MAIN.NextY = Y;
  2531. MAIN.NextW = W;
  2532. MAIN.NextH = H;
  2533. }
  2534. int laIsInBlock(laBlock *b, int X, int Y){
  2535. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  2536. return 0;
  2537. }
  2538. 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; }
  2539. 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; }
  2540. 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; }
  2541. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  2542. laPanel *p;
  2543. laBlock *sb = 0;
  2544. if (!laIsInBlock(b, X, Y)) return 0;
  2545. if (!b->B1 && !b->B2) return b;
  2546. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  2547. return laDetectBlockRecursive(b->B2, X, Y);
  2548. }
  2549. laPanel *laDetectPanel(int X, int Y){
  2550. laPanel *p; laBlock *b;
  2551. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  2552. int x = X, y = Y;
  2553. laWindowToLocal(0, p, &x, &y);
  2554. if (p->Show && laIsInPanel(p, x, y)){
  2555. return p;
  2556. }
  2557. }
  2558. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  2559. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  2560. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  2561. return 0;
  2562. }
  2563. laUiList *laPrepareUi(laPanel *p){
  2564. return &p->UI;
  2565. }
  2566. laColumn *laFirstColumn(laUiList *uil){
  2567. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  2568. else{
  2569. laColumn *c = memAcquireSimple(sizeof(laColumn));
  2570. c->SP = 1;
  2571. c->PreWidth = 1;
  2572. lstAppendItem(&uil->Columns, c);
  2573. c->Top = c;
  2574. return uil->Columns.pFirst;
  2575. }
  2576. }
  2577. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  2578. laColumn *lc, *rc;
  2579. if (c->LS || c->RS) return c;
  2580. lc = memAcquireSimple(sizeof(laColumn));
  2581. rc = memAcquireSimple(sizeof(laColumn));
  2582. c->LS = lc;
  2583. c->RS = rc;
  2584. c->LS->SP = Percent;
  2585. c->RS->SP = Percent;
  2586. c->LS->Top = c->Top;
  2587. c->RS->Top = c->Top;
  2588. if (uil){
  2589. lstAppendItem(&uil->Columns, lc);
  2590. lstAppendItem(&uil->Columns, rc);
  2591. }
  2592. if (c->LS && c->RS->MaxW == 0){
  2593. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  2594. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  2595. }else if (c->RS && c->LS->MaxW == 0){
  2596. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  2597. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  2598. }
  2599. return c;
  2600. }
  2601. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  2602. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  2603. return c->LS;
  2604. }
  2605. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  2606. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  2607. if (MaxWidth) c->RS->MaxW = MaxWidth;
  2608. return c->RS;
  2609. }
  2610. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  2611. lstRemoveItem(List, c);
  2612. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  2613. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  2614. memFree(c);
  2615. }
  2616. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  2617. laUiList *uil = TopUil;
  2618. laUiList *sub;
  2619. laUiItem *ui;
  2620. laColumn *cc, *NextCC = 0;
  2621. int Occupied = 0;
  2622. int Removed = 0;
  2623. if (!c->LS) return 0;
  2624. else{
  2625. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  2626. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  2627. }
  2628. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  2629. if (ui->C == c->LS || ui->C == c->RS){
  2630. if (DoMerge){
  2631. ui->C = c;
  2632. Occupied = 1;
  2633. }else
  2634. return 1;
  2635. }
  2636. if (ui->Subs.pFirst){
  2637. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2638. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  2639. }
  2640. }
  2641. }
  2642. if (!Removed){
  2643. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  2644. if (cc == c){
  2645. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  2646. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  2647. c->LS = 0;
  2648. c->RS = 0;
  2649. Removed = 1;
  2650. break;
  2651. }
  2652. }
  2653. }
  2654. return Occupied;
  2655. }
  2656. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int hyper){
  2657. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,L'◳',0,size,0,0,hyper);
  2658. ut->FakeProp = memAcquire(sizeof(laSubProp));
  2659. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  2660. ut->FakeProp->Base.Identifier = ut->Identifier;
  2661. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  2662. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  2663. ut->FakeProp->Base.OffsetIsPointer = 1;
  2664. //ut->FakeProp->Base.Container = ut->ExtraProps;
  2665. return ut->ExtraProps;
  2666. }
  2667. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int hyper){
  2668. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,L'◳',0,size,0,0,hyper);
  2669. ct->FakeProp = memAcquire(sizeof(laSubProp));
  2670. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  2671. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  2672. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  2673. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  2674. ct->FakeProp->Base.OffsetIsPointer = 1;
  2675. //ut->FakeProp->Base.Container = ut->ExtraProps;
  2676. return ct->ExtraProps;
  2677. }
  2678. void la_DestroyUiType(laUiType* uit){
  2679. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  2680. memFree(uit);
  2681. }
  2682. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  2683. laUiType *ut = memAcquire(sizeof(laUiType));
  2684. ut->Identifier = Identifer;
  2685. ut->OperatorID = UseOperator;
  2686. ut->Draw = Draw;
  2687. ut->Theme = bt;
  2688. ut->ForType = ForType;
  2689. ut->OperatorType = laGetOperatorType(UseOperator);
  2690. ut->GetHeight = GetHeight;
  2691. ut->Init = Init;
  2692. ut->Destroy = Destroy;
  2693. la_UDFAppendSharedTypePointer(Identifer, ut);
  2694. lstAppendItem(&MAIN.UiTypes, ut);
  2695. return ut;
  2696. }
  2697. laUiType *la_GetUiTypeFromProperty(laProp *P){
  2698. laUiType *ut = MAIN.UiTypes.pFirst;
  2699. if (!P) return 0;
  2700. if (P->DefaultUiType) return P->DefaultUiType;
  2701. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  2702. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  2703. for (ut; ut; ut = ut->Item.pNext){
  2704. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  2705. return ut;
  2706. }
  2707. }
  2708. return 0;
  2709. }
  2710. laUiType *la_GetUiButtonType(){
  2711. laUiType *ut = MAIN.UiTypes.pFirst;
  2712. for (ut; ut; ut = ut->Item.pNext){
  2713. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  2714. }
  2715. return 0;
  2716. }
  2717. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  2718. laCanvasTemplate *vdt;
  2719. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  2720. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  2721. }
  2722. return 0;
  2723. }
  2724. void la_AssignPropExtras(laUiItem* ui){
  2725. if(!ui->Type || !ui->Type->FakeProp) return;
  2726. ui->FakePs.p = ui->Type->FakeProp;
  2727. ui->FakePs.Type = L'.';
  2728. ui->FakePs.UseInstance = ui;
  2729. ui->ExtraPP.LastPs = &ui->FakePs;
  2730. }
  2731. void la_AssignCanvasPropExtras(laUiItem* ui){
  2732. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  2733. laCanvasTemplate*ct=ui->CanvasTemplate;
  2734. ui->FakePs.p = ct->FakeProp;
  2735. ui->FakePs.Type = L'.';
  2736. ui->FakePs.UseInstance = ui;
  2737. ui->ExtraPP.EndInstance = ui->Extra;
  2738. ui->ExtraPP.LastPs = &ui->FakePs;
  2739. }
  2740. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  2741. int result;
  2742. if (!ui) return;
  2743. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  2744. if (Path){
  2745. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  2746. if (!result){
  2747. ui->AT = laGetOperatorType(Path);
  2748. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  2749. ui->Type = la_GetUiButtonType();
  2750. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  2751. }else{
  2752. ui->Type = (OverrideType && ((OverrideType->ForType == ui->PP.LastPs->p->PropertyType) || (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ? OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  2753. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  2754. }
  2755. if (Base){
  2756. ui->PP.RawThis = Base;
  2757. }
  2758. }else if (Base){
  2759. ui->PP.LastPs = Base->LastPs;
  2760. ui->Type = (OverrideType && ((OverrideType->ForType == ui->PP.LastPs->p->PropertyType) || (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ? OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  2761. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  2762. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  2763. }
  2764. la_AssignPropExtras(ui);
  2765. if(Widget){ ui->Flags|= Widget->Flags; }
  2766. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  2767. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  2768. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  2769. return ui;
  2770. }
  2771. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  2772. ui->Type = _LA_UI_LABEL;
  2773. ui->Template = Template;
  2774. ui->State = LA_UI_NORMAL;
  2775. strSafeSet(&ui->Display, Content);
  2776. la_AssignPropExtras(ui);
  2777. return ui;
  2778. }
  2779. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  2780. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2781. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  2782. ui->State = LA_UI_NORMAL;
  2783. la_AssignPropExtras(ui);
  2784. return ui;
  2785. }
  2786. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  2787. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2788. transLate(Content);
  2789. la_UpdateLabelDisplay(ui, Template, Content);
  2790. ui->C = c;
  2791. if (ui->Type->Init) ui->Type->Init(ui);
  2792. ui->ExtraPP.EndInstance = ui->Extra;
  2793. lstAppendItem(&uil->UiItems, ui);
  2794. return ui;
  2795. }
  2796. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  2797. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2798. la_UpdateLabelDisplay(ui, Template, Content);
  2799. ui->C = c;
  2800. if (ui->Type->Init) ui->Type->Init(ui);
  2801. ui->ExtraPP.EndInstance = ui->Extra;
  2802. lstAppendItem(&uil->UiItems, ui);
  2803. return ui;
  2804. }
  2805. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  2806. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2807. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  2808. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  2809. ui->C = c;
  2810. if (ui->Type->Init) ui->Type->Init(ui);
  2811. ui->ExtraPP.EndInstance = ui->Extra;
  2812. lstAppendItem(&uil->UiItems, ui);
  2813. return ui;
  2814. }
  2815. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  2816. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  2817. }
  2818. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  2819. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2820. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  2821. ui->C = c;
  2822. ui->TemplateContext = TemplateContext;
  2823. if (ui->Type->Init) ui->Type->Init(ui);
  2824. ui->ExtraPP.EndInstance = ui->Extra;
  2825. lstAppendItem(&uil->UiItems, ui);
  2826. return ui;
  2827. }
  2828. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  2829. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  2830. }
  2831. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  2832. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  2833. }
  2834. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  2835. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2836. ui->Type = _LA_UI_CANVAS;
  2837. ui->State = LA_UI_NORMAL;
  2838. ui->C = c;
  2839. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  2840. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  2841. else{
  2842. 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); }
  2843. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  2844. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  2845. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  2846. }
  2847. if (ui->Type->Init) ui->Type->Init(ui);
  2848. la_AssignCanvasPropExtras(ui);
  2849. if (Height) ui->Expand=Height; else ui->Expand=6;
  2850. lstAppendItem(&uil->UiItems, ui);
  2851. return ui;
  2852. }
  2853. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  2854. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2855. laCanvasExtra *e;
  2856. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  2857. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  2858. ui->C = c;
  2859. if (ui->Type->Init) ui->Type->Init(ui);
  2860. ui->ExtraPP.EndInstance = ui->Extra;
  2861. lstAppendItem(&uil->UiItems, ui);
  2862. return ui;
  2863. }
  2864. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  2865. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2866. ui->Type = _LA_UI_SYMBOL;
  2867. ui->SymbolID = SymbolID;
  2868. if (Height) ui->State = Height;
  2869. ui->C = c;
  2870. if (ui->Type->Init) ui->Type->Init(ui);
  2871. ui->ExtraPP.EndInstance = ui->Extra;
  2872. lstAppendItem(&uil->UiItems, ui);
  2873. return ui;
  2874. }
  2875. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  2876. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2877. ui->Type = &_LA_UI_ROW_BEGIN;
  2878. ui->State=Expand;
  2879. ui->Flags=Even;
  2880. ui->C = c;
  2881. if (ui->Type->Init) ui->Type->Init(ui);
  2882. ui->ExtraPP.EndInstance = ui->Extra;
  2883. lstAppendItem(&uil->UiItems, ui);
  2884. return ui;
  2885. }
  2886. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  2887. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2888. ui->Type = &_LA_UI_ROW_END;
  2889. ui->C = Begin->C;
  2890. ui->Page = (laUiList*)Begin;
  2891. if (ui->Type->Init) ui->Type->Init(ui);
  2892. ui->ExtraPP.EndInstance = ui->Extra;
  2893. lstAppendItem(&uil->UiItems, ui);
  2894. return ui;
  2895. }
  2896. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  2897. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  2898. e->Expression = Expression;
  2899. ui->Extra = e;
  2900. la_AssignPropExtras(ui);
  2901. }
  2902. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  2903. laUiItem *ui = la_CreateGroupHandle(Widget);
  2904. laUiList *nuil;
  2905. ui->C = c;
  2906. lstAppendItem(&uil->UiItems, ui);
  2907. nuil = memAcquireSimple(sizeof(laUiList));
  2908. strSafeSet(&nuil->TabName, Name);
  2909. ui->Page = nuil;
  2910. lstAppendItem(&ui->Subs, nuil);
  2911. if (ui->Type->Init) ui->Type->Init(ui);
  2912. ui->ExtraPP.EndInstance = ui->Extra;
  2913. return ui;
  2914. }
  2915. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  2916. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  2917. laUiList *sub = SubUi->Page;
  2918. laColumn *s = laFirstColumn(sub);
  2919. SubUi->State = LA_UI_ACTIVE;
  2920. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  2921. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  2922. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  2923. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  2924. laShowSeparator(sub, s);
  2925. return SubUi;
  2926. }
  2927. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  2928. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  2929. laUiList *sub = SubUi->Page;
  2930. laColumn *s = laFirstColumn(sub);
  2931. SubUi->State = LA_UI_ACTIVE;
  2932. return SubUi;
  2933. }
  2934. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  2935. laEndCondition(sub, sub->UiItems.pFirst);
  2936. }
  2937. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  2938. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  2939. laUiList *nuil;
  2940. ui->C = c;
  2941. lstAppendItem(&uil->UiItems, ui);
  2942. if (ui->Type->Init) ui->Type->Init(ui);
  2943. ui->ExtraPP.EndInstance = ui->Extra;
  2944. return ui;
  2945. }
  2946. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  2947. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  2948. if (!ui->Page) ui->Page = uil;
  2949. lstAppendItem(&ui->Subs, uil);
  2950. strSafeSet(&uil->TabName, Name);
  2951. laFirstColumn(uil);
  2952. //laFirstColumn(uil);
  2953. return uil;
  2954. }
  2955. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  2956. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  2957. /*if (!ui->Page) */ ui->Page = uil;
  2958. lstAppendItem(&ui->Subs, uil);
  2959. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  2960. return uil;
  2961. }
  2962. laUiConditionNode *laTrue(){
  2963. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  2964. ucn->Type = LA_CONDITION_TRUE;
  2965. return ucn;
  2966. }
  2967. laUiConditionNode *laFalse(){
  2968. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  2969. ucn->Type = LA_CONDITION_FALSE;
  2970. return ucn;
  2971. }
  2972. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  2973. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  2974. ucn->Type = LA_CONDITION_PROP;
  2975. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  2976. strSafeSet(&ucn->String, Prop);
  2977. return ucn;
  2978. }
  2979. laUiConditionNode *laIntExpression(int Value){
  2980. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  2981. ucn->Type = LA_CONDITION_INT;
  2982. ucn->IntValue = Value;
  2983. return ucn;
  2984. }
  2985. laUiConditionNode *laFloatExpression(real Value){
  2986. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  2987. ucn->Type = LA_CONDITION_FLOAT;
  2988. ucn->FloatValue = Value;
  2989. return ucn;
  2990. }
  2991. laUiConditionNode *laStringExpression(char *Content){
  2992. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  2993. ucn->Type = LA_CONDITION_STRING;
  2994. strSafeSet(&ucn->String, Content);
  2995. return ucn;
  2996. }
  2997. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  2998. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  2999. ucn->Type = LA_CONDITION_AND;
  3000. ucn->Expression1 = Expression1;
  3001. ucn->Expression2 = Expression2;
  3002. return ucn;
  3003. }
  3004. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3005. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3006. ucn->Type = LA_CONDITION_OR;
  3007. ucn->Expression1 = Expression1;
  3008. ucn->Expression2 = Expression2;
  3009. return ucn;
  3010. }
  3011. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  3012. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3013. ucn->Type = LA_CONDITION_NOT;
  3014. ucn->Expression1 = Expression1;
  3015. return ucn;
  3016. }
  3017. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3018. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3019. ucn->Type = LA_CONDITION_EQ;
  3020. ucn->Expression1 = Expression1;
  3021. ucn->Expression2 = Expression2;
  3022. return ucn;
  3023. }
  3024. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3025. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3026. ucn->Type = LA_CONDITION_GT;
  3027. ucn->Expression1 = Expression1;
  3028. ucn->Expression2 = Expression2;
  3029. return ucn;
  3030. }
  3031. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3032. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3033. ucn->Type = LA_CONDITION_LT;
  3034. ucn->Expression1 = Expression1;
  3035. ucn->Expression2 = Expression2;
  3036. return ucn;
  3037. }
  3038. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3039. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3040. ucn->Type = LA_CONDITION_GE;
  3041. ucn->Expression1 = Expression1;
  3042. ucn->Expression2 = Expression2;
  3043. return ucn;
  3044. }
  3045. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3046. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3047. ucn->Type = LA_CONDITION_LE;
  3048. ucn->Expression1 = Expression1;
  3049. ucn->Expression2 = Expression2;
  3050. return ucn;
  3051. }
  3052. int la_GetIntConditionValue(laUiConditionNode *Expression){
  3053. if (Expression->Type != LA_CONDITION_INT) return 0;
  3054. return Expression->Expression1;
  3055. }
  3056. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  3057. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  3058. return Expression->FloatValue;
  3059. }
  3060. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  3061. return Expression->String->Ptr;
  3062. }
  3063. 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){
  3064. switch (Mode1){
  3065. case LA_PROP_ENUM:
  3066. case LA_PROP_INT:
  3067. case LA_CONDITION_INT:
  3068. switch (Mode2){
  3069. case LA_PROP_ENUM:
  3070. case LA_PROP_INT:
  3071. case LA_CONDITION_INT:
  3072. switch (CompMode){
  3073. case LA_CONDITION_GE:
  3074. return (i1 >= i2);
  3075. case LA_CONDITION_GT:
  3076. return (i1 > i2);
  3077. case LA_CONDITION_EQ:
  3078. return (i1 == i2);
  3079. case LA_CONDITION_LT:
  3080. return (i1 < i2);
  3081. case LA_CONDITION_LE:
  3082. return (i1 <= i2);
  3083. }
  3084. case LA_PROP_FLOAT:
  3085. case LA_CONDITION_FLOAT:
  3086. switch (CompMode){
  3087. case LA_CONDITION_GE:
  3088. return ((real)i1 >= f2);
  3089. case LA_CONDITION_GT:
  3090. return ((real)i1 > f2);
  3091. case LA_CONDITION_EQ:
  3092. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  3093. case LA_CONDITION_LT:
  3094. return ((real)i1 < f2);
  3095. case LA_CONDITION_LE:
  3096. return ((real)i1 <= f2);
  3097. }
  3098. case LA_PROP_SUB:
  3099. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  3100. default:
  3101. return 0;
  3102. }
  3103. case LA_PROP_FLOAT:
  3104. case LA_CONDITION_FLOAT:
  3105. switch (Mode2){
  3106. case LA_PROP_INT:
  3107. case LA_PROP_ENUM:
  3108. case LA_CONDITION_INT:
  3109. switch (CompMode){
  3110. case LA_CONDITION_GE:
  3111. return (f1 >= (real)i2);
  3112. case LA_CONDITION_GT:
  3113. return (f1 > (real)i2);
  3114. case LA_CONDITION_EQ:
  3115. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  3116. case LA_CONDITION_LT:
  3117. return (f1 < (real)i2);
  3118. case LA_CONDITION_LE:
  3119. return (f1 <= (real)i2);
  3120. }
  3121. case LA_PROP_FLOAT:
  3122. case LA_CONDITION_FLOAT:
  3123. switch (CompMode){
  3124. case LA_CONDITION_GE:
  3125. return (f1 >= f2);
  3126. case LA_CONDITION_GT:
  3127. return (f1 > f2);
  3128. case LA_CONDITION_EQ:
  3129. return (f1 == f2);
  3130. case LA_CONDITION_LT:
  3131. return (f1 < f2);
  3132. case LA_CONDITION_LE:
  3133. return (f1 <= f2);
  3134. }
  3135. default:
  3136. return 0;
  3137. }
  3138. case LA_PROP_STRING:
  3139. case LA_CONDITION_STRING:
  3140. switch (Mode2){
  3141. case LA_PROP_STRING:
  3142. case LA_CONDITION_STRING:
  3143. return strSame(s1, s2);
  3144. default:
  3145. return 0;
  3146. }
  3147. case LA_PROP_SUB:
  3148. switch (Mode2){
  3149. case LA_PROP_SUB:
  3150. return p1 == p2;
  3151. case LA_CONDITION_INT:
  3152. case LA_PROP_INT:
  3153. case LA_PROP_ENUM:
  3154. return (int)p1 == i2;
  3155. default:
  3156. return 0;
  3157. }
  3158. default:
  3159. switch (CompMode){
  3160. case LA_CONDITION_GE:
  3161. return (i1 >= i2);
  3162. case LA_CONDITION_GT:
  3163. return (i1 > i2);
  3164. case LA_CONDITION_EQ:
  3165. return (i1 == i2);
  3166. case LA_CONDITION_LT:
  3167. return (i1 < i2);
  3168. case LA_CONDITION_LE:
  3169. return (i1 <= i2);
  3170. }
  3171. }
  3172. }
  3173. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  3174. void *Instance = 0;
  3175. int IValue1 = 0, IValue2 = 0;
  3176. real FValue1 = 0, FValue2 = 0;
  3177. void *Ptr1 = 0, *Ptr2 = 0;
  3178. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  3179. int Result1, Result2;
  3180. laEnumItem *ei;
  3181. if (!Expression) return 0;
  3182. Str1[0] = 0;
  3183. Str2[0] = 0;
  3184. laPropIterator pi = {0};
  3185. switch (Expression->Type){
  3186. case LA_CONDITION_PROP:
  3187. if (!Expression->PP.LastPs){
  3188. (*IResult) = 0;
  3189. return 0;
  3190. }
  3191. switch (Expression->PP.LastPs->p->PropertyType){
  3192. case LA_PROP_INT:
  3193. *IResult = laGetInt(&Expression->PP);
  3194. if (*IResult) return LA_CONDITION_INT;
  3195. else
  3196. return 0;
  3197. case LA_PROP_FLOAT:
  3198. *FResult = laGetFloat(&Expression->PP);
  3199. if (*FResult) return 1;
  3200. else
  3201. return 0;
  3202. break;
  3203. case LA_PROP_STRING:
  3204. laGetString(&Expression->PP, _StrResult, &StrResult);
  3205. if (StrResult[0]) return 1;
  3206. else
  3207. return 0;
  3208. break;
  3209. case LA_PROP_ENUM:
  3210. ei = laGetEnum(&Expression->PP);
  3211. if (!ei) return 0;
  3212. /*if(ei) */ *IResult = ei->Index;
  3213. if (*IResult) return LA_CONDITION_INT;
  3214. break;
  3215. case LA_PROP_SUB:
  3216. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  3217. else
  3218. Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  3219. *PtrResult = Instance;
  3220. if (Instance) return 1;
  3221. break;
  3222. default:
  3223. return 0;
  3224. }
  3225. case LA_CONDITION_INT:
  3226. *IResult = Expression->IntValue;
  3227. if (*IResult) return 1;
  3228. else
  3229. return 0;
  3230. case LA_CONDITION_FLOAT:
  3231. *FResult = Expression->FloatValue;
  3232. if (*FResult) return 1;
  3233. else
  3234. return 0;
  3235. case LA_CONDITION_STRING:
  3236. if (Expression->String){
  3237. strCopyFull(StrResult, Expression->String->Ptr);
  3238. return 1;
  3239. }else
  3240. return 0;
  3241. case LA_CONDITION_TRUE:
  3242. if (*IResult) *IResult = 1;
  3243. return 1;
  3244. case LA_CONDITION_FALSE:
  3245. if (*IResult) *IResult = 0;
  3246. return 0;
  3247. default:
  3248. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  3249. switch (Expression->Type){
  3250. case LA_CONDITION_AND:
  3251. if (Result1){
  3252. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3253. if (Result2) *IResult = 1;
  3254. return (Result2);
  3255. }else
  3256. return 0;
  3257. case LA_CONDITION_OR:
  3258. if (!Result1){
  3259. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3260. if (Result2) *IResult = 1;
  3261. return (Result2);
  3262. }else
  3263. return 1;
  3264. case LA_CONDITION_NOT:
  3265. return !Result1;
  3266. default:
  3267. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3268. return la_DoCompare(Expression->Type,
  3269. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  3270. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  3271. }
  3272. break;
  3273. }
  3274. return 0;
  3275. }
  3276. int la_DoSingleExpression(laUiConditionNode *Expression){
  3277. int a;
  3278. real b;
  3279. char c[128]={0};
  3280. void *p;
  3281. if (!Expression) return 1;
  3282. c[0] = 0;
  3283. return la_DoExpression(Expression, &a, &b, c, &p);
  3284. }
  3285. void la_StepExpression(laUiConditionNode *e){
  3286. if (!e) return;
  3287. switch (e->Type){
  3288. case LA_CONDITION_AND:
  3289. case LA_CONDITION_OR:
  3290. case LA_CONDITION_GE:
  3291. case LA_CONDITION_GT:
  3292. case LA_CONDITION_EQ:
  3293. case LA_CONDITION_LT:
  3294. case LA_CONDITION_LE:
  3295. la_StepExpression(e->Expression1);
  3296. la_StepExpression(e->Expression2);
  3297. break;
  3298. case LA_CONDITION_NOT:
  3299. la_StepExpression(e->Expression1);
  3300. break;
  3301. case LA_CONDITION_PROP:
  3302. la_StepPropPack(&e->PP);
  3303. if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){
  3304. la_UsePropPack(&e->PP, 1);
  3305. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  3306. }
  3307. break;
  3308. default:
  3309. break;
  3310. }
  3311. }
  3312. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  3313. if (!ucn) return;
  3314. la_ConditionNodeFreeRecursive(ucn->Expression1);
  3315. la_ConditionNodeFreeRecursive(ucn->Expression2);
  3316. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  3317. if (ucn->String) strSafeDestroy(&ucn->String);
  3318. if (ucn) memFree(ucn);
  3319. }
  3320. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  3321. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3322. ui->C = c;
  3323. ui->Type = &_LA_UI_CONDITION;
  3324. la_ConditionerInit(ui, Expression);
  3325. lstAppendItem(&uil->UiItems, ui);
  3326. return ui;
  3327. }
  3328. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  3329. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3330. laConditionUiExtraData *cued;
  3331. ui->Type = &_LA_UI_CONDITION_ELSE;
  3332. la_ConditionerInit(ui, 0);
  3333. cued = ui->Extra;
  3334. cued->EndUi = Beginner;
  3335. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  3336. ui->C = Beginner->C;
  3337. lstAppendItem(&uil->UiItems, ui);
  3338. return ui;
  3339. }
  3340. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  3341. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3342. laConditionUiExtraData *cued;
  3343. ui->Template = define;
  3344. ui->C = col;
  3345. ui->PP.RawThis = ExtraBase;
  3346. ui->Page = ExtraThis;
  3347. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  3348. la_ConditionerInit(ui, 0);
  3349. cued = ui->Extra;
  3350. //cued->Remove = Remove;
  3351. ui->State = LA_UI_NORMAL;
  3352. lstAppendItem(&uil->UiItems, ui);
  3353. return ui;
  3354. }
  3355. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  3356. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3357. laConditionUiExtraData *cued;
  3358. ui->Type = &_LA_UI_CONDITION_END;
  3359. la_ConditionerInit(ui, 0);
  3360. cued = ui->Extra;
  3361. cued->EndUi = Beginner;
  3362. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  3363. ui->C = Beginner->C;
  3364. lstAppendItem(&uil->UiItems, ui);
  3365. return ui;
  3366. }
  3367. laUiList *laMakeMenuPage(laUiList *uil, laColumn *c, const char *Title){
  3368. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3369. laUiList *muil = memAcquireSimple(sizeof(laUiList));
  3370. ui->Type = _LA_UI_MENU_ROOT;
  3371. strSafeSet(&ui->Display, Title);
  3372. ui->State = LA_UI_NORMAL;
  3373. ui->C = c;
  3374. lstAppendItem(&uil->UiItems, ui);
  3375. lstAppendItem(&ui->Subs, muil);
  3376. return muil;
  3377. }
  3378. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  3379. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3380. ui->Type = _LA_UI_ALIGN;
  3381. ui->C = widest;
  3382. lstAppendItem(&uil->UiItems, ui);
  3383. return ui;
  3384. }
  3385. void laFixHeight(laUiList *uil, short Rows){
  3386. if (!uil) return;
  3387. uil->HeightCoeff = Rows;
  3388. }
  3389. int la_GetUiType(laUiItem* ui) {
  3390. if (ui->AT) return LA_UI_INTERNAL_BUTTON;
  3391. if (ui->PP.LastPs) {
  3392. if (ui->Type == _LA_UI_CANVAS) return LA_UI_INTERNAL_2D_VIEW;
  3393. return LA_UI_INTERNAL_WATCHER;
  3394. }
  3395. if (ui->Display) {
  3396. if (ui->Type == _LA_UI_MENU_ROOT) return LA_UI_INTERNAL_MENU;
  3397. return LA_UI_INTERNAL_LABEL;
  3398. }
  3399. if (ui->Subs.pFirst) {
  3400. if (ui->Type == _LA_UI_FIXED_GROUP)return LA_UI_INTERNAL_GROUP;
  3401. if (ui->Type == _LA_UI_TAB)return LA_UI_INTERNAL_TAB;
  3402. return LA_UI_INTERNAL_GROUP;
  3403. }
  3404. if (ui->Type == _LA_UI_BUTTON) return LA_UI_INTERNAL_BUTTON;
  3405. if (ui->Type == &_LA_UI_CONDITION) return LA_UI_INTERNAL_BRACKET_BEGIN;
  3406. if (ui->Type == &_LA_UI_CONDITION_ELSE) return LA_UI_INTERNAL_BRACKET_ELSE;
  3407. if (ui->Type == &_LA_UI_CONDITION_END) return LA_UI_INTERNAL_BRACKET_END;
  3408. if (ui->Type == _LA_UI_CONDITION_TOGGLE) return LA_UI_INTERNAL_FOLDER_BEGIN;
  3409. if (ui->Type == _LA_UI_ALIGN) return LA_UI_INTERNAL_ALIGNER;
  3410. if (ui->Type == _LA_UI_COLUMN_ADJUSTER) return LA_UI_INTERNAL_ADJUSTER;
  3411. if (ui->Type == _LA_UI_SYMBOL) return LA_UI_INTERNAL_SYMBOL;
  3412. return LA_UI_INTERNAL_WATCHER;
  3413. }
  3414. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  3415. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  3416. if (!ExtraColumns) return;
  3417. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  3418. }
  3419. laUiTemplate *laFindUiTemplate(char *Identifier){
  3420. laUiTemplate *uit;
  3421. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3422. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3423. }
  3424. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3425. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3426. }
  3427. return 0;
  3428. }
  3429. void la_DestroyUiTemplate(laUiTemplate* uit){
  3430. strSafeDestroy(&uit->Identifier);
  3431. strSafeDestroy(&uit->Title);
  3432. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  3433. memFree(uit);
  3434. }
  3435. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  3436. strSafeDestroy(&uit->Identifier);
  3437. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3438. memFree(uit);
  3439. }
  3440. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat){
  3441. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  3442. strSafeSet(&uit->Identifier, Identifier);
  3443. strSafeSet(&uit->Title, Title);
  3444. strSafeSet(&uit->CategoryName, NewCategory);
  3445. uit->Define = func;
  3446. uit->Header = header;
  3447. uit->PropFunc = PropFunc;
  3448. uit->DefaultGLFormat=DefaultGLFormat;
  3449. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  3450. la_UDFAppendSharedTypePointer(Identifier, uit);
  3451. return uit;
  3452. }
  3453. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  3454. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  3455. strSafeSet(&t->Identifier, Identifier);
  3456. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  3457. t->Init = CustomInit; t->Destroy = CustomDestroy;
  3458. lstAppendItem(&MAIN.View2DTemplates, t);
  3459. la_UDFAppendSharedTypePointer(Identifier, t);
  3460. return t;
  3461. }
  3462. void laFinalizeUiTemplates(){
  3463. laUiTemplate *uit;
  3464. laCanvasTemplate *u2d;
  3465. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  3466. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  3467. }
  3468. }
  3469. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  3470. laPanel *p;
  3471. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  3472. if (p->PanelTemplate==uit){
  3473. return p;
  3474. }
  3475. }
  3476. return 0;
  3477. }
  3478. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  3479. laUiList *uil, *NextUil;
  3480. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  3481. NextUil = uil->Item.pNext;
  3482. lstRemoveItem(&ui->Subs, uil);
  3483. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  3484. }
  3485. la_StopUiOperatorService(ui);
  3486. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  3487. strSafeDestroy(&ui->Display);
  3488. if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3489. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3490. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3491. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  3492. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  3493. memFree(ui);
  3494. }
  3495. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  3496. laUiItem *ui, *NextUi;
  3497. laColumn *col, *NextCol;
  3498. if (!uil) return;
  3499. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  3500. NextUi = ui->Item.pNext;
  3501. if(OnlyRemoveUser && RemoveUsers){
  3502. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3503. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3504. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3505. continue;
  3506. }
  3507. lstRemoveItem(&uil->UiItems, ui);
  3508. la_DestroyUiItem(ui, RemoveUsers);
  3509. }
  3510. if(OnlyRemoveUser){ return; }
  3511. for (col = uil->Columns.pFirst; col; col = NextCol){
  3512. NextCol = col->Item.pNext;
  3513. lstRemoveItem(&uil->Columns, col);
  3514. memFree(col);
  3515. }
  3516. strSafeDestroy(&uil->TabName);
  3517. if (!NoFree) memFree(uil);
  3518. }
  3519. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  3520. if(ui) lstRemoveItem(&ui->Subs, Tab);
  3521. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  3522. }
  3523. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  3524. laUiItem *Next = after->Item.pNext;
  3525. laUiItem *Last = uil->UiItems.pLast;
  3526. after->Item.pNext = 0;
  3527. uil->UiItems.pLast = after;
  3528. Define(uil, Base, This, ExtraColums, 0);
  3529. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  3530. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  3531. if (Next != Last) uil->UiItems.pLast = Last;
  3532. }
  3533. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  3534. // int i = 0;
  3535. // int FromW=FromR-FromL, ToW=ToR-ToL;
  3536. // if (!ui->ExtraColums) return;
  3537. // for (i; ui->ExtraColums[i]; i++) {
  3538. // laColumn* c = ui->ExtraColums[i];
  3539. // c->B = B;
  3540. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  3541. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  3542. // }
  3543. //}
  3544. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  3545. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ p->Refresh |= LA_TAG_RECALC; }
  3546. }
  3547. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  3548. laColumn *c = ui->C;
  3549. laColumn *ic = lst->pFirst;
  3550. c->B = ui->TB + (*ui->Type->Theme)->BP;
  3551. for (ic; ic; ic = ic->Item.pNext){
  3552. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3553. ic->B = ic->B < c->B ? c->B : ic->B;
  3554. }
  3555. }
  3556. ic = ui->C;
  3557. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  3558. ;
  3559. for (ic; ic; ic = ic->Item.pNext){
  3560. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3561. ic->B = ic->B < c->B ? c->B : ic->B;
  3562. }
  3563. }
  3564. }
  3565. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  3566. laColumn *c = ui->C;
  3567. laColumn *ic = lst->pFirst;
  3568. c->B = ui->TB + (*ui->Type->Theme)->TP;
  3569. for (ic; ic; ic = ic->Item.pNext){
  3570. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3571. ic->B = ic->B < c->B ? c->B : ic->B;
  3572. }
  3573. }
  3574. ic = ui->C;
  3575. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  3576. ;
  3577. for (ic; ic; ic = ic->Item.pNext){
  3578. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3579. ic->B = ic->B < c->B ? c->B : ic->B;
  3580. }
  3581. }
  3582. }
  3583. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  3584. int rep;
  3585. int sp;
  3586. int rev;
  3587. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  3588. if (!c) return 0;
  3589. sp = (c->SP * (R - L)) + L;
  3590. rev = sp;
  3591. /*if (U)*/ c->B = U;
  3592. if (LR == 1){
  3593. c->IL = L;
  3594. c->IR = sp;
  3595. if (repos){
  3596. c->IR = repos;
  3597. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  3598. c->IR = c->IL + c->MaxW*LA_RH+M;
  3599. rev = c->IR;
  3600. }
  3601. }else if (LR == 2){
  3602. c->IL = sp;
  3603. c->IR = R;
  3604. if (repos){
  3605. c->IL = repos;
  3606. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  3607. c->IL = c->IR - c->MaxW*LA_RH-M;
  3608. rev = c->IL;
  3609. }
  3610. }else if (LR == 0){
  3611. c->IL = L;
  3612. c->IR = R;
  3613. }
  3614. if (c->LS && c->RS->MaxW == 0){
  3615. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  3616. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  3617. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3618. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3619. }else if (c->RS && c->LS->MaxW == 0){
  3620. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  3621. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  3622. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3623. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3624. }
  3625. return rev;
  3626. }
  3627. STRUCTURE(laRowInfo){
  3628. int MaxW;
  3629. int MinW;
  3630. int UnitMinW;
  3631. int NonExpandW;
  3632. int TotalPadding;
  3633. int Expand, Even;
  3634. int ExpandAccum;
  3635. int CountElements;
  3636. int U,MaxB,L;
  3637. laListHandle Elements;
  3638. };
  3639. STRUCTURE(laRowNode){
  3640. laListItem Item;
  3641. laUiItem* ui;
  3642. int GotW, LP, RP, H;
  3643. int Expand;
  3644. };
  3645. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  3646. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  3647. ri->UnitMinW=LA_RH+bt->LM+bt->RM;
  3648. ri->Expand=ui->State?1:0;
  3649. ri->Even=ui->Flags?1:0;
  3650. ri->U=ui->TU; ri->L=ui->TL;
  3651. ri->MaxB=ui->TU;
  3652. }
  3653. int la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H){
  3654. laRowNode* rn=CreateNew(laRowNode);
  3655. rn->LP=bt->LP;rn->RP=bt->RP;
  3656. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH)) +bt->LM+bt->RM;
  3657. rn->ui=ui;
  3658. rn->H=H;
  3659. rn->Expand=ui->Expand;
  3660. lstAppendItem(&ri->Elements, rn);
  3661. if(!ri->UnitMinW){ri->UnitMinW=LA_RH+bt->LM+bt->RM;}
  3662. ri->TotalPadding += bt->LP+bt->RP;
  3663. ri->MinW+=ri->UnitMinW;
  3664. ri->NonExpandW+=rn->GotW;
  3665. ri->ExpandAccum+=ui->Expand;
  3666. ri->CountElements++;
  3667. if(ui->Expand){ri->Expand=1;}
  3668. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  3669. }
  3670. int la_ShrinkableRowElements(laRowInfo* ri){
  3671. int count=0;
  3672. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  3673. if(rn->GotW<=ri->UnitMinW) continue;
  3674. count++;
  3675. }
  3676. return count;
  3677. }
  3678. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end, int WaitAnimation){
  3679. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  3680. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  3681. if(Available<0){
  3682. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  3683. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  3684. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  3685. }else{
  3686. if(!ri->Expand && Available>0){Available=0;}
  3687. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  3688. }
  3689. if(!ShareCount) return;
  3690. int PerNode = Available/ShareCount;
  3691. int Remaining = Available-PerNode*ShareCount;
  3692. int L = ri->L; int i=0; laRowNode* rn;
  3693. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  3694. laUiItem* ui=rn->ui;
  3695. int NodeAdd, Node=rn->GotW;
  3696. if(Available>=0){
  3697. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  3698. NodeAdd+=(i<Remaining?1:0);i++;
  3699. }else{
  3700. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  3701. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  3702. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  3703. }else{ Node=ri->UnitMinW;
  3704. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  3705. }
  3706. }
  3707. ui->TL = L + rn->LP;
  3708. ui->TR = ui->TL + Node+NodeAdd;
  3709. ui->TB = ui->TU + rn->H;
  3710. L=ui->TR+rn->RP;
  3711. if (!WaitAnimation){
  3712. ui->L = ui->TL; ui->R = ui->TR;
  3713. ui->U = ui->TU; ui->B = ui->TB;
  3714. }
  3715. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  3716. }
  3717. ui_end->TB = ri->MaxB;
  3718. while(rn=lstPopItem(&ri->Elements)){
  3719. FreeMem(rn);
  3720. }
  3721. memset(ri, 0, sizeof(laRowInfo));
  3722. }
  3723. void la_RecordSocketRuntimePosition(laUiItem* ui){
  3724. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  3725. int sl,sr,su,sb;
  3726. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  3727. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  3728. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  3729. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  3730. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  3731. if(pc==LA_PC_SOCKET_OUT){
  3732. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  3733. }else{
  3734. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  3735. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  3736. }
  3737. }
  3738. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  3739. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } }
  3740. }
  3741. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  3742. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  3743. laBoxedTheme *bt;
  3744. int Lowest = 0;
  3745. int HyperValue = 0;
  3746. int WaitAnimation;
  3747. int RowMode=0; laRowInfo ri={0};
  3748. laBoxedTheme* pt=*(ParentPanel->BT);
  3749. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  3750. int MaxR=0;
  3751. if(!uil->Scale){uil->Scale=1;}
  3752. uil->SaveScale=MAIN.UiScale;
  3753. MAIN.UiScale*=uil->Scale;
  3754. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  3755. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  3756. WaitAnimation = 0;
  3757. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  3758. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  3759. for (ui = uil->UiItems.pFirst; ui;){
  3760. int SubB = 0;
  3761. int H;
  3762. WaitAnimation = 0;
  3763. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  3764. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  3765. //if (Fast && ui->C->B > B) {
  3766. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  3767. // ui = ui->Item.pNext;
  3768. // continue;
  3769. //}
  3770. if (!ui->Instructions){
  3771. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  3772. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  3773. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  3774. laOperatorProp *ap = ui->PP.LastPs->p;
  3775. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  3776. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  3777. }
  3778. }
  3779. if (/*!ui->NoRefresh && */ ui->PP.LastPs){
  3780. la_StepPropPack(&ui->PP);
  3781. }
  3782. la_UsePropPack(&ui->PP, 0);
  3783. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  3784. // 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);
  3785. //}
  3786. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  3787. ParentPanel->Refresh |= LA_TAG_ANIMATION;
  3788. WaitAnimation = 1;
  3789. }
  3790. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  3791. bt = (*ui->Type->Theme);
  3792. if (ui->Type == &_LA_UI_CONDITION){
  3793. laConditionUiExtraData *cued = ui->Extra;
  3794. la_StepExpression(cued->Expression);
  3795. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  3796. if (!cued->IsTrue){
  3797. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  3798. }else{
  3799. ui = ui->Item.pNext;
  3800. }
  3801. continue;
  3802. }else if (ui->Type == &_LA_UI_CONDITION_END){
  3803. ui = ui->Item.pNext;
  3804. continue;
  3805. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  3806. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  3807. if (cued->IsTrue) ui = cued->EndUi;
  3808. else
  3809. ui = ui->Item.pNext;
  3810. continue;
  3811. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  3812. laConditionUiExtraData *cued = ui->Extra;
  3813. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  3814. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  3815. if (!WaitAnimation){
  3816. ui->L = ui->TL; ui->R = ui->TR;
  3817. ui->U = ui->TU; ui->B = ui->TB;
  3818. }
  3819. if(!RowMode){
  3820. la_CalcUiItemInfluence(&uil->Columns, ui);
  3821. }else{
  3822. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  3823. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  3824. }
  3825. if (ui->State == LA_UI_NORMAL){
  3826. cued->IsTrue = 0;
  3827. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  3828. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  3829. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  3830. }else{
  3831. cued->IsTrue = 1;
  3832. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  3833. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  3834. //}
  3835. ui = ui->Item.pNext;
  3836. }
  3837. continue;
  3838. }
  3839. if (ui->Type == _LA_UI_ALIGN){
  3840. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU;
  3841. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  3842. if (ui->TB > Lowest) Lowest = ui->TB;
  3843. if (!WaitAnimation){
  3844. ui->L = ui->TL; ui->R = ui->TR;
  3845. ui->U = ui->TU; ui->B = ui->TB;
  3846. }
  3847. if(!RowMode){
  3848. la_CalcUiItemInfluence(&uil->Columns, ui);
  3849. }else{
  3850. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  3851. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  3852. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  3853. }
  3854. ui = ui->Item.pNext; continue;
  3855. }
  3856. if (ui->Type == &_LA_UI_ROW_BEGIN){
  3857. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  3858. la_InitRowNode(&ri, ui, bt);
  3859. RowMode=1; ui=ui->Item.pNext; continue;
  3860. }
  3861. if (ui->Type == &_LA_UI_ROW_END){
  3862. la_CalculateRowExpand(&ri, ui, WaitAnimation);
  3863. la_CalcUiItemInfluence(&uil->Columns, ui);
  3864. RowMode=0; ui=ui->Item.pNext; continue;
  3865. }
  3866. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  3867. int GB=0;
  3868. 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; }
  3869. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  3870. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  3871. if (H < 0){
  3872. if(B){ H = B + (H+1) * LA_RH - ui->TU; }
  3873. else{ H=LA_RH; }
  3874. }
  3875. else H *= LA_RH;
  3876. ui->TB = ui->TU;
  3877. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  3878. 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
  3879. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  3880. if (ui->Type == _LA_UI_COLLECTION){
  3881. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  3882. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  3883. ui->PP.EndInstance = TInstance;
  3884. laUiList *iuil = ui->Subs.pFirst;
  3885. laUiList *puil = iuil;
  3886. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  3887. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  3888. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  3889. int Begin = ui->TB;
  3890. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  3891. int ElementB = ui->TU;
  3892. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  3893. int MaxB = ElementB;
  3894. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  3895. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  3896. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  3897. if (!ElementLimit) RowPriority = 0;
  3898. if (!TInstance){
  3899. while (iuil){
  3900. puil = iuil->Item.pNext;
  3901. la_DestroyTabPage(ui, iuil, 0);
  3902. iuil = puil;
  3903. }
  3904. }
  3905. while (TInstance){
  3906. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  3907. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  3908. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  3909. ui->PP.EndInstance = TInstance; continue;
  3910. }
  3911. if(CanGetTheme){
  3912. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  3913. la_SwitchThemeQuick(t, OriginalTheme);
  3914. }
  3915. if(CanGetGap){
  3916. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  3917. Gap=g*LA_RH;
  3918. }else Gap=0;
  3919. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  3920. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  3921. }else GotCategory=0;
  3922. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  3923. if (RowPriority){
  3924. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  3925. }
  3926. }
  3927. FirstIn=0;
  3928. if (ElementLimit){
  3929. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  3930. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  3931. }
  3932. while (iuil && iuil->Instance != TInstance){
  3933. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  3934. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  3935. }else{
  3936. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  3937. }
  3938. iuil = puil;
  3939. }
  3940. if(!iuil){
  3941. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  3942. }
  3943. if (!iuil){
  3944. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  3945. la_CalcUiTopInfluence(&uil->Columns, ui);
  3946. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  3947. 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);
  3948. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  3949. iuil = ui->Page->Item.pNext;
  3950. }else{
  3951. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  3952. 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);
  3953. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  3954. la_CalcUiItemInfluence(&uil->Columns, ui);
  3955. iuil = iuil->Item.pNext;
  3956. }
  3957. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  3958. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  3959. ui->PP.EndInstance = TInstance;
  3960. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  3961. if (RowPriority){
  3962. Col += 1;
  3963. if (Col >= ElementLimit){
  3964. Col = 0;
  3965. Row += 1;
  3966. Begin = ElementB + bt->TM;
  3967. }
  3968. }elif(Spread){
  3969. EL+=Spread*LA_RH;
  3970. ER+=Spread*LA_RH;
  3971. }else{
  3972. Row += 1;
  3973. Begin = ElementB + bt->TM;
  3974. if (ElementLimit && Row >= ElementLimit){
  3975. Row = 0;
  3976. Col += 1;
  3977. Begin = ui->TU + bt->TM;
  3978. }
  3979. }
  3980. ui->TB = ElementB;
  3981. MaxB = MaxB < ElementB ? ElementB : MaxB;
  3982. }
  3983. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  3984. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  3985. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  3986. ui->TB = MaxB;
  3987. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  3988. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  3989. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  3990. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  3991. ui->PP.EndInstance = TInstance;
  3992. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  3993. if(!Template) Template=laui_SubPropInfoDefault;
  3994. //ui->Template = Template;
  3995. if (!ui->Subs.pFirst && TInstance){
  3996. la_AddInstancePage(ui, TInstance, 0);
  3997. la_CalcUiTopInfluence(&uil->Columns, ui);
  3998. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  3999. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4000. ui->TB = SubB + (NoDecal?0:bt->TM);
  4001. }else if (ui->Subs.pFirst){
  4002. if (!TInstance || TInstance != ui->Page->Instance){
  4003. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  4004. ui->Page = 0;
  4005. if (TInstance){
  4006. la_AddInstancePage(ui, TInstance, 0);
  4007. la_CalcUiTopInfluence(&uil->Columns, ui);
  4008. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4009. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4010. ui->TB = SubB + (NoDecal?0:bt->TM);
  4011. }else
  4012. ui->TB = ui->TU + LA_RH + bt->BM;
  4013. }else{
  4014. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4015. ui->TB = SubB + (NoDecal?0:bt->TM);
  4016. }
  4017. }
  4018. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  4019. if (!WaitAnimation){
  4020. ui->L = ui->TL;
  4021. ui->R = ui->TR;
  4022. ui->U = ui->TU;
  4023. ui->B = ui->TB;
  4024. }
  4025. }
  4026. }else{
  4027. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4028. if (ui->Type != _LA_UI_CANVAS){
  4029. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  4030. la_CalcUiTopInfluence(&uil->Columns, ui);
  4031. SubB = la_UpdateUiListRecursive(ui->Page,
  4032. 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);
  4033. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  4034. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH : SubB)) + (NoDecal?0:bt->TM);
  4035. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  4036. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  4037. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  4038. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  4039. }
  4040. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  4041. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  4042. if(GB && ui->TB >= GB){
  4043. ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  4044. if(ui->Page->HeightCoeff){
  4045. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  4046. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  4047. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  4048. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  4049. }
  4050. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  4051. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  4052. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  4053. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  4054. }
  4055. }
  4056. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  4057. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  4058. }else{
  4059. laUiList *suil;
  4060. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  4061. la_CalcUiTopInfluence(&uil->Columns, ui);
  4062. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4063. 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);
  4064. }
  4065. }
  4066. ui->TB = ui->TU + H;
  4067. }
  4068. }else ui->TB = ui->TU + H;
  4069. }
  4070. if (ui->TB > Lowest) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  4071. if(!RowMode){
  4072. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  4073. }else{
  4074. la_AddRowNode(&ri, ui, bt, H);
  4075. }
  4076. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  4077. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4078. ui = ui->Item.pNext;
  4079. }
  4080. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  4081. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  4082. else uil->TB = Lowest;
  4083. if (!WaitAnimation){
  4084. uil->L = uil->TL;
  4085. uil->R = uil->TR;
  4086. uil->U = uil->TU;
  4087. uil->B = uil->TB;
  4088. }
  4089. MAIN.UiScale=uil->SaveScale;
  4090. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4091. return uil->TB;
  4092. }
  4093. int la_AnimateSingleUiSize(int To, int *Now){
  4094. int Delta;
  4095. if (To != *Now){
  4096. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  4097. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  4098. *Now += Delta;
  4099. return 1;
  4100. }else
  4101. return 0;
  4102. }
  4103. int la_AnimateUiListRecursive(laUiList *uil){
  4104. laUiItem *ui;
  4105. int Again = 0;
  4106. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  4107. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  4108. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  4109. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  4110. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  4111. la_AnimateSingleUiSize(ui->TR, &ui->R));
  4112. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4113. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  4114. laUiList *suil;
  4115. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4116. Again += la_AnimateUiListRecursive(suil);
  4117. }
  4118. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  4119. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4120. Again += la_AnimateUiListRecursive(ui->Page);
  4121. }
  4122. }
  4123. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  4124. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  4125. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  4126. la_AnimateSingleUiSize(uil->TR, &uil->R));
  4127. return Again;
  4128. }
  4129. int la_DrawUiItem(laUiItem *ui){
  4130. tnsUseNoTexture();
  4131. tnsColor4d(1, 1, 1, 1);
  4132. tnsVertex2d(ui->L, ui->U);
  4133. tnsVertex2d(ui->R, ui->U);
  4134. tnsVertex2d(ui->R, ui->B);
  4135. tnsVertex2d(ui->L, ui->B);
  4136. tnsPackAs(GL_LINE_LOOP);
  4137. }
  4138. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  4139. tnsUseNoTexture();
  4140. tnsColor4d(1, 1, 1, 1);
  4141. tnsVertex2d(ui->L - 1, ui->U - 1);
  4142. tnsVertex2d(ui->R + 1, ui->U - 1);
  4143. tnsVertex2d(ui->R + 1, ui->B + 1);
  4144. tnsVertex2d(ui->L - 1, ui->B + 1);
  4145. tnsPackAs(GL_LINE_LOOP);
  4146. }
  4147. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  4148. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  4149. return 1;
  4150. }
  4151. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  4152. laUiListDrawItem *uildi = uild->Items.pFirst;
  4153. laUiList *Target = uildi->Target;
  4154. int L, R, U, B;
  4155. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  4156. L = Target->L + Target->PanX + uildi->DifX;
  4157. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4158. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4159. U = Target->U + Target->PanY + uildi->DifY;
  4160. return la_UiInBound(ui, L, R, U, B);
  4161. }
  4162. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  4163. laUiListDrawItem *uildi = uild->Items.pFirst;
  4164. laUiList *Target = uildi->Target;
  4165. int L, R, U, B;
  4166. if (Target){
  4167. L = Target->L + Target->PanX + uildi->DifX;
  4168. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4169. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4170. U = Target->U + Target->PanY + uildi->DifY;
  4171. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  4172. return 1;
  4173. }else{
  4174. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  4175. return 1;
  4176. }
  4177. }
  4178. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  4179. laUiItem *ui = uil->UiItems.pFirst;
  4180. while (!strGetArgument(ui->Instructions, mark))
  4181. ui = ui->Item.pNext;
  4182. return ui;
  4183. }
  4184. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  4185. laUiList *uil;
  4186. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  4187. if (uil->Instance == Instance) return uil;
  4188. }
  4189. return uil;
  4190. }
  4191. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  4192. int mx=(L+R)/2; int my=(U+B)/2;
  4193. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  4194. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  4195. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  4196. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  4197. tnsFlush();
  4198. }
  4199. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  4200. if(!uil->ScrollerShownV) return;
  4201. int W = LA_SCROLL_W;
  4202. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  4203. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  4204. int U = uil->U + Offset;
  4205. int B = U + Len;
  4206. int L = UiR - _LA_THEME_PANEL->RM - W;
  4207. int R = L + W;
  4208. if (B > U + DisplayH) B = U + DisplayH;
  4209. if (U < uil->U) U = uil->U;
  4210. if (B <= uil->U || U >= uil->B) return;
  4211. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  4212. if (U < uil->U) U = uil->U;
  4213. tnsUseNoTexture();
  4214. laBoxedTheme* bt=_LA_THEME_PANEL;
  4215. real* color=laThemeColor(bt, LA_BT_TEXT);
  4216. tnsColor4d(LA_COLOR3(color), 0.8);
  4217. tnsVertex2d(R, U);
  4218. tnsVertex2d(L, U);
  4219. tnsVertex2d(L, B);
  4220. tnsVertex2d(R, B);
  4221. tnsPackAs(GL_TRIANGLE_FAN);
  4222. tnsColor4d(LA_COLOR3(color), 0.8);
  4223. tnsVertex2d(R, uil->U);
  4224. tnsVertex2d(L, uil->U);
  4225. tnsVertex2d(L, uil->U + DisplayH);
  4226. tnsVertex2d(R, uil->U + DisplayH);
  4227. tnsPackAs(GL_LINE_LOOP);
  4228. int HU=(U+B)/2+LA_RH2;
  4229. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4230. }
  4231. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  4232. if(!uil->ScrollerShownH) return;
  4233. int W = LA_SCROLL_W;
  4234. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  4235. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  4236. int L = uil->L + Offset;
  4237. int R = L + Len;
  4238. int U = UiB - _LA_THEME_PANEL->RM - W;
  4239. int B = U + W;
  4240. if (B > U + DisplayW) B = U + DisplayW;
  4241. if (U < uil->U) U = uil->U;
  4242. if (R <= uil->L || L >= uil->R) return;
  4243. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  4244. if (L < uil->L) L = uil->L;
  4245. tnsUseNoTexture();
  4246. laBoxedTheme* bt=_LA_THEME_PANEL;
  4247. real* color=laThemeColor(bt, LA_BT_TEXT);
  4248. tnsColor4d(LA_COLOR3(color), 0.8);
  4249. tnsVertex2d(R, U);
  4250. tnsVertex2d(L, U);
  4251. tnsVertex2d(L, B);
  4252. tnsVertex2d(R, B);
  4253. tnsPackAs(GL_TRIANGLE_FAN);
  4254. tnsColor4d(LA_COLOR3(color), 0.8);
  4255. tnsVertex2d(uil->L,U);
  4256. tnsVertex2d(uil->L,B);
  4257. tnsVertex2d(uil->L + DisplayW,B);
  4258. tnsVertex2d(uil->L + DisplayW,U);
  4259. tnsPackAs(GL_LINE_LOOP);
  4260. int HU=(U+B)/2+LA_RH2;
  4261. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4262. }
  4263. void la_DrawInstanceBkg(laUiList *uil, real* color){
  4264. tnsUseNoTexture();
  4265. tnsColor4dv(color);
  4266. tnsVertex2d(uil->L, uil->U); tnsVertex2d(uil->R, uil->U);
  4267. tnsVertex2d(uil->R, uil->B); tnsVertex2d(uil->L, uil->B);
  4268. tnsPackAs(GL_TRIANGLE_FAN);
  4269. }
  4270. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  4271. laSocketRecord* sr;
  4272. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  4273. uild->WiresContainer=container;
  4274. }
  4275. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  4276. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  4277. if(lip->Target==uild->WiresContainer) break;
  4278. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  4279. }
  4280. }
  4281. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  4282. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4283. int PanX, PanY;
  4284. if(pc==LA_PC_SOCKET_OUT){
  4285. laNodeOutSocket* s=ui->PP.EndInstance;
  4286. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  4287. }else{
  4288. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  4289. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  4290. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  4291. }
  4292. }
  4293. void la_RegenerateWireColors(){
  4294. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  4295. laTheme* t=MAIN.CurrentTheme;
  4296. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  4297. real hcy[]={0.0,0.8,0.6}; hcy[1]=t->WireSaturation; hcy[2]=t->WireBrightness;
  4298. for(int i=0;i<MAIN.WireColorSlices;i++){
  4299. hcy[0]=(real)i/(real)MAIN.WireColorSlices;
  4300. tnsHCY2RGB(hcy, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  4301. }
  4302. }
  4303. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  4304. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  4305. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  4306. tnsInterpolate2dv(v1,v2,0.5,vi);
  4307. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=log(dist+1)*MAIN.WireSaggyness; }
  4308. tnsVectorMinus2d(v1s,vi,v1); tnsNormalizeSelf2d(v1s); tnsVectorMultiSelf2d(v1s,circle_r);
  4309. tnsVectorMinus2d(v2s,vi,v2); tnsNormalizeSelf2d(v2s); tnsVectorMultiSelf2d(v2s,circle_r);
  4310. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  4311. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  4312. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  4313. tnsVertex2d(v1[0],v1[1]);
  4314. for(int i=1;i<=steps;i++){
  4315. real ratio=i==steps?1.0f:step*i;
  4316. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  4317. tnsVertex2d(v1s[0],v1s[1]);
  4318. }
  4319. }
  4320. void la_DrawNodeWires(laUiListDraw* uild){
  4321. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  4322. laBoxedTheme* bt=_LA_THEME_SOCKET;
  4323. tnsUseNoTexture();
  4324. #define _RSLICES 16
  4325. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  4326. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4327. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4328. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4329. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4330. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4331. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4332. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4333. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4334. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4335. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4336. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4337. }
  4338. if(MAIN.tNodeIn->Source){
  4339. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4340. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4341. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4342. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4343. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4344. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4345. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4346. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4347. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4348. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4349. }
  4350. #undef _RSLICES
  4351. tnsFlush();
  4352. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  4353. glLineWidth(ww);
  4354. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4355. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4356. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4357. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4358. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4359. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4360. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4361. }
  4362. if(MAIN.tNodeIn->Source){
  4363. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4364. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4365. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4366. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4367. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4368. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4369. }
  4370. tnsFlush();
  4371. glLineWidth(1);
  4372. la_InitSocketRecord(uild,0);
  4373. }
  4374. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  4375. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  4376. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  4377. }
  4378. 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){
  4379. laUiItem *ui;
  4380. laBoxedTheme *bt;
  4381. laUiList *sub;
  4382. laUiListDrawItem *uildi;
  4383. int Ret = 0;
  4384. if (!uil) return;
  4385. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  4386. ui = uil->UiItems.pFirst;
  4387. if(uil->PanY<0){uil->PanY=0;}
  4388. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  4389. uil->SaveScale=MAIN.UiScale;
  4390. MAIN.UiScale*=uil->Scale;
  4391. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4392. for (; ui;){
  4393. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4394. if (ui->Type == &_LA_UI_CONDITION){
  4395. laConditionUiExtraData *cued = ui->Extra;
  4396. la_StepExpression(cued->Expression);
  4397. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4398. if (!cued->IsTrue){
  4399. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4400. }else{
  4401. ui = ui->Item.pNext;
  4402. }
  4403. continue;
  4404. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4405. ui = ui->Item.pNext;
  4406. continue;
  4407. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4408. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4409. if (cued->IsTrue) ui = cued->EndUi;
  4410. else
  4411. ui = ui->Item.pNext;
  4412. continue;
  4413. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4414. laConditionUiExtraData *cued = ui->Extra;
  4415. ui->Type->Draw(ui, LA_RH);
  4416. if (ui->State == LA_UI_NORMAL){
  4417. cued->IsTrue = 0;
  4418. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4419. }else{
  4420. cued->IsTrue = 1;
  4421. ui = ui->Item.pNext;
  4422. }
  4423. continue;
  4424. }
  4425. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  4426. int NeedDraw=0;
  4427. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  4428. if(NeedDraw){
  4429. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  4430. }else{ ui->Type->Draw(ui, LA_RH); }
  4431. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  4432. tnsFlush();
  4433. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  4434. tnsResetViewMatrix();
  4435. }
  4436. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  4437. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  4438. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  4439. tnsFlush();
  4440. }
  4441. }
  4442. if(NeedDraw || RegisterNodes){
  4443. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  4444. if (ui->Type == _LA_UI_FIXED_GROUP ||
  4445. ui->Type == _LA_UI_TAB ||
  4446. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4447. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  4448. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  4449. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4450. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  4451. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  4452. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  4453. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  4454. 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); }
  4455. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  4456. 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);
  4457. 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)); }
  4458. }elif (ui->Type == _LA_UI_COLLECTION){
  4459. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  4460. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4461. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4462. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4463. int State;
  4464. ui->PP.EndInstance = sub->Instance;
  4465. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  4466. if(!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && NeedDraw){
  4467. if (CanGetState){
  4468. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  4469. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL));
  4470. }elif (sub->Instance == Active){
  4471. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL));
  4472. }
  4473. }
  4474. if(sub->TabName && sub->TabName->Ptr){
  4475. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4476. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4477. tnsDrawStringAuto(sub->TabName->Ptr,laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  4478. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  4479. tnsFlush();
  4480. }
  4481. if(CanGetTheme){
  4482. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4483. la_SwitchThemeQuick(t, OriginalTheme);
  4484. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL));
  4485. }
  4486. tnsFlush();
  4487. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  4488. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4489. }
  4490. ui->PP.EndInstance = Active;
  4491. }elif (ui->Type == _LA_UI_CANVAS){
  4492. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4493. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4494. tnsFlush();
  4495. Ret += la_DrawUiListRecursive(uild, sub, L-1, R+1, U-1, B+1, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  4496. }
  4497. }
  4498. }
  4499. ui = ui->Item.pNext;
  4500. }else{
  4501. ui = ui->Item.pNext;
  4502. }
  4503. }
  4504. tnsFlush();
  4505. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  4506. la_RestoreLastUiListMatrix(uild, B - U);
  4507. MAIN.UiScale=uil->SaveScale;
  4508. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4509. return Ret;
  4510. }
  4511. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  4512. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  4513. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  4514. tnsUseNoTexture();
  4515. tnsColor4d(1, 1, 1, 1);
  4516. tnsVertex2d(L, U);
  4517. tnsVertex2d(R, U);
  4518. tnsVertex2d(R, B);
  4519. tnsVertex2d(L, B);
  4520. tnsPackAs(GL_LINE_LOOP);
  4521. tnsVertex2d(L + 3, Begin);
  4522. tnsVertex2d(R - 3, Begin);
  4523. tnsVertex2d(R - 3, End);
  4524. tnsVertex2d(L + 3, End);
  4525. tnsPackAs(GL_LINE_LOOP);
  4526. }
  4527. int laIsInUiItem(laUiItem *ui, int x, int y){
  4528. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  4529. return 1;
  4530. }
  4531. int laIsInBound(int x, int y, int l, int r, int u, int b){
  4532. if (x < l || x > r || y < u || y > b) return 0;
  4533. return 1;
  4534. }
  4535. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  4536. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  4537. laUiItem *ui, *tui;
  4538. laBoxedTheme *bt;
  4539. laUiList *sub;
  4540. int CPB = 0;
  4541. if (!uil || (LimB && y > LimB)) return 0;
  4542. x += uil->PanX;
  4543. y += uil->PanY;
  4544. for (ui = uil->UiItems.pFirst; ui;){
  4545. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4546. if (ui->Type == &_LA_UI_CONDITION){
  4547. laConditionUiExtraData *cued = ui->Extra;
  4548. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  4549. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4550. if (!cued->IsTrue){
  4551. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4552. }else{
  4553. ui = ui->Item.pNext;
  4554. }
  4555. continue;
  4556. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4557. ui = ui->Item.pNext;
  4558. continue;
  4559. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4560. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4561. if (cued->IsTrue) ui = cued->EndUi;
  4562. else
  4563. ui = ui->Item.pNext;
  4564. continue;
  4565. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4566. laConditionUiExtraData *cued = ui->Extra;
  4567. if (laIsInUiItem(ui, x, y)){
  4568. lstAppendPointer(LocalBuf, uil);
  4569. return ui;
  4570. }
  4571. if (ui->State == LA_UI_NORMAL){
  4572. cued->IsTrue = 0;
  4573. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4574. }else{
  4575. cued->IsTrue = 1;
  4576. ui = ui->Item.pNext;
  4577. }
  4578. continue;
  4579. }
  4580. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  4581. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  4582. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  4583. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  4584. if(!la_DetectSplit(ui->C, x)) Add=0;
  4585. }
  4586. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  4587. }
  4588. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4589. if (ui->Page->HeightCoeff) CPB = ui->B;
  4590. else CPB = ui->Page->B;
  4591. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4592. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  4593. lstAppendPointer(LocalBuf, uil);
  4594. return tui;
  4595. }
  4596. }else if (laIsInUiItem(ui, x, y)){
  4597. lstAppendPointer(LocalBuf, uil);return ui;
  4598. }
  4599. }
  4600. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  4601. if (laIsInUiItem(ui, x, y)){
  4602. lstAppendPointer(LocalBuf, uil);
  4603. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  4604. if(Deep){
  4605. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  4606. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  4607. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  4608. lstAppendPointer(LocalBuf, iuil);
  4609. return tui;
  4610. }
  4611. }
  4612. }
  4613. }
  4614. return ui;
  4615. }
  4616. }
  4617. if (ui->Type == _LA_UI_CANVAS){
  4618. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4619. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4620. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  4621. lstAppendPointer(LocalBuf, uil);
  4622. return tui;
  4623. }
  4624. }
  4625. }
  4626. if (laIsInUiItem(ui, x, y)){
  4627. lstAppendPointer(LocalBuf, uil);
  4628. return ui;
  4629. }
  4630. }
  4631. ui = ui->Item.pNext;
  4632. }
  4633. return 0;
  4634. }
  4635. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  4636. laListHandle Locals={0};
  4637. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  4638. while(lstPopPointer(&Locals));
  4639. printf("%s\n", ui?ui->Type->Identifier:"?");
  4640. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  4641. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4642. if(pc==PCInOrOut) return ui;
  4643. }
  4644. return 0;
  4645. }
  4646. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  4647. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  4648. laUiItem *ui = uil->UiItems.pFirst;
  4649. laBoxedTheme *bt;
  4650. laUiList *tuil;
  4651. laUiList *sub;
  4652. int CPB = 0;
  4653. x += uil->PanX;
  4654. y += uil->PanY;
  4655. if (y > LimH) return uil;
  4656. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  4657. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  4658. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  4659. return uil;
  4660. }
  4661. for (ui = uil->UiItems.pFirst; ui;){
  4662. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4663. if (ui->Type == &_LA_UI_CONDITION){
  4664. laConditionUiExtraData *cued = ui->Extra;
  4665. //la_StepExpression(cued->Expression);
  4666. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4667. if (!cued->IsTrue){
  4668. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4669. }else{
  4670. ui = ui->Item.pNext;
  4671. }
  4672. continue;
  4673. }
  4674. if (ui->Type == &_LA_UI_CONDITION_END){
  4675. ui = ui->Item.pNext;
  4676. continue;
  4677. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4678. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4679. if (cued->IsTrue) ui = cued->EndUi;
  4680. else
  4681. ui = ui->Item.pNext;
  4682. continue;
  4683. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4684. laConditionUiExtraData *cued = ui->Extra;
  4685. if (ui->State == LA_UI_NORMAL){
  4686. cued->IsTrue = 0;
  4687. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4688. }else{
  4689. cued->IsTrue = 1;
  4690. ui = ui->Item.pNext;
  4691. }
  4692. continue;
  4693. }
  4694. if (InToContainerUI && ui != Exception){
  4695. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4696. if (ContainerParent) (*ContainerParent) = uil;
  4697. if (ParentUi) *ParentUi = ui;
  4698. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4699. //if (y > LimH) return uil;
  4700. 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))){
  4701. return tuil;
  4702. }
  4703. }
  4704. }
  4705. }
  4706. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4707. if (ui->Page->HeightCoeff) CPB = ui->B;
  4708. else CPB = ui->Page->B;
  4709. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  4710. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  4711. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  4712. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  4713. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4714. if (ParentUi) *ParentUi = ui;
  4715. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  4716. }
  4717. }
  4718. ui = ui->Item.pNext;
  4719. }
  4720. return uil;
  4721. }
  4722. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  4723. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  4724. laUiItem *ui = uil->UiItems.pFirst;
  4725. laBoxedTheme *bt;
  4726. laUiList *tuil;
  4727. laUiList *sub;
  4728. int CPB = 0;
  4729. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  4730. x += uil->PanX;
  4731. y += uil->PanY;
  4732. if (y > LimH) return uil;
  4733. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  4734. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  4735. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  4736. return uil;
  4737. }
  4738. for (ui = uil->UiItems.pFirst; ui;){
  4739. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4740. if (ui->Type == &_LA_UI_CONDITION){
  4741. laConditionUiExtraData *cued = ui->Extra;
  4742. //la_StepExpression(cued->Expression);
  4743. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4744. if (!cued->IsTrue){
  4745. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4746. }else{
  4747. ui = ui->Item.pNext;
  4748. }
  4749. continue;
  4750. }
  4751. if (ui->Type == &_LA_UI_CONDITION_END){
  4752. ui = ui->Item.pNext;
  4753. continue;
  4754. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4755. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4756. if (cued->IsTrue) ui = cued->EndUi;
  4757. else
  4758. ui = ui->Item.pNext;
  4759. continue;
  4760. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4761. laConditionUiExtraData *cued = ui->Extra;
  4762. if (ui->State == LA_UI_NORMAL){
  4763. cued->IsTrue = 0;
  4764. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4765. }else{
  4766. cued->IsTrue = 1;
  4767. ui = ui->Item.pNext;
  4768. }
  4769. continue;
  4770. }
  4771. if (InToContainerUI && ui != Exception){
  4772. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4773. if (ContainerParent) (*ContainerParent) = uil;
  4774. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4775. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4776. //if (y > LimH) return uil;
  4777. 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))){
  4778. return tuil;
  4779. }
  4780. }
  4781. }
  4782. }
  4783. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4784. if (ui->Page->HeightCoeff) CPB = ui->B;
  4785. else CPB = ui->Page->B;
  4786. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  4787. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4788. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  4789. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4790. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4791. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4792. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  4793. }
  4794. }
  4795. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  4796. if (ui->Page->HeightCoeff) CPB = ui->B;
  4797. else
  4798. CPB = ui->Page->B;
  4799. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  4800. if (ScrollUil) *ScrollUil = ui->Page;
  4801. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4802. }
  4803. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4804. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4805. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  4806. }
  4807. }
  4808. ui = ui->Item.pNext;
  4809. }
  4810. return uil;
  4811. }
  4812. int la_TestUiListMinumWidth(laUiList *uil){
  4813. laUiItem *ui, *tui;
  4814. laBoxedTheme *bt;
  4815. laUiList *sub;
  4816. int CPB = 0;
  4817. int W = 0;
  4818. int tW, sW, RowMode=0, rW;
  4819. void *Restore;
  4820. for (ui = uil->UiItems.pFirst; ui;){
  4821. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4822. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4823. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  4824. tW = (int)((float)tW / ui->C->PreWidth + 2);
  4825. if (W < tW) W = tW;
  4826. }elif (ui->Type == _LA_UI_COLLECTION){
  4827. Restore = ui->PP.EndInstance;
  4828. tW = 0; sW = 0;
  4829. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4830. ui->PP.EndInstance = sub->Instance;
  4831. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  4832. if (sW > tW) tW = sW;
  4833. }
  4834. ui->PP.EndInstance = Restore;
  4835. tW = (int)((float)tW / ui->C->PreWidth + 2);
  4836. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  4837. if (W < tW) W = tW;
  4838. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  4839. RowMode=1; rW=0;
  4840. }elif (ui->Type==&_LA_UI_ROW_END){
  4841. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  4842. }elif (ui->Type->GetMinWidth){
  4843. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  4844. tW = (int)((float)tW / ui->C->PreWidth + 2);
  4845. if(RowMode){ rW+=tW; }else{ if (W < tW) W = tW; }
  4846. }
  4847. ui = ui->Item.pNext;
  4848. }
  4849. return W;
  4850. }
  4851. void la_InitLLVM(){
  4852. //LLVMLinkInMCJIT();
  4853. //LLVMInitializeNativeTarget();
  4854. //LLVMInitializeNativeAsmPrinter();
  4855. //LLVMInitializeNativeAsmParser();
  4856. // MAIN.llvmContext = LLVMGetGlobalContext();
  4857. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  4858. }
  4859. //==================================================================================================
  4860. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  4861. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  4862. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  4863. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  4864. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  4865. memFree(kmi);
  4866. }
  4867. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  4868. laKeyMapItem *kmi;
  4869. if (!km) return 0;
  4870. kmi = memAcquire(sizeof(laKeyMapItem));
  4871. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  4872. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  4873. }else{
  4874. strSafeSet(&kmi->Operation, Operation);
  4875. }
  4876. strSafeSet(&kmi->Instructions, ExtraInstructions);
  4877. kmi->SpecialKeyBits = SpecialKeyBits;
  4878. kmi->EventType = EventType;
  4879. kmi->Key = Key;
  4880. kmi->SelectBase = SelectBase;
  4881. lstAppendItem(&km->Items, kmi);
  4882. return kmi;
  4883. }
  4884. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  4885. laKeyMapItem *kmi; int inv=0;
  4886. char *instructions;
  4887. if(e->Type==LA_MOUSEMOVE) return 0;
  4888. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  4889. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  4890. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  4891. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  4892. if (kmi->Operation)
  4893. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  4894. else
  4895. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  4896. inv = 1;
  4897. }
  4898. }
  4899. return inv;
  4900. }
  4901. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  4902. laKeyMapItem *kmi;
  4903. char *instructions;
  4904. int inv = 0; int lx = -1, ly = -1;
  4905. if(e->Type==LA_MOUSEMOVE) return 0;
  4906. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  4907. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  4908. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  4909. if (e->Localized){
  4910. lx = e->x;
  4911. ly = e->y;
  4912. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  4913. e->Localized = 0;
  4914. }
  4915. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  4916. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  4917. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  4918. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  4919. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  4920. }elif (kmi->Operation){
  4921. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  4922. }else{
  4923. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  4924. }
  4925. inv = 1;
  4926. if (lx >= 0){
  4927. e->x = lx;
  4928. e->y = ly;
  4929. e->Localized = 1;
  4930. }
  4931. }
  4932. }
  4933. return inv;
  4934. }
  4935. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  4936. void la_DestroyOperatorType(laOperatorType* at){
  4937. //if(at->PC) la_FreePropertyContainer(at->PC);
  4938. memFree(at);
  4939. }
  4940. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  4941. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  4942. uint32_t IconID, int ExtraMark){
  4943. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  4944. at->Identifier = ID;
  4945. at->Name = Name;
  4946. at->Description = Description;
  4947. at->Check = Check;
  4948. at->Invoke = Invoke;
  4949. at->Init = Init;
  4950. at->Exit = Exit;
  4951. at->Modal = Modal;
  4952. at->IconID = IconID;
  4953. at->ExtraMark = ExtraMark;
  4954. at->ParseArgs = la_DefaultOperatorParser;
  4955. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  4956. return at;
  4957. }
  4958. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  4959. ot->PC = memAcquire(sizeof(laPropContainer));
  4960. ot->PC->Identifier = ot->Identifier;
  4961. ot->PC->Hyper = HyperLevel;
  4962. return ot->PC;
  4963. }
  4964. laOperator *la_CreateOperator(laOperatorType *at){
  4965. laOperator *a = CreateNew(laOperator);
  4966. a->Type = at;
  4967. if (at->PC && at->PC->Props.pFirst){
  4968. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  4969. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  4970. a->PP.LastPs->p->SubProp = at->PC;
  4971. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  4972. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  4973. a->PP.LastPs->Type = L'.';
  4974. }
  4975. return a;
  4976. }
  4977. int la_OperatorTypeByID(laOperatorType *a, char *id){
  4978. return (!strcmp(a->Identifier, id));
  4979. }
  4980. laOperatorType *laGetOperatorType(const char *ID){
  4981. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  4982. }
  4983. int laOperatorExistsT(laOperatorType* at){
  4984. if (!at) return 0;
  4985. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  4986. return 0;
  4987. }
  4988. int laOperatorExists(const char* ID){
  4989. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  4990. return laOperatorExistsT(at);
  4991. }
  4992. int la_OperatorExists(laOperator *ac){
  4993. if (!ac) return 0;
  4994. laOperator *a;
  4995. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  4996. return 0;
  4997. }
  4998. int la_UiOperatorExists(void *inst){
  4999. laOperator *a;
  5000. if (!inst) return 0;
  5001. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  5002. if (((laUiItem *)a->Instance) == inst){
  5003. return 1;
  5004. }
  5005. }
  5006. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5007. if (a->Instance == inst){
  5008. return 1;
  5009. }
  5010. }
  5011. return 0;
  5012. }
  5013. int la_OperatorPending(laOperator *target){
  5014. laOperator *a;
  5015. if (!target) return 0;
  5016. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5017. if (a == target){
  5018. return 1;
  5019. }
  5020. }
  5021. return 0;
  5022. }
  5023. void laSetOperatorLocalizer(void *ToPanel){
  5024. MAIN.ToPanel = ToPanel;
  5025. }
  5026. void la_DestroyConfirmData(laConfirmData **cd);
  5027. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  5028. laOperator *ai = (*a);
  5029. laOperator *ac = ((*a)->Child);
  5030. void *Ret = 0;
  5031. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using){
  5032. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  5033. }
  5034. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  5035. if ((*a)->PP.LastPs){
  5036. memFree((*a)->PP.LastPs->p);
  5037. memFree((*a)->PP.LastPs);
  5038. }
  5039. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  5040. la_SetPropMathcerContext((*a)->OperatorPanel);
  5041. MAIN.CurrentPanel = (*a)->OperatorPanel;
  5042. laDestroySinglePanel((*a)->OperatorPanel,0);
  5043. }
  5044. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  5045. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  5046. lstClearPointer(&(*a)->LocalUiLists);
  5047. if (Operators){
  5048. Ret = ai->Item.pNext;
  5049. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  5050. else
  5051. lstRemoveItem(Operators, *a);
  5052. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  5053. if (ai->Child == (*a)) ai->Child = 0;
  5054. }
  5055. }
  5056. strSafeDestroy(&(*a)->RuntimeHint);
  5057. free(*a);
  5058. return Ret;
  5059. }
  5060. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  5061. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5062. if (!at) return 0;
  5063. if (!at->Check) return 1;
  5064. return (at->Check(This, Instructions));
  5065. }
  5066. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  5067. if (!at) return 0;
  5068. if (!at->Check) return 1;
  5069. return (at->Check(This, Instructions));
  5070. }
  5071. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5072. laPropPack FakePP = {0};
  5073. laPropStep FakePs = {0};
  5074. if (!at) return 0;
  5075. if (!at->Check) return 1;
  5076. FakePP.LastPs = &FakePs;
  5077. FakePP.Go = FakePP.LastPs;
  5078. FakePP.LastPs->p = This->LastPs->p;
  5079. FakePP.LastPs->UseInstance = This->EndInstance;
  5080. FakePP.EndInstance = Real_FromInstance;
  5081. FakePP.LastIndex = This->LastIndex;
  5082. return (at->Check(&FakePP, Instructions));
  5083. }
  5084. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5085. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5086. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  5087. }
  5088. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  5089. laOperator *a, *f = From;
  5090. int rev;
  5091. if (!f && e&&e->Localized) return -1;
  5092. a = la_CreateOperator(at);
  5093. a->ToPanel = MAIN.ToPanel;
  5094. a->This = This;
  5095. a->ExtraInstructions = args;
  5096. strMakeInstructions(&a->ExtraInstructionsP, args);
  5097. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5098. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5099. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  5100. la_DestroyOperator(&a, 0, 0);
  5101. return LA_CANCELED;
  5102. }
  5103. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5104. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  5105. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5106. e->Localized = 1;
  5107. }
  5108. if (e&&e->Localized){
  5109. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  5110. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5111. e->Localized = 0;
  5112. }else{
  5113. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5114. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5115. }
  5116. }
  5117. if (From) f->Child = a;
  5118. a->Using = 1;
  5119. if (at->Init) at->Init(a);
  5120. rev = at->Invoke(a, e);
  5121. a->Using = 0;
  5122. if (rev & LA_FINISH){
  5123. a->StopNow = 1; if(From)From->Child=0;
  5124. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5125. }
  5126. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5127. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5128. a->State = rev;
  5129. a->PP.EndInstance = a->CustomData;
  5130. if (a->PP.LastPs) a->PP.LastPs->Type = L'.';
  5131. }else
  5132. la_DestroyOperator(&a, 0, 0);
  5133. return rev;
  5134. }
  5135. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  5136. laOperatorType *at; laOperator *a, *f = From;
  5137. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5138. if (!at) return -1;
  5139. return laInvokeP(From,at,e,This,args,args2);
  5140. }
  5141. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  5142. laOperator *a, *f = From;
  5143. int rev;
  5144. laPropPack *created;
  5145. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  5146. created = memAcquireSimple(sizeof(laPropPack));
  5147. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  5148. created->Go = created->LastPs;
  5149. created->LastPs->p = OrigionalThis->LastPs->p;
  5150. created->LastPs->UseInstance = FromInstance;
  5151. created->EndInstance = FromInstance;
  5152. created->LastIndex = OrigionalThis->LastIndex;
  5153. a = la_CreateOperator(at);
  5154. a->ToPanel = MAIN.ToPanel;
  5155. a->This = created;
  5156. a->CreatedThis = created;
  5157. a->ExtraInstructions = args;
  5158. strMakeInstructions(&a->ExtraInstructionsP, args);
  5159. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5160. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5161. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  5162. la_DestroyOperator(&a, 0, 0);
  5163. return LA_CANCELED;
  5164. }
  5165. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5166. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5167. if (From) f->Child = a;
  5168. a->Using = 1;
  5169. if (at->Init) at->Init(a);
  5170. rev = at->Invoke(a, e);
  5171. a->Using = 0;
  5172. if (rev & LA_FINISH){
  5173. a->StopNow = 1; if(From)From->Child=0;
  5174. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5175. }
  5176. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5177. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5178. a->State = rev;
  5179. a->PP.EndInstance = a->CustomData;
  5180. }else
  5181. la_DestroyOperator(&a, 0, 0);
  5182. return rev;
  5183. }
  5184. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5185. laOperator *a, *f = From;
  5186. int rev;
  5187. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  5188. a = la_CreateOperator(at);
  5189. a->Instance = inst;
  5190. a->ToPanel = MAIN.ToPanel;
  5191. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  5192. if (From) f->Child = a;
  5193. a->Using = 1;
  5194. if (at->Init) at->Init(a);
  5195. rev = at->Invoke(a, e);
  5196. a->Using = 0;
  5197. if (rev & LA_FINISH){
  5198. a->StopNow = 1; if(From)From->Child=0;
  5199. }
  5200. if (rev & LA_BLOCK){
  5201. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5202. a->State = rev;
  5203. }else la_DestroyOperator(&a, 0, 0);
  5204. DEB = a;
  5205. return rev;
  5206. }
  5207. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5208. laOperatorType *at;
  5209. laOperator *a, *f = From;
  5210. if (la_UiOperatorExists(inst)) return -1;
  5211. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  5212. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  5213. }
  5214. void laRequestDelayEvent(real Seconds){
  5215. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  5216. int la_UiStillInService(void *UiInstance){
  5217. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  5218. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  5219. if (ai->Instance == UiInstance) return 1;
  5220. }
  5221. return 0;
  5222. }
  5223. void la_StopUiOperatorService(void *UiInstance){
  5224. laOperator *ai, *dai, *NextAi;
  5225. if (!MAIN.CurrentWindow) return;
  5226. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5227. NextAi = ai->Item.pNext;
  5228. if (ai->Instance == UiInstance){
  5229. if (ai->Child){
  5230. la_StopUiOperatorService(ai->Child->Instance);
  5231. ai->Child = 0;
  5232. }
  5233. laOperator *dai = ai;
  5234. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  5235. continue;
  5236. }
  5237. }
  5238. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5239. NextAi = ai->Item.pNext;
  5240. if (ai->Instance == UiInstance){
  5241. if (ai->Instance == ai->ToPanel){
  5242. //laHidePanelWithDissoveEffect(ai->ToPanel);
  5243. //ai->ToPanel->LaterDestroy = 1;
  5244. }
  5245. if (ai->Child && la_OperatorExists(ai->Child)){
  5246. la_StopUiOperatorService(ai->Child->Instance);
  5247. //ai->Child = 0;
  5248. }
  5249. if (!ai->Using){
  5250. laOperator *dai = ai;
  5251. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5252. }else
  5253. ai->StopNow = 1;
  5254. }
  5255. }
  5256. }
  5257. void la_StopAllOperators(){
  5258. laOperator *ai, *dai, *NextAi;
  5259. if (!MAIN.CurrentWindow) return;
  5260. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5261. NextAi = ai->Item.pNext;
  5262. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  5263. continue;
  5264. }
  5265. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5266. NextAi = ai->Item.pNext;
  5267. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  5268. laHidePanelWithDissoveEffect(ai->ToPanel);
  5269. ai->ToPanel->LaterDestroy = 1;
  5270. }
  5271. if (!ai->Using){
  5272. laOperator *dai = ai;
  5273. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5274. }else ai->StopNow = 1;
  5275. }
  5276. }
  5277. void la_DestroyConfirmData(laConfirmData **cd){
  5278. if((!cd)||!(*cd)) return;
  5279. if ((*cd)->CustomData) (*cd)->Destroy((*cd)->CustomData);
  5280. if ((*cd)->StrData) free((*cd)->StrData);
  5281. FreeMem((*cd));
  5282. (*cd) = 0;
  5283. }
  5284. void laConfirmInt(laOperator *a, int Data, int mode){
  5285. laOperator *ai = a;
  5286. laConfirmData *cd = CreateNew(laConfirmData);
  5287. cd->IData = Data;
  5288. cd->Mode = mode;
  5289. ai->NextConfirmData = cd;
  5290. laRetriggerOperators();
  5291. }
  5292. void laConfirmFloat(laOperator *a, real Data, int mode){
  5293. laOperator *ai = a;
  5294. laConfirmData *cd = CreateNew(laConfirmData);
  5295. cd->FData = Data;
  5296. cd->Mode = mode;
  5297. ai->NextConfirmData = cd;
  5298. laRetriggerOperators();
  5299. }
  5300. void laConfirmString(laOperator *a, char *Str, int mode){
  5301. laOperator *ai = a;
  5302. laConfirmData *cd = CreateNew(laConfirmData);
  5303. int len = strlen(Str);
  5304. char *buf = calloc(len + 1, sizeof(char));
  5305. strcpy(buf, Str);
  5306. cd->StrData = buf;
  5307. cd->Mode = mode;
  5308. cd->Destroy = free;
  5309. ai->NextConfirmData = cd;
  5310. laRetriggerOperators();
  5311. }
  5312. int laConfirmSameDataIfAny(laOperator *a){
  5313. laOperator *ai = a;
  5314. laConfirmData *cd;
  5315. char *buf = 0;
  5316. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  5317. cd = CreateNew(laConfirmData);
  5318. if (ai->ConfirmData->StrData){
  5319. int len = strlen(ai->ConfirmData->StrData);
  5320. buf = calloc(len + 1, sizeof(char));
  5321. strcpy(buf, ai->ConfirmData->StrData);
  5322. }
  5323. //cd->CustomData = cd->CustomData;
  5324. cd->IData = ai->ConfirmData->IData;
  5325. cd->FData = ai->ConfirmData->FData;
  5326. cd->StrData = buf;
  5327. cd->Mode = ai->ConfirmData->Mode;
  5328. cd->Destroy = ai->ConfirmData->Destroy;
  5329. ai->NextConfirmData = cd;
  5330. laRetriggerOperators();
  5331. return 1;
  5332. }
  5333. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  5334. laOperator *ai = a;
  5335. laConfirmData *cd = CreateNew(laConfirmData);
  5336. cd->CustomData = UserData;
  5337. cd->Mode = mode;
  5338. cd->Destroy = Destroy;
  5339. ai->NextConfirmData = cd;
  5340. laRetriggerOperators();
  5341. }
  5342. int laGetConfirmMode(laOperator *a){
  5343. return ((laOperator *)a)->ConfirmData->Mode;
  5344. }
  5345. int laGetConfirmInt(laOperator *a){
  5346. laOperator *ai = a;
  5347. int rev = ai->ConfirmData->IData;
  5348. la_DestroyConfirmData(&ai->ConfirmData);
  5349. ai->ConfirmData = 0;
  5350. return rev;
  5351. }
  5352. real laGetConfirmFloat(laOperator *a){
  5353. laOperator *ai = a;
  5354. real rev = ai->ConfirmData->FData;
  5355. la_DestroyConfirmData(&ai->ConfirmData);
  5356. ai->ConfirmData = 0;
  5357. return rev;
  5358. }
  5359. void laGetConfirmString(laOperator *a, char *buf){
  5360. laOperator *ai = a;
  5361. strcpy(buf, ai->ConfirmData->StrData);
  5362. la_DestroyConfirmData(&ai->ConfirmData);
  5363. ai->ConfirmData = 0;
  5364. }
  5365. void *laGetConfirmUserData(laOperator *a){
  5366. laOperator *ai = a;
  5367. return ai->ConfirmData->CustomData;
  5368. }
  5369. void laFinalizeOperators(){
  5370. laOperatorType *at;
  5371. laListHandle *lst;
  5372. int i;
  5373. for (i = 0; i < 256; i++){
  5374. lst = &MAIN.OperatorTypeHash.Entries[i];
  5375. for (at = lst->pFirst; at; at = at->Item.pNext){
  5376. if (at->PC && at->PC->Props.pFirst){
  5377. lstAppendItem(&MAIN.PropContainers, at->PC);
  5378. }
  5379. }
  5380. }
  5381. }
  5382. //=================
  5383. static void la_RecordWacomMotions(XIRawEvent *event)
  5384. {
  5385. double *valuator = event->valuators.values;
  5386. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  5387. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  5388. //Window root_return, child_return;
  5389. //int root_x_return, root_y_return;
  5390. //int win_x_return, win_y_return;
  5391. //unsigned int mask_return;
  5392. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  5393. // &root_x_return, &root_y_return,
  5394. // &win_x_return, &win_y_return,
  5395. // &mask_return);
  5396. //
  5397. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  5398. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  5399. if(XIMaskIsSet(event->valuators.mask, 3)){ if(IsStylus) MAIN.StylusAngleX=valuator[3]; else MAIN.EraserAngleX=valuator[3]; }
  5400. if(XIMaskIsSet(event->valuators.mask, 4)){ if(IsStylus) MAIN.StylusAngleY=valuator[4]; else MAIN.EraserAngleY=valuator[4]; }
  5401. MAIN.IsPen=1;
  5402. }
  5403. int la_UpdateOperatorHints(laWindow* w){
  5404. laSafeString* ss=0;
  5405. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  5406. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  5407. }
  5408. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  5409. }else{
  5410. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  5411. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  5412. }
  5413. strSafeDestroy(&ss);
  5414. }
  5415. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  5416. laOperator *a, *NextA = 0;
  5417. int Result = 0;
  5418. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  5419. a = Operators->pFirst;
  5420. while (1){
  5421. if (!a) break;
  5422. if (a->StopNow){
  5423. NextA = a->Item.pNext;
  5424. if (a->Type->Exit) a->Type->Exit(a, Result);
  5425. ConfirmData = a->NextConfirmData;
  5426. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  5427. NextConfirmData = ConfirmData;
  5428. a->ConfirmData = 0;
  5429. a->NextConfirmData = 0;
  5430. la_DestroyOperator(&a, Operators, 0);
  5431. a = NextA;
  5432. if (a){
  5433. a->ConfirmData = NextConfirmData;
  5434. }
  5435. continue;
  5436. }
  5437. a->Using = 1;
  5438. la_SetPropMathcerContext(a->ToPanel);
  5439. laSetOperatorLocalizer(a->ToPanel);
  5440. MAIN.CurrentPanel = a->ToPanel;
  5441. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  5442. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5443. e->Localized = 1;
  5444. }
  5445. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  5446. //la_PrintOperatorStack();
  5447. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  5448. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  5449. e->Localized = 0;
  5450. }
  5451. la_SetPropMathcerContext(0);
  5452. laSetOperatorLocalizer(0);
  5453. MAIN.CurrentPanel = 0;
  5454. a->Using = 0;
  5455. if (Result & LA_PASS_ON){
  5456. laConfirmSameDataIfAny(a);
  5457. NextA = a->Item.pNext;
  5458. }else{
  5459. NextA = 0;
  5460. if (a->NextConfirmData){
  5461. la_DestroyConfirmData(&a->NextConfirmData);
  5462. }
  5463. }
  5464. ConfirmData = a->NextConfirmData;
  5465. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  5466. NextConfirmData = ConfirmData;
  5467. a->ConfirmData = 0;
  5468. a->NextConfirmData = 0;
  5469. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  5470. if (a->Type->Exit) a->Type->Exit(a, Result);
  5471. la_DestroyOperator(&a, Operators, 0);
  5472. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  5473. }
  5474. a = NextA;
  5475. if (a){
  5476. a->ConfirmData = NextConfirmData;
  5477. }
  5478. }
  5479. return 1;
  5480. }
  5481. int la_HandleEvents(laWindow *w){
  5482. laEvent *e, *NextE;
  5483. laOperator *a;
  5484. laThreadNotifier *tn;
  5485. MAIN.CurrentWindow=w;
  5486. //pthread_spin_lock(&MAIN.csNotifier);
  5487. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  5488. //pthread_spin_unlock(&MAIN.csNotifier);
  5489. laNotifyUsers(tn->Path);
  5490. FreeMem(tn);
  5491. //if (MAIN.ThreadNotifiers.pFirst)
  5492. //pthread_spin_lock(&MAIN.csNotifier);
  5493. }
  5494. //pthread_spin_unlock(&MAIN.csNotifier);
  5495. while (1){
  5496. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  5497. while (w->PendingOperators.pLast){
  5498. a = w->PendingOperators.pLast;
  5499. if (a->OperatorPanel){
  5500. laSetOperatorLocalizer(a->OperatorPanel);
  5501. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  5502. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  5503. }
  5504. lstRemoveItem(&w->PendingOperators, a);
  5505. lstPushItem(&w->Operators, a);
  5506. }
  5507. while (1){
  5508. if (!w->EventList.pFirst) break;
  5509. e = lstPopItem(&w->EventList);
  5510. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  5511. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); FreeMem(e); return 0; } //EXIT
  5512. FreeMem(e);
  5513. }
  5514. if (!MAIN.ReTriggerOperators) break;
  5515. }
  5516. la_UpdateOperatorHints(w);
  5517. return 1;
  5518. }
  5519. int la_AllowInput(uint32_t ch){
  5520. if(ch>=32 || ch==L'\n' || ch==L'\t' || ch==L'\b') return 1;
  5521. return 0;
  5522. }
  5523. int laCopyToClipboard(unsigned char * text){
  5524. XEvent event; Window owner, window=MAIN.CurrentWindow->win;
  5525. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  5526. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return;
  5527. strSafeSet(&MAIN.CopyPending, text);
  5528. }
  5529. int la_ProcessSysMessage(){
  5530. XEvent e;
  5531. int type;
  5532. int InputCount = 0, CharCount=0;
  5533. KeySym InputKeysym = 0;
  5534. Status InputStatus = 0;
  5535. int SendDelay=0,SendIdle=0;
  5536. if(!MAIN.DelayTriggered && MAIN.TimeAccum-MAIN.DelayStart>MAIN.DelayTime) SendDelay=1;
  5537. if(!MAIN.IdleTriggered && MAIN.TimeAccum-MAIN.IdleStart>MAIN.IdleTime) SendIdle=1;
  5538. while(XPending(MAIN.dpy)){
  5539. XGenericEventCookie *cookie = &e.xcookie;
  5540. XNextEvent(MAIN.dpy, &e);
  5541. if (XFilterEvent(&e, None)) continue;
  5542. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  5543. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  5544. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  5545. XFreeEventData(MAIN.dpy, cookie); continue;
  5546. }
  5547. switch(e.type){
  5548. case ConfigureNotify:
  5549. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  5550. break;
  5551. case Expose:
  5552. //glXSwapBuffers(MAIN.dpy,e.xexpose.window);
  5553. //SwapBuffers(GetDC(hwnd));
  5554. break;
  5555. case MotionNotify:
  5556. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  5557. MAIN.IsPen=0;
  5558. break;
  5559. case ButtonPress:
  5560. type=LA_MOUSEDOWN;
  5561. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  5562. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  5563. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  5564. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  5565. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  5566. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  5567. MAIN.IsPen=0;
  5568. break;
  5569. case ButtonRelease:
  5570. type=LA_MOUSEUP;
  5571. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  5572. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  5573. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  5574. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  5575. MAIN.IsPen=0;
  5576. break;
  5577. case KeyPress:
  5578. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  5579. MAIN.InputBuf[InputCount]=0;
  5580. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  5581. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  5582. /*printf("pressed KEY: %d\n", (int)InputKeysym);*/
  5583. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  5584. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  5585. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  5586. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  5587. }
  5588. break;
  5589. case KeyRelease:
  5590. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  5591. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  5592. }
  5593. case ClientMessage:
  5594. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  5595. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  5596. }
  5597. break;
  5598. case SelectionNotify:
  5599. if(e.xselection.selection != MAIN.bufid) continue;
  5600. if (e.xselection.property){
  5601. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  5602. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  5603. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  5604. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  5605. else if(result) {
  5606. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  5607. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  5608. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  5609. }
  5610. XFree(result);
  5611. return True;
  5612. }
  5613. case SelectionRequest:
  5614. if(!MAIN.CopyPending){ break; }
  5615. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  5616. if (e.xselectionrequest.selection != MAIN.selection) break;
  5617. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  5618. XSelectionEvent ev = {0};
  5619. int R = 0;
  5620. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  5621. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  5622. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  5623. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  5624. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  5625. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  5626. else if (ev.target == MAIN.UTF8)
  5627. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  5628. else ev.property = None;
  5629. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  5630. break;
  5631. case SelectionClear:
  5632. return;
  5633. default:
  5634. break;
  5635. }
  5636. }
  5637. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  5638. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  5639. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  5640. }
  5641. return 1;
  5642. };
  5643. void la_PrintOperatorStack(){
  5644. laWindow *w = MAIN.CurrentWindow;
  5645. laOperator *a;
  5646. printf("\n");
  5647. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  5648. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  5649. a->Type->Identifier, a->Instance,
  5650. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  5651. }
  5652. }
  5653. int la_DrawWindow(laWindow *w){
  5654. MAIN.CurrentWindow = w;
  5655. la_WindowDefDraw(w, 0);
  5656. }
  5657. int laFinalize(){
  5658. if(!laValidateProperties()){ laShutoff(); return 0; }
  5659. laUiTemplate* uit;
  5660. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  5661. return 1;
  5662. }
  5663. void laMainLoop(){
  5664. laWindow *w = MAIN.Windows.pFirst, *NextW;
  5665. laTimeRecorder FrameStartTime, FrameEndTime;
  5666. time_t t1, t2;
  5667. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  5668. static int a = 0;
  5669. if(!laFinalize()) return;
  5670. MAIN.DelayTriggered=1;
  5671. while (1){
  5672. laRecordTime(&FrameStartTime);
  5673. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  5674. if(!la_ProcessSysMessage()){ return; }
  5675. la_UpdateControllerStatus();
  5676. if(MAIN.InputMapping->NeedRebuild){ la_RebuildInputMapping(); }
  5677. if(MAIN.InputMapping->NeedEval){ la_RunInputMapping(); }
  5678. if(MAIN.Drivers->NeedRebuild){ la_RebuildDriverEval(); }
  5679. if(MAIN.Drivers->NeedEval){ la_RunDrivers(); }
  5680. for (w=MAIN.Windows.pFirst;w;w = NextW){
  5681. NextW = w->Item.pNext;
  5682. if(!la_HandleEvents(w)){ laShutoff(); return; }
  5683. }
  5684. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  5685. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  5686. tnsSwitchToCurrentWindowContext(w);
  5687. la_DrawWindow(w);
  5688. }
  5689. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  5690. glXSwapBuffers(MAIN.dpy, w->win);
  5691. }
  5692. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  5693. //t2 = clock();
  5694. laRecordTime(&FrameEndTime);
  5695. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  5696. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  5697. if (Pause > 0){
  5698. int ms = Pause * 1000000.0;
  5699. usleep(ms);
  5700. }
  5701. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  5702. FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  5703. }
  5704. }