*/}}

la_kernel.c 330 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763
  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. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  61. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  62. static int android_read(void *cookie, char *buf, int size);
  63. static int android_write(void *cookie, const char *buf, int size);
  64. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  65. static int android_close(void *cookie);
  66. void la_InitAndroidPlatform(struct android_app *app);
  67. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  68. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  69. void la_InitAndroidPlatform(struct android_app *app);
  70. #endif
  71. LA MAIN={0};
  72. extern tnsMain *T;
  73. int deb = 0;
  74. laOperator *DEB;
  75. laColumn *DEBUG_C;
  76. #ifdef _WIN32
  77. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  78. #else
  79. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  80. #endif
  81. #ifdef LA_LINUX
  82. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  83. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  84. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  85. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  86. #endif
  87. #ifdef LA_LINUX
  88. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  89. int i;
  90. for (i = 0; i < num_classes; i++) {
  91. if (classes[i]->type == XIValuatorClass) {
  92. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  93. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  94. logPrint(" Range: %f - %f\n", v->min, v->max);
  95. logPrint(" Resolution: %d units/m\n", v->resolution);
  96. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  97. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  98. }
  99. }
  100. }
  101. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  102. XIDeviceInfo *info, *dev;
  103. int i, ndevices;
  104. dev = XIQueryDevice(display, deviceid, &ndevices);
  105. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  106. mask->deviceid = deviceid;
  107. mask->mask_len = XIMaskLen(XI_RawMotion);
  108. mask->mask=memAcquireSimple(mask->mask_len);
  109. memset(mask->mask, 0, mask->mask_len);
  110. XISetMask(mask->mask, XI_RawMotion);
  111. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  112. int FoundMax=0;
  113. for (i = 0; i < dev->num_classes; i++) {
  114. if (dev->classes[i]->type == XIValuatorClass) {
  115. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  116. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  117. }
  118. }
  119. if(!FoundMax){*max_pressure=65535;}
  120. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  121. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  122. XIFreeDeviceInfo(dev);
  123. }
  124. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  125. int axis=0;
  126. for (int i = 0; i < dev->num_classes; i++) {
  127. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  128. }
  129. return axis>=3;
  130. }
  131. #define LA_G_STYLUS(dev) \
  132. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  133. #define LA_G_ERASER \
  134. (!MAIN.WacomDeviceEraser)
  135. void la_ScanWacomDevices(Display *display, int deviceid){
  136. XIDeviceInfo *info, *dev;
  137. int ndevices;
  138. int i; char * word;
  139. int _event, _error;
  140. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  141. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  142. }
  143. info = XIQueryDevice(display, deviceid, &ndevices);
  144. for(i = 0; i < ndevices; i++) {
  145. dev = &info[i]; strToLower(dev->name);
  146. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  147. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  148. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  149. word = strtok (dev->name," ");
  150. while (1) {
  151. word = strtok (NULL, " "); if (!word) break;
  152. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  153. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  154. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  155. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  156. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  157. }
  158. }
  159. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  160. logPrintNew("Found wacom devices:\n");
  161. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  162. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  163. }else{
  164. logPrintNew("No wacom pen device connected.\n");
  165. }
  166. XIFreeDeviceInfo(info);
  167. }
  168. void laHideCursor(){
  169. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  170. }
  171. void laShowCursor(){
  172. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  173. }
  174. void la_XErrorHandler(Display *display, XErrorEvent *event){
  175. char buf[512];
  176. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  177. printf("X Error:\n%s\n",buf);
  178. }
  179. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  180. XSetWindowAttributes swa;
  181. XWindowAttributes wa;
  182. swa.event_mask =
  183. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  184. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  185. swa.colormap = MAIN.cmap;
  186. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  187. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  188. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  189. if(x>0||y>0){
  190. XSizeHints my_hints = {0};
  191. my_hints.flags = PPosition;
  192. my_hints.x = x; my_hints.y = y;
  193. XSetNormalHints(MAIN.dpy, win, &my_hints);
  194. }
  195. XStoreName(MAIN.dpy, win, title);
  196. #ifdef LA_USE_GLES
  197. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  198. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  199. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  200. EGLSurface* surf=egl_surf;
  201. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  202. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  203. tnsContextMakeCurrent((*r_glc),win,(*surf));
  204. #else
  205. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  206. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  207. printf("\n\tcannot create gl context\n\n"); exit(0);
  208. }
  209. tnsContextMakeCurrent((*r_glc),win,0);
  210. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  211. #endif
  212. XSetLocaleModifiers("");
  213. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  214. if(!MAIN.im){
  215. XSetLocaleModifiers("@im=local");
  216. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  217. }
  218. if(!MAIN.im){
  219. XSetLocaleModifiers("@im=none");
  220. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  221. }
  222. if(!MAIN.im){
  223. XSetLocaleModifiers("@im=");
  224. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  225. }
  226. if(!MAIN.im){
  227. logPrint("Can't open a input method.\n");
  228. }
  229. if(MAIN.im){
  230. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  231. XSetICFocus(MAIN.ic);
  232. }
  233. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  234. XSetClassHint(MAIN.dpy, win, &ch);
  235. #define _NET_WM_STATE_ADD 1
  236. if(w<0&&h<0){
  237. XEvent xev;
  238. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  239. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  240. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  241. memset(&xev, 0, sizeof(xev));
  242. xev.type = ClientMessage;
  243. xev.xclient.window = win;
  244. xev.xclient.message_type = wm_state;
  245. xev.xclient.format = 32;
  246. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  247. xev.xclient.data.l[1] = max_horz;
  248. xev.xclient.data.l[2] = max_vert;
  249. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  250. }
  251. return win;
  252. };
  253. void la_DestroySystemWindowX11(laWindow* w) {
  254. tnsContextMakeCurrent(0,0,0);
  255. tnsDeleteContext(w->glc);
  256. #ifdef LA_USE_GLES
  257. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  258. #endif
  259. XDestroyWindow(MAIN.dpy, w->win);
  260. };
  261. #endif //linux
  262. #ifdef _WIN32
  263. #include <msgdef.h>
  264. #include <wintab.h>
  265. #include <wintab_utils.h>
  266. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  267. #define PACKETMODE PK_BUTTONS
  268. #include <pktdef.h>
  269. void la_OpenWacomWinTab(HWND hwnd){
  270. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  271. static LOGCONTEXT glogContext = { 0 };
  272. HCTX hctx = NULL;
  273. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  274. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  275. glogContext.lcOptions |= CXO_SYSTEM;
  276. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  277. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  278. assert(glogContext.lcOptions & CXO_SYSTEM);
  279. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  280. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  281. glogContext.lcPktData = PACKETDATA;
  282. glogContext.lcPktMode = PACKETMODE;
  283. glogContext.lcMoveMask = PACKETDATA;
  284. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  285. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  286. assert(wWTInfoRetVal == sizeof(AXIS));
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  290. if (wWTInfoRetVal) {
  291. assert(wWTInfoRetVal == sizeof(AXIS));
  292. MAIN.WinTabMaxHover = TabletZ.axMax;
  293. }
  294. AXIS tabletPressure = { 0 };
  295. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  296. //glogContext.lcInOrgX = 0;
  297. //glogContext.lcInOrgY = 0;
  298. //glogContext.lcInExtX = TabletX.axMax;
  299. //glogContext.lcInExtY = TabletY.axMax;
  300. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  301. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  312. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  313. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  314. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  315. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  316. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  317. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  318. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  319. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  320. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  321. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  322. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  323. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  324. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  325. if (!hctx)return;
  326. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  327. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  328. }
  329. void laHideCursor() {
  330. if (!MAIN.CurrentWindow) return; //impl
  331. }
  332. void laShowCursor() {
  333. if (!MAIN.CurrentWindow) return; //impl
  334. }
  335. static PIXELFORMATDESCRIPTOR cpfd = {
  336. sizeof(PIXELFORMATDESCRIPTOR),1,
  337. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  338. PFD_TYPE_RGBA,
  339. 8,
  340. 0, 0, 0, 0, 0, 0,
  341. 0, 0, 0,
  342. 0, 0, 0, 0,
  343. 32,
  344. 8, 0,
  345. 0,
  346. 0, 0, 0, 0
  347. };
  348. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  349. int nBestMS = 0;
  350. int i;
  351. int iResults[9];
  352. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  353. WGL_ACCELERATION_ARB, // 1
  354. WGL_DRAW_TO_WINDOW_ARB, // 2
  355. WGL_DOUBLE_BUFFER_ARB, // 3
  356. WGL_PIXEL_TYPE_ARB, // 4
  357. WGL_DEPTH_BITS_ARB, // 5
  358. WGL_STENCIL_BITS_ARB, // 6
  359. WGL_SAMPLE_BUFFERS_ARB, // 7
  360. WGL_SAMPLES_ARB }; // 8
  361. // How many pixelformats are there?
  362. int nFormatCount[] = { 0 };
  363. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  364. if (!wglGetPixelFormatAttribivARB)
  365. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  366. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  367. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  368. for (i = 0; i < nFormatCount[0]; i++){
  369. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  370. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  371. if (iResults[3] == 1) // Double buffered
  372. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  373. if (iResults[5] >= 24) // Any Depth greater than 16
  374. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  375. }
  376. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  377. };
  378. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  379. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  380. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  381. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  382. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  383. 0 };
  384. HGLRC hglrc = 0;
  385. HDC hdc = 0;
  386. int a, b;
  387. hdc = GetDC(hwnd);
  388. la_SetupPxlFormat(hdc, &a, &b);
  389. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  390. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  391. tnsContextMakeCurrent(hglrc, hdc,0);
  392. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  393. wglSwapIntervalEXT(-1);
  394. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  395. };
  396. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  397. HINSTANCE* inst = &MAIN.hinstance;
  398. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  399. x, y, w, h, 0, 0, *inst, 0);
  400. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  401. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  402. return hwnd;
  403. };
  404. void la_DestroySystemWindowWin32(laWindow* w) {
  405. tnsContextMakeCurrent(0,0,0);
  406. tnsDeleteContext(w->glc);
  407. ReleaseDC(w->win, w->hdc);
  408. DestroyWindow(w->win);
  409. };
  410. #endif
  411. #ifdef LAGUI_ANDROID
  412. SYSWINDOW la_CreateWindowAndroid(){
  413. return 0;
  414. };
  415. void laShowCursor(){}
  416. void laHideCursor(){}
  417. #endif
  418. #ifdef LA_LINUX
  419. void la_HandlerSIGSEGV(int sig) {
  420. void *array[30];
  421. size_t sz;
  422. sz = backtrace(array, 30);
  423. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  424. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  425. exit(1);
  426. }
  427. #endif
  428. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  429. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  430. //#ifndef LAGUI_ANDROID
  431. // ignore non-significant error/warning codes
  432. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  433. logPrint("GL %d: %s\n", id, message);
  434. char* strsource="",*strtype="",*strseverity="";
  435. switch (source) {
  436. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  437. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  438. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  439. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  440. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  441. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  442. }
  443. switch (type) {
  444. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  445. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  446. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  447. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  448. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  449. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  450. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  451. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  452. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  453. }
  454. switch (severity) {
  455. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  456. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  457. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  458. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  459. }
  460. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  461. //#endif
  462. }
  463. void la_SetCurrentGLContextDebug(){
  464. //#ifndef LAGUI_ANDROID
  465. int force=MAIN.InitArgs.GLDebug;
  466. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  467. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  468. glDebugMessageCallback(la_glDebugOutput, 0);
  469. int sev=GL_DONT_CARE;
  470. if(!force){
  471. switch(MAIN.GLDebugLevel){
  472. default: sev=GL_DONT_CARE; break;
  473. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  474. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  475. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  476. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  477. }
  478. }
  479. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  480. //#endif
  481. }
  482. void la_NotifyGLDebugChanges(){
  483. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  484. }
  485. void la_SetupWindowGLStates(laWindow* w){
  486. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  487. if(w->GLDebugNeedsUpdate){
  488. tnsContextMakeWindowCurrent(w);
  489. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  490. }
  491. }
  492. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  493. SYSGLCONTEXT glc;
  494. #ifdef LA_LINUX
  495. void* egl_surf=0;
  496. #ifdef LA_USE_GLES
  497. egl_surf=&window->egl_surf;
  498. #endif
  499. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  500. #endif
  501. #ifdef _WIN32
  502. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  503. #endif
  504. #ifdef LAGUI_ANDROID
  505. la_CreateWindowAndroid();
  506. window->win = 1;
  507. window->glc = MAIN.glc;
  508. #else
  509. window->win = hwnd;
  510. window->glc = glc;
  511. #endif
  512. #ifdef _WIN32
  513. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  514. RECT rc; GetClientRect(window->win, &rc);
  515. window->CW = rc.right - rc.left;
  516. window->CH = rc.bottom - rc.top;
  517. #endif
  518. #ifdef LA_LINUX
  519. XWindowAttributes attr;
  520. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  521. window->CW =attr.width;
  522. window->CH = attr.height;
  523. #endif
  524. la_SetCurrentGLContextDebug();
  525. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  526. la_SetupWindowGLStates(window);
  527. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  528. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  529. #else
  530. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #endif
  532. window->OutputShowStripes=1; window->Redraw=1;
  533. window->GLDebugNeedsUpdate=1;
  534. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  535. return 1;
  536. };
  537. int la_DestroySystemWindow(laWindow* wnd){
  538. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  539. nvgDeleteGLES3(wnd->nvg);
  540. #else
  541. nvgDeleteGL3(wnd->nvg);
  542. #endif
  543. #ifdef LA_LINUX
  544. la_DestroySystemWindowX11(wnd);
  545. #endif
  546. #ifdef _WIN32
  547. la_DestroySystemWindowWin32(wnd);
  548. #endif
  549. }
  550. void la_DestroyWindow(laWindow *wnd){
  551. laLayout *l; laPanel *p; if (!wnd) return;
  552. tnsSwitchToCurrentWindowContext(wnd);
  553. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  554. la_StopAllOperators();
  555. strSafeDestroy(&wnd->Title);
  556. //la_PrintUserList(wnd);
  557. //printf("----\n");
  558. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  559. while (l = lstPopItem(&wnd->Layouts)){
  560. laDestroyBlocksRecursive(l->FirstBlock);
  561. //la_PrintUserList(l);
  562. //printf("%x %s\n", l, l->ID->Ptr);
  563. strSafeDestroy(&l->ID);
  564. memFree(l);
  565. //la_PrintUserList(wnd);
  566. //printf("----\n");
  567. }
  568. //printf("----\n%x\n",wnd);
  569. //la_PrintUserList(wnd);
  570. la_DestroySystemWindow(wnd);
  571. lstRemoveItem(&MAIN.Windows, wnd);
  572. memFree(wnd);
  573. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  574. }
  575. void laRenameWindow(laWindow* wnd, char* name){
  576. if((!wnd)||MAIN.IsReadingUDF) return;
  577. strSafeSet(&wnd->Title, name);
  578. if(!wnd->win) return;
  579. #ifdef LA_LINUX
  580. XStoreName(MAIN.dpy, wnd->win, name);
  581. #endif
  582. #ifdef _WIN32
  583. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  584. SetWindowTextW(wnd->win, name);
  585. #endif
  586. }
  587. #ifdef LA_LINUX
  588. const char* la_ConvertCursorID(int id){
  589. switch (id) {
  590. case LA_ARROW: return "arrow";
  591. case LA_CROSS: return "cross";
  592. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  593. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  594. case LA_MOVE: return "diamond_cross";
  595. case LA_HAND: return "hand1";
  596. case LA_CORNER: return "bottom_right_corner";
  597. }
  598. return "arrow";
  599. }
  600. #endif
  601. #ifdef _WIN32
  602. HCURSOR la_ConvertCursorID(int id){
  603. switch (id){
  604. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  605. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  606. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  607. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  608. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  609. case LA_HAND: return LoadCursor(0, IDC_HAND);
  610. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  611. }
  612. return LoadCursor(0, IDC_ARROW);;
  613. }
  614. #endif
  615. void la_InitThreadEnviornment(){
  616. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  617. }
  618. laLogEntry* logEnsure(int Create){
  619. if(!MAIN.Logs.pFirst || Create){
  620. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  621. lstAppendItem(&MAIN.Logs, le);
  622. }
  623. return MAIN.Logs.pLast;
  624. }
  625. void logPrintTV(int Continued, char* format, va_list v){
  626. if(!format || !format[0]) return;
  627. laLogEntry* le=logEnsure(Continued);
  628. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  629. strSafePrintV(&le->Content, format, v);
  630. #ifdef LAGUI_ANDROID
  631. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  632. #endif
  633. laNotifyUsers("la.logs");
  634. }
  635. void logPrintT(int Continued, char* format, ...){
  636. if(!format || !format[0]) return;
  637. laLogEntry* le=logEnsure(Continued);
  638. va_list aptr; va_start(aptr, format);
  639. strSafePrint(&le->Content, format, aptr);
  640. va_end(aptr);
  641. #ifdef LAGUI_ANDROID
  642. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  643. #endif
  644. laNotifyUsers("la.logs");
  645. }
  646. void logPrint(char* format, ...){
  647. va_list aptr; va_start(aptr, format);
  648. logPrintTV(0, format, aptr);
  649. va_end(aptr);
  650. }
  651. void logPrintNew(char* format, ...){
  652. logEnsure(1);
  653. va_list aptr; va_start(aptr, format);
  654. logPrintTV(0, format, aptr);
  655. va_end(aptr);
  656. }
  657. void logClear(){
  658. laLogEntry*l;
  659. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  660. laNotifyUsers("la.logs");
  661. }
  662. 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;
  663. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  664. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  665. }
  666. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  667. strSafeSet(&s->Name,Name);
  668. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  669. s->x=x;s->y=y;s->w=w;s->h=h;
  670. laNotifyUsers("la.user_preferences.screens");
  671. return s;
  672. }
  673. void la_RemoveScreen(laScreen*s){
  674. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  675. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  676. }
  677. void la_RemoveDuplicatedScreenConf(){
  678. laScreen* NextS;
  679. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  680. NextS = s->Item.pNext;
  681. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  682. 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; }
  683. }
  684. }
  685. }
  686. laScreen* laGetWindowScreen(laWindow* w){
  687. int l,r,u,b; int area=-1; laScreen* maxs=0;
  688. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  689. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  690. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  691. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  692. int a=w*h; if(a>area){ maxs = s; area = a; }
  693. }
  694. return maxs;
  695. }
  696. #ifdef LA_LINUX
  697. int la_GetDPI(Window* root_win){
  698. XRRScreenResources *screen;
  699. XRROutputInfo *info;
  700. XRRCrtcInfo *crtc_info;
  701. XRRCrtcInfo *crtc;
  702. int iscres, icrtc, dpi=0;
  703. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  704. for(iscres=0;iscres<screen->noutput;iscres++){
  705. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  706. if(!info->mm_width || !info->mm_height){ continue; }
  707. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  708. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  709. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  710. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  711. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  712. XRRFreeCrtcInfo(crtc);
  713. //if(info->connection==RR_Connected){
  714. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  715. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  716. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  717. // XRRFreeCrtcInfo(crtc_info);
  718. // }
  719. //}
  720. XRRFreeOutputInfo(info);
  721. }
  722. XRRFreeScreenResources(screen);
  723. return dpi;
  724. }
  725. #endif
  726. #ifdef _WIN32
  727. typedef struct laWin32MonitorEnumData {
  728. int id;
  729. }laWin32MonitorEnumData;
  730. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  731. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  732. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  733. return TRUE;
  734. }
  735. int la_GetDPI(HWND win){
  736. laWin32MonitorEnumData data = { 0 };
  737. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  738. return GetDpiForWindow(win);
  739. return 144;
  740. }
  741. #endif
  742. #define PROGRESSW (LA_RH*15)
  743. void laShowProgress(real p1, real p2){
  744. laSpinLock(&MAIN.OpsLock);
  745. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  746. if(!MAIN.Progress.Called){
  747. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  748. }else{
  749. laTimeRecorder tm; laRecordTime(&tm);
  750. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  751. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  752. if(!MAIN.Progress.Shown){
  753. int ww=PROGRESSW+LA_RH*2;
  754. #ifdef LA_LINUX
  755. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  756. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  757. long a=LA_COLOR3_TO_HEX(bg);
  758. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  759. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  760. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  761. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  762. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  763. #endif
  764. #ifdef _WIN32
  765. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  766. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  767. ShowWindow(MAIN.Progress.w,SW_SHOW);
  768. #endif
  769. MAIN.Progress.Shown = 1;
  770. }
  771. }
  772. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  773. #ifdef LA_LINUX
  774. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  775. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  776. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  777. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  778. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  779. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  780. #endif
  781. #ifdef _WIN32
  782. InvalidateRect(MAIN.Progress.w,0,1);
  783. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  784. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  785. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  786. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  787. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  788. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  789. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  790. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  791. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  792. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  793. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  794. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  795. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  796. EndPaint(MAIN.Progress.w,&ps);
  797. MSG msg;
  798. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  799. #endif
  800. laSpinUnlock(&MAIN.OpsLock);
  801. }
  802. void laHideProgress(){
  803. laSpinLock(&MAIN.OpsLock);
  804. if(!MAIN.Progress.Shown){
  805. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  806. }
  807. laTimeRecorder tm; laRecordTime(&tm);
  808. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  809. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  810. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  811. #ifdef LA_LINUX
  812. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  813. #endif
  814. #ifdef _WIN32
  815. ShowWindow(MAIN.Progress.w,SW_HIDE);
  816. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  817. #endif
  818. laSpinUnlock(&MAIN.OpsLock);
  819. }
  820. //=======================
  821. void la_InitProgressWindow(){
  822. #ifdef LA_LINUX
  823. 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));
  824. if(!MAIN.Progress.w) return;
  825. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  826. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  827. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  828. if(MAIN.Progress.gc<0) return;
  829. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  830. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  831. XSync(MAIN.dpy,0);
  832. #endif
  833. #ifdef _WIN32
  834. WNDCLASSW wc;
  835. wc.hInstance = MAIN.hinstance;
  836. wc.lpfnWndProc = LA_ProgressWindowProc;
  837. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  838. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  839. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  840. wc.cbWndExtra = 0;
  841. wc.cbClsExtra = 0;
  842. wc.lpszClassName = L"_LAGUIPROGRESS";
  843. wc.lpszMenuName = NULL;
  844. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  845. if (!RegisterClassW(&wc)){ return; }
  846. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  847. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  848. #endif
  849. }
  850. void laSetFontFolderPath(char* absolute){
  851. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  852. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  853. }
  854. void laSetDefaultInitArguments(laInitArguments* ia){
  855. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  856. ia->UseColorManagement=0;
  857. ia->HasWorldObjects=0;
  858. ia->HasAction=0;
  859. ia->HasTextureInspector=0;
  860. ia->HasHistories=0;
  861. ia->HasTerminal=1;
  862. ia->HasAudio=0;
  863. }
  864. void laSetCompleteInitArguments(laInitArguments* ia){
  865. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  866. ia->UseColorManagement=1;
  867. ia->HasWorldObjects=1;
  868. ia->HasAction=1;
  869. ia->HasTextureInspector=1;
  870. ia->HasHistories=1;
  871. ia->HasTerminal=1;
  872. ia->HasAudio=1;
  873. }
  874. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  875. MAIN.GLMajor=MAIN.GLMinor=-1;
  876. char* arg = 0;
  877. printf("Initializing LaGUI...\n",argc);
  878. for(int i=0;i<argc;i++){
  879. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  880. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  881. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  882. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  883. }
  884. continue;
  885. }
  886. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  887. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  888. }
  889. }
  890. int laGetReadyWith(laInitArguments* ia){
  891. #ifdef LA_LINUX
  892. //signal(SIGSEGV,la_HandlerSIGSEGV);
  893. #endif
  894. laSpinInit(&MAIN.MemLock);
  895. laSpinInit(&MAIN.OpsLock);
  896. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  897. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  898. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  899. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  900. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  901. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  902. tnsInit();
  903. #ifdef LA_LINUX
  904. SYSWINDOW root, win;
  905. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  906. XSetWindowAttributes swa={0};
  907. XWindowAttributes wa={0};
  908. XEvent xev;
  909. logPrintNew("Initializing LaGUI...\n");
  910. setlocale(LC_CTYPE, "zh_CN.utf8");
  911. XSetErrorHandler(la_XErrorHandler);
  912. int i;
  913. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  914. printf("\n\tcannot connect to x server\n\n");
  915. exit(0);
  916. }
  917. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  918. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  919. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  920. #ifdef LA_USE_GLES
  921. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  922. #else
  923. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  924. #endif
  925. #ifdef LA_USE_GLES
  926. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  927. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  928. EGLint egl_major, egl_minor;
  929. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  930. printf("Error: eglInitialize() failed\n"); return -1;
  931. }
  932. int scrnum;
  933. XSetWindowAttributes attr;
  934. XVisualInfo *visInfo, visTemplate;
  935. int num_visuals;
  936. EGLContext ctx;
  937. EGLint num_configs;
  938. EGLint vid;
  939. static const EGLint attribs[] = {
  940. EGL_RED_SIZE, 8,
  941. EGL_GREEN_SIZE, 8,
  942. EGL_BLUE_SIZE, 8,
  943. EGL_DEPTH_SIZE, 1,
  944. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  945. EGL_NONE
  946. };
  947. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  948. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  949. }
  950. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  951. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  952. }
  953. visTemplate.visualid = vid;
  954. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  955. if (!visInfo) {
  956. printf("Error: couldn't get X visual\n"); exit(1);
  957. }
  958. MAIN.xvi=visInfo;
  959. root = DefaultRootWindow(MAIN.dpy);
  960. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  961. printf("\n\tcannot create colormap\n\n"); exit(1);
  962. }
  963. eglBindAPI(EGL_OPENGL_ES_API);
  964. EGLint ctx_attribs[] = {
  965. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  966. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  967. EGL_NONE
  968. };
  969. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  970. if (!MAIN.glc) {
  971. printf("Error: eglCreateContext failed\n"); exit(1);
  972. }
  973. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  974. #else
  975. int visual_attribs[] = {
  976. GLX_X_RENDERABLE , True,
  977. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  978. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  979. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  980. GLX_RED_SIZE , 8,
  981. GLX_GREEN_SIZE , 8,
  982. GLX_BLUE_SIZE , 8,
  983. GLX_ALPHA_SIZE , 8,
  984. GLX_DEPTH_SIZE , 24,
  985. //GLX_STENCIL_SIZE , 8,
  986. GLX_DOUBLEBUFFER , True,
  987. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  988. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  989. None
  990. };
  991. int fbcount = -1;
  992. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  993. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  994. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  995. MAIN.BestFBC = fbconfig[0];
  996. int sample_buf,samples;
  997. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  998. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  999. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1000. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1001. free(fbconfig);
  1002. root = DefaultRootWindow(MAIN.dpy);
  1003. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1004. printf("\n\tcannot create colormap\n\n"); exit(0);
  1005. }
  1006. swa.colormap = MAIN.cmap;
  1007. root = DefaultRootWindow(MAIN.dpy);
  1008. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1009. MAIN.win=win;
  1010. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1011. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1012. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1013. printf("\n\tcannot create gl context\n\n"); exit(0);
  1014. }
  1015. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1016. tnsContextMakeCurrent(MAIN.glc,win,0);
  1017. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1018. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1019. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1020. int err=0;
  1021. if((err=glewInit())!=GLEW_OK){
  1022. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1023. };
  1024. #endif /* gles or glx */
  1025. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1026. la_SetCurrentGLContextDebug();
  1027. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1028. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1029. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1030. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1031. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1032. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1033. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1034. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1035. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1036. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1037. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1038. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1039. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1040. #endif //linux
  1041. #ifdef _WIN32
  1042. logPrintNew("Initializing LaGUI...\n");
  1043. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1044. setlocale(LC_ALL, "zh_CN.utf8");
  1045. MAIN.hinstance = GetModuleHandle(NULL);
  1046. HINSTANCE* hInst = &MAIN.hinstance;
  1047. WNDCLASSEXW wt;
  1048. wt.cbSize = sizeof(WNDCLASSEXW);
  1049. wt.cbClsExtra = 0;
  1050. wt.cbWndExtra = 0;
  1051. wt.hbrBackground = 0;
  1052. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1053. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1054. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1055. wt.hInstance = *hInst;
  1056. wt.lpfnWndProc = LA_WindowProc;
  1057. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1058. wt.lpszMenuName = 0;
  1059. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1060. if (!RegisterClassExW(&wt)) return 0;
  1061. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1062. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1063. SetProcessDPIAware();
  1064. GLenum err;
  1065. PIXELFORMATDESCRIPTOR pfd;
  1066. HINSTANCE* hinst = &MAIN.hinstance;
  1067. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1068. "Temp Window For Accessing GLEW!",
  1069. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1070. 0, 0, *hinst, 0);
  1071. HDC hdc = GetDC(hwnd);
  1072. HGLRC hglrc = 0;
  1073. SetPixelFormat(hdc, 1, &cpfd);
  1074. hglrc = wglCreateContext(hdc);
  1075. tnsContextMakeCurrent(hglrc, hdc,0);
  1076. //MAIN.hdc = hdc;
  1077. // MAIN.tWND = hwnd;
  1078. MAIN.glc = hglrc;
  1079. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1080. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1081. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1082. if (err = glewInit()) {
  1083. printf("Init Glew Failed\n");
  1084. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1085. return 0;
  1086. }
  1087. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1088. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1089. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1090. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1091. #endif
  1092. la_GetWorkingDirectoryInternal();
  1093. MAIN.SavePreferenceOnExit=1;
  1094. MAIN.FontSize = 0.6;
  1095. int dpi=64;
  1096. #ifdef _WIN32
  1097. dpi=la_GetDPI(hwnd);
  1098. #endif
  1099. #ifdef LA_LINUX
  1100. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1101. #endif
  1102. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1103. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1104. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1105. MAIN.UiScale=1;
  1106. MAIN.MarginSize = 1;
  1107. MAIN.ColorPickerGamma=1.5;
  1108. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1109. MAIN.ViewportHalftoneFactor=0.5;
  1110. MAIN.ViewportHalftoneSize=3.7;
  1111. tnsInitRenderKernel(64);
  1112. tnsInitBuiltinShaders();
  1113. tnsSetuptnsFontManager();
  1114. #define LOAD_FONT(font) \
  1115. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1116. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1117. LOAD_FONT("NotoEmoji-Regular.ttf");
  1118. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1119. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1120. //LOAD_FONT("NotoMusic-Regular.ttf");
  1121. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1122. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1123. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1124. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1125. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1126. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1127. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1128. MAIN.Audio=memAcquire(sizeof(laAudio));
  1129. #ifdef LA_WITH_LUAJIT
  1130. // starting lua
  1131. logPrint("Starting luajit...\n");
  1132. MAIN.L = lua_open();
  1133. la_luaLoadLibs(MAIN.L);
  1134. la_luaPrintStatus(MAIN.L);
  1135. tnsLuaInit(MAIN.L);
  1136. #endif
  1137. //interactions:
  1138. MAIN.TopFramerate = 60;
  1139. MAIN.ValuatorThreshold = 8;
  1140. MAIN.ScrollingSpeed = 3;
  1141. MAIN.AnimationSpeed = 0.4;
  1142. MAIN.PanelAnimationSpeed = 0.4;
  1143. MAIN.ZoomSpeed2D = 0.01;
  1144. MAIN.IdleTime = 0.75;
  1145. MAIN.TooltipCloseDistance = 30;
  1146. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1147. //display:
  1148. MAIN.FloatingAlpha = 0.35;
  1149. MAIN.SolidShadowLength = 20;
  1150. MAIN.WireColorSlices = 16;
  1151. MAIN.WireThickness = 5;
  1152. MAIN.WireSaggyness = 0.5;
  1153. #ifdef LAGUI_ANDROID
  1154. laAddResourceFolder("");
  1155. #else
  1156. laAddResourceFolder(".");
  1157. #endif
  1158. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1159. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1160. la_InitProgressWindow();
  1161. la_MakeTranslations_es_ES();
  1162. la_MakeTranslations_zh_hans();
  1163. //tns_RegisterResourcesForSoftwareRender();
  1164. la_RegisterDefaultSignals();
  1165. la_RegisterGeneralProps();
  1166. la_RegisterBuiltinTemplates();
  1167. la_RegisterMainThemes();
  1168. la_RegisterMainOperators();
  1169. la_RegisterMainUiTypes();
  1170. la_RegisterModellingOperators();
  1171. la_RegisterShapeOperators();
  1172. la_RegisterInternalProps();
  1173. la_RegisterAnimationResources();
  1174. la_RegisterWindowKeys();
  1175. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1176. laFinalizeUiTemplates();
  1177. laFinalizeOperators();
  1178. la_RegisterControllerProps();
  1179. la_RefreshControllers();
  1180. la_RegisterBasicNodes();
  1181. tns_RegisterNodes();
  1182. la_InitThreadEnviornment();
  1183. laSetRootInstance(&MAIN);
  1184. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1185. laPushDifferences(0, 0);
  1186. la_MakeDummyManagedUDF();
  1187. la_RegenerateWireColors();
  1188. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1189. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1190. logPrintNew("Initialization Completed\n");
  1191. MAIN.InitDone=1;
  1192. return 1;
  1193. }
  1194. int laGetReady(){
  1195. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1196. return laGetReadyWith(&ia);
  1197. }
  1198. void la_DestroyUiType(laUiType* uit);
  1199. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1200. void laShutoff(int SavePrefereces){
  1201. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1202. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1203. // transLate(pc->Description);
  1204. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1205. // transLate(p->Description);
  1206. // }
  1207. //}
  1208. transDumpMissMatchRecord("TranslationDump.txt");
  1209. if(MAIN.Cleanup) MAIN.Cleanup();
  1210. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1211. strSafeDestroy(&MAIN.WorkingDirectory);
  1212. strSafeDestroy(&MAIN.example_string);
  1213. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1214. // (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. )
  1215. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1216. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1217. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1218. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1219. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1220. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1221. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1222. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1223. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1224. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1225. strSafeDestroy(&MAIN.CopyPending);
  1226. la_ClearUDFRegistryAndFolders();
  1227. laClearManagedUDF();
  1228. laClearSaveProp();
  1229. logClear();
  1230. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1231. #ifdef LA_LINUX
  1232. tnsContextMakeCurrent(0,0,0);
  1233. tnsDeleteContext(MAIN.glc);
  1234. #ifdef LA_USE_GLES
  1235. eglTerminate(MAIN.egl_dpy);
  1236. #endif
  1237. #endif
  1238. #ifdef _WIN32
  1239. tnsContextMakeCurrent(0,0,0);
  1240. tnsDeleteContext(MAIN.glc);
  1241. UnloadWintab();
  1242. #endif
  1243. tnsQuit();
  1244. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1245. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1246. strSafeDump();
  1247. hshFree(&MAIN.DBInstMemLeft);
  1248. memNoLonger();
  1249. laSpinDestroy(&MAIN.MemLock);
  1250. laSpinDestroy(&MAIN.OpsLock);
  1251. #ifdef LA_WITH_LUAJIT
  1252. lua_close(MAIN.L);
  1253. #endif
  1254. printf("LaGUI has cleaned up.\n");
  1255. }
  1256. int laRestoreFactorySettings(){
  1257. char path[1024];
  1258. #ifdef LAGUI_ANDROID
  1259. sprintf(path,"%s","preferences.udf");
  1260. #else
  1261. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1262. #endif
  1263. if(remove(path)){ return 0; }
  1264. return 1;
  1265. }
  1266. void laSaveUserPreferences(){
  1267. char path[1024];
  1268. #ifdef LAGUI_ANDROID
  1269. sprintf(path,"%s","preferences.udf");
  1270. #else
  1271. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1272. #endif
  1273. laUDF* udf=laPrepareUDF(path);
  1274. laWriteProp(udf,"la.windows");
  1275. laWriteProp(udf,"la.user_preferences");
  1276. laWriteProp(udf,"la.input_mapping");
  1277. laWriteProp(udf,"la.controllers");
  1278. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1279. laWriteProp(udf,lip->p);
  1280. }
  1281. laPackUDF(udf,0,0);
  1282. }
  1283. void laEnsureUserPreferences(){
  1284. char path[1024];
  1285. #ifdef LAGUI_ANDROID
  1286. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1287. #else
  1288. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1289. #endif
  1290. laUDFRegistry* r=laFindUDFRegistry(path);
  1291. if(!r){ laSaveUserPreferences(); return; }
  1292. 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; }
  1293. laClearUDFRegistries();
  1294. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1295. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1296. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1297. laCloseUDF(udf);
  1298. la_RemoveDuplicatedScreenConf();
  1299. la_RemoveDuplicatedControllers();
  1300. laRefreshUDFRegistries();
  1301. //restore forced settings
  1302. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1303. }
  1304. void laAddExtraExtension(int FileType, ...){
  1305. va_list list; va_start(list,FileType);
  1306. char* ext;
  1307. while(ext=va_arg(list,char*)){ if(!ext) break;
  1308. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1309. et->FileType=FileType; et->Extension=ext;
  1310. lstAppendItem(&MAIN.ExtraExtensions, et);
  1311. logPrintNew("add ext %s",ext);
  1312. }
  1313. va_end(list);
  1314. }
  1315. void laAddExtraPreferencePath(const char* path){
  1316. if(!path) return;
  1317. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1318. }
  1319. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1320. if(!name || !Func) return;
  1321. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1322. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1323. }
  1324. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1325. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1326. }
  1327. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1328. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1329. }
  1330. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1331. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1332. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1333. }
  1334. void la_InputMappingGetKeyName(int key, int special, char* name){
  1335. char *_next=name; name[0]=0;
  1336. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1337. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1338. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1339. switch(key){
  1340. case ' ': strcat(name,"Space"); break;
  1341. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1342. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1343. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1344. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1345. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1346. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1347. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1348. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1349. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1350. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1351. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1352. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1353. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1354. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1355. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1356. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1357. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1358. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1359. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1360. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1361. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1362. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1363. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1364. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1365. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1366. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1367. case LA_KEY_F1: strcat(name,"F1"); break;
  1368. case LA_KEY_F2: strcat(name,"F2"); break;
  1369. case LA_KEY_F3: strcat(name,"F3"); break;
  1370. case LA_KEY_F4: strcat(name,"F4"); break;
  1371. case LA_KEY_F5: strcat(name,"F5"); break;
  1372. case LA_KEY_F6: strcat(name,"F6"); break;
  1373. case LA_KEY_F7: strcat(name,"F7"); break;
  1374. case LA_KEY_F8: strcat(name,"F8"); break;
  1375. case LA_KEY_F9: strcat(name,"F9"); break;
  1376. case LA_KEY_F10: strcat(name,"F10"); break;
  1377. case LA_KEY_F11: strcat(name,"F11"); break;
  1378. case LA_KEY_F12: strcat(name,"F12"); break;
  1379. default:
  1380. name = name+strlen(name); _next=name;
  1381. laToUTF8(key,name,&_next); *_next=0; break;
  1382. }
  1383. }
  1384. int la_InputMappingGetKeyFromName(char* name, int* special){
  1385. if(!name ||name[0]==0){ *special=0; return 0; }
  1386. *special=0;
  1387. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1388. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1389. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1390. char* p=name+strlen(name)-1;
  1391. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1392. while(*p=='+' || *p==' '){ p++; }
  1393. if(strSame(p,"Space")) return ' ';
  1394. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1395. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1396. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1397. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1398. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1399. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1400. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1401. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1402. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1403. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1404. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1405. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1406. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1407. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1408. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1409. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1410. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1411. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1412. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1413. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1414. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1415. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1416. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1417. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1418. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1419. if(strSame(p,"F1")) return LA_KEY_F1;
  1420. if(strSame(p,"F2")) return LA_KEY_F2;
  1421. if(strSame(p,"F3")) return LA_KEY_F3;
  1422. if(strSame(p,"F4")) return LA_KEY_F4;
  1423. if(strSame(p,"F5")) return LA_KEY_F5;
  1424. if(strSame(p,"F6")) return LA_KEY_F6;
  1425. if(strSame(p,"F7")) return LA_KEY_F7;
  1426. if(strSame(p,"F8")) return LA_KEY_F8;
  1427. if(strSame(p,"F9")) return LA_KEY_F9;
  1428. if(strSame(p,"F10")) return LA_KEY_F10;
  1429. if(strSame(p,"F11")) return LA_KEY_F11;
  1430. if(strSame(p,"F12")) return LA_KEY_F12;
  1431. int adv;
  1432. return laToUnicode(p,&adv);
  1433. }
  1434. laCustomSignal* laFindSignal(char* Name){
  1435. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1436. return 0;
  1437. }
  1438. laCustomSignal* laFindSignalByID(int ID){
  1439. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1440. return 0;
  1441. }
  1442. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1443. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1444. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1445. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1446. char* signal = SSTR(ime->Signal);
  1447. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1448. }
  1449. laInputMapping* laNewInputMapping(char* Name){
  1450. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1451. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1452. strSafeSet(&im->Name,Name);
  1453. return im;
  1454. }
  1455. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1456. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1457. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1458. memAssignRef(e,&e->Parent,im);
  1459. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1460. laInputMappingUpdateSignal(e);
  1461. e->SpecialKeyBits=SpecialKeyBit;
  1462. char buf[64],*_next=buf;
  1463. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1464. }
  1465. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1466. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1467. laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1468. }
  1469. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1470. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1471. }
  1472. void laRemoveInputMapping(laInputMapping* im){
  1473. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1474. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1475. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1476. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1477. }
  1478. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1479. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1480. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1481. return cs;
  1482. }
  1483. void laRemoveCustomSignal(laCustomSignal* cs){
  1484. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1485. }
  1486. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1487. void la_SendSignalsFromEvent(laEvent* e){
  1488. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1489. if(!im){return;}
  1490. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1491. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1492. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1493. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1494. }
  1495. }
  1496. }
  1497. }
  1498. //MSG====================================================
  1499. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1500. if (wnd->win == hwnd) return 1;
  1501. else return 0;
  1502. };
  1503. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1504. if (p->SL){ int s=p->SL<0?0:p->SL;
  1505. if (p->TX != s) laRecalcPanel(p);
  1506. p->TX = s;
  1507. }
  1508. if (p->SR){ int s=p->SR<0?0:p->SR;
  1509. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1510. p->TW = CW - p->TX - s;
  1511. }
  1512. if (p->ST){ int s=p->ST<0?0:p->ST;
  1513. if (p->TY != s) laRecalcPanel(p);
  1514. p->TY = s;
  1515. }
  1516. if (p->SB){ int s=p->SB<0?0:p->SB;
  1517. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1518. p->TH = CH - p->TY - s;
  1519. }
  1520. }
  1521. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1522. laPanel *p = 0;
  1523. b->X = X;
  1524. b->Y = Y;
  1525. b->W = W;
  1526. b->H = H;
  1527. if (b->B1){
  1528. int SplitWidth;
  1529. if (b->Vertical){
  1530. SplitWidth = H * b->SplitRatio;
  1531. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1532. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1533. }else{
  1534. SplitWidth = W * b->SplitRatio;
  1535. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1536. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1537. }
  1538. }
  1539. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1540. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1541. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1542. }
  1543. if (p = b->CurrentPanel){
  1544. int TitleGap=b->Folded?0:LA_RH;
  1545. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1546. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1547. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1548. laRecalcPanel(p);
  1549. }
  1550. }
  1551. void la_UpdateUiPlacement(laWindow *w){
  1552. laLayout *l;
  1553. laPanel *p;
  1554. int CW = w->CW;
  1555. int CH = w->CH;
  1556. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1557. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1558. if(w->MaximizedUi && w->MaximizedUiPanel){
  1559. laRecalcPanel(w->MaximizedUiPanel);
  1560. }elif(w->MaximizedBlock){
  1561. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1562. }else{
  1563. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1564. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1565. }
  1566. }
  1567. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1568. if(p->IsMenuPanel){
  1569. p->TH=p->H=MenuHeight;
  1570. }
  1571. la_EnsurePanelSnapping(p, CW, CH);
  1572. laRecalcPanel(p);
  1573. }
  1574. }
  1575. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1576. laWindow *window;
  1577. #ifdef LAGUI_ANDROID
  1578. window = MAIN.Windows.pFirst; if (!window) return;
  1579. window->X=x;window->Y=y;window->W=w;window->H=h;
  1580. window->CW=w;window->CH=h;
  1581. la_UpdateUiPlacement(window); return;
  1582. #endif
  1583. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1584. if (!window) return;
  1585. #ifdef _WIN32
  1586. RECT rcc; GetClientRect(window->win, &rcc);
  1587. RECT rcw; GetWindowRect(window->win, &rcw);
  1588. window->CW = rcc.right - rcc.left;
  1589. window->CH = rcc.bottom - rcc.top;
  1590. window->W = rcw.right - rcw.left;
  1591. window->H = rcw.bottom - rcw.top;
  1592. window->X = rcw.left; window->Y = rcw.top;
  1593. if (MAIN.AutoSwitchColorSpace) {
  1594. laScreen* s = laGetWindowScreen(window);
  1595. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1596. }
  1597. #endif
  1598. #ifdef LA_LINUX
  1599. XWindowAttributes attr;
  1600. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1601. window->CW = w; window->CH = h;
  1602. window->W = w; window->H = h;
  1603. window->X = x; window->Y = y;
  1604. if(MAIN.AutoSwitchColorSpace){
  1605. laScreen* s = laGetWindowScreen(window);
  1606. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1607. }
  1608. #endif
  1609. la_UpdateUiPlacement(window);
  1610. }
  1611. int la_OnWindowDestroy(SYSWINDOW wnd){
  1612. laListHandle *hlst = &MAIN.Windows;
  1613. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1614. if (!w) return 0;
  1615. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1616. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1617. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1618. laShutoff(1);
  1619. return 1;
  1620. }
  1621. laListHandle h={0};laLayout*l=0;
  1622. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1623. la_DestroyWindow(w);
  1624. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1625. #ifdef LA_LINUX
  1626. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1627. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1628. #endif
  1629. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1630. }
  1631. return 0;
  1632. }
  1633. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1634. laListHandle *el = &wnd->EventList;
  1635. laEvent* last_e=el->pLast;
  1636. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1637. #ifdef LA_LINUX
  1638. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1639. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1640. #endif
  1641. #ifdef _WIN32
  1642. 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);
  1643. #endif
  1644. }
  1645. void laMappingRequestEval();
  1646. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1647. laListHandle *wl = &MAIN.Windows;
  1648. laWindow* wnd;
  1649. #ifdef LAGUI_ANDROID
  1650. wnd = MAIN.Windows.pFirst;
  1651. #else
  1652. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1653. #endif
  1654. if (!wnd){ memFree(e); return; }
  1655. laListHandle *el = &wnd->EventList;
  1656. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1657. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1658. e->window = wnd;
  1659. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1660. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1661. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1662. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1663. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1664. e->GoodPressure=MAIN.IsPen;
  1665. lstAppendItem(el, (laListItem *)e);
  1666. laMappingRequestEval();
  1667. };
  1668. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1669. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1670. la_SaveEvent(hwnd, e, 1);
  1671. };
  1672. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1673. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1674. e->type = LA_INPUT; e->Input=Input;
  1675. la_SaveEvent(hwnd, e, 1);
  1676. }
  1677. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1678. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1679. e->type = LA_EMPTY;
  1680. la_SaveEvent(hwnd, e, 1);
  1681. }
  1682. void laSendOperatorTriggerEvent(){
  1683. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1684. MAIN.ReTriggerOperators = 0;
  1685. }
  1686. int la_TranslateSpecialKey(int keysym){
  1687. #ifdef LA_LINUX
  1688. switch(keysym){
  1689. case XK_Return: return LA_KEY_ENTER;
  1690. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1691. case XK_Delete: return LA_KEY_DELETE;
  1692. case XK_Escape: return LA_KEY_ESCAPE;
  1693. case XK_Tab: return LA_KEY_TAB;
  1694. case XK_Left: return LA_KEY_ARRLEFT;
  1695. case XK_Right: return LA_KEY_ARRRIGHT;
  1696. case XK_Up: return LA_KEY_ARRUP;
  1697. case XK_Down: return LA_KEY_ARRDOWN;
  1698. case XK_Control_L: return LA_KEY_CTRL;
  1699. case XK_Control_R: return LA_KEY_CTRL;
  1700. case XK_Shift_L: return LA_KEY_SHIFT;
  1701. case XK_Shift_R: return LA_KEY_SHIFT;
  1702. case XK_Alt_L: return LA_KEY_ALT;
  1703. case XK_Alt_R: return LA_KEY_ALT;
  1704. case XK_KP_1: return LA_KEY_NUM1;
  1705. case XK_KP_2: return LA_KEY_NUM2;
  1706. case XK_KP_3: return LA_KEY_NUM3;
  1707. case XK_KP_4: return LA_KEY_NUM4;
  1708. case XK_KP_5: return LA_KEY_NUM5;
  1709. case XK_KP_6: return LA_KEY_NUM6;
  1710. case XK_KP_7: return LA_KEY_NUM7;
  1711. case XK_KP_8: return LA_KEY_NUM8;
  1712. case XK_KP_9: return LA_KEY_NUM9;
  1713. case XK_KP_0: return LA_KEY_NUM0;
  1714. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1715. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1716. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1717. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1718. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1719. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1720. default: return keysym;
  1721. }
  1722. #endif
  1723. #ifdef _WIN32
  1724. switch (keysym) {
  1725. case VK_RETURN: return LA_KEY_ENTER;
  1726. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1727. case VK_TAB: return LA_KEY_TAB;
  1728. case VK_LEFT: return LA_KEY_ARRLEFT;
  1729. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1730. case VK_UP: return LA_KEY_ARRUP;
  1731. case VK_DOWN: return LA_KEY_ARRDOWN;
  1732. case VK_CONTROL: return LA_KEY_CTRL;
  1733. case VK_SHIFT: return LA_KEY_SHIFT;
  1734. case VK_MENU: return LA_KEY_ALT;
  1735. case VK_F1: return LA_KEY_F1;
  1736. case VK_F2: return LA_KEY_F2;
  1737. case VK_F3: return LA_KEY_F3;
  1738. case VK_F4: return LA_KEY_F4;
  1739. case VK_F5: return LA_KEY_F5;
  1740. case VK_F6: return LA_KEY_F6;
  1741. case VK_F7: return LA_KEY_F7;
  1742. case VK_F8: return LA_KEY_F8;
  1743. case VK_F9: return LA_KEY_F9;
  1744. case VK_F10: return LA_KEY_F10;
  1745. case VK_F11: return LA_KEY_F11;
  1746. case VK_F12: return LA_KEY_F12;
  1747. case VK_NUMPAD0: return LA_KEY_NUM0;
  1748. case VK_NUMPAD1: return LA_KEY_NUM1;
  1749. case VK_NUMPAD2: return LA_KEY_NUM2;
  1750. case VK_NUMPAD3: return LA_KEY_NUM3;
  1751. case VK_NUMPAD4: return LA_KEY_NUM4;
  1752. case VK_NUMPAD5: return LA_KEY_NUM5;
  1753. case VK_NUMPAD6: return LA_KEY_NUM6;
  1754. case VK_NUMPAD7: return LA_KEY_NUM7;
  1755. case VK_NUMPAD8: return LA_KEY_NUM8;
  1756. case VK_NUMPAD9: return LA_KEY_NUM9;
  1757. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1758. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1759. case VK_ADD: return LA_KEY_NUMPLUS;
  1760. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1761. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1762. case VK_OEM_1: return ';';
  1763. case VK_OEM_2: return '/';
  1764. case VK_OEM_3: return '`';
  1765. case VK_OEM_4: return '[';
  1766. case VK_OEM_5: return '\\';
  1767. case VK_OEM_6: return ']';
  1768. case VK_OEM_7: return '\'';
  1769. case VK_OEM_COMMA: return ',';
  1770. case VK_OEM_PERIOD: return '.';
  1771. case VK_OEM_PLUS: return '+';
  1772. case VK_OEM_MINUS: return '-';
  1773. default: return keysym;
  1774. }
  1775. #endif
  1776. }
  1777. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1778. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1779. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1780. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1781. // la_SaveEvent(hwnd, e, 0);
  1782. //}
  1783. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1784. e->type = type; e->x = x; e->y = y;
  1785. la_SaveEvent(hwnd, e, 0);
  1786. MAIN.evLastX=x; MAIN.evLastY=y;
  1787. };
  1788. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1789. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1790. e->type = type;
  1791. la_SaveEvent(hwnd, e, 1);
  1792. };
  1793. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1794. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1795. e->type = LA_SIGNAL_EVENT;
  1796. e->key = signal;
  1797. la_SaveEvent(hwnd, e, 1);
  1798. };
  1799. void laRetriggerOperators(){
  1800. MAIN.ReTriggerOperators = 1;
  1801. }
  1802. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1803. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1804. }
  1805. void laSetCleanupCallback(laCleanupF Cleanup){
  1806. MAIN.Cleanup=Cleanup;
  1807. }
  1808. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1809. MAIN.InputProcess=InputProcess;
  1810. }
  1811. //====================================================================================================
  1812. void la_DestroyTheme(laTheme* t){
  1813. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1814. strSafeDestroy(&t->Name);
  1815. strSafeDestroy(&t->Author);
  1816. }
  1817. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1818. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1819. strSafeSet(&t->Name, Name);
  1820. strSafeSet(&t->Author, AuthorName);
  1821. lstAppendItem(&MAIN.Themes, t);
  1822. MAIN.CurrentTheme = t;
  1823. return t;
  1824. }
  1825. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1826. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1827. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1828. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1829. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1830. strSafeSet(&bt->Name, Name);
  1831. bt->NormalY=NormalY;
  1832. bt->ActiveY=ActiveY;
  1833. bt->BorderY=BorderY;
  1834. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1835. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1836. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1837. bt->BackRef = BackRef;
  1838. lstAppendItem(&t->BoxedThemes, bt);
  1839. return bt;
  1840. }
  1841. laTheme *laGetTheme(const char *ThemeName){
  1842. laTheme *t = MAIN.Themes.pFirst;
  1843. for (t; t; t = t->Item.pNext){
  1844. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1845. }
  1846. return 0;
  1847. }
  1848. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1849. laTheme *t = MAIN.Themes.pFirst;
  1850. for (t; t; t = t->Item.pNext){
  1851. laBoxedTheme *bt;
  1852. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1853. bt = t->BoxedThemes.pFirst;
  1854. for (bt; bt; bt = bt->Item.pNext){
  1855. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1856. }
  1857. }
  1858. return 0;
  1859. }
  1860. real* laThemeColor(laBoxedTheme* bt, int which){
  1861. switch(which){
  1862. default:
  1863. case LA_BT_NORMAL: return bt->Normal;
  1864. case LA_UI_EDITING:
  1865. case LA_BT_ACTIVE: return bt->Active;
  1866. case LA_BT_BORDER: return bt->Border;
  1867. case LA_BT_TEXT: return bt->Text; break;
  1868. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1869. case LA_BT_DISABLED: return bt->Inactive; break;
  1870. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1871. }
  1872. return bt->Normal;
  1873. }
  1874. real* laAccentColor(int which){
  1875. switch(which){
  1876. default:
  1877. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1878. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1879. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1880. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1881. case LA_BT_FACE:
  1882. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1883. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1884. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1885. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1886. }
  1887. return MAIN.CurrentTheme->SelectionColor;
  1888. }
  1889. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1890. real hcy[3];
  1891. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1892. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1893. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1894. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1895. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1896. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1897. int *tm=&bt->LM,*tp=&bt->LP;
  1898. for(int i=0;i<4;i++){
  1899. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1900. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1901. }
  1902. }
  1903. void la_RefreshThemeColorSelf(laTheme* th){
  1904. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1905. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1906. real hcy[3], usehcy[3];
  1907. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1908. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1909. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1910. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1911. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1912. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1913. }
  1914. void la_RefreshThemeColor(laTheme* th){
  1915. real hcy[3], usehcy[3], normalhcy[3];
  1916. tnsRGB2HCY(th->Color,hcy);
  1917. la_RefreshThemeColorSelf(th);
  1918. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1919. la_RefreshBoxedThemeColor(bt);
  1920. (*bt->BackRef) = bt;
  1921. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1922. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1923. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1924. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1925. }
  1926. }
  1927. //I FUCKING HATE THIS STUPID FUNCTION
  1928. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1929. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1930. laUiListDrawItem *last = uild->Items.pFirst;
  1931. int LimW=_R-_L;
  1932. int SL, SR, SU, SB;
  1933. int Target__B = Target->B;
  1934. int Target__R = Target->R;
  1935. uildi->Target = Target;
  1936. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1937. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1938. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1939. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1940. uildi->L = last ? Target->L - last->XP : Target->L;
  1941. uildi->R = last ? Target__R - last->XP : Target__R;
  1942. uildi->U = last ? Target->U - last->YP : Target->U;
  1943. uildi->B = last ? Target__B - last->YP : Target__B;
  1944. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1945. uildi->L -= GlobalX;
  1946. uildi->R -= GlobalX;
  1947. uildi->U -= GlobalY;
  1948. uildi->B -= GlobalY;
  1949. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1950. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1951. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1952. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1953. uildi->DifX = SL - uildi->L;
  1954. uildi->DifY = SU - uildi->U;
  1955. uildi->L = SL;
  1956. uildi->R = SR+uildi->DifX;
  1957. uildi->U = SU;
  1958. uildi->B = SB;//+uildi->DifY;
  1959. if(uildi->R>_R){ uildi->R=_R; }
  1960. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1961. //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);
  1962. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1963. memFree(uildi);
  1964. return 0;
  1965. }
  1966. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  1967. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  1968. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  1969. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  1970. Target->U + Target->PanY + uildi->DifY+1,
  1971. -100, 100);
  1972. lstPushItem(&uild->Items, uildi);
  1973. return 1;
  1974. }
  1975. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1976. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1977. laUiListDrawItem *last = uild->Items.pFirst;
  1978. int SL, SR, SU, SB;
  1979. if (B - U > LimH) B = U + LimH;
  1980. uildi->XP = last ? last->XP + PanX : PanX;
  1981. uildi->YP = last ? last->YP + PanY : PanY;
  1982. uildi->L = last ? L - last->XP : L;
  1983. uildi->R = last ? R - last->XP : R;
  1984. uildi->U = last ? U - last->YP : U;
  1985. uildi->B = last ? B - last->YP : B;
  1986. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1987. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1988. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1989. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1990. uildi->DifX = SL - uildi->L;
  1991. uildi->DifY = SU - uildi->U;
  1992. uildi->L = SL;
  1993. uildi->R = SR;
  1994. uildi->U = SU;
  1995. uildi->B = SB;
  1996. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1997. tnsOrtho(L + PanX + uildi->DifX,
  1998. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  1999. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2000. U + PanY + uildi->DifY,
  2001. -100, 100);
  2002. lstPushItem(&uild->Items, uildi);
  2003. }
  2004. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2005. int* savel, int* saver, int* saveu, int* saveb){
  2006. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2007. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2008. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2009. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2010. real x,y,w,h;
  2011. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2012. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2013. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2014. }
  2015. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2016. laUiListDrawItem *uildi = uild->Items.pFirst;
  2017. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2018. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2019. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2020. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2021. Target->U + Target->PanY + uildi->DifY -1,
  2022. -100, 100);
  2023. }
  2024. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2025. laUiListDrawItem *uildi = lstPopItem(uild);
  2026. laUiList *Target;
  2027. memFree(uildi);
  2028. uildi = uild->Items.pFirst;
  2029. if (!uildi || !uildi->Target){
  2030. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2031. return;
  2032. }
  2033. Target = uildi->Target;
  2034. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2035. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2036. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2037. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2038. Target->U + Target->PanY + uildi->DifY -1,
  2039. -100, 100);
  2040. }
  2041. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2042. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2043. uildi->L = L;
  2044. uildi->R = R;
  2045. uildi->U = U;
  2046. uildi->B = B;
  2047. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2048. tnsOrtho(L, R, B, U, -100, 100);
  2049. lstPushItem(&uild->Items, uildi);
  2050. }
  2051. void la_ClearUiListMatrix(laUiListDraw *uild){
  2052. laUiListDrawItem *uildi;
  2053. while (uildi = lstPopItem(uild)){
  2054. memFree(uildi);
  2055. }
  2056. }
  2057. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2058. 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);
  2059. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2060. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2061. int la_TestUiListMinumWidth(laUiList *uil);
  2062. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2063. if (ui){
  2064. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2065. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2066. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2067. p->X = p->TX; p->Y = p->TY;
  2068. p->W = p->TW;
  2069. }
  2070. }
  2071. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2072. int cw = MAIN.CurrentWindow->CW;
  2073. int ch = MAIN.CurrentWindow->CH;
  2074. int PH = p->TH;
  2075. laBoxedTheme*bt = *p->BT;
  2076. int uih=uil->B + bt->BM;
  2077. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2078. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2079. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2080. else p->TH = PH;
  2081. p->H = p->TH;
  2082. if(p->BoundUi){
  2083. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2084. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2085. if (p->X < 0) p->X = 0;
  2086. if (p->Y < 0) p->Y = 0;
  2087. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2088. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2089. }else{
  2090. if (p->Y < 0) p->Y = 0;
  2091. if ((!p->Block)&&(!p->IsMenuPanel)){
  2092. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2093. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2094. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2095. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2096. }
  2097. }
  2098. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2099. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2100. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2101. }
  2102. if (p->ST) p->TY = p->ST;
  2103. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2104. if (p->SB) p->TH = ch - p->TY - p->SB;
  2105. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2106. p->TX = p->X; p->TY = p->Y;
  2107. p->TW = p->W; p->TH = p->H;
  2108. }
  2109. void laPlacePanelForCreation(laPanel *p){
  2110. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2111. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2112. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2113. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2114. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2115. p->TX=p->X; p->TY=p->Y;
  2116. }
  2117. }
  2118. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2119. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2120. tnsViewportWithScissor(0, 0, p->W, p->H);
  2121. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2122. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2123. }
  2124. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2125. tnsDrawToScreen();
  2126. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2127. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2128. }
  2129. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2130. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2131. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2132. }
  2133. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2134. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2135. tnsClearAll();
  2136. }
  2137. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2138. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2139. real Color[] = {1, 1, 1, 1};
  2140. real L, W, U, H;
  2141. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2142. if(MAIN.EnableColorManagement){
  2143. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2144. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2145. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2146. }else{
  2147. tnsUniformOutputColorSpace(T->immShader,0);
  2148. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2149. tnsUniformColorComposing(T->immShader,0,0,0);
  2150. }
  2151. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2152. tnsUseNoTexture();
  2153. if (!p->IsMenuPanel){
  2154. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2155. }
  2156. tnsFlush();
  2157. }
  2158. if(p->ParentOperator){
  2159. tnsUseNoTexture();
  2160. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2161. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2162. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2163. }
  2164. switch (p->AnimationMode){
  2165. case 0: /* and */
  2166. case LA_PANEL_ANIMATION_FLASH:
  2167. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2168. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2169. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2170. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2171. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2172. tnsPackAs(GL_TRIANGLES);
  2173. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2174. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2175. }
  2176. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2177. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2178. if((int)(p->AnimationRatio*6)%2){
  2179. tnsUseNoTexture();
  2180. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2181. 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);
  2182. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2183. }
  2184. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2185. }
  2186. break;
  2187. case LA_PANEL_ANIMATION_DROP_DOWN:
  2188. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2189. tnsDraw2DTextureArg(
  2190. p->OffScr->pColor[0],
  2191. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2192. Color,
  2193. 0, 0, 1 - p->AnimationRatio, 0);
  2194. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2195. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2196. break;
  2197. case LA_PANEL_ANIMATION_EXPAND:
  2198. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2199. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2200. W = tnsLinearItp(0, p->W, 0.4);
  2201. H = tnsLinearItp(0, p->H, 0.4);
  2202. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2203. tnsDraw2DTextureArg(
  2204. p->OffScr->pColor[0],
  2205. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2206. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2207. Color,
  2208. 0, 0, 0, 0);
  2209. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2210. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2211. break;
  2212. case LA_PANEL_ANIMATION_DISSOVE:
  2213. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2214. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2215. W = tnsLinearItp(0, p->W, 1.4);
  2216. H = tnsLinearItp(0, p->H, 1.4);
  2217. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2218. if (p->OffScr) tnsDraw2DTextureArg(
  2219. p->OffScr->pColor[0],
  2220. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2221. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2222. Color,
  2223. 0, 0, 0, 0);
  2224. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2225. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2226. break;
  2227. case LA_PANEL_ANIMATION_COLLAPSE:
  2228. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2229. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2230. W = tnsLinearItp(0, p->W, 0.4);
  2231. H = tnsLinearItp(0, p->H, 0.4);
  2232. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2233. if (p->OffScr) tnsDraw2DTextureArg(
  2234. p->OffScr->pColor[0],
  2235. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2236. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2237. Color,
  2238. 0, 0, 0, 0);
  2239. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2240. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2241. break;
  2242. case LA_PANEL_ANIMATION_MINIMIZE:
  2243. L = tnsLinearItp(0, p->X, 0.3);
  2244. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2245. W = tnsLinearItp(0, p->W, 0.4);
  2246. H = tnsLinearItp(0, p->H, 0.4);
  2247. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2248. tnsDraw2DTextureArg(
  2249. p->OffScr->pColor[0],
  2250. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2251. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2252. Color,
  2253. 0, 0, 0, 0);
  2254. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2255. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2256. break;
  2257. }
  2258. tnsFlush();
  2259. tnsUniformOutputColorSpace(T->immShader,0);
  2260. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2261. tnsUniformColorComposing(T->immShader,0,0,0);
  2262. }
  2263. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2264. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2265. else{
  2266. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:GL_RGBA8;
  2267. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2268. }
  2269. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2270. }
  2271. void la_PanelRefreshDetachedProp(laPanel *panel){
  2272. laProp *p;
  2273. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2274. la_StepPropPack(&p->DetachedPP);
  2275. la_UsePropPack(&p->DetachedPP, 0);
  2276. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2277. // laUseDataBlock(
  2278. // p->DetachedPP.LastPs->UseInstance,
  2279. // p->DetachedPP.LastPs->p,
  2280. // MAIN.PropMatcherContextP->FrameDistinguish,
  2281. // MAIN.PropMatcherContextP,
  2282. // la_PropPanelUserRemover, 0);
  2283. //}
  2284. }
  2285. }
  2286. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2287. real* color=laThemeColor(bt,LA_BT_BORDER);
  2288. tnsColor4d(0,0,0,Alpha);
  2289. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2290. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2291. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2292. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2293. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2294. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2295. tnsPackAs(GL_TRIANGLE_STRIP);
  2296. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2297. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2298. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2299. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2300. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2301. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2302. }
  2303. int la_AnimateUiListRecursive(laUiList *uil);
  2304. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2305. int DrawState_ = 0;
  2306. laUiListDraw uild = {0};
  2307. if (p->Show){
  2308. la_SetPropMathcerContext(p);
  2309. MAIN.CurrentPanel = p;
  2310. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2311. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2312. //}
  2313. if (p->Refresh & LA_TAG_RECALC){
  2314. laRecalcPanelImmediate(p);
  2315. }
  2316. if (!p->MenuRefer){
  2317. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2318. if (p->Refresh || !p->OffScr){
  2319. la_PanelDrawToOffsceen(p, &p->UI);
  2320. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2321. la_PanelBackgroundInit(p, bt);
  2322. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2323. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2324. tnsFlush();
  2325. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2326. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2327. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2328. DrawState_++;
  2329. }
  2330. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2331. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2332. if(p->UI.PanY<0){p->UI.PanY=0;}
  2333. DrawState_++;
  2334. }
  2335. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2336. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2337. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2338. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2339. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2340. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2341. if(p!=w->MaximizedUiPanel){
  2342. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2343. }else{
  2344. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2345. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2346. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2347. tnsFlush();
  2348. }
  2349. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2350. }
  2351. }else{
  2352. if (p->Refresh || !p->OffScr){
  2353. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2354. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2355. la_PanelBackgroundInit(p, bt);
  2356. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2357. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2358. tnsFlush();
  2359. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2360. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2361. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2362. DrawState_++;
  2363. }
  2364. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2365. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2366. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2367. DrawState_++;
  2368. }
  2369. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2370. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2371. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2372. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2373. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2374. }
  2375. }
  2376. tnsDrawToScreen();
  2377. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2378. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2379. la_PanelDrawToWindow(p, w);
  2380. }elif (p->AnimationMode){
  2381. la_PanelDrawToWindow(p, w);
  2382. }
  2383. }
  2384. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2385. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2386. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2387. laPanel *pi, *PrevPI;
  2388. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2389. PrevPI = pi->Item.pPrev;
  2390. if (pi->AnimationMode && pi->LaterDestroy){
  2391. lstRemoveItem(&p->SubPanels, pi);
  2392. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2393. continue;
  2394. }
  2395. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2396. la_AttachedPanelDefDraw(w,pi,bt);
  2397. }
  2398. }
  2399. }
  2400. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2401. real PanelSquare[] = {
  2402. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2403. b->X + 2, CH - (b->Y + b->H - 4),
  2404. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2405. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2406. real Center[] = {
  2407. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2408. real DraggingPlot[] = {
  2409. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2410. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2411. PanelSquare[0],
  2412. PanelSquare[1],
  2413. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2414. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2415. PanelSquare[2],
  2416. PanelSquare[3],
  2417. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2418. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2419. PanelSquare[4],
  2420. PanelSquare[5],
  2421. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2422. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2423. PanelSquare[6],
  2424. PanelSquare[7],
  2425. };
  2426. real Square[] = {
  2427. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2428. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2429. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2430. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2431. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2432. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2433. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2434. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2435. };
  2436. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2437. LA_COLOR3(BorderColor4dV), 0,
  2438. LA_COLOR3(BorderColor4dV), 0.8,
  2439. LA_COLOR3(BorderColor4dV), 0,
  2440. LA_COLOR3(BorderColor4dV), 0.8,
  2441. LA_COLOR3(BorderColor4dV), 0,
  2442. LA_COLOR3(BorderColor4dV), 0.8,
  2443. LA_COLOR3(BorderColor4dV), 0,
  2444. };
  2445. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2446. LA_COLOR3(FillColor4dv), 0,
  2447. LA_COLOR3(FillColor4dv), 0.8,
  2448. LA_COLOR3(FillColor4dv), 0,
  2449. LA_COLOR3(FillColor4dv), 0.8,
  2450. LA_COLOR3(FillColor4dv), 0,
  2451. LA_COLOR3(FillColor4dv), 0.8,
  2452. LA_COLOR3(FillColor4dv), 0,
  2453. };
  2454. tnsUseNoTexture();
  2455. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2456. int Index[4];
  2457. tnsVertexArray2d(DraggingPlot, 8);
  2458. tnsColorArray4d(FillColor, 8);
  2459. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2460. case 0:
  2461. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2462. break;
  2463. case LA_BLOCK_DROP_LOCATION_L:
  2464. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2465. break;
  2466. case LA_BLOCK_DROP_LOCATION_R:
  2467. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2468. break;
  2469. case LA_BLOCK_DROP_LOCATION_U:
  2470. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2471. break;
  2472. case LA_BLOCK_DROP_LOCATION_B:
  2473. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2474. break;
  2475. }
  2476. //glDisable(GL_CULL_FACE);
  2477. tnsIndexArray(Index, 4);
  2478. tnsPackAs(GL_TRIANGLE_FAN);
  2479. //tnsFlush();
  2480. }
  2481. tnsVertexArray2d(DraggingPlot, 8);
  2482. tnsColorArray4d(PlotColor, 8);
  2483. tnsPackAs(GL_LINES);
  2484. tnsVertexArray2d(Square, 4);
  2485. tnsColor4dv(BorderColor4dV);
  2486. tnsPackAs(GL_LINE_LOOP);
  2487. glLineWidth(LA_SEAM_W);
  2488. tnsFlush();
  2489. glLineWidth(1);
  2490. }
  2491. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2492. laBoxedTheme *bt = _LA_THEME_TAB;
  2493. laPanel *p;
  2494. real v[] = {
  2495. b->X, CH - b->Y,
  2496. b->X + LA_SEAM_W, CH - b->Y ,
  2497. b->X, CH - (b->Y + b->H),
  2498. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2499. b->X + b->W, CH - (b->Y + b->H),
  2500. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2501. b->X + b->W, CH - b->Y,
  2502. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2503. real tv[8];
  2504. real ratio = 1.0001f;
  2505. int tw = 0;
  2506. int L = LA_RH+LA_SEAM_W;
  2507. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2508. if(MAIN.EnableColorManagement){
  2509. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2510. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2511. }else{
  2512. tnsUniformOutputColorSpace(T->immShader,0);
  2513. tnsUniformColorComposing(T->immShader,0,0,0);
  2514. }
  2515. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2516. tw += p->TitleWidth + LA_SEAM_W*2;
  2517. }
  2518. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2519. tnsUseNoTexture();
  2520. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2521. tnsVertexArray2d(v, 8);
  2522. tnsPackAs(GL_TRIANGLE_STRIP);
  2523. int TitleGap=b->Folded?0:LA_RH;
  2524. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2525. b->X + b->W, (CH - b->Y),
  2526. b->X + b->W, (CH - b->Y - TitleGap),
  2527. b->X, (CH - b->Y - TitleGap));
  2528. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2529. tnsVertexArray2d(tv, 4);
  2530. tnsPackAs(GL_TRIANGLE_FAN);
  2531. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2532. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2533. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2534. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2535. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2536. tnsVertexArray2d(tv, 4);
  2537. tnsPackAs(GL_TRIANGLE_FAN);
  2538. if(b->Folded){
  2539. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2540. 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);
  2541. 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);
  2542. tnsFlush(); return;
  2543. }
  2544. int LT=0,RT=0;
  2545. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2546. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2547. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2548. b->X + L+RT * ratio, (CH - b->Y),
  2549. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2550. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2551. if (p == b->CurrentPanel){
  2552. tnsUseNoTexture();
  2553. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2554. tnsVertexArray2d(tv, 4);
  2555. tnsPackAs(GL_TRIANGLE_FAN);
  2556. 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);
  2557. }else{
  2558. 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);
  2559. }
  2560. LT =RT;
  2561. }
  2562. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2563. tnsFlush();
  2564. tnsUniformOutputColorSpace(T->immShader,0);
  2565. tnsUniformColorComposing(T->immShader,0,0,0);
  2566. }
  2567. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2568. laBoxedTheme *bt = _LA_THEME_PANEL;
  2569. real tv[8];
  2570. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2571. if(MAIN.EnableColorManagement){
  2572. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2573. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2574. }else{
  2575. tnsUniformOutputColorSpace(T->immShader,0);
  2576. tnsUniformColorComposing(T->immShader,0,0,0);
  2577. }
  2578. tnsUseNoTexture();
  2579. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2580. b->X + b->W, (CH - b->Y),
  2581. b->X + b->W, (CH - b->Y-b->H),
  2582. b->X, (CH - b->Y-b->H));
  2583. tnsVertexArray2d(tv, 4);
  2584. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2585. tnsPackAs(GL_TRIANGLE_FAN);
  2586. 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,
  2587. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2588. tnsFlush();
  2589. tnsUniformOutputColorSpace(T->immShader,0);
  2590. tnsUniformColorComposing(T->immShader,0,0,0);
  2591. }
  2592. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2593. if (b->B1){
  2594. la_BlockDefDrawRecursive(w, bt, b->B1);
  2595. la_BlockDefDrawRecursive(w, bt, b->B2);
  2596. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2597. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2598. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2599. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2600. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2601. la_BlockDefDrawSelf(b, w->CH);
  2602. }else{
  2603. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2604. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2605. la_BlockDefDrawSelfEmpty(b, w->CH);
  2606. }
  2607. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2608. tnsUseNoTexture();
  2609. int at; real tv[8];
  2610. if (b->Vertical){
  2611. at = b->H * b->SplitRatio + b->Y;
  2612. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2613. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2614. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2615. b->X, (w->CH - at - LA_SEAM_W));
  2616. }else{
  2617. at = b->X + b->W * b->SplitRatio;
  2618. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2619. at- LA_SEAM_W, (w->CH - b->Y),
  2620. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2621. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2622. }
  2623. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2624. tnsVertexArray2d(tv, 4);
  2625. tnsPackAs(GL_TRIANGLE_FAN);
  2626. }
  2627. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2628. tnsFlush();
  2629. }
  2630. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2631. if (b->B1){
  2632. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2633. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2634. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2635. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2636. }
  2637. tnsFlush();
  2638. }
  2639. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2640. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2641. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2642. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2643. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2644. if(p->OffScr){
  2645. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2646. }
  2647. }
  2648. }
  2649. void la_ClearUnusedFramebuffers(laWindow* w){
  2650. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2651. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2652. }
  2653. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2654. if(p->Show || p->AnimationMode) continue;
  2655. if(p->OffScr){
  2656. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2657. }
  2658. }
  2659. }
  2660. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2661. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2662. laPanel *p, *NextP;
  2663. laLayout *l = w->CurrentLayout;
  2664. if (!w->CH || !w->CW) return;
  2665. la_ClearUnusedFramebuffers(w);
  2666. tnsDrawToScreen();
  2667. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2668. glClearColor(0.2, 0.2, 0.3, 1.0);
  2669. tnsClearAll();
  2670. tnsUseNoTexture();
  2671. if (l->Draw) l->Draw(w, l);
  2672. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2673. glEnable(GL_BLEND);
  2674. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2675. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2676. laUiItem* ui;
  2677. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2678. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2679. la_SetPropMathcerContext(p);
  2680. if(p->Refresh){
  2681. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2682. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2683. if(MAIN.EnableColorManagement){
  2684. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2685. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2686. }else{
  2687. tnsUniformOutputColorSpace(T->immShader,0);
  2688. tnsUniformColorComposing(T->immShader,0,0,0);
  2689. }
  2690. if(p->Refresh&LA_TAG_RECALC){
  2691. laRecalcPanelImmediate(p);
  2692. }
  2693. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2694. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2695. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2696. }
  2697. tnsDrawToScreen();
  2698. tnsResetViewMatrix();
  2699. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2700. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2701. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2702. tnsFlush();
  2703. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2704. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2705. tnsFlush();
  2706. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2707. }
  2708. }
  2709. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2710. la_AttachedPanelDefDraw(w,p,*p->BT);
  2711. }else{
  2712. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2713. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2714. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2715. }
  2716. for (p = w->Panels.pLast; p; p = NextP){
  2717. NextP = p->Item.pPrev;
  2718. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2719. if (p->AnimationMode && p->LaterDestroy){
  2720. lstRemoveItem(&w->Panels, p);
  2721. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2722. continue;
  2723. }
  2724. la_PanelDefDraw(w, p, *p->BT);
  2725. }
  2726. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2727. la_AttachedPanelDefDraw(w,p,*p->BT);
  2728. }
  2729. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2730. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2731. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2732. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2733. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2734. tnsFlush();
  2735. }
  2736. for (p = w->FadingPanels.pLast; p; p = NextP){
  2737. NextP = p->Item.pPrev;
  2738. if (!p->AnimationMode){
  2739. lstRemoveItem(&w->FadingPanels, p);
  2740. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2741. laDeferredDestroyPanel(p, 0);
  2742. }else
  2743. la_PanelDrawToWindow(p, w);
  2744. }
  2745. }
  2746. int laStartWindow(laWindow *w){
  2747. #ifdef LA_LINUX
  2748. XMapWindow(MAIN.dpy,w->win);
  2749. tnsContextMakeWindowCurrent(w);
  2750. #endif
  2751. #ifdef _WIN32
  2752. ShowWindow(w->win, SW_SHOWNORMAL);
  2753. #endif
  2754. MAIN.CurrentWindow = w;
  2755. if(!w->CurrentLayout){
  2756. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2757. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2758. }
  2759. laRedrawCurrentWindow();
  2760. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2761. w->Shown = 1;
  2762. }
  2763. void la_AssignWindowPP(laWindow* w){
  2764. w->PP.EndInstance = w;
  2765. w->PP.LastPs = &w->FakePS;
  2766. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2767. w->PP.LastPs->UseInstance = w;
  2768. w->PP.LastPs->Type = U'.';
  2769. }
  2770. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2771. #ifdef LAGUI_ANDROID
  2772. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2773. #endif
  2774. laWindow *n = memAcquire(sizeof(laWindow));
  2775. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2776. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2777. #ifdef LAGUI_ANDROID
  2778. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2779. #endif
  2780. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2781. lstAppendItem(&MAIN.Windows, n);
  2782. MAIN.CurrentWindow = n;
  2783. la_AssignWindowPP(n);
  2784. laui_DefaultMenuBar(n);
  2785. return n;
  2786. }
  2787. void laSetWindowCursor(int id){
  2788. MAIN.CurrentCursor = id;
  2789. #ifdef LA_LINUX
  2790. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2791. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2792. #endif
  2793. #ifdef _WIN32
  2794. SetCursor(la_ConvertCursorID(id));
  2795. #endif
  2796. };
  2797. void la_AssignBlockPP(laBlock* b){
  2798. b->PP.EndInstance = b;
  2799. b->PP.LastPs = &b->FakePS;
  2800. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2801. b->PP.LastPs->UseInstance = b;
  2802. b->PP.LastPs->Type = U'.';
  2803. }
  2804. void laDestroyLayout(laWindow *w, laLayout* l){
  2805. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2806. laDestroyBlocksRecursive(l->FirstBlock);
  2807. strSafeDestroy(&l->ID);
  2808. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2809. lstRemoveItem(&w->Layouts,l); memFree(l);
  2810. }
  2811. laLayout *laDesignLayout(laWindow *w, char *Title){
  2812. laLayout *l = memAcquire(sizeof(laLayout));
  2813. l->FirstBlock = memAcquire(sizeof(laBlock));
  2814. la_AssignBlockPP(l->FirstBlock);
  2815. lstAppendItem(&w->Layouts, l);
  2816. strSafeSet(&l->ID, Title);
  2817. memAssignRef(w, &w->CurrentLayout, l);
  2818. laRenameWindow(w, Title);
  2819. return l;
  2820. }
  2821. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2822. 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); }
  2823. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2824. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2825. laNotifyUsers("la.windows.maximized_block"); }
  2826. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2827. laNotifyUsers("la.windows.maximized_block"); }
  2828. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2829. laRestoreCanvasUI();
  2830. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2831. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2832. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2833. UiParentPanel->Show=0;
  2834. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2835. }
  2836. void laRestoreCanvasUI(){
  2837. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2838. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2839. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2840. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2841. }
  2842. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2843. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2844. }
  2845. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2846. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2847. laPanel *p;
  2848. b->SplitRatio = Percentage;
  2849. b->Vertical = 0;
  2850. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2851. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2852. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2853. p->Block = b->B1;
  2854. }
  2855. b->B1->Panels.pFirst = b->Panels.pFirst;
  2856. b->B1->Panels.pLast = b->Panels.pLast;
  2857. b->B1->CurrentPanel = b->CurrentPanel;
  2858. b->B1->parent = b->B2->parent=b;
  2859. b->Panels.pFirst = 0;
  2860. b->Panels.pLast = 0;
  2861. b->CurrentPanel = 0;
  2862. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2863. }
  2864. void laSplitBlockVertical(laBlock *b, real Percentage){
  2865. laPanel *p;
  2866. b->SplitRatio = Percentage;
  2867. b->Vertical = 1;
  2868. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2869. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2870. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2871. p->Block = b->B1;
  2872. }
  2873. b->B1->Panels.pFirst = b->Panels.pFirst;
  2874. b->B1->Panels.pLast = b->Panels.pLast;
  2875. b->B1->CurrentPanel = b->CurrentPanel;
  2876. b->B1->parent = b->B2->parent=b;
  2877. b->Panels.pFirst = 0;
  2878. b->Panels.pLast = 0;
  2879. b->CurrentPanel = 0;
  2880. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2881. }
  2882. void laCombineChildBlocks(laBlock *b){
  2883. laPanel *p; if(!b) return;
  2884. if (!b->B1->B1 && !b->B2->B1){
  2885. lstCombineLists(&b->Panels, &b->B1->Panels);
  2886. lstCombineLists(&b->Panels, &b->B2->Panels);
  2887. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2888. p->Block = b;
  2889. }
  2890. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2891. memFree(b->B1);
  2892. memFree(b->B2);
  2893. b->B1 = 0;
  2894. b->B2 = 0;
  2895. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2896. }elif(!b->B1->B1){
  2897. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2898. b->Vertical = b->B2->Vertical;
  2899. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2900. p->Block = b1;
  2901. }
  2902. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2903. memFree(b->B1); memFree(b->B2);
  2904. b->B1 = b1; b->B2 = b2;
  2905. b1->parent = b; b2->parent = b;
  2906. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2907. }elif(!b->B2->B1){
  2908. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2909. b->Vertical = b->B1->Vertical;
  2910. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2911. p->Block = b1;
  2912. }
  2913. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2914. memFree(b->B1); memFree(b->B2);
  2915. b->B1 = b1; b->B2 = b2;
  2916. b1->parent = b; b2->parent = b;
  2917. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2918. }
  2919. }
  2920. laBlock *laBlock1(laBlock *b){
  2921. return b->B1;
  2922. }
  2923. laBlock *laBlock2(laBlock *b){
  2924. return b->B2;
  2925. }
  2926. laBlock *laSwapSubBlocks(laBlock *b){
  2927. laBlock *tB;
  2928. tB = b->B2;
  2929. b->B2 = b->B1;
  2930. b->B1 = tB;
  2931. b->SplitRatio = 1 - b->SplitRatio;
  2932. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2933. }
  2934. void laDestroyBlocksRecursive(laBlock *Root){
  2935. laPanel *p;
  2936. if (Root->B1){
  2937. laDestroyBlocksRecursive(Root->B1);
  2938. laDestroyBlocksRecursive(Root->B2);
  2939. }else{
  2940. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2941. }
  2942. memFree(Root);
  2943. }
  2944. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2945. if(!b->CurrentPanel ) return 0;
  2946. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2947. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2948. lstRemoveItem(&b->Panels, p);
  2949. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  2950. if(!p->TitleBar.UiItems.pFirst){
  2951. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2952. }
  2953. p->Mode = LA_PANEL_FLOATING_TOP;
  2954. p->TY-=LA_RH; p->TH+=LA_RH;
  2955. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  2956. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  2957. p->Block = 0;
  2958. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  2959. laRecalcPanel(p);
  2960. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2961. p->BT = &_LA_THEME_FLOATING_PANEL;
  2962. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2963. laNotifyUsers("la.windows.panels");
  2964. return b->CurrentPanel;
  2965. }
  2966. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2967. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2968. lstRemoveItem(&from->Panels, p);
  2969. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2970. p->Mode = LA_PANEL_NORMAL;
  2971. p->Block=b;
  2972. b->CurrentPanel = p;
  2973. lstPushItem(&b->Panels, p);
  2974. laRecalcPanel(p);
  2975. p->BT = &_LA_THEME_PANEL;
  2976. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2977. tnsFlush();
  2978. laNotifyUsers("la.windows.panels");
  2979. }
  2980. void laPopPanel(laPanel *p){
  2981. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2982. lstRemoveItem(&p->Parent->SubPanels, p);
  2983. lstPushItem(&p->Parent->SubPanels, p);
  2984. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2985. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2986. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2987. laNotifyUsers("la.windows.panels");
  2988. }
  2989. }
  2990. void la_EnsurePanelExtras(laPanel *p){
  2991. laUiTemplate* uit=p->PanelTemplate;
  2992. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  2993. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  2994. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  2995. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  2996. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  2997. p->PropLinkFakeProp->Base.Offset = 0;
  2998. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  2999. p->PropLinkPP.EndInstance = p;
  3000. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3001. p->PropLinkPP.LastPs->Type = U'.';
  3002. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3003. }
  3004. laPanel* la_GivePanelNode(){
  3005. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3006. return memAcquire(sizeof(laPanel));
  3007. }
  3008. void la_ReturnPanelNode(laPanel* p){
  3009. memset(p,0,sizeof(laPanel));
  3010. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3011. lstAppendItem(&MAIN.WastedPanels, p);
  3012. }
  3013. 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){
  3014. laPanel *p = la_GivePanelNode();
  3015. int CW = MAIN.CurrentWindow->CW;
  3016. int CH = MAIN.CurrentWindow->CH;
  3017. p->PanelTemplate = uit;
  3018. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3019. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3020. if (!MaxW) MaxW = 10000;
  3021. if (!MaxH) MaxH = 10000;
  3022. if (W > MaxW) W = MaxW;
  3023. if (H > MaxH) H = MaxH;
  3024. if (W < MinW) W = MinW;
  3025. if (H < MinH) H = MinH;
  3026. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3027. p->X = p->TX = (X < 0 ? 0 : X);
  3028. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3029. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3030. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3031. p->MaxW = MaxW; p->MaxH = MaxH;
  3032. p->MinW = MinW; p->MinH = MinH;
  3033. p->SL = SnapL; p->ST = SnapT;
  3034. p->SR = SnapR; p->SB = SnapB;
  3035. if (p->SR) p->X = CW - p->W - p->SR;
  3036. if (p->SB) p->Y = CH - p->H - p->SB;
  3037. la_EnsurePanelSnapping(p, CW, CH);
  3038. p->Show = 1;
  3039. p->PP.EndInstance = p;
  3040. p->PP.LastPs = &p->FakePS;
  3041. p->PP.LastPs->p = _LA_PROP_PANEL;
  3042. p->PP.LastPs->UseInstance = p;
  3043. p->PP.LastPs->Type = U'.';
  3044. la_EnsurePanelExtras(p);
  3045. laRecalcPanel(p);
  3046. p->FrameDistinguish = 100; //greater than 1 is ok
  3047. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3048. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3049. return p;
  3050. }
  3051. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3052. if(!uit) return 0;
  3053. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3054. strSafeSet(&p->Title, uit->Title->Ptr);
  3055. p->PanelTemplate = uit;
  3056. p->Show = 1;
  3057. p->PP.EndInstance = p;
  3058. p->PP.LastPs = &p->FakePS;
  3059. p->PP.LastPs->p = _LA_PROP_PANEL;
  3060. p->PP.LastPs->UseInstance = p;
  3061. p->PP.LastPs->Type = U'.';
  3062. la_EnsurePanelExtras(p);
  3063. laRecalcPanel(p);
  3064. p->FrameDistinguish = 100; //greater than 1 is ok
  3065. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3066. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3067. p->Block = b; b->CurrentPanel = p;
  3068. if(uit->PropFunc){ uit->PropFunc(p); }
  3069. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3070. laNotifyUsers("la.windows.panels");
  3071. return p;
  3072. }
  3073. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3074. laUiTemplate* uit=laFindUiTemplate(template_id);
  3075. return laCreatePanelT(b, uit);
  3076. }
  3077. 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){
  3078. laUiTemplate* uit=0;
  3079. if(template_id) uit=laFindUiTemplate(template_id);
  3080. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3081. p->Mode = LA_PANEL_FLOATING_TOP;
  3082. laPlacePanelForCreation(p);
  3083. if(uit){
  3084. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3085. }
  3086. if (w) lstPushItem(&w->Panels, p);
  3087. return p;
  3088. }
  3089. void laShowPanel(laPanel *p){
  3090. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3091. }
  3092. void laShowPanelWithDropDownEffect(laPanel *p){
  3093. laShowPanel(p);
  3094. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3095. p->AnimationRatio = 0;
  3096. }
  3097. void laShowPanelWithExpandEffect(laPanel *p){
  3098. laShowPanel(p);
  3099. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3100. p->AnimationRatio = 0;
  3101. }
  3102. void laHidePanel(laPanel *p){
  3103. if (!p->Mode) return;
  3104. p->Show = 0;
  3105. laNotifyUsers("la.windows.panels_hidden");
  3106. }
  3107. void laHidePanelWithDissoveEffect(laPanel *p){
  3108. if (!p->Mode) return;
  3109. laHidePanel(p);
  3110. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3111. p->AnimationRatio = 1;
  3112. }
  3113. void laHidePanelWithCollapseEffect(laPanel *p){
  3114. if (!p->Mode) return;
  3115. laHidePanel(p);
  3116. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3117. p->AnimationRatio = 1;
  3118. }
  3119. void laHidePanelWithMinimizeEffect(laPanel *p){
  3120. if (!p->Mode) return;
  3121. laHidePanel(p);
  3122. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3123. p->AnimationRatio = 1;
  3124. }
  3125. void laActivatePanel(char* TemplateID, int x, int y){
  3126. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3127. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3128. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3129. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3130. }
  3131. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3132. p->UI.PanX += DeltaX;
  3133. p->UI.PanY += DeltaY;
  3134. }
  3135. int laPanUiListFree(laUiList *uil, int X, int Y){
  3136. uil->PanX+=X; uil->PanY+=Y;
  3137. }
  3138. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3139. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3140. if(Y){X+=Y;Y=0;}
  3141. }
  3142. if (Y > 0){
  3143. if (uil->B - uil->PanY <= B) return 0;
  3144. else{
  3145. uil->PanY += Y;
  3146. if (uil->B - uil->PanY <= B){
  3147. uil->PanY = uil->B - B;
  3148. return 1;
  3149. }
  3150. }
  3151. }
  3152. if (Y < 0){
  3153. if (uil->U - uil->PanY >= U) return 0;
  3154. else{
  3155. uil->PanY += Y;
  3156. if (uil->U - uil->PanY >= U){
  3157. uil->PanY = uil->U - U;
  3158. return 1;
  3159. }
  3160. }
  3161. }
  3162. if(uil->AllowScale){
  3163. laPanUiListFree(uil, X, 0);
  3164. }else{
  3165. if (X > 0){
  3166. if (uil->R - uil->PanX <= R) return 0;
  3167. else{
  3168. uil->PanX += X;
  3169. if (uil->R - uil->PanX <= R){
  3170. uil->PanX = uil->R - R;
  3171. return 1;
  3172. }
  3173. }
  3174. }
  3175. if (X < 0){
  3176. if (uil->L - uil->PanX >= L) return 0;
  3177. else{
  3178. uil->PanX += X;
  3179. if (uil->L - uil->PanX >= L){
  3180. uil->PanX = uil->L - L;
  3181. return 1;
  3182. }
  3183. }
  3184. }
  3185. }
  3186. return 1;
  3187. }
  3188. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3189. int ret=1;
  3190. if(!uil->AllowScale){ return 0; }
  3191. real NewScale=uil->Scale*factor;
  3192. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3193. if(NewScale>5) {NewScale=5; ret=0;}
  3194. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3195. factor=NewScale/uil->Scale;
  3196. uil->Scale=NewScale;
  3197. real mx=(L+R)/2,my=(U+B)/2;
  3198. real dx= (mx+uil->PanX)*factor;
  3199. real dy= (my+uil->PanY)*factor;
  3200. uil->PanX=dx-mx;
  3201. uil->PanY=dy-my;
  3202. MAIN.CurrentPanel->FrameDistinguish=100;
  3203. return ret;
  3204. }
  3205. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3206. if(uil->AllowScale) return 0;
  3207. return laPanUiList(uil,X,Y,L,R,U,B);
  3208. }
  3209. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3210. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3211. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3212. strSafeSet(&p->Title, Title);
  3213. if (Define){
  3214. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3215. }
  3216. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3217. p->BT= &_LA_THEME_FLOATING_PANEL;
  3218. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3219. p->BoundUi = 1;
  3220. return p;
  3221. }
  3222. 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,
  3223. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3224. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3225. strSafeSet(&p->Title, Title);
  3226. if (Define){
  3227. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3228. }
  3229. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3230. p->BT= &_LA_THEME_FLOATING_PANEL;
  3231. p->Mode = LA_PANEL_FLOATING_TOP;
  3232. p->BoundUi = 1;
  3233. return p;
  3234. }
  3235. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3236. laPanel *ip;
  3237. tnsDelete2DOffscreen(p->OffScr);
  3238. p->OffScr = 0;
  3239. strSafeDestroy(&p->Title);
  3240. if (!p->AnimationMode){
  3241. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3242. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3243. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3244. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3245. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3246. }else if (p->Block){
  3247. lstRemoveItem(&p->Block->Panels, p);
  3248. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3249. }
  3250. laNotifyUsers("la.windows.panels");
  3251. }
  3252. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3253. //lstRemoveItem(&p->SubPanels, ip);
  3254. laDestroySinglePanel(ip, immediate);
  3255. laNotifyUsers("la.windows.panels");
  3256. }
  3257. la_ClearDetachedProp(p);
  3258. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3259. la_ReturnPanelNode(p);
  3260. }
  3261. void laDestroySinglePanel(laPanel *p, int immediate){
  3262. la_SetPropMathcerContext(p);
  3263. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3264. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3265. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3266. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3267. }
  3268. }
  3269. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3270. la_DestroyUiList(&p->UI, 1, 1, 0);
  3271. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3272. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3273. if (p->Mode){
  3274. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3275. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3276. }
  3277. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3278. if (la_UiStillInService(p)){
  3279. la_StopUiOperatorService(p);
  3280. }
  3281. if ((!p->AnimationMode) || immediate){
  3282. laDeferredDestroyPanel(p, immediate);
  3283. }else{
  3284. p->LaterDestroy = 1;
  3285. }
  3286. }
  3287. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3288. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3289. int MinW,MinWt=0;
  3290. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3291. int CW = MAIN.CurrentWindow->CW;
  3292. if(p->SL && p->SR){return 0;}
  3293. la_SetPropMathcerContext(p);
  3294. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3295. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3296. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3297. MinW = la_TestUiListMinumWidth(uil);
  3298. if (MinW<MinWt){MinW=MinWt;}
  3299. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3300. if (MinW > 20){
  3301. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3302. }
  3303. la_PanelValidateWidth(p,uil);
  3304. laEnsurePanelInBound(p,uil);
  3305. if(p->TW>CW){ p->TW=CW; }
  3306. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3307. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3308. laRedrawPanel(p);
  3309. return 1;
  3310. }
  3311. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3312. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3313. laOperator *ai = a;
  3314. laPanel *p;
  3315. int GX, GY, GW, t = 0;
  3316. int b;
  3317. laUiDefineFunc def = ReplaceUiDefine;
  3318. int MinW;
  3319. if (!def){ def=laui_DefaultPropDetails; }
  3320. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3321. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3322. laEnclosePanelContent(p, &p->UI);
  3323. laSetOperatorLocalizer(p);
  3324. p->CloseWhenMovedOut=1;
  3325. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3326. //laShowPanelWithDropDownEffect(p);
  3327. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3328. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3329. return p;
  3330. }
  3331. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3332. laPanel *p;
  3333. int GX, GY, GW, t = 0;
  3334. int b;
  3335. laUiDefineFunc def = ReplaceUiDefine;
  3336. int MinW;
  3337. if (!def) return 0;
  3338. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3339. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3340. p->Mode = LA_PANEL_FLOATING_TOP;
  3341. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3342. laEnclosePanelContent(p, &p->UI);
  3343. if(MAIN.CurrentWindow->Operators.pFirst){
  3344. laSetOperatorLocalizer(MAIN.PendingSplash);
  3345. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3346. MAIN.PendingSplash=0;
  3347. }
  3348. //laShowPanelWithExpandEffect(p);
  3349. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3350. return p;
  3351. }
  3352. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3353. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3354. laOperator *ai = a;
  3355. laPanel *p; laPropContainer* sub;
  3356. int GX, GY, GW, t = 0;
  3357. int b;
  3358. laUiDefineFunc def = ReplaceUiDefine;
  3359. int MinW;
  3360. if (!def){
  3361. if (This && This->LastPs->p){
  3362. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3363. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3364. }
  3365. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3366. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3367. }
  3368. GX = L; GY = B;
  3369. GW = (R - L) > MaxW ? MaxW : (R - L);
  3370. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3371. laEnclosePanelContent(p, &p->UI);
  3372. laSetOperatorLocalizer(p);
  3373. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3374. laShowPanelWithDropDownEffect(p);
  3375. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3376. if(Attachment){
  3377. p->Parent = Attachment;
  3378. lstAppendItem(&Attachment->SubPanels, p);
  3379. }
  3380. return p;
  3381. }
  3382. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3383. laPanel *p;
  3384. int t = 0;
  3385. int b;
  3386. //laLocalToWindow(0, Attachment, &L, &t);
  3387. //laLocalToWindow(0, Attachment, &R, &U);
  3388. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3389. laSetOperatorLocalizer(p);
  3390. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3391. laShowPanelWithDropDownEffect(p);
  3392. p->Parent = Attachment;
  3393. lstPushItem(&Attachment->SubPanels, p);
  3394. return p;
  3395. }
  3396. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3397. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3398. laOperator *ai = a;
  3399. laPanel *p;
  3400. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3401. int GX, GY, GW, t = 0;
  3402. int b;
  3403. int MinW;
  3404. //laLocalToWindow(0,Attachment, &L, &t);
  3405. //laLocalToWindow(0,Attachment, &R, &B);
  3406. GX = L;
  3407. GY = B;
  3408. GW = (R - L) > MaxW ? MaxW : (R - L);
  3409. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3410. p->MenuRefer = MenuRefer;
  3411. laEnclosePanelContent(p, MenuRefer);
  3412. laSetOperatorLocalizer(p);
  3413. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3414. laShowPanelWithDropDownEffect(p);
  3415. p->Parent = Attachment;
  3416. lstPushItem(&Attachment->SubPanels, p);
  3417. return p;
  3418. }
  3419. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3420. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3421. laOperator *ai = a;
  3422. laPanel *p;
  3423. int GX, GY, GW, t = 0;
  3424. int b;
  3425. GX = L;
  3426. GY = B;
  3427. GW = MaxW;
  3428. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3429. p->MenuRefer = &p->UI;
  3430. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3431. laSetOperatorLocalizer(p);
  3432. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3433. laShowPanelWithDropDownEffect(p);
  3434. if (Attachment){
  3435. p->Parent = Attachment;
  3436. lstPushItem(&Attachment->SubPanels, p);
  3437. }else{
  3438. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3439. }
  3440. return p;
  3441. }
  3442. 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){
  3443. laOperator *ai = For;
  3444. laPanel *p;
  3445. int b;
  3446. laUiDefineFunc def = 0;
  3447. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3448. else def = laui_DefaultPropUiDefine;
  3449. For->PP.EndInstance = For->CustomData;
  3450. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3451. laEnclosePanelContent(p, &p->UI);
  3452. MAIN.ToPanel = p;
  3453. laShowPanelWithExpandEffect(p);
  3454. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3455. ai->OperatorPanel = p;
  3456. p->ParentOperator = For;
  3457. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3458. return p;
  3459. }
  3460. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3461. laPanel *p; int b; laUiList *uil; laColumn* col;
  3462. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3463. strSafeSet(&p->Title, Title);
  3464. p->BoundUi = 1;
  3465. p->Mode = LA_PANEL_FLOATING_TOP;
  3466. p->BT = &_LA_THEME_FLOATING_PANEL;
  3467. MAIN.ToPanel = p;
  3468. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3469. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3470. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3471. laUiItem* r=laBeginRow(uil,col,0,0);
  3472. laShowSeparator(uil,col)->Expand=1;
  3473. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3474. laEndRow(uil,r);
  3475. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3476. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3477. laSetOperatorLocalizer(p);
  3478. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3479. return p;
  3480. }
  3481. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3482. laPanel *p; int b; laUiList *uil; laColumn* col;
  3483. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3484. strSafeSet(&p->Title, Title);
  3485. p->BoundUi = 1;
  3486. p->Mode = LA_PANEL_FLOATING_TOP;
  3487. p->BT = &_LA_THEME_FLOATING_PANEL;
  3488. MAIN.ToPanel = p;
  3489. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3490. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3491. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3492. laUiItem* r = laBeginRow(uil,col,0,0);
  3493. laShowSeparator(uil,col)->Expand=1;
  3494. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3495. laEndRow(uil, r);
  3496. laEnclosePanelContent(p,uil);
  3497. laShowPanelWithExpandEffect(p);
  3498. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3499. laSetOperatorLocalizer(p);
  3500. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3501. return p;
  3502. }
  3503. void laOperatorModalOver(laOperator* For){
  3504. For->ModalOver = 1;
  3505. }
  3506. void laDeferredRedraw(laPanel* p){
  3507. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3508. if(lip->p==p) return;
  3509. }
  3510. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3511. }
  3512. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3513. laWindow* cur=MAIN.CurrentWindow;
  3514. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3515. MAIN.CurrentWindow=w;
  3516. la_UpdateUiPlacement(w);
  3517. }
  3518. MAIN.CurrentWindow=cur;
  3519. }
  3520. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3521. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3522. }
  3523. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3524. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3525. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3526. void laRedrawCurrentPanel(){
  3527. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3528. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3529. }
  3530. void laRecalcCurrentPanel(){
  3531. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3532. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3533. }
  3534. void laRecalcPanelImmediate(laPanel* p){
  3535. p->FrameDistinguish++;
  3536. laBoxedTheme* bt = (*p->BT);
  3537. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3538. la_PanelRefreshDetachedProp(p);
  3539. int enclosed=0;
  3540. if(p->BoundUi || p->MenuRefer){
  3541. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3542. else enclosed=laEnclosePanelContent(p, &p->UI);
  3543. }
  3544. if(!enclosed){
  3545. la_PanelValidateWidth(p,&p->UI);
  3546. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3547. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3548. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3549. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3550. }
  3551. laWindow* w=MAIN.CurrentWindow;
  3552. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3553. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3554. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3555. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3556. }
  3557. }
  3558. void laRecalcCurrentPanelImmediate(){
  3559. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3560. }
  3561. int laNonFixedPanelExists(laPanel *p){
  3562. laPanel *ip;
  3563. if (!p) return 0;
  3564. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3565. // if (ip == p) return 1;
  3566. //}
  3567. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3568. if (ip == p) return 1;
  3569. }
  3570. return 0;
  3571. }
  3572. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3573. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3574. return 1;
  3575. }
  3576. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3577. int tt=MAIN.TooltipCloseDistance;
  3578. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3579. return 1;
  3580. }
  3581. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3582. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3583. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3584. return 0;
  3585. return 1;
  3586. }
  3587. void laUnlinkSharedPanel(laPanel *p){
  3588. laWindow *w;
  3589. laPanel *ip;
  3590. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3591. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3592. if (ip == p){
  3593. lstRemoveItem(&w->Panels, ip);
  3594. return;
  3595. }
  3596. }
  3597. }
  3598. }
  3599. int laIsPanelCovered(laPanel *p){
  3600. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3601. laPanel *ip;
  3602. laPanel *resp;
  3603. int in1 = 0, in2 = 0, in3 = 0;
  3604. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3605. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3606. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3607. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3608. //}
  3609. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3610. if (ip == p){
  3611. in3 = 1;
  3612. d3 = 0;
  3613. continue;
  3614. }
  3615. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3616. }
  3617. if (!in2 && !in3) in1 = 1;
  3618. if (in1){
  3619. if (d1 || d2 || d3) return 1;
  3620. }else{
  3621. if (in2){
  3622. if (d2 || d3) return 1;
  3623. }else if (in3)
  3624. if (d3) return 1;
  3625. }
  3626. return 0;
  3627. }
  3628. int laIsTopPanel(laPanel *p){
  3629. //if (!p->Item.pPrev) return 1;
  3630. //else {
  3631. if (!laIsPanelCovered(p)){
  3632. //laPopPanel(p);
  3633. return 1;
  3634. }
  3635. return 0;
  3636. //}
  3637. return 0;
  3638. }
  3639. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3640. if(!p) return;
  3641. int ix = *x, iy = *y;
  3642. laListItemPointer *lip;
  3643. laOperator *ai = a;
  3644. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3645. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3646. if (a){
  3647. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3648. laUiList *uil = lip->p;
  3649. (*x) += uil->PanX;
  3650. (*y) += uil->PanY;
  3651. }
  3652. }
  3653. }
  3654. void laPanelToLocal(laOperator *a, int *x, int *y){
  3655. int ix = *x, iy = *y;
  3656. laListItemPointer *lip;
  3657. if (a){
  3658. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3659. laUiList *uil = lip->p;
  3660. (*x) += uil->PanX;
  3661. (*y) += uil->PanY;
  3662. }
  3663. }
  3664. }
  3665. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3666. if(!p) return;
  3667. int ix = *x, iy = *y;
  3668. laListItemPointer *lip;
  3669. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3670. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3671. if (a){
  3672. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3673. laUiList *uil = lip->p;
  3674. (*x) -= uil->PanX;
  3675. (*y) -= uil->PanY;
  3676. }
  3677. }
  3678. }
  3679. void laPanelToWindow(laPanel *p, int *x, int *y){
  3680. int ix = *x, iy = *y;
  3681. laListItemPointer *lip;
  3682. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3683. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3684. }
  3685. void laLocalToPanel(laOperator *a, int *x, int *y){
  3686. int ix = *x, iy = *y;
  3687. laListItemPointer *lip;
  3688. if (a){
  3689. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3690. laUiList *uil = lip->p;
  3691. (*x) -= uil->PanX;
  3692. (*y) -= uil->PanY;
  3693. }
  3694. }
  3695. }
  3696. void laSetNextMenuPos(int X, int Y, int W, int H){
  3697. MAIN.NextX = X;
  3698. MAIN.NextY = Y;
  3699. MAIN.NextW = W;
  3700. MAIN.NextH = H;
  3701. }
  3702. int laIsInBlock(laBlock *b, int X, int Y){
  3703. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3704. return 0;
  3705. }
  3706. 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; }
  3707. 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; }
  3708. 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; }
  3709. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3710. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3711. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3712. if (!b->B1 && !b->B2){
  3713. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3714. }
  3715. }
  3716. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3717. laPanel *p;
  3718. laBlock *sb = 0;
  3719. if (!laIsInBlock(b, X, Y)) return 0;
  3720. if (!b->B1 && !b->B2) return b;
  3721. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3722. return laDetectBlockRecursive(b->B2, X, Y);
  3723. }
  3724. laPanel *laDetectPanel(int X, int Y){
  3725. laPanel *p; laBlock *b;
  3726. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3727. int x = X, y = Y;
  3728. laWindowToLocal(0, p, &x, &y);
  3729. if (p->Show && laIsInPanel(p, x, y)){
  3730. return p;
  3731. }
  3732. }
  3733. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3734. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3735. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3736. return 0;
  3737. }
  3738. laUiList *laPrepareUi(laPanel *p){
  3739. return &p->UI;
  3740. }
  3741. laColumn *laFirstColumn(laUiList *uil){
  3742. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3743. else{
  3744. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3745. c->SP = 1;
  3746. c->PreWidth = 1;
  3747. lstAppendItem(&uil->Columns, c);
  3748. c->Top = c;
  3749. return uil->Columns.pFirst;
  3750. }
  3751. }
  3752. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3753. laColumn *lc, *rc;
  3754. if (c->LS || c->RS) return c;
  3755. lc = memAcquireSimple(sizeof(laColumn));
  3756. rc = memAcquireSimple(sizeof(laColumn));
  3757. c->LS = lc;
  3758. c->RS = rc;
  3759. c->LS->SP = Percent;
  3760. c->RS->SP = Percent;
  3761. c->LS->Top = c->Top;
  3762. c->RS->Top = c->Top;
  3763. if (uil){
  3764. lstAppendItem(&uil->Columns, lc);
  3765. lstAppendItem(&uil->Columns, rc);
  3766. }
  3767. if (c->LS && c->RS->MaxW == 0){
  3768. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3769. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3770. }else if (c->RS && c->LS->MaxW == 0){
  3771. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3772. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3773. }
  3774. return c;
  3775. }
  3776. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3777. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3778. return c->LS;
  3779. }
  3780. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3781. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3782. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3783. return c->RS;
  3784. }
  3785. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3786. lstRemoveItem(List, c);
  3787. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3788. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3789. memFree(c);
  3790. }
  3791. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3792. laUiList *uil = TopUil;
  3793. laUiList *sub;
  3794. laUiItem *ui;
  3795. laColumn *cc, *NextCC = 0;
  3796. int Occupied = 0;
  3797. int Removed = 0;
  3798. if (!c->LS) return 0;
  3799. else{
  3800. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3801. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3802. }
  3803. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3804. if (ui->C == c->LS || ui->C == c->RS){
  3805. if (DoMerge){
  3806. ui->C = c;
  3807. Occupied = 1;
  3808. }else
  3809. return 1;
  3810. }
  3811. if (ui->Subs.pFirst){
  3812. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3813. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3814. }
  3815. }
  3816. }
  3817. if (!Removed){
  3818. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3819. if (cc == c){
  3820. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3821. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3822. c->LS = 0;
  3823. c->RS = 0;
  3824. Removed = 1;
  3825. break;
  3826. }
  3827. }
  3828. }
  3829. return Occupied;
  3830. }
  3831. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3832. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3833. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3834. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3835. ut->FakeProp->Base.Identifier = ut->Identifier;
  3836. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3837. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3838. ut->FakeProp->Base.OffsetIsPointer = 1;
  3839. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3840. return ut->ExtraProps;
  3841. }
  3842. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3843. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3844. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3845. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3846. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3847. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3848. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3849. ct->FakeProp->Base.OffsetIsPointer = 1;
  3850. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3851. return ct->ExtraProps;
  3852. }
  3853. void la_DestroyUiType(laUiType* uit){
  3854. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3855. memFree(uit);
  3856. }
  3857. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3858. laUiType *ut = memAcquire(sizeof(laUiType));
  3859. ut->Identifier = Identifer;
  3860. ut->OperatorID = UseOperator;
  3861. ut->Draw = Draw;
  3862. ut->Theme = bt;
  3863. ut->ForType = ForType;
  3864. ut->OperatorType = laGetOperatorType(UseOperator);
  3865. ut->GetHeight = GetHeight;
  3866. ut->Init = Init;
  3867. ut->Destroy = Destroy;
  3868. la_UDFAppendSharedTypePointer(Identifer, ut);
  3869. lstAppendItem(&MAIN.UiTypes, ut);
  3870. return ut;
  3871. }
  3872. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3873. laUiType *ut = MAIN.UiTypes.pFirst;
  3874. if (!P) return 0;
  3875. if (P->DefaultUiType) return P->DefaultUiType;
  3876. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3877. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3878. for (ut; ut; ut = ut->Item.pNext){
  3879. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3880. return ut;
  3881. }
  3882. }
  3883. return 0;
  3884. }
  3885. laUiType *la_GetUiButtonType(){
  3886. laUiType *ut = MAIN.UiTypes.pFirst;
  3887. for (ut; ut; ut = ut->Item.pNext){
  3888. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3889. }
  3890. return 0;
  3891. }
  3892. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3893. laCanvasTemplate *vdt;
  3894. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3895. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3896. }
  3897. return 0;
  3898. }
  3899. void la_AssignPropExtras(laUiItem* ui){
  3900. if(!ui->Type || !ui->Type->FakeProp) return;
  3901. ui->FakePs.p = ui->Type->FakeProp;
  3902. ui->FakePs.Type = U'.';
  3903. ui->FakePs.UseInstance = ui;
  3904. ui->ExtraPP.LastPs = &ui->FakePs;
  3905. }
  3906. void la_AssignCanvasPropExtras(laUiItem* ui){
  3907. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3908. laCanvasTemplate*ct=ui->CanvasTemplate;
  3909. ui->FakePs.p = ct->FakeProp;
  3910. ui->FakePs.Type = U'.';
  3911. ui->FakePs.UseInstance = ui;
  3912. ui->ExtraPP.EndInstance = ui->Extra;
  3913. ui->ExtraPP.LastPs = &ui->FakePs;
  3914. }
  3915. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3916. int result;
  3917. if (!ui) return 0;
  3918. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3919. if (Path){
  3920. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3921. if (!result){
  3922. ui->AT = laGetOperatorType(Path);
  3923. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3924. ui->Type = la_GetUiButtonType();
  3925. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3926. }else{
  3927. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3928. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3929. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3930. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3931. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3932. }
  3933. if (Base){
  3934. ui->PP.RawThis = Base;
  3935. }
  3936. }else if (Base){
  3937. ui->PP.LastPs = Base->LastPs;
  3938. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3939. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3940. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3941. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3942. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3943. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3944. }
  3945. la_AssignPropExtras(ui);
  3946. if(Widget){ ui->Flags|= Widget->Flags; }
  3947. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3948. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3949. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3950. return ui;
  3951. }
  3952. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3953. ui->Type = _LA_UI_LABEL;
  3954. ui->Template = Template;
  3955. ui->State = LA_UI_NORMAL;
  3956. strSafeSet(&ui->Display, Content);
  3957. la_AssignPropExtras(ui);
  3958. return ui;
  3959. }
  3960. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3961. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3962. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3963. ui->State = LA_UI_NORMAL;
  3964. la_AssignPropExtras(ui);
  3965. return ui;
  3966. }
  3967. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3968. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3969. transLate(Content);
  3970. la_UpdateLabelDisplay(ui, Template, Content);
  3971. ui->C = c;
  3972. if (ui->Type->Init) ui->Type->Init(ui);
  3973. ui->ExtraPP.EndInstance = ui->Extra;
  3974. lstAppendItem(&uil->UiItems, ui);
  3975. return ui;
  3976. }
  3977. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3978. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3979. la_UpdateLabelDisplay(ui, Template, Content);
  3980. ui->C = c;
  3981. if (ui->Type->Init) ui->Type->Init(ui);
  3982. ui->ExtraPP.EndInstance = ui->Extra;
  3983. lstAppendItem(&uil->UiItems, ui);
  3984. return ui;
  3985. }
  3986. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3987. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3988. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3989. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3990. ui->C = c;
  3991. if (ui->Type->Init) ui->Type->Init(ui);
  3992. ui->ExtraPP.EndInstance = ui->Extra;
  3993. lstAppendItem(&uil->UiItems, ui);
  3994. return ui;
  3995. }
  3996. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3997. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  3998. }
  3999. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4000. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4001. }
  4002. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4003. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4004. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4005. ui->C = c;
  4006. ui->TemplateContext = TemplateContext;
  4007. if (ui->Type->Init) ui->Type->Init(ui);
  4008. ui->ExtraPP.EndInstance = ui->Extra;
  4009. lstAppendItem(&uil->UiItems, ui);
  4010. return ui;
  4011. }
  4012. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4013. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4014. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4015. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4016. ui->SymbolID=Height;
  4017. lstAppendItem(&uil->UiItems, ui);
  4018. return ui;
  4019. }
  4020. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4021. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4022. }
  4023. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4024. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4025. }
  4026. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4027. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4028. ui->Type = _LA_UI_CANVAS;
  4029. ui->State = LA_UI_NORMAL;
  4030. ui->C = c;
  4031. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4032. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4033. else{
  4034. 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); }
  4035. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4036. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4037. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4038. }
  4039. if (ui->Type->Init) ui->Type->Init(ui);
  4040. la_AssignCanvasPropExtras(ui);
  4041. if (Height) ui->Expand=Height; else ui->Expand=6;
  4042. lstAppendItem(&uil->UiItems, ui);
  4043. return ui;
  4044. }
  4045. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4046. laUiItem* ui=0;
  4047. #define ADD_CANVAS \
  4048. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4049. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4050. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4051. }laEndCondition(uil,b3);\
  4052. laEndRow(uil,b);
  4053. if(Detached){
  4054. laColumn* cl,*cll,*clr,*cr;
  4055. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4056. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4057. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4058. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4059. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4060. ADD_CANVAS
  4061. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4062. }laElse(uil,b2);{
  4063. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4064. ADD_CANVAS
  4065. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4066. }laEndCondition(uil,b2);
  4067. }else{
  4068. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4069. }
  4070. #undef ADD_CANVAS
  4071. }
  4072. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4073. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4074. laCanvasExtra *e;
  4075. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4076. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4077. ui->C = c;
  4078. if (ui->Type->Init) ui->Type->Init(ui);
  4079. ui->ExtraPP.EndInstance = ui->Extra;
  4080. lstAppendItem(&uil->UiItems, ui);
  4081. return ui;
  4082. }
  4083. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4084. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4085. ui->Type = _LA_UI_SYMBOL;
  4086. ui->SymbolID = SymbolID;
  4087. if (Height) ui->State = Height;
  4088. ui->C = c;
  4089. if (ui->Type->Init) ui->Type->Init(ui);
  4090. ui->ExtraPP.EndInstance = ui->Extra;
  4091. lstAppendItem(&uil->UiItems, ui);
  4092. return ui;
  4093. }
  4094. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4095. laPropPack PP={0}; int result;
  4096. if (Path){
  4097. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4098. if (!result){ return 0; }
  4099. if (Base){ PP.RawThis = Base; }
  4100. }else if (Base){
  4101. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4102. }
  4103. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4104. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4105. lstAppendItem(&ui->CompoundPPs,CPP);
  4106. return &CPP->PP;
  4107. }
  4108. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4109. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4110. ui->Type = &_LA_UI_ROW_BEGIN;
  4111. ui->State=Expand;
  4112. ui->Flags=Even;
  4113. ui->C = c;
  4114. if (ui->Type->Init) ui->Type->Init(ui);
  4115. ui->ExtraPP.EndInstance = ui->Extra;
  4116. lstAppendItem(&uil->UiItems, ui);
  4117. return ui;
  4118. }
  4119. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4120. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4121. ui->Type = &_LA_UI_ROW_END;
  4122. ui->C = Begin->C;
  4123. ui->Page = (laUiList*)Begin;
  4124. if (ui->Type->Init) ui->Type->Init(ui);
  4125. ui->ExtraPP.EndInstance = ui->Extra;
  4126. lstAppendItem(&uil->UiItems, ui);
  4127. return ui;
  4128. }
  4129. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4130. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4131. e->Expression = Expression;
  4132. ui->Extra = e;
  4133. la_AssignPropExtras(ui);
  4134. }
  4135. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4136. laUiItem *ui = la_CreateGroupHandle(Widget);
  4137. laUiList *nuil;
  4138. ui->C = c;
  4139. lstAppendItem(&uil->UiItems, ui);
  4140. nuil = memAcquireSimple(sizeof(laUiList));
  4141. strSafeSet(&nuil->TabName, Name);
  4142. ui->Page = nuil;
  4143. lstAppendItem(&ui->Subs, nuil);
  4144. if (ui->Type->Init) ui->Type->Init(ui);
  4145. ui->ExtraPP.EndInstance = ui->Extra;
  4146. return ui;
  4147. }
  4148. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4149. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4150. laUiList *sub = SubUi->Page;
  4151. laColumn *s = laFirstColumn(sub);
  4152. SubUi->State = LA_UI_ACTIVE;
  4153. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4154. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4155. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4156. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4157. laShowSeparator(sub, s);
  4158. return SubUi;
  4159. }
  4160. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4161. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4162. laUiList *sub = SubUi->Page;
  4163. laColumn *s = laFirstColumn(sub);
  4164. SubUi->State = LA_UI_ACTIVE;
  4165. return SubUi;
  4166. }
  4167. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4168. laEndCondition(sub, sub->UiItems.pFirst);
  4169. }
  4170. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4171. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4172. laUiList *nuil;
  4173. ui->C = c;
  4174. lstAppendItem(&uil->UiItems, ui);
  4175. if (ui->Type->Init) ui->Type->Init(ui);
  4176. ui->ExtraPP.EndInstance = ui->Extra;
  4177. return ui;
  4178. }
  4179. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4180. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4181. if (!ui->Page) ui->Page = uil;
  4182. lstAppendItem(&ui->Subs, uil);
  4183. strSafeSet(&uil->TabName, Name);
  4184. laFirstColumn(uil);
  4185. //laFirstColumn(uil);
  4186. return uil;
  4187. }
  4188. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4189. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4190. /*if (!ui->Page) */ ui->Page = uil;
  4191. lstAppendItem(&ui->Subs, uil);
  4192. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4193. return uil;
  4194. }
  4195. laUiConditionNode *laTrue(){
  4196. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4197. ucn->Type = LA_CONDITION_TRUE;
  4198. return ucn;
  4199. }
  4200. laUiConditionNode *laFalse(){
  4201. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4202. ucn->Type = LA_CONDITION_FALSE;
  4203. return ucn;
  4204. }
  4205. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4206. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4207. ucn->Type = LA_CONDITION_PROP;
  4208. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4209. strSafeSet(&ucn->String, Prop);
  4210. return ucn;
  4211. }
  4212. laUiConditionNode *laIntExpression(int Value){
  4213. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4214. ucn->Type = LA_CONDITION_INT;
  4215. ucn->IntValue = Value;
  4216. return ucn;
  4217. }
  4218. laUiConditionNode *laFloatExpression(real Value){
  4219. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4220. ucn->Type = LA_CONDITION_FLOAT;
  4221. ucn->FloatValue = Value;
  4222. return ucn;
  4223. }
  4224. laUiConditionNode *laStringExpression(char *Content){
  4225. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4226. ucn->Type = LA_CONDITION_STRING;
  4227. strSafeSet(&ucn->String, Content);
  4228. return ucn;
  4229. }
  4230. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4231. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4232. ucn->Type = LA_CONDITION_AND;
  4233. ucn->Expression1 = Expression1;
  4234. ucn->Expression2 = Expression2;
  4235. return ucn;
  4236. }
  4237. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4238. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4239. ucn->Type = LA_CONDITION_OR;
  4240. ucn->Expression1 = Expression1;
  4241. ucn->Expression2 = Expression2;
  4242. return ucn;
  4243. }
  4244. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4245. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4246. ucn->Type = LA_CONDITION_NOT;
  4247. ucn->Expression1 = Expression1;
  4248. return ucn;
  4249. }
  4250. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4251. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4252. ucn->Type = LA_CONDITION_EQ;
  4253. ucn->Expression1 = Expression1;
  4254. ucn->Expression2 = Expression2;
  4255. return ucn;
  4256. }
  4257. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4258. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4259. ucn->Type = LA_CONDITION_GT;
  4260. ucn->Expression1 = Expression1;
  4261. ucn->Expression2 = Expression2;
  4262. return ucn;
  4263. }
  4264. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4265. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4266. ucn->Type = LA_CONDITION_LT;
  4267. ucn->Expression1 = Expression1;
  4268. ucn->Expression2 = Expression2;
  4269. return ucn;
  4270. }
  4271. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4272. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4273. ucn->Type = LA_CONDITION_GE;
  4274. ucn->Expression1 = Expression1;
  4275. ucn->Expression2 = Expression2;
  4276. return ucn;
  4277. }
  4278. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4279. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4280. ucn->Type = LA_CONDITION_LE;
  4281. ucn->Expression1 = Expression1;
  4282. ucn->Expression2 = Expression2;
  4283. return ucn;
  4284. }
  4285. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4286. if (Expression->Type != LA_CONDITION_INT) return 0;
  4287. return Expression->IntValue;
  4288. }
  4289. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4290. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4291. return Expression->FloatValue;
  4292. }
  4293. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4294. return Expression->String->Ptr;
  4295. }
  4296. 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){
  4297. switch (Mode1){
  4298. case LA_PROP_ENUM:
  4299. case LA_PROP_INT:
  4300. case LA_CONDITION_INT:
  4301. switch (Mode2){
  4302. case LA_PROP_ENUM:
  4303. case LA_PROP_INT:
  4304. case LA_CONDITION_INT:
  4305. switch (CompMode){
  4306. case LA_CONDITION_GE:
  4307. return (i1 >= i2);
  4308. case LA_CONDITION_GT:
  4309. return (i1 > i2);
  4310. case LA_CONDITION_EQ:
  4311. return (i1 == i2);
  4312. case LA_CONDITION_LT:
  4313. return (i1 < i2);
  4314. case LA_CONDITION_LE:
  4315. return (i1 <= i2);
  4316. }
  4317. case LA_PROP_FLOAT:
  4318. case LA_CONDITION_FLOAT:
  4319. switch (CompMode){
  4320. case LA_CONDITION_GE:
  4321. return ((real)i1 >= f2);
  4322. case LA_CONDITION_GT:
  4323. return ((real)i1 > f2);
  4324. case LA_CONDITION_EQ:
  4325. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4326. case LA_CONDITION_LT:
  4327. return ((real)i1 < f2);
  4328. case LA_CONDITION_LE:
  4329. return ((real)i1 <= f2);
  4330. }
  4331. case LA_PROP_SUB:
  4332. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4333. default:
  4334. return 0;
  4335. }
  4336. case LA_PROP_FLOAT:
  4337. case LA_CONDITION_FLOAT:
  4338. switch (Mode2){
  4339. case LA_PROP_INT:
  4340. case LA_PROP_ENUM:
  4341. case LA_CONDITION_INT:
  4342. switch (CompMode){
  4343. case LA_CONDITION_GE:
  4344. return (f1 >= (real)i2);
  4345. case LA_CONDITION_GT:
  4346. return (f1 > (real)i2);
  4347. case LA_CONDITION_EQ:
  4348. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4349. case LA_CONDITION_LT:
  4350. return (f1 < (real)i2);
  4351. case LA_CONDITION_LE:
  4352. return (f1 <= (real)i2);
  4353. }
  4354. case LA_PROP_FLOAT:
  4355. case LA_CONDITION_FLOAT:
  4356. switch (CompMode){
  4357. case LA_CONDITION_GE:
  4358. return (f1 >= f2);
  4359. case LA_CONDITION_GT:
  4360. return (f1 > f2);
  4361. case LA_CONDITION_EQ:
  4362. return (f1 == f2);
  4363. case LA_CONDITION_LT:
  4364. return (f1 < f2);
  4365. case LA_CONDITION_LE:
  4366. return (f1 <= f2);
  4367. }
  4368. default:
  4369. return 0;
  4370. }
  4371. case LA_PROP_STRING:
  4372. case LA_CONDITION_STRING:
  4373. switch (Mode2){
  4374. case LA_PROP_STRING:
  4375. case LA_CONDITION_STRING:
  4376. return strSame(s1, s2);
  4377. default:
  4378. return 0;
  4379. }
  4380. case LA_PROP_SUB:
  4381. switch (Mode2){
  4382. case LA_PROP_SUB:
  4383. return p1 == p2;
  4384. case LA_CONDITION_INT:
  4385. case LA_PROP_INT:
  4386. case LA_PROP_ENUM:
  4387. return (int)p1 == i2;
  4388. default:
  4389. return 0;
  4390. }
  4391. default:
  4392. switch (CompMode){
  4393. case LA_CONDITION_GE:
  4394. return (i1 >= i2);
  4395. case LA_CONDITION_GT:
  4396. return (i1 > i2);
  4397. case LA_CONDITION_EQ:
  4398. return (i1 == i2);
  4399. case LA_CONDITION_LT:
  4400. return (i1 < i2);
  4401. case LA_CONDITION_LE:
  4402. return (i1 <= i2);
  4403. }
  4404. }
  4405. }
  4406. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4407. void *Instance = 0;
  4408. int IValue1 = 0, IValue2 = 0;
  4409. real FValue1 = 0, FValue2 = 0;
  4410. void *Ptr1 = 0, *Ptr2 = 0;
  4411. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4412. int Result1, Result2;
  4413. laEnumItem *ei; laSubProp*sp;
  4414. if (!Expression) return 0;
  4415. Str1[0] = 0;
  4416. Str2[0] = 0;
  4417. laPropIterator pi = {0};
  4418. switch (Expression->Type){
  4419. case LA_CONDITION_PROP:
  4420. if (!Expression->PP.LastPs){
  4421. (*IResult) = 0;
  4422. return 0;
  4423. }
  4424. switch (Expression->PP.LastPs->p->PropertyType){
  4425. case LA_PROP_INT:
  4426. *IResult = laGetInt(&Expression->PP);
  4427. if (*IResult) return LA_CONDITION_INT;
  4428. else return 0;
  4429. case LA_PROP_FLOAT:
  4430. *FResult = laGetFloat(&Expression->PP);
  4431. if (*FResult) return 1;
  4432. else return 0;
  4433. break;
  4434. case LA_PROP_STRING:
  4435. laGetString(&Expression->PP, _StrResult, &StrResult);
  4436. if (StrResult[0]) return 1;
  4437. else return 0;
  4438. break;
  4439. case LA_PROP_ENUM:
  4440. ei = laGetEnum(&Expression->PP);
  4441. if (!ei) return 0;
  4442. /*if(ei) */ *IResult = ei->Index;
  4443. if (*IResult) return LA_CONDITION_INT;
  4444. else return 0;
  4445. break;
  4446. case LA_PROP_SUB:
  4447. sp=Expression->PP.LastPs->p;
  4448. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4449. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4450. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4451. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4452. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4453. }
  4454. }
  4455. *PtrResult = Instance;
  4456. if (Instance) return 1;
  4457. break;
  4458. default:
  4459. return 0;
  4460. }
  4461. break;
  4462. case LA_CONDITION_INT:
  4463. *IResult = Expression->IntValue;
  4464. if (*IResult) return 1;
  4465. else
  4466. return 0;
  4467. case LA_CONDITION_FLOAT:
  4468. *FResult = Expression->FloatValue;
  4469. if (*FResult) return 1;
  4470. else
  4471. return 0;
  4472. case LA_CONDITION_STRING:
  4473. if (Expression->String){
  4474. strCopyFull(StrResult, Expression->String->Ptr);
  4475. return 1;
  4476. }else
  4477. return 0;
  4478. case LA_CONDITION_TRUE:
  4479. if (*IResult) *IResult = 1;
  4480. return 1;
  4481. case LA_CONDITION_FALSE:
  4482. if (*IResult) *IResult = 0;
  4483. return 0;
  4484. default:
  4485. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4486. switch (Expression->Type){
  4487. case LA_CONDITION_AND:
  4488. if (Result1){
  4489. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4490. if (Result2) *IResult = 1;
  4491. return (Result2);
  4492. }else
  4493. return 0;
  4494. case LA_CONDITION_OR:
  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 1;
  4501. case LA_CONDITION_NOT:
  4502. return !Result1;
  4503. default:
  4504. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4505. return la_DoCompare(Expression->Type,
  4506. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4507. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4508. }
  4509. break;
  4510. }
  4511. return 0;
  4512. }
  4513. int la_DoSingleExpression(laUiConditionNode *Expression){
  4514. int a;
  4515. real b;
  4516. char c[128]={0};
  4517. void *p;
  4518. if (!Expression) return 1;
  4519. c[0] = 0;
  4520. return la_DoExpression(Expression, &a, &b, c, &p);
  4521. }
  4522. void la_StepExpression(laUiConditionNode *e){
  4523. if (!e) return;
  4524. switch (e->Type){
  4525. case LA_CONDITION_AND:
  4526. case LA_CONDITION_OR:
  4527. case LA_CONDITION_GE:
  4528. case LA_CONDITION_GT:
  4529. case LA_CONDITION_EQ:
  4530. case LA_CONDITION_LT:
  4531. case LA_CONDITION_LE:
  4532. la_StepExpression(e->Expression1);
  4533. la_StepExpression(e->Expression2);
  4534. break;
  4535. case LA_CONDITION_NOT:
  4536. la_StepExpression(e->Expression1);
  4537. break;
  4538. case LA_CONDITION_PROP:
  4539. la_StepPropPack(&e->PP);
  4540. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4541. la_UsePropPack(&e->PP, 1);
  4542. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4543. //}
  4544. break;
  4545. default:
  4546. break;
  4547. }
  4548. }
  4549. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4550. if (!ucn) return;
  4551. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4552. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4553. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4554. if (ucn->String) strSafeDestroy(&ucn->String);
  4555. if (ucn) memFree(ucn);
  4556. }
  4557. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4558. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4559. ui->C = c;
  4560. ui->Type = &_LA_UI_CONDITION;
  4561. la_ConditionerInit(ui, Expression);
  4562. lstAppendItem(&uil->UiItems, ui);
  4563. return ui;
  4564. }
  4565. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4566. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4567. laConditionUiExtraData *cued;
  4568. ui->Type = &_LA_UI_CONDITION_ELSE;
  4569. la_ConditionerInit(ui, 0);
  4570. cued = ui->Extra;
  4571. cued->EndUi = Beginner;
  4572. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4573. ui->C = Beginner->C;
  4574. lstAppendItem(&uil->UiItems, ui);
  4575. return ui;
  4576. }
  4577. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4578. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4579. laConditionUiExtraData *cued;
  4580. ui->Template = define;
  4581. ui->C = col;
  4582. ui->PP.RawThis = ExtraBase;
  4583. ui->Page = ExtraThis;
  4584. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4585. la_ConditionerInit(ui, 0);
  4586. cued = ui->Extra;
  4587. //cued->Remove = Remove;
  4588. ui->State = LA_UI_NORMAL;
  4589. lstAppendItem(&uil->UiItems, ui);
  4590. return ui;
  4591. }
  4592. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4593. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4594. laConditionUiExtraData *cued;
  4595. ui->Type = &_LA_UI_CONDITION_END;
  4596. la_ConditionerInit(ui, 0);
  4597. cued = ui->Extra;
  4598. cued->EndUi = Beginner;
  4599. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4600. ui->C = Beginner->C;
  4601. lstAppendItem(&uil->UiItems, ui);
  4602. return ui;
  4603. }
  4604. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4605. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4606. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4607. ui->Type = _LA_UI_MENU_ROOT;
  4608. strSafeSet(&ui->Display, Title);
  4609. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4610. ui->C = c;
  4611. lstAppendItem(&uil->UiItems, ui);
  4612. lstAppendItem(&ui->Subs, muil);
  4613. return muil;
  4614. }
  4615. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4616. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4617. ui->Type = _LA_UI_ALIGN;
  4618. ui->C = widest;
  4619. lstAppendItem(&uil->UiItems, ui);
  4620. return ui;
  4621. }
  4622. void laFixHeight(laUiList *uil, short Rows){
  4623. if (!uil) return;
  4624. uil->HeightCoeff = Rows;
  4625. }
  4626. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4627. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4628. if (!ExtraColumns) return;
  4629. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4630. }
  4631. laUiTemplate *laFindUiTemplate(char *Identifier){
  4632. laUiTemplate *uit;
  4633. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4634. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4635. }
  4636. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4637. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4638. }
  4639. return 0;
  4640. }
  4641. void la_DestroyUiTemplate(laUiTemplate* uit){
  4642. strSafeDestroy(&uit->Identifier);
  4643. strSafeDestroy(&uit->Title);
  4644. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4645. memFree(uit);
  4646. }
  4647. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4648. strSafeDestroy(&uit->Identifier);
  4649. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4650. memFree(uit);
  4651. }
  4652. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4653. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4654. strSafeSet(&uit->Identifier, Identifier);
  4655. strSafeSet(&uit->Title, Title);
  4656. strSafeSet(&uit->CategoryName, NewCategory);
  4657. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4658. uit->DefaultGLFormat=DefaultGLFormat;
  4659. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4660. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4661. la_UDFAppendSharedTypePointer(Identifier, uit);
  4662. return uit;
  4663. }
  4664. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4665. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4666. strSafeSet(&t->Identifier, Identifier);
  4667. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4668. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4669. lstAppendItem(&MAIN.View2DTemplates, t);
  4670. la_UDFAppendSharedTypePointer(Identifier, t);
  4671. return t;
  4672. }
  4673. void laFinalizeUiTemplates(){
  4674. laUiTemplate *uit;
  4675. laCanvasTemplate *u2d;
  4676. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4677. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4678. }
  4679. }
  4680. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4681. laPanel *p;
  4682. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4683. if (p->PanelTemplate==uit){
  4684. return p;
  4685. }
  4686. }
  4687. return 0;
  4688. }
  4689. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4690. laUiList *uil, *NextUil;
  4691. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4692. NextUil = uil->Item.pNext;
  4693. lstRemoveItem(&ui->Subs, uil);
  4694. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4695. }
  4696. la_StopUiOperatorService(ui);
  4697. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4698. strSafeDestroy(&ui->Display);
  4699. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4700. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4701. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4702. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4703. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4704. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4705. }
  4706. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4707. memFree(ui);
  4708. }
  4709. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4710. laUiItem *ui, *NextUi;
  4711. laColumn *col, *NextCol;
  4712. if (!uil) return;
  4713. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4714. NextUi = ui->Item.pNext;
  4715. if(OnlyRemoveUser && RemoveUsers){
  4716. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4717. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4718. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4719. continue;
  4720. }
  4721. lstRemoveItem(&uil->UiItems, ui);
  4722. la_DestroyUiItem(ui, RemoveUsers);
  4723. }
  4724. if(OnlyRemoveUser){ return; }
  4725. for (col = uil->Columns.pFirst; col; col = NextCol){
  4726. NextCol = col->Item.pNext;
  4727. lstRemoveItem(&uil->Columns, col);
  4728. memFree(col);
  4729. }
  4730. strSafeDestroy(&uil->TabName);
  4731. if (!NoFree) memFree(uil);
  4732. }
  4733. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4734. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4735. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4736. }
  4737. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4738. laUiItem *Next = after->Item.pNext;
  4739. laUiItem *Last = uil->UiItems.pLast;
  4740. after->Item.pNext = 0;
  4741. uil->UiItems.pLast = after;
  4742. Define(uil, Base, This, ExtraColums, 0);
  4743. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4744. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4745. if (Next != Last) uil->UiItems.pLast = Last;
  4746. }
  4747. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4748. // int i = 0;
  4749. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4750. // if (!ui->ExtraColums) return;
  4751. // for (i; ui->ExtraColums[i]; i++) {
  4752. // laColumn* c = ui->ExtraColums[i];
  4753. // c->B = B;
  4754. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4755. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4756. // }
  4757. //}
  4758. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4759. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4760. }
  4761. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4762. laColumn *c = ui->C;
  4763. laColumn *ic = lst->pFirst;
  4764. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4765. for (ic; ic; ic = ic->Item.pNext){
  4766. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4767. ic->B = ic->B < c->B ? c->B : ic->B;
  4768. }
  4769. }
  4770. ic = ui->C;
  4771. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4772. ;
  4773. for (ic; ic; ic = ic->Item.pNext){
  4774. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4775. ic->B = ic->B < c->B ? c->B : ic->B;
  4776. }
  4777. }
  4778. }
  4779. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4780. laColumn *c = ui->C;
  4781. laColumn *ic = lst->pFirst;
  4782. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4783. for (ic; ic; ic = ic->Item.pNext){
  4784. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4785. ic->B = ic->B < c->B ? c->B : ic->B;
  4786. }
  4787. }
  4788. ic = ui->C;
  4789. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4790. ;
  4791. for (ic; ic; ic = ic->Item.pNext){
  4792. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4793. ic->B = ic->B < c->B ? c->B : ic->B;
  4794. }
  4795. }
  4796. }
  4797. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4798. int rep;
  4799. int sp;
  4800. int rev;
  4801. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4802. if (!c) return 0;
  4803. sp = (c->SP * (R - L)) + L;
  4804. rev = sp;
  4805. /*if (U)*/ c->B = U;
  4806. if (LR == 1){
  4807. c->IL = L;
  4808. c->IR = sp;
  4809. if (repos){
  4810. c->IR = repos;
  4811. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4812. c->IR = c->IL + c->MaxW*LA_RH+M;
  4813. rev = c->IR;
  4814. }
  4815. }else if (LR == 2){
  4816. c->IL = sp;
  4817. c->IR = R;
  4818. if (repos){
  4819. c->IL = repos;
  4820. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4821. c->IL = c->IR - c->MaxW*LA_RH-M;
  4822. rev = c->IL;
  4823. }
  4824. }else if (LR == 0){
  4825. c->IL = L;
  4826. c->IR = R;
  4827. }
  4828. if (c->LS && c->RS->MaxW == 0){
  4829. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4830. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4831. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4832. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4833. }else if (c->RS && c->LS->MaxW == 0){
  4834. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4835. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4836. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4837. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4838. }
  4839. return rev;
  4840. }
  4841. STRUCTURE(laRowInfo){
  4842. int MaxW;
  4843. int MinW;
  4844. int UnitMinW;
  4845. int NonExpandW;
  4846. int TotalPadding;
  4847. int Expand, Even;
  4848. int ExpandAccum;
  4849. int CountElements;
  4850. int U,MaxB,L;
  4851. laListHandle Elements;
  4852. int LastNoHeight;
  4853. };
  4854. STRUCTURE(laRowNode){
  4855. laListItem Item;
  4856. laUiItem* ui;
  4857. int GotW, LP, RP, H;
  4858. int Expand;
  4859. int UseLast;
  4860. int WaitAnimation;
  4861. };
  4862. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4863. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4864. ri->UnitMinW=LA_RH;
  4865. ri->Expand=ui->State?1:0;
  4866. ri->Even=ui->Flags?1:0;
  4867. ri->U=ui->TU; ri->L=ui->TL;
  4868. ri->MaxB=ui->TU;
  4869. }
  4870. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  4871. laRowNode* rn=CreateNew(laRowNode);
  4872. rn->LP=bt->LP;rn->RP=bt->RP;
  4873. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4874. rn->ui=ui;
  4875. rn->H=H;
  4876. rn->Expand=ui->Expand;
  4877. rn->WaitAnimation=WaitAnimation;
  4878. lstAppendItem(&ri->Elements, rn);
  4879. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4880. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4881. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4882. ri->TotalPadding += (bt->LP+bt->RP);
  4883. ri->MinW+=ri->UnitMinW;
  4884. ri->NonExpandW+=rn->GotW;
  4885. ri->ExpandAccum+=ui->Expand;
  4886. ri->CountElements++;
  4887. if(ui->Expand){ri->Expand=1;}
  4888. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4889. }
  4890. int la_ShrinkableRowElements(laRowInfo* ri){
  4891. int count=0;
  4892. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4893. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4894. count++;
  4895. }
  4896. return count;
  4897. }
  4898. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4899. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  4900. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4901. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4902. if(Available<0){
  4903. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4904. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4905. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4906. }else{
  4907. if(!ri->Expand && Available>0){Available=0;}
  4908. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4909. }
  4910. if(!ShareCount) return 0;
  4911. int PerNode = Available/ShareCount;
  4912. int Remaining = Available-PerNode*ShareCount;
  4913. int L = ri->L; int i=0; laRowNode* rn;
  4914. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4915. laUiItem* ui=rn->ui;
  4916. int NodeAdd, Node=rn->GotW;
  4917. if(rn->UseLast){
  4918. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4919. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4920. continue;
  4921. }
  4922. if(Available>=0){
  4923. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4924. NodeAdd+=(i<Remaining?1:0);i++;
  4925. }else{
  4926. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4927. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4928. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4929. }else{ Node=ri->UnitMinW;
  4930. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4931. }
  4932. }
  4933. ui->TL = L + rn->LP;
  4934. ui->TR = ui->TL + Node+NodeAdd;
  4935. ui->TB = ui->TU + rn->H;
  4936. L=ui->TR+rn->RP;
  4937. if (!rn->WaitAnimation){
  4938. ui->L = ui->TL; ui->R = ui->TR;
  4939. ui->U = ui->TU; ui->B = ui->TB;
  4940. }
  4941. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4942. }
  4943. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  4944. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  4945. memset(ri, 0, sizeof(laRowInfo));
  4946. }
  4947. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4948. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4949. int sl,sr,su,sb;
  4950. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4951. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4952. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4953. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4954. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4955. if(pc==LA_PC_SOCKET_OUT){
  4956. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4957. }else{
  4958. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4959. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4960. }
  4961. }
  4962. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4963. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4964. }
  4965. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4966. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4967. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4968. laBoxedTheme *bt;
  4969. int Lowest = 0;
  4970. int HyperValue = 0;
  4971. int WaitAnimation;
  4972. int RowMode=0; laRowInfo ri={0};
  4973. laBoxedTheme* pt=*(ParentPanel->BT);
  4974. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4975. int MaxR=0;
  4976. if(!uil->Scale){uil->Scale=1;}
  4977. uil->SaveScale=MAIN.UiScale;
  4978. MAIN.UiScale*=uil->Scale;
  4979. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4980. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4981. WaitAnimation = 0;
  4982. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4983. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4984. for (ui = uil->UiItems.pFirst; ui;){
  4985. int SubB = 0;
  4986. int H;
  4987. WaitAnimation = 0;
  4988. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4989. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4990. //if (Fast && ui->C->B > B) {
  4991. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4992. // ui = ui->Item.pNext;
  4993. // continue;
  4994. //}
  4995. if (!ui->Instructions){
  4996. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4997. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4998. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4999. laOperatorProp *ap = ui->PP.LastPs->p;
  5000. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5001. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5002. }
  5003. }
  5004. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5005. la_UsePropPack(&ui->PP, 0);
  5006. if (ui->CompoundPPs.pFirst){
  5007. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5008. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5009. }
  5010. }
  5011. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5012. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5013. // 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);
  5014. //}
  5015. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5016. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5017. WaitAnimation = 1;
  5018. }
  5019. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5020. bt = (*ui->Type->Theme);
  5021. if (ui->Type == &_LA_UI_CONDITION){
  5022. laConditionUiExtraData *cued = ui->Extra;
  5023. la_StepExpression(cued->Expression);
  5024. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5025. if (!cued->IsTrue){
  5026. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5027. }else{
  5028. ui = ui->Item.pNext;
  5029. }
  5030. continue;
  5031. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5032. ui = ui->Item.pNext;
  5033. continue;
  5034. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5035. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5036. if (cued->IsTrue) ui = cued->EndUi;
  5037. else
  5038. ui = ui->Item.pNext;
  5039. continue;
  5040. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5041. laConditionUiExtraData *cued = ui->Extra;
  5042. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5043. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5044. if (!WaitAnimation){
  5045. ui->L = ui->TL; ui->R = ui->TR;
  5046. ui->U = ui->TU; ui->B = ui->TB;
  5047. }
  5048. if(!RowMode){
  5049. la_CalcUiItemInfluence(&uil->Columns, ui);
  5050. }else{
  5051. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5052. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5053. }
  5054. if (ui->State == LA_UI_NORMAL){
  5055. cued->IsTrue = 0;
  5056. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5057. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5058. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5059. }else{
  5060. cued->IsTrue = 1;
  5061. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5062. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5063. //}
  5064. ui = ui->Item.pNext;
  5065. }
  5066. continue;
  5067. }
  5068. if (ui->Type == _LA_UI_ALIGN){
  5069. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5070. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5071. if (ui->TB > Lowest) Lowest = ui->TB;
  5072. if (!WaitAnimation){
  5073. ui->L = ui->TL; ui->R = ui->TR;
  5074. ui->U = ui->TU; ui->B = ui->TB;
  5075. }
  5076. if(!RowMode){
  5077. la_CalcUiItemInfluence(&uil->Columns, ui);
  5078. }else{
  5079. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5080. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5081. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5082. }
  5083. ui = ui->Item.pNext; continue;
  5084. }
  5085. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5086. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5087. la_InitRowNode(&ri, ui, bt);
  5088. RowMode=1; ui=ui->Item.pNext; continue;
  5089. }
  5090. if (ui->Type == &_LA_UI_ROW_END){
  5091. la_CalculateRowExpand(&ri, ui);
  5092. la_CalcUiItemInfluence(&uil->Columns, ui);
  5093. RowMode=0; ui=ui->Item.pNext; continue;
  5094. }
  5095. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5096. int GB=0;
  5097. 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; }
  5098. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5099. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5100. if (H < 0){
  5101. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5102. else{ H=LA_RH; }
  5103. }
  5104. else H *= LA_RH;
  5105. ui->TB = ui->TU;
  5106. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5107. 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
  5108. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5109. if (ui->Type == _LA_UI_COLLECTION){
  5110. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5111. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5112. ui->PP.EndInstance = TInstance;
  5113. laUiList *iuil = ui->Subs.pFirst;
  5114. laUiList *puil = iuil;
  5115. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5116. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5117. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5118. int Begin = ui->TB;
  5119. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5120. int ElementB = ui->TU;
  5121. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5122. int MaxB = ElementB;
  5123. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5124. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5125. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5126. if (!ElementLimit) RowPriority = 0;
  5127. if (!TInstance){
  5128. while (iuil){
  5129. puil = iuil->Item.pNext;
  5130. la_DestroyTabPage(ui, iuil, 0);
  5131. iuil = puil;
  5132. }
  5133. }
  5134. while (TInstance){
  5135. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  5136. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5137. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5138. ui->PP.EndInstance = TInstance; continue;
  5139. }
  5140. if(CanGetTheme){
  5141. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5142. la_SwitchThemeQuick(t, OriginalTheme);
  5143. }
  5144. if(CanGetGap){
  5145. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5146. Gap=g*LA_RH;
  5147. }else Gap=0;
  5148. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5149. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5150. }else GotCategory=0;
  5151. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5152. if (RowPriority){
  5153. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5154. }
  5155. }
  5156. FirstIn=0;
  5157. if (ElementLimit){
  5158. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5159. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5160. }
  5161. while (iuil && iuil->Instance != TInstance){
  5162. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5163. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5164. }else{
  5165. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5166. }
  5167. iuil = puil;
  5168. }
  5169. if(!iuil){
  5170. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5171. }
  5172. if (!iuil){
  5173. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5174. la_CalcUiTopInfluence(&uil->Columns, ui);
  5175. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5176. 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);
  5177. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5178. iuil = ui->Page->Item.pNext;
  5179. }else{
  5180. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5181. 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);
  5182. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5183. la_CalcUiItemInfluence(&uil->Columns, ui);
  5184. iuil = iuil->Item.pNext;
  5185. }
  5186. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5187. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5188. ui->PP.EndInstance = TInstance;
  5189. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5190. if (RowPriority){
  5191. Col += 1;
  5192. if (Col >= ElementLimit){
  5193. Col = 0;
  5194. Row += 1;
  5195. Begin = ElementB + bt->TM;
  5196. }
  5197. }elif(Spread){
  5198. EL+=Spread*LA_RH;
  5199. ER+=Spread*LA_RH;
  5200. }else{
  5201. Row += 1;
  5202. Begin = ElementB + bt->TM;
  5203. if (ElementLimit && Row >= ElementLimit){
  5204. Row = 0;
  5205. Col += 1;
  5206. Begin = ui->TU + bt->TM;
  5207. }
  5208. }
  5209. ui->TB = ElementB;
  5210. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5211. }
  5212. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5213. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5214. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5215. ui->TB = MaxB;
  5216. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5217. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5218. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5219. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5220. ui->TB=ui->TU+LA_RH;
  5221. }else{
  5222. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5223. ui->PP.EndInstance = TInstance;
  5224. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5225. if(!Template) Template=laui_SubPropInfoDefault;
  5226. //ui->Template = Template;
  5227. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5228. if (!ui->Subs.pFirst && TInstance){
  5229. la_AddInstancePage(ui, TInstance, 0);
  5230. la_CalcUiTopInfluence(&uil->Columns, ui);
  5231. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5232. 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);
  5233. ui->TB = SubB + (NoDecal?0:bt->BM);
  5234. }else if (ui->Subs.pFirst){
  5235. if (!TInstance || TInstance != ui->Page->Instance){
  5236. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5237. ui->Page = 0;
  5238. if (TInstance){
  5239. la_AddInstancePage(ui, TInstance, 0);
  5240. la_CalcUiTopInfluence(&uil->Columns, ui);
  5241. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5242. 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);
  5243. ui->TB = SubB + (NoDecal?0:bt->TM);
  5244. }else
  5245. ui->TB = ui->TU + LA_RH + bt->BM;
  5246. }else{
  5247. 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);
  5248. ui->TB = SubB + (NoDecal?0:bt->BM);
  5249. }
  5250. }
  5251. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5252. ui->TB=ui->TU+LA_RH;
  5253. }
  5254. }
  5255. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5256. if (!WaitAnimation){
  5257. ui->L = ui->TL;
  5258. ui->R = ui->TR;
  5259. ui->U = ui->TU;
  5260. ui->B = ui->TB;
  5261. }
  5262. }
  5263. }else{
  5264. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5265. if (ui->Type != _LA_UI_CANVAS){
  5266. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5267. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5268. SubB = la_UpdateUiListRecursive(ui->Page,
  5269. 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);
  5270. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5271. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5272. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5273. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5274. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5275. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5276. }
  5277. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5278. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5279. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5280. if(ui->Page->HeightCoeff){
  5281. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5282. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5283. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5284. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5285. }
  5286. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5287. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5288. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5289. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5290. }
  5291. }
  5292. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5293. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5294. }else{
  5295. laUiList *suil;
  5296. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5297. la_CalcUiTopInfluence(&uil->Columns, ui);
  5298. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5299. 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);
  5300. }
  5301. }
  5302. ui->TB = ui->TU + H;
  5303. }
  5304. }else ui->TB = ui->TU + H;
  5305. }
  5306. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5307. if(!RowMode){
  5308. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5309. }else{
  5310. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5311. }
  5312. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5313. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5314. ui = ui->Item.pNext;
  5315. }
  5316. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5317. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5318. else uil->TB = Lowest;
  5319. if (!WaitAnimation){
  5320. uil->L = uil->TL;
  5321. uil->R = uil->TR;
  5322. uil->U = uil->TU;
  5323. uil->B = uil->TB;
  5324. }
  5325. MAIN.UiScale=uil->SaveScale;
  5326. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5327. return uil->TB;
  5328. }
  5329. int la_AnimateSingleUiSize(int To, int *Now){
  5330. int Delta;
  5331. if (To != *Now){
  5332. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5333. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5334. *Now += Delta;
  5335. return 1;
  5336. }else
  5337. return 0;
  5338. }
  5339. int la_AnimateUiListRecursive(laUiList *uil){
  5340. laUiItem *ui;
  5341. int Again = 0;
  5342. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5343. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5344. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5345. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5346. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5347. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5348. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5349. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5350. laUiList *suil;
  5351. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5352. Again += la_AnimateUiListRecursive(suil);
  5353. }
  5354. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5355. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5356. Again += la_AnimateUiListRecursive(ui->Page);
  5357. }
  5358. }
  5359. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5360. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5361. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5362. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5363. return Again;
  5364. }
  5365. int la_DrawUiItem(laUiItem *ui){
  5366. tnsUseNoTexture();
  5367. tnsColor4d(1, 1, 1, 1);
  5368. tnsVertex2d(ui->L, ui->U);
  5369. tnsVertex2d(ui->R, ui->U);
  5370. tnsVertex2d(ui->R, ui->B);
  5371. tnsVertex2d(ui->L, ui->B);
  5372. tnsPackAs(GL_LINE_LOOP);
  5373. }
  5374. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5375. tnsUseNoTexture();
  5376. tnsColor4d(1, 1, 1, 1);
  5377. tnsVertex2d(ui->L - 1, ui->U - 1);
  5378. tnsVertex2d(ui->R + 1, ui->U - 1);
  5379. tnsVertex2d(ui->R + 1, ui->B + 1);
  5380. tnsVertex2d(ui->L - 1, ui->B + 1);
  5381. tnsPackAs(GL_LINE_LOOP);
  5382. }
  5383. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5384. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5385. return 1;
  5386. }
  5387. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5388. laUiListDrawItem *uildi = uild->Items.pFirst;
  5389. laUiList *Target = uildi->Target;
  5390. int L, R, U, B;
  5391. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5392. L = Target->L + Target->PanX + uildi->DifX;
  5393. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5394. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5395. U = Target->U + Target->PanY + uildi->DifY;
  5396. return la_UiInBound(ui, L, R, U, B);
  5397. }
  5398. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5399. laUiListDrawItem *uildi = uild->Items.pFirst;
  5400. laUiList *Target = uildi->Target;
  5401. int L, R, U, B;
  5402. if (Target){
  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. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5408. return 1;
  5409. }else{
  5410. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5411. return 1;
  5412. }
  5413. }
  5414. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5415. laUiItem *ui = uil->UiItems.pFirst;
  5416. while (!strGetArgument(ui->Instructions, mark))
  5417. ui = ui->Item.pNext;
  5418. return ui;
  5419. }
  5420. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5421. laUiList *uil;
  5422. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5423. if (uil->Instance == Instance) return uil;
  5424. }
  5425. return uil;
  5426. }
  5427. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5428. int mx=(L+R)/2; int my=(U+B)/2;
  5429. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5430. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5431. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5432. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5433. tnsFlush();
  5434. }
  5435. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5436. if(!uil->ScrollerShownV) return;
  5437. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5438. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5439. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5440. int U = uil->U + Offset;
  5441. int B = U + Len;
  5442. int L = UiR - RM*2 - W;
  5443. int R = L + W;
  5444. if (B > U + DisplayH) B = U + DisplayH;
  5445. if (U < uil->U) U = uil->U;
  5446. if (B <= uil->U || U >= uil->B) return;
  5447. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5448. if (U < uil->U) U = uil->U;
  5449. tnsUseNoTexture();
  5450. laBoxedTheme* bt=_LA_THEME_PANEL;
  5451. real* color=laThemeColor(bt, LA_BT_TEXT);
  5452. tnsColor4d(LA_COLOR3(color), 0.2);
  5453. tnsVertex2d(R-RM, uil->U);
  5454. tnsVertex2d(L+RM, uil->U);
  5455. tnsVertex2d(L+RM, uil->U + DisplayH);
  5456. tnsVertex2d(R-RM, uil->U + DisplayH);
  5457. tnsPackAs(GL_TRIANGLE_FAN);
  5458. tnsColor4d(LA_COLOR3(color), 0.5);
  5459. tnsVertex2d(R-RM, uil->U);
  5460. tnsVertex2d(L+RM, uil->U);
  5461. tnsVertex2d(L+RM, uil->U + DisplayH);
  5462. tnsVertex2d(R-RM, uil->U + DisplayH);
  5463. tnsPackAs(GL_LINE_LOOP);
  5464. tnsColor4d(LA_COLOR3(color), 1);
  5465. tnsVertex2d(R, U);
  5466. tnsVertex2d(L, U);
  5467. tnsVertex2d(L, B);
  5468. tnsVertex2d(R, B);
  5469. tnsPackAs(GL_TRIANGLE_FAN);
  5470. int HU=(U+B)/2+LA_RH2;
  5471. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5472. tnsFlush();
  5473. }
  5474. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5475. if(!uil->ScrollerShownH) return;
  5476. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5477. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5478. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5479. int L = uil->L + Offset;
  5480. int R = L + Len;
  5481. int U = UiB - RM - W;
  5482. int B = U + W;
  5483. if (B > U + DisplayW) B = U + DisplayW;
  5484. if (U < uil->U) U = uil->U;
  5485. if (R <= uil->L || L >= uil->R) return;
  5486. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5487. if (L < uil->L) L = uil->L;
  5488. tnsUseNoTexture();
  5489. laBoxedTheme* bt=_LA_THEME_PANEL;
  5490. real* color=laThemeColor(bt, LA_BT_TEXT);
  5491. tnsColor4d(LA_COLOR3(color), 0.2);
  5492. tnsVertex2d(uil->L,U+RM);
  5493. tnsVertex2d(uil->L,B-RM);
  5494. tnsVertex2d(uil->L + DisplayW,B-RM);
  5495. tnsVertex2d(uil->L + DisplayW,U+RM);
  5496. tnsPackAs(GL_TRIANGLE_FAN);
  5497. tnsColor4d(LA_COLOR3(color), 0.5);
  5498. tnsVertex2d(uil->L,U+RM);
  5499. tnsVertex2d(uil->L,B-RM);
  5500. tnsVertex2d(uil->L + DisplayW,B-RM);
  5501. tnsVertex2d(uil->L + DisplayW,U+RM);
  5502. tnsPackAs(GL_LINE_LOOP);
  5503. tnsColor4d(LA_COLOR3(color), 1);
  5504. tnsVertex2d(R, U);
  5505. tnsVertex2d(L, U);
  5506. tnsVertex2d(L, B);
  5507. tnsVertex2d(R, B);
  5508. tnsPackAs(GL_TRIANGLE_FAN);
  5509. int HU=(U+B)/2+LA_RH2;
  5510. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5511. tnsFlush();
  5512. }
  5513. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5514. tnsUseNoTexture();
  5515. tnsColor4dv(color);
  5516. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5517. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5518. tnsPackAs(GL_TRIANGLE_FAN);
  5519. }
  5520. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5521. laSocketRecord* sr;
  5522. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5523. uild->WiresContainer=container;
  5524. }
  5525. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5526. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5527. if(lip->Target==uild->WiresContainer) break;
  5528. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5529. }
  5530. }
  5531. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5532. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5533. int PanX, PanY;
  5534. if(pc==LA_PC_SOCKET_OUT){
  5535. laNodeOutSocket* s=ui->PP.EndInstance;
  5536. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5537. }else{
  5538. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5539. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5540. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5541. }
  5542. }
  5543. void la_RegenerateWireColors(){
  5544. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5545. laTheme* t=MAIN.CurrentTheme;
  5546. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5547. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5548. for(int i=0;i<MAIN.WireColorSlices;i++){
  5549. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5550. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5551. }
  5552. }
  5553. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5554. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5555. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5556. tnsInterpolate2dv(v1,v2,0.5,vi);
  5557. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5558. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5559. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5560. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5561. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5562. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5563. tnsVertex2d(v1[0],v1[1]);
  5564. for(int i=1;i<=steps;i++){
  5565. real ratio=i==steps?1.0f:step*i;
  5566. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5567. tnsVertex2d(v1s[0],v1s[1]);
  5568. }
  5569. }
  5570. void la_DrawNodeWires(laUiListDraw* uild){
  5571. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5572. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5573. tnsUseNoTexture();
  5574. #define _RSLICES 16
  5575. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5576. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5577. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5578. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5579. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5580. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5581. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5582. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5583. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5584. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5585. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5586. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5587. }
  5588. if(MAIN.tNodeIn->Source){
  5589. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5590. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5591. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5592. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5593. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5594. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5595. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5596. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5597. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5598. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5599. }
  5600. #undef _RSLICES
  5601. tnsFlush();
  5602. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5603. glLineWidth(ww);
  5604. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5605. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5606. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5607. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5608. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5609. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5610. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5611. }
  5612. if(MAIN.tNodeIn->Source){
  5613. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5614. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5615. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5616. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5617. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5618. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5619. }
  5620. tnsFlush();
  5621. glLineWidth(1);
  5622. la_InitSocketRecord(uild,0);
  5623. }
  5624. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5625. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5626. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5627. }
  5628. 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){
  5629. laUiItem *ui;
  5630. laBoxedTheme *bt;
  5631. laUiList *sub;
  5632. laUiListDrawItem *uildi;
  5633. int Ret = 0;
  5634. if (!uil) return 0;
  5635. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5636. ui = uil->UiItems.pFirst;
  5637. if(uil->PanY<0){uil->PanY=0;}
  5638. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5639. uil->SaveScale=MAIN.UiScale;
  5640. MAIN.UiScale*=uil->Scale;
  5641. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5642. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5643. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5644. if (ui->Type == &_LA_UI_CONDITION){
  5645. laConditionUiExtraData *cued = ui->Extra;
  5646. la_StepExpression(cued->Expression);
  5647. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5648. if (!cued->IsTrue){
  5649. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5650. }else{
  5651. ui = ui->Item.pNext;
  5652. }
  5653. continue;
  5654. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5655. ui = ui->Item.pNext;
  5656. continue;
  5657. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5658. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5659. if (cued->IsTrue) ui = cued->EndUi;
  5660. else
  5661. ui = ui->Item.pNext;
  5662. continue;
  5663. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5664. laConditionUiExtraData *cued = ui->Extra;
  5665. ui->Type->Draw(ui, LA_RH);
  5666. if (ui->State == LA_UI_NORMAL){
  5667. cued->IsTrue = 0;
  5668. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5669. }else{
  5670. cued->IsTrue = 1;
  5671. ui = ui->Item.pNext;
  5672. }
  5673. continue;
  5674. }
  5675. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5676. int NeedDraw=0;
  5677. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5678. if(NeedDraw){
  5679. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5680. }else{ ui->Type->Draw(ui, LA_RH); }
  5681. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5682. tnsFlush();
  5683. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5684. tnsResetViewMatrix();
  5685. }
  5686. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5687. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5688. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5689. tnsFlush();
  5690. }
  5691. }
  5692. if(NeedDraw || RegisterNodes){
  5693. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5694. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5695. ui->Type == _LA_UI_TAB ||
  5696. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5697. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5698. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5699. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5700. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5701. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5702. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5703. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5704. 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); }
  5705. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5706. 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);
  5707. 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)); }
  5708. }elif (ui->Type == _LA_UI_COLLECTION){
  5709. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5710. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5711. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5712. void* SaveInstance = ui->PP.EndInstance;
  5713. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5714. int State;
  5715. ui->PP.EndInstance = sub->Instance;
  5716. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5717. if(NeedDraw){ int drawn=0;
  5718. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5719. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5720. }
  5721. if (CanGetState && !drawn){
  5722. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5723. if(State >= 0){
  5724. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5725. }
  5726. }
  5727. }
  5728. if(sub->TabName && sub->TabName->Ptr){
  5729. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5730. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5731. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5732. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5733. tnsFlush();
  5734. }
  5735. if(CanGetTheme){
  5736. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5737. la_SwitchThemeQuick(t, OriginalTheme);
  5738. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5739. }
  5740. tnsFlush();
  5741. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5742. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5743. }
  5744. //ui->PP.EndInstance = Active;
  5745. ui->PP.EndInstance = SaveInstance;
  5746. }elif (ui->Type == _LA_UI_CANVAS){
  5747. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5748. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5749. tnsFlush();
  5750. 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);
  5751. }
  5752. }
  5753. }
  5754. ui = ui->Item.pNext;
  5755. }else{
  5756. ui = ui->Item.pNext;
  5757. }
  5758. }
  5759. tnsFlush();
  5760. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5761. la_RestoreLastUiListMatrix(uild, B - U);
  5762. MAIN.UiScale=uil->SaveScale;
  5763. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5764. return Ret;
  5765. }
  5766. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5767. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5768. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5769. tnsUseNoTexture();
  5770. tnsColor4d(1, 1, 1, 1);
  5771. tnsVertex2d(L, U);
  5772. tnsVertex2d(R, U);
  5773. tnsVertex2d(R, B);
  5774. tnsVertex2d(L, B);
  5775. tnsPackAs(GL_LINE_LOOP);
  5776. tnsVertex2d(L + 3, Begin);
  5777. tnsVertex2d(R - 3, Begin);
  5778. tnsVertex2d(R - 3, End);
  5779. tnsVertex2d(L + 3, End);
  5780. tnsPackAs(GL_LINE_LOOP);
  5781. }
  5782. int laIsInUiItem(laUiItem *ui, int x, int y){
  5783. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5784. return 1;
  5785. }
  5786. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5787. if (x < l || x > r || y < u || y > b) return 0;
  5788. return 1;
  5789. }
  5790. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5791. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5792. laUiItem *ui, *tui;
  5793. laBoxedTheme *bt;
  5794. laUiList *sub;
  5795. int CPB = 0;
  5796. if (!uil || (LimB && y > LimB)) return 0;
  5797. x += uil->PanX;
  5798. y += uil->PanY;
  5799. for (ui = uil->UiItems.pFirst; ui;){
  5800. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5801. if (ui->Type == &_LA_UI_CONDITION){
  5802. laConditionUiExtraData *cued = ui->Extra;
  5803. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5804. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5805. if (!cued->IsTrue){
  5806. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5807. }else{
  5808. ui = ui->Item.pNext;
  5809. }
  5810. continue;
  5811. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5812. ui = ui->Item.pNext;
  5813. continue;
  5814. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5815. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5816. if (cued->IsTrue) ui = cued->EndUi;
  5817. else
  5818. ui = ui->Item.pNext;
  5819. continue;
  5820. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5821. laConditionUiExtraData *cued = ui->Extra;
  5822. if (laIsInUiItem(ui, x, y)){
  5823. lstAppendPointer(LocalBuf, uil);
  5824. return ui;
  5825. }
  5826. if (ui->State == LA_UI_NORMAL){
  5827. cued->IsTrue = 0;
  5828. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5829. }else{
  5830. cued->IsTrue = 1;
  5831. ui = ui->Item.pNext;
  5832. }
  5833. continue;
  5834. }
  5835. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5836. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5837. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5838. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5839. if(!la_DetectSplit(ui->C, x)) Add=0;
  5840. }
  5841. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5842. }
  5843. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5844. if (ui->Page->HeightCoeff) CPB = ui->B;
  5845. else CPB = ui->Page->B;
  5846. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5847. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5848. lstAppendPointer(LocalBuf, uil);
  5849. return tui;
  5850. }
  5851. }else if (laIsInUiItem(ui, x, y)){
  5852. lstAppendPointer(LocalBuf, uil);return ui;
  5853. }
  5854. }
  5855. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5856. if (laIsInUiItem(ui, x, y)){
  5857. lstAppendPointer(LocalBuf, uil);
  5858. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5859. if(Deep){
  5860. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5861. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5862. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5863. lstAppendPointer(LocalBuf, iuil);
  5864. return tui;
  5865. }
  5866. }
  5867. }
  5868. }
  5869. return ui;
  5870. }
  5871. }
  5872. if (ui->Type == _LA_UI_CANVAS){
  5873. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5874. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5875. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5876. lstAppendPointer(LocalBuf, uil);
  5877. return tui;
  5878. }
  5879. }
  5880. }
  5881. if (laIsInUiItem(ui, x, y)){
  5882. lstAppendPointer(LocalBuf, uil);
  5883. return ui;
  5884. }
  5885. }
  5886. ui = ui->Item.pNext;
  5887. }
  5888. return 0;
  5889. }
  5890. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5891. laListHandle Locals={0};
  5892. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5893. while(lstPopPointer(&Locals));
  5894. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5895. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5896. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5897. if(pc==PCInOrOut) return ui;
  5898. }
  5899. return 0;
  5900. }
  5901. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5902. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5903. laUiItem *ui = uil->UiItems.pFirst;
  5904. laBoxedTheme *bt;
  5905. laUiList *tuil;
  5906. laUiList *sub;
  5907. int CPB = 0;
  5908. x += uil->PanX;
  5909. y += uil->PanY;
  5910. if (y > LimH) return uil;
  5911. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  5912. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  5913. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5914. return uil;
  5915. }
  5916. for (ui = uil->UiItems.pFirst; ui;){
  5917. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5918. if (ui->Type == &_LA_UI_CONDITION){
  5919. laConditionUiExtraData *cued = ui->Extra;
  5920. //la_StepExpression(cued->Expression);
  5921. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5922. if (!cued->IsTrue){
  5923. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5924. }else{
  5925. ui = ui->Item.pNext;
  5926. }
  5927. continue;
  5928. }
  5929. if (ui->Type == &_LA_UI_CONDITION_END){
  5930. ui = ui->Item.pNext;
  5931. continue;
  5932. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5933. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5934. if (cued->IsTrue) ui = cued->EndUi;
  5935. else
  5936. ui = ui->Item.pNext;
  5937. continue;
  5938. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5939. laConditionUiExtraData *cued = ui->Extra;
  5940. if (ui->State == LA_UI_NORMAL){
  5941. cued->IsTrue = 0;
  5942. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5943. }else{
  5944. cued->IsTrue = 1;
  5945. ui = ui->Item.pNext;
  5946. }
  5947. continue;
  5948. }
  5949. if (InToContainerUI && ui != Exception){
  5950. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5951. if (ContainerParent) (*ContainerParent) = uil;
  5952. if (ParentUi) *ParentUi = ui;
  5953. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5954. //if (y > LimH) return uil;
  5955. 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))){
  5956. return tuil;
  5957. }
  5958. }
  5959. }
  5960. }
  5961. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5962. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  5963. else CPB = ui->Page->B;
  5964. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5965. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5966. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5967. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5968. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5969. if (ParentUi) *ParentUi = ui;
  5970. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5971. }
  5972. }
  5973. ui = ui->Item.pNext;
  5974. }
  5975. return uil;
  5976. }
  5977. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5978. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5979. laUiItem *ui = uil->UiItems.pFirst;
  5980. laBoxedTheme *bt;
  5981. laUiList *tuil;
  5982. laUiList *sub;
  5983. int CPB = 0;
  5984. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5985. x += uil->PanX;
  5986. y += uil->PanY;
  5987. if (y > LimH) return uil;
  5988. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5989. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5990. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5991. return uil;
  5992. }
  5993. for (ui = uil->UiItems.pFirst; ui;){
  5994. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5995. if (ui->Type == &_LA_UI_CONDITION){
  5996. laConditionUiExtraData *cued = ui->Extra;
  5997. //la_StepExpression(cued->Expression);
  5998. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5999. if (!cued->IsTrue){
  6000. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6001. }else{
  6002. ui = ui->Item.pNext;
  6003. }
  6004. continue;
  6005. }
  6006. if (ui->Type == &_LA_UI_CONDITION_END){
  6007. ui = ui->Item.pNext;
  6008. continue;
  6009. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6010. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6011. if (cued->IsTrue) ui = cued->EndUi;
  6012. else
  6013. ui = ui->Item.pNext;
  6014. continue;
  6015. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6016. laConditionUiExtraData *cued = ui->Extra;
  6017. if (ui->State == LA_UI_NORMAL){
  6018. cued->IsTrue = 0;
  6019. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6020. }else{
  6021. cued->IsTrue = 1;
  6022. ui = ui->Item.pNext;
  6023. }
  6024. continue;
  6025. }
  6026. if (InToContainerUI && ui != Exception){
  6027. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6028. if (ContainerParent) (*ContainerParent) = uil;
  6029. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6030. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6031. //if (y > LimH) return uil;
  6032. 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))){
  6033. return tuil;
  6034. }
  6035. }
  6036. }
  6037. }
  6038. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6039. if (ui->Page->HeightCoeff) CPB = ui->B;
  6040. else CPB = ui->Page->B;
  6041. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6042. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6043. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6044. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6045. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6046. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6047. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6048. }
  6049. }
  6050. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6051. if (ui->Page->HeightCoeff) CPB = ui->B;
  6052. else
  6053. CPB = ui->Page->B;
  6054. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6055. if (ScrollUil) *ScrollUil = ui->Page;
  6056. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6057. }
  6058. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6059. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6060. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6061. }
  6062. }
  6063. ui = ui->Item.pNext;
  6064. }
  6065. return uil;
  6066. }
  6067. int la_TestUiListMinumWidth(laUiList *uil){
  6068. laUiItem *ui, *tui;
  6069. laBoxedTheme *bt;
  6070. laUiList *sub;
  6071. int CPB = 0;
  6072. int W = 0;
  6073. int tW, sW, RowMode=0, rW;
  6074. void *Restore;
  6075. for (ui = uil->UiItems.pFirst; ui;){
  6076. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6077. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6078. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6079. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6080. if (W < tW) W = tW;
  6081. }elif (ui->Type == _LA_UI_COLLECTION){
  6082. Restore = ui->PP.EndInstance;
  6083. tW = 0; sW = 0;
  6084. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6085. ui->PP.EndInstance = sub->Instance;
  6086. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6087. if (sW > tW) tW = sW;
  6088. }
  6089. ui->PP.EndInstance = Restore;
  6090. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6091. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6092. if (W < tW) W = tW;
  6093. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6094. RowMode=1; rW=0;
  6095. }elif (ui->Type==&_LA_UI_ROW_END){
  6096. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6097. }elif (ui->Type->GetMinWidth){
  6098. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6099. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6100. }
  6101. ui = ui->Item.pNext;
  6102. }
  6103. return W;
  6104. }
  6105. void la_InitLLVM(){
  6106. //LLVMLinkInMCJIT();
  6107. //LLVMInitializeNativeTarget();
  6108. //LLVMInitializeNativeAsmPrinter();
  6109. //LLVMInitializeNativeAsmParser();
  6110. // MAIN.llvmContext = LLVMGetGlobalContext();
  6111. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6112. }
  6113. //==================================================================================================
  6114. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6115. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6116. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6117. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6118. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6119. memFree(kmi);
  6120. }
  6121. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6122. laKeyMapItem *kmi;
  6123. if (!km) return 0;
  6124. kmi = memAcquire(sizeof(laKeyMapItem));
  6125. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6126. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6127. }else{
  6128. strSafeSet(&kmi->Operation, Operation);
  6129. }
  6130. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6131. kmi->SpecialKeyBits = SpecialKeyBits;
  6132. kmi->EventType = EventType;
  6133. kmi->Key = tolowerGuarded(Key);
  6134. kmi->SelectBase = SelectBase;
  6135. lstAppendItem(&km->Items, kmi);
  6136. return kmi;
  6137. }
  6138. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6139. laKeyMapItem *kmi; int inv=0;
  6140. char *instructions;
  6141. if(e->type==LA_MOUSEMOVE) return 0;
  6142. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6143. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6144. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6145. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6146. if (kmi->Operation)
  6147. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6148. else
  6149. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6150. inv = 1;
  6151. }
  6152. }
  6153. return inv;
  6154. }
  6155. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6156. laKeyMapItem *kmi;
  6157. char *instructions;
  6158. int inv = 0; int lx = -1, ly = -1;
  6159. if(e->type==LA_MOUSEMOVE) return 0;
  6160. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6161. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6162. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6163. if (e->Localized){
  6164. lx = e->x;
  6165. ly = e->y;
  6166. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6167. e->Localized = 0;
  6168. }
  6169. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6170. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6171. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6172. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6173. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6174. }elif (kmi->Operation){
  6175. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6176. }else{
  6177. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6178. }
  6179. inv = 1;
  6180. if (lx >= 0){
  6181. e->x = lx;
  6182. e->y = ly;
  6183. e->Localized = 1;
  6184. }
  6185. }
  6186. }
  6187. return inv;
  6188. }
  6189. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6190. void la_DestroyOperatorType(laOperatorType* at){
  6191. //if(at->PC) la_FreePropertyContainer(at->PC);
  6192. memFree(at);
  6193. }
  6194. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6195. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6196. uint32_t IconID, int ExtraMark){
  6197. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6198. at->Identifier = ID;
  6199. at->Name = Name;
  6200. at->Description = Description;
  6201. at->Check = Check;
  6202. at->Invoke = Invoke;
  6203. at->Init = Init;
  6204. at->Exit = Exit;
  6205. at->Modal = Modal;
  6206. at->IconID = IconID;
  6207. at->ExtraMark = ExtraMark;
  6208. at->ParseArgs = la_DefaultOperatorParser;
  6209. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6210. return at;
  6211. }
  6212. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6213. ot->PC = memAcquire(sizeof(laPropContainer));
  6214. ot->PC->Identifier = ot->Identifier;
  6215. ot->PC->Hyper = HyperLevel;
  6216. return ot->PC;
  6217. }
  6218. laOperator *la_CreateOperator(laOperatorType *at){
  6219. laOperator *a = CreateNew(laOperator);
  6220. a->Type = at;
  6221. if (at->PC && at->PC->Props.pFirst){
  6222. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6223. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6224. a->PP.LastPs->p->SubProp = at->PC;
  6225. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6226. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6227. a->PP.LastPs->Type = U'.';
  6228. }
  6229. return a;
  6230. }
  6231. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6232. return (!strcmp(a->Identifier, id));
  6233. }
  6234. laOperatorType *laGetOperatorType(const char *ID){
  6235. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6236. }
  6237. int laOperatorExistsT(laOperatorType* at){
  6238. if (!at) return 0;
  6239. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6240. return 0;
  6241. }
  6242. int laOperatorExists(const char* ID){
  6243. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6244. return laOperatorExistsT(at);
  6245. }
  6246. int la_OperatorExists(laOperator *ac){
  6247. if (!ac) return 0;
  6248. laOperator *a;
  6249. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6250. return 0;
  6251. }
  6252. int la_UiOperatorExists(void *inst){
  6253. laOperator *a;
  6254. if (!inst) return 0;
  6255. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6256. if (((laUiItem *)a->Instance) == inst){
  6257. return 1;
  6258. }
  6259. }
  6260. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6261. if (a->Instance == inst){
  6262. return 1;
  6263. }
  6264. }
  6265. return 0;
  6266. }
  6267. int la_OperatorPending(laOperator *target){
  6268. laOperator *a;
  6269. if (!target) return 0;
  6270. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6271. if (a == target){
  6272. return 1;
  6273. }
  6274. }
  6275. return 0;
  6276. }
  6277. void laSetOperatorLocalizer(void *ToPanel){
  6278. MAIN.ToPanel = ToPanel;
  6279. }
  6280. void la_DestroyConfirmData(laConfirmData **cd);
  6281. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6282. laOperator *ai = (*a);
  6283. laOperator *ac = ((*a)->Child);
  6284. void *Ret = 0;
  6285. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6286. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6287. }
  6288. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6289. if ((*a)->PP.LastPs){
  6290. memFree((*a)->PP.LastPs->p);
  6291. memFree((*a)->PP.LastPs);
  6292. }
  6293. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6294. la_SetPropMathcerContext((*a)->OperatorPanel);
  6295. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6296. laDestroySinglePanel((*a)->OperatorPanel,0);
  6297. }
  6298. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6299. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6300. lstClearPointer(&(*a)->LocalUiLists);
  6301. if (Operators){
  6302. Ret = ai->Item.pNext;
  6303. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6304. else
  6305. lstRemoveItem(Operators, *a);
  6306. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6307. if (ai->Child == (*a)) ai->Child = 0;
  6308. }
  6309. }
  6310. strSafeDestroy(&(*a)->RuntimeHint);
  6311. free(*a);
  6312. return Ret;
  6313. }
  6314. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6315. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6316. if (!at) return 0;
  6317. if (!at->Check) return 1;
  6318. return (at->Check(This, Instructions));
  6319. }
  6320. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6321. if (!at) return 0;
  6322. if (!at->Check) return 1;
  6323. return (at->Check(This, Instructions));
  6324. }
  6325. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6326. laPropPack FakePP = {0};
  6327. laPropStep FakePs = {0};
  6328. if (!at) return 0;
  6329. if (!at->Check) return 1;
  6330. FakePP.LastPs = &FakePs;
  6331. FakePP.Go = FakePP.LastPs;
  6332. FakePP.LastPs->p = This->LastPs->p;
  6333. FakePP.LastPs->UseInstance = This->EndInstance;
  6334. FakePP.EndInstance = Real_FromInstance;
  6335. FakePP.LastIndex = This->LastIndex;
  6336. return (at->Check(&FakePP, Instructions));
  6337. }
  6338. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6339. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6340. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6341. }
  6342. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6343. laOperator *a, *f = From;
  6344. int rev;
  6345. if (!f && e&&e->Localized) return -1;
  6346. a = la_CreateOperator(at);
  6347. a->ToPanel = MAIN.ToPanel;
  6348. a->This = This;
  6349. a->ExtraInstructions = args;
  6350. strMakeInstructions(&a->ExtraInstructionsP, args);
  6351. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6352. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6353. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6354. la_DestroyOperator(&a, 0, 0);
  6355. return LA_CANCELED;
  6356. }
  6357. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6358. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6359. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6360. e->Localized = 1;
  6361. }
  6362. if (e&&e->Localized){
  6363. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6364. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6365. e->Localized = 0;
  6366. }else{
  6367. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6368. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6369. }
  6370. }
  6371. if (From) f->Child = a;
  6372. a->Using = 1;
  6373. if (at->Init) at->Init(a);
  6374. rev = at->Invoke(a, e);
  6375. a->Using = 0;
  6376. if (rev & LA_FINISH){
  6377. a->StopNow = 1; if(From)From->Child=0;
  6378. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6379. }
  6380. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6381. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6382. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6383. a->State = rev;
  6384. a->PP.EndInstance = a->CustomData;
  6385. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6386. }else
  6387. la_DestroyOperator(&a, 0, 0);
  6388. return rev;
  6389. }
  6390. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6391. laOperatorType *at; laOperator *a, *f = From;
  6392. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6393. if (!at) return -1;
  6394. return laInvokeP(From,at,e,This,args,args2);
  6395. }
  6396. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6397. laOperator *a, *f = From;
  6398. int rev;
  6399. laPropPack *created;
  6400. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6401. created = memAcquireSimple(sizeof(laPropPack));
  6402. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6403. created->Go = created->LastPs;
  6404. created->LastPs->p = OrigionalThis->LastPs->p;
  6405. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6406. created->EndInstance = FromInstance;
  6407. created->LastIndex = OrigionalThis->LastIndex;
  6408. a = la_CreateOperator(at);
  6409. a->ToPanel = MAIN.ToPanel;
  6410. a->This = created;
  6411. a->CreatedThis = created;
  6412. a->ExtraInstructions = args;
  6413. strMakeInstructions(&a->ExtraInstructionsP, args);
  6414. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6415. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6416. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6417. la_DestroyOperator(&a, 0, 0);
  6418. return LA_CANCELED;
  6419. }
  6420. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6421. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6422. if (From) f->Child = a;
  6423. a->Using = 1;
  6424. if (at->Init) at->Init(a);
  6425. rev = at->Invoke(a, e);
  6426. a->Using = 0;
  6427. if (rev & LA_FINISH){
  6428. a->StopNow = 1; if(From)From->Child=0;
  6429. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6430. }
  6431. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6432. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6433. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6434. a->State = rev;
  6435. a->PP.EndInstance = a->CustomData;
  6436. }else
  6437. la_DestroyOperator(&a, 0, 0);
  6438. return rev;
  6439. }
  6440. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6441. laOperator *a, *f = From;
  6442. int rev;
  6443. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6444. a = la_CreateOperator(at);
  6445. a->Instance = inst;
  6446. a->ToPanel = MAIN.ToPanel;
  6447. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6448. if (From) f->Child = a;
  6449. a->Using = 1;
  6450. if (at->Init) at->Init(a);
  6451. rev = at->Invoke(a, e);
  6452. a->Using = 0;
  6453. if (rev & LA_FINISH){
  6454. a->StopNow = 1; if(From)From->Child=0;
  6455. }
  6456. if (rev & LA_BLOCK){
  6457. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6458. a->State = rev;
  6459. }else la_DestroyOperator(&a, 0, 0);
  6460. DEB = a;
  6461. return rev;
  6462. }
  6463. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6464. laOperatorType *at;
  6465. laOperator *a, *f = From;
  6466. if (la_UiOperatorExists(inst)) return -1;
  6467. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6468. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6469. }
  6470. void laRequestDelayEvent(real Seconds){
  6471. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6472. int la_UiStillInService(void *UiInstance){
  6473. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6474. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6475. if (ai->Instance == UiInstance) return 1;
  6476. }
  6477. return 0;
  6478. }
  6479. void la_StopUiOperatorService(void *UiInstance){
  6480. laOperator *ai, *dai, *NextAi;
  6481. if (!MAIN.CurrentWindow) return;
  6482. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6483. NextAi = ai->Item.pNext;
  6484. if (ai->Instance == UiInstance){
  6485. if (ai->Child){
  6486. la_StopUiOperatorService(ai->Child->Instance);
  6487. ai->Child = 0;
  6488. }
  6489. laOperator *dai = ai;
  6490. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6491. continue;
  6492. }
  6493. }
  6494. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6495. NextAi = ai->Item.pNext;
  6496. if (ai->Instance == UiInstance){
  6497. if (ai->Instance == ai->ToPanel){
  6498. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6499. //ai->ToPanel->LaterDestroy = 1;
  6500. }
  6501. if (ai->Child && la_OperatorExists(ai->Child)){
  6502. la_StopUiOperatorService(ai->Child->Instance);
  6503. //ai->Child = 0;
  6504. }
  6505. if (!ai->Using){
  6506. laOperator *dai = ai;
  6507. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6508. }else
  6509. ai->StopNow = 1;
  6510. }
  6511. }
  6512. }
  6513. void la_StopAllOperators(){
  6514. laOperator *ai, *dai, *NextAi;
  6515. if (!MAIN.CurrentWindow) return;
  6516. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6517. NextAi = ai->Item.pNext;
  6518. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6519. continue;
  6520. }
  6521. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6522. NextAi = ai->Item.pNext;
  6523. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6524. laHidePanelWithDissoveEffect(ai->ToPanel);
  6525. ai->ToPanel->LaterDestroy = 1;
  6526. }
  6527. if (!ai->Using){
  6528. laOperator *dai = ai;
  6529. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6530. }else ai->StopNow = 1;
  6531. }
  6532. }
  6533. void la_DestroyConfirmData(laConfirmData **cd){
  6534. if((!cd)||!(*cd)) return;
  6535. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6536. if ((*cd)->StrData) free((*cd)->StrData);
  6537. FreeMem((*cd));
  6538. (*cd) = 0;
  6539. }
  6540. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6541. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6542. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6543. ai->NextConfirmData = cd; laRetriggerOperators();
  6544. }
  6545. void laConfirmInt(laOperator *a, int Data, int mode){
  6546. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6547. cd->IData = Data; cd->Mode = mode;
  6548. ai->NextConfirmData = cd; laRetriggerOperators();
  6549. }
  6550. void laConfirmFloat(laOperator *a, real Data, int mode){
  6551. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6552. cd->FData = Data; cd->Mode = mode;
  6553. ai->NextConfirmData = cd; laRetriggerOperators();
  6554. }
  6555. void laConfirmString(laOperator *a, char *Str, int mode){
  6556. laOperator *ai = a;
  6557. laConfirmData *cd = CreateNew(laConfirmData);
  6558. int len = strlen(Str);
  6559. char *buf = calloc(len + 1, sizeof(char));
  6560. strcpy(buf, Str);
  6561. cd->StrData = buf;
  6562. cd->Mode = mode;
  6563. cd->Destroy = free;
  6564. ai->NextConfirmData = cd;
  6565. laRetriggerOperators();
  6566. }
  6567. int laConfirmSameDataIfAny(laOperator *a){
  6568. laOperator *ai = a;
  6569. laConfirmData *cd;
  6570. char *buf = 0;
  6571. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6572. cd = CreateNew(laConfirmData);
  6573. if (ai->ConfirmData->StrData){
  6574. int len = strlen(ai->ConfirmData->StrData);
  6575. buf = calloc(len + 1, sizeof(char));
  6576. strcpy(buf, ai->ConfirmData->StrData);
  6577. }
  6578. //cd->CustomData = cd->CustomData;
  6579. cd->IData = ai->ConfirmData->IData;
  6580. cd->FData = ai->ConfirmData->FData;
  6581. cd->PointerData = ai->ConfirmData->PointerData;
  6582. cd->PointerType = a->ConfirmData->PointerType;
  6583. cd->StrData = buf;
  6584. cd->Mode = ai->ConfirmData->Mode;
  6585. cd->Destroy = ai->ConfirmData->Destroy;
  6586. ai->NextConfirmData = cd;
  6587. laRetriggerOperators();
  6588. return 1;
  6589. }
  6590. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6591. laOperator *ai = a;
  6592. laConfirmData *cd = CreateNew(laConfirmData);
  6593. cd->CustomData = UserData;
  6594. cd->Mode = mode;
  6595. cd->Destroy = Destroy;
  6596. ai->NextConfirmData = cd;
  6597. laRetriggerOperators();
  6598. }
  6599. int laGetConfirmMode(laOperator *a){
  6600. return ((laOperator *)a)->ConfirmData->Mode;
  6601. }
  6602. int laGetConfirmInt(laOperator *a){
  6603. laOperator *ai = a;
  6604. int rev = ai->ConfirmData->IData;
  6605. la_DestroyConfirmData(&ai->ConfirmData);
  6606. ai->ConfirmData = 0;
  6607. return rev;
  6608. }
  6609. real laGetConfirmFloat(laOperator *a){
  6610. laOperator *ai = a;
  6611. real rev = ai->ConfirmData->FData;
  6612. la_DestroyConfirmData(&ai->ConfirmData);
  6613. ai->ConfirmData = 0;
  6614. return rev;
  6615. }
  6616. void laGetConfirmString(laOperator *a, char *buf){
  6617. laOperator *ai = a;
  6618. strcpy(buf, ai->ConfirmData->StrData);
  6619. la_DestroyConfirmData(&ai->ConfirmData);
  6620. ai->ConfirmData = 0;
  6621. }
  6622. void *laGetConfirmUserData(laOperator *a){
  6623. laOperator *ai = a;
  6624. return ai->ConfirmData->CustomData;
  6625. }
  6626. void laFinalizeOperators(){
  6627. laOperatorType *at;
  6628. laListHandle *lst;
  6629. int i;
  6630. for (i = 0; i < 256; i++){
  6631. lst = &MAIN.OperatorTypeHash.Entries[i];
  6632. for (at = lst->pFirst; at; at = at->Item.pNext){
  6633. if (at->PC && at->PC->Props.pFirst){
  6634. lstAppendItem(&MAIN.PropContainers, at->PC);
  6635. }
  6636. }
  6637. }
  6638. }
  6639. //=================
  6640. #ifdef LA_LINUX
  6641. static void la_RecordWacomMotions(XIRawEvent *event)
  6642. {
  6643. double *valuator = event->valuators.values;
  6644. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6645. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6646. //SYSWINDOW root_return, child_return;
  6647. //int root_x_return, root_y_return;
  6648. //int win_x_return, win_y_return;
  6649. //unsigned int mask_return;
  6650. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6651. // &root_x_return, &root_y_return,
  6652. // &win_x_return, &win_y_return,
  6653. // &mask_return);
  6654. //
  6655. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6656. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6657. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6658. real x=valuator[3],y=valuator[4];
  6659. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6660. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6661. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6662. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6663. if(XIMaskIsSet(event->valuators.mask, 5)){
  6664. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6665. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6666. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6667. MAIN.IsPen=1;
  6668. }
  6669. #endif
  6670. #ifdef _WIN32
  6671. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6672. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6673. static uint32_t ch = 0; static int lead = 0;
  6674. static wchar_t buf[10] = { 0 }; int adv;
  6675. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6676. short wheelmark = 0;
  6677. int WheelDir = 0;
  6678. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6679. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6680. POINT point;
  6681. PACKET pkt;
  6682. static POINT ptOld, ptNew;
  6683. static UINT prsOld, prsNew, vkey;
  6684. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6685. switch (message) {
  6686. case WM_PAINT:
  6687. //SwapBuffers(GetDC(hwnd));
  6688. break;
  6689. case WM_MOUSEMOVE:
  6690. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6691. MAIN.IsPen = 0;
  6692. break;
  6693. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6694. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6695. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6696. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6697. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6698. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6699. case WM_MOUSEWHEEL:
  6700. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6701. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6702. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6703. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6704. break;
  6705. case WT_PACKET:
  6706. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6707. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6708. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6709. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6710. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6711. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6712. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6713. MAIN.StylusTwist = tw;
  6714. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6715. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6716. MAIN.EraserPressure = MAIN.StylusPressure;
  6717. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6718. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6719. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6720. }
  6721. return 0; break;
  6722. case WM_SYSCOMMAND:
  6723. switch (wparam) {
  6724. case SC_MAXIMIZE:
  6725. case SC_RESTORE:
  6726. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6727. break;
  6728. case SC_KEYMENU:
  6729. return 0;
  6730. case SC_MINIMIZE:
  6731. break;
  6732. }
  6733. break;
  6734. case WM_SIZE:
  6735. if (wparam == SIZE_MINIMIZED) break;
  6736. case WM_MOVE: /* And size */
  6737. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6738. break;
  6739. case WM_SETCURSOR:
  6740. if(MAIN.CurrentCursor) return 1;
  6741. break;
  6742. case WM_POINTERDOWN:
  6743. case WM_POINTERUP:
  6744. case WM_POINTERUPDATE:
  6745. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6746. pointerId = GET_POINTERID_WPARAM(wparam);
  6747. pointerType = PT_POINTER;
  6748. if(!GetPointerType(pointerId, &pointerType)){
  6749. pointerType = PT_POINTER;
  6750. }
  6751. if(pointerType == PT_PEN){
  6752. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6753. for (int i = peninfonum-1; i>=0; i--) {
  6754. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6755. ScreenToClient(hwnd, &point);
  6756. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6757. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6758. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6759. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6760. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6761. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6762. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6763. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6764. }
  6765. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6766. }
  6767. }
  6768. SkipPointerFrameMessages(pointerId);
  6769. return 0;
  6770. }
  6771. else if (pointerType == PT_TOUCH){
  6772. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6773. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6774. ScreenToClient(hwnd, &point);
  6775. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6776. }
  6777. }
  6778. break;
  6779. case WM_SYSKEYDOWN:
  6780. if (lparam & 0x40000000) break;
  6781. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6782. break;
  6783. case WM_KEYDOWN:
  6784. if (lparam & 0x40000000) break;
  6785. vkey = wparam;
  6786. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6787. break;
  6788. case WM_KEYUP:
  6789. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6790. break;
  6791. case WM_SYSKEYUP:
  6792. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6793. break;
  6794. case WM_UNICHAR:
  6795. la_SendInputEvent(hwnd, wparam);
  6796. break;
  6797. case WM_IME_CHAR:
  6798. la_SendInputEvent(hwnd, wparam);
  6799. return 0;
  6800. case WM_CHAR:
  6801. la_SendInputEvent(hwnd, wparam);
  6802. break;
  6803. case WM_SHOWWINDOW:
  6804. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6805. break;
  6806. case WM_CLOSE:
  6807. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6808. break;
  6809. default:
  6810. return DefWindowProc(hwnd, message, wparam, lparam);
  6811. }
  6812. return DefWindowProc(hwnd, message, wparam, lparam);
  6813. }
  6814. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6815. return DefWindowProc(hwnd, message, wparam, lparam);
  6816. }
  6817. #endif
  6818. int la_UpdateOperatorHints(laWindow* w){
  6819. laSafeString* ss=0;
  6820. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6821. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6822. }
  6823. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6824. }else{
  6825. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6826. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6827. }
  6828. strSafeDestroy(&ss);
  6829. }
  6830. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6831. laOperator *a, *NextA = 0;
  6832. int Result = 0;
  6833. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6834. la_SendSignalsFromEvent(e);
  6835. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6836. a = Operators->pFirst;
  6837. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6838. while (1){
  6839. if (!a) break;
  6840. if (a->StopNow){
  6841. NextA = a->Item.pNext;
  6842. if (a->Type->Exit) a->Type->Exit(a, Result);
  6843. ConfirmData = a->NextConfirmData;
  6844. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6845. NextConfirmData = ConfirmData;
  6846. a->ConfirmData = 0;
  6847. a->NextConfirmData = 0;
  6848. la_DestroyOperator(&a, Operators, 0);
  6849. a = NextA;
  6850. if (a){
  6851. a->ConfirmData = NextConfirmData;
  6852. }
  6853. continue;
  6854. }
  6855. a->Using = 1;
  6856. la_SetPropMathcerContext(a->ToPanel);
  6857. laSetOperatorLocalizer(a->ToPanel);
  6858. MAIN.CurrentPanel = a->ToPanel;
  6859. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6860. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6861. e->Localized = 1;
  6862. }
  6863. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6864. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6865. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6866. e->Localized = 0;
  6867. }
  6868. la_SetPropMathcerContext(0);
  6869. laSetOperatorLocalizer(0);
  6870. MAIN.CurrentPanel = 0;
  6871. a->Using = 0;
  6872. if (Result & LA_PASS_ON){
  6873. laConfirmSameDataIfAny(a);
  6874. NextA = a->Item.pNext;
  6875. }else{
  6876. NextA = 0;
  6877. if (a->NextConfirmData){
  6878. la_DestroyConfirmData(&a->NextConfirmData);
  6879. }
  6880. }
  6881. ConfirmData = a->NextConfirmData;
  6882. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6883. NextConfirmData = ConfirmData;
  6884. a->ConfirmData = 0;
  6885. a->NextConfirmData = 0;
  6886. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6887. if (a->Type->Exit) a->Type->Exit(a, Result);
  6888. la_DestroyOperator(&a, Operators, 0);
  6889. int found=0;
  6890. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6891. if(!found){ NextA=0; }
  6892. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6893. }
  6894. a = NextA;
  6895. if (a){
  6896. a->ConfirmData = NextConfirmData;
  6897. }
  6898. }
  6899. return 1;
  6900. }
  6901. int la_HandleEvents(laWindow *w){
  6902. laEvent *e, *NextE;
  6903. laOperator *a;
  6904. laThreadNotifier *tn;
  6905. MAIN.CurrentWindow=w;
  6906. //laSpinLock(&MAIN.csNotifier);
  6907. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6908. //laSpinUnlock(&MAIN.csNotifier);
  6909. laNotifyUsers(tn->Path);
  6910. FreeMem(tn);
  6911. //if (MAIN.ThreadNotifiers.pFirst)
  6912. //laSpinLock(&MAIN.csNotifier);
  6913. }
  6914. //laSpinUnlock(&MAIN.csNotifier);
  6915. while (1){
  6916. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6917. while (w->EventList.pFirst){
  6918. while (w->PendingOperators.pLast){
  6919. a = w->PendingOperators.pLast;
  6920. if (a->OperatorPanel){
  6921. laSetOperatorLocalizer(a->OperatorPanel);
  6922. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6923. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6924. }
  6925. lstRemoveItem(&w->PendingOperators, a);
  6926. lstPushItem(&w->Operators, a);
  6927. }
  6928. e = lstPopItem(&w->EventList);
  6929. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6930. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6931. memFree(e);
  6932. }
  6933. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  6934. if (!MAIN.ReTriggerOperators) break;
  6935. }
  6936. la_UpdateOperatorHints(w);
  6937. return 1;
  6938. }
  6939. int la_AllowInput(uint32_t ch){
  6940. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6941. return 0;
  6942. }
  6943. int laCopyToClipboard(unsigned char * text){
  6944. #ifdef LA_LINUX
  6945. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6946. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6947. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6948. strSafeSet(&MAIN.CopyPending, text);
  6949. #endif
  6950. }
  6951. int la_ProcessSysMessage(){
  6952. int SendDelay = 0, SendIdle = 0;
  6953. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6954. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6955. #ifdef LA_LINUX
  6956. XEvent e;
  6957. int type;
  6958. int InputCount = 0, CharCount=0;
  6959. KeySym InputKeysym = 0;
  6960. Status InputStatus = 0;
  6961. laWindow* wnd ;
  6962. while(XPending(MAIN.dpy)){
  6963. XGenericEventCookie *cookie = &e.xcookie;
  6964. XNextEvent(MAIN.dpy, &e);
  6965. if (XFilterEvent(&e, None)) continue;
  6966. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6967. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6968. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6969. XFreeEventData(MAIN.dpy, cookie); continue;
  6970. }
  6971. switch(e.type){
  6972. case ConfigureNotify:
  6973. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6974. break;
  6975. case Expose:
  6976. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6977. if(!wnd) break;
  6978. laRefreshWindow(wnd);
  6979. break;
  6980. case MotionNotify:
  6981. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6982. MAIN.IsPen=0;
  6983. break;
  6984. case ButtonPress:
  6985. type=LA_MOUSEDOWN;
  6986. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6987. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6988. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6989. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  6990. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  6991. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6992. MAIN.IsPen=0;
  6993. break;
  6994. case ButtonRelease:
  6995. type=LA_MOUSEUP;
  6996. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6997. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6998. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6999. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7000. MAIN.IsPen=0;
  7001. break;
  7002. case KeyPress:
  7003. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7004. MAIN.InputBuf[InputCount]=0;
  7005. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7006. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7007. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7008. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7009. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7010. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7011. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7012. #ifdef DEBUG
  7013. printf("pressed KEY: %d\n", (int)InputKeysym);
  7014. #endif
  7015. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7016. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7017. }
  7018. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7019. }
  7020. break;
  7021. case KeyRelease:
  7022. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7023. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7024. }
  7025. case ClientMessage:
  7026. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7027. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7028. }
  7029. break;
  7030. case SelectionNotify:
  7031. if(e.xselection.selection != MAIN.bufid) continue;
  7032. if (e.xselection.property){
  7033. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7034. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7035. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7036. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7037. else if(result) {
  7038. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7039. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7040. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7041. }
  7042. XFree(result);
  7043. return True;
  7044. }
  7045. case SelectionRequest:
  7046. if(!MAIN.CopyPending){ break; }
  7047. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7048. if (e.xselectionrequest.selection != MAIN.selection) break;
  7049. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7050. XSelectionEvent ev = {0};
  7051. int R = 0;
  7052. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7053. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7054. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7055. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7056. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7057. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7058. else if (ev.target == MAIN.UTF8)
  7059. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7060. else ev.property = None;
  7061. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7062. break;
  7063. case SelectionClear:
  7064. break;
  7065. default:
  7066. break;
  7067. }
  7068. }
  7069. #endif //linux
  7070. #ifdef _WIN32
  7071. MSG msg; int Processed = 0;
  7072. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7073. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7074. if (msg.wParam == VK_PROCESSKEY) {
  7075. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7076. }
  7077. TranslateMessage(&msg); DispatchMessage(&msg);
  7078. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7079. };
  7080. if(!MAIN.Windows.pFirst){ return 0; }
  7081. #endif
  7082. #ifdef LAGUI_ANDROID
  7083. int pollResult = 0;
  7084. int pollEvents = 0;
  7085. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7086. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7087. // NOTE: Never close window, native activity is controlled by the system!
  7088. if (MAIN.app->destroyRequested != 0)
  7089. {
  7090. //CORE.Window.shouldClose = true;
  7091. //ANativeActivity_finish(MAIN.app->activity);
  7092. }
  7093. }
  7094. #endif
  7095. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7096. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7097. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7098. }
  7099. return 1;
  7100. };
  7101. void la_PrintOperatorStack(){
  7102. laWindow *w = MAIN.CurrentWindow;
  7103. laOperator *a;
  7104. printf("\n");
  7105. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7106. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7107. a->Type->Identifier, a->Instance,
  7108. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7109. }
  7110. }
  7111. void la_DrawWindow(laWindow *w){
  7112. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7113. MAIN.CurrentWindow = w;
  7114. la_WindowDefDraw(w, 0);
  7115. }
  7116. int laFinalize(){
  7117. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7118. laUiTemplate* uit;
  7119. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7120. return 1;
  7121. }
  7122. void la_PreFrame(){
  7123. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7124. la_AnimationPreFrame();
  7125. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7126. }
  7127. void la_PostFrame(){
  7128. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7129. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7130. }
  7131. void laMainLoop(){
  7132. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7133. laTimeRecorder FrameStartTime, FrameEndTime;
  7134. time_t t1, t2;
  7135. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7136. static int a = 0;
  7137. if(!laFinalize()) return;
  7138. laSetWindowCursor(LA_ARROW);
  7139. MAIN.DelayTriggered=1;
  7140. #ifdef LAGUI_ANDROID
  7141. while(!MAIN.AppReady){ usleep(1000); }
  7142. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7143. #endif
  7144. while (1){
  7145. laRecordTime(&FrameStartTime);
  7146. la_PreFrame();
  7147. if(!la_ProcessSysMessage()){ return; }
  7148. la_UpdateControllerStatus();
  7149. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7150. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7151. NextW = w->Item.pNext;
  7152. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7153. }
  7154. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7155. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7156. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7157. if(MAIN.GLDebugNeedsUpdate){
  7158. la_SetCurrentGLContextDebug();
  7159. }
  7160. la_DrawWindow(w);
  7161. }
  7162. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7163. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7164. #ifdef LA_LINUX
  7165. #ifdef LA_USE_GLES
  7166. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7167. #else
  7168. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7169. #endif
  7170. #endif
  7171. #ifdef _WIN32
  7172. SwapBuffers(w->hdc);
  7173. #endif
  7174. #ifdef LAGUI_ANDROID
  7175. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7176. #endif
  7177. }
  7178. MAIN.GLDebugNeedsUpdate=0;
  7179. la_PostFrame();
  7180. //t2 = clock();
  7181. laRecordTime(&FrameEndTime);
  7182. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  7183. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7184. if (Pause > 0){
  7185. int us = Pause * 1000000.0;
  7186. usleep(us);
  7187. }
  7188. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7189. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7190. la_AnimationPostFrame();
  7191. }
  7192. }
  7193. #ifdef LAGUI_ANDROID
  7194. int la_AndroidInitGraphics(void){
  7195. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7196. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7197. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7198. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7199. EGLint samples = 0;
  7200. EGLint sampleBuffer = 0;
  7201. const EGLint framebufferAttribs[] = {
  7202. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7203. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7204. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7205. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7206. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7207. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7208. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7209. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7210. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7211. EGL_NONE
  7212. };
  7213. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7214. EGLint numConfigs = 0;
  7215. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7216. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7217. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7218. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7219. eglBindAPI(EGL_OPENGL_API);
  7220. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7221. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7222. EGLint displayFormat = 0;
  7223. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7224. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7225. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7226. // There must be at least one frame displayed before the buffers are swapped
  7227. eglSwapInterval(MAIN.egl_dpy, 1);
  7228. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7229. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7230. MAIN.AppReady = 1;
  7231. return 0;
  7232. }
  7233. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7234. switch (cmd){
  7235. case APP_CMD_START: break;
  7236. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7237. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7238. case APP_CMD_RESUME:break;//InitPlatform();break;
  7239. case APP_CMD_INIT_WINDOW:
  7240. if (app->window != NULL){
  7241. if (MAIN.ContextRebindRequired){
  7242. // Reset screen scaling to full display size
  7243. EGLint displayFormat = 0;
  7244. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7245. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7246. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7247. // appropriate way to fix this
  7248. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7249. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7250. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7251. displayFormat);
  7252. // Recreate display surface and re-attach OpenGL context
  7253. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7254. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7255. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7256. //glClearColor(1,0.2,1,1);
  7257. //glClear(GL_COLOR_BUFFER_BIT);
  7258. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7259. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7260. MAIN.ContextRebindRequired = false;
  7261. }else{
  7262. la_AndroidInitGraphics();
  7263. }
  7264. }
  7265. break;
  7266. case APP_CMD_TERM_WINDOW:
  7267. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7268. // 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.
  7269. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7270. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7271. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7272. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7273. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7274. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7275. MAIN.egl_surf = EGL_NO_SURFACE;
  7276. }
  7277. MAIN.ContextRebindRequired = true;
  7278. }
  7279. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7280. // this means that the user has already called 'CloseWindow()'
  7281. break;
  7282. case APP_CMD_SAVE_STATE: break;
  7283. case APP_CMD_STOP: break;
  7284. case APP_CMD_DESTROY: break;
  7285. case APP_CMD_CONFIG_CHANGED:
  7286. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7287. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7288. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7289. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7290. //print_cur_config(MAIN.app);
  7291. // Check screen orientation here!
  7292. break;
  7293. default: break;
  7294. }
  7295. }
  7296. #define KEYCODE_MAP_SIZE 162
  7297. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7298. 0, // AKEYCODE_UNKNOWN
  7299. 0, // AKEYCODE_SOFT_LEFT
  7300. 0, // AKEYCODE_SOFT_RIGHT
  7301. 0, // AKEYCODE_HOME
  7302. 0, // AKEYCODE_BACK
  7303. 0, // AKEYCODE_CALL
  7304. 0, // AKEYCODE_ENDCALL
  7305. '0', // AKEYCODE_0
  7306. '1', // AKEYCODE_1
  7307. '2', // AKEYCODE_2
  7308. '3', // AKEYCODE_3
  7309. '4', // AKEYCODE_4
  7310. '5', // AKEYCODE_5
  7311. '6', // AKEYCODE_6
  7312. '7', // AKEYCODE_7
  7313. '8', // AKEYCODE_8
  7314. '9', // AKEYCODE_9
  7315. 0, // AKEYCODE_STAR
  7316. 0, // AKEYCODE_POUND
  7317. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7318. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7319. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7320. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7321. 0, // AKEYCODE_DPAD_CENTER
  7322. 0, // AKEYCODE_VOLUME_UP
  7323. 0, // AKEYCODE_VOLUME_DOWN
  7324. 0, // AKEYCODE_POWER
  7325. 0, // AKEYCODE_CAMERA
  7326. 0, // AKEYCODE_CLEAR
  7327. 'a', // AKEYCODE_A
  7328. 'b', // AKEYCODE_B
  7329. 'c', // AKEYCODE_C
  7330. 'd', // AKEYCODE_D
  7331. 'e', // AKEYCODE_E
  7332. 'f', // AKEYCODE_F
  7333. 'g', // AKEYCODE_G
  7334. 'h', // AKEYCODE_H
  7335. 'i', // AKEYCODE_I
  7336. 'j', // AKEYCODE_J
  7337. 'k', // AKEYCODE_K
  7338. 'l', // AKEYCODE_L
  7339. 'm', // AKEYCODE_M
  7340. 'n', // AKEYCODE_N
  7341. 'o', // AKEYCODE_O
  7342. 'p', // AKEYCODE_P
  7343. 'q', // AKEYCODE_Q
  7344. 'r', // AKEYCODE_R
  7345. 's', // AKEYCODE_S
  7346. 't', // AKEYCODE_T
  7347. 'u', // AKEYCODE_U
  7348. 'v', // AKEYCODE_V
  7349. 'w', // AKEYCODE_W
  7350. 'x', // AKEYCODE_X
  7351. 'y', // AKEYCODE_Y
  7352. 'z', // AKEYCODE_Z
  7353. ',', // AKEYCODE_COMMA
  7354. '.', // AKEYCODE_PERIOD
  7355. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7356. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7357. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7358. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7359. LA_KEY_TAB, // AKEYCODE_TAB
  7360. ' ', // AKEYCODE_SPACE
  7361. 0, // AKEYCODE_SYM
  7362. 0, // AKEYCODE_EXPLORER
  7363. 0, // AKEYCODE_ENVELOPE
  7364. LA_KEY_ENTER, // AKEYCODE_ENTER
  7365. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7366. '`', // AKEYCODE_GRAVE
  7367. '-', // AKEYCODE_MINUS
  7368. '=', // AKEYCODE_EQUALS
  7369. '(', // AKEYCODE_LEFT_BRACKET
  7370. ')', // AKEYCODE_RIGHT_BRACKET
  7371. '\\', // AKEYCODE_BACKSLASH
  7372. ';', // AKEYCODE_SEMICOLON
  7373. '\'', // AKEYCODE_APOSTROPHE
  7374. '/', // AKEYCODE_SLASH
  7375. 0, // AKEYCODE_AT
  7376. 0, // AKEYCODE_NUM
  7377. 0, // AKEYCODE_HEADSETHOOK
  7378. 0, // AKEYCODE_FOCUS
  7379. 0, // AKEYCODE_PLUS
  7380. 0, // AKEYCODE_MENU
  7381. 0, // AKEYCODE_NOTIFICATION
  7382. 0, // AKEYCODE_SEARCH
  7383. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7384. 0, // AKEYCODE_MEDIA_STOP
  7385. 0, // AKEYCODE_MEDIA_NEXT
  7386. 0, // AKEYCODE_MEDIA_PREVIOUS
  7387. 0, // AKEYCODE_MEDIA_REWIND
  7388. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7389. 0, // AKEYCODE_MUTE
  7390. 0, // AKEYCODE_PAGE_UP
  7391. 0, // AKEYCODE_PAGE_DOWN
  7392. 0, // AKEYCODE_PICTSYMBOLS
  7393. 0, // AKEYCODE_SWITCH_CHARSET
  7394. 0, // AKEYCODE_BUTTON_A
  7395. 0, // AKEYCODE_BUTTON_B
  7396. 0, // AKEYCODE_BUTTON_C
  7397. 0, // AKEYCODE_BUTTON_X
  7398. 0, // AKEYCODE_BUTTON_Y
  7399. 0, // AKEYCODE_BUTTON_Z
  7400. 0, // AKEYCODE_BUTTON_L1
  7401. 0, // AKEYCODE_BUTTON_R1
  7402. 0, // AKEYCODE_BUTTON_L2
  7403. 0, // AKEYCODE_BUTTON_R2
  7404. 0, // AKEYCODE_BUTTON_THUMBL
  7405. 0, // AKEYCODE_BUTTON_THUMBR
  7406. 0, // AKEYCODE_BUTTON_START
  7407. 0, // AKEYCODE_BUTTON_SELECT
  7408. 0, // AKEYCODE_BUTTON_MODE
  7409. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7410. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7411. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7412. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7413. 0, // AKEYCODE_CAPS_LOCK
  7414. 0, // AKEYCODE_SCROLL_LOCK
  7415. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7416. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7417. 0, // AKEYCODE_FUNCTION
  7418. 0, // AKEYCODE_SYSRQ
  7419. 0, // AKEYCODE_BREAK
  7420. 0, // AKEYCODE_MOVE_HOME
  7421. 0, // AKEYCODE_MOVE_END
  7422. 0, // AKEYCODE_INSERT
  7423. 0, // AKEYCODE_FORWARD
  7424. 0, // AKEYCODE_MEDIA_PLAY
  7425. 0, // AKEYCODE_MEDIA_PAUSE
  7426. 0, // AKEYCODE_MEDIA_CLOSE
  7427. 0, // AKEYCODE_MEDIA_EJECT
  7428. 0, // AKEYCODE_MEDIA_RECORD
  7429. LA_KEY_F1, // AKEYCODE_F1
  7430. LA_KEY_F2, // AKEYCODE_F2
  7431. LA_KEY_F3, // AKEYCODE_F3
  7432. LA_KEY_F4, // AKEYCODE_F4
  7433. LA_KEY_F5, // AKEYCODE_F5
  7434. LA_KEY_F6, // AKEYCODE_F6
  7435. LA_KEY_F7, // AKEYCODE_F7
  7436. LA_KEY_F8, // AKEYCODE_F8
  7437. LA_KEY_F9, // AKEYCODE_F9
  7438. LA_KEY_F10, // AKEYCODE_F10
  7439. LA_KEY_F11, // AKEYCODE_F11
  7440. LA_KEY_F12, // AKEYCODE_F12
  7441. 0, // AKEYCODE_NUM_LOCK
  7442. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7443. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7444. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7445. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7446. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7447. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7448. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7449. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7450. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7451. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7452. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7453. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7454. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7455. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7456. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7457. 0, // AKEYCODE_NUMPAD_COMMA
  7458. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7459. '=' // AKEYCODE_NUMPAD_EQUALS
  7460. };
  7461. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7462. {
  7463. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7464. if(!MAIN.AppEnabled){return 0;}
  7465. //laRedrawAllWindows();
  7466. int type = AInputEvent_getType(event);
  7467. if(type == AINPUT_EVENT_TYPE_KEY){
  7468. int32_t keycode = AKeyEvent_getKeyCode(event);
  7469. //int32_t AKeyEvent_getMetaState(event);
  7470. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7471. if (key != 0){
  7472. // Save current key and its state
  7473. // NOTE: Android key action is 0 for down and 1 for up
  7474. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7475. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7476. if(key!=LA_KEY_BACKSPACE)
  7477. la_SendInputEvent(0,key);
  7478. }
  7479. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7480. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7481. la_SendInputEvent(0,key);
  7482. }
  7483. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7484. }
  7485. if (keycode == AKEYCODE_POWER)
  7486. {
  7487. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7488. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7489. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7490. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7491. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7492. return 0;
  7493. }
  7494. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7495. {
  7496. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7497. return 1;
  7498. }
  7499. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7500. {
  7501. // Set default OS behaviour
  7502. return 0;
  7503. }
  7504. return 0;
  7505. }
  7506. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7507. int pcount = AMotionEvent_getPointerCount(event); int x,y;
  7508. if(pcount){
  7509. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7510. x=rx; y=ry;
  7511. }
  7512. int32_t action = AMotionEvent_getAction(event);
  7513. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7514. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7515. if (flags == AMOTION_EVENT_ACTION_DOWN){
  7516. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7517. la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
  7518. }
  7519. else if (flags == AMOTION_EVENT_ACTION_UP){
  7520. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7521. }
  7522. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7523. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7524. }
  7525. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7526. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7527. }
  7528. }
  7529. //static float r=0;
  7530. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7531. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7532. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7533. //glClear(GL_COLOR_BUFFER_BIT);
  7534. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7535. return 0;
  7536. }
  7537. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7538. MAIN.AssetManager = manager;
  7539. MAIN.InternalDataPath = dataPath;
  7540. MAIN.ExternalDataPath = externalDataPath;
  7541. }
  7542. static int android_read(void *cookie, char *data, int dataSize){
  7543. return AAsset_read((AAsset *)cookie, data, dataSize);
  7544. }
  7545. static int android_write(void *cookie, const char *data, int dataSize){
  7546. return 0;
  7547. }
  7548. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7549. return AAsset_seek((AAsset *)cookie, offset, whence);
  7550. }
  7551. static int android_close(void *cookie){
  7552. AAsset_close((AAsset *)cookie);
  7553. return 0;
  7554. }
  7555. // Replacement for fopen()
  7556. // Ref: https://developer.android.com/ndk/reference/group/asset
  7557. FILE *android_fopen(const char *fileName, const char *mode)
  7558. {
  7559. char buf[1024];
  7560. if (mode[0] == 'w')
  7561. {
  7562. // fopen() is mapped to android_fopen() that only grants read access to
  7563. // assets directory through AAssetManager but we want to also be able to
  7564. // write data when required using the standard stdio FILE access functions
  7565. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7566. #undef fopen
  7567. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7568. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7569. result=fopen(buf, mode); if(result) return result;
  7570. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7571. return fopen(buf, mode);
  7572. #define fopen(name, mode) android_fopen(name, mode)
  7573. }
  7574. else
  7575. {
  7576. // NOTE: AAsset provides access to read-only asset
  7577. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7578. if (asset != NULL)
  7579. {
  7580. // Get pointer to file in the assets
  7581. return funopen(asset, android_read, android_write, android_seek, android_close);
  7582. }
  7583. else
  7584. {
  7585. #undef fopen
  7586. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7587. // Just do a regular open if file is not found in the assets
  7588. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7589. result=fopen(buf, mode); if(result){ return result; }
  7590. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7591. return fopen(buf, mode);
  7592. #define fopen(name, mode) android_fopen(name, mode)
  7593. }
  7594. }
  7595. }
  7596. void la_HideNavBar(){
  7597. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7598. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7599. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7600. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7601. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7602. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7603. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7604. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7605. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7606. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7607. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7608. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7609. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7610. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7611. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7612. int flag = flagFullscreen | flagHideNavigation;
  7613. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7614. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7615. }
  7616. void la_InitAndroidPlatform(struct android_app *app){
  7617. MAIN.app=app;
  7618. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7619. //la_HideNavBar();
  7620. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7621. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7622. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7623. int pollResult = 0;
  7624. int pollEvents = 0;
  7625. while (!MAIN.AppReady){
  7626. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7627. // Process this event
  7628. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7629. // NOTE: Never close window, native activity is controlled by the system!
  7630. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7631. }
  7632. }
  7633. }
  7634. int main(int, char *[]);
  7635. void android_main(struct android_app *app){
  7636. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7637. la_InitAndroidPlatform(app);
  7638. // NOTE: Return from main is ignored
  7639. (void)main(1, (char *[]) { arg0, NULL });
  7640. // Request to end the native activity
  7641. ANativeActivity_finish(app->activity);
  7642. // Android ALooper_pollAll() variables
  7643. int pollResult = 0;
  7644. int pollEvents = 0;
  7645. // Waiting for application events before complete finishing
  7646. while (!app->destroyRequested)
  7647. {
  7648. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7649. {
  7650. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7651. }
  7652. }
  7653. }
  7654. void la_DisplayKeyboard(bool pShow) {
  7655. // Attaches the current thread to the JVM.
  7656. jint lResult;
  7657. jint lFlags = 0;
  7658. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7659. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7660. JavaVMAttachArgs lJavaVMAttachArgs;
  7661. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7662. lJavaVMAttachArgs.name = "NativeThread";
  7663. lJavaVMAttachArgs.group = NULL;
  7664. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7665. if (lResult == JNI_ERR) {
  7666. return;
  7667. }
  7668. // Retrieves NativeActivity.
  7669. jobject lNativeActivity = MAIN.app->activity->clazz;
  7670. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7671. logPrintNew("jvm3");
  7672. // Retrieves Context.INPUT_METHOD_SERVICE.
  7673. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7674. jfieldID FieldINPUT_METHOD_SERVICE =
  7675. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7676. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7677. jobject INPUT_METHOD_SERVICE =
  7678. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7679. FieldINPUT_METHOD_SERVICE);
  7680. //jniCheck(INPUT_METHOD_SERVICE);
  7681. logPrintNew("jvm4");
  7682. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7683. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7684. "android/view/inputmethod/InputMethodManager");
  7685. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7686. ClassNativeActivity, "getSystemService",
  7687. "(Ljava/lang/String;)Ljava/lang/Object;");
  7688. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7689. lNativeActivity, MethodGetSystemService,
  7690. INPUT_METHOD_SERVICE);
  7691. // Runs getWindow().getDecorView().
  7692. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7693. ClassNativeActivity, "getWindow",
  7694. "()Landroid/view/Window;");
  7695. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7696. MethodGetWindow);
  7697. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7698. "android/view/Window");
  7699. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7700. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7701. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7702. MethodGetDecorView);
  7703. if (pShow) {
  7704. // Runs lInputMethodManager.showSoftInput(...).
  7705. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7706. ClassInputMethodManager, "showSoftInput",
  7707. "(Landroid/view/View;I)Z");
  7708. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7709. lInputMethodManager, MethodShowSoftInput,
  7710. lDecorView, lFlags);
  7711. } else {
  7712. // Runs lWindow.getViewToken()
  7713. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7714. "android/view/View");
  7715. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7716. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7717. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7718. MethodGetWindowToken);
  7719. // lInputMethodManager.hideSoftInput(...).
  7720. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7721. ClassInputMethodManager, "hideSoftInputFromWindow",
  7722. "(Landroid/os/IBinder;I)Z");
  7723. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7724. lInputMethodManager, MethodHideSoftInput,
  7725. lBinder, lFlags);
  7726. }
  7727. // Finished with the JVM.
  7728. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7729. }
  7730. #endif //android
  7731. #ifndef LAGUI_ANDROID
  7732. void la_DisplayKeyboard(bool pShow) {
  7733. return;
  7734. }
  7735. void la_HideNavBar(){
  7736. return;
  7737. }
  7738. #endif