*/}}

la_kernel.c 267 KB

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