*/}}

la_kernel.c 227 KB

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