*/}}

la_kernel.c 284 KB

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