*/}}
1
0

la_kernel.c 262 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188
  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. #include "la_5.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <math.h>
  22. #include <time.h>
  23. #ifdef __linux__
  24. #include <sys/time.h>
  25. #include <X11/Xlib.h>
  26. #include <X11/Xutil.h>
  27. #include <X11/Xos.h>
  28. #include <X11/keysymdef.h>
  29. #include <X11/XKBlib.h>
  30. #include <X11/extensions/XInput.h>
  31. #include <X11/extensions/XInput2.h>
  32. #include <X11/extensions/Xfixes.h>
  33. #include <X11/Xcursor/Xcursor.h>
  34. #include <X11/cursorfont.h>
  35. #include <GL/glx.h>
  36. #endif
  37. #ifdef _WIN32
  38. #include <GL/wglew.h>
  39. #include <GL/wgl.h>
  40. #endif
  41. LA MAIN;
  42. extern tnsMain *T;
  43. int deb = 0;
  44. laOperator *DEB;
  45. laColumn *DEBUG_C;
  46. #ifdef _WIN32
  47. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  48. #else
  49. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  50. #endif
  51. #ifdef __linux__
  52. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
  53. typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
  54. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  55. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  56. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  57. #endif
  58. #ifdef __linux__
  59. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  60. int i;
  61. for (i = 0; i < num_classes; i++) {
  62. if (classes[i]->type == XIValuatorClass) {
  63. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  64. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  65. logPrint(" Range: %f - %f\n", v->min, v->max);
  66. logPrint(" Resolution: %d units/m\n", v->resolution);
  67. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  68. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  69. }
  70. }
  71. }
  72. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  73. XIDeviceInfo *info, *dev;
  74. int i, ndevices;
  75. dev = XIQueryDevice(display, deviceid, &ndevices);
  76. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  77. mask->deviceid = deviceid;
  78. mask->mask_len = XIMaskLen(XI_RawMotion);
  79. mask->mask=memAcquireSimple(mask->mask_len);
  80. memset(mask->mask, 0, mask->mask_len);
  81. XISetMask(mask->mask, XI_RawMotion);
  82. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  83. int FoundMax=0;
  84. for (i = 0; i < dev->num_classes; i++) {
  85. if (dev->classes[i]->type == XIValuatorClass) {
  86. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  87. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  88. }
  89. }
  90. if(!FoundMax){*max_pressure=65535;}
  91. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  92. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  93. XIFreeDeviceInfo(dev);
  94. }
  95. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  96. int axis=0;
  97. for (int i = 0; i < dev->num_classes; i++) {
  98. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  99. }
  100. return axis>=3;
  101. }
  102. #define LA_G_STYLUS(dev) \
  103. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  104. #define LA_G_ERASER \
  105. (!MAIN.WacomDeviceEraser)
  106. void la_ScanWacomDevices(Display *display, int deviceid){
  107. XIDeviceInfo *info, *dev;
  108. int ndevices;
  109. int i; char * word;
  110. int _event, _error;
  111. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  112. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  113. }
  114. info = XIQueryDevice(display, deviceid, &ndevices);
  115. for(i = 0; i < ndevices; i++) {
  116. dev = &info[i]; strToLower(dev->name);
  117. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  118. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  119. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  120. word = strtok (dev->name," ");
  121. while (1) {
  122. word = strtok (NULL, " "); if (!word) break;
  123. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  124. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  125. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  126. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  127. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  128. }
  129. }
  130. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  131. logPrintNew("Found wacom devices:\n");
  132. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  133. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  134. }else{
  135. logPrintNew("No wacom pen device connected.\n");
  136. }
  137. XIFreeDeviceInfo(info);
  138. }
  139. void laHideCursor(){
  140. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  141. }
  142. void laShowCursor(){
  143. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  144. }
  145. void la_XErrorHandler(Display *display, XErrorEvent *event){
  146. char buf[512];
  147. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  148. printf("X Error:\n%s\n",buf);
  149. }
  150. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc){
  151. XSetWindowAttributes swa;
  152. XWindowAttributes wa;
  153. swa.event_mask =
  154. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  155. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  156. swa.colormap = MAIN.cmap;
  157. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  158. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  159. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  160. if(x>0||y>0){
  161. XSizeHints my_hints = {0};
  162. my_hints.flags = PPosition;
  163. my_hints.x = x; my_hints.y = y;
  164. XSetNormalHints(MAIN.dpy, win, &my_hints);
  165. }
  166. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  167. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  168. printf("\n\tcannot create gl context\n\n"); exit(0);
  169. }
  170. XStoreName(MAIN.dpy, win, title);
  171. //XMapWindow(MAIN.dpy, win);
  172. glXMakeCurrent(MAIN.dpy, win, MAIN.glc);
  173. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  174. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  175. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  176. XSetICFocus(MAIN.ic);
  177. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  178. XSetClassHint(MAIN.dpy, win, &ch);
  179. #define _NET_WM_STATE_ADD 1
  180. if(w<0&&h<0){
  181. XEvent xev;
  182. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  183. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  184. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  185. memset(&xev, 0, sizeof(xev));
  186. xev.type = ClientMessage;
  187. xev.xclient.window = win;
  188. xev.xclient.message_type = wm_state;
  189. xev.xclient.format = 32;
  190. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  191. xev.xclient.data.l[1] = max_horz;
  192. xev.xclient.data.l[2] = max_vert;
  193. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  194. }
  195. return win;
  196. };
  197. void la_DestroySystemWindowX11(laWindow* w) {
  198. glXMakeCurrent(MAIN.dpy, None, NULL);
  199. glXDestroyContext(MAIN.dpy, w->glc);
  200. XDestroyWindow(MAIN.dpy, w->win);
  201. };
  202. #endif //linux
  203. #ifdef _WIN32
  204. #include <msgdef.h>
  205. #include <wintab.h>
  206. #include <wintab_utils.h>
  207. #define PACKETDATA (PK_X | PK_Y | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  208. #define PACKETMODE PK_BUTTONS
  209. #include <pktdef.h>
  210. void la_OpenWacomWinTab(HWND hwnd){
  211. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  212. static LOGCONTEXT glogContext = { 0 };
  213. HCTX hctx = NULL;
  214. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  215. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 };
  216. glogContext.lcOptions |= CXO_SYSTEM;
  217. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  218. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  219. assert(glogContext.lcOptions & CXO_SYSTEM);
  220. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  221. glogContext.lcOptions |= CXO_MESSAGES;
  222. glogContext.lcPktData = PACKETDATA;
  223. glogContext.lcPktMode = PACKETMODE;
  224. glogContext.lcMoveMask = PACKETDATA;
  225. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  226. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  227. assert(wWTInfoRetVal == sizeof(AXIS));
  228. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  229. assert(wWTInfoRetVal == sizeof(AXIS));
  230. AXIS tabletPressure = { 0 };
  231. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  232. glogContext.lcInOrgX = 0;
  233. glogContext.lcInOrgY = 0;
  234. glogContext.lcInExtX = TabletX.axMax;
  235. glogContext.lcInExtY = TabletY.axMax;
  236. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  237. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  238. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  239. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  240. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  241. if (!hctx)return;
  242. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  243. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  244. }
  245. void laHideCursor() {
  246. if (!MAIN.CurrentWindow) return; //impl
  247. }
  248. void laShowCursor() {
  249. if (!MAIN.CurrentWindow) return; //impl
  250. }
  251. static PIXELFORMATDESCRIPTOR cpfd = {
  252. sizeof(PIXELFORMATDESCRIPTOR),1,
  253. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  254. PFD_TYPE_RGBA,
  255. 8,
  256. 0, 0, 0, 0, 0, 0,
  257. 0, 0, 0,
  258. 0, 0, 0, 0,
  259. 32,
  260. 8, 0,
  261. 0,
  262. 0, 0, 0, 0
  263. };
  264. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  265. int nBestMS = 0;
  266. int i;
  267. int iResults[9];
  268. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  269. WGL_ACCELERATION_ARB, // 1
  270. WGL_DRAW_TO_WINDOW_ARB, // 2
  271. WGL_DOUBLE_BUFFER_ARB, // 3
  272. WGL_PIXEL_TYPE_ARB, // 4
  273. WGL_DEPTH_BITS_ARB, // 5
  274. WGL_STENCIL_BITS_ARB, // 6
  275. WGL_SAMPLE_BUFFERS_ARB, // 7
  276. WGL_SAMPLES_ARB }; // 8
  277. // How many pixelformats are there?
  278. int nFormatCount[] = { 0 };
  279. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  280. if (!wglGetPixelFormatAttribivARB)
  281. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  282. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  283. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  284. for (i = 0; i < nFormatCount[0]; i++){
  285. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  286. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  287. if (iResults[3] == 1) // Double buffered
  288. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  289. if (iResults[5] >= 24) // Any Depth greater than 16
  290. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  291. }
  292. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  293. };
  294. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  295. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  296. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  297. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
  298. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  299. 0 };
  300. HGLRC hglrc = 0;
  301. HDC hdc = 0;
  302. int a, b;
  303. hdc = GetDC(hwnd);
  304. la_SetupPxlFormat(hdc, &a, &b);
  305. wglMakeCurrent(0, 0);
  306. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  307. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  308. //wglShareLists(hglrc, MAIN.glc);
  309. wglMakeCurrent(hdc, hglrc);
  310. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  311. wglSwapIntervalEXT(-1);
  312. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  313. };
  314. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  315. HINSTANCE* inst = &MAIN.hinstance;
  316. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  317. x, y, w, h, 0, 0, *inst, 0);
  318. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  319. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  320. return hwnd;
  321. };
  322. void la_DestroySystemWindowWin32(laWindow* w) {
  323. wglDeleteContext(w->glc);
  324. ReleaseDC(w->win, w->hdc);
  325. DestroyWindow(w->win);
  326. };
  327. #endif
  328. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  329. SYSGLCONTEXT glc;
  330. #ifdef __linux__
  331. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  332. #endif
  333. #ifdef _WIN32
  334. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  335. #endif
  336. window->win = hwnd;
  337. #ifdef _WIN32
  338. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  339. RECT rc; GetClientRect(window->win, &rc);
  340. window->CW = rc.right - rc.left;
  341. window->CH = rc.bottom - rc.top;
  342. #endif
  343. #ifdef __linux__
  344. XWindowAttributes attr;
  345. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  346. window->CW =attr.width;
  347. window->CH = attr.height;
  348. window->glc = glc;
  349. #endif
  350. return 1;
  351. };
  352. int la_DestroySystemWindow(laWindow* wnd){
  353. #ifdef __linux__
  354. la_DestroySystemWindowX11(wnd);
  355. #endif
  356. #ifdef _WIN32
  357. la_DestroySystemWindowWin32(wnd);
  358. #endif
  359. }
  360. void la_DestroyWindow(laWindow *wnd){
  361. laLayout *l; laPanel *p;
  362. if (!wnd) return;
  363. la_StopAllOperators();
  364. strSafeDestroy(&wnd->Title);
  365. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  366. while (l = lstPopItem(&wnd->Layouts)){
  367. laDestroyBlocksRecursive(l->FirstBlock);
  368. strSafeDestroy(&l->ID);
  369. memFree(l);
  370. }
  371. la_DestroySystemWindow(wnd);
  372. lstRemoveItem(&MAIN.Windows, wnd);
  373. memFree(wnd);
  374. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  375. }
  376. void laRenameWindow(laWindow* wnd, char* name){
  377. if(!wnd) return;
  378. strSafeSet(&wnd->Title, name);
  379. if(!wnd->win) return;
  380. #ifdef __linux__
  381. XStoreName(MAIN.dpy, wnd->win, name);
  382. #endif
  383. #ifdef _WIN32
  384. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  385. SetWindowTextW(wnd->win, name);
  386. #endif
  387. }
  388. #ifdef __linux__
  389. const char* la_ConvertCursorID(int id){
  390. switch (id) {
  391. case LA_ARROW: return "arrow";
  392. case LA_CROSS: return "cross";
  393. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  394. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  395. case LA_MOVE: return "diamond_cross";
  396. case LA_HAND: return "hand1";
  397. case LA_CORNER: return "bottom_right_corner";
  398. }
  399. return "arrow";
  400. }
  401. #endif
  402. #ifdef _WIN32
  403. HCURSOR la_ConvertCursorID(int id){
  404. switch (id){
  405. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  406. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  407. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  408. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  409. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  410. case LA_HAND: return LoadCursor(0, IDC_HAND);
  411. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  412. }
  413. return LoadCursor(0, IDC_ARROW);;
  414. }
  415. #endif
  416. void la_InitThreadEnviornment(){
  417. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  418. }
  419. laLogEntry* logEnsure(int Create){
  420. if(!MAIN.Logs.pFirst || Create){
  421. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  422. lstAppendItem(&MAIN.Logs, le);
  423. }
  424. return MAIN.Logs.pLast;
  425. }
  426. void logPrintTV(int Continued, char* format, va_list v){
  427. if(!format || !format[0]) return;
  428. laLogEntry* le=logEnsure(Continued);
  429. strSafePrintV(&le->Content, format, v);
  430. laNotifyUsers("la.logs");
  431. }
  432. void logPrintT(int Continued, char* format, ...){
  433. if(!format || !format[0]) return;
  434. laLogEntry* le=logEnsure(Continued);
  435. va_list aptr; va_start(aptr, format);
  436. strSafePrint(&le->Content, format, aptr);
  437. va_end(aptr);
  438. laNotifyUsers("la.logs");
  439. }
  440. void logPrint(char* format, ...){
  441. va_list aptr; va_start(aptr, format);
  442. logPrintTV(0, format, aptr);
  443. va_end(aptr);
  444. }
  445. void logPrintNew(char* format, ...){
  446. logEnsure(1);
  447. va_list aptr; va_start(aptr, format);
  448. logPrintTV(0, format, aptr);
  449. va_end(aptr);
  450. }
  451. void logClear(){
  452. laLogEntry*l;
  453. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  454. }
  455. #define PROGRESSW (LA_RH*15)
  456. void laShowProgress(real p1, real p2){
  457. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  458. if(!MAIN.Progress.Called){
  459. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  460. }else{
  461. laTimeRecorder tm; laRecordTime(&tm);
  462. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1) return;
  463. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  464. if(!MAIN.Progress.Shown){
  465. int ww=PROGRESSW+LA_RH*2;
  466. #ifdef __linux__
  467. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  468. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  469. long a=LA_COLOR3_TO_HEX(bg);
  470. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  471. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  472. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  473. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  474. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  475. #endif
  476. #ifdef _WIN32
  477. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  478. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  479. ShowWindow(MAIN.Progress.w,SW_SHOW);
  480. #endif
  481. MAIN.Progress.Shown = 1;
  482. }
  483. }
  484. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  485. #ifdef __linux__
  486. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  487. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  488. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  489. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  490. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  491. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  492. #endif
  493. #ifdef _WIN32
  494. InvalidateRect(MAIN.Progress.w,0,1);
  495. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  496. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  497. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  498. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  499. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  500. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  501. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  502. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  503. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  504. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  505. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  506. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  507. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  508. EndPaint(MAIN.Progress.w,&ps);
  509. MSG msg;
  510. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  511. #endif
  512. }
  513. void laHideProgress(){
  514. if(!MAIN.Progress.Shown){
  515. MAIN.Progress.Called=0; return;
  516. }
  517. laTimeRecorder tm; laRecordTime(&tm);
  518. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  519. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  520. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  521. #ifdef __linux__
  522. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  523. #endif
  524. #ifdef _WIN32
  525. ShowWindow(MAIN.Progress.w,SW_HIDE);
  526. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  527. #endif
  528. }
  529. //=======================
  530. void la_InitProgressWindow(){
  531. #ifdef __linux__
  532. 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));
  533. if(!MAIN.Progress.w) return;
  534. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  535. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  536. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  537. if(MAIN.Progress.gc<0) return;
  538. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  539. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  540. XSync(MAIN.dpy,0);
  541. #endif
  542. #ifdef _WIN32
  543. WNDCLASSW wc;
  544. wc.hInstance = MAIN.hinstance;
  545. wc.lpfnWndProc = LA_ProgressWindowProc;
  546. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  547. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  548. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  549. wc.cbWndExtra = 0;
  550. wc.cbClsExtra = 0;
  551. wc.lpszClassName = L"_LAGUIPROGRESS";
  552. wc.lpszMenuName = NULL;
  553. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  554. if (!RegisterClassW(&wc)){ return; }
  555. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  556. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  557. #endif
  558. }
  559. void laSetFontFolderPath(char* absolute){
  560. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  561. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  562. }
  563. void laProcessInitArguments(int argc, char* argv[]) {
  564. MAIN.GLMajor=MAIN.GLMinor=-1;
  565. char* arg = 0;
  566. printf("%d\n",argc);
  567. for(int i=0;i<argc;i++){
  568. printf("%s\n",argv[i]);
  569. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  570. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<= '9'){ MAIN.GLMajor=arg[0]-'0'; MAIN.GLMinor=arg[2]-'0'; }
  571. }
  572. }
  573. }
  574. int laGetReadyWith(int GLMajor, int GLMinor, int BufferSamples){
  575. #ifdef __linux__
  576. SYSWINDOW root, win;
  577. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  578. XSetWindowAttributes swa={0};
  579. XWindowAttributes wa={0};
  580. XEvent xev;
  581. logPrintNew("Initializing LaGUI...\n");
  582. setlocale(LC_CTYPE, "zh_CN.utf8");
  583. XSetLocaleModifiers("");
  584. XSetErrorHandler(la_XErrorHandler);
  585. int i;
  586. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  587. printf("\n\tcannot connect to x server\n\n");
  588. exit(0);
  589. }
  590. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  591. MAIN.GLMajor=MAIN.GLMajor<0?GLMajor:3; MAIN.GLMinor=MAIN.GLMinor<0?GLMinor:3; MAIN.BufferSamples=BufferSamples;
  592. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  593. int visual_attribs[] = {
  594. GLX_X_RENDERABLE , True,
  595. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  596. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  597. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  598. GLX_RED_SIZE , 8,
  599. GLX_GREEN_SIZE , 8,
  600. GLX_BLUE_SIZE , 8,
  601. GLX_ALPHA_SIZE , 8,
  602. GLX_DEPTH_SIZE , 24,
  603. //GLX_STENCIL_SIZE , 8,
  604. GLX_DOUBLEBUFFER , True,
  605. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  606. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  607. None
  608. };
  609. int fbcount = -1;
  610. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  611. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  612. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  613. MAIN.BestFBC = fbconfig[0];
  614. int sample_buf,samples;
  615. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  616. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  617. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  618. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  619. free(fbconfig);
  620. root = DefaultRootWindow(MAIN.dpy);
  621. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  622. printf("\n\tcannot create colormap\n\n"); exit(0);
  623. }
  624. swa.colormap = MAIN.cmap;
  625. root = DefaultRootWindow(MAIN.dpy);
  626. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  627. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  628. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  629. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  630. printf("\n\tcannot create gl context\n\n"); exit(0);
  631. }
  632. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  633. glXMakeCurrent(MAIN.dpy, win, MAIN.glc);
  634. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  635. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  636. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  637. int err=0;
  638. if((err=glewInit())!=GLEW_OK){
  639. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  640. };
  641. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  642. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  643. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  644. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  645. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  646. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  647. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  648. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  649. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  650. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  651. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  652. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  653. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  654. #endif //linux
  655. #ifdef _WIN32
  656. logPrintNew("Initializing LaGUI...\n");
  657. setlocale(LC_ALL, "zh_CN.utf8");
  658. MAIN.hinstance = GetModuleHandle(NULL);
  659. HINSTANCE* hInst = &MAIN.hinstance;
  660. WNDCLASSEXW wt;
  661. wt.cbSize = sizeof(WNDCLASSEXW);
  662. wt.cbClsExtra = 0;
  663. wt.cbWndExtra = 0;
  664. wt.hbrBackground = 0;
  665. wt.hCursor = LoadCursor(0, IDC_ARROW);
  666. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  667. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  668. wt.hInstance = *hInst;
  669. wt.lpfnWndProc = LA_WindowProc;
  670. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  671. wt.lpszMenuName = 0;
  672. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  673. if (!RegisterClassExW(&wt)) return 0;
  674. MAIN.GLMajor=MAIN.GLMajor<0?GLMajor:3; MAIN.GLMinor=MAIN.GLMinor<0?GLMinor:3; MAIN.BufferSamples=BufferSamples;
  675. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  676. SetProcessDPIAware();
  677. GLenum err;
  678. PIXELFORMATDESCRIPTOR pfd;
  679. HINSTANCE* hinst = &MAIN.hinstance;
  680. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  681. "Temp Window For Accessing GLEW!",
  682. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  683. 0, 0, *hinst, 0);
  684. HDC hdc = GetDC(hwnd);
  685. HGLRC hglrc = 0;
  686. SetPixelFormat(hdc, 1, &cpfd);
  687. hglrc = wglCreateContext(hdc);
  688. wglMakeCurrent(hdc, hglrc);
  689. //MAIN.hdc = hdc;
  690. // MAIN.tWND = hwnd;
  691. MAIN.glc = hglrc;
  692. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  693. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  694. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  695. if (err = glewInit()) {
  696. printf("Init Glew Failed\n");
  697. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  698. return 0;
  699. }
  700. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  701. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  702. if (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  703. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  704. #endif
  705. la_GetWorkingDirectoryInternal();
  706. MAIN.SavePreferenceOnExit=1;
  707. MAIN.FontSize = 0.6;
  708. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =24;
  709. MAIN.UiScale=1;
  710. MAIN.MarginSize = 1;
  711. MAIN.ColorPickerGamma=1.5;
  712. tnsInitRenderKernel(64);
  713. tnsInitBuiltinShaders();
  714. tnsSetuptnsFontManager();
  715. #define LOAD_FONT(font) \
  716. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  717. LOAD_FONT("NotoSansCJK-Regular.ttc");
  718. LOAD_FONT("NotoEmoji-Regular.ttf");
  719. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  720. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  721. //LOAD_FONT("NotoMusic-Regular.ttf");
  722. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  723. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) printf("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  724. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  725. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  726. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  727. MAIN.InputMapping=memAcquire(sizeof(laRackPageCollection));
  728. MAIN.Drivers=memAcquire(sizeof(laRackPageCollection));
  729. //interactions:
  730. MAIN.TopFramerate = 60;
  731. MAIN.ValuatorThreshold = 8;
  732. MAIN.ScrollingSpeed = 3;
  733. MAIN.AnimationSpeed = 0.4;
  734. MAIN.PanelAnimationSpeed = 0.4;
  735. MAIN.ZoomSpeed2D = 0.01;
  736. MAIN.IdleTime = 0.75;
  737. MAIN.TooltipCloseDistance = 30;
  738. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  739. //display:
  740. MAIN.FloatingAlpha = 0.7;
  741. MAIN.SolidShadowLength = 20;
  742. MAIN.WireColorSlices = 16;
  743. MAIN.WireThickness = 5;
  744. MAIN.WireSaggyness = 5;
  745. //timeline:
  746. MAIN.Animation.FrameBegin = 1;
  747. MAIN.Animation.FrameEnd = 250;
  748. MAIN.Animation.Frame = 1;
  749. MAIN.Animation.FrameRate = 25;
  750. MAIN.Animation.FrameStep = 1;
  751. laAddResourceFolder(".");
  752. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  753. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0);
  754. la_InitProgressWindow();
  755. la_MakeTranslations();
  756. //tns_RegisterResourcesForSoftwareRender();
  757. la_RegisterGeneralProps();
  758. la_RegisterBuiltinTemplates();
  759. la_RegisterMainThemes();
  760. la_RegisterMainOperators();
  761. la_RegisterMainUiTypes();
  762. la_RegisterModellingOperators();
  763. la_RegisterInternalProps();
  764. la_RegisterWindowKeys();
  765. laFinalizeUiTemplates();
  766. laFinalizeOperators();
  767. la_InitControllers();
  768. la_RegisterControllerProps();
  769. la_RegisterInputMapperOperators();
  770. tns_RegisterNodes();
  771. la_InitThreadEnviornment();
  772. laSetRootInstance(&MAIN);
  773. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  774. laPushDifferences(0, 0);
  775. la_MakeDummyManagedUDF();
  776. la_RegenerateWireColors();
  777. logPrintNew("Initialization Completed\n");
  778. MAIN.InitDone=1;
  779. return 1;
  780. }
  781. int laGetReady(){
  782. return laGetReadyWith(3,3,0);
  783. }
  784. void la_DestroyUiType(laUiType* uit);
  785. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  786. void laShutoff(int SavePrefereces){
  787. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  788. transDumpMissMatchRecord("TranslationDump.txt");
  789. if(MAIN.Cleanup) MAIN.Cleanup();
  790. strSafeDestroy(&MAIN.WorkingDirectory);
  791. strSafeDestroy(&MAIN.example_string);
  792. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  793. // (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. )
  794. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  795. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  796. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  797. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  798. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  799. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  800. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  801. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  802. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  803. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  804. strSafeDestroy(&MAIN.CopyPending);
  805. la_ClearUDFRegistryAndFolders();
  806. laClearManagedUDF();
  807. laClearSaveProp();
  808. logClear();
  809. tnsQuit();
  810. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  811. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  812. strSafeDump();
  813. hshFree(&MAIN.DBInstMemLeft);
  814. memNoLonger();
  815. #ifdef __linux__
  816. glXDestroyContext(MAIN.dpy,MAIN.glc);
  817. #endif
  818. #ifdef _WIN32
  819. wglDeleteContext(MAIN.glc);
  820. UnloadWintab();
  821. #endif
  822. }
  823. void laSaveUserPreferences(){
  824. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  825. laUDF* udf=laPrepareUDF(path);
  826. laWriteProp(udf,"la.windows");
  827. laWriteProp(udf,"la.user_preferences");
  828. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  829. laWriteProp(udf,lip->p);
  830. }
  831. laPackUDF(udf,0,0);
  832. }
  833. void laEnsureUserPreferences(){
  834. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  835. laUDFRegistry* r=laFindUDFRegistry(path);
  836. if(!r){ laSaveUserPreferences(); return; }
  837. laUDF* udf=laOpenUDF(r->Path->Ptr,1,0,0); if(!udf){ logPrint("Can't read preferences. Using default settings."); return; }
  838. laClearUDFRegistries(); while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  839. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE,0);
  840. laCloseUDF(udf);
  841. laRefreshUDFRegistries();
  842. }
  843. void laAddExtraExtension(int FileType, ...){
  844. va_list list; va_start(list,FileType);
  845. char* ext;
  846. while(ext=va_arg(list,char*)){ if(!ext) break;
  847. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  848. et->FileType=FileType; et->Extension=ext;
  849. lstAppendItem(&MAIN.ExtraExtensions, et);
  850. }
  851. va_end(list);
  852. }
  853. void laAddExtraPreferencePath(const char* path){
  854. if(!path) return;
  855. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  856. }
  857. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  858. if(!name || !Func) return;
  859. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  860. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  861. }
  862. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  863. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  864. }
  865. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  866. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  867. }
  868. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  869. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  870. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  871. }
  872. //MSG====================================================
  873. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  874. if (wnd->win == hwnd) return 1;
  875. else return 0;
  876. };
  877. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  878. if (p->SL){ int s=p->SL<0?0:p->SL;
  879. if (p->TX != s) laRecalcPanel(p);
  880. p->TX = s;
  881. }
  882. if (p->SR){ int s=p->SR<0?0:p->SR;
  883. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  884. p->TW = CW - p->TX - s;
  885. }
  886. if (p->ST){ int s=p->ST<0?0:p->ST;
  887. if (p->TY != s) laRecalcPanel(p);
  888. p->TY = s;
  889. }
  890. if (p->SB){ int s=p->SB<0?0:p->SB;
  891. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  892. p->TH = CH - p->TY - s;
  893. }
  894. }
  895. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  896. laPanel *p = 0;
  897. b->X = X;
  898. b->Y = Y;
  899. b->W = W;
  900. b->H = H;
  901. if (b->B1){
  902. int SplitWidth;
  903. if (b->Vertical){
  904. SplitWidth = H * b->SplitRatio;
  905. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  906. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  907. }else{
  908. SplitWidth = W * b->SplitRatio;
  909. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  910. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  911. }
  912. }
  913. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  914. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  915. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  916. }
  917. if (p = b->CurrentPanel){
  918. int TitleGap=b->Folded?0:LA_RH;
  919. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  920. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  921. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  922. laRecalcPanel(p);
  923. }
  924. }
  925. void la_UpdateUiPlacement(laWindow *w){
  926. laLayout *l;
  927. laPanel *p;
  928. int CW = w->CW;
  929. int CH = w->CH;
  930. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  931. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  932. if(w->MaximizedUi && w->MaximizedUiPanel){
  933. laRecalcPanel(w->MaximizedUiPanel);
  934. }elif(w->MaximizedBlock){
  935. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  936. }else{
  937. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  938. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  939. }
  940. }
  941. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  942. if(p->IsMenuPanel){
  943. p->TH=p->H=MenuHeight;
  944. }
  945. la_EnsurePanelSnapping(p, CW, CH);
  946. laRecalcPanel(p);
  947. }
  948. }
  949. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  950. laWindow *window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  951. if (!window) return;
  952. #ifdef _WIN32
  953. RECT rc; GetClientRect(window->win, &rc);
  954. window->CW = rc.right - rc.left;
  955. window->CH = rc.bottom - rc.top;
  956. window->W = window->CW; window->H = window->CH;
  957. window->X = rc.left; window->Y = rc.top;
  958. #endif
  959. #ifdef __linux__
  960. XWindowAttributes attr;
  961. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  962. window->CW = w; window->CH = h;
  963. window->W = w; window->H = h;
  964. window->X = x; window->Y = y;
  965. #endif
  966. la_UpdateUiPlacement(window);
  967. }
  968. int la_OnWindowDestroy(SYSWINDOW wnd){
  969. laListHandle *hlst = &MAIN.Windows;
  970. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  971. if (!w) return 0;
  972. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  973. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  974. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  975. laShutoff(1);
  976. return 1;
  977. }
  978. laListHandle h={0};laLayout*l=0;
  979. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  980. la_DestroyWindow(w);
  981. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  982. #ifdef __linux__
  983. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  984. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  985. #endif
  986. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  987. }
  988. return 0;
  989. }
  990. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  991. laListHandle *el = &wnd->EventList;
  992. laEvent* last_e=el->pLast;
  993. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  994. #ifdef __linux__
  995. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  996. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  997. #endif
  998. #ifdef _WIN32
  999. 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);
  1000. #endif
  1001. }
  1002. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1003. laListHandle *wl = &MAIN.Windows;
  1004. laWindow* wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1005. if (!wnd){ memFree(e); return; }
  1006. laListHandle *el = &wnd->EventList;
  1007. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1008. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1009. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1010. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1011. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1012. e->IsEraser=MAIN.PointerIsEraser;
  1013. e->GoodPressure=MAIN.IsPen;
  1014. lstAppendItem(el, (laListItem *)e);
  1015. laMappingRequestEval();
  1016. };
  1017. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1018. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->Type = type; e->key = key;
  1019. la_SaveEvent(hwnd, e, 1);
  1020. };
  1021. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1022. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1023. e->Type = LA_INPUT; e->Input=Input;
  1024. la_SaveEvent(hwnd, e, 1);
  1025. }
  1026. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1027. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1028. e->Type = LA_EMPTY;
  1029. la_SaveEvent(hwnd, e, 1);
  1030. }
  1031. void laSendOperatorTriggerEvent(){
  1032. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1033. MAIN.ReTriggerOperators = 0;
  1034. }
  1035. int la_TranslateSpecialKey(int keysym){
  1036. #ifdef __linux__
  1037. switch(keysym){
  1038. case XK_Return: return LA_KEY_ENTER;
  1039. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1040. case XK_Delete: return LA_KEY_DELETE;
  1041. case XK_Escape: return LA_KEY_ESCAPE;
  1042. case XK_Tab: return LA_KEY_TAB;
  1043. case XK_Left: return LA_KEY_ARRLEFT;
  1044. case XK_Right: return LA_KEY_ARRRIGHT;
  1045. case XK_Up: return LA_KEY_ARRUP;
  1046. case XK_Down: return LA_KEY_ARRDOWN;
  1047. case XK_Control_L: return LA_KEY_CTRL;
  1048. case XK_Control_R: return LA_KEY_CTRL;
  1049. case XK_Shift_L: return LA_KEY_SHIFT;
  1050. case XK_Shift_R: return LA_KEY_SHIFT;
  1051. case XK_Alt_L: return LA_KEY_ALT;
  1052. case XK_Alt_R: return LA_KEY_ALT;
  1053. default: return keysym;
  1054. }
  1055. #endif
  1056. #ifdef _WIN32
  1057. switch (keysym) {
  1058. case VK_RETURN: return LA_KEY_ENTER;
  1059. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1060. case VK_TAB: return LA_KEY_TAB;
  1061. case VK_LEFT: return LA_KEY_ARRLEFT;
  1062. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1063. case VK_UP: return LA_KEY_ARRUP;
  1064. case VK_DOWN: return LA_KEY_ARRDOWN;
  1065. case VK_CONTROL: return LA_KEY_CTRL;
  1066. case VK_SHIFT: return LA_KEY_SHIFT;
  1067. case VK_MENU: return LA_KEY_ALT;
  1068. default: return keysym;
  1069. }
  1070. #endif
  1071. }
  1072. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1073. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1074. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1075. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1076. // la_SaveEvent(hwnd, e, 0);
  1077. //}
  1078. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1079. e->Type = type; e->x = x; e->y = y;
  1080. la_SaveEvent(hwnd, e, 0);
  1081. MAIN.evLastX=x; MAIN.evLastY=y;
  1082. };
  1083. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1084. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1085. e->Type = type;
  1086. la_SaveEvent(hwnd, e, 1);
  1087. };
  1088. void laRetriggerOperators(){
  1089. MAIN.ReTriggerOperators = 1;
  1090. }
  1091. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1092. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1093. }
  1094. void laSetCleanupCallback(laCleanupF Cleanup){
  1095. MAIN.Cleanup=Cleanup;
  1096. }
  1097. //====================================================================================================
  1098. void la_DestroyTheme(laTheme* t){
  1099. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1100. strSafeDestroy(&t->Name);
  1101. strSafeDestroy(&t->Author);
  1102. }
  1103. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1104. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1105. strSafeSet(&t->Name, Name);
  1106. strSafeSet(&t->Author, AuthorName);
  1107. lstAppendItem(&MAIN.Themes, t);
  1108. MAIN.CurrentTheme = t;
  1109. return t;
  1110. }
  1111. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1112. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1113. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1114. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1115. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1116. strSafeSet(&bt->Name, Name);
  1117. bt->NormalY=NormalY;
  1118. bt->ActiveY=ActiveY;
  1119. bt->BorderY=BorderY;
  1120. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1121. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1122. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1123. bt->BackRef = BackRef;
  1124. lstAppendItem(&t->BoxedThemes, bt);
  1125. return bt;
  1126. }
  1127. laTheme *laGetTheme(const char *ThemeName){
  1128. laTheme *t = MAIN.Themes.pFirst;
  1129. for (t; t; t = t->Item.pNext){
  1130. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1131. }
  1132. return 0;
  1133. }
  1134. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1135. laTheme *t = MAIN.Themes.pFirst;
  1136. for (t; t; t = t->Item.pNext){
  1137. laBoxedTheme *bt;
  1138. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1139. bt = t->BoxedThemes.pFirst;
  1140. for (bt; bt; bt = bt->Item.pNext){
  1141. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1142. }
  1143. }
  1144. return 0;
  1145. }
  1146. real* laThemeColor(laBoxedTheme* bt, int which){
  1147. switch(which){
  1148. default:
  1149. case LA_BT_NORMAL: return bt->Normal;
  1150. case LA_UI_EDITING:
  1151. case LA_BT_ACTIVE: return bt->Active;
  1152. case LA_BT_BORDER: return bt->Border;
  1153. case LA_BT_TEXT: return bt->Text; break;
  1154. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1155. case LA_BT_DISABLED: return bt->Inactive; break;
  1156. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1157. }
  1158. return bt->Normal;
  1159. }
  1160. real* laAccentColor(int which){
  1161. switch(which){
  1162. default:
  1163. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1164. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1165. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1166. case LA_BT_FACE:
  1167. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1168. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1169. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1170. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1171. }
  1172. return MAIN.CurrentTheme->SelectionColor;
  1173. }
  1174. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1175. real hcy[3];
  1176. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1177. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1178. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1179. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1180. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1181. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1182. int *tm=&bt->LM,*tp=&bt->LP;
  1183. for(int i=0;i<4;i++){
  1184. tm[i]=bt->Margins[i]*LA_RH*MAIN.MarginSize;
  1185. tp[i]=bt->Paddings[i]*LA_RH*MAIN.MarginSize;
  1186. }
  1187. }
  1188. void la_RefreshThemeColorSelf(laTheme* th){
  1189. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1190. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha;
  1191. real hcy[3], usehcy[3];
  1192. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1193. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1194. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1195. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1196. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1197. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1198. }
  1199. void la_RefreshThemeColor(laTheme* th){
  1200. real hcy[3], usehcy[3], normalhcy[3];
  1201. tnsRGB2HCY(th->Color,hcy);
  1202. la_RefreshThemeColorSelf(th);
  1203. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1204. la_RefreshBoxedThemeColor(bt);
  1205. (*bt->BackRef) = bt;
  1206. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1207. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1208. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1209. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1210. }
  1211. }
  1212. //I FUCKING HATE THIS STUPID FUNCTION
  1213. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1214. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1215. laUiListDrawItem *last = uild->Items.pFirst;
  1216. int LimW=_R-_L;
  1217. int SL, SR, SU, SB;
  1218. int Target__B = Target->B;
  1219. int Target__R = Target->R;
  1220. uildi->Target = Target;
  1221. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1222. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1223. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1224. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1225. uildi->L = last ? Target->L - last->XP : Target->L;
  1226. uildi->R = last ? Target__R - last->XP : Target__R;
  1227. uildi->U = last ? Target->U - last->YP : Target->U;
  1228. uildi->B = last ? Target__B - last->YP : Target__B;
  1229. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1230. uildi->L -= GlobalX;
  1231. uildi->R -= GlobalX;
  1232. uildi->U -= GlobalY;
  1233. uildi->B -= GlobalY;
  1234. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1235. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1236. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1237. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1238. uildi->DifX = SL - uildi->L;
  1239. uildi->DifY = SU - uildi->U;
  1240. uildi->L = SL;
  1241. uildi->R = SR+uildi->DifX;
  1242. uildi->U = SU;
  1243. uildi->B = SB;//+uildi->DifY;
  1244. if(uildi->R>_R){ uildi->R=_R; }
  1245. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1246. //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);
  1247. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1248. memFree(uildi);
  1249. return 0;
  1250. }
  1251. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  1252. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  1253. Target->L + Target->PanX + uildi->DifX +1+ (uildi->R - uildi->L),
  1254. Target->U + Target->PanY + uildi->DifY +1+ (uildi->B - uildi->U),
  1255. Target->U + Target->PanY + uildi->DifY -1,
  1256. -100, 100);
  1257. lstPushItem(&uild->Items, uildi);
  1258. return 1;
  1259. }
  1260. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1261. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1262. laUiListDrawItem *last = uild->Items.pFirst;
  1263. int SL, SR, SU, SB;
  1264. if (B - U > LimH) B = U + LimH;
  1265. uildi->XP = last ? last->XP + PanX : PanX;
  1266. uildi->YP = last ? last->YP + PanY : PanY;
  1267. uildi->L = last ? L - last->XP : L;
  1268. uildi->R = last ? R - last->XP : R;
  1269. uildi->U = last ? U - last->YP : U;
  1270. uildi->B = last ? B - last->YP : B;
  1271. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1272. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1273. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1274. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1275. uildi->DifX = SL - uildi->L;
  1276. uildi->DifY = SU - uildi->U;
  1277. uildi->L = SL;
  1278. uildi->R = SR;
  1279. uildi->U = SU;
  1280. uildi->B = SB;
  1281. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1282. tnsOrtho(L + PanX + uildi->DifX,
  1283. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  1284. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  1285. U + PanY + uildi->DifY,
  1286. -100, 100);
  1287. lstPushItem(&uild->Items, uildi);
  1288. }
  1289. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  1290. laUiListDrawItem *uildi = uild->Items.pFirst;
  1291. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  1292. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  1293. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  1294. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  1295. Target->U + Target->PanY + uildi->DifY -1,
  1296. -100, 100);
  1297. }
  1298. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  1299. laUiListDrawItem *uildi = lstPopItem(uild);
  1300. laUiList *Target;
  1301. memFree(uildi);
  1302. uildi = uild->Items.pFirst;
  1303. if (!uildi || !uildi->Target){
  1304. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  1305. return;
  1306. }
  1307. Target = uildi->Target;
  1308. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  1309. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  1310. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  1311. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  1312. Target->U + Target->PanY + uildi->DifY -1,
  1313. -100, 100);
  1314. }
  1315. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  1316. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1317. uildi->L = L;
  1318. uildi->R = R;
  1319. uildi->U = U;
  1320. uildi->B = B;
  1321. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1322. tnsOrtho(L, R, B, U, -100, 100);
  1323. lstPushItem(&uild->Items, uildi);
  1324. }
  1325. void la_ClearUiListMatrix(laUiListDraw *uild){
  1326. laUiListDrawItem *uildi;
  1327. while (uildi = lstPopItem(uild)){
  1328. memFree(uildi);
  1329. }
  1330. }
  1331. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  1332. 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);
  1333. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  1334. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  1335. int la_TestUiListMinumWidth(laUiList *uil);
  1336. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  1337. if (ui){
  1338. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  1339. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  1340. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  1341. p->X = p->TX; p->Y = p->TY;
  1342. p->W = p->TW;
  1343. }
  1344. }
  1345. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  1346. int cw = MAIN.CurrentWindow->CW;
  1347. int ch = MAIN.CurrentWindow->CH;
  1348. int PH = p->TH;
  1349. laBoxedTheme*bt = *p->BT;
  1350. int uih=uil->B + bt->TM+bt->BM;
  1351. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  1352. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  1353. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  1354. else p->TH = PH;
  1355. p->H = p->TH;
  1356. if(p->BoundUi){
  1357. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  1358. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  1359. if (p->X < 0) p->X = 0;
  1360. if (p->Y < 0) p->Y = 0;
  1361. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  1362. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  1363. }else{
  1364. if (p->X+p->W < LA_RH*5) p->X = LA_RH*5-+p->W;
  1365. if (p->Y < 0) p->Y = 0;
  1366. if (p->X > cw-LA_RH*2) p->X = cw-LA_RH*2;
  1367. if (p->Y > ch-LA_RH*2) p->Y = ch-LA_RH;
  1368. if (p->W > cw){ p->W = cw; } if (p->H > ch){ p->H = ch; }
  1369. }
  1370. if(!p->IsMenuPanel){
  1371. if(p->W<LA_RH*4) p->W=LA_RH*4;
  1372. if(p->H<LA_RH*2) p->H=LA_RH*2;
  1373. }
  1374. if (p->ST) p->TY = p->ST;
  1375. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  1376. if (p->SB) p->TH = ch - p->TY - p->SB;
  1377. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  1378. p->TX = p->X; p->TY = p->Y;
  1379. p->TW = p->W; p->TH = p->H;
  1380. if (p->OffScr &&
  1381. (p->W != p->OffScr->pColor[0]->Width ||
  1382. p->H != p->OffScr->pColor[0]->Height)){
  1383. tnsConfigureOffscreen(p->OffScr, p->W,p->H);
  1384. }
  1385. }
  1386. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  1387. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1388. tnsViewportWithScissor(0, 0, p->W, p->H);
  1389. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  1390. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1391. }
  1392. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  1393. tnsDrawToScreen();
  1394. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  1395. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1396. }
  1397. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  1398. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  1399. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  1400. }
  1401. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  1402. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  1403. tnsClearAll();
  1404. }
  1405. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  1406. real Color[] = {1, 1, 1, 1};
  1407. real L, W, U, H;
  1408. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  1409. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  1410. switch (p->AnimationMode){
  1411. case 0:
  1412. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  1413. if(p->ShowCorner && ((!p->SR) && (!p->SB))){ tnsDrawStringAuto("◢",laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT),p->X+p->W-LA_RH,p->X+p->W,p->Y+p->H-LA_RH,0); }
  1414. //if(p->Mode==LA_PANEL_FLOATING_TOP)
  1415. // tnsDrawStringAuto("◿",laThemeColor(*p->BT,LA_BT_BORDER),p->X+p->W-LA_RH, p->X+p->W, p->H+p->Y-LA_RH, LA_TEXT_ALIGN_CENTER);
  1416. break;
  1417. case LA_PANEL_ANIMATION_DROP_DOWN:
  1418. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1419. tnsDraw2DTextureArg(
  1420. p->OffScr->pColor[0],
  1421. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  1422. Color,
  1423. 0, 0, 1 - p->AnimationRatio, 0);
  1424. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1425. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  1426. break;
  1427. case LA_PANEL_ANIMATION_EXPAND:
  1428. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1429. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1430. W = tnsLinearItp(0, p->W, 0.4);
  1431. H = tnsLinearItp(0, p->H, 0.4);
  1432. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1433. tnsDraw2DTextureArg(
  1434. p->OffScr->pColor[0],
  1435. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1436. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1437. Color,
  1438. 0, 0, 0, 0);
  1439. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1440. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  1441. break;
  1442. case LA_PANEL_ANIMATION_DISSOVE:
  1443. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  1444. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  1445. W = tnsLinearItp(0, p->W, 1.4);
  1446. H = tnsLinearItp(0, p->H, 1.4);
  1447. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  1448. if (p->OffScr) tnsDraw2DTextureArg(
  1449. p->OffScr->pColor[0],
  1450. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1451. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1452. Color,
  1453. 0, 0, 0, 0);
  1454. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1455. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1456. break;
  1457. case LA_PANEL_ANIMATION_COLLAPSE:
  1458. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1459. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1460. W = tnsLinearItp(0, p->W, 0.4);
  1461. H = tnsLinearItp(0, p->H, 0.4);
  1462. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1463. if (p->OffScr) tnsDraw2DTextureArg(
  1464. p->OffScr->pColor[0],
  1465. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1466. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1467. Color,
  1468. 0, 0, 0, 0);
  1469. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1470. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1471. break;
  1472. case LA_PANEL_ANIMATION_MINIMIZE:
  1473. L = tnsLinearItp(0, p->X, 0.3);
  1474. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  1475. W = tnsLinearItp(0, p->W, 0.4);
  1476. H = tnsLinearItp(0, p->H, 0.4);
  1477. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1478. tnsDraw2DTextureArg(
  1479. p->OffScr->pColor[0],
  1480. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1481. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1482. Color,
  1483. 0, 0, 0, 0);
  1484. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1485. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1486. break;
  1487. }
  1488. tnsFlush();
  1489. tnsUniformOutputColorSpace(T->immShader,0);
  1490. tnsUniformShowColorOverflowStripes(T->immShader,0);
  1491. }
  1492. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  1493. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  1494. if (!p->OffScr){
  1495. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:GL_RGBA8;
  1496. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0);
  1497. }
  1498. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1499. }
  1500. void la_PanelRefreshDetachedProp(laPanel *panel){
  1501. laProp *p;
  1502. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  1503. la_StepPropPack(&p->DetachedPP);
  1504. la_UsePropPack(&p->DetachedPP, 0);
  1505. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  1506. // laUseDataBlock(
  1507. // p->DetachedPP.LastPs->UseInstance,
  1508. // p->DetachedPP.LastPs->p,
  1509. // MAIN.PropMatcherContextP->FrameDistinguish,
  1510. // MAIN.PropMatcherContextP,
  1511. // la_PropPanelUserRemover, 0);
  1512. //}
  1513. }
  1514. }
  1515. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  1516. real* color=laThemeColor(bt,LA_BT_BORDER);
  1517. tnsColor4d(0,0,0,Alpha);
  1518. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  1519. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  1520. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  1521. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  1522. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  1523. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  1524. tnsPackAs(GL_TRIANGLE_STRIP);
  1525. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1526. tnsVertex2d(Panel->X, Panel->Y);
  1527. tnsVertex2d(Panel->X, Panel->Y + Panel->H);
  1528. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  1529. tnsVertex2d(Panel->X + Panel->W, Panel->Y);
  1530. tnsPackAs(GL_LINE_LOOP);
  1531. }
  1532. int la_AnimateUiListRecursive(laUiList *uil);
  1533. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  1534. int DrawState_ = 0;
  1535. laUiListDraw uild = {0};
  1536. if (p->Show){
  1537. la_SetPropMathcerContext(p);
  1538. MAIN.CurrentPanel = p;
  1539. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  1540. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  1541. //}
  1542. if (p->Refresh & LA_TAG_RECALC){
  1543. laRecalcPanelImmediate(p);
  1544. }
  1545. if (!p->MenuRefer){
  1546. if(!p->OffScr){la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  1547. if (p->Refresh || !p->OffScr){
  1548. la_PanelDrawToOffsceen(p, &p->UI);
  1549. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  1550. la_PanelBackgroundInit(p, bt);
  1551. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U-bt->TM-bt->BM, p->H-p->TitleBar.B-bt->TM-bt->BM*2, p->W);
  1552. tnsFlush();
  1553. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  1554. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  1555. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  1556. DrawState_++;
  1557. }
  1558. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  1559. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  1560. if(p->UI.PanY<0){p->UI.PanY=0;}
  1561. DrawState_++;
  1562. }
  1563. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  1564. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  1565. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  1566. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  1567. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  1568. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1569. if(p!=w->MaximizedUiPanel){
  1570. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1571. }else{
  1572. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  1573. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  1574. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  1575. tnsFlush();
  1576. }
  1577. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  1578. }
  1579. }else{
  1580. if (p->Refresh || !p->OffScr){
  1581. la_PanelDrawToOffsceen(p, p->MenuRefer);
  1582. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  1583. la_PanelBackgroundInit(p, bt);
  1584. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  1585. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  1586. tnsFlush();
  1587. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  1588. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  1589. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  1590. DrawState_++;
  1591. }
  1592. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  1593. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  1594. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  1595. DrawState_++;
  1596. }
  1597. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  1598. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  1599. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  1600. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1601. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  1602. }
  1603. }
  1604. tnsDrawToScreen();
  1605. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1606. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  1607. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99))){
  1608. tnsUseNoTexture();
  1609. if (!p->IsMenuPanel){
  1610. la_PanelDrawDescendBorder(p, bt, MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  1611. }
  1612. tnsFlush();
  1613. }
  1614. la_PanelDrawToWindow(p, w);
  1615. }elif (p->AnimationMode){
  1616. la_PanelDrawToWindow(p, w);
  1617. }
  1618. }
  1619. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  1620. if(!p->Show && p!=w->MaximizedUiPanel) return;
  1621. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  1622. laPanel *pi, *PrevPI;
  1623. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  1624. PrevPI = pi->Item.pPrev;
  1625. if (pi->AnimationMode && pi->LaterDestroy){
  1626. lstRemoveItem(&p->SubPanels, pi);
  1627. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  1628. continue;
  1629. }
  1630. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  1631. la_AttachedPanelDefDraw(w,pi,bt);
  1632. }
  1633. }
  1634. }
  1635. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  1636. real PanelSquare[] = {
  1637. b->X + 2, CH - (b->Y + 2 + LA_RH),
  1638. b->X + 2, CH - (b->Y + b->H - 4),
  1639. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  1640. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  1641. real Center[] = {
  1642. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  1643. real DraggingPlot[] = {
  1644. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  1645. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  1646. PanelSquare[0],
  1647. PanelSquare[1],
  1648. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  1649. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  1650. PanelSquare[2],
  1651. PanelSquare[3],
  1652. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  1653. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  1654. PanelSquare[4],
  1655. PanelSquare[5],
  1656. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  1657. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  1658. PanelSquare[6],
  1659. PanelSquare[7],
  1660. };
  1661. real Square[] = {
  1662. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  1663. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  1664. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  1665. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  1666. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  1667. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  1668. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  1669. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  1670. };
  1671. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  1672. LA_COLOR3(BorderColor4dV), 0,
  1673. LA_COLOR3(BorderColor4dV), 0.8,
  1674. LA_COLOR3(BorderColor4dV), 0,
  1675. LA_COLOR3(BorderColor4dV), 0.8,
  1676. LA_COLOR3(BorderColor4dV), 0,
  1677. LA_COLOR3(BorderColor4dV), 0.8,
  1678. LA_COLOR3(BorderColor4dV), 0,
  1679. };
  1680. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  1681. LA_COLOR3(FillColor4dv), 0,
  1682. LA_COLOR3(FillColor4dv), 0.8,
  1683. LA_COLOR3(FillColor4dv), 0,
  1684. LA_COLOR3(FillColor4dv), 0.8,
  1685. LA_COLOR3(FillColor4dv), 0,
  1686. LA_COLOR3(FillColor4dv), 0.8,
  1687. LA_COLOR3(FillColor4dv), 0,
  1688. };
  1689. tnsUseNoTexture();
  1690. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  1691. int Index[4];
  1692. tnsVertexArray2d(DraggingPlot, 8);
  1693. tnsColorArray4d(FillColor, 8);
  1694. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  1695. case 0:
  1696. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  1697. break;
  1698. case LA_BLOCK_DROP_LOCATION_L:
  1699. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  1700. break;
  1701. case LA_BLOCK_DROP_LOCATION_R:
  1702. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  1703. break;
  1704. case LA_BLOCK_DROP_LOCATION_U:
  1705. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  1706. break;
  1707. case LA_BLOCK_DROP_LOCATION_B:
  1708. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  1709. break;
  1710. }
  1711. //glDisable(GL_CULL_FACE);
  1712. tnsIndexArray(Index, 4);
  1713. tnsPackAs(GL_TRIANGLE_FAN);
  1714. //tnsFlush();
  1715. }
  1716. tnsVertexArray2d(DraggingPlot, 8);
  1717. tnsColorArray4d(PlotColor, 8);
  1718. tnsPackAs(GL_LINES);
  1719. tnsVertexArray2d(Square, 4);
  1720. tnsColor4dv(BorderColor4dV);
  1721. tnsPackAs(GL_LINE_LOOP);
  1722. glLineWidth(LA_SEAM_W);
  1723. tnsFlush();
  1724. glLineWidth(1);
  1725. }
  1726. void la_BlockDefDrawSelf(laBlock *b, int CH){
  1727. laBoxedTheme *bt = _LA_THEME_TAB;
  1728. laPanel *p;
  1729. real v[] = {
  1730. b->X, CH - b->Y,
  1731. b->X + LA_SEAM_W, CH - b->Y ,
  1732. b->X, CH - (b->Y + b->H),
  1733. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  1734. b->X + b->W, CH - (b->Y + b->H),
  1735. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  1736. b->X + b->W, CH - b->Y,
  1737. b->X + b->W - LA_SEAM_W, CH - b->Y};
  1738. real tv[8];
  1739. real ratio = 1.0001f;
  1740. int tw = 0;
  1741. int L = LA_RH+LA_SEAM_W;
  1742. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  1743. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1744. tw += p->TitleWidth + LA_SEAM_W*2;
  1745. }
  1746. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  1747. tnsUseNoTexture();
  1748. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  1749. tnsVertexArray2d(v, 8);
  1750. tnsPackAs(GL_TRIANGLE_STRIP);
  1751. int TitleGap=b->Folded?0:LA_RH;
  1752. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  1753. b->X + b->W, (CH - b->Y),
  1754. b->X + b->W, (CH - b->Y - TitleGap),
  1755. b->X, (CH - b->Y - TitleGap));
  1756. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  1757. tnsVertexArray2d(tv, 4);
  1758. tnsPackAs(GL_TRIANGLE_FAN);
  1759. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  1760. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  1761. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  1762. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  1763. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1764. tnsVertexArray2d(tv, 4);
  1765. tnsPackAs(GL_TRIANGLE_FAN);
  1766. if(b->Folded){
  1767. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  1768. 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);
  1769. 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);
  1770. tnsFlush(); return;
  1771. }
  1772. int LT=0,RT=0;
  1773. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1774. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  1775. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  1776. b->X + L+RT * ratio, (CH - b->Y),
  1777. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  1778. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  1779. if (p == b->CurrentPanel){
  1780. tnsUseNoTexture();
  1781. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1782. tnsVertexArray2d(tv, 4);
  1783. tnsPackAs(GL_TRIANGLE_FAN);
  1784. 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);
  1785. }else{
  1786. 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);
  1787. }
  1788. LT =RT;
  1789. }
  1790. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  1791. tnsFlush();
  1792. tnsUniformOutputColorSpace(T->immShader,0);
  1793. }
  1794. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  1795. laBoxedTheme *bt = _LA_THEME_PANEL;
  1796. real tv[8];
  1797. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  1798. tnsUseNoTexture();
  1799. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  1800. b->X + b->W, (CH - b->Y),
  1801. b->X + b->W, (CH - b->Y-b->H),
  1802. b->X, (CH - b->Y-b->H));
  1803. tnsVertexArray2d(tv, 4);
  1804. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  1805. tnsPackAs(GL_TRIANGLE_FAN);
  1806. 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,
  1807. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  1808. tnsFlush();
  1809. tnsUniformOutputColorSpace(T->immShader,0);
  1810. }
  1811. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  1812. if (b->B1){
  1813. la_BlockDefDrawRecursive(w, bt, b->B1);
  1814. la_BlockDefDrawRecursive(w, bt, b->B2);
  1815. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  1816. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  1817. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  1818. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1819. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1820. la_BlockDefDrawSelf(b, w->CH);
  1821. }else{
  1822. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1823. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1824. la_BlockDefDrawSelfEmpty(b, w->CH);
  1825. }
  1826. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  1827. tnsUseNoTexture();
  1828. int at; real tv[8];
  1829. if (b->Vertical){
  1830. at = b->H * b->SplitRatio + b->Y;
  1831. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  1832. b->X + b->W, (w->CH - at + LA_SEAM_W),
  1833. b->X + b->W, (w->CH - at - LA_SEAM_W),
  1834. b->X, (w->CH - at - LA_SEAM_W));
  1835. }else{
  1836. at = b->X + b->W * b->SplitRatio;
  1837. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  1838. at- LA_SEAM_W, (w->CH - b->Y),
  1839. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  1840. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  1841. }
  1842. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  1843. tnsVertexArray2d(tv, 4);
  1844. tnsPackAs(GL_TRIANGLE_FAN);
  1845. }
  1846. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  1847. tnsFlush();
  1848. }
  1849. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  1850. if (b->B1){
  1851. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  1852. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  1853. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  1854. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  1855. }
  1856. tnsFlush();
  1857. }
  1858. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  1859. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  1860. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  1861. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  1862. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  1863. if(p->OffScr){
  1864. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  1865. }
  1866. }
  1867. }
  1868. void la_ClearUnusedFramebuffers(laWindow* w){
  1869. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  1870. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  1871. }
  1872. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  1873. if(p->Show || p->AnimationMode) continue;
  1874. if(p->OffScr){
  1875. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  1876. }
  1877. }
  1878. }
  1879. void laDeferredDestroyPanel(laPanel* p, int immediate);
  1880. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  1881. laPanel *p, *NextP;
  1882. laLayout *l = w->CurrentLayout;
  1883. la_ClearUnusedFramebuffers(w);
  1884. tnsDrawToScreen();
  1885. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1886. glClearColor(0.2, 0.2, 0.3, 1.0);
  1887. tnsClearAll();
  1888. tnsUseNoTexture();
  1889. if (l->Draw) l->Draw(w, l);
  1890. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  1891. //tnsShadeMode(GL_SMOOTH);
  1892. glEnable(GL_BLEND);
  1893. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1894. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  1895. laUiItem* ui;
  1896. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  1897. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  1898. if(p->Refresh){
  1899. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  1900. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  1901. if(p->Refresh&LA_TAG_RECALC){
  1902. la_SetPropMathcerContext(p);
  1903. laRecalcPanelImmediate(p);
  1904. }
  1905. ui->Type->Draw(ui, LA_RH); tnsFlush();
  1906. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  1907. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  1908. }
  1909. tnsDrawToScreen();
  1910. tnsResetViewMatrix();
  1911. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1912. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  1913. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  1914. tnsFlush();
  1915. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  1916. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  1917. tnsFlush();
  1918. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  1919. }
  1920. }
  1921. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  1922. }else{
  1923. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  1924. la_BlockDefDrawRecursive(w, bt, RootBlock);
  1925. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  1926. }
  1927. for (p = w->Panels.pLast; p; p = NextP){
  1928. NextP = p->Item.pPrev;
  1929. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  1930. if (p->AnimationMode && p->LaterDestroy){
  1931. lstRemoveItem(&w->Panels, p);
  1932. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  1933. continue;
  1934. }
  1935. la_PanelDefDraw(w, p, *p->BT);
  1936. }
  1937. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  1938. la_AttachedPanelDefDraw(w,p,*p->BT);
  1939. }
  1940. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  1941. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  1942. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1943. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  1944. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  1945. tnsFlush();
  1946. }
  1947. for (p = w->FadingPanels.pLast; p; p = NextP){
  1948. NextP = p->Item.pPrev;
  1949. if (!p->AnimationMode){
  1950. lstRemoveItem(&w->FadingPanels, p);
  1951. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  1952. laDeferredDestroyPanel(p, 0);
  1953. }else
  1954. la_PanelDrawToWindow(p, w);
  1955. }
  1956. }
  1957. int laStartWindow(laWindow *w){
  1958. #ifdef __linux__
  1959. XMapWindow(MAIN.dpy,w->win);
  1960. glXMakeContextCurrent(MAIN.dpy, w->win,w->win, w->glc);
  1961. #endif
  1962. #ifdef _WIN32
  1963. ShowWindow(w->win, SW_SHOWNORMAL);
  1964. #endif
  1965. MAIN.CurrentWindow = w;
  1966. if(!w->CurrentLayout){
  1967. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  1968. w->CurrentLayout=w->Layouts.pFirst;
  1969. }
  1970. laRedrawCurrentWindow();
  1971. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  1972. w->Shown = 1;
  1973. }
  1974. void la_AssignWindowPP(laWindow* w){
  1975. w->PP.EndInstance = w;
  1976. w->PP.LastPs = &w->FakePS;
  1977. w->PP.LastPs->p = _LA_PROP_WINDOW;
  1978. w->PP.LastPs->UseInstance = w;
  1979. w->PP.LastPs->Type = U'.';
  1980. }
  1981. laWindow *laDesignWindow(int X, int Y, int W, int H){
  1982. laWindow *n = memAcquire(sizeof(laWindow));
  1983. strSafeSet(&n->Title, "Empty SYSWINDOW");
  1984. n->X = X; n->Y = Y; n->W = W; n->H = H;
  1985. n->OutputShowStripes=1;
  1986. n->Redraw=1;
  1987. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  1988. lstAppendItem(&MAIN.Windows, n);
  1989. MAIN.CurrentWindow = n;
  1990. la_AssignWindowPP(n);
  1991. laui_DefaultMenuBar(n);
  1992. return n;
  1993. }
  1994. void laSetWindowCursor(int id){
  1995. #ifdef __linux__
  1996. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  1997. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  1998. #endif
  1999. #ifdef _WIN32
  2000. SetCursor(la_ConvertCursorID(id));
  2001. #endif
  2002. };
  2003. void la_AssignBlockPP(laBlock* b){
  2004. b->PP.EndInstance = b;
  2005. b->PP.LastPs = &b->FakePS;
  2006. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2007. b->PP.LastPs->UseInstance = b;
  2008. b->PP.LastPs->Type = U'.';
  2009. }
  2010. void laDestroyLayout(laWindow *w, laLayout* l){
  2011. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2012. laDestroyBlocksRecursive(l->FirstBlock);
  2013. strSafeDestroy(&l->ID);
  2014. if(w->CurrentLayout==l){ w->CurrentLayout=l->Item.pPrev?l->Item.pPrev:l->Item.pNext; }
  2015. lstRemoveItem(&w->Layouts,l); memFree(l);
  2016. }
  2017. laLayout *laDesignLayout(laWindow *w, char *Title){
  2018. laLayout *l = memAcquireHyper(sizeof(laLayout));
  2019. l->FirstBlock = memAcquire(sizeof(laBlock));
  2020. la_AssignBlockPP(l->FirstBlock);
  2021. lstAppendItem(&w->Layouts, l);
  2022. strSafeSet(&l->ID, Title);
  2023. w->CurrentLayout = l;
  2024. laRenameWindow(w, Title);
  2025. return l;
  2026. }
  2027. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2028. 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); }
  2029. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2030. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2031. laNotifyUsers("la.windows.maximized_block"); }
  2032. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2033. laNotifyUsers("la.windows.maximized_block"); }
  2034. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2035. laRestoreCanvasUI();
  2036. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2037. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2038. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2039. UiParentPanel->Show=0;
  2040. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2041. }
  2042. void laRestoreCanvasUI(){
  2043. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2044. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2045. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2046. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2047. }
  2048. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2049. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2050. }
  2051. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2052. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2053. laPanel *p;
  2054. b->SplitRatio = Percentage;
  2055. b->Vertical = 0;
  2056. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2057. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2058. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2059. p->Block = b->B1;
  2060. }
  2061. b->B1->Panels.pFirst = b->Panels.pFirst;
  2062. b->B1->Panels.pLast = b->Panels.pLast;
  2063. b->B1->CurrentPanel = b->CurrentPanel;
  2064. b->B1->parent = b->B2->parent=b;
  2065. b->Panels.pFirst = 0;
  2066. b->Panels.pLast = 0;
  2067. b->CurrentPanel = 0;
  2068. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2069. }
  2070. void laSplitBlockVertical(laBlock *b, real Percentage){
  2071. laPanel *p;
  2072. b->SplitRatio = Percentage;
  2073. b->Vertical = 1;
  2074. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2075. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2076. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2077. p->Block = b->B1;
  2078. }
  2079. b->B1->Panels.pFirst = b->Panels.pFirst;
  2080. b->B1->Panels.pLast = b->Panels.pLast;
  2081. b->B1->CurrentPanel = b->CurrentPanel;
  2082. b->B1->parent = b->B2->parent=b;
  2083. b->Panels.pFirst = 0;
  2084. b->Panels.pLast = 0;
  2085. b->CurrentPanel = 0;
  2086. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2087. }
  2088. void laCombineChildBlocks(laBlock *b){
  2089. laPanel *p; if(!b) return;
  2090. if (!b->B1->B1 && !b->B2->B1){
  2091. lstCombineLists(&b->Panels, &b->B1->Panels);
  2092. lstCombineLists(&b->Panels, &b->B2->Panels);
  2093. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2094. p->Block = b;
  2095. }
  2096. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2097. memFree(b->B1);
  2098. memFree(b->B2);
  2099. b->B1 = 0;
  2100. b->B2 = 0;
  2101. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2102. }elif(!b->B1->B1){
  2103. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2104. b->Vertical = b->B2->Vertical;
  2105. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2106. p->Block = b1;
  2107. }
  2108. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2109. memFree(b->B1); memFree(b->B2);
  2110. b->B1 = b1; b->B2 = b2;
  2111. b1->parent = b; b2->parent = b;
  2112. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2113. }elif(!b->B2->B1){
  2114. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2115. b->Vertical = b->B1->Vertical;
  2116. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2117. p->Block = b1;
  2118. }
  2119. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2120. memFree(b->B1); memFree(b->B2);
  2121. b->B1 = b1; b->B2 = b2;
  2122. b1->parent = b; b2->parent = b;
  2123. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2124. }
  2125. }
  2126. laBlock *laBlock1(laBlock *b){
  2127. return b->B1;
  2128. }
  2129. laBlock *laBlock2(laBlock *b){
  2130. return b->B2;
  2131. }
  2132. laBlock *laSwapSubBlocks(laBlock *b){
  2133. laBlock *tB;
  2134. tB = b->B2;
  2135. b->B2 = b->B1;
  2136. b->B1 = tB;
  2137. b->SplitRatio = 1 - b->SplitRatio;
  2138. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2139. }
  2140. void laDestroyBlocksRecursive(laBlock *Root){
  2141. laPanel *p;
  2142. if (Root->B1){
  2143. laDestroyBlocksRecursive(Root->B1);
  2144. laDestroyBlocksRecursive(Root->B2);
  2145. }else{
  2146. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2147. }
  2148. memFree(Root);
  2149. }
  2150. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2151. if(!b->CurrentPanel ) return 0;
  2152. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2153. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2154. lstRemoveItem(&b->Panels, p);
  2155. if(!b->CurrentPanel && b->parent){
  2156. b=b->parent;
  2157. laCombineChildBlocks(b);
  2158. }
  2159. if(!p->TitleBar.UiItems.pFirst){
  2160. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2161. }
  2162. p->Mode = LA_PANEL_FLOATING_TOP;
  2163. p->TY-=LA_RH;
  2164. p->TH+=LA_RH;
  2165. laRecalcPanel(p);
  2166. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2167. p->BT = &_LA_THEME_FLOATING_PANEL;
  2168. p->Block = 0;
  2169. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2170. laNotifyUsers("la.windows.panels");
  2171. return b->CurrentPanel;
  2172. }
  2173. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2174. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2175. lstRemoveItem(&from->Panels, p);
  2176. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2177. p->Mode = LA_PANEL_NORMAL;
  2178. p->Block=b;
  2179. b->CurrentPanel = p;
  2180. lstPushItem(&b->Panels, p);
  2181. laRecalcPanel(p);
  2182. p->BT = &_LA_THEME_PANEL;
  2183. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2184. tnsFlush();
  2185. laNotifyUsers("la.windows.panels");
  2186. }
  2187. void laPopPanel(laPanel *p){
  2188. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2189. lstRemoveItem(&p->Parent->SubPanels, p);
  2190. lstPushItem(&p->Parent->SubPanels, p);
  2191. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2192. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2193. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2194. laNotifyUsers("la.windows.panels");
  2195. }
  2196. }
  2197. void la_EnsurePanelExtras(laPanel *p){
  2198. laUiTemplate* uit=p->PanelTemplate;
  2199. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  2200. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  2201. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  2202. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  2203. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  2204. p->PropLinkFakeProp->Base.Offset = 0;
  2205. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  2206. p->PropLinkPP.EndInstance = p;
  2207. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  2208. p->PropLinkPP.LastPs->Type = U'.';
  2209. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  2210. }
  2211. laPanel* la_GivePanelNode(){
  2212. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  2213. return memAcquire(sizeof(laPanel));
  2214. }
  2215. void la_ReturnPanelNode(laPanel* p){
  2216. memset(p,0,sizeof(laPanel));
  2217. lstAppendItem(&MAIN.WastedPanels, p);
  2218. }
  2219. 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){
  2220. laPanel *p = la_GivePanelNode();
  2221. int CW = MAIN.CurrentWindow->CW;
  2222. int CH = MAIN.CurrentWindow->CH;
  2223. p->PanelTemplate = uit;
  2224. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  2225. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  2226. if (!MaxW) MaxW = 10000;
  2227. if (!MaxH) MaxH = 10000;
  2228. if (W > MaxW) W = MaxW;
  2229. if (H > MaxH) H = MaxH;
  2230. if (W < MinW) W = MinW;
  2231. if (H < MinH) H = MinH;
  2232. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  2233. p->X = p->TX = (X < 0 ? 0 : X);
  2234. p->Y = p->TY = (Y < 0 ? 0 : Y);
  2235. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  2236. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  2237. p->MaxW = MaxW;
  2238. p->MaxH = MaxH;
  2239. p->MinW = MinW;
  2240. p->MinH = MinH;
  2241. p->SL = SnapL;
  2242. p->ST = SnapT;
  2243. p->SR = SnapR;
  2244. p->SB = SnapB;
  2245. if (p->SR) p->X = CW - p->W - p->SR;
  2246. if (p->SB) p->Y = CH - p->H - p->SB;
  2247. la_EnsurePanelSnapping(p, CW, CH);
  2248. p->Show = 1;
  2249. p->PP.EndInstance = p;
  2250. p->PP.LastPs = &p->FakePS;
  2251. p->PP.LastPs->p = _LA_PROP_PANEL;
  2252. p->PP.LastPs->UseInstance = p;
  2253. p->PP.LastPs->Type = U'.';
  2254. la_EnsurePanelExtras(p);
  2255. laRecalcPanel(p);
  2256. p->FrameDistinguish = 100; //greater than 1 is ok
  2257. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  2258. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  2259. return p;
  2260. }
  2261. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  2262. if(!uit) return 0;
  2263. laPanel *p = memAcquireHyper(sizeof(laPanel));
  2264. strSafeSet(&p->Title, uit->Title->Ptr);
  2265. p->PanelTemplate = uit;
  2266. p->Show = 1;
  2267. p->PP.EndInstance = p;
  2268. p->PP.LastPs = &p->FakePS;
  2269. p->PP.LastPs->p = _LA_PROP_PANEL;
  2270. p->PP.LastPs->UseInstance = p;
  2271. p->PP.LastPs->Type = U'.';
  2272. la_EnsurePanelExtras(p);
  2273. laRecalcPanel(p);
  2274. p->FrameDistinguish = 100; //greater than 1 is ok
  2275. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  2276. while (b->B1){
  2277. b = b->B1;
  2278. }
  2279. lstPushItem(&b->Panels, p);
  2280. p->Block = b;
  2281. b->CurrentPanel = p;
  2282. if(uit->PropFunc){ uit->PropFunc(p); }
  2283. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  2284. laNotifyUsers("la.windows.panels");
  2285. return p;
  2286. }
  2287. laPanel *laCreatePanel(laBlock *b, char *template_id){
  2288. laUiTemplate* uit=laFindUiTemplate(template_id);
  2289. return laCreatePanelT(b, uit);
  2290. }
  2291. 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){
  2292. laUiTemplate* uit=0;
  2293. if(template_id) uit=laFindUiTemplate(template_id);
  2294. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  2295. p->Mode = LA_PANEL_FLOATING_TOP;
  2296. if(uit){
  2297. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  2298. }
  2299. if (w) lstPushItem(&w->Panels, p);
  2300. return p;
  2301. }
  2302. void laShowPanel(laPanel *p){
  2303. p->Show = 1;
  2304. laNotifyUsers("la.windows.panels_hidden");
  2305. }
  2306. void laShowPanelWithDropDownEffect(laPanel *p){
  2307. laShowPanel(p);
  2308. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  2309. p->AnimationRatio = 0;
  2310. }
  2311. void laShowPanelWithExpandEffect(laPanel *p){
  2312. laShowPanel(p);
  2313. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  2314. p->AnimationRatio = 0;
  2315. }
  2316. void laHidePanel(laPanel *p){
  2317. if (!p->Mode) return;
  2318. p->Show = 0;
  2319. laNotifyUsers("la.windows.panels_hidden");
  2320. }
  2321. void laHidePanelWithDissoveEffect(laPanel *p){
  2322. if (!p->Mode) return;
  2323. laHidePanel(p);
  2324. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  2325. p->AnimationRatio = 1;
  2326. }
  2327. void laHidePanelWithCollapseEffect(laPanel *p){
  2328. if (!p->Mode) return;
  2329. laHidePanel(p);
  2330. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  2331. p->AnimationRatio = 1;
  2332. }
  2333. void laHidePanelWithMinimizeEffect(laPanel *p){
  2334. if (!p->Mode) return;
  2335. laHidePanel(p);
  2336. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  2337. p->AnimationRatio = 1;
  2338. }
  2339. void laActivatePanel(char* TemplateID, int x, int y){
  2340. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  2341. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  2342. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  2343. laShowPanelWithExpandEffect(p); laPopPanel(p);
  2344. }
  2345. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  2346. p->UI.PanX += DeltaX;
  2347. p->UI.PanY += DeltaY;
  2348. }
  2349. int laPanUiListFree(laUiList *uil, int X, int Y){
  2350. uil->PanX+=X; uil->PanY+=Y;
  2351. }
  2352. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  2353. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  2354. if(Y){X+=Y;Y=0;}
  2355. }
  2356. if (Y > 0){
  2357. if (uil->B - uil->PanY <= B) return 0;
  2358. else{
  2359. uil->PanY += Y;
  2360. if (uil->B - uil->PanY <= B){
  2361. uil->PanY = uil->B - B;
  2362. return 1;
  2363. }
  2364. }
  2365. }
  2366. if (Y < 0){
  2367. if (uil->U - uil->PanY >= U) return 0;
  2368. else{
  2369. uil->PanY += Y;
  2370. if (uil->U - uil->PanY >= U){
  2371. uil->PanY = uil->U - U;
  2372. return 1;
  2373. }
  2374. }
  2375. }
  2376. if(uil->AllowScale){
  2377. laPanUiListFree(uil, X, 0);
  2378. }else{
  2379. if (X > 0){
  2380. if (uil->R - uil->PanX <= R) return 0;
  2381. else{
  2382. uil->PanX += X;
  2383. if (uil->R - uil->PanX <= R){
  2384. uil->PanX = uil->R - R;
  2385. return 1;
  2386. }
  2387. }
  2388. }
  2389. if (X < 0){
  2390. if (uil->L - uil->PanX >= L) return 0;
  2391. else{
  2392. uil->PanX += X;
  2393. if (uil->L - uil->PanX >= L){
  2394. uil->PanX = uil->L - L;
  2395. return 1;
  2396. }
  2397. }
  2398. }
  2399. }
  2400. return 1;
  2401. }
  2402. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  2403. int ret=1;
  2404. if(!uil->AllowScale){ return 0; }
  2405. real NewScale=uil->Scale*factor;
  2406. if(NewScale<0.2){NewScale=0.2; ret=0;}
  2407. if(NewScale>5) {NewScale=5; ret=0;}
  2408. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  2409. factor=NewScale/uil->Scale;
  2410. uil->Scale=NewScale;
  2411. real mx=(L+R)/2,my=(U+B)/2;
  2412. real dx= (mx+uil->PanX)*factor;
  2413. real dy= (my+uil->PanY)*factor;
  2414. uil->PanX=dx-mx;
  2415. uil->PanY=dy-my;
  2416. MAIN.CurrentPanel->FrameDistinguish=100;
  2417. return ret;
  2418. }
  2419. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  2420. if(uil->AllowScale) return 0;
  2421. return laPanUiList(uil,X,Y,L,R,U,B);
  2422. }
  2423. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  2424. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2425. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  2426. strSafeSet(&p->Title, Title);
  2427. if (Define){
  2428. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2429. }
  2430. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2431. p->BT= &_LA_THEME_FLOATING_PANEL;
  2432. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  2433. p->BoundUi = 1;
  2434. return p;
  2435. }
  2436. 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,
  2437. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2438. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  2439. strSafeSet(&p->Title, Title);
  2440. if (Define){
  2441. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2442. }
  2443. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2444. p->BT= &_LA_THEME_FLOATING_PANEL;
  2445. p->Mode = LA_PANEL_FLOATING_TOP;
  2446. p->BoundUi = 1;
  2447. return p;
  2448. }
  2449. void laDeferredDestroyPanel(laPanel *p, int immediate){
  2450. laPanel *ip;
  2451. tnsDelete2DOffscreen(p->OffScr);
  2452. p->OffScr = 0;
  2453. strSafeDestroy(&p->Title);
  2454. if (!p->AnimationMode){
  2455. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  2456. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2457. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2458. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  2459. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2460. }else if (p->Block){
  2461. lstRemoveItem(&p->Block->Panels, p);
  2462. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  2463. }
  2464. laNotifyUsers("la.windows.panels");
  2465. }
  2466. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  2467. //lstRemoveItem(&p->SubPanels, ip);
  2468. laDestroySinglePanel(ip, immediate);
  2469. laNotifyUsers("la.windows.panels");
  2470. }
  2471. la_ClearDetachedProp(p);
  2472. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  2473. la_ReturnPanelNode(p);
  2474. }
  2475. void laDestroySinglePanel(laPanel *p, int immediate){
  2476. la_SetPropMathcerContext(p);
  2477. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  2478. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  2479. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  2480. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  2481. }
  2482. }
  2483. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  2484. la_DestroyUiList(&p->UI, 1, 1, 0);
  2485. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2486. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  2487. if (p->Mode){
  2488. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  2489. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  2490. }
  2491. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  2492. if (la_UiStillInService(p)){
  2493. la_StopUiOperatorService(p);
  2494. }
  2495. if ((!p->AnimationMode) || immediate){
  2496. laDeferredDestroyPanel(p, immediate);
  2497. }else{
  2498. p->LaterDestroy = 1;
  2499. }
  2500. }
  2501. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  2502. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2503. int MinW,MinWt=0;
  2504. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  2505. int CW = MAIN.CurrentWindow->CW;
  2506. if(p->SL && p->SR){return 0;}
  2507. la_SetPropMathcerContext(p);
  2508. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  2509. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  2510. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  2511. MinW = la_TestUiListMinumWidth(uil);
  2512. if (MinW<MinWt){MinW=MinWt;}
  2513. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  2514. if (MinW > 20){
  2515. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  2516. }
  2517. la_PanelValidateWidth(p,uil);
  2518. laEnsurePanelInBound(p,uil);
  2519. if(p->TW>CW){ p->TW=CW; }
  2520. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  2521. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  2522. laRedrawPanel(p);
  2523. return 1;
  2524. }
  2525. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  2526. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2527. laOperator *ai = a;
  2528. laPanel *p;
  2529. int GX, GY, GW, t = 0;
  2530. int b;
  2531. laUiDefineFunc def = ReplaceUiDefine;
  2532. int MinW;
  2533. if (!def){ def=laui_DefaultPropDetails; }
  2534. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  2535. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  2536. laEnclosePanelContent(p, &p->UI);
  2537. laSetOperatorLocalizer(p);
  2538. p->CloseWhenMovedOut=1;
  2539. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2540. //laShowPanelWithDropDownEffect(p);
  2541. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  2542. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  2543. return p;
  2544. }
  2545. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  2546. laPanel *p;
  2547. int GX, GY, GW, t = 0;
  2548. int b;
  2549. laUiDefineFunc def = ReplaceUiDefine;
  2550. int MinW;
  2551. if (!def) return 0;
  2552. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  2553. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  2554. p->Mode = LA_PANEL_FLOATING_TOP;
  2555. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  2556. laEnclosePanelContent(p, &p->UI);
  2557. if(MAIN.CurrentWindow->Operators.pFirst){
  2558. laSetOperatorLocalizer(MAIN.PendingSplash);
  2559. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  2560. MAIN.PendingSplash=0;
  2561. }
  2562. //laShowPanelWithExpandEffect(p);
  2563. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2564. return p;
  2565. }
  2566. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  2567. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2568. laOperator *ai = a;
  2569. laPanel *p; laPropContainer* sub;
  2570. int GX, GY, GW, t = 0;
  2571. int b;
  2572. laUiDefineFunc def = ReplaceUiDefine;
  2573. int MinW;
  2574. if (!def){
  2575. if (This && This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  2576. if ((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  2577. else def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  2578. }
  2579. GX = L; GY = B;
  2580. GW = (R - L) > MaxW ? MaxW : (R - L);
  2581. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  2582. laEnclosePanelContent(p, &p->UI);
  2583. laSetOperatorLocalizer(p);
  2584. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2585. laShowPanelWithDropDownEffect(p);
  2586. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  2587. if(Attachment){
  2588. p->Parent = Attachment;
  2589. lstAppendItem(&Attachment->SubPanels, p);
  2590. }
  2591. return p;
  2592. }
  2593. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  2594. laPanel *p;
  2595. int t = 0;
  2596. int b;
  2597. //laLocalToWindow(0, Attachment, &L, &t);
  2598. //laLocalToWindow(0, Attachment, &R, &U);
  2599. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  2600. laSetOperatorLocalizer(p);
  2601. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2602. laShowPanelWithDropDownEffect(p);
  2603. p->Parent = Attachment;
  2604. lstPushItem(&Attachment->SubPanels, p);
  2605. return p;
  2606. }
  2607. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  2608. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2609. laOperator *ai = a;
  2610. laPanel *p;
  2611. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2612. int GX, GY, GW, t = 0;
  2613. int b;
  2614. int MinW;
  2615. //laLocalToWindow(0,Attachment, &L, &t);
  2616. //laLocalToWindow(0,Attachment, &R, &B);
  2617. GX = L;
  2618. GY = B;
  2619. GW = (R - L) > MaxW ? MaxW : (R - L);
  2620. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2621. p->MenuRefer = MenuRefer;
  2622. laEnclosePanelContent(p, MenuRefer);
  2623. laSetOperatorLocalizer(p);
  2624. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2625. laShowPanelWithDropDownEffect(p);
  2626. p->Parent = Attachment;
  2627. lstPushItem(&Attachment->SubPanels, p);
  2628. return p;
  2629. }
  2630. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  2631. int L, int B, int MaxGH, int MaxW, laEvent *e){
  2632. laOperator *ai = a;
  2633. laPanel *p;
  2634. int GX, GY, GW, t = 0;
  2635. int b;
  2636. GX = L;
  2637. GY = B;
  2638. GW = MaxW;
  2639. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2640. p->MenuRefer = &p->UI;
  2641. p->Mode = LA_PANEL_NO_PARENT_MENU;
  2642. laSetOperatorLocalizer(p);
  2643. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2644. laShowPanelWithDropDownEffect(p);
  2645. if (Attachment){
  2646. p->Parent = Attachment;
  2647. lstPushItem(&Attachment->SubPanels, p);
  2648. }else{
  2649. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2650. }
  2651. return p;
  2652. }
  2653. 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){
  2654. laOperator *ai = For;
  2655. laPanel *p;
  2656. int b;
  2657. laUiDefineFunc def = 0;
  2658. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  2659. else def = laui_DefaultPropUiDefine;
  2660. For->PP.EndInstance = For->CustomData;
  2661. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  2662. laEnclosePanelContent(p, &p->UI);
  2663. MAIN.ToPanel = p;
  2664. laShowPanelWithExpandEffect(p);
  2665. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2666. ai->OperatorPanel = p;
  2667. p->ParentOperator = For;
  2668. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  2669. return p;
  2670. }
  2671. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2672. laPanel *p;
  2673. int b;
  2674. laUiList *uil;
  2675. laColumn *col, *cor, *corl, *corr;
  2676. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  2677. strSafeSet(&p->Title, Title);
  2678. p->BoundUi = 1;
  2679. p->Mode = LA_PANEL_FLOATING_TOP;
  2680. p->BT = &_LA_THEME_FLOATING_PANEL;
  2681. MAIN.ToPanel = p;
  2682. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2683. uil = laPrepareUi(p);
  2684. col = laFirstColumn(uil);
  2685. laSplitColumn(uil, col, 0.5);
  2686. cor = laRightColumn(col, 600);
  2687. laShowLabel(uil, col, Message, 0, 0);
  2688. laShowItem(uil, cor, 0, "LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  2689. laEnclosePanelContent(p,uil);
  2690. laShowPanelWithExpandEffect(p);
  2691. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2692. laSetOperatorLocalizer(p);
  2693. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2694. return p;
  2695. }
  2696. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2697. laPanel *p;
  2698. int b;
  2699. laUiList *uil;
  2700. laColumn *col, *cor, *corl, *corr;
  2701. p = la_NewPanel(0, X, Y, W, 0, 1000, 90, 100, 0, 0, 0, 0, 0);
  2702. strSafeSet(&p->Title, Title);
  2703. p->BoundUi = 1;
  2704. p->Mode = LA_PANEL_FLOATING_TOP;
  2705. p->BT = &_LA_THEME_FLOATING_PANEL;
  2706. MAIN.ToPanel = p;
  2707. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2708. uil = laPrepareUi(p);
  2709. col = laFirstColumn(uil);
  2710. laSplitColumn(uil, col, 0.35);
  2711. cor = laRightColumn(col, 200);
  2712. laShowLabel(uil, col, Message, 0, 0);
  2713. laShowItemFull(uil, cor, 0, "LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  2714. laEnclosePanelContent(p,uil);
  2715. laShowPanelWithExpandEffect(p);
  2716. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2717. laSetOperatorLocalizer(p);
  2718. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2719. return p;
  2720. }
  2721. laPanel *laEnableMultiMessagePanel(laOperator *a, laPanel *Attachment, char *Title, laPanelMessageList *pml, int X, int Y, int W, laEvent *e){
  2722. laPanel *p;
  2723. int b;
  2724. laUiList *uil;
  2725. laColumn *col, *cor, *corl, *corr;
  2726. laPanelMessage *pm;
  2727. p = la_NewPanel(0, X, Y, W, 0, 1000, 1000, 100, 0, 0, 0, 0, 0);
  2728. strSafeSet(&p->Title, Title);
  2729. p->BoundUi = 1;
  2730. p->Mode = LA_PANEL_FLOATING_TOP;
  2731. p->BT = &_LA_THEME_FLOATING_PANEL;
  2732. MAIN.ToPanel = p;
  2733. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2734. uil = laPrepareUi(p);
  2735. col = laFirstColumn(uil);
  2736. laSplitColumn(uil, col, 0.35);
  2737. cor = laRightColumn(col, 200);
  2738. while (pm = lstPopItem(pml)){
  2739. laShowLabel(uil, col, pm->Message->Ptr, 0, 0);
  2740. strSafeDestroy(&pm->Message);
  2741. FreeMem(pm);
  2742. }
  2743. laShowItemFull(uil, cor, 0, "LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  2744. laShowPanelWithExpandEffect(p);
  2745. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2746. laSetOperatorLocalizer(p);
  2747. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2748. return p;
  2749. }
  2750. void laAddPanelMessage(laPanelMessageList *pml, char *Message){
  2751. if (!Message || !Message[0]) return;
  2752. laPanelMessage *pm = CreateNew(laPanelMessage);
  2753. strSafeSet(&pm->Message, Message);
  2754. lstAppendItem(&pml->Msg, pm);
  2755. }
  2756. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2757. laWindow* cur=MAIN.CurrentWindow;
  2758. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  2759. MAIN.CurrentWindow=w;
  2760. la_UpdateUiPlacement(w);
  2761. }
  2762. MAIN.CurrentWindow=cur;
  2763. }
  2764. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2765. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  2766. }
  2767. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  2768. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  2769. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  2770. void laRedrawCurrentPanel(){
  2771. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  2772. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2773. }
  2774. void laRecalcCurrentPanel(){
  2775. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  2776. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2777. }
  2778. void laRecalcPanelImmediate(laPanel* p){
  2779. p->FrameDistinguish++;
  2780. laBoxedTheme* bt = (*p->BT);
  2781. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  2782. la_PanelRefreshDetachedProp(p);
  2783. int enclosed=0;
  2784. if(p->BoundUi || p->MenuRefer){
  2785. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  2786. else enclosed=laEnclosePanelContent(p, &p->UI);
  2787. }
  2788. if(!enclosed){
  2789. la_PanelValidateWidth(p,&p->UI);
  2790. //laEnsurePanelInBound(p,&p->UI);
  2791. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->TM-bt->BM, 0, p);
  2792. la_UpdateUiListRecursive(&p->UI, bt->TM+p->TitleBar.TB, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->TM-bt->BM, 0, p);
  2793. }
  2794. laWindow* w=MAIN.CurrentWindow;
  2795. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  2796. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  2797. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  2798. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  2799. }
  2800. }
  2801. void laRecalcCurrentPanelImmediate(){
  2802. laRecalcPanelImmediate(MAIN.CurrentPanel);
  2803. }
  2804. int laNonFixedPanelExists(laPanel *p){
  2805. laPanel *ip;
  2806. if (!p) return 0;
  2807. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2808. // if (ip == p) return 1;
  2809. //}
  2810. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2811. if (ip == p) return 1;
  2812. }
  2813. return 0;
  2814. }
  2815. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  2816. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  2817. return 1;
  2818. }
  2819. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  2820. int tt=MAIN.TooltipCloseDistance;
  2821. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  2822. return 1;
  2823. }
  2824. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  2825. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  2826. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  2827. return 0;
  2828. return 1;
  2829. }
  2830. void laUnlinkSharedPanel(laPanel *p){
  2831. laWindow *w;
  2832. laPanel *ip;
  2833. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  2834. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  2835. if (ip == p){
  2836. lstRemoveItem(&w->Panels, ip);
  2837. return;
  2838. }
  2839. }
  2840. }
  2841. }
  2842. int laIsPanelCovered(laPanel *p){
  2843. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  2844. laPanel *ip;
  2845. laPanel *resp;
  2846. int in1 = 0, in2 = 0, in3 = 0;
  2847. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  2848. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2849. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  2850. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  2851. //}
  2852. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2853. if (ip == p){
  2854. in3 = 1;
  2855. d3 = 0;
  2856. continue;
  2857. }
  2858. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  2859. }
  2860. if (!in2 && !in3) in1 = 1;
  2861. if (in1){
  2862. if (d1 || d2 || d3) return 1;
  2863. }else{
  2864. if (in2){
  2865. if (d2 || d3) return 1;
  2866. }else if (in3)
  2867. if (d3) return 1;
  2868. }
  2869. return 0;
  2870. }
  2871. int laIsTopPanel(laPanel *p){
  2872. //if (!p->Item.pPrev) return 1;
  2873. //else {
  2874. if (!laIsPanelCovered(p)){
  2875. //laPopPanel(p);
  2876. return 1;
  2877. }
  2878. return 0;
  2879. //}
  2880. return 0;
  2881. }
  2882. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  2883. if(!p) return;
  2884. int ix = *x, iy = *y;
  2885. laListItemPointer *lip;
  2886. laOperator *ai = a;
  2887. (*x) = ix - p->X;
  2888. (*y) = iy - p->Y;
  2889. if (a){
  2890. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2891. laUiList *uil = lip->p;
  2892. (*x) += uil->PanX;
  2893. (*y) += uil->PanY;
  2894. }
  2895. }
  2896. }
  2897. void laPanelToLocal(laOperator *a, int *x, int *y){
  2898. int ix = *x, iy = *y;
  2899. laListItemPointer *lip;
  2900. if (a){
  2901. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2902. laUiList *uil = lip->p;
  2903. (*x) += uil->PanX;
  2904. (*y) += uil->PanY;
  2905. }
  2906. }
  2907. }
  2908. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  2909. if(!p) return;
  2910. int ix = *x, iy = *y;
  2911. laListItemPointer *lip;
  2912. (*x) = ix + p->X;
  2913. (*y) = iy + p->Y;
  2914. if (a){
  2915. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2916. laUiList *uil = lip->p;
  2917. (*x) -= uil->PanX;
  2918. (*y) -= uil->PanY;
  2919. }
  2920. }
  2921. }
  2922. void laPanelToWindow(laPanel *p, int *x, int *y){
  2923. int ix = *x, iy = *y;
  2924. laListItemPointer *lip;
  2925. (*x) = ix + p->X;
  2926. (*y) = iy + p->Y;
  2927. }
  2928. void laLocalToPanel(laOperator *a, int *x, int *y){
  2929. int ix = *x, iy = *y;
  2930. laListItemPointer *lip;
  2931. if (a){
  2932. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2933. laUiList *uil = lip->p;
  2934. (*x) -= uil->PanX;
  2935. (*y) -= uil->PanY;
  2936. }
  2937. }
  2938. }
  2939. void laSetNextMenuPos(int X, int Y, int W, int H){
  2940. MAIN.NextX = X;
  2941. MAIN.NextY = Y;
  2942. MAIN.NextW = W;
  2943. MAIN.NextH = H;
  2944. }
  2945. int laIsInBlock(laBlock *b, int X, int Y){
  2946. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  2947. return 0;
  2948. }
  2949. 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; }
  2950. 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; }
  2951. 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; }
  2952. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  2953. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  2954. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  2955. if (!b->B1 && !b->B2){
  2956. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  2957. }
  2958. }
  2959. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  2960. laPanel *p;
  2961. laBlock *sb = 0;
  2962. if (!laIsInBlock(b, X, Y)) return 0;
  2963. if (!b->B1 && !b->B2) return b;
  2964. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  2965. return laDetectBlockRecursive(b->B2, X, Y);
  2966. }
  2967. laPanel *laDetectPanel(int X, int Y){
  2968. laPanel *p; laBlock *b;
  2969. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  2970. int x = X, y = Y;
  2971. laWindowToLocal(0, p, &x, &y);
  2972. if (p->Show && laIsInPanel(p, x, y)){
  2973. return p;
  2974. }
  2975. }
  2976. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  2977. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  2978. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  2979. return 0;
  2980. }
  2981. laUiList *laPrepareUi(laPanel *p){
  2982. return &p->UI;
  2983. }
  2984. laColumn *laFirstColumn(laUiList *uil){
  2985. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  2986. else{
  2987. laColumn *c = memAcquireSimple(sizeof(laColumn));
  2988. c->SP = 1;
  2989. c->PreWidth = 1;
  2990. lstAppendItem(&uil->Columns, c);
  2991. c->Top = c;
  2992. return uil->Columns.pFirst;
  2993. }
  2994. }
  2995. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  2996. laColumn *lc, *rc;
  2997. if (c->LS || c->RS) return c;
  2998. lc = memAcquireSimple(sizeof(laColumn));
  2999. rc = memAcquireSimple(sizeof(laColumn));
  3000. c->LS = lc;
  3001. c->RS = rc;
  3002. c->LS->SP = Percent;
  3003. c->RS->SP = Percent;
  3004. c->LS->Top = c->Top;
  3005. c->RS->Top = c->Top;
  3006. if (uil){
  3007. lstAppendItem(&uil->Columns, lc);
  3008. lstAppendItem(&uil->Columns, rc);
  3009. }
  3010. if (c->LS && c->RS->MaxW == 0){
  3011. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3012. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3013. }else if (c->RS && c->LS->MaxW == 0){
  3014. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3015. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3016. }
  3017. return c;
  3018. }
  3019. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3020. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3021. return c->LS;
  3022. }
  3023. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3024. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3025. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3026. return c->RS;
  3027. }
  3028. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3029. lstRemoveItem(List, c);
  3030. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3031. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3032. memFree(c);
  3033. }
  3034. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3035. laUiList *uil = TopUil;
  3036. laUiList *sub;
  3037. laUiItem *ui;
  3038. laColumn *cc, *NextCC = 0;
  3039. int Occupied = 0;
  3040. int Removed = 0;
  3041. if (!c->LS) return 0;
  3042. else{
  3043. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3044. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3045. }
  3046. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3047. if (ui->C == c->LS || ui->C == c->RS){
  3048. if (DoMerge){
  3049. ui->C = c;
  3050. Occupied = 1;
  3051. }else
  3052. return 1;
  3053. }
  3054. if (ui->Subs.pFirst){
  3055. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3056. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3057. }
  3058. }
  3059. }
  3060. if (!Removed){
  3061. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3062. if (cc == c){
  3063. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3064. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3065. c->LS = 0;
  3066. c->RS = 0;
  3067. Removed = 1;
  3068. break;
  3069. }
  3070. }
  3071. }
  3072. return Occupied;
  3073. }
  3074. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3075. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3076. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3077. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3078. ut->FakeProp->Base.Identifier = ut->Identifier;
  3079. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3080. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3081. ut->FakeProp->Base.OffsetIsPointer = 1;
  3082. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3083. return ut->ExtraProps;
  3084. }
  3085. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3086. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3087. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3088. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3089. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3090. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3091. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3092. ct->FakeProp->Base.OffsetIsPointer = 1;
  3093. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3094. return ct->ExtraProps;
  3095. }
  3096. void la_DestroyUiType(laUiType* uit){
  3097. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3098. memFree(uit);
  3099. }
  3100. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3101. laUiType *ut = memAcquire(sizeof(laUiType));
  3102. ut->Identifier = Identifer;
  3103. ut->OperatorID = UseOperator;
  3104. ut->Draw = Draw;
  3105. ut->Theme = bt;
  3106. ut->ForType = ForType;
  3107. ut->OperatorType = laGetOperatorType(UseOperator);
  3108. ut->GetHeight = GetHeight;
  3109. ut->Init = Init;
  3110. ut->Destroy = Destroy;
  3111. la_UDFAppendSharedTypePointer(Identifer, ut);
  3112. lstAppendItem(&MAIN.UiTypes, ut);
  3113. return ut;
  3114. }
  3115. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3116. laUiType *ut = MAIN.UiTypes.pFirst;
  3117. if (!P) return 0;
  3118. if (P->DefaultUiType) return P->DefaultUiType;
  3119. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3120. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3121. for (ut; ut; ut = ut->Item.pNext){
  3122. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3123. return ut;
  3124. }
  3125. }
  3126. return 0;
  3127. }
  3128. laUiType *la_GetUiButtonType(){
  3129. laUiType *ut = MAIN.UiTypes.pFirst;
  3130. for (ut; ut; ut = ut->Item.pNext){
  3131. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3132. }
  3133. return 0;
  3134. }
  3135. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3136. laCanvasTemplate *vdt;
  3137. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3138. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3139. }
  3140. return 0;
  3141. }
  3142. void la_AssignPropExtras(laUiItem* ui){
  3143. if(!ui->Type || !ui->Type->FakeProp) return;
  3144. ui->FakePs.p = ui->Type->FakeProp;
  3145. ui->FakePs.Type = U'.';
  3146. ui->FakePs.UseInstance = ui;
  3147. ui->ExtraPP.LastPs = &ui->FakePs;
  3148. }
  3149. void la_AssignCanvasPropExtras(laUiItem* ui){
  3150. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3151. laCanvasTemplate*ct=ui->CanvasTemplate;
  3152. ui->FakePs.p = ct->FakeProp;
  3153. ui->FakePs.Type = U'.';
  3154. ui->FakePs.UseInstance = ui;
  3155. ui->ExtraPP.EndInstance = ui->Extra;
  3156. ui->ExtraPP.LastPs = &ui->FakePs;
  3157. }
  3158. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3159. int result;
  3160. if (!ui) return 0;
  3161. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3162. if (Path){
  3163. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3164. if (!result){
  3165. ui->AT = laGetOperatorType(Path);
  3166. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3167. ui->Type = la_GetUiButtonType();
  3168. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3169. }else{
  3170. ui->Type = (OverrideType && ((OverrideType->ForType == ui->PP.LastPs->p->PropertyType) || (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ? OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3171. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3172. }
  3173. if (Base){
  3174. ui->PP.RawThis = Base;
  3175. }
  3176. }else if (Base){
  3177. ui->PP.LastPs = Base->LastPs;
  3178. ui->Type = (OverrideType && ((OverrideType->ForType == ui->PP.LastPs->p->PropertyType) || (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ? OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3179. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3180. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3181. }
  3182. la_AssignPropExtras(ui);
  3183. if(Widget){ ui->Flags|= Widget->Flags; }
  3184. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3185. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3186. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3187. return ui;
  3188. }
  3189. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3190. ui->Type = _LA_UI_LABEL;
  3191. ui->Template = Template;
  3192. ui->State = LA_UI_NORMAL;
  3193. strSafeSet(&ui->Display, Content);
  3194. la_AssignPropExtras(ui);
  3195. return ui;
  3196. }
  3197. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3198. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3199. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3200. ui->State = LA_UI_NORMAL;
  3201. la_AssignPropExtras(ui);
  3202. return ui;
  3203. }
  3204. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3205. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3206. transLate(Content);
  3207. la_UpdateLabelDisplay(ui, Template, Content);
  3208. ui->C = c;
  3209. if (ui->Type->Init) ui->Type->Init(ui);
  3210. ui->ExtraPP.EndInstance = ui->Extra;
  3211. lstAppendItem(&uil->UiItems, ui);
  3212. return ui;
  3213. }
  3214. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3215. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3216. la_UpdateLabelDisplay(ui, Template, Content);
  3217. ui->C = c;
  3218. if (ui->Type->Init) ui->Type->Init(ui);
  3219. ui->ExtraPP.EndInstance = ui->Extra;
  3220. lstAppendItem(&uil->UiItems, ui);
  3221. return ui;
  3222. }
  3223. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3224. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3225. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3226. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3227. ui->C = c;
  3228. if (ui->Type->Init) ui->Type->Init(ui);
  3229. ui->ExtraPP.EndInstance = ui->Extra;
  3230. lstAppendItem(&uil->UiItems, ui);
  3231. return ui;
  3232. }
  3233. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3234. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  3235. }
  3236. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  3237. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3238. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  3239. ui->C = c;
  3240. ui->TemplateContext = TemplateContext;
  3241. if (ui->Type->Init) ui->Type->Init(ui);
  3242. ui->ExtraPP.EndInstance = ui->Extra;
  3243. lstAppendItem(&uil->UiItems, ui);
  3244. return ui;
  3245. }
  3246. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  3247. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3248. ui->C = c; ui->Extra=Image;
  3249. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  3250. ui->SymbolID=Height;
  3251. lstAppendItem(&uil->UiItems, ui);
  3252. return ui;
  3253. }
  3254. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3255. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  3256. }
  3257. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3258. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  3259. }
  3260. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  3261. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3262. ui->Type = _LA_UI_CANVAS;
  3263. ui->State = LA_UI_NORMAL;
  3264. ui->C = c;
  3265. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3266. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  3267. else{
  3268. 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); }
  3269. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  3270. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  3271. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  3272. }
  3273. if (ui->Type->Init) ui->Type->Init(ui);
  3274. la_AssignCanvasPropExtras(ui);
  3275. if (Height) ui->Expand=Height; else ui->Expand=6;
  3276. lstAppendItem(&uil->UiItems, ui);
  3277. return ui;
  3278. }
  3279. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  3280. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3281. laCanvasExtra *e;
  3282. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  3283. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  3284. ui->C = c;
  3285. if (ui->Type->Init) ui->Type->Init(ui);
  3286. ui->ExtraPP.EndInstance = ui->Extra;
  3287. lstAppendItem(&uil->UiItems, ui);
  3288. return ui;
  3289. }
  3290. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  3291. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3292. ui->Type = _LA_UI_SYMBOL;
  3293. ui->SymbolID = SymbolID;
  3294. if (Height) ui->State = Height;
  3295. ui->C = c;
  3296. if (ui->Type->Init) ui->Type->Init(ui);
  3297. ui->ExtraPP.EndInstance = ui->Extra;
  3298. lstAppendItem(&uil->UiItems, ui);
  3299. return ui;
  3300. }
  3301. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  3302. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3303. ui->Type = &_LA_UI_ROW_BEGIN;
  3304. ui->State=Expand;
  3305. ui->Flags=Even;
  3306. ui->C = c;
  3307. if (ui->Type->Init) ui->Type->Init(ui);
  3308. ui->ExtraPP.EndInstance = ui->Extra;
  3309. lstAppendItem(&uil->UiItems, ui);
  3310. return ui;
  3311. }
  3312. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  3313. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3314. ui->Type = &_LA_UI_ROW_END;
  3315. ui->C = Begin->C;
  3316. ui->Page = (laUiList*)Begin;
  3317. if (ui->Type->Init) ui->Type->Init(ui);
  3318. ui->ExtraPP.EndInstance = ui->Extra;
  3319. lstAppendItem(&uil->UiItems, ui);
  3320. return ui;
  3321. }
  3322. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  3323. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  3324. e->Expression = Expression;
  3325. ui->Extra = e;
  3326. la_AssignPropExtras(ui);
  3327. }
  3328. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3329. laUiItem *ui = la_CreateGroupHandle(Widget);
  3330. laUiList *nuil;
  3331. ui->C = c;
  3332. lstAppendItem(&uil->UiItems, ui);
  3333. nuil = memAcquireSimple(sizeof(laUiList));
  3334. strSafeSet(&nuil->TabName, Name);
  3335. ui->Page = nuil;
  3336. lstAppendItem(&ui->Subs, nuil);
  3337. if (ui->Type->Init) ui->Type->Init(ui);
  3338. ui->ExtraPP.EndInstance = ui->Extra;
  3339. return ui;
  3340. }
  3341. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  3342. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  3343. laUiList *sub = SubUi->Page;
  3344. laColumn *s = laFirstColumn(sub);
  3345. SubUi->State = LA_UI_ACTIVE;
  3346. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  3347. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  3348. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  3349. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  3350. laShowSeparator(sub, s);
  3351. return SubUi;
  3352. }
  3353. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3354. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  3355. laUiList *sub = SubUi->Page;
  3356. laColumn *s = laFirstColumn(sub);
  3357. SubUi->State = LA_UI_ACTIVE;
  3358. return SubUi;
  3359. }
  3360. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  3361. laEndCondition(sub, sub->UiItems.pFirst);
  3362. }
  3363. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  3364. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  3365. laUiList *nuil;
  3366. ui->C = c;
  3367. lstAppendItem(&uil->UiItems, ui);
  3368. if (ui->Type->Init) ui->Type->Init(ui);
  3369. ui->ExtraPP.EndInstance = ui->Extra;
  3370. return ui;
  3371. }
  3372. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  3373. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3374. if (!ui->Page) ui->Page = uil;
  3375. lstAppendItem(&ui->Subs, uil);
  3376. strSafeSet(&uil->TabName, Name);
  3377. laFirstColumn(uil);
  3378. //laFirstColumn(uil);
  3379. return uil;
  3380. }
  3381. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  3382. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3383. /*if (!ui->Page) */ ui->Page = uil;
  3384. lstAppendItem(&ui->Subs, uil);
  3385. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  3386. return uil;
  3387. }
  3388. laUiConditionNode *laTrue(){
  3389. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3390. ucn->Type = LA_CONDITION_TRUE;
  3391. return ucn;
  3392. }
  3393. laUiConditionNode *laFalse(){
  3394. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3395. ucn->Type = LA_CONDITION_FALSE;
  3396. return ucn;
  3397. }
  3398. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  3399. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3400. ucn->Type = LA_CONDITION_PROP;
  3401. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  3402. strSafeSet(&ucn->String, Prop);
  3403. return ucn;
  3404. }
  3405. laUiConditionNode *laIntExpression(int Value){
  3406. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3407. ucn->Type = LA_CONDITION_INT;
  3408. ucn->IntValue = Value;
  3409. return ucn;
  3410. }
  3411. laUiConditionNode *laFloatExpression(real Value){
  3412. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3413. ucn->Type = LA_CONDITION_FLOAT;
  3414. ucn->FloatValue = Value;
  3415. return ucn;
  3416. }
  3417. laUiConditionNode *laStringExpression(char *Content){
  3418. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3419. ucn->Type = LA_CONDITION_STRING;
  3420. strSafeSet(&ucn->String, Content);
  3421. return ucn;
  3422. }
  3423. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3424. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3425. ucn->Type = LA_CONDITION_AND;
  3426. ucn->Expression1 = Expression1;
  3427. ucn->Expression2 = Expression2;
  3428. return ucn;
  3429. }
  3430. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3431. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3432. ucn->Type = LA_CONDITION_OR;
  3433. ucn->Expression1 = Expression1;
  3434. ucn->Expression2 = Expression2;
  3435. return ucn;
  3436. }
  3437. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  3438. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3439. ucn->Type = LA_CONDITION_NOT;
  3440. ucn->Expression1 = Expression1;
  3441. return ucn;
  3442. }
  3443. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3444. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3445. ucn->Type = LA_CONDITION_EQ;
  3446. ucn->Expression1 = Expression1;
  3447. ucn->Expression2 = Expression2;
  3448. return ucn;
  3449. }
  3450. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3451. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3452. ucn->Type = LA_CONDITION_GT;
  3453. ucn->Expression1 = Expression1;
  3454. ucn->Expression2 = Expression2;
  3455. return ucn;
  3456. }
  3457. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3458. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3459. ucn->Type = LA_CONDITION_LT;
  3460. ucn->Expression1 = Expression1;
  3461. ucn->Expression2 = Expression2;
  3462. return ucn;
  3463. }
  3464. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3465. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3466. ucn->Type = LA_CONDITION_GE;
  3467. ucn->Expression1 = Expression1;
  3468. ucn->Expression2 = Expression2;
  3469. return ucn;
  3470. }
  3471. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3472. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3473. ucn->Type = LA_CONDITION_LE;
  3474. ucn->Expression1 = Expression1;
  3475. ucn->Expression2 = Expression2;
  3476. return ucn;
  3477. }
  3478. int la_GetIntConditionValue(laUiConditionNode *Expression){
  3479. if (Expression->Type != LA_CONDITION_INT) return 0;
  3480. return Expression->IntValue;
  3481. }
  3482. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  3483. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  3484. return Expression->FloatValue;
  3485. }
  3486. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  3487. return Expression->String->Ptr;
  3488. }
  3489. 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){
  3490. switch (Mode1){
  3491. case LA_PROP_ENUM:
  3492. case LA_PROP_INT:
  3493. case LA_CONDITION_INT:
  3494. switch (Mode2){
  3495. case LA_PROP_ENUM:
  3496. case LA_PROP_INT:
  3497. case LA_CONDITION_INT:
  3498. switch (CompMode){
  3499. case LA_CONDITION_GE:
  3500. return (i1 >= i2);
  3501. case LA_CONDITION_GT:
  3502. return (i1 > i2);
  3503. case LA_CONDITION_EQ:
  3504. return (i1 == i2);
  3505. case LA_CONDITION_LT:
  3506. return (i1 < i2);
  3507. case LA_CONDITION_LE:
  3508. return (i1 <= i2);
  3509. }
  3510. case LA_PROP_FLOAT:
  3511. case LA_CONDITION_FLOAT:
  3512. switch (CompMode){
  3513. case LA_CONDITION_GE:
  3514. return ((real)i1 >= f2);
  3515. case LA_CONDITION_GT:
  3516. return ((real)i1 > f2);
  3517. case LA_CONDITION_EQ:
  3518. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  3519. case LA_CONDITION_LT:
  3520. return ((real)i1 < f2);
  3521. case LA_CONDITION_LE:
  3522. return ((real)i1 <= f2);
  3523. }
  3524. case LA_PROP_SUB:
  3525. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  3526. default:
  3527. return 0;
  3528. }
  3529. case LA_PROP_FLOAT:
  3530. case LA_CONDITION_FLOAT:
  3531. switch (Mode2){
  3532. case LA_PROP_INT:
  3533. case LA_PROP_ENUM:
  3534. case LA_CONDITION_INT:
  3535. switch (CompMode){
  3536. case LA_CONDITION_GE:
  3537. return (f1 >= (real)i2);
  3538. case LA_CONDITION_GT:
  3539. return (f1 > (real)i2);
  3540. case LA_CONDITION_EQ:
  3541. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  3542. case LA_CONDITION_LT:
  3543. return (f1 < (real)i2);
  3544. case LA_CONDITION_LE:
  3545. return (f1 <= (real)i2);
  3546. }
  3547. case LA_PROP_FLOAT:
  3548. case LA_CONDITION_FLOAT:
  3549. switch (CompMode){
  3550. case LA_CONDITION_GE:
  3551. return (f1 >= f2);
  3552. case LA_CONDITION_GT:
  3553. return (f1 > f2);
  3554. case LA_CONDITION_EQ:
  3555. return (f1 == f2);
  3556. case LA_CONDITION_LT:
  3557. return (f1 < f2);
  3558. case LA_CONDITION_LE:
  3559. return (f1 <= f2);
  3560. }
  3561. default:
  3562. return 0;
  3563. }
  3564. case LA_PROP_STRING:
  3565. case LA_CONDITION_STRING:
  3566. switch (Mode2){
  3567. case LA_PROP_STRING:
  3568. case LA_CONDITION_STRING:
  3569. return strSame(s1, s2);
  3570. default:
  3571. return 0;
  3572. }
  3573. case LA_PROP_SUB:
  3574. switch (Mode2){
  3575. case LA_PROP_SUB:
  3576. return p1 == p2;
  3577. case LA_CONDITION_INT:
  3578. case LA_PROP_INT:
  3579. case LA_PROP_ENUM:
  3580. return (int)p1 == i2;
  3581. default:
  3582. return 0;
  3583. }
  3584. default:
  3585. switch (CompMode){
  3586. case LA_CONDITION_GE:
  3587. return (i1 >= i2);
  3588. case LA_CONDITION_GT:
  3589. return (i1 > i2);
  3590. case LA_CONDITION_EQ:
  3591. return (i1 == i2);
  3592. case LA_CONDITION_LT:
  3593. return (i1 < i2);
  3594. case LA_CONDITION_LE:
  3595. return (i1 <= i2);
  3596. }
  3597. }
  3598. }
  3599. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  3600. void *Instance = 0;
  3601. int IValue1 = 0, IValue2 = 0;
  3602. real FValue1 = 0, FValue2 = 0;
  3603. void *Ptr1 = 0, *Ptr2 = 0;
  3604. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  3605. int Result1, Result2;
  3606. laEnumItem *ei;
  3607. if (!Expression) return 0;
  3608. Str1[0] = 0;
  3609. Str2[0] = 0;
  3610. laPropIterator pi = {0};
  3611. switch (Expression->Type){
  3612. case LA_CONDITION_PROP:
  3613. if (!Expression->PP.LastPs){
  3614. (*IResult) = 0;
  3615. return 0;
  3616. }
  3617. switch (Expression->PP.LastPs->p->PropertyType){
  3618. case LA_PROP_INT:
  3619. *IResult = laGetInt(&Expression->PP);
  3620. if (*IResult) return LA_CONDITION_INT;
  3621. else
  3622. return 0;
  3623. case LA_PROP_FLOAT:
  3624. *FResult = laGetFloat(&Expression->PP);
  3625. if (*FResult) return 1;
  3626. else
  3627. return 0;
  3628. break;
  3629. case LA_PROP_STRING:
  3630. laGetString(&Expression->PP, _StrResult, &StrResult);
  3631. if (StrResult[0]) return 1;
  3632. else
  3633. return 0;
  3634. break;
  3635. case LA_PROP_ENUM:
  3636. ei = laGetEnum(&Expression->PP);
  3637. if (!ei) return 0;
  3638. /*if(ei) */ *IResult = ei->Index;
  3639. if (*IResult) return LA_CONDITION_INT;
  3640. break;
  3641. case LA_PROP_SUB:
  3642. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  3643. else
  3644. Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  3645. *PtrResult = Instance;
  3646. if (Instance) return 1;
  3647. break;
  3648. default:
  3649. return 0;
  3650. }
  3651. case LA_CONDITION_INT:
  3652. *IResult = Expression->IntValue;
  3653. if (*IResult) return 1;
  3654. else
  3655. return 0;
  3656. case LA_CONDITION_FLOAT:
  3657. *FResult = Expression->FloatValue;
  3658. if (*FResult) return 1;
  3659. else
  3660. return 0;
  3661. case LA_CONDITION_STRING:
  3662. if (Expression->String){
  3663. strCopyFull(StrResult, Expression->String->Ptr);
  3664. return 1;
  3665. }else
  3666. return 0;
  3667. case LA_CONDITION_TRUE:
  3668. if (*IResult) *IResult = 1;
  3669. return 1;
  3670. case LA_CONDITION_FALSE:
  3671. if (*IResult) *IResult = 0;
  3672. return 0;
  3673. default:
  3674. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  3675. switch (Expression->Type){
  3676. case LA_CONDITION_AND:
  3677. if (Result1){
  3678. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3679. if (Result2) *IResult = 1;
  3680. return (Result2);
  3681. }else
  3682. return 0;
  3683. case LA_CONDITION_OR:
  3684. if (!Result1){
  3685. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3686. if (Result2) *IResult = 1;
  3687. return (Result2);
  3688. }else
  3689. return 1;
  3690. case LA_CONDITION_NOT:
  3691. return !Result1;
  3692. default:
  3693. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3694. return la_DoCompare(Expression->Type,
  3695. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  3696. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  3697. }
  3698. break;
  3699. }
  3700. return 0;
  3701. }
  3702. int la_DoSingleExpression(laUiConditionNode *Expression){
  3703. int a;
  3704. real b;
  3705. char c[128]={0};
  3706. void *p;
  3707. if (!Expression) return 1;
  3708. c[0] = 0;
  3709. return la_DoExpression(Expression, &a, &b, c, &p);
  3710. }
  3711. void la_StepExpression(laUiConditionNode *e){
  3712. if (!e) return;
  3713. switch (e->Type){
  3714. case LA_CONDITION_AND:
  3715. case LA_CONDITION_OR:
  3716. case LA_CONDITION_GE:
  3717. case LA_CONDITION_GT:
  3718. case LA_CONDITION_EQ:
  3719. case LA_CONDITION_LT:
  3720. case LA_CONDITION_LE:
  3721. la_StepExpression(e->Expression1);
  3722. la_StepExpression(e->Expression2);
  3723. break;
  3724. case LA_CONDITION_NOT:
  3725. la_StepExpression(e->Expression1);
  3726. break;
  3727. case LA_CONDITION_PROP:
  3728. la_StepPropPack(&e->PP);
  3729. if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){
  3730. la_UsePropPack(&e->PP, 1);
  3731. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  3732. }
  3733. break;
  3734. default:
  3735. break;
  3736. }
  3737. }
  3738. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  3739. if (!ucn) return;
  3740. la_ConditionNodeFreeRecursive(ucn->Expression1);
  3741. la_ConditionNodeFreeRecursive(ucn->Expression2);
  3742. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  3743. if (ucn->String) strSafeDestroy(&ucn->String);
  3744. if (ucn) memFree(ucn);
  3745. }
  3746. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  3747. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3748. ui->C = c;
  3749. ui->Type = &_LA_UI_CONDITION;
  3750. la_ConditionerInit(ui, Expression);
  3751. lstAppendItem(&uil->UiItems, ui);
  3752. return ui;
  3753. }
  3754. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  3755. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3756. laConditionUiExtraData *cued;
  3757. ui->Type = &_LA_UI_CONDITION_ELSE;
  3758. la_ConditionerInit(ui, 0);
  3759. cued = ui->Extra;
  3760. cued->EndUi = Beginner;
  3761. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  3762. ui->C = Beginner->C;
  3763. lstAppendItem(&uil->UiItems, ui);
  3764. return ui;
  3765. }
  3766. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  3767. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3768. laConditionUiExtraData *cued;
  3769. ui->Template = define;
  3770. ui->C = col;
  3771. ui->PP.RawThis = ExtraBase;
  3772. ui->Page = ExtraThis;
  3773. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  3774. la_ConditionerInit(ui, 0);
  3775. cued = ui->Extra;
  3776. //cued->Remove = Remove;
  3777. ui->State = LA_UI_NORMAL;
  3778. lstAppendItem(&uil->UiItems, ui);
  3779. return ui;
  3780. }
  3781. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  3782. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3783. laConditionUiExtraData *cued;
  3784. ui->Type = &_LA_UI_CONDITION_END;
  3785. la_ConditionerInit(ui, 0);
  3786. cued = ui->Extra;
  3787. cued->EndUi = Beginner;
  3788. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  3789. ui->C = Beginner->C;
  3790. lstAppendItem(&uil->UiItems, ui);
  3791. return ui;
  3792. }
  3793. laUiList *laMakeMenuPage(laUiList *uil, laColumn *c, const char *Title){
  3794. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3795. laUiList *muil = memAcquireSimple(sizeof(laUiList));
  3796. ui->Type = _LA_UI_MENU_ROOT;
  3797. strSafeSet(&ui->Display, Title);
  3798. ui->State = LA_UI_NORMAL;
  3799. ui->C = c;
  3800. lstAppendItem(&uil->UiItems, ui);
  3801. lstAppendItem(&ui->Subs, muil);
  3802. return muil;
  3803. }
  3804. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  3805. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3806. ui->Type = _LA_UI_ALIGN;
  3807. ui->C = widest;
  3808. lstAppendItem(&uil->UiItems, ui);
  3809. return ui;
  3810. }
  3811. void laFixHeight(laUiList *uil, short Rows){
  3812. if (!uil) return;
  3813. uil->HeightCoeff = Rows;
  3814. }
  3815. int la_GetUiType(laUiItem* ui) {
  3816. if (ui->AT) return LA_UI_INTERNAL_BUTTON;
  3817. if (ui->PP.LastPs) {
  3818. if (ui->Type == _LA_UI_CANVAS) return LA_UI_INTERNAL_2D_VIEW;
  3819. return LA_UI_INTERNAL_WATCHER;
  3820. }
  3821. if (ui->Display) {
  3822. if (ui->Type == _LA_UI_MENU_ROOT) return LA_UI_INTERNAL_MENU;
  3823. return LA_UI_INTERNAL_LABEL;
  3824. }
  3825. if (ui->Subs.pFirst) {
  3826. if (ui->Type == _LA_UI_FIXED_GROUP)return LA_UI_INTERNAL_GROUP;
  3827. if (ui->Type == _LA_UI_TAB)return LA_UI_INTERNAL_TAB;
  3828. return LA_UI_INTERNAL_GROUP;
  3829. }
  3830. if (ui->Type == _LA_UI_BUTTON) return LA_UI_INTERNAL_BUTTON;
  3831. if (ui->Type == &_LA_UI_CONDITION) return LA_UI_INTERNAL_BRACKET_BEGIN;
  3832. if (ui->Type == &_LA_UI_CONDITION_ELSE) return LA_UI_INTERNAL_BRACKET_ELSE;
  3833. if (ui->Type == &_LA_UI_CONDITION_END) return LA_UI_INTERNAL_BRACKET_END;
  3834. if (ui->Type == _LA_UI_CONDITION_TOGGLE) return LA_UI_INTERNAL_FOLDER_BEGIN;
  3835. if (ui->Type == _LA_UI_ALIGN) return LA_UI_INTERNAL_ALIGNER;
  3836. if (ui->Type == _LA_UI_COLUMN_ADJUSTER) return LA_UI_INTERNAL_ADJUSTER;
  3837. if (ui->Type == _LA_UI_SYMBOL) return LA_UI_INTERNAL_SYMBOL;
  3838. return LA_UI_INTERNAL_WATCHER;
  3839. }
  3840. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  3841. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  3842. if (!ExtraColumns) return;
  3843. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  3844. }
  3845. laUiTemplate *laFindUiTemplate(char *Identifier){
  3846. laUiTemplate *uit;
  3847. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3848. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3849. }
  3850. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3851. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3852. }
  3853. return 0;
  3854. }
  3855. void la_DestroyUiTemplate(laUiTemplate* uit){
  3856. strSafeDestroy(&uit->Identifier);
  3857. strSafeDestroy(&uit->Title);
  3858. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  3859. memFree(uit);
  3860. }
  3861. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  3862. strSafeDestroy(&uit->Identifier);
  3863. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3864. memFree(uit);
  3865. }
  3866. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  3867. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  3868. strSafeSet(&uit->Identifier, Identifier);
  3869. strSafeSet(&uit->Title, Title);
  3870. strSafeSet(&uit->CategoryName, NewCategory);
  3871. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  3872. uit->DefaultGLFormat=DefaultGLFormat;
  3873. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  3874. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  3875. la_UDFAppendSharedTypePointer(Identifier, uit);
  3876. return uit;
  3877. }
  3878. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  3879. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  3880. strSafeSet(&t->Identifier, Identifier);
  3881. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  3882. t->Init = CustomInit; t->Destroy = CustomDestroy;
  3883. lstAppendItem(&MAIN.View2DTemplates, t);
  3884. la_UDFAppendSharedTypePointer(Identifier, t);
  3885. return t;
  3886. }
  3887. void laFinalizeUiTemplates(){
  3888. laUiTemplate *uit;
  3889. laCanvasTemplate *u2d;
  3890. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  3891. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  3892. }
  3893. }
  3894. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  3895. laPanel *p;
  3896. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  3897. if (p->PanelTemplate==uit){
  3898. return p;
  3899. }
  3900. }
  3901. return 0;
  3902. }
  3903. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  3904. laUiList *uil, *NextUil;
  3905. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  3906. NextUil = uil->Item.pNext;
  3907. lstRemoveItem(&ui->Subs, uil);
  3908. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  3909. }
  3910. la_StopUiOperatorService(ui);
  3911. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  3912. strSafeDestroy(&ui->Display);
  3913. if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3914. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3915. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3916. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  3917. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  3918. memFree(ui);
  3919. }
  3920. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  3921. laUiItem *ui, *NextUi;
  3922. laColumn *col, *NextCol;
  3923. if (!uil) return;
  3924. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  3925. NextUi = ui->Item.pNext;
  3926. if(OnlyRemoveUser && RemoveUsers){
  3927. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3928. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3929. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3930. continue;
  3931. }
  3932. lstRemoveItem(&uil->UiItems, ui);
  3933. la_DestroyUiItem(ui, RemoveUsers);
  3934. }
  3935. if(OnlyRemoveUser){ return; }
  3936. for (col = uil->Columns.pFirst; col; col = NextCol){
  3937. NextCol = col->Item.pNext;
  3938. lstRemoveItem(&uil->Columns, col);
  3939. memFree(col);
  3940. }
  3941. strSafeDestroy(&uil->TabName);
  3942. if (!NoFree) memFree(uil);
  3943. }
  3944. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  3945. if(ui) lstRemoveItem(&ui->Subs, Tab);
  3946. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  3947. }
  3948. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  3949. laUiItem *Next = after->Item.pNext;
  3950. laUiItem *Last = uil->UiItems.pLast;
  3951. after->Item.pNext = 0;
  3952. uil->UiItems.pLast = after;
  3953. Define(uil, Base, This, ExtraColums, 0);
  3954. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  3955. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  3956. if (Next != Last) uil->UiItems.pLast = Last;
  3957. }
  3958. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  3959. // int i = 0;
  3960. // int FromW=FromR-FromL, ToW=ToR-ToL;
  3961. // if (!ui->ExtraColums) return;
  3962. // for (i; ui->ExtraColums[i]; i++) {
  3963. // laColumn* c = ui->ExtraColums[i];
  3964. // c->B = B;
  3965. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  3966. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  3967. // }
  3968. //}
  3969. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  3970. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  3971. }
  3972. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  3973. laColumn *c = ui->C;
  3974. laColumn *ic = lst->pFirst;
  3975. c->B = ui->TB + (*ui->Type->Theme)->BP;
  3976. for (ic; ic; ic = ic->Item.pNext){
  3977. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3978. ic->B = ic->B < c->B ? c->B : ic->B;
  3979. }
  3980. }
  3981. ic = ui->C;
  3982. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  3983. ;
  3984. for (ic; ic; ic = ic->Item.pNext){
  3985. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3986. ic->B = ic->B < c->B ? c->B : ic->B;
  3987. }
  3988. }
  3989. }
  3990. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  3991. laColumn *c = ui->C;
  3992. laColumn *ic = lst->pFirst;
  3993. c->B = ui->TB + (*ui->Type->Theme)->TP;
  3994. for (ic; ic; ic = ic->Item.pNext){
  3995. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3996. ic->B = ic->B < c->B ? c->B : ic->B;
  3997. }
  3998. }
  3999. ic = ui->C;
  4000. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4001. ;
  4002. for (ic; ic; ic = ic->Item.pNext){
  4003. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4004. ic->B = ic->B < c->B ? c->B : ic->B;
  4005. }
  4006. }
  4007. }
  4008. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4009. int rep;
  4010. int sp;
  4011. int rev;
  4012. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4013. if (!c) return 0;
  4014. sp = (c->SP * (R - L)) + L;
  4015. rev = sp;
  4016. /*if (U)*/ c->B = U;
  4017. if (LR == 1){
  4018. c->IL = L;
  4019. c->IR = sp;
  4020. if (repos){
  4021. c->IR = repos;
  4022. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4023. c->IR = c->IL + c->MaxW*LA_RH+M;
  4024. rev = c->IR;
  4025. }
  4026. }else if (LR == 2){
  4027. c->IL = sp;
  4028. c->IR = R;
  4029. if (repos){
  4030. c->IL = repos;
  4031. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4032. c->IL = c->IR - c->MaxW*LA_RH-M;
  4033. rev = c->IL;
  4034. }
  4035. }else if (LR == 0){
  4036. c->IL = L;
  4037. c->IR = R;
  4038. }
  4039. if (c->LS && c->RS->MaxW == 0){
  4040. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4041. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4042. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4043. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4044. }else if (c->RS && c->LS->MaxW == 0){
  4045. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4046. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4047. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4048. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4049. }
  4050. return rev;
  4051. }
  4052. STRUCTURE(laRowInfo){
  4053. int MaxW;
  4054. int MinW;
  4055. int UnitMinW;
  4056. int NonExpandW;
  4057. int TotalPadding;
  4058. int Expand, Even;
  4059. int ExpandAccum;
  4060. int CountElements;
  4061. int U,MaxB,L;
  4062. laListHandle Elements;
  4063. };
  4064. STRUCTURE(laRowNode){
  4065. laListItem Item;
  4066. laUiItem* ui;
  4067. int GotW, LP, RP, H;
  4068. int Expand;
  4069. };
  4070. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4071. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4072. ri->UnitMinW=LA_RH+bt->LM+bt->RM;
  4073. ri->Expand=ui->State?1:0;
  4074. ri->Even=ui->Flags?1:0;
  4075. ri->U=ui->TU; ri->L=ui->TL;
  4076. ri->MaxB=ui->TU;
  4077. }
  4078. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H){
  4079. laRowNode* rn=CreateNew(laRowNode);
  4080. rn->LP=bt->LP;rn->RP=bt->RP;
  4081. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH)) +bt->LM+bt->RM;
  4082. rn->ui=ui;
  4083. rn->H=H;
  4084. rn->Expand=ui->Expand;
  4085. lstAppendItem(&ri->Elements, rn);
  4086. if(!ri->UnitMinW){ri->UnitMinW=LA_RH+bt->LM+bt->RM;}
  4087. ri->TotalPadding += bt->LP+bt->RP;
  4088. ri->MinW+=ri->UnitMinW;
  4089. ri->NonExpandW+=rn->GotW;
  4090. ri->ExpandAccum+=ui->Expand;
  4091. ri->CountElements++;
  4092. if(ui->Expand){ri->Expand=1;}
  4093. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4094. }
  4095. int la_ShrinkableRowElements(laRowInfo* ri){
  4096. int count=0;
  4097. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4098. if(rn->GotW<=ri->UnitMinW) continue;
  4099. count++;
  4100. }
  4101. return count;
  4102. }
  4103. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4104. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end, int WaitAnimation){
  4105. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4106. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4107. if(Available<0){
  4108. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4109. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4110. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4111. }else{
  4112. if(!ri->Expand && Available>0){Available=0;}
  4113. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4114. }
  4115. if(!ShareCount) return 0;
  4116. int PerNode = Available/ShareCount;
  4117. int Remaining = Available-PerNode*ShareCount;
  4118. int L = ri->L; int i=0; laRowNode* rn;
  4119. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4120. laUiItem* ui=rn->ui;
  4121. int NodeAdd, Node=rn->GotW;
  4122. if(Available>=0){
  4123. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4124. NodeAdd+=(i<Remaining?1:0);i++;
  4125. }else{
  4126. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4127. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4128. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4129. }else{ Node=ri->UnitMinW;
  4130. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4131. }
  4132. }
  4133. ui->TL = L + rn->LP;
  4134. ui->TR = ui->TL + Node+NodeAdd;
  4135. ui->TB = ui->TU + rn->H;
  4136. L=ui->TR+rn->RP;
  4137. if (!WaitAnimation){
  4138. ui->L = ui->TL; ui->R = ui->TR;
  4139. ui->U = ui->TU; ui->B = ui->TB;
  4140. }
  4141. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4142. }
  4143. ui_end->TB = ri->MaxB;
  4144. while(rn=lstPopItem(&ri->Elements)){
  4145. FreeMem(rn);
  4146. }
  4147. memset(ri, 0, sizeof(laRowInfo));
  4148. }
  4149. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4150. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4151. int sl,sr,su,sb;
  4152. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4153. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4154. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4155. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4156. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4157. if(pc==LA_PC_SOCKET_OUT){
  4158. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4159. }else{
  4160. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4161. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4162. }
  4163. }
  4164. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4165. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4166. }
  4167. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4168. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4169. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4170. laBoxedTheme *bt;
  4171. int Lowest = 0;
  4172. int HyperValue = 0;
  4173. int WaitAnimation;
  4174. int RowMode=0; laRowInfo ri={0};
  4175. laBoxedTheme* pt=*(ParentPanel->BT);
  4176. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4177. int MaxR=0;
  4178. if(!uil->Scale){uil->Scale=1;}
  4179. uil->SaveScale=MAIN.UiScale;
  4180. MAIN.UiScale*=uil->Scale;
  4181. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4182. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4183. WaitAnimation = 0;
  4184. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4185. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4186. for (ui = uil->UiItems.pFirst; ui;){
  4187. int SubB = 0;
  4188. int H;
  4189. WaitAnimation = 0;
  4190. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4191. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4192. //if (Fast && ui->C->B > B) {
  4193. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4194. // ui = ui->Item.pNext;
  4195. // continue;
  4196. //}
  4197. if (!ui->Instructions){
  4198. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4199. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4200. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4201. laOperatorProp *ap = ui->PP.LastPs->p;
  4202. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  4203. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  4204. }
  4205. }
  4206. if (/*!ui->NoRefresh && */ ui->PP.LastPs){
  4207. la_StepPropPack(&ui->PP);
  4208. }
  4209. la_UsePropPack(&ui->PP, 0);
  4210. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  4211. // 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);
  4212. //}
  4213. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  4214. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  4215. WaitAnimation = 1;
  4216. }
  4217. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  4218. bt = (*ui->Type->Theme);
  4219. if (ui->Type == &_LA_UI_CONDITION){
  4220. laConditionUiExtraData *cued = ui->Extra;
  4221. la_StepExpression(cued->Expression);
  4222. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4223. if (!cued->IsTrue){
  4224. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4225. }else{
  4226. ui = ui->Item.pNext;
  4227. }
  4228. continue;
  4229. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4230. ui = ui->Item.pNext;
  4231. continue;
  4232. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4233. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4234. if (cued->IsTrue) ui = cued->EndUi;
  4235. else
  4236. ui = ui->Item.pNext;
  4237. continue;
  4238. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4239. laConditionUiExtraData *cued = ui->Extra;
  4240. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  4241. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  4242. if (!WaitAnimation){
  4243. ui->L = ui->TL; ui->R = ui->TR;
  4244. ui->U = ui->TU; ui->B = ui->TB;
  4245. }
  4246. if(!RowMode){
  4247. la_CalcUiItemInfluence(&uil->Columns, ui);
  4248. }else{
  4249. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4250. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4251. }
  4252. if (ui->State == LA_UI_NORMAL){
  4253. cued->IsTrue = 0;
  4254. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  4255. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  4256. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4257. }else{
  4258. cued->IsTrue = 1;
  4259. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  4260. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  4261. //}
  4262. ui = ui->Item.pNext;
  4263. }
  4264. continue;
  4265. }
  4266. if (ui->Type == _LA_UI_ALIGN){
  4267. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU;
  4268. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4269. if (ui->TB > Lowest) Lowest = ui->TB;
  4270. if (!WaitAnimation){
  4271. ui->L = ui->TL; ui->R = ui->TR;
  4272. ui->U = ui->TU; ui->B = ui->TB;
  4273. }
  4274. if(!RowMode){
  4275. la_CalcUiItemInfluence(&uil->Columns, ui);
  4276. }else{
  4277. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  4278. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4279. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4280. }
  4281. ui = ui->Item.pNext; continue;
  4282. }
  4283. if (ui->Type == &_LA_UI_ROW_BEGIN){
  4284. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4285. la_InitRowNode(&ri, ui, bt);
  4286. RowMode=1; ui=ui->Item.pNext; continue;
  4287. }
  4288. if (ui->Type == &_LA_UI_ROW_END){
  4289. la_CalculateRowExpand(&ri, ui, WaitAnimation);
  4290. la_CalcUiItemInfluence(&uil->Columns, ui);
  4291. RowMode=0; ui=ui->Item.pNext; continue;
  4292. }
  4293. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  4294. int GB=0;
  4295. 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; }
  4296. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4297. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  4298. if (H < 0){
  4299. if(B){ H = B + (H+1) * LA_RH - ui->TU; }
  4300. else{ H=LA_RH; }
  4301. }
  4302. else H *= LA_RH;
  4303. ui->TB = ui->TU;
  4304. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4305. 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
  4306. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  4307. if (ui->Type == _LA_UI_COLLECTION){
  4308. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  4309. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4310. ui->PP.EndInstance = TInstance;
  4311. laUiList *iuil = ui->Subs.pFirst;
  4312. laUiList *puil = iuil;
  4313. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  4314. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  4315. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4316. int Begin = ui->TB;
  4317. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  4318. int ElementB = ui->TU;
  4319. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  4320. int MaxB = ElementB;
  4321. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4322. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  4323. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  4324. if (!ElementLimit) RowPriority = 0;
  4325. if (!TInstance){
  4326. while (iuil){
  4327. puil = iuil->Item.pNext;
  4328. la_DestroyTabPage(ui, iuil, 0);
  4329. iuil = puil;
  4330. }
  4331. }
  4332. while (TInstance){
  4333. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  4334. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4335. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4336. ui->PP.EndInstance = TInstance; continue;
  4337. }
  4338. if(CanGetTheme){
  4339. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4340. la_SwitchThemeQuick(t, OriginalTheme);
  4341. }
  4342. if(CanGetGap){
  4343. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  4344. Gap=g*LA_RH;
  4345. }else Gap=0;
  4346. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  4347. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  4348. }else GotCategory=0;
  4349. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  4350. if (RowPriority){
  4351. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  4352. }
  4353. }
  4354. FirstIn=0;
  4355. if (ElementLimit){
  4356. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  4357. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  4358. }
  4359. while (iuil && iuil->Instance != TInstance){
  4360. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  4361. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  4362. }else{
  4363. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  4364. }
  4365. iuil = puil;
  4366. }
  4367. if(!iuil){
  4368. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  4369. }
  4370. if (!iuil){
  4371. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  4372. la_CalcUiTopInfluence(&uil->Columns, ui);
  4373. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4374. 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);
  4375. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4376. iuil = ui->Page->Item.pNext;
  4377. }else{
  4378. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  4379. 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);
  4380. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4381. la_CalcUiItemInfluence(&uil->Columns, ui);
  4382. iuil = iuil->Item.pNext;
  4383. }
  4384. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4385. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4386. ui->PP.EndInstance = TInstance;
  4387. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4388. if (RowPriority){
  4389. Col += 1;
  4390. if (Col >= ElementLimit){
  4391. Col = 0;
  4392. Row += 1;
  4393. Begin = ElementB + bt->TM;
  4394. }
  4395. }elif(Spread){
  4396. EL+=Spread*LA_RH;
  4397. ER+=Spread*LA_RH;
  4398. }else{
  4399. Row += 1;
  4400. Begin = ElementB + bt->TM;
  4401. if (ElementLimit && Row >= ElementLimit){
  4402. Row = 0;
  4403. Col += 1;
  4404. Begin = ui->TU + bt->TM;
  4405. }
  4406. }
  4407. ui->TB = ElementB;
  4408. MaxB = MaxB < ElementB ? ElementB : MaxB;
  4409. }
  4410. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  4411. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  4412. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4413. ui->TB = MaxB;
  4414. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  4415. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  4416. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  4417. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4418. ui->PP.EndInstance = TInstance;
  4419. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4420. if(!Template) Template=laui_SubPropInfoDefault;
  4421. //ui->Template = Template;
  4422. if (!ui->Subs.pFirst && TInstance){
  4423. la_AddInstancePage(ui, TInstance, 0);
  4424. la_CalcUiTopInfluence(&uil->Columns, ui);
  4425. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4426. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4427. ui->TB = SubB + (NoDecal?0:bt->TM);
  4428. }else if (ui->Subs.pFirst){
  4429. if (!TInstance || TInstance != ui->Page->Instance){
  4430. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  4431. ui->Page = 0;
  4432. if (TInstance){
  4433. la_AddInstancePage(ui, TInstance, 0);
  4434. la_CalcUiTopInfluence(&uil->Columns, ui);
  4435. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4436. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4437. ui->TB = SubB + (NoDecal?0:bt->TM);
  4438. }else
  4439. ui->TB = ui->TU + LA_RH + bt->BM;
  4440. }else{
  4441. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4442. ui->TB = SubB + (NoDecal?0:bt->TM);
  4443. }
  4444. }
  4445. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  4446. if (!WaitAnimation){
  4447. ui->L = ui->TL;
  4448. ui->R = ui->TR;
  4449. ui->U = ui->TU;
  4450. ui->B = ui->TB;
  4451. }
  4452. }
  4453. }else{
  4454. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4455. if (ui->Type != _LA_UI_CANVAS){
  4456. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  4457. la_CalcUiTopInfluence(&uil->Columns, ui);
  4458. SubB = la_UpdateUiListRecursive(ui->Page,
  4459. 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);
  4460. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  4461. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH : SubB)) + (NoDecal?0:bt->TM);
  4462. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  4463. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  4464. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  4465. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  4466. }
  4467. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  4468. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  4469. if(GB && ui->TB >= GB){
  4470. ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  4471. if(ui->Page->HeightCoeff){
  4472. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  4473. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  4474. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  4475. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  4476. }
  4477. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  4478. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  4479. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  4480. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  4481. }
  4482. }
  4483. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  4484. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  4485. }else{
  4486. laUiList *suil;
  4487. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  4488. la_CalcUiTopInfluence(&uil->Columns, ui);
  4489. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4490. 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);
  4491. }
  4492. }
  4493. ui->TB = ui->TU + H;
  4494. }
  4495. }else ui->TB = ui->TU + H;
  4496. }
  4497. if (ui->TB > Lowest) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  4498. if(!RowMode){
  4499. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  4500. }else{
  4501. la_AddRowNode(&ri, ui, bt, H);
  4502. }
  4503. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  4504. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4505. ui = ui->Item.pNext;
  4506. }
  4507. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  4508. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  4509. else uil->TB = Lowest;
  4510. if (!WaitAnimation){
  4511. uil->L = uil->TL;
  4512. uil->R = uil->TR;
  4513. uil->U = uil->TU;
  4514. uil->B = uil->TB;
  4515. }
  4516. MAIN.UiScale=uil->SaveScale;
  4517. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4518. return uil->TB;
  4519. }
  4520. int la_AnimateSingleUiSize(int To, int *Now){
  4521. int Delta;
  4522. if (To != *Now){
  4523. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  4524. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  4525. *Now += Delta;
  4526. return 1;
  4527. }else
  4528. return 0;
  4529. }
  4530. int la_AnimateUiListRecursive(laUiList *uil){
  4531. laUiItem *ui;
  4532. int Again = 0;
  4533. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  4534. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  4535. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  4536. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  4537. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  4538. la_AnimateSingleUiSize(ui->TR, &ui->R));
  4539. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4540. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  4541. laUiList *suil;
  4542. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4543. Again += la_AnimateUiListRecursive(suil);
  4544. }
  4545. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  4546. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4547. Again += la_AnimateUiListRecursive(ui->Page);
  4548. }
  4549. }
  4550. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  4551. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  4552. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  4553. la_AnimateSingleUiSize(uil->TR, &uil->R));
  4554. return Again;
  4555. }
  4556. int la_DrawUiItem(laUiItem *ui){
  4557. tnsUseNoTexture();
  4558. tnsColor4d(1, 1, 1, 1);
  4559. tnsVertex2d(ui->L, ui->U);
  4560. tnsVertex2d(ui->R, ui->U);
  4561. tnsVertex2d(ui->R, ui->B);
  4562. tnsVertex2d(ui->L, ui->B);
  4563. tnsPackAs(GL_LINE_LOOP);
  4564. }
  4565. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  4566. tnsUseNoTexture();
  4567. tnsColor4d(1, 1, 1, 1);
  4568. tnsVertex2d(ui->L - 1, ui->U - 1);
  4569. tnsVertex2d(ui->R + 1, ui->U - 1);
  4570. tnsVertex2d(ui->R + 1, ui->B + 1);
  4571. tnsVertex2d(ui->L - 1, ui->B + 1);
  4572. tnsPackAs(GL_LINE_LOOP);
  4573. }
  4574. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  4575. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  4576. return 1;
  4577. }
  4578. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  4579. laUiListDrawItem *uildi = uild->Items.pFirst;
  4580. laUiList *Target = uildi->Target;
  4581. int L, R, U, B;
  4582. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  4583. L = Target->L + Target->PanX + uildi->DifX;
  4584. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4585. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4586. U = Target->U + Target->PanY + uildi->DifY;
  4587. return la_UiInBound(ui, L, R, U, B);
  4588. }
  4589. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  4590. laUiListDrawItem *uildi = uild->Items.pFirst;
  4591. laUiList *Target = uildi->Target;
  4592. int L, R, U, B;
  4593. if (Target){
  4594. L = Target->L + Target->PanX + uildi->DifX;
  4595. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4596. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4597. U = Target->U + Target->PanY + uildi->DifY;
  4598. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  4599. return 1;
  4600. }else{
  4601. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  4602. return 1;
  4603. }
  4604. }
  4605. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  4606. laUiItem *ui = uil->UiItems.pFirst;
  4607. while (!strGetArgument(ui->Instructions, mark))
  4608. ui = ui->Item.pNext;
  4609. return ui;
  4610. }
  4611. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  4612. laUiList *uil;
  4613. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  4614. if (uil->Instance == Instance) return uil;
  4615. }
  4616. return uil;
  4617. }
  4618. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  4619. int mx=(L+R)/2; int my=(U+B)/2;
  4620. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  4621. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  4622. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  4623. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  4624. tnsFlush();
  4625. }
  4626. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  4627. if(!uil->ScrollerShownV) return;
  4628. int W = LA_SCROLL_W;
  4629. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  4630. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  4631. int U = uil->U + Offset;
  4632. int B = U + Len;
  4633. int L = UiR - _LA_THEME_PANEL->RM - W;
  4634. int R = L + W;
  4635. if (B > U + DisplayH) B = U + DisplayH;
  4636. if (U < uil->U) U = uil->U;
  4637. if (B <= uil->U || U >= uil->B) return;
  4638. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  4639. if (U < uil->U) U = uil->U;
  4640. tnsUseNoTexture();
  4641. laBoxedTheme* bt=_LA_THEME_PANEL;
  4642. real* color=laThemeColor(bt, LA_BT_TEXT);
  4643. tnsColor4d(LA_COLOR3(color), 0.8);
  4644. tnsVertex2d(R, U);
  4645. tnsVertex2d(L, U);
  4646. tnsVertex2d(L, B);
  4647. tnsVertex2d(R, B);
  4648. tnsPackAs(GL_TRIANGLE_FAN);
  4649. tnsColor4d(LA_COLOR3(color), 0.8);
  4650. tnsVertex2d(R, uil->U);
  4651. tnsVertex2d(L, uil->U);
  4652. tnsVertex2d(L, uil->U + DisplayH);
  4653. tnsVertex2d(R, uil->U + DisplayH);
  4654. tnsPackAs(GL_LINE_LOOP);
  4655. int HU=(U+B)/2+LA_RH2;
  4656. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4657. }
  4658. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  4659. if(!uil->ScrollerShownH) return;
  4660. int W = LA_SCROLL_W;
  4661. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  4662. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  4663. int L = uil->L + Offset;
  4664. int R = L + Len;
  4665. int U = UiB - _LA_THEME_PANEL->RM - W;
  4666. int B = U + W;
  4667. if (B > U + DisplayW) B = U + DisplayW;
  4668. if (U < uil->U) U = uil->U;
  4669. if (R <= uil->L || L >= uil->R) return;
  4670. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  4671. if (L < uil->L) L = uil->L;
  4672. tnsUseNoTexture();
  4673. laBoxedTheme* bt=_LA_THEME_PANEL;
  4674. real* color=laThemeColor(bt, LA_BT_TEXT);
  4675. tnsColor4d(LA_COLOR3(color), 0.8);
  4676. tnsVertex2d(R, U);
  4677. tnsVertex2d(L, U);
  4678. tnsVertex2d(L, B);
  4679. tnsVertex2d(R, B);
  4680. tnsPackAs(GL_TRIANGLE_FAN);
  4681. tnsColor4d(LA_COLOR3(color), 0.8);
  4682. tnsVertex2d(uil->L,U);
  4683. tnsVertex2d(uil->L,B);
  4684. tnsVertex2d(uil->L + DisplayW,B);
  4685. tnsVertex2d(uil->L + DisplayW,U);
  4686. tnsPackAs(GL_LINE_LOOP);
  4687. int HU=(U+B)/2+LA_RH2;
  4688. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4689. }
  4690. void la_DrawInstanceBkg(laUiList *uil, real* color){
  4691. tnsUseNoTexture();
  4692. tnsColor4dv(color);
  4693. tnsVertex2d(uil->L, uil->U); tnsVertex2d(uil->R, uil->U);
  4694. tnsVertex2d(uil->R, uil->B); tnsVertex2d(uil->L, uil->B);
  4695. tnsPackAs(GL_TRIANGLE_FAN);
  4696. }
  4697. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  4698. laSocketRecord* sr;
  4699. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  4700. uild->WiresContainer=container;
  4701. }
  4702. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  4703. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  4704. if(lip->Target==uild->WiresContainer) break;
  4705. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  4706. }
  4707. }
  4708. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  4709. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4710. int PanX, PanY;
  4711. if(pc==LA_PC_SOCKET_OUT){
  4712. laNodeOutSocket* s=ui->PP.EndInstance;
  4713. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  4714. }else{
  4715. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  4716. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  4717. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  4718. }
  4719. }
  4720. void la_RegenerateWireColors(){
  4721. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  4722. laTheme* t=MAIN.CurrentTheme;
  4723. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  4724. real hcy[]={0.0,0.8,0.6}; hcy[1]=t->WireSaturation; hcy[2]=t->WireBrightness;
  4725. for(int i=0;i<MAIN.WireColorSlices;i++){
  4726. hcy[0]=(real)i/(real)MAIN.WireColorSlices;
  4727. tnsHCY2RGB(hcy, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  4728. }
  4729. }
  4730. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  4731. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  4732. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  4733. tnsInterpolate2dv(v1,v2,0.5,vi);
  4734. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=log(dist+1)*MAIN.WireSaggyness; }
  4735. tnsVectorMinus2d(v1s,vi,v1); tnsNormalizeSelf2d(v1s); tnsVectorMultiSelf2d(v1s,circle_r);
  4736. tnsVectorMinus2d(v2s,vi,v2); tnsNormalizeSelf2d(v2s); tnsVectorMultiSelf2d(v2s,circle_r);
  4737. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  4738. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  4739. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  4740. tnsVertex2d(v1[0],v1[1]);
  4741. for(int i=1;i<=steps;i++){
  4742. real ratio=i==steps?1.0f:step*i;
  4743. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  4744. tnsVertex2d(v1s[0],v1s[1]);
  4745. }
  4746. }
  4747. void la_DrawNodeWires(laUiListDraw* uild){
  4748. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  4749. laBoxedTheme* bt=_LA_THEME_SOCKET;
  4750. tnsUseNoTexture();
  4751. #define _RSLICES 16
  4752. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  4753. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4754. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4755. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4756. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4757. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4758. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4759. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4760. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4761. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4762. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4763. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4764. }
  4765. if(MAIN.tNodeIn->Source){
  4766. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4767. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4768. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4769. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4770. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4771. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4772. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4773. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4774. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4775. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4776. }
  4777. #undef _RSLICES
  4778. tnsFlush();
  4779. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  4780. glLineWidth(ww);
  4781. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4782. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4783. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4784. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4785. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4786. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4787. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4788. }
  4789. if(MAIN.tNodeIn->Source){
  4790. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4791. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4792. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4793. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4794. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4795. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4796. }
  4797. tnsFlush();
  4798. glLineWidth(1);
  4799. la_InitSocketRecord(uild,0);
  4800. }
  4801. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  4802. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  4803. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  4804. }
  4805. 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){
  4806. laUiItem *ui;
  4807. laBoxedTheme *bt;
  4808. laUiList *sub;
  4809. laUiListDrawItem *uildi;
  4810. int Ret = 0;
  4811. if (!uil) return 0;
  4812. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  4813. ui = uil->UiItems.pFirst;
  4814. if(uil->PanY<0){uil->PanY=0;}
  4815. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  4816. uil->SaveScale=MAIN.UiScale;
  4817. MAIN.UiScale*=uil->Scale;
  4818. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4819. for (; ui;){
  4820. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4821. if (ui->Type == &_LA_UI_CONDITION){
  4822. laConditionUiExtraData *cued = ui->Extra;
  4823. la_StepExpression(cued->Expression);
  4824. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4825. if (!cued->IsTrue){
  4826. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4827. }else{
  4828. ui = ui->Item.pNext;
  4829. }
  4830. continue;
  4831. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4832. ui = ui->Item.pNext;
  4833. continue;
  4834. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4835. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4836. if (cued->IsTrue) ui = cued->EndUi;
  4837. else
  4838. ui = ui->Item.pNext;
  4839. continue;
  4840. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4841. laConditionUiExtraData *cued = ui->Extra;
  4842. ui->Type->Draw(ui, LA_RH);
  4843. if (ui->State == LA_UI_NORMAL){
  4844. cued->IsTrue = 0;
  4845. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4846. }else{
  4847. cued->IsTrue = 1;
  4848. ui = ui->Item.pNext;
  4849. }
  4850. continue;
  4851. }
  4852. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  4853. int NeedDraw=0;
  4854. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  4855. if(NeedDraw){
  4856. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  4857. }else{ ui->Type->Draw(ui, LA_RH); }
  4858. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  4859. tnsFlush();
  4860. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  4861. tnsResetViewMatrix();
  4862. }
  4863. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  4864. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  4865. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  4866. tnsFlush();
  4867. }
  4868. }
  4869. if(NeedDraw || RegisterNodes){
  4870. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  4871. if (ui->Type == _LA_UI_FIXED_GROUP ||
  4872. ui->Type == _LA_UI_TAB ||
  4873. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4874. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  4875. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  4876. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4877. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  4878. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  4879. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  4880. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  4881. 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); }
  4882. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  4883. 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);
  4884. 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)); }
  4885. }elif (ui->Type == _LA_UI_COLLECTION){
  4886. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  4887. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4888. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4889. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4890. int State;
  4891. ui->PP.EndInstance = sub->Instance;
  4892. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  4893. if(!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && NeedDraw){
  4894. if (CanGetState){
  4895. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  4896. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL));
  4897. }elif (sub->Instance == Active){
  4898. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL));
  4899. }
  4900. }
  4901. if(sub->TabName && sub->TabName->Ptr){
  4902. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4903. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4904. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  4905. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  4906. tnsFlush();
  4907. }
  4908. if(CanGetTheme){
  4909. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4910. la_SwitchThemeQuick(t, OriginalTheme);
  4911. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL));
  4912. }
  4913. tnsFlush();
  4914. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  4915. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4916. }
  4917. ui->PP.EndInstance = Active;
  4918. }elif (ui->Type == _LA_UI_CANVAS){
  4919. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4920. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4921. tnsFlush();
  4922. Ret += la_DrawUiListRecursive(uild, sub, L-1, R+1, U-1, B+1, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  4923. }
  4924. }
  4925. }
  4926. ui = ui->Item.pNext;
  4927. }else{
  4928. ui = ui->Item.pNext;
  4929. }
  4930. }
  4931. tnsFlush();
  4932. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  4933. la_RestoreLastUiListMatrix(uild, B - U);
  4934. MAIN.UiScale=uil->SaveScale;
  4935. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4936. return Ret;
  4937. }
  4938. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  4939. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  4940. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  4941. tnsUseNoTexture();
  4942. tnsColor4d(1, 1, 1, 1);
  4943. tnsVertex2d(L, U);
  4944. tnsVertex2d(R, U);
  4945. tnsVertex2d(R, B);
  4946. tnsVertex2d(L, B);
  4947. tnsPackAs(GL_LINE_LOOP);
  4948. tnsVertex2d(L + 3, Begin);
  4949. tnsVertex2d(R - 3, Begin);
  4950. tnsVertex2d(R - 3, End);
  4951. tnsVertex2d(L + 3, End);
  4952. tnsPackAs(GL_LINE_LOOP);
  4953. }
  4954. int laIsInUiItem(laUiItem *ui, int x, int y){
  4955. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  4956. return 1;
  4957. }
  4958. int laIsInBound(int x, int y, int l, int r, int u, int b){
  4959. if (x < l || x > r || y < u || y > b) return 0;
  4960. return 1;
  4961. }
  4962. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  4963. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  4964. laUiItem *ui, *tui;
  4965. laBoxedTheme *bt;
  4966. laUiList *sub;
  4967. int CPB = 0;
  4968. if (!uil || (LimB && y > LimB)) return 0;
  4969. x += uil->PanX;
  4970. y += uil->PanY;
  4971. for (ui = uil->UiItems.pFirst; ui;){
  4972. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4973. if (ui->Type == &_LA_UI_CONDITION){
  4974. laConditionUiExtraData *cued = ui->Extra;
  4975. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  4976. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4977. if (!cued->IsTrue){
  4978. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4979. }else{
  4980. ui = ui->Item.pNext;
  4981. }
  4982. continue;
  4983. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4984. ui = ui->Item.pNext;
  4985. continue;
  4986. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4987. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4988. if (cued->IsTrue) ui = cued->EndUi;
  4989. else
  4990. ui = ui->Item.pNext;
  4991. continue;
  4992. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4993. laConditionUiExtraData *cued = ui->Extra;
  4994. if (laIsInUiItem(ui, x, y)){
  4995. lstAppendPointer(LocalBuf, uil);
  4996. return ui;
  4997. }
  4998. if (ui->State == LA_UI_NORMAL){
  4999. cued->IsTrue = 0;
  5000. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5001. }else{
  5002. cued->IsTrue = 1;
  5003. ui = ui->Item.pNext;
  5004. }
  5005. continue;
  5006. }
  5007. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5008. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5009. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5010. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5011. if(!la_DetectSplit(ui->C, x)) Add=0;
  5012. }
  5013. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5014. }
  5015. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5016. if (ui->Page->HeightCoeff) CPB = ui->B;
  5017. else CPB = ui->Page->B;
  5018. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5019. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5020. lstAppendPointer(LocalBuf, uil);
  5021. return tui;
  5022. }
  5023. }else if (laIsInUiItem(ui, x, y)){
  5024. lstAppendPointer(LocalBuf, uil);return ui;
  5025. }
  5026. }
  5027. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5028. if (laIsInUiItem(ui, x, y)){
  5029. lstAppendPointer(LocalBuf, uil);
  5030. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5031. if(Deep){
  5032. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5033. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5034. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5035. lstAppendPointer(LocalBuf, iuil);
  5036. return tui;
  5037. }
  5038. }
  5039. }
  5040. }
  5041. return ui;
  5042. }
  5043. }
  5044. if (ui->Type == _LA_UI_CANVAS){
  5045. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5046. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5047. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5048. lstAppendPointer(LocalBuf, uil);
  5049. return tui;
  5050. }
  5051. }
  5052. }
  5053. if (laIsInUiItem(ui, x, y)){
  5054. lstAppendPointer(LocalBuf, uil);
  5055. return ui;
  5056. }
  5057. }
  5058. ui = ui->Item.pNext;
  5059. }
  5060. return 0;
  5061. }
  5062. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5063. laListHandle Locals={0};
  5064. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5065. while(lstPopPointer(&Locals));
  5066. printf("%s\n", ui?ui->Type->Identifier:"?");
  5067. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5068. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5069. if(pc==PCInOrOut) return ui;
  5070. }
  5071. return 0;
  5072. }
  5073. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5074. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5075. laUiItem *ui = uil->UiItems.pFirst;
  5076. laBoxedTheme *bt;
  5077. laUiList *tuil;
  5078. laUiList *sub;
  5079. int CPB = 0;
  5080. x += uil->PanX;
  5081. y += uil->PanY;
  5082. if (y > LimH) return uil;
  5083. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5084. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5085. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5086. return uil;
  5087. }
  5088. for (ui = uil->UiItems.pFirst; ui;){
  5089. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5090. if (ui->Type == &_LA_UI_CONDITION){
  5091. laConditionUiExtraData *cued = ui->Extra;
  5092. //la_StepExpression(cued->Expression);
  5093. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5094. if (!cued->IsTrue){
  5095. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5096. }else{
  5097. ui = ui->Item.pNext;
  5098. }
  5099. continue;
  5100. }
  5101. if (ui->Type == &_LA_UI_CONDITION_END){
  5102. ui = ui->Item.pNext;
  5103. continue;
  5104. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5105. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5106. if (cued->IsTrue) ui = cued->EndUi;
  5107. else
  5108. ui = ui->Item.pNext;
  5109. continue;
  5110. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5111. laConditionUiExtraData *cued = ui->Extra;
  5112. if (ui->State == LA_UI_NORMAL){
  5113. cued->IsTrue = 0;
  5114. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5115. }else{
  5116. cued->IsTrue = 1;
  5117. ui = ui->Item.pNext;
  5118. }
  5119. continue;
  5120. }
  5121. if (InToContainerUI && ui != Exception){
  5122. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5123. if (ContainerParent) (*ContainerParent) = uil;
  5124. if (ParentUi) *ParentUi = ui;
  5125. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5126. //if (y > LimH) return uil;
  5127. 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))){
  5128. return tuil;
  5129. }
  5130. }
  5131. }
  5132. }
  5133. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5134. if (ui->Page->HeightCoeff) CPB = ui->B;
  5135. else CPB = ui->Page->B;
  5136. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5137. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5138. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5139. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5140. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5141. if (ParentUi) *ParentUi = ui;
  5142. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5143. }
  5144. }
  5145. ui = ui->Item.pNext;
  5146. }
  5147. return uil;
  5148. }
  5149. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5150. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5151. laUiItem *ui = uil->UiItems.pFirst;
  5152. laBoxedTheme *bt;
  5153. laUiList *tuil;
  5154. laUiList *sub;
  5155. int CPB = 0;
  5156. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5157. x += uil->PanX;
  5158. y += uil->PanY;
  5159. if (y > LimH) return uil;
  5160. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5161. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5162. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5163. return uil;
  5164. }
  5165. for (ui = uil->UiItems.pFirst; ui;){
  5166. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5167. if (ui->Type == &_LA_UI_CONDITION){
  5168. laConditionUiExtraData *cued = ui->Extra;
  5169. //la_StepExpression(cued->Expression);
  5170. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5171. if (!cued->IsTrue){
  5172. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5173. }else{
  5174. ui = ui->Item.pNext;
  5175. }
  5176. continue;
  5177. }
  5178. if (ui->Type == &_LA_UI_CONDITION_END){
  5179. ui = ui->Item.pNext;
  5180. continue;
  5181. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5182. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5183. if (cued->IsTrue) ui = cued->EndUi;
  5184. else
  5185. ui = ui->Item.pNext;
  5186. continue;
  5187. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5188. laConditionUiExtraData *cued = ui->Extra;
  5189. if (ui->State == LA_UI_NORMAL){
  5190. cued->IsTrue = 0;
  5191. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5192. }else{
  5193. cued->IsTrue = 1;
  5194. ui = ui->Item.pNext;
  5195. }
  5196. continue;
  5197. }
  5198. if (InToContainerUI && ui != Exception){
  5199. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5200. if (ContainerParent) (*ContainerParent) = uil;
  5201. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5202. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5203. //if (y > LimH) return uil;
  5204. 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))){
  5205. return tuil;
  5206. }
  5207. }
  5208. }
  5209. }
  5210. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5211. if (ui->Page->HeightCoeff) CPB = ui->B;
  5212. else CPB = ui->Page->B;
  5213. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5214. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5215. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5216. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5217. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5218. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5219. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5220. }
  5221. }
  5222. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  5223. if (ui->Page->HeightCoeff) CPB = ui->B;
  5224. else
  5225. CPB = ui->Page->B;
  5226. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  5227. if (ScrollUil) *ScrollUil = ui->Page;
  5228. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5229. }
  5230. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5231. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5232. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5233. }
  5234. }
  5235. ui = ui->Item.pNext;
  5236. }
  5237. return uil;
  5238. }
  5239. int la_TestUiListMinumWidth(laUiList *uil){
  5240. laUiItem *ui, *tui;
  5241. laBoxedTheme *bt;
  5242. laUiList *sub;
  5243. int CPB = 0;
  5244. int W = 0;
  5245. int tW, sW, RowMode=0, rW;
  5246. void *Restore;
  5247. for (ui = uil->UiItems.pFirst; ui;){
  5248. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5249. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5250. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  5251. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5252. if (W < tW) W = tW;
  5253. }elif (ui->Type == _LA_UI_COLLECTION){
  5254. Restore = ui->PP.EndInstance;
  5255. tW = 0; sW = 0;
  5256. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5257. ui->PP.EndInstance = sub->Instance;
  5258. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  5259. if (sW > tW) tW = sW;
  5260. }
  5261. ui->PP.EndInstance = Restore;
  5262. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5263. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  5264. if (W < tW) W = tW;
  5265. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  5266. RowMode=1; rW=0;
  5267. }elif (ui->Type==&_LA_UI_ROW_END){
  5268. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  5269. }elif (ui->Type->GetMinWidth){
  5270. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  5271. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  5272. }
  5273. ui = ui->Item.pNext;
  5274. }
  5275. return W;
  5276. }
  5277. void la_InitLLVM(){
  5278. //LLVMLinkInMCJIT();
  5279. //LLVMInitializeNativeTarget();
  5280. //LLVMInitializeNativeAsmPrinter();
  5281. //LLVMInitializeNativeAsmParser();
  5282. // MAIN.llvmContext = LLVMGetGlobalContext();
  5283. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  5284. }
  5285. //==================================================================================================
  5286. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  5287. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  5288. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  5289. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  5290. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  5291. memFree(kmi);
  5292. }
  5293. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  5294. laKeyMapItem *kmi;
  5295. if (!km) return 0;
  5296. kmi = memAcquire(sizeof(laKeyMapItem));
  5297. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  5298. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  5299. }else{
  5300. strSafeSet(&kmi->Operation, Operation);
  5301. }
  5302. strSafeSet(&kmi->Instructions, ExtraInstructions);
  5303. kmi->SpecialKeyBits = SpecialKeyBits;
  5304. kmi->EventType = EventType;
  5305. kmi->Key = Key;
  5306. kmi->SelectBase = SelectBase;
  5307. lstAppendItem(&km->Items, kmi);
  5308. return kmi;
  5309. }
  5310. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  5311. laKeyMapItem *kmi; int inv=0;
  5312. char *instructions;
  5313. if(e->Type==LA_MOUSEMOVE) return 0;
  5314. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5315. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5316. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5317. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5318. if (kmi->Operation)
  5319. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5320. else
  5321. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5322. inv = 1;
  5323. }
  5324. }
  5325. return inv;
  5326. }
  5327. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  5328. laKeyMapItem *kmi;
  5329. char *instructions;
  5330. int inv = 0; int lx = -1, ly = -1;
  5331. if(e->Type==LA_MOUSEMOVE) return 0;
  5332. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5333. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5334. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5335. if (e->Localized){
  5336. lx = e->x;
  5337. ly = e->y;
  5338. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  5339. e->Localized = 0;
  5340. }
  5341. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5342. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  5343. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  5344. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  5345. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  5346. }elif (kmi->Operation){
  5347. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5348. }else{
  5349. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5350. }
  5351. inv = 1;
  5352. if (lx >= 0){
  5353. e->x = lx;
  5354. e->y = ly;
  5355. e->Localized = 1;
  5356. }
  5357. }
  5358. }
  5359. return inv;
  5360. }
  5361. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  5362. void la_DestroyOperatorType(laOperatorType* at){
  5363. //if(at->PC) la_FreePropertyContainer(at->PC);
  5364. memFree(at);
  5365. }
  5366. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  5367. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  5368. uint32_t IconID, int ExtraMark){
  5369. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  5370. at->Identifier = ID;
  5371. at->Name = Name;
  5372. at->Description = Description;
  5373. at->Check = Check;
  5374. at->Invoke = Invoke;
  5375. at->Init = Init;
  5376. at->Exit = Exit;
  5377. at->Modal = Modal;
  5378. at->IconID = IconID;
  5379. at->ExtraMark = ExtraMark;
  5380. at->ParseArgs = la_DefaultOperatorParser;
  5381. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  5382. return at;
  5383. }
  5384. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  5385. ot->PC = memAcquire(sizeof(laPropContainer));
  5386. ot->PC->Identifier = ot->Identifier;
  5387. ot->PC->Hyper = HyperLevel;
  5388. return ot->PC;
  5389. }
  5390. laOperator *la_CreateOperator(laOperatorType *at){
  5391. laOperator *a = CreateNew(laOperator);
  5392. a->Type = at;
  5393. if (at->PC && at->PC->Props.pFirst){
  5394. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  5395. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  5396. a->PP.LastPs->p->SubProp = at->PC;
  5397. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  5398. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  5399. a->PP.LastPs->Type = U'.';
  5400. }
  5401. return a;
  5402. }
  5403. int la_OperatorTypeByID(laOperatorType *a, char *id){
  5404. return (!strcmp(a->Identifier, id));
  5405. }
  5406. laOperatorType *laGetOperatorType(const char *ID){
  5407. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5408. }
  5409. int laOperatorExistsT(laOperatorType* at){
  5410. if (!at) return 0;
  5411. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  5412. return 0;
  5413. }
  5414. int laOperatorExists(const char* ID){
  5415. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  5416. return laOperatorExistsT(at);
  5417. }
  5418. int la_OperatorExists(laOperator *ac){
  5419. if (!ac) return 0;
  5420. laOperator *a;
  5421. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  5422. return 0;
  5423. }
  5424. int la_UiOperatorExists(void *inst){
  5425. laOperator *a;
  5426. if (!inst) return 0;
  5427. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  5428. if (((laUiItem *)a->Instance) == inst){
  5429. return 1;
  5430. }
  5431. }
  5432. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5433. if (a->Instance == inst){
  5434. return 1;
  5435. }
  5436. }
  5437. return 0;
  5438. }
  5439. int la_OperatorPending(laOperator *target){
  5440. laOperator *a;
  5441. if (!target) return 0;
  5442. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5443. if (a == target){
  5444. return 1;
  5445. }
  5446. }
  5447. return 0;
  5448. }
  5449. void laSetOperatorLocalizer(void *ToPanel){
  5450. MAIN.ToPanel = ToPanel;
  5451. }
  5452. void la_DestroyConfirmData(laConfirmData **cd);
  5453. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  5454. laOperator *ai = (*a);
  5455. laOperator *ac = ((*a)->Child);
  5456. void *Ret = 0;
  5457. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using){
  5458. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  5459. }
  5460. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  5461. if ((*a)->PP.LastPs){
  5462. memFree((*a)->PP.LastPs->p);
  5463. memFree((*a)->PP.LastPs);
  5464. }
  5465. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  5466. la_SetPropMathcerContext((*a)->OperatorPanel);
  5467. MAIN.CurrentPanel = (*a)->OperatorPanel;
  5468. laDestroySinglePanel((*a)->OperatorPanel,0);
  5469. }
  5470. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  5471. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  5472. lstClearPointer(&(*a)->LocalUiLists);
  5473. if (Operators){
  5474. Ret = ai->Item.pNext;
  5475. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  5476. else
  5477. lstRemoveItem(Operators, *a);
  5478. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  5479. if (ai->Child == (*a)) ai->Child = 0;
  5480. }
  5481. }
  5482. strSafeDestroy(&(*a)->RuntimeHint);
  5483. free(*a);
  5484. return Ret;
  5485. }
  5486. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  5487. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5488. if (!at) return 0;
  5489. if (!at->Check) return 1;
  5490. return (at->Check(This, Instructions));
  5491. }
  5492. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  5493. if (!at) return 0;
  5494. if (!at->Check) return 1;
  5495. return (at->Check(This, Instructions));
  5496. }
  5497. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5498. laPropPack FakePP = {0};
  5499. laPropStep FakePs = {0};
  5500. if (!at) return 0;
  5501. if (!at->Check) return 1;
  5502. FakePP.LastPs = &FakePs;
  5503. FakePP.Go = FakePP.LastPs;
  5504. FakePP.LastPs->p = This->LastPs->p;
  5505. FakePP.LastPs->UseInstance = This->EndInstance;
  5506. FakePP.EndInstance = Real_FromInstance;
  5507. FakePP.LastIndex = This->LastIndex;
  5508. return (at->Check(&FakePP, Instructions));
  5509. }
  5510. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5511. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5512. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  5513. }
  5514. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  5515. laOperator *a, *f = From;
  5516. int rev;
  5517. if (!f && e&&e->Localized) return -1;
  5518. a = la_CreateOperator(at);
  5519. a->ToPanel = MAIN.ToPanel;
  5520. a->This = This;
  5521. a->ExtraInstructions = args;
  5522. strMakeInstructions(&a->ExtraInstructionsP, args);
  5523. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5524. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5525. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  5526. la_DestroyOperator(&a, 0, 0);
  5527. return LA_CANCELED;
  5528. }
  5529. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5530. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  5531. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5532. e->Localized = 1;
  5533. }
  5534. if (e&&e->Localized){
  5535. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  5536. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5537. e->Localized = 0;
  5538. }else{
  5539. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5540. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5541. }
  5542. }
  5543. if (From) f->Child = a;
  5544. a->Using = 1;
  5545. if (at->Init) at->Init(a);
  5546. rev = at->Invoke(a, e);
  5547. a->Using = 0;
  5548. if (rev & LA_FINISH){
  5549. a->StopNow = 1; if(From)From->Child=0;
  5550. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5551. }
  5552. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5553. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5554. a->State = rev;
  5555. a->PP.EndInstance = a->CustomData;
  5556. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  5557. }else
  5558. la_DestroyOperator(&a, 0, 0);
  5559. return rev;
  5560. }
  5561. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  5562. laOperatorType *at; laOperator *a, *f = From;
  5563. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5564. if (!at) return -1;
  5565. return laInvokeP(From,at,e,This,args,args2);
  5566. }
  5567. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  5568. laOperator *a, *f = From;
  5569. int rev;
  5570. laPropPack *created;
  5571. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  5572. created = memAcquireSimple(sizeof(laPropPack));
  5573. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  5574. created->Go = created->LastPs;
  5575. created->LastPs->p = OrigionalThis->LastPs->p;
  5576. created->LastPs->UseInstance = FromInstance;
  5577. created->EndInstance = FromInstance;
  5578. created->LastIndex = OrigionalThis->LastIndex;
  5579. a = la_CreateOperator(at);
  5580. a->ToPanel = MAIN.ToPanel;
  5581. a->This = created;
  5582. a->CreatedThis = created;
  5583. a->ExtraInstructions = args;
  5584. strMakeInstructions(&a->ExtraInstructionsP, args);
  5585. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5586. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5587. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  5588. la_DestroyOperator(&a, 0, 0);
  5589. return LA_CANCELED;
  5590. }
  5591. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5592. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5593. if (From) f->Child = a;
  5594. a->Using = 1;
  5595. if (at->Init) at->Init(a);
  5596. rev = at->Invoke(a, e);
  5597. a->Using = 0;
  5598. if (rev & LA_FINISH){
  5599. a->StopNow = 1; if(From)From->Child=0;
  5600. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5601. }
  5602. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5603. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5604. a->State = rev;
  5605. a->PP.EndInstance = a->CustomData;
  5606. }else
  5607. la_DestroyOperator(&a, 0, 0);
  5608. return rev;
  5609. }
  5610. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5611. laOperator *a, *f = From;
  5612. int rev;
  5613. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  5614. a = la_CreateOperator(at);
  5615. a->Instance = inst;
  5616. a->ToPanel = MAIN.ToPanel;
  5617. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  5618. if (From) f->Child = a;
  5619. a->Using = 1;
  5620. if (at->Init) at->Init(a);
  5621. rev = at->Invoke(a, e);
  5622. a->Using = 0;
  5623. if (rev & LA_FINISH){
  5624. a->StopNow = 1; if(From)From->Child=0;
  5625. }
  5626. if (rev & LA_BLOCK){
  5627. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5628. a->State = rev;
  5629. }else la_DestroyOperator(&a, 0, 0);
  5630. DEB = a;
  5631. return rev;
  5632. }
  5633. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5634. laOperatorType *at;
  5635. laOperator *a, *f = From;
  5636. if (la_UiOperatorExists(inst)) return -1;
  5637. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  5638. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  5639. }
  5640. void laRequestDelayEvent(real Seconds){
  5641. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  5642. int la_UiStillInService(void *UiInstance){
  5643. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  5644. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  5645. if (ai->Instance == UiInstance) return 1;
  5646. }
  5647. return 0;
  5648. }
  5649. void la_StopUiOperatorService(void *UiInstance){
  5650. laOperator *ai, *dai, *NextAi;
  5651. if (!MAIN.CurrentWindow) return;
  5652. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5653. NextAi = ai->Item.pNext;
  5654. if (ai->Instance == UiInstance){
  5655. if (ai->Child){
  5656. la_StopUiOperatorService(ai->Child->Instance);
  5657. ai->Child = 0;
  5658. }
  5659. laOperator *dai = ai;
  5660. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  5661. continue;
  5662. }
  5663. }
  5664. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5665. NextAi = ai->Item.pNext;
  5666. if (ai->Instance == UiInstance){
  5667. if (ai->Instance == ai->ToPanel){
  5668. //laHidePanelWithDissoveEffect(ai->ToPanel);
  5669. //ai->ToPanel->LaterDestroy = 1;
  5670. }
  5671. if (ai->Child && la_OperatorExists(ai->Child)){
  5672. la_StopUiOperatorService(ai->Child->Instance);
  5673. //ai->Child = 0;
  5674. }
  5675. if (!ai->Using){
  5676. laOperator *dai = ai;
  5677. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5678. }else
  5679. ai->StopNow = 1;
  5680. }
  5681. }
  5682. }
  5683. void la_StopAllOperators(){
  5684. laOperator *ai, *dai, *NextAi;
  5685. if (!MAIN.CurrentWindow) return;
  5686. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5687. NextAi = ai->Item.pNext;
  5688. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  5689. continue;
  5690. }
  5691. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5692. NextAi = ai->Item.pNext;
  5693. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  5694. laHidePanelWithDissoveEffect(ai->ToPanel);
  5695. ai->ToPanel->LaterDestroy = 1;
  5696. }
  5697. if (!ai->Using){
  5698. laOperator *dai = ai;
  5699. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5700. }else ai->StopNow = 1;
  5701. }
  5702. }
  5703. void la_DestroyConfirmData(laConfirmData **cd){
  5704. if((!cd)||!(*cd)) return;
  5705. if ((*cd)->CustomData) (*cd)->Destroy((*cd)->CustomData);
  5706. if ((*cd)->StrData) free((*cd)->StrData);
  5707. FreeMem((*cd));
  5708. (*cd) = 0;
  5709. }
  5710. void laConfirmInt(laOperator *a, int Data, int mode){
  5711. laOperator *ai = a;
  5712. laConfirmData *cd = CreateNew(laConfirmData);
  5713. cd->IData = Data;
  5714. cd->Mode = mode;
  5715. ai->NextConfirmData = cd;
  5716. laRetriggerOperators();
  5717. }
  5718. void laConfirmFloat(laOperator *a, real Data, int mode){
  5719. laOperator *ai = a;
  5720. laConfirmData *cd = CreateNew(laConfirmData);
  5721. cd->FData = Data;
  5722. cd->Mode = mode;
  5723. ai->NextConfirmData = cd;
  5724. laRetriggerOperators();
  5725. }
  5726. void laConfirmString(laOperator *a, char *Str, int mode){
  5727. laOperator *ai = a;
  5728. laConfirmData *cd = CreateNew(laConfirmData);
  5729. int len = strlen(Str);
  5730. char *buf = calloc(len + 1, sizeof(char));
  5731. strcpy(buf, Str);
  5732. cd->StrData = buf;
  5733. cd->Mode = mode;
  5734. cd->Destroy = free;
  5735. ai->NextConfirmData = cd;
  5736. laRetriggerOperators();
  5737. }
  5738. int laConfirmSameDataIfAny(laOperator *a){
  5739. laOperator *ai = a;
  5740. laConfirmData *cd;
  5741. char *buf = 0;
  5742. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  5743. cd = CreateNew(laConfirmData);
  5744. if (ai->ConfirmData->StrData){
  5745. int len = strlen(ai->ConfirmData->StrData);
  5746. buf = calloc(len + 1, sizeof(char));
  5747. strcpy(buf, ai->ConfirmData->StrData);
  5748. }
  5749. //cd->CustomData = cd->CustomData;
  5750. cd->IData = ai->ConfirmData->IData;
  5751. cd->FData = ai->ConfirmData->FData;
  5752. cd->StrData = buf;
  5753. cd->Mode = ai->ConfirmData->Mode;
  5754. cd->Destroy = ai->ConfirmData->Destroy;
  5755. ai->NextConfirmData = cd;
  5756. laRetriggerOperators();
  5757. return 1;
  5758. }
  5759. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  5760. laOperator *ai = a;
  5761. laConfirmData *cd = CreateNew(laConfirmData);
  5762. cd->CustomData = UserData;
  5763. cd->Mode = mode;
  5764. cd->Destroy = Destroy;
  5765. ai->NextConfirmData = cd;
  5766. laRetriggerOperators();
  5767. }
  5768. int laGetConfirmMode(laOperator *a){
  5769. return ((laOperator *)a)->ConfirmData->Mode;
  5770. }
  5771. int laGetConfirmInt(laOperator *a){
  5772. laOperator *ai = a;
  5773. int rev = ai->ConfirmData->IData;
  5774. la_DestroyConfirmData(&ai->ConfirmData);
  5775. ai->ConfirmData = 0;
  5776. return rev;
  5777. }
  5778. real laGetConfirmFloat(laOperator *a){
  5779. laOperator *ai = a;
  5780. real rev = ai->ConfirmData->FData;
  5781. la_DestroyConfirmData(&ai->ConfirmData);
  5782. ai->ConfirmData = 0;
  5783. return rev;
  5784. }
  5785. void laGetConfirmString(laOperator *a, char *buf){
  5786. laOperator *ai = a;
  5787. strcpy(buf, ai->ConfirmData->StrData);
  5788. la_DestroyConfirmData(&ai->ConfirmData);
  5789. ai->ConfirmData = 0;
  5790. }
  5791. void *laGetConfirmUserData(laOperator *a){
  5792. laOperator *ai = a;
  5793. return ai->ConfirmData->CustomData;
  5794. }
  5795. void laFinalizeOperators(){
  5796. laOperatorType *at;
  5797. laListHandle *lst;
  5798. int i;
  5799. for (i = 0; i < 256; i++){
  5800. lst = &MAIN.OperatorTypeHash.Entries[i];
  5801. for (at = lst->pFirst; at; at = at->Item.pNext){
  5802. if (at->PC && at->PC->Props.pFirst){
  5803. lstAppendItem(&MAIN.PropContainers, at->PC);
  5804. }
  5805. }
  5806. }
  5807. }
  5808. //=================
  5809. #ifdef __linux__
  5810. static void la_RecordWacomMotions(XIRawEvent *event)
  5811. {
  5812. double *valuator = event->valuators.values;
  5813. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  5814. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  5815. //SYSWINDOW root_return, child_return;
  5816. //int root_x_return, root_y_return;
  5817. //int win_x_return, win_y_return;
  5818. //unsigned int mask_return;
  5819. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  5820. // &root_x_return, &root_y_return,
  5821. // &win_x_return, &win_y_return,
  5822. // &mask_return);
  5823. //
  5824. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  5825. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  5826. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  5827. real x=valuator[3],y=valuator[4];
  5828. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  5829. //printf("%f %f\n",orientation,deviation);
  5830. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  5831. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  5832. }
  5833. MAIN.IsPen=1;
  5834. }
  5835. #endif
  5836. #ifdef _WIN32
  5837. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  5838. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  5839. static uint32_t ch = 0; static int lead = 0;
  5840. static wchar_t buf[10] = { 0 }; int adv;
  5841. char mbuf[10] = { 0 }; uint32_t uchar=0;
  5842. short wheelmark = 0;
  5843. int WheelDir = 0;
  5844. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  5845. POINTER_PEN_INFO penInfo; POINTER_TOUCH_INFO touchInfo;
  5846. POINT point;
  5847. PACKET pkt;
  5848. static POINT ptOld, ptNew;
  5849. static UINT prsOld, prsNew;
  5850. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  5851. switch (message) {
  5852. case WM_PAINT:
  5853. //SwapBuffers(GetDC(hwnd));
  5854. break;
  5855. case WM_MOUSEMOVE:
  5856. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  5857. MAIN.IsPen = 0;
  5858. break;
  5859. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  5860. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  5861. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  5862. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  5863. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  5864. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  5865. case WM_MOUSEWHEEL:
  5866. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  5867. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  5868. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, PARAM_2_FROM(lparam));
  5869. break;
  5870. case WT_PACKET:
  5871. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  5872. if (gpWTPacket((HCTX)lparam, wparam, &pkt)){
  5873. MAIN.StylusPressure = (real)pkt.pkNormalPressure/MAIN.WinTabMaxPenPressure;
  5874. real angle = (real)pkt.pkOrientation.orAzimuth / 3600*TNS_PI*2+TNS_PI/2;
  5875. MAIN.StylusOrientation = angle; MAIN.StylusDeviation=rad((90.0f-(real)pkt.pkOrientation.orAltitude/10.0f));
  5876. //printf("%f %f\n",angle,MAIN.StylusDeviation);
  5877. MAIN.IsPen = 1; MAIN.PointerIsEraser=((pkt.pkStatus & TPS_INVERT)==TPS_INVERT);
  5878. }
  5879. break;
  5880. case WM_SYSCOMMAND:
  5881. switch (wparam) {
  5882. case SC_MAXIMIZE:
  5883. case SC_RESTORE:
  5884. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  5885. break;
  5886. case SC_KEYMENU:
  5887. return 0;
  5888. }
  5889. break;
  5890. case WM_SIZE:
  5891. if (wparam == SIZE_MINIMIZED) break;
  5892. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  5893. break;
  5894. case WM_POINTERUPDATE:
  5895. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  5896. pointerId = GET_POINTERID_WPARAM(wparam);
  5897. pointerType = PT_POINTER;
  5898. if(!GetPointerType(pointerId, &pointerType)){
  5899. pointerType = PT_POINTER;
  5900. printf("is pointer\n");
  5901. }
  5902. if(pointerType == PT_PEN){
  5903. if(GetPointerPenInfo(pointerId, &penInfo)){
  5904. point.x = penInfo.pointerInfo.ptPixelLocation.x; point.y = penInfo.pointerInfo.ptPixelLocation.y;
  5905. ScreenToClient(hwnd, &point);
  5906. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo.pressure / 1024; MAIN.PointerIsEraser = 0;
  5907. }
  5908. }
  5909. else if (pointerType == PT_TOUCH){
  5910. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  5911. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  5912. ScreenToClient(hwnd, &point);
  5913. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  5914. }
  5915. }
  5916. break;
  5917. //case WM_SYSKEYDOWN:
  5918. // if (lparam & 0x40000000) break;
  5919. // if (la_SendSpecialKey(hwnd, LA_STATE_DOWN, wparam))
  5920. // break;
  5921. case WM_KEYDOWN:
  5922. if (lparam & 0x40000000) break;
  5923. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  5924. break;
  5925. case WM_KEYUP:
  5926. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  5927. break;
  5928. //case WM_SYSKEYUP:
  5929. // if (la_SendSpecialKey(hwnd, LA_STATE_UP, wparam));
  5930. // break;
  5931. case WM_UNICHAR:
  5932. la_SendInputEvent(hwnd, wparam);
  5933. break;
  5934. case WM_IME_CHAR:
  5935. la_SendInputEvent(hwnd, wparam);
  5936. return 0;
  5937. case WM_CHAR:
  5938. la_SendInputEvent(hwnd, wparam);
  5939. break;
  5940. case WM_SHOWWINDOW:
  5941. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  5942. break;
  5943. case WM_CLOSE:
  5944. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  5945. break;
  5946. default:
  5947. return DefWindowProc(hwnd, message, wparam, lparam);
  5948. }
  5949. return DefWindowProc(hwnd, message, wparam, lparam);
  5950. }
  5951. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  5952. return DefWindowProc(hwnd, message, wparam, lparam);
  5953. }
  5954. #endif
  5955. int la_UpdateOperatorHints(laWindow* w){
  5956. laSafeString* ss=0;
  5957. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  5958. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  5959. }
  5960. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  5961. }else{
  5962. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  5963. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  5964. }
  5965. strSafeDestroy(&ss);
  5966. }
  5967. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  5968. laOperator *a, *NextA = 0;
  5969. int Result = 0;
  5970. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  5971. a = Operators->pFirst;
  5972. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  5973. while (1){
  5974. if (!a) break;
  5975. if (a->StopNow){
  5976. NextA = a->Item.pNext;
  5977. if (a->Type->Exit) a->Type->Exit(a, Result);
  5978. ConfirmData = a->NextConfirmData;
  5979. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  5980. NextConfirmData = ConfirmData;
  5981. a->ConfirmData = 0;
  5982. a->NextConfirmData = 0;
  5983. la_DestroyOperator(&a, Operators, 0);
  5984. a = NextA;
  5985. if (a){
  5986. a->ConfirmData = NextConfirmData;
  5987. }
  5988. continue;
  5989. }
  5990. a->Using = 1;
  5991. la_SetPropMathcerContext(a->ToPanel);
  5992. laSetOperatorLocalizer(a->ToPanel);
  5993. MAIN.CurrentPanel = a->ToPanel;
  5994. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  5995. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5996. e->Localized = 1;
  5997. }
  5998. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  5999. //la_PrintOperatorStack();
  6000. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6001. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6002. e->Localized = 0;
  6003. }
  6004. la_SetPropMathcerContext(0);
  6005. laSetOperatorLocalizer(0);
  6006. MAIN.CurrentPanel = 0;
  6007. a->Using = 0;
  6008. if (Result & LA_PASS_ON){
  6009. laConfirmSameDataIfAny(a);
  6010. NextA = a->Item.pNext;
  6011. }else{
  6012. NextA = 0;
  6013. if (a->NextConfirmData){
  6014. la_DestroyConfirmData(&a->NextConfirmData);
  6015. }
  6016. }
  6017. ConfirmData = a->NextConfirmData;
  6018. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6019. NextConfirmData = ConfirmData;
  6020. a->ConfirmData = 0;
  6021. a->NextConfirmData = 0;
  6022. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6023. if (a->Type->Exit) a->Type->Exit(a, Result);
  6024. la_DestroyOperator(&a, Operators, 0);
  6025. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6026. }
  6027. a = NextA;
  6028. if (a){
  6029. a->ConfirmData = NextConfirmData;
  6030. }
  6031. }
  6032. return 1;
  6033. }
  6034. int la_HandleEvents(laWindow *w){
  6035. laEvent *e, *NextE;
  6036. laOperator *a;
  6037. laThreadNotifier *tn;
  6038. MAIN.CurrentWindow=w;
  6039. //pthread_spin_lock(&MAIN.csNotifier);
  6040. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6041. //pthread_spin_unlock(&MAIN.csNotifier);
  6042. laNotifyUsers(tn->Path);
  6043. FreeMem(tn);
  6044. //if (MAIN.ThreadNotifiers.pFirst)
  6045. //pthread_spin_lock(&MAIN.csNotifier);
  6046. }
  6047. //pthread_spin_unlock(&MAIN.csNotifier);
  6048. while (1){
  6049. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6050. while (w->EventList.pFirst){
  6051. while (w->PendingOperators.pLast){
  6052. a = w->PendingOperators.pLast;
  6053. if (a->OperatorPanel){
  6054. laSetOperatorLocalizer(a->OperatorPanel);
  6055. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6056. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6057. }
  6058. lstRemoveItem(&w->PendingOperators, a);
  6059. lstPushItem(&w->Operators, a);
  6060. }
  6061. e = lstPopItem(&w->EventList);
  6062. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6063. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6064. memFree(e);
  6065. }
  6066. if (!MAIN.ReTriggerOperators) break;
  6067. }
  6068. la_UpdateOperatorHints(w);
  6069. return 1;
  6070. }
  6071. int la_AllowInput(uint32_t ch){
  6072. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6073. return 0;
  6074. }
  6075. int laCopyToClipboard(unsigned char * text){
  6076. #ifdef __linux__
  6077. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6078. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6079. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6080. strSafeSet(&MAIN.CopyPending, text);
  6081. #endif
  6082. }
  6083. int la_ProcessSysMessage(){
  6084. int SendDelay = 0, SendIdle = 0;
  6085. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6086. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6087. #ifdef __linux__
  6088. XEvent e;
  6089. int type;
  6090. int InputCount = 0, CharCount=0;
  6091. KeySym InputKeysym = 0;
  6092. Status InputStatus = 0;
  6093. laWindow* wnd ;
  6094. while(XPending(MAIN.dpy)){
  6095. XGenericEventCookie *cookie = &e.xcookie;
  6096. XNextEvent(MAIN.dpy, &e);
  6097. if (XFilterEvent(&e, None)) continue;
  6098. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6099. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6100. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6101. XFreeEventData(MAIN.dpy, cookie); continue;
  6102. }
  6103. switch(e.type){
  6104. case ConfigureNotify:
  6105. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6106. break;
  6107. case Expose:
  6108. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6109. if(!wnd) break;
  6110. laRefreshWindow(wnd);
  6111. break;
  6112. case MotionNotify:
  6113. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6114. MAIN.IsPen=0;
  6115. break;
  6116. case ButtonPress:
  6117. type=LA_MOUSEDOWN;
  6118. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6119. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6120. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6121. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  6122. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  6123. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6124. MAIN.IsPen=0;
  6125. break;
  6126. case ButtonRelease:
  6127. type=LA_MOUSEUP;
  6128. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6129. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6130. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6131. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6132. MAIN.IsPen=0;
  6133. break;
  6134. case KeyPress:
  6135. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  6136. MAIN.InputBuf[InputCount]=0;
  6137. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  6138. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  6139. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  6140. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6141. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6142. #ifdef DEBUG
  6143. printf("pressed KEY: %d\n", (int)InputKeysym);
  6144. #endif
  6145. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  6146. }
  6147. break;
  6148. case KeyRelease:
  6149. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6150. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  6151. }
  6152. case ClientMessage:
  6153. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  6154. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  6155. }
  6156. break;
  6157. case SelectionNotify:
  6158. if(e.xselection.selection != MAIN.bufid) continue;
  6159. if (e.xselection.property){
  6160. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  6161. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  6162. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  6163. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  6164. else if(result) {
  6165. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  6166. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  6167. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6168. }
  6169. XFree(result);
  6170. return True;
  6171. }
  6172. case SelectionRequest:
  6173. if(!MAIN.CopyPending){ break; }
  6174. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  6175. if (e.xselectionrequest.selection != MAIN.selection) break;
  6176. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  6177. XSelectionEvent ev = {0};
  6178. int R = 0;
  6179. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  6180. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  6181. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  6182. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  6183. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  6184. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  6185. else if (ev.target == MAIN.UTF8)
  6186. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  6187. else ev.property = None;
  6188. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  6189. break;
  6190. case SelectionClear:
  6191. break;
  6192. default:
  6193. break;
  6194. }
  6195. }
  6196. #endif //linux
  6197. #ifdef _WIN32
  6198. MSG msg; int Processed = 0;
  6199. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  6200. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  6201. TranslateMessage(&msg); DispatchMessage(&msg);
  6202. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  6203. };
  6204. #endif
  6205. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6206. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  6207. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  6208. }
  6209. return 1;
  6210. };
  6211. void la_PrintOperatorStack(){
  6212. laWindow *w = MAIN.CurrentWindow;
  6213. laOperator *a;
  6214. printf("\n");
  6215. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  6216. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  6217. a->Type->Identifier, a->Instance,
  6218. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  6219. }
  6220. }
  6221. void la_DrawWindow(laWindow *w){
  6222. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  6223. MAIN.CurrentWindow = w;
  6224. la_WindowDefDraw(w, 0);
  6225. }
  6226. int laFinalize(){
  6227. if(!laValidateProperties()){ laShutoff(0); return 0; }
  6228. laUiTemplate* uit;
  6229. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  6230. return 1;
  6231. }
  6232. void laMainLoop(){
  6233. laWindow *w = MAIN.Windows.pFirst, *NextW;
  6234. laTimeRecorder FrameStartTime, FrameEndTime;
  6235. time_t t1, t2;
  6236. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  6237. static int a = 0;
  6238. if(!laFinalize()) return;
  6239. MAIN.DelayTriggered=1;
  6240. while (1){
  6241. laRecordTime(&FrameStartTime);
  6242. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  6243. if(!la_ProcessSysMessage()){ return; }
  6244. la_UpdateControllerStatus();
  6245. if(MAIN.InputMapping->NeedRebuild){ la_RebuildInputMapping(); }
  6246. if(MAIN.InputMapping->NeedEval){ la_RunInputMapping(); }
  6247. if(MAIN.Drivers->NeedRebuild){ la_RebuildDriverEval(); }
  6248. if(MAIN.Drivers->NeedEval){ la_RunDrivers(); }
  6249. for (w=MAIN.Windows.pFirst;w;w = NextW){
  6250. NextW = w->Item.pNext;
  6251. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  6252. }
  6253. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  6254. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6255. tnsSwitchToCurrentWindowContext(w);
  6256. la_DrawWindow(w);
  6257. }
  6258. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6259. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  6260. #ifdef __linux__
  6261. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  6262. #endif
  6263. #ifdef _WIN32
  6264. SwapBuffers(w->hdc);
  6265. #endif
  6266. }
  6267. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  6268. //t2 = clock();
  6269. laRecordTime(&FrameEndTime);
  6270. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  6271. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  6272. if (Pause > 0){
  6273. int us = Pause * 1000000.0;
  6274. usleep(us);
  6275. }
  6276. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  6277. FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  6278. }
  6279. }