*/}}

la_kernel.c 289 KB

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