*/}}

la_kernel.c 276 KB

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