*/}}

la_kernel.c 315 KB

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