*/}}

la_kernel.c 342 KB

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