*/}}

la_kernel.c 291 KB

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