*/}}

la_kernel.c 226 KB

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