*/}}

la_kernel.c 230 KB

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