*/}}

la_kernel.c 262 KB

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