*/}}

la_kernel.c 330 KB

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