*/}}

la_kernel.c 302 KB

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