*/}}
1
0

la_kernel.c 284 KB

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