*/}}

la_kernel.c 335 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850
  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. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  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 LA_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. #include <shellscalingapi.h>
  49. #endif
  50. #ifdef LAGUI_ANDROID
  51. #include <GLES3/gl32.h>
  52. #include <jni.h>
  53. #include <android/log.h>
  54. #include <android/native_activity.h>
  55. #include <android/native_window.h>
  56. #include <android/native_window_jni.h>
  57. #include <android_native_app_glue.h>
  58. #include <android/window.h>
  59. #include <android/asset_manager.h>
  60. #include <android/input.h>
  61. #include <android/keycodes.h>
  62. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  63. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  64. static int android_read(void *cookie, char *buf, int size);
  65. static int android_write(void *cookie, const char *buf, int size);
  66. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  67. static int android_close(void *cookie);
  68. void la_InitAndroidPlatform(struct android_app *app);
  69. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  70. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  71. void la_InitAndroidPlatform(struct android_app *app);
  72. #endif
  73. LA MAIN={0};
  74. extern tnsMain *T;
  75. int deb = 0;
  76. laOperator *DEB;
  77. laColumn *DEBUG_C;
  78. #ifdef _WIN32
  79. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  80. #else
  81. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  82. #endif
  83. #ifdef LA_LINUX
  84. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  85. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  86. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  87. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  88. #endif
  89. #ifdef LA_LINUX
  90. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  91. int i;
  92. for (i = 0; i < num_classes; i++) {
  93. if (classes[i]->type == XIValuatorClass) {
  94. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  95. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  96. logPrint(" Range: %f - %f\n", v->min, v->max);
  97. logPrint(" Resolution: %d units/m\n", v->resolution);
  98. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  99. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  100. }
  101. }
  102. }
  103. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  104. XIDeviceInfo *info, *dev;
  105. int i, ndevices;
  106. dev = XIQueryDevice(display, deviceid, &ndevices);
  107. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  108. mask->deviceid = deviceid;
  109. mask->mask_len = XIMaskLen(XI_RawMotion);
  110. mask->mask=memAcquireSimple(mask->mask_len);
  111. memset(mask->mask, 0, mask->mask_len);
  112. XISetMask(mask->mask, XI_RawMotion);
  113. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  114. int FoundMax=0;
  115. for (i = 0; i < dev->num_classes; i++) {
  116. if (dev->classes[i]->type == XIValuatorClass) {
  117. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  118. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  119. }
  120. }
  121. if(!FoundMax){*max_pressure=65535;}
  122. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  123. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  124. XIFreeDeviceInfo(dev);
  125. }
  126. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  127. int axis=0;
  128. for (int i = 0; i < dev->num_classes; i++) {
  129. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  130. }
  131. return axis>=3;
  132. }
  133. #define LA_G_STYLUS(dev) \
  134. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  135. #define LA_G_ERASER \
  136. (!MAIN.WacomDeviceEraser)
  137. void la_ScanWacomDevices(Display *display, int deviceid){
  138. XIDeviceInfo *info, *dev;
  139. int ndevices;
  140. int i; char * word;
  141. int _event, _error;
  142. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  143. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  144. }
  145. info = XIQueryDevice(display, deviceid, &ndevices);
  146. for(i = 0; i < ndevices; i++) {
  147. dev = &info[i]; strToLower(dev->name);
  148. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  149. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  150. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  151. word = strtok (dev->name," ");
  152. while (1) {
  153. word = strtok (NULL, " "); if (!word) break;
  154. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  155. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  156. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  157. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  158. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  159. }
  160. }
  161. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  162. logPrintNew("Found wacom devices:\n");
  163. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  164. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  165. }else{
  166. logPrintNew("No wacom pen device connected.\n");
  167. }
  168. XIFreeDeviceInfo(info);
  169. }
  170. void laHideCursor(){
  171. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  172. }
  173. void laShowCursor(){
  174. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  175. }
  176. void la_XErrorHandler(Display *display, XErrorEvent *event){
  177. char buf[512];
  178. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  179. printf("X Error:\n%s\n",buf);
  180. }
  181. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  182. XSetWindowAttributes swa;
  183. XWindowAttributes wa;
  184. swa.event_mask =
  185. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  186. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  187. swa.colormap = MAIN.cmap;
  188. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  189. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  190. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  191. if(x>0||y>0){
  192. XSizeHints my_hints = {0};
  193. my_hints.flags = PPosition;
  194. my_hints.x = x; my_hints.y = y;
  195. XSetNormalHints(MAIN.dpy, win, &my_hints);
  196. }
  197. XStoreName(MAIN.dpy, win, title);
  198. #ifdef LA_USE_GLES
  199. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  200. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  201. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  202. EGLSurface* surf=egl_surf;
  203. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  204. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  205. tnsContextMakeCurrent((*r_glc),win,(*surf));
  206. #else
  207. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  208. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  209. printf("\n\tcannot create gl context\n\n"); exit(0);
  210. }
  211. tnsContextMakeCurrent((*r_glc),win,0);
  212. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  213. #endif
  214. XSetLocaleModifiers("");
  215. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  216. if(!MAIN.im){
  217. XSetLocaleModifiers("@im=local");
  218. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  219. }
  220. if(!MAIN.im){
  221. XSetLocaleModifiers("@im=none");
  222. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  223. }
  224. if(!MAIN.im){
  225. XSetLocaleModifiers("@im=");
  226. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  227. }
  228. if(!MAIN.im){
  229. logPrint("Can't open a input method.\n");
  230. }
  231. if(MAIN.im){
  232. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  233. XSetICFocus(MAIN.ic);
  234. }
  235. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  236. XSetClassHint(MAIN.dpy, win, &ch);
  237. #define _NET_WM_STATE_ADD 1
  238. if(w<0&&h<0){
  239. XEvent xev;
  240. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  241. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  242. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  243. memset(&xev, 0, sizeof(xev));
  244. xev.type = ClientMessage;
  245. xev.xclient.window = win;
  246. xev.xclient.message_type = wm_state;
  247. xev.xclient.format = 32;
  248. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  249. xev.xclient.data.l[1] = max_horz;
  250. xev.xclient.data.l[2] = max_vert;
  251. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  252. }
  253. return win;
  254. };
  255. void la_DestroySystemWindowX11(laWindow* w) {
  256. tnsContextMakeCurrent(0,0,0);
  257. tnsDeleteContext(w->glc);
  258. #ifdef LA_USE_GLES
  259. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  260. #endif
  261. XDestroyWindow(MAIN.dpy, w->win);
  262. };
  263. #endif //linux
  264. #ifdef _WIN32
  265. #include <msgdef.h>
  266. #include <wintab.h>
  267. #include <wintab_utils.h>
  268. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  269. #define PACKETMODE PK_BUTTONS
  270. #include <pktdef.h>
  271. void la_OpenWacomWinTab(HWND hwnd){
  272. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  273. static LOGCONTEXT glogContext = { 0 };
  274. HCTX hctx = NULL;
  275. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  276. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  277. glogContext.lcOptions |= CXO_SYSTEM;
  278. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  279. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  280. assert(glogContext.lcOptions & CXO_SYSTEM);
  281. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  282. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  283. glogContext.lcPktData = PACKETDATA;
  284. glogContext.lcPktMode = PACKETMODE;
  285. glogContext.lcMoveMask = PACKETDATA;
  286. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  290. assert(wWTInfoRetVal == sizeof(AXIS));
  291. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  292. if (wWTInfoRetVal) {
  293. assert(wWTInfoRetVal == sizeof(AXIS));
  294. MAIN.WinTabMaxHover = TabletZ.axMax;
  295. }
  296. AXIS tabletPressure = { 0 };
  297. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  298. //glogContext.lcInOrgX = 0;
  299. //glogContext.lcInOrgY = 0;
  300. //glogContext.lcInExtX = TabletX.axMax;
  301. //glogContext.lcInExtY = TabletY.axMax;
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  312. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  313. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  314. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  315. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  316. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  317. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  318. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  319. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  320. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  321. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  322. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  323. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  324. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  325. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  326. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  327. if (!hctx)return;
  328. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  329. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  330. }
  331. void laHideCursor() {
  332. if (!MAIN.CurrentWindow) return; //impl
  333. }
  334. void laShowCursor() {
  335. if (!MAIN.CurrentWindow) return; //impl
  336. }
  337. static PIXELFORMATDESCRIPTOR cpfd = {
  338. sizeof(PIXELFORMATDESCRIPTOR),1,
  339. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  340. PFD_TYPE_RGBA,
  341. 8,
  342. 0, 0, 0, 0, 0, 0,
  343. 0, 0, 0,
  344. 0, 0, 0, 0,
  345. 32,
  346. 8, 0,
  347. 0,
  348. 0, 0, 0, 0
  349. };
  350. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  351. int nBestMS = 0;
  352. int i;
  353. int iResults[9];
  354. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  355. WGL_ACCELERATION_ARB, // 1
  356. WGL_DRAW_TO_WINDOW_ARB, // 2
  357. WGL_DOUBLE_BUFFER_ARB, // 3
  358. WGL_PIXEL_TYPE_ARB, // 4
  359. WGL_DEPTH_BITS_ARB, // 5
  360. WGL_STENCIL_BITS_ARB, // 6
  361. WGL_SAMPLE_BUFFERS_ARB, // 7
  362. WGL_SAMPLES_ARB }; // 8
  363. // How many pixelformats are there?
  364. int nFormatCount[] = { 0 };
  365. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  366. if (!wglGetPixelFormatAttribivARB)
  367. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  368. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  369. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  370. for (i = 0; i < nFormatCount[0]; i++){
  371. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  372. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  373. if (iResults[3] == 1) // Double buffered
  374. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  375. if (iResults[5] >= 24) // Any Depth greater than 16
  376. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  377. }
  378. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  379. };
  380. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  381. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  382. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  383. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  384. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  385. 0 };
  386. HGLRC hglrc = 0;
  387. HDC hdc = 0;
  388. int a, b;
  389. hdc = GetDC(hwnd);
  390. la_SetupPxlFormat(hdc, &a, &b);
  391. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  392. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  393. tnsContextMakeCurrent(hglrc, hdc,0);
  394. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  395. wglSwapIntervalEXT(-1);
  396. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  397. };
  398. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  399. HINSTANCE* inst = &MAIN.hinstance;
  400. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  401. x, y, w, h, 0, 0, *inst, 0);
  402. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  403. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  404. return hwnd;
  405. };
  406. void la_DestroySystemWindowWin32(laWindow* w) {
  407. tnsContextMakeCurrent(0,0,0);
  408. tnsDeleteContext(w->glc);
  409. ReleaseDC(w->win, w->hdc);
  410. DestroyWindow(w->win);
  411. };
  412. #endif
  413. #ifdef LAGUI_ANDROID
  414. SYSWINDOW la_CreateWindowAndroid(){
  415. return 0;
  416. };
  417. void laShowCursor(){}
  418. void laHideCursor(){}
  419. #endif
  420. #ifdef LA_LINUX
  421. void la_HandlerSIGSEGV(int sig) {
  422. void *array[30];
  423. size_t sz;
  424. sz = backtrace(array, 30);
  425. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  426. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  427. exit(1);
  428. }
  429. #endif
  430. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  431. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  432. //#ifndef LAGUI_ANDROID
  433. // ignore non-significant error/warning codes
  434. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  435. logPrint("GL %d: %s\n", id, message);
  436. char* strsource="",*strtype="",*strseverity="";
  437. switch (source) {
  438. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  439. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  440. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  441. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  442. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  443. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  444. }
  445. switch (type) {
  446. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  447. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  448. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  449. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  450. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  451. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  452. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  453. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  454. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  455. }
  456. switch (severity) {
  457. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  458. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  459. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  460. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  461. }
  462. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  463. //#endif
  464. }
  465. void la_SetCurrentGLContextDebug(){
  466. //#ifndef LAGUI_ANDROID
  467. int force=MAIN.InitArgs.GLDebug;
  468. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  469. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  470. glDebugMessageCallback(la_glDebugOutput, 0);
  471. int sev=GL_DONT_CARE;
  472. if(!force){
  473. switch(MAIN.GLDebugLevel){
  474. default: sev=GL_DONT_CARE; break;
  475. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  476. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  477. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  478. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  479. }
  480. }
  481. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  482. //#endif
  483. }
  484. void la_NotifyGLDebugChanges(){
  485. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  486. }
  487. void la_SetupWindowGLStates(laWindow* w){
  488. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  489. if(w->GLDebugNeedsUpdate){
  490. tnsContextMakeWindowCurrent(w);
  491. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  492. }
  493. }
  494. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  495. SYSGLCONTEXT glc;
  496. #ifdef LA_LINUX
  497. void* egl_surf=0;
  498. #ifdef LA_USE_GLES
  499. egl_surf=&window->egl_surf;
  500. #endif
  501. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  502. #endif
  503. #ifdef _WIN32
  504. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  505. #endif
  506. #ifdef LAGUI_ANDROID
  507. la_CreateWindowAndroid();
  508. window->win = 1;
  509. window->glc = MAIN.glc;
  510. #else
  511. window->win = hwnd;
  512. window->glc = glc;
  513. #endif
  514. #ifdef _WIN32
  515. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  516. RECT rc; GetClientRect(window->win, &rc);
  517. window->CW = rc.right - rc.left;
  518. window->CH = rc.bottom - rc.top;
  519. #endif
  520. #ifdef LA_LINUX
  521. XWindowAttributes attr;
  522. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  523. window->CW =attr.width;
  524. window->CH = attr.height;
  525. #endif
  526. la_SetCurrentGLContextDebug();
  527. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  528. la_SetupWindowGLStates(window);
  529. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  530. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #else
  532. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  533. #endif
  534. window->OutputShowStripes=1; window->Redraw=1;
  535. window->GLDebugNeedsUpdate=1;
  536. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  537. return 1;
  538. };
  539. int la_DestroySystemWindow(laWindow* wnd){
  540. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  541. nvgDeleteGLES3(wnd->nvg);
  542. #else
  543. nvgDeleteGL3(wnd->nvg);
  544. #endif
  545. #ifdef LA_LINUX
  546. la_DestroySystemWindowX11(wnd);
  547. #endif
  548. #ifdef _WIN32
  549. la_DestroySystemWindowWin32(wnd);
  550. #endif
  551. }
  552. void la_DestroyWindow(laWindow *wnd){
  553. laLayout *l; laPanel *p; if (!wnd) return;
  554. tnsSwitchToCurrentWindowContext(wnd);
  555. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  556. la_StopAllOperators();
  557. strSafeDestroy(&wnd->Title);
  558. //la_PrintUserList(wnd);
  559. //printf("----\n");
  560. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  561. while (l = lstPopItem(&wnd->Layouts)){
  562. laDestroyBlocksRecursive(l->FirstBlock);
  563. //la_PrintUserList(l);
  564. //printf("%x %s\n", l, l->ID->Ptr);
  565. strSafeDestroy(&l->ID);
  566. memFree(l);
  567. //la_PrintUserList(wnd);
  568. //printf("----\n");
  569. }
  570. //printf("----\n%x\n",wnd);
  571. //la_PrintUserList(wnd);
  572. la_DestroySystemWindow(wnd);
  573. lstRemoveItem(&MAIN.Windows, wnd);
  574. memFree(wnd);
  575. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  576. }
  577. void laRenameWindow(laWindow* wnd, char* name){
  578. if((!wnd)||MAIN.IsReadingUDF) return;
  579. strSafeSet(&wnd->Title, name);
  580. if(!wnd->win) return;
  581. #ifdef LA_LINUX
  582. XStoreName(MAIN.dpy, wnd->win, name);
  583. #endif
  584. #ifdef _WIN32
  585. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  586. SetWindowTextW(wnd->win, name);
  587. #endif
  588. }
  589. #ifdef LA_LINUX
  590. const char* la_ConvertCursorID(int id){
  591. switch (id) {
  592. case LA_ARROW: return "arrow";
  593. case LA_CROSS: return "cross";
  594. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  595. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  596. case LA_MOVE: return "diamond_cross";
  597. case LA_HAND: return "hand1";
  598. case LA_CORNER: return "bottom_right_corner";
  599. }
  600. return "arrow";
  601. }
  602. #endif
  603. #ifdef _WIN32
  604. HCURSOR la_ConvertCursorID(int id){
  605. switch (id){
  606. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  607. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  608. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  609. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  610. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  611. case LA_HAND: return LoadCursor(0, IDC_HAND);
  612. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  613. }
  614. return LoadCursor(0, IDC_ARROW);;
  615. }
  616. #endif
  617. void la_InitThreadEnviornment(){
  618. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  619. }
  620. laLogEntry* logEnsure(int Create){
  621. if(!MAIN.Logs.pFirst || Create){
  622. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  623. lstAppendItem(&MAIN.Logs, le);
  624. }
  625. return MAIN.Logs.pLast;
  626. }
  627. void logPrintTV(int Continued, char* format, va_list v){
  628. if(!format || !format[0]) return;
  629. laLogEntry* le=logEnsure(Continued);
  630. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  631. strSafePrintV(&le->Content, format, v);
  632. #ifdef LAGUI_ANDROID
  633. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  634. #endif
  635. laNotifyUsers("la.logs");
  636. }
  637. void logPrintT(int Continued, char* format, ...){
  638. if(!format || !format[0]) return;
  639. laLogEntry* le=logEnsure(Continued);
  640. va_list aptr; va_start(aptr, format);
  641. strSafePrint(&le->Content, format, aptr);
  642. va_end(aptr);
  643. #ifdef LAGUI_ANDROID
  644. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  645. #endif
  646. laNotifyUsers("la.logs");
  647. }
  648. void logPrint(char* format, ...){
  649. va_list aptr; va_start(aptr, format);
  650. logPrintTV(0, format, aptr);
  651. va_end(aptr);
  652. }
  653. void logPrintNew(char* format, ...){
  654. logEnsure(1);
  655. va_list aptr; va_start(aptr, format);
  656. logPrintTV(0, format, aptr);
  657. va_end(aptr);
  658. }
  659. void logClear(){
  660. laLogEntry*l;
  661. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  662. laNotifyUsers("la.logs");
  663. }
  664. laScreen* la_EnsureScreen(char* Name, int mmw, int mmh, int x, int y, int w, int h,int dpi){ if(!Name || !Name[0]) return 0;
  665. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  666. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  667. }
  668. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  669. strSafeSet(&s->Name,Name);
  670. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  671. s->x=x;s->y=y;s->w=w;s->h=h;
  672. laNotifyUsers("la.user_preferences.screens");
  673. return s;
  674. }
  675. void la_RemoveScreen(laScreen*s){
  676. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  677. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  678. }
  679. void la_RemoveDuplicatedScreenConf(){
  680. laScreen* NextS;
  681. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  682. NextS = s->Item.pNext;
  683. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  684. if(strSame(SSTR(fs->Name),SSTR(s->Name))){ fs->x=s->x;fs->y=s->y;fs->w=s->w;fs->h=s->h; la_RemoveScreen(s); break; }
  685. }
  686. }
  687. }
  688. laScreen* laGetWindowScreen(laWindow* w){
  689. int l,r,u,b; int area=-1; laScreen* maxs=0;
  690. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  691. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  692. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  693. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  694. int a=w*h; if(a>area){ maxs = s; area = a; }
  695. }
  696. return maxs;
  697. }
  698. #ifdef LA_LINUX
  699. int la_GetDPI(Window* root_win){
  700. XRRScreenResources *screen;
  701. XRROutputInfo *info;
  702. XRRCrtcInfo *crtc_info;
  703. XRRCrtcInfo *crtc;
  704. int iscres, icrtc, dpi=0;
  705. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  706. for(iscres=0;iscres<screen->noutput;iscres++){
  707. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  708. if(!info->mm_width || !info->mm_height){ continue; }
  709. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  710. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  711. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  712. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  713. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  714. XRRFreeCrtcInfo(crtc);
  715. //if(info->connection==RR_Connected){
  716. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  717. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  718. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  719. // XRRFreeCrtcInfo(crtc_info);
  720. // }
  721. //}
  722. XRRFreeOutputInfo(info);
  723. }
  724. XRRFreeScreenResources(screen);
  725. return dpi;
  726. }
  727. #endif
  728. #ifdef _WIN32
  729. typedef struct laWin32MonitorEnumData {
  730. int id;
  731. }laWin32MonitorEnumData;
  732. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  733. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  734. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  735. return TRUE;
  736. }
  737. int la_GetDPI(HWND win){
  738. laWin32MonitorEnumData data = { 0 };
  739. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  740. return GetDpiForWindow(win);
  741. return 144;
  742. }
  743. #endif
  744. #define PROGRESSW (LA_RH*15)
  745. void laShowProgress(real p1, real p2){
  746. laSpinLock(&MAIN.OpsLock);
  747. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  748. if(!MAIN.Progress.Called){
  749. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  750. }else{
  751. laTimeRecorder tm; laRecordTime(&tm);
  752. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  753. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  754. if(!MAIN.Progress.Shown){
  755. int ww=PROGRESSW+LA_RH*2;
  756. #ifdef LA_LINUX
  757. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  758. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  759. long a=LA_COLOR3_TO_HEX(bg);
  760. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  761. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  762. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  763. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  764. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  765. #endif
  766. #ifdef _WIN32
  767. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  768. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  769. ShowWindow(MAIN.Progress.w,SW_SHOW);
  770. #endif
  771. MAIN.Progress.Shown = 1;
  772. }
  773. }
  774. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  775. #ifdef LA_LINUX
  776. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  777. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  778. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  779. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  780. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  781. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  782. #endif
  783. #ifdef _WIN32
  784. InvalidateRect(MAIN.Progress.w,0,1);
  785. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  786. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  787. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  788. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  789. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  790. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  791. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  792. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  793. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  794. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  795. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  796. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  797. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  798. EndPaint(MAIN.Progress.w,&ps);
  799. MSG msg;
  800. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  801. #endif
  802. laSpinUnlock(&MAIN.OpsLock);
  803. }
  804. void laHideProgress(){
  805. laSpinLock(&MAIN.OpsLock);
  806. if(!MAIN.Progress.Shown){
  807. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  808. }
  809. laTimeRecorder tm; laRecordTime(&tm);
  810. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  811. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  812. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  813. #ifdef LA_LINUX
  814. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  815. #endif
  816. #ifdef _WIN32
  817. ShowWindow(MAIN.Progress.w,SW_HIDE);
  818. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  819. #endif
  820. laSpinUnlock(&MAIN.OpsLock);
  821. }
  822. //=======================
  823. void la_InitProgressWindow(){
  824. #ifdef LA_LINUX
  825. 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));
  826. if(!MAIN.Progress.w) return;
  827. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  828. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  829. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  830. if(MAIN.Progress.gc<0) return;
  831. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  832. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  833. XSync(MAIN.dpy,0);
  834. #endif
  835. #ifdef _WIN32
  836. WNDCLASSW wc;
  837. wc.hInstance = MAIN.hinstance;
  838. wc.lpfnWndProc = LA_ProgressWindowProc;
  839. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  840. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  841. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  842. wc.cbWndExtra = 0;
  843. wc.cbClsExtra = 0;
  844. wc.lpszClassName = L"_LAGUIPROGRESS";
  845. wc.lpszMenuName = NULL;
  846. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  847. if (!RegisterClassW(&wc)){ return; }
  848. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  849. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  850. #endif
  851. }
  852. void laSetFontFolderPath(char* absolute){
  853. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  854. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  855. }
  856. void laSetDefaultInitArguments(laInitArguments* ia){
  857. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  858. ia->UseColorManagement=0;
  859. ia->HasWorldObjects=0;
  860. ia->HasAction=0;
  861. ia->HasTextureInspector=0;
  862. ia->HasHistories=0;
  863. ia->HasTerminal=1;
  864. ia->HasAudio=0;
  865. }
  866. void laSetCompleteInitArguments(laInitArguments* ia){
  867. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  868. ia->UseColorManagement=1;
  869. ia->HasWorldObjects=1;
  870. ia->HasAction=1;
  871. ia->HasTextureInspector=1;
  872. ia->HasHistories=1;
  873. ia->HasTerminal=1;
  874. ia->HasAudio=1;
  875. }
  876. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  877. MAIN.GLMajor=MAIN.GLMinor=-1;
  878. char* arg = 0;
  879. printf("Initializing LaGUI...\n",argc);
  880. for(int i=0;i<argc;i++){
  881. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  882. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  883. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  884. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  885. }
  886. continue;
  887. }
  888. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  889. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  890. }
  891. }
  892. int laGetReadyWith(laInitArguments* ia){
  893. #ifdef LA_LINUX
  894. //signal(SIGSEGV,la_HandlerSIGSEGV);
  895. #endif
  896. laSpinInit(&MAIN.MemLock);
  897. laSpinInit(&MAIN.OpsLock);
  898. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  899. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  900. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  901. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  902. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  903. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  904. tnsInit();
  905. #ifdef LA_LINUX
  906. SYSWINDOW root, win;
  907. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  908. XSetWindowAttributes swa={0};
  909. XWindowAttributes wa={0};
  910. XEvent xev;
  911. logPrintNew("Initializing LaGUI...\n");
  912. setlocale(LC_CTYPE, "zh_CN.utf8");
  913. XSetErrorHandler(la_XErrorHandler);
  914. int i;
  915. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  916. printf("\n\tcannot connect to x server\n\n");
  917. exit(0);
  918. }
  919. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  920. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  921. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  922. #ifdef LA_USE_GLES
  923. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  924. #else
  925. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  926. #endif
  927. #ifdef LA_USE_GLES
  928. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  929. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  930. EGLint egl_major, egl_minor;
  931. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  932. printf("Error: eglInitialize() failed\n"); return -1;
  933. }
  934. int scrnum;
  935. XSetWindowAttributes attr;
  936. XVisualInfo *visInfo, visTemplate;
  937. int num_visuals;
  938. EGLContext ctx;
  939. EGLint num_configs;
  940. EGLint vid;
  941. static const EGLint attribs[] = {
  942. EGL_RED_SIZE, 8,
  943. EGL_GREEN_SIZE, 8,
  944. EGL_BLUE_SIZE, 8,
  945. EGL_DEPTH_SIZE, 1,
  946. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  947. EGL_NONE
  948. };
  949. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  950. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  951. }
  952. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  953. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  954. }
  955. visTemplate.visualid = vid;
  956. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  957. if (!visInfo) {
  958. printf("Error: couldn't get X visual\n"); exit(1);
  959. }
  960. MAIN.xvi=visInfo;
  961. root = DefaultRootWindow(MAIN.dpy);
  962. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  963. printf("\n\tcannot create colormap\n\n"); exit(1);
  964. }
  965. eglBindAPI(EGL_OPENGL_ES_API);
  966. EGLint ctx_attribs[] = {
  967. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  968. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  969. EGL_NONE
  970. };
  971. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  972. if (!MAIN.glc) {
  973. printf("Error: eglCreateContext failed\n"); exit(1);
  974. }
  975. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  976. #else
  977. int visual_attribs[] = {
  978. GLX_X_RENDERABLE , True,
  979. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  980. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  981. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  982. GLX_RED_SIZE , 8,
  983. GLX_GREEN_SIZE , 8,
  984. GLX_BLUE_SIZE , 8,
  985. GLX_ALPHA_SIZE , 8,
  986. GLX_DEPTH_SIZE , 24,
  987. //GLX_STENCIL_SIZE , 8,
  988. GLX_DOUBLEBUFFER , True,
  989. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  990. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  991. None
  992. };
  993. int fbcount = -1;
  994. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  995. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  996. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  997. MAIN.BestFBC = fbconfig[0];
  998. int sample_buf,samples;
  999. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  1000. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  1001. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1002. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1003. free(fbconfig);
  1004. root = DefaultRootWindow(MAIN.dpy);
  1005. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1006. printf("\n\tcannot create colormap\n\n"); exit(0);
  1007. }
  1008. swa.colormap = MAIN.cmap;
  1009. root = DefaultRootWindow(MAIN.dpy);
  1010. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1011. MAIN.win=win;
  1012. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1013. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1014. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1015. printf("\n\tcannot create gl context\n\n"); exit(0);
  1016. }
  1017. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1018. tnsContextMakeCurrent(MAIN.glc,win,0);
  1019. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1020. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1021. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1022. int err=0;
  1023. if((err=glewInit())!=GLEW_OK){
  1024. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1025. };
  1026. #endif /* gles or glx */
  1027. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1028. la_SetCurrentGLContextDebug();
  1029. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1030. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1031. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1032. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1033. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1034. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1035. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1036. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1037. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1038. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1039. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1040. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1041. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1042. #endif //linux
  1043. #ifdef _WIN32
  1044. logPrintNew("Initializing LaGUI...\n");
  1045. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1046. setlocale(LC_ALL, "zh_CN.utf8");
  1047. MAIN.hinstance = GetModuleHandle(NULL);
  1048. HINSTANCE* hInst = &MAIN.hinstance;
  1049. WNDCLASSEXW wt;
  1050. wt.cbSize = sizeof(WNDCLASSEXW);
  1051. wt.cbClsExtra = 0;
  1052. wt.cbWndExtra = 0;
  1053. wt.hbrBackground = 0;
  1054. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1055. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1056. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1057. wt.hInstance = *hInst;
  1058. wt.lpfnWndProc = LA_WindowProc;
  1059. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1060. wt.lpszMenuName = 0;
  1061. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1062. if (!RegisterClassExW(&wt)) return 0;
  1063. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1064. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1065. SetProcessDPIAware();
  1066. GLenum err;
  1067. PIXELFORMATDESCRIPTOR pfd;
  1068. HINSTANCE* hinst = &MAIN.hinstance;
  1069. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1070. "Temp Window For Accessing GLEW!",
  1071. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1072. 0, 0, *hinst, 0);
  1073. HDC hdc = GetDC(hwnd);
  1074. HGLRC hglrc = 0;
  1075. SetPixelFormat(hdc, 1, &cpfd);
  1076. hglrc = wglCreateContext(hdc);
  1077. tnsContextMakeCurrent(hglrc, hdc,0);
  1078. //MAIN.hdc = hdc;
  1079. // MAIN.tWND = hwnd;
  1080. MAIN.glc = hglrc;
  1081. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1082. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1083. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1084. if (err = glewInit()) {
  1085. printf("Init Glew Failed\n");
  1086. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1087. return 0;
  1088. }
  1089. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1090. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1091. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1092. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1093. #endif
  1094. la_GetWorkingDirectoryInternal();
  1095. MAIN.SavePreferenceOnExit=1;
  1096. MAIN.FontSize = 0.6;
  1097. int dpi=64;
  1098. #ifdef _WIN32
  1099. dpi=la_GetDPI(hwnd);
  1100. #endif
  1101. #ifdef LA_LINUX
  1102. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1103. #endif
  1104. #ifdef LAGUI_ANDROID
  1105. dpi = 144;
  1106. #endif
  1107. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1108. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1109. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1110. MAIN.UiScale=1;
  1111. MAIN.MarginSize = 1;
  1112. MAIN.ColorPickerGamma=1.5;
  1113. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1114. MAIN.ViewportHalftoneFactor=0.5;
  1115. MAIN.ViewportHalftoneSize=3.7;
  1116. tnsInitRenderKernel(64);
  1117. tnsInitBuiltinShaders();
  1118. tnsSetuptnsFontManager();
  1119. #define LOAD_FONT(font) \
  1120. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1121. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1122. LOAD_FONT("NotoEmoji-Regular.ttf");
  1123. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1124. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1125. //LOAD_FONT("NotoMusic-Regular.ttf");
  1126. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1127. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1128. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1129. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1130. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1131. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1132. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1133. MAIN.Audio=memAcquire(sizeof(laAudio));
  1134. #ifdef LA_WITH_LUAJIT
  1135. // starting lua
  1136. logPrint("Starting luajit...\n");
  1137. MAIN.L = lua_open();
  1138. la_luaLoadLibs(MAIN.L);
  1139. la_luaPrintStatus(MAIN.L);
  1140. tnsLuaInit(MAIN.L);
  1141. #endif
  1142. //interactions:
  1143. MAIN.TopFramerate = 60;
  1144. MAIN.ValuatorThreshold = 8;
  1145. MAIN.ScrollingSpeed = 3;
  1146. MAIN.AnimationSpeed = 0.4;
  1147. MAIN.PanelAnimationSpeed = 0.4;
  1148. MAIN.ZoomSpeed2D = 0.01;
  1149. MAIN.IdleTime = 0.75;
  1150. MAIN.TooltipCloseDistance = 30;
  1151. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1152. //display:
  1153. MAIN.FloatingAlpha = 0.35;
  1154. MAIN.SolidShadowLength = 20;
  1155. MAIN.WireColorSlices = 16;
  1156. MAIN.WireThickness = 5;
  1157. MAIN.WireSaggyness = 0.5;
  1158. #ifdef LAGUI_ANDROID
  1159. laAddResourceFolder("");
  1160. #else
  1161. laAddResourceFolder(".");
  1162. #endif
  1163. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1164. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1165. la_InitProgressWindow();
  1166. la_MakeTranslations_es_ES();
  1167. la_MakeTranslations_zh_hans();
  1168. //tns_RegisterResourcesForSoftwareRender();
  1169. la_RegisterDefaultSignals();
  1170. la_RegisterGeneralProps();
  1171. la_RegisterBuiltinTemplates();
  1172. la_RegisterMainThemes();
  1173. la_RegisterMainOperators();
  1174. la_RegisterMainUiTypes();
  1175. la_RegisterModellingOperators();
  1176. la_RegisterShapeOperators();
  1177. la_RegisterInternalProps();
  1178. la_RegisterAnimationResources();
  1179. la_RegisterWindowKeys();
  1180. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1181. laFinalizeUiTemplates();
  1182. laFinalizeOperators();
  1183. la_RegisterControllerProps();
  1184. la_RefreshControllers();
  1185. la_RegisterBasicNodes();
  1186. tns_RegisterNodes();
  1187. la_InitThreadEnviornment();
  1188. laSetRootInstance(&MAIN);
  1189. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1190. laPushDifferences(0, 0);
  1191. la_MakeDummyManagedUDF();
  1192. la_RegenerateWireColors();
  1193. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1194. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1195. logPrintNew("Initialization Completed\n");
  1196. MAIN.InitDone=1;
  1197. return 1;
  1198. }
  1199. int laGetReady(){
  1200. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1201. return laGetReadyWith(&ia);
  1202. }
  1203. void la_DestroyUiType(laUiType* uit);
  1204. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1205. void laShutoff(int SavePrefereces){
  1206. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1207. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1208. // transLate(pc->Description);
  1209. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1210. // transLate(p->Description);
  1211. // }
  1212. //}
  1213. transDumpMissMatchRecord("TranslationDump.txt");
  1214. if(MAIN.Cleanup) MAIN.Cleanup();
  1215. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1216. strSafeDestroy(&MAIN.WorkingDirectory);
  1217. strSafeDestroy(&MAIN.example_string);
  1218. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1219. // (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. )
  1220. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1221. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1222. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1223. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1224. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1225. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1226. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1227. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1228. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1229. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1230. strSafeDestroy(&MAIN.CopyPending);
  1231. la_ClearUDFRegistryAndFolders();
  1232. laClearManagedUDF();
  1233. laClearSaveProp();
  1234. logClear();
  1235. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1236. #ifdef LA_LINUX
  1237. tnsContextMakeCurrent(0,0,0);
  1238. tnsDeleteContext(MAIN.glc);
  1239. #ifdef LA_USE_GLES
  1240. eglTerminate(MAIN.egl_dpy);
  1241. #endif
  1242. #endif
  1243. #ifdef _WIN32
  1244. tnsContextMakeCurrent(0,0,0);
  1245. tnsDeleteContext(MAIN.glc);
  1246. UnloadWintab();
  1247. #endif
  1248. tnsQuit();
  1249. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1250. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1251. strSafeDump();
  1252. hshFree(&MAIN.DBInstMemLeft);
  1253. memNoLonger();
  1254. laSpinDestroy(&MAIN.MemLock);
  1255. laSpinDestroy(&MAIN.OpsLock);
  1256. #ifdef LA_WITH_LUAJIT
  1257. lua_close(MAIN.L);
  1258. #endif
  1259. printf("LaGUI has cleaned up.\n");
  1260. }
  1261. int laRestoreFactorySettings(){
  1262. char path[1024];
  1263. #ifdef LAGUI_ANDROID
  1264. sprintf(path,"%s","preferences.udf");
  1265. #else
  1266. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1267. #endif
  1268. if(remove(path)){ return 0; }
  1269. return 1;
  1270. }
  1271. void laSaveUserPreferences(){
  1272. char path[1024];
  1273. #ifdef LAGUI_ANDROID
  1274. sprintf(path,"%s","preferences.udf");
  1275. #else
  1276. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1277. #endif
  1278. laUDF* udf=laPrepareUDF(path);
  1279. laWriteProp(udf,"la.windows");
  1280. laWriteProp(udf,"la.user_preferences");
  1281. laWriteProp(udf,"la.input_mapping");
  1282. laWriteProp(udf,"la.controllers");
  1283. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1284. laWriteProp(udf,lip->p);
  1285. }
  1286. laPackUDF(udf,0,0);
  1287. }
  1288. void laEnsureUserPreferences(){
  1289. char path[1024];
  1290. #ifdef LAGUI_ANDROID
  1291. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1292. #else
  1293. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1294. #endif
  1295. laUDFRegistry* r=laFindUDFRegistry(path);
  1296. if(!r){ laSaveUserPreferences(); return; }
  1297. laUDF* udf=laOpenUDF(SSTR(r->Path),1,0,0); if(!udf){ logPrint("Can't read preferences on %s. Using default settings.",SSTR(r->Path)); return; }
  1298. laClearUDFRegistries();
  1299. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1300. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1301. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1302. laCloseUDF(udf);
  1303. la_RemoveDuplicatedScreenConf();
  1304. la_RemoveDuplicatedControllers();
  1305. laRefreshUDFRegistries();
  1306. //restore forced settings
  1307. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1308. }
  1309. void laAddExtraExtension(int FileType, ...){
  1310. va_list list; va_start(list,FileType);
  1311. char* ext;
  1312. while(ext=va_arg(list,char*)){ if(!ext) break;
  1313. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1314. et->FileType=FileType; et->Extension=ext;
  1315. lstAppendItem(&MAIN.ExtraExtensions, et);
  1316. logPrintNew("add ext %s",ext);
  1317. }
  1318. va_end(list);
  1319. }
  1320. void laAddExtraPreferencePath(const char* path){
  1321. if(!path) return;
  1322. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1323. }
  1324. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1325. if(!name || !Func) return;
  1326. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1327. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1328. }
  1329. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1330. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1331. }
  1332. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1333. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1334. }
  1335. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1336. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1337. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1338. }
  1339. void la_InputMappingGetKeyName(int key, int special, char* name){
  1340. char *_next=name; name[0]=0;
  1341. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1342. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1343. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1344. switch(key){
  1345. case ' ': strcat(name,"Space"); break;
  1346. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1347. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1348. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1349. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1350. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1351. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1352. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1353. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1354. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1355. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1356. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1357. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1358. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1359. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1360. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1361. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1362. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1363. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1364. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1365. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1366. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1367. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1368. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1369. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1370. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1371. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1372. case LA_KEY_F1: strcat(name,"F1"); break;
  1373. case LA_KEY_F2: strcat(name,"F2"); break;
  1374. case LA_KEY_F3: strcat(name,"F3"); break;
  1375. case LA_KEY_F4: strcat(name,"F4"); break;
  1376. case LA_KEY_F5: strcat(name,"F5"); break;
  1377. case LA_KEY_F6: strcat(name,"F6"); break;
  1378. case LA_KEY_F7: strcat(name,"F7"); break;
  1379. case LA_KEY_F8: strcat(name,"F8"); break;
  1380. case LA_KEY_F9: strcat(name,"F9"); break;
  1381. case LA_KEY_F10: strcat(name,"F10"); break;
  1382. case LA_KEY_F11: strcat(name,"F11"); break;
  1383. case LA_KEY_F12: strcat(name,"F12"); break;
  1384. default:
  1385. name = name+strlen(name); _next=name;
  1386. laToUTF8(key,name,&_next); *_next=0; break;
  1387. }
  1388. }
  1389. int la_InputMappingGetKeyFromName(char* name, int* special){
  1390. if(!name ||name[0]==0){ *special=0; return 0; }
  1391. *special=0;
  1392. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1393. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1394. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1395. char* p=name+strlen(name)-1;
  1396. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1397. while(*p=='+' || *p==' '){ p++; }
  1398. if(strSame(p,"Space")) return ' ';
  1399. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1400. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1401. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1402. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1403. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1404. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1405. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1406. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1407. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1408. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1409. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1410. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1411. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1412. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1413. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1414. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1415. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1416. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1417. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1418. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1419. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1420. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1421. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1422. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1423. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1424. if(strSame(p,"F1")) return LA_KEY_F1;
  1425. if(strSame(p,"F2")) return LA_KEY_F2;
  1426. if(strSame(p,"F3")) return LA_KEY_F3;
  1427. if(strSame(p,"F4")) return LA_KEY_F4;
  1428. if(strSame(p,"F5")) return LA_KEY_F5;
  1429. if(strSame(p,"F6")) return LA_KEY_F6;
  1430. if(strSame(p,"F7")) return LA_KEY_F7;
  1431. if(strSame(p,"F8")) return LA_KEY_F8;
  1432. if(strSame(p,"F9")) return LA_KEY_F9;
  1433. if(strSame(p,"F10")) return LA_KEY_F10;
  1434. if(strSame(p,"F11")) return LA_KEY_F11;
  1435. if(strSame(p,"F12")) return LA_KEY_F12;
  1436. int adv;
  1437. return laToUnicode(p,&adv);
  1438. }
  1439. laCustomSignal* laFindSignal(char* Name){
  1440. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1441. return 0;
  1442. }
  1443. laCustomSignal* laFindSignalByID(int ID){
  1444. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1445. return 0;
  1446. }
  1447. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1448. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1449. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1450. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1451. char* signal = SSTR(ime->Signal);
  1452. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1453. }
  1454. laInputMapping* laNewInputMapping(char* Name){
  1455. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1456. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1457. strSafeSet(&im->Name,Name);
  1458. return im;
  1459. }
  1460. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1461. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1462. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1463. memAssignRef(e,&e->Parent,im);
  1464. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1465. laInputMappingUpdateSignal(e);
  1466. e->SpecialKeyBits=SpecialKeyBit;
  1467. char buf[64],*_next=buf;
  1468. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1469. }
  1470. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1471. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1472. laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1473. }
  1474. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1475. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1476. }
  1477. void laRemoveInputMapping(laInputMapping* im){
  1478. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1479. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1480. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1481. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1482. }
  1483. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1484. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1485. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1486. return cs;
  1487. }
  1488. void laRemoveCustomSignal(laCustomSignal* cs){
  1489. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1490. }
  1491. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1492. void la_SendSignalsFromEvent(laEvent* e){
  1493. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1494. if(!im){return;}
  1495. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1496. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1497. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1498. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1499. }
  1500. }
  1501. }
  1502. }
  1503. //MSG====================================================
  1504. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1505. if (wnd->win == hwnd) return 1;
  1506. else return 0;
  1507. };
  1508. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1509. if (p->SL){ int s=p->SL<0?0:p->SL;
  1510. if (p->TX != s) laRecalcPanel(p);
  1511. p->TX = s;
  1512. }
  1513. if (p->SR){ int s=p->SR<0?0:p->SR;
  1514. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1515. p->TW = CW - p->TX - s;
  1516. }
  1517. if (p->ST){ int s=p->ST<0?0:p->ST;
  1518. if (p->TY != s) laRecalcPanel(p);
  1519. p->TY = s;
  1520. }
  1521. if (p->SB){ int s=p->SB<0?0:p->SB;
  1522. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1523. p->TH = CH - p->TY - s;
  1524. }
  1525. }
  1526. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1527. laPanel *p = 0;
  1528. b->X = X;
  1529. b->Y = Y;
  1530. b->W = W;
  1531. b->H = H;
  1532. if (b->B1){
  1533. int SplitWidth;
  1534. if (b->Vertical){
  1535. SplitWidth = H * b->SplitRatio;
  1536. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1537. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1538. }else{
  1539. SplitWidth = W * b->SplitRatio;
  1540. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1541. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1542. }
  1543. }
  1544. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1545. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1546. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1547. }
  1548. if (p = b->CurrentPanel){
  1549. int TitleGap=b->Folded?0:LA_RH;
  1550. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1551. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1552. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1553. laRecalcPanel(p);
  1554. }
  1555. }
  1556. void la_UpdateUiPlacement(laWindow *w){
  1557. laLayout *l;
  1558. laPanel *p;
  1559. int CW = w->CW;
  1560. int CH = w->CH;
  1561. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1562. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1563. if(w->MaximizedUi && w->MaximizedUiPanel){
  1564. laRecalcPanel(w->MaximizedUiPanel);
  1565. }elif(w->MaximizedBlock){
  1566. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1567. }else{
  1568. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1569. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1570. }
  1571. }
  1572. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1573. if(p->IsMenuPanel){
  1574. p->TH=p->H=MenuHeight;
  1575. }
  1576. la_EnsurePanelSnapping(p, CW, CH);
  1577. laRecalcPanel(p);
  1578. }
  1579. }
  1580. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1581. laWindow *window;
  1582. #ifdef LAGUI_ANDROID
  1583. window = MAIN.Windows.pFirst; if (!window) return;
  1584. window->X=x;window->Y=y;window->W=w;window->H=h;
  1585. window->CW=w;window->CH=h;
  1586. la_UpdateUiPlacement(window); return;
  1587. #endif
  1588. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1589. if (!window) return;
  1590. #ifdef _WIN32
  1591. RECT rcc; GetClientRect(window->win, &rcc);
  1592. RECT rcw; GetWindowRect(window->win, &rcw);
  1593. window->CW = rcc.right - rcc.left;
  1594. window->CH = rcc.bottom - rcc.top;
  1595. window->W = rcw.right - rcw.left;
  1596. window->H = rcw.bottom - rcw.top;
  1597. window->X = rcw.left; window->Y = rcw.top;
  1598. if (MAIN.AutoSwitchColorSpace) {
  1599. laScreen* s = laGetWindowScreen(window);
  1600. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1601. }
  1602. #endif
  1603. #ifdef LA_LINUX
  1604. XWindowAttributes attr;
  1605. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1606. window->CW = w; window->CH = h;
  1607. window->W = w; window->H = h;
  1608. window->X = x; window->Y = y;
  1609. if(MAIN.AutoSwitchColorSpace){
  1610. laScreen* s = laGetWindowScreen(window);
  1611. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1612. }
  1613. #endif
  1614. la_UpdateUiPlacement(window);
  1615. }
  1616. int la_OnWindowDestroy(SYSWINDOW wnd){
  1617. laListHandle *hlst = &MAIN.Windows;
  1618. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1619. if (!w) return 0;
  1620. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1621. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1622. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1623. laShutoff(1);
  1624. return 1;
  1625. }
  1626. laListHandle h={0};laLayout*l=0;
  1627. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1628. la_DestroyWindow(w);
  1629. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1630. #ifdef LA_LINUX
  1631. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1632. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1633. #endif
  1634. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1635. }
  1636. return 0;
  1637. }
  1638. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1639. laListHandle *el = &wnd->EventList;
  1640. laEvent* last_e=el->pLast;
  1641. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1642. #ifdef LA_LINUX
  1643. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1644. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1645. #endif
  1646. #ifdef _WIN32
  1647. 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);
  1648. #endif
  1649. }
  1650. void laMappingRequestEval();
  1651. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1652. laListHandle *wl = &MAIN.Windows;
  1653. laWindow* wnd;
  1654. #ifdef LAGUI_ANDROID
  1655. wnd = MAIN.Windows.pFirst;
  1656. #else
  1657. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1658. #endif
  1659. if (!wnd){ memFree(e); return; }
  1660. laListHandle *el = &wnd->EventList;
  1661. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1662. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1663. e->window = wnd;
  1664. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1665. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1666. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1667. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1668. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1669. e->GoodPressure=MAIN.IsPen;
  1670. lstAppendItem(el, (laListItem *)e);
  1671. laMappingRequestEval();
  1672. };
  1673. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1674. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1675. la_SaveEvent(hwnd, e, 1);
  1676. };
  1677. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1678. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1679. e->type = LA_INPUT; e->Input=Input;
  1680. la_SaveEvent(hwnd, e, 1);
  1681. }
  1682. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1683. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1684. e->type = LA_EMPTY;
  1685. la_SaveEvent(hwnd, e, 1);
  1686. }
  1687. void laSendOperatorTriggerEvent(){
  1688. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1689. MAIN.ReTriggerOperators = 0;
  1690. }
  1691. int la_TranslateSpecialKey(int keysym){
  1692. #ifdef LA_LINUX
  1693. switch(keysym){
  1694. case XK_Return: return LA_KEY_ENTER;
  1695. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1696. case XK_Delete: return LA_KEY_DELETE;
  1697. case XK_Escape: return LA_KEY_ESCAPE;
  1698. case XK_Tab: return LA_KEY_TAB;
  1699. case XK_Left: return LA_KEY_ARRLEFT;
  1700. case XK_Right: return LA_KEY_ARRRIGHT;
  1701. case XK_Up: return LA_KEY_ARRUP;
  1702. case XK_Down: return LA_KEY_ARRDOWN;
  1703. case XK_Control_L: return LA_KEY_CTRL;
  1704. case XK_Control_R: return LA_KEY_CTRL;
  1705. case XK_Shift_L: return LA_KEY_SHIFT;
  1706. case XK_Shift_R: return LA_KEY_SHIFT;
  1707. case XK_Alt_L: return LA_KEY_ALT;
  1708. case XK_Alt_R: return LA_KEY_ALT;
  1709. case XK_KP_1: return LA_KEY_NUM1;
  1710. case XK_KP_2: return LA_KEY_NUM2;
  1711. case XK_KP_3: return LA_KEY_NUM3;
  1712. case XK_KP_4: return LA_KEY_NUM4;
  1713. case XK_KP_5: return LA_KEY_NUM5;
  1714. case XK_KP_6: return LA_KEY_NUM6;
  1715. case XK_KP_7: return LA_KEY_NUM7;
  1716. case XK_KP_8: return LA_KEY_NUM8;
  1717. case XK_KP_9: return LA_KEY_NUM9;
  1718. case XK_KP_0: return LA_KEY_NUM0;
  1719. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1720. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1721. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1722. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1723. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1724. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1725. default: return keysym;
  1726. }
  1727. #endif
  1728. #ifdef _WIN32
  1729. switch (keysym) {
  1730. case VK_RETURN: return LA_KEY_ENTER;
  1731. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1732. case VK_TAB: return LA_KEY_TAB;
  1733. case VK_LEFT: return LA_KEY_ARRLEFT;
  1734. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1735. case VK_UP: return LA_KEY_ARRUP;
  1736. case VK_DOWN: return LA_KEY_ARRDOWN;
  1737. case VK_CONTROL: return LA_KEY_CTRL;
  1738. case VK_SHIFT: return LA_KEY_SHIFT;
  1739. case VK_MENU: return LA_KEY_ALT;
  1740. case VK_F1: return LA_KEY_F1;
  1741. case VK_F2: return LA_KEY_F2;
  1742. case VK_F3: return LA_KEY_F3;
  1743. case VK_F4: return LA_KEY_F4;
  1744. case VK_F5: return LA_KEY_F5;
  1745. case VK_F6: return LA_KEY_F6;
  1746. case VK_F7: return LA_KEY_F7;
  1747. case VK_F8: return LA_KEY_F8;
  1748. case VK_F9: return LA_KEY_F9;
  1749. case VK_F10: return LA_KEY_F10;
  1750. case VK_F11: return LA_KEY_F11;
  1751. case VK_F12: return LA_KEY_F12;
  1752. case VK_NUMPAD0: return LA_KEY_NUM0;
  1753. case VK_NUMPAD1: return LA_KEY_NUM1;
  1754. case VK_NUMPAD2: return LA_KEY_NUM2;
  1755. case VK_NUMPAD3: return LA_KEY_NUM3;
  1756. case VK_NUMPAD4: return LA_KEY_NUM4;
  1757. case VK_NUMPAD5: return LA_KEY_NUM5;
  1758. case VK_NUMPAD6: return LA_KEY_NUM6;
  1759. case VK_NUMPAD7: return LA_KEY_NUM7;
  1760. case VK_NUMPAD8: return LA_KEY_NUM8;
  1761. case VK_NUMPAD9: return LA_KEY_NUM9;
  1762. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1763. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1764. case VK_ADD: return LA_KEY_NUMPLUS;
  1765. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1766. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1767. case VK_OEM_1: return ';';
  1768. case VK_OEM_2: return '/';
  1769. case VK_OEM_3: return '`';
  1770. case VK_OEM_4: return '[';
  1771. case VK_OEM_5: return '\\';
  1772. case VK_OEM_6: return ']';
  1773. case VK_OEM_7: return '\'';
  1774. case VK_OEM_COMMA: return ',';
  1775. case VK_OEM_PERIOD: return '.';
  1776. case VK_OEM_PLUS: return '+';
  1777. case VK_OEM_MINUS: return '-';
  1778. default: return keysym;
  1779. }
  1780. #endif
  1781. }
  1782. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1783. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1784. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1785. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1786. // la_SaveEvent(hwnd, e, 0);
  1787. //}
  1788. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1789. e->type = type; e->x = x; e->y = y;
  1790. la_SaveEvent(hwnd, e, 0);
  1791. MAIN.evLastX=x; MAIN.evLastY=y;
  1792. };
  1793. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1794. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1795. e->type = type;
  1796. la_SaveEvent(hwnd, e, 1);
  1797. };
  1798. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1799. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1800. e->type = LA_SIGNAL_EVENT;
  1801. e->key = signal;
  1802. la_SaveEvent(hwnd, e, 1);
  1803. };
  1804. void laRetriggerOperators(){
  1805. MAIN.ReTriggerOperators = 1;
  1806. }
  1807. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1808. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1809. }
  1810. void laSetCleanupCallback(laCleanupF Cleanup){
  1811. MAIN.Cleanup=Cleanup;
  1812. }
  1813. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1814. MAIN.InputProcess=InputProcess;
  1815. }
  1816. //====================================================================================================
  1817. void la_DestroyTheme(laTheme* t){
  1818. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1819. strSafeDestroy(&t->Name);
  1820. strSafeDestroy(&t->Author);
  1821. }
  1822. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1823. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1824. strSafeSet(&t->Name, Name);
  1825. strSafeSet(&t->Author, AuthorName);
  1826. lstAppendItem(&MAIN.Themes, t);
  1827. MAIN.CurrentTheme = t;
  1828. return t;
  1829. }
  1830. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1831. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1832. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1833. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1834. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1835. strSafeSet(&bt->Name, Name);
  1836. bt->NormalY=NormalY;
  1837. bt->ActiveY=ActiveY;
  1838. bt->BorderY=BorderY;
  1839. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1840. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1841. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1842. bt->BackRef = BackRef;
  1843. lstAppendItem(&t->BoxedThemes, bt);
  1844. return bt;
  1845. }
  1846. laTheme *laGetTheme(const char *ThemeName){
  1847. laTheme *t = MAIN.Themes.pFirst;
  1848. for (t; t; t = t->Item.pNext){
  1849. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1850. }
  1851. return 0;
  1852. }
  1853. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1854. laTheme *t = MAIN.Themes.pFirst;
  1855. for (t; t; t = t->Item.pNext){
  1856. laBoxedTheme *bt;
  1857. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1858. bt = t->BoxedThemes.pFirst;
  1859. for (bt; bt; bt = bt->Item.pNext){
  1860. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1861. }
  1862. }
  1863. return 0;
  1864. }
  1865. real* laThemeColor(laBoxedTheme* bt, int which){
  1866. switch(which){
  1867. default:
  1868. case LA_BT_NORMAL: return bt->Normal;
  1869. case LA_UI_EDITING:
  1870. case LA_BT_ACTIVE: return bt->Active;
  1871. case LA_BT_BORDER: return bt->Border;
  1872. case LA_BT_TEXT: return bt->Text; break;
  1873. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1874. case LA_BT_DISABLED: return bt->Inactive; break;
  1875. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1876. }
  1877. return bt->Normal;
  1878. }
  1879. real* laAccentColor(int which){
  1880. switch(which){
  1881. default:
  1882. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1883. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1884. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1885. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1886. case LA_BT_FACE:
  1887. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1888. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1889. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1890. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1891. case LA_BT_SHADOW: return MAIN.CurrentTheme->ShadowColor;
  1892. }
  1893. return MAIN.CurrentTheme->SelectionColor;
  1894. }
  1895. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1896. real hcy[3];
  1897. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1898. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1899. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1900. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1901. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1902. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1903. int *tm=&bt->LM,*tp=&bt->LP;
  1904. for(int i=0;i<4;i++){
  1905. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1906. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1907. }
  1908. }
  1909. void la_RefreshThemeColorSelf(laTheme* th){
  1910. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1911. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1912. real hcy[3], usehcy[3];
  1913. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1914. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1915. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1916. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1917. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1918. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1919. tnsVectorCopy3d(th->Color, th->ShadowColor); th->ShadowColor[3]=th->CursorAlpha;
  1920. }
  1921. void la_RefreshThemeColor(laTheme* th){
  1922. real hcy[3], usehcy[3], normalhcy[3];
  1923. tnsRGB2HCY(th->Color,hcy);
  1924. la_RefreshThemeColorSelf(th);
  1925. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1926. la_RefreshBoxedThemeColor(bt);
  1927. (*bt->BackRef) = bt;
  1928. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1929. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1930. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1931. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1932. }
  1933. }
  1934. //I FUCKING HATE THIS STUPID FUNCTION
  1935. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1936. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1937. laUiListDrawItem *last = uild->Items.pFirst;
  1938. int LimW=_R-_L;
  1939. int SL, SR, SU, SB;
  1940. int Target__B = Target->B;
  1941. int Target__R = Target->R;
  1942. uildi->Target = Target;
  1943. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1944. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1945. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1946. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1947. uildi->L = last ? Target->L - last->XP : Target->L;
  1948. uildi->R = last ? Target__R - last->XP : Target__R;
  1949. uildi->U = last ? Target->U - last->YP : Target->U;
  1950. uildi->B = last ? Target__B - last->YP : Target__B;
  1951. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1952. uildi->L -= GlobalX;
  1953. uildi->R -= GlobalX;
  1954. uildi->U -= GlobalY;
  1955. uildi->B -= GlobalY;
  1956. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1957. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1958. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1959. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1960. uildi->DifX = SL - uildi->L;
  1961. uildi->DifY = SU - uildi->U;
  1962. uildi->L = SL;
  1963. uildi->R = SR+uildi->DifX;
  1964. uildi->U = SU;
  1965. uildi->B = SB;//+uildi->DifY;
  1966. if(uildi->R>_R){ uildi->R=_R; }
  1967. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1968. //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);
  1969. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1970. memFree(uildi);
  1971. return 0;
  1972. }
  1973. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  1974. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  1975. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  1976. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  1977. Target->U + Target->PanY + uildi->DifY+1,
  1978. -100, 100);
  1979. lstPushItem(&uild->Items, uildi);
  1980. return 1;
  1981. }
  1982. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1983. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1984. laUiListDrawItem *last = uild->Items.pFirst;
  1985. int SL, SR, SU, SB;
  1986. if (B - U > LimH) B = U + LimH;
  1987. uildi->XP = last ? last->XP + PanX : PanX;
  1988. uildi->YP = last ? last->YP + PanY : PanY;
  1989. uildi->L = last ? L - last->XP : L;
  1990. uildi->R = last ? R - last->XP : R;
  1991. uildi->U = last ? U - last->YP : U;
  1992. uildi->B = last ? B - last->YP : B;
  1993. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1994. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1995. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1996. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1997. uildi->DifX = SL - uildi->L;
  1998. uildi->DifY = SU - uildi->U;
  1999. uildi->L = SL;
  2000. uildi->R = SR;
  2001. uildi->U = SU;
  2002. uildi->B = SB;
  2003. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2004. tnsOrtho(L + PanX + uildi->DifX,
  2005. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  2006. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2007. U + PanY + uildi->DifY,
  2008. -100, 100);
  2009. lstPushItem(&uild->Items, uildi);
  2010. }
  2011. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2012. int* savel, int* saver, int* saveu, int* saveb){
  2013. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2014. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2015. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2016. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2017. real x,y,w,h;
  2018. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2019. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2020. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2021. }
  2022. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2023. laUiListDrawItem *uildi = uild->Items.pFirst;
  2024. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2025. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2026. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2027. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2028. Target->U + Target->PanY + uildi->DifY -1,
  2029. -100, 100);
  2030. }
  2031. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2032. laUiListDrawItem *uildi = lstPopItem(uild);
  2033. laUiList *Target;
  2034. memFree(uildi);
  2035. uildi = uild->Items.pFirst;
  2036. if (!uildi || !uildi->Target){
  2037. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2038. return;
  2039. }
  2040. Target = uildi->Target;
  2041. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2042. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2043. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2044. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2045. Target->U + Target->PanY + uildi->DifY -1,
  2046. -100, 100);
  2047. }
  2048. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2049. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2050. uildi->L = L;
  2051. uildi->R = R;
  2052. uildi->U = U;
  2053. uildi->B = B;
  2054. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2055. tnsOrtho(L, R, B, U, -100, 100);
  2056. lstPushItem(&uild->Items, uildi);
  2057. }
  2058. void la_ClearUiListMatrix(laUiListDraw *uild){
  2059. laUiListDrawItem *uildi;
  2060. while (uildi = lstPopItem(uild)){
  2061. memFree(uildi);
  2062. }
  2063. }
  2064. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2065. 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);
  2066. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2067. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2068. int la_TestUiListMinumWidth(laUiList *uil);
  2069. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2070. if (ui){
  2071. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2072. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2073. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2074. p->X = p->TX; p->Y = p->TY;
  2075. p->W = p->TW;
  2076. }
  2077. }
  2078. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2079. int cw = MAIN.CurrentWindow->CW;
  2080. int ch = MAIN.CurrentWindow->CH;
  2081. int PH = p->TH;
  2082. laBoxedTheme*bt = *p->BT;
  2083. int uih=uil->B + bt->BM;
  2084. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2085. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2086. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2087. else p->TH = PH;
  2088. p->H = p->TH;
  2089. if(p->BoundUi){
  2090. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2091. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2092. if (p->X < 0) p->X = 0;
  2093. if (p->Y < 0) p->Y = 0;
  2094. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2095. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2096. }else{
  2097. if (p->Y < 0) p->Y = 0;
  2098. if ((!p->Block)&&(!p->IsMenuPanel)){
  2099. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2100. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2101. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2102. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2103. }
  2104. }
  2105. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2106. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2107. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2108. }
  2109. if (p->ST) p->TY = p->ST;
  2110. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2111. if (p->SB) p->TH = ch - p->TY - p->SB;
  2112. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2113. p->TX = p->X; p->TY = p->Y;
  2114. p->TW = p->W; p->TH = p->H;
  2115. }
  2116. void laPlacePanelForCreation(laPanel *p){
  2117. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2118. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2119. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2120. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2121. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2122. p->TX=p->X; p->TY=p->Y;
  2123. }
  2124. }
  2125. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2126. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2127. tnsViewportWithScissor(0, 0, p->W, p->H);
  2128. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2129. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2130. }
  2131. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2132. tnsDrawToScreen();
  2133. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2134. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2135. }
  2136. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2137. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2138. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2139. }
  2140. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2141. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2142. tnsClearAll();
  2143. }
  2144. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2145. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2146. real Color[] = {1, 1, 1, 1};
  2147. real L, W, U, H;
  2148. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2149. if(MAIN.EnableColorManagement){
  2150. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2151. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2152. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2153. }else{
  2154. tnsUniformOutputColorSpace(T->immShader,0);
  2155. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2156. tnsUniformColorComposing(T->immShader,0,0,0);
  2157. }
  2158. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2159. tnsUseNoTexture();
  2160. if (!p->IsMenuPanel){
  2161. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2162. }
  2163. tnsFlush();
  2164. }
  2165. if(p->ParentOperator){
  2166. tnsUseNoTexture();
  2167. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2168. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2169. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2170. }
  2171. switch (p->AnimationMode){
  2172. case 0: /* and */
  2173. case LA_PANEL_ANIMATION_FLASH:
  2174. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2175. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2176. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2177. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2178. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2179. tnsPackAs(GL_TRIANGLES);
  2180. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2181. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2182. }
  2183. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2184. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2185. if((int)(p->AnimationRatio*6)%2){
  2186. tnsUseNoTexture();
  2187. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2188. tnsVertex2d(p->X,p->Y); tnsVertex2d(p->X+p->W,p->Y); tnsVertex2d(p->X+p->W,p->Y+p->H); tnsVertex2d(p->X,p->Y+p->H);
  2189. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2190. }
  2191. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2192. }
  2193. break;
  2194. case LA_PANEL_ANIMATION_DROP_DOWN:
  2195. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2196. tnsDraw2DTextureArg(
  2197. p->OffScr->pColor[0],
  2198. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2199. Color,
  2200. 0, 0, 1 - p->AnimationRatio, 0);
  2201. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2202. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2203. break;
  2204. case LA_PANEL_ANIMATION_EXPAND:
  2205. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2206. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2207. W = tnsLinearItp(0, p->W, 0.4);
  2208. H = tnsLinearItp(0, p->H, 0.4);
  2209. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2210. tnsDraw2DTextureArg(
  2211. p->OffScr->pColor[0],
  2212. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2213. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2214. Color,
  2215. 0, 0, 0, 0);
  2216. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2217. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2218. break;
  2219. case LA_PANEL_ANIMATION_DISSOVE:
  2220. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2221. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2222. W = tnsLinearItp(0, p->W, 1.4);
  2223. H = tnsLinearItp(0, p->H, 1.4);
  2224. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2225. if (p->OffScr) tnsDraw2DTextureArg(
  2226. p->OffScr->pColor[0],
  2227. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2228. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2229. Color,
  2230. 0, 0, 0, 0);
  2231. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2232. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2233. break;
  2234. case LA_PANEL_ANIMATION_COLLAPSE:
  2235. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2236. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2237. W = tnsLinearItp(0, p->W, 0.4);
  2238. H = tnsLinearItp(0, p->H, 0.4);
  2239. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2240. if (p->OffScr) tnsDraw2DTextureArg(
  2241. p->OffScr->pColor[0],
  2242. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2243. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2244. Color,
  2245. 0, 0, 0, 0);
  2246. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2247. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2248. break;
  2249. case LA_PANEL_ANIMATION_MINIMIZE:
  2250. L = tnsLinearItp(0, p->X, 0.3);
  2251. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2252. W = tnsLinearItp(0, p->W, 0.4);
  2253. H = tnsLinearItp(0, p->H, 0.4);
  2254. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2255. tnsDraw2DTextureArg(
  2256. p->OffScr->pColor[0],
  2257. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2258. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2259. Color,
  2260. 0, 0, 0, 0);
  2261. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2262. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2263. break;
  2264. }
  2265. tnsFlush();
  2266. tnsUniformOutputColorSpace(T->immShader,0);
  2267. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2268. tnsUniformColorComposing(T->immShader,0,0,0);
  2269. }
  2270. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2271. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2272. else{
  2273. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:LA_PANEL_DEFAULT_GL_FORMAT;
  2274. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2275. }
  2276. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2277. }
  2278. void la_PanelRefreshDetachedProp(laPanel *panel){
  2279. laProp *p;
  2280. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2281. la_StepPropPack(&p->DetachedPP);
  2282. la_UsePropPack(&p->DetachedPP, 0);
  2283. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2284. // laUseDataBlock(
  2285. // p->DetachedPP.LastPs->UseInstance,
  2286. // p->DetachedPP.LastPs->p,
  2287. // MAIN.PropMatcherContextP->FrameDistinguish,
  2288. // MAIN.PropMatcherContextP,
  2289. // la_PropPanelUserRemover, 0);
  2290. //}
  2291. }
  2292. }
  2293. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2294. real* color=laThemeColor(bt,LA_BT_BORDER);
  2295. tnsColor4d(0,0,0,Alpha);
  2296. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2297. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2298. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2299. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2300. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2301. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2302. tnsPackAs(GL_TRIANGLE_STRIP);
  2303. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2304. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2305. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2306. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2307. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2308. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2309. }
  2310. int la_AnimateUiListRecursive(laUiList *uil);
  2311. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2312. int DrawState_ = 0;
  2313. laUiListDraw uild = {0};
  2314. if (p->Show){
  2315. la_SetPropMathcerContext(p);
  2316. MAIN.CurrentPanel = p;
  2317. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2318. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2319. //}
  2320. if (p->Refresh & LA_TAG_RECALC){
  2321. laRecalcPanelImmediate(p);
  2322. }
  2323. if (!p->MenuRefer){
  2324. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2325. if (p->Refresh || !p->OffScr){
  2326. la_PanelDrawToOffsceen(p, &p->UI);
  2327. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2328. la_PanelBackgroundInit(p, bt);
  2329. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2330. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2331. tnsFlush();
  2332. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2333. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2334. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2335. DrawState_++;
  2336. }
  2337. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2338. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2339. if(p->UI.PanY<0){p->UI.PanY=0;}
  2340. DrawState_++;
  2341. }
  2342. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2343. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2344. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2345. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2346. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2347. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2348. if(p!=w->MaximizedUiPanel){
  2349. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2350. }else{
  2351. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2352. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2353. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2354. tnsFlush();
  2355. }
  2356. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2357. }
  2358. }else{
  2359. if (p->Refresh || !p->OffScr){
  2360. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2361. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2362. la_PanelBackgroundInit(p, bt);
  2363. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2364. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2365. tnsFlush();
  2366. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2367. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2368. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2369. DrawState_++;
  2370. }
  2371. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2372. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2373. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2374. DrawState_++;
  2375. }
  2376. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2377. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2378. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2379. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2380. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2381. }
  2382. }
  2383. tnsDrawToScreen();
  2384. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2385. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2386. la_PanelDrawToWindow(p, w);
  2387. }elif (p->AnimationMode){
  2388. la_PanelDrawToWindow(p, w);
  2389. }
  2390. }
  2391. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2392. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2393. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2394. laPanel *pi, *PrevPI;
  2395. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2396. PrevPI = pi->Item.pPrev;
  2397. if (pi->AnimationMode && pi->LaterDestroy){
  2398. lstRemoveItem(&p->SubPanels, pi);
  2399. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2400. continue;
  2401. }
  2402. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2403. la_AttachedPanelDefDraw(w,pi,bt);
  2404. }
  2405. }
  2406. }
  2407. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2408. real PanelSquare[] = {
  2409. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2410. b->X + 2, CH - (b->Y + b->H - 4),
  2411. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2412. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2413. real Center[] = {
  2414. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2415. real DraggingPlot[] = {
  2416. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2417. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2418. PanelSquare[0],
  2419. PanelSquare[1],
  2420. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2421. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2422. PanelSquare[2],
  2423. PanelSquare[3],
  2424. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2425. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2426. PanelSquare[4],
  2427. PanelSquare[5],
  2428. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2429. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2430. PanelSquare[6],
  2431. PanelSquare[7],
  2432. };
  2433. real Square[] = {
  2434. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2435. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2436. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2437. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2438. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2439. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2440. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2441. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2442. };
  2443. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2444. LA_COLOR3(BorderColor4dV), 0,
  2445. LA_COLOR3(BorderColor4dV), 0.8,
  2446. LA_COLOR3(BorderColor4dV), 0,
  2447. LA_COLOR3(BorderColor4dV), 0.8,
  2448. LA_COLOR3(BorderColor4dV), 0,
  2449. LA_COLOR3(BorderColor4dV), 0.8,
  2450. LA_COLOR3(BorderColor4dV), 0,
  2451. };
  2452. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2453. LA_COLOR3(FillColor4dv), 0,
  2454. LA_COLOR3(FillColor4dv), 0.8,
  2455. LA_COLOR3(FillColor4dv), 0,
  2456. LA_COLOR3(FillColor4dv), 0.8,
  2457. LA_COLOR3(FillColor4dv), 0,
  2458. LA_COLOR3(FillColor4dv), 0.8,
  2459. LA_COLOR3(FillColor4dv), 0,
  2460. };
  2461. tnsUseNoTexture();
  2462. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2463. int Index[4];
  2464. tnsVertexArray2d(DraggingPlot, 8);
  2465. tnsColorArray4d(FillColor, 8);
  2466. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2467. case 0:
  2468. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2469. break;
  2470. case LA_BLOCK_DROP_LOCATION_L:
  2471. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2472. break;
  2473. case LA_BLOCK_DROP_LOCATION_R:
  2474. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2475. break;
  2476. case LA_BLOCK_DROP_LOCATION_U:
  2477. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2478. break;
  2479. case LA_BLOCK_DROP_LOCATION_B:
  2480. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2481. break;
  2482. }
  2483. //glDisable(GL_CULL_FACE);
  2484. tnsIndexArray(Index, 4);
  2485. tnsPackAs(GL_TRIANGLE_FAN);
  2486. //tnsFlush();
  2487. }
  2488. tnsVertexArray2d(DraggingPlot, 8);
  2489. tnsColorArray4d(PlotColor, 8);
  2490. tnsPackAs(GL_LINES);
  2491. tnsVertexArray2d(Square, 4);
  2492. tnsColor4dv(BorderColor4dV);
  2493. tnsPackAs(GL_LINE_LOOP);
  2494. glLineWidth(LA_SEAM_W);
  2495. tnsFlush();
  2496. glLineWidth(1);
  2497. }
  2498. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2499. laBoxedTheme *bt = _LA_THEME_TAB;
  2500. laPanel *p;
  2501. real v[] = {
  2502. b->X, CH - b->Y,
  2503. b->X + LA_SEAM_W, CH - b->Y ,
  2504. b->X, CH - (b->Y + b->H),
  2505. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2506. b->X + b->W, CH - (b->Y + b->H),
  2507. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2508. b->X + b->W, CH - b->Y,
  2509. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2510. real tv[8];
  2511. real ratio = 1.0001f;
  2512. int tw = 0;
  2513. int L = LA_RH+LA_SEAM_W;
  2514. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2515. if(MAIN.EnableColorManagement){
  2516. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2517. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2518. }else{
  2519. tnsUniformOutputColorSpace(T->immShader,0);
  2520. tnsUniformColorComposing(T->immShader,0,0,0);
  2521. }
  2522. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2523. tw += p->TitleWidth + LA_SEAM_W*2;
  2524. }
  2525. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2526. tnsUseNoTexture();
  2527. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2528. tnsVertexArray2d(v, 8);
  2529. tnsPackAs(GL_TRIANGLE_STRIP);
  2530. int TitleGap=b->Folded?0:LA_RH;
  2531. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2532. b->X + b->W, (CH - b->Y),
  2533. b->X + b->W, (CH - b->Y - TitleGap),
  2534. b->X, (CH - b->Y - TitleGap));
  2535. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2536. tnsVertexArray2d(tv, 4);
  2537. tnsPackAs(GL_TRIANGLE_FAN);
  2538. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2539. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2540. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2541. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2542. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2543. tnsVertexArray2d(tv, 4);
  2544. tnsPackAs(GL_TRIANGLE_FAN);
  2545. if(b->Folded){
  2546. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2547. 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);
  2548. 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);
  2549. tnsFlush(); return;
  2550. }
  2551. int LT=0,RT=0;
  2552. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2553. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2554. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2555. b->X + L+RT * ratio, (CH - b->Y),
  2556. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2557. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2558. if (p == b->CurrentPanel){
  2559. tnsUseNoTexture();
  2560. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2561. tnsVertexArray2d(tv, 4);
  2562. tnsPackAs(GL_TRIANGLE_FAN);
  2563. 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);
  2564. }else{
  2565. 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);
  2566. }
  2567. LT =RT;
  2568. }
  2569. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2570. tnsFlush();
  2571. tnsUniformOutputColorSpace(T->immShader,0);
  2572. tnsUniformColorComposing(T->immShader,0,0,0);
  2573. }
  2574. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2575. laBoxedTheme *bt = _LA_THEME_PANEL;
  2576. real tv[8];
  2577. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2578. if(MAIN.EnableColorManagement){
  2579. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2580. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2581. }else{
  2582. tnsUniformOutputColorSpace(T->immShader,0);
  2583. tnsUniformColorComposing(T->immShader,0,0,0);
  2584. }
  2585. tnsUseNoTexture();
  2586. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2587. b->X + b->W, (CH - b->Y),
  2588. b->X + b->W, (CH - b->Y-b->H),
  2589. b->X, (CH - b->Y-b->H));
  2590. tnsVertexArray2d(tv, 4);
  2591. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2592. tnsPackAs(GL_TRIANGLE_FAN);
  2593. 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,
  2594. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2595. tnsFlush();
  2596. tnsUniformOutputColorSpace(T->immShader,0);
  2597. tnsUniformColorComposing(T->immShader,0,0,0);
  2598. }
  2599. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2600. if (b->B1){
  2601. la_BlockDefDrawRecursive(w, bt, b->B1);
  2602. la_BlockDefDrawRecursive(w, bt, b->B2);
  2603. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2604. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2605. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2606. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2607. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2608. la_BlockDefDrawSelf(b, w->CH);
  2609. }else{
  2610. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2611. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2612. la_BlockDefDrawSelfEmpty(b, w->CH);
  2613. }
  2614. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2615. tnsUseNoTexture();
  2616. int at; real tv[8];
  2617. if (b->Vertical){
  2618. at = b->H * b->SplitRatio + b->Y;
  2619. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2620. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2621. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2622. b->X, (w->CH - at - LA_SEAM_W));
  2623. }else{
  2624. at = b->X + b->W * b->SplitRatio;
  2625. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2626. at- LA_SEAM_W, (w->CH - b->Y),
  2627. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2628. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2629. }
  2630. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2631. tnsVertexArray2d(tv, 4);
  2632. tnsPackAs(GL_TRIANGLE_FAN);
  2633. }
  2634. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2635. tnsFlush();
  2636. }
  2637. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2638. if (b->B1){
  2639. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2640. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2641. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2642. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2643. }
  2644. tnsFlush();
  2645. }
  2646. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2647. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2648. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2649. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2650. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2651. if(p->OffScr){
  2652. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2653. }
  2654. }
  2655. }
  2656. void la_ClearUnusedFramebuffers(laWindow* w){
  2657. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2658. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2659. }
  2660. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2661. if(p->Show || p->AnimationMode) continue;
  2662. if(p->OffScr){
  2663. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2664. }
  2665. }
  2666. }
  2667. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2668. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2669. laPanel *p, *NextP;
  2670. laLayout *l = w->CurrentLayout;
  2671. if (!w->CH || !w->CW) return;
  2672. la_ClearUnusedFramebuffers(w);
  2673. tnsDrawToScreen();
  2674. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2675. glClearColor(0.2, 0.2, 0.3, 1.0);
  2676. tnsClearAll();
  2677. tnsUseNoTexture();
  2678. if (l->Draw) l->Draw(w, l);
  2679. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2680. glEnable(GL_BLEND);
  2681. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2682. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2683. laUiItem* ui;
  2684. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2685. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2686. la_SetPropMathcerContext(p);
  2687. if(p->Refresh){
  2688. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2689. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2690. if(MAIN.EnableColorManagement){
  2691. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2692. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2693. }else{
  2694. tnsUniformOutputColorSpace(T->immShader,0);
  2695. tnsUniformColorComposing(T->immShader,0,0,0);
  2696. }
  2697. if(p->Refresh&LA_TAG_RECALC){
  2698. laRecalcPanelImmediate(p);
  2699. }
  2700. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2701. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2702. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2703. }
  2704. tnsDrawToScreen();
  2705. tnsResetViewMatrix();
  2706. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2707. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2708. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2709. tnsFlush();
  2710. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2711. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2712. tnsFlush();
  2713. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2714. }
  2715. }
  2716. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2717. la_AttachedPanelDefDraw(w,p,*p->BT);
  2718. }else{
  2719. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2720. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2721. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2722. }
  2723. for (p = w->Panels.pLast; p; p = NextP){
  2724. NextP = p->Item.pPrev;
  2725. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2726. if (p->AnimationMode && p->LaterDestroy){
  2727. lstRemoveItem(&w->Panels, p);
  2728. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2729. continue;
  2730. }
  2731. la_PanelDefDraw(w, p, *p->BT);
  2732. }
  2733. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2734. la_AttachedPanelDefDraw(w,p,*p->BT);
  2735. }
  2736. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2737. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2738. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2739. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2740. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2741. tnsFlush();
  2742. }
  2743. for (p = w->FadingPanels.pLast; p; p = NextP){
  2744. NextP = p->Item.pPrev;
  2745. if (!p->AnimationMode){
  2746. lstRemoveItem(&w->FadingPanels, p);
  2747. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2748. laDeferredDestroyPanel(p, 0);
  2749. }else
  2750. la_PanelDrawToWindow(p, w);
  2751. }
  2752. }
  2753. int laStartWindow(laWindow *w){
  2754. #ifdef LA_LINUX
  2755. XMapWindow(MAIN.dpy,w->win);
  2756. tnsContextMakeWindowCurrent(w);
  2757. #endif
  2758. #ifdef _WIN32
  2759. ShowWindow(w->win, SW_SHOWNORMAL);
  2760. #endif
  2761. MAIN.CurrentWindow = w;
  2762. if(!w->CurrentLayout){
  2763. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2764. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2765. }
  2766. laRedrawCurrentWindow();
  2767. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2768. w->Shown = 1;
  2769. }
  2770. void la_AssignWindowPP(laWindow* w){
  2771. w->PP.EndInstance = w;
  2772. w->PP.LastPs = &w->FakePS;
  2773. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2774. w->PP.LastPs->UseInstance = w;
  2775. w->PP.LastPs->Type = U'.';
  2776. }
  2777. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2778. #ifdef LAGUI_ANDROID
  2779. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2780. #endif
  2781. laWindow *n = memAcquire(sizeof(laWindow));
  2782. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2783. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2784. #ifdef LAGUI_ANDROID
  2785. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2786. #endif
  2787. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2788. lstAppendItem(&MAIN.Windows, n);
  2789. MAIN.CurrentWindow = n;
  2790. la_AssignWindowPP(n);
  2791. laui_DefaultMenuBar(n);
  2792. return n;
  2793. }
  2794. void laSetWindowCursor(int id){
  2795. MAIN.CurrentCursor = id;
  2796. #ifdef LA_LINUX
  2797. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2798. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2799. #endif
  2800. #ifdef _WIN32
  2801. SetCursor(la_ConvertCursorID(id));
  2802. #endif
  2803. };
  2804. void la_AssignBlockPP(laBlock* b){
  2805. b->PP.EndInstance = b;
  2806. b->PP.LastPs = &b->FakePS;
  2807. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2808. b->PP.LastPs->UseInstance = b;
  2809. b->PP.LastPs->Type = U'.';
  2810. }
  2811. void laDestroyLayout(laWindow *w, laLayout* l){
  2812. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2813. laDestroyBlocksRecursive(l->FirstBlock);
  2814. strSafeDestroy(&l->ID);
  2815. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2816. lstRemoveItem(&w->Layouts,l); memFree(l);
  2817. }
  2818. laLayout *laDesignLayout(laWindow *w, char *Title){
  2819. laLayout *l = memAcquire(sizeof(laLayout));
  2820. l->FirstBlock = memAcquire(sizeof(laBlock));
  2821. la_AssignBlockPP(l->FirstBlock);
  2822. lstAppendItem(&w->Layouts, l);
  2823. strSafeSet(&l->ID, Title);
  2824. memAssignRef(w, &w->CurrentLayout, l);
  2825. laRenameWindow(w, Title);
  2826. return l;
  2827. }
  2828. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2829. 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); }
  2830. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2831. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2832. laNotifyUsers("la.windows.maximized_block"); }
  2833. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2834. laNotifyUsers("la.windows.maximized_block"); }
  2835. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2836. laRestoreCanvasUI();
  2837. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2838. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2839. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2840. UiParentPanel->Show=0;
  2841. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2842. }
  2843. void laRestoreCanvasUI(){
  2844. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2845. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2846. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2847. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2848. }
  2849. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2850. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2851. }
  2852. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2853. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2854. laPanel *p;
  2855. b->SplitRatio = Percentage;
  2856. b->Vertical = 0;
  2857. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2858. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2859. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2860. p->Block = b->B1;
  2861. }
  2862. b->B1->Panels.pFirst = b->Panels.pFirst;
  2863. b->B1->Panels.pLast = b->Panels.pLast;
  2864. b->B1->CurrentPanel = b->CurrentPanel;
  2865. b->B1->parent = b->B2->parent=b;
  2866. b->Panels.pFirst = 0;
  2867. b->Panels.pLast = 0;
  2868. b->CurrentPanel = 0;
  2869. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2870. }
  2871. void laSplitBlockVertical(laBlock *b, real Percentage){
  2872. laPanel *p;
  2873. b->SplitRatio = Percentage;
  2874. b->Vertical = 1;
  2875. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2876. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2877. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2878. p->Block = b->B1;
  2879. }
  2880. b->B1->Panels.pFirst = b->Panels.pFirst;
  2881. b->B1->Panels.pLast = b->Panels.pLast;
  2882. b->B1->CurrentPanel = b->CurrentPanel;
  2883. b->B1->parent = b->B2->parent=b;
  2884. b->Panels.pFirst = 0;
  2885. b->Panels.pLast = 0;
  2886. b->CurrentPanel = 0;
  2887. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2888. }
  2889. void laCombineChildBlocks(laBlock *b){
  2890. laPanel *p; if(!b) return;
  2891. if (!b->B1->B1 && !b->B2->B1){
  2892. lstCombineLists(&b->Panels, &b->B1->Panels);
  2893. lstCombineLists(&b->Panels, &b->B2->Panels);
  2894. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2895. p->Block = b;
  2896. }
  2897. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2898. memFree(b->B1);
  2899. memFree(b->B2);
  2900. b->B1 = 0;
  2901. b->B2 = 0;
  2902. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2903. }elif(!b->B1->B1){
  2904. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2905. b->Vertical = b->B2->Vertical;
  2906. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2907. p->Block = b1;
  2908. }
  2909. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2910. memFree(b->B1); memFree(b->B2);
  2911. b->B1 = b1; b->B2 = b2;
  2912. b1->parent = b; b2->parent = b;
  2913. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2914. }elif(!b->B2->B1){
  2915. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2916. b->Vertical = b->B1->Vertical;
  2917. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2918. p->Block = b1;
  2919. }
  2920. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2921. memFree(b->B1); memFree(b->B2);
  2922. b->B1 = b1; b->B2 = b2;
  2923. b1->parent = b; b2->parent = b;
  2924. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2925. }
  2926. }
  2927. laBlock *laBlock1(laBlock *b){
  2928. return b->B1;
  2929. }
  2930. laBlock *laBlock2(laBlock *b){
  2931. return b->B2;
  2932. }
  2933. laBlock *laSwapSubBlocks(laBlock *b){
  2934. laBlock *tB;
  2935. tB = b->B2;
  2936. b->B2 = b->B1;
  2937. b->B1 = tB;
  2938. b->SplitRatio = 1 - b->SplitRatio;
  2939. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2940. }
  2941. void laDestroyBlocksRecursive(laBlock *Root){
  2942. laPanel *p;
  2943. if (Root->B1){
  2944. laDestroyBlocksRecursive(Root->B1);
  2945. laDestroyBlocksRecursive(Root->B2);
  2946. }else{
  2947. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2948. }
  2949. memFree(Root);
  2950. }
  2951. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2952. if(!b->CurrentPanel ) return 0;
  2953. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2954. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2955. lstRemoveItem(&b->Panels, p);
  2956. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  2957. if(!p->TitleBar.UiItems.pFirst){
  2958. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2959. }
  2960. p->Mode = LA_PANEL_FLOATING_TOP;
  2961. p->TY-=LA_RH; p->TH+=LA_RH;
  2962. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  2963. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  2964. p->Block = 0;
  2965. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  2966. laRecalcPanel(p);
  2967. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2968. p->BT = &_LA_THEME_FLOATING_PANEL;
  2969. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2970. laNotifyUsers("la.windows.panels");
  2971. return b->CurrentPanel;
  2972. }
  2973. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2974. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2975. lstRemoveItem(&from->Panels, p);
  2976. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2977. p->Mode = LA_PANEL_NORMAL;
  2978. p->Block=b;
  2979. b->CurrentPanel = p;
  2980. lstPushItem(&b->Panels, p);
  2981. laRecalcPanel(p);
  2982. p->BT = &_LA_THEME_PANEL;
  2983. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2984. tnsFlush();
  2985. laNotifyUsers("la.windows.panels");
  2986. }
  2987. void laPopPanel(laPanel *p){
  2988. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2989. lstRemoveItem(&p->Parent->SubPanels, p);
  2990. lstPushItem(&p->Parent->SubPanels, p);
  2991. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2992. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2993. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2994. laNotifyUsers("la.windows.panels");
  2995. }
  2996. }
  2997. void la_EnsurePanelExtras(laPanel *p){
  2998. laUiTemplate* uit=p->PanelTemplate;
  2999. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  3000. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  3001. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  3002. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  3003. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  3004. p->PropLinkFakeProp->Base.Offset = 0;
  3005. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  3006. p->PropLinkPP.EndInstance = p;
  3007. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3008. p->PropLinkPP.LastPs->Type = U'.';
  3009. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3010. }
  3011. laPanel* la_GivePanelNode(){
  3012. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3013. return memAcquire(sizeof(laPanel));
  3014. }
  3015. void la_ReturnPanelNode(laPanel* p){
  3016. memset(p,0,sizeof(laPanel));
  3017. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3018. lstAppendItem(&MAIN.WastedPanels, p);
  3019. }
  3020. 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){
  3021. laPanel *p = la_GivePanelNode();
  3022. int CW = MAIN.CurrentWindow->CW;
  3023. int CH = MAIN.CurrentWindow->CH;
  3024. p->PanelTemplate = uit;
  3025. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3026. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3027. if (!MaxW) MaxW = 10000;
  3028. if (!MaxH) MaxH = 10000;
  3029. if (W > MaxW) W = MaxW;
  3030. if (H > MaxH) H = MaxH;
  3031. if (W < MinW) W = MinW;
  3032. if (H < MinH) H = MinH;
  3033. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3034. p->X = p->TX = (X < 0 ? 0 : X);
  3035. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3036. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3037. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3038. p->MaxW = MaxW; p->MaxH = MaxH;
  3039. p->MinW = MinW; p->MinH = MinH;
  3040. p->SL = SnapL; p->ST = SnapT;
  3041. p->SR = SnapR; p->SB = SnapB;
  3042. if (p->SR) p->X = CW - p->W - p->SR;
  3043. if (p->SB) p->Y = CH - p->H - p->SB;
  3044. la_EnsurePanelSnapping(p, CW, CH);
  3045. p->Show = 1;
  3046. p->PP.EndInstance = p;
  3047. p->PP.LastPs = &p->FakePS;
  3048. p->PP.LastPs->p = _LA_PROP_PANEL;
  3049. p->PP.LastPs->UseInstance = p;
  3050. p->PP.LastPs->Type = U'.';
  3051. la_EnsurePanelExtras(p);
  3052. laRecalcPanel(p);
  3053. p->FrameDistinguish = 100; //greater than 1 is ok
  3054. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3055. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3056. return p;
  3057. }
  3058. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3059. if(!uit) return 0;
  3060. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3061. strSafeSet(&p->Title, uit->Title->Ptr);
  3062. p->PanelTemplate = uit;
  3063. p->Show = 1;
  3064. p->PP.EndInstance = p;
  3065. p->PP.LastPs = &p->FakePS;
  3066. p->PP.LastPs->p = _LA_PROP_PANEL;
  3067. p->PP.LastPs->UseInstance = p;
  3068. p->PP.LastPs->Type = U'.';
  3069. la_EnsurePanelExtras(p);
  3070. laRecalcPanel(p);
  3071. p->FrameDistinguish = 100; //greater than 1 is ok
  3072. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3073. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3074. p->Block = b; b->CurrentPanel = p;
  3075. if(uit->PropFunc){ uit->PropFunc(p); }
  3076. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3077. laNotifyUsers("la.windows.panels");
  3078. return p;
  3079. }
  3080. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3081. laUiTemplate* uit=laFindUiTemplate(template_id);
  3082. return laCreatePanelT(b, uit);
  3083. }
  3084. 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){
  3085. laUiTemplate* uit=0;
  3086. if(template_id) uit=laFindUiTemplate(template_id);
  3087. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3088. p->Mode = LA_PANEL_FLOATING_TOP;
  3089. laPlacePanelForCreation(p);
  3090. if(uit){
  3091. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3092. }
  3093. if (w) lstPushItem(&w->Panels, p);
  3094. return p;
  3095. }
  3096. void laShowPanel(laPanel *p){
  3097. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3098. }
  3099. void laShowPanelWithDropDownEffect(laPanel *p){
  3100. laShowPanel(p);
  3101. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3102. p->AnimationRatio = 0;
  3103. }
  3104. void laShowPanelWithExpandEffect(laPanel *p){
  3105. laShowPanel(p);
  3106. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3107. p->AnimationRatio = 0;
  3108. }
  3109. void laHidePanel(laPanel *p){
  3110. if (!p->Mode) return;
  3111. p->Show = 0;
  3112. laNotifyUsers("la.windows.panels_hidden");
  3113. }
  3114. void laHidePanelWithDissoveEffect(laPanel *p){
  3115. if (!p->Mode) return;
  3116. laHidePanel(p);
  3117. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3118. p->AnimationRatio = 1;
  3119. }
  3120. void laHidePanelWithCollapseEffect(laPanel *p){
  3121. if (!p->Mode) return;
  3122. laHidePanel(p);
  3123. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3124. p->AnimationRatio = 1;
  3125. }
  3126. void laHidePanelWithMinimizeEffect(laPanel *p){
  3127. if (!p->Mode) return;
  3128. laHidePanel(p);
  3129. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3130. p->AnimationRatio = 1;
  3131. }
  3132. void laActivatePanel(char* TemplateID, int x, int y){
  3133. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3134. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3135. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3136. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3137. }
  3138. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3139. p->UI.PanX += DeltaX;
  3140. p->UI.PanY += DeltaY;
  3141. }
  3142. int laPanUiListFree(laUiList *uil, int X, int Y){
  3143. uil->PanX+=X; uil->PanY+=Y;
  3144. }
  3145. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3146. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3147. if(Y){X+=Y;Y=0;}
  3148. }
  3149. if (Y > 0){
  3150. if (uil->B - uil->PanY <= B) return 0;
  3151. else{
  3152. uil->PanY += Y;
  3153. if (uil->B - uil->PanY <= B){
  3154. uil->PanY = uil->B - B;
  3155. return 1;
  3156. }
  3157. }
  3158. }
  3159. if (Y < 0){
  3160. if (uil->U - uil->PanY >= U) return 0;
  3161. else{
  3162. uil->PanY += Y;
  3163. if (uil->U - uil->PanY >= U){
  3164. uil->PanY = uil->U - U;
  3165. return 1;
  3166. }
  3167. }
  3168. }
  3169. if(uil->AllowScale){
  3170. laPanUiListFree(uil, X, 0);
  3171. }else{
  3172. if (X > 0){
  3173. if (uil->R - uil->PanX <= R) return 0;
  3174. else{
  3175. uil->PanX += X;
  3176. if (uil->R - uil->PanX <= R){
  3177. uil->PanX = uil->R - R;
  3178. return 1;
  3179. }
  3180. }
  3181. }
  3182. if (X < 0){
  3183. if (uil->L - uil->PanX >= L) return 0;
  3184. else{
  3185. uil->PanX += X;
  3186. if (uil->L - uil->PanX >= L){
  3187. uil->PanX = uil->L - L;
  3188. return 1;
  3189. }
  3190. }
  3191. }
  3192. }
  3193. return 1;
  3194. }
  3195. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3196. int ret=1;
  3197. if(!uil->AllowScale){ return 0; }
  3198. real NewScale=uil->Scale*factor;
  3199. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3200. if(NewScale>5) {NewScale=5; ret=0;}
  3201. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3202. factor=NewScale/uil->Scale;
  3203. uil->Scale=NewScale;
  3204. real mx=(L+R)/2,my=(U+B)/2;
  3205. real dx= (mx+uil->PanX)*factor;
  3206. real dy= (my+uil->PanY)*factor;
  3207. uil->PanX=dx-mx;
  3208. uil->PanY=dy-my;
  3209. MAIN.CurrentPanel->FrameDistinguish=100;
  3210. return ret;
  3211. }
  3212. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3213. if(uil->AllowScale) return 0;
  3214. return laPanUiList(uil,X,Y,L,R,U,B);
  3215. }
  3216. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3217. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3218. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3219. strSafeSet(&p->Title, Title);
  3220. if (Define){
  3221. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3222. }
  3223. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3224. p->BT= &_LA_THEME_FLOATING_PANEL;
  3225. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3226. p->BoundUi = 1;
  3227. return p;
  3228. }
  3229. 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,
  3230. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3231. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3232. strSafeSet(&p->Title, Title);
  3233. if (Define){
  3234. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3235. }
  3236. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3237. p->BT= &_LA_THEME_FLOATING_PANEL;
  3238. p->Mode = LA_PANEL_FLOATING_TOP;
  3239. p->BoundUi = 1;
  3240. return p;
  3241. }
  3242. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3243. laPanel *ip;
  3244. tnsDelete2DOffscreen(p->OffScr);
  3245. p->OffScr = 0;
  3246. strSafeDestroy(&p->Title);
  3247. if (!p->AnimationMode){
  3248. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3249. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3250. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3251. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3252. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3253. }else if (p->Block){
  3254. lstRemoveItem(&p->Block->Panels, p);
  3255. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3256. }
  3257. laNotifyUsers("la.windows.panels");
  3258. }
  3259. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3260. //lstRemoveItem(&p->SubPanels, ip);
  3261. laDestroySinglePanel(ip, immediate);
  3262. laNotifyUsers("la.windows.panels");
  3263. }
  3264. la_ClearDetachedProp(p);
  3265. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3266. la_ReturnPanelNode(p);
  3267. }
  3268. void laDestroySinglePanel(laPanel *p, int immediate){
  3269. la_SetPropMathcerContext(p);
  3270. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3271. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3272. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3273. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3274. }
  3275. }
  3276. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3277. la_DestroyUiList(&p->UI, 1, 1, 0);
  3278. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3279. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3280. if (p->Mode){
  3281. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3282. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3283. }
  3284. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3285. if (la_UiStillInService(p)){
  3286. la_StopUiOperatorService(p);
  3287. }
  3288. if ((!p->AnimationMode) || immediate){
  3289. laDeferredDestroyPanel(p, immediate);
  3290. }else{
  3291. p->LaterDestroy = 1;
  3292. }
  3293. }
  3294. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3295. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3296. int MinW,MinWt=0;
  3297. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3298. int CW = MAIN.CurrentWindow->CW;
  3299. if(p->SL && p->SR){return 0;}
  3300. la_SetPropMathcerContext(p);
  3301. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3302. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3303. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3304. MinW = la_TestUiListMinumWidth(uil);
  3305. if (MinW<MinWt){MinW=MinWt;}
  3306. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3307. if (MinW > 20){
  3308. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3309. }
  3310. la_PanelValidateWidth(p,uil);
  3311. laEnsurePanelInBound(p,uil);
  3312. if(p->TW>CW){ p->TW=CW; }
  3313. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3314. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3315. laRedrawPanel(p);
  3316. return 1;
  3317. }
  3318. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3319. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3320. laOperator *ai = a;
  3321. laPanel *p;
  3322. int GX, GY, GW, t = 0;
  3323. int b;
  3324. laUiDefineFunc def = ReplaceUiDefine;
  3325. int MinW;
  3326. if (!def){ def=laui_DefaultPropDetails; }
  3327. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3328. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3329. laEnclosePanelContent(p, &p->UI);
  3330. laSetOperatorLocalizer(p);
  3331. p->CloseWhenMovedOut=1;
  3332. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3333. //laShowPanelWithDropDownEffect(p);
  3334. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3335. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3336. return p;
  3337. }
  3338. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3339. laPanel *p;
  3340. int GX, GY, GW, t = 0;
  3341. int b;
  3342. laUiDefineFunc def = ReplaceUiDefine;
  3343. int MinW;
  3344. if (!def) return 0;
  3345. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3346. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3347. p->Mode = LA_PANEL_FLOATING_TOP;
  3348. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3349. laEnclosePanelContent(p, &p->UI);
  3350. if(MAIN.CurrentWindow->Operators.pFirst){
  3351. laSetOperatorLocalizer(MAIN.PendingSplash);
  3352. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3353. MAIN.PendingSplash=0;
  3354. }
  3355. //laShowPanelWithExpandEffect(p);
  3356. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3357. return p;
  3358. }
  3359. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3360. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3361. laOperator *ai = a;
  3362. laPanel *p; laPropContainer* sub;
  3363. int GX, GY, GW, t = 0;
  3364. int b;
  3365. laUiDefineFunc def = ReplaceUiDefine;
  3366. int MinW;
  3367. if (!def){
  3368. if (This && This->LastPs->p){
  3369. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3370. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3371. }
  3372. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3373. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3374. }
  3375. GX = L; GY = B;
  3376. GW = (R - L) > MaxW ? MaxW : (R - L);
  3377. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3378. laEnclosePanelContent(p, &p->UI);
  3379. laSetOperatorLocalizer(p);
  3380. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3381. laShowPanelWithDropDownEffect(p);
  3382. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3383. if(Attachment){
  3384. p->Parent = Attachment;
  3385. lstAppendItem(&Attachment->SubPanels, p);
  3386. }
  3387. return p;
  3388. }
  3389. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3390. laPanel *p;
  3391. int t = 0;
  3392. int b;
  3393. //laLocalToWindow(0, Attachment, &L, &t);
  3394. //laLocalToWindow(0, Attachment, &R, &U);
  3395. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3396. laSetOperatorLocalizer(p);
  3397. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3398. laShowPanelWithDropDownEffect(p);
  3399. p->Parent = Attachment;
  3400. lstPushItem(&Attachment->SubPanels, p);
  3401. return p;
  3402. }
  3403. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3404. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3405. laOperator *ai = a;
  3406. laPanel *p;
  3407. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3408. int GX, GY, GW, t = 0;
  3409. int b;
  3410. int MinW;
  3411. //laLocalToWindow(0,Attachment, &L, &t);
  3412. //laLocalToWindow(0,Attachment, &R, &B);
  3413. GX = L;
  3414. GY = B;
  3415. GW = (R - L) > MaxW ? MaxW : (R - L);
  3416. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3417. p->MenuRefer = MenuRefer;
  3418. laEnclosePanelContent(p, MenuRefer);
  3419. laSetOperatorLocalizer(p);
  3420. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3421. laShowPanelWithDropDownEffect(p);
  3422. p->Parent = Attachment;
  3423. lstPushItem(&Attachment->SubPanels, p);
  3424. return p;
  3425. }
  3426. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3427. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3428. laOperator *ai = a;
  3429. laPanel *p;
  3430. int GX, GY, GW, t = 0;
  3431. int b;
  3432. GX = L;
  3433. GY = B;
  3434. GW = MaxW;
  3435. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3436. p->MenuRefer = &p->UI;
  3437. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3438. laSetOperatorLocalizer(p);
  3439. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3440. laShowPanelWithDropDownEffect(p);
  3441. if (Attachment){
  3442. p->Parent = Attachment;
  3443. lstPushItem(&Attachment->SubPanels, p);
  3444. }else{
  3445. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3446. }
  3447. return p;
  3448. }
  3449. 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){
  3450. laOperator *ai = For;
  3451. laPanel *p;
  3452. int b;
  3453. laUiDefineFunc def = 0;
  3454. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3455. else def = laui_DefaultPropUiDefine;
  3456. For->PP.EndInstance = For->CustomData;
  3457. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3458. laEnclosePanelContent(p, &p->UI);
  3459. MAIN.ToPanel = p;
  3460. laShowPanelWithExpandEffect(p);
  3461. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3462. ai->OperatorPanel = p;
  3463. p->ParentOperator = For;
  3464. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3465. return p;
  3466. }
  3467. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3468. laPanel *p; int b; laUiList *uil; laColumn* col;
  3469. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3470. strSafeSet(&p->Title, Title);
  3471. p->BoundUi = 1;
  3472. p->Mode = LA_PANEL_FLOATING_TOP;
  3473. p->BT = &_LA_THEME_FLOATING_PANEL;
  3474. MAIN.ToPanel = p;
  3475. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3476. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3477. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3478. laUiItem* r=laBeginRow(uil,col,0,0);
  3479. laShowSeparator(uil,col)->Expand=1;
  3480. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3481. laEndRow(uil,r);
  3482. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3483. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3484. laSetOperatorLocalizer(p);
  3485. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3486. return p;
  3487. }
  3488. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3489. laPanel *p; int b; laUiList *uil; laColumn* col;
  3490. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3491. strSafeSet(&p->Title, Title);
  3492. p->BoundUi = 1;
  3493. p->Mode = LA_PANEL_FLOATING_TOP;
  3494. p->BT = &_LA_THEME_FLOATING_PANEL;
  3495. MAIN.ToPanel = p;
  3496. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3497. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3498. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3499. laUiItem* r = laBeginRow(uil,col,0,0);
  3500. laShowSeparator(uil,col)->Expand=1;
  3501. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3502. laEndRow(uil, r);
  3503. laEnclosePanelContent(p,uil);
  3504. laShowPanelWithExpandEffect(p);
  3505. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3506. laSetOperatorLocalizer(p);
  3507. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3508. return p;
  3509. }
  3510. void laOperatorModalOver(laOperator* For){
  3511. For->ModalOver = 1;
  3512. }
  3513. void laDeferredRedraw(laPanel* p){
  3514. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3515. if(lip->p==p) return;
  3516. }
  3517. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3518. }
  3519. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3520. laWindow* cur=MAIN.CurrentWindow;
  3521. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3522. MAIN.CurrentWindow=w;
  3523. la_UpdateUiPlacement(w);
  3524. }
  3525. MAIN.CurrentWindow=cur;
  3526. }
  3527. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3528. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3529. }
  3530. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3531. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3532. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3533. void laRedrawCurrentPanel(){
  3534. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3535. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3536. }
  3537. void laRecalcCurrentPanel(){
  3538. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3539. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3540. }
  3541. void laRecalcPanelImmediate(laPanel* p){
  3542. p->FrameDistinguish++;
  3543. laBoxedTheme* bt = (*p->BT);
  3544. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3545. la_PanelRefreshDetachedProp(p);
  3546. int enclosed=0;
  3547. if(p->BoundUi || p->MenuRefer){
  3548. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3549. else enclosed=laEnclosePanelContent(p, &p->UI);
  3550. }
  3551. if(!enclosed){
  3552. la_PanelValidateWidth(p,&p->UI);
  3553. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3554. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3555. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3556. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3557. }
  3558. laWindow* w=MAIN.CurrentWindow;
  3559. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3560. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3561. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3562. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3563. }
  3564. }
  3565. void laRecalcCurrentPanelImmediate(){
  3566. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3567. }
  3568. int laNonFixedPanelExists(laPanel *p){
  3569. laPanel *ip;
  3570. if (!p) return 0;
  3571. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3572. // if (ip == p) return 1;
  3573. //}
  3574. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3575. if (ip == p) return 1;
  3576. }
  3577. return 0;
  3578. }
  3579. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3580. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3581. return 1;
  3582. }
  3583. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3584. int tt=MAIN.TooltipCloseDistance;
  3585. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3586. return 1;
  3587. }
  3588. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3589. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3590. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3591. return 0;
  3592. return 1;
  3593. }
  3594. void laUnlinkSharedPanel(laPanel *p){
  3595. laWindow *w;
  3596. laPanel *ip;
  3597. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3598. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3599. if (ip == p){
  3600. lstRemoveItem(&w->Panels, ip);
  3601. return;
  3602. }
  3603. }
  3604. }
  3605. }
  3606. int laIsPanelCovered(laPanel *p){
  3607. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3608. laPanel *ip;
  3609. laPanel *resp;
  3610. int in1 = 0, in2 = 0, in3 = 0;
  3611. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3612. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3613. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3614. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3615. //}
  3616. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3617. if (ip == p){
  3618. in3 = 1;
  3619. d3 = 0;
  3620. continue;
  3621. }
  3622. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3623. }
  3624. if (!in2 && !in3) in1 = 1;
  3625. if (in1){
  3626. if (d1 || d2 || d3) return 1;
  3627. }else{
  3628. if (in2){
  3629. if (d2 || d3) return 1;
  3630. }else if (in3)
  3631. if (d3) return 1;
  3632. }
  3633. return 0;
  3634. }
  3635. int laIsTopPanel(laPanel *p){
  3636. //if (!p->Item.pPrev) return 1;
  3637. //else {
  3638. if (!laIsPanelCovered(p)){
  3639. //laPopPanel(p);
  3640. return 1;
  3641. }
  3642. return 0;
  3643. //}
  3644. return 0;
  3645. }
  3646. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3647. if(!p) return;
  3648. int ix = *x, iy = *y;
  3649. laListItemPointer *lip;
  3650. laOperator *ai = a;
  3651. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3652. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3653. if (a){
  3654. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3655. laUiList *uil = lip->p;
  3656. (*x) += uil->PanX;
  3657. (*y) += uil->PanY;
  3658. }
  3659. }
  3660. }
  3661. void laPanelToLocal(laOperator *a, int *x, int *y){
  3662. int ix = *x, iy = *y;
  3663. laListItemPointer *lip;
  3664. if (a){
  3665. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3666. laUiList *uil = lip->p;
  3667. (*x) += uil->PanX;
  3668. (*y) += uil->PanY;
  3669. }
  3670. }
  3671. }
  3672. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3673. if(!p) return;
  3674. int ix = *x, iy = *y;
  3675. laListItemPointer *lip;
  3676. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3677. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3678. if (a){
  3679. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3680. laUiList *uil = lip->p;
  3681. (*x) -= uil->PanX;
  3682. (*y) -= uil->PanY;
  3683. }
  3684. }
  3685. }
  3686. void laPanelToWindow(laPanel *p, int *x, int *y){
  3687. int ix = *x, iy = *y;
  3688. laListItemPointer *lip;
  3689. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3690. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3691. }
  3692. void laLocalToPanel(laOperator *a, int *x, int *y){
  3693. int ix = *x, iy = *y;
  3694. laListItemPointer *lip;
  3695. if (a){
  3696. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3697. laUiList *uil = lip->p;
  3698. (*x) -= uil->PanX;
  3699. (*y) -= uil->PanY;
  3700. }
  3701. }
  3702. }
  3703. void laSetNextMenuPos(int X, int Y, int W, int H){
  3704. MAIN.NextX = X;
  3705. MAIN.NextY = Y;
  3706. MAIN.NextW = W;
  3707. MAIN.NextH = H;
  3708. }
  3709. int laIsInBlock(laBlock *b, int X, int Y){
  3710. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3711. return 0;
  3712. }
  3713. 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; }
  3714. 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; }
  3715. 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; }
  3716. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3717. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3718. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3719. if (!b->B1 && !b->B2){
  3720. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3721. }
  3722. }
  3723. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3724. laPanel *p;
  3725. laBlock *sb = 0;
  3726. if (!laIsInBlock(b, X, Y)) return 0;
  3727. if (!b->B1 && !b->B2) return b;
  3728. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3729. return laDetectBlockRecursive(b->B2, X, Y);
  3730. }
  3731. laPanel *laDetectPanel(int X, int Y){
  3732. laPanel *p; laBlock *b;
  3733. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3734. int x = X, y = Y;
  3735. laWindowToLocal(0, p, &x, &y);
  3736. if (p->Show && laIsInPanel(p, x, y)){
  3737. return p;
  3738. }
  3739. }
  3740. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3741. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3742. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3743. return 0;
  3744. }
  3745. laUiList *laPrepareUi(laPanel *p){
  3746. return &p->UI;
  3747. }
  3748. laColumn *laFirstColumn(laUiList *uil){
  3749. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3750. else{
  3751. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3752. c->SP = 1;
  3753. c->PreWidth = 1;
  3754. lstAppendItem(&uil->Columns, c);
  3755. c->Top = c;
  3756. return uil->Columns.pFirst;
  3757. }
  3758. }
  3759. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3760. laColumn *lc, *rc;
  3761. if (c->LS || c->RS) return c;
  3762. lc = memAcquireSimple(sizeof(laColumn));
  3763. rc = memAcquireSimple(sizeof(laColumn));
  3764. c->LS = lc;
  3765. c->RS = rc;
  3766. c->LS->SP = Percent;
  3767. c->RS->SP = Percent;
  3768. c->LS->Top = c->Top;
  3769. c->RS->Top = c->Top;
  3770. if (uil){
  3771. lstAppendItem(&uil->Columns, lc);
  3772. lstAppendItem(&uil->Columns, rc);
  3773. }
  3774. if (c->LS && c->RS->MaxW == 0){
  3775. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3776. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3777. }else if (c->RS && c->LS->MaxW == 0){
  3778. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3779. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3780. }
  3781. return c;
  3782. }
  3783. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3784. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3785. return c->LS;
  3786. }
  3787. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3788. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3789. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3790. return c->RS;
  3791. }
  3792. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3793. lstRemoveItem(List, c);
  3794. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3795. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3796. memFree(c);
  3797. }
  3798. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3799. laUiList *uil = TopUil;
  3800. laUiList *sub;
  3801. laUiItem *ui;
  3802. laColumn *cc, *NextCC = 0;
  3803. int Occupied = 0;
  3804. int Removed = 0;
  3805. if (!c->LS) return 0;
  3806. else{
  3807. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3808. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3809. }
  3810. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3811. if (ui->C == c->LS || ui->C == c->RS){
  3812. if (DoMerge){
  3813. ui->C = c;
  3814. Occupied = 1;
  3815. }else
  3816. return 1;
  3817. }
  3818. if (ui->Subs.pFirst){
  3819. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3820. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3821. }
  3822. }
  3823. }
  3824. if (!Removed){
  3825. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3826. if (cc == c){
  3827. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3828. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3829. c->LS = 0;
  3830. c->RS = 0;
  3831. Removed = 1;
  3832. break;
  3833. }
  3834. }
  3835. }
  3836. return Occupied;
  3837. }
  3838. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3839. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3840. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3841. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3842. ut->FakeProp->Base.Identifier = ut->Identifier;
  3843. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3844. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3845. ut->FakeProp->Base.OffsetIsPointer = 1;
  3846. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3847. return ut->ExtraProps;
  3848. }
  3849. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3850. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3851. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3852. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3853. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3854. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3855. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3856. ct->FakeProp->Base.OffsetIsPointer = 1;
  3857. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3858. return ct->ExtraProps;
  3859. }
  3860. void la_DestroyUiType(laUiType* uit){
  3861. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3862. memFree(uit);
  3863. }
  3864. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3865. laUiType *ut = memAcquire(sizeof(laUiType));
  3866. ut->Identifier = Identifer;
  3867. ut->OperatorID = UseOperator;
  3868. ut->Draw = Draw;
  3869. ut->Theme = bt;
  3870. ut->ForType = ForType;
  3871. ut->OperatorType = laGetOperatorType(UseOperator);
  3872. ut->GetHeight = GetHeight;
  3873. ut->Init = Init;
  3874. ut->Destroy = Destroy;
  3875. la_UDFAppendSharedTypePointer(Identifer, ut);
  3876. lstAppendItem(&MAIN.UiTypes, ut);
  3877. return ut;
  3878. }
  3879. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3880. laUiType *ut = MAIN.UiTypes.pFirst;
  3881. if (!P) return 0;
  3882. if (P->DefaultUiType) return P->DefaultUiType;
  3883. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3884. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3885. for (ut; ut; ut = ut->Item.pNext){
  3886. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3887. return ut;
  3888. }
  3889. }
  3890. return 0;
  3891. }
  3892. laUiType *la_GetUiButtonType(){
  3893. laUiType *ut = MAIN.UiTypes.pFirst;
  3894. for (ut; ut; ut = ut->Item.pNext){
  3895. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3896. }
  3897. return 0;
  3898. }
  3899. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3900. laCanvasTemplate *vdt;
  3901. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3902. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3903. }
  3904. return 0;
  3905. }
  3906. void la_AssignPropExtras(laUiItem* ui){
  3907. if(!ui->Type || !ui->Type->FakeProp) return;
  3908. ui->FakePs.p = ui->Type->FakeProp;
  3909. ui->FakePs.Type = U'.';
  3910. ui->FakePs.UseInstance = ui;
  3911. ui->ExtraPP.LastPs = &ui->FakePs;
  3912. }
  3913. void la_AssignCanvasPropExtras(laUiItem* ui){
  3914. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3915. laCanvasTemplate*ct=ui->CanvasTemplate;
  3916. ui->FakePs.p = ct->FakeProp;
  3917. ui->FakePs.Type = U'.';
  3918. ui->FakePs.UseInstance = ui;
  3919. ui->ExtraPP.EndInstance = ui->Extra;
  3920. ui->ExtraPP.LastPs = &ui->FakePs;
  3921. }
  3922. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3923. int result;
  3924. if (!ui) return 0;
  3925. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3926. if (Path){
  3927. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3928. if (!result){
  3929. ui->AT = laGetOperatorType(Path);
  3930. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3931. ui->Type = la_GetUiButtonType();
  3932. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3933. }else{
  3934. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3935. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3936. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3937. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3938. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3939. }
  3940. if (Base){
  3941. ui->PP.RawThis = Base;
  3942. }
  3943. }else if (Base){
  3944. ui->PP.LastPs = Base->LastPs;
  3945. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3946. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3947. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3948. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3949. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3950. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3951. }
  3952. la_AssignPropExtras(ui);
  3953. if(Widget){ ui->Flags|= Widget->Flags; }
  3954. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3955. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3956. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3957. return ui;
  3958. }
  3959. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3960. ui->Type = _LA_UI_LABEL;
  3961. ui->Template = Template;
  3962. ui->State = LA_UI_NORMAL;
  3963. strSafeSet(&ui->Display, Content);
  3964. la_AssignPropExtras(ui);
  3965. return ui;
  3966. }
  3967. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3968. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3969. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3970. ui->State = LA_UI_NORMAL;
  3971. la_AssignPropExtras(ui);
  3972. return ui;
  3973. }
  3974. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3975. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3976. transLate(Content);
  3977. la_UpdateLabelDisplay(ui, Template, Content);
  3978. ui->C = c;
  3979. if (ui->Type->Init) ui->Type->Init(ui);
  3980. ui->ExtraPP.EndInstance = ui->Extra;
  3981. lstAppendItem(&uil->UiItems, ui);
  3982. return ui;
  3983. }
  3984. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3985. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3986. la_UpdateLabelDisplay(ui, Template, Content);
  3987. ui->C = c;
  3988. if (ui->Type->Init) ui->Type->Init(ui);
  3989. ui->ExtraPP.EndInstance = ui->Extra;
  3990. lstAppendItem(&uil->UiItems, ui);
  3991. return ui;
  3992. }
  3993. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3994. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3995. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3996. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3997. ui->C = c;
  3998. if (ui->Type->Init) ui->Type->Init(ui);
  3999. ui->ExtraPP.EndInstance = ui->Extra;
  4000. lstAppendItem(&uil->UiItems, ui);
  4001. return ui;
  4002. }
  4003. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4004. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  4005. }
  4006. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4007. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4008. }
  4009. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4010. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4011. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4012. ui->C = c;
  4013. ui->TemplateContext = TemplateContext;
  4014. if (ui->Type->Init) ui->Type->Init(ui);
  4015. ui->ExtraPP.EndInstance = ui->Extra;
  4016. lstAppendItem(&uil->UiItems, ui);
  4017. return ui;
  4018. }
  4019. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4020. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4021. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4022. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4023. ui->SymbolID=Height;
  4024. lstAppendItem(&uil->UiItems, ui);
  4025. return ui;
  4026. }
  4027. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4028. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4029. }
  4030. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4031. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4032. }
  4033. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4034. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4035. ui->Type = _LA_UI_CANVAS;
  4036. ui->State = LA_UI_NORMAL;
  4037. ui->C = c;
  4038. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4039. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4040. else{
  4041. 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); }
  4042. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4043. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4044. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4045. }
  4046. if (ui->Type->Init) ui->Type->Init(ui);
  4047. la_AssignCanvasPropExtras(ui);
  4048. if (Height) ui->Expand=Height; else ui->Expand=6;
  4049. lstAppendItem(&uil->UiItems, ui);
  4050. return ui;
  4051. }
  4052. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4053. laUiItem* ui=0;
  4054. #define ADD_CANVAS \
  4055. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4056. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4057. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4058. }laEndCondition(uil,b3);\
  4059. laEndRow(uil,b);
  4060. if(Detached){
  4061. laColumn* cl,*cll,*clr,*cr;
  4062. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4063. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4064. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4065. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4066. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4067. ADD_CANVAS
  4068. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4069. }laElse(uil,b2);{
  4070. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4071. ADD_CANVAS
  4072. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4073. }laEndCondition(uil,b2);
  4074. }else{
  4075. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4076. }
  4077. #undef ADD_CANVAS
  4078. }
  4079. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4080. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4081. laCanvasExtra *e;
  4082. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4083. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4084. ui->C = c;
  4085. if (ui->Type->Init) ui->Type->Init(ui);
  4086. ui->ExtraPP.EndInstance = ui->Extra;
  4087. lstAppendItem(&uil->UiItems, ui);
  4088. return ui;
  4089. }
  4090. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4091. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4092. ui->Type = _LA_UI_SYMBOL;
  4093. ui->SymbolID = SymbolID;
  4094. if (Height) ui->State = Height;
  4095. ui->C = c;
  4096. if (ui->Type->Init) ui->Type->Init(ui);
  4097. ui->ExtraPP.EndInstance = ui->Extra;
  4098. lstAppendItem(&uil->UiItems, ui);
  4099. return ui;
  4100. }
  4101. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4102. laPropPack PP={0}; int result;
  4103. if (Path){
  4104. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4105. if (!result){ return 0; }
  4106. if (Base){ PP.RawThis = Base; }
  4107. }else if (Base){
  4108. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4109. }
  4110. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4111. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4112. lstAppendItem(&ui->CompoundPPs,CPP);
  4113. return &CPP->PP;
  4114. }
  4115. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4116. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4117. ui->Type = &_LA_UI_ROW_BEGIN;
  4118. ui->State=Expand;
  4119. ui->Flags=Even;
  4120. ui->C = c;
  4121. if (ui->Type->Init) ui->Type->Init(ui);
  4122. ui->ExtraPP.EndInstance = ui->Extra;
  4123. lstAppendItem(&uil->UiItems, ui);
  4124. return ui;
  4125. }
  4126. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4127. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4128. ui->Type = &_LA_UI_ROW_END;
  4129. ui->C = Begin->C;
  4130. ui->Page = (laUiList*)Begin;
  4131. if (ui->Type->Init) ui->Type->Init(ui);
  4132. ui->ExtraPP.EndInstance = ui->Extra;
  4133. lstAppendItem(&uil->UiItems, ui);
  4134. return ui;
  4135. }
  4136. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4137. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4138. e->Expression = Expression;
  4139. ui->Extra = e;
  4140. la_AssignPropExtras(ui);
  4141. }
  4142. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4143. laUiItem *ui = la_CreateGroupHandle(Widget);
  4144. laUiList *nuil;
  4145. ui->C = c;
  4146. lstAppendItem(&uil->UiItems, ui);
  4147. nuil = memAcquireSimple(sizeof(laUiList));
  4148. strSafeSet(&nuil->TabName, Name);
  4149. ui->Page = nuil;
  4150. lstAppendItem(&ui->Subs, nuil);
  4151. if (ui->Type->Init) ui->Type->Init(ui);
  4152. ui->ExtraPP.EndInstance = ui->Extra;
  4153. return ui;
  4154. }
  4155. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4156. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4157. laUiList *sub = SubUi->Page;
  4158. laColumn *s = laFirstColumn(sub);
  4159. SubUi->State = LA_UI_ACTIVE;
  4160. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4161. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4162. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4163. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4164. laShowSeparator(sub, s);
  4165. return SubUi;
  4166. }
  4167. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4168. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4169. laUiList *sub = SubUi->Page;
  4170. laColumn *s = laFirstColumn(sub);
  4171. SubUi->State = LA_UI_ACTIVE;
  4172. return SubUi;
  4173. }
  4174. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4175. laEndCondition(sub, sub->UiItems.pFirst);
  4176. }
  4177. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4178. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4179. laUiList *nuil;
  4180. ui->C = c;
  4181. lstAppendItem(&uil->UiItems, ui);
  4182. if (ui->Type->Init) ui->Type->Init(ui);
  4183. ui->ExtraPP.EndInstance = ui->Extra;
  4184. return ui;
  4185. }
  4186. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4187. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4188. if (!ui->Page) ui->Page = uil;
  4189. lstAppendItem(&ui->Subs, uil);
  4190. strSafeSet(&uil->TabName, Name);
  4191. laFirstColumn(uil);
  4192. //laFirstColumn(uil);
  4193. return uil;
  4194. }
  4195. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4196. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4197. /*if (!ui->Page) */ ui->Page = uil;
  4198. lstAppendItem(&ui->Subs, uil);
  4199. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4200. return uil;
  4201. }
  4202. laUiConditionNode *laTrue(){
  4203. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4204. ucn->Type = LA_CONDITION_TRUE;
  4205. return ucn;
  4206. }
  4207. laUiConditionNode *laFalse(){
  4208. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4209. ucn->Type = LA_CONDITION_FALSE;
  4210. return ucn;
  4211. }
  4212. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4213. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4214. ucn->Type = LA_CONDITION_PROP;
  4215. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4216. strSafeSet(&ucn->String, Prop);
  4217. return ucn;
  4218. }
  4219. laUiConditionNode *laIntExpression(int Value){
  4220. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4221. ucn->Type = LA_CONDITION_INT;
  4222. ucn->IntValue = Value;
  4223. return ucn;
  4224. }
  4225. laUiConditionNode *laFloatExpression(real Value){
  4226. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4227. ucn->Type = LA_CONDITION_FLOAT;
  4228. ucn->FloatValue = Value;
  4229. return ucn;
  4230. }
  4231. laUiConditionNode *laStringExpression(char *Content){
  4232. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4233. ucn->Type = LA_CONDITION_STRING;
  4234. strSafeSet(&ucn->String, Content);
  4235. return ucn;
  4236. }
  4237. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4238. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4239. ucn->Type = LA_CONDITION_AND;
  4240. ucn->Expression1 = Expression1;
  4241. ucn->Expression2 = Expression2;
  4242. return ucn;
  4243. }
  4244. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4245. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4246. ucn->Type = LA_CONDITION_OR;
  4247. ucn->Expression1 = Expression1;
  4248. ucn->Expression2 = Expression2;
  4249. return ucn;
  4250. }
  4251. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4252. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4253. ucn->Type = LA_CONDITION_NOT;
  4254. ucn->Expression1 = Expression1;
  4255. return ucn;
  4256. }
  4257. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4258. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4259. ucn->Type = LA_CONDITION_EQ;
  4260. ucn->Expression1 = Expression1;
  4261. ucn->Expression2 = Expression2;
  4262. return ucn;
  4263. }
  4264. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4265. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4266. ucn->Type = LA_CONDITION_GT;
  4267. ucn->Expression1 = Expression1;
  4268. ucn->Expression2 = Expression2;
  4269. return ucn;
  4270. }
  4271. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4272. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4273. ucn->Type = LA_CONDITION_LT;
  4274. ucn->Expression1 = Expression1;
  4275. ucn->Expression2 = Expression2;
  4276. return ucn;
  4277. }
  4278. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4279. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4280. ucn->Type = LA_CONDITION_GE;
  4281. ucn->Expression1 = Expression1;
  4282. ucn->Expression2 = Expression2;
  4283. return ucn;
  4284. }
  4285. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4286. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4287. ucn->Type = LA_CONDITION_LE;
  4288. ucn->Expression1 = Expression1;
  4289. ucn->Expression2 = Expression2;
  4290. return ucn;
  4291. }
  4292. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4293. if (Expression->Type != LA_CONDITION_INT) return 0;
  4294. return Expression->IntValue;
  4295. }
  4296. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4297. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4298. return Expression->FloatValue;
  4299. }
  4300. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4301. return Expression->String->Ptr;
  4302. }
  4303. 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){
  4304. switch (Mode1){
  4305. case LA_PROP_ENUM:
  4306. case LA_PROP_INT:
  4307. case LA_CONDITION_INT:
  4308. switch (Mode2){
  4309. case LA_PROP_ENUM:
  4310. case LA_PROP_INT:
  4311. case LA_CONDITION_INT:
  4312. switch (CompMode){
  4313. case LA_CONDITION_GE:
  4314. return (i1 >= i2);
  4315. case LA_CONDITION_GT:
  4316. return (i1 > i2);
  4317. case LA_CONDITION_EQ:
  4318. return (i1 == i2);
  4319. case LA_CONDITION_LT:
  4320. return (i1 < i2);
  4321. case LA_CONDITION_LE:
  4322. return (i1 <= i2);
  4323. }
  4324. case LA_PROP_FLOAT:
  4325. case LA_CONDITION_FLOAT:
  4326. switch (CompMode){
  4327. case LA_CONDITION_GE:
  4328. return ((real)i1 >= f2);
  4329. case LA_CONDITION_GT:
  4330. return ((real)i1 > f2);
  4331. case LA_CONDITION_EQ:
  4332. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4333. case LA_CONDITION_LT:
  4334. return ((real)i1 < f2);
  4335. case LA_CONDITION_LE:
  4336. return ((real)i1 <= f2);
  4337. }
  4338. case LA_PROP_SUB:
  4339. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4340. default:
  4341. return 0;
  4342. }
  4343. case LA_PROP_FLOAT:
  4344. case LA_CONDITION_FLOAT:
  4345. switch (Mode2){
  4346. case LA_PROP_INT:
  4347. case LA_PROP_ENUM:
  4348. case LA_CONDITION_INT:
  4349. switch (CompMode){
  4350. case LA_CONDITION_GE:
  4351. return (f1 >= (real)i2);
  4352. case LA_CONDITION_GT:
  4353. return (f1 > (real)i2);
  4354. case LA_CONDITION_EQ:
  4355. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4356. case LA_CONDITION_LT:
  4357. return (f1 < (real)i2);
  4358. case LA_CONDITION_LE:
  4359. return (f1 <= (real)i2);
  4360. }
  4361. case LA_PROP_FLOAT:
  4362. case LA_CONDITION_FLOAT:
  4363. switch (CompMode){
  4364. case LA_CONDITION_GE:
  4365. return (f1 >= f2);
  4366. case LA_CONDITION_GT:
  4367. return (f1 > f2);
  4368. case LA_CONDITION_EQ:
  4369. return (f1 == f2);
  4370. case LA_CONDITION_LT:
  4371. return (f1 < f2);
  4372. case LA_CONDITION_LE:
  4373. return (f1 <= f2);
  4374. }
  4375. default:
  4376. return 0;
  4377. }
  4378. case LA_PROP_STRING:
  4379. case LA_CONDITION_STRING:
  4380. switch (Mode2){
  4381. case LA_PROP_STRING:
  4382. case LA_CONDITION_STRING:
  4383. return strSame(s1, s2);
  4384. default:
  4385. return 0;
  4386. }
  4387. case LA_PROP_SUB:
  4388. switch (Mode2){
  4389. case LA_PROP_SUB:
  4390. return p1 == p2;
  4391. case LA_CONDITION_INT:
  4392. case LA_PROP_INT:
  4393. case LA_PROP_ENUM:
  4394. return (int)p1 == i2;
  4395. default:
  4396. return 0;
  4397. }
  4398. default:
  4399. switch (CompMode){
  4400. case LA_CONDITION_GE:
  4401. return (i1 >= i2);
  4402. case LA_CONDITION_GT:
  4403. return (i1 > i2);
  4404. case LA_CONDITION_EQ:
  4405. return (i1 == i2);
  4406. case LA_CONDITION_LT:
  4407. return (i1 < i2);
  4408. case LA_CONDITION_LE:
  4409. return (i1 <= i2);
  4410. }
  4411. }
  4412. }
  4413. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4414. void *Instance = 0;
  4415. int IValue1 = 0, IValue2 = 0;
  4416. real FValue1 = 0, FValue2 = 0;
  4417. void *Ptr1 = 0, *Ptr2 = 0;
  4418. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4419. int Result1, Result2;
  4420. laEnumItem *ei; laSubProp*sp;
  4421. if (!Expression) return 0;
  4422. Str1[0] = 0;
  4423. Str2[0] = 0;
  4424. laPropIterator pi = {0};
  4425. switch (Expression->Type){
  4426. case LA_CONDITION_PROP:
  4427. if (!Expression->PP.LastPs){
  4428. (*IResult) = 0;
  4429. return 0;
  4430. }
  4431. switch (Expression->PP.LastPs->p->PropertyType){
  4432. case LA_PROP_INT:
  4433. *IResult = laGetInt(&Expression->PP);
  4434. if (*IResult) return LA_CONDITION_INT;
  4435. else return 0;
  4436. case LA_PROP_FLOAT:
  4437. *FResult = laGetFloat(&Expression->PP);
  4438. if (*FResult) return 1;
  4439. else return 0;
  4440. break;
  4441. case LA_PROP_STRING:
  4442. laGetString(&Expression->PP, _StrResult, &StrResult);
  4443. if (StrResult[0]) return 1;
  4444. else return 0;
  4445. break;
  4446. case LA_PROP_ENUM:
  4447. ei = laGetEnum(&Expression->PP);
  4448. if (!ei) return 0;
  4449. /*if(ei) */ *IResult = ei->Index;
  4450. if (*IResult) return LA_CONDITION_INT;
  4451. else return 0;
  4452. break;
  4453. case LA_PROP_SUB:
  4454. sp=Expression->PP.LastPs->p;
  4455. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4456. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4457. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4458. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4459. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4460. }
  4461. }
  4462. *PtrResult = Instance;
  4463. if (Instance) return 1;
  4464. break;
  4465. default:
  4466. return 0;
  4467. }
  4468. break;
  4469. case LA_CONDITION_INT:
  4470. *IResult = Expression->IntValue;
  4471. if (*IResult) return 1;
  4472. else
  4473. return 0;
  4474. case LA_CONDITION_FLOAT:
  4475. *FResult = Expression->FloatValue;
  4476. if (*FResult) return 1;
  4477. else
  4478. return 0;
  4479. case LA_CONDITION_STRING:
  4480. if (Expression->String){
  4481. strCopyFull(StrResult, Expression->String->Ptr);
  4482. return 1;
  4483. }else
  4484. return 0;
  4485. case LA_CONDITION_TRUE:
  4486. if (*IResult) *IResult = 1;
  4487. return 1;
  4488. case LA_CONDITION_FALSE:
  4489. if (*IResult) *IResult = 0;
  4490. return 0;
  4491. default:
  4492. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4493. switch (Expression->Type){
  4494. case LA_CONDITION_AND:
  4495. if (Result1){
  4496. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4497. if (Result2) *IResult = 1;
  4498. return (Result2);
  4499. }else
  4500. return 0;
  4501. case LA_CONDITION_OR:
  4502. if (!Result1){
  4503. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4504. if (Result2) *IResult = 1;
  4505. return (Result2);
  4506. }else
  4507. return 1;
  4508. case LA_CONDITION_NOT:
  4509. return !Result1;
  4510. default:
  4511. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4512. return la_DoCompare(Expression->Type,
  4513. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4514. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4515. }
  4516. break;
  4517. }
  4518. return 0;
  4519. }
  4520. int la_DoSingleExpression(laUiConditionNode *Expression){
  4521. int a;
  4522. real b;
  4523. char c[128]={0};
  4524. void *p;
  4525. if (!Expression) return 1;
  4526. c[0] = 0;
  4527. return la_DoExpression(Expression, &a, &b, c, &p);
  4528. }
  4529. void la_StepExpression(laUiConditionNode *e){
  4530. if (!e) return;
  4531. switch (e->Type){
  4532. case LA_CONDITION_AND:
  4533. case LA_CONDITION_OR:
  4534. case LA_CONDITION_GE:
  4535. case LA_CONDITION_GT:
  4536. case LA_CONDITION_EQ:
  4537. case LA_CONDITION_LT:
  4538. case LA_CONDITION_LE:
  4539. la_StepExpression(e->Expression1);
  4540. la_StepExpression(e->Expression2);
  4541. break;
  4542. case LA_CONDITION_NOT:
  4543. la_StepExpression(e->Expression1);
  4544. break;
  4545. case LA_CONDITION_PROP:
  4546. la_StepPropPack(&e->PP);
  4547. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4548. la_UsePropPack(&e->PP, 1);
  4549. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4550. //}
  4551. break;
  4552. default:
  4553. break;
  4554. }
  4555. }
  4556. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4557. if (!ucn) return;
  4558. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4559. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4560. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4561. if (ucn->String) strSafeDestroy(&ucn->String);
  4562. if (ucn) memFree(ucn);
  4563. }
  4564. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4565. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4566. ui->C = c;
  4567. ui->Type = &_LA_UI_CONDITION;
  4568. la_ConditionerInit(ui, Expression);
  4569. lstAppendItem(&uil->UiItems, ui);
  4570. return ui;
  4571. }
  4572. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4573. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4574. laConditionUiExtraData *cued;
  4575. ui->Type = &_LA_UI_CONDITION_ELSE;
  4576. la_ConditionerInit(ui, 0);
  4577. cued = ui->Extra;
  4578. cued->EndUi = Beginner;
  4579. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4580. ui->C = Beginner->C;
  4581. lstAppendItem(&uil->UiItems, ui);
  4582. return ui;
  4583. }
  4584. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4585. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4586. laConditionUiExtraData *cued;
  4587. ui->Template = define;
  4588. ui->C = col;
  4589. ui->PP.RawThis = ExtraBase;
  4590. ui->Page = ExtraThis;
  4591. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4592. la_ConditionerInit(ui, 0);
  4593. cued = ui->Extra;
  4594. //cued->Remove = Remove;
  4595. ui->State = LA_UI_NORMAL;
  4596. lstAppendItem(&uil->UiItems, ui);
  4597. return ui;
  4598. }
  4599. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4600. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4601. laConditionUiExtraData *cued;
  4602. ui->Type = &_LA_UI_CONDITION_END;
  4603. la_ConditionerInit(ui, 0);
  4604. cued = ui->Extra;
  4605. cued->EndUi = Beginner;
  4606. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4607. ui->C = Beginner->C;
  4608. lstAppendItem(&uil->UiItems, ui);
  4609. return ui;
  4610. }
  4611. laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags) {
  4612. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4613. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4614. ui->Type = _LA_UI_MENU_ROOT;
  4615. strSafeSet(&ui->Display, Title);
  4616. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4617. ui->C = c;
  4618. ui->Flags|=flags;
  4619. lstAppendItem(&uil->UiItems, ui);
  4620. lstAppendItem(&ui->Subs, muil);
  4621. return muil;
  4622. }
  4623. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4624. return laMakeMenuPageEx(uil,c,Title,0);
  4625. }
  4626. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4627. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4628. ui->Type = _LA_UI_ALIGN;
  4629. ui->C = widest;
  4630. lstAppendItem(&uil->UiItems, ui);
  4631. return ui;
  4632. }
  4633. void laFixHeight(laUiList *uil, short Rows){
  4634. if (!uil) return;
  4635. uil->HeightCoeff = Rows;
  4636. }
  4637. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4638. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4639. if (!ExtraColumns) return;
  4640. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4641. }
  4642. laUiTemplate *laFindUiTemplate(char *Identifier){
  4643. laUiTemplate *uit;
  4644. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4645. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4646. }
  4647. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4648. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4649. }
  4650. return 0;
  4651. }
  4652. void la_DestroyUiTemplate(laUiTemplate* uit){
  4653. strSafeDestroy(&uit->Identifier);
  4654. strSafeDestroy(&uit->Title);
  4655. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4656. memFree(uit);
  4657. }
  4658. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4659. strSafeDestroy(&uit->Identifier);
  4660. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4661. memFree(uit);
  4662. }
  4663. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4664. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4665. strSafeSet(&uit->Identifier, Identifier);
  4666. strSafeSet(&uit->Title, Title);
  4667. strSafeSet(&uit->CategoryName, NewCategory);
  4668. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4669. uit->DefaultGLFormat=DefaultGLFormat;
  4670. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4671. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4672. la_UDFAppendSharedTypePointer(Identifier, uit);
  4673. return uit;
  4674. }
  4675. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4676. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4677. strSafeSet(&t->Identifier, Identifier);
  4678. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4679. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4680. lstAppendItem(&MAIN.View2DTemplates, t);
  4681. la_UDFAppendSharedTypePointer(Identifier, t);
  4682. return t;
  4683. }
  4684. void laFinalizeUiTemplates(){
  4685. laUiTemplate *uit;
  4686. laCanvasTemplate *u2d;
  4687. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4688. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4689. }
  4690. }
  4691. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4692. laPanel *p;
  4693. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4694. if (p->PanelTemplate==uit){
  4695. return p;
  4696. }
  4697. }
  4698. return 0;
  4699. }
  4700. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4701. laUiList *uil, *NextUil;
  4702. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4703. NextUil = uil->Item.pNext;
  4704. lstRemoveItem(&ui->Subs, uil);
  4705. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4706. }
  4707. la_StopUiOperatorService(ui);
  4708. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4709. strSafeDestroy(&ui->Display);
  4710. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4711. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4712. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4713. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4714. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4715. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4716. }
  4717. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4718. memFree(ui);
  4719. }
  4720. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4721. laUiItem *ui, *NextUi;
  4722. laColumn *col, *NextCol;
  4723. if (!uil) return;
  4724. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4725. NextUi = ui->Item.pNext;
  4726. if(OnlyRemoveUser && RemoveUsers){
  4727. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4728. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4729. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4730. continue;
  4731. }
  4732. lstRemoveItem(&uil->UiItems, ui);
  4733. la_DestroyUiItem(ui, RemoveUsers);
  4734. }
  4735. if(OnlyRemoveUser){ return; }
  4736. for (col = uil->Columns.pFirst; col; col = NextCol){
  4737. NextCol = col->Item.pNext;
  4738. lstRemoveItem(&uil->Columns, col);
  4739. memFree(col);
  4740. }
  4741. strSafeDestroy(&uil->TabName);
  4742. if (!NoFree) memFree(uil);
  4743. }
  4744. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4745. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4746. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4747. }
  4748. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4749. laUiItem *Next = after->Item.pNext;
  4750. laUiItem *Last = uil->UiItems.pLast;
  4751. after->Item.pNext = 0;
  4752. uil->UiItems.pLast = after;
  4753. Define(uil, Base, This, ExtraColums, 0);
  4754. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4755. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4756. if (Next != Last) uil->UiItems.pLast = Last;
  4757. }
  4758. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4759. // int i = 0;
  4760. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4761. // if (!ui->ExtraColums) return;
  4762. // for (i; ui->ExtraColums[i]; i++) {
  4763. // laColumn* c = ui->ExtraColums[i];
  4764. // c->B = B;
  4765. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4766. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4767. // }
  4768. //}
  4769. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4770. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4771. }
  4772. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4773. laColumn *c = ui->C;
  4774. laColumn *ic = lst->pFirst;
  4775. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4776. for (ic; ic; ic = ic->Item.pNext){
  4777. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4778. ic->B = ic->B < c->B ? c->B : ic->B;
  4779. }
  4780. }
  4781. ic = ui->C;
  4782. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4783. ;
  4784. for (ic; ic; ic = ic->Item.pNext){
  4785. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4786. ic->B = ic->B < c->B ? c->B : ic->B;
  4787. }
  4788. }
  4789. }
  4790. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4791. laColumn *c = ui->C;
  4792. laColumn *ic = lst->pFirst;
  4793. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4794. for (ic; ic; ic = ic->Item.pNext){
  4795. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4796. ic->B = ic->B < c->B ? c->B : ic->B;
  4797. }
  4798. }
  4799. ic = ui->C;
  4800. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4801. ;
  4802. for (ic; ic; ic = ic->Item.pNext){
  4803. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4804. ic->B = ic->B < c->B ? c->B : ic->B;
  4805. }
  4806. }
  4807. }
  4808. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4809. int rep;
  4810. int sp;
  4811. int rev;
  4812. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4813. if (!c) return 0;
  4814. sp = (c->SP * (R - L)) + L;
  4815. rev = sp;
  4816. /*if (U)*/ c->B = U;
  4817. if (LR == 1){
  4818. c->IL = L;
  4819. c->IR = sp;
  4820. if (repos){
  4821. c->IR = repos;
  4822. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4823. c->IR = c->IL + c->MaxW*LA_RH+M;
  4824. rev = c->IR;
  4825. }
  4826. }else if (LR == 2){
  4827. c->IL = sp;
  4828. c->IR = R;
  4829. if (repos){
  4830. c->IL = repos;
  4831. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4832. c->IL = c->IR - c->MaxW*LA_RH-M;
  4833. rev = c->IL;
  4834. }
  4835. }else if (LR == 0){
  4836. c->IL = L;
  4837. c->IR = R;
  4838. }
  4839. if (c->LS && c->RS->MaxW == 0){
  4840. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4841. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4842. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4843. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4844. }else if (c->RS && c->LS->MaxW == 0){
  4845. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4846. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4847. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4848. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4849. }
  4850. return rev;
  4851. }
  4852. STRUCTURE(laRowInfo){
  4853. int MaxW;
  4854. int MinW;
  4855. int UnitMinW;
  4856. int NonExpandW;
  4857. int TotalPadding;
  4858. int Expand, Even;
  4859. int ExpandAccum;
  4860. int CountElements;
  4861. int U,MaxB,L;
  4862. laListHandle Elements;
  4863. int LastNoHeight;
  4864. };
  4865. STRUCTURE(laRowNode){
  4866. laListItem Item;
  4867. laUiItem* ui;
  4868. int GotW, LP, RP, H;
  4869. int Expand;
  4870. int UseLast;
  4871. int WaitAnimation;
  4872. };
  4873. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4874. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4875. ri->UnitMinW=LA_RH;
  4876. ri->Expand=ui->State?1:0;
  4877. ri->Even=ui->Flags?1:0;
  4878. ri->U=ui->TU; ri->L=ui->TL;
  4879. ri->MaxB=ui->TU;
  4880. }
  4881. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  4882. laRowNode* rn=CreateNew(laRowNode);
  4883. rn->LP=bt->LP;rn->RP=bt->RP;
  4884. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4885. rn->ui=ui;
  4886. rn->H=H;
  4887. rn->Expand=ui->Expand;
  4888. rn->WaitAnimation=WaitAnimation;
  4889. lstAppendItem(&ri->Elements, rn);
  4890. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4891. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4892. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4893. ri->TotalPadding += (bt->LP+bt->RP);
  4894. ri->MinW+=ri->UnitMinW;
  4895. ri->NonExpandW+=rn->GotW;
  4896. ri->ExpandAccum+=ui->Expand;
  4897. ri->CountElements++;
  4898. if(ui->Expand){ri->Expand=1;}
  4899. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4900. }
  4901. int la_ShrinkableRowElements(laRowInfo* ri){
  4902. int count=0;
  4903. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4904. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4905. count++;
  4906. }
  4907. return count;
  4908. }
  4909. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4910. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  4911. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4912. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4913. if(Available<0){
  4914. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4915. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4916. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4917. }else{
  4918. if(!ri->Expand && Available>0){Available=0;}
  4919. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4920. }
  4921. if(!ShareCount) return 0;
  4922. int PerNode = Available/ShareCount;
  4923. int Remaining = Available-PerNode*ShareCount;
  4924. int L = ri->L; int i=0; laRowNode* rn;
  4925. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4926. laUiItem* ui=rn->ui;
  4927. int NodeAdd, Node=rn->GotW;
  4928. if(rn->UseLast){
  4929. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4930. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4931. continue;
  4932. }
  4933. if(Available>=0){
  4934. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4935. NodeAdd+=(i<Remaining?1:0);i++;
  4936. }else{
  4937. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4938. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4939. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4940. }else{ Node=ri->UnitMinW;
  4941. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4942. }
  4943. }
  4944. ui->TL = L + rn->LP;
  4945. ui->TR = ui->TL + Node+NodeAdd;
  4946. ui->TB = ui->TU + rn->H;
  4947. L=ui->TR+rn->RP;
  4948. if (!rn->WaitAnimation){
  4949. ui->L = ui->TL; ui->R = ui->TR;
  4950. ui->U = ui->TU; ui->B = ui->TB;
  4951. }
  4952. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4953. }
  4954. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  4955. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  4956. memset(ri, 0, sizeof(laRowInfo));
  4957. }
  4958. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4959. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4960. int sl,sr,su,sb;
  4961. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4962. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4963. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4964. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4965. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4966. if(pc==LA_PC_SOCKET_OUT){
  4967. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4968. }else{
  4969. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4970. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4971. }
  4972. }
  4973. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4974. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4975. }
  4976. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4977. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4978. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4979. laBoxedTheme *bt;
  4980. int Lowest = 0;
  4981. int HyperValue = 0;
  4982. int WaitAnimation;
  4983. int RowMode=0; laRowInfo ri={0};
  4984. laBoxedTheme* pt=*(ParentPanel->BT);
  4985. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4986. int MaxR=0;
  4987. if(!uil->Scale){uil->Scale=1;}
  4988. uil->SaveScale=MAIN.UiScale;
  4989. MAIN.UiScale*=uil->Scale;
  4990. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4991. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4992. WaitAnimation = 0;
  4993. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4994. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4995. for (ui = uil->UiItems.pFirst; ui;){
  4996. int SubB = 0;
  4997. int H;
  4998. WaitAnimation = 0;
  4999. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5000. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  5001. //if (Fast && ui->C->B > B) {
  5002. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  5003. // ui = ui->Item.pNext;
  5004. // continue;
  5005. //}
  5006. if (!ui->Instructions){
  5007. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  5008. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  5009. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  5010. laOperatorProp *ap = ui->PP.LastPs->p;
  5011. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5012. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5013. }
  5014. }
  5015. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5016. la_UsePropPack(&ui->PP, 0);
  5017. if (ui->CompoundPPs.pFirst){
  5018. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5019. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5020. }
  5021. }
  5022. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5023. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5024. // 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);
  5025. //}
  5026. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5027. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5028. WaitAnimation = 1;
  5029. }
  5030. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5031. bt = (*ui->Type->Theme);
  5032. if (ui->Type == &_LA_UI_CONDITION){
  5033. laConditionUiExtraData *cued = ui->Extra;
  5034. la_StepExpression(cued->Expression);
  5035. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5036. if (!cued->IsTrue){
  5037. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5038. }else{
  5039. ui = ui->Item.pNext;
  5040. }
  5041. continue;
  5042. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5043. ui = ui->Item.pNext;
  5044. continue;
  5045. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5046. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5047. if (cued->IsTrue) ui = cued->EndUi;
  5048. else
  5049. ui = ui->Item.pNext;
  5050. continue;
  5051. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5052. laConditionUiExtraData *cued = ui->Extra;
  5053. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5054. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5055. if (!WaitAnimation){
  5056. ui->L = ui->TL; ui->R = ui->TR;
  5057. ui->U = ui->TU; ui->B = ui->TB;
  5058. }
  5059. if(!RowMode){
  5060. la_CalcUiItemInfluence(&uil->Columns, ui);
  5061. }else{
  5062. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5063. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5064. }
  5065. if (ui->State == LA_UI_NORMAL){
  5066. cued->IsTrue = 0;
  5067. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5068. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5069. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5070. }else{
  5071. cued->IsTrue = 1;
  5072. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5073. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5074. //}
  5075. ui = ui->Item.pNext;
  5076. }
  5077. continue;
  5078. }
  5079. if (ui->Type == _LA_UI_ALIGN){
  5080. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5081. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5082. if (ui->TB > Lowest) Lowest = ui->TB;
  5083. if (!WaitAnimation){
  5084. ui->L = ui->TL; ui->R = ui->TR;
  5085. ui->U = ui->TU; ui->B = ui->TB;
  5086. }
  5087. if(!RowMode){
  5088. la_CalcUiItemInfluence(&uil->Columns, ui);
  5089. }else{
  5090. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5091. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5092. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5093. }
  5094. ui = ui->Item.pNext; continue;
  5095. }
  5096. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5097. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5098. la_InitRowNode(&ri, ui, bt);
  5099. RowMode=1; ui=ui->Item.pNext; continue;
  5100. }
  5101. if (ui->Type == &_LA_UI_ROW_END){
  5102. la_CalculateRowExpand(&ri, ui);
  5103. la_CalcUiItemInfluence(&uil->Columns, ui);
  5104. RowMode=0; ui=ui->Item.pNext; continue;
  5105. }
  5106. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5107. int GB=0;
  5108. 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; }
  5109. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5110. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5111. if (H < 0){
  5112. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5113. else{ H=LA_RH; }
  5114. }
  5115. else H *= LA_RH;
  5116. ui->TB = ui->TU;
  5117. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5118. 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
  5119. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5120. if (ui->Type == _LA_UI_COLLECTION){
  5121. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5122. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5123. ui->PP.EndInstance = TInstance;
  5124. laUiList *iuil = ui->Subs.pFirst;
  5125. laUiList *puil = iuil;
  5126. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5127. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5128. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5129. int Begin = ui->TB;
  5130. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5131. int ElementB = ui->TU;
  5132. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5133. int MaxB = ElementB;
  5134. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5135. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5136. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5137. if (!ElementLimit) RowPriority = 0;
  5138. if (!TInstance){
  5139. while (iuil){
  5140. puil = iuil->Item.pNext;
  5141. la_DestroyTabPage(ui, iuil, 0);
  5142. iuil = puil;
  5143. }
  5144. }
  5145. while (TInstance){
  5146. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  5147. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5148. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5149. ui->PP.EndInstance = TInstance; continue;
  5150. }
  5151. if(CanGetTheme){
  5152. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5153. la_SwitchThemeQuick(t, OriginalTheme);
  5154. }
  5155. if(CanGetGap){
  5156. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5157. Gap=g*LA_RH;
  5158. }else Gap=0;
  5159. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5160. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5161. }else GotCategory=0;
  5162. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5163. if (RowPriority){
  5164. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5165. }
  5166. }
  5167. FirstIn=0;
  5168. if (ElementLimit){
  5169. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5170. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5171. }
  5172. while (iuil && iuil->Instance != TInstance){
  5173. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5174. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5175. }else{
  5176. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5177. }
  5178. iuil = puil;
  5179. }
  5180. if(!iuil){
  5181. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5182. }
  5183. if (!iuil){
  5184. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5185. la_CalcUiTopInfluence(&uil->Columns, ui);
  5186. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5187. 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);
  5188. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5189. iuil = ui->Page->Item.pNext;
  5190. }else{
  5191. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5192. 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);
  5193. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5194. la_CalcUiItemInfluence(&uil->Columns, ui);
  5195. iuil = iuil->Item.pNext;
  5196. }
  5197. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5198. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5199. ui->PP.EndInstance = TInstance;
  5200. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5201. if (RowPriority){
  5202. Col += 1;
  5203. if (Col >= ElementLimit){
  5204. Col = 0;
  5205. Row += 1;
  5206. Begin = ElementB + bt->TM;
  5207. }
  5208. }elif(Spread){
  5209. EL+=Spread*LA_RH;
  5210. ER+=Spread*LA_RH;
  5211. }else{
  5212. Row += 1;
  5213. Begin = ElementB + bt->TM;
  5214. if (ElementLimit && Row >= ElementLimit){
  5215. Row = 0;
  5216. Col += 1;
  5217. Begin = ui->TU + bt->TM;
  5218. }
  5219. }
  5220. ui->TB = ElementB;
  5221. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5222. }
  5223. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5224. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5225. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5226. ui->TB = MaxB;
  5227. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5228. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5229. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5230. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5231. ui->TB=ui->TU+LA_RH;
  5232. }else{
  5233. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5234. ui->PP.EndInstance = TInstance;
  5235. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5236. if(!Template) Template=laui_SubPropInfoDefault;
  5237. //ui->Template = Template;
  5238. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5239. if (!ui->Subs.pFirst && TInstance){
  5240. la_AddInstancePage(ui, TInstance, 0);
  5241. la_CalcUiTopInfluence(&uil->Columns, ui);
  5242. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5243. 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);
  5244. ui->TB = SubB + (NoDecal?0:bt->BM);
  5245. }else if (ui->Subs.pFirst){
  5246. if (!TInstance || TInstance != ui->Page->Instance){
  5247. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5248. ui->Page = 0;
  5249. if (TInstance){
  5250. la_AddInstancePage(ui, TInstance, 0);
  5251. la_CalcUiTopInfluence(&uil->Columns, ui);
  5252. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5253. 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);
  5254. ui->TB = SubB + (NoDecal?0:bt->TM);
  5255. }else
  5256. ui->TB = ui->TU + LA_RH + bt->BM;
  5257. }else{
  5258. 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);
  5259. ui->TB = SubB + (NoDecal?0:bt->BM);
  5260. }
  5261. }
  5262. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5263. ui->TB=ui->TU+LA_RH;
  5264. }
  5265. }
  5266. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5267. if (!WaitAnimation){
  5268. ui->L = ui->TL;
  5269. ui->R = ui->TR;
  5270. ui->U = ui->TU;
  5271. ui->B = ui->TB;
  5272. }
  5273. }
  5274. }else{
  5275. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5276. if (ui->Type != _LA_UI_CANVAS){
  5277. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5278. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5279. SubB = la_UpdateUiListRecursive(ui->Page,
  5280. 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);
  5281. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5282. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5283. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5284. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5285. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5286. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5287. }
  5288. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5289. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5290. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5291. if(ui->Page->HeightCoeff){
  5292. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5293. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5294. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5295. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5296. }
  5297. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5298. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5299. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5300. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5301. }
  5302. }
  5303. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5304. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5305. }else{
  5306. laUiList *suil;
  5307. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5308. la_CalcUiTopInfluence(&uil->Columns, ui);
  5309. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5310. 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);
  5311. }
  5312. }
  5313. ui->TB = ui->TU + H;
  5314. }
  5315. }else ui->TB = ui->TU + H;
  5316. }
  5317. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5318. if(!RowMode){
  5319. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5320. }else{
  5321. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5322. }
  5323. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5324. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5325. ui = ui->Item.pNext;
  5326. }
  5327. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5328. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5329. else uil->TB = Lowest;
  5330. if (!WaitAnimation){
  5331. uil->L = uil->TL;
  5332. uil->R = uil->TR;
  5333. uil->U = uil->TU;
  5334. uil->B = uil->TB;
  5335. }
  5336. MAIN.UiScale=uil->SaveScale;
  5337. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5338. return uil->TB;
  5339. }
  5340. int la_AnimateSingleUiSize(int To, int *Now){
  5341. int Delta;
  5342. if (To != *Now){
  5343. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5344. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5345. *Now += Delta;
  5346. return 1;
  5347. }else
  5348. return 0;
  5349. }
  5350. int la_AnimateUiListRecursive(laUiList *uil){
  5351. laUiItem *ui;
  5352. int Again = 0;
  5353. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5354. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5355. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5356. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5357. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5358. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5359. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5360. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5361. laUiList *suil;
  5362. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5363. Again += la_AnimateUiListRecursive(suil);
  5364. }
  5365. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5366. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5367. Again += la_AnimateUiListRecursive(ui->Page);
  5368. }
  5369. }
  5370. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5371. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5372. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5373. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5374. return Again;
  5375. }
  5376. int la_DrawUiItem(laUiItem *ui){
  5377. tnsUseNoTexture();
  5378. tnsColor4d(1, 1, 1, 1);
  5379. tnsVertex2d(ui->L, ui->U);
  5380. tnsVertex2d(ui->R, ui->U);
  5381. tnsVertex2d(ui->R, ui->B);
  5382. tnsVertex2d(ui->L, ui->B);
  5383. tnsPackAs(GL_LINE_LOOP);
  5384. }
  5385. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5386. tnsUseNoTexture();
  5387. tnsColor4d(1, 1, 1, 1);
  5388. tnsVertex2d(ui->L - 1, ui->U - 1);
  5389. tnsVertex2d(ui->R + 1, ui->U - 1);
  5390. tnsVertex2d(ui->R + 1, ui->B + 1);
  5391. tnsVertex2d(ui->L - 1, ui->B + 1);
  5392. tnsPackAs(GL_LINE_LOOP);
  5393. }
  5394. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5395. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5396. return 1;
  5397. }
  5398. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5399. laUiListDrawItem *uildi = uild->Items.pFirst;
  5400. laUiList *Target = uildi->Target;
  5401. int L, R, U, B;
  5402. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5403. L = Target->L + Target->PanX + uildi->DifX;
  5404. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5405. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5406. U = Target->U + Target->PanY + uildi->DifY;
  5407. return la_UiInBound(ui, L, R, U, B);
  5408. }
  5409. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5410. laUiListDrawItem *uildi = uild->Items.pFirst;
  5411. laUiList *Target = uildi->Target;
  5412. int L, R, U, B;
  5413. if (Target){
  5414. L = Target->L + Target->PanX + uildi->DifX;
  5415. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5416. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5417. U = Target->U + Target->PanY + uildi->DifY;
  5418. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5419. return 1;
  5420. }else{
  5421. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5422. return 1;
  5423. }
  5424. }
  5425. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5426. laUiItem *ui = uil->UiItems.pFirst;
  5427. while (!strGetArgument(ui->Instructions, mark))
  5428. ui = ui->Item.pNext;
  5429. return ui;
  5430. }
  5431. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5432. laUiList *uil;
  5433. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5434. if (uil->Instance == Instance) return uil;
  5435. }
  5436. return uil;
  5437. }
  5438. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5439. int mx=(L+R)/2; int my=(U+B)/2;
  5440. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5441. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5442. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5443. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5444. tnsFlush();
  5445. }
  5446. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5447. if(!uil->ScrollerShownV) return;
  5448. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5449. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5450. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5451. int U = uil->U + Offset;
  5452. int B = U + Len;
  5453. int L = UiR - RM*2 - W;
  5454. int R = L + W;
  5455. if (B > U + DisplayH) B = U + DisplayH;
  5456. if (U < uil->U) U = uil->U;
  5457. if (B <= uil->U || U >= uil->B) return;
  5458. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5459. if (U < uil->U) U = uil->U;
  5460. tnsUseNoTexture();
  5461. laBoxedTheme* bt=_LA_THEME_PANEL;
  5462. real* color=laThemeColor(bt, LA_BT_TEXT);
  5463. tnsColor4d(LA_COLOR3(color), 0.2);
  5464. tnsVertex2d(R-RM, uil->U);
  5465. tnsVertex2d(L+RM, uil->U);
  5466. tnsVertex2d(L+RM, uil->U + DisplayH);
  5467. tnsVertex2d(R-RM, uil->U + DisplayH);
  5468. tnsPackAs(GL_TRIANGLE_FAN);
  5469. tnsColor4d(LA_COLOR3(color), 0.5);
  5470. tnsVertex2d(R-RM, uil->U);
  5471. tnsVertex2d(L+RM, uil->U);
  5472. tnsVertex2d(L+RM, uil->U + DisplayH);
  5473. tnsVertex2d(R-RM, uil->U + DisplayH);
  5474. tnsPackAs(GL_LINE_LOOP);
  5475. tnsColor4d(LA_COLOR3(color), 1);
  5476. tnsVertex2d(R, U);
  5477. tnsVertex2d(L, U);
  5478. tnsVertex2d(L, B);
  5479. tnsVertex2d(R, B);
  5480. tnsPackAs(GL_TRIANGLE_FAN);
  5481. int HU=(U+B)/2+LA_RH2;
  5482. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5483. tnsFlush();
  5484. }
  5485. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5486. if(!uil->ScrollerShownH) return;
  5487. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5488. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5489. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5490. int L = uil->L + Offset;
  5491. int R = L + Len;
  5492. int U = UiB - RM - W;
  5493. int B = U + W;
  5494. if (B > U + DisplayW) B = U + DisplayW;
  5495. if (U < uil->U) U = uil->U;
  5496. if (R <= uil->L || L >= uil->R) return;
  5497. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5498. if (L < uil->L) L = uil->L;
  5499. tnsUseNoTexture();
  5500. laBoxedTheme* bt=_LA_THEME_PANEL;
  5501. real* color=laThemeColor(bt, LA_BT_TEXT);
  5502. tnsColor4d(LA_COLOR3(color), 0.2);
  5503. tnsVertex2d(uil->L,U+RM);
  5504. tnsVertex2d(uil->L,B-RM);
  5505. tnsVertex2d(uil->L + DisplayW,B-RM);
  5506. tnsVertex2d(uil->L + DisplayW,U+RM);
  5507. tnsPackAs(GL_TRIANGLE_FAN);
  5508. tnsColor4d(LA_COLOR3(color), 0.5);
  5509. tnsVertex2d(uil->L,U+RM);
  5510. tnsVertex2d(uil->L,B-RM);
  5511. tnsVertex2d(uil->L + DisplayW,B-RM);
  5512. tnsVertex2d(uil->L + DisplayW,U+RM);
  5513. tnsPackAs(GL_LINE_LOOP);
  5514. tnsColor4d(LA_COLOR3(color), 1);
  5515. tnsVertex2d(R, U);
  5516. tnsVertex2d(L, U);
  5517. tnsVertex2d(L, B);
  5518. tnsVertex2d(R, B);
  5519. tnsPackAs(GL_TRIANGLE_FAN);
  5520. int HU=(U+B)/2+LA_RH2;
  5521. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5522. tnsFlush();
  5523. }
  5524. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5525. tnsUseNoTexture();
  5526. tnsColor4dv(color);
  5527. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5528. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5529. tnsPackAs(GL_TRIANGLE_FAN);
  5530. }
  5531. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5532. laSocketRecord* sr;
  5533. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5534. uild->WiresContainer=container;
  5535. }
  5536. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5537. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5538. if(lip->Target==uild->WiresContainer) break;
  5539. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5540. }
  5541. }
  5542. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5543. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5544. int PanX, PanY;
  5545. if(pc==LA_PC_SOCKET_OUT){
  5546. laNodeOutSocket* s=ui->PP.EndInstance;
  5547. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5548. }else{
  5549. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5550. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5551. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5552. }
  5553. }
  5554. void la_RegenerateWireColors(){
  5555. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5556. laTheme* t=MAIN.CurrentTheme;
  5557. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5558. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5559. for(int i=0;i<MAIN.WireColorSlices;i++){
  5560. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5561. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5562. }
  5563. }
  5564. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5565. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5566. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5567. tnsInterpolate2dv(v1,v2,0.5,vi);
  5568. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5569. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5570. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5571. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5572. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5573. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5574. tnsVertex2d(v1[0],v1[1]);
  5575. for(int i=1;i<=steps;i++){
  5576. real ratio=i==steps?1.0f:step*i;
  5577. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5578. tnsVertex2d(v1s[0],v1s[1]);
  5579. }
  5580. }
  5581. void la_DrawNodeWires(laUiListDraw* uild){
  5582. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5583. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5584. tnsUseNoTexture();
  5585. #define _RSLICES 16
  5586. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5587. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5588. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5589. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5590. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5591. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5592. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5593. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5594. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5595. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5596. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5597. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5598. }
  5599. if(MAIN.tNodeIn->Source){
  5600. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5601. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5602. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5603. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5604. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5605. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5606. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5607. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5608. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5609. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5610. }
  5611. #undef _RSLICES
  5612. tnsFlush();
  5613. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5614. glLineWidth(ww);
  5615. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5616. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5617. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5618. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5619. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5620. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5621. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5622. }
  5623. if(MAIN.tNodeIn->Source){
  5624. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5625. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5626. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5627. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5628. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5629. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5630. }
  5631. tnsFlush();
  5632. glLineWidth(1);
  5633. la_InitSocketRecord(uild,0);
  5634. }
  5635. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5636. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5637. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5638. }
  5639. 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){
  5640. laUiItem *ui;
  5641. laBoxedTheme *bt;
  5642. laUiList *sub;
  5643. laUiListDrawItem *uildi;
  5644. int Ret = 0;
  5645. if (!uil) return 0;
  5646. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5647. ui = uil->UiItems.pFirst;
  5648. if(uil->PanY<0){uil->PanY=0;}
  5649. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5650. uil->SaveScale=MAIN.UiScale;
  5651. MAIN.UiScale*=uil->Scale;
  5652. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5653. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5654. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5655. if (ui->Type == &_LA_UI_CONDITION){
  5656. laConditionUiExtraData *cued = ui->Extra;
  5657. la_StepExpression(cued->Expression);
  5658. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5659. if (!cued->IsTrue){
  5660. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5661. }else{
  5662. ui = ui->Item.pNext;
  5663. }
  5664. continue;
  5665. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5666. ui = ui->Item.pNext;
  5667. continue;
  5668. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5669. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5670. if (cued->IsTrue) ui = cued->EndUi;
  5671. else
  5672. ui = ui->Item.pNext;
  5673. continue;
  5674. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5675. laConditionUiExtraData *cued = ui->Extra;
  5676. ui->Type->Draw(ui, LA_RH);
  5677. if (ui->State == LA_UI_NORMAL){
  5678. cued->IsTrue = 0;
  5679. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5680. }else{
  5681. cued->IsTrue = 1;
  5682. ui = ui->Item.pNext;
  5683. }
  5684. continue;
  5685. }
  5686. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5687. int NeedDraw=0;
  5688. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5689. if(NeedDraw){
  5690. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5691. }else{ ui->Type->Draw(ui, LA_RH); }
  5692. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5693. tnsFlush();
  5694. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5695. tnsResetViewMatrix();
  5696. }
  5697. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5698. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5699. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5700. tnsFlush();
  5701. }
  5702. }
  5703. if(NeedDraw || RegisterNodes){
  5704. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5705. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5706. ui->Type == _LA_UI_TAB ||
  5707. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5708. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5709. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5710. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5711. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5712. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5713. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5714. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5715. 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); }
  5716. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5717. 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);
  5718. 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)); }
  5719. }elif (ui->Type == _LA_UI_COLLECTION){
  5720. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5721. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5722. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5723. void* SaveInstance = ui->PP.EndInstance;
  5724. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5725. int State;
  5726. ui->PP.EndInstance = sub->Instance;
  5727. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5728. if(NeedDraw){ int drawn=0;
  5729. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5730. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5731. }
  5732. if (CanGetState && !drawn){
  5733. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5734. if(State >= 0){
  5735. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5736. }
  5737. }
  5738. }
  5739. if(sub->TabName && sub->TabName->Ptr){
  5740. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5741. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5742. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5743. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5744. tnsFlush();
  5745. }
  5746. if(CanGetTheme){
  5747. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5748. la_SwitchThemeQuick(t, OriginalTheme);
  5749. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5750. }
  5751. tnsFlush();
  5752. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5753. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5754. }
  5755. //ui->PP.EndInstance = Active;
  5756. ui->PP.EndInstance = SaveInstance;
  5757. }elif (ui->Type == _LA_UI_CANVAS){
  5758. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5759. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5760. tnsFlush();
  5761. 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);
  5762. }
  5763. }
  5764. }
  5765. ui = ui->Item.pNext;
  5766. }else{
  5767. ui = ui->Item.pNext;
  5768. }
  5769. }
  5770. tnsFlush();
  5771. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5772. la_RestoreLastUiListMatrix(uild, B - U);
  5773. MAIN.UiScale=uil->SaveScale;
  5774. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5775. return Ret;
  5776. }
  5777. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5778. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5779. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5780. tnsUseNoTexture();
  5781. tnsColor4d(1, 1, 1, 1);
  5782. tnsVertex2d(L, U);
  5783. tnsVertex2d(R, U);
  5784. tnsVertex2d(R, B);
  5785. tnsVertex2d(L, B);
  5786. tnsPackAs(GL_LINE_LOOP);
  5787. tnsVertex2d(L + 3, Begin);
  5788. tnsVertex2d(R - 3, Begin);
  5789. tnsVertex2d(R - 3, End);
  5790. tnsVertex2d(L + 3, End);
  5791. tnsPackAs(GL_LINE_LOOP);
  5792. }
  5793. int laIsInUiItem(laUiItem *ui, int x, int y){
  5794. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5795. return 1;
  5796. }
  5797. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5798. if (x < l || x > r || y < u || y > b) return 0;
  5799. return 1;
  5800. }
  5801. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5802. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5803. laUiItem *ui, *tui;
  5804. laBoxedTheme *bt;
  5805. laUiList *sub;
  5806. int CPB = 0;
  5807. if (!uil || (LimB && y > LimB)) return 0;
  5808. x += uil->PanX;
  5809. y += uil->PanY;
  5810. for (ui = uil->UiItems.pFirst; ui;){
  5811. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5812. if (ui->Type == &_LA_UI_CONDITION){
  5813. laConditionUiExtraData *cued = ui->Extra;
  5814. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5815. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5816. if (!cued->IsTrue){
  5817. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5818. }else{
  5819. ui = ui->Item.pNext;
  5820. }
  5821. continue;
  5822. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5823. ui = ui->Item.pNext;
  5824. continue;
  5825. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5826. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5827. if (cued->IsTrue) ui = cued->EndUi;
  5828. else
  5829. ui = ui->Item.pNext;
  5830. continue;
  5831. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5832. laConditionUiExtraData *cued = ui->Extra;
  5833. if (laIsInUiItem(ui, x, y)){
  5834. lstAppendPointer(LocalBuf, uil);
  5835. return ui;
  5836. }
  5837. if (ui->State == LA_UI_NORMAL){
  5838. cued->IsTrue = 0;
  5839. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5840. }else{
  5841. cued->IsTrue = 1;
  5842. ui = ui->Item.pNext;
  5843. }
  5844. continue;
  5845. }
  5846. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5847. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5848. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5849. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5850. if(!la_DetectSplit(ui->C, x)) Add=0;
  5851. }
  5852. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5853. }
  5854. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5855. if (ui->Page->HeightCoeff) CPB = ui->B;
  5856. else CPB = ui->Page->B;
  5857. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5858. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5859. lstAppendPointer(LocalBuf, uil);
  5860. return tui;
  5861. }
  5862. }else if (laIsInUiItem(ui, x, y)){
  5863. lstAppendPointer(LocalBuf, uil);return ui;
  5864. }
  5865. }
  5866. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5867. if (laIsInUiItem(ui, x, y)){
  5868. lstAppendPointer(LocalBuf, uil);
  5869. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5870. if(Deep){
  5871. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5872. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5873. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5874. lstAppendPointer(LocalBuf, iuil);
  5875. return tui;
  5876. }
  5877. }
  5878. }
  5879. }
  5880. return ui;
  5881. }
  5882. }
  5883. if (ui->Type == _LA_UI_CANVAS){
  5884. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5885. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5886. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5887. lstAppendPointer(LocalBuf, uil);
  5888. return tui;
  5889. }
  5890. }
  5891. }
  5892. if (laIsInUiItem(ui, x, y)){
  5893. lstAppendPointer(LocalBuf, uil);
  5894. return ui;
  5895. }
  5896. }
  5897. ui = ui->Item.pNext;
  5898. }
  5899. return 0;
  5900. }
  5901. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5902. laListHandle Locals={0};
  5903. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5904. while(lstPopPointer(&Locals));
  5905. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5906. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5907. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5908. if(pc==PCInOrOut) return ui;
  5909. }
  5910. return 0;
  5911. }
  5912. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5913. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5914. laUiItem *ui = uil->UiItems.pFirst;
  5915. laBoxedTheme *bt;
  5916. laUiList *tuil;
  5917. laUiList *sub;
  5918. int CPB = 0;
  5919. x += uil->PanX;
  5920. y += uil->PanY;
  5921. if (y > LimH) return uil;
  5922. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  5923. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  5924. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5925. return uil;
  5926. }
  5927. for (ui = uil->UiItems.pFirst; ui;){
  5928. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5929. if (ui->Type == &_LA_UI_CONDITION){
  5930. laConditionUiExtraData *cued = ui->Extra;
  5931. //la_StepExpression(cued->Expression);
  5932. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5933. if (!cued->IsTrue){
  5934. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5935. }else{
  5936. ui = ui->Item.pNext;
  5937. }
  5938. continue;
  5939. }
  5940. if (ui->Type == &_LA_UI_CONDITION_END){
  5941. ui = ui->Item.pNext;
  5942. continue;
  5943. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5944. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5945. if (cued->IsTrue) ui = cued->EndUi;
  5946. else
  5947. ui = ui->Item.pNext;
  5948. continue;
  5949. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5950. laConditionUiExtraData *cued = ui->Extra;
  5951. if (ui->State == LA_UI_NORMAL){
  5952. cued->IsTrue = 0;
  5953. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5954. }else{
  5955. cued->IsTrue = 1;
  5956. ui = ui->Item.pNext;
  5957. }
  5958. continue;
  5959. }
  5960. if (InToContainerUI && ui != Exception){
  5961. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5962. if (ContainerParent) (*ContainerParent) = uil;
  5963. if (ParentUi) *ParentUi = ui;
  5964. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5965. //if (y > LimH) return uil;
  5966. 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))){
  5967. return tuil;
  5968. }
  5969. }
  5970. }
  5971. }
  5972. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5973. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  5974. else CPB = ui->Page->B;
  5975. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5976. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5977. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5978. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5979. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5980. if (ParentUi) *ParentUi = ui;
  5981. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5982. }
  5983. }
  5984. ui = ui->Item.pNext;
  5985. }
  5986. return uil;
  5987. }
  5988. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5989. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5990. laUiItem *ui = uil->UiItems.pFirst;
  5991. laBoxedTheme *bt;
  5992. laUiList *tuil;
  5993. laUiList *sub;
  5994. int CPB = 0;
  5995. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5996. x += uil->PanX;
  5997. y += uil->PanY;
  5998. if (y > LimH) return uil;
  5999. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  6000. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  6001. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6002. return uil;
  6003. }
  6004. for (ui = uil->UiItems.pFirst; ui;){
  6005. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6006. if (ui->Type == &_LA_UI_CONDITION){
  6007. laConditionUiExtraData *cued = ui->Extra;
  6008. //la_StepExpression(cued->Expression);
  6009. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6010. if (!cued->IsTrue){
  6011. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6012. }else{
  6013. ui = ui->Item.pNext;
  6014. }
  6015. continue;
  6016. }
  6017. if (ui->Type == &_LA_UI_CONDITION_END){
  6018. ui = ui->Item.pNext;
  6019. continue;
  6020. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6021. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6022. if (cued->IsTrue) ui = cued->EndUi;
  6023. else
  6024. ui = ui->Item.pNext;
  6025. continue;
  6026. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6027. laConditionUiExtraData *cued = ui->Extra;
  6028. if (ui->State == LA_UI_NORMAL){
  6029. cued->IsTrue = 0;
  6030. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6031. }else{
  6032. cued->IsTrue = 1;
  6033. ui = ui->Item.pNext;
  6034. }
  6035. continue;
  6036. }
  6037. if (InToContainerUI && ui != Exception){
  6038. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6039. if (ContainerParent) (*ContainerParent) = uil;
  6040. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6041. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6042. //if (y > LimH) return uil;
  6043. 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))){
  6044. return tuil;
  6045. }
  6046. }
  6047. }
  6048. }
  6049. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6050. if (ui->Page->HeightCoeff) CPB = ui->B;
  6051. else CPB = ui->Page->B;
  6052. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6053. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6054. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6055. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6056. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6057. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6058. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6059. }
  6060. }
  6061. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6062. if (ui->Page->HeightCoeff) CPB = ui->B;
  6063. else
  6064. CPB = ui->Page->B;
  6065. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6066. if (ScrollUil) *ScrollUil = ui->Page;
  6067. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6068. }
  6069. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6070. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6071. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6072. }
  6073. }
  6074. ui = ui->Item.pNext;
  6075. }
  6076. return uil;
  6077. }
  6078. int la_TestUiListMinumWidth(laUiList *uil){
  6079. laUiItem *ui, *tui;
  6080. laBoxedTheme *bt;
  6081. laUiList *sub;
  6082. int CPB = 0;
  6083. int W = 0;
  6084. int tW, sW, RowMode=0, rW;
  6085. void *Restore;
  6086. for (ui = uil->UiItems.pFirst; ui;){
  6087. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6088. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6089. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6090. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6091. if (W < tW) W = tW;
  6092. }elif (ui->Type == _LA_UI_COLLECTION){
  6093. Restore = ui->PP.EndInstance;
  6094. tW = 0; sW = 0;
  6095. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6096. ui->PP.EndInstance = sub->Instance;
  6097. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6098. if (sW > tW) tW = sW;
  6099. }
  6100. ui->PP.EndInstance = Restore;
  6101. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6102. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6103. if (W < tW) W = tW;
  6104. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6105. RowMode=1; rW=0;
  6106. }elif (ui->Type==&_LA_UI_ROW_END){
  6107. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6108. }elif (ui->Type->GetMinWidth){
  6109. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6110. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6111. }
  6112. ui = ui->Item.pNext;
  6113. }
  6114. return W;
  6115. }
  6116. void la_InitLLVM(){
  6117. //LLVMLinkInMCJIT();
  6118. //LLVMInitializeNativeTarget();
  6119. //LLVMInitializeNativeAsmPrinter();
  6120. //LLVMInitializeNativeAsmParser();
  6121. // MAIN.llvmContext = LLVMGetGlobalContext();
  6122. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6123. }
  6124. //==================================================================================================
  6125. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6126. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6127. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6128. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6129. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6130. memFree(kmi);
  6131. }
  6132. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6133. laKeyMapItem *kmi;
  6134. if (!km) return 0;
  6135. kmi = memAcquire(sizeof(laKeyMapItem));
  6136. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6137. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6138. }else{
  6139. strSafeSet(&kmi->Operation, Operation);
  6140. }
  6141. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6142. kmi->SpecialKeyBits = SpecialKeyBits;
  6143. kmi->EventType = EventType;
  6144. kmi->Key = tolowerGuarded(Key);
  6145. kmi->SelectBase = SelectBase;
  6146. lstAppendItem(&km->Items, kmi);
  6147. return kmi;
  6148. }
  6149. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6150. laKeyMapItem *kmi; int inv=0;
  6151. char *instructions;
  6152. if(e->type==LA_MOUSEMOVE) return 0;
  6153. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6154. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6155. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6156. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6157. if (kmi->Operation)
  6158. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6159. else
  6160. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6161. inv = 1;
  6162. }
  6163. }
  6164. return inv;
  6165. }
  6166. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6167. laKeyMapItem *kmi;
  6168. char *instructions;
  6169. int inv = 0; int lx = -1, ly = -1;
  6170. if(e->type==LA_MOUSEMOVE) return 0;
  6171. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6172. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6173. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6174. if (e->Localized){
  6175. lx = e->x;
  6176. ly = e->y;
  6177. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6178. e->Localized = 0;
  6179. }
  6180. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6181. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6182. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6183. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6184. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6185. }elif (kmi->Operation){
  6186. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6187. }else{
  6188. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6189. }
  6190. inv = 1;
  6191. if (lx >= 0){
  6192. e->x = lx;
  6193. e->y = ly;
  6194. e->Localized = 1;
  6195. }
  6196. }
  6197. }
  6198. return inv;
  6199. }
  6200. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6201. void la_DestroyOperatorType(laOperatorType* at){
  6202. //if(at->PC) la_FreePropertyContainer(at->PC);
  6203. memFree(at);
  6204. }
  6205. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6206. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6207. uint32_t IconID, int ExtraMark){
  6208. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6209. at->Identifier = ID;
  6210. at->Name = Name;
  6211. at->Description = Description;
  6212. at->Check = Check;
  6213. at->Invoke = Invoke;
  6214. at->Init = Init;
  6215. at->Exit = Exit;
  6216. at->Modal = Modal;
  6217. at->IconID = IconID;
  6218. at->ExtraMark = ExtraMark;
  6219. at->ParseArgs = la_DefaultOperatorParser;
  6220. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6221. return at;
  6222. }
  6223. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6224. ot->PC = memAcquire(sizeof(laPropContainer));
  6225. ot->PC->Identifier = ot->Identifier;
  6226. ot->PC->Hyper = HyperLevel;
  6227. return ot->PC;
  6228. }
  6229. laOperator *la_CreateOperator(laOperatorType *at){
  6230. laOperator *a = CreateNew(laOperator);
  6231. a->Type = at;
  6232. if (at->PC && at->PC->Props.pFirst){
  6233. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6234. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6235. a->PP.LastPs->p->SubProp = at->PC;
  6236. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6237. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6238. a->PP.LastPs->Type = U'.';
  6239. }
  6240. return a;
  6241. }
  6242. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6243. return (!strcmp(a->Identifier, id));
  6244. }
  6245. laOperatorType *laGetOperatorType(const char *ID){
  6246. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6247. }
  6248. int laOperatorExistsT(laOperatorType* at){
  6249. if (!at) return 0;
  6250. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6251. return 0;
  6252. }
  6253. int laOperatorExists(const char* ID){
  6254. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6255. return laOperatorExistsT(at);
  6256. }
  6257. int la_OperatorExists(laOperator *ac){
  6258. if (!ac) return 0;
  6259. laOperator *a;
  6260. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6261. return 0;
  6262. }
  6263. int la_UiOperatorExists(void *inst){
  6264. laOperator *a;
  6265. if (!inst) return 0;
  6266. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6267. if (((laUiItem *)a->Instance) == inst){
  6268. return 1;
  6269. }
  6270. }
  6271. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6272. if (a->Instance == inst){
  6273. return 1;
  6274. }
  6275. }
  6276. return 0;
  6277. }
  6278. int la_OperatorPending(laOperator *target){
  6279. laOperator *a;
  6280. if (!target) return 0;
  6281. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6282. if (a == target){
  6283. return 1;
  6284. }
  6285. }
  6286. return 0;
  6287. }
  6288. void laSetOperatorLocalizer(void *ToPanel){
  6289. MAIN.ToPanel = ToPanel;
  6290. }
  6291. void la_DestroyConfirmData(laConfirmData **cd);
  6292. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6293. laOperator *ai = (*a);
  6294. laOperator *ac = ((*a)->Child);
  6295. void *Ret = 0;
  6296. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6297. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6298. }
  6299. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6300. if ((*a)->PP.LastPs){
  6301. memFree((*a)->PP.LastPs->p);
  6302. memFree((*a)->PP.LastPs);
  6303. }
  6304. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6305. la_SetPropMathcerContext((*a)->OperatorPanel);
  6306. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6307. laDestroySinglePanel((*a)->OperatorPanel,0);
  6308. }
  6309. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6310. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6311. lstClearPointer(&(*a)->LocalUiLists);
  6312. if (Operators){
  6313. Ret = ai->Item.pNext;
  6314. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6315. else
  6316. lstRemoveItem(Operators, *a);
  6317. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6318. if (ai->Child == (*a)) ai->Child = 0;
  6319. }
  6320. }
  6321. strSafeDestroy(&(*a)->RuntimeHint);
  6322. free(*a);
  6323. return Ret;
  6324. }
  6325. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6326. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6327. if (!at) return 0;
  6328. if (!at->Check) return 1;
  6329. return (at->Check(This, Instructions));
  6330. }
  6331. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6332. if (!at) return 0;
  6333. if (!at->Check) return 1;
  6334. return (at->Check(This, Instructions));
  6335. }
  6336. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6337. laPropPack FakePP = {0};
  6338. laPropStep FakePs = {0};
  6339. if (!at) return 0;
  6340. if (!at->Check) return 1;
  6341. FakePP.LastPs = &FakePs;
  6342. FakePP.Go = FakePP.LastPs;
  6343. FakePP.LastPs->p = This->LastPs->p;
  6344. FakePP.LastPs->UseInstance = This->EndInstance;
  6345. FakePP.EndInstance = Real_FromInstance;
  6346. FakePP.LastIndex = This->LastIndex;
  6347. return (at->Check(&FakePP, Instructions));
  6348. }
  6349. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6350. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6351. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6352. }
  6353. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6354. laOperator *a, *f = From;
  6355. int rev;
  6356. if (!f && e&&e->Localized) return -1;
  6357. a = la_CreateOperator(at);
  6358. a->ToPanel = MAIN.ToPanel;
  6359. a->This = This;
  6360. a->ExtraInstructions = args;
  6361. strMakeInstructions(&a->ExtraInstructionsP, args);
  6362. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6363. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6364. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6365. la_DestroyOperator(&a, 0, 0);
  6366. return LA_CANCELED;
  6367. }
  6368. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6369. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6370. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6371. e->Localized = 1;
  6372. }
  6373. if (e&&e->Localized){
  6374. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6375. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6376. e->Localized = 0;
  6377. }else{
  6378. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6379. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6380. }
  6381. }
  6382. if (From) f->Child = a;
  6383. a->Using = 1;
  6384. if (at->Init) at->Init(a);
  6385. rev = at->Invoke(a, e);
  6386. a->Using = 0;
  6387. if (rev & LA_FINISH){
  6388. a->StopNow = 1; if(From)From->Child=0;
  6389. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6390. }
  6391. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6392. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6393. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6394. a->State = rev;
  6395. a->PP.EndInstance = a->CustomData;
  6396. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6397. }else
  6398. la_DestroyOperator(&a, 0, 0);
  6399. return rev;
  6400. }
  6401. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6402. laOperatorType *at; laOperator *a, *f = From;
  6403. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6404. if (!at) return -1;
  6405. return laInvokeP(From,at,e,This,args,args2);
  6406. }
  6407. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6408. laOperator *a, *f = From;
  6409. int rev;
  6410. laPropPack *created;
  6411. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6412. created = memAcquireSimple(sizeof(laPropPack));
  6413. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6414. created->Go = created->LastPs;
  6415. created->LastPs->p = OrigionalThis->LastPs->p;
  6416. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6417. created->EndInstance = FromInstance;
  6418. created->LastIndex = OrigionalThis->LastIndex;
  6419. a = la_CreateOperator(at);
  6420. a->ToPanel = MAIN.ToPanel;
  6421. a->This = created;
  6422. a->CreatedThis = created;
  6423. a->ExtraInstructions = args;
  6424. strMakeInstructions(&a->ExtraInstructionsP, args);
  6425. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6426. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6427. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6428. la_DestroyOperator(&a, 0, 0);
  6429. return LA_CANCELED;
  6430. }
  6431. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6432. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6433. if (From) f->Child = a;
  6434. a->Using = 1;
  6435. if (at->Init) at->Init(a);
  6436. rev = at->Invoke(a, e);
  6437. a->Using = 0;
  6438. if (rev & LA_FINISH){
  6439. a->StopNow = 1; if(From)From->Child=0;
  6440. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6441. }
  6442. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6443. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6444. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6445. a->State = rev;
  6446. a->PP.EndInstance = a->CustomData;
  6447. }else
  6448. la_DestroyOperator(&a, 0, 0);
  6449. return rev;
  6450. }
  6451. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6452. laOperator *a, *f = From;
  6453. int rev;
  6454. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6455. a = la_CreateOperator(at);
  6456. a->Instance = inst;
  6457. a->ToPanel = MAIN.ToPanel;
  6458. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6459. if (From) f->Child = a;
  6460. a->Using = 1;
  6461. if (at->Init) at->Init(a);
  6462. rev = at->Invoke(a, e);
  6463. a->Using = 0;
  6464. if (rev & LA_FINISH){
  6465. a->StopNow = 1; if(From)From->Child=0;
  6466. }
  6467. if (rev & LA_BLOCK){
  6468. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6469. a->State = rev;
  6470. }else la_DestroyOperator(&a, 0, 0);
  6471. DEB = a;
  6472. return rev;
  6473. }
  6474. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6475. laOperatorType *at;
  6476. laOperator *a, *f = From;
  6477. if (la_UiOperatorExists(inst)) return -1;
  6478. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6479. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6480. }
  6481. void laRequestDelayEvent(real Seconds){
  6482. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6483. int la_UiStillInService(void *UiInstance){
  6484. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6485. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6486. if (ai->Instance == UiInstance) return 1;
  6487. }
  6488. return 0;
  6489. }
  6490. void la_StopUiOperatorService(void *UiInstance){
  6491. laOperator *ai, *dai, *NextAi;
  6492. if (!MAIN.CurrentWindow) return;
  6493. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6494. NextAi = ai->Item.pNext;
  6495. if (ai->Instance == UiInstance){
  6496. if (ai->Child){
  6497. la_StopUiOperatorService(ai->Child->Instance);
  6498. ai->Child = 0;
  6499. }
  6500. laOperator *dai = ai;
  6501. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6502. continue;
  6503. }
  6504. }
  6505. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6506. NextAi = ai->Item.pNext;
  6507. if (ai->Instance == UiInstance){
  6508. if (ai->Instance == ai->ToPanel){
  6509. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6510. //ai->ToPanel->LaterDestroy = 1;
  6511. }
  6512. if (ai->Child && la_OperatorExists(ai->Child)){
  6513. la_StopUiOperatorService(ai->Child->Instance);
  6514. //ai->Child = 0;
  6515. }
  6516. if (!ai->Using){
  6517. laOperator *dai = ai;
  6518. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6519. }else
  6520. ai->StopNow = 1;
  6521. }
  6522. }
  6523. }
  6524. void la_StopAllOperators(){
  6525. laOperator *ai, *dai, *NextAi;
  6526. if (!MAIN.CurrentWindow) return;
  6527. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6528. NextAi = ai->Item.pNext;
  6529. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6530. continue;
  6531. }
  6532. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6533. NextAi = ai->Item.pNext;
  6534. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6535. laHidePanelWithDissoveEffect(ai->ToPanel);
  6536. ai->ToPanel->LaterDestroy = 1;
  6537. }
  6538. if (!ai->Using){
  6539. laOperator *dai = ai;
  6540. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6541. }else ai->StopNow = 1;
  6542. }
  6543. }
  6544. void la_DestroyConfirmData(laConfirmData **cd){
  6545. if((!cd)||!(*cd)) return;
  6546. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6547. if ((*cd)->StrData) free((*cd)->StrData);
  6548. FreeMem((*cd));
  6549. (*cd) = 0;
  6550. }
  6551. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6552. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6553. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6554. ai->NextConfirmData = cd; laRetriggerOperators();
  6555. }
  6556. void laConfirmInt(laOperator *a, int Data, int mode){
  6557. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6558. cd->IData = Data; cd->Mode = mode;
  6559. ai->NextConfirmData = cd; laRetriggerOperators();
  6560. }
  6561. void laConfirmFloat(laOperator *a, real Data, int mode){
  6562. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6563. cd->FData = Data; cd->Mode = mode;
  6564. ai->NextConfirmData = cd; laRetriggerOperators();
  6565. }
  6566. void laConfirmString(laOperator *a, char *Str, int mode){
  6567. laOperator *ai = a;
  6568. laConfirmData *cd = CreateNew(laConfirmData);
  6569. int len = strlen(Str);
  6570. char *buf = calloc(len + 1, sizeof(char));
  6571. strcpy(buf, Str);
  6572. cd->StrData = buf;
  6573. cd->Mode = mode;
  6574. cd->Destroy = free;
  6575. ai->NextConfirmData = cd;
  6576. laRetriggerOperators();
  6577. }
  6578. int laConfirmSameDataIfAny(laOperator *a){
  6579. laOperator *ai = a;
  6580. laConfirmData *cd;
  6581. char *buf = 0;
  6582. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6583. cd = CreateNew(laConfirmData);
  6584. if (ai->ConfirmData->StrData){
  6585. int len = strlen(ai->ConfirmData->StrData);
  6586. buf = calloc(len + 1, sizeof(char));
  6587. strcpy(buf, ai->ConfirmData->StrData);
  6588. }
  6589. //cd->CustomData = cd->CustomData;
  6590. cd->IData = ai->ConfirmData->IData;
  6591. cd->FData = ai->ConfirmData->FData;
  6592. cd->PointerData = ai->ConfirmData->PointerData;
  6593. cd->PointerType = a->ConfirmData->PointerType;
  6594. cd->StrData = buf;
  6595. cd->Mode = ai->ConfirmData->Mode;
  6596. cd->Destroy = ai->ConfirmData->Destroy;
  6597. ai->NextConfirmData = cd;
  6598. laRetriggerOperators();
  6599. return 1;
  6600. }
  6601. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6602. laOperator *ai = a;
  6603. laConfirmData *cd = CreateNew(laConfirmData);
  6604. cd->CustomData = UserData;
  6605. cd->Mode = mode;
  6606. cd->Destroy = Destroy;
  6607. ai->NextConfirmData = cd;
  6608. laRetriggerOperators();
  6609. }
  6610. int laGetConfirmMode(laOperator *a){
  6611. return ((laOperator *)a)->ConfirmData->Mode;
  6612. }
  6613. int laGetConfirmInt(laOperator *a){
  6614. laOperator *ai = a;
  6615. int rev = ai->ConfirmData->IData;
  6616. la_DestroyConfirmData(&ai->ConfirmData);
  6617. ai->ConfirmData = 0;
  6618. return rev;
  6619. }
  6620. real laGetConfirmFloat(laOperator *a){
  6621. laOperator *ai = a;
  6622. real rev = ai->ConfirmData->FData;
  6623. la_DestroyConfirmData(&ai->ConfirmData);
  6624. ai->ConfirmData = 0;
  6625. return rev;
  6626. }
  6627. void laGetConfirmString(laOperator *a, char *buf){
  6628. laOperator *ai = a;
  6629. strcpy(buf, ai->ConfirmData->StrData);
  6630. la_DestroyConfirmData(&ai->ConfirmData);
  6631. ai->ConfirmData = 0;
  6632. }
  6633. void *laGetConfirmUserData(laOperator *a){
  6634. laOperator *ai = a;
  6635. return ai->ConfirmData->CustomData;
  6636. }
  6637. void laFinalizeOperators(){
  6638. laOperatorType *at;
  6639. laListHandle *lst;
  6640. int i;
  6641. for (i = 0; i < 256; i++){
  6642. lst = &MAIN.OperatorTypeHash.Entries[i];
  6643. for (at = lst->pFirst; at; at = at->Item.pNext){
  6644. if (at->PC && at->PC->Props.pFirst){
  6645. lstAppendItem(&MAIN.PropContainers, at->PC);
  6646. }
  6647. }
  6648. }
  6649. }
  6650. //=================
  6651. #ifdef LA_LINUX
  6652. static void la_RecordWacomMotions(XIRawEvent *event)
  6653. {
  6654. double *valuator = event->valuators.values;
  6655. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6656. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6657. //SYSWINDOW root_return, child_return;
  6658. //int root_x_return, root_y_return;
  6659. //int win_x_return, win_y_return;
  6660. //unsigned int mask_return;
  6661. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6662. // &root_x_return, &root_y_return,
  6663. // &win_x_return, &win_y_return,
  6664. // &mask_return);
  6665. //
  6666. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6667. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6668. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6669. real x=valuator[3],y=valuator[4];
  6670. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6671. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6672. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6673. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6674. if(XIMaskIsSet(event->valuators.mask, 5)){
  6675. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6676. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6677. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6678. MAIN.IsPen=1;
  6679. }
  6680. #endif
  6681. #ifdef _WIN32
  6682. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6683. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6684. static uint32_t ch = 0; static int lead = 0;
  6685. static wchar_t buf[10] = { 0 }; int adv;
  6686. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6687. short wheelmark = 0;
  6688. int WheelDir = 0;
  6689. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6690. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6691. POINT point;
  6692. PACKET pkt;
  6693. static POINT ptOld, ptNew;
  6694. static UINT prsOld, prsNew, vkey;
  6695. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6696. switch (message) {
  6697. case WM_PAINT:
  6698. //SwapBuffers(GetDC(hwnd));
  6699. break;
  6700. case WM_MOUSEMOVE:
  6701. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6702. MAIN.IsPen = 0;
  6703. break;
  6704. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6705. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6706. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6707. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6708. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6709. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6710. case WM_MOUSEWHEEL:
  6711. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6712. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6713. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6714. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6715. break;
  6716. case WT_PACKET:
  6717. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6718. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6719. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6720. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6721. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6722. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6723. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6724. MAIN.StylusTwist = tw;
  6725. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6726. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6727. MAIN.EraserPressure = MAIN.StylusPressure;
  6728. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6729. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6730. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6731. }
  6732. return 0; break;
  6733. case WM_SYSCOMMAND:
  6734. switch (wparam) {
  6735. case SC_MAXIMIZE:
  6736. case SC_RESTORE:
  6737. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6738. break;
  6739. case SC_KEYMENU:
  6740. return 0;
  6741. case SC_MINIMIZE:
  6742. break;
  6743. }
  6744. break;
  6745. case WM_SIZE:
  6746. if (wparam == SIZE_MINIMIZED) break;
  6747. case WM_MOVE: /* And size */
  6748. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6749. break;
  6750. case WM_SETCURSOR:
  6751. if(MAIN.CurrentCursor) return 1;
  6752. break;
  6753. case WM_POINTERDOWN:
  6754. case WM_POINTERUP:
  6755. case WM_POINTERUPDATE:
  6756. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6757. pointerId = GET_POINTERID_WPARAM(wparam);
  6758. pointerType = PT_POINTER;
  6759. if(!GetPointerType(pointerId, &pointerType)){
  6760. pointerType = PT_POINTER;
  6761. }
  6762. if(pointerType == PT_PEN){
  6763. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6764. for (int i = peninfonum-1; i>=0; i--) {
  6765. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6766. ScreenToClient(hwnd, &point);
  6767. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6768. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6769. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6770. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6771. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6772. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6773. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6774. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6775. }
  6776. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6777. }
  6778. }
  6779. SkipPointerFrameMessages(pointerId);
  6780. return 0;
  6781. }
  6782. else if (pointerType == PT_TOUCH){
  6783. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6784. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6785. ScreenToClient(hwnd, &point);
  6786. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6787. }
  6788. }
  6789. break;
  6790. case WM_SYSKEYDOWN:
  6791. if (lparam & 0x40000000) break;
  6792. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6793. break;
  6794. case WM_KEYDOWN:
  6795. if (lparam & 0x40000000) break;
  6796. vkey = wparam;
  6797. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6798. break;
  6799. case WM_KEYUP:
  6800. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6801. break;
  6802. case WM_SYSKEYUP:
  6803. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6804. break;
  6805. case WM_UNICHAR:
  6806. la_SendInputEvent(hwnd, wparam);
  6807. break;
  6808. case WM_IME_CHAR:
  6809. la_SendInputEvent(hwnd, wparam);
  6810. return 0;
  6811. case WM_CHAR:
  6812. la_SendInputEvent(hwnd, wparam);
  6813. break;
  6814. case WM_SHOWWINDOW:
  6815. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6816. break;
  6817. case WM_CLOSE:
  6818. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6819. break;
  6820. default:
  6821. return DefWindowProc(hwnd, message, wparam, lparam);
  6822. }
  6823. return DefWindowProc(hwnd, message, wparam, lparam);
  6824. }
  6825. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6826. return DefWindowProc(hwnd, message, wparam, lparam);
  6827. }
  6828. #endif
  6829. int la_UpdateOperatorHints(laWindow* w){
  6830. laSafeString* ss=0;
  6831. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6832. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6833. }
  6834. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6835. }else{
  6836. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6837. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6838. }
  6839. strSafeDestroy(&ss);
  6840. }
  6841. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6842. laOperator *a, *NextA = 0;
  6843. int Result = 0;
  6844. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6845. la_SendSignalsFromEvent(e);
  6846. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6847. a = Operators->pFirst;
  6848. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6849. while (1){
  6850. if (!a) break;
  6851. if (a->StopNow){
  6852. NextA = a->Item.pNext;
  6853. if (a->Type->Exit) a->Type->Exit(a, Result);
  6854. ConfirmData = a->NextConfirmData;
  6855. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6856. NextConfirmData = ConfirmData;
  6857. a->ConfirmData = 0;
  6858. a->NextConfirmData = 0;
  6859. la_DestroyOperator(&a, Operators, 0);
  6860. a = NextA;
  6861. if (a){
  6862. a->ConfirmData = NextConfirmData;
  6863. }
  6864. continue;
  6865. }
  6866. a->Using = 1;
  6867. la_SetPropMathcerContext(a->ToPanel);
  6868. laSetOperatorLocalizer(a->ToPanel);
  6869. MAIN.CurrentPanel = a->ToPanel;
  6870. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6871. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6872. e->Localized = 1;
  6873. }
  6874. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6875. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6876. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6877. e->Localized = 0;
  6878. }
  6879. la_SetPropMathcerContext(0);
  6880. laSetOperatorLocalizer(0);
  6881. MAIN.CurrentPanel = 0;
  6882. a->Using = 0;
  6883. if (Result & LA_PASS_ON){
  6884. laConfirmSameDataIfAny(a);
  6885. NextA = a->Item.pNext;
  6886. }else{
  6887. NextA = 0;
  6888. if (a->NextConfirmData){
  6889. la_DestroyConfirmData(&a->NextConfirmData);
  6890. }
  6891. }
  6892. ConfirmData = a->NextConfirmData;
  6893. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6894. NextConfirmData = ConfirmData;
  6895. a->ConfirmData = 0;
  6896. a->NextConfirmData = 0;
  6897. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6898. if (a->Type->Exit) a->Type->Exit(a, Result);
  6899. la_DestroyOperator(&a, Operators, 0);
  6900. int found=0;
  6901. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6902. if(!found){ NextA=0; }
  6903. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6904. }
  6905. a = NextA;
  6906. if (a){
  6907. a->ConfirmData = NextConfirmData;
  6908. }
  6909. }
  6910. return 1;
  6911. }
  6912. int la_HandleEvents(laWindow *w){
  6913. laEvent *e, *NextE;
  6914. laOperator *a;
  6915. laThreadNotifier *tn;
  6916. MAIN.CurrentWindow=w;
  6917. //laSpinLock(&MAIN.csNotifier);
  6918. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6919. //laSpinUnlock(&MAIN.csNotifier);
  6920. laNotifyUsers(tn->Path);
  6921. FreeMem(tn);
  6922. //if (MAIN.ThreadNotifiers.pFirst)
  6923. //laSpinLock(&MAIN.csNotifier);
  6924. }
  6925. //laSpinUnlock(&MAIN.csNotifier);
  6926. while (1){
  6927. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6928. while (w->EventList.pFirst){
  6929. while (w->PendingOperators.pLast){
  6930. a = w->PendingOperators.pLast;
  6931. if (a->OperatorPanel){
  6932. laSetOperatorLocalizer(a->OperatorPanel);
  6933. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6934. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6935. }
  6936. lstRemoveItem(&w->PendingOperators, a);
  6937. lstPushItem(&w->Operators, a);
  6938. }
  6939. e = lstPopItem(&w->EventList);
  6940. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6941. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6942. memFree(e);
  6943. }
  6944. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  6945. if (!MAIN.ReTriggerOperators) break;
  6946. }
  6947. la_UpdateOperatorHints(w);
  6948. return 1;
  6949. }
  6950. int la_AllowInput(uint32_t ch){
  6951. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6952. return 0;
  6953. }
  6954. int laCopyToClipboard(unsigned char * text){
  6955. #ifdef LA_LINUX
  6956. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6957. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6958. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6959. strSafeSet(&MAIN.CopyPending, text);
  6960. #endif
  6961. }
  6962. int la_ProcessSysMessage(){
  6963. int SendDelay = 0, SendIdle = 0;
  6964. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6965. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6966. #ifdef LA_LINUX
  6967. XEvent e;
  6968. int type;
  6969. int InputCount = 0, CharCount=0;
  6970. KeySym InputKeysym = 0;
  6971. Status InputStatus = 0;
  6972. laWindow* wnd ;
  6973. while(XPending(MAIN.dpy)){
  6974. XGenericEventCookie *cookie = &e.xcookie;
  6975. XNextEvent(MAIN.dpy, &e);
  6976. if (XFilterEvent(&e, None)) continue;
  6977. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6978. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6979. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6980. XFreeEventData(MAIN.dpy, cookie); continue;
  6981. }
  6982. switch(e.type){
  6983. case ConfigureNotify:
  6984. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6985. break;
  6986. case Expose:
  6987. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6988. if(!wnd) break;
  6989. laRefreshWindow(wnd);
  6990. break;
  6991. case MotionNotify:
  6992. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6993. MAIN.IsPen=0;
  6994. break;
  6995. case ButtonPress:
  6996. type=LA_MOUSEDOWN;
  6997. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6998. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6999. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7000. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7001. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7002. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7003. MAIN.IsPen=0;
  7004. break;
  7005. case ButtonRelease:
  7006. type=LA_MOUSEUP;
  7007. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7008. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7009. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7010. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7011. MAIN.IsPen=0;
  7012. break;
  7013. case KeyPress:
  7014. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7015. MAIN.InputBuf[InputCount]=0;
  7016. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7017. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7018. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7019. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7020. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7021. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7022. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7023. #ifdef DEBUG
  7024. printf("pressed KEY: %d\n", (int)InputKeysym);
  7025. #endif
  7026. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7027. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7028. }
  7029. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7030. }
  7031. break;
  7032. case KeyRelease:
  7033. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7034. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7035. }
  7036. case ClientMessage:
  7037. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7038. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7039. }
  7040. break;
  7041. case SelectionNotify:
  7042. if(e.xselection.selection != MAIN.bufid) continue;
  7043. if (e.xselection.property){
  7044. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7045. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7046. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7047. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7048. else if(result) {
  7049. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7050. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7051. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7052. }
  7053. XFree(result);
  7054. return True;
  7055. }
  7056. case SelectionRequest:
  7057. if(!MAIN.CopyPending){ break; }
  7058. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7059. if (e.xselectionrequest.selection != MAIN.selection) break;
  7060. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7061. XSelectionEvent ev = {0};
  7062. int R = 0;
  7063. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7064. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7065. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7066. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7067. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7068. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7069. else if (ev.target == MAIN.UTF8)
  7070. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7071. else ev.property = None;
  7072. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7073. break;
  7074. case SelectionClear:
  7075. break;
  7076. default:
  7077. break;
  7078. }
  7079. }
  7080. #endif //linux
  7081. #ifdef _WIN32
  7082. MSG msg; int Processed = 0;
  7083. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7084. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7085. if (msg.wParam == VK_PROCESSKEY) {
  7086. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7087. }
  7088. TranslateMessage(&msg); DispatchMessage(&msg);
  7089. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7090. };
  7091. if(!MAIN.Windows.pFirst){ return 0; }
  7092. #endif
  7093. #ifdef LAGUI_ANDROID
  7094. int pollResult = 0;
  7095. int pollEvents = 0;
  7096. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7097. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7098. // NOTE: Never close window, native activity is controlled by the system!
  7099. if (MAIN.app->destroyRequested != 0)
  7100. {
  7101. //CORE.Window.shouldClose = true;
  7102. //ANativeActivity_finish(MAIN.app->activity);
  7103. }
  7104. }
  7105. #endif
  7106. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7107. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7108. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7109. }
  7110. return 1;
  7111. };
  7112. void la_PrintOperatorStack(){
  7113. laWindow *w = MAIN.CurrentWindow;
  7114. laOperator *a;
  7115. printf("\n");
  7116. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7117. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7118. a->Type->Identifier, a->Instance,
  7119. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7120. }
  7121. }
  7122. void la_DrawWindow(laWindow *w){
  7123. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7124. MAIN.CurrentWindow = w;
  7125. la_WindowDefDraw(w, 0);
  7126. }
  7127. int laFinalize(){
  7128. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7129. laUiTemplate* uit;
  7130. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7131. return 1;
  7132. }
  7133. void la_PreFrame(){
  7134. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7135. la_AnimationPreFrame();
  7136. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7137. }
  7138. void la_PostFrame(){
  7139. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7140. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7141. }
  7142. void laMainLoop(){
  7143. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7144. laTimeRecorder FrameStartTime, FrameEndTime;
  7145. time_t t1, t2;
  7146. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7147. static int a = 0;
  7148. if(!laFinalize()) return;
  7149. laSetWindowCursor(LA_ARROW);
  7150. MAIN.DelayTriggered=1;
  7151. #ifdef LAGUI_ANDROID
  7152. while(!MAIN.AppReady){ usleep(1000); }
  7153. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7154. #endif
  7155. while (1){
  7156. laRecordTime(&FrameStartTime);
  7157. la_PreFrame();
  7158. if(!la_ProcessSysMessage()){ return; }
  7159. la_UpdateControllerStatus();
  7160. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7161. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7162. NextW = w->Item.pNext;
  7163. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7164. }
  7165. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7166. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7167. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7168. if(MAIN.GLDebugNeedsUpdate){
  7169. la_SetCurrentGLContextDebug();
  7170. }
  7171. la_DrawWindow(w);
  7172. }
  7173. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7174. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7175. #ifdef LA_LINUX
  7176. #ifdef LA_USE_GLES
  7177. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7178. #else
  7179. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7180. #endif
  7181. #endif
  7182. #ifdef _WIN32
  7183. SwapBuffers(w->hdc);
  7184. #endif
  7185. #ifdef LAGUI_ANDROID
  7186. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7187. #endif
  7188. }
  7189. MAIN.GLDebugNeedsUpdate=0;
  7190. la_PostFrame();
  7191. //t2 = clock();
  7192. laRecordTime(&FrameEndTime);
  7193. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  7194. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7195. if (Pause > 0){
  7196. int us = Pause * 1000000.0;
  7197. usleep(us);
  7198. }
  7199. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7200. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7201. la_AnimationPostFrame();
  7202. }
  7203. }
  7204. #ifdef LAGUI_ANDROID
  7205. int la_AndroidInitGraphics(void){
  7206. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7207. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7208. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7209. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7210. EGLint samples = 0;
  7211. EGLint sampleBuffer = 0;
  7212. const EGLint framebufferAttribs[] = {
  7213. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7214. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7215. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7216. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7217. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7218. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7219. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7220. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7221. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7222. EGL_NONE
  7223. };
  7224. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7225. EGLint numConfigs = 0;
  7226. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7227. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7228. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7229. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7230. eglBindAPI(EGL_OPENGL_API);
  7231. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7232. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7233. EGLint displayFormat = 0;
  7234. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7235. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7236. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7237. // There must be at least one frame displayed before the buffers are swapped
  7238. eglSwapInterval(MAIN.egl_dpy, 1);
  7239. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7240. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7241. MAIN.AppReady = 1;
  7242. return 0;
  7243. }
  7244. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7245. switch (cmd){
  7246. case APP_CMD_START: break;
  7247. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7248. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7249. case APP_CMD_RESUME:break;//InitPlatform();break;
  7250. case APP_CMD_INIT_WINDOW:
  7251. if (app->window != NULL){
  7252. if (MAIN.ContextRebindRequired){
  7253. // Reset screen scaling to full display size
  7254. EGLint displayFormat = 0;
  7255. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7256. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7257. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7258. // appropriate way to fix this
  7259. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7260. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7261. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7262. displayFormat);
  7263. // Recreate display surface and re-attach OpenGL context
  7264. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7265. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7266. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7267. //glClearColor(1,0.2,1,1);
  7268. //glClear(GL_COLOR_BUFFER_BIT);
  7269. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7270. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7271. MAIN.ContextRebindRequired = false;
  7272. }else{
  7273. la_AndroidInitGraphics();
  7274. }
  7275. }
  7276. break;
  7277. case APP_CMD_DESTROY:
  7278. case APP_CMD_TERM_WINDOW:
  7279. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7280. // NOTE 1: This case is used when the user exits the app without closing it. We detach the context to ensure everything is recoverable upon resuming.
  7281. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7282. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7283. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7284. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7285. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7286. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7287. MAIN.egl_surf = EGL_NO_SURFACE;
  7288. }
  7289. MAIN.ContextRebindRequired = true;
  7290. }
  7291. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7292. // this means that the user has already called 'CloseWindow()'
  7293. break;
  7294. case APP_CMD_SAVE_STATE: break;
  7295. case APP_CMD_STOP: break;
  7296. case APP_CMD_CONFIG_CHANGED:
  7297. case APP_CMD_WINDOW_RESIZED:
  7298. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7299. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7300. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7301. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7302. //print_cur_config(MAIN.app);
  7303. // Check screen orientation here!
  7304. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7305. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7306. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7307. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7308. MAIN.egl_surf = EGL_NO_SURFACE;
  7309. }
  7310. EGLint displayFormat = 0;
  7311. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7312. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7313. displayFormat);
  7314. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7315. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7316. }
  7317. break;
  7318. default: break;
  7319. }
  7320. }
  7321. #define KEYCODE_MAP_SIZE 162
  7322. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7323. 0, // AKEYCODE_UNKNOWN
  7324. 0, // AKEYCODE_SOFT_LEFT
  7325. 0, // AKEYCODE_SOFT_RIGHT
  7326. 0, // AKEYCODE_HOME
  7327. 0, // AKEYCODE_BACK
  7328. 0, // AKEYCODE_CALL
  7329. 0, // AKEYCODE_ENDCALL
  7330. '0', // AKEYCODE_0
  7331. '1', // AKEYCODE_1
  7332. '2', // AKEYCODE_2
  7333. '3', // AKEYCODE_3
  7334. '4', // AKEYCODE_4
  7335. '5', // AKEYCODE_5
  7336. '6', // AKEYCODE_6
  7337. '7', // AKEYCODE_7
  7338. '8', // AKEYCODE_8
  7339. '9', // AKEYCODE_9
  7340. 0, // AKEYCODE_STAR
  7341. 0, // AKEYCODE_POUND
  7342. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7343. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7344. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7345. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7346. 0, // AKEYCODE_DPAD_CENTER
  7347. 0, // AKEYCODE_VOLUME_UP
  7348. 0, // AKEYCODE_VOLUME_DOWN
  7349. 0, // AKEYCODE_POWER
  7350. 0, // AKEYCODE_CAMERA
  7351. 0, // AKEYCODE_CLEAR
  7352. 'a', // AKEYCODE_A
  7353. 'b', // AKEYCODE_B
  7354. 'c', // AKEYCODE_C
  7355. 'd', // AKEYCODE_D
  7356. 'e', // AKEYCODE_E
  7357. 'f', // AKEYCODE_F
  7358. 'g', // AKEYCODE_G
  7359. 'h', // AKEYCODE_H
  7360. 'i', // AKEYCODE_I
  7361. 'j', // AKEYCODE_J
  7362. 'k', // AKEYCODE_K
  7363. 'l', // AKEYCODE_L
  7364. 'm', // AKEYCODE_M
  7365. 'n', // AKEYCODE_N
  7366. 'o', // AKEYCODE_O
  7367. 'p', // AKEYCODE_P
  7368. 'q', // AKEYCODE_Q
  7369. 'r', // AKEYCODE_R
  7370. 's', // AKEYCODE_S
  7371. 't', // AKEYCODE_T
  7372. 'u', // AKEYCODE_U
  7373. 'v', // AKEYCODE_V
  7374. 'w', // AKEYCODE_W
  7375. 'x', // AKEYCODE_X
  7376. 'y', // AKEYCODE_Y
  7377. 'z', // AKEYCODE_Z
  7378. ',', // AKEYCODE_COMMA
  7379. '.', // AKEYCODE_PERIOD
  7380. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7381. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7382. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7383. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7384. LA_KEY_TAB, // AKEYCODE_TAB
  7385. ' ', // AKEYCODE_SPACE
  7386. 0, // AKEYCODE_SYM
  7387. 0, // AKEYCODE_EXPLORER
  7388. 0, // AKEYCODE_ENVELOPE
  7389. LA_KEY_ENTER, // AKEYCODE_ENTER
  7390. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7391. '`', // AKEYCODE_GRAVE
  7392. '-', // AKEYCODE_MINUS
  7393. '=', // AKEYCODE_EQUALS
  7394. '(', // AKEYCODE_LEFT_BRACKET
  7395. ')', // AKEYCODE_RIGHT_BRACKET
  7396. '\\', // AKEYCODE_BACKSLASH
  7397. ';', // AKEYCODE_SEMICOLON
  7398. '\'', // AKEYCODE_APOSTROPHE
  7399. '/', // AKEYCODE_SLASH
  7400. 0, // AKEYCODE_AT
  7401. 0, // AKEYCODE_NUM
  7402. 0, // AKEYCODE_HEADSETHOOK
  7403. 0, // AKEYCODE_FOCUS
  7404. 0, // AKEYCODE_PLUS
  7405. 0, // AKEYCODE_MENU
  7406. 0, // AKEYCODE_NOTIFICATION
  7407. 0, // AKEYCODE_SEARCH
  7408. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7409. 0, // AKEYCODE_MEDIA_STOP
  7410. 0, // AKEYCODE_MEDIA_NEXT
  7411. 0, // AKEYCODE_MEDIA_PREVIOUS
  7412. 0, // AKEYCODE_MEDIA_REWIND
  7413. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7414. 0, // AKEYCODE_MUTE
  7415. 0, // AKEYCODE_PAGE_UP
  7416. 0, // AKEYCODE_PAGE_DOWN
  7417. 0, // AKEYCODE_PICTSYMBOLS
  7418. 0, // AKEYCODE_SWITCH_CHARSET
  7419. 0, // AKEYCODE_BUTTON_A
  7420. 0, // AKEYCODE_BUTTON_B
  7421. 0, // AKEYCODE_BUTTON_C
  7422. 0, // AKEYCODE_BUTTON_X
  7423. 0, // AKEYCODE_BUTTON_Y
  7424. 0, // AKEYCODE_BUTTON_Z
  7425. 0, // AKEYCODE_BUTTON_L1
  7426. 0, // AKEYCODE_BUTTON_R1
  7427. 0, // AKEYCODE_BUTTON_L2
  7428. 0, // AKEYCODE_BUTTON_R2
  7429. 0, // AKEYCODE_BUTTON_THUMBL
  7430. 0, // AKEYCODE_BUTTON_THUMBR
  7431. 0, // AKEYCODE_BUTTON_START
  7432. 0, // AKEYCODE_BUTTON_SELECT
  7433. 0, // AKEYCODE_BUTTON_MODE
  7434. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7435. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7436. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7437. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7438. 0, // AKEYCODE_CAPS_LOCK
  7439. 0, // AKEYCODE_SCROLL_LOCK
  7440. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7441. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7442. 0, // AKEYCODE_FUNCTION
  7443. 0, // AKEYCODE_SYSRQ
  7444. 0, // AKEYCODE_BREAK
  7445. 0, // AKEYCODE_MOVE_HOME
  7446. 0, // AKEYCODE_MOVE_END
  7447. 0, // AKEYCODE_INSERT
  7448. 0, // AKEYCODE_FORWARD
  7449. 0, // AKEYCODE_MEDIA_PLAY
  7450. 0, // AKEYCODE_MEDIA_PAUSE
  7451. 0, // AKEYCODE_MEDIA_CLOSE
  7452. 0, // AKEYCODE_MEDIA_EJECT
  7453. 0, // AKEYCODE_MEDIA_RECORD
  7454. LA_KEY_F1, // AKEYCODE_F1
  7455. LA_KEY_F2, // AKEYCODE_F2
  7456. LA_KEY_F3, // AKEYCODE_F3
  7457. LA_KEY_F4, // AKEYCODE_F4
  7458. LA_KEY_F5, // AKEYCODE_F5
  7459. LA_KEY_F6, // AKEYCODE_F6
  7460. LA_KEY_F7, // AKEYCODE_F7
  7461. LA_KEY_F8, // AKEYCODE_F8
  7462. LA_KEY_F9, // AKEYCODE_F9
  7463. LA_KEY_F10, // AKEYCODE_F10
  7464. LA_KEY_F11, // AKEYCODE_F11
  7465. LA_KEY_F12, // AKEYCODE_F12
  7466. 0, // AKEYCODE_NUM_LOCK
  7467. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7468. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7469. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7470. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7471. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7472. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7473. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7474. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7475. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7476. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7477. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7478. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7479. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7480. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7481. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7482. 0, // AKEYCODE_NUMPAD_COMMA
  7483. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7484. '=' // AKEYCODE_NUMPAD_EQUALS
  7485. };
  7486. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7487. {
  7488. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7489. if(!MAIN.AppEnabled){return 0;}
  7490. //laRedrawAllWindows();
  7491. static int prev_button_state=0;
  7492. int type = AInputEvent_getType(event);
  7493. if(type == AINPUT_EVENT_TYPE_KEY){
  7494. int32_t keycode = AKeyEvent_getKeyCode(event);
  7495. //int32_t AKeyEvent_getMetaState(event);
  7496. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7497. if (key != 0){
  7498. // Save current key and its state
  7499. // NOTE: Android key action is 0 for down and 1 for up
  7500. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7501. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7502. if(key!=LA_KEY_BACKSPACE)
  7503. la_SendInputEvent(0,key);
  7504. }
  7505. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7506. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7507. la_SendInputEvent(0,key);
  7508. }
  7509. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7510. }
  7511. if (keycode == AKEYCODE_POWER)
  7512. {
  7513. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7514. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7515. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7516. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7517. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7518. return 0;
  7519. }
  7520. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7521. {
  7522. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7523. return 1;
  7524. }
  7525. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7526. {
  7527. // Set default OS behaviour
  7528. return 0;
  7529. }
  7530. return 0;
  7531. }
  7532. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7533. static real zoom_offset=1; static real temp_distance=0;
  7534. real zoom; int gesture_handled=0;
  7535. int pcount = AMotionEvent_getPointerCount(event); int x,y; static real cx=0,cy=0;
  7536. int32_t action = AMotionEvent_getAction(event);
  7537. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7538. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7539. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7540. if(pcount){
  7541. x=rx; y=ry;
  7542. int tool_type=AMotionEvent_getToolType(event,0);
  7543. real pressure = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_PRESSURE,0);
  7544. if(tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS || tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER){
  7545. MAIN.StylusPressure = MAIN.EraserPressure = pressure; MAIN.IsPen = 1;
  7546. MAIN.PointerIsEraser = (tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER);
  7547. }else{
  7548. MAIN.IsPen = 0;
  7549. }
  7550. if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
  7551. && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
  7552. real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
  7553. real ctx=(x+x2)/2, cty=(y+y2)/2;
  7554. real distance = tnsDistIdv2(x2,y2,rx,ry);
  7555. if(temp_distance){ zoom_offset*=(distance/temp_distance); }
  7556. temp_distance = distance;
  7557. while(zoom_offset > 1.1){ zoom_offset-=0.1;
  7558. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7559. la_SendMouseEvent(0, LA_MOUSEUP|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7560. }
  7561. while(zoom_offset < (1.0/1.1)){ zoom_offset+=(0.1/1.1);
  7562. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7563. la_SendMouseEvent(0, LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7564. }
  7565. if(cx || cy){
  7566. if(!gesture_handled){
  7567. real dist = tnsDistIdv2(ctx,cty,cx,cy);
  7568. while(dist > LA_RH){
  7569. int udlr = fabs(cty-cy) > fabs(ctx-cx);
  7570. int direction = udlr?(cty>cy?LA_KEY_ARRUP:LA_KEY_ARRDOWN):
  7571. (ctx>cx?LA_KEY_ARRLEFT:LA_KEY_ARRRIGHT);
  7572. real fac = (real)(LA_RH)/dist;
  7573. cx=tnsLinearItp(cx,ctx,fac); cy=tnsLinearItp(cy,cty,fac);
  7574. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7575. la_SendKeyboardEvent(0, LA_KEY_DOWN, direction|LA_KEYBOARD_EVENT|LA_KEY_PANNING);
  7576. gesture_handled=1;
  7577. dist = tnsDistIdv2(ctx,cty,cx,cy);
  7578. }
  7579. }
  7580. }else{
  7581. cx=ctx; cy=cty;
  7582. }
  7583. }else{
  7584. temp_distance = 0; cx=0; cy=0;
  7585. }
  7586. if(flags==AMOTION_EVENT_ACTION_HOVER_MOVE){
  7587. la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
  7588. }
  7589. }
  7590. if(!gesture_handled){
  7591. if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_BUTTON_PRESS){
  7592. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7593. int btn=AMotionEvent_getButtonState(event);
  7594. int evtype=LA_L_MOUSE_DOWN;
  7595. if(btn & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_DOWN; }
  7596. elif(btn & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_DOWN; }
  7597. la_SendMouseEvent(0,evtype,x,y);
  7598. prev_button_state = btn;
  7599. }
  7600. else if (flags == AMOTION_EVENT_ACTION_UP || flags == AMOTION_EVENT_ACTION_BUTTON_RELEASE){
  7601. int btn=AMotionEvent_getButtonState(event); int changed = (~btn)&prev_button_state;
  7602. int evtype=LA_L_MOUSE_UP;
  7603. if(changed & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_UP; }
  7604. elif(changed & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_UP; }
  7605. la_SendMouseEvent(0,evtype,x,y);
  7606. }
  7607. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7608. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7609. }
  7610. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7611. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7612. }
  7613. }
  7614. }
  7615. //static float r=0;
  7616. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7617. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7618. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7619. //glClear(GL_COLOR_BUFFER_BIT);
  7620. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7621. return 0;
  7622. }
  7623. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7624. MAIN.AssetManager = manager;
  7625. MAIN.InternalDataPath = dataPath;
  7626. MAIN.ExternalDataPath = externalDataPath;
  7627. }
  7628. static int android_read(void *cookie, char *data, int dataSize){
  7629. return AAsset_read((AAsset *)cookie, data, dataSize);
  7630. }
  7631. static int android_write(void *cookie, const char *data, int dataSize){
  7632. return 0;
  7633. }
  7634. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7635. return AAsset_seek((AAsset *)cookie, offset, whence);
  7636. }
  7637. static int android_close(void *cookie){
  7638. AAsset_close((AAsset *)cookie);
  7639. return 0;
  7640. }
  7641. // Replacement for fopen()
  7642. // Ref: https://developer.android.com/ndk/reference/group/asset
  7643. FILE *android_fopen(const char *fileName, const char *mode)
  7644. {
  7645. char buf[1024];
  7646. if (mode[0] == 'w')
  7647. {
  7648. // fopen() is mapped to android_fopen() that only grants read access to
  7649. // assets directory through AAssetManager but we want to also be able to
  7650. // write data when required using the standard stdio FILE access functions
  7651. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7652. #undef fopen
  7653. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7654. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7655. result=fopen(buf, mode); if(result) return result;
  7656. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7657. return fopen(buf, mode);
  7658. #define fopen(name, mode) android_fopen(name, mode)
  7659. }
  7660. else
  7661. {
  7662. // NOTE: AAsset provides access to read-only asset
  7663. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7664. if (asset != NULL)
  7665. {
  7666. // Get pointer to file in the assets
  7667. return funopen(asset, android_read, android_write, android_seek, android_close);
  7668. }
  7669. else
  7670. {
  7671. #undef fopen
  7672. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7673. // Just do a regular open if file is not found in the assets
  7674. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7675. result=fopen(buf, mode); if(result){ return result; }
  7676. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7677. return fopen(buf, mode);
  7678. #define fopen(name, mode) android_fopen(name, mode)
  7679. }
  7680. }
  7681. }
  7682. void la_HideNavBar(){
  7683. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7684. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7685. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7686. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7687. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7688. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7689. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7690. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7691. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7692. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7693. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7694. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7695. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7696. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7697. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7698. int flag = flagFullscreen | flagHideNavigation;
  7699. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7700. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7701. }
  7702. void la_InitAndroidPlatform(struct android_app *app){
  7703. MAIN.app=app;
  7704. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7705. //la_HideNavBar();
  7706. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7707. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7708. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7709. int pollResult = 0;
  7710. int pollEvents = 0;
  7711. while (!MAIN.AppReady){
  7712. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7713. // Process this event
  7714. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7715. // NOTE: Never close window, native activity is controlled by the system!
  7716. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7717. }
  7718. }
  7719. }
  7720. int main(int, char *[]);
  7721. void android_main(struct android_app *app){
  7722. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7723. la_InitAndroidPlatform(app);
  7724. // NOTE: Return from main is ignored
  7725. (void)main(1, (char *[]) { arg0, NULL });
  7726. // Request to end the native activity
  7727. ANativeActivity_finish(app->activity);
  7728. // Android ALooper_pollAll() variables
  7729. int pollResult = 0;
  7730. int pollEvents = 0;
  7731. // Waiting for application events before complete finishing
  7732. while (!app->destroyRequested)
  7733. {
  7734. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7735. {
  7736. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7737. }
  7738. }
  7739. }
  7740. void la_DisplayKeyboard(bool pShow) {
  7741. // Attaches the current thread to the JVM.
  7742. jint lResult;
  7743. jint lFlags = 0;
  7744. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7745. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7746. JavaVMAttachArgs lJavaVMAttachArgs;
  7747. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7748. lJavaVMAttachArgs.name = "NativeThread";
  7749. lJavaVMAttachArgs.group = NULL;
  7750. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7751. if (lResult == JNI_ERR) {
  7752. return;
  7753. }
  7754. // Retrieves NativeActivity.
  7755. jobject lNativeActivity = MAIN.app->activity->clazz;
  7756. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7757. logPrintNew("jvm3");
  7758. // Retrieves Context.INPUT_METHOD_SERVICE.
  7759. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7760. jfieldID FieldINPUT_METHOD_SERVICE =
  7761. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7762. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7763. jobject INPUT_METHOD_SERVICE =
  7764. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7765. FieldINPUT_METHOD_SERVICE);
  7766. //jniCheck(INPUT_METHOD_SERVICE);
  7767. logPrintNew("jvm4");
  7768. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7769. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7770. "android/view/inputmethod/InputMethodManager");
  7771. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7772. ClassNativeActivity, "getSystemService",
  7773. "(Ljava/lang/String;)Ljava/lang/Object;");
  7774. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7775. lNativeActivity, MethodGetSystemService,
  7776. INPUT_METHOD_SERVICE);
  7777. // Runs getWindow().getDecorView().
  7778. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7779. ClassNativeActivity, "getWindow",
  7780. "()Landroid/view/Window;");
  7781. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7782. MethodGetWindow);
  7783. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7784. "android/view/Window");
  7785. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7786. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7787. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7788. MethodGetDecorView);
  7789. if (pShow) {
  7790. // Runs lInputMethodManager.showSoftInput(...).
  7791. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7792. ClassInputMethodManager, "showSoftInput",
  7793. "(Landroid/view/View;I)Z");
  7794. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7795. lInputMethodManager, MethodShowSoftInput,
  7796. lDecorView, lFlags);
  7797. } else {
  7798. // Runs lWindow.getViewToken()
  7799. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7800. "android/view/View");
  7801. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7802. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7803. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7804. MethodGetWindowToken);
  7805. // lInputMethodManager.hideSoftInput(...).
  7806. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7807. ClassInputMethodManager, "hideSoftInputFromWindow",
  7808. "(Landroid/os/IBinder;I)Z");
  7809. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7810. lInputMethodManager, MethodHideSoftInput,
  7811. lBinder, lFlags);
  7812. }
  7813. // Finished with the JVM.
  7814. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7815. }
  7816. #endif //android
  7817. #ifndef LAGUI_ANDROID
  7818. void la_DisplayKeyboard(bool pShow) {
  7819. return;
  7820. }
  7821. void la_HideNavBar(){
  7822. return;
  7823. }
  7824. #endif