*/}}
1
0

la_kernel.c 282 KB

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