*/}}

la_kernel.c 277 KB

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