*/}}

la_kernel.c 348 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  19. #define NANOVG_GLES3_IMPLEMENTATION
  20. #else
  21. #define NANOVG_GL3_IMPLEMENTATION
  22. #endif
  23. #include "la_5.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <time.h>
  28. #ifdef LA_LINUX
  29. #include <execinfo.h>
  30. #include <signal.h>
  31. #include <sys/time.h>
  32. #include <X11/Xlib.h>
  33. #include <X11/Xutil.h>
  34. #include <X11/Xos.h>
  35. #include <X11/keysymdef.h>
  36. #include <X11/XKBlib.h>
  37. #include <X11/extensions/XInput.h>
  38. #include <X11/extensions/XInput2.h>
  39. #include <X11/extensions/Xfixes.h>
  40. #include <X11/extensions/Xrandr.h>
  41. #include <X11/Xcursor/Xcursor.h>
  42. #include <X11/cursorfont.h>
  43. #include <GL/glx.h>
  44. #endif
  45. #ifdef _WIN32
  46. #include <GL/wglew.h>
  47. #include <GL/wgl.h>
  48. #include <shellscalingapi.h>
  49. #endif
  50. #ifdef LAGUI_ANDROID
  51. #include <GLES3/gl32.h>
  52. #include <jni.h>
  53. #include <android/log.h>
  54. #include <android/native_activity.h>
  55. #include <android/native_window.h>
  56. #include <android/native_window_jni.h>
  57. #include <android_native_app_glue.h>
  58. #include <android/window.h>
  59. #include <android/asset_manager.h>
  60. #include <android/input.h>
  61. #include <android/keycodes.h>
  62. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  63. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  64. static int android_read(void *cookie, char *buf, int size);
  65. static int android_write(void *cookie, const char *buf, int size);
  66. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  67. static int android_close(void *cookie);
  68. void la_InitAndroidPlatform(struct android_app *app);
  69. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  70. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  71. void la_InitAndroidPlatform(struct android_app *app);
  72. #endif
  73. LA MAIN={0};
  74. extern tnsMain *T;
  75. int deb = 0;
  76. laOperator *DEB;
  77. laColumn *DEBUG_C;
  78. #ifdef _WIN32
  79. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  80. #else
  81. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  82. #endif
  83. #ifdef LA_LINUX
  84. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  85. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  86. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  87. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  88. #endif
  89. #ifdef LA_LINUX
  90. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  91. int i;
  92. for (i = 0; i < num_classes; i++) {
  93. if (classes[i]->type == XIValuatorClass) {
  94. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  95. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  96. logPrint(" Range: %f - %f\n", v->min, v->max);
  97. logPrint(" Resolution: %d units/m\n", v->resolution);
  98. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  99. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  100. }
  101. }
  102. }
  103. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  104. XIDeviceInfo *info, *dev;
  105. int i, ndevices;
  106. dev = XIQueryDevice(display, deviceid, &ndevices);
  107. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  108. mask->deviceid = deviceid;
  109. mask->mask_len = XIMaskLen(XI_RawMotion);
  110. mask->mask=memAcquireSimple(mask->mask_len);
  111. memset(mask->mask, 0, mask->mask_len);
  112. XISetMask(mask->mask, XI_RawMotion);
  113. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  114. int FoundMax=0;
  115. for (i = 0; i < dev->num_classes; i++) {
  116. if (dev->classes[i]->type == XIValuatorClass) {
  117. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  118. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  119. }
  120. }
  121. if(!FoundMax){*max_pressure=65535;}
  122. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  123. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  124. XIFreeDeviceInfo(dev);
  125. }
  126. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  127. int axis=0;
  128. for (int i = 0; i < dev->num_classes; i++) {
  129. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  130. }
  131. return axis>=3;
  132. }
  133. #define LA_G_STYLUS(dev) \
  134. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  135. #define LA_G_ERASER \
  136. (!MAIN.WacomDeviceEraser)
  137. void la_ScanWacomDevices(Display *display, int deviceid){
  138. XIDeviceInfo *info, *dev;
  139. int ndevices;
  140. int i; char * word;
  141. int _event, _error;
  142. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  143. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  144. }
  145. info = XIQueryDevice(display, deviceid, &ndevices);
  146. for(i = 0; i < ndevices; i++) {
  147. dev = &info[i]; strToLower(dev->name);
  148. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  149. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  150. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  151. word = strtok (dev->name," ");
  152. while (1) {
  153. word = strtok (NULL, " "); if (!word) break;
  154. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  155. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  156. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  157. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  158. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  159. }
  160. }
  161. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  162. logPrintNew("Found wacom devices:\n");
  163. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  164. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  165. }else{
  166. logPrintNew("No wacom pen device connected.\n");
  167. }
  168. XIFreeDeviceInfo(info);
  169. }
  170. void laHideCursor(){
  171. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  172. }
  173. void laShowCursor(){
  174. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  175. }
  176. void la_XErrorHandler(Display *display, XErrorEvent *event){
  177. char buf[512];
  178. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  179. printf("X Error:\n%s\n",buf);
  180. }
  181. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  182. XSetWindowAttributes swa;
  183. XWindowAttributes wa;
  184. swa.event_mask =
  185. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  186. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  187. swa.colormap = MAIN.cmap;
  188. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  189. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  190. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  191. if(x>0||y>0){
  192. XSizeHints my_hints = {0};
  193. my_hints.flags = PPosition;
  194. my_hints.x = x; my_hints.y = y;
  195. XSetNormalHints(MAIN.dpy, win, &my_hints);
  196. }
  197. XStoreName(MAIN.dpy, win, title);
  198. #ifdef LA_USE_GLES
  199. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  200. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  201. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  202. EGLSurface* surf=egl_surf;
  203. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  204. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  205. tnsContextMakeCurrent((*r_glc),win,(*surf));
  206. #else
  207. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  208. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  209. printf("\n\tcannot create gl context\n\n"); exit(0);
  210. }
  211. tnsContextMakeCurrent((*r_glc),win,0);
  212. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  213. #endif
  214. XSetLocaleModifiers("");
  215. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  216. if(!MAIN.im){
  217. XSetLocaleModifiers("@im=local");
  218. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  219. }
  220. if(!MAIN.im){
  221. XSetLocaleModifiers("@im=none");
  222. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  223. }
  224. if(!MAIN.im){
  225. XSetLocaleModifiers("@im=");
  226. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  227. }
  228. if(!MAIN.im){
  229. logPrint("Can't open a input method.\n");
  230. }
  231. if(MAIN.im){
  232. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  233. XSetICFocus(MAIN.ic);
  234. }
  235. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  236. XSetClassHint(MAIN.dpy, win, &ch);
  237. #define _NET_WM_STATE_ADD 1
  238. if(w<0&&h<0){
  239. XEvent xev;
  240. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  241. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  242. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  243. memset(&xev, 0, sizeof(xev));
  244. xev.type = ClientMessage;
  245. xev.xclient.window = win;
  246. xev.xclient.message_type = wm_state;
  247. xev.xclient.format = 32;
  248. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  249. xev.xclient.data.l[1] = max_horz;
  250. xev.xclient.data.l[2] = max_vert;
  251. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  252. }
  253. return win;
  254. };
  255. void la_DestroySystemWindowX11(laWindow* w) {
  256. tnsContextMakeCurrent(0,0,0);
  257. tnsDeleteContext(w->glc);
  258. #ifdef LA_USE_GLES
  259. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  260. #endif
  261. XDestroyWindow(MAIN.dpy, w->win);
  262. };
  263. #endif //linux
  264. #ifdef _WIN32
  265. #include <msgdef.h>
  266. #include <wintab.h>
  267. #include <wintab_utils.h>
  268. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  269. #define PACKETMODE PK_BUTTONS
  270. #include <pktdef.h>
  271. void la_OpenWacomWinTab(HWND hwnd){
  272. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  273. static LOGCONTEXT glogContext = { 0 };
  274. HCTX hctx = NULL;
  275. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  276. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  277. glogContext.lcOptions |= CXO_SYSTEM;
  278. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  279. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  280. assert(glogContext.lcOptions & CXO_SYSTEM);
  281. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  282. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  283. glogContext.lcPktData = PACKETDATA;
  284. glogContext.lcPktMode = PACKETMODE;
  285. glogContext.lcMoveMask = PACKETDATA;
  286. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  290. assert(wWTInfoRetVal == sizeof(AXIS));
  291. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  292. if (wWTInfoRetVal) {
  293. assert(wWTInfoRetVal == sizeof(AXIS));
  294. MAIN.WinTabMaxHover = TabletZ.axMax;
  295. }
  296. AXIS tabletPressure = { 0 };
  297. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  298. //glogContext.lcInOrgX = 0;
  299. //glogContext.lcInOrgY = 0;
  300. //glogContext.lcInExtX = TabletX.axMax;
  301. //glogContext.lcInExtY = TabletY.axMax;
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  312. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  313. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  314. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  315. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  316. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  317. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  318. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  319. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  320. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  321. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  322. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  323. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  324. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  325. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  326. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  327. if (!hctx)return;
  328. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  329. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  330. }
  331. void laHideCursor() {
  332. if (!MAIN.CurrentWindow) return; //impl
  333. }
  334. void laShowCursor() {
  335. if (!MAIN.CurrentWindow) return; //impl
  336. }
  337. static PIXELFORMATDESCRIPTOR cpfd = {
  338. sizeof(PIXELFORMATDESCRIPTOR),1,
  339. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  340. PFD_TYPE_RGBA,
  341. 8,
  342. 0, 0, 0, 0, 0, 0,
  343. 0, 0, 0,
  344. 0, 0, 0, 0,
  345. 32,
  346. 8, 0,
  347. 0,
  348. 0, 0, 0, 0
  349. };
  350. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  351. int nBestMS = 0;
  352. int i;
  353. int iResults[9];
  354. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  355. WGL_ACCELERATION_ARB, // 1
  356. WGL_DRAW_TO_WINDOW_ARB, // 2
  357. WGL_DOUBLE_BUFFER_ARB, // 3
  358. WGL_PIXEL_TYPE_ARB, // 4
  359. WGL_DEPTH_BITS_ARB, // 5
  360. WGL_STENCIL_BITS_ARB, // 6
  361. WGL_SAMPLE_BUFFERS_ARB, // 7
  362. WGL_SAMPLES_ARB }; // 8
  363. // How many pixelformats are there?
  364. int nFormatCount[] = { 0 };
  365. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  366. if (!wglGetPixelFormatAttribivARB)
  367. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  368. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  369. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  370. for (i = 0; i < nFormatCount[0]; i++){
  371. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  372. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  373. if (iResults[3] == 1) // Double buffered
  374. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  375. if (iResults[5] >= 24) // Any Depth greater than 16
  376. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  377. }
  378. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  379. };
  380. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  381. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  382. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  383. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  384. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  385. 0 };
  386. HGLRC hglrc = 0;
  387. HDC hdc = 0;
  388. int a, b;
  389. hdc = GetDC(hwnd);
  390. la_SetupPxlFormat(hdc, &a, &b);
  391. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  392. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  393. tnsContextMakeCurrent(hglrc, hdc,0);
  394. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  395. wglSwapIntervalEXT(-1);
  396. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  397. };
  398. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  399. HINSTANCE* inst = &MAIN.hinstance;
  400. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  401. x, y, w, h, 0, 0, *inst, 0);
  402. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  403. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  404. return hwnd;
  405. };
  406. void la_DestroySystemWindowWin32(laWindow* w) {
  407. tnsContextMakeCurrent(0,0,0);
  408. tnsDeleteContext(w->glc);
  409. ReleaseDC(w->win, w->hdc);
  410. DestroyWindow(w->win);
  411. };
  412. #endif
  413. #ifdef LAGUI_ANDROID
  414. SYSWINDOW la_CreateWindowAndroid(){
  415. return 0;
  416. };
  417. void laShowCursor(){}
  418. void laHideCursor(){}
  419. #endif
  420. #ifdef LA_LINUX
  421. void la_HandlerSIGSEGV(int sig) {
  422. void *array[30];
  423. size_t sz;
  424. sz = backtrace(array, 30);
  425. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  426. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  427. exit(1);
  428. }
  429. #endif
  430. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  431. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  432. //#ifndef LAGUI_ANDROID
  433. // ignore non-significant error/warning codes
  434. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  435. logPrint("GL %d: %s\n", id, message);
  436. char* strsource="",*strtype="",*strseverity="";
  437. switch (source) {
  438. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  439. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  440. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  441. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  442. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  443. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  444. }
  445. switch (type) {
  446. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  447. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  448. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  449. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  450. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  451. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  452. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  453. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  454. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  455. }
  456. switch (severity) {
  457. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  458. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  459. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  460. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  461. }
  462. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  463. //#endif
  464. }
  465. void la_SetCurrentGLContextDebug(){
  466. //#ifndef LAGUI_ANDROID
  467. int force=MAIN.InitArgs.GLDebug;
  468. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  469. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  470. glDebugMessageCallback(la_glDebugOutput, 0);
  471. int sev=GL_DONT_CARE;
  472. if(!force){
  473. switch(MAIN.GLDebugLevel){
  474. default: sev=GL_DONT_CARE; break;
  475. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  476. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  477. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  478. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  479. }
  480. }
  481. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  482. //#endif
  483. }
  484. void la_NotifyGLDebugChanges(){
  485. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  486. }
  487. void la_SetupWindowGLStates(laWindow* w){
  488. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  489. if(w->GLDebugNeedsUpdate){
  490. tnsContextMakeWindowCurrent(w);
  491. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  492. }
  493. }
  494. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  495. SYSGLCONTEXT glc;
  496. #ifdef LA_LINUX
  497. void* egl_surf=0;
  498. #ifdef LA_USE_GLES
  499. egl_surf=&window->egl_surf;
  500. #endif
  501. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  502. #endif
  503. #ifdef _WIN32
  504. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  505. #endif
  506. #ifdef LAGUI_ANDROID
  507. la_CreateWindowAndroid();
  508. window->win = 1;
  509. window->glc = MAIN.glc;
  510. #else
  511. window->win = hwnd;
  512. window->glc = glc;
  513. #endif
  514. #ifdef _WIN32
  515. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  516. RECT rc; GetClientRect(window->win, &rc);
  517. window->CW = rc.right - rc.left;
  518. window->CH = rc.bottom - rc.top;
  519. #endif
  520. #ifdef LA_LINUX
  521. XWindowAttributes attr;
  522. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  523. window->CW =attr.width;
  524. window->CH = attr.height;
  525. #endif
  526. la_SetCurrentGLContextDebug();
  527. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  528. la_SetupWindowGLStates(window);
  529. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  530. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #else
  532. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  533. #endif
  534. window->OutputShowStripes=1; window->Redraw=1;
  535. window->GLDebugNeedsUpdate=1;
  536. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  537. return 1;
  538. };
  539. int la_DestroySystemWindow(laWindow* wnd){
  540. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  541. nvgDeleteGLES3(wnd->nvg);
  542. #else
  543. nvgDeleteGL3(wnd->nvg);
  544. #endif
  545. #ifdef LA_LINUX
  546. la_DestroySystemWindowX11(wnd);
  547. #endif
  548. #ifdef _WIN32
  549. la_DestroySystemWindowWin32(wnd);
  550. #endif
  551. }
  552. void la_DestroyWindow(laWindow *wnd){
  553. laLayout *l; laPanel *p; if (!wnd) return;
  554. tnsSwitchToCurrentWindowContext(wnd);
  555. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  556. la_StopAllOperators();
  557. strSafeDestroy(&wnd->Title);
  558. //la_PrintUserList(wnd);
  559. //printf("----\n");
  560. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  561. while (l = lstPopItem(&wnd->Layouts)){
  562. laDestroyBlocksRecursive(l->FirstBlock);
  563. //la_PrintUserList(l);
  564. //printf("%x %s\n", l, l->ID->Ptr);
  565. strSafeDestroy(&l->ID);
  566. memFree(l);
  567. //la_PrintUserList(wnd);
  568. //printf("----\n");
  569. }
  570. //printf("----\n%x\n",wnd);
  571. //la_PrintUserList(wnd);
  572. la_DestroySystemWindow(wnd);
  573. lstRemoveItem(&MAIN.Windows, wnd);
  574. memFree(wnd);
  575. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  576. }
  577. void laRenameWindow(laWindow* wnd, char* name){
  578. if((!wnd)||MAIN.IsReadingUDF) return;
  579. strSafeSet(&wnd->Title, name);
  580. if(!wnd->win) return;
  581. #ifdef LA_LINUX
  582. XStoreName(MAIN.dpy, wnd->win, name);
  583. #endif
  584. #ifdef _WIN32
  585. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  586. SetWindowTextW(wnd->win, name);
  587. #endif
  588. }
  589. #ifdef LA_LINUX
  590. const char* la_ConvertCursorID(int id){
  591. switch (id) {
  592. case LA_ARROW: return "arrow";
  593. case LA_CROSS: return "cross";
  594. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  595. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  596. case LA_MOVE: return "diamond_cross";
  597. case LA_HAND: return "hand1";
  598. case LA_CORNER: return "bottom_right_corner";
  599. }
  600. return "arrow";
  601. }
  602. #endif
  603. #ifdef _WIN32
  604. HCURSOR la_ConvertCursorID(int id){
  605. switch (id){
  606. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  607. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  608. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  609. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  610. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  611. case LA_HAND: return LoadCursor(0, IDC_HAND);
  612. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  613. }
  614. return LoadCursor(0, IDC_ARROW);;
  615. }
  616. #endif
  617. void la_InitThreadEnviornment(){
  618. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  619. }
  620. laLogEntry* logEnsure(int Create){
  621. if(!MAIN.Logs.pFirst || Create){
  622. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  623. lstAppendItem(&MAIN.Logs, le);
  624. }
  625. return MAIN.Logs.pLast;
  626. }
  627. void logPrintTV(int Continued, char* format, va_list v){
  628. if(!format || !format[0]) return;
  629. laLogEntry* le=logEnsure(Continued);
  630. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  631. strSafePrintV(&le->Content, format, v);
  632. #ifdef LAGUI_ANDROID
  633. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  634. #endif
  635. laNotifyUsers("la.logs");
  636. }
  637. void logPrintT(int Continued, char* format, ...){
  638. if(!format || !format[0]) return;
  639. laLogEntry* le=logEnsure(Continued);
  640. va_list aptr; va_start(aptr, format);
  641. strSafePrint(&le->Content, format, aptr);
  642. va_end(aptr);
  643. #ifdef LAGUI_ANDROID
  644. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  645. #endif
  646. laNotifyUsers("la.logs");
  647. }
  648. void logPrint(char* format, ...){
  649. va_list aptr; va_start(aptr, format);
  650. logPrintTV(0, format, aptr);
  651. va_end(aptr);
  652. }
  653. void logPrintNew(char* format, ...){
  654. logEnsure(1);
  655. va_list aptr; va_start(aptr, format);
  656. logPrintTV(0, format, aptr);
  657. va_end(aptr);
  658. }
  659. void logClear(){
  660. laLogEntry*l;
  661. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  662. laNotifyUsers("la.logs");
  663. }
  664. laSafeString** la_PerfEnsure(){
  665. MAIN.NextPerfCounter++;
  666. if(MAIN.NextPerfCounter>=32){ MAIN.NextPerfCounter=0; }
  667. return &MAIN.PerfLogs[MAIN.NextPerfCounter];
  668. }
  669. void la_PerfClear(){
  670. if(!MAIN.ShowPerf){ return; }
  671. MAIN.NextPerfCounter=0; MAIN.NextPerfGroup++; if(MAIN.NextPerfGroup>=32){ MAIN.NextPerfGroup=0; }
  672. memset(&MAIN.PerfCounter[MAIN.NextPerfGroup],0,32*sizeof(real));
  673. for(int i=0;i<32;i++){ strSafeDestroy(&MAIN.PerfLogs[i]); }
  674. }
  675. void laPerfRecordV(char* format, va_list v){
  676. if(!format || !format[0]) return;
  677. laSafeString** ss=la_PerfEnsure();
  678. strSafePrintV(ss, format, v);
  679. laTimeRecorder tm; laRecordTime(&tm);
  680. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  681. }
  682. void laPerfRecord(char* format, ...){
  683. if(!format || !format[0]) return;
  684. laSafeString** ss=la_PerfEnsure();
  685. va_list aptr; va_start(aptr, format);
  686. strSafePrintV(ss, format, aptr);
  687. va_end(aptr);
  688. laTimeRecorder tm; laRecordTime(&tm);
  689. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  690. }
  691. void la_PerfDraw(){
  692. tnsScale3d(0.75,0.75,0.75);
  693. int sy=0; laBoxedTheme* bt=_LA_THEME_LABEL; real* color=laThemeColor(bt,LA_BT_TEXT);
  694. int sl=LA_RH*4; char buf[16]; real totval=0; real vals[32];
  695. for(int i=0;i<32;i++){
  696. if(MAIN.PerfLogs[i]){
  697. real value = MAIN.PerfCounter[MAIN.NextPerfGroup][i]-(i>0?MAIN.PerfCounter[MAIN.NextPerfGroup][i-1]:0);
  698. sprintf(buf,"%0.2lf",value*1000); totval+=value; vals[i]=value;
  699. tnsDrawStringAuto(buf,color,0,10000,sy,LA_TEXT_SHADOW);
  700. tnsDrawStringAuto(SSTR(MAIN.PerfLogs[i]),color,sl,10000,sy,LA_TEXT_SHADOW);
  701. sy+=LA_RH;
  702. }
  703. }
  704. real SL=LA_RH*2,SR=LA_RH*3.5; sy=0; tnsColor4dv(color); tnsUseNoTexture();
  705. for(int i=0;i<32;i++){
  706. if(MAIN.PerfLogs[i]){
  707. real r=vals[i]/totval; real use_r=tnsInterpolate(SL,SR,r);
  708. tnsVertex2d(SL,sy); tnsVertex2d(SL,sy+LA_RH); tnsVertex2d(use_r,sy+LA_RH); tnsVertex2d(use_r,sy);
  709. tnsPackAs(GL_TRIANGLE_FAN);
  710. sy+=LA_RH;
  711. }
  712. }
  713. tnsFlush();
  714. }
  715. 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;
  716. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  717. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  718. }
  719. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  720. strSafeSet(&s->Name,Name);
  721. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  722. s->x=x;s->y=y;s->w=w;s->h=h;
  723. laNotifyUsers("la.user_preferences.screens");
  724. return s;
  725. }
  726. void la_RemoveScreen(laScreen*s){
  727. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  728. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  729. }
  730. void la_RemoveDuplicatedScreenConf(){
  731. laScreen* NextS;
  732. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  733. NextS = s->Item.pNext;
  734. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  735. 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; }
  736. }
  737. }
  738. }
  739. laScreen* laGetWindowScreen(laWindow* w){
  740. int l,r,u,b; int area=-1; laScreen* maxs=0;
  741. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  742. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  743. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  744. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  745. int a=w*h; if(a>area){ maxs = s; area = a; }
  746. }
  747. return maxs;
  748. }
  749. #ifdef LA_LINUX
  750. int la_GetDPI(Window* root_win){
  751. XRRScreenResources *screen;
  752. XRROutputInfo *info;
  753. XRRCrtcInfo *crtc_info;
  754. XRRCrtcInfo *crtc;
  755. int iscres, icrtc, dpi=0;
  756. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  757. for(iscres=0;iscres<screen->noutput;iscres++){
  758. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  759. if(!info->mm_width || !info->mm_height){ continue; }
  760. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  761. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  762. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  763. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  764. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  765. XRRFreeCrtcInfo(crtc);
  766. //if(info->connection==RR_Connected){
  767. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  768. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  769. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  770. // XRRFreeCrtcInfo(crtc_info);
  771. // }
  772. //}
  773. XRRFreeOutputInfo(info);
  774. }
  775. XRRFreeScreenResources(screen);
  776. return dpi;
  777. }
  778. #endif
  779. #ifdef _WIN32
  780. typedef struct laWin32MonitorEnumData {
  781. int id;
  782. }laWin32MonitorEnumData;
  783. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  784. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  785. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  786. return TRUE;
  787. }
  788. int la_GetDPI(HWND win){
  789. laWin32MonitorEnumData data = { 0 };
  790. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  791. return GetDpiForWindow(win);
  792. return 144;
  793. }
  794. #endif
  795. #define PROGRESSW (LA_RH*15)
  796. void laShowProgress(real p1, real p2){
  797. laSpinLock(&MAIN.OpsLock);
  798. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  799. if(!MAIN.Progress.Called){
  800. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  801. }
  802. laTimeRecorder tm; laRecordTime(&tm);
  803. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  804. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  805. if((!MAIN.Progress.Shown) && MAIN.Progress.Called){
  806. int ww=PROGRESSW+LA_RH*2;
  807. #ifdef LA_LINUX
  808. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  809. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  810. long a=LA_COLOR3_TO_HEX(bg);
  811. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  812. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  813. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  814. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  815. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  816. #endif
  817. #ifdef _WIN32
  818. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  819. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  820. ShowWindow(MAIN.Progress.w,SW_SHOW);
  821. #endif
  822. MAIN.Progress.Shown = 1;
  823. }
  824. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  825. #ifdef LA_LINUX
  826. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  827. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  828. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  829. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  830. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  831. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  832. #endif
  833. #ifdef _WIN32
  834. InvalidateRect(MAIN.Progress.w,0,1);
  835. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  836. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  837. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  838. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  839. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  840. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  841. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  842. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  843. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  844. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  845. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  846. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  847. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  848. EndPaint(MAIN.Progress.w,&ps);
  849. MSG msg;
  850. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  851. #endif
  852. #ifdef LAGUI_ANDROID
  853. laWindow* window=MAIN.CurrentWindow; int pw=window->CW;
  854. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  855. tnsViewportWithScissor(0,0,window->CW,window->CH);
  856. tnsOrtho(0,window->CW,-window->CH+LA_2RH,LA_2RH,-100,100);
  857. tnsClearColorv(bg); tnsClearAll(); tnsUseNoTexture(); tnsColor4dv(fg);
  858. tnsVertex2d(0,0);tnsVertex2d(pw*MAIN.Progress.p2,0);tnsVertex2d(pw*MAIN.Progress.p2,LA_RH);tnsVertex2d(0,LA_RH);
  859. tnsPackAs(GL_TRIANGLE_FAN);
  860. tnsVertex2d(0,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_2RH);tnsVertex2d(0,LA_2RH);
  861. tnsPackAs(GL_TRIANGLE_FAN);
  862. tnsFlush();
  863. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  864. eglMakeCurrent(MAIN.egl_dpy,0,0,0);
  865. #endif
  866. laSpinUnlock(&MAIN.OpsLock);
  867. }
  868. void laHideProgress(){
  869. laSpinLock(&MAIN.OpsLock);
  870. if(!MAIN.Progress.Shown){
  871. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  872. }
  873. laTimeRecorder tm; laRecordTime(&tm);
  874. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  875. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  876. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  877. #ifdef LA_LINUX
  878. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  879. #endif
  880. #ifdef _WIN32
  881. ShowWindow(MAIN.Progress.w,SW_HIDE);
  882. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  883. #endif
  884. #ifdef LAGUI_ANDROID
  885. laRedrawAllWindows();
  886. #endif
  887. laSpinUnlock(&MAIN.OpsLock);
  888. }
  889. //=======================
  890. void la_InitProgressWindow(){
  891. #ifdef LA_LINUX
  892. 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));
  893. if(!MAIN.Progress.w) return;
  894. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  895. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  896. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  897. if(MAIN.Progress.gc<0) return;
  898. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  899. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  900. XSync(MAIN.dpy,0);
  901. #endif
  902. #ifdef _WIN32
  903. WNDCLASSW wc;
  904. wc.hInstance = MAIN.hinstance;
  905. wc.lpfnWndProc = LA_ProgressWindowProc;
  906. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  907. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  908. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  909. wc.cbWndExtra = 0;
  910. wc.cbClsExtra = 0;
  911. wc.lpszClassName = L"_LAGUIPROGRESS";
  912. wc.lpszMenuName = NULL;
  913. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  914. if (!RegisterClassW(&wc)){ return; }
  915. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  916. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  917. #endif
  918. }
  919. void laSetFontFolderPath(char* absolute){
  920. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  921. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  922. }
  923. void laSetDefaultInitArguments(laInitArguments* ia){
  924. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  925. ia->UseColorManagement=0;
  926. ia->HasWorldObjects=0;
  927. ia->HasAction=0;
  928. ia->HasTextureInspector=0;
  929. ia->HasHistories=0;
  930. ia->HasTerminal=1;
  931. ia->HasAudio=0;
  932. }
  933. void laSetCompleteInitArguments(laInitArguments* ia){
  934. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  935. ia->UseColorManagement=1;
  936. ia->HasWorldObjects=1;
  937. ia->HasAction=1;
  938. ia->HasTextureInspector=1;
  939. ia->HasHistories=1;
  940. ia->HasTerminal=1;
  941. ia->HasAudio=1;
  942. }
  943. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  944. MAIN.GLMajor=MAIN.GLMinor=-1;
  945. char* arg = 0;
  946. printf("Initializing LaGUI...\n",argc);
  947. for(int i=0;i<argc;i++){
  948. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  949. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  950. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  951. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  952. }
  953. continue;
  954. }
  955. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  956. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  957. }
  958. }
  959. int laGetReadyWith(laInitArguments* ia){
  960. #ifdef LA_LINUX
  961. //signal(SIGSEGV,la_HandlerSIGSEGV);
  962. #endif
  963. laSpinInit(&MAIN.MemLock);
  964. laSpinInit(&MAIN.OpsLock);
  965. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  966. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  967. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  968. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  969. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  970. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  971. tnsInit();
  972. #ifdef LA_LINUX
  973. SYSWINDOW root, win;
  974. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  975. XSetWindowAttributes swa={0};
  976. XWindowAttributes wa={0};
  977. XEvent xev;
  978. logPrintNew("Initializing LaGUI...\n");
  979. setlocale(LC_CTYPE, "zh_CN.utf8");
  980. XSetErrorHandler(la_XErrorHandler);
  981. int i;
  982. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  983. printf("\n\tcannot connect to x server\n\n");
  984. exit(0);
  985. }
  986. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  987. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  988. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  989. #ifdef LA_USE_GLES
  990. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  991. #else
  992. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  993. #endif
  994. #ifdef LA_USE_GLES
  995. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  996. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  997. EGLint egl_major, egl_minor;
  998. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  999. printf("Error: eglInitialize() failed\n"); return -1;
  1000. }
  1001. int scrnum;
  1002. XSetWindowAttributes attr;
  1003. XVisualInfo *visInfo, visTemplate;
  1004. int num_visuals;
  1005. EGLContext ctx;
  1006. EGLint num_configs;
  1007. EGLint vid;
  1008. static const EGLint attribs[] = {
  1009. EGL_RED_SIZE, 8,
  1010. EGL_GREEN_SIZE, 8,
  1011. EGL_BLUE_SIZE, 8,
  1012. EGL_DEPTH_SIZE, 1,
  1013. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  1014. EGL_NONE
  1015. };
  1016. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  1017. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  1018. }
  1019. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  1020. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  1021. }
  1022. visTemplate.visualid = vid;
  1023. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  1024. if (!visInfo) {
  1025. printf("Error: couldn't get X visual\n"); exit(1);
  1026. }
  1027. MAIN.xvi=visInfo;
  1028. root = DefaultRootWindow(MAIN.dpy);
  1029. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1030. printf("\n\tcannot create colormap\n\n"); exit(1);
  1031. }
  1032. eglBindAPI(EGL_OPENGL_ES_API);
  1033. EGLint ctx_attribs[] = {
  1034. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  1035. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  1036. EGL_NONE
  1037. };
  1038. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  1039. if (!MAIN.glc) {
  1040. printf("Error: eglCreateContext failed\n"); exit(1);
  1041. }
  1042. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  1043. #else
  1044. int visual_attribs[] = {
  1045. GLX_X_RENDERABLE , True,
  1046. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  1047. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  1048. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  1049. GLX_RED_SIZE , 8,
  1050. GLX_GREEN_SIZE , 8,
  1051. GLX_BLUE_SIZE , 8,
  1052. GLX_ALPHA_SIZE , 8,
  1053. GLX_DEPTH_SIZE , 24,
  1054. //GLX_STENCIL_SIZE , 8,
  1055. GLX_DOUBLEBUFFER , True,
  1056. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  1057. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  1058. None
  1059. };
  1060. int fbcount = -1;
  1061. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  1062. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  1063. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  1064. MAIN.BestFBC = fbconfig[0];
  1065. int sample_buf,samples;
  1066. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  1067. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  1068. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1069. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1070. free(fbconfig);
  1071. root = DefaultRootWindow(MAIN.dpy);
  1072. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1073. printf("\n\tcannot create colormap\n\n"); exit(0);
  1074. }
  1075. swa.colormap = MAIN.cmap;
  1076. root = DefaultRootWindow(MAIN.dpy);
  1077. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1078. MAIN.win=win;
  1079. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1080. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1081. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1082. printf("\n\tcannot create gl context\n\n"); exit(0);
  1083. }
  1084. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1085. tnsContextMakeCurrent(MAIN.glc,win,0);
  1086. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1087. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1088. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1089. int err=0;
  1090. if((err=glewInit())!=GLEW_OK){
  1091. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1092. };
  1093. #endif /* gles or glx */
  1094. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1095. la_SetCurrentGLContextDebug();
  1096. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1097. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1098. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1099. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1100. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1101. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1102. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1103. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1104. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1105. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1106. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1107. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1108. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1109. #endif //linux
  1110. #ifdef _WIN32
  1111. logPrintNew("Initializing LaGUI...\n");
  1112. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1113. setlocale(LC_ALL, "zh_CN.utf8");
  1114. MAIN.hinstance = GetModuleHandle(NULL);
  1115. HINSTANCE* hInst = &MAIN.hinstance;
  1116. WNDCLASSEXW wt;
  1117. wt.cbSize = sizeof(WNDCLASSEXW);
  1118. wt.cbClsExtra = 0;
  1119. wt.cbWndExtra = 0;
  1120. wt.hbrBackground = 0;
  1121. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1122. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1123. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1124. wt.hInstance = *hInst;
  1125. wt.lpfnWndProc = LA_WindowProc;
  1126. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1127. wt.lpszMenuName = 0;
  1128. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1129. if (!RegisterClassExW(&wt)) return 0;
  1130. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1131. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1132. SetProcessDPIAware();
  1133. GLenum err;
  1134. PIXELFORMATDESCRIPTOR pfd;
  1135. HINSTANCE* hinst = &MAIN.hinstance;
  1136. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1137. "Temp Window For Accessing GLEW!",
  1138. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1139. 0, 0, *hinst, 0);
  1140. HDC hdc = GetDC(hwnd);
  1141. HGLRC hglrc = 0;
  1142. SetPixelFormat(hdc, 1, &cpfd);
  1143. hglrc = wglCreateContext(hdc);
  1144. tnsContextMakeCurrent(hglrc, hdc,0);
  1145. //MAIN.hdc = hdc;
  1146. // MAIN.tWND = hwnd;
  1147. MAIN.glc = hglrc;
  1148. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1149. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1150. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1151. if (err = glewInit()) {
  1152. printf("Init Glew Failed\n");
  1153. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1154. return 0;
  1155. }
  1156. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1157. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1158. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1159. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1160. #endif
  1161. la_GetWorkingDirectoryInternal();
  1162. MAIN.SavePreferenceOnExit=1;
  1163. MAIN.FontSize = 0.6;
  1164. int dpi=64;
  1165. #ifdef _WIN32
  1166. dpi=la_GetDPI(hwnd);
  1167. #endif
  1168. #ifdef LA_LINUX
  1169. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1170. #endif
  1171. #ifdef LAGUI_ANDROID
  1172. dpi = 72;
  1173. #endif
  1174. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1175. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1176. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1177. MAIN.UiScale=1;
  1178. MAIN.MarginSize = 1;
  1179. MAIN.ColorPickerGamma=1.5;
  1180. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1181. MAIN.ViewportHalftoneFactor=0.5;
  1182. MAIN.ViewportHalftoneSize=3.7;
  1183. tnsInitRenderKernel(64);
  1184. tnsInitBuiltinShaders();
  1185. tnsSetuptnsFontManager();
  1186. #define LOAD_FONT(font) \
  1187. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1188. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1189. LOAD_FONT("NotoEmoji-Regular.ttf");
  1190. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1191. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1192. //LOAD_FONT("NotoMusic-Regular.ttf");
  1193. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1194. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1195. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1196. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1197. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1198. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1199. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1200. MAIN.Audio=memAcquire(sizeof(laAudio));
  1201. #ifdef LA_WITH_LUAJIT
  1202. // starting lua
  1203. logPrint("Starting luajit...\n");
  1204. MAIN.L = lua_open();
  1205. la_luaLoadLibs(MAIN.L);
  1206. la_luaPrintStatus(MAIN.L);
  1207. tnsLuaInit(MAIN.L);
  1208. #endif
  1209. //interactions:
  1210. MAIN.TopFramerate = 60;
  1211. MAIN.ValuatorThreshold = 8;
  1212. MAIN.ScrollingSpeed = 3;
  1213. MAIN.AnimationSpeed = 0.4;
  1214. MAIN.PanelAnimationSpeed = 0.4;
  1215. MAIN.ZoomSpeed2D = 0.01;
  1216. MAIN.IdleTime = 0.75;
  1217. MAIN.TooltipCloseDistance = 30;
  1218. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1219. //display:
  1220. MAIN.FloatingAlpha = 0.35;
  1221. MAIN.SolidShadowLength = 20;
  1222. MAIN.WireColorSlices = 16;
  1223. MAIN.WireThickness = 5;
  1224. MAIN.WireSaggyness = 0.5;
  1225. MAIN.ManagerFilterInstances = 1;
  1226. #ifdef LAGUI_ANDROID
  1227. laAddResourceFolder("");
  1228. #else
  1229. laAddResourceFolder(".");
  1230. #endif
  1231. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1232. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1233. la_InitProgressWindow();
  1234. la_MakeTranslations_es_ES();
  1235. la_MakeTranslations_zh_hans();
  1236. //tns_RegisterResourcesForSoftwareRender();
  1237. la_RegisterDefaultSignals();
  1238. la_RegisterGeneralProps();
  1239. la_RegisterBuiltinTemplates();
  1240. la_RegisterMainThemes();
  1241. la_RegisterMainOperators();
  1242. la_RegisterMainUiTypes();
  1243. la_RegisterInternalProps();
  1244. la_RegisterAnimationResources();
  1245. la_RegisterWindowKeys();
  1246. if(MAIN.InitArgs.HasWorldObjects){
  1247. la_RegisterModellingOperators();
  1248. la_RegisterShapeOperators();
  1249. }
  1250. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1251. laFinalizeUiTemplates();
  1252. laFinalizeOperators();
  1253. la_RegisterControllerProps();
  1254. la_RefreshControllers();
  1255. la_RegisterBasicNodes();
  1256. tns_RegisterNodes();
  1257. la_InitThreadEnviornment();
  1258. laSetRootInstance(&MAIN);
  1259. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1260. laPushDifferences(0, 0);
  1261. la_MakeDummyManagedUDF();
  1262. la_RegenerateWireColors();
  1263. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1264. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1265. laSetProofingLut(DATA_LUT_PROOF_SRGB, 0);
  1266. laSetProofingLut(DATA_LUT_PROOF_CLAY, 1);
  1267. laSetProofingLut(DATA_LUT_PROOF_D65P3, 2);
  1268. logPrintNew("Initialization Completed\n");
  1269. MAIN.InitDone=1;
  1270. #ifdef LAGUI_ANDROID
  1271. MAIN.AutoSwitchColorSpace = 0;
  1272. MAIN.GotFilePermission = la_check_permission("android.permission.WRITE_EXTERNAL_STORAGE");
  1273. #else
  1274. MAIN.AutoSwitchColorSpace = 1;
  1275. #endif
  1276. return 1;
  1277. }
  1278. int laGetReady(){
  1279. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1280. return laGetReadyWith(&ia);
  1281. }
  1282. void la_DestroyUiType(laUiType* uit);
  1283. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1284. void laShutoff(int SavePrefereces){
  1285. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1286. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1287. // transLate(pc->Description);
  1288. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1289. // transLate(p->Description);
  1290. // }
  1291. //}
  1292. transDumpMissMatchRecord("TranslationDump.txt");
  1293. if(MAIN.Cleanup) MAIN.Cleanup();
  1294. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1295. strSafeDestroy(&MAIN.WorkingDirectory);
  1296. strSafeDestroy(&MAIN.example_string);
  1297. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1298. // (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. )
  1299. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1300. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1301. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1302. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1303. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1304. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1305. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1306. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1307. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1308. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1309. strSafeDestroy(&MAIN.CopyPending);
  1310. la_ClearUDFRegistryAndFolders();
  1311. laClearManagedUDF();
  1312. laClearSaveProp();
  1313. logClear();
  1314. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1315. #ifdef LA_LINUX
  1316. tnsContextMakeCurrent(0,0,0);
  1317. tnsDeleteContext(MAIN.glc);
  1318. #ifdef LA_USE_GLES
  1319. eglTerminate(MAIN.egl_dpy);
  1320. #endif
  1321. #endif
  1322. #ifdef _WIN32
  1323. tnsContextMakeCurrent(0,0,0);
  1324. tnsDeleteContext(MAIN.glc);
  1325. UnloadWintab();
  1326. #endif
  1327. tnsQuit();
  1328. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1329. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1330. strSafeDump();
  1331. hshFree(&MAIN.DBInstMemLeft);
  1332. memNoLonger();
  1333. laSpinDestroy(&MAIN.MemLock);
  1334. laSpinDestroy(&MAIN.OpsLock);
  1335. #ifdef LA_WITH_LUAJIT
  1336. lua_close(MAIN.L);
  1337. #endif
  1338. printf("LaGUI has cleaned up.\n");
  1339. }
  1340. int laRestoreFactorySettings(){
  1341. char path[1024];
  1342. #ifdef LAGUI_ANDROID
  1343. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1344. logPrintNew("%s", path);
  1345. if(!remove(path)){ return 1; }
  1346. sprintf(path,"%s/%s",MAIN.ExternalDataPath,"preferences.udf");
  1347. logPrintNew("%s", path);
  1348. if(!remove(path)){ return 1; }
  1349. return 0;
  1350. #else
  1351. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1352. #endif
  1353. if(remove(path)){ return 0; }
  1354. return 1;
  1355. }
  1356. void laSaveUserPreferences(){
  1357. char path[1024];
  1358. #ifdef LAGUI_ANDROID
  1359. sprintf(path,"%s","preferences.udf");
  1360. #else
  1361. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1362. #endif
  1363. laUDF* udf=laPrepareUDF(path);
  1364. laWriteProp(udf,"la.windows");
  1365. laWriteProp(udf,"la.user_preferences");
  1366. laWriteProp(udf,"la.input_mapping");
  1367. laWriteProp(udf,"la.controllers");
  1368. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1369. laWriteProp(udf,lip->p);
  1370. }
  1371. laPackUDF(udf,0,0);
  1372. }
  1373. void laEnsureUserPreferences(){
  1374. char path[1024];
  1375. #ifdef LAGUI_ANDROID
  1376. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1377. #else
  1378. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1379. #endif
  1380. laUDFRegistry* r=laFindUDFRegistry(path);
  1381. if(!r){ laSaveUserPreferences(); return; }
  1382. 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; }
  1383. laClearUDFRegistries();
  1384. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1385. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1386. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1387. laCloseUDF(udf);
  1388. la_RemoveDuplicatedScreenConf();
  1389. la_RemoveDuplicatedControllers();
  1390. laRefreshUDFRegistries();
  1391. //restore forced settings
  1392. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1393. }
  1394. void laAddExtraExtension(int FileType, ...){
  1395. va_list list; va_start(list,FileType);
  1396. char* ext;
  1397. while(ext=va_arg(list,char*)){ if(!ext) break;
  1398. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1399. et->FileType=FileType; et->Extension=ext;
  1400. lstAppendItem(&MAIN.ExtraExtensions, et);
  1401. logPrintNew("add ext %s",ext);
  1402. }
  1403. va_end(list);
  1404. }
  1405. void laAddExtraPreferencePath(const char* path){
  1406. if(!path) return;
  1407. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1408. }
  1409. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1410. if(!name || !Func) return;
  1411. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1412. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1413. }
  1414. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1415. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1416. }
  1417. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1418. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1419. }
  1420. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1421. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1422. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1423. }
  1424. void la_InputMappingGetKeyName(int key, int special, char* name){
  1425. char *_next=name; name[0]=0;
  1426. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1427. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1428. if(special&LA_KEY_ALT){ strcat(name,"Alt+"); }
  1429. switch(key){
  1430. case ' ': strcat(name,"Space"); break;
  1431. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1432. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1433. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1434. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1435. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1436. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1437. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1438. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1439. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1440. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1441. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1442. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1443. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1444. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1445. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1446. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1447. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1448. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1449. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1450. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1451. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1452. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1453. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1454. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1455. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1456. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1457. case LA_KEY_F1: strcat(name,"F1"); break;
  1458. case LA_KEY_F2: strcat(name,"F2"); break;
  1459. case LA_KEY_F3: strcat(name,"F3"); break;
  1460. case LA_KEY_F4: strcat(name,"F4"); break;
  1461. case LA_KEY_F5: strcat(name,"F5"); break;
  1462. case LA_KEY_F6: strcat(name,"F6"); break;
  1463. case LA_KEY_F7: strcat(name,"F7"); break;
  1464. case LA_KEY_F8: strcat(name,"F8"); break;
  1465. case LA_KEY_F9: strcat(name,"F9"); break;
  1466. case LA_KEY_F10: strcat(name,"F10"); break;
  1467. case LA_KEY_F11: strcat(name,"F11"); break;
  1468. case LA_KEY_F12: strcat(name,"F12"); break;
  1469. case LA_KEY_MOUSE_LEFT: strcat(name,"Mouse1"); break;
  1470. case LA_KEY_MOUSE_MIDDLE: strcat(name,"Mouse2"); break;
  1471. case LA_KEY_MOUSE_RIGHT: strcat(name,"Mouse3"); break;
  1472. case LA_KEY_MOUSE_SCROLL|LA_STATE_UP: strcat(name,"MouseWheelUp"); break;
  1473. case LA_KEY_MOUSE_SCROLL|LA_STATE_DOWN: strcat(name,"MouseWheelDown"); break;
  1474. default:
  1475. name = name+strlen(name); _next=name;
  1476. laToUTF8(key,name,&_next); *_next=0; break;
  1477. }
  1478. }
  1479. int la_InputMappingGetKeyFromName(char* name, int* special){
  1480. if(!name ||name[0]==0){ *special=0; return 0; }
  1481. *special=0;
  1482. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1483. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1484. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1485. char* p=name+strlen(name)-1;
  1486. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1487. while(*p=='+' || *p==' '){ p++; }
  1488. if(strSame(p,"Space")) return ' ';
  1489. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1490. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1491. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1492. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1493. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1494. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1495. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1496. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1497. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1498. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1499. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1500. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1501. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1502. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1503. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1504. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1505. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1506. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1507. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1508. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1509. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1510. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1511. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1512. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1513. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1514. if(strSame(p,"F1")) return LA_KEY_F1;
  1515. if(strSame(p,"F2")) return LA_KEY_F2;
  1516. if(strSame(p,"F3")) return LA_KEY_F3;
  1517. if(strSame(p,"F4")) return LA_KEY_F4;
  1518. if(strSame(p,"F5")) return LA_KEY_F5;
  1519. if(strSame(p,"F6")) return LA_KEY_F6;
  1520. if(strSame(p,"F7")) return LA_KEY_F7;
  1521. if(strSame(p,"F8")) return LA_KEY_F8;
  1522. if(strSame(p,"F9")) return LA_KEY_F9;
  1523. if(strSame(p,"F10")) return LA_KEY_F10;
  1524. if(strSame(p,"F11")) return LA_KEY_F11;
  1525. if(strSame(p,"F12")) return LA_KEY_F12;
  1526. if(strSame(p,"Mouse1")) return LA_KEY_MOUSE_LEFT;
  1527. if(strSame(p,"Mouse2")) return LA_KEY_MOUSE_MIDDLE;
  1528. if(strSame(p,"Mouse3")) return LA_KEY_MOUSE_RIGHT;
  1529. if(strSame(p,"MouseWheelUp")) return LA_KEY_MOUSE_SCROLL|LA_STATE_UP;
  1530. if(strSame(p,"MouseWheelDown")) return LA_KEY_MOUSE_SCROLL|LA_STATE_DOWN;
  1531. int adv;
  1532. return laToUnicode(p,&adv);
  1533. }
  1534. laCustomSignal* laFindSignal(char* Name){
  1535. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1536. return 0;
  1537. }
  1538. laCustomSignal* laFindSignalByID(int ID){
  1539. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1540. return 0;
  1541. }
  1542. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1543. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD || ime->DeviceType==LA_INPUT_DEVICE_MOUSE){ char* str=SSTR(ime->Key);
  1544. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1545. }
  1546. elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1547. char* signal = SSTR(ime->Signal);
  1548. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1549. }
  1550. laInputMapping* laNewInputMapping(char* Name){
  1551. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1552. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1553. strSafeSet(&im->Name,Name);
  1554. return im;
  1555. }
  1556. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1557. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1558. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1559. memAssignRef(e,&e->Parent,im);
  1560. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1561. laInputMappingUpdateSignal(e);
  1562. e->SpecialKeyBits=SpecialKeyBit;
  1563. char buf[64],*_next=buf;
  1564. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1565. return e;
  1566. }
  1567. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1568. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1569. return laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1570. }
  1571. laInputMappingEntry* laNewInputMappingMouseEntryP(laInputMapping* im, int MouseEventType, int SpecialKeyBit, int Signal){
  1572. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1573. char* Key="Mouse2";
  1574. if(MouseEventType&LA_KEY_MOUSE_LEFT){ Key="Mouse1"; }
  1575. elif(MouseEventType&LA_KEY_MOUSE_MIDDLE){ Key="Mouse2"; }
  1576. elif(MouseEventType&LA_KEY_MOUSE_RIGHT){ Key="Mouse3"; }
  1577. elif((MouseEventType&LA_KEY_MOUSE_SCROLL) && (MouseEventType&LA_STATE_UP)){ Key="MouseWheelUp"; }
  1578. elif((MouseEventType&LA_KEY_MOUSE_SCROLL) && (MouseEventType&LA_STATE_DOWN)){ Key="MouseWheelDown"; }
  1579. return laNewInputMappingEntry(im,LA_INPUT_DEVICE_MOUSE,0,Key,SpecialKeyBit,SSTR(cs->Name));
  1580. }
  1581. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1582. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1583. }
  1584. void laRemoveInputMapping(laInputMapping* im){
  1585. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1586. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1587. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1588. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1589. }
  1590. laInputMapping* laNewToolbox(char* Name){
  1591. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->Toolboxes,im);
  1592. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentToolbox,im);
  1593. strSafeSet(&im->Name,Name);
  1594. return im;
  1595. }
  1596. void laRemoveToolbox(laInputMapping* im){
  1597. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1598. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1599. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentToolbox,use);
  1600. lstRemoveItem(&MAIN.InputMapping->Toolboxes,im); strSafeDestroy(&im->Name); memFree(im);
  1601. }
  1602. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1603. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1604. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1605. return cs;
  1606. }
  1607. void laRemoveCustomSignal(laCustomSignal* cs){
  1608. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1609. }
  1610. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1611. void la_SendOperatorEvent(SYSWINDOW* hwnd, laOperatorType* at, int use_base, char* instructions);
  1612. void la_SendInputMappingSignalsAuto(SYSWINDOW* hwnd, laInputMappingEntry* ime){
  1613. if(ime->UseOperator){ la_SendOperatorEvent(hwnd, ime->OperatorType, ime->OperatorBase, SSTR(ime->OperatorArguments)); }
  1614. else{ la_SendSignalEvent(hwnd, ime->SignalValue); }
  1615. }
  1616. void la_SendSignalsFromEvent(laEvent* e){
  1617. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1618. if(!im){return;}
  1619. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1620. if(ime->Disabled) continue;
  1621. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1622. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1623. la_SendInputMappingSignalsAuto(e->window->win,ime);
  1624. }
  1625. }elif((e->type&LA_MOUSE_EVENT) && ime->DeviceType == LA_INPUT_DEVICE_MOUSE){
  1626. int matchkey; if(!(e->type&LA_KEY_MOUSE_SCROLL)){ matchkey = ((e->type&ime->KeyValue) && (e->type&LA_STATE_DOWN)); }
  1627. else{ matchkey = (e->type==(ime->KeyValue&LA_MOUSE_EVENT)); }
  1628. if(e->SpecialKeyBit == ime->SpecialKeyBits && matchkey){
  1629. la_SendInputMappingSignalsAuto(e->window->win,ime);
  1630. }
  1631. }
  1632. }
  1633. }
  1634. //MSG====================================================
  1635. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1636. if (wnd->win == hwnd) return 1;
  1637. else return 0;
  1638. };
  1639. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1640. if (p->SL){ int s=p->SL<0?0:p->SL;
  1641. if (p->TX != s) laRecalcPanel(p);
  1642. p->TX = s;
  1643. }
  1644. if (p->SR){ int s=p->SR<0?0:p->SR;
  1645. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1646. p->TW = CW - p->TX - s;
  1647. }
  1648. if (p->ST){ int s=p->ST<0?0:p->ST;
  1649. if (p->TY != s) laRecalcPanel(p);
  1650. p->TY = s;
  1651. }
  1652. if (p->SB){ int s=p->SB<0?0:p->SB;
  1653. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1654. p->TH = CH - p->TY - s;
  1655. }
  1656. }
  1657. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1658. laPanel *p = 0;
  1659. b->X = X;
  1660. b->Y = Y;
  1661. b->W = W;
  1662. b->H = H;
  1663. if (b->B1){
  1664. int SplitWidth;
  1665. if (b->Vertical){
  1666. SplitWidth = H * b->SplitRatio;
  1667. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1668. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1669. }else{
  1670. SplitWidth = W * b->SplitRatio;
  1671. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1672. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1673. }
  1674. }
  1675. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1676. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1677. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1678. }
  1679. if (p = b->CurrentPanel){
  1680. int TitleGap=b->Folded?0:LA_RH;
  1681. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1682. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1683. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1684. laRecalcPanel(p);
  1685. }
  1686. }
  1687. void la_UpdateUiPlacement(laWindow *w){
  1688. laLayout *l;
  1689. laPanel *p;
  1690. int CW = w->CW;
  1691. int CH = w->CH;
  1692. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1693. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1694. if(w->MaximizedUi && w->MaximizedUiPanel){
  1695. laRecalcPanel(w->MaximizedUiPanel);
  1696. }elif(w->MaximizedBlock){
  1697. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1698. }else{
  1699. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1700. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1701. }
  1702. }
  1703. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1704. if(p->IsMenuPanel){
  1705. p->TH=p->H=MenuHeight;
  1706. }
  1707. la_EnsurePanelSnapping(p, CW, CH);
  1708. laRecalcPanel(p);
  1709. }
  1710. }
  1711. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1712. laWindow *window;
  1713. #ifdef LAGUI_ANDROID
  1714. window = MAIN.Windows.pFirst; if (!window) return;
  1715. window->X=x;window->Y=y;window->W=w;window->H=h;
  1716. window->CW=w;window->CH=h;
  1717. la_UpdateUiPlacement(window); return;
  1718. #endif
  1719. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1720. if (!window) return;
  1721. #ifdef _WIN32
  1722. RECT rcc; GetClientRect(window->win, &rcc);
  1723. RECT rcw; GetWindowRect(window->win, &rcw);
  1724. window->CW = rcc.right - rcc.left;
  1725. window->CH = rcc.bottom - rcc.top;
  1726. window->W = rcw.right - rcw.left;
  1727. window->H = rcw.bottom - rcw.top;
  1728. window->X = rcw.left; window->Y = rcw.top;
  1729. if (MAIN.AutoSwitchColorSpace) {
  1730. laScreen* s = laGetWindowScreen(window);
  1731. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1732. }
  1733. #endif
  1734. #ifdef LA_LINUX
  1735. XWindowAttributes attr;
  1736. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1737. window->CW = w; window->CH = h;
  1738. window->W = w; window->H = h;
  1739. window->X = x; window->Y = y;
  1740. if(MAIN.AutoSwitchColorSpace){
  1741. laScreen* s = laGetWindowScreen(window);
  1742. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1743. }
  1744. #endif
  1745. la_UpdateUiPlacement(window);
  1746. }
  1747. int la_OnWindowDestroy(SYSWINDOW wnd){
  1748. laListHandle *hlst = &MAIN.Windows;
  1749. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1750. if (!w) return 0;
  1751. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1752. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1753. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1754. laShutoff(1);
  1755. return 1;
  1756. }
  1757. laListHandle h={0};laLayout*l=0;
  1758. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1759. la_DestroyWindow(w);
  1760. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1761. #ifdef LA_LINUX
  1762. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1763. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1764. #endif
  1765. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1766. }
  1767. return 0;
  1768. }
  1769. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1770. laListHandle *el = &wnd->EventList;
  1771. laEvent* last_e=el->pLast;
  1772. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1773. #ifdef LA_LINUX
  1774. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1775. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1776. #endif
  1777. #ifdef _WIN32
  1778. 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);
  1779. #endif
  1780. }
  1781. void laMappingRequestEval();
  1782. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1783. laListHandle *wl = &MAIN.Windows;
  1784. laWindow* wnd;
  1785. #ifdef LAGUI_ANDROID
  1786. wnd = MAIN.Windows.pFirst;
  1787. #else
  1788. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1789. #endif
  1790. if (!wnd){ memFree(e); return; }
  1791. laListHandle *el = &wnd->EventList;
  1792. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1793. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1794. e->window = wnd;
  1795. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1796. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1797. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1798. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1799. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1800. e->GoodPressure=MAIN.IsPen;
  1801. lstAppendItem(el, (laListItem *)e);
  1802. laMappingRequestEval();
  1803. };
  1804. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1805. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1806. la_SaveEvent(hwnd, e, 1);
  1807. };
  1808. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1809. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1810. e->type = LA_INPUT; e->Input=Input;
  1811. la_SaveEvent(hwnd, e, 1);
  1812. }
  1813. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1814. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1815. e->type = LA_EMPTY;
  1816. la_SaveEvent(hwnd, e, 1);
  1817. }
  1818. void laSendOperatorTriggerEvent(){
  1819. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1820. MAIN.ReTriggerOperators = 0;
  1821. }
  1822. int la_TranslateSpecialKey(int keysym){
  1823. #ifdef LA_LINUX
  1824. switch(keysym){
  1825. case XK_Return: return LA_KEY_ENTER;
  1826. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1827. case XK_Delete: return LA_KEY_DELETE;
  1828. case XK_Escape: return LA_KEY_ESCAPE;
  1829. case XK_Tab: return LA_KEY_TAB;
  1830. case XK_Left: return LA_KEY_ARRLEFT;
  1831. case XK_Right: return LA_KEY_ARRRIGHT;
  1832. case XK_Up: return LA_KEY_ARRUP;
  1833. case XK_Down: return LA_KEY_ARRDOWN;
  1834. case XK_Control_L: return LA_KEY_CTRL;
  1835. case XK_Control_R: return LA_KEY_CTRL;
  1836. case XK_Shift_L: return LA_KEY_SHIFT;
  1837. case XK_Shift_R: return LA_KEY_SHIFT;
  1838. case XK_Alt_L: return LA_KEY_ALT;
  1839. case XK_Alt_R: return LA_KEY_ALT;
  1840. case XK_KP_1: return LA_KEY_NUM1;
  1841. case XK_KP_2: return LA_KEY_NUM2;
  1842. case XK_KP_3: return LA_KEY_NUM3;
  1843. case XK_KP_4: return LA_KEY_NUM4;
  1844. case XK_KP_5: return LA_KEY_NUM5;
  1845. case XK_KP_6: return LA_KEY_NUM6;
  1846. case XK_KP_7: return LA_KEY_NUM7;
  1847. case XK_KP_8: return LA_KEY_NUM8;
  1848. case XK_KP_9: return LA_KEY_NUM9;
  1849. case XK_KP_0: return LA_KEY_NUM0;
  1850. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1851. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1852. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1853. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1854. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1855. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1856. default: return keysym;
  1857. }
  1858. #endif
  1859. #ifdef _WIN32
  1860. switch (keysym) {
  1861. case VK_RETURN: return LA_KEY_ENTER;
  1862. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1863. case VK_TAB: return LA_KEY_TAB;
  1864. case VK_LEFT: return LA_KEY_ARRLEFT;
  1865. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1866. case VK_UP: return LA_KEY_ARRUP;
  1867. case VK_DOWN: return LA_KEY_ARRDOWN;
  1868. case VK_CONTROL: return LA_KEY_CTRL;
  1869. case VK_SHIFT: return LA_KEY_SHIFT;
  1870. case VK_MENU: return LA_KEY_ALT;
  1871. case VK_F1: return LA_KEY_F1;
  1872. case VK_F2: return LA_KEY_F2;
  1873. case VK_F3: return LA_KEY_F3;
  1874. case VK_F4: return LA_KEY_F4;
  1875. case VK_F5: return LA_KEY_F5;
  1876. case VK_F6: return LA_KEY_F6;
  1877. case VK_F7: return LA_KEY_F7;
  1878. case VK_F8: return LA_KEY_F8;
  1879. case VK_F9: return LA_KEY_F9;
  1880. case VK_F10: return LA_KEY_F10;
  1881. case VK_F11: return LA_KEY_F11;
  1882. case VK_F12: return LA_KEY_F12;
  1883. case VK_NUMPAD0: return LA_KEY_NUM0;
  1884. case VK_NUMPAD1: return LA_KEY_NUM1;
  1885. case VK_NUMPAD2: return LA_KEY_NUM2;
  1886. case VK_NUMPAD3: return LA_KEY_NUM3;
  1887. case VK_NUMPAD4: return LA_KEY_NUM4;
  1888. case VK_NUMPAD5: return LA_KEY_NUM5;
  1889. case VK_NUMPAD6: return LA_KEY_NUM6;
  1890. case VK_NUMPAD7: return LA_KEY_NUM7;
  1891. case VK_NUMPAD8: return LA_KEY_NUM8;
  1892. case VK_NUMPAD9: return LA_KEY_NUM9;
  1893. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1894. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1895. case VK_ADD: return LA_KEY_NUMPLUS;
  1896. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1897. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1898. case VK_OEM_1: return ';';
  1899. case VK_OEM_2: return '/';
  1900. case VK_OEM_3: return '`';
  1901. case VK_OEM_4: return '[';
  1902. case VK_OEM_5: return '\\';
  1903. case VK_OEM_6: return ']';
  1904. case VK_OEM_7: return '\'';
  1905. case VK_OEM_COMMA: return ',';
  1906. case VK_OEM_PERIOD: return '.';
  1907. case VK_OEM_PLUS: return '+';
  1908. case VK_OEM_MINUS: return '-';
  1909. default: return keysym;
  1910. }
  1911. #endif
  1912. }
  1913. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1914. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1915. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1916. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1917. // la_SaveEvent(hwnd, e, 0);
  1918. //}
  1919. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1920. e->type = type; e->x = x; e->y = y;
  1921. la_SaveEvent(hwnd, e, 0);
  1922. MAIN.evLastX=x; MAIN.evLastY=y;
  1923. };
  1924. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1925. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1926. e->type = type;
  1927. la_SaveEvent(hwnd, e, 1);
  1928. };
  1929. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1930. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1931. e->type = LA_SIGNAL_EVENT;
  1932. e->key = signal;
  1933. la_SaveEvent(hwnd, e, 1);
  1934. };
  1935. void la_SendOperatorEvent(SYSWINDOW* hwnd, laOperatorType* at, int use_base, char* instructions){
  1936. if(!at){ return; }
  1937. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1938. e->type = LA_OPERATOR_EVENT;
  1939. e->Operator = at; e->OperatorBase = use_base; e->OperatorInstructions = instructions;
  1940. la_SaveEvent(hwnd, e, 1);
  1941. };
  1942. void laRetriggerOperators(){
  1943. MAIN.ReTriggerOperators = 1;
  1944. }
  1945. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1946. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1947. }
  1948. void laSetCleanupCallback(laCleanupF Cleanup){
  1949. MAIN.Cleanup=Cleanup;
  1950. }
  1951. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1952. MAIN.InputProcess=InputProcess;
  1953. }
  1954. //====================================================================================================
  1955. void la_DestroyTheme(laTheme* t){
  1956. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1957. strSafeDestroy(&t->Name);
  1958. strSafeDestroy(&t->Author);
  1959. }
  1960. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1961. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1962. strSafeSet(&t->Name, Name);
  1963. strSafeSet(&t->Author, AuthorName);
  1964. lstAppendItem(&MAIN.Themes, t);
  1965. MAIN.CurrentTheme = t;
  1966. return t;
  1967. }
  1968. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1969. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1970. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1971. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1972. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1973. strSafeSet(&bt->Name, Name);
  1974. bt->NormalY=NormalY;
  1975. bt->ActiveY=ActiveY;
  1976. bt->BorderY=BorderY;
  1977. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1978. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1979. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1980. bt->BackRef = BackRef;
  1981. lstAppendItem(&t->BoxedThemes, bt);
  1982. return bt;
  1983. }
  1984. laTheme *laGetTheme(const char *ThemeName){
  1985. laTheme *t = MAIN.Themes.pFirst;
  1986. for (t; t; t = t->Item.pNext){
  1987. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1988. }
  1989. return 0;
  1990. }
  1991. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1992. laTheme *t = MAIN.Themes.pFirst;
  1993. for (t; t; t = t->Item.pNext){
  1994. laBoxedTheme *bt;
  1995. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1996. bt = t->BoxedThemes.pFirst;
  1997. for (bt; bt; bt = bt->Item.pNext){
  1998. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1999. }
  2000. }
  2001. return 0;
  2002. }
  2003. real* laThemeColor(laBoxedTheme* bt, int which){
  2004. switch(which){
  2005. default:
  2006. case LA_BT_NORMAL: return bt->Normal;
  2007. case LA_UI_EDITING:
  2008. case LA_BT_ACTIVE: return bt->Active;
  2009. case LA_BT_BORDER: return bt->Border;
  2010. case LA_BT_TEXT: return bt->Text; break;
  2011. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  2012. case LA_BT_DISABLED: return bt->Inactive; break;
  2013. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  2014. }
  2015. return bt->Normal;
  2016. }
  2017. real* laAccentColor(int which){
  2018. switch(which){
  2019. default:
  2020. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  2021. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  2022. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  2023. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  2024. case LA_BT_FACE:
  2025. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  2026. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  2027. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  2028. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  2029. case LA_BT_SHADOW: return MAIN.CurrentTheme->ShadowColor;
  2030. }
  2031. return MAIN.CurrentTheme->SelectionColor;
  2032. }
  2033. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  2034. real hcy[3];
  2035. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  2036. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  2037. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  2038. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  2039. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  2040. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  2041. int *tm=&bt->LM,*tp=&bt->LP;
  2042. for(int i=0;i<4;i++){
  2043. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  2044. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  2045. }
  2046. }
  2047. void la_RefreshThemeColorSelf(laTheme* th){
  2048. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  2049. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  2050. real hcy[3], usehcy[3];
  2051. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  2052. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  2053. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  2054. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  2055. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  2056. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  2057. tnsVectorCopy3d(th->Color, th->ShadowColor); th->ShadowColor[3]=th->CursorAlpha;
  2058. }
  2059. void la_RefreshThemeColor(laTheme* th){
  2060. real hcy[3], usehcy[3], normalhcy[3];
  2061. tnsRGB2HCY(th->Color,hcy);
  2062. la_RefreshThemeColorSelf(th);
  2063. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  2064. la_RefreshBoxedThemeColor(bt);
  2065. (*bt->BackRef) = bt;
  2066. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  2067. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  2068. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  2069. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  2070. }
  2071. }
  2072. void laSetProofingLut(void* data, int which){
  2073. TNS_CLAMP(which,0,2);
  2074. MAIN.ProofingLUT[which]=data;
  2075. MAIN.LutNeedsRefreshing=1;
  2076. }
  2077. void la_RefreshProofingLut(){
  2078. if(!MAIN.CurrentWindow) return;
  2079. int table = MAIN.CurrentWindow->OutputColorSpace;
  2080. if(MAIN.CurrentLut != table+1){ MAIN.LutNeedsRefreshing=1; }
  2081. if(!MAIN.LutNeedsRefreshing) return;
  2082. tnsEnableShaderv(T->immShader);
  2083. tnsShader* s = T->immShader;
  2084. if(!MAIN.ProofingLUT[table] || !MAIN.CurrentWindow->OutputProofing){
  2085. return;
  2086. }
  2087. if(!MAIN.LutTexture) glGenTextures(1, &MAIN.LutTexture);
  2088. tnsActiveTexture(GL_TEXTURE3);
  2089. glBindTexture(GL_TEXTURE_3D, MAIN.LutTexture);
  2090. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  2091. glTexImage3D(GL_TEXTURE_3D,0,GL_RGB,LA_LUT_PRECISION,LA_LUT_PRECISION,LA_LUT_PRECISION,0,GL_RGB, GL_UNSIGNED_BYTE,MAIN.ProofingLUT[table]);
  2092. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  2093. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  2094. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  2095. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  2096. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  2097. //glBindTexture(GL_TEXTURE_3D,0);
  2098. tnsActiveTexture(GL_TEXTURE0);
  2099. MAIN.CurrentLut = table+1;
  2100. MAIN.LutNeedsRefreshing=0;
  2101. }
  2102. //I FUCKING HATE THIS STUPID FUNCTION
  2103. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  2104. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2105. laUiListDrawItem *last = uild->Items.pFirst;
  2106. int LimW=_R-_L;
  2107. int SL, SR, SU, SB;
  2108. int Target__B = Target->B;
  2109. int Target__R = Target->R;
  2110. uildi->Target = Target;
  2111. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  2112. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  2113. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  2114. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  2115. uildi->L = last ? Target->L - last->XP : Target->L;
  2116. uildi->R = last ? Target__R - last->XP : Target__R;
  2117. uildi->U = last ? Target->U - last->YP : Target->U;
  2118. uildi->B = last ? Target__B - last->YP : Target__B;
  2119. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  2120. uildi->L -= GlobalX;
  2121. uildi->R -= GlobalX;
  2122. uildi->U -= GlobalY;
  2123. uildi->B -= GlobalY;
  2124. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2125. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2126. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2127. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2128. uildi->DifX = SL - uildi->L;
  2129. uildi->DifY = SU - uildi->U;
  2130. uildi->L = SL;
  2131. uildi->R = SR+uildi->DifX;
  2132. uildi->U = SU;
  2133. uildi->B = SB;//+uildi->DifY;
  2134. if(uildi->R>_R){ uildi->R=_R; }
  2135. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  2136. //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);
  2137. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  2138. memFree(uildi);
  2139. return 0;
  2140. }
  2141. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  2142. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  2143. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  2144. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  2145. Target->U + Target->PanY + uildi->DifY+1,
  2146. -100, 100);
  2147. lstPushItem(&uild->Items, uildi);
  2148. return 1;
  2149. }
  2150. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  2151. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2152. laUiListDrawItem *last = uild->Items.pFirst;
  2153. int SL, SR, SU, SB;
  2154. if (B - U > LimH) B = U + LimH;
  2155. uildi->XP = last ? last->XP + PanX : PanX;
  2156. uildi->YP = last ? last->YP + PanY : PanY;
  2157. uildi->L = last ? L - last->XP : L;
  2158. uildi->R = last ? R - last->XP : R;
  2159. uildi->U = last ? U - last->YP : U;
  2160. uildi->B = last ? B - last->YP : B;
  2161. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2162. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2163. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2164. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2165. uildi->DifX = SL - uildi->L;
  2166. uildi->DifY = SU - uildi->U;
  2167. uildi->L = SL;
  2168. uildi->R = SR;
  2169. uildi->U = SU;
  2170. uildi->B = SB;
  2171. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2172. tnsOrtho(L + PanX + uildi->DifX,
  2173. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  2174. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2175. U + PanY + uildi->DifY,
  2176. -100, 100);
  2177. lstPushItem(&uild->Items, uildi);
  2178. }
  2179. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2180. int* savel, int* saver, int* saveu, int* saveb){
  2181. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2182. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2183. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2184. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2185. real x,y,w,h;
  2186. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2187. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2188. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2189. }
  2190. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2191. laUiListDrawItem *uildi = uild->Items.pFirst;
  2192. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2193. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2194. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2195. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2196. Target->U + Target->PanY + uildi->DifY -1,
  2197. -100, 100);
  2198. }
  2199. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2200. laUiListDrawItem *uildi = lstPopItem(uild);
  2201. laUiList *Target;
  2202. memFree(uildi);
  2203. uildi = uild->Items.pFirst;
  2204. if (!uildi || !uildi->Target){
  2205. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2206. return;
  2207. }
  2208. Target = uildi->Target;
  2209. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2210. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2211. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2212. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2213. Target->U + Target->PanY + uildi->DifY -1,
  2214. -100, 100);
  2215. }
  2216. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2217. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2218. uildi->L = L;
  2219. uildi->R = R;
  2220. uildi->U = U;
  2221. uildi->B = B;
  2222. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2223. tnsOrtho(L, R, B, U, -100, 100);
  2224. lstPushItem(&uild->Items, uildi);
  2225. }
  2226. void la_ClearUiListMatrix(laUiListDraw *uild){
  2227. laUiListDrawItem *uildi;
  2228. while (uildi = lstPopItem(uild)){
  2229. memFree(uildi);
  2230. }
  2231. }
  2232. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2233. 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);
  2234. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2235. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2236. int la_TestUiListMinumWidth(laUiList *uil);
  2237. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2238. if (ui){
  2239. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2240. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2241. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2242. p->X = p->TX; p->Y = p->TY;
  2243. p->W = p->TW;
  2244. }
  2245. }
  2246. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2247. int cw = MAIN.CurrentWindow->CW;
  2248. int ch = MAIN.CurrentWindow->CH;
  2249. int PH = p->TH;
  2250. laBoxedTheme*bt = *p->BT;
  2251. int uih=uil->B + bt->BM;
  2252. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2253. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2254. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2255. else p->TH = PH;
  2256. p->H = p->TH;
  2257. if(p->BoundUi){
  2258. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2259. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2260. if (p->X < 0) p->X = 0;
  2261. if (p->Y < 0) p->Y = 0;
  2262. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2263. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2264. }else{
  2265. if (p->Y < 0) p->Y = 0;
  2266. if ((!p->Block)&&(!p->IsMenuPanel)){
  2267. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2268. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2269. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2270. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2271. }
  2272. }
  2273. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE) && (!p->Block)){
  2274. if(p->W<LA_RH*3) p->W=LA_RH*3;
  2275. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2276. }
  2277. if (p->ST) p->TY = p->ST;
  2278. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2279. if (p->SB) p->TH = ch - p->TY - p->SB;
  2280. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2281. p->TX = p->X; p->TY = p->Y;
  2282. p->TW = p->W; p->TH = p->H;
  2283. }
  2284. void laPlacePanelForCreation(laPanel *p){
  2285. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2286. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2287. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2288. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2289. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2290. p->TX=p->X; p->TY=p->Y;
  2291. }
  2292. }
  2293. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2294. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2295. tnsViewportWithScissor(0, 0, p->W, p->H);
  2296. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2297. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2298. }
  2299. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2300. tnsDrawToScreen();
  2301. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2302. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2303. }
  2304. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2305. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2306. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2307. }
  2308. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2309. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2310. tnsClearAll();
  2311. }
  2312. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2313. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2314. real Color[] = {1, 1, 1, 1};
  2315. real L, W, U, H;
  2316. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2317. if(MAIN.EnableColorManagement){
  2318. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2319. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2320. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2321. }else{
  2322. tnsUniformOutputColorSpace(T->immShader,0);
  2323. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2324. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2325. }
  2326. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2327. tnsUseNoTexture();
  2328. if (!p->IsMenuPanel){
  2329. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2330. }
  2331. tnsFlush();
  2332. }
  2333. if(p->ParentOperator){
  2334. tnsUseNoTexture();
  2335. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2336. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2337. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2338. }
  2339. switch (p->AnimationMode){
  2340. case 0: /* and */
  2341. case LA_PANEL_ANIMATION_FLASH:
  2342. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2343. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2344. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2345. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2346. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2347. tnsPackAs(GL_TRIANGLES);
  2348. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2349. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2350. }
  2351. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2352. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2353. if((int)(p->AnimationRatio*6)%2){
  2354. tnsUseNoTexture();
  2355. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2356. 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);
  2357. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2358. }
  2359. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2360. }
  2361. break;
  2362. case LA_PANEL_ANIMATION_DROP_DOWN:
  2363. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2364. tnsDraw2DTextureArg(
  2365. p->OffScr->pColor[0],
  2366. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2367. Color,
  2368. 0, 0, 1 - p->AnimationRatio, 0);
  2369. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2370. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2371. break;
  2372. case LA_PANEL_ANIMATION_EXPAND:
  2373. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2374. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2375. W = tnsLinearItp(0, p->W, 0.4);
  2376. H = tnsLinearItp(0, p->H, 0.4);
  2377. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2378. tnsDraw2DTextureArg(
  2379. p->OffScr->pColor[0],
  2380. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2381. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2382. Color,
  2383. 0, 0, 0, 0);
  2384. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2385. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2386. break;
  2387. case LA_PANEL_ANIMATION_DISSOVE:
  2388. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2389. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2390. W = tnsLinearItp(0, p->W, 1.4);
  2391. H = tnsLinearItp(0, p->H, 1.4);
  2392. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2393. if (p->OffScr) tnsDraw2DTextureArg(
  2394. p->OffScr->pColor[0],
  2395. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2396. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2397. Color,
  2398. 0, 0, 0, 0);
  2399. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2400. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2401. break;
  2402. case LA_PANEL_ANIMATION_COLLAPSE:
  2403. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2404. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2405. W = tnsLinearItp(0, p->W, 0.4);
  2406. H = tnsLinearItp(0, p->H, 0.4);
  2407. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2408. if (p->OffScr) tnsDraw2DTextureArg(
  2409. p->OffScr->pColor[0],
  2410. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2411. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2412. Color,
  2413. 0, 0, 0, 0);
  2414. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2415. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2416. break;
  2417. case LA_PANEL_ANIMATION_MINIMIZE:
  2418. L = tnsLinearItp(0, p->X, 0.3);
  2419. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2420. W = tnsLinearItp(0, p->W, 0.4);
  2421. H = tnsLinearItp(0, p->H, 0.4);
  2422. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2423. tnsDraw2DTextureArg(
  2424. p->OffScr->pColor[0],
  2425. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2426. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2427. Color,
  2428. 0, 0, 0, 0);
  2429. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2430. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2431. break;
  2432. }
  2433. tnsFlush();
  2434. tnsUniformOutputColorSpace(T->immShader,0);
  2435. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2436. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2437. }
  2438. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2439. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2440. else{
  2441. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:LA_PANEL_DEFAULT_GL_FORMAT;
  2442. if(p->MenuRefer && (p->MenuRefer->Flags&LA_UI_FLAGS_MENU_FLOAT16)){ GLFormat=GL_RGBA16F; }
  2443. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2444. }
  2445. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2446. }
  2447. void la_PanelRefreshDetachedProp(laPanel *panel){
  2448. laProp *p;
  2449. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2450. la_StepPropPack(&p->DetachedPP);
  2451. la_UsePropPack(&p->DetachedPP, 0);
  2452. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2453. // laUseDataBlock(
  2454. // p->DetachedPP.LastPs->UseInstance,
  2455. // p->DetachedPP.LastPs->p,
  2456. // MAIN.PropMatcherContextP->FrameDistinguish,
  2457. // MAIN.PropMatcherContextP,
  2458. // la_PropPanelUserRemover, 0);
  2459. //}
  2460. }
  2461. }
  2462. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2463. real* color=laThemeColor(bt,LA_BT_BORDER);
  2464. tnsColor4d(0,0,0,Alpha);
  2465. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2466. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2467. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2468. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2469. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2470. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2471. tnsPackAs(GL_TRIANGLE_STRIP);
  2472. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2473. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2474. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2475. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2476. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2477. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2478. }
  2479. int la_AnimateUiListRecursive(laUiList *uil);
  2480. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2481. int DrawState_ = 0;
  2482. laUiListDraw uild = {0}; int orig_refresh=p->Refresh;
  2483. if (p->Show){
  2484. la_SetPropMathcerContext(p);
  2485. MAIN.CurrentPanel = p;
  2486. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2487. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2488. //}
  2489. if (p->Refresh & LA_TAG_RECALC){
  2490. laRecalcPanelImmediate(p);
  2491. }
  2492. if (!p->MenuRefer){
  2493. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2494. if (p->Refresh || !p->OffScr){
  2495. la_PanelDrawToOffsceen(p, &p->UI);
  2496. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2497. la_PanelBackgroundInit(p, bt);
  2498. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2499. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2500. tnsFlush();
  2501. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2502. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2503. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2504. DrawState_++;
  2505. }
  2506. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2507. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2508. if(p->UI.PanY<0){p->UI.PanY=0;}
  2509. DrawState_++;
  2510. }
  2511. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2512. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2513. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2514. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2515. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2516. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2517. if(p!=w->MaximizedUiPanel){
  2518. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2519. }else{
  2520. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2521. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2522. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2523. tnsFlush();
  2524. }
  2525. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2526. }
  2527. }else{
  2528. if (p->Refresh || !p->OffScr){
  2529. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2530. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2531. la_PanelBackgroundInit(p, bt);
  2532. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2533. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2534. tnsFlush();
  2535. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2536. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2537. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2538. DrawState_++;
  2539. }
  2540. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2541. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2542. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2543. DrawState_++;
  2544. }
  2545. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2546. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2547. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2548. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2549. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2550. }
  2551. }
  2552. tnsDrawToScreen();
  2553. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2554. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2555. la_PanelDrawToWindow(p, w);
  2556. }elif (p->AnimationMode){
  2557. la_PanelDrawToWindow(p, w);
  2558. }
  2559. laPerfRecord("%s [%s]",(orig_refresh&LA_TAG_RECALC)?"🌑":
  2560. ((orig_refresh&LA_TAG_REDRAW)?"🌓":
  2561. ((orig_refresh&LA_TAG_ANIMATION)?"🌔":"🌕")), SSTR(p->Title));
  2562. }
  2563. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2564. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2565. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2566. laPanel *pi, *PrevPI;
  2567. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2568. PrevPI = pi->Item.pPrev;
  2569. if (pi->AnimationMode && pi->LaterDestroy){
  2570. lstRemoveItem(&p->SubPanels, pi);
  2571. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2572. continue;
  2573. }
  2574. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2575. la_AttachedPanelDefDraw(w,pi,bt);
  2576. }
  2577. }
  2578. }
  2579. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2580. real PanelSquare[] = {
  2581. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2582. b->X + 2, CH - (b->Y + b->H - 4),
  2583. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2584. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2585. real Center[] = {
  2586. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2587. real DraggingPlot[] = {
  2588. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2589. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2590. PanelSquare[0],
  2591. PanelSquare[1],
  2592. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2593. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2594. PanelSquare[2],
  2595. PanelSquare[3],
  2596. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2597. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2598. PanelSquare[4],
  2599. PanelSquare[5],
  2600. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2601. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2602. PanelSquare[6],
  2603. PanelSquare[7],
  2604. };
  2605. real Square[] = {
  2606. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2607. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2608. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2609. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2610. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2611. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2612. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2613. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2614. };
  2615. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2616. LA_COLOR3(BorderColor4dV), 0,
  2617. LA_COLOR3(BorderColor4dV), 0.8,
  2618. LA_COLOR3(BorderColor4dV), 0,
  2619. LA_COLOR3(BorderColor4dV), 0.8,
  2620. LA_COLOR3(BorderColor4dV), 0,
  2621. LA_COLOR3(BorderColor4dV), 0.8,
  2622. LA_COLOR3(BorderColor4dV), 0,
  2623. };
  2624. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2625. LA_COLOR3(FillColor4dv), 0,
  2626. LA_COLOR3(FillColor4dv), 0.8,
  2627. LA_COLOR3(FillColor4dv), 0,
  2628. LA_COLOR3(FillColor4dv), 0.8,
  2629. LA_COLOR3(FillColor4dv), 0,
  2630. LA_COLOR3(FillColor4dv), 0.8,
  2631. LA_COLOR3(FillColor4dv), 0,
  2632. };
  2633. tnsUseNoTexture();
  2634. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2635. int Index[4];
  2636. tnsVertexArray2d(DraggingPlot, 8);
  2637. tnsColorArray4d(FillColor, 8);
  2638. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2639. case 0:
  2640. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2641. break;
  2642. case LA_BLOCK_DROP_LOCATION_L:
  2643. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2644. break;
  2645. case LA_BLOCK_DROP_LOCATION_R:
  2646. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2647. break;
  2648. case LA_BLOCK_DROP_LOCATION_U:
  2649. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2650. break;
  2651. case LA_BLOCK_DROP_LOCATION_B:
  2652. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2653. break;
  2654. }
  2655. //glDisable(GL_CULL_FACE);
  2656. tnsIndexArray(Index, 4);
  2657. tnsPackAs(GL_TRIANGLE_FAN);
  2658. //tnsFlush();
  2659. }
  2660. tnsVertexArray2d(DraggingPlot, 8);
  2661. tnsColorArray4d(PlotColor, 8);
  2662. tnsPackAs(GL_LINES);
  2663. tnsVertexArray2d(Square, 4);
  2664. tnsColor4dv(BorderColor4dV);
  2665. tnsPackAs(GL_LINE_LOOP);
  2666. glLineWidth(LA_SEAM_W);
  2667. tnsFlush();
  2668. glLineWidth(1);
  2669. }
  2670. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2671. laBoxedTheme *bt = _LA_THEME_TAB;
  2672. laPanel *p;
  2673. real v[] = {
  2674. b->X, CH - b->Y,
  2675. b->X + LA_SEAM_W, CH - b->Y ,
  2676. b->X, CH - (b->Y + b->H),
  2677. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2678. b->X + b->W, CH - (b->Y + b->H),
  2679. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2680. b->X + b->W, CH - b->Y,
  2681. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2682. real tv[8];
  2683. real ratio = 1.0001f;
  2684. int tw = 0;
  2685. int L = LA_RH+LA_SEAM_W;
  2686. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2687. if(MAIN.EnableColorManagement){
  2688. laWindow* w=MAIN.CurrentWindow;
  2689. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2690. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2691. }else{
  2692. tnsUniformOutputColorSpace(T->immShader,0);
  2693. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2694. }
  2695. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2696. tw += p->TitleWidth + LA_SEAM_W*2;
  2697. }
  2698. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2699. tnsUseNoTexture();
  2700. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2701. tnsVertexArray2d(v, 8);
  2702. tnsPackAs(GL_TRIANGLE_STRIP);
  2703. int TitleGap=b->Folded?0:LA_RH;
  2704. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2705. b->X + b->W, (CH - b->Y),
  2706. b->X + b->W, (CH - b->Y - TitleGap),
  2707. b->X, (CH - b->Y - TitleGap));
  2708. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2709. tnsVertexArray2d(tv, 4);
  2710. tnsPackAs(GL_TRIANGLE_FAN);
  2711. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2712. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2713. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2714. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2715. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2716. tnsVertexArray2d(tv, 4);
  2717. tnsPackAs(GL_TRIANGLE_FAN);
  2718. if(b->Folded){
  2719. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2720. 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);
  2721. 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);
  2722. tnsFlush(); return;
  2723. }
  2724. int LT=0,RT=0;
  2725. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2726. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2727. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2728. b->X + L+RT * ratio, (CH - b->Y),
  2729. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2730. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2731. if (p == b->CurrentPanel){
  2732. tnsUseNoTexture();
  2733. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2734. tnsVertexArray2d(tv, 4);
  2735. tnsPackAs(GL_TRIANGLE_FAN);
  2736. 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);
  2737. }else{
  2738. 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);
  2739. }
  2740. LT =RT;
  2741. }
  2742. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2743. tnsFlush();
  2744. tnsUniformOutputColorSpace(T->immShader,0);
  2745. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2746. }
  2747. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2748. laBoxedTheme *bt = _LA_THEME_PANEL;
  2749. real tv[8];
  2750. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2751. if(MAIN.EnableColorManagement){
  2752. laWindow* w=MAIN.CurrentWindow;
  2753. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2754. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2755. }else{
  2756. tnsUniformOutputColorSpace(T->immShader,0);
  2757. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2758. }
  2759. tnsUseNoTexture();
  2760. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2761. b->X + b->W, (CH - b->Y),
  2762. b->X + b->W, (CH - b->Y-b->H),
  2763. b->X, (CH - b->Y-b->H));
  2764. tnsVertexArray2d(tv, 4);
  2765. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2766. tnsPackAs(GL_TRIANGLE_FAN);
  2767. 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,
  2768. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2769. tnsFlush();
  2770. tnsUniformOutputColorSpace(T->immShader,0);
  2771. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2772. }
  2773. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2774. if (b->B1){
  2775. la_BlockDefDrawRecursive(w, bt, b->B1);
  2776. la_BlockDefDrawRecursive(w, bt, b->B2);
  2777. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2778. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2779. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2780. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2781. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2782. la_BlockDefDrawSelf(b, w->CH);
  2783. }else{
  2784. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2785. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2786. la_BlockDefDrawSelfEmpty(b, w->CH);
  2787. }
  2788. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2789. tnsUseNoTexture();
  2790. int at; real tv[8];
  2791. if (b->Vertical){
  2792. at = b->H * b->SplitRatio + b->Y;
  2793. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2794. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2795. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2796. b->X, (w->CH - at - LA_SEAM_W));
  2797. }else{
  2798. at = b->X + b->W * b->SplitRatio;
  2799. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2800. at- LA_SEAM_W, (w->CH - b->Y),
  2801. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2802. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2803. }
  2804. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2805. tnsVertexArray2d(tv, 4);
  2806. tnsPackAs(GL_TRIANGLE_FAN);
  2807. }
  2808. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2809. tnsFlush();
  2810. }
  2811. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2812. if (b->B1){
  2813. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2814. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2815. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2816. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2817. }
  2818. tnsFlush();
  2819. }
  2820. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2821. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2822. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2823. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2824. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2825. if(p->OffScr){
  2826. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2827. }
  2828. }
  2829. }
  2830. void la_ClearUnusedFramebuffers(laWindow* w){
  2831. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2832. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2833. }
  2834. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2835. if(p->Show || p->AnimationMode) continue;
  2836. if(p->OffScr){
  2837. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2838. }
  2839. }
  2840. }
  2841. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2842. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2843. laPanel *p, *NextP;
  2844. laLayout *l = w->CurrentLayout;
  2845. if (!w->CH || !w->CW) return;
  2846. la_ClearUnusedFramebuffers(w);
  2847. tnsDrawToScreen();
  2848. la_RefreshProofingLut();
  2849. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2850. glClearColor(0.2, 0.2, 0.3, 1.0);
  2851. tnsClearAll();
  2852. tnsUseNoTexture();
  2853. if (l->Draw) l->Draw(w, l);
  2854. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2855. glEnable(GL_BLEND);
  2856. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2857. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2858. laUiItem* ui;
  2859. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2860. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2861. la_SetPropMathcerContext(p);
  2862. if(p->Refresh){
  2863. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2864. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2865. if(MAIN.EnableColorManagement){
  2866. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2867. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2868. }else{
  2869. tnsUniformOutputColorSpace(T->immShader,0);
  2870. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2871. }
  2872. if(p->Refresh&LA_TAG_RECALC){
  2873. laRecalcPanelImmediate(p);
  2874. }
  2875. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2876. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2877. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2878. }
  2879. tnsDrawToScreen();
  2880. tnsResetViewMatrix();
  2881. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2882. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2883. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2884. tnsFlush();
  2885. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2886. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2887. tnsFlush();
  2888. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2889. }
  2890. }
  2891. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2892. la_AttachedPanelDefDraw(w,p,*p->BT);
  2893. }else{
  2894. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2895. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2896. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2897. }
  2898. for (p = w->Panels.pLast; p; p = NextP){
  2899. NextP = p->Item.pPrev;
  2900. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2901. if (p->AnimationMode && p->LaterDestroy){
  2902. lstRemoveItem(&w->Panels, p);
  2903. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2904. continue;
  2905. }
  2906. la_PanelDefDraw(w, p, *p->BT);
  2907. }
  2908. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2909. la_AttachedPanelDefDraw(w,p,*p->BT);
  2910. }
  2911. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2912. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2913. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2914. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2915. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2916. tnsFlush();
  2917. }
  2918. for (p = w->FadingPanels.pLast; p; p = NextP){
  2919. NextP = p->Item.pPrev;
  2920. if (!p->AnimationMode){
  2921. lstRemoveItem(&w->FadingPanels, p);
  2922. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2923. laDeferredDestroyPanel(p, 0);
  2924. }else
  2925. la_PanelDrawToWindow(p, w);
  2926. }
  2927. if(MAIN.ShowPerf){
  2928. la_PerfDraw();
  2929. }
  2930. }
  2931. int laStartWindow(laWindow *w){
  2932. #ifdef LA_LINUX
  2933. XMapWindow(MAIN.dpy,w->win);
  2934. tnsContextMakeWindowCurrent(w);
  2935. #endif
  2936. #ifdef _WIN32
  2937. ShowWindow(w->win, SW_SHOWNORMAL);
  2938. #endif
  2939. MAIN.CurrentWindow = w;
  2940. if(!w->CurrentLayout){
  2941. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2942. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2943. }
  2944. laRedrawCurrentWindow();
  2945. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2946. w->Shown = 1;
  2947. }
  2948. void la_AssignWindowPP(laWindow* w){
  2949. w->PP.EndInstance = w;
  2950. w->PP.LastPs = &w->FakePS;
  2951. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2952. w->PP.LastPs->UseInstance = w;
  2953. w->PP.LastPs->Type = U'.';
  2954. }
  2955. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2956. #ifdef LAGUI_ANDROID
  2957. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2958. #endif
  2959. laWindow *n = memAcquire(sizeof(laWindow));
  2960. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2961. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2962. #ifdef LAGUI_ANDROID
  2963. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2964. #endif
  2965. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2966. lstAppendItem(&MAIN.Windows, n);
  2967. MAIN.CurrentWindow = n;
  2968. la_AssignWindowPP(n);
  2969. laui_DefaultMenuBar(n);
  2970. return n;
  2971. }
  2972. void laSetWindowCursor(int id){
  2973. MAIN.CurrentCursor = id;
  2974. #ifdef LA_LINUX
  2975. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2976. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2977. #endif
  2978. #ifdef _WIN32
  2979. SetCursor(la_ConvertCursorID(id));
  2980. #endif
  2981. };
  2982. void la_AssignBlockPP(laBlock* b){
  2983. b->PP.EndInstance = b;
  2984. b->PP.LastPs = &b->FakePS;
  2985. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2986. b->PP.LastPs->UseInstance = b;
  2987. b->PP.LastPs->Type = U'.';
  2988. }
  2989. void laDestroyLayout(laWindow *w, laLayout* l){
  2990. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2991. laDestroyBlocksRecursive(l->FirstBlock);
  2992. strSafeDestroy(&l->ID);
  2993. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2994. lstRemoveItem(&w->Layouts,l); memFree(l);
  2995. }
  2996. laLayout *laDesignLayout(laWindow *w, char *Title){
  2997. laLayout *l = memAcquire(sizeof(laLayout));
  2998. l->FirstBlock = memAcquire(sizeof(laBlock));
  2999. la_AssignBlockPP(l->FirstBlock);
  3000. lstAppendItem(&w->Layouts, l);
  3001. strSafeSet(&l->ID, Title);
  3002. memAssignRef(w, &w->CurrentLayout, l);
  3003. laRenameWindow(w, Title);
  3004. return l;
  3005. }
  3006. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  3007. 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); }
  3008. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  3009. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  3010. laNotifyUsers("la.windows.maximized_block"); }
  3011. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  3012. laNotifyUsers("la.windows.maximized_block"); }
  3013. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  3014. laRestoreCanvasUI();
  3015. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  3016. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  3017. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  3018. UiParentPanel->Show=0;
  3019. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  3020. }
  3021. void laRestoreCanvasUI(){
  3022. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  3023. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  3024. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  3025. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  3026. }
  3027. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  3028. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  3029. }
  3030. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  3031. void laSplitBlockHorizon(laBlock *b, real Percentage){
  3032. laPanel *p;
  3033. b->SplitRatio = Percentage;
  3034. b->Vertical = 0;
  3035. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  3036. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  3037. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3038. p->Block = b->B1;
  3039. }
  3040. b->B1->Panels.pFirst = b->Panels.pFirst;
  3041. b->B1->Panels.pLast = b->Panels.pLast;
  3042. b->B1->CurrentPanel = b->CurrentPanel;
  3043. b->B1->parent = b->B2->parent=b;
  3044. b->Panels.pFirst = 0;
  3045. b->Panels.pLast = 0;
  3046. b->CurrentPanel = 0;
  3047. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3048. }
  3049. void laSplitBlockVertical(laBlock *b, real Percentage){
  3050. laPanel *p;
  3051. b->SplitRatio = Percentage;
  3052. b->Vertical = 1;
  3053. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  3054. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  3055. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3056. p->Block = b->B1;
  3057. }
  3058. b->B1->Panels.pFirst = b->Panels.pFirst;
  3059. b->B1->Panels.pLast = b->Panels.pLast;
  3060. b->B1->CurrentPanel = b->CurrentPanel;
  3061. b->B1->parent = b->B2->parent=b;
  3062. b->Panels.pFirst = 0;
  3063. b->Panels.pLast = 0;
  3064. b->CurrentPanel = 0;
  3065. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3066. }
  3067. void laCombineChildBlocks(laBlock *b){
  3068. laPanel *p; if(!b) return;
  3069. if (!b->B1->B1 && !b->B2->B1){
  3070. lstCombineLists(&b->Panels, &b->B1->Panels);
  3071. lstCombineLists(&b->Panels, &b->B2->Panels);
  3072. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3073. p->Block = b;
  3074. }
  3075. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  3076. memFree(b->B1);
  3077. memFree(b->B2);
  3078. b->B1 = 0;
  3079. b->B2 = 0;
  3080. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3081. }elif(!b->B1->B1){
  3082. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  3083. b->Vertical = b->B2->Vertical;
  3084. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  3085. p->Block = b1;
  3086. }
  3087. lstCombineLists(&b1->Panels, &b->B1->Panels);
  3088. memFree(b->B1); memFree(b->B2);
  3089. b->B1 = b1; b->B2 = b2;
  3090. b1->parent = b; b2->parent = b;
  3091. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3092. }elif(!b->B2->B1){
  3093. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  3094. b->Vertical = b->B1->Vertical;
  3095. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  3096. p->Block = b1;
  3097. }
  3098. lstCombineLists(&b1->Panels, &b->B2->Panels);
  3099. memFree(b->B1); memFree(b->B2);
  3100. b->B1 = b1; b->B2 = b2;
  3101. b1->parent = b; b2->parent = b;
  3102. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3103. }
  3104. }
  3105. laBlock *laBlock1(laBlock *b){
  3106. return b->B1;
  3107. }
  3108. laBlock *laBlock2(laBlock *b){
  3109. return b->B2;
  3110. }
  3111. laBlock *laSwapSubBlocks(laBlock *b){
  3112. laBlock *tB;
  3113. tB = b->B2;
  3114. b->B2 = b->B1;
  3115. b->B1 = tB;
  3116. b->SplitRatio = 1 - b->SplitRatio;
  3117. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3118. }
  3119. void laDestroyBlocksRecursive(laBlock *Root){
  3120. laPanel *p;
  3121. if (Root->B1){
  3122. laDestroyBlocksRecursive(Root->B1);
  3123. laDestroyBlocksRecursive(Root->B2);
  3124. }else{
  3125. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  3126. }
  3127. memFree(Root);
  3128. }
  3129. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  3130. if(!b->CurrentPanel ) return 0;
  3131. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  3132. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  3133. lstRemoveItem(&b->Panels, p);
  3134. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  3135. if(!p->TitleBar.UiItems.pFirst){
  3136. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  3137. }
  3138. p->Mode = LA_PANEL_FLOATING_TOP;
  3139. p->TY-=LA_RH; p->TH+=LA_RH;
  3140. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  3141. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  3142. p->Block = 0;
  3143. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  3144. laRecalcPanel(p);
  3145. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3146. p->BT = &_LA_THEME_FLOATING_PANEL;
  3147. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3148. laNotifyUsers("la.windows.panels");
  3149. return b->CurrentPanel;
  3150. }
  3151. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  3152. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  3153. lstRemoveItem(&from->Panels, p);
  3154. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3155. p->Mode = LA_PANEL_NORMAL;
  3156. p->Block=b;
  3157. b->CurrentPanel = p;
  3158. b->Folded = 0;
  3159. lstPushItem(&b->Panels, p);
  3160. laRecalcPanel(p);
  3161. p->BT = &_LA_THEME_PANEL;
  3162. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3163. tnsFlush();
  3164. laNotifyUsers("la.windows.panels");
  3165. }
  3166. void laPopPanel(laPanel *p){
  3167. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  3168. lstRemoveItem(&p->Parent->SubPanels, p);
  3169. lstPushItem(&p->Parent->SubPanels, p);
  3170. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3171. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3172. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3173. laNotifyUsers("la.windows.panels");
  3174. }
  3175. }
  3176. void la_EnsurePanelExtras(laPanel *p){
  3177. laUiTemplate* uit=p->PanelTemplate;
  3178. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  3179. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  3180. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  3181. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  3182. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  3183. p->PropLinkFakeProp->Base.Offset = 0;
  3184. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  3185. p->PropLinkPP.EndInstance = p;
  3186. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3187. p->PropLinkPP.LastPs->Type = U'.';
  3188. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3189. }
  3190. laPanel* la_GivePanelNode(){
  3191. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3192. return memAcquire(sizeof(laPanel));
  3193. }
  3194. void la_ReturnPanelNode(laPanel* p){
  3195. memset(p,0,sizeof(laPanel));
  3196. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3197. lstAppendItem(&MAIN.WastedPanels, p);
  3198. }
  3199. 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){
  3200. laPanel *p = la_GivePanelNode();
  3201. int CW = MAIN.CurrentWindow->CW;
  3202. int CH = MAIN.CurrentWindow->CH;
  3203. p->PanelTemplate = uit;
  3204. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3205. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3206. if (!MaxW) MaxW = 10000;
  3207. if (!MaxH) MaxH = 10000;
  3208. if (W > MaxW) W = MaxW;
  3209. if (H > MaxH) H = MaxH;
  3210. if (W < MinW) W = MinW;
  3211. if (H < MinH) H = MinH;
  3212. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3213. p->X = p->TX = (X < 0 ? 0 : X);
  3214. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3215. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3216. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3217. p->MaxW = MaxW; p->MaxH = MaxH;
  3218. p->MinW = MinW; p->MinH = MinH;
  3219. p->SL = SnapL; p->ST = SnapT;
  3220. p->SR = SnapR; p->SB = SnapB;
  3221. if (p->SR) p->X = CW - p->W - p->SR;
  3222. if (p->SB) p->Y = CH - p->H - p->SB;
  3223. la_EnsurePanelSnapping(p, CW, CH);
  3224. p->Show = 1;
  3225. p->PP.EndInstance = p;
  3226. p->PP.LastPs = &p->FakePS;
  3227. p->PP.LastPs->p = _LA_PROP_PANEL;
  3228. p->PP.LastPs->UseInstance = p;
  3229. p->PP.LastPs->Type = U'.';
  3230. la_EnsurePanelExtras(p);
  3231. laRecalcPanel(p);
  3232. p->FrameDistinguish = 100; //greater than 1 is ok
  3233. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3234. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3235. return p;
  3236. }
  3237. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3238. if(!uit) return 0;
  3239. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3240. strSafeSet(&p->Title, uit->Title->Ptr);
  3241. p->PanelTemplate = uit;
  3242. p->Show = 1;
  3243. p->PP.EndInstance = p;
  3244. p->PP.LastPs = &p->FakePS;
  3245. p->PP.LastPs->p = _LA_PROP_PANEL;
  3246. p->PP.LastPs->UseInstance = p;
  3247. p->PP.LastPs->Type = U'.';
  3248. la_EnsurePanelExtras(p);
  3249. laRecalcPanel(p);
  3250. p->FrameDistinguish = 100; //greater than 1 is ok
  3251. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3252. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3253. p->Block = b; b->CurrentPanel = p;
  3254. if(uit->PropFunc){ uit->PropFunc(p); }
  3255. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3256. laNotifyUsers("la.windows.panels");
  3257. return p;
  3258. }
  3259. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3260. laUiTemplate* uit=laFindUiTemplate(template_id);
  3261. return laCreatePanelT(b, uit);
  3262. }
  3263. 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){
  3264. laUiTemplate* uit=0;
  3265. if(template_id) uit=laFindUiTemplate(template_id);
  3266. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3267. p->Mode = LA_PANEL_FLOATING_TOP;
  3268. laPlacePanelForCreation(p);
  3269. if(uit){
  3270. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3271. }
  3272. if (w) lstPushItem(&w->Panels, p);
  3273. return p;
  3274. }
  3275. void laShowPanel(laPanel *p){
  3276. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3277. }
  3278. void laShowPanelWithDropDownEffect(laPanel *p){
  3279. laShowPanel(p);
  3280. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3281. p->AnimationRatio = 0;
  3282. }
  3283. void laShowPanelWithExpandEffect(laPanel *p){
  3284. laShowPanel(p);
  3285. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3286. p->AnimationRatio = 0;
  3287. }
  3288. void laHidePanel(laPanel *p){
  3289. if (!p->Mode) return;
  3290. p->Show = 0;
  3291. laNotifyUsers("la.windows.panels_hidden");
  3292. }
  3293. void laHidePanelWithDissoveEffect(laPanel *p){
  3294. if (!p->Mode) return;
  3295. laHidePanel(p);
  3296. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3297. p->AnimationRatio = 1;
  3298. }
  3299. void laHidePanelWithCollapseEffect(laPanel *p){
  3300. if (!p->Mode) return;
  3301. laHidePanel(p);
  3302. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3303. p->AnimationRatio = 1;
  3304. }
  3305. void laHidePanelWithMinimizeEffect(laPanel *p){
  3306. if (!p->Mode) return;
  3307. laHidePanel(p);
  3308. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3309. p->AnimationRatio = 1;
  3310. }
  3311. void laActivatePanel(char* TemplateID, int x, int y){
  3312. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3313. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3314. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3315. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3316. }
  3317. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3318. p->UI.PanX += DeltaX;
  3319. p->UI.PanY += DeltaY;
  3320. }
  3321. int laPanUiListFree(laUiList *uil, int X, int Y){
  3322. uil->PanX+=X; uil->PanY+=Y;
  3323. }
  3324. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3325. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3326. if(Y){X+=Y;Y=0;}
  3327. }
  3328. if (Y > 0){
  3329. if (uil->B - uil->PanY <= B) return 0;
  3330. else{
  3331. uil->PanY += Y;
  3332. if (uil->B - uil->PanY <= B){
  3333. uil->PanY = uil->B - B;
  3334. return 1;
  3335. }
  3336. }
  3337. }
  3338. if (Y < 0){
  3339. if (uil->U - uil->PanY >= U) return 0;
  3340. else{
  3341. uil->PanY += Y;
  3342. if (uil->U - uil->PanY >= U){
  3343. uil->PanY = uil->U - U;
  3344. return 1;
  3345. }
  3346. }
  3347. }
  3348. if(uil->AllowScale){
  3349. laPanUiListFree(uil, X, 0);
  3350. }else{
  3351. if (X > 0){
  3352. if (uil->R - uil->PanX <= R) return 0;
  3353. else{
  3354. uil->PanX += X;
  3355. if (uil->R - uil->PanX <= R){
  3356. uil->PanX = uil->R - R;
  3357. return 1;
  3358. }
  3359. }
  3360. }
  3361. if (X < 0){
  3362. if (uil->L - uil->PanX >= L) return 0;
  3363. else{
  3364. uil->PanX += X;
  3365. if (uil->L - uil->PanX >= L){
  3366. uil->PanX = uil->L - L;
  3367. return 1;
  3368. }
  3369. }
  3370. }
  3371. }
  3372. return 1;
  3373. }
  3374. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3375. int ret=1;
  3376. if(!uil->AllowScale){ return 0; }
  3377. real NewScale=uil->Scale*factor;
  3378. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3379. if(NewScale>5) {NewScale=5; ret=0;}
  3380. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3381. factor=NewScale/uil->Scale;
  3382. uil->Scale=NewScale;
  3383. real mx=(L+R)/2,my=(U+B)/2;
  3384. real dx= (mx+uil->PanX)*factor;
  3385. real dy= (my+uil->PanY)*factor;
  3386. uil->PanX=dx-mx;
  3387. uil->PanY=dy-my;
  3388. MAIN.CurrentPanel->FrameDistinguish=100;
  3389. return ret;
  3390. }
  3391. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3392. if(uil->AllowScale) return 0;
  3393. return laPanUiList(uil,X,Y,L,R,U,B);
  3394. }
  3395. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3396. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3397. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3398. strSafeSet(&p->Title, Title);
  3399. if (Define){
  3400. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3401. }
  3402. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3403. p->BT= &_LA_THEME_FLOATING_PANEL;
  3404. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3405. p->BoundUi = 1;
  3406. return p;
  3407. }
  3408. 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,
  3409. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3410. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3411. strSafeSet(&p->Title, Title);
  3412. if (Define){
  3413. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3414. }
  3415. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3416. p->BT= &_LA_THEME_FLOATING_PANEL;
  3417. p->Mode = LA_PANEL_FLOATING_TOP;
  3418. p->BoundUi = 1;
  3419. return p;
  3420. }
  3421. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3422. laPanel *ip;
  3423. tnsDelete2DOffscreen(p->OffScr);
  3424. p->OffScr = 0;
  3425. strSafeDestroy(&p->Title);
  3426. if (!p->AnimationMode){
  3427. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3428. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3429. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3430. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3431. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3432. }else if (p->Block){
  3433. lstRemoveItem(&p->Block->Panels, p);
  3434. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3435. }
  3436. laNotifyUsers("la.windows.panels");
  3437. }
  3438. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3439. //lstRemoveItem(&p->SubPanels, ip);
  3440. laDestroySinglePanel(ip, immediate);
  3441. laNotifyUsers("la.windows.panels");
  3442. }
  3443. la_ClearDetachedProp(p);
  3444. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3445. la_ReturnPanelNode(p);
  3446. }
  3447. void laDestroySinglePanel(laPanel *p, int immediate){
  3448. la_SetPropMathcerContext(p);
  3449. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3450. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3451. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3452. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3453. }
  3454. }
  3455. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3456. la_DestroyUiList(&p->UI, 1, 1, 0);
  3457. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3458. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3459. if (p->Mode){
  3460. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3461. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3462. }
  3463. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3464. if (la_UiStillInService(p)){
  3465. la_StopUiOperatorService(p);
  3466. }
  3467. if ((!p->AnimationMode) || immediate){
  3468. laDeferredDestroyPanel(p, immediate);
  3469. }else{
  3470. p->LaterDestroy = 1;
  3471. }
  3472. }
  3473. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3474. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3475. int MinW,MinWt=0;
  3476. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3477. int CW = MAIN.CurrentWindow->CW;
  3478. if(p->SL && p->SR){return 0;}
  3479. la_SetPropMathcerContext(p);
  3480. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3481. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3482. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3483. MinW = la_TestUiListMinumWidth(uil);
  3484. if (MinW<MinWt){MinW=MinWt;}
  3485. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3486. if (MinW > 20){
  3487. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3488. }
  3489. la_PanelValidateWidth(p,uil);
  3490. laEnsurePanelInBound(p,uil);
  3491. if(p->TW>CW){ p->TW=CW; }
  3492. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3493. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3494. laRedrawPanel(p);
  3495. return 1;
  3496. }
  3497. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3498. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3499. laOperator *ai = a;
  3500. laPanel *p;
  3501. int GX, GY, GW, t = 0;
  3502. int b;
  3503. laUiDefineFunc def = ReplaceUiDefine;
  3504. int MinW;
  3505. if (!def){ def=laui_DefaultPropDetails; }
  3506. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3507. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3508. laEnclosePanelContent(p, &p->UI);
  3509. laSetOperatorLocalizer(p);
  3510. p->CloseWhenMovedOut=1;
  3511. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3512. //laShowPanelWithDropDownEffect(p);
  3513. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3514. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3515. return p;
  3516. }
  3517. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3518. laPanel *p;
  3519. int GX, GY, GW, t = 0;
  3520. int b;
  3521. laUiDefineFunc def = ReplaceUiDefine;
  3522. int MinW;
  3523. if (!def) return 0;
  3524. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3525. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3526. p->Mode = LA_PANEL_FLOATING_TOP;
  3527. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3528. laEnclosePanelContent(p, &p->UI);
  3529. if(MAIN.CurrentWindow->Operators.pFirst){
  3530. laSetOperatorLocalizer(MAIN.PendingSplash);
  3531. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3532. MAIN.PendingSplash=0;
  3533. }
  3534. //laShowPanelWithExpandEffect(p);
  3535. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3536. return p;
  3537. }
  3538. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3539. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3540. laOperator *ai = a;
  3541. laPanel *p; laPropContainer* sub;
  3542. int GX, GY, GW, t = 0;
  3543. int b;
  3544. laUiDefineFunc def = ReplaceUiDefine;
  3545. int MinW;
  3546. if (!def){
  3547. if (This && This->LastPs->p){
  3548. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3549. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3550. }
  3551. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3552. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3553. }
  3554. GX = L; GY = B;
  3555. GW = (R - L) > MaxW ? MaxW : (R - L);
  3556. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3557. laEnclosePanelContent(p, &p->UI);
  3558. laSetOperatorLocalizer(p);
  3559. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3560. laShowPanelWithDropDownEffect(p);
  3561. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3562. if(Attachment){
  3563. p->Parent = Attachment;
  3564. lstAppendItem(&Attachment->SubPanels, p);
  3565. }
  3566. return p;
  3567. }
  3568. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3569. laPanel *p;
  3570. int t = 0;
  3571. int b;
  3572. //laLocalToWindow(0, Attachment, &L, &t);
  3573. //laLocalToWindow(0, Attachment, &R, &U);
  3574. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3575. laSetOperatorLocalizer(p);
  3576. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3577. laShowPanelWithDropDownEffect(p);
  3578. p->Parent = Attachment;
  3579. lstPushItem(&Attachment->SubPanels, p);
  3580. return p;
  3581. }
  3582. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3583. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3584. laOperator *ai = a;
  3585. laPanel *p;
  3586. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3587. int GX, GY, GW, t = 0;
  3588. int b;
  3589. int MinW;
  3590. //laLocalToWindow(0,Attachment, &L, &t);
  3591. //laLocalToWindow(0,Attachment, &R, &B);
  3592. GX = L;
  3593. GY = B;
  3594. GW = (R - L) > MaxW ? MaxW : (R - L);
  3595. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3596. p->MenuRefer = MenuRefer;
  3597. laEnclosePanelContent(p, MenuRefer);
  3598. laSetOperatorLocalizer(p);
  3599. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3600. laShowPanelWithDropDownEffect(p);
  3601. p->Parent = Attachment;
  3602. lstPushItem(&Attachment->SubPanels, p);
  3603. return p;
  3604. }
  3605. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3606. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3607. laOperator *ai = a;
  3608. laPanel *p;
  3609. int GX, GY, GW, t = 0;
  3610. int b;
  3611. GX = L;
  3612. GY = B;
  3613. GW = MaxW;
  3614. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3615. p->MenuRefer = &p->UI;
  3616. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3617. laSetOperatorLocalizer(p);
  3618. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3619. laShowPanelWithDropDownEffect(p);
  3620. if (Attachment){
  3621. p->Parent = Attachment;
  3622. lstPushItem(&Attachment->SubPanels, p);
  3623. }else{
  3624. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3625. }
  3626. return p;
  3627. }
  3628. 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){
  3629. laOperator *ai = For;
  3630. laPanel *p;
  3631. int b;
  3632. laUiDefineFunc def = 0;
  3633. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3634. else def = laui_DefaultPropUiDefine;
  3635. For->PP.EndInstance = For->CustomData;
  3636. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3637. laEnclosePanelContent(p, &p->UI);
  3638. MAIN.ToPanel = p;
  3639. laShowPanelWithExpandEffect(p);
  3640. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3641. ai->OperatorPanel = p;
  3642. p->ParentOperator = For;
  3643. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3644. return p;
  3645. }
  3646. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3647. laPanel *p; int b; laUiList *uil; laColumn* col;
  3648. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3649. strSafeSet(&p->Title, Title);
  3650. p->BoundUi = 1;
  3651. p->Mode = LA_PANEL_FLOATING_TOP;
  3652. p->BT = &_LA_THEME_FLOATING_PANEL;
  3653. MAIN.ToPanel = p;
  3654. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3655. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3656. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3657. laUiItem* r=laBeginRow(uil,col,0,0);
  3658. laShowSeparator(uil,col)->Expand=1;
  3659. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3660. laEndRow(uil,r);
  3661. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3662. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3663. laSetOperatorLocalizer(p);
  3664. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3665. return p;
  3666. }
  3667. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3668. laPanel *p; int b; laUiList *uil; laColumn* col;
  3669. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3670. strSafeSet(&p->Title, Title);
  3671. p->BoundUi = 1;
  3672. p->Mode = LA_PANEL_FLOATING_TOP;
  3673. p->BT = &_LA_THEME_FLOATING_PANEL;
  3674. MAIN.ToPanel = p;
  3675. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3676. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3677. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3678. laUiItem* r = laBeginRow(uil,col,0,0);
  3679. laShowSeparator(uil,col)->Expand=1;
  3680. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3681. laEndRow(uil, r);
  3682. laEnclosePanelContent(p,uil);
  3683. laShowPanelWithExpandEffect(p);
  3684. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3685. laSetOperatorLocalizer(p);
  3686. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3687. return p;
  3688. }
  3689. void laOperatorModalOver(laOperator* For){
  3690. For->ModalOver = 1;
  3691. }
  3692. void laDeferredRedraw(laPanel* p){
  3693. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3694. if(lip->p==p) return;
  3695. }
  3696. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3697. }
  3698. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3699. laWindow* cur=MAIN.CurrentWindow;
  3700. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3701. MAIN.CurrentWindow=w;
  3702. la_UpdateUiPlacement(w);
  3703. }
  3704. MAIN.CurrentWindow=cur;
  3705. }
  3706. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3707. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3708. }
  3709. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3710. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3711. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3712. void laRedrawCurrentPanel(){
  3713. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3714. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3715. }
  3716. void laRecalcCurrentPanel(){
  3717. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3718. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3719. }
  3720. void laRecalcPanelImmediate(laPanel* p){
  3721. p->FrameDistinguish++;
  3722. laBoxedTheme* bt = (*p->BT);
  3723. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3724. la_PanelRefreshDetachedProp(p);
  3725. int enclosed=0;
  3726. if(p->BoundUi || p->MenuRefer){
  3727. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3728. else enclosed=laEnclosePanelContent(p, &p->UI);
  3729. }
  3730. if(!enclosed){
  3731. la_PanelValidateWidth(p,&p->UI);
  3732. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3733. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3734. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3735. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3736. }
  3737. laWindow* w=MAIN.CurrentWindow;
  3738. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3739. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3740. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3741. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3742. }
  3743. }
  3744. void laRecalcCurrentPanelImmediate(){
  3745. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3746. }
  3747. int laNonFixedPanelExists(laPanel *p){
  3748. laPanel *ip;
  3749. if (!p) return 0;
  3750. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3751. // if (ip == p) return 1;
  3752. //}
  3753. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3754. if (ip == p) return 1;
  3755. }
  3756. return 0;
  3757. }
  3758. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3759. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3760. return 1;
  3761. }
  3762. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3763. int tt=MAIN.TooltipCloseDistance;
  3764. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3765. return 1;
  3766. }
  3767. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3768. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3769. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3770. return 0;
  3771. return 1;
  3772. }
  3773. void laUnlinkSharedPanel(laPanel *p){
  3774. laWindow *w;
  3775. laPanel *ip;
  3776. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3777. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3778. if (ip == p){
  3779. lstRemoveItem(&w->Panels, ip);
  3780. return;
  3781. }
  3782. }
  3783. }
  3784. }
  3785. int laIsPanelCovered(laPanel *p){
  3786. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3787. laPanel *ip;
  3788. laPanel *resp;
  3789. int in1 = 0, in2 = 0, in3 = 0;
  3790. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3791. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3792. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3793. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3794. //}
  3795. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3796. if (ip == p){
  3797. in3 = 1;
  3798. d3 = 0;
  3799. continue;
  3800. }
  3801. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3802. }
  3803. if (!in2 && !in3) in1 = 1;
  3804. if (in1){
  3805. if (d1 || d2 || d3) return 1;
  3806. }else{
  3807. if (in2){
  3808. if (d2 || d3) return 1;
  3809. }else if (in3)
  3810. if (d3) return 1;
  3811. }
  3812. return 0;
  3813. }
  3814. int laIsTopPanel(laPanel *p){
  3815. //if (!p->Item.pPrev) return 1;
  3816. //else {
  3817. if (!laIsPanelCovered(p)){
  3818. //laPopPanel(p);
  3819. return 1;
  3820. }
  3821. return 0;
  3822. //}
  3823. return 0;
  3824. }
  3825. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3826. if(!p) return;
  3827. int ix = *x, iy = *y;
  3828. laListItemPointer *lip;
  3829. laOperator *ai = a;
  3830. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3831. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3832. if (a){
  3833. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3834. laUiList *uil = lip->p;
  3835. (*x) += uil->PanX;
  3836. (*y) += uil->PanY;
  3837. }
  3838. }
  3839. }
  3840. void laPanelToLocal(laOperator *a, int *x, int *y){
  3841. int ix = *x, iy = *y;
  3842. laListItemPointer *lip;
  3843. if (a){
  3844. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3845. laUiList *uil = lip->p;
  3846. (*x) += uil->PanX;
  3847. (*y) += uil->PanY;
  3848. }
  3849. }
  3850. }
  3851. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3852. if(!p) return;
  3853. int ix = *x, iy = *y;
  3854. laListItemPointer *lip;
  3855. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3856. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3857. if (a){
  3858. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3859. laUiList *uil = lip->p;
  3860. (*x) -= uil->PanX;
  3861. (*y) -= uil->PanY;
  3862. }
  3863. }
  3864. }
  3865. void laPanelToWindow(laPanel *p, int *x, int *y){
  3866. int ix = *x, iy = *y;
  3867. laListItemPointer *lip;
  3868. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3869. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3870. }
  3871. void laLocalToPanel(laOperator *a, int *x, int *y){
  3872. int ix = *x, iy = *y;
  3873. laListItemPointer *lip;
  3874. if (a){
  3875. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3876. laUiList *uil = lip->p;
  3877. (*x) -= uil->PanX;
  3878. (*y) -= uil->PanY;
  3879. }
  3880. }
  3881. }
  3882. void laSetNextMenuPos(int X, int Y, int W, int H){
  3883. MAIN.NextX = X;
  3884. MAIN.NextY = Y;
  3885. MAIN.NextW = W;
  3886. MAIN.NextH = H;
  3887. }
  3888. int laIsInBlock(laBlock *b, int X, int Y){
  3889. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3890. return 0;
  3891. }
  3892. 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; }
  3893. 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; }
  3894. 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; }
  3895. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3896. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3897. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3898. if (!b->B1 && !b->B2){
  3899. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3900. }
  3901. }
  3902. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3903. laPanel *p;
  3904. laBlock *sb = 0;
  3905. if (!laIsInBlock(b, X, Y)) return 0;
  3906. if (!b->B1 && !b->B2) return b;
  3907. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3908. return laDetectBlockRecursive(b->B2, X, Y);
  3909. }
  3910. laPanel *laDetectPanel(int X, int Y){
  3911. laPanel *p; laBlock *b;
  3912. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3913. int x = X, y = Y;
  3914. laWindowToLocal(0, p, &x, &y);
  3915. if (p->Show && laIsInPanel(p, x, y)){
  3916. return p;
  3917. }
  3918. }
  3919. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3920. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3921. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3922. return 0;
  3923. }
  3924. laUiList *laPrepareUi(laPanel *p){
  3925. return &p->UI;
  3926. }
  3927. laColumn *laFirstColumn(laUiList *uil){
  3928. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3929. else{
  3930. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3931. c->SP = 1;
  3932. c->PreWidth = 1;
  3933. lstAppendItem(&uil->Columns, c);
  3934. c->Top = c;
  3935. return uil->Columns.pFirst;
  3936. }
  3937. }
  3938. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3939. laColumn *lc, *rc;
  3940. if (c->LS || c->RS) return c;
  3941. lc = memAcquireSimple(sizeof(laColumn));
  3942. rc = memAcquireSimple(sizeof(laColumn));
  3943. c->LS = lc;
  3944. c->RS = rc;
  3945. c->LS->SP = Percent;
  3946. c->RS->SP = Percent;
  3947. c->LS->Top = c->Top;
  3948. c->RS->Top = c->Top;
  3949. if (uil){
  3950. lstAppendItem(&uil->Columns, lc);
  3951. lstAppendItem(&uil->Columns, rc);
  3952. }
  3953. if (c->LS && c->RS->MaxW == 0){
  3954. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3955. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3956. }else if (c->RS && c->LS->MaxW == 0){
  3957. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3958. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3959. }
  3960. return c;
  3961. }
  3962. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3963. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3964. return c->LS;
  3965. }
  3966. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3967. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3968. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3969. return c->RS;
  3970. }
  3971. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3972. lstRemoveItem(List, c);
  3973. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3974. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3975. memFree(c);
  3976. }
  3977. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3978. laUiList *uil = TopUil;
  3979. laUiList *sub;
  3980. laUiItem *ui;
  3981. laColumn *cc, *NextCC = 0;
  3982. int Occupied = 0;
  3983. int Removed = 0;
  3984. if (!c->LS) return 0;
  3985. else{
  3986. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3987. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3988. }
  3989. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3990. if (ui->C == c->LS || ui->C == c->RS){
  3991. if (DoMerge){
  3992. ui->C = c;
  3993. Occupied = 1;
  3994. }else
  3995. return 1;
  3996. }
  3997. if (ui->Subs.pFirst){
  3998. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3999. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  4000. }
  4001. }
  4002. }
  4003. if (!Removed){
  4004. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  4005. if (cc == c){
  4006. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  4007. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  4008. c->LS = 0;
  4009. c->RS = 0;
  4010. Removed = 1;
  4011. break;
  4012. }
  4013. }
  4014. }
  4015. return Occupied;
  4016. }
  4017. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  4018. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  4019. ut->FakeProp = memAcquire(sizeof(laSubProp));
  4020. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  4021. ut->FakeProp->Base.Identifier = ut->Identifier;
  4022. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  4023. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  4024. ut->FakeProp->Base.OffsetIsPointer = 1;
  4025. //ut->FakeProp->Base.Container = ut->ExtraProps;
  4026. return ut->ExtraProps;
  4027. }
  4028. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  4029. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  4030. ct->FakeProp = memAcquire(sizeof(laSubProp));
  4031. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  4032. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  4033. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  4034. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  4035. ct->FakeProp->Base.OffsetIsPointer = 1;
  4036. //ut->FakeProp->Base.Container = ut->ExtraProps;
  4037. return ct->ExtraProps;
  4038. }
  4039. void la_DestroyUiType(laUiType* uit){
  4040. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4041. memFree(uit);
  4042. }
  4043. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  4044. laUiType *ut = memAcquire(sizeof(laUiType));
  4045. ut->Identifier = Identifer;
  4046. ut->OperatorID = UseOperator;
  4047. ut->Draw = Draw;
  4048. ut->Theme = bt;
  4049. ut->ForType = ForType;
  4050. ut->OperatorType = laGetOperatorType(UseOperator);
  4051. ut->GetHeight = GetHeight;
  4052. ut->Init = Init;
  4053. ut->Destroy = Destroy;
  4054. la_UDFAppendSharedTypePointer(Identifer, ut);
  4055. lstAppendItem(&MAIN.UiTypes, ut);
  4056. return ut;
  4057. }
  4058. laUiType *la_GetUiTypeFromProperty(laProp *P){
  4059. laUiType *ut = MAIN.UiTypes.pFirst;
  4060. if (!P) return 0;
  4061. if (P->DefaultUiType) return P->DefaultUiType;
  4062. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  4063. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  4064. for (ut; ut; ut = ut->Item.pNext){
  4065. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  4066. return ut;
  4067. }
  4068. }
  4069. return 0;
  4070. }
  4071. laUiType *la_GetUiButtonType(){
  4072. laUiType *ut = MAIN.UiTypes.pFirst;
  4073. for (ut; ut; ut = ut->Item.pNext){
  4074. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  4075. }
  4076. return 0;
  4077. }
  4078. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  4079. laCanvasTemplate *vdt;
  4080. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  4081. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  4082. }
  4083. return 0;
  4084. }
  4085. void la_AssignPropExtras(laUiItem* ui){
  4086. if(!ui->Type || !ui->Type->FakeProp) return;
  4087. ui->FakePs.p = ui->Type->FakeProp;
  4088. ui->FakePs.Type = U'.';
  4089. ui->FakePs.UseInstance = ui;
  4090. ui->ExtraPP.LastPs = &ui->FakePs;
  4091. }
  4092. void la_AssignCanvasPropExtras(laUiItem* ui){
  4093. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  4094. laCanvasTemplate*ct=ui->CanvasTemplate;
  4095. ui->FakePs.p = ct->FakeProp;
  4096. ui->FakePs.Type = U'.';
  4097. ui->FakePs.UseInstance = ui;
  4098. ui->ExtraPP.EndInstance = ui->Extra;
  4099. ui->ExtraPP.LastPs = &ui->FakePs;
  4100. }
  4101. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  4102. int result;
  4103. if (!ui) return 0;
  4104. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  4105. if (Path){
  4106. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4107. if (!result){
  4108. ui->AT = laGetOperatorType(Path);
  4109. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  4110. ui->Type = la_GetUiButtonType();
  4111. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  4112. }else{
  4113. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4114. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4115. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  4116. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4117. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4118. }
  4119. if (Base){
  4120. ui->PP.RawThis = Base;
  4121. }
  4122. }else if (Base){
  4123. ui->PP.LastPs = Base->LastPs;
  4124. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4125. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4126. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  4127. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4128. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4129. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4130. }
  4131. la_AssignPropExtras(ui);
  4132. if(Widget){ ui->Flags|= Widget->Flags; }
  4133. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  4134. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  4135. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4136. return ui;
  4137. }
  4138. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  4139. ui->Type = _LA_UI_LABEL;
  4140. ui->Template = Template;
  4141. ui->State = LA_UI_NORMAL;
  4142. strSafeSet(&ui->Display, Content);
  4143. la_AssignPropExtras(ui);
  4144. return ui;
  4145. }
  4146. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  4147. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4148. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  4149. ui->State = LA_UI_NORMAL;
  4150. la_AssignPropExtras(ui);
  4151. return ui;
  4152. }
  4153. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4154. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4155. transLate(Content);
  4156. la_UpdateLabelDisplay(ui, Template, Content);
  4157. ui->C = c;
  4158. if (ui->Type->Init) ui->Type->Init(ui);
  4159. ui->ExtraPP.EndInstance = ui->Extra;
  4160. lstAppendItem(&uil->UiItems, ui);
  4161. return ui;
  4162. }
  4163. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4164. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4165. la_UpdateLabelDisplay(ui, Template, Content);
  4166. ui->C = c;
  4167. if (ui->Type->Init) ui->Type->Init(ui);
  4168. ui->ExtraPP.EndInstance = ui->Extra;
  4169. lstAppendItem(&uil->UiItems, ui);
  4170. return ui;
  4171. }
  4172. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  4173. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4174. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  4175. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  4176. ui->C = c;
  4177. if (ui->Type->Init) ui->Type->Init(ui);
  4178. ui->ExtraPP.EndInstance = ui->Extra;
  4179. lstAppendItem(&uil->UiItems, ui);
  4180. return ui;
  4181. }
  4182. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4183. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  4184. }
  4185. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4186. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4187. }
  4188. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4189. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4190. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4191. ui->C = c;
  4192. ui->TemplateContext = TemplateContext;
  4193. if (ui->Type->Init) ui->Type->Init(ui);
  4194. ui->ExtraPP.EndInstance = ui->Extra;
  4195. lstAppendItem(&uil->UiItems, ui);
  4196. return ui;
  4197. }
  4198. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4199. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4200. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4201. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4202. ui->SymbolID=Height;
  4203. lstAppendItem(&uil->UiItems, ui);
  4204. return ui;
  4205. }
  4206. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4207. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4208. }
  4209. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4210. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4211. }
  4212. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4213. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4214. ui->Type = _LA_UI_CANVAS;
  4215. ui->State = LA_UI_NORMAL;
  4216. ui->C = c;
  4217. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4218. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4219. else{
  4220. 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); }
  4221. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4222. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4223. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4224. }
  4225. if (ui->Type->Init) ui->Type->Init(ui);
  4226. la_AssignCanvasPropExtras(ui);
  4227. if (Height) ui->Expand=Height; else ui->Expand=6;
  4228. lstAppendItem(&uil->UiItems, ui);
  4229. return ui;
  4230. }
  4231. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4232. laUiItem* ui=0;
  4233. #define ADD_CANVAS \
  4234. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4235. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4236. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4237. }laEndCondition(uil,b3);\
  4238. laEndRow(uil,b);
  4239. if(Detached){
  4240. laColumn* cl,*cll,*clr,*cr;
  4241. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4242. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4243. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4244. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4245. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4246. ADD_CANVAS
  4247. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4248. }laElse(uil,b2);{
  4249. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4250. ADD_CANVAS
  4251. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4252. }laEndCondition(uil,b2);
  4253. }else{
  4254. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4255. }
  4256. #undef ADD_CANVAS
  4257. }
  4258. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4259. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4260. laCanvasExtra *e;
  4261. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4262. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4263. ui->C = c;
  4264. if (ui->Type->Init) ui->Type->Init(ui);
  4265. ui->ExtraPP.EndInstance = ui->Extra;
  4266. lstAppendItem(&uil->UiItems, ui);
  4267. return ui;
  4268. }
  4269. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4270. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4271. ui->Type = _LA_UI_SYMBOL;
  4272. ui->SymbolID = SymbolID;
  4273. if (Height) ui->State = Height;
  4274. ui->C = c;
  4275. if (ui->Type->Init) ui->Type->Init(ui);
  4276. ui->ExtraPP.EndInstance = ui->Extra;
  4277. lstAppendItem(&uil->UiItems, ui);
  4278. return ui;
  4279. }
  4280. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4281. laPropPack PP={0}; int result;
  4282. if (Path){
  4283. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4284. if (!result){ return 0; }
  4285. if (Base){ PP.RawThis = Base; }
  4286. }else if (Base){
  4287. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4288. }
  4289. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4290. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4291. lstAppendItem(&ui->CompoundPPs,CPP);
  4292. return &CPP->PP;
  4293. }
  4294. laUiItem *laShowMouseActionReporter(laUiList* uil, laColumn* c, int Height, const char* Display, const char* instructions){
  4295. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4296. ui->C = c;
  4297. ui->Type=_LA_UI_MOUSE_ACTION_REPORTER;
  4298. ui->State=Height; if(!ui->State){ ui->State=1; }
  4299. if(Display) strSafeSet(&ui->Display, Display);
  4300. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4301. lstAppendItem(&uil->UiItems, ui);
  4302. return ui;
  4303. }
  4304. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4305. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4306. ui->Type = &_LA_UI_ROW_BEGIN;
  4307. ui->State=Expand;
  4308. ui->Flags=Even;
  4309. ui->C = c;
  4310. if (ui->Type->Init) ui->Type->Init(ui);
  4311. ui->ExtraPP.EndInstance = ui->Extra;
  4312. lstAppendItem(&uil->UiItems, ui);
  4313. return ui;
  4314. }
  4315. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4316. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4317. ui->Type = &_LA_UI_ROW_END;
  4318. ui->C = Begin->C;
  4319. ui->Page = (laUiList*)Begin;
  4320. if (ui->Type->Init) ui->Type->Init(ui);
  4321. ui->ExtraPP.EndInstance = ui->Extra;
  4322. lstAppendItem(&uil->UiItems, ui);
  4323. return ui;
  4324. }
  4325. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4326. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4327. e->Expression = Expression;
  4328. ui->Extra = e;
  4329. la_AssignPropExtras(ui);
  4330. }
  4331. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4332. laUiItem *ui = la_CreateGroupHandle(Widget);
  4333. laUiList *nuil;
  4334. ui->C = c;
  4335. lstAppendItem(&uil->UiItems, ui);
  4336. nuil = memAcquireSimple(sizeof(laUiList));
  4337. strSafeSet(&nuil->TabName, Name);
  4338. ui->Page = nuil;
  4339. lstAppendItem(&ui->Subs, nuil);
  4340. if (ui->Type->Init) ui->Type->Init(ui);
  4341. ui->ExtraPP.EndInstance = ui->Extra;
  4342. return ui;
  4343. }
  4344. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4345. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4346. laUiList *sub = SubUi->Page;
  4347. laColumn *s = laFirstColumn(sub);
  4348. SubUi->State = LA_UI_ACTIVE;
  4349. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4350. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4351. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4352. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4353. laShowSeparator(sub, s);
  4354. return SubUi;
  4355. }
  4356. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4357. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4358. laUiList *sub = SubUi->Page;
  4359. laColumn *s = laFirstColumn(sub);
  4360. SubUi->State = LA_UI_ACTIVE;
  4361. return SubUi;
  4362. }
  4363. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4364. laEndCondition(sub, sub->UiItems.pFirst);
  4365. }
  4366. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4367. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4368. laUiList *nuil;
  4369. ui->C = c;
  4370. lstAppendItem(&uil->UiItems, ui);
  4371. if (ui->Type->Init) ui->Type->Init(ui);
  4372. ui->ExtraPP.EndInstance = ui->Extra;
  4373. return ui;
  4374. }
  4375. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4376. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4377. if (!ui->Page) ui->Page = uil;
  4378. lstAppendItem(&ui->Subs, uil);
  4379. strSafeSet(&uil->TabName, Name);
  4380. laFirstColumn(uil);
  4381. //laFirstColumn(uil);
  4382. return uil;
  4383. }
  4384. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4385. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4386. /*if (!ui->Page) */ ui->Page = uil;
  4387. lstAppendItem(&ui->Subs, uil);
  4388. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4389. return uil;
  4390. }
  4391. laUiConditionNode *laTrue(){
  4392. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4393. ucn->Type = LA_CONDITION_TRUE;
  4394. return ucn;
  4395. }
  4396. laUiConditionNode *laFalse(){
  4397. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4398. ucn->Type = LA_CONDITION_FALSE;
  4399. return ucn;
  4400. }
  4401. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4402. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4403. ucn->Type = LA_CONDITION_PROP;
  4404. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4405. strSafeSet(&ucn->String, Prop);
  4406. return ucn;
  4407. }
  4408. laUiConditionNode *laIntExpression(int Value){
  4409. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4410. ucn->Type = LA_CONDITION_INT;
  4411. ucn->IntValue = Value;
  4412. return ucn;
  4413. }
  4414. laUiConditionNode *laFloatExpression(real Value){
  4415. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4416. ucn->Type = LA_CONDITION_FLOAT;
  4417. ucn->FloatValue = Value;
  4418. return ucn;
  4419. }
  4420. laUiConditionNode *laStringExpression(char *Content){
  4421. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4422. ucn->Type = LA_CONDITION_STRING;
  4423. strSafeSet(&ucn->String, Content);
  4424. return ucn;
  4425. }
  4426. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4427. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4428. ucn->Type = LA_CONDITION_AND;
  4429. ucn->Expression1 = Expression1;
  4430. ucn->Expression2 = Expression2;
  4431. return ucn;
  4432. }
  4433. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4434. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4435. ucn->Type = LA_CONDITION_OR;
  4436. ucn->Expression1 = Expression1;
  4437. ucn->Expression2 = Expression2;
  4438. return ucn;
  4439. }
  4440. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4441. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4442. ucn->Type = LA_CONDITION_NOT;
  4443. ucn->Expression1 = Expression1;
  4444. return ucn;
  4445. }
  4446. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4447. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4448. ucn->Type = LA_CONDITION_EQ;
  4449. ucn->Expression1 = Expression1;
  4450. ucn->Expression2 = Expression2;
  4451. return ucn;
  4452. }
  4453. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4454. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4455. ucn->Type = LA_CONDITION_GT;
  4456. ucn->Expression1 = Expression1;
  4457. ucn->Expression2 = Expression2;
  4458. return ucn;
  4459. }
  4460. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4461. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4462. ucn->Type = LA_CONDITION_LT;
  4463. ucn->Expression1 = Expression1;
  4464. ucn->Expression2 = Expression2;
  4465. return ucn;
  4466. }
  4467. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4468. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4469. ucn->Type = LA_CONDITION_GE;
  4470. ucn->Expression1 = Expression1;
  4471. ucn->Expression2 = Expression2;
  4472. return ucn;
  4473. }
  4474. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4475. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4476. ucn->Type = LA_CONDITION_LE;
  4477. ucn->Expression1 = Expression1;
  4478. ucn->Expression2 = Expression2;
  4479. return ucn;
  4480. }
  4481. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4482. if (Expression->Type != LA_CONDITION_INT) return 0;
  4483. return Expression->IntValue;
  4484. }
  4485. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4486. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4487. return Expression->FloatValue;
  4488. }
  4489. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4490. return Expression->String->Ptr;
  4491. }
  4492. 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){
  4493. switch (Mode1){
  4494. case LA_PROP_ENUM:
  4495. case LA_PROP_INT:
  4496. case LA_CONDITION_INT:
  4497. switch (Mode2){
  4498. case LA_PROP_ENUM:
  4499. case LA_PROP_INT:
  4500. case LA_CONDITION_INT:
  4501. switch (CompMode){
  4502. case LA_CONDITION_GE:
  4503. return (i1 >= i2);
  4504. case LA_CONDITION_GT:
  4505. return (i1 > i2);
  4506. case LA_CONDITION_EQ:
  4507. return (i1 == i2);
  4508. case LA_CONDITION_LT:
  4509. return (i1 < i2);
  4510. case LA_CONDITION_LE:
  4511. return (i1 <= i2);
  4512. }
  4513. case LA_PROP_FLOAT:
  4514. case LA_CONDITION_FLOAT:
  4515. switch (CompMode){
  4516. case LA_CONDITION_GE:
  4517. return ((real)i1 >= f2);
  4518. case LA_CONDITION_GT:
  4519. return ((real)i1 > f2);
  4520. case LA_CONDITION_EQ:
  4521. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4522. case LA_CONDITION_LT:
  4523. return ((real)i1 < f2);
  4524. case LA_CONDITION_LE:
  4525. return ((real)i1 <= f2);
  4526. }
  4527. case LA_PROP_SUB:
  4528. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4529. default:
  4530. return 0;
  4531. }
  4532. case LA_PROP_FLOAT:
  4533. case LA_CONDITION_FLOAT:
  4534. switch (Mode2){
  4535. case LA_PROP_INT:
  4536. case LA_PROP_ENUM:
  4537. case LA_CONDITION_INT:
  4538. switch (CompMode){
  4539. case LA_CONDITION_GE:
  4540. return (f1 >= (real)i2);
  4541. case LA_CONDITION_GT:
  4542. return (f1 > (real)i2);
  4543. case LA_CONDITION_EQ:
  4544. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4545. case LA_CONDITION_LT:
  4546. return (f1 < (real)i2);
  4547. case LA_CONDITION_LE:
  4548. return (f1 <= (real)i2);
  4549. }
  4550. case LA_PROP_FLOAT:
  4551. case LA_CONDITION_FLOAT:
  4552. switch (CompMode){
  4553. case LA_CONDITION_GE:
  4554. return (f1 >= f2);
  4555. case LA_CONDITION_GT:
  4556. return (f1 > f2);
  4557. case LA_CONDITION_EQ:
  4558. return (f1 == f2);
  4559. case LA_CONDITION_LT:
  4560. return (f1 < f2);
  4561. case LA_CONDITION_LE:
  4562. return (f1 <= f2);
  4563. }
  4564. default:
  4565. return 0;
  4566. }
  4567. case LA_PROP_STRING:
  4568. case LA_CONDITION_STRING:
  4569. switch (Mode2){
  4570. case LA_PROP_STRING:
  4571. case LA_CONDITION_STRING:
  4572. return strSame(s1, s2);
  4573. default:
  4574. return 0;
  4575. }
  4576. case LA_PROP_SUB:
  4577. switch (Mode2){
  4578. case LA_PROP_SUB:
  4579. return p1 == p2;
  4580. case LA_CONDITION_INT:
  4581. case LA_PROP_INT:
  4582. case LA_PROP_ENUM:
  4583. return (int)p1 == i2;
  4584. default:
  4585. return 0;
  4586. }
  4587. default:
  4588. switch (CompMode){
  4589. case LA_CONDITION_GE:
  4590. return (i1 >= i2);
  4591. case LA_CONDITION_GT:
  4592. return (i1 > i2);
  4593. case LA_CONDITION_EQ:
  4594. return (i1 == i2);
  4595. case LA_CONDITION_LT:
  4596. return (i1 < i2);
  4597. case LA_CONDITION_LE:
  4598. return (i1 <= i2);
  4599. }
  4600. }
  4601. }
  4602. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4603. void *Instance = 0;
  4604. int IValue1 = 0, IValue2 = 0;
  4605. real FValue1 = 0, FValue2 = 0;
  4606. void *Ptr1 = 0, *Ptr2 = 0;
  4607. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4608. int Result1, Result2;
  4609. laEnumItem *ei; laSubProp*sp;
  4610. if (!Expression) return 0;
  4611. Str1[0] = 0;
  4612. Str2[0] = 0;
  4613. laPropIterator pi = {0};
  4614. switch (Expression->Type){
  4615. case LA_CONDITION_PROP:
  4616. if (!Expression->PP.LastPs){
  4617. (*IResult) = 0;
  4618. return 0;
  4619. }
  4620. switch (Expression->PP.LastPs->p->PropertyType){
  4621. case LA_PROP_INT:
  4622. *IResult = laGetInt(&Expression->PP);
  4623. if (*IResult) return LA_CONDITION_INT;
  4624. else return 0;
  4625. case LA_PROP_FLOAT:
  4626. *FResult = laGetFloat(&Expression->PP);
  4627. if (*FResult) return 1;
  4628. else return 0;
  4629. break;
  4630. case LA_PROP_STRING:
  4631. laGetString(&Expression->PP, _StrResult, &StrResult);
  4632. if (StrResult[0]) return 1;
  4633. else return 0;
  4634. break;
  4635. case LA_PROP_ENUM:
  4636. ei = laGetEnum(&Expression->PP);
  4637. if (!ei) return 0;
  4638. /*if(ei) */ *IResult = ei->Index;
  4639. if (*IResult) return LA_CONDITION_INT;
  4640. else return 0;
  4641. break;
  4642. case LA_PROP_SUB:
  4643. sp=Expression->PP.LastPs->p;
  4644. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4645. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4646. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4647. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4648. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4649. }
  4650. }
  4651. *PtrResult = Instance;
  4652. if (Instance) return 1;
  4653. break;
  4654. default:
  4655. return 0;
  4656. }
  4657. break;
  4658. case LA_CONDITION_INT:
  4659. *IResult = Expression->IntValue;
  4660. if (*IResult) return 1;
  4661. else
  4662. return 0;
  4663. case LA_CONDITION_FLOAT:
  4664. *FResult = Expression->FloatValue;
  4665. if (*FResult) return 1;
  4666. else
  4667. return 0;
  4668. case LA_CONDITION_STRING:
  4669. if (Expression->String){
  4670. strCopyFull(StrResult, Expression->String->Ptr);
  4671. return 1;
  4672. }else
  4673. return 0;
  4674. case LA_CONDITION_TRUE:
  4675. if (*IResult) *IResult = 1;
  4676. return 1;
  4677. case LA_CONDITION_FALSE:
  4678. if (*IResult) *IResult = 0;
  4679. return 0;
  4680. default:
  4681. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4682. switch (Expression->Type){
  4683. case LA_CONDITION_AND:
  4684. if (Result1){
  4685. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4686. if (Result2) *IResult = 1;
  4687. return (Result2);
  4688. }else
  4689. return 0;
  4690. case LA_CONDITION_OR:
  4691. if (!Result1){
  4692. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4693. if (Result2) *IResult = 1;
  4694. return (Result2);
  4695. }else
  4696. return 1;
  4697. case LA_CONDITION_NOT:
  4698. return !Result1;
  4699. default:
  4700. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4701. return la_DoCompare(Expression->Type,
  4702. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4703. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4704. }
  4705. break;
  4706. }
  4707. return 0;
  4708. }
  4709. int la_DoSingleExpression(laUiConditionNode *Expression){
  4710. int a;
  4711. real b;
  4712. char c[128]={0};
  4713. void *p;
  4714. if (!Expression) return 1;
  4715. c[0] = 0;
  4716. return la_DoExpression(Expression, &a, &b, c, &p);
  4717. }
  4718. void la_StepExpression(laUiConditionNode *e){
  4719. if (!e) return;
  4720. switch (e->Type){
  4721. case LA_CONDITION_AND:
  4722. case LA_CONDITION_OR:
  4723. case LA_CONDITION_GE:
  4724. case LA_CONDITION_GT:
  4725. case LA_CONDITION_EQ:
  4726. case LA_CONDITION_LT:
  4727. case LA_CONDITION_LE:
  4728. la_StepExpression(e->Expression1);
  4729. la_StepExpression(e->Expression2);
  4730. break;
  4731. case LA_CONDITION_NOT:
  4732. la_StepExpression(e->Expression1);
  4733. break;
  4734. case LA_CONDITION_PROP:
  4735. la_StepPropPack(&e->PP);
  4736. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4737. la_UsePropPack(&e->PP, 1);
  4738. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4739. //}
  4740. break;
  4741. default:
  4742. break;
  4743. }
  4744. }
  4745. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4746. if (!ucn) return;
  4747. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4748. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4749. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4750. if (ucn->String) strSafeDestroy(&ucn->String);
  4751. if (ucn) memFree(ucn);
  4752. }
  4753. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4754. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4755. ui->C = c;
  4756. ui->Type = &_LA_UI_CONDITION;
  4757. la_ConditionerInit(ui, Expression);
  4758. lstAppendItem(&uil->UiItems, ui);
  4759. return ui;
  4760. }
  4761. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4762. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4763. laConditionUiExtraData *cued;
  4764. ui->Type = &_LA_UI_CONDITION_ELSE;
  4765. la_ConditionerInit(ui, 0);
  4766. cued = ui->Extra;
  4767. cued->EndUi = Beginner;
  4768. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4769. ui->C = Beginner->C;
  4770. lstAppendItem(&uil->UiItems, ui);
  4771. return ui;
  4772. }
  4773. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4774. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4775. laConditionUiExtraData *cued;
  4776. ui->Template = define;
  4777. ui->C = col;
  4778. ui->PP.RawThis = ExtraBase;
  4779. ui->Page = ExtraThis;
  4780. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4781. la_ConditionerInit(ui, 0);
  4782. cued = ui->Extra;
  4783. //cued->Remove = Remove;
  4784. ui->State = LA_UI_NORMAL;
  4785. lstAppendItem(&uil->UiItems, ui);
  4786. return ui;
  4787. }
  4788. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4789. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4790. laConditionUiExtraData *cued;
  4791. ui->Type = &_LA_UI_CONDITION_END;
  4792. la_ConditionerInit(ui, 0);
  4793. cued = ui->Extra;
  4794. cued->EndUi = Beginner;
  4795. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4796. ui->C = Beginner->C;
  4797. lstAppendItem(&uil->UiItems, ui);
  4798. return ui;
  4799. }
  4800. laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags) {
  4801. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4802. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4803. ui->Type = _LA_UI_MENU_ROOT;
  4804. strSafeSet(&ui->Display, Title);
  4805. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4806. ui->C = c;
  4807. ui->Flags|=flags;
  4808. lstAppendItem(&uil->UiItems, ui);
  4809. muil->Flags|=flags;
  4810. lstAppendItem(&ui->Subs, muil);
  4811. return muil;
  4812. }
  4813. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4814. return laMakeMenuPageEx(uil,c,Title,0);
  4815. }
  4816. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4817. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4818. ui->Type = _LA_UI_ALIGN;
  4819. ui->C = widest;
  4820. lstAppendItem(&uil->UiItems, ui);
  4821. return ui;
  4822. }
  4823. void laFixHeight(laUiList *uil, short Rows){
  4824. if (!uil) return;
  4825. uil->HeightCoeff = Rows;
  4826. }
  4827. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4828. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4829. if (!ExtraColumns) return;
  4830. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4831. }
  4832. laUiTemplate *laFindUiTemplate(char *Identifier){
  4833. laUiTemplate *uit;
  4834. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4835. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4836. }
  4837. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4838. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4839. }
  4840. return 0;
  4841. }
  4842. void la_DestroyUiTemplate(laUiTemplate* uit){
  4843. strSafeDestroy(&uit->Identifier);
  4844. strSafeDestroy(&uit->Title);
  4845. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4846. memFree(uit);
  4847. }
  4848. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4849. strSafeDestroy(&uit->Identifier);
  4850. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4851. memFree(uit);
  4852. }
  4853. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4854. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4855. strSafeSet(&uit->Identifier, Identifier);
  4856. strSafeSet(&uit->Title, Title);
  4857. strSafeSet(&uit->CategoryName, NewCategory);
  4858. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4859. uit->DefaultGLFormat=DefaultGLFormat;
  4860. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4861. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4862. la_UDFAppendSharedTypePointer(Identifier, uit);
  4863. return uit;
  4864. }
  4865. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4866. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4867. strSafeSet(&t->Identifier, Identifier);
  4868. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4869. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4870. lstAppendItem(&MAIN.View2DTemplates, t);
  4871. la_UDFAppendSharedTypePointer(Identifier, t);
  4872. return t;
  4873. }
  4874. void laFinalizeUiTemplates(){
  4875. laUiTemplate *uit;
  4876. laCanvasTemplate *u2d;
  4877. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4878. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4879. }
  4880. }
  4881. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4882. laPanel *p;
  4883. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4884. if (p->PanelTemplate==uit){
  4885. return p;
  4886. }
  4887. }
  4888. return 0;
  4889. }
  4890. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4891. laUiList *uil, *NextUil;
  4892. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4893. NextUil = uil->Item.pNext;
  4894. lstRemoveItem(&ui->Subs, uil);
  4895. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4896. }
  4897. la_StopUiOperatorService(ui);
  4898. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4899. strSafeDestroy(&ui->Display);
  4900. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4901. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4902. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4903. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4904. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4905. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4906. }
  4907. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4908. memFree(ui);
  4909. }
  4910. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4911. laUiItem *ui, *NextUi;
  4912. laColumn *col, *NextCol;
  4913. if (!uil) return;
  4914. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4915. NextUi = ui->Item.pNext;
  4916. if(OnlyRemoveUser && RemoveUsers){
  4917. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4918. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4919. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4920. continue;
  4921. }
  4922. lstRemoveItem(&uil->UiItems, ui);
  4923. la_DestroyUiItem(ui, RemoveUsers);
  4924. }
  4925. if(OnlyRemoveUser){ return; }
  4926. for (col = uil->Columns.pFirst; col; col = NextCol){
  4927. NextCol = col->Item.pNext;
  4928. lstRemoveItem(&uil->Columns, col);
  4929. memFree(col);
  4930. }
  4931. strSafeDestroy(&uil->TabName);
  4932. if (!NoFree) memFree(uil);
  4933. }
  4934. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4935. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4936. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4937. }
  4938. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4939. laUiItem *Next = after->Item.pNext;
  4940. laUiItem *Last = uil->UiItems.pLast;
  4941. after->Item.pNext = 0;
  4942. uil->UiItems.pLast = after;
  4943. Define(uil, Base, This, ExtraColums, 0);
  4944. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4945. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4946. if (Next != Last) uil->UiItems.pLast = Last;
  4947. }
  4948. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4949. // int i = 0;
  4950. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4951. // if (!ui->ExtraColums) return;
  4952. // for (i; ui->ExtraColums[i]; i++) {
  4953. // laColumn* c = ui->ExtraColums[i];
  4954. // c->B = B;
  4955. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4956. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4957. // }
  4958. //}
  4959. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4960. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4961. }
  4962. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4963. laColumn *c = ui->C;
  4964. laColumn *ic = lst->pFirst;
  4965. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4966. for (ic; ic; ic = ic->Item.pNext){
  4967. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4968. ic->B = ic->B < c->B ? c->B : ic->B;
  4969. }
  4970. }
  4971. ic = ui->C;
  4972. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4973. ;
  4974. for (ic; ic; ic = ic->Item.pNext){
  4975. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4976. ic->B = ic->B < c->B ? c->B : ic->B;
  4977. }
  4978. }
  4979. }
  4980. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4981. laColumn *c = ui->C;
  4982. laColumn *ic = lst->pFirst;
  4983. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4984. for (ic; ic; ic = ic->Item.pNext){
  4985. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4986. ic->B = ic->B < c->B ? c->B : ic->B;
  4987. }
  4988. }
  4989. ic = ui->C;
  4990. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4991. ;
  4992. for (ic; ic; ic = ic->Item.pNext){
  4993. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4994. ic->B = ic->B < c->B ? c->B : ic->B;
  4995. }
  4996. }
  4997. }
  4998. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4999. int rep;
  5000. int sp;
  5001. int rev;
  5002. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  5003. if (!c) return 0;
  5004. sp = (c->SP * (R - L)) + L;
  5005. rev = sp;
  5006. /*if (U)*/ c->B = U;
  5007. if (LR == 1){
  5008. c->IL = L;
  5009. c->IR = sp;
  5010. if (repos){
  5011. c->IR = repos;
  5012. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  5013. c->IR = c->IL + c->MaxW*LA_RH+M;
  5014. rev = c->IR;
  5015. }
  5016. }else if (LR == 2){
  5017. c->IL = sp;
  5018. c->IR = R;
  5019. if (repos){
  5020. c->IL = repos;
  5021. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  5022. c->IL = c->IR - c->MaxW*LA_RH-M;
  5023. rev = c->IL;
  5024. }
  5025. }else if (LR == 0){
  5026. c->IL = L;
  5027. c->IR = R;
  5028. }
  5029. if (c->LS && c->RS->MaxW == 0){
  5030. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  5031. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  5032. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  5033. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  5034. }else if (c->RS && c->LS->MaxW == 0){
  5035. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  5036. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  5037. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  5038. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  5039. }
  5040. return rev;
  5041. }
  5042. STRUCTURE(laRowInfo){
  5043. int MaxW;
  5044. int MinW;
  5045. int UnitMinW;
  5046. int NonExpandW;
  5047. int TotalPadding;
  5048. int Expand, Even;
  5049. int ExpandAccum;
  5050. int CountElements;
  5051. int U,MaxB,L;
  5052. laListHandle Elements;
  5053. int LastNoHeight;
  5054. };
  5055. STRUCTURE(laRowNode){
  5056. laListItem Item;
  5057. laUiItem* ui;
  5058. int GotW, LP, RP, H;
  5059. int Expand;
  5060. int UseLast;
  5061. int WaitAnimation;
  5062. };
  5063. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  5064. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  5065. ri->UnitMinW=LA_RH;
  5066. ri->Expand=ui->State?1:0;
  5067. ri->Even=ui->Flags?1:0;
  5068. ri->U=ui->TU; ri->L=ui->TL;
  5069. ri->MaxB=ui->TU;
  5070. }
  5071. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  5072. laRowNode* rn=CreateNew(laRowNode);
  5073. rn->LP=bt->LP;rn->RP=bt->RP;
  5074. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  5075. rn->ui=ui;
  5076. rn->H=H;
  5077. rn->Expand=ui->Expand;
  5078. rn->WaitAnimation=WaitAnimation;
  5079. lstAppendItem(&ri->Elements, rn);
  5080. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  5081. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  5082. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  5083. ri->TotalPadding += (bt->LP+bt->RP);
  5084. ri->MinW+=ri->UnitMinW;
  5085. ri->NonExpandW+=rn->GotW;
  5086. ri->ExpandAccum+=ui->Expand;
  5087. ri->CountElements++;
  5088. if(ui->Expand){ri->Expand=1;}
  5089. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  5090. }
  5091. int la_ShrinkableRowElements(laRowInfo* ri){
  5092. int count=0;
  5093. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5094. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  5095. count++;
  5096. }
  5097. return count;
  5098. }
  5099. void la_RecordSocketRuntimePosition(laUiItem* ui);
  5100. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  5101. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  5102. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  5103. if(Available<0){
  5104. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  5105. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  5106. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  5107. }else{
  5108. if(!ri->Expand && Available>0){Available=0;}
  5109. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  5110. }
  5111. if(!ShareCount) return 0;
  5112. int PerNode = Available/ShareCount;
  5113. int Remaining = Available-PerNode*ShareCount;
  5114. int L = ri->L; int i=0; laRowNode* rn;
  5115. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5116. laUiItem* ui=rn->ui;
  5117. int NodeAdd, Node=rn->GotW;
  5118. if(rn->UseLast){
  5119. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  5120. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  5121. continue;
  5122. }
  5123. if(Available>=0){
  5124. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  5125. NodeAdd+=(i<Remaining?1:0);i++;
  5126. }else{
  5127. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  5128. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  5129. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  5130. }else{ Node=ri->UnitMinW;
  5131. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  5132. }
  5133. }
  5134. ui->TL = L + rn->LP;
  5135. ui->TR = ui->TL + Node+NodeAdd;
  5136. ui->TB = ui->TU + rn->H;
  5137. L=ui->TR+rn->RP;
  5138. if (!rn->WaitAnimation){
  5139. ui->L = ui->TL; ui->R = ui->TR;
  5140. ui->U = ui->TU; ui->B = ui->TB;
  5141. }
  5142. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5143. }
  5144. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  5145. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  5146. memset(ri, 0, sizeof(laRowInfo));
  5147. }
  5148. void la_RecordSocketRuntimePosition(laUiItem* ui){
  5149. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5150. int sl,sr,su,sb;
  5151. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  5152. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  5153. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  5154. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  5155. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  5156. if(pc==LA_PC_SOCKET_OUT){
  5157. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5158. }else{
  5159. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5160. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  5161. }
  5162. }
  5163. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  5164. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  5165. }
  5166. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  5167. int laget_Hyper2InstanceModified(void* instance){
  5168. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  5169. if(level==2){
  5170. laManagedUDF* mu=m->FromFile;
  5171. int not_assigned = (!mu) || mu==MAIN.DummyManageUDF|| mu==MAIN.DummyManageUDFSingle || mu==MAIN.DummyManageUDFSingleForce;
  5172. return (m->Modified||not_assigned)?1:0;
  5173. }
  5174. return 1;
  5175. }
  5176. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  5177. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  5178. laBoxedTheme *bt;
  5179. int Lowest = 0;
  5180. int HyperValue = 0;
  5181. int WaitAnimation;
  5182. int RowMode=0; laRowInfo ri={0};
  5183. laBoxedTheme* pt=*(ParentPanel->BT);
  5184. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  5185. int MaxR=0;
  5186. if(!uil->Scale){uil->Scale=1;}
  5187. uil->SaveScale=MAIN.UiScale;
  5188. MAIN.UiScale*=uil->Scale;
  5189. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5190. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  5191. WaitAnimation = 0;
  5192. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  5193. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  5194. for (ui = uil->UiItems.pFirst; ui;){
  5195. int SubB = 0;
  5196. int H;
  5197. WaitAnimation = 0;
  5198. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5199. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  5200. //if (Fast && ui->C->B > B) {
  5201. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  5202. // ui = ui->Item.pNext;
  5203. // continue;
  5204. //}
  5205. if (!ui->Instructions){
  5206. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  5207. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  5208. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  5209. laOperatorProp *ap = ui->PP.LastPs->p;
  5210. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5211. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5212. }
  5213. }
  5214. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5215. la_UsePropPack(&ui->PP, 0);
  5216. if (ui->CompoundPPs.pFirst){
  5217. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5218. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5219. }
  5220. }
  5221. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5222. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5223. // 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);
  5224. //}
  5225. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5226. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5227. WaitAnimation = 1;
  5228. }
  5229. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5230. bt = (*ui->Type->Theme);
  5231. if (ui->Type == &_LA_UI_CONDITION){
  5232. laConditionUiExtraData *cued = ui->Extra;
  5233. la_StepExpression(cued->Expression);
  5234. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5235. if (!cued->IsTrue){
  5236. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5237. }else{
  5238. ui = ui->Item.pNext;
  5239. }
  5240. continue;
  5241. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5242. ui = ui->Item.pNext;
  5243. continue;
  5244. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5245. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5246. if (cued->IsTrue) ui = cued->EndUi;
  5247. else
  5248. ui = ui->Item.pNext;
  5249. continue;
  5250. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5251. laConditionUiExtraData *cued = ui->Extra;
  5252. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5253. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5254. if (!WaitAnimation){
  5255. ui->L = ui->TL; ui->R = ui->TR;
  5256. ui->U = ui->TU; ui->B = ui->TB;
  5257. }
  5258. if(!RowMode){
  5259. la_CalcUiItemInfluence(&uil->Columns, ui);
  5260. }else{
  5261. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5262. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5263. }
  5264. if (ui->State == LA_UI_NORMAL){
  5265. cued->IsTrue = 0;
  5266. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5267. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5268. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5269. }else{
  5270. cued->IsTrue = 1;
  5271. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5272. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5273. //}
  5274. ui = ui->Item.pNext;
  5275. }
  5276. continue;
  5277. }
  5278. if (ui->Type == _LA_UI_ALIGN){
  5279. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5280. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5281. if (ui->TB > Lowest) Lowest = ui->TB;
  5282. if (!WaitAnimation){
  5283. ui->L = ui->TL; ui->R = ui->TR;
  5284. ui->U = ui->TU; ui->B = ui->TB;
  5285. }
  5286. if(!RowMode){
  5287. la_CalcUiItemInfluence(&uil->Columns, ui);
  5288. }else{
  5289. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5290. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5291. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5292. }
  5293. ui = ui->Item.pNext; continue;
  5294. }
  5295. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5296. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5297. la_InitRowNode(&ri, ui, bt);
  5298. RowMode=1; ui=ui->Item.pNext; continue;
  5299. }
  5300. if (ui->Type == &_LA_UI_ROW_END){
  5301. la_CalculateRowExpand(&ri, ui);
  5302. la_CalcUiItemInfluence(&uil->Columns, ui);
  5303. RowMode=0; ui=ui->Item.pNext; continue;
  5304. }
  5305. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5306. int GB=0;
  5307. 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; }
  5308. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5309. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5310. if (H < 0){
  5311. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5312. else{ H=LA_RH; }
  5313. }
  5314. else H *= LA_RH;
  5315. ui->TB = ui->TU;
  5316. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5317. 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
  5318. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5319. if (ui->Type == _LA_UI_COLLECTION){
  5320. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5321. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5322. ui->PP.EndInstance = TInstance;
  5323. laUiList *iuil = ui->Subs.pFirst;
  5324. laUiList *puil = iuil;
  5325. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5326. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5327. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5328. int Begin = ui->TB;
  5329. int SpreadWidth = Spread*LA_RH; if((!uil->AllowScale) && (SpreadWidth > ui->TR-ui->TL)){ SpreadWidth=ui->TR-ui->TL; }
  5330. int EL = ui->TL, ER = Spread?(SpreadWidth+ui->TL):ui->TR; int MaxER=ER;
  5331. int ElementB = ui->TU;
  5332. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5333. int MaxB = ElementB;
  5334. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5335. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5336. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5337. if (!ElementLimit) RowPriority = 0;
  5338. if (!TInstance){
  5339. while (iuil){
  5340. puil = iuil->Item.pNext;
  5341. la_DestroyTabPage(ui, iuil, 0);
  5342. iuil = puil;
  5343. }
  5344. }
  5345. while (TInstance){
  5346. int UiFilterSkip = uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance));
  5347. int ManagerFilterSkip = MAIN.ManagerFilterInstances && (ui->Flags&LA_UI_COLLECTION_MANAGER_FILTER) && (!laget_Hyper2InstanceModified(TInstance));
  5348. if(UiFilterSkip || ManagerFilterSkip){
  5349. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5350. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5351. ui->PP.EndInstance = TInstance; continue;
  5352. }
  5353. if(CanGetTheme){
  5354. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5355. la_SwitchThemeQuick(t, OriginalTheme);
  5356. }
  5357. if(CanGetGap){
  5358. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5359. Gap=g*LA_RH;
  5360. }else Gap=0;
  5361. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5362. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5363. }else GotCategory=0;
  5364. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5365. if (RowPriority){
  5366. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5367. }
  5368. }
  5369. FirstIn=0;
  5370. if (ElementLimit){
  5371. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5372. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth); MaxER=TNS_MAX2(ER,MaxER);
  5373. }
  5374. while (iuil && iuil->Instance != TInstance){
  5375. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5376. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5377. }else{
  5378. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5379. }
  5380. iuil = puil;
  5381. }
  5382. if(!iuil){
  5383. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5384. }
  5385. if (!iuil){
  5386. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5387. la_CalcUiTopInfluence(&uil->Columns, ui);
  5388. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5389. 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);
  5390. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5391. iuil = ui->Page->Item.pNext;
  5392. }else{
  5393. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5394. 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);
  5395. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5396. la_CalcUiItemInfluence(&uil->Columns, ui);
  5397. iuil = iuil->Item.pNext;
  5398. }
  5399. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5400. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5401. ui->PP.EndInstance = TInstance;
  5402. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5403. if (RowPriority){
  5404. Col += 1;
  5405. if (Col >= ElementLimit){
  5406. Col = 0;
  5407. Row += 1;
  5408. Begin = ElementB + bt->TM;
  5409. }
  5410. }elif(Spread){
  5411. EL+=SpreadWidth;
  5412. ER+=SpreadWidth;
  5413. MaxER=TNS_MAX2(ER,MaxER);
  5414. if((!uil->AllowScale) && (ER > ui->TR)){
  5415. EL=ui->TL; ER=SpreadWidth+EL;
  5416. Begin = ElementB + bt->TM;
  5417. }
  5418. }else{
  5419. Row += 1;
  5420. Begin = ElementB + bt->TM;
  5421. if (ElementLimit && Row >= ElementLimit){
  5422. Row = 0;
  5423. Col += 1;
  5424. Begin = ui->TU + bt->TM;
  5425. }
  5426. }
  5427. ui->TB = ElementB;
  5428. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5429. }
  5430. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5431. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5432. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5433. ui->TB = MaxB;
  5434. if(Spread){ ui->TR=MaxER-SpreadWidth; if(ui->TR>MaxR) MaxR=ui->TR; }
  5435. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5436. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5437. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5438. ui->TB=ui->TU+LA_RH;
  5439. }else{
  5440. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5441. ui->PP.EndInstance = TInstance;
  5442. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5443. if(!Template) Template=laui_SubPropInfoDefault;
  5444. //ui->Template = Template;
  5445. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5446. if (!ui->Subs.pFirst && TInstance){
  5447. la_AddInstancePage(ui, TInstance, 0);
  5448. la_CalcUiTopInfluence(&uil->Columns, ui);
  5449. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5450. 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);
  5451. ui->TB = SubB + (NoDecal?0:bt->BM);
  5452. }else if (ui->Subs.pFirst){
  5453. if (!TInstance || TInstance != ui->Page->Instance){
  5454. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5455. ui->Page = 0;
  5456. if (TInstance){
  5457. la_AddInstancePage(ui, TInstance, 0);
  5458. la_CalcUiTopInfluence(&uil->Columns, ui);
  5459. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5460. 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);
  5461. ui->TB = SubB + (NoDecal?0:bt->TM);
  5462. }else
  5463. ui->TB = ui->TU + LA_RH + bt->BM;
  5464. }else{
  5465. 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);
  5466. ui->TB = SubB + (NoDecal?0:bt->BM);
  5467. }
  5468. }
  5469. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5470. ui->TB=ui->TU+LA_RH;
  5471. }
  5472. }
  5473. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5474. if (!WaitAnimation){
  5475. ui->L = ui->TL;
  5476. ui->R = ui->TR;
  5477. ui->U = ui->TU;
  5478. ui->B = ui->TB;
  5479. }
  5480. }
  5481. }else{
  5482. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5483. if (ui->Type != _LA_UI_CANVAS){
  5484. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5485. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5486. SubB = la_UpdateUiListRecursive(ui->Page,
  5487. 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);
  5488. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5489. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5490. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5491. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5492. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5493. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5494. }
  5495. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5496. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5497. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5498. if(ui->Page->HeightCoeff){
  5499. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5500. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5501. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5502. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5503. }
  5504. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5505. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5506. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5507. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5508. }
  5509. }
  5510. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5511. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5512. }else{
  5513. laUiList *suil;
  5514. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5515. la_CalcUiTopInfluence(&uil->Columns, ui);
  5516. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5517. 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);
  5518. }
  5519. }
  5520. ui->TB = ui->TU + H;
  5521. }
  5522. }else ui->TB = ui->TU + H;
  5523. }
  5524. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5525. if(!RowMode){
  5526. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5527. }else{
  5528. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5529. }
  5530. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5531. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5532. ui = ui->Item.pNext;
  5533. }
  5534. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5535. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5536. else uil->TB = Lowest;
  5537. if (!WaitAnimation){
  5538. uil->L = uil->TL;
  5539. uil->R = uil->TR;
  5540. uil->U = uil->TU;
  5541. uil->B = uil->TB;
  5542. }
  5543. MAIN.UiScale=uil->SaveScale;
  5544. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5545. return uil->TB;
  5546. }
  5547. int la_AnimateSingleUiSize(int To, int *Now){
  5548. int Delta;
  5549. if (To != *Now){
  5550. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5551. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5552. *Now += Delta;
  5553. return 1;
  5554. }else
  5555. return 0;
  5556. }
  5557. int la_AnimateUiListRecursive(laUiList *uil){
  5558. laUiItem *ui;
  5559. int Again = 0;
  5560. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5561. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5562. if(ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish){
  5563. ui->B=ui->TB; ui->L=ui->TL; ui->R=ui->TR; ui->U=ui->TU;
  5564. }else{
  5565. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5566. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5567. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5568. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5569. }
  5570. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5571. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5572. laUiList *suil;
  5573. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5574. Again += la_AnimateUiListRecursive(suil);
  5575. }
  5576. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5577. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5578. Again += la_AnimateUiListRecursive(ui->Page);
  5579. }
  5580. }
  5581. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5582. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5583. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5584. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5585. return Again;
  5586. }
  5587. int la_DrawUiItem(laUiItem *ui){
  5588. tnsUseNoTexture();
  5589. tnsColor4d(1, 1, 1, 1);
  5590. tnsVertex2d(ui->L, ui->U);
  5591. tnsVertex2d(ui->R, ui->U);
  5592. tnsVertex2d(ui->R, ui->B);
  5593. tnsVertex2d(ui->L, ui->B);
  5594. tnsPackAs(GL_LINE_LOOP);
  5595. }
  5596. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5597. tnsUseNoTexture();
  5598. tnsColor4d(1, 1, 1, 1);
  5599. tnsVertex2d(ui->L - 1, ui->U - 1);
  5600. tnsVertex2d(ui->R + 1, ui->U - 1);
  5601. tnsVertex2d(ui->R + 1, ui->B + 1);
  5602. tnsVertex2d(ui->L - 1, ui->B + 1);
  5603. tnsPackAs(GL_LINE_LOOP);
  5604. }
  5605. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5606. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5607. return 1;
  5608. }
  5609. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5610. laUiListDrawItem *uildi = uild->Items.pFirst;
  5611. laUiList *Target = uildi->Target;
  5612. int L, R, U, B;
  5613. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5614. L = Target->L + Target->PanX + uildi->DifX;
  5615. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5616. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5617. U = Target->U + Target->PanY + uildi->DifY;
  5618. return la_UiInBound(ui, L, R, U, B);
  5619. }
  5620. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5621. laUiListDrawItem *uildi = uild->Items.pFirst;
  5622. laUiList *Target = uildi->Target;
  5623. int L, R, U, B;
  5624. if (Target){
  5625. L = Target->L + Target->PanX + uildi->DifX;
  5626. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5627. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5628. U = Target->U + Target->PanY + uildi->DifY;
  5629. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5630. return 1;
  5631. }else{
  5632. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5633. return 1;
  5634. }
  5635. }
  5636. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5637. laUiItem *ui = uil->UiItems.pFirst;
  5638. while (!strGetArgument(ui->Instructions, mark))
  5639. ui = ui->Item.pNext;
  5640. return ui;
  5641. }
  5642. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5643. laUiList *uil;
  5644. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5645. if (uil->Instance == Instance) return uil;
  5646. }
  5647. return uil;
  5648. }
  5649. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5650. int mx=(L+R)/2; int my=(U+B)/2;
  5651. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5652. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5653. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5654. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5655. tnsFlush();
  5656. }
  5657. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5658. if(!uil->ScrollerShownV) return;
  5659. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5660. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5661. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5662. int U = uil->U + Offset;
  5663. int B = U + Len;
  5664. int L = UiR - RM*2 - W;
  5665. int R = L + W;
  5666. if (B > U + DisplayH) B = U + DisplayH;
  5667. if (U < uil->U) U = uil->U;
  5668. if (B <= uil->U || U >= uil->B) return;
  5669. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5670. if (U < uil->U) U = uil->U;
  5671. tnsUseNoTexture();
  5672. laBoxedTheme* bt=_LA_THEME_PANEL;
  5673. real* color=laThemeColor(bt, LA_BT_TEXT);
  5674. tnsColor4d(LA_COLOR3(color), 0.2);
  5675. tnsVertex2d(R-RM, uil->U);
  5676. tnsVertex2d(L+RM, uil->U);
  5677. tnsVertex2d(L+RM, uil->U + DisplayH);
  5678. tnsVertex2d(R-RM, uil->U + DisplayH);
  5679. tnsPackAs(GL_TRIANGLE_FAN);
  5680. tnsColor4d(LA_COLOR3(color), 0.5);
  5681. tnsVertex2d(R-RM, uil->U);
  5682. tnsVertex2d(L+RM, uil->U);
  5683. tnsVertex2d(L+RM, uil->U + DisplayH);
  5684. tnsVertex2d(R-RM, uil->U + DisplayH);
  5685. tnsPackAs(GL_LINE_LOOP);
  5686. tnsColor4d(LA_COLOR3(color), 1);
  5687. tnsVertex2d(R, U);
  5688. tnsVertex2d(L, U);
  5689. tnsVertex2d(L, B);
  5690. tnsVertex2d(R, B);
  5691. tnsPackAs(GL_TRIANGLE_FAN);
  5692. int HU=(U+B)/2+LA_RH2;
  5693. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5694. tnsFlush();
  5695. }
  5696. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5697. if(!uil->ScrollerShownH) return;
  5698. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5699. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5700. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5701. int L = uil->L + Offset;
  5702. int R = L + Len;
  5703. int U = UiB - RM - W;
  5704. int B = U + W;
  5705. if (B > U + DisplayW) B = U + DisplayW;
  5706. if (U < uil->U) U = uil->U;
  5707. if (R <= uil->L || L >= uil->R) return;
  5708. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5709. if (L < uil->L) L = uil->L;
  5710. tnsUseNoTexture();
  5711. laBoxedTheme* bt=_LA_THEME_PANEL;
  5712. real* color=laThemeColor(bt, LA_BT_TEXT);
  5713. tnsColor4d(LA_COLOR3(color), 0.2);
  5714. tnsVertex2d(uil->L,U+RM);
  5715. tnsVertex2d(uil->L,B-RM);
  5716. tnsVertex2d(uil->L + DisplayW,B-RM);
  5717. tnsVertex2d(uil->L + DisplayW,U+RM);
  5718. tnsPackAs(GL_TRIANGLE_FAN);
  5719. tnsColor4d(LA_COLOR3(color), 0.5);
  5720. tnsVertex2d(uil->L,U+RM);
  5721. tnsVertex2d(uil->L,B-RM);
  5722. tnsVertex2d(uil->L + DisplayW,B-RM);
  5723. tnsVertex2d(uil->L + DisplayW,U+RM);
  5724. tnsPackAs(GL_LINE_LOOP);
  5725. tnsColor4d(LA_COLOR3(color), 1);
  5726. tnsVertex2d(R, U);
  5727. tnsVertex2d(L, U);
  5728. tnsVertex2d(L, B);
  5729. tnsVertex2d(R, B);
  5730. tnsPackAs(GL_TRIANGLE_FAN);
  5731. int HU=(U+B)/2+LA_RH2;
  5732. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5733. tnsFlush();
  5734. }
  5735. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5736. tnsUseNoTexture();
  5737. tnsColor4dv(color);
  5738. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5739. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5740. tnsPackAs(GL_TRIANGLE_FAN);
  5741. }
  5742. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5743. laSocketRecord* sr;
  5744. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5745. uild->WiresContainer=container;
  5746. }
  5747. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5748. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5749. if(lip->Target==uild->WiresContainer) break;
  5750. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5751. }
  5752. }
  5753. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5754. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5755. int PanX, PanY;
  5756. if(pc==LA_PC_SOCKET_OUT){
  5757. laNodeOutSocket* s=ui->PP.EndInstance;
  5758. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5759. }else{
  5760. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5761. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5762. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5763. }
  5764. }
  5765. void la_RegenerateWireColors(){
  5766. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5767. laTheme* t=MAIN.CurrentTheme;
  5768. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5769. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5770. for(int i=0;i<MAIN.WireColorSlices;i++){
  5771. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5772. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5773. }
  5774. }
  5775. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5776. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5777. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5778. tnsInterpolate2dv(v1,v2,0.5,vi);
  5779. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5780. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5781. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5782. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5783. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5784. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5785. tnsVertex2d(v1[0],v1[1]);
  5786. for(int i=1;i<=steps;i++){
  5787. real ratio=i==steps?1.0f:step*i;
  5788. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5789. tnsVertex2d(v1s[0],v1s[1]);
  5790. }
  5791. }
  5792. void la_DrawNodeWires(laUiListDraw* uild){
  5793. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5794. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5795. tnsUseNoTexture();
  5796. #define _RSLICES 16
  5797. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5798. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5799. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5800. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5801. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5802. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5803. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5804. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5805. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5806. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5807. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5808. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5809. }
  5810. if(MAIN.tNodeIn->Source){
  5811. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5812. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5813. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5814. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5815. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5816. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5817. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5818. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5819. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5820. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5821. }
  5822. #undef _RSLICES
  5823. tnsFlush();
  5824. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5825. glLineWidth(ww);
  5826. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5827. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5828. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5829. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5830. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5831. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5832. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5833. }
  5834. if(MAIN.tNodeIn->Source){
  5835. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5836. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5837. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5838. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5839. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5840. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5841. }
  5842. tnsFlush();
  5843. glLineWidth(1);
  5844. la_InitSocketRecord(uild,0);
  5845. }
  5846. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5847. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5848. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5849. }
  5850. 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){
  5851. laUiItem *ui;
  5852. laBoxedTheme *bt;
  5853. laUiList *sub;
  5854. laUiListDrawItem *uildi;
  5855. int Ret = 0;
  5856. if (!uil) return 0;
  5857. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5858. ui = uil->UiItems.pFirst;
  5859. if(uil->PanY<0){uil->PanY=0;}
  5860. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5861. uil->SaveScale=MAIN.UiScale;
  5862. MAIN.UiScale*=uil->Scale;
  5863. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5864. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5865. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5866. if (ui->Type == &_LA_UI_CONDITION){
  5867. laConditionUiExtraData *cued = ui->Extra;
  5868. la_StepExpression(cued->Expression);
  5869. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5870. if (!cued->IsTrue){
  5871. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5872. }else{
  5873. ui = ui->Item.pNext;
  5874. }
  5875. continue;
  5876. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5877. ui = ui->Item.pNext;
  5878. continue;
  5879. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5880. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5881. if (cued->IsTrue) ui = cued->EndUi;
  5882. else
  5883. ui = ui->Item.pNext;
  5884. continue;
  5885. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5886. laConditionUiExtraData *cued = ui->Extra;
  5887. ui->Type->Draw(ui, LA_RH);
  5888. if (ui->State == LA_UI_NORMAL){
  5889. cued->IsTrue = 0;
  5890. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5891. }else{
  5892. cued->IsTrue = 1;
  5893. ui = ui->Item.pNext;
  5894. }
  5895. continue;
  5896. }
  5897. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5898. int NeedDraw=0;
  5899. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5900. if(NeedDraw){
  5901. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5902. }else{ ui->Type->Draw(ui, LA_RH); }
  5903. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5904. tnsFlush();
  5905. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5906. tnsResetViewMatrix();
  5907. }
  5908. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5909. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5910. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5911. tnsFlush();
  5912. }
  5913. }
  5914. if(NeedDraw || RegisterNodes){
  5915. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5916. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5917. ui->Type == _LA_UI_TAB ||
  5918. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5919. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5920. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5921. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5922. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5923. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5924. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5925. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5926. 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); }
  5927. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5928. 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);
  5929. 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)); }
  5930. }elif (ui->Type == _LA_UI_COLLECTION){
  5931. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5932. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5933. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5934. void* SaveInstance = ui->PP.EndInstance;
  5935. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5936. int State;
  5937. ui->PP.EndInstance = sub->Instance;
  5938. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5939. if(NeedDraw){ int drawn=0;
  5940. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5941. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5942. }
  5943. if (CanGetState && !drawn){
  5944. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5945. if(State >= 0){
  5946. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5947. }
  5948. }
  5949. }
  5950. if(sub->TabName && sub->TabName->Ptr){
  5951. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5952. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5953. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5954. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5955. tnsFlush();
  5956. }
  5957. if(CanGetTheme){
  5958. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5959. la_SwitchThemeQuick(t, OriginalTheme);
  5960. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5961. }
  5962. tnsFlush();
  5963. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5964. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5965. }
  5966. //ui->PP.EndInstance = Active;
  5967. ui->PP.EndInstance = SaveInstance;
  5968. }elif (ui->Type == _LA_UI_CANVAS){
  5969. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5970. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5971. tnsFlush();
  5972. 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);
  5973. }
  5974. }
  5975. }
  5976. ui = ui->Item.pNext;
  5977. }else{
  5978. ui = ui->Item.pNext;
  5979. }
  5980. }
  5981. tnsFlush();
  5982. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5983. la_RestoreLastUiListMatrix(uild, B - U);
  5984. MAIN.UiScale=uil->SaveScale;
  5985. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5986. return Ret;
  5987. }
  5988. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5989. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5990. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5991. tnsUseNoTexture();
  5992. tnsColor4d(1, 1, 1, 1);
  5993. tnsVertex2d(L, U);
  5994. tnsVertex2d(R, U);
  5995. tnsVertex2d(R, B);
  5996. tnsVertex2d(L, B);
  5997. tnsPackAs(GL_LINE_LOOP);
  5998. tnsVertex2d(L + 3, Begin);
  5999. tnsVertex2d(R - 3, Begin);
  6000. tnsVertex2d(R - 3, End);
  6001. tnsVertex2d(L + 3, End);
  6002. tnsPackAs(GL_LINE_LOOP);
  6003. }
  6004. int laIsInUiItem(laUiItem *ui, int x, int y){
  6005. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  6006. return 1;
  6007. }
  6008. int laIsInBound(int x, int y, int l, int r, int u, int b){
  6009. if (x < l || x > r || y < u || y > b) return 0;
  6010. return 1;
  6011. }
  6012. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  6013. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  6014. laUiItem *ui, *tui;
  6015. laBoxedTheme *bt;
  6016. laUiList *sub;
  6017. int CPB = 0;
  6018. if (!uil || (LimB && y > LimB)) return 0;
  6019. x += uil->PanX;
  6020. y += uil->PanY;
  6021. for (ui = uil->UiItems.pFirst; ui;){
  6022. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6023. if (ui->Type == &_LA_UI_CONDITION){
  6024. laConditionUiExtraData *cued = ui->Extra;
  6025. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  6026. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6027. if (!cued->IsTrue){
  6028. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6029. }else{
  6030. ui = ui->Item.pNext;
  6031. }
  6032. continue;
  6033. }else if (ui->Type == &_LA_UI_CONDITION_END){
  6034. ui = ui->Item.pNext;
  6035. continue;
  6036. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6037. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6038. if (cued->IsTrue) ui = cued->EndUi;
  6039. else
  6040. ui = ui->Item.pNext;
  6041. continue;
  6042. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6043. laConditionUiExtraData *cued = ui->Extra;
  6044. if (laIsInUiItem(ui, x, y)){
  6045. lstAppendPointer(LocalBuf, uil);
  6046. return ui;
  6047. }
  6048. if (ui->State == LA_UI_NORMAL){
  6049. cued->IsTrue = 0;
  6050. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6051. }else{
  6052. cued->IsTrue = 1;
  6053. ui = ui->Item.pNext;
  6054. }
  6055. continue;
  6056. }
  6057. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  6058. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  6059. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  6060. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  6061. if(!la_DetectSplit(ui->C, x)) Add=0;
  6062. }
  6063. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  6064. }
  6065. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6066. if (ui->Page->HeightCoeff) CPB = ui->B;
  6067. else CPB = ui->Page->B;
  6068. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6069. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  6070. lstAppendPointer(LocalBuf, uil);
  6071. return tui;
  6072. }
  6073. }else if (laIsInUiItem(ui, x, y)){
  6074. lstAppendPointer(LocalBuf, uil);return ui;
  6075. }
  6076. }
  6077. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  6078. if (laIsInUiItem(ui, x, y)){
  6079. lstAppendPointer(LocalBuf, uil);
  6080. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  6081. if(Deep){
  6082. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  6083. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  6084. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  6085. lstAppendPointer(LocalBuf, iuil);
  6086. return tui;
  6087. }
  6088. }
  6089. }
  6090. }
  6091. return ui;
  6092. }
  6093. }
  6094. if (ui->Type == _LA_UI_CANVAS){
  6095. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6096. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6097. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  6098. lstAppendPointer(LocalBuf, uil);
  6099. return tui;
  6100. }
  6101. }
  6102. }
  6103. if (laIsInUiItem(ui, x, y)){
  6104. lstAppendPointer(LocalBuf, uil);
  6105. return ui;
  6106. }
  6107. }
  6108. ui = ui->Item.pNext;
  6109. }
  6110. return 0;
  6111. }
  6112. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  6113. laListHandle Locals={0};
  6114. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  6115. while(lstPopPointer(&Locals));
  6116. //printf("%s\n", ui?ui->Type->Identifier:"?");
  6117. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  6118. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  6119. if(pc==PCInOrOut) return ui;
  6120. }
  6121. return 0;
  6122. }
  6123. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  6124. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  6125. laUiItem *ui = uil->UiItems.pFirst;
  6126. laBoxedTheme *bt;
  6127. laUiList *tuil;
  6128. laUiList *sub;
  6129. int CPB = 0;
  6130. x += uil->PanX;
  6131. y += uil->PanY;
  6132. if (y > LimH) return uil;
  6133. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  6134. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  6135. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6136. return uil;
  6137. }
  6138. for (ui = uil->UiItems.pFirst; ui;){
  6139. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6140. if (ui->Type == &_LA_UI_CONDITION){
  6141. laConditionUiExtraData *cued = ui->Extra;
  6142. //la_StepExpression(cued->Expression);
  6143. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6144. if (!cued->IsTrue){
  6145. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6146. }else{
  6147. ui = ui->Item.pNext;
  6148. }
  6149. continue;
  6150. }
  6151. if (ui->Type == &_LA_UI_CONDITION_END){
  6152. ui = ui->Item.pNext;
  6153. continue;
  6154. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6155. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6156. if (cued->IsTrue) ui = cued->EndUi;
  6157. else
  6158. ui = ui->Item.pNext;
  6159. continue;
  6160. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6161. laConditionUiExtraData *cued = ui->Extra;
  6162. if (ui->State == LA_UI_NORMAL){
  6163. cued->IsTrue = 0;
  6164. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6165. }else{
  6166. cued->IsTrue = 1;
  6167. ui = ui->Item.pNext;
  6168. }
  6169. continue;
  6170. }
  6171. if (InToContainerUI && ui != Exception){
  6172. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6173. if (ContainerParent) (*ContainerParent) = uil;
  6174. if (ParentUi) *ParentUi = ui;
  6175. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6176. //if (y > LimH) return uil;
  6177. 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))){
  6178. return tuil;
  6179. }
  6180. }
  6181. }
  6182. }
  6183. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6184. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  6185. else CPB = ui->Page->B;
  6186. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6187. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6188. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6189. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6190. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6191. if (ParentUi) *ParentUi = ui;
  6192. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  6193. }
  6194. }
  6195. ui = ui->Item.pNext;
  6196. }
  6197. return uil;
  6198. }
  6199. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  6200. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  6201. laUiItem *ui = uil->UiItems.pFirst;
  6202. laBoxedTheme *bt;
  6203. laUiList *tuil;
  6204. laUiList *sub;
  6205. int CPB = 0;
  6206. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  6207. x += uil->PanX;
  6208. y += uil->PanY;
  6209. if (y > LimH) return uil;
  6210. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  6211. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  6212. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6213. return uil;
  6214. }
  6215. for (ui = uil->UiItems.pFirst; ui;){
  6216. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6217. if (ui->Type == &_LA_UI_CONDITION){
  6218. laConditionUiExtraData *cued = ui->Extra;
  6219. //la_StepExpression(cued->Expression);
  6220. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6221. if (!cued->IsTrue){
  6222. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6223. }else{
  6224. ui = ui->Item.pNext;
  6225. }
  6226. continue;
  6227. }
  6228. if (ui->Type == &_LA_UI_CONDITION_END){
  6229. ui = ui->Item.pNext;
  6230. continue;
  6231. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6232. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6233. if (cued->IsTrue) ui = cued->EndUi;
  6234. else
  6235. ui = ui->Item.pNext;
  6236. continue;
  6237. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6238. laConditionUiExtraData *cued = ui->Extra;
  6239. if (ui->State == LA_UI_NORMAL){
  6240. cued->IsTrue = 0;
  6241. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6242. }else{
  6243. cued->IsTrue = 1;
  6244. ui = ui->Item.pNext;
  6245. }
  6246. continue;
  6247. }
  6248. if (InToContainerUI && ui != Exception){
  6249. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6250. if (ContainerParent) (*ContainerParent) = uil;
  6251. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6252. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6253. //if (y > LimH) return uil;
  6254. 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))){
  6255. return tuil;
  6256. }
  6257. }
  6258. }
  6259. }
  6260. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6261. if (ui->Page->HeightCoeff) CPB = ui->B;
  6262. else CPB = ui->Page->B;
  6263. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6264. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6265. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6266. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6267. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6268. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6269. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6270. }
  6271. }
  6272. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6273. if (ui->Page->HeightCoeff) CPB = ui->B;
  6274. else
  6275. CPB = ui->Page->B;
  6276. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6277. if (ScrollUil) *ScrollUil = ui->Page;
  6278. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6279. }
  6280. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6281. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6282. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6283. }
  6284. }
  6285. ui = ui->Item.pNext;
  6286. }
  6287. return uil;
  6288. }
  6289. int la_TestUiListMinumWidth(laUiList *uil){
  6290. laUiItem *ui, *tui;
  6291. laBoxedTheme *bt;
  6292. laUiList *sub;
  6293. int CPB = 0;
  6294. int W = 0;
  6295. int tW, sW, RowMode=0, rW;
  6296. void *Restore;
  6297. for (ui = uil->UiItems.pFirst; ui;){
  6298. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6299. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6300. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6301. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6302. if (W < tW) W = tW;
  6303. }elif (ui->Type == _LA_UI_COLLECTION){
  6304. Restore = ui->PP.EndInstance;
  6305. tW = 0; sW = 0;
  6306. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6307. ui->PP.EndInstance = sub->Instance;
  6308. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6309. if (sW > tW) tW = sW;
  6310. }
  6311. ui->PP.EndInstance = Restore;
  6312. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6313. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6314. if (W < tW) W = tW;
  6315. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6316. RowMode=1; rW=0;
  6317. }elif (ui->Type==&_LA_UI_ROW_END){
  6318. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6319. }elif (ui->Type->GetMinWidth){
  6320. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6321. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6322. }
  6323. ui = ui->Item.pNext;
  6324. }
  6325. return W;
  6326. }
  6327. void la_InitLLVM(){
  6328. //LLVMLinkInMCJIT();
  6329. //LLVMInitializeNativeTarget();
  6330. //LLVMInitializeNativeAsmPrinter();
  6331. //LLVMInitializeNativeAsmParser();
  6332. // MAIN.llvmContext = LLVMGetGlobalContext();
  6333. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6334. }
  6335. //==================================================================================================
  6336. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6337. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6338. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6339. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6340. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6341. memFree(kmi);
  6342. }
  6343. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6344. laKeyMapItem *kmi;
  6345. if (!km) return 0;
  6346. kmi = memAcquire(sizeof(laKeyMapItem));
  6347. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6348. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6349. }else{
  6350. strSafeSet(&kmi->Operation, Operation);
  6351. }
  6352. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6353. kmi->SpecialKeyBits = SpecialKeyBits;
  6354. kmi->EventType = EventType;
  6355. kmi->Key = tolowerGuarded(Key);
  6356. kmi->SelectBase = SelectBase;
  6357. lstAppendItem(&km->Items, kmi);
  6358. return kmi;
  6359. }
  6360. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6361. laKeyMapItem *kmi; int inv=0;
  6362. char *instructions;
  6363. if(e->type==LA_MOUSEMOVE) return 0;
  6364. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6365. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6366. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6367. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6368. if (kmi->Operation)
  6369. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6370. else
  6371. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6372. inv = 1;
  6373. }
  6374. }
  6375. return inv;
  6376. }
  6377. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6378. laKeyMapItem *kmi;
  6379. char *instructions;
  6380. int inv = 0; int lx = -1, ly = -1;
  6381. if(e->type==LA_MOUSEMOVE) return 0;
  6382. if(e->type == LA_OPERATOR_EVENT && e->OperatorBase){
  6383. if (e->OperatorBase == LA_KM_SEL_UI_EXTRA){
  6384. laInvokeP(from, e->Operator, e, UiExtra, e->OperatorInstructions, 0);
  6385. }elif (e->OperatorBase == LA_KM_SEL_PANEL){
  6386. laInvokeP(from, e->Operator, e, &((laPanel *)MAIN.ToPanel)->PP, e->OperatorInstructions, 0);
  6387. }
  6388. return 1;
  6389. }
  6390. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6391. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6392. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6393. if (e->Localized){
  6394. lx = e->x;
  6395. ly = e->y;
  6396. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6397. e->Localized = 0;
  6398. }
  6399. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6400. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6401. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6402. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6403. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6404. }elif (kmi->Operation){
  6405. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6406. }else{
  6407. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6408. }
  6409. inv = 1;
  6410. if (lx >= 0){
  6411. e->x = lx;
  6412. e->y = ly;
  6413. e->Localized = 1;
  6414. }
  6415. }
  6416. }
  6417. return inv;
  6418. }
  6419. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6420. void la_DestroyOperatorType(laOperatorType* at){
  6421. //if(at->PC) la_FreePropertyContainer(at->PC);
  6422. memFree(at);
  6423. }
  6424. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6425. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6426. uint32_t IconID, int ExtraMark){
  6427. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6428. at->Identifier = ID;
  6429. at->Name = Name;
  6430. at->Description = Description;
  6431. at->Check = Check;
  6432. at->Invoke = Invoke;
  6433. at->Init = Init;
  6434. at->Exit = Exit;
  6435. at->Modal = Modal;
  6436. at->IconID = IconID;
  6437. at->ExtraMark = ExtraMark;
  6438. at->ParseArgs = la_DefaultOperatorParser;
  6439. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6440. lstAppendItem2(&MAIN.OperatorList, at);
  6441. return at;
  6442. }
  6443. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6444. ot->PC = memAcquire(sizeof(laPropContainer));
  6445. ot->PC->Identifier = ot->Identifier;
  6446. ot->PC->Hyper = HyperLevel;
  6447. return ot->PC;
  6448. }
  6449. laOperator *la_CreateOperator(laOperatorType *at){
  6450. laOperator *a = CreateNew(laOperator);
  6451. a->Type = at;
  6452. if (at->PC && at->PC->Props.pFirst){
  6453. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6454. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6455. a->PP.LastPs->p->SubProp = at->PC;
  6456. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6457. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6458. a->PP.LastPs->Type = U'.';
  6459. }
  6460. return a;
  6461. }
  6462. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6463. return (!strcmp(a->Identifier, id));
  6464. }
  6465. laOperatorType *laGetOperatorType(const char *ID){
  6466. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6467. }
  6468. int laOperatorExistsT(laOperatorType* at){
  6469. if (!at) return 0;
  6470. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6471. return 0;
  6472. }
  6473. int laOperatorExists(const char* ID){
  6474. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6475. return laOperatorExistsT(at);
  6476. }
  6477. int la_OperatorExists(laOperator *ac){
  6478. if (!ac) return 0;
  6479. laOperator *a;
  6480. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6481. return 0;
  6482. }
  6483. int la_UiOperatorExists(void *inst){
  6484. laOperator *a;
  6485. if (!inst) return 0;
  6486. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6487. if (((laUiItem *)a->Instance) == inst){
  6488. return 1;
  6489. }
  6490. }
  6491. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6492. if (a->Instance == inst){
  6493. return 1;
  6494. }
  6495. }
  6496. return 0;
  6497. }
  6498. int la_OperatorPending(laOperator *target){
  6499. laOperator *a;
  6500. if (!target) return 0;
  6501. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6502. if (a == target){
  6503. return 1;
  6504. }
  6505. }
  6506. return 0;
  6507. }
  6508. void laSetOperatorLocalizer(void *ToPanel){
  6509. MAIN.ToPanel = ToPanel;
  6510. }
  6511. void la_DestroyConfirmData(laConfirmData **cd);
  6512. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6513. laOperator *ai = (*a);
  6514. laOperator *ac = ((*a)->Child);
  6515. void *Ret = 0;
  6516. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6517. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6518. }
  6519. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6520. if ((*a)->PP.LastPs){
  6521. memFree((*a)->PP.LastPs->p);
  6522. memFree((*a)->PP.LastPs);
  6523. }
  6524. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6525. la_SetPropMathcerContext((*a)->OperatorPanel);
  6526. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6527. laDestroySinglePanel((*a)->OperatorPanel,0);
  6528. }
  6529. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6530. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6531. lstClearPointer(&(*a)->LocalUiLists);
  6532. if (Operators){
  6533. Ret = ai->Item.pNext;
  6534. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6535. else
  6536. lstRemoveItem(Operators, *a);
  6537. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6538. if (ai->Child == (*a)) ai->Child = 0;
  6539. }
  6540. }
  6541. strSafeDestroy(&(*a)->RuntimeHint);
  6542. free(*a);
  6543. return Ret;
  6544. }
  6545. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6546. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6547. if (!at) return 0;
  6548. if (!at->Check) return 1;
  6549. return (at->Check(This, Instructions));
  6550. }
  6551. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6552. if (!at) return 0;
  6553. if (!at->Check) return 1;
  6554. return (at->Check(This, Instructions));
  6555. }
  6556. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6557. laPropPack FakePP = {0};
  6558. laPropStep FakePs = {0};
  6559. if (!at) return 0;
  6560. if (!at->Check) return 1;
  6561. FakePP.LastPs = &FakePs;
  6562. FakePP.Go = FakePP.LastPs;
  6563. FakePP.LastPs->p = This->LastPs->p;
  6564. FakePP.LastPs->UseInstance = This->EndInstance;
  6565. FakePP.EndInstance = Real_FromInstance;
  6566. FakePP.LastIndex = This->LastIndex;
  6567. return (at->Check(&FakePP, Instructions));
  6568. }
  6569. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6570. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6571. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6572. }
  6573. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6574. laOperator *a, *f = From;
  6575. int rev;
  6576. if (!f && e&&e->Localized) return -1;
  6577. a = la_CreateOperator(at);
  6578. a->ToPanel = MAIN.ToPanel;
  6579. a->This = This;
  6580. a->ExtraInstructions = args;
  6581. strMakeInstructions(&a->ExtraInstructionsP, args);
  6582. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6583. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6584. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6585. la_DestroyOperator(&a, 0, 0);
  6586. return LA_CANCELED;
  6587. }
  6588. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6589. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6590. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6591. e->Localized = 1;
  6592. }
  6593. if (e&&e->Localized){
  6594. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6595. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6596. e->Localized = 0;
  6597. }else{
  6598. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6599. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6600. }
  6601. }
  6602. if (From) f->Child = a;
  6603. a->Using = 1;
  6604. if (at->Init) at->Init(a);
  6605. rev = at->Invoke(a, e);
  6606. a->Using = 0;
  6607. if (rev & LA_FINISH){
  6608. a->StopNow = 1; if(From)From->Child=0;
  6609. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6610. }
  6611. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6612. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6613. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6614. a->State = rev;
  6615. a->PP.EndInstance = a->CustomData;
  6616. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6617. }else
  6618. la_DestroyOperator(&a, 0, 0);
  6619. return rev;
  6620. }
  6621. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6622. laOperatorType *at; laOperator *a, *f = From;
  6623. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6624. if (!at) return -1;
  6625. return laInvokeP(From,at,e,This,args,args2);
  6626. }
  6627. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6628. laOperator *a, *f = From;
  6629. int rev;
  6630. laPropPack *created;
  6631. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6632. created = memAcquireSimple(sizeof(laPropPack));
  6633. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6634. created->Go = created->LastPs;
  6635. created->LastPs->p = OrigionalThis->LastPs->p;
  6636. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6637. created->EndInstance = FromInstance;
  6638. created->LastIndex = OrigionalThis->LastIndex;
  6639. a = la_CreateOperator(at);
  6640. a->ToPanel = MAIN.ToPanel;
  6641. a->This = created;
  6642. a->CreatedThis = created;
  6643. a->ExtraInstructions = args;
  6644. strMakeInstructions(&a->ExtraInstructionsP, args);
  6645. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6646. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6647. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6648. la_DestroyOperator(&a, 0, 0);
  6649. return LA_CANCELED;
  6650. }
  6651. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6652. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6653. if (From) f->Child = a;
  6654. a->Using = 1;
  6655. if (at->Init) at->Init(a);
  6656. rev = at->Invoke(a, e);
  6657. a->Using = 0;
  6658. if (rev & LA_FINISH){
  6659. a->StopNow = 1; if(From)From->Child=0;
  6660. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6661. }
  6662. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6663. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6664. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6665. a->State = rev;
  6666. a->PP.EndInstance = a->CustomData;
  6667. }else
  6668. la_DestroyOperator(&a, 0, 0);
  6669. return rev;
  6670. }
  6671. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6672. laOperator *a, *f = From;
  6673. int rev;
  6674. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6675. a = la_CreateOperator(at);
  6676. a->Instance = inst;
  6677. a->ToPanel = MAIN.ToPanel;
  6678. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6679. if (From) f->Child = a;
  6680. a->Using = 1;
  6681. if (at->Init) at->Init(a);
  6682. rev = at->Invoke(a, e);
  6683. a->Using = 0;
  6684. if (rev & LA_FINISH){
  6685. a->StopNow = 1; if(From)From->Child=0;
  6686. }
  6687. if (rev & LA_BLOCK){
  6688. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6689. a->State = rev;
  6690. }else la_DestroyOperator(&a, 0, 0);
  6691. DEB = a;
  6692. return rev;
  6693. }
  6694. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6695. laOperatorType *at;
  6696. laOperator *a, *f = From;
  6697. if (la_UiOperatorExists(inst)) return -1;
  6698. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6699. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6700. }
  6701. void laRequestDelayEvent(real Seconds){
  6702. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6703. int la_UiStillInService(void *UiInstance){
  6704. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6705. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6706. if (ai->Instance == UiInstance) return 1;
  6707. }
  6708. return 0;
  6709. }
  6710. void la_StopUiOperatorService(void *UiInstance){
  6711. laOperator *ai, *dai, *NextAi;
  6712. if (!MAIN.CurrentWindow) return;
  6713. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6714. NextAi = ai->Item.pNext;
  6715. if (ai->Instance == UiInstance){
  6716. if (ai->Child){
  6717. la_StopUiOperatorService(ai->Child->Instance);
  6718. ai->Child = 0;
  6719. }
  6720. laOperator *dai = ai;
  6721. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6722. continue;
  6723. }
  6724. }
  6725. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6726. NextAi = ai->Item.pNext;
  6727. if (ai->Instance == UiInstance){
  6728. if (ai->Instance == ai->ToPanel){
  6729. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6730. //ai->ToPanel->LaterDestroy = 1;
  6731. }
  6732. if (ai->Child && la_OperatorExists(ai->Child)){
  6733. la_StopUiOperatorService(ai->Child->Instance);
  6734. //ai->Child = 0;
  6735. }
  6736. if (!ai->Using){
  6737. laOperator *dai = ai;
  6738. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6739. }else
  6740. ai->StopNow = 1;
  6741. }
  6742. }
  6743. }
  6744. void la_StopAllOperators(){
  6745. laOperator *ai, *dai, *NextAi;
  6746. if (!MAIN.CurrentWindow) return;
  6747. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6748. NextAi = ai->Item.pNext;
  6749. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6750. continue;
  6751. }
  6752. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6753. NextAi = ai->Item.pNext;
  6754. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6755. laHidePanelWithDissoveEffect(ai->ToPanel);
  6756. ai->ToPanel->LaterDestroy = 1;
  6757. }
  6758. if (!ai->Using){
  6759. laOperator *dai = ai;
  6760. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6761. }else ai->StopNow = 1;
  6762. }
  6763. }
  6764. void la_DestroyConfirmData(laConfirmData **cd){
  6765. if((!cd)||!(*cd)) return;
  6766. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6767. if ((*cd)->StrData) free((*cd)->StrData);
  6768. FreeMem((*cd));
  6769. (*cd) = 0;
  6770. }
  6771. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6772. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6773. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6774. ai->NextConfirmData = cd; laRetriggerOperators();
  6775. }
  6776. void laConfirmInt(laOperator *a, int Data, int mode){
  6777. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6778. cd->IData = Data; cd->Mode = mode;
  6779. ai->NextConfirmData = cd; laRetriggerOperators();
  6780. }
  6781. void laConfirmFloat(laOperator *a, real Data, int mode){
  6782. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6783. cd->FData = Data; cd->Mode = mode;
  6784. ai->NextConfirmData = cd; laRetriggerOperators();
  6785. }
  6786. void laConfirmString(laOperator *a, char *Str, int mode){
  6787. laOperator *ai = a;
  6788. laConfirmData *cd = CreateNew(laConfirmData);
  6789. int len = strlen(Str);
  6790. char *buf = calloc(len + 1, sizeof(char));
  6791. strcpy(buf, Str);
  6792. cd->StrData = buf;
  6793. cd->Mode = mode;
  6794. cd->Destroy = free;
  6795. ai->NextConfirmData = cd;
  6796. laRetriggerOperators();
  6797. }
  6798. int laConfirmSameDataIfAny(laOperator *a){
  6799. laOperator *ai = a;
  6800. laConfirmData *cd;
  6801. char *buf = 0;
  6802. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6803. cd = CreateNew(laConfirmData);
  6804. if (ai->ConfirmData->StrData){
  6805. int len = strlen(ai->ConfirmData->StrData);
  6806. buf = calloc(len + 1, sizeof(char));
  6807. strcpy(buf, ai->ConfirmData->StrData);
  6808. }
  6809. //cd->CustomData = cd->CustomData;
  6810. cd->IData = ai->ConfirmData->IData;
  6811. cd->FData = ai->ConfirmData->FData;
  6812. cd->PointerData = ai->ConfirmData->PointerData;
  6813. cd->PointerType = a->ConfirmData->PointerType;
  6814. cd->StrData = buf;
  6815. cd->Mode = ai->ConfirmData->Mode;
  6816. cd->Destroy = ai->ConfirmData->Destroy;
  6817. ai->NextConfirmData = cd;
  6818. laRetriggerOperators();
  6819. return 1;
  6820. }
  6821. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6822. laOperator *ai = a;
  6823. laConfirmData *cd = CreateNew(laConfirmData);
  6824. cd->CustomData = UserData;
  6825. cd->Mode = mode;
  6826. cd->Destroy = Destroy;
  6827. ai->NextConfirmData = cd;
  6828. laRetriggerOperators();
  6829. }
  6830. int laGetConfirmMode(laOperator *a){
  6831. return ((laOperator *)a)->ConfirmData->Mode;
  6832. }
  6833. int laGetConfirmInt(laOperator *a){
  6834. laOperator *ai = a;
  6835. int rev = ai->ConfirmData->IData;
  6836. la_DestroyConfirmData(&ai->ConfirmData);
  6837. ai->ConfirmData = 0;
  6838. return rev;
  6839. }
  6840. real laGetConfirmFloat(laOperator *a){
  6841. laOperator *ai = a;
  6842. real rev = ai->ConfirmData->FData;
  6843. la_DestroyConfirmData(&ai->ConfirmData);
  6844. ai->ConfirmData = 0;
  6845. return rev;
  6846. }
  6847. void laGetConfirmString(laOperator *a, char *buf){
  6848. laOperator *ai = a;
  6849. strcpy(buf, ai->ConfirmData->StrData);
  6850. la_DestroyConfirmData(&ai->ConfirmData);
  6851. ai->ConfirmData = 0;
  6852. }
  6853. void *laGetConfirmUserData(laOperator *a){
  6854. laOperator *ai = a;
  6855. return ai->ConfirmData->CustomData;
  6856. }
  6857. void laFinalizeOperators(){
  6858. laOperatorType *at;
  6859. laListHandle *lst;
  6860. int i;
  6861. for (i = 0; i < 256; i++){
  6862. lst = &MAIN.OperatorTypeHash.Entries[i];
  6863. for (at = lst->pFirst; at; at = at->Item.pNext){
  6864. if (at->PC && at->PC->Props.pFirst){
  6865. lstAppendItem(&MAIN.PropContainers, at->PC);
  6866. }
  6867. }
  6868. }
  6869. }
  6870. //=================
  6871. #ifdef LA_LINUX
  6872. static void la_RecordWacomMotions(XIRawEvent *event)
  6873. {
  6874. double *valuator = event->valuators.values;
  6875. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6876. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6877. //SYSWINDOW root_return, child_return;
  6878. //int root_x_return, root_y_return;
  6879. //int win_x_return, win_y_return;
  6880. //unsigned int mask_return;
  6881. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6882. // &root_x_return, &root_y_return,
  6883. // &win_x_return, &win_y_return,
  6884. // &mask_return);
  6885. //
  6886. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6887. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6888. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6889. real x=valuator[3],y=valuator[4];
  6890. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6891. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6892. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6893. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6894. if(XIMaskIsSet(event->valuators.mask, 5)){
  6895. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6896. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6897. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6898. MAIN.IsPen=1;
  6899. }
  6900. #endif
  6901. #ifdef _WIN32
  6902. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6903. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6904. static uint32_t ch = 0; static int lead = 0;
  6905. static wchar_t buf[10] = { 0 }; int adv;
  6906. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6907. short wheelmark = 0;
  6908. int WheelDir = 0;
  6909. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6910. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6911. POINT point;
  6912. PACKET pkt;
  6913. static POINT ptOld, ptNew;
  6914. static UINT prsOld, prsNew, vkey;
  6915. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6916. switch (message) {
  6917. case WM_PAINT:
  6918. //SwapBuffers(GetDC(hwnd));
  6919. break;
  6920. case WM_MOUSEMOVE:
  6921. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6922. MAIN.IsPen = 0;
  6923. break;
  6924. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6925. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6926. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6927. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6928. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6929. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6930. case WM_MOUSEWHEEL:
  6931. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6932. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6933. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6934. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6935. break;
  6936. case WT_PACKET:
  6937. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6938. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6939. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6940. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6941. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6942. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6943. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6944. MAIN.StylusTwist = tw;
  6945. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6946. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6947. MAIN.EraserPressure = MAIN.StylusPressure;
  6948. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6949. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6950. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6951. }
  6952. return 0; break;
  6953. case WM_SYSCOMMAND:
  6954. switch (wparam) {
  6955. case SC_MAXIMIZE:
  6956. case SC_RESTORE:
  6957. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6958. break;
  6959. case SC_KEYMENU:
  6960. return 0;
  6961. case SC_MINIMIZE:
  6962. break;
  6963. }
  6964. break;
  6965. case WM_SIZE:
  6966. if (wparam == SIZE_MINIMIZED) break;
  6967. case WM_MOVE: /* And size */
  6968. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6969. break;
  6970. case WM_SETCURSOR:
  6971. if(MAIN.CurrentCursor) return 1;
  6972. break;
  6973. case WM_POINTERDOWN:
  6974. case WM_POINTERUP:
  6975. case WM_POINTERUPDATE:
  6976. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6977. pointerId = GET_POINTERID_WPARAM(wparam);
  6978. pointerType = PT_POINTER;
  6979. if(!GetPointerType(pointerId, &pointerType)){
  6980. pointerType = PT_POINTER;
  6981. }
  6982. if(pointerType == PT_PEN){
  6983. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6984. for (int i = peninfonum-1; i>=0; i--) {
  6985. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6986. ScreenToClient(hwnd, &point);
  6987. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6988. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6989. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6990. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6991. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6992. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6993. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6994. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6995. }
  6996. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6997. }
  6998. }
  6999. SkipPointerFrameMessages(pointerId);
  7000. return 0;
  7001. }
  7002. else if (pointerType == PT_TOUCH){
  7003. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  7004. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  7005. ScreenToClient(hwnd, &point);
  7006. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  7007. }
  7008. }
  7009. break;
  7010. case WM_SYSKEYDOWN:
  7011. if (lparam & 0x40000000) break;
  7012. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  7013. break;
  7014. case WM_KEYDOWN:
  7015. if (lparam & 0x40000000) break;
  7016. vkey = wparam;
  7017. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  7018. break;
  7019. case WM_KEYUP:
  7020. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  7021. break;
  7022. case WM_SYSKEYUP:
  7023. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  7024. break;
  7025. case WM_UNICHAR:
  7026. la_SendInputEvent(hwnd, wparam);
  7027. break;
  7028. case WM_IME_CHAR:
  7029. la_SendInputEvent(hwnd, wparam);
  7030. return 0;
  7031. case WM_CHAR:
  7032. la_SendInputEvent(hwnd, wparam);
  7033. break;
  7034. case WM_SHOWWINDOW:
  7035. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  7036. break;
  7037. case WM_CLOSE:
  7038. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  7039. break;
  7040. default:
  7041. return DefWindowProc(hwnd, message, wparam, lparam);
  7042. }
  7043. return DefWindowProc(hwnd, message, wparam, lparam);
  7044. }
  7045. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  7046. return DefWindowProc(hwnd, message, wparam, lparam);
  7047. }
  7048. #endif
  7049. int la_UpdateOperatorHints(laWindow* w){
  7050. laSafeString* ss=0;
  7051. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  7052. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  7053. }
  7054. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  7055. }else{
  7056. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  7057. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  7058. }
  7059. strSafeDestroy(&ss);
  7060. }
  7061. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  7062. laOperator *a, *NextA = 0;
  7063. int Result = 0;
  7064. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  7065. la_SendSignalsFromEvent(e);
  7066. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  7067. a = Operators->pFirst;
  7068. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  7069. while (1){
  7070. if (!a) break;
  7071. if (a->StopNow){
  7072. NextA = a->Item.pNext;
  7073. if (a->Type->Exit) a->Type->Exit(a, Result);
  7074. ConfirmData = a->NextConfirmData;
  7075. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7076. NextConfirmData = ConfirmData;
  7077. a->ConfirmData = 0;
  7078. a->NextConfirmData = 0;
  7079. la_DestroyOperator(&a, Operators, 0);
  7080. a = NextA;
  7081. if (a){
  7082. a->ConfirmData = NextConfirmData;
  7083. }
  7084. continue;
  7085. }
  7086. a->Using = 1;
  7087. la_SetPropMathcerContext(a->ToPanel);
  7088. laSetOperatorLocalizer(a->ToPanel);
  7089. MAIN.CurrentPanel = a->ToPanel;
  7090. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7091. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  7092. e->Localized = 1;
  7093. }
  7094. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  7095. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7096. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  7097. e->Localized = 0;
  7098. }
  7099. la_SetPropMathcerContext(0);
  7100. laSetOperatorLocalizer(0);
  7101. MAIN.CurrentPanel = 0;
  7102. a->Using = 0;
  7103. if (Result & LA_PASS_ON){
  7104. laConfirmSameDataIfAny(a);
  7105. NextA = a->Item.pNext;
  7106. }else{
  7107. NextA = 0;
  7108. if (a->NextConfirmData){
  7109. la_DestroyConfirmData(&a->NextConfirmData);
  7110. }
  7111. }
  7112. ConfirmData = a->NextConfirmData;
  7113. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7114. NextConfirmData = ConfirmData;
  7115. a->ConfirmData = 0;
  7116. a->NextConfirmData = 0;
  7117. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  7118. if (a->Type->Exit) a->Type->Exit(a, Result);
  7119. la_DestroyOperator(&a, Operators, 0);
  7120. int found=0;
  7121. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  7122. if(!found){ NextA=0; }
  7123. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  7124. }
  7125. a = NextA;
  7126. if (a){
  7127. a->ConfirmData = NextConfirmData;
  7128. }
  7129. }
  7130. return 1;
  7131. }
  7132. int la_HandleEvents(laWindow *w){
  7133. laEvent *e, *NextE;
  7134. laOperator *a;
  7135. laThreadNotifier *tn;
  7136. MAIN.CurrentWindow=w;
  7137. //laSpinLock(&MAIN.csNotifier);
  7138. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  7139. //laSpinUnlock(&MAIN.csNotifier);
  7140. laNotifyUsers(tn->Path);
  7141. FreeMem(tn);
  7142. //if (MAIN.ThreadNotifiers.pFirst)
  7143. //laSpinLock(&MAIN.csNotifier);
  7144. }
  7145. //laSpinUnlock(&MAIN.csNotifier);
  7146. while (1){
  7147. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  7148. while (w->EventList.pFirst){
  7149. while (w->PendingOperators.pLast){
  7150. a = w->PendingOperators.pLast;
  7151. if (a->OperatorPanel){
  7152. laSetOperatorLocalizer(a->OperatorPanel);
  7153. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  7154. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  7155. }
  7156. lstRemoveItem(&w->PendingOperators, a);
  7157. lstPushItem(&w->Operators, a);
  7158. }
  7159. e = lstPopItem(&w->EventList);
  7160. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  7161. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  7162. memFree(e);
  7163. }
  7164. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  7165. if (!MAIN.ReTriggerOperators) break;
  7166. }
  7167. la_UpdateOperatorHints(w);
  7168. return 1;
  7169. }
  7170. int la_AllowInput(uint32_t ch){
  7171. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  7172. return 0;
  7173. }
  7174. int laCopyToClipboard(unsigned char * text){
  7175. #ifdef LA_LINUX
  7176. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  7177. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  7178. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  7179. strSafeSet(&MAIN.CopyPending, text);
  7180. #endif
  7181. }
  7182. int la_ProcessSysMessage(){
  7183. int SendDelay = 0, SendIdle = 0;
  7184. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  7185. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  7186. #ifdef LA_LINUX
  7187. XEvent e;
  7188. int type;
  7189. int InputCount = 0, CharCount=0;
  7190. KeySym InputKeysym = 0;
  7191. Status InputStatus = 0;
  7192. laWindow* wnd ;
  7193. while(XPending(MAIN.dpy)){
  7194. XGenericEventCookie *cookie = &e.xcookie;
  7195. XNextEvent(MAIN.dpy, &e);
  7196. if (XFilterEvent(&e, None)) continue;
  7197. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  7198. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  7199. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  7200. XFreeEventData(MAIN.dpy, cookie); continue;
  7201. }
  7202. switch(e.type){
  7203. case ConfigureNotify:
  7204. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  7205. break;
  7206. case Expose:
  7207. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  7208. if(!wnd) break;
  7209. laRefreshWindow(wnd);
  7210. break;
  7211. case MotionNotify:
  7212. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  7213. MAIN.IsPen=0;
  7214. break;
  7215. case ButtonPress:
  7216. type=LA_MOUSEDOWN;
  7217. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7218. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7219. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7220. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7221. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7222. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7223. MAIN.IsPen=0;
  7224. break;
  7225. case ButtonRelease:
  7226. type=LA_MOUSEUP;
  7227. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7228. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7229. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7230. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7231. MAIN.IsPen=0;
  7232. break;
  7233. case KeyPress:
  7234. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7235. MAIN.InputBuf[InputCount]=0;
  7236. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7237. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7238. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7239. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7240. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7241. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7242. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7243. #ifdef DEBUG
  7244. printf("pressed KEY: %d\n", (int)InputKeysym);
  7245. #endif
  7246. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7247. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7248. }
  7249. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7250. }
  7251. break;
  7252. case KeyRelease:
  7253. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7254. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7255. }
  7256. case ClientMessage:
  7257. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7258. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7259. }
  7260. break;
  7261. case SelectionNotify:
  7262. if(e.xselection.selection != MAIN.bufid) continue;
  7263. if (e.xselection.property){
  7264. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7265. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7266. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7267. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7268. else if(result) {
  7269. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7270. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7271. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7272. }
  7273. XFree(result);
  7274. return True;
  7275. }
  7276. case SelectionRequest:
  7277. if(!MAIN.CopyPending){ break; }
  7278. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7279. if (e.xselectionrequest.selection != MAIN.selection) break;
  7280. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7281. XSelectionEvent ev = {0};
  7282. int R = 0;
  7283. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7284. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7285. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7286. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7287. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7288. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7289. else if (ev.target == MAIN.UTF8)
  7290. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7291. else ev.property = None;
  7292. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7293. break;
  7294. case SelectionClear:
  7295. break;
  7296. default:
  7297. break;
  7298. }
  7299. }
  7300. #endif //linux
  7301. #ifdef _WIN32
  7302. MSG msg; int Processed = 0;
  7303. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7304. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7305. if (msg.wParam == VK_PROCESSKEY) {
  7306. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7307. }
  7308. TranslateMessage(&msg); DispatchMessage(&msg);
  7309. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7310. };
  7311. if(!MAIN.Windows.pFirst){ return 0; }
  7312. #endif
  7313. #ifdef LAGUI_ANDROID
  7314. int pollResult = 0;
  7315. int pollEvents = 0;
  7316. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7317. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7318. // NOTE: Never close window, native activity is controlled by the system!
  7319. if (MAIN.app->destroyRequested != 0)
  7320. {
  7321. //CORE.Window.shouldClose = true;
  7322. //ANativeActivity_finish(MAIN.app->activity);
  7323. }
  7324. }
  7325. #endif
  7326. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7327. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7328. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7329. }
  7330. return 1;
  7331. };
  7332. void la_PrintOperatorStack(){
  7333. laWindow *w = MAIN.CurrentWindow;
  7334. laOperator *a;
  7335. printf("\n");
  7336. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7337. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7338. a->Type->Identifier, a->Instance,
  7339. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7340. }
  7341. }
  7342. void la_DrawWindow(laWindow *w){
  7343. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7344. MAIN.CurrentWindow = w;
  7345. la_WindowDefDraw(w, 0);
  7346. }
  7347. int laFinalize(){
  7348. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7349. laUiTemplate* uit;
  7350. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7351. return 1;
  7352. }
  7353. void la_PreFrame(){
  7354. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7355. la_AnimationPreFrame();
  7356. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7357. }
  7358. void la_PostFrame(){
  7359. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7360. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7361. }
  7362. void laMainLoop(){
  7363. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7364. time_t t1, t2;
  7365. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7366. static int a = 0;
  7367. if(!laFinalize()) return;
  7368. laSetWindowCursor(LA_ARROW);
  7369. MAIN.DelayTriggered=1;
  7370. #ifdef LAGUI_ANDROID
  7371. while(!MAIN.AppReady){ usleep(1000); }
  7372. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7373. #endif
  7374. while (1){
  7375. laRecordTime(&MAIN.FrameStartTime);
  7376. la_PerfClear();
  7377. la_PreFrame();
  7378. if(!la_ProcessSysMessage()){ return; }
  7379. la_UpdateControllerStatus();
  7380. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7381. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7382. NextW = w->Item.pNext;
  7383. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7384. }
  7385. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7386. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7387. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7388. if(MAIN.GLDebugNeedsUpdate){
  7389. la_SetCurrentGLContextDebug();
  7390. }
  7391. la_DrawWindow(w);
  7392. }
  7393. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7394. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7395. #ifdef LA_LINUX
  7396. #ifdef LA_USE_GLES
  7397. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7398. #else
  7399. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7400. #endif
  7401. #endif
  7402. #ifdef _WIN32
  7403. SwapBuffers(w->hdc);
  7404. #endif
  7405. #ifdef LAGUI_ANDROID
  7406. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7407. #endif
  7408. }
  7409. MAIN.GLDebugNeedsUpdate=0;
  7410. la_PostFrame();
  7411. //t2 = clock();
  7412. laRecordTime(&MAIN.FrameEndTime);
  7413. TimeInterval = laTimeElapsedSecondsf(&MAIN.FrameEndTime, &MAIN.FrameStartTime);
  7414. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7415. if (Pause > 0){
  7416. int us = Pause * 1000000.0;
  7417. usleep(us);
  7418. }
  7419. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7420. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7421. la_AnimationPostFrame();
  7422. }
  7423. }
  7424. #ifdef LAGUI_ANDROID
  7425. int la_AndroidInitGraphics(void){
  7426. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7427. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7428. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7429. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7430. EGLint samples = 0;
  7431. EGLint sampleBuffer = 0;
  7432. const EGLint framebufferAttribs[] = {
  7433. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7434. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7435. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7436. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7437. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7438. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7439. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7440. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7441. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7442. EGL_NONE
  7443. };
  7444. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7445. EGLint numConfigs = 0;
  7446. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7447. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7448. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7449. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7450. eglBindAPI(EGL_OPENGL_API);
  7451. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7452. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7453. EGLint displayFormat = 0;
  7454. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7455. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7456. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7457. // There must be at least one frame displayed before the buffers are swapped
  7458. eglSwapInterval(MAIN.egl_dpy, 1);
  7459. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7460. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7461. MAIN.AppReady = 1;
  7462. return 0;
  7463. }
  7464. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7465. switch (cmd){
  7466. case APP_CMD_START: break;
  7467. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7468. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7469. case APP_CMD_RESUME:break;//InitPlatform();break;
  7470. case APP_CMD_INIT_WINDOW:
  7471. if (app->window != NULL){
  7472. if (MAIN.ContextRebindRequired){
  7473. // Reset screen scaling to full display size
  7474. EGLint displayFormat = 0;
  7475. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7476. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7477. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7478. // appropriate way to fix this
  7479. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7480. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7481. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7482. displayFormat);
  7483. // Recreate display surface and re-attach OpenGL context
  7484. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7485. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7486. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7487. //glClearColor(1,0.2,1,1);
  7488. //glClear(GL_COLOR_BUFFER_BIT);
  7489. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7490. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7491. MAIN.ContextRebindRequired = false;
  7492. }else{
  7493. la_AndroidInitGraphics();
  7494. }
  7495. }
  7496. break;
  7497. case APP_CMD_DESTROY:
  7498. case APP_CMD_TERM_WINDOW:
  7499. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7500. // 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.
  7501. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7502. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7503. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7504. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7505. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7506. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7507. MAIN.egl_surf = EGL_NO_SURFACE;
  7508. }
  7509. MAIN.ContextRebindRequired = true;
  7510. }
  7511. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7512. // this means that the user has already called 'CloseWindow()'
  7513. break;
  7514. case APP_CMD_SAVE_STATE: break;
  7515. case APP_CMD_STOP: break;
  7516. case APP_CMD_CONFIG_CHANGED:
  7517. case APP_CMD_WINDOW_RESIZED:
  7518. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7519. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7520. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7521. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7522. //print_cur_config(MAIN.app);
  7523. // Check screen orientation here!
  7524. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7525. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7526. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7527. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7528. MAIN.egl_surf = EGL_NO_SURFACE;
  7529. }
  7530. EGLint displayFormat = 0;
  7531. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7532. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7533. displayFormat);
  7534. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7535. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7536. }
  7537. break;
  7538. default: break;
  7539. }
  7540. }
  7541. #define KEYCODE_MAP_SIZE 162
  7542. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7543. 0, // AKEYCODE_UNKNOWN
  7544. 0, // AKEYCODE_SOFT_LEFT
  7545. 0, // AKEYCODE_SOFT_RIGHT
  7546. 0, // AKEYCODE_HOME
  7547. 0, // AKEYCODE_BACK
  7548. 0, // AKEYCODE_CALL
  7549. 0, // AKEYCODE_ENDCALL
  7550. '0', // AKEYCODE_0
  7551. '1', // AKEYCODE_1
  7552. '2', // AKEYCODE_2
  7553. '3', // AKEYCODE_3
  7554. '4', // AKEYCODE_4
  7555. '5', // AKEYCODE_5
  7556. '6', // AKEYCODE_6
  7557. '7', // AKEYCODE_7
  7558. '8', // AKEYCODE_8
  7559. '9', // AKEYCODE_9
  7560. 0, // AKEYCODE_STAR
  7561. 0, // AKEYCODE_POUND
  7562. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7563. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7564. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7565. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7566. 0, // AKEYCODE_DPAD_CENTER
  7567. 0, // AKEYCODE_VOLUME_UP
  7568. 0, // AKEYCODE_VOLUME_DOWN
  7569. 0, // AKEYCODE_POWER
  7570. 0, // AKEYCODE_CAMERA
  7571. 0, // AKEYCODE_CLEAR
  7572. 'a', // AKEYCODE_A
  7573. 'b', // AKEYCODE_B
  7574. 'c', // AKEYCODE_C
  7575. 'd', // AKEYCODE_D
  7576. 'e', // AKEYCODE_E
  7577. 'f', // AKEYCODE_F
  7578. 'g', // AKEYCODE_G
  7579. 'h', // AKEYCODE_H
  7580. 'i', // AKEYCODE_I
  7581. 'j', // AKEYCODE_J
  7582. 'k', // AKEYCODE_K
  7583. 'l', // AKEYCODE_L
  7584. 'm', // AKEYCODE_M
  7585. 'n', // AKEYCODE_N
  7586. 'o', // AKEYCODE_O
  7587. 'p', // AKEYCODE_P
  7588. 'q', // AKEYCODE_Q
  7589. 'r', // AKEYCODE_R
  7590. 's', // AKEYCODE_S
  7591. 't', // AKEYCODE_T
  7592. 'u', // AKEYCODE_U
  7593. 'v', // AKEYCODE_V
  7594. 'w', // AKEYCODE_W
  7595. 'x', // AKEYCODE_X
  7596. 'y', // AKEYCODE_Y
  7597. 'z', // AKEYCODE_Z
  7598. ',', // AKEYCODE_COMMA
  7599. '.', // AKEYCODE_PERIOD
  7600. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7601. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7602. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7603. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7604. LA_KEY_TAB, // AKEYCODE_TAB
  7605. ' ', // AKEYCODE_SPACE
  7606. 0, // AKEYCODE_SYM
  7607. 0, // AKEYCODE_EXPLORER
  7608. 0, // AKEYCODE_ENVELOPE
  7609. LA_KEY_ENTER, // AKEYCODE_ENTER
  7610. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7611. '`', // AKEYCODE_GRAVE
  7612. '-', // AKEYCODE_MINUS
  7613. '=', // AKEYCODE_EQUALS
  7614. '(', // AKEYCODE_LEFT_BRACKET
  7615. ')', // AKEYCODE_RIGHT_BRACKET
  7616. '\\', // AKEYCODE_BACKSLASH
  7617. ';', // AKEYCODE_SEMICOLON
  7618. '\'', // AKEYCODE_APOSTROPHE
  7619. '/', // AKEYCODE_SLASH
  7620. 0, // AKEYCODE_AT
  7621. 0, // AKEYCODE_NUM
  7622. 0, // AKEYCODE_HEADSETHOOK
  7623. 0, // AKEYCODE_FOCUS
  7624. 0, // AKEYCODE_PLUS
  7625. 0, // AKEYCODE_MENU
  7626. 0, // AKEYCODE_NOTIFICATION
  7627. 0, // AKEYCODE_SEARCH
  7628. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7629. 0, // AKEYCODE_MEDIA_STOP
  7630. 0, // AKEYCODE_MEDIA_NEXT
  7631. 0, // AKEYCODE_MEDIA_PREVIOUS
  7632. 0, // AKEYCODE_MEDIA_REWIND
  7633. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7634. 0, // AKEYCODE_MUTE
  7635. 0, // AKEYCODE_PAGE_UP
  7636. 0, // AKEYCODE_PAGE_DOWN
  7637. 0, // AKEYCODE_PICTSYMBOLS
  7638. 0, // AKEYCODE_SWITCH_CHARSET
  7639. 0, // AKEYCODE_BUTTON_A
  7640. 0, // AKEYCODE_BUTTON_B
  7641. 0, // AKEYCODE_BUTTON_C
  7642. 0, // AKEYCODE_BUTTON_X
  7643. 0, // AKEYCODE_BUTTON_Y
  7644. 0, // AKEYCODE_BUTTON_Z
  7645. 0, // AKEYCODE_BUTTON_L1
  7646. 0, // AKEYCODE_BUTTON_R1
  7647. 0, // AKEYCODE_BUTTON_L2
  7648. 0, // AKEYCODE_BUTTON_R2
  7649. 0, // AKEYCODE_BUTTON_THUMBL
  7650. 0, // AKEYCODE_BUTTON_THUMBR
  7651. 0, // AKEYCODE_BUTTON_START
  7652. 0, // AKEYCODE_BUTTON_SELECT
  7653. 0, // AKEYCODE_BUTTON_MODE
  7654. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7655. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7656. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7657. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7658. 0, // AKEYCODE_CAPS_LOCK
  7659. 0, // AKEYCODE_SCROLL_LOCK
  7660. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7661. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7662. 0, // AKEYCODE_FUNCTION
  7663. 0, // AKEYCODE_SYSRQ
  7664. 0, // AKEYCODE_BREAK
  7665. 0, // AKEYCODE_MOVE_HOME
  7666. 0, // AKEYCODE_MOVE_END
  7667. 0, // AKEYCODE_INSERT
  7668. 0, // AKEYCODE_FORWARD
  7669. 0, // AKEYCODE_MEDIA_PLAY
  7670. 0, // AKEYCODE_MEDIA_PAUSE
  7671. 0, // AKEYCODE_MEDIA_CLOSE
  7672. 0, // AKEYCODE_MEDIA_EJECT
  7673. 0, // AKEYCODE_MEDIA_RECORD
  7674. LA_KEY_F1, // AKEYCODE_F1
  7675. LA_KEY_F2, // AKEYCODE_F2
  7676. LA_KEY_F3, // AKEYCODE_F3
  7677. LA_KEY_F4, // AKEYCODE_F4
  7678. LA_KEY_F5, // AKEYCODE_F5
  7679. LA_KEY_F6, // AKEYCODE_F6
  7680. LA_KEY_F7, // AKEYCODE_F7
  7681. LA_KEY_F8, // AKEYCODE_F8
  7682. LA_KEY_F9, // AKEYCODE_F9
  7683. LA_KEY_F10, // AKEYCODE_F10
  7684. LA_KEY_F11, // AKEYCODE_F11
  7685. LA_KEY_F12, // AKEYCODE_F12
  7686. 0, // AKEYCODE_NUM_LOCK
  7687. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7688. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7689. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7690. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7691. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7692. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7693. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7694. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7695. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7696. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7697. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7698. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7699. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7700. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7701. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7702. 0, // AKEYCODE_NUMPAD_COMMA
  7703. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7704. '=' // AKEYCODE_NUMPAD_EQUALS
  7705. };
  7706. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7707. {
  7708. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7709. if(!MAIN.AppEnabled){return 0;}
  7710. //laRedrawAllWindows();
  7711. static int prev_button_state=0;
  7712. int type = AInputEvent_getType(event);
  7713. if(type == AINPUT_EVENT_TYPE_KEY){
  7714. int32_t keycode = AKeyEvent_getKeyCode(event);
  7715. //int32_t AKeyEvent_getMetaState(event);
  7716. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7717. if (key != 0){
  7718. // Save current key and its state
  7719. // NOTE: Android key action is 0 for down and 1 for up
  7720. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7721. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7722. if(key!=LA_KEY_BACKSPACE)
  7723. la_SendInputEvent(0,key);
  7724. }
  7725. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7726. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7727. la_SendInputEvent(0,key);
  7728. }
  7729. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7730. }
  7731. if (keycode == AKEYCODE_POWER)
  7732. {
  7733. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7734. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7735. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7736. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7737. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7738. return 0;
  7739. }
  7740. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7741. {
  7742. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7743. return 1;
  7744. }
  7745. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7746. {
  7747. // Set default OS behaviour
  7748. return 0;
  7749. }
  7750. return 0;
  7751. }
  7752. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7753. static real zoom_offset=1; static real temp_distance=0;
  7754. real zoom; int gesture_handled=0;
  7755. int pcount = AMotionEvent_getPointerCount(event); int x,y; static real cx=0,cy=0;
  7756. int32_t action = AMotionEvent_getAction(event);
  7757. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7758. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7759. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7760. if(pcount){
  7761. x=rx; y=ry;
  7762. int tool_type=AMotionEvent_getToolType(event,0);
  7763. real pressure = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_PRESSURE,0);
  7764. if(tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS || tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER){
  7765. MAIN.StylusPressure = MAIN.EraserPressure = pressure; MAIN.IsPen = 1;
  7766. MAIN.PointerIsEraser = (tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER);
  7767. }else{
  7768. MAIN.IsPen = 0;
  7769. }
  7770. if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
  7771. && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
  7772. real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
  7773. real ctx=(x+x2)/2, cty=(y+y2)/2;
  7774. real distance = tnsDistIdv2(x2,y2,rx,ry);
  7775. if(temp_distance){ zoom_offset*=(distance/temp_distance); }
  7776. temp_distance = distance;
  7777. while(zoom_offset > 1.1){ zoom_offset-=0.1;
  7778. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7779. la_SendMouseEvent(0, LA_MOUSEUP|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7780. }
  7781. while(zoom_offset < (1.0/1.1)){ zoom_offset+=(0.1/1.1);
  7782. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7783. la_SendMouseEvent(0, LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7784. }
  7785. if(cx || cy){
  7786. if(!gesture_handled){
  7787. real dist = tnsDistIdv2(ctx,cty,cx,cy);
  7788. while(dist > LA_RH){
  7789. int udlr = fabs(cty-cy) > fabs(ctx-cx);
  7790. int direction = udlr?(cty>cy?LA_KEY_ARRUP:LA_KEY_ARRDOWN):
  7791. (ctx>cx?LA_KEY_ARRLEFT:LA_KEY_ARRRIGHT);
  7792. real fac = (real)(LA_RH)/dist;
  7793. cx=tnsLinearItp(cx,ctx,fac); cy=tnsLinearItp(cy,cty,fac);
  7794. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7795. la_SendKeyboardEvent(0, LA_KEY_DOWN, direction|LA_KEYBOARD_EVENT|LA_KEY_PANNING);
  7796. gesture_handled=1;
  7797. dist = tnsDistIdv2(ctx,cty,cx,cy);
  7798. }
  7799. }
  7800. }else{
  7801. cx=ctx; cy=cty;
  7802. }
  7803. }else{
  7804. temp_distance = 0; cx=0; cy=0;
  7805. }
  7806. if(flags==AMOTION_EVENT_ACTION_HOVER_MOVE){
  7807. la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
  7808. }
  7809. }
  7810. if(!gesture_handled){
  7811. if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_BUTTON_PRESS){
  7812. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7813. int btn=AMotionEvent_getButtonState(event);
  7814. int evtype=LA_L_MOUSE_DOWN;
  7815. if(btn & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_DOWN; }
  7816. elif(btn & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_DOWN; }
  7817. la_SendMouseEvent(0,evtype,x,y);
  7818. prev_button_state = btn;
  7819. }
  7820. else if (flags == AMOTION_EVENT_ACTION_UP || flags == AMOTION_EVENT_ACTION_BUTTON_RELEASE){
  7821. int btn=AMotionEvent_getButtonState(event); int changed = (~btn)&prev_button_state;
  7822. int evtype=LA_L_MOUSE_UP;
  7823. if(changed & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_UP; }
  7824. elif(changed & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_UP; }
  7825. la_SendMouseEvent(0,evtype,x,y);
  7826. }
  7827. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7828. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7829. }
  7830. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7831. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7832. }
  7833. }
  7834. }
  7835. //static float r=0;
  7836. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7837. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7838. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7839. //glClear(GL_COLOR_BUFFER_BIT);
  7840. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7841. return 0;
  7842. }
  7843. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7844. MAIN.AssetManager = manager;
  7845. MAIN.InternalDataPath = dataPath;
  7846. MAIN.ExternalDataPath = externalDataPath;
  7847. }
  7848. static int android_read(void *cookie, char *data, int dataSize){
  7849. return AAsset_read((AAsset *)cookie, data, dataSize);
  7850. }
  7851. static int android_write(void *cookie, const char *data, int dataSize){
  7852. return 0;
  7853. }
  7854. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7855. return AAsset_seek((AAsset *)cookie, offset, whence);
  7856. }
  7857. static int android_close(void *cookie){
  7858. AAsset_close((AAsset *)cookie);
  7859. return 0;
  7860. }
  7861. // Replacement for fopen()
  7862. // Ref: https://developer.android.com/ndk/reference/group/asset
  7863. FILE *android_fopen(const char *fileName, const char *mode)
  7864. {
  7865. char buf[1024];
  7866. if (mode[0] == 'w')
  7867. {
  7868. // fopen() is mapped to android_fopen() that only grants read access to
  7869. // assets directory through AAssetManager but we want to also be able to
  7870. // write data when required using the standard stdio FILE access functions
  7871. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7872. #undef fopen
  7873. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7874. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7875. result=fopen(buf, mode); if(result) return result;
  7876. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7877. return fopen(buf, mode);
  7878. #define fopen(name, mode) android_fopen(name, mode)
  7879. }
  7880. else
  7881. {
  7882. // NOTE: AAsset provides access to read-only asset
  7883. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7884. if (asset != NULL)
  7885. {
  7886. // Get pointer to file in the assets
  7887. return funopen(asset, android_read, android_write, android_seek, android_close);
  7888. }
  7889. else
  7890. {
  7891. #undef fopen
  7892. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7893. // Just do a regular open if file is not found in the assets
  7894. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7895. result=fopen(buf, mode); if(result){ return result; }
  7896. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7897. return fopen(buf, mode);
  7898. #define fopen(name, mode) android_fopen(name, mode)
  7899. }
  7900. }
  7901. }
  7902. void la_HideNavBar(){
  7903. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7904. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7905. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7906. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7907. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7908. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7909. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7910. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7911. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7912. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7913. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7914. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7915. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7916. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7917. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7918. int flag = flagFullscreen | flagHideNavigation;
  7919. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7920. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7921. }
  7922. void la_InitAndroidPlatform(struct android_app *app){
  7923. MAIN.app=app;
  7924. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7925. //la_HideNavBar();
  7926. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7927. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7928. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7929. int pollResult = 0;
  7930. int pollEvents = 0;
  7931. while (!MAIN.AppReady){
  7932. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7933. // Process this event
  7934. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7935. // NOTE: Never close window, native activity is controlled by the system!
  7936. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7937. }
  7938. }
  7939. }
  7940. int main(int, char *[]);
  7941. void android_main(struct android_app *app){
  7942. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7943. la_InitAndroidPlatform(app);
  7944. // NOTE: Return from main is ignored
  7945. (void)main(1, (char *[]) { arg0, NULL });
  7946. // Request to end the native activity
  7947. ANativeActivity_finish(app->activity);
  7948. // Android ALooper_pollAll() variables
  7949. int pollResult = 0;
  7950. int pollEvents = 0;
  7951. // Waiting for application events before complete finishing
  7952. while (!app->destroyRequested)
  7953. {
  7954. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7955. {
  7956. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7957. }
  7958. }
  7959. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "Application successfully ended.\n");
  7960. /* Unloads the native dynamic library so we can get clean restarts. */
  7961. exit(0);
  7962. }
  7963. void la_DisplayKeyboard(bool pShow) {
  7964. // Attaches the current thread to the JVM.
  7965. jint lResult;
  7966. jint lFlags = 0;
  7967. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7968. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7969. JavaVMAttachArgs lJavaVMAttachArgs;
  7970. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7971. lJavaVMAttachArgs.name = "NativeThread";
  7972. lJavaVMAttachArgs.group = NULL;
  7973. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7974. if (lResult == JNI_ERR) {
  7975. return;
  7976. }
  7977. // Retrieves NativeActivity.
  7978. jobject lNativeActivity = MAIN.app->activity->clazz;
  7979. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7980. logPrintNew("jvm3");
  7981. // Retrieves Context.INPUT_METHOD_SERVICE.
  7982. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7983. jfieldID FieldINPUT_METHOD_SERVICE =
  7984. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7985. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7986. jobject INPUT_METHOD_SERVICE =
  7987. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7988. FieldINPUT_METHOD_SERVICE);
  7989. //jniCheck(INPUT_METHOD_SERVICE);
  7990. logPrintNew("jvm4");
  7991. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7992. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7993. "android/view/inputmethod/InputMethodManager");
  7994. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7995. ClassNativeActivity, "getSystemService",
  7996. "(Ljava/lang/String;)Ljava/lang/Object;");
  7997. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7998. lNativeActivity, MethodGetSystemService,
  7999. INPUT_METHOD_SERVICE);
  8000. // Runs getWindow().getDecorView().
  8001. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8002. ClassNativeActivity, "getWindow",
  8003. "()Landroid/view/Window;");
  8004. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  8005. MethodGetWindow);
  8006. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  8007. "android/view/Window");
  8008. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8009. ClassWindow, "getDecorView", "()Landroid/view/View;");
  8010. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  8011. MethodGetDecorView);
  8012. if (pShow) {
  8013. // Runs lInputMethodManager.showSoftInput(...).
  8014. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8015. ClassInputMethodManager, "showSoftInput",
  8016. "(Landroid/view/View;I)Z");
  8017. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  8018. lInputMethodManager, MethodShowSoftInput,
  8019. lDecorView, lFlags);
  8020. } else {
  8021. // Runs lWindow.getViewToken()
  8022. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  8023. "android/view/View");
  8024. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8025. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  8026. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  8027. MethodGetWindowToken);
  8028. // lInputMethodManager.hideSoftInput(...).
  8029. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8030. ClassInputMethodManager, "hideSoftInputFromWindow",
  8031. "(Landroid/os/IBinder;I)Z");
  8032. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  8033. lInputMethodManager, MethodHideSoftInput,
  8034. lBinder, lFlags);
  8035. }
  8036. // Finished with the JVM.
  8037. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8038. }
  8039. bool la_check_permission(const char* permission) {
  8040. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8041. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8042. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8043. jobject lNativeActivity = MAIN.app->activity->clazz;
  8044. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  8045. jmethodID activity_checkSelfPermission = (*lJNIEnv)->GetMethodID(lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  8046. jstring jobj_permission = (*lJNIEnv)->NewStringUTF(lJNIEnv,permission);
  8047. jint result = (*lJNIEnv)->CallIntMethod(lJNIEnv,ClassNativeActivity, activity_checkSelfPermission, jobj_permission);
  8048. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  8049. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8050. return result == 0;
  8051. }
  8052. void la_request_permission(const char* permission) {
  8053. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8054. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8055. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8056. jobject lNativeActivity = MAIN.app->activity->clazz;
  8057. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  8058. jmethodID contextCompat_checkSelfPermission = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  8059. jmethodID activity_requestPermissions = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "requestPermissions", "([Ljava/lang/String;I)V");
  8060. jstring jobj_permission = (*lJNIEnv)->NewStringUTF (lJNIEnv,permission);
  8061. jobjectArray jobj_permission_list = (*lJNIEnv)->NewObjectArray(lJNIEnv,1, (*lJNIEnv)->FindClass(lJNIEnv,"java/lang/String"), NULL);
  8062. (*lJNIEnv)->SetObjectArrayElement(lJNIEnv,jobj_permission_list, 0, jobj_permission);
  8063. (*lJNIEnv)->CallVoidMethod (lJNIEnv,lNativeActivity, activity_requestPermissions, jobj_permission_list, 0);
  8064. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  8065. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission_list);
  8066. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8067. }
  8068. #endif //android
  8069. #ifndef LAGUI_ANDROID
  8070. void la_DisplayKeyboard(bool pShow) {
  8071. return;
  8072. }
  8073. void la_HideNavBar(){
  8074. return;
  8075. }
  8076. #endif