*/}}

la_kernel.c 226 KB

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