*/}}

la_kernel.c 302 KB

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