*/}}
1
0

la_kernel.c 277 KB

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