*/}}

la_kernel.c 243 KB

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