*/}}

la_kernel.c 353 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  19. #define NANOVG_GLES3_IMPLEMENTATION
  20. #else
  21. #define NANOVG_GL3_IMPLEMENTATION
  22. #endif
  23. #include "la_5.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <time.h>
  28. #ifdef LA_LINUX
  29. #include <execinfo.h>
  30. #include <signal.h>
  31. #include <sys/time.h>
  32. #include <X11/Xlib.h>
  33. #include <X11/Xutil.h>
  34. #include <X11/Xos.h>
  35. #include <X11/keysymdef.h>
  36. #include <X11/XKBlib.h>
  37. #include <X11/extensions/XInput.h>
  38. #include <X11/extensions/XInput2.h>
  39. #include <X11/extensions/Xfixes.h>
  40. #include <X11/extensions/Xrandr.h>
  41. #include <X11/Xcursor/Xcursor.h>
  42. #include <X11/cursorfont.h>
  43. #include <GL/glx.h>
  44. #endif
  45. #ifdef _WIN32
  46. #include <GL/wglew.h>
  47. #include <GL/wgl.h>
  48. #include <shellscalingapi.h>
  49. #endif
  50. #ifdef LAGUI_ANDROID
  51. #include <GLES3/gl32.h>
  52. #include <jni.h>
  53. #include <android/log.h>
  54. #include <android/native_activity.h>
  55. #include <android/native_window.h>
  56. #include <android/native_window_jni.h>
  57. #include <android_native_app_glue.h>
  58. #include <android/window.h>
  59. #include <android/asset_manager.h>
  60. #include <android/input.h>
  61. #include <android/keycodes.h>
  62. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  63. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  64. static int android_read(void *cookie, char *buf, int size);
  65. static int android_write(void *cookie, const char *buf, int size);
  66. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  67. static int android_close(void *cookie);
  68. void la_InitAndroidPlatform(struct android_app *app);
  69. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  70. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  71. void la_InitAndroidPlatform(struct android_app *app);
  72. #endif
  73. LA MAIN={0};
  74. extern tnsMain *T;
  75. int deb = 0;
  76. laOperator *DEB;
  77. laColumn *DEBUG_C;
  78. #ifdef _WIN32
  79. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  80. #else
  81. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  82. #endif
  83. #ifdef LA_LINUX
  84. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  85. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  86. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  87. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  88. #endif
  89. #ifdef LA_LINUX
  90. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  91. int i;
  92. for (i = 0; i < num_classes; i++) {
  93. if (classes[i]->type == XIValuatorClass) {
  94. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  95. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  96. logPrint(" Range: %f - %f\n", v->min, v->max);
  97. logPrint(" Resolution: %d units/m\n", v->resolution);
  98. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  99. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  100. }
  101. }
  102. }
  103. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  104. XIDeviceInfo *info, *dev;
  105. int i, ndevices;
  106. dev = XIQueryDevice(display, deviceid, &ndevices);
  107. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  108. mask->deviceid = deviceid;
  109. mask->mask_len = XIMaskLen(XI_RawMotion);
  110. mask->mask=memAcquireSimple(mask->mask_len);
  111. memset(mask->mask, 0, mask->mask_len);
  112. XISetMask(mask->mask, XI_RawMotion);
  113. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  114. int FoundMax=0;
  115. for (i = 0; i < dev->num_classes; i++) {
  116. if (dev->classes[i]->type == XIValuatorClass) {
  117. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  118. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  119. }
  120. }
  121. if(!FoundMax){*max_pressure=65535;}
  122. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  123. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  124. XIFreeDeviceInfo(dev);
  125. }
  126. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  127. int axis=0;
  128. for (int i = 0; i < dev->num_classes; i++) {
  129. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  130. }
  131. return axis>=3;
  132. }
  133. #define LA_G_STYLUS(dev) \
  134. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  135. #define LA_G_ERASER \
  136. (!MAIN.WacomDeviceEraser)
  137. void la_ScanWacomDevices(Display *display, int deviceid){
  138. XIDeviceInfo *info, *dev;
  139. int ndevices;
  140. int i; char * word;
  141. int _event, _error;
  142. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  143. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  144. }
  145. info = XIQueryDevice(display, deviceid, &ndevices);
  146. for(i = 0; i < ndevices; i++) {
  147. dev = &info[i]; strToLower(dev->name);
  148. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  149. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  150. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  151. word = strtok (dev->name," ");
  152. while (1) {
  153. word = strtok (NULL, " "); if (!word) break;
  154. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  155. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  156. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  157. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  158. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  159. }
  160. }
  161. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  162. logPrintNew("Found wacom devices:\n");
  163. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  164. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  165. }else{
  166. logPrintNew("No wacom pen device connected.\n");
  167. }
  168. XIFreeDeviceInfo(info);
  169. }
  170. void laHideCursor(){
  171. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  172. }
  173. void laShowCursor(){
  174. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  175. }
  176. int la_XErrorHandler(Display *display, XErrorEvent *event){
  177. char buf[512];
  178. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  179. printf("X Error:\n%s\n",buf);
  180. return 0;
  181. }
  182. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  183. XSetWindowAttributes swa;
  184. XWindowAttributes wa;
  185. swa.event_mask =
  186. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  187. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  188. swa.colormap = MAIN.cmap;
  189. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  190. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  191. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  192. if(x>0||y>0){
  193. XSizeHints my_hints = {0};
  194. my_hints.flags = PPosition;
  195. my_hints.x = x; my_hints.y = y;
  196. XSetNormalHints(MAIN.dpy, win, &my_hints);
  197. }
  198. XStoreName(MAIN.dpy, win, title);
  199. #ifdef LA_USE_GLES
  200. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  201. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  202. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  203. EGLSurface* surf=egl_surf;
  204. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  205. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  206. tnsContextMakeCurrent((*r_glc),win,(*surf));
  207. #else
  208. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  209. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  210. printf("\n\tcannot create gl context\n\n"); exit(0);
  211. }
  212. tnsContextMakeCurrent((*r_glc),win,0);
  213. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  214. #endif
  215. XSetLocaleModifiers("");
  216. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  217. if(!MAIN.im){
  218. XSetLocaleModifiers("@im=local");
  219. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  220. }
  221. if(!MAIN.im){
  222. XSetLocaleModifiers("@im=none");
  223. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  224. }
  225. if(!MAIN.im){
  226. XSetLocaleModifiers("@im=");
  227. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  228. }
  229. if(!MAIN.im){
  230. logPrint("Can't open a input method.\n");
  231. }
  232. if(MAIN.im){
  233. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  234. XSetICFocus(MAIN.ic);
  235. }
  236. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  237. XSetClassHint(MAIN.dpy, win, &ch);
  238. #define _NET_WM_STATE_ADD 1
  239. if(w<0&&h<0){
  240. XEvent xev;
  241. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  242. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  243. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  244. memset(&xev, 0, sizeof(xev));
  245. xev.type = ClientMessage;
  246. xev.xclient.window = win;
  247. xev.xclient.message_type = wm_state;
  248. xev.xclient.format = 32;
  249. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  250. xev.xclient.data.l[1] = max_horz;
  251. xev.xclient.data.l[2] = max_vert;
  252. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  253. }
  254. return win;
  255. };
  256. void la_DestroySystemWindowX11(laWindow* w) {
  257. tnsContextMakeCurrent(0,0,0);
  258. tnsDeleteContext(w->glc);
  259. #ifdef LA_USE_GLES
  260. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  261. #endif
  262. XDestroyWindow(MAIN.dpy, w->win);
  263. };
  264. #endif //linux
  265. #ifdef _WIN32
  266. #include <msgdef.h>
  267. #include <wintab.h>
  268. #include <wintab_utils.h>
  269. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  270. #define PACKETMODE PK_BUTTONS
  271. #include <pktdef.h>
  272. void la_OpenWacomWinTab(HWND hwnd){
  273. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  274. static LOGCONTEXT glogContext = { 0 };
  275. HCTX hctx = NULL;
  276. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  277. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  278. glogContext.lcOptions |= CXO_SYSTEM;
  279. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  280. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  281. assert(glogContext.lcOptions & CXO_SYSTEM);
  282. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  283. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  284. glogContext.lcPktData = PACKETDATA;
  285. glogContext.lcPktMode = PACKETMODE;
  286. glogContext.lcMoveMask = PACKETDATA;
  287. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  288. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  289. assert(wWTInfoRetVal == sizeof(AXIS));
  290. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  291. assert(wWTInfoRetVal == sizeof(AXIS));
  292. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  293. if (wWTInfoRetVal) {
  294. assert(wWTInfoRetVal == sizeof(AXIS));
  295. MAIN.WinTabMaxHover = TabletZ.axMax;
  296. }
  297. AXIS tabletPressure = { 0 };
  298. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  299. //glogContext.lcInOrgX = 0;
  300. //glogContext.lcInOrgY = 0;
  301. //glogContext.lcInExtX = TabletX.axMax;
  302. //glogContext.lcInExtY = TabletY.axMax;
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  312. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  313. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  314. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  315. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  316. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  317. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  318. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  319. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  320. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  321. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  322. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  323. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  324. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  325. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  326. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  327. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  328. if (!hctx)return;
  329. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  330. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  331. }
  332. void laHideCursor() {
  333. if (!MAIN.CurrentWindow) return; //impl
  334. }
  335. void laShowCursor() {
  336. if (!MAIN.CurrentWindow) return; //impl
  337. }
  338. static PIXELFORMATDESCRIPTOR cpfd = {
  339. sizeof(PIXELFORMATDESCRIPTOR),1,
  340. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  341. PFD_TYPE_RGBA,
  342. 8,
  343. 0, 0, 0, 0, 0, 0,
  344. 0, 0, 0,
  345. 0, 0, 0, 0,
  346. 32,
  347. 8, 0,
  348. 0,
  349. 0, 0, 0, 0
  350. };
  351. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  352. int nBestMS = 0;
  353. int i;
  354. int iResults[9];
  355. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  356. WGL_ACCELERATION_ARB, // 1
  357. WGL_DRAW_TO_WINDOW_ARB, // 2
  358. WGL_DOUBLE_BUFFER_ARB, // 3
  359. WGL_PIXEL_TYPE_ARB, // 4
  360. WGL_DEPTH_BITS_ARB, // 5
  361. WGL_STENCIL_BITS_ARB, // 6
  362. WGL_SAMPLE_BUFFERS_ARB, // 7
  363. WGL_SAMPLES_ARB }; // 8
  364. // How many pixelformats are there?
  365. int nFormatCount[] = { 0 };
  366. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  367. if (!wglGetPixelFormatAttribivARB)
  368. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  369. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  370. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  371. for (i = 0; i < nFormatCount[0]; i++){
  372. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  373. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  374. if (iResults[3] == 1) // Double buffered
  375. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  376. if (iResults[5] >= 24) // Any Depth greater than 16
  377. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  378. }
  379. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  380. };
  381. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  382. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  383. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  384. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  385. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  386. 0 };
  387. HGLRC hglrc = 0;
  388. HDC hdc = 0;
  389. int a, b;
  390. hdc = GetDC(hwnd);
  391. la_SetupPxlFormat(hdc, &a, &b);
  392. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  393. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n");
  394. tnsContextMakeCurrent(hglrc, hdc,0);
  395. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  396. wglSwapIntervalEXT(-1);
  397. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  398. };
  399. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  400. HINSTANCE* inst = &MAIN.hinstance;
  401. HWND hwnd = CreateWindow(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  402. x, y, w, h, 0, 0, *inst, 0);
  403. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  404. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  405. return hwnd;
  406. };
  407. void la_DestroySystemWindowWin32(laWindow* w) {
  408. tnsContextMakeCurrent(0,0,0);
  409. tnsDeleteContext(w->glc);
  410. ReleaseDC(w->win, w->hdc);
  411. DestroyWindow(w->win);
  412. };
  413. #endif
  414. #ifdef LAGUI_ANDROID
  415. SYSWINDOW la_CreateWindowAndroid(){
  416. return 0;
  417. };
  418. void laShowCursor(){}
  419. void laHideCursor(){}
  420. #endif
  421. #ifdef LA_LINUX
  422. void la_HandlerSIGSEGV(int sig) {
  423. void *array[30];
  424. size_t sz;
  425. sz = backtrace(array, 30);
  426. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  427. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  428. exit(1);
  429. }
  430. #endif
  431. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  432. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  433. //#ifndef LAGUI_ANDROID
  434. // ignore non-significant error/warning codes
  435. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  436. logPrint("GL %d: %s\n", id, message);
  437. char* strsource="",*strtype="",*strseverity="";
  438. switch (source) {
  439. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  440. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  441. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  442. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  443. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  444. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  445. }
  446. switch (type) {
  447. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  448. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  449. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  450. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  451. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  452. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  453. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  454. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  455. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  456. }
  457. switch (severity) {
  458. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  459. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  460. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  461. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  462. }
  463. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  464. //#endif
  465. }
  466. static void la_SetCurrentGLContextDebug(){
  467. //#ifndef LAGUI_ANDROID
  468. int force=MAIN.InitArgs.GLDebug;
  469. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  470. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  471. glDebugMessageCallback(la_glDebugOutput, 0);
  472. int sev=GL_DONT_CARE;
  473. if(!force){
  474. switch(MAIN.GLDebugLevel){
  475. default: sev=GL_DONT_CARE; break;
  476. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  477. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  478. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  479. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  480. }
  481. }
  482. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  483. //#endif
  484. }
  485. void la_NotifyGLDebugChanges(){
  486. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  487. }
  488. void la_SetupWindowGLStates(laWindow* w){
  489. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  490. if(w->GLDebugNeedsUpdate){
  491. tnsContextMakeWindowCurrent(w);
  492. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  493. }
  494. }
  495. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  496. SYSGLCONTEXT glc;
  497. #ifdef LA_LINUX
  498. void* egl_surf=0;
  499. #ifdef LA_USE_GLES
  500. egl_surf=&window->egl_surf;
  501. #endif
  502. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  503. #endif
  504. #ifdef _WIN32
  505. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  506. #endif
  507. #ifdef LAGUI_ANDROID
  508. la_CreateWindowAndroid();
  509. window->win = 1;
  510. window->glc = MAIN.glc;
  511. #else
  512. window->win = hwnd;
  513. window->glc = glc;
  514. #endif
  515. #ifdef _WIN32
  516. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  517. RECT rc; GetClientRect(window->win, &rc);
  518. window->CW = rc.right - rc.left;
  519. window->CH = rc.bottom - rc.top;
  520. window->himc = ImmCreateContext();
  521. #endif
  522. #ifdef LA_LINUX
  523. XWindowAttributes attr;
  524. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  525. window->CW =attr.width;
  526. window->CH = attr.height;
  527. #endif
  528. la_SetCurrentGLContextDebug();
  529. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  530. la_SetupWindowGLStates(window);
  531. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  532. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  533. #else
  534. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  535. #endif
  536. window->OutputShowStripes=0; window->Redraw=1;
  537. window->GLDebugNeedsUpdate=1;
  538. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  539. return 1;
  540. };
  541. void la_DestroySystemWindow(laWindow* wnd){
  542. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  543. nvgDeleteGLES3(wnd->nvg);
  544. #else
  545. nvgDeleteGL3(wnd->nvg);
  546. #endif
  547. #ifdef LA_LINUX
  548. la_DestroySystemWindowX11(wnd);
  549. #endif
  550. #ifdef _WIN32
  551. la_DestroySystemWindowWin32(wnd);
  552. #endif
  553. }
  554. void la_DestroyWindow(laWindow *wnd){
  555. laLayout *l; laPanel *p; if (!wnd) return;
  556. tnsSwitchToCurrentWindowContext(wnd);
  557. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  558. la_StopAllOperators();
  559. strSafeDestroy(&wnd->Title);
  560. //la_PrintUserList(wnd);
  561. //printf("----\n");
  562. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  563. while (l = lstPopItem(&wnd->Layouts)){
  564. laDestroyBlocksRecursive(l->FirstBlock);
  565. //la_PrintUserList(l);
  566. //printf("%x %s\n", l, l->ID->Ptr);
  567. strSafeDestroy(&l->ID);
  568. memFree(l);
  569. //la_PrintUserList(wnd);
  570. //printf("----\n");
  571. }
  572. //printf("----\n%x\n",wnd);
  573. //la_PrintUserList(wnd);
  574. la_DestroySystemWindow(wnd);
  575. lstRemoveItem(&MAIN.Windows, wnd);
  576. memFree(wnd);
  577. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  578. }
  579. void laRenameWindow(laWindow* wnd, char* name){
  580. if((!wnd)||MAIN.IsReadingUDF) return;
  581. strSafeSet(&wnd->Title, name);
  582. if(!wnd->win) return;
  583. #ifdef LA_LINUX
  584. XStoreName(MAIN.dpy, wnd->win, name);
  585. #endif
  586. #ifdef _WIN32
  587. int wlen=strlen(name)+1;
  588. int unisize=MultiByteToWideChar(CP_UTF8, 0, name, -1, 0, 0);
  589. WCHAR *unistr=malloc(wlen*sizeof(WCHAR));
  590. MultiByteToWideChar(CP_UTF8, 0, name, -1, unistr, unisize);
  591. int bufsize=WideCharToMultiByte(CP_ACP, 0, unistr, -1, 0, 0, 0, 0);
  592. char* acpstr = malloc(bufsize);
  593. WideCharToMultiByte(CP_ACP, 0, unistr, -1, acpstr, bufsize, 0, 0);
  594. SetWindowText(wnd->win, acpstr);
  595. free(unistr); free(acpstr);
  596. #endif
  597. }
  598. #ifdef LA_LINUX
  599. const char* la_ConvertCursorID(int id){
  600. switch (id) {
  601. case LA_ARROW: return "arrow";
  602. case LA_CROSS: return "cross";
  603. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  604. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  605. case LA_MOVE: return "diamond_cross";
  606. case LA_HAND: return "hand1";
  607. case LA_CORNER: return "bottom_right_corner";
  608. }
  609. return "arrow";
  610. }
  611. #endif
  612. #ifdef _WIN32
  613. HCURSOR la_ConvertCursorID(int id){
  614. switch (id){
  615. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  616. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  617. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  618. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  619. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  620. case LA_HAND: return LoadCursor(0, IDC_HAND);
  621. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  622. }
  623. return LoadCursor(0, IDC_ARROW);;
  624. }
  625. #endif
  626. void la_InitThreadEnviornment(){
  627. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  628. }
  629. laLogEntry* logEnsure(int Create){
  630. if(!MAIN.Logs.pFirst || Create){
  631. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  632. lstAppendItem(&MAIN.Logs, le);
  633. }
  634. return MAIN.Logs.pLast;
  635. }
  636. void logPrintTV(int Continued, char* format, va_list v){
  637. if(!format || !format[0]) return;
  638. laLogEntry* le=logEnsure(Continued);
  639. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  640. strSafePrintV(&le->Content, format, v);
  641. #ifdef LAGUI_ANDROID
  642. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  643. #endif
  644. laNotifyUsers("la.logs");
  645. }
  646. void logPrintT(int Continued, char* format, ...){
  647. if(!format || !format[0]) return;
  648. laLogEntry* le=logEnsure(Continued);
  649. va_list aptr; va_start(aptr, format);
  650. strSafePrint(&le->Content, format, aptr);
  651. va_end(aptr);
  652. #ifdef LAGUI_ANDROID
  653. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  654. #endif
  655. laNotifyUsers("la.logs");
  656. }
  657. void logPrint(char* format, ...){
  658. va_list aptr; va_start(aptr, format);
  659. logPrintTV(0, format, aptr);
  660. va_end(aptr);
  661. }
  662. void logPrintNew(char* format, ...){
  663. logEnsure(1);
  664. va_list aptr; va_start(aptr, format);
  665. logPrintTV(0, format, aptr);
  666. va_end(aptr);
  667. }
  668. void logClear(){
  669. laLogEntry*l;
  670. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  671. laNotifyUsers("la.logs");
  672. }
  673. laSafeString** la_PerfEnsure(){
  674. MAIN.NextPerfCounter++;
  675. if(MAIN.NextPerfCounter>=32){ MAIN.NextPerfCounter=0; }
  676. return &MAIN.PerfLogs[MAIN.NextPerfCounter];
  677. }
  678. void la_PerfClear(){
  679. if(!MAIN.ShowPerf){ return; }
  680. MAIN.NextPerfCounter=0; MAIN.NextPerfGroup++; if(MAIN.NextPerfGroup>=32){ MAIN.NextPerfGroup=0; }
  681. memset(&MAIN.PerfCounter[MAIN.NextPerfGroup],0,32*sizeof(real));
  682. for(int i=0;i<32;i++){ strSafeDestroy(&MAIN.PerfLogs[i]); }
  683. }
  684. void laPerfRecordV(char* format, va_list v){
  685. if(!format || !format[0]) return;
  686. laSafeString** ss=la_PerfEnsure();
  687. strSafePrintV(ss, format, v);
  688. laTimeRecorder tm; laRecordTime(&tm);
  689. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  690. }
  691. void laPerfRecord(char* format, ...){
  692. if(!format || !format[0]) return;
  693. laSafeString** ss=la_PerfEnsure();
  694. va_list aptr; va_start(aptr, format);
  695. strSafePrintV(ss, format, aptr);
  696. va_end(aptr);
  697. laTimeRecorder tm; laRecordTime(&tm);
  698. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  699. }
  700. void la_PerfDraw(){
  701. tnsScale3d(0.75,0.75,0.75);
  702. int sy=0; laBoxedTheme* bt=_LA_THEME_LABEL; real* color=laThemeColor(bt,LA_BT_TEXT);
  703. int sl=LA_RH*4; char buf[16]; real totval=0; real vals[32];
  704. for(int i=0;i<32;i++){
  705. if(MAIN.PerfLogs[i]){
  706. real value = MAIN.PerfCounter[MAIN.NextPerfGroup][i]-(i>0?MAIN.PerfCounter[MAIN.NextPerfGroup][i-1]:0);
  707. sprintf(buf,"%0.2lf",value*1000); totval+=value; vals[i]=value;
  708. tnsDrawStringAuto(buf,color,0,10000,sy,LA_TEXT_SHADOW);
  709. tnsDrawStringAuto(SSTR(MAIN.PerfLogs[i]),color,sl,10000,sy,LA_TEXT_SHADOW);
  710. sy+=LA_RH;
  711. }
  712. }
  713. real SL=LA_RH*2,SR=LA_RH*3.5; sy=0; tnsColor4dv(color); tnsUseNoTexture();
  714. for(int i=0;i<32;i++){
  715. if(MAIN.PerfLogs[i]){
  716. real r=vals[i]/totval; real use_r=tnsInterpolate(SL,SR,r);
  717. tnsVertex2d(SL,sy); tnsVertex2d(SL,sy+LA_RH); tnsVertex2d(use_r,sy+LA_RH); tnsVertex2d(use_r,sy);
  718. tnsPackAs(GL_TRIANGLE_FAN);
  719. sy+=LA_RH;
  720. }
  721. }
  722. tnsFlush();
  723. }
  724. 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;
  725. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  726. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  727. }
  728. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  729. strSafeSet(&s->Name,Name);
  730. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  731. s->x=x;s->y=y;s->w=w;s->h=h;
  732. laNotifyUsers("la.user_preferences.screens");
  733. return s;
  734. }
  735. void la_RemoveScreen(laScreen*s){
  736. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  737. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  738. }
  739. void la_RemoveDuplicatedScreenConf(){
  740. laScreen* NextS;
  741. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  742. NextS = s->Item.pNext;
  743. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  744. 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; }
  745. }
  746. }
  747. }
  748. laScreen* laGetWindowScreen(laWindow* w){
  749. int l,r,u,b; int area=-1; laScreen* maxs=0;
  750. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  751. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  752. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  753. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  754. int a=w*h; if(a>area){ maxs = s; area = a; }
  755. }
  756. return maxs;
  757. }
  758. #ifdef LA_LINUX
  759. int la_GetDPI(Window* root_win){
  760. XRRScreenResources *screen;
  761. XRROutputInfo *info;
  762. XRRCrtcInfo *crtc_info;
  763. XRRCrtcInfo *crtc;
  764. int iscres, icrtc, dpi=0;
  765. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  766. for(iscres=0;iscres<screen->noutput;iscres++){
  767. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  768. if(!info->mm_width || !info->mm_height){ continue; }
  769. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  770. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  771. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  772. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  773. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  774. XRRFreeCrtcInfo(crtc);
  775. //if(info->connection==RR_Connected){
  776. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  777. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  778. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  779. // XRRFreeCrtcInfo(crtc_info);
  780. // }
  781. //}
  782. XRRFreeOutputInfo(info);
  783. }
  784. XRRFreeScreenResources(screen);
  785. return dpi;
  786. }
  787. #endif
  788. #ifdef _WIN32
  789. typedef struct laWin32MonitorEnumData {
  790. int id;
  791. }laWin32MonitorEnumData;
  792. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  793. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  794. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  795. return TRUE;
  796. }
  797. int la_GetDPI(HWND win){
  798. laWin32MonitorEnumData data = { 0 };
  799. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  800. return GetDpiForWindow(win);
  801. return 144;
  802. }
  803. #endif
  804. #define PROGRESSW (LA_RH*15)
  805. void laShowProgress(real p1, real p2){
  806. laSpinLock(&MAIN.OpsLock);
  807. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  808. if(!MAIN.Progress.Called){
  809. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  810. }
  811. laTimeRecorder tm; laRecordTime(&tm);
  812. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  813. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  814. if((!MAIN.Progress.Shown) && MAIN.Progress.Called){
  815. int ww=PROGRESSW+LA_RH*2;
  816. #ifdef LA_LINUX
  817. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  818. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  819. long a=LA_COLOR3_TO_HEX(bg);
  820. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  821. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  822. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  823. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  824. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  825. #endif
  826. #ifdef _WIN32
  827. ShowWindow(MAIN.Progress.w, SW_NORMAL);
  828. #endif
  829. MAIN.Progress.Shown = 1;
  830. }
  831. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  832. #ifdef LA_LINUX
  833. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  834. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  835. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  836. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  837. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  838. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  839. #endif
  840. #ifdef _WIN32
  841. PostMessage(MAIN.Progress.w, LA_PROGRESS_REPAINT_MESSAGE, 0, 0);
  842. #endif
  843. #ifdef LAGUI_ANDROID
  844. laWindow* window=MAIN.CurrentWindow; int pw=window->CW;
  845. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  846. tnsViewportWithScissor(0,0,window->CW,window->CH);
  847. tnsOrtho(0,window->CW,-window->CH+LA_2RH,LA_2RH,-100,100);
  848. tnsClearColorv(bg); tnsClearAll(); tnsUseNoTexture(); tnsColor4dv(fg);
  849. tnsVertex2d(0,0);tnsVertex2d(pw*MAIN.Progress.p2,0);tnsVertex2d(pw*MAIN.Progress.p2,LA_RH);tnsVertex2d(0,LA_RH);
  850. tnsPackAs(GL_TRIANGLE_FAN);
  851. tnsVertex2d(0,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_2RH);tnsVertex2d(0,LA_2RH);
  852. tnsPackAs(GL_TRIANGLE_FAN);
  853. tnsFlush();
  854. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  855. eglMakeCurrent(MAIN.egl_dpy,0,0,0);
  856. #endif
  857. laSpinUnlock(&MAIN.OpsLock);
  858. }
  859. void laHideProgress(){
  860. laSpinLock(&MAIN.OpsLock);
  861. if(!MAIN.Progress.Shown){
  862. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  863. }
  864. laTimeRecorder tm; laRecordTime(&tm);
  865. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  866. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  867. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  868. #ifdef LA_LINUX
  869. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  870. #endif
  871. #ifdef _WIN32
  872. ShowWindow(MAIN.Progress.w,SW_HIDE);
  873. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  874. #endif
  875. #ifdef LAGUI_ANDROID
  876. laRedrawAllWindows();
  877. #endif
  878. laSpinUnlock(&MAIN.OpsLock);
  879. }
  880. //=======================
  881. #ifdef _WIN32
  882. void la_Win32ProgressWindowThread(void* unused) {
  883. laSpinLock(&MAIN.OpsLock);
  884. WNDCLASSW wc;
  885. wc.hInstance = MAIN.hinstance;
  886. wc.lpfnWndProc = LA_ProgressWindowProc;
  887. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  888. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  889. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  890. wc.cbWndExtra = 0;
  891. wc.cbClsExtra = 0;
  892. wc.lpszClassName = L"_LAGUIPROGRESS";
  893. wc.lpszMenuName = NULL;
  894. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  895. if (!RegisterClassW(&wc)) { return; }
  896. MAIN.Progress.w = CreateWindowW(L"_LAGUIPROGRESS", L"Progress", WS_POPUP, 0, 0, PROGRESSW + LA_RH * 2, LA_RH * 2, 0, 0, MAIN.hinstance, 0);
  897. laSpinUnlock(&MAIN.OpsLock);
  898. MSG msg;
  899. while (GetMessage(&msg, MAIN.Progress.w, 0, 0)) {
  900. TranslateMessage(&msg); DispatchMessage(&msg);
  901. }
  902. }
  903. #endif
  904. void la_InitProgressWindow(){
  905. #ifdef LA_LINUX
  906. 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));
  907. if(!MAIN.Progress.w) return;
  908. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  909. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  910. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  911. if(MAIN.Progress.gc<0) return;
  912. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  913. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  914. XSync(MAIN.dpy,0);
  915. #endif
  916. #ifdef _WIN32
  917. thrd_create(&MAIN.Progress.th, la_Win32ProgressWindowThread, 0);
  918. //MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  919. #endif
  920. }
  921. void laSetFontFolderPath(char* absolute){
  922. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  923. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  924. }
  925. void laSetDefaultInitArguments(laInitArguments* ia){
  926. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  927. ia->UseColorManagement=0;
  928. ia->HasWorldObjects=0;
  929. ia->HasAction=0;
  930. ia->HasTextureInspector=0;
  931. ia->HasHistories=0;
  932. ia->HasTerminal=1;
  933. ia->HasAudio=0;
  934. }
  935. void laSetCompleteInitArguments(laInitArguments* ia){
  936. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  937. ia->GLESMajor=3; ia->GLESMinor=0;
  938. ia->UseColorManagement=1;
  939. ia->HasWorldObjects=1;
  940. ia->HasAction=1;
  941. ia->HasTextureInspector=1;
  942. ia->HasHistories=1;
  943. ia->HasTerminal=1;
  944. ia->HasAudio=1;
  945. }
  946. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  947. MAIN.GLMajor=MAIN.GLMinor=-1;
  948. char* arg = 0;
  949. printf("Initializing LaGUI...\n",argc);
  950. for(int i=0;i<argc;i++){
  951. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  952. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  953. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  954. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  955. }
  956. continue;
  957. }
  958. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  959. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  960. }
  961. }
  962. int laGetReadyWith(laInitArguments* ia){
  963. #ifdef LA_LINUX
  964. //signal(SIGSEGV,la_HandlerSIGSEGV);
  965. #endif
  966. laSpinInit(&MAIN.MemLock);
  967. laSpinInit(&MAIN.OpsLock);
  968. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  969. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  970. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  971. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  972. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  973. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  974. la_GetWorkingDirectoryInternal();
  975. tnsInit();
  976. #ifdef LA_LINUX
  977. SYSWINDOW root, win;
  978. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  979. XSetWindowAttributes swa={0};
  980. XWindowAttributes wa={0};
  981. XEvent xev;
  982. logPrintNew("Initializing LaGUI...\n");
  983. setlocale(LC_CTYPE, "zh_CN.utf8");
  984. XSetErrorHandler(la_XErrorHandler);
  985. int i;
  986. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  987. printf("\n\tcannot connect to x server\n\n");
  988. exit(0);
  989. }
  990. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  991. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  992. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  993. #ifdef LA_USE_GLES
  994. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  995. #else
  996. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  997. #endif
  998. #ifdef LA_USE_GLES
  999. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  1000. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  1001. EGLint egl_major, egl_minor;
  1002. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  1003. printf("Error: eglInitialize() failed\n"); return -1;
  1004. }
  1005. int scrnum;
  1006. XSetWindowAttributes attr;
  1007. XVisualInfo *visInfo, visTemplate;
  1008. int num_visuals;
  1009. EGLContext ctx;
  1010. EGLint num_configs;
  1011. EGLint vid;
  1012. static const EGLint attribs[] = {
  1013. EGL_RED_SIZE, 8,
  1014. EGL_GREEN_SIZE, 8,
  1015. EGL_BLUE_SIZE, 8,
  1016. EGL_DEPTH_SIZE, 1,
  1017. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  1018. EGL_NONE
  1019. };
  1020. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  1021. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  1022. }
  1023. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  1024. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  1025. }
  1026. visTemplate.visualid = vid;
  1027. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  1028. if (!visInfo) {
  1029. printf("Error: couldn't get X visual\n"); exit(1);
  1030. }
  1031. MAIN.xvi=visInfo;
  1032. root = DefaultRootWindow(MAIN.dpy);
  1033. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1034. printf("\n\tcannot create colormap\n\n"); exit(1);
  1035. }
  1036. eglBindAPI(EGL_OPENGL_ES_API);
  1037. EGLint ctx_attribs[] = {
  1038. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  1039. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  1040. EGL_NONE
  1041. };
  1042. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  1043. if (!MAIN.glc) {
  1044. printf("Error: eglCreateContext failed\n"); exit(1);
  1045. }
  1046. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  1047. #else
  1048. int visual_attribs[] = {
  1049. GLX_X_RENDERABLE , True,
  1050. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  1051. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  1052. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  1053. GLX_RED_SIZE , 8,
  1054. GLX_GREEN_SIZE , 8,
  1055. GLX_BLUE_SIZE , 8,
  1056. GLX_ALPHA_SIZE , 8,
  1057. GLX_DEPTH_SIZE , 24,
  1058. //GLX_STENCIL_SIZE , 8,
  1059. GLX_DOUBLEBUFFER , True,
  1060. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  1061. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  1062. None
  1063. };
  1064. int fbcount = -1;
  1065. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  1066. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  1067. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  1068. MAIN.BestFBC = fbconfig[0];
  1069. int sample_buf,samples;
  1070. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  1071. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  1072. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1073. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1074. free(fbconfig);
  1075. root = DefaultRootWindow(MAIN.dpy);
  1076. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1077. printf("\n\tcannot create colormap\n\n"); exit(0);
  1078. }
  1079. swa.colormap = MAIN.cmap;
  1080. root = DefaultRootWindow(MAIN.dpy);
  1081. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1082. MAIN.win=win;
  1083. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1084. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1085. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1086. printf("\n\tcannot create gl context\n\n"); exit(0);
  1087. }
  1088. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1089. tnsContextMakeCurrent(MAIN.glc,win,0);
  1090. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1091. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1092. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1093. int err=0;
  1094. if((err=glewInit())!=GLEW_OK){
  1095. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1096. };
  1097. #endif /* gles or glx */
  1098. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1099. la_SetCurrentGLContextDebug();
  1100. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1101. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1102. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1103. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1104. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1105. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1106. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1107. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1108. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1109. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1110. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1111. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1112. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1113. #endif //linux
  1114. #ifdef _WIN32
  1115. logPrintNew("Initializing LaGUI...\n");
  1116. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1117. setlocale(LC_ALL, "zh_CN.utf8");
  1118. MAIN.hinstance = GetModuleHandle(NULL);
  1119. HINSTANCE* hInst = &MAIN.hinstance;
  1120. WNDCLASSEXW wt;
  1121. wt.cbSize = sizeof(WNDCLASSEXW);
  1122. wt.cbClsExtra = 0;
  1123. wt.cbWndExtra = 0;
  1124. wt.hbrBackground = 0;
  1125. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1126. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1127. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1128. wt.hInstance = *hInst;
  1129. wt.lpfnWndProc = LA_WindowProc;
  1130. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1131. wt.lpszMenuName = 0;
  1132. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1133. if (!RegisterClassEx(&wt)) return 0;
  1134. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1135. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1136. SetProcessDPIAware();
  1137. GLenum err;
  1138. PIXELFORMATDESCRIPTOR pfd;
  1139. HINSTANCE* hinst = &MAIN.hinstance;
  1140. HWND hwnd = CreateWindowEx(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1141. "Temp Window For Accessing GLEW!",
  1142. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1143. 0, 0, *hinst, 0);
  1144. HDC hdc = GetDC(hwnd);
  1145. HGLRC hglrc = 0;
  1146. SetPixelFormat(hdc, 1, &cpfd);
  1147. hglrc = wglCreateContext(hdc);
  1148. tnsContextMakeCurrent(hglrc, hdc,0);
  1149. //MAIN.hdc = hdc;
  1150. // MAIN.tWND = hwnd;
  1151. MAIN.glc = hglrc;
  1152. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1153. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1154. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1155. if (err = glewInit()) {
  1156. printf("Init Glew Failed\n");
  1157. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1158. return 0;
  1159. }
  1160. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1161. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1162. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1163. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1164. #endif
  1165. MAIN.SavePreferenceOnExit=1;
  1166. MAIN.FontSize = 0.6;
  1167. int dpi=64;
  1168. #ifdef _WIN32
  1169. dpi=la_GetDPI(hwnd);
  1170. #endif
  1171. #ifdef LA_LINUX
  1172. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1173. #endif
  1174. #ifdef LAGUI_ANDROID
  1175. dpi = 72;
  1176. #endif
  1177. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1178. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1179. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight = UiSize;
  1180. MAIN.UiScale=1;
  1181. MAIN.MarginSize = 1;
  1182. MAIN.ColorPickerGamma=1.5;
  1183. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1184. MAIN.ViewportHalftoneFactor=0.5;
  1185. MAIN.ViewportHalftoneSize=3.7;
  1186. tnsInitRenderKernel(64);
  1187. tnsInitBuiltinShaders();
  1188. tnsSetuptnsFontManager();
  1189. #define LOAD_FONT(font) \
  1190. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1191. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1192. LOAD_FONT("NotoEmoji-Regular.ttf");
  1193. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1194. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1195. LOAD_FONT("NotoSansMath-Regular.ttf");
  1196. //LOAD_FONT("NotoMusic-Regular.ttf");
  1197. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1198. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1199. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1200. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1201. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1202. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1203. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1204. MAIN.Audio=memAcquire(sizeof(laAudio));
  1205. #ifdef LA_WITH_LUAJIT
  1206. // starting lua
  1207. logPrint("Starting luajit...\n");
  1208. MAIN.L = lua_open();
  1209. la_luaLoadLibs(MAIN.L);
  1210. la_luaPrintStatus(MAIN.L);
  1211. tnsLuaInit(MAIN.L);
  1212. #endif
  1213. //interactions:
  1214. MAIN.TopFramerate = 60;
  1215. MAIN.ValuatorThreshold = 8;
  1216. MAIN.ScrollingSpeed = 3;
  1217. MAIN.AnimationSpeed = 0.4;
  1218. MAIN.PanelAnimationSpeed = 0.4;
  1219. MAIN.ZoomSpeed2D = 0.01;
  1220. MAIN.IdleTime = 0.75;
  1221. MAIN.TooltipCloseDistance = 30;
  1222. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1223. //display:
  1224. MAIN.FloatingAlpha = 0.35;
  1225. MAIN.SolidShadowLength = 20;
  1226. MAIN.WireColorSlices = 16;
  1227. MAIN.WireThickness = 5;
  1228. MAIN.WireSaggyness = 0.5;
  1229. MAIN.ManagerFilterInstances = 1;
  1230. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1231. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1232. la_InitProgressWindow();
  1233. la_MakeTranslations_es_ES();
  1234. la_MakeTranslations_zh_hans();
  1235. //tns_RegisterResourcesForSoftwareRender();
  1236. la_RegisterDefaultSignals();
  1237. la_RegisterGeneralProps();
  1238. la_RegisterBuiltinTemplates();
  1239. la_RegisterMainThemes();
  1240. la_RegisterMainOperators();
  1241. la_RegisterMainUiTypes();
  1242. la_RegisterInternalProps();
  1243. la_RegisterAnimationResources();
  1244. la_RegisterWindowKeys();
  1245. if(MAIN.InitArgs.HasWorldObjects){
  1246. la_RegisterModellingOperators();
  1247. la_RegisterShapeOperators();
  1248. }
  1249. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1250. laFinalizeUiTemplates();
  1251. laFinalizeOperators();
  1252. la_RegisterControllerProps();
  1253. la_RefreshControllers();
  1254. la_RegisterBasicNodes();
  1255. tns_RegisterNodes();
  1256. la_InitThreadEnviornment();
  1257. laSetRootInstance(&MAIN);
  1258. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1259. laPushDifferences(0, 0);
  1260. la_MakeDummyManagedUDF();
  1261. la_RegenerateWireColors();
  1262. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1263. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1264. laSetProofingLut(DATA_LUT_PROOF_SRGB, 0);
  1265. laSetProofingLut(DATA_LUT_PROOF_CLAY, 1);
  1266. laSetProofingLut(DATA_LUT_PROOF_D65P3, 2);
  1267. logPrintNew("Initialization Completed\n");
  1268. MAIN.InitDone=1;
  1269. #ifdef LAGUI_ANDROID
  1270. MAIN.AutoSwitchColorSpace = 0;
  1271. MAIN.GotFilePermission = la_check_permission("android.permission.WRITE_EXTERNAL_STORAGE");
  1272. #else
  1273. MAIN.AutoSwitchColorSpace = 1;
  1274. #endif
  1275. return 1;
  1276. }
  1277. int laGetReady(){
  1278. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1279. return laGetReadyWith(&ia);
  1280. }
  1281. void la_DestroyUiType(laUiType* uit);
  1282. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1283. void laShutoff(int SavePrefereces){
  1284. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1285. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1286. // transLate(pc->Description);
  1287. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1288. // transLate(p->Description);
  1289. // }
  1290. //}
  1291. #ifdef _WIN32
  1292. laSpinLock(&MAIN.OpsLock);
  1293. PostMessage(MAIN.Progress.w, WM_QUIT, 0, 0);
  1294. laSpinUnlock(&MAIN.OpsLock);
  1295. thrd_join(MAIN.Progress.th, 0);
  1296. #endif
  1297. transDumpMissMatchRecord("TranslationDump.txt");
  1298. if(MAIN.Cleanup) MAIN.Cleanup();
  1299. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1300. strSafeDestroy(&MAIN.WorkingDirectory);
  1301. strSafeDestroy(&MAIN.example_string);
  1302. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1303. // (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. )
  1304. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1305. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1306. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1307. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1308. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1309. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1310. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1311. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1312. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1313. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1314. strSafeDestroy(&MAIN.CopyPending);
  1315. la_ClearUDFRegistryAndFolders();
  1316. laClearManagedUDF();
  1317. laClearSaveProp();
  1318. logClear();
  1319. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1320. #ifdef LA_LINUX
  1321. tnsContextMakeCurrent(0,0,0);
  1322. tnsDeleteContext(MAIN.glc);
  1323. #ifdef LA_USE_GLES
  1324. eglTerminate(MAIN.egl_dpy);
  1325. #endif
  1326. #endif
  1327. #ifdef _WIN32
  1328. tnsContextMakeCurrent(0,0,0);
  1329. tnsDeleteContext(MAIN.glc);
  1330. UnloadWintab();
  1331. #endif
  1332. tnsQuit();
  1333. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1334. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1335. strSafeDump();
  1336. hshFree(&MAIN.DBInstMemLeft);
  1337. memNoLonger();
  1338. laSpinDestroy(&MAIN.MemLock);
  1339. laSpinDestroy(&MAIN.OpsLock);
  1340. #ifdef LA_WITH_LUAJIT
  1341. lua_close(MAIN.L);
  1342. #endif
  1343. printf("LaGUI has cleaned up.\n");
  1344. }
  1345. int laRestoreFactorySettings(){
  1346. char path[1024];
  1347. #ifdef LAGUI_ANDROID
  1348. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1349. logPrintNew("%s", path);
  1350. if(!remove(path)){ return 1; }
  1351. sprintf(path,"%s/%s",MAIN.ExternalDataPath,"preferences.udf");
  1352. logPrintNew("%s", path);
  1353. if(!remove(path)){ return 1; }
  1354. return 0;
  1355. #else
  1356. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1357. #endif
  1358. if(remove(path)){ return 0; }
  1359. return 1;
  1360. }
  1361. void laSaveUserPreferences(){
  1362. char path[1024];
  1363. #ifdef LAGUI_ANDROID
  1364. sprintf(path,"%s","preferences.udf");
  1365. #else
  1366. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1367. #endif
  1368. laUDF* udf=laPrepareUDF(path);
  1369. laWriteProp(udf,"la.windows");
  1370. laWriteProp(udf,"la.themes");
  1371. laWriteProp(udf,"la.user_preferences");
  1372. laWriteProp(udf,"la.input_mapping");
  1373. laWriteProp(udf,"la.controllers");
  1374. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1375. laWriteProp(udf,lip->p);
  1376. }
  1377. laPackUDF(udf,0,0);
  1378. }
  1379. void laEnsureUserPreferences(){
  1380. //laLoadHyperResources("LATHEME");
  1381. char path[1024];
  1382. #ifdef LAGUI_ANDROID
  1383. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1384. #else
  1385. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1386. #endif
  1387. laUDFRegistry* r=laFindUDFRegistry(path);
  1388. if(!r){ laSaveUserPreferences(); return; }
  1389. laUDF* udf=laOpenUDF(SSTR(r->Path),1,0,0); if(!udf){ logPrint("Can't read preferences on %s. Using default settings.",SSTR(r->Path)); return; }
  1390. laClearUDFRegistries();
  1391. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1392. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1393. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1394. laCloseUDF(udf);
  1395. la_RemoveDuplicatedScreenConf();
  1396. la_RemoveDuplicatedControllers();
  1397. laRefreshUDFRegistries();
  1398. //restore forced settings
  1399. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1400. }
  1401. void laAddExtraExtension(int FileType, ...){
  1402. va_list list; va_start(list,FileType);
  1403. char* ext;
  1404. while(ext=va_arg(list,char*)){ if(!ext) break;
  1405. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1406. et->FileType=FileType; et->Extension=ext;
  1407. lstAppendItem(&MAIN.ExtraExtensions, et);
  1408. logPrintNew("add ext %s",ext);
  1409. }
  1410. va_end(list);
  1411. }
  1412. void laAddExtraPreferencePath(const char* path){
  1413. if(!path) return;
  1414. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1415. }
  1416. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1417. if(!name || !Func) return;
  1418. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1419. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1420. }
  1421. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1422. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1423. }
  1424. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1425. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1426. }
  1427. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1428. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1429. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1430. }
  1431. void la_InputMappingGetKeyName(int key, int special, char* name){
  1432. char *_next=name; name[0]=0;
  1433. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1434. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1435. if(special&LA_KEY_ALT){ strcat(name,"Alt+"); }
  1436. switch(key){
  1437. case ' ': strcat(name,"Space"); break;
  1438. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1439. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1440. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1441. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1442. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1443. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1444. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1445. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1446. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1447. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1448. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1449. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1450. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1451. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1452. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1453. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1454. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1455. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1456. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1457. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1458. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1459. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1460. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1461. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1462. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1463. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1464. case LA_KEY_F1: strcat(name,"F1"); break;
  1465. case LA_KEY_F2: strcat(name,"F2"); break;
  1466. case LA_KEY_F3: strcat(name,"F3"); break;
  1467. case LA_KEY_F4: strcat(name,"F4"); break;
  1468. case LA_KEY_F5: strcat(name,"F5"); break;
  1469. case LA_KEY_F6: strcat(name,"F6"); break;
  1470. case LA_KEY_F7: strcat(name,"F7"); break;
  1471. case LA_KEY_F8: strcat(name,"F8"); break;
  1472. case LA_KEY_F9: strcat(name,"F9"); break;
  1473. case LA_KEY_F10: strcat(name,"F10"); break;
  1474. case LA_KEY_F11: strcat(name,"F11"); break;
  1475. case LA_KEY_F12: strcat(name,"F12"); break;
  1476. case LA_KEY_MOUSE_LEFT: strcat(name,"Mouse1"); break;
  1477. case LA_KEY_MOUSE_MIDDLE: strcat(name,"Mouse2"); break;
  1478. case LA_KEY_MOUSE_RIGHT: strcat(name,"Mouse3"); break;
  1479. case LA_KEY_MOUSE_SCROLL|LA_STATE_UP: strcat(name,"MouseWheelUp"); break;
  1480. case LA_KEY_MOUSE_SCROLL|LA_STATE_DOWN: strcat(name,"MouseWheelDown"); break;
  1481. default:
  1482. name = name+strlen(name); _next=name;
  1483. laToUTF8(key,name,&_next); *_next=0; break;
  1484. }
  1485. }
  1486. int la_InputMappingGetKeyFromName(char* name, int* special){
  1487. if(!name ||name[0]==0){ *special=0; return 0; }
  1488. *special=0;
  1489. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1490. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1491. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1492. char* p=name+strlen(name)-1;
  1493. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1494. while(*p=='+' || *p==' '){ p++; }
  1495. if(strSame(p,"Space")) return ' ';
  1496. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1497. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1498. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1499. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1500. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1501. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1502. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1503. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1504. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1505. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1506. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1507. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1508. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1509. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1510. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1511. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1512. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1513. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1514. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1515. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1516. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1517. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1518. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1519. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1520. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1521. if(strSame(p,"F1")) return LA_KEY_F1;
  1522. if(strSame(p,"F2")) return LA_KEY_F2;
  1523. if(strSame(p,"F3")) return LA_KEY_F3;
  1524. if(strSame(p,"F4")) return LA_KEY_F4;
  1525. if(strSame(p,"F5")) return LA_KEY_F5;
  1526. if(strSame(p,"F6")) return LA_KEY_F6;
  1527. if(strSame(p,"F7")) return LA_KEY_F7;
  1528. if(strSame(p,"F8")) return LA_KEY_F8;
  1529. if(strSame(p,"F9")) return LA_KEY_F9;
  1530. if(strSame(p,"F10")) return LA_KEY_F10;
  1531. if(strSame(p,"F11")) return LA_KEY_F11;
  1532. if(strSame(p,"F12")) return LA_KEY_F12;
  1533. if(strSame(p,"Mouse1")) return LA_KEY_MOUSE_LEFT;
  1534. if(strSame(p,"Mouse2")) return LA_KEY_MOUSE_MIDDLE;
  1535. if(strSame(p,"Mouse3")) return LA_KEY_MOUSE_RIGHT;
  1536. if(strSame(p,"MouseWheelUp")) return LA_KEY_MOUSE_SCROLL|LA_STATE_UP;
  1537. if(strSame(p,"MouseWheelDown")) return LA_KEY_MOUSE_SCROLL|LA_STATE_DOWN;
  1538. int adv;
  1539. return laToUnicode(p,&adv);
  1540. }
  1541. laCustomSignal* laFindSignal(char* Name){
  1542. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1543. return 0;
  1544. }
  1545. laCustomSignal* laFindSignalByID(int ID){
  1546. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1547. return 0;
  1548. }
  1549. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1550. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD || ime->DeviceType==LA_INPUT_DEVICE_MOUSE){ char* str=SSTR(ime->Key);
  1551. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1552. }
  1553. elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1554. char* signal = SSTR(ime->Signal);
  1555. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1556. }
  1557. laInputMapping* laNewInputMapping(char* Name){
  1558. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1559. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1560. strSafeSet(&im->Name,Name);
  1561. return im;
  1562. }
  1563. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1564. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1565. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1566. memAssignRef(e,&e->Parent,im);
  1567. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1568. laInputMappingUpdateSignal(e);
  1569. e->SpecialKeyBits=SpecialKeyBit;
  1570. char buf[64],*_next=buf;
  1571. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1572. return e;
  1573. }
  1574. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1575. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1576. return laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1577. }
  1578. laInputMappingEntry* laNewInputMappingMouseEntryP(laInputMapping* im, int MouseEventType, int SpecialKeyBit, int Signal){
  1579. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1580. char* Key="Mouse2";
  1581. if(MouseEventType&LA_KEY_MOUSE_LEFT){ Key="Mouse1"; }
  1582. elif(MouseEventType&LA_KEY_MOUSE_MIDDLE){ Key="Mouse2"; }
  1583. elif(MouseEventType&LA_KEY_MOUSE_RIGHT){ Key="Mouse3"; }
  1584. elif((MouseEventType&LA_KEY_MOUSE_SCROLL) && (MouseEventType&LA_STATE_UP)){ Key="MouseWheelUp"; }
  1585. elif((MouseEventType&LA_KEY_MOUSE_SCROLL) && (MouseEventType&LA_STATE_DOWN)){ Key="MouseWheelDown"; }
  1586. return laNewInputMappingEntry(im,LA_INPUT_DEVICE_MOUSE,0,Key,SpecialKeyBit,SSTR(cs->Name));
  1587. }
  1588. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1589. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1590. }
  1591. void laRemoveInputMapping(laInputMapping* im){
  1592. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1593. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1594. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1595. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1596. }
  1597. laInputMapping* laNewToolbox(char* Name){
  1598. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->Toolboxes,im);
  1599. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentToolbox,im);
  1600. strSafeSet(&im->Name,Name);
  1601. return im;
  1602. }
  1603. void laRemoveToolbox(laInputMapping* im){
  1604. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1605. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1606. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentToolbox,use);
  1607. lstRemoveItem(&MAIN.InputMapping->Toolboxes,im); strSafeDestroy(&im->Name); memFree(im);
  1608. }
  1609. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1610. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1611. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1612. return cs;
  1613. }
  1614. void laRemoveCustomSignal(laCustomSignal* cs){
  1615. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1616. }
  1617. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1618. void la_SendOperatorEvent(SYSWINDOW* hwnd, laOperatorType* at, int use_base, char* instructions);
  1619. void la_SendInputMappingSignalsAuto(SYSWINDOW* hwnd, laInputMappingEntry* ime){
  1620. if(ime->UseOperator){ la_SendOperatorEvent(hwnd, ime->OperatorType, ime->OperatorBase, SSTR(ime->OperatorArguments)); }
  1621. else{ la_SendSignalEvent(hwnd, ime->SignalValue); }
  1622. }
  1623. void la_SendSignalsFromEvent(laEvent* e){
  1624. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1625. if(!im){return;}
  1626. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1627. if(ime->Disabled) continue;
  1628. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1629. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1630. la_SendInputMappingSignalsAuto(e->window->win,ime);
  1631. }
  1632. }elif((e->type&LA_MOUSE_EVENT) && ime->DeviceType == LA_INPUT_DEVICE_MOUSE){
  1633. int matchkey; if(!(e->type&LA_KEY_MOUSE_SCROLL)){ matchkey = ((e->type&ime->KeyValue) && (e->type&LA_STATE_DOWN)); }
  1634. else{ matchkey = (e->type==(ime->KeyValue&LA_MOUSE_EVENT)); }
  1635. if(e->SpecialKeyBit == ime->SpecialKeyBits && matchkey){
  1636. la_SendInputMappingSignalsAuto(e->window->win,ime);
  1637. }
  1638. }
  1639. }
  1640. }
  1641. //MSG====================================================
  1642. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1643. if (wnd->win == hwnd) return 1;
  1644. else return 0;
  1645. };
  1646. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1647. if (p->SL){ int s=p->SL<0?0:p->SL;
  1648. if (p->TX != s) laRecalcPanel(p);
  1649. p->TX = s;
  1650. }
  1651. if (p->SR){ int s=p->SR<0?0:p->SR;
  1652. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1653. p->TW = CW - p->TX - s;
  1654. }
  1655. if (p->ST){ int s=p->ST<0?0:p->ST;
  1656. if (p->TY != s) laRecalcPanel(p);
  1657. p->TY = s;
  1658. }
  1659. if (p->SB){ int s=p->SB<0?0:p->SB;
  1660. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1661. p->TH = CH - p->TY - s;
  1662. }
  1663. }
  1664. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1665. laPanel *p = 0;
  1666. b->X = X;
  1667. b->Y = Y;
  1668. b->W = W;
  1669. b->H = H;
  1670. if (b->B1){
  1671. int SplitWidth;
  1672. if (b->Vertical){
  1673. SplitWidth = H * b->SplitRatio;
  1674. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1675. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1676. }else{
  1677. SplitWidth = W * b->SplitRatio;
  1678. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1679. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1680. }
  1681. }
  1682. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1683. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1684. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1685. }
  1686. if (p = b->CurrentPanel){
  1687. int TitleGap=b->Folded?0:LA_RH;
  1688. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1689. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1690. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1691. laRecalcPanel(p);
  1692. }
  1693. }
  1694. void la_UpdateUiPlacement(laWindow *w){
  1695. laLayout *l;
  1696. laPanel *p;
  1697. int CW = w->CW;
  1698. int CH = w->CH;
  1699. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1700. int MenuHeight=(LA_M+LA_M)*2+LA_RH;
  1701. if(w->MaximizedUi && w->MaximizedUiPanel){
  1702. laRecalcPanel(w->MaximizedUiPanel);
  1703. }elif(w->MaximizedBlock){
  1704. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1705. }else{
  1706. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1707. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1708. }
  1709. }
  1710. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1711. if(p->IsMenuPanel){
  1712. p->TH=p->H=MenuHeight;
  1713. }
  1714. la_EnsurePanelSnapping(p, CW, CH);
  1715. laRecalcPanel(p);
  1716. }
  1717. }
  1718. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1719. laWindow *window;
  1720. #ifdef LAGUI_ANDROID
  1721. window = MAIN.Windows.pFirst; if (!window) return;
  1722. window->X=x;window->Y=y;window->W=w;window->H=h;
  1723. window->CW=w;window->CH=h;
  1724. la_UpdateUiPlacement(window); return;
  1725. #endif
  1726. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1727. if (!window) return;
  1728. #ifdef _WIN32
  1729. RECT rcc; GetClientRect(window->win, &rcc);
  1730. RECT rcw; GetWindowRect(window->win, &rcw);
  1731. window->CW = rcc.right - rcc.left;
  1732. window->CH = rcc.bottom - rcc.top;
  1733. window->W = rcw.right - rcw.left;
  1734. window->H = rcw.bottom - rcw.top;
  1735. window->X = rcw.left; window->Y = rcw.top;
  1736. if (MAIN.AutoSwitchColorSpace) {
  1737. laScreen* s = laGetWindowScreen(window);
  1738. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1739. }
  1740. #endif
  1741. #ifdef LA_LINUX
  1742. XWindowAttributes attr;
  1743. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1744. window->CW = w; window->CH = h;
  1745. window->W = w; window->H = h;
  1746. window->X = x; window->Y = y;
  1747. if(MAIN.AutoSwitchColorSpace){
  1748. laScreen* s = laGetWindowScreen(window);
  1749. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1750. }
  1751. #endif
  1752. la_UpdateUiPlacement(window);
  1753. }
  1754. int la_OnWindowDestroy(SYSWINDOW wnd){
  1755. laListHandle *hlst = &MAIN.Windows;
  1756. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1757. if (!w) return 0;
  1758. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1759. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1760. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1761. laShutoff(1);
  1762. return 1;
  1763. }
  1764. laListHandle h={0};laLayout*l=0;
  1765. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1766. la_DestroyWindow(w);
  1767. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1768. #ifdef LA_LINUX
  1769. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1770. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1771. #endif
  1772. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1773. }
  1774. return 0;
  1775. }
  1776. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1777. laListHandle *el = &wnd->EventList;
  1778. laEvent* last_e=el->pLast;
  1779. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1780. #ifdef LA_LINUX
  1781. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1782. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1783. #endif
  1784. #ifdef _WIN32
  1785. 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);
  1786. #endif
  1787. }
  1788. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1789. laListHandle *wl = &MAIN.Windows;
  1790. laWindow* wnd;
  1791. #ifdef LAGUI_ANDROID
  1792. wnd = MAIN.Windows.pFirst;
  1793. #else
  1794. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1795. #endif
  1796. if (!wnd){ memFree(e); return; }
  1797. laListHandle *el = &wnd->EventList;
  1798. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1799. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1800. e->window = wnd;
  1801. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1802. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1803. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1804. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1805. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1806. e->GoodPressure=MAIN.IsPen;
  1807. lstAppendItem(el, (laListItem *)e);
  1808. laMappingRequestEval();
  1809. };
  1810. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1811. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1812. la_SaveEvent(hwnd, e, 1);
  1813. };
  1814. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1815. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1816. e->type = LA_INPUT; e->Input=Input;
  1817. la_SaveEvent(hwnd, e, 1);
  1818. }
  1819. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1820. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1821. e->type = LA_EMPTY;
  1822. la_SaveEvent(hwnd, e, 1);
  1823. }
  1824. void laSendOperatorTriggerEvent(){
  1825. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1826. MAIN.ReTriggerOperators = 0;
  1827. }
  1828. int la_TranslateSpecialKey(int keysym){
  1829. #ifdef LA_LINUX
  1830. switch(keysym){
  1831. case XK_Return: return LA_KEY_ENTER;
  1832. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1833. case XK_Delete: return LA_KEY_DELETE;
  1834. case XK_Escape: return LA_KEY_ESCAPE;
  1835. case XK_Tab: return LA_KEY_TAB;
  1836. case XK_Left: return LA_KEY_ARRLEFT;
  1837. case XK_Right: return LA_KEY_ARRRIGHT;
  1838. case XK_Up: return LA_KEY_ARRUP;
  1839. case XK_Down: return LA_KEY_ARRDOWN;
  1840. case XK_Control_L: return LA_KEY_CTRL;
  1841. case XK_Control_R: return LA_KEY_CTRL;
  1842. case XK_Shift_L: return LA_KEY_SHIFT;
  1843. case XK_Shift_R: return LA_KEY_SHIFT;
  1844. case XK_Alt_L: return LA_KEY_ALT;
  1845. case XK_Alt_R: return LA_KEY_ALT;
  1846. case XK_KP_1: return LA_KEY_NUM1;
  1847. case XK_KP_2: return LA_KEY_NUM2;
  1848. case XK_KP_3: return LA_KEY_NUM3;
  1849. case XK_KP_4: return LA_KEY_NUM4;
  1850. case XK_KP_5: return LA_KEY_NUM5;
  1851. case XK_KP_6: return LA_KEY_NUM6;
  1852. case XK_KP_7: return LA_KEY_NUM7;
  1853. case XK_KP_8: return LA_KEY_NUM8;
  1854. case XK_KP_9: return LA_KEY_NUM9;
  1855. case XK_KP_0: return LA_KEY_NUM0;
  1856. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1857. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1858. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1859. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1860. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1861. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1862. default: return keysym;
  1863. }
  1864. #endif
  1865. #ifdef _WIN32
  1866. switch (keysym) {
  1867. case VK_RETURN: return LA_KEY_ENTER;
  1868. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1869. case VK_TAB: return LA_KEY_TAB;
  1870. case VK_LEFT: return LA_KEY_ARRLEFT;
  1871. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1872. case VK_UP: return LA_KEY_ARRUP;
  1873. case VK_DOWN: return LA_KEY_ARRDOWN;
  1874. case VK_CONTROL: return LA_KEY_CTRL;
  1875. case VK_SHIFT: return LA_KEY_SHIFT;
  1876. case VK_MENU: return LA_KEY_ALT;
  1877. case VK_F1: return LA_KEY_F1;
  1878. case VK_F2: return LA_KEY_F2;
  1879. case VK_F3: return LA_KEY_F3;
  1880. case VK_F4: return LA_KEY_F4;
  1881. case VK_F5: return LA_KEY_F5;
  1882. case VK_F6: return LA_KEY_F6;
  1883. case VK_F7: return LA_KEY_F7;
  1884. case VK_F8: return LA_KEY_F8;
  1885. case VK_F9: return LA_KEY_F9;
  1886. case VK_F10: return LA_KEY_F10;
  1887. case VK_F11: return LA_KEY_F11;
  1888. case VK_F12: return LA_KEY_F12;
  1889. case VK_NUMPAD0: return LA_KEY_NUM0;
  1890. case VK_NUMPAD1: return LA_KEY_NUM1;
  1891. case VK_NUMPAD2: return LA_KEY_NUM2;
  1892. case VK_NUMPAD3: return LA_KEY_NUM3;
  1893. case VK_NUMPAD4: return LA_KEY_NUM4;
  1894. case VK_NUMPAD5: return LA_KEY_NUM5;
  1895. case VK_NUMPAD6: return LA_KEY_NUM6;
  1896. case VK_NUMPAD7: return LA_KEY_NUM7;
  1897. case VK_NUMPAD8: return LA_KEY_NUM8;
  1898. case VK_NUMPAD9: return LA_KEY_NUM9;
  1899. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1900. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1901. case VK_ADD: return LA_KEY_NUMPLUS;
  1902. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1903. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1904. case VK_OEM_1: return ';';
  1905. case VK_OEM_2: return '/';
  1906. case VK_OEM_3: return '`';
  1907. case VK_OEM_4: return '[';
  1908. case VK_OEM_5: return '\\';
  1909. case VK_OEM_6: return ']';
  1910. case VK_OEM_7: return '\'';
  1911. case VK_OEM_COMMA: return ',';
  1912. case VK_OEM_PERIOD: return '.';
  1913. case VK_OEM_PLUS: return '+';
  1914. case VK_OEM_MINUS: return '-';
  1915. default: return keysym;
  1916. }
  1917. #endif
  1918. }
  1919. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1920. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1921. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1922. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1923. // la_SaveEvent(hwnd, e, 0);
  1924. //}
  1925. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1926. e->type = type; e->x = x; e->y = y;
  1927. la_SaveEvent(hwnd, e, 0);
  1928. MAIN.evLastX=x; MAIN.evLastY=y;
  1929. };
  1930. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1931. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1932. e->type = type;
  1933. la_SaveEvent(hwnd, e, 1);
  1934. };
  1935. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1936. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1937. e->type = LA_SIGNAL_EVENT;
  1938. e->key = signal;
  1939. la_SaveEvent(hwnd, e, 1);
  1940. };
  1941. void la_SendPasteEvent(SYSWINDOW* hwnd) {
  1942. laEvent* e = memAcquireSimple(sizeof(laEvent));
  1943. e->type = LA_PASTE;
  1944. la_SaveEvent(hwnd, e, 1);
  1945. };
  1946. void la_SendOperatorEvent(SYSWINDOW* hwnd, laOperatorType* at, int use_base, char* instructions){
  1947. if(!at){ return; }
  1948. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1949. e->type = LA_OPERATOR_EVENT;
  1950. e->Operator = at; e->OperatorBase = use_base; e->OperatorInstructions = instructions;
  1951. la_SaveEvent(hwnd, e, 1);
  1952. };
  1953. void laRetriggerOperators(){
  1954. MAIN.ReTriggerOperators = 1;
  1955. }
  1956. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1957. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1958. }
  1959. void laSetCleanupCallback(laCleanupF Cleanup){
  1960. MAIN.Cleanup=Cleanup;
  1961. }
  1962. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1963. MAIN.InputProcess=InputProcess;
  1964. }
  1965. //====================================================================================================
  1966. laTheme *laDuplicateTheme(laTheme* from){
  1967. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1968. strSafePrint(&t->Name, "~%s", SSTR(from->Name));
  1969. lstPushItem(&MAIN.Themes, t);
  1970. MAIN.CurrentTheme = t;
  1971. char buf[32]; sprintf(buf,"LATHEME_%.22s",SSTR(t->Name));
  1972. laset_InstanceUID(t, buf);
  1973. tnsVectorSet3v(t->Color,from->Color);
  1974. tnsVectorSet3v(t->ColorB,from->ColorB);
  1975. tnsVectorSet3v(t->ColorC,from->ColorC);
  1976. tnsVectorSet3v(t->AccentColor,from->AccentColor);
  1977. tnsVectorSet3v(t->WarningColor,from->WarningColor);
  1978. t->InactiveMix=from->InactiveMix;
  1979. t->InactiveSaturation=from->InactiveSaturation;
  1980. t->CursorAlpha=from->CursorAlpha;
  1981. t->SelectionAlpha=from->SelectionAlpha;
  1982. t->ShadowAlpha=from->ShadowAlpha; t->TextShadowAlpha=from->TextShadowAlpha;
  1983. t->WireBrightness=from->WireBrightness;
  1984. t->WireSaturation=from->WireSaturation;
  1985. t->WireTransparency=from->WireTransparency;
  1986. t->EdgeBrightness=from->EdgeBrightness;
  1987. t->EdgeTransparency=from->EdgeTransparency;
  1988. t->VertexBrightness=from->VertexBrightness;
  1989. t->VertexTransparency=from->VertexTransparency;
  1990. t->SelectedFaceTransparency=from->SelectedFaceTransparency;
  1991. t->SelectedEdgeTransparency=from->SelectedEdgeTransparency;
  1992. t->SelectedVertexTransparency=from->SelectedVertexTransparency;
  1993. for(laBoxedTheme* bt=from->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1994. laBoxedTheme* new_bt = laDesignBoxedTheme(t,SSTR(bt->Name),bt->BackRef,bt->ColorSelection,
  1995. bt->NormalY,bt->ActiveY,bt->BorderY,bt->TextY,bt->TextActiveY,bt->Alpha,bt->BoxStyle,bt->TextShadow);
  1996. }
  1997. la_RefreshThemeColor(t);
  1998. return t;
  1999. }
  2000. void la_DestroyTheme(laTheme* t){
  2001. MAIN.CurrentTheme = t->Item.pPrev?t->Item.pPrev:t->Item.pNext;
  2002. lstRemoveItem(&MAIN.Themes, t);
  2003. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  2004. strSafeDestroy(&t->Name);
  2005. memFree(t);
  2006. }
  2007. laTheme *laDesignTheme(const char *Name){
  2008. laTheme *t = memAcquireHyper(sizeof(laTheme));
  2009. strSafeSet(&t->Name, Name);
  2010. lstPushItem(&MAIN.Themes, t);
  2011. MAIN.CurrentTheme = t;
  2012. char buf[32]; sprintf(buf,"LATHEME_%.22s",Name);
  2013. laset_InstanceUID(t, buf);
  2014. return t;
  2015. }
  2016. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef, int ColorSelection,
  2017. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  2018. int BoxStyle, int TextShadow){
  2019. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  2020. strSafeSet(&bt->Name, Name);
  2021. bt->ColorSelection = ColorSelection;
  2022. bt->NormalY=NormalY; bt->ActiveY=ActiveY; bt->BorderY=BorderY;
  2023. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  2024. bt->BoxStyle = BoxStyle; bt->TextShadow = TextShadow;
  2025. bt->BackRef = BackRef;
  2026. memAssignRef(bt, &bt->Parent, t);
  2027. lstAppendItem(&t->BoxedThemes, bt);
  2028. return bt;
  2029. }
  2030. laTheme *laGetTheme(const char *ThemeName){
  2031. laTheme *t = MAIN.Themes.pFirst;
  2032. for (t; t; t = t->Item.pNext){
  2033. if (strSame(t->Name->Ptr, ThemeName)) return t;
  2034. }
  2035. return 0;
  2036. }
  2037. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  2038. laTheme *t = MAIN.Themes.pFirst;
  2039. for (t; t; t = t->Item.pNext){
  2040. laBoxedTheme *bt;
  2041. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  2042. bt = t->BoxedThemes.pFirst;
  2043. for (bt; bt; bt = bt->Item.pNext){
  2044. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  2045. }
  2046. }
  2047. return 0;
  2048. }
  2049. real* laThemeColor(laBoxedTheme* bt, int which){
  2050. switch(which){
  2051. default:
  2052. case LA_BT_NORMAL: return bt->Normal;
  2053. case LA_UI_EDITING:
  2054. case LA_BT_ACTIVE: return bt->Active;
  2055. case LA_BT_BORDER: return bt->Border;
  2056. case LA_BT_TEXT|LA_BT_NO_DECAL: return bt->TextInvert;
  2057. case LA_BT_TEXT: return bt->Text;
  2058. case LA_BT_TEXT|LA_UI_EDITING:
  2059. case LA_BT_TEXT_ACTIVE: return bt->TextActive;
  2060. case LA_BT_DISABLED: return bt->Inactive;
  2061. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive;
  2062. }
  2063. return bt->Normal;
  2064. }
  2065. real* laAccentColor(int which){
  2066. switch(which){
  2067. default:
  2068. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  2069. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  2070. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  2071. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  2072. case LA_BT_FACE:
  2073. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  2074. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  2075. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  2076. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  2077. case LA_BT_SHADOW: return MAIN.CurrentTheme->ShadowColor;
  2078. case LA_BT_SHADOW|LA_BT_TEXT: return MAIN.CurrentTheme->TextShadowColor;
  2079. }
  2080. return MAIN.CurrentTheme->SelectionColor;
  2081. }
  2082. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  2083. real hcy[3]; if(!bt->Parent){ return; }
  2084. laTheme* th = bt->Parent; real* color = bt->ColorSelection==2?th->ColorC:(bt->ColorSelection==1?th->ColorB:th->Color);
  2085. tnsRGB2HCY(color,hcy);
  2086. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  2087. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  2088. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  2089. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  2090. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  2091. if(bt->NoDecalInvert){ hcy[2]=1.0f-bt->TextY; tnsHCY2RGB(hcy, bt->TextInvert); bt->TextInvert[3]=1.0f; }
  2092. else{ tnsVectorSet4v(bt->TextInvert,bt->Text); }
  2093. }
  2094. void la_RefreshThemeColorSelf(laTheme* th){
  2095. if((!th) || (!th->BoxedThemes.pFirst)) return;
  2096. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  2097. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  2098. real hcy[3], usehcy[3];
  2099. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  2100. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  2101. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  2102. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  2103. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  2104. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  2105. //tnsVectorCopy3d(th->Color, th->ShadowColor); th->ShadowColor[3]=th->CursorAlpha;
  2106. tnsVectorSet4(th->ShadowColor,0,0,0,th->ShadowAlpha);
  2107. tnsVectorSet4(th->TextShadowColor,0,0,0,th->TextShadowAlpha);
  2108. }
  2109. void la_RefreshThemeColor(laTheme* th){
  2110. if(!th) return;
  2111. real hcy[3], usehcy[3], normalhcy[3];
  2112. la_RefreshThemeColorSelf(th);
  2113. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  2114. la_RefreshBoxedThemeColor(bt);
  2115. (*bt->BackRef) = bt;
  2116. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  2117. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  2118. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  2119. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  2120. }
  2121. }
  2122. void laSetProofingLut(void* data, int which){
  2123. TNS_CLAMP(which,0,2);
  2124. MAIN.ProofingLUT[which]=data;
  2125. MAIN.LutNeedsRefreshing=1;
  2126. }
  2127. void la_RefreshProofingLut(){
  2128. if(!MAIN.CurrentWindow) return;
  2129. int table = MAIN.CurrentWindow->OutputColorSpace;
  2130. if(MAIN.CurrentLut != table+1){ MAIN.LutNeedsRefreshing=1; }
  2131. if(!MAIN.LutNeedsRefreshing) return;
  2132. tnsEnableShaderv(T->immShader);
  2133. tnsShader* s = T->immShader;
  2134. if(!MAIN.ProofingLUT[table] || !MAIN.CurrentWindow->OutputProofing){
  2135. return;
  2136. }
  2137. if(!MAIN.LutTexture) glGenTextures(1, &MAIN.LutTexture);
  2138. tnsActiveTexture(GL_TEXTURE3);
  2139. glBindTexture(GL_TEXTURE_3D, MAIN.LutTexture);
  2140. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  2141. glTexImage3D(GL_TEXTURE_3D,0,GL_RGB,LA_LUT_PRECISION,LA_LUT_PRECISION,LA_LUT_PRECISION,0,GL_RGB, GL_UNSIGNED_BYTE,MAIN.ProofingLUT[table]);
  2142. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  2143. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  2144. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  2145. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  2146. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  2147. //glBindTexture(GL_TEXTURE_3D,0);
  2148. tnsActiveTexture(GL_TEXTURE0);
  2149. MAIN.CurrentLut = table+1;
  2150. MAIN.LutNeedsRefreshing=0;
  2151. }
  2152. //I FUCKING HATE THIS STUPID FUNCTION
  2153. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH){
  2154. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2155. laUiListDrawItem *last = uild->Items.pFirst;
  2156. int LimW=_R-_L;
  2157. int SL, SR, SU, SB;
  2158. int Target__B = Target->B;
  2159. int Target__R = Target->R;
  2160. uildi->Target = Target;
  2161. // uildi->
  2162. // XP,YP total pan
  2163. // LRUB border after previous pan
  2164. // SLRUB border after clamping
  2165. // DifXY clamped distance
  2166. //
  2167. // why we still need this line
  2168. if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  2169. //if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  2170. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  2171. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  2172. uildi->L = last ? Target->L - last->XP : Target->L;
  2173. uildi->R = last ? Target__R - last->XP : Target__R;
  2174. uildi->U = last ? Target->U - last->YP : Target->U;
  2175. uildi->B = last ? Target__B - last->YP : Target__B;
  2176. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  2177. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2178. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2179. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2180. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2181. if(SL<_L) SL=_L;
  2182. if(SR>_R) SR=_R;
  2183. uildi->DifX = SL - uildi->L;
  2184. uildi->DifY = SU - uildi->U;
  2185. uildi->L = SL;
  2186. uildi->R = SR;
  2187. uildi->U = SU;
  2188. uildi->B = SB;
  2189. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  2190. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  2191. memFree(uildi);
  2192. return 0;
  2193. }
  2194. int Pad=2;
  2195. tnsViewportWithScissor(uildi->L-Pad, PanelH - uildi->B-Pad, uildi->R - uildi->L+Pad*2, uildi->B - uildi->U+Pad*2);
  2196. tnsOrtho(Target->L + Target->PanX + uildi->DifX-Pad,
  2197. Target->L + Target->PanX + uildi->DifX+Pad+ (uildi->R - uildi->L),
  2198. Target->U + Target->PanY + uildi->DifY+Pad+ (uildi->B - uildi->U),
  2199. Target->U + Target->PanY + uildi->DifY-Pad,
  2200. -100, 100);
  2201. lstPushItem(&uild->Items, uildi);
  2202. return 1;
  2203. }
  2204. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  2205. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2206. laUiListDrawItem *last = uild->Items.pFirst;
  2207. int SL, SR, SU, SB;
  2208. if (B - U > LimH) B = U + LimH;
  2209. uildi->XP = last ? last->XP + PanX : PanX;
  2210. uildi->YP = last ? last->YP + PanY : PanY;
  2211. uildi->L = last ? L - last->XP : L;
  2212. uildi->R = last ? R - last->XP : R;
  2213. uildi->U = last ? U - last->YP : U;
  2214. uildi->B = last ? B - last->YP : B;
  2215. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2216. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2217. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2218. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2219. uildi->DifX = SL - uildi->L;
  2220. uildi->DifY = SU - uildi->U;
  2221. uildi->L = SL;
  2222. uildi->R = SR;
  2223. uildi->U = SU;
  2224. uildi->B = SB;
  2225. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2226. tnsOrtho(L + PanX + uildi->DifX,
  2227. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  2228. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2229. U + PanY + uildi->DifY,
  2230. -100, 100);
  2231. lstPushItem(&uild->Items, uildi);
  2232. }
  2233. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2234. int* savel, int* saver, int* saveu, int* saveb){
  2235. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2236. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2237. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2238. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2239. real x,y,w,h;
  2240. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2241. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2242. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2243. }
  2244. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2245. laUiListDrawItem *uildi = uild->Items.pFirst;
  2246. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2247. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2248. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2249. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2250. Target->U + Target->PanY + uildi->DifY -1,
  2251. -100, 100);
  2252. }
  2253. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2254. laUiListDrawItem *uildi = lstPopItem(uild);
  2255. laUiList *Target;
  2256. memFree(uildi);
  2257. uildi = uild->Items.pFirst;
  2258. if (!uildi || !uildi->Target){
  2259. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2260. return;
  2261. }
  2262. Target = uildi->Target;
  2263. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2264. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2265. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2266. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2267. Target->U + Target->PanY + uildi->DifY -1,
  2268. -100, 100);
  2269. }
  2270. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2271. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2272. uildi->L = L;
  2273. uildi->R = R;
  2274. uildi->U = U;
  2275. uildi->B = B;
  2276. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2277. tnsOrtho(L, R, B, U, -100, 100);
  2278. lstPushItem(&uild->Items, uildi);
  2279. }
  2280. void la_ClearUiListMatrix(laUiListDraw *uild){
  2281. laUiListDrawItem *uildi;
  2282. while (uildi = lstPopItem(uild)){
  2283. memFree(uildi);
  2284. }
  2285. }
  2286. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2287. int la_DrawUiListRecursive(laUiListDraw *uild, laUiList *uil, int L, int R, int U, int B, int LimH, int ConditionStackLevel, int RegisterNodes);
  2288. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2289. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayedH, int UiR, int BarTop, int BarBottom);
  2290. int la_TestUiListMinumWidth(laUiList *uil);
  2291. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2292. if (ui){
  2293. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2294. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2295. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2296. p->X = p->TX; p->Y = p->TY;
  2297. p->W = p->TW;
  2298. }
  2299. }
  2300. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2301. int cw = MAIN.CurrentWindow->CW;
  2302. int ch = MAIN.CurrentWindow->CH;
  2303. int PH = p->TH;
  2304. laBoxedTheme*bt = *p->BT;
  2305. int uih=uil->B + LA_M;
  2306. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2307. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2308. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2309. else p->TH = PH;
  2310. p->H = p->TH;
  2311. if(p->BoundUi){
  2312. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2313. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2314. if (p->X < 0) p->X = 0;
  2315. if (p->Y < 0) p->Y = 0;
  2316. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2317. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2318. }else{
  2319. if (p->Y < 0) p->Y = 0;
  2320. if ((!p->Block)&&(!p->IsMenuPanel)){
  2321. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2322. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2323. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2324. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2325. }
  2326. }
  2327. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE) && (!p->Block)){
  2328. if(p->W<LA_RH*3) p->W=LA_RH*3;
  2329. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2330. }
  2331. if (p->ST) p->TY = p->ST;
  2332. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2333. if (p->SB) p->TH = ch - p->TY - p->SB;
  2334. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2335. p->TX = p->X; p->TY = p->Y;
  2336. p->TW = p->W; p->TH = p->H;
  2337. }
  2338. void laPlacePanelForCreation(laPanel *p){
  2339. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2340. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2341. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2342. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2343. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2344. p->TX=p->X; p->TY=p->Y;
  2345. }
  2346. }
  2347. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2348. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2349. tnsViewportWithScissor(0, 0, p->W, p->H);
  2350. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2351. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2352. }
  2353. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2354. tnsDrawToScreen();
  2355. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2356. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2357. }
  2358. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2359. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2360. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2361. }
  2362. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2363. real* color=laThemeColor(bt,LA_BT_NORMAL);
  2364. glClearColor(LA_COLOR3(color), p->Block?1.0f:color[3]);
  2365. tnsClearAll();
  2366. if(bt->BoxStyle==-1){ tnsUseNoTexture(); tnsColor4dv(laAccentColor(LA_BT_SHADOW)); la_DrawInnerShadow(0,p->W,0,p->H); }
  2367. }
  2368. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt);
  2369. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2370. real Color[] = {1, 1, 1, 1};
  2371. real L, W, U, H;
  2372. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2373. if(MAIN.EnableColorManagement){
  2374. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2375. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2376. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2377. }else{
  2378. tnsUniformOutputColorSpace(T->immShader,0);
  2379. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2380. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2381. }
  2382. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2383. tnsUseNoTexture();
  2384. if (!p->IsMenuPanel){
  2385. la_PanelDrawDescendBorder(p, (*p->BT));
  2386. }
  2387. tnsFlush();
  2388. }
  2389. if(p->ParentOperator){
  2390. tnsUseNoTexture();
  2391. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2392. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2393. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2394. }
  2395. switch (p->AnimationMode){
  2396. case 0: /* and */
  2397. case LA_PANEL_ANIMATION_FLASH:
  2398. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2399. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2400. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2401. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2402. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2403. tnsPackAs(GL_TRIANGLES);
  2404. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2405. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2406. }
  2407. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2408. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2409. if((int)(p->AnimationRatio*6)%2){
  2410. tnsUseNoTexture();
  2411. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2412. 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);
  2413. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2414. }
  2415. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2416. }
  2417. break;
  2418. case LA_PANEL_ANIMATION_DROP_DOWN:
  2419. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2420. tnsDraw2DTextureArg(
  2421. p->OffScr->pColor[0],
  2422. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2423. Color,
  2424. 0, 0, 1 - p->AnimationRatio, 0);
  2425. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2426. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2427. break;
  2428. case LA_PANEL_ANIMATION_EXPAND:
  2429. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2430. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2431. W = tnsLinearItp(0, p->W, 0.4);
  2432. H = tnsLinearItp(0, p->H, 0.4);
  2433. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2434. tnsDraw2DTextureArg(
  2435. p->OffScr->pColor[0],
  2436. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2437. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2438. Color,
  2439. 0, 0, 0, 0);
  2440. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2441. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2442. break;
  2443. case LA_PANEL_ANIMATION_DISSOVE:
  2444. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2445. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2446. W = tnsLinearItp(0, p->W, 1.4);
  2447. H = tnsLinearItp(0, p->H, 1.4);
  2448. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2449. if (p->OffScr) tnsDraw2DTextureArg(
  2450. p->OffScr->pColor[0],
  2451. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2452. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2453. Color,
  2454. 0, 0, 0, 0);
  2455. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2456. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2457. break;
  2458. case LA_PANEL_ANIMATION_COLLAPSE:
  2459. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2460. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2461. W = tnsLinearItp(0, p->W, 0.4);
  2462. H = tnsLinearItp(0, p->H, 0.4);
  2463. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2464. if (p->OffScr) tnsDraw2DTextureArg(
  2465. p->OffScr->pColor[0],
  2466. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2467. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2468. Color,
  2469. 0, 0, 0, 0);
  2470. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2471. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2472. break;
  2473. case LA_PANEL_ANIMATION_MINIMIZE:
  2474. L = tnsLinearItp(0, p->X, 0.3);
  2475. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2476. W = tnsLinearItp(0, p->W, 0.4);
  2477. H = tnsLinearItp(0, p->H, 0.4);
  2478. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2479. tnsDraw2DTextureArg(
  2480. p->OffScr->pColor[0],
  2481. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2482. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2483. Color,
  2484. 0, 0, 0, 0);
  2485. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2486. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2487. break;
  2488. }
  2489. tnsFlush();
  2490. tnsUniformOutputColorSpace(T->immShader,0);
  2491. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2492. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2493. }
  2494. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2495. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2496. else{
  2497. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:LA_PANEL_DEFAULT_GL_FORMAT;
  2498. if(p->MenuRefer && (p->MenuRefer->Flags&LA_UI_FLAGS_MENU_FLOAT16)){ GLFormat=GL_RGBA16F; }
  2499. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2500. }
  2501. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2502. }
  2503. void la_PanelRefreshDetachedProp(laPanel *panel){
  2504. laProp *p;
  2505. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2506. la_StepPropPack(&p->DetachedPP);
  2507. la_UsePropPack(&p->DetachedPP, 0);
  2508. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2509. // laUseDataBlock(
  2510. // p->DetachedPP.LastPs->UseInstance,
  2511. // p->DetachedPP.LastPs->p,
  2512. // MAIN.PropMatcherContextP->FrameDistinguish,
  2513. // MAIN.PropMatcherContextP,
  2514. // la_PropPanelUserRemover, 0);
  2515. //}
  2516. }
  2517. }
  2518. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt){
  2519. real* color=laThemeColor(bt,LA_BT_BORDER);
  2520. real* shadow=laAccentColor(LA_BT_SHADOW);
  2521. int sw=LA_SHADOW_W;
  2522. tnsColor4d(LA_COLOR3(shadow),shadow[3]);
  2523. la_DrawOuterShadowLength(Panel->X,Panel->X+Panel->W,Panel->Y,Panel->Y+Panel->H,sw*2);
  2524. tnsColor4d(LA_COLOR3(shadow),shadow[3]*0.5);
  2525. la_DrawOuterShadowLength(Panel->X+sw*2,Panel->X+Panel->W+sw*2,Panel->Y+sw*2,Panel->Y+Panel->H+sw*2,sw*2);
  2526. tnsColor4d(LA_COLOR3(shadow),shadow[3]*0.25);
  2527. la_DrawOuterShadowLength(Panel->X+sw*4,Panel->X+Panel->W+sw*4,Panel->Y+sw*4,Panel->Y+Panel->H+sw*4,sw*2);
  2528. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2529. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2530. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2531. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2532. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2533. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2534. }
  2535. int la_AnimateUiListRecursive(laUiList *uil);
  2536. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2537. int DrawState_ = 0;
  2538. laUiListDraw uild = {0}; int orig_refresh=p->Refresh;
  2539. if (p->Show){
  2540. la_SetPropMathcerContext(p);
  2541. MAIN.CurrentPanel = p;
  2542. if (p->Refresh & LA_TAG_RECALC){
  2543. laRecalcPanelImmediate(p);
  2544. }
  2545. if (!p->MenuRefer){
  2546. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2547. if (p->Refresh || !p->OffScr){
  2548. la_PanelDrawToOffsceen(p, &p->UI);
  2549. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2550. la_PanelBackgroundInit(p, bt);
  2551. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2552. tnsUniformOutputColorSpace(T->immShader,0);
  2553. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2554. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2555. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2556. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-extrap, p->W, p->UI.U+LA_M,p->H-LA_M*2);
  2557. tnsFlush();
  2558. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2559. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2560. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2561. DrawState_++;
  2562. }
  2563. if(p->UI.PanY && p->UI.B-p->UI.PanY < p->H - LA_M){
  2564. p->UI.PanY = (p->UI.B-p->H+LA_M);
  2565. if(p->UI.PanY<0){p->UI.PanY=0;}
  2566. DrawState_++;
  2567. }
  2568. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2569. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2570. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2571. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2572. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2573. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0);
  2574. if(p!=w->MaximizedUiPanel){
  2575. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0);
  2576. }else{
  2577. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2578. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2579. LA_M,p->W-LA_M,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2580. tnsFlush();
  2581. }
  2582. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2583. }
  2584. }else{
  2585. if (p->Refresh || !p->OffScr){
  2586. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2587. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2588. la_PanelBackgroundInit(p, bt);
  2589. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2590. p->MenuRefer->B-p->MenuRefer->U-LA_M*2, p->H-LA_M*3, p->W, p->MenuRefer->U+LA_M,p->H-LA_M*2);
  2591. tnsFlush();
  2592. if(((p->MenuRefer->TB>p->H-LA_M) && (!p->MenuRefer->ScrollerShownV))||
  2593. ((p->MenuRefer->TB<=p->H-LA_M) && p->MenuRefer->ScrollerShownV)){
  2594. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2595. DrawState_++;
  2596. }
  2597. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-LA_M){
  2598. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-LA_M);
  2599. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2600. DrawState_++;
  2601. }
  2602. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2603. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2604. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2605. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0);
  2606. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2607. }
  2608. }
  2609. tnsDrawToScreen();
  2610. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2611. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2612. la_PanelDrawToWindow(p, w);
  2613. }elif (p->AnimationMode){
  2614. la_PanelDrawToWindow(p, w);
  2615. }
  2616. laPerfRecord("%s [%s]",(orig_refresh&LA_TAG_RECALC)?"🌑":
  2617. ((orig_refresh&LA_TAG_REDRAW)?"🌓":
  2618. ((orig_refresh&LA_TAG_ANIMATION)?"🌔":"🌕")), SSTR(p->Title));
  2619. }
  2620. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2621. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2622. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2623. laPanel *pi, *PrevPI;
  2624. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2625. PrevPI = pi->Item.pPrev;
  2626. if (pi->AnimationMode && pi->LaterDestroy){
  2627. lstRemoveItem(&p->SubPanels, pi);
  2628. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2629. continue;
  2630. }
  2631. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2632. la_AttachedPanelDefDraw(w,pi,bt);
  2633. }
  2634. }
  2635. }
  2636. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2637. real PanelSquare[] = {
  2638. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2639. b->X + 2, CH - (b->Y + b->H - 4),
  2640. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2641. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2642. real Center[] = {
  2643. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2644. real DraggingPlot[] = {
  2645. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2646. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2647. PanelSquare[0],
  2648. PanelSquare[1],
  2649. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2650. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2651. PanelSquare[2],
  2652. PanelSquare[3],
  2653. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2654. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2655. PanelSquare[4],
  2656. PanelSquare[5],
  2657. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2658. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2659. PanelSquare[6],
  2660. PanelSquare[7],
  2661. };
  2662. real Square[] = {
  2663. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2664. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2665. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2666. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2667. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2668. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2669. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2670. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2671. };
  2672. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2673. LA_COLOR3(BorderColor4dV), 0,
  2674. LA_COLOR3(BorderColor4dV), 0.8,
  2675. LA_COLOR3(BorderColor4dV), 0,
  2676. LA_COLOR3(BorderColor4dV), 0.8,
  2677. LA_COLOR3(BorderColor4dV), 0,
  2678. LA_COLOR3(BorderColor4dV), 0.8,
  2679. LA_COLOR3(BorderColor4dV), 0,
  2680. };
  2681. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2682. LA_COLOR3(FillColor4dv), 0,
  2683. LA_COLOR3(FillColor4dv), 0.8,
  2684. LA_COLOR3(FillColor4dv), 0,
  2685. LA_COLOR3(FillColor4dv), 0.8,
  2686. LA_COLOR3(FillColor4dv), 0,
  2687. LA_COLOR3(FillColor4dv), 0.8,
  2688. LA_COLOR3(FillColor4dv), 0,
  2689. };
  2690. tnsUseNoTexture();
  2691. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2692. int Index[4];
  2693. tnsVertexArray2d(DraggingPlot, 8);
  2694. tnsColorArray4d(FillColor, 8);
  2695. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2696. case 0:
  2697. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2698. break;
  2699. case LA_BLOCK_DROP_LOCATION_L:
  2700. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2701. break;
  2702. case LA_BLOCK_DROP_LOCATION_R:
  2703. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2704. break;
  2705. case LA_BLOCK_DROP_LOCATION_U:
  2706. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2707. break;
  2708. case LA_BLOCK_DROP_LOCATION_B:
  2709. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2710. break;
  2711. }
  2712. //glDisable(GL_CULL_FACE);
  2713. tnsIndexArray(Index, 4);
  2714. tnsPackAs(GL_TRIANGLE_FAN);
  2715. //tnsFlush();
  2716. }
  2717. tnsVertexArray2d(DraggingPlot, 8);
  2718. tnsColorArray4d(PlotColor, 8);
  2719. tnsPackAs(GL_LINES);
  2720. tnsVertexArray2d(Square, 4);
  2721. tnsColor4dv(BorderColor4dV);
  2722. tnsPackAs(GL_LINE_LOOP);
  2723. glLineWidth(LA_SEAM_W);
  2724. tnsFlush();
  2725. glLineWidth(1);
  2726. }
  2727. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2728. laBoxedTheme *bt = _LA_THEME_TAB;
  2729. laPanel *p;
  2730. real v[] = {
  2731. b->X, CH - b->Y,
  2732. b->X + LA_SEAM_W, CH - b->Y ,
  2733. b->X, CH - (b->Y + b->H),
  2734. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2735. b->X + b->W, CH - (b->Y + b->H),
  2736. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2737. b->X + b->W, CH - b->Y,
  2738. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2739. real ratio = 1.0001f;
  2740. int tw = 0;
  2741. int L = LA_RH+LA_SEAM_W;
  2742. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2743. if(MAIN.EnableColorManagement){
  2744. laWindow* w=MAIN.CurrentWindow;
  2745. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2746. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2747. }else{
  2748. tnsUniformOutputColorSpace(T->immShader,0);
  2749. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2750. }
  2751. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2752. tw += p->TitleWidth + LA_SEAM_W*2;
  2753. }
  2754. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2755. real* cactive=laThemeColor(bt,LA_BT_ACTIVE);
  2756. real* cborder=laThemeColor(bt,LA_BT_BORDER);
  2757. tnsUseNoTexture();
  2758. tnsColor4d(LA_COLOR3(cactive),1);
  2759. tnsVertexArray2d(v, 8);
  2760. tnsPackAs(GL_TRIANGLE_STRIP);
  2761. int TitleGap=b->Folded?0:LA_RH;
  2762. tnsColor4d(LA_COLOR3(cactive),1);
  2763. la_DrawBox(b->X, b->X+b->W, CH-b->Y, CH-b->Y-TitleGap);
  2764. tnsColor4d(LA_COLOR3(cborder),1);
  2765. la_DrawBox(b->X+LA_SEAM_W, b->X+b->W-LA_SEAM_W, CH-b->Y-TitleGap, CH-b->Y-TitleGap-LA_SEAM_W);
  2766. if(b->Folded){ return; }
  2767. int LT=0,RT=0;
  2768. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2769. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2770. if (p == b->CurrentPanel){
  2771. tnsUseNoTexture();
  2772. tnsColor4d(LA_COLOR3(cborder),1);
  2773. la_DrawBox(b->X+L+LT*ratio, b->X+L+RT*ratio, CH-b->Y, CH-b->Y-LA_RH);
  2774. 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);
  2775. }else{
  2776. 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);
  2777. }
  2778. LT =RT;
  2779. }
  2780. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2781. tnsFlush();
  2782. tnsUniformOutputColorSpace(T->immShader,0);
  2783. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2784. }
  2785. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2786. laBoxedTheme *bt = _LA_THEME_PANEL;
  2787. real tv[8];
  2788. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2789. if(MAIN.EnableColorManagement){
  2790. laWindow* w=MAIN.CurrentWindow;
  2791. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2792. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2793. }else{
  2794. tnsUniformOutputColorSpace(T->immShader,0);
  2795. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2796. }
  2797. tnsUseNoTexture();
  2798. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2799. b->X + b->W, (CH - b->Y),
  2800. b->X + b->W, (CH - b->Y-b->H),
  2801. b->X, (CH - b->Y-b->H));
  2802. tnsVertexArray2d(tv, 4);
  2803. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2804. tnsPackAs(GL_TRIANGLE_FAN);
  2805. 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,
  2806. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2807. tnsFlush();
  2808. tnsUniformOutputColorSpace(T->immShader,0);
  2809. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2810. }
  2811. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2812. if (b->B1){
  2813. la_BlockDefDrawRecursive(w, bt, b->B1);
  2814. la_BlockDefDrawRecursive(w, bt, b->B2);
  2815. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2816. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2817. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2818. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2819. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2820. la_BlockDefDrawSelf(b, w->CH);
  2821. }else{
  2822. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2823. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2824. la_BlockDefDrawSelfEmpty(b, w->CH);
  2825. }
  2826. laLayout* l=MAIN.CurrentWindow->CurrentLayout;
  2827. if(b==l->HeaderBlock){
  2828. tnsUseNoTexture(); real tv[8]; int YOffset=0;
  2829. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL; int MenuHeight=(LA_M+LA_M)*2+LA_RH;
  2830. if(b->Y<MenuHeight+LA_SEAM_W){ YOffset=LA_SEAM_W; }
  2831. tnsMakeQuad2d(tv, b->X, (w->CH-(b->Y-LA_SEAM_W))-YOffset,
  2832. b->X+b->W, (w->CH-(b->Y-LA_SEAM_W))-YOffset,
  2833. b->X+b->W, (w->CH-(b->Y+LA_SEAM_W))-YOffset,
  2834. b->X, (w->CH-(b->Y+LA_SEAM_W))-YOffset);
  2835. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2836. tnsVertexArray2d(tv, 4);
  2837. tnsPackAs(GL_TRIANGLE_FAN);
  2838. if(l->IsBlockHeaderClicked && (!l->IsMoving)){
  2839. char* Hint=transLate("Double-click to expand 🖱");
  2840. int Width = tnsStringGetWidth(Hint,0,0)+LA_M*2;
  2841. int UseL=l->LastX-Width-LA_RH; UseL=TNS_MAX2(UseL,b->X);
  2842. tnsMakeQuad2d(tv, UseL, w->CH-b->Y,
  2843. UseL+Width, w->CH-b->Y,
  2844. UseL+Width, w->CH-b->Y-LA_RH,
  2845. UseL, w->CH-b->Y-LA_RH);
  2846. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2847. tnsVertexArray2d(tv, 4);
  2848. tnsPackAs(GL_TRIANGLE_FAN);
  2849. tnsDrawStringAuto(Hint,laThemeColor(_LA_THEME_TAB,LA_BT_TEXT_ACTIVE),UseL+LA_M,UseL+Width,w->CH-b->Y,LA_TEXT_REVERT_Y);
  2850. }
  2851. }elif(b==l->MovingBlock){
  2852. tnsUseNoTexture();
  2853. int at; real tv[8];
  2854. if (b->Vertical){
  2855. at = b->H * b->SplitRatio + b->Y;
  2856. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2857. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2858. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2859. b->X, (w->CH - at - LA_SEAM_W));
  2860. }else{
  2861. at = b->X + b->W * b->SplitRatio;
  2862. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2863. at- LA_SEAM_W, (w->CH - b->Y),
  2864. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2865. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2866. }
  2867. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2868. tnsVertexArray2d(tv, 4);
  2869. tnsPackAs(GL_TRIANGLE_FAN);
  2870. }
  2871. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2872. tnsFlush();
  2873. }
  2874. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2875. if (b->B1){
  2876. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2877. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2878. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2879. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2880. }
  2881. tnsFlush();
  2882. }
  2883. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2884. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2885. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2886. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2887. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2888. if(p->OffScr){
  2889. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2890. }
  2891. }
  2892. }
  2893. void la_ClearUnusedFramebuffers(laWindow* w){
  2894. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2895. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2896. }
  2897. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2898. if(p->Show || p->AnimationMode) continue;
  2899. if(p->OffScr){
  2900. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2901. }
  2902. }
  2903. }
  2904. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2905. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2906. laPanel *p, *NextP;
  2907. laLayout *l = w->CurrentLayout;
  2908. if (!w->CH || !w->CW) return;
  2909. la_ClearUnusedFramebuffers(w);
  2910. tnsDrawToScreen();
  2911. la_RefreshProofingLut();
  2912. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2913. glClearColor(0.2, 0.2, 0.3, 1.0);
  2914. tnsClearAll();
  2915. tnsUseNoTexture();
  2916. if (l->Draw) l->Draw(w, l);
  2917. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2918. glEnable(GL_BLEND);
  2919. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2920. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2921. laUiItem* ui;
  2922. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2923. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2924. la_SetPropMathcerContext(p);
  2925. if(p->Refresh){
  2926. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2927. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2928. if(MAIN.EnableColorManagement){
  2929. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2930. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2931. }else{
  2932. tnsUniformOutputColorSpace(T->immShader,0);
  2933. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2934. }
  2935. if(p->Refresh&LA_TAG_RECALC){
  2936. laRecalcPanelImmediate(p);
  2937. }
  2938. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2939. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2940. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2941. }
  2942. tnsDrawToScreen();
  2943. tnsResetViewMatrix();
  2944. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2945. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2946. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2947. tnsFlush();
  2948. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2949. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2950. tnsFlush();
  2951. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0);
  2952. }
  2953. }
  2954. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2955. la_AttachedPanelDefDraw(w,p,*p->BT);
  2956. }else{
  2957. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2958. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2959. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2960. }
  2961. for (p = w->Panels.pLast; p; p = NextP){
  2962. NextP = p->Item.pPrev;
  2963. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2964. if (p->AnimationMode && p->LaterDestroy){
  2965. lstRemoveItem(&w->Panels, p);
  2966. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2967. continue;
  2968. }
  2969. la_PanelDefDraw(w, p, *p->BT);
  2970. }
  2971. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2972. la_AttachedPanelDefDraw(w,p,*p->BT);
  2973. }
  2974. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2975. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2976. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2977. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2978. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2979. tnsFlush();
  2980. }
  2981. for (p = w->FadingPanels.pLast; p; p = NextP){
  2982. NextP = p->Item.pPrev;
  2983. if (!p->AnimationMode){
  2984. lstRemoveItem(&w->FadingPanels, p);
  2985. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2986. laDeferredDestroyPanel(p, 0);
  2987. }else
  2988. la_PanelDrawToWindow(p, w);
  2989. }
  2990. if(MAIN.ShowPerf){
  2991. la_PerfDraw();
  2992. }
  2993. }
  2994. void laStartWindow(laWindow *w){
  2995. #ifdef LA_LINUX
  2996. XMapWindow(MAIN.dpy,w->win);
  2997. tnsContextMakeWindowCurrent(w);
  2998. #endif
  2999. #ifdef _WIN32
  3000. ShowWindow(w->win, SW_SHOWNORMAL);
  3001. #endif
  3002. MAIN.CurrentWindow = w;
  3003. if(!w->CurrentLayout){
  3004. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  3005. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  3006. }
  3007. laRedrawCurrentWindow();
  3008. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  3009. w->Shown = 1;
  3010. }
  3011. void la_AssignWindowPP(laWindow* w){
  3012. w->PP.EndInstance = w;
  3013. w->PP.LastPs = &w->FakePS;
  3014. w->PP.LastPs->p = _LA_PROP_WINDOW;
  3015. w->PP.LastPs->UseInstance = w;
  3016. w->PP.LastPs->Type = U'.';
  3017. }
  3018. laWindow *laDesignWindow(int X, int Y, int W, int H){
  3019. #ifdef LAGUI_ANDROID
  3020. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  3021. #endif
  3022. laWindow *n = memAcquire(sizeof(laWindow));
  3023. strSafeSet(&n->Title, "Empty SYSWINDOW");
  3024. n->X = X; n->Y = Y; n->W = W; n->H = H;
  3025. #ifdef LAGUI_ANDROID
  3026. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  3027. #endif
  3028. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  3029. lstAppendItem(&MAIN.Windows, n);
  3030. MAIN.CurrentWindow = n;
  3031. la_AssignWindowPP(n);
  3032. laui_DefaultMenuBar(n);
  3033. return n;
  3034. }
  3035. void laSetWindowCursor(int id){
  3036. MAIN.CurrentCursor = id;
  3037. #ifdef LA_LINUX
  3038. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  3039. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  3040. #endif
  3041. #ifdef _WIN32
  3042. SetCursor(la_ConvertCursorID(id));
  3043. #endif
  3044. };
  3045. void la_AssignBlockPP(laBlock* b){
  3046. b->PP.EndInstance = b;
  3047. b->PP.LastPs = &b->FakePS;
  3048. b->PP.LastPs->p = _LA_PROP_BLOCK;
  3049. b->PP.LastPs->UseInstance = b;
  3050. b->PP.LastPs->Type = U'.';
  3051. }
  3052. void laDestroyLayout(laWindow *w, laLayout* l){
  3053. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  3054. laDestroyBlocksRecursive(l->FirstBlock);
  3055. strSafeDestroy(&l->ID);
  3056. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  3057. lstRemoveItem(&w->Layouts,l); memFree(l);
  3058. }
  3059. laLayout *laDesignLayout(laWindow *w, char *Title){
  3060. laLayout *l = memAcquire(sizeof(laLayout));
  3061. l->FirstBlock = memAcquire(sizeof(laBlock));
  3062. la_AssignBlockPP(l->FirstBlock);
  3063. lstAppendItem(&w->Layouts, l);
  3064. strSafeSet(&l->ID, Title);
  3065. memAssignRef(w, &w->CurrentLayout, l);
  3066. laRenameWindow(w, Title);
  3067. return l;
  3068. }
  3069. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  3070. void laUnfoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=0; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  3071. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  3072. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  3073. laNotifyUsers("la.windows.maximized_block"); }
  3074. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  3075. laNotifyUsers("la.windows.maximized_block"); }
  3076. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  3077. laRestoreCanvasUI();
  3078. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  3079. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  3080. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  3081. UiParentPanel->Show=0;
  3082. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  3083. }
  3084. void laRestoreCanvasUI(){
  3085. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  3086. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  3087. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  3088. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  3089. }
  3090. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  3091. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  3092. }
  3093. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  3094. void laSplitBlockHorizon(laBlock *b, real Percentage){
  3095. laPanel *p;
  3096. b->SplitRatio = Percentage;
  3097. b->Vertical = 0;
  3098. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  3099. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  3100. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3101. p->Block = b->B1;
  3102. }
  3103. b->B1->Panels.pFirst = b->Panels.pFirst;
  3104. b->B1->Panels.pLast = b->Panels.pLast;
  3105. b->B1->CurrentPanel = b->CurrentPanel;
  3106. b->B1->parent = b->B2->parent=b;
  3107. b->Panels.pFirst = 0;
  3108. b->Panels.pLast = 0;
  3109. b->CurrentPanel = 0;
  3110. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3111. }
  3112. void laSplitBlockVertical(laBlock *b, real Percentage){
  3113. laPanel *p;
  3114. b->SplitRatio = Percentage;
  3115. b->Vertical = 1;
  3116. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  3117. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  3118. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3119. p->Block = b->B1;
  3120. }
  3121. b->B1->Panels.pFirst = b->Panels.pFirst;
  3122. b->B1->Panels.pLast = b->Panels.pLast;
  3123. b->B1->CurrentPanel = b->CurrentPanel;
  3124. b->B1->parent = b->B2->parent=b;
  3125. b->Panels.pFirst = 0;
  3126. b->Panels.pLast = 0;
  3127. b->CurrentPanel = 0;
  3128. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3129. }
  3130. void laCombineChildBlocks(laBlock *b){
  3131. laPanel *p; if(!b) return;
  3132. if (!b->B1->B1 && !b->B2->B1){
  3133. lstCombineLists(&b->Panels, &b->B1->Panels);
  3134. lstCombineLists(&b->Panels, &b->B2->Panels);
  3135. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3136. p->Block = b;
  3137. }
  3138. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  3139. memFree(b->B1);
  3140. memFree(b->B2);
  3141. b->B1 = 0;
  3142. b->B2 = 0;
  3143. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3144. }elif(!b->B1->B1){
  3145. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  3146. b->Vertical = b->B2->Vertical;
  3147. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  3148. p->Block = b1;
  3149. }
  3150. lstCombineLists(&b1->Panels, &b->B1->Panels);
  3151. memFree(b->B1); memFree(b->B2);
  3152. b->B1 = b1; b->B2 = b2;
  3153. b1->parent = b; b2->parent = b;
  3154. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3155. }elif(!b->B2->B1){
  3156. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  3157. b->Vertical = b->B1->Vertical;
  3158. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  3159. p->Block = b1;
  3160. }
  3161. lstCombineLists(&b1->Panels, &b->B2->Panels);
  3162. memFree(b->B1); memFree(b->B2);
  3163. b->B1 = b1; b->B2 = b2;
  3164. b1->parent = b; b2->parent = b;
  3165. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3166. }
  3167. }
  3168. laBlock *laBlock1(laBlock *b){
  3169. return b->B1;
  3170. }
  3171. laBlock *laBlock2(laBlock *b){
  3172. return b->B2;
  3173. }
  3174. void laSwapSubBlocks(laBlock *b){
  3175. laBlock *tB;
  3176. tB = b->B2;
  3177. b->B2 = b->B1;
  3178. b->B1 = tB;
  3179. b->SplitRatio = 1 - b->SplitRatio;
  3180. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3181. }
  3182. void laDestroyBlocksRecursive(laBlock *Root){
  3183. laPanel *p;
  3184. if (Root->B1){
  3185. laDestroyBlocksRecursive(Root->B1);
  3186. laDestroyBlocksRecursive(Root->B2);
  3187. }else{
  3188. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  3189. }
  3190. memFree(Root);
  3191. }
  3192. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  3193. if(!b->CurrentPanel ) return 0;
  3194. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  3195. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  3196. lstRemoveItem(&b->Panels, p);
  3197. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  3198. if(!p->TitleBar.UiItems.pFirst){
  3199. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  3200. }
  3201. p->Mode = LA_PANEL_FLOATING_TOP;
  3202. p->TY-=LA_RH; p->TH+=LA_RH;
  3203. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  3204. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  3205. p->Block = 0;
  3206. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  3207. laRecalcPanel(p);
  3208. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3209. p->BT = &_LA_THEME_FLOATING_PANEL;
  3210. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3211. laNotifyUsers("la.windows.panels");
  3212. return b->CurrentPanel;
  3213. }
  3214. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  3215. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  3216. lstRemoveItem(&from->Panels, p);
  3217. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3218. p->Mode = LA_PANEL_NORMAL;
  3219. p->Block=b;
  3220. b->CurrentPanel = p;
  3221. b->Folded = 0;
  3222. lstPushItem(&b->Panels, p);
  3223. laRecalcPanel(p);
  3224. p->BT = &_LA_THEME_PANEL;
  3225. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3226. tnsFlush();
  3227. laNotifyUsers("la.windows.panels");
  3228. }
  3229. void laPopPanel(laPanel *p){
  3230. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  3231. lstRemoveItem(&p->Parent->SubPanels, p);
  3232. lstPushItem(&p->Parent->SubPanels, p);
  3233. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3234. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3235. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3236. laNotifyUsers("la.windows.panels");
  3237. }
  3238. }
  3239. void la_EnsurePanelExtras(laPanel *p){
  3240. laUiTemplate* uit=p->PanelTemplate;
  3241. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  3242. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  3243. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  3244. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  3245. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  3246. p->PropLinkFakeProp->Base.Offset = 0;
  3247. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  3248. p->PropLinkPP.EndInstance = p;
  3249. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3250. p->PropLinkPP.LastPs->Type = U'.';
  3251. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3252. }
  3253. laPanel* la_GivePanelNode(){
  3254. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3255. return memAcquire(sizeof(laPanel));
  3256. }
  3257. void la_ReturnPanelNode(laPanel* p){
  3258. memset(p,0,sizeof(laPanel));
  3259. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3260. lstAppendItem(&MAIN.WastedPanels, p);
  3261. }
  3262. 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){
  3263. laPanel *p = la_GivePanelNode();
  3264. int CW = MAIN.CurrentWindow->CW;
  3265. int CH = MAIN.CurrentWindow->CH;
  3266. p->PanelTemplate = uit;
  3267. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3268. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3269. if (!MaxW) MaxW = 10000;
  3270. if (!MaxH) MaxH = 10000;
  3271. if (W > MaxW) W = MaxW;
  3272. if (H > MaxH) H = MaxH;
  3273. if (W < MinW) W = MinW;
  3274. if (H < MinH) H = MinH;
  3275. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3276. p->X = p->TX = (X < 0 ? 0 : X);
  3277. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3278. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3279. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3280. p->MaxW = MaxW; p->MaxH = MaxH;
  3281. p->MinW = MinW; p->MinH = MinH;
  3282. p->SL = SnapL; p->ST = SnapT;
  3283. p->SR = SnapR; p->SB = SnapB;
  3284. if (p->SR) p->X = CW - p->W - p->SR;
  3285. if (p->SB) p->Y = CH - p->H - p->SB;
  3286. la_EnsurePanelSnapping(p, CW, CH);
  3287. p->Show = 1;
  3288. p->PP.EndInstance = p;
  3289. p->PP.LastPs = &p->FakePS;
  3290. p->PP.LastPs->p = _LA_PROP_PANEL;
  3291. p->PP.LastPs->UseInstance = p;
  3292. p->PP.LastPs->Type = U'.';
  3293. la_EnsurePanelExtras(p);
  3294. laRecalcPanel(p);
  3295. p->FrameDistinguish = 100; //greater than 1 is ok
  3296. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3297. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3298. return p;
  3299. }
  3300. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3301. if(!uit) return 0;
  3302. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3303. strSafeSet(&p->Title, uit->Title->Ptr);
  3304. p->PanelTemplate = uit;
  3305. p->Show = 1;
  3306. p->PP.EndInstance = p;
  3307. p->PP.LastPs = &p->FakePS;
  3308. p->PP.LastPs->p = _LA_PROP_PANEL;
  3309. p->PP.LastPs->UseInstance = p;
  3310. p->PP.LastPs->Type = U'.';
  3311. la_EnsurePanelExtras(p);
  3312. laRecalcPanel(p);
  3313. p->FrameDistinguish = 100; //greater than 1 is ok
  3314. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3315. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3316. p->Block = b; b->CurrentPanel = p;
  3317. if(uit->PropFunc){ uit->PropFunc(p); }
  3318. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3319. laNotifyUsers("la.windows.panels");
  3320. return p;
  3321. }
  3322. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3323. laUiTemplate* uit=laFindUiTemplate(template_id);
  3324. return laCreatePanelT(b, uit);
  3325. }
  3326. 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){
  3327. laUiTemplate* uit=0;
  3328. if(template_id) uit=laFindUiTemplate(template_id);
  3329. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3330. p->Mode = LA_PANEL_FLOATING_TOP;
  3331. laPlacePanelForCreation(p);
  3332. if(uit){
  3333. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3334. }
  3335. if (w) lstPushItem(&w->Panels, p);
  3336. return p;
  3337. }
  3338. void laShowPanel(laPanel *p){
  3339. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3340. }
  3341. void laShowPanelWithDropDownEffect(laPanel *p){
  3342. laShowPanel(p);
  3343. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3344. p->AnimationRatio = 0;
  3345. }
  3346. void laShowPanelWithExpandEffect(laPanel *p){
  3347. laShowPanel(p);
  3348. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3349. p->AnimationRatio = 0;
  3350. }
  3351. void laHidePanel(laPanel *p){
  3352. if (!p->Mode) return;
  3353. p->Show = 0;
  3354. laNotifyUsers("la.windows.panels_hidden");
  3355. }
  3356. void laHidePanelWithDissoveEffect(laPanel *p){
  3357. if (!p->Mode) return;
  3358. laHidePanel(p);
  3359. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3360. p->AnimationRatio = 1;
  3361. }
  3362. void laHidePanelWithCollapseEffect(laPanel *p){
  3363. if (!p->Mode) return;
  3364. laHidePanel(p);
  3365. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3366. p->AnimationRatio = 1;
  3367. }
  3368. void laHidePanelWithMinimizeEffect(laPanel *p){
  3369. if (!p->Mode) return;
  3370. laHidePanel(p);
  3371. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3372. p->AnimationRatio = 1;
  3373. }
  3374. void laActivatePanel(char* TemplateID, int x, int y){
  3375. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3376. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3377. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3378. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3379. }
  3380. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3381. p->UI.PanX += DeltaX;
  3382. p->UI.PanY += DeltaY;
  3383. }
  3384. void laPanUiListFree(laUiList *uil, int X, int Y){
  3385. uil->PanX+=X; uil->PanY+=Y;
  3386. }
  3387. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3388. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3389. if(Y){X+=Y;Y=0;}
  3390. }
  3391. if (Y > 0){
  3392. if (uil->B - uil->PanY <= B) return 0;
  3393. else{
  3394. uil->PanY += Y;
  3395. if (uil->B - uil->PanY <= B){
  3396. uil->PanY = uil->B - B;
  3397. return 1;
  3398. }
  3399. }
  3400. }
  3401. if (Y < 0){
  3402. if (uil->U - uil->PanY >= U) return 0;
  3403. else{
  3404. uil->PanY += Y;
  3405. if (uil->U - uil->PanY >= U){
  3406. uil->PanY = uil->U - U;
  3407. return 1;
  3408. }
  3409. }
  3410. }
  3411. if(uil->AllowScale){
  3412. laPanUiListFree(uil, X, 0);
  3413. }else{
  3414. if (X > 0){
  3415. if (uil->R - uil->PanX <= R) return 0;
  3416. else{
  3417. uil->PanX += X;
  3418. if (uil->R - uil->PanX <= R){
  3419. uil->PanX = uil->R - R;
  3420. return 1;
  3421. }
  3422. }
  3423. }
  3424. if (X < 0){
  3425. if (uil->L - uil->PanX >= L) return 0;
  3426. else{
  3427. uil->PanX += X;
  3428. if (uil->L - uil->PanX >= L){
  3429. uil->PanX = uil->L - L;
  3430. return 1;
  3431. }
  3432. }
  3433. }
  3434. }
  3435. return 1;
  3436. }
  3437. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3438. int ret=1;
  3439. if(!uil->AllowScale){ return 0; }
  3440. real NewScale=uil->Scale*factor;
  3441. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3442. if(NewScale>5) {NewScale=5; ret=0;}
  3443. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3444. factor=NewScale/uil->Scale;
  3445. uil->Scale=NewScale;
  3446. real mx=(L+R)/2,my=(U+B)/2;
  3447. real dx= (mx+uil->PanX)*factor;
  3448. real dy= (my+uil->PanY)*factor;
  3449. uil->PanX=dx-mx;
  3450. uil->PanY=dy-my;
  3451. MAIN.CurrentPanel->FrameDistinguish=100;
  3452. return ret;
  3453. }
  3454. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3455. if(uil->AllowScale) return 0;
  3456. return laPanUiList(uil,X,Y,L,R,U,B);
  3457. }
  3458. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3459. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3460. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3461. strSafeSet(&p->Title, Title);
  3462. if (Define){
  3463. if (!This) { This = &p->PP; }
  3464. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3465. }
  3466. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3467. p->BT= &_LA_THEME_FLOATING_PANEL;
  3468. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3469. p->BoundUi = 1;
  3470. return p;
  3471. }
  3472. 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,
  3473. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3474. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3475. strSafeSet(&p->Title, Title);
  3476. if (Define){
  3477. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3478. }
  3479. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3480. p->BT= &_LA_THEME_FLOATING_PANEL;
  3481. p->Mode = LA_PANEL_FLOATING_TOP;
  3482. p->BoundUi = 1;
  3483. return p;
  3484. }
  3485. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3486. laPanel *ip;
  3487. tnsDelete2DOffscreen(p->OffScr);
  3488. p->OffScr = 0;
  3489. strSafeDestroy(&p->Title);
  3490. if (!p->AnimationMode){
  3491. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3492. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3493. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3494. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3495. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3496. }else if (p->Block){
  3497. lstRemoveItem(&p->Block->Panels, p);
  3498. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3499. }
  3500. laNotifyUsers("la.windows.panels");
  3501. }
  3502. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3503. //lstRemoveItem(&p->SubPanels, ip);
  3504. laDestroySinglePanel(ip, immediate);
  3505. laNotifyUsers("la.windows.panels");
  3506. }
  3507. la_ClearDetachedProp(p);
  3508. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3509. la_ReturnPanelNode(p);
  3510. }
  3511. void laDestroySinglePanel(laPanel *p, int immediate){
  3512. la_SetPropMathcerContext(p);
  3513. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3514. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3515. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3516. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3517. }
  3518. }
  3519. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3520. la_DestroyUiList(&p->UI, 1, 1, 0);
  3521. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3522. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3523. if (p->Mode){
  3524. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3525. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3526. }
  3527. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3528. if (la_UiStillInService(p)){
  3529. la_StopUiOperatorService(p);
  3530. }
  3531. if ((!p->AnimationMode) || immediate){
  3532. laDeferredDestroyPanel(p, immediate);
  3533. }else{
  3534. p->LaterDestroy = 1;
  3535. }
  3536. }
  3537. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3538. int MinW,MinWt=0;
  3539. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3540. if(!MAIN.CurrentWindow){ MAIN.CurrentWindow=MAIN.Windows.pFirst; if(!MAIN.CurrentWindow) return 0; }
  3541. int CW = MAIN.CurrentWindow->CW;
  3542. if(p->SL && p->SR){return 0;}
  3543. la_SetPropMathcerContext(p);
  3544. la_UpdateUiListRecursive(&p->TitleBar, LA_M, LA_M, p->TW - LA_M*2, p->TH, 0, p);
  3545. la_UpdateUiListRecursive(uil, LA_M+p->TitleBar.B, 0, 1000, 0, 0, p);
  3546. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3547. MinW = la_TestUiListMinumWidth(uil);
  3548. if (MinW<MinWt){MinW=MinWt;}
  3549. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+LA_M):0);
  3550. if (MinW > 20){
  3551. p->TW = MinW + LA_M*2 +ScrollerW;
  3552. }
  3553. la_PanelValidateWidth(p,uil);
  3554. laEnsurePanelInBound(p,uil);
  3555. if(p->TW>CW){ p->TW=CW; }
  3556. la_UpdateUiListRecursive(&p->TitleBar, LA_M, LA_M, p->TW-LA_M*2, p->TH, 0, p);
  3557. la_UpdateUiListRecursive(uil, LA_M+p->TitleBar.B, LA_M, p->TW-LA_M-ScrollerW, 0, 0, p);
  3558. laRedrawPanel(p);
  3559. return 1;
  3560. }
  3561. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3562. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3563. laOperator *ai = a;
  3564. laPanel *p;
  3565. int GX, GY, GW, t = 0;
  3566. int b;
  3567. laUiDefineFunc def = ReplaceUiDefine;
  3568. int MinW;
  3569. if (!def){ def=laui_DefaultPropDetails; }
  3570. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3571. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3572. laEnclosePanelContent(p, &p->UI);
  3573. laSetOperatorLocalizer(p);
  3574. p->CloseWhenMovedOut=1;
  3575. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3576. //laShowPanelWithDropDownEffect(p);
  3577. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3578. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3579. return p;
  3580. }
  3581. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3582. laPanel *p;
  3583. int GX, GY, GW, t = 0;
  3584. int b;
  3585. laUiDefineFunc def = ReplaceUiDefine;
  3586. int MinW;
  3587. if (!def) return 0;
  3588. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3589. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3590. p->Mode = LA_PANEL_FLOATING_TOP;
  3591. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3592. laEnclosePanelContent(p, &p->UI);
  3593. if(MAIN.CurrentWindow->Operators.pFirst){
  3594. laSetOperatorLocalizer(MAIN.PendingSplash);
  3595. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3596. MAIN.PendingSplash=0;
  3597. }
  3598. //laShowPanelWithExpandEffect(p);
  3599. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3600. return p;
  3601. }
  3602. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3603. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3604. laOperator *ai = a;
  3605. laPanel *p; laPropContainer* sub;
  3606. int GX, GY, GW, t = 0;
  3607. int b;
  3608. laUiDefineFunc def = ReplaceUiDefine;
  3609. int MinW;
  3610. if (!def){
  3611. if (This && This->LastPs->p){
  3612. if(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3613. }
  3614. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3615. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3616. }
  3617. GX = L; GY = B;
  3618. GW = (R - L) > MaxW ? MaxW : (R - L);
  3619. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3620. laEnclosePanelContent(p, &p->UI);
  3621. laSetOperatorLocalizer(p);
  3622. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3623. laShowPanelWithDropDownEffect(p);
  3624. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3625. if(Attachment){
  3626. p->Parent = Attachment;
  3627. lstAppendItem(&Attachment->SubPanels, p);
  3628. }
  3629. return p;
  3630. }
  3631. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3632. laPanel *p;
  3633. int t = 0;
  3634. int b;
  3635. //laLocalToWindow(0, Attachment, &L, &t);
  3636. //laLocalToWindow(0, Attachment, &R, &U);
  3637. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3638. laSetOperatorLocalizer(p);
  3639. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3640. laShowPanelWithDropDownEffect(p);
  3641. p->Parent = Attachment;
  3642. lstPushItem(&Attachment->SubPanels, p);
  3643. return p;
  3644. }
  3645. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3646. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3647. laOperator *ai = a;
  3648. laPanel *p;
  3649. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3650. int GX, GY, GW, t = 0;
  3651. int b;
  3652. int MinW;
  3653. //laLocalToWindow(0,Attachment, &L, &t);
  3654. //laLocalToWindow(0,Attachment, &R, &B);
  3655. GX = L;
  3656. GY = B;
  3657. GW = (R - L) > MaxW ? MaxW : (R - L);
  3658. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3659. p->MenuRefer = MenuRefer;
  3660. laEnclosePanelContent(p, MenuRefer);
  3661. laSetOperatorLocalizer(p);
  3662. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3663. laShowPanelWithDropDownEffect(p);
  3664. p->Parent = Attachment;
  3665. lstPushItem(&Attachment->SubPanels, p);
  3666. return p;
  3667. }
  3668. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3669. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3670. laOperator *ai = a;
  3671. laPanel *p;
  3672. int GX, GY, GW, t = 0;
  3673. int b;
  3674. GX = L;
  3675. GY = B;
  3676. GW = MaxW;
  3677. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3678. p->MenuRefer = &p->UI;
  3679. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3680. laSetOperatorLocalizer(p);
  3681. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3682. laShowPanelWithDropDownEffect(p);
  3683. if (Attachment){
  3684. p->Parent = Attachment;
  3685. lstPushItem(&Attachment->SubPanels, p);
  3686. }else{
  3687. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3688. }
  3689. return p;
  3690. }
  3691. 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){
  3692. laOperator *ai = For;
  3693. laPanel *p;
  3694. int b;
  3695. laUiDefineFunc def = 0;
  3696. if(ai->OperatorPanel){ return ai->OperatorPanel; }
  3697. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3698. else def = laui_DefaultPropUiDefine;
  3699. For->PP.EndInstance = For->CustomData;
  3700. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3701. laEnclosePanelContent(p, &p->UI);
  3702. MAIN.ToPanel = p;
  3703. laShowPanelWithExpandEffect(p);
  3704. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3705. ai->OperatorPanel = p;
  3706. p->ParentOperator = For;
  3707. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3708. return p;
  3709. }
  3710. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3711. laPanel *p; int b; laUiList *uil; laColumn* col;
  3712. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3713. strSafeSet(&p->Title, Title);
  3714. p->BoundUi = 1;
  3715. p->Mode = LA_PANEL_FLOATING_TOP;
  3716. p->BT = &_LA_THEME_FLOATING_PANEL;
  3717. MAIN.ToPanel = p;
  3718. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3719. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3720. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3721. laUiItem* r=laBeginRow(uil,col,0,0);
  3722. laShowSeparator(uil,col)->Expand=1;
  3723. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3724. laEndRow(uil,r);
  3725. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3726. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3727. laSetOperatorLocalizer(p);
  3728. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3729. return p;
  3730. }
  3731. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3732. laPanel *p; int b; laUiList *uil; laColumn* col;
  3733. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3734. strSafeSet(&p->Title, Title);
  3735. p->BoundUi = 1;
  3736. p->Mode = LA_PANEL_FLOATING_TOP;
  3737. p->BT = &_LA_THEME_FLOATING_PANEL;
  3738. MAIN.ToPanel = p;
  3739. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3740. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3741. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3742. laUiItem* r = laBeginRow(uil,col,0,0);
  3743. laShowSeparator(uil,col)->Expand=1;
  3744. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3745. laEndRow(uil, r);
  3746. laEnclosePanelContent(p,uil);
  3747. laShowPanelWithExpandEffect(p);
  3748. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3749. laSetOperatorLocalizer(p);
  3750. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3751. return p;
  3752. }
  3753. void laOperatorModalOver(laOperator* For){
  3754. For->ModalOver = 1;
  3755. }
  3756. void laDeferredRedraw(laPanel* p){
  3757. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3758. if(lip->p==p) return;
  3759. }
  3760. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3761. }
  3762. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3763. laWindow* cur=MAIN.CurrentWindow;
  3764. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3765. MAIN.CurrentWindow=w;
  3766. la_UpdateUiPlacement(w);
  3767. }
  3768. MAIN.CurrentWindow=cur;
  3769. }
  3770. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3771. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3772. }
  3773. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3774. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3775. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3776. void laRedrawCurrentPanel(){
  3777. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3778. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3779. }
  3780. void laRecalcCurrentPanel(){
  3781. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3782. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3783. }
  3784. void laRecalcPanelImmediate(laPanel* p){
  3785. p->FrameDistinguish++;
  3786. laBoxedTheme* bt = (*p->BT);
  3787. int em=bt->BoxStyle==-1?LA_M:0;
  3788. int scrollw=p->UI.ScrollerShownV?LA_M*2+LA_SCROLL_W:0;
  3789. la_PanelRefreshDetachedProp(p);
  3790. int enclosed=0;
  3791. if(p->BoundUi || p->MenuRefer){
  3792. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3793. else enclosed=laEnclosePanelContent(p, &p->UI);
  3794. }
  3795. if(!enclosed){
  3796. la_PanelValidateWidth(p,&p->UI);
  3797. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3798. la_UpdateUiListRecursive(&p->TitleBar, LA_M+em, LA_M+em, p->TW-LA_M, p->TH-LA_M, 0, p);
  3799. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=em; }
  3800. la_UpdateUiListRecursive(&p->UI, UseB+LA_M, LA_M+em, p->TW-LA_M-scrollw, p->TH-LA_M, 0, p);
  3801. }
  3802. laWindow* w=MAIN.CurrentWindow;
  3803. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3804. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3805. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3806. la_UpdateUiListRecursive(ui->Page, ui->TU+LA_M, ui->TL+LA_M, ui->TR-LA_M, ui->TB, 0, w->MaximizedUiPanel);
  3807. }
  3808. }
  3809. void laRecalcCurrentPanelImmediate(){
  3810. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3811. }
  3812. int laNonFixedPanelExists(laPanel *p){
  3813. laPanel *ip;
  3814. if (!p) return 0;
  3815. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3816. // if (ip == p) return 1;
  3817. //}
  3818. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3819. if (ip == p) return 1;
  3820. }
  3821. return 0;
  3822. }
  3823. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3824. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3825. return 1;
  3826. }
  3827. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3828. int tt=MAIN.TooltipCloseDistance;
  3829. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3830. return 1;
  3831. }
  3832. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3833. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3834. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3835. return 0;
  3836. return 1;
  3837. }
  3838. void laUnlinkSharedPanel(laPanel *p){
  3839. laWindow *w;
  3840. laPanel *ip;
  3841. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3842. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3843. if (ip == p){
  3844. lstRemoveItem(&w->Panels, ip);
  3845. return;
  3846. }
  3847. }
  3848. }
  3849. }
  3850. int laIsPanelCovered(laPanel *p){
  3851. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3852. laPanel *ip;
  3853. laPanel *resp;
  3854. int in1 = 0, in2 = 0, in3 = 0;
  3855. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3856. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3857. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3858. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3859. //}
  3860. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3861. if (ip == p){
  3862. in3 = 1;
  3863. d3 = 0;
  3864. continue;
  3865. }
  3866. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3867. }
  3868. if (!in2 && !in3) in1 = 1;
  3869. if (in1){
  3870. if (d1 || d2 || d3) return 1;
  3871. }else{
  3872. if (in2){
  3873. if (d2 || d3) return 1;
  3874. }else if (in3)
  3875. if (d3) return 1;
  3876. }
  3877. return 0;
  3878. }
  3879. int laIsTopPanel(laPanel *p){
  3880. //if (!p->Item.pPrev) return 1;
  3881. //else {
  3882. if (!laIsPanelCovered(p)){
  3883. //laPopPanel(p);
  3884. return 1;
  3885. }
  3886. return 0;
  3887. //}
  3888. return 0;
  3889. }
  3890. void laPanelToLocal(laOperator *a, int *x, int *y){
  3891. int ix = *x, iy = *y;
  3892. laListItemPointer *lip;
  3893. if (a){
  3894. //printf("\n");
  3895. int SL,SR,SU,SB; int PX=0,PY=0;
  3896. for (lip = a->LocalUiLists.pLast; lip; lip = lip->pPrev){
  3897. laUiList *uil = lip->p;
  3898. if(lip->pNext){
  3899. int PadR=(uil->AllowScale && uil->ScrollerShownV)?LA_SCROLL_W+LA_M*4:0;
  3900. int PadB=(uil->AllowScale && uil->ScrollerShownH)?LA_SCROLL_W+LA_M*3:0;
  3901. int UseB=uil->LimH?uil->U+uil->LimH:uil->B;
  3902. SL=TNS_MAX2(SL,uil->L); SR=TNS_MIN2(SR-PadR,uil->R);
  3903. SU=TNS_MAX2(SU,uil->U); SB=TNS_MIN2(SB-PadB,UseB);
  3904. SL+=uil->PanX; SR+=uil->PanX; SU+=uil->PanY; SB+=uil->PanY;
  3905. }else{
  3906. SL=uil->L+uil->PanX;SR=uil->R+uil->PanX;SU=uil->U+uil->PanY;SB=uil->B+uil->PanY;
  3907. }
  3908. PX += uil->PanX; PY += uil->PanY;
  3909. //printf("u %d %d %d %d %s\n",uil->L,uil->R,uil->U,uil->B,SSTR(uil->TabName));
  3910. }
  3911. (*x)+=PX; (*y)+=PY;
  3912. lip=a->LocalUiLists.pFirst; if(lip){
  3913. laUiList *uil = lip->p;
  3914. uil->FL=SL; uil->FR=SR; uil->FU=SU; uil->FB=SB;
  3915. //printf("uil limit %d %d | %d %d %d %d %d %d\n",*x,*y,uil->FL,uil->FR,uil->FU,uil->FB,PX,PY);
  3916. }
  3917. }
  3918. }
  3919. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3920. if(!p) return;
  3921. int ix = *x, iy = *y;
  3922. laListItemPointer *lip;
  3923. laOperator *ai = a;
  3924. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3925. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3926. laPanelToLocal(a,x,y);
  3927. }
  3928. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3929. if(!p) return;
  3930. int ix = *x, iy = *y;
  3931. laListItemPointer *lip;
  3932. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3933. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3934. if (a){
  3935. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3936. laUiList *uil = lip->p;
  3937. (*x) -= uil->PanX;
  3938. (*y) -= uil->PanY;
  3939. }
  3940. }
  3941. }
  3942. void laPanelToWindow(laPanel *p, int *x, int *y){
  3943. int ix = *x, iy = *y;
  3944. laListItemPointer *lip;
  3945. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3946. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3947. }
  3948. void laLocalToPanel(laOperator *a, int *x, int *y){
  3949. int ix = *x, iy = *y;
  3950. laListItemPointer *lip;
  3951. if (a){
  3952. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3953. laUiList *uil = lip->p;
  3954. (*x) -= uil->PanX;
  3955. (*y) -= uil->PanY;
  3956. }
  3957. }
  3958. }
  3959. void laSetNextMenuPos(int X, int Y, int W, int H){
  3960. MAIN.NextX = X;
  3961. MAIN.NextY = Y;
  3962. MAIN.NextW = W;
  3963. MAIN.NextH = H;
  3964. }
  3965. int laIsInBlock(laBlock *b, int X, int Y){
  3966. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3967. return 0;
  3968. }
  3969. 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; }
  3970. 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; }
  3971. 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; }
  3972. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3973. laPanel *p;
  3974. laBlock *sb = 0;
  3975. if (!laIsInBlock(b, X, Y)) return 0;
  3976. if (!b->B1 && !b->B2) return b;
  3977. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3978. return laDetectBlockRecursive(b->B2, X, Y);
  3979. }
  3980. laPanel *laDetectPanel(int X, int Y){
  3981. laPanel *p; laBlock *b;
  3982. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3983. int x = X, y = Y;
  3984. laWindowToLocal(0, p, &x, &y);
  3985. if (p->Show && laIsInPanel(p, x, y)){
  3986. return p;
  3987. }
  3988. }
  3989. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3990. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3991. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3992. return 0;
  3993. }
  3994. laUiList *laPrepareUi(laPanel *p){
  3995. return &p->UI;
  3996. }
  3997. laColumn *laFirstColumn(laUiList *uil){
  3998. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3999. else{
  4000. laColumn *c = memAcquireSimple(sizeof(laColumn));
  4001. c->SP = 1;
  4002. c->PreWidth = 1;
  4003. lstAppendItem(&uil->Columns, c);
  4004. c->Top = c;
  4005. return uil->Columns.pFirst;
  4006. }
  4007. }
  4008. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  4009. laColumn *lc, *rc;
  4010. if (c->LS || c->RS) return c;
  4011. lc = memAcquireSimple(sizeof(laColumn));
  4012. rc = memAcquireSimple(sizeof(laColumn));
  4013. c->LS = lc;
  4014. c->RS = rc;
  4015. c->LS->SP = Percent;
  4016. c->RS->SP = Percent;
  4017. c->LS->Top = c->Top;
  4018. c->RS->Top = c->Top;
  4019. if (uil){
  4020. lstAppendItem(&uil->Columns, lc);
  4021. lstAppendItem(&uil->Columns, rc);
  4022. }
  4023. if (c->LS && c->RS->MaxW == 0){
  4024. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4025. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4026. }else if (c->RS && c->LS->MaxW == 0){
  4027. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4028. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4029. }
  4030. return c;
  4031. }
  4032. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  4033. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  4034. return c->LS;
  4035. }
  4036. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  4037. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  4038. if (MaxWidth) c->RS->MaxW = MaxWidth;
  4039. return c->RS;
  4040. }
  4041. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  4042. lstRemoveItem(List, c);
  4043. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  4044. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  4045. memFree(c);
  4046. }
  4047. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  4048. laUiList *uil = TopUil;
  4049. laUiList *sub;
  4050. laUiItem *ui;
  4051. laColumn *cc, *NextCC = 0;
  4052. int Occupied = 0;
  4053. int Removed = 0;
  4054. if (!c->LS) return 0;
  4055. else{
  4056. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  4057. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  4058. }
  4059. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  4060. if (ui->C == c->LS || ui->C == c->RS){
  4061. if (DoMerge){
  4062. ui->C = c;
  4063. Occupied = 1;
  4064. }else
  4065. return 1;
  4066. }
  4067. if (ui->Subs.pFirst){
  4068. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4069. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  4070. }
  4071. }
  4072. }
  4073. if (!Removed){
  4074. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  4075. if (cc == c){
  4076. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  4077. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  4078. c->LS = 0;
  4079. c->RS = 0;
  4080. Removed = 1;
  4081. break;
  4082. }
  4083. }
  4084. }
  4085. return Occupied;
  4086. }
  4087. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  4088. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  4089. ut->FakeProp = memAcquire(sizeof(laSubProp));
  4090. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  4091. ut->FakeProp->Base.Identifier = ut->Identifier;
  4092. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  4093. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  4094. ut->FakeProp->Base.OffsetIsPointer = 1;
  4095. //ut->FakeProp->Base.Container = ut->ExtraProps;
  4096. return ut->ExtraProps;
  4097. }
  4098. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  4099. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  4100. ct->FakeProp = memAcquire(sizeof(laSubProp));
  4101. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  4102. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  4103. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  4104. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  4105. ct->FakeProp->Base.OffsetIsPointer = 1;
  4106. //ut->FakeProp->Base.Container = ut->ExtraProps;
  4107. return ct->ExtraProps;
  4108. }
  4109. void la_DestroyUiType(laUiType* uit){
  4110. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4111. memFree(uit);
  4112. }
  4113. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  4114. laUiType *ut = memAcquire(sizeof(laUiType));
  4115. ut->Identifier = Identifer;
  4116. ut->OperatorID = UseOperator;
  4117. ut->Draw = Draw;
  4118. ut->Theme = bt;
  4119. ut->ForType = ForType;
  4120. ut->OperatorType = laGetOperatorType(UseOperator);
  4121. ut->GetHeight = GetHeight;
  4122. ut->Init = Init;
  4123. ut->Destroy = Destroy;
  4124. la_UDFAppendSharedTypePointer(Identifer, ut);
  4125. lstAppendItem(&MAIN.UiTypes, ut);
  4126. return ut;
  4127. }
  4128. laUiType *la_GetUiTypeFromProperty(laProp *P){
  4129. laUiType *ut = MAIN.UiTypes.pFirst;
  4130. if (!P) return 0;
  4131. if (P->DefaultUiType) return P->DefaultUiType;
  4132. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  4133. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  4134. for (ut; ut; ut = ut->Item.pNext){
  4135. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  4136. return ut;
  4137. }
  4138. }
  4139. return 0;
  4140. }
  4141. laUiType *la_GetUiButtonType(){
  4142. laUiType *ut = MAIN.UiTypes.pFirst;
  4143. for (ut; ut; ut = ut->Item.pNext){
  4144. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  4145. }
  4146. return 0;
  4147. }
  4148. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  4149. laCanvasTemplate *vdt;
  4150. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  4151. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  4152. }
  4153. return 0;
  4154. }
  4155. void la_AssignPropExtras(laUiItem* ui){
  4156. if(!ui->Type || !ui->Type->FakeProp) return;
  4157. ui->FakePs.p = ui->Type->FakeProp;
  4158. ui->FakePs.Type = U'.';
  4159. ui->FakePs.UseInstance = ui;
  4160. ui->ExtraPP.LastPs = &ui->FakePs;
  4161. }
  4162. void la_AssignCanvasPropExtras(laUiItem* ui){
  4163. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  4164. laCanvasTemplate*ct=ui->CanvasTemplate;
  4165. ui->FakePs.p = ct->FakeProp;
  4166. ui->FakePs.Type = U'.';
  4167. ui->FakePs.UseInstance = ui;
  4168. ui->ExtraPP.EndInstance = ui->Extra;
  4169. ui->ExtraPP.LastPs = &ui->FakePs;
  4170. }
  4171. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  4172. int result;
  4173. if (!ui) return 0;
  4174. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  4175. if (Path){
  4176. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4177. if (!result){
  4178. ui->AT = laGetOperatorType(Path);
  4179. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  4180. ui->Type = la_GetUiButtonType();
  4181. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  4182. }else{
  4183. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4184. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4185. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  4186. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4187. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4188. }
  4189. if (Base){
  4190. ui->PP.RawThis = Base;
  4191. }
  4192. }else if (Base){
  4193. ui->PP.LastPs = Base->LastPs;
  4194. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4195. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4196. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  4197. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4198. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4199. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4200. }
  4201. la_AssignPropExtras(ui);
  4202. if(Widget){ ui->Flags|= Widget->Flags; }
  4203. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  4204. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  4205. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4206. return ui;
  4207. }
  4208. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  4209. ui->Type = _LA_UI_LABEL;
  4210. ui->Template = Template;
  4211. ui->State = LA_UI_NORMAL;
  4212. strSafeSet(&ui->Display, Content);
  4213. la_AssignPropExtras(ui);
  4214. return ui;
  4215. }
  4216. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  4217. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4218. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  4219. ui->State = LA_UI_NORMAL;
  4220. la_AssignPropExtras(ui);
  4221. return ui;
  4222. }
  4223. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4224. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4225. transLate(Content);
  4226. la_UpdateLabelDisplay(ui, Template, Content);
  4227. ui->C = c;
  4228. if (ui->Type->Init) ui->Type->Init(ui);
  4229. ui->ExtraPP.EndInstance = ui->Extra;
  4230. lstAppendItem(&uil->UiItems, ui);
  4231. return ui;
  4232. }
  4233. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4234. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4235. la_UpdateLabelDisplay(ui, Template, Content);
  4236. ui->C = c;
  4237. if (ui->Type->Init) ui->Type->Init(ui);
  4238. ui->ExtraPP.EndInstance = ui->Extra;
  4239. lstAppendItem(&uil->UiItems, ui);
  4240. return ui;
  4241. }
  4242. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  4243. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4244. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  4245. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  4246. ui->C = c;
  4247. if (ui->Type->Init) ui->Type->Init(ui);
  4248. ui->ExtraPP.EndInstance = ui->Extra;
  4249. lstAppendItem(&uil->UiItems, ui);
  4250. return ui;
  4251. }
  4252. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4253. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  4254. }
  4255. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4256. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4257. }
  4258. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4259. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4260. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4261. ui->C = c;
  4262. ui->TemplateContext = TemplateContext;
  4263. if (ui->Type->Init) ui->Type->Init(ui);
  4264. ui->ExtraPP.EndInstance = ui->Extra;
  4265. lstAppendItem(&uil->UiItems, ui);
  4266. return ui;
  4267. }
  4268. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4269. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4270. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4271. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4272. ui->SymbolID=Height;
  4273. lstAppendItem(&uil->UiItems, ui);
  4274. return ui;
  4275. }
  4276. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4277. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4278. }
  4279. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4280. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4281. }
  4282. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4283. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4284. ui->Type = _LA_UI_CANVAS;
  4285. ui->State = LA_UI_NORMAL;
  4286. ui->C = c;
  4287. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4288. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4289. else{
  4290. 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); }
  4291. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4292. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4293. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4294. }
  4295. if (ui->Type->Init) ui->Type->Init(ui);
  4296. la_AssignCanvasPropExtras(ui);
  4297. if (Height) ui->Expand=Height; else ui->Expand=6;
  4298. lstAppendItem(&uil->UiItems, ui);
  4299. return ui;
  4300. }
  4301. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4302. laUiItem* ui=0;
  4303. #define ADD_CANVAS \
  4304. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4305. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4306. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4307. }laEndCondition(uil,b3);\
  4308. laEndRow(uil,b);
  4309. if(Detached){
  4310. laColumn* cl,*cll,*clr,*cr;
  4311. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4312. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4313. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4314. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4315. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4316. ADD_CANVAS
  4317. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4318. }laElse(uil,b2);{
  4319. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4320. ADD_CANVAS
  4321. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4322. }laEndCondition(uil,b2);
  4323. }else{
  4324. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4325. }
  4326. #undef ADD_CANVAS
  4327. return ui;
  4328. }
  4329. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4330. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4331. laCanvasExtra *e;
  4332. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4333. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4334. ui->C = c;
  4335. if (ui->Type->Init) ui->Type->Init(ui);
  4336. ui->ExtraPP.EndInstance = ui->Extra;
  4337. lstAppendItem(&uil->UiItems, ui);
  4338. return ui;
  4339. }
  4340. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4341. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4342. ui->Type = _LA_UI_SYMBOL;
  4343. ui->SymbolID = SymbolID;
  4344. if (Height) ui->State = Height;
  4345. ui->C = c;
  4346. if (ui->Type->Init) ui->Type->Init(ui);
  4347. ui->ExtraPP.EndInstance = ui->Extra;
  4348. lstAppendItem(&uil->UiItems, ui);
  4349. return ui;
  4350. }
  4351. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4352. laPropPack PP={0}; int result;
  4353. if (Path){
  4354. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4355. if (!result){ return 0; }
  4356. if (Base){ PP.RawThis = Base; }
  4357. }else if (Base){
  4358. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4359. }
  4360. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4361. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4362. lstAppendItem(&ui->CompoundPPs,CPP);
  4363. return &CPP->PP;
  4364. }
  4365. laUiItem *laShowMouseActionReporter(laUiList* uil, laColumn* c, int Height, const char* Display, const char* instructions){
  4366. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4367. ui->C = c;
  4368. ui->Type=_LA_UI_MOUSE_ACTION_REPORTER;
  4369. ui->State=Height; if(!ui->State){ ui->State=1; }
  4370. if(Display) strSafeSet(&ui->Display, Display);
  4371. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4372. lstAppendItem(&uil->UiItems, ui);
  4373. return ui;
  4374. }
  4375. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4376. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4377. ui->Type = &_LA_UI_ROW_BEGIN;
  4378. ui->State=Expand;
  4379. ui->Flags=Even;
  4380. ui->C = c;
  4381. if (ui->Type->Init) ui->Type->Init(ui);
  4382. ui->ExtraPP.EndInstance = ui->Extra;
  4383. lstAppendItem(&uil->UiItems, ui);
  4384. return ui;
  4385. }
  4386. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4387. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4388. ui->Type = &_LA_UI_ROW_END;
  4389. ui->C = Begin->C;
  4390. ui->Page = (laUiList*)Begin;
  4391. if (ui->Type->Init) ui->Type->Init(ui);
  4392. ui->ExtraPP.EndInstance = ui->Extra;
  4393. lstAppendItem(&uil->UiItems, ui);
  4394. return ui;
  4395. }
  4396. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4397. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4398. e->Expression = Expression;
  4399. ui->Extra = e;
  4400. la_AssignPropExtras(ui);
  4401. }
  4402. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4403. laUiItem *ui = la_CreateGroupHandle(Widget);
  4404. laUiList *nuil;
  4405. ui->C = c;
  4406. lstAppendItem(&uil->UiItems, ui);
  4407. nuil = memAcquireSimple(sizeof(laUiList));
  4408. strSafeSet(&nuil->TabName, Name);
  4409. ui->Page = nuil;
  4410. lstAppendItem(&ui->Subs, nuil);
  4411. if (ui->Type->Init) ui->Type->Init(ui);
  4412. ui->ExtraPP.EndInstance = ui->Extra;
  4413. return ui;
  4414. }
  4415. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4416. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4417. laUiList *sub = SubUi->Page;
  4418. laColumn *s = laFirstColumn(sub);
  4419. SubUi->State = LA_UI_ACTIVE;
  4420. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4421. strSafePrint(&b1->ExtraInstructions, "text=%s", Name);
  4422. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4423. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4424. laShowSeparator(sub, s);
  4425. return SubUi;
  4426. }
  4427. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4428. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4429. laUiList *sub = SubUi->Page;
  4430. laColumn *s = laFirstColumn(sub);
  4431. SubUi->State = LA_UI_ACTIVE;
  4432. return SubUi;
  4433. }
  4434. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4435. laEndCondition(sub, sub->UiItems.pFirst);
  4436. }
  4437. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4438. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4439. laUiList *nuil;
  4440. ui->C = c;
  4441. lstAppendItem(&uil->UiItems, ui);
  4442. if (ui->Type->Init) ui->Type->Init(ui);
  4443. ui->ExtraPP.EndInstance = ui->Extra;
  4444. return ui;
  4445. }
  4446. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4447. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4448. if (!ui->Page) ui->Page = uil;
  4449. lstAppendItem(&ui->Subs, uil);
  4450. strSafeSet(&uil->TabName, Name);
  4451. laFirstColumn(uil);
  4452. //laFirstColumn(uil);
  4453. return uil;
  4454. }
  4455. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4456. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4457. /*if (!ui->Page) */ ui->Page = uil;
  4458. lstAppendItem(&ui->Subs, uil);
  4459. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4460. return uil;
  4461. }
  4462. laUiConditionNode *laTrue(){
  4463. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4464. ucn->Type = LA_CONDITION_TRUE;
  4465. return ucn;
  4466. }
  4467. laUiConditionNode *laFalse(){
  4468. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4469. ucn->Type = LA_CONDITION_FALSE;
  4470. return ucn;
  4471. }
  4472. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4473. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4474. ucn->Type = LA_CONDITION_PROP;
  4475. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4476. strSafeSet(&ucn->String, Prop);
  4477. return ucn;
  4478. }
  4479. laUiConditionNode *laIntExpression(int Value){
  4480. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4481. ucn->Type = LA_CONDITION_INT;
  4482. ucn->IntValue = Value;
  4483. return ucn;
  4484. }
  4485. laUiConditionNode *laFloatExpression(real Value){
  4486. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4487. ucn->Type = LA_CONDITION_FLOAT;
  4488. ucn->FloatValue = Value;
  4489. return ucn;
  4490. }
  4491. laUiConditionNode *laStringExpression(char *Content){
  4492. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4493. ucn->Type = LA_CONDITION_STRING;
  4494. strSafeSet(&ucn->String, Content);
  4495. return ucn;
  4496. }
  4497. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4498. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4499. ucn->Type = LA_CONDITION_AND;
  4500. ucn->Expression1 = Expression1;
  4501. ucn->Expression2 = Expression2;
  4502. return ucn;
  4503. }
  4504. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4505. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4506. ucn->Type = LA_CONDITION_OR;
  4507. ucn->Expression1 = Expression1;
  4508. ucn->Expression2 = Expression2;
  4509. return ucn;
  4510. }
  4511. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4512. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4513. ucn->Type = LA_CONDITION_NOT;
  4514. ucn->Expression1 = Expression1;
  4515. return ucn;
  4516. }
  4517. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4518. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4519. ucn->Type = LA_CONDITION_EQ;
  4520. ucn->Expression1 = Expression1;
  4521. ucn->Expression2 = Expression2;
  4522. return ucn;
  4523. }
  4524. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4525. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4526. ucn->Type = LA_CONDITION_GT;
  4527. ucn->Expression1 = Expression1;
  4528. ucn->Expression2 = Expression2;
  4529. return ucn;
  4530. }
  4531. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4532. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4533. ucn->Type = LA_CONDITION_LT;
  4534. ucn->Expression1 = Expression1;
  4535. ucn->Expression2 = Expression2;
  4536. return ucn;
  4537. }
  4538. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4539. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4540. ucn->Type = LA_CONDITION_GE;
  4541. ucn->Expression1 = Expression1;
  4542. ucn->Expression2 = Expression2;
  4543. return ucn;
  4544. }
  4545. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4546. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4547. ucn->Type = LA_CONDITION_LE;
  4548. ucn->Expression1 = Expression1;
  4549. ucn->Expression2 = Expression2;
  4550. return ucn;
  4551. }
  4552. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4553. if (Expression->Type != LA_CONDITION_INT) return 0;
  4554. return Expression->IntValue;
  4555. }
  4556. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4557. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4558. return Expression->FloatValue;
  4559. }
  4560. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4561. return Expression->String->Ptr;
  4562. }
  4563. 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){
  4564. switch (Mode1){
  4565. case LA_PROP_ENUM:
  4566. case LA_PROP_INT:
  4567. case LA_CONDITION_INT:
  4568. switch (Mode2){
  4569. case LA_PROP_ENUM:
  4570. case LA_PROP_INT:
  4571. case LA_CONDITION_INT:
  4572. switch (CompMode){
  4573. case LA_CONDITION_GE:
  4574. return (i1 >= i2);
  4575. case LA_CONDITION_GT:
  4576. return (i1 > i2);
  4577. case LA_CONDITION_EQ:
  4578. return (i1 == i2);
  4579. case LA_CONDITION_LT:
  4580. return (i1 < i2);
  4581. case LA_CONDITION_LE:
  4582. return (i1 <= i2);
  4583. }
  4584. case LA_PROP_FLOAT:
  4585. case LA_CONDITION_FLOAT:
  4586. switch (CompMode){
  4587. case LA_CONDITION_GE:
  4588. return ((real)i1 >= f2);
  4589. case LA_CONDITION_GT:
  4590. return ((real)i1 > f2);
  4591. case LA_CONDITION_EQ:
  4592. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4593. case LA_CONDITION_LT:
  4594. return ((real)i1 < f2);
  4595. case LA_CONDITION_LE:
  4596. return ((real)i1 <= f2);
  4597. }
  4598. case LA_PROP_SUB:
  4599. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4600. default:
  4601. return 0;
  4602. }
  4603. case LA_PROP_FLOAT:
  4604. case LA_CONDITION_FLOAT:
  4605. switch (Mode2){
  4606. case LA_PROP_INT:
  4607. case LA_PROP_ENUM:
  4608. case LA_CONDITION_INT:
  4609. switch (CompMode){
  4610. case LA_CONDITION_GE:
  4611. return (f1 >= (real)i2);
  4612. case LA_CONDITION_GT:
  4613. return (f1 > (real)i2);
  4614. case LA_CONDITION_EQ:
  4615. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4616. case LA_CONDITION_LT:
  4617. return (f1 < (real)i2);
  4618. case LA_CONDITION_LE:
  4619. return (f1 <= (real)i2);
  4620. }
  4621. case LA_PROP_FLOAT:
  4622. case LA_CONDITION_FLOAT:
  4623. switch (CompMode){
  4624. case LA_CONDITION_GE:
  4625. return (f1 >= f2);
  4626. case LA_CONDITION_GT:
  4627. return (f1 > f2);
  4628. case LA_CONDITION_EQ:
  4629. return (f1 == f2);
  4630. case LA_CONDITION_LT:
  4631. return (f1 < f2);
  4632. case LA_CONDITION_LE:
  4633. return (f1 <= f2);
  4634. }
  4635. default:
  4636. return 0;
  4637. }
  4638. case LA_PROP_STRING:
  4639. case LA_CONDITION_STRING:
  4640. switch (Mode2){
  4641. case LA_PROP_STRING:
  4642. case LA_CONDITION_STRING:
  4643. return strSame(s1, s2);
  4644. default:
  4645. return 0;
  4646. }
  4647. case LA_PROP_SUB:
  4648. switch (Mode2){
  4649. case LA_PROP_SUB:
  4650. return p1 == p2;
  4651. case LA_CONDITION_INT:
  4652. case LA_PROP_INT:
  4653. case LA_PROP_ENUM:
  4654. return (int)p1 == i2;
  4655. default:
  4656. return 0;
  4657. }
  4658. default:
  4659. switch (CompMode){
  4660. case LA_CONDITION_GE:
  4661. return (i1 >= i2);
  4662. case LA_CONDITION_GT:
  4663. return (i1 > i2);
  4664. case LA_CONDITION_EQ:
  4665. return (i1 == i2);
  4666. case LA_CONDITION_LT:
  4667. return (i1 < i2);
  4668. case LA_CONDITION_LE:
  4669. return (i1 <= i2);
  4670. }
  4671. }
  4672. return 0;
  4673. }
  4674. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4675. void *Instance = 0;
  4676. int IValue1 = 0, IValue2 = 0;
  4677. real FValue1 = 0, FValue2 = 0;
  4678. void *Ptr1 = 0, *Ptr2 = 0;
  4679. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4680. int Result1, Result2;
  4681. laEnumItem *ei; laSubProp*sp;
  4682. if (!Expression) return 0;
  4683. Str1[0] = 0;
  4684. Str2[0] = 0;
  4685. laPropIterator pi = {0};
  4686. switch (Expression->Type){
  4687. case LA_CONDITION_PROP:
  4688. if (!Expression->PP.LastPs){
  4689. (*IResult) = 0;
  4690. return 0;
  4691. }
  4692. switch (Expression->PP.LastPs->p->PropertyType){
  4693. case LA_PROP_INT:
  4694. *IResult = laGetInt(&Expression->PP);
  4695. if (*IResult) return LA_CONDITION_INT;
  4696. else return 0;
  4697. case LA_PROP_FLOAT:
  4698. *FResult = laGetFloat(&Expression->PP);
  4699. if (*FResult) return 1;
  4700. else return 0;
  4701. break;
  4702. case LA_PROP_STRING:
  4703. laGetString(&Expression->PP, _StrResult, &StrResult);
  4704. if (StrResult[0]) return 1;
  4705. else return 0;
  4706. break;
  4707. case LA_PROP_ENUM:
  4708. ei = laGetEnum(&Expression->PP);
  4709. if (!ei) return 0;
  4710. /*if(ei) */ *IResult = ei->Index;
  4711. if (*IResult) return LA_CONDITION_INT;
  4712. else return 0;
  4713. break;
  4714. case LA_PROP_SUB:
  4715. sp=Expression->PP.LastPs->p;
  4716. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4717. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4718. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4719. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4720. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4721. }
  4722. }
  4723. *PtrResult = Instance;
  4724. if (Instance) return 1;
  4725. break;
  4726. default:
  4727. return 0;
  4728. }
  4729. break;
  4730. case LA_CONDITION_INT:
  4731. *IResult = Expression->IntValue;
  4732. if (*IResult) return 1;
  4733. else
  4734. return 0;
  4735. case LA_CONDITION_FLOAT:
  4736. *FResult = Expression->FloatValue;
  4737. if (*FResult) return 1;
  4738. else
  4739. return 0;
  4740. case LA_CONDITION_STRING:
  4741. if (Expression->String){
  4742. strCopyFull(StrResult, Expression->String->Ptr);
  4743. return 1;
  4744. }else
  4745. return 0;
  4746. case LA_CONDITION_TRUE:
  4747. if (*IResult) *IResult = 1;
  4748. return 1;
  4749. case LA_CONDITION_FALSE:
  4750. if (*IResult) *IResult = 0;
  4751. return 0;
  4752. default:
  4753. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4754. switch (Expression->Type){
  4755. case LA_CONDITION_AND:
  4756. if (Result1){
  4757. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4758. if (Result2) *IResult = 1;
  4759. return (Result2);
  4760. }else
  4761. return 0;
  4762. case LA_CONDITION_OR:
  4763. if (!Result1){
  4764. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4765. if (Result2) *IResult = 1;
  4766. return (Result2);
  4767. }else
  4768. return 1;
  4769. case LA_CONDITION_NOT:
  4770. return !Result1;
  4771. default:
  4772. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4773. return la_DoCompare(Expression->Type,
  4774. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4775. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4776. }
  4777. break;
  4778. }
  4779. return 0;
  4780. }
  4781. int la_DoSingleExpression(laUiConditionNode *Expression){
  4782. int a;
  4783. real b;
  4784. char c[128]={0};
  4785. void *p;
  4786. if (!Expression) return 1;
  4787. c[0] = 0;
  4788. return la_DoExpression(Expression, &a, &b, c, &p);
  4789. }
  4790. void la_StepExpression(laUiConditionNode *e){
  4791. if (!e) return;
  4792. switch (e->Type){
  4793. case LA_CONDITION_AND:
  4794. case LA_CONDITION_OR:
  4795. case LA_CONDITION_GE:
  4796. case LA_CONDITION_GT:
  4797. case LA_CONDITION_EQ:
  4798. case LA_CONDITION_LT:
  4799. case LA_CONDITION_LE:
  4800. la_StepExpression(e->Expression1);
  4801. la_StepExpression(e->Expression2);
  4802. break;
  4803. case LA_CONDITION_NOT:
  4804. la_StepExpression(e->Expression1);
  4805. break;
  4806. case LA_CONDITION_PROP:
  4807. la_StepPropPack(&e->PP);
  4808. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4809. la_UsePropPack(&e->PP, 1);
  4810. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4811. //}
  4812. break;
  4813. default:
  4814. break;
  4815. }
  4816. }
  4817. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4818. if (!ucn) return;
  4819. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4820. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4821. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4822. if (ucn->String) strSafeDestroy(&ucn->String);
  4823. if (ucn) memFree(ucn);
  4824. }
  4825. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4826. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4827. ui->C = c;
  4828. ui->Type = &_LA_UI_CONDITION;
  4829. la_ConditionerInit(ui, Expression);
  4830. lstAppendItem(&uil->UiItems, ui);
  4831. return ui;
  4832. }
  4833. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4834. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4835. laConditionUiExtraData *cued;
  4836. ui->Type = &_LA_UI_CONDITION_ELSE;
  4837. la_ConditionerInit(ui, 0);
  4838. cued = ui->Extra;
  4839. cued->EndUi = Beginner;
  4840. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4841. ui->C = Beginner->C;
  4842. lstAppendItem(&uil->UiItems, ui);
  4843. return ui;
  4844. }
  4845. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4846. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4847. laConditionUiExtraData *cued;
  4848. ui->Template = define;
  4849. ui->C = col;
  4850. ui->PP.RawThis = ExtraBase;
  4851. ui->Page = ExtraThis;
  4852. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4853. la_ConditionerInit(ui, 0);
  4854. cued = ui->Extra;
  4855. //cued->Remove = Remove;
  4856. ui->State = LA_UI_NORMAL;
  4857. lstAppendItem(&uil->UiItems, ui);
  4858. return ui;
  4859. }
  4860. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4861. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4862. laConditionUiExtraData *cued;
  4863. ui->Type = &_LA_UI_CONDITION_END;
  4864. la_ConditionerInit(ui, 0);
  4865. cued = ui->Extra;
  4866. cued->EndUi = Beginner;
  4867. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4868. ui->C = Beginner->C;
  4869. lstAppendItem(&uil->UiItems, ui);
  4870. return ui;
  4871. }
  4872. laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags) {
  4873. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4874. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4875. ui->Type = _LA_UI_MENU_ROOT;
  4876. strSafeSet(&ui->Display, Title);
  4877. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4878. ui->C = c;
  4879. ui->Flags|=flags;
  4880. lstAppendItem(&uil->UiItems, ui);
  4881. muil->Flags|=flags;
  4882. lstAppendItem(&ui->Subs, muil);
  4883. return muil;
  4884. }
  4885. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4886. return laMakeMenuPageEx(uil,c,Title,0);
  4887. }
  4888. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4889. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4890. ui->Type = _LA_UI_ALIGN;
  4891. ui->C = widest;
  4892. lstAppendItem(&uil->UiItems, ui);
  4893. return ui;
  4894. }
  4895. void laFixHeight(laUiList *uil, short Rows){
  4896. if (!uil) return;
  4897. uil->HeightCoeff = Rows;
  4898. }
  4899. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4900. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4901. if (!ExtraColumns) return;
  4902. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4903. }
  4904. laUiTemplate *laFindUiTemplate(char *Identifier){
  4905. laUiTemplate *uit;
  4906. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4907. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4908. }
  4909. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4910. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4911. }
  4912. return 0;
  4913. }
  4914. void la_DestroyUiTemplate(laUiTemplate* uit){
  4915. strSafeDestroy(&uit->Identifier);
  4916. strSafeDestroy(&uit->Title);
  4917. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4918. memFree(uit);
  4919. }
  4920. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4921. strSafeDestroy(&uit->Identifier);
  4922. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4923. memFree(uit);
  4924. }
  4925. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4926. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4927. strSafeSet(&uit->Identifier, Identifier);
  4928. strSafeSet(&uit->Title, Title);
  4929. strSafeSet(&uit->CategoryName, NewCategory);
  4930. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4931. uit->DefaultGLFormat=DefaultGLFormat;
  4932. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4933. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4934. la_UDFAppendSharedTypePointer(Identifier, uit);
  4935. return uit;
  4936. }
  4937. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4938. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4939. strSafeSet(&t->Identifier, Identifier);
  4940. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4941. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4942. lstAppendItem(&MAIN.View2DTemplates, t);
  4943. la_UDFAppendSharedTypePointer(Identifier, t);
  4944. return t;
  4945. }
  4946. void laFinalizeUiTemplates(){
  4947. laUiTemplate *uit;
  4948. laCanvasTemplate *u2d;
  4949. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4950. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4951. }
  4952. }
  4953. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4954. laPanel *p;
  4955. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4956. if (p->PanelTemplate==uit){
  4957. return p;
  4958. }
  4959. }
  4960. return 0;
  4961. }
  4962. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4963. laUiList *uil, *NextUil;
  4964. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4965. NextUil = uil->Item.pNext;
  4966. lstRemoveItem(&ui->Subs, uil);
  4967. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4968. }
  4969. la_StopUiOperatorService(ui);
  4970. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4971. strSafeDestroy(&ui->Display);
  4972. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4973. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4974. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4975. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4976. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4977. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4978. }
  4979. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4980. memFree(ui);
  4981. }
  4982. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4983. laUiItem *ui, *NextUi;
  4984. laColumn *col, *NextCol;
  4985. if (!uil) return;
  4986. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4987. NextUi = ui->Item.pNext;
  4988. if(OnlyRemoveUser && RemoveUsers){
  4989. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4990. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4991. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4992. continue;
  4993. }
  4994. lstRemoveItem(&uil->UiItems, ui);
  4995. la_DestroyUiItem(ui, RemoveUsers);
  4996. }
  4997. if(OnlyRemoveUser){ return; }
  4998. for (col = uil->Columns.pFirst; col; col = NextCol){
  4999. NextCol = col->Item.pNext;
  5000. lstRemoveItem(&uil->Columns, col);
  5001. memFree(col);
  5002. }
  5003. strSafeDestroy(&uil->TabName);
  5004. if (!NoFree) memFree(uil);
  5005. }
  5006. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  5007. if(ui) lstRemoveItem(&ui->Subs, Tab);
  5008. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  5009. }
  5010. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  5011. laUiItem *Next = after->Item.pNext;
  5012. laUiItem *Last = uil->UiItems.pLast;
  5013. after->Item.pNext = 0;
  5014. uil->UiItems.pLast = after;
  5015. Define(uil, Base, This, ExtraColums, 0);
  5016. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  5017. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  5018. if (Next != Last) uil->UiItems.pLast = Last;
  5019. }
  5020. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  5021. // int i = 0;
  5022. // int FromW=FromR-FromL, ToW=ToR-ToL;
  5023. // if (!ui->ExtraColums) return;
  5024. // for (i; ui->ExtraColums[i]; i++) {
  5025. // laColumn* c = ui->ExtraColums[i];
  5026. // c->B = B;
  5027. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  5028. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  5029. // }
  5030. //}
  5031. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  5032. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  5033. }
  5034. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  5035. laColumn *c = ui->C;
  5036. laColumn *ic = lst->pFirst;
  5037. c->B = ui->TB + LA_M;
  5038. for (ic; ic; ic = ic->Item.pNext){
  5039. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  5040. ic->B = ic->B < c->B ? c->B : ic->B;
  5041. }
  5042. }
  5043. ic = ui->C;
  5044. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  5045. ;
  5046. for (ic; ic; ic = ic->Item.pNext){
  5047. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  5048. ic->B = ic->B < c->B ? c->B : ic->B;
  5049. }
  5050. }
  5051. }
  5052. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  5053. laColumn *c = ui->C;
  5054. laColumn *ic = lst->pFirst;
  5055. c->B = ui->TB + LA_M;
  5056. for (ic; ic; ic = ic->Item.pNext){
  5057. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  5058. ic->B = ic->B < c->B ? c->B : ic->B;
  5059. }
  5060. }
  5061. ic = ui->C;
  5062. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  5063. ;
  5064. for (ic; ic; ic = ic->Item.pNext){
  5065. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  5066. ic->B = ic->B < c->B ? c->B : ic->B;
  5067. }
  5068. }
  5069. }
  5070. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  5071. int rep;
  5072. int sp;
  5073. int rev;
  5074. int M=LA_M*2;
  5075. if (!c) return 0;
  5076. sp = (c->SP * (R - L)) + L;
  5077. rev = sp;
  5078. /*if (U)*/ c->B = U;
  5079. if (LR == 1){
  5080. c->IL = L;
  5081. c->IR = sp;
  5082. if (repos){
  5083. c->IR = repos;
  5084. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  5085. c->IR = c->IL + c->MaxW*LA_RH+M;
  5086. rev = c->IR;
  5087. }
  5088. }else if (LR == 2){
  5089. c->IL = sp;
  5090. c->IR = R;
  5091. if (repos){
  5092. c->IL = repos;
  5093. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  5094. c->IL = c->IR - c->MaxW*LA_RH-M;
  5095. rev = c->IL;
  5096. }
  5097. }else if (LR == 0){
  5098. c->IL = L;
  5099. c->IR = R;
  5100. }
  5101. if (c->LS && c->RS->MaxW == 0){
  5102. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  5103. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  5104. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  5105. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  5106. }else if (c->RS && c->LS->MaxW == 0){
  5107. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  5108. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  5109. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  5110. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  5111. }
  5112. return rev;
  5113. }
  5114. STRUCTURE(laRowInfo){
  5115. int MaxW;
  5116. int MinW;
  5117. int UnitMinW;
  5118. int NonExpandW;
  5119. int TotalPadding;
  5120. int Expand, Even;
  5121. int ExpandAccum;
  5122. int CountElements;
  5123. int U,MaxB,L;
  5124. laListHandle Elements;
  5125. int LastNoHeight;
  5126. };
  5127. STRUCTURE(laRowNode){
  5128. laListItem Item;
  5129. laUiItem* ui;
  5130. int GotW, LP, RP, H;
  5131. int Expand;
  5132. int UseLast;
  5133. int WaitAnimation;
  5134. };
  5135. void la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  5136. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  5137. ri->UnitMinW=LA_RH;
  5138. ri->Expand=ui->State?1:0;
  5139. ri->Even=ui->Flags?1:0;
  5140. ri->U=ui->TU; ri->L=ui->TL;
  5141. ri->MaxB=ui->TU;
  5142. }
  5143. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  5144. laRowNode* rn=CreateNew(laRowNode);
  5145. rn->LP=LA_M;rn->RP=LA_M;
  5146. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  5147. rn->ui=ui;
  5148. rn->H=H;
  5149. rn->Expand=ui->Expand;
  5150. rn->WaitAnimation=WaitAnimation;
  5151. lstAppendItem(&ri->Elements, rn);
  5152. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  5153. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  5154. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  5155. ri->TotalPadding += LA_M*2;
  5156. ri->MinW+=ri->UnitMinW;
  5157. ri->NonExpandW+=rn->GotW;
  5158. ri->ExpandAccum+=ui->Expand;
  5159. ri->CountElements++;
  5160. if(ui->Expand){ri->Expand=1;}
  5161. if(ri->U+H+LA_M>ri->MaxB){ri->MaxB=ri->U+H+LA_M;}
  5162. }
  5163. int la_ShrinkableRowElements(laRowInfo* ri){
  5164. int count=0;
  5165. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5166. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  5167. count++;
  5168. }
  5169. return count;
  5170. }
  5171. void la_RecordSocketRuntimePosition(laUiItem* ui);
  5172. void la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  5173. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  5174. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  5175. if(Available<0){
  5176. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  5177. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  5178. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  5179. }else{
  5180. if(!ri->Expand && Available>0){Available=0;}
  5181. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  5182. }
  5183. if(!ShareCount) return;
  5184. int PerNode = Available/ShareCount;
  5185. int Remaining = Available-PerNode*ShareCount;
  5186. int L = ri->L; int i=0; laRowNode* rn;
  5187. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5188. laUiItem* ui=rn->ui;
  5189. int NodeAdd, Node=rn->GotW;
  5190. if(rn->UseLast){
  5191. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  5192. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  5193. continue;
  5194. }
  5195. if(Available>=0){
  5196. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  5197. NodeAdd+=(i<Remaining?1:0);i++;
  5198. }else{
  5199. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  5200. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  5201. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  5202. }else{ Node=ri->UnitMinW;
  5203. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  5204. }
  5205. }
  5206. ui->TL = L + rn->LP;
  5207. ui->TR = ui->TL + Node+NodeAdd;
  5208. ui->TB = ui->TU + rn->H;
  5209. L=ui->TR+rn->RP;
  5210. if (!rn->WaitAnimation){
  5211. ui->L = ui->TL; ui->R = ui->TR;
  5212. ui->U = ui->TU; ui->B = ui->TB;
  5213. }
  5214. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5215. }
  5216. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  5217. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  5218. memset(ri, 0, sizeof(laRowInfo));
  5219. }
  5220. void la_RecordSocketRuntimePosition(laUiItem* ui){
  5221. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5222. int sl,sr,su,sb;
  5223. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  5224. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  5225. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  5226. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  5227. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  5228. if(pc==LA_PC_SOCKET_OUT){
  5229. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5230. }else{
  5231. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5232. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  5233. }
  5234. }
  5235. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  5236. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  5237. }
  5238. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  5239. int laget_Hyper2InstanceModified(void* instance){
  5240. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  5241. if(level==2){
  5242. laManagedUDF* mu=m->FromFile;
  5243. int not_assigned = (!mu) || mu==MAIN.DummyManageUDF|| mu==MAIN.DummyManageUDFSingle || mu==MAIN.DummyManageUDFSingleForce;
  5244. return (m->Modified||not_assigned)?1:0;
  5245. }
  5246. return 1;
  5247. }
  5248. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  5249. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  5250. laBoxedTheme *bt;
  5251. int Lowest = 0;
  5252. int HyperValue = 0;
  5253. int WaitAnimation;
  5254. int RowMode=0; laRowInfo ri={0};
  5255. laBoxedTheme* pt=*(ParentPanel->BT);
  5256. //int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  5257. int MaxR=0;
  5258. if(!uil->Scale){uil->Scale=1;}
  5259. uil->SaveScale=MAIN.UiScale;
  5260. MAIN.UiScale*=uil->Scale;
  5261. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5262. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  5263. WaitAnimation = 0;
  5264. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  5265. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  5266. for (ui = uil->UiItems.pFirst; ui;){
  5267. int SubB = 0;
  5268. int H;
  5269. WaitAnimation = 0;
  5270. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5271. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  5272. //if (Fast && ui->C->B > B) {
  5273. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  5274. // ui = ui->Item.pNext;
  5275. // continue;
  5276. //}
  5277. if (!ui->Instructions){
  5278. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  5279. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  5280. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  5281. laOperatorProp *ap = ui->PP.LastPs->p;
  5282. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5283. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5284. }
  5285. }
  5286. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5287. la_UsePropPack(&ui->PP, 0);
  5288. if (ui->CompoundPPs.pFirst){
  5289. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5290. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5291. }
  5292. }
  5293. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5294. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5295. // 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);
  5296. //}
  5297. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5298. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5299. WaitAnimation = 1;
  5300. }
  5301. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5302. bt = (*ui->Type->Theme);
  5303. if (ui->Type == &_LA_UI_CONDITION){
  5304. laConditionUiExtraData *cued = ui->Extra;
  5305. la_StepExpression(cued->Expression);
  5306. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5307. if (!cued->IsTrue){
  5308. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5309. }else{
  5310. ui = ui->Item.pNext;
  5311. }
  5312. continue;
  5313. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5314. ui = ui->Item.pNext;
  5315. continue;
  5316. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5317. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5318. if (cued->IsTrue) ui = cued->EndUi;
  5319. else
  5320. ui = ui->Item.pNext;
  5321. continue;
  5322. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5323. laConditionUiExtraData *cued = ui->Extra;
  5324. ui->TL = ui->C->IL + LA_M; ui->TR = ui->C->IR - LA_M;
  5325. ui->TU = ui->C->B + LA_M; ui->TB = ui->TU + LA_RH;
  5326. if (!WaitAnimation){
  5327. ui->L = ui->TL; ui->R = ui->TR;
  5328. ui->U = ui->TU; ui->B = ui->TB;
  5329. }
  5330. if(!RowMode){
  5331. la_CalcUiItemInfluence(&uil->Columns, ui);
  5332. }else{
  5333. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5334. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5335. }
  5336. if (ui->State == LA_UI_NORMAL){
  5337. cued->IsTrue = 0;
  5338. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5339. }else{
  5340. cued->IsTrue = 1;
  5341. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5342. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5343. //}
  5344. ui = ui->Item.pNext;
  5345. }
  5346. continue;
  5347. }
  5348. if (ui->Type == _LA_UI_ALIGN){
  5349. ui->TU = ui->C->B + LA_M; ui->TB = ui->TU+LA_RH/5;
  5350. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5351. if (ui->TB > Lowest) Lowest = ui->TB;
  5352. if (!WaitAnimation){
  5353. ui->L = ui->TL; ui->R = ui->TR;
  5354. ui->U = ui->TU; ui->B = ui->TB;
  5355. }
  5356. if(!RowMode){
  5357. la_CalcUiItemInfluence(&uil->Columns, ui);
  5358. }else{
  5359. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5360. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5361. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5362. }
  5363. ui = ui->Item.pNext; continue;
  5364. }
  5365. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5366. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5367. la_InitRowNode(&ri, ui, bt);
  5368. RowMode=1; ui=ui->Item.pNext; continue;
  5369. }
  5370. if (ui->Type == &_LA_UI_ROW_END){
  5371. la_CalculateRowExpand(&ri, ui);
  5372. la_CalcUiItemInfluence(&uil->Columns, ui);
  5373. RowMode=0; ui=ui->Item.pNext; continue;
  5374. }
  5375. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?0:LA_M); ui->TR = ui->C->IR - (NoGap?0:LA_M); }
  5376. int GB=0;
  5377. 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-LA_M; }
  5378. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5379. ui->TU = ui->C->B + (NoGap?0:LA_M);
  5380. if (H < 0){
  5381. if(B){ H = B + (H+1) * LA_RH - ui->TU-LA_M+((H<-1)?-LA_M:0); }
  5382. else{ H=LA_RH; }
  5383. }
  5384. else H *= LA_RH;
  5385. ui->TB = ui->TU;
  5386. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5387. 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
  5388. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5389. if (ui->Type == _LA_UI_COLLECTION){
  5390. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5391. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5392. ui->PP.EndInstance = TInstance;
  5393. laUiList *iuil = ui->Subs.pFirst;
  5394. laUiList *puil = iuil;
  5395. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5396. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5397. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5398. int Begin = ui->TB;
  5399. int SpreadWidth = Spread*LA_RH; if((!uil->AllowScale) && (SpreadWidth > ui->TR-ui->TL)){ SpreadWidth=ui->TR-ui->TL; }
  5400. int EL = ui->TL, ER = Spread?(SpreadWidth+ui->TL):ui->TR; int MaxER=ER;
  5401. int ElementB = ui->TU;
  5402. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5403. int MaxB = ElementB;
  5404. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5405. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5406. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5407. if (!ElementLimit) RowPriority = 0;
  5408. if (!TInstance){
  5409. while (iuil){
  5410. puil = iuil->Item.pNext;
  5411. la_DestroyTabPage(ui, iuil, 0);
  5412. iuil = puil;
  5413. }
  5414. }
  5415. while (TInstance){
  5416. int UiFilterSkip = uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance));
  5417. int ManagerFilterSkip = MAIN.ManagerFilterInstances && (ui->Flags&LA_UI_COLLECTION_MANAGER_FILTER) && (!laget_Hyper2InstanceModified(TInstance));
  5418. if(UiFilterSkip || ManagerFilterSkip){
  5419. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5420. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5421. ui->PP.EndInstance = TInstance; continue;
  5422. }
  5423. if(CanGetTheme){
  5424. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5425. la_SwitchThemeQuick(t, OriginalTheme);
  5426. }
  5427. if(CanGetGap){
  5428. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5429. Gap=g*LA_RH;
  5430. }else Gap=0;
  5431. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5432. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5433. }else GotCategory=0;
  5434. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5);
  5435. if (RowPriority){
  5436. Row += 1; Col=0; Begin = ElementB+LA_RH*(FirstIn?1:1.5);
  5437. }
  5438. }
  5439. FirstIn=0;
  5440. if (ElementLimit){
  5441. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5442. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth); MaxER=TNS_MAX2(ER,MaxER);
  5443. }
  5444. while (iuil && iuil->Instance != TInstance){
  5445. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5446. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5447. }else{
  5448. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5449. }
  5450. iuil = puil;
  5451. }
  5452. if(!iuil){
  5453. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5454. }
  5455. if (!iuil){
  5456. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5457. la_CalcUiTopInfluence(&uil->Columns, ui);
  5458. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5459. SubB = la_UpdateUiListRecursive(ui->Page, Gap+Begin, EL+(NoDecal?0:LA_M), ER-(NoDecal?0:LA_M), B, Fast, ParentPanel);
  5460. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5461. iuil = ui->Page->Item.pNext;
  5462. }else{
  5463. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5464. SubB = la_UpdateUiListRecursive(iuil, Gap+Begin, EL+(NoDecal?0:LA_M), ER-(NoDecal?0:LA_M), B, Fast, ParentPanel);
  5465. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5466. la_CalcUiItemInfluence(&uil->Columns, ui);
  5467. iuil = iuil->Item.pNext;
  5468. }
  5469. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5470. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5471. ui->PP.EndInstance = TInstance;
  5472. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5473. if (RowPriority){
  5474. Col += 1;
  5475. if (Col >= ElementLimit){
  5476. Col = 0;
  5477. Row += 1;
  5478. Begin = ElementB;
  5479. }
  5480. }elif(Spread){
  5481. EL+=SpreadWidth;
  5482. ER+=SpreadWidth;
  5483. MaxER=TNS_MAX2(ER,MaxER);
  5484. if((!uil->AllowScale) && (ER > ui->TR)){
  5485. EL=ui->TL; ER=SpreadWidth+EL;
  5486. Begin = ElementB;
  5487. }
  5488. }else{
  5489. Row += 1;
  5490. Begin = ElementB;
  5491. if (ElementLimit && Row >= ElementLimit){
  5492. Row = 0;
  5493. Col += 1;
  5494. Begin = ui->TU;
  5495. }
  5496. }
  5497. ui->TB = ElementB;
  5498. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5499. }
  5500. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5501. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5502. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5503. ui->TB = MaxB;
  5504. if(Spread){ ui->TR=MaxER-SpreadWidth; if(ui->TR>MaxR) MaxR=ui->TR; }
  5505. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5506. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5507. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5508. ui->TB=ui->TU+LA_RH;
  5509. }else{
  5510. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5511. ui->PP.EndInstance = TInstance;
  5512. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5513. if(!Template) Template=laui_SubPropInfoDefault;
  5514. //ui->Template = Template;
  5515. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5516. int TopPad = (ui->Type == _LA_UI_COLLECTION_SINGLE)?(NoDecal?0:LA_M):-LA_M;
  5517. int SidePad = NoDecal?0:LA_M;
  5518. if (!ui->Subs.pFirst && TInstance){
  5519. la_AddInstancePage(ui, TInstance, 0);
  5520. la_CalcUiTopInfluence(&uil->Columns, ui);
  5521. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5522. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+TopPad, ui->TL+SidePad, ui->TR-SidePad-EraseWidth, B, Fast, ParentPanel);
  5523. ui->TB = SubB - (NoDecal?0:LA_M);
  5524. }else if (ui->Subs.pFirst){
  5525. if (!TInstance || TInstance != ui->Page->Instance){
  5526. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5527. ui->Page = 0;
  5528. if (TInstance){
  5529. la_AddInstancePage(ui, TInstance, 0);
  5530. la_CalcUiTopInfluence(&uil->Columns, ui);
  5531. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5532. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+TopPad, ui->TL+SidePad, ui->TR-SidePad-EraseWidth, B, Fast, ParentPanel);
  5533. ui->TB = SubB - (NoDecal?0:LA_M);
  5534. }else
  5535. ui->TB = ui->TU + LA_RH;// + bt->BM;
  5536. }else{
  5537. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+TopPad, ui->TL+SidePad, ui->TR-SidePad-EraseWidth, B, Fast, ParentPanel);
  5538. ui->TB = SubB - (NoDecal?0:LA_M);
  5539. }
  5540. }
  5541. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5542. ui->TB=ui->TU+LA_RH;
  5543. }
  5544. if(ui->Type == _LA_UI_COLLECTION_SINGLE){
  5545. ui->TB+= NoDecal?0:LA_M*2;
  5546. }
  5547. }
  5548. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5549. if (!WaitAnimation){
  5550. ui->L = ui->TL;
  5551. ui->R = ui->TR;
  5552. ui->U = ui->TU;
  5553. ui->B = ui->TB;
  5554. }
  5555. }
  5556. }else{
  5557. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5558. if (ui->Type != _LA_UI_CANVAS){
  5559. int scrollw=ui->Page->ScrollerShownV?LA_M*2+LA_SCROLL_W:0;
  5560. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5561. SubB = la_UpdateUiListRecursive(ui->Page,
  5562. ui->TB + (ui->State == LA_UI_ACTIVE ? 0 : LA_RH)+(NoDecal?0:LA_M), ui->TL+(NoDecal?0:LA_M), ui->TR-(NoDecal?0:LA_M)-scrollw, B, Fast, ParentPanel);
  5563. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5564. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH - (LA_M*2)+(ui->Page->HeightCoeff==-2?-LA_M:0) : SubB)) + (NoDecal?0:LA_M);
  5565. ui->Page->LimH = ui->TB-ui->Page->TU - (NoDecal?0:LA_M);
  5566. int subh = ui->TB-ui->TU-LA_RH-LA_M*2;
  5567. if((ui->Page->TR>ui->TR-(NoDecal?0:LA_M) && (!ui->Page->ScrollerShownH)) ||
  5568. (ui->Page->TR<=ui->TR-(NoDecal?0:LA_M) && ui->Page->ScrollerShownH)){
  5569. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5570. }
  5571. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5572. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-LA_M;}
  5573. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-LA_M); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5574. if(ui->Page->HeightCoeff){
  5575. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5576. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5577. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5578. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5579. }
  5580. if(SubB-ui->Page->PanY<ui->TB-LA_M-(ui->Page->ScrollerShownH?LA_SCROLL_W+LA_M:0)){
  5581. ui->Page->PanY = (SubB-ui->TB-LA_M+(ui->Page->ScrollerShownH?LA_SCROLL_W+LA_M:0));
  5582. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5583. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5584. }
  5585. }
  5586. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5587. ui->TB+=(LA_M*2+LA_SCROLL_W); }
  5588. }else{
  5589. laUiList *suil;
  5590. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5591. la_CalcUiTopInfluence(&uil->Columns, ui);
  5592. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5593. SubB = la_UpdateUiListRecursive(suil, ui->TB+(NoDecal?0:LA_M), ui->TL+(NoDecal?0:LA_M), ui->TR-(NoDecal?0:LA_M), ui->TU+H, Fast, ParentPanel);
  5594. }
  5595. }
  5596. ui->TB = ui->TU + H;
  5597. }
  5598. }else ui->TB = ui->TU + H;
  5599. }
  5600. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?0:LA_M) : 0);
  5601. if(!RowMode){
  5602. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5603. }else{
  5604. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5605. }
  5606. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5607. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5608. ui = ui->Item.pNext;
  5609. }
  5610. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5611. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5612. else uil->TB = Lowest;
  5613. if (!WaitAnimation){
  5614. uil->L = uil->TL;
  5615. uil->R = uil->TR;
  5616. uil->U = uil->TU;
  5617. uil->B = uil->TB;
  5618. }
  5619. MAIN.UiScale=uil->SaveScale;
  5620. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5621. return uil->TB;
  5622. }
  5623. int la_AnimateSingleUiSize(int To, int *Now){
  5624. int Delta;
  5625. if (To != *Now){
  5626. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5627. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5628. *Now += Delta;
  5629. return 1;
  5630. }else
  5631. return 0;
  5632. }
  5633. int la_AnimateUiListRecursive(laUiList *uil){
  5634. laUiItem *ui;
  5635. int Again = 0;
  5636. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5637. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5638. if(ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish){
  5639. ui->B=ui->TB; ui->L=ui->TL; ui->R=ui->TR; ui->U=ui->TU;
  5640. }else{
  5641. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5642. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5643. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5644. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5645. }
  5646. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5647. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5648. laUiList *suil;
  5649. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5650. Again += la_AnimateUiListRecursive(suil);
  5651. }
  5652. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5653. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5654. Again += la_AnimateUiListRecursive(ui->Page);
  5655. }
  5656. }
  5657. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5658. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5659. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5660. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5661. return Again;
  5662. }
  5663. void la_DrawEmptyUiItem(laUiItem *ui){
  5664. tnsUseNoTexture();
  5665. tnsColor4d(1, 1, 1, 1);
  5666. tnsVertex2d(ui->L, ui->U);
  5667. tnsVertex2d(ui->R, ui->U);
  5668. tnsVertex2d(ui->R, ui->B);
  5669. tnsVertex2d(ui->L, ui->B);
  5670. tnsPackAs(GL_LINE_LOOP);
  5671. }
  5672. void la_DrawActiveUiItemOverlay(laUiItem *ui){
  5673. tnsUseNoTexture();
  5674. tnsColor4d(1, 1, 1, 1);
  5675. tnsVertex2d(ui->L - 1, ui->U - 1);
  5676. tnsVertex2d(ui->R + 1, ui->U - 1);
  5677. tnsVertex2d(ui->R + 1, ui->B + 1);
  5678. tnsVertex2d(ui->L - 1, ui->B + 1);
  5679. tnsPackAs(GL_LINE_LOOP);
  5680. }
  5681. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5682. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5683. return 1;
  5684. }
  5685. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5686. laUiListDrawItem *uildi = uild->Items.pFirst;
  5687. laUiList *Target = uildi->Target;
  5688. int L, R, U, B;
  5689. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5690. L = Target->L + Target->PanX + uildi->DifX;
  5691. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5692. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5693. U = Target->U + Target->PanY + uildi->DifY;
  5694. return la_UiInBound(ui, L, R, U, B);
  5695. }
  5696. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5697. laUiListDrawItem *uildi = uild->Items.pFirst;
  5698. laUiList *Target = uildi->Target;
  5699. int L, R, U, B;
  5700. if (Target){
  5701. L = Target->L + Target->PanX + uildi->DifX;
  5702. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5703. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5704. U = Target->U + Target->PanY + uildi->DifY;
  5705. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5706. return 1;
  5707. }else{
  5708. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5709. return 1;
  5710. }
  5711. }
  5712. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5713. laUiItem *ui = uil->UiItems.pFirst;
  5714. while (!strGetArgument(ui->Instructions, mark))
  5715. ui = ui->Item.pNext;
  5716. return ui;
  5717. }
  5718. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5719. laUiList *uil;
  5720. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5721. if (uil->Instance == Instance) return uil;
  5722. }
  5723. return uil;
  5724. }
  5725. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5726. int mx=(L+R)/2; int my=(U+B)/2;
  5727. int PadR=uil->ScrollerShownV?LA_SCROLL_W+LA_M*2:0;
  5728. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("⯈", color, R-PadR-LA_RH, R-PadR, my-LA_RH2, LA_TEXT_ALIGN_RIGHT|LA_TEXT_SHADOW); }
  5729. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("⯇", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT|LA_TEXT_SHADOW); }
  5730. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("⯅", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER|LA_TEXT_SHADOW); }
  5731. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("⯆", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER|LA_TEXT_SHADOW); }
  5732. tnsFlush();
  5733. }
  5734. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayedH, int UiR, int BarTop, int BarBottom){
  5735. if(!uil->ScrollerShownV) return;
  5736. int W = LA_SCROLL_W, RM=LA_M;
  5737. int DrawH = (BarBottom-BarTop);
  5738. int Len = (int)((real)DisplayedH / (real)TotalH * (real)DrawH);
  5739. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DrawH);
  5740. int U = BarTop + Offset;
  5741. int B = U + Len;
  5742. int L = UiR - RM*2 - W;
  5743. int R = L + W;
  5744. if (B > BarBottom) B = BarBottom;
  5745. if (U < BarTop) U = BarTop;
  5746. Len=B-U;
  5747. if(Len < LA_RH0){ int Sub=(LA_RH0-Len)/2; U-=Sub; B+=(LA_RH0-Len-Sub); }
  5748. if(U < BarTop){ int Sub=BarTop-U; U+=Sub; B+=Sub; }
  5749. if(B > BarBottom){ int Sub=B-BarBottom; B-=Sub; U-=Sub; }
  5750. if (U < BarTop) U = BarTop;
  5751. tnsUseNoTexture();
  5752. laBoxedTheme* bt=_LA_THEME_PANEL;
  5753. real* color=laThemeColor(bt, LA_BT_TEXT);
  5754. real colorb[4]; tnsVectorSet3v(colorb,color); colorb[3]=0.3;
  5755. la_DrawBoxAutoArrayStyle(L+RM,R-RM,BarTop,BarBottom,bt,LA_BT_NORMAL,colorb,0,1,-1);
  5756. colorb[3]=1;
  5757. la_DrawBoxAutoArrayStyle(L,R,U,B,bt,LA_BT_NORMAL,colorb,0,0,0);
  5758. int HU=(U+B)/2+LA_RH2;
  5759. tnsDrawStringAuto("⋮",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5760. tnsFlush();
  5761. }
  5762. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB, int BarLeft, int BarRight){
  5763. if(!uil->ScrollerShownH) return;
  5764. int W = LA_SCROLL_W,RM=LA_M;
  5765. int DrawW = (BarRight-BarLeft);
  5766. int Len = (int)((real)DisplayW / (real)TotalW * (real)DrawW);
  5767. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DrawW);
  5768. int L = BarLeft + Offset;
  5769. int R = L + Len;
  5770. int U = UiB - RM - W;
  5771. int B = U + W;
  5772. if (R > BarRight) R = BarRight;
  5773. if (L < BarLeft) L = BarLeft;
  5774. Len=R-L;
  5775. if(Len < LA_RH0){ int Sub=(LA_RH0-Len)/2; L-=Sub; R+=(LA_RH0-Len-Sub); }
  5776. if(L < BarLeft){ int Sub=BarLeft-L; L+=Sub; R+=Sub; }
  5777. if(R > BarRight){ int Sub=R-BarRight; R-=Sub; L-=Sub; }
  5778. if (L < BarLeft) L = BarLeft;
  5779. tnsUseNoTexture();
  5780. laBoxedTheme* bt=_LA_THEME_PANEL;
  5781. real* color=laThemeColor(bt, LA_BT_TEXT);
  5782. real colorb[4]; tnsVectorSet3v(colorb,color); colorb[3]=0.3;
  5783. la_DrawBoxAutoArrayStyle(BarLeft,BarRight,U+RM,B-RM,bt,LA_BT_NORMAL,colorb,0,1,-1);
  5784. tnsPackAs(GL_LINE_LOOP);
  5785. colorb[3]=1;
  5786. la_DrawBoxAutoArrayStyle(L,R,U,B,bt,LA_BT_NORMAL,colorb,0,0,0);
  5787. int HU=(U+B)/2+LA_RH2;
  5788. tnsDrawStringAuto("⋯",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5789. tnsFlush();
  5790. }
  5791. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5792. tnsUseNoTexture(); tnsColor4dv(color);
  5793. la_DrawBox(uil->L-LP,uil->R+RP,uil->U,uil->B);
  5794. }
  5795. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5796. laSocketRecord* sr;
  5797. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5798. uild->WiresContainer=container;
  5799. }
  5800. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5801. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5802. if(lip->Target==uild->WiresContainer) break;
  5803. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5804. }
  5805. }
  5806. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5807. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5808. int PanX, PanY;
  5809. if(pc==LA_PC_SOCKET_OUT){
  5810. laNodeOutSocket* s=ui->PP.EndInstance;
  5811. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5812. }else{
  5813. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5814. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5815. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5816. }
  5817. }
  5818. void la_RegenerateWireColors(){
  5819. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5820. laTheme* t=MAIN.CurrentTheme; if(!t) return;
  5821. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5822. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5823. for(int i=0;i<MAIN.WireColorSlices;i++){
  5824. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5825. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5826. }
  5827. }
  5828. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5829. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5830. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5831. tnsInterpolate2dv(v1,v2,0.5,vi);
  5832. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5833. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5834. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5835. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5836. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5837. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5838. tnsVertex2d(v1[0],v1[1]);
  5839. for(int i=1;i<=steps;i++){
  5840. real ratio=i==steps?1.0f:step*i;
  5841. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5842. tnsVertex2d(v1s[0],v1s[1]);
  5843. }
  5844. }
  5845. void la_DrawNodeWires(laUiListDraw* uild){
  5846. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5847. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5848. tnsUseNoTexture();
  5849. #define _RSLICES 16
  5850. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5851. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5852. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5853. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5854. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5855. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5856. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5857. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5858. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5859. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5860. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5861. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5862. }
  5863. if(MAIN.tNodeIn->Source){
  5864. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5865. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5866. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5867. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5868. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5869. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5870. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5871. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5872. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5873. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5874. }
  5875. #undef _RSLICES
  5876. tnsFlush();
  5877. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5878. glLineWidth(ww);
  5879. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5880. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5881. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5882. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5883. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5884. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5885. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5886. }
  5887. if(MAIN.tNodeIn->Source){
  5888. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5889. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5890. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5891. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5892. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5893. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5894. }
  5895. tnsFlush();
  5896. glLineWidth(1);
  5897. la_InitSocketRecord(uild,0);
  5898. }
  5899. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5900. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5901. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5902. }
  5903. int la_DrawUiListRecursive(laUiListDraw *uild, laUiList *uil, int L, int R, int U, int B, int LimH, int ConditionStackLevel, int RegisterNodes){
  5904. laUiItem *ui;
  5905. laBoxedTheme *bt;
  5906. laUiList *sub;
  5907. laUiListDrawItem *uildi;
  5908. int Ret = 0;
  5909. if (!uil) return 0;
  5910. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5911. ui = uil->UiItems.pFirst;
  5912. if(uil->PanY<0){uil->PanY=0;}
  5913. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U)) return 0;
  5914. uil->SaveScale=MAIN.UiScale;
  5915. MAIN.UiScale*=uil->Scale;
  5916. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5917. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5918. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5919. if (ui->Type == &_LA_UI_CONDITION){
  5920. laConditionUiExtraData *cued = ui->Extra;
  5921. la_StepExpression(cued->Expression);
  5922. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5923. if (!cued->IsTrue){
  5924. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5925. }else{
  5926. ui = ui->Item.pNext;
  5927. }
  5928. continue;
  5929. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5930. ui = ui->Item.pNext;
  5931. continue;
  5932. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5933. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5934. if (cued->IsTrue) ui = cued->EndUi;
  5935. else
  5936. ui = ui->Item.pNext;
  5937. continue;
  5938. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5939. laConditionUiExtraData *cued = ui->Extra;
  5940. ui->Type->Draw(ui, LA_RH);
  5941. if (ui->State == LA_UI_NORMAL){
  5942. cued->IsTrue = 0;
  5943. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5944. }else{
  5945. cued->IsTrue = 1;
  5946. ui = ui->Item.pNext;
  5947. }
  5948. continue;
  5949. }
  5950. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5951. int NeedDraw=0;
  5952. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5953. if(NeedDraw){
  5954. if (!ui->Type->Draw){ la_DrawEmptyUiItem(ui); tnsFlush();
  5955. }else{ ui->Type->Draw(ui, LA_RH); }
  5956. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5957. tnsFlush();
  5958. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5959. tnsResetViewMatrix();
  5960. }
  5961. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5962. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5963. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5964. tnsFlush();
  5965. }
  5966. }
  5967. if(NeedDraw || RegisterNodes){
  5968. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5969. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5970. ui->Type == _LA_UI_TAB ||
  5971. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5972. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5973. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5974. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5975. int SidePad=NoDecal?-LA_M:LA_M;
  5976. int RightPad=(ui->Page->ScrollerShownV?LA_SCROLL_W+LA_M*2:0);
  5977. int BottomPad=(ui->Page->ScrollerShownH?LA_SCROLL_W+LA_M:0);
  5978. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5979. int LimH=(ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000);
  5980. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+SidePad, ui->R-SidePad-RightPad,
  5981. U, B, LimH-(NoDecal?0:LA_M)-BottomPad, ConditionStackLevel, DoNodes);
  5982. if (ui->Page->ScrollerShownH){
  5983. int PadBottom=(ui->Page->ScrollerShownH?LA_SCROLL_W+LA_M:0);
  5984. int PadRight=(ui->Page->ScrollerShownV?LA_SCROLL_W+LA_M:0);
  5985. la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5986. ui->Page->R-ui->Page->L, ui->R-ui->L-PadRight,ui->B,
  5987. ui->L+LA_M, ui->R-LA_M-PadRight);
  5988. }
  5989. if (ui->Page->HeightCoeff){
  5990. int PadBottom=(ui->Page->ScrollerShownH?LA_SCROLL_W:0);
  5991. la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5992. ui->Page->B-ui->Page->U, ui->B-ui->Page->U-PadBottom,ui->R,
  5993. ui->Page->U+LA_M,ui->B-LA_M-PadBottom);
  5994. }
  5995. if (ui->Page->AllowScale){ la_DrawUiListArrows(ui->Page,ui->L, ui->R, ui->Page->U, ui->B-LA_SCROLL_W-LA_M*2, laThemeColor(bt, LA_BT_TEXT)); }
  5996. }elif (ui->Type == _LA_UI_COLLECTION){
  5997. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5998. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5999. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  6000. void* SaveInstance = ui->PP.EndInstance;
  6001. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6002. int State;
  6003. ui->PP.EndInstance = sub->Instance;
  6004. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  6005. laTheme* SwitchedTheme=0;
  6006. if(CanGetTheme){
  6007. SwitchedTheme=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  6008. la_SwitchThemeQuick(SwitchedTheme, OriginalTheme);
  6009. }
  6010. if(NeedDraw){ int drawn=0;
  6011. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  6012. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),LA_M,LA_M); drawn=1;
  6013. }
  6014. if (CanGetState && !drawn){
  6015. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  6016. if(State >= 0){
  6017. la_DrawInstanceBkg(sub, laAccentColor(State),LA_M,LA_M); drawn=1;
  6018. }
  6019. }
  6020. if((!drawn) && SwitchedTheme){
  6021. la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),LA_M,LA_M);
  6022. }
  6023. }
  6024. if(sub->TabName && sub->TabName->Ptr){
  6025. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  6026. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  6027. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  6028. ui->L+(NoDecal?0:LA_M)+(NoGap?0:LA_M),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  6029. tnsFlush();
  6030. }
  6031. tnsFlush();
  6032. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, RegisterNodes);
  6033. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  6034. }
  6035. //ui->PP.EndInstance = Active;
  6036. ui->PP.EndInstance = SaveInstance;
  6037. }elif (ui->Type == _LA_UI_CANVAS){
  6038. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6039. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6040. tnsFlush();
  6041. Ret += la_DrawUiListRecursive(uild, sub, L-1, R+1, U-1, B+1, ui->B-LA_M*2-LA_M*2, ConditionStackLevel, RegisterNodes);
  6042. }
  6043. }
  6044. }
  6045. ui = ui->Item.pNext;
  6046. }else{
  6047. ui = ui->Item.pNext;
  6048. }
  6049. }
  6050. tnsFlush();
  6051. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  6052. la_RestoreLastUiListMatrix(uild, B - U);
  6053. MAIN.UiScale=uil->SaveScale;
  6054. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  6055. return Ret;
  6056. }
  6057. int la_RejectByUiList(laOperator* a, int x, int y){
  6058. laListItemPointer* lip=a->LocalUiLists.pFirst;
  6059. if(lip){ laUiList* uil=lip->p;
  6060. if(uil->FL!=uil->FR && (x < uil->FL || y < uil->FU || x > uil->FR || y > uil->FB)){
  6061. //printf("rejected %d %d | %d %d %d %d\n",x,y,uil->FL,uil->FR,uil->FU,uil->FB);
  6062. return 1;
  6063. }
  6064. }
  6065. return 0;
  6066. }
  6067. int laIsInUiItem(laUiItem *ui, laOperator* a, int x, int y){
  6068. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  6069. if (a && la_RejectByUiList(a,x,y)) return 0;
  6070. return 1;
  6071. }
  6072. int laIsInBound(int x, int y, int l, int r, int u, int b){
  6073. if (x < l || x > r || y < u || y > b) return 0;
  6074. return 1;
  6075. }
  6076. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  6077. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  6078. laUiItem *ui, *tui;
  6079. laBoxedTheme *bt;
  6080. laUiList *sub;
  6081. int CPB = 0;
  6082. if (!uil || (LimB && y > LimB)) return 0;
  6083. x += uil->PanX;
  6084. y += uil->PanY;
  6085. for (ui = uil->UiItems.pFirst; ui;){
  6086. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6087. if (ui->Type == &_LA_UI_CONDITION){
  6088. laConditionUiExtraData *cued = ui->Extra;
  6089. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  6090. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6091. if (!cued->IsTrue){
  6092. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6093. }else{
  6094. ui = ui->Item.pNext;
  6095. }
  6096. continue;
  6097. }else if (ui->Type == &_LA_UI_CONDITION_END){
  6098. ui = ui->Item.pNext;
  6099. continue;
  6100. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6101. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6102. if (cued->IsTrue) ui = cued->EndUi;
  6103. else
  6104. ui = ui->Item.pNext;
  6105. continue;
  6106. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6107. laConditionUiExtraData *cued = ui->Extra;
  6108. if (laIsInUiItem(ui, 0, x, y)){
  6109. lstAppendPointer(LocalBuf, uil);
  6110. return ui;
  6111. }
  6112. if (ui->State == LA_UI_NORMAL){
  6113. cued->IsTrue = 0;
  6114. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6115. }else{
  6116. cued->IsTrue = 1;
  6117. ui = ui->Item.pNext;
  6118. }
  6119. continue;
  6120. }
  6121. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  6122. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  6123. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, 0, x, y)){
  6124. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  6125. if(!la_DetectSplit(ui->C, x)) Add=0;
  6126. }
  6127. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  6128. }
  6129. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6130. if (ui->Page->HeightCoeff) CPB = ui->B;
  6131. else CPB = ui->Page->B;
  6132. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6133. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  6134. lstAppendPointer(LocalBuf, uil);
  6135. return tui;
  6136. }
  6137. }else if (laIsInUiItem(ui, 0, x, y)){
  6138. lstAppendPointer(LocalBuf, uil);return ui;
  6139. }
  6140. }
  6141. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  6142. if (laIsInUiItem(ui, 0, x, y)){
  6143. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  6144. if(Deep){
  6145. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  6146. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  6147. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  6148. lstAppendPointer(LocalBuf, iuil);
  6149. lstAppendPointer(LocalBuf, uil);
  6150. return tui;
  6151. }
  6152. }
  6153. }
  6154. }
  6155. lstAppendPointer(LocalBuf, uil);
  6156. return ui;
  6157. }
  6158. }
  6159. if (ui->Type == _LA_UI_CANVAS){
  6160. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6161. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6162. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  6163. lstAppendPointer(LocalBuf, uil);
  6164. return tui;
  6165. }
  6166. }
  6167. }
  6168. if (laIsInUiItem(ui, 0, x, y)){
  6169. lstAppendPointer(LocalBuf, uil);
  6170. return ui;
  6171. }
  6172. }
  6173. ui = ui->Item.pNext;
  6174. }
  6175. return 0;
  6176. }
  6177. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  6178. laListHandle Locals={0};
  6179. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  6180. while(lstPopPointer(&Locals));
  6181. //printf("%s\n", ui?ui->Type->Identifier:"?");
  6182. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  6183. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  6184. if(pc==PCInOrOut) return ui;
  6185. }
  6186. return 0;
  6187. }
  6188. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  6189. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  6190. laUiItem *ui = uil->UiItems.pFirst;
  6191. laBoxedTheme *bt;
  6192. laUiList *tuil;
  6193. laUiList *sub;
  6194. int CPB = 0;
  6195. x += uil->PanX;
  6196. y += uil->PanY;
  6197. if (y > LimH) return uil;
  6198. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  6199. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  6200. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6201. return uil;
  6202. }
  6203. for (ui = uil->UiItems.pFirst; ui;){
  6204. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6205. if (ui->Type == &_LA_UI_CONDITION){
  6206. laConditionUiExtraData *cued = ui->Extra;
  6207. //la_StepExpression(cued->Expression);
  6208. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6209. if (!cued->IsTrue){
  6210. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6211. }else{
  6212. ui = ui->Item.pNext;
  6213. }
  6214. continue;
  6215. }
  6216. if (ui->Type == &_LA_UI_CONDITION_END){
  6217. ui = ui->Item.pNext;
  6218. continue;
  6219. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6220. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6221. if (cued->IsTrue) ui = cued->EndUi;
  6222. else
  6223. ui = ui->Item.pNext;
  6224. continue;
  6225. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6226. laConditionUiExtraData *cued = ui->Extra;
  6227. if (ui->State == LA_UI_NORMAL){
  6228. cued->IsTrue = 0;
  6229. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6230. }else{
  6231. cued->IsTrue = 1;
  6232. ui = ui->Item.pNext;
  6233. }
  6234. continue;
  6235. }
  6236. if (InToContainerUI && ui != Exception){
  6237. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6238. if (ContainerParent) (*ContainerParent) = uil;
  6239. if (ParentUi) *ParentUi = ui;
  6240. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6241. //if (y > LimH) return uil;
  6242. 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))){
  6243. return tuil;
  6244. }
  6245. }
  6246. }
  6247. }
  6248. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6249. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  6250. else CPB = ui->Page->B;
  6251. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - LA_M*2, ui->R, ui->Page->U, CPB)){
  6252. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6253. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - LA_M*2, ui->B)){
  6254. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6255. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6256. if (ParentUi) *ParentUi = ui;
  6257. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  6258. }
  6259. }
  6260. ui = ui->Item.pNext;
  6261. }
  6262. return uil;
  6263. }
  6264. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  6265. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  6266. laUiItem *ui = uil->UiItems.pFirst;
  6267. laBoxedTheme *bt;
  6268. laUiList *tuil;
  6269. laUiList *sub;
  6270. int CPB = 0;
  6271. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  6272. x += uil->PanX;
  6273. y += uil->PanY;
  6274. if (y > LimH) return uil;
  6275. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  6276. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  6277. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6278. return uil;
  6279. }
  6280. for (ui = uil->UiItems.pFirst; ui;){
  6281. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6282. if (ui->Type == &_LA_UI_CONDITION){
  6283. laConditionUiExtraData *cued = ui->Extra;
  6284. //la_StepExpression(cued->Expression);
  6285. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6286. if (!cued->IsTrue){
  6287. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6288. }else{
  6289. ui = ui->Item.pNext;
  6290. }
  6291. continue;
  6292. }
  6293. if (ui->Type == &_LA_UI_CONDITION_END){
  6294. ui = ui->Item.pNext;
  6295. continue;
  6296. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6297. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6298. if (cued->IsTrue) ui = cued->EndUi;
  6299. else
  6300. ui = ui->Item.pNext;
  6301. continue;
  6302. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6303. laConditionUiExtraData *cued = ui->Extra;
  6304. if (ui->State == LA_UI_NORMAL){
  6305. cued->IsTrue = 0;
  6306. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6307. }else{
  6308. cued->IsTrue = 1;
  6309. ui = ui->Item.pNext;
  6310. }
  6311. continue;
  6312. }
  6313. if (InToContainerUI && ui != Exception){
  6314. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6315. if (ContainerParent) (*ContainerParent) = uil;
  6316. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6317. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6318. //if (y > LimH) return uil;
  6319. 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))){
  6320. return tuil;
  6321. }
  6322. }
  6323. }
  6324. }
  6325. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6326. if (ui->Page->HeightCoeff) CPB = ui->B;
  6327. else CPB = ui->Page->B;
  6328. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - LA_M*2, ui->R, ui->Page->U, CPB)){
  6329. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6330. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - LA_M*2, ui->B)){
  6331. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6332. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6333. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6334. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6335. }
  6336. }
  6337. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6338. if (ui->Page->HeightCoeff) CPB = ui->B;
  6339. else
  6340. CPB = ui->Page->B;
  6341. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + LA_M, ui->Page->U, CPB)){
  6342. if (ScrollUil) *ScrollUil = ui->Page;
  6343. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6344. }
  6345. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6346. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6347. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6348. }
  6349. }
  6350. ui = ui->Item.pNext;
  6351. }
  6352. return uil;
  6353. }
  6354. int la_TestUiListMinumWidth(laUiList *uil){
  6355. laUiItem *ui, *tui;
  6356. laBoxedTheme *bt;
  6357. laUiList *sub;
  6358. int CPB = 0;
  6359. int W = 0;
  6360. int tW, sW, RowMode=0, rW;
  6361. void *Restore;
  6362. for (ui = uil->UiItems.pFirst; ui;){
  6363. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6364. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6365. tW = la_TestUiListMinumWidth(ui->Page) + LA_M*2;
  6366. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6367. if (W < tW) W = tW;
  6368. }elif (ui->Type == _LA_UI_COLLECTION){
  6369. Restore = ui->PP.EndInstance;
  6370. tW = 0; sW = 0;
  6371. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6372. ui->PP.EndInstance = sub->Instance;
  6373. sW = la_TestUiListMinumWidth(sub) + LA_M*2;
  6374. if (sW > tW) tW = sW;
  6375. }
  6376. ui->PP.EndInstance = Restore;
  6377. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6378. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6379. if (W < tW) W = tW;
  6380. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6381. RowMode=1; rW=0;
  6382. }elif (ui->Type==&_LA_UI_ROW_END){
  6383. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6384. }elif (ui->Type->GetMinWidth){
  6385. tW = ui->Type->GetMinWidth(ui) + LA_M*2;
  6386. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6387. }
  6388. ui = ui->Item.pNext;
  6389. }
  6390. return W;
  6391. }
  6392. void la_InitLLVM(){
  6393. //LLVMLinkInMCJIT();
  6394. //LLVMInitializeNativeTarget();
  6395. //LLVMInitializeNativeAsmPrinter();
  6396. //LLVMInitializeNativeAsmParser();
  6397. // MAIN.llvmContext = LLVMGetGlobalContext();
  6398. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6399. }
  6400. //==================================================================================================
  6401. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6402. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6403. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6404. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6405. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6406. memFree(kmi);
  6407. }
  6408. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6409. laKeyMapItem *kmi;
  6410. if (!km) return 0;
  6411. kmi = memAcquire(sizeof(laKeyMapItem));
  6412. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6413. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6414. }else{
  6415. strSafeSet(&kmi->Operation, Operation);
  6416. }
  6417. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6418. kmi->SpecialKeyBits = SpecialKeyBits;
  6419. kmi->EventType = EventType;
  6420. kmi->Key = tolowerGuarded(Key);
  6421. kmi->SelectBase = SelectBase;
  6422. lstAppendItem(&km->Items, kmi);
  6423. return kmi;
  6424. }
  6425. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6426. laKeyMapItem *kmi; int inv=0;
  6427. char *instructions;
  6428. if(e->type==LA_MOUSEMOVE) return 0;
  6429. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6430. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6431. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6432. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6433. if (kmi->Operation)
  6434. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6435. else
  6436. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6437. inv = 1;
  6438. }
  6439. }
  6440. return inv;
  6441. }
  6442. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6443. laKeyMapItem *kmi;
  6444. char *instructions;
  6445. int inv = 0; int lx = -1, ly = -1;
  6446. if(e->type==LA_MOUSEMOVE) return 0;
  6447. if(e->type == LA_OPERATOR_EVENT && e->OperatorBase){
  6448. if (e->OperatorBase == LA_KM_SEL_UI_EXTRA){
  6449. laInvokeP(from, e->Operator, e, UiExtra, e->OperatorInstructions, 0);
  6450. }elif (e->OperatorBase == LA_KM_SEL_PANEL){
  6451. laInvokeP(from, e->Operator, e, &((laPanel *)MAIN.ToPanel)->PP, e->OperatorInstructions, 0);
  6452. }
  6453. return 1;
  6454. }
  6455. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6456. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6457. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6458. if (e->Localized){
  6459. lx = e->x;
  6460. ly = e->y;
  6461. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6462. e->Localized = 0;
  6463. }
  6464. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6465. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6466. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6467. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6468. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6469. }elif (kmi->Operation){
  6470. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6471. }else{
  6472. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6473. }
  6474. inv = 1;
  6475. if (lx >= 0){
  6476. e->x = lx;
  6477. e->y = ly;
  6478. e->Localized = 1;
  6479. }
  6480. }
  6481. }
  6482. return inv;
  6483. }
  6484. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6485. void la_DestroyOperatorType(laOperatorType* at){
  6486. //if(at->PC) la_FreePropertyContainer(at->PC);
  6487. memFree(at);
  6488. }
  6489. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6490. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6491. uint32_t IconID, int ExtraMark){
  6492. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6493. at->Identifier = ID;
  6494. at->Name = Name;
  6495. at->Description = Description;
  6496. at->Check = Check;
  6497. at->Invoke = Invoke;
  6498. at->Init = Init;
  6499. at->Exit = Exit;
  6500. at->Modal = Modal;
  6501. at->IconID = IconID;
  6502. at->ExtraMark = ExtraMark;
  6503. at->ParseArgs = la_DefaultOperatorParser;
  6504. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6505. lstAppendItem2(&MAIN.OperatorList, at);
  6506. return at;
  6507. }
  6508. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6509. ot->PC = memAcquire(sizeof(laPropContainer));
  6510. ot->PC->Identifier = ot->Identifier;
  6511. ot->PC->Hyper = HyperLevel;
  6512. return ot->PC;
  6513. }
  6514. laOperator *la_CreateOperator(laOperatorType *at){
  6515. laOperator *a = CreateNew(laOperator);
  6516. a->Type = at;
  6517. if (at->PC && at->PC->Props.pFirst){
  6518. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6519. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6520. a->PP.LastPs->p->SubProp = at->PC;
  6521. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6522. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6523. a->PP.LastPs->Type = U'.';
  6524. }
  6525. return a;
  6526. }
  6527. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6528. return (!strcmp(a->Identifier, id));
  6529. }
  6530. laOperatorType *laGetOperatorType(const char *ID){
  6531. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6532. }
  6533. int laOperatorExistsT(laOperatorType* at){
  6534. if (!at) return 0;
  6535. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6536. return 0;
  6537. }
  6538. int laOperatorExists(const char* ID){
  6539. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6540. return laOperatorExistsT(at);
  6541. }
  6542. int la_OperatorExists(laOperator *ac){
  6543. if (!ac) return 0;
  6544. laOperator *a;
  6545. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6546. return 0;
  6547. }
  6548. int la_UiOperatorExists(void *inst){
  6549. laOperator *a;
  6550. if (!inst) return 0;
  6551. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6552. if (((laUiItem *)a->Instance) == inst){
  6553. return 1;
  6554. }
  6555. }
  6556. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6557. if (a->Instance == inst){
  6558. return 1;
  6559. }
  6560. }
  6561. return 0;
  6562. }
  6563. int la_OperatorPending(laOperator *target){
  6564. laOperator *a;
  6565. if (!target) return 0;
  6566. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6567. if (a == target){
  6568. return 1;
  6569. }
  6570. }
  6571. return 0;
  6572. }
  6573. void laSetOperatorLocalizer(void *ToPanel){
  6574. MAIN.ToPanel = ToPanel;
  6575. }
  6576. void la_DestroyConfirmData(laConfirmData **cd);
  6577. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6578. laOperator *ai = (*a);
  6579. laOperator *ac = ((*a)->Child);
  6580. void *Ret = 0;
  6581. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6582. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6583. }
  6584. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6585. if ((*a)->PP.LastPs){
  6586. memFree((*a)->PP.LastPs->p);
  6587. memFree((*a)->PP.LastPs);
  6588. }
  6589. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6590. la_SetPropMathcerContext((*a)->OperatorPanel);
  6591. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6592. laDestroySinglePanel((*a)->OperatorPanel,0);
  6593. }
  6594. if ((*a)->CreatedThis){ la_FreePropStepCache((*a)->CreatedThis->Go); memFree((*a)->CreatedThis); }
  6595. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6596. lstClearPointer(&(*a)->LocalUiLists);
  6597. if (Operators){
  6598. Ret = ai->Item.pNext;
  6599. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6600. else
  6601. lstRemoveItem(Operators, *a);
  6602. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6603. if (ai->Child == (*a)) ai->Child = 0;
  6604. }
  6605. }
  6606. strSafeDestroy(&(*a)->RuntimeHint);
  6607. free(*a);
  6608. return Ret;
  6609. }
  6610. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6611. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6612. if (!at) return 0;
  6613. if (!at->Check) return 1;
  6614. return (at->Check(This, Instructions));
  6615. }
  6616. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6617. if (!at) return 0;
  6618. if (!at->Check) return 1;
  6619. return (at->Check(This, Instructions));
  6620. }
  6621. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6622. laPropPack FakePP = {0};
  6623. laPropStep FakePs = {0};
  6624. if (!at) return 0;
  6625. if (!at->Check) return 1;
  6626. FakePP.LastPs = &FakePs;
  6627. FakePP.Go = FakePP.LastPs;
  6628. FakePP.LastPs->p = This->LastPs->p;
  6629. FakePP.LastPs->UseInstance = This->EndInstance;
  6630. FakePP.EndInstance = Real_FromInstance;
  6631. FakePP.LastIndex = This->LastIndex;
  6632. return (at->Check(&FakePP, Instructions));
  6633. }
  6634. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6635. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6636. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6637. }
  6638. void la_EnsureLocalizedEvent(laOperator *From, laOperator *a, laEvent *e){
  6639. if(!a){ return; }
  6640. laOperatorType *at=a->Type;
  6641. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6642. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6643. e->Localized = 1;
  6644. }
  6645. if (e&&e->Localized && From){
  6646. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6647. laLocalToWindow(From, From->ToPanel, &e->x, &e->y);
  6648. e->Localized = 0;
  6649. }else{
  6650. laLocalToWindow(From, From->ToPanel, &e->x, &e->y);
  6651. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6652. }
  6653. }
  6654. }
  6655. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6656. laOperator *a, *f = From;
  6657. int rev;
  6658. if (!f && e&&e->Localized) return -1;
  6659. a = la_CreateOperator(at);
  6660. a->ToPanel = MAIN.ToPanel;
  6661. a->This = This;
  6662. a->ExtraInstructions = args;
  6663. strMakeInstructions(&a->ExtraInstructionsP, args);
  6664. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6665. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6666. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6667. la_DestroyOperator(&a, 0, 0);
  6668. return LA_CANCELED;
  6669. }
  6670. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6671. la_EnsureLocalizedEvent(From,a,e);
  6672. if (From) f->Child = a;
  6673. a->Using = 1;
  6674. if (at->Init) at->Init(a);
  6675. rev = at->Invoke(a, e);
  6676. a->Using = 0;
  6677. if (rev & LA_FINISH){
  6678. a->StopNow = 1; if(From)From->Child=0;
  6679. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6680. }
  6681. la_EnsureLocalizedEvent(a, From, e);
  6682. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6683. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6684. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6685. a->State = rev;
  6686. a->PP.EndInstance = a->CustomData;
  6687. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6688. } else {
  6689. la_DestroyOperator(&a, 0, 0);
  6690. }
  6691. return rev;
  6692. }
  6693. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6694. laOperatorType *at; laOperator *a, *f = From;
  6695. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6696. if (!at) return -1;
  6697. return laInvokeP(From,at,e,This,args,args2);
  6698. }
  6699. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6700. laOperator *a, *f = From;
  6701. int rev;
  6702. laPropPack *created;
  6703. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6704. created = memAcquireSimple(sizeof(laPropPack));
  6705. la_CopyPropPack(OrigionalThis, created);
  6706. created->EndInstance = FromInstance;
  6707. a = la_CreateOperator(at);
  6708. a->ToPanel = MAIN.ToPanel;
  6709. a->This = created;
  6710. a->CreatedThis = created;
  6711. a->ExtraInstructions = args;
  6712. strMakeInstructions(&a->ExtraInstructionsP, args);
  6713. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6714. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6715. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6716. la_DestroyOperator(&a, 0, 0);
  6717. return LA_CANCELED;
  6718. }
  6719. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6720. la_EnsureLocalizedEvent(From,a,e);
  6721. if (From) f->Child = a;
  6722. a->Using = 1;
  6723. if (at->Init) at->Init(a);
  6724. rev = at->Invoke(a, e);
  6725. a->Using = 0;
  6726. la_EnsureLocalizedEvent(a,From,e);
  6727. if (rev & LA_FINISH){
  6728. a->StopNow = 1; if(From)From->Child=0;
  6729. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6730. }
  6731. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6732. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6733. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6734. a->State = rev;
  6735. a->PP.EndInstance = a->CustomData;
  6736. }else
  6737. la_DestroyOperator(&a, 0, 0);
  6738. return rev;
  6739. }
  6740. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6741. laOperator *a, *f = From;
  6742. int rev=0;
  6743. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6744. a = la_CreateOperator(at);
  6745. a->Instance = inst;
  6746. a->ToPanel = MAIN.ToPanel;
  6747. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6748. la_EnsureLocalizedEvent(From,a,e);
  6749. if (From) f->Child = a;
  6750. a->Using = 1;
  6751. if (at->Init) at->Init(a);
  6752. rev = at->Invoke(a, e);
  6753. a->Using = 0;
  6754. la_EnsureLocalizedEvent(a,From,e);
  6755. if (rev & LA_FINISH){
  6756. a->StopNow = 1; if(From)From->Child=0;
  6757. }elif (rev & LA_BLOCK){
  6758. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6759. a->State = rev;
  6760. }else la_DestroyOperator(&a, 0, 0);
  6761. DEB = a;
  6762. return rev;
  6763. }
  6764. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6765. laOperatorType *at;
  6766. laOperator *a, *f = From;
  6767. if (la_UiOperatorExists(inst)) return -1;
  6768. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6769. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6770. }
  6771. void laRequestDelayEvent(real Seconds){
  6772. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6773. int la_UiStillInService(void *UiInstance){
  6774. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6775. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6776. if (ai->Instance == UiInstance) return 1;
  6777. }
  6778. return 0;
  6779. }
  6780. void la_StopUiOperatorService(void *UiInstance){
  6781. laOperator *ai, *dai, *NextAi;
  6782. if (!MAIN.CurrentWindow) return;
  6783. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6784. NextAi = ai->Item.pNext;
  6785. if (ai->Instance == UiInstance){
  6786. if (ai->Child){
  6787. la_StopUiOperatorService(ai->Child->Instance);
  6788. ai->Child = 0;
  6789. }
  6790. laOperator *dai = ai;
  6791. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6792. continue;
  6793. }
  6794. }
  6795. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6796. NextAi = ai->Item.pNext;
  6797. if (ai->Instance == UiInstance){
  6798. if (ai->Instance == ai->ToPanel){
  6799. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6800. //ai->ToPanel->LaterDestroy = 1;
  6801. }
  6802. if (ai->Child && la_OperatorExists(ai->Child)){
  6803. la_StopUiOperatorService(ai->Child->Instance);
  6804. //ai->Child = 0;
  6805. }
  6806. if (!ai->Using){
  6807. laOperator *dai = ai;
  6808. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6809. }else
  6810. ai->StopNow = 1;
  6811. }
  6812. }
  6813. }
  6814. void la_StopAllOperators(){
  6815. laOperator *ai, *dai, *NextAi;
  6816. if (!MAIN.CurrentWindow) return;
  6817. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6818. NextAi = ai->Item.pNext;
  6819. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6820. continue;
  6821. }
  6822. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6823. NextAi = ai->Item.pNext;
  6824. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6825. laHidePanelWithDissoveEffect(ai->ToPanel);
  6826. ai->ToPanel->LaterDestroy = 1;
  6827. }
  6828. if (!ai->Using){
  6829. laOperator *dai = ai;
  6830. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6831. }else ai->StopNow = 1;
  6832. }
  6833. }
  6834. void la_DestroyConfirmData(laConfirmData **cd){
  6835. if((!cd)||!(*cd)) return;
  6836. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6837. if ((*cd)->StrData) free((*cd)->StrData);
  6838. FreeMem((*cd));
  6839. (*cd) = 0;
  6840. }
  6841. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6842. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6843. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6844. ai->NextConfirmData = cd; laRetriggerOperators();
  6845. }
  6846. void laConfirmInt(laOperator *a, int Data, int mode){
  6847. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6848. cd->IData = Data; cd->Mode = mode;
  6849. ai->NextConfirmData = cd; laRetriggerOperators();
  6850. }
  6851. void laConfirmFloat(laOperator *a, real Data, int mode){
  6852. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6853. cd->FData = Data; cd->Mode = mode;
  6854. ai->NextConfirmData = cd; laRetriggerOperators();
  6855. }
  6856. void laConfirmString(laOperator *a, char *Str, int mode){
  6857. laOperator *ai = a;
  6858. laConfirmData *cd = CreateNew(laConfirmData);
  6859. int len = strlen(Str);
  6860. char *buf = calloc(len + 1, sizeof(char));
  6861. strcpy(buf, Str);
  6862. cd->StrData = buf;
  6863. cd->Mode = mode;
  6864. cd->Destroy = free;
  6865. ai->NextConfirmData = cd;
  6866. laRetriggerOperators();
  6867. }
  6868. int laConfirmSameDataIfAny(laOperator *a){
  6869. laOperator *ai = a;
  6870. laConfirmData *cd;
  6871. char *buf = 0;
  6872. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6873. cd = CreateNew(laConfirmData);
  6874. if (ai->ConfirmData->StrData){
  6875. int len = strlen(ai->ConfirmData->StrData);
  6876. buf = calloc(len + 1, sizeof(char));
  6877. strcpy(buf, ai->ConfirmData->StrData);
  6878. }
  6879. //cd->CustomData = cd->CustomData;
  6880. cd->IData = ai->ConfirmData->IData;
  6881. cd->FData = ai->ConfirmData->FData;
  6882. cd->PointerData = ai->ConfirmData->PointerData;
  6883. cd->PointerType = a->ConfirmData->PointerType;
  6884. cd->StrData = buf;
  6885. cd->Mode = ai->ConfirmData->Mode;
  6886. cd->Destroy = ai->ConfirmData->Destroy;
  6887. ai->NextConfirmData = cd;
  6888. laRetriggerOperators();
  6889. return 1;
  6890. }
  6891. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6892. laOperator *ai = a;
  6893. laConfirmData *cd = CreateNew(laConfirmData);
  6894. cd->CustomData = UserData;
  6895. cd->Mode = mode;
  6896. cd->Destroy = Destroy;
  6897. ai->NextConfirmData = cd;
  6898. laRetriggerOperators();
  6899. }
  6900. int laGetConfirmMode(laOperator *a){
  6901. return ((laOperator *)a)->ConfirmData->Mode;
  6902. }
  6903. int laGetConfirmInt(laOperator *a){
  6904. laOperator *ai = a;
  6905. int rev = ai->ConfirmData->IData;
  6906. la_DestroyConfirmData(&ai->ConfirmData);
  6907. ai->ConfirmData = 0;
  6908. return rev;
  6909. }
  6910. real laGetConfirmFloat(laOperator *a){
  6911. laOperator *ai = a;
  6912. real rev = ai->ConfirmData->FData;
  6913. la_DestroyConfirmData(&ai->ConfirmData);
  6914. ai->ConfirmData = 0;
  6915. return rev;
  6916. }
  6917. void laGetConfirmString(laOperator *a, char *buf){
  6918. laOperator *ai = a;
  6919. strcpy(buf, ai->ConfirmData->StrData);
  6920. la_DestroyConfirmData(&ai->ConfirmData);
  6921. ai->ConfirmData = 0;
  6922. }
  6923. void *laGetConfirmUserData(laOperator *a){
  6924. laOperator *ai = a;
  6925. return ai->ConfirmData->CustomData;
  6926. }
  6927. void laFinalizeOperators(){
  6928. laOperatorType *at;
  6929. laListHandle *lst;
  6930. int i;
  6931. for (i = 0; i < 256; i++){
  6932. lst = &MAIN.OperatorTypeHash.Entries[i];
  6933. for (at = lst->pFirst; at; at = at->Item.pNext){
  6934. if (at->PC && at->PC->Props.pFirst){
  6935. lstAppendItem(&MAIN.PropContainers, at->PC);
  6936. }
  6937. }
  6938. }
  6939. }
  6940. //=================
  6941. #ifdef LA_LINUX
  6942. static void la_RecordWacomMotions(XIRawEvent *event)
  6943. {
  6944. double *valuator = event->valuators.values;
  6945. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6946. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6947. //SYSWINDOW root_return, child_return;
  6948. //int root_x_return, root_y_return;
  6949. //int win_x_return, win_y_return;
  6950. //unsigned int mask_return;
  6951. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6952. // &root_x_return, &root_y_return,
  6953. // &win_x_return, &win_y_return,
  6954. // &mask_return);
  6955. //
  6956. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6957. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6958. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6959. real x=valuator[3],y=valuator[4];
  6960. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6961. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6962. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6963. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6964. if(XIMaskIsSet(event->valuators.mask, 5)){
  6965. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6966. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6967. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6968. MAIN.IsPen=1;
  6969. }
  6970. #endif
  6971. #ifdef _WIN32
  6972. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6973. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6974. static uint32_t ch = 0; static int lead = 0;
  6975. static wchar_t buf[10] = { 0 }; int adv;
  6976. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6977. short wheelmark = 0;
  6978. int WheelDir = 0;
  6979. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6980. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6981. POINT point;
  6982. PACKET pkt;
  6983. static POINT ptOld, ptNew;
  6984. static UINT prsOld, prsNew, vkey;
  6985. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6986. switch (message) {
  6987. case WM_PAINT:
  6988. //SwapBuffers(GetDC(hwnd));
  6989. break;
  6990. case WM_MOUSEMOVE:
  6991. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6992. MAIN.IsPen = 0;
  6993. break;
  6994. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6995. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6996. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6997. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6998. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6999. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  7000. case WM_MOUSEWHEEL:
  7001. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  7002. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  7003. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  7004. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  7005. break;
  7006. case WT_PACKET:
  7007. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  7008. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  7009. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  7010. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  7011. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  7012. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  7013. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  7014. MAIN.StylusTwist = tw;
  7015. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  7016. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  7017. MAIN.EraserPressure = MAIN.StylusPressure;
  7018. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  7019. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  7020. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  7021. }
  7022. return 0; break;
  7023. case WM_SYSCOMMAND:
  7024. switch (wparam) {
  7025. case SC_MAXIMIZE:
  7026. case SC_RESTORE:
  7027. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  7028. break;
  7029. case SC_KEYMENU:
  7030. return 0;
  7031. case SC_MINIMIZE:
  7032. break;
  7033. }
  7034. break;
  7035. case WM_SIZE:
  7036. if (wparam == SIZE_MINIMIZED) break;
  7037. case WM_MOVE: /* And size */
  7038. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  7039. break;
  7040. case WM_SETCURSOR:
  7041. if(MAIN.CurrentCursor) return 1;
  7042. break;
  7043. case WM_POINTERDOWN:
  7044. case WM_POINTERUP:
  7045. case WM_POINTERUPDATE:
  7046. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  7047. pointerId = GET_POINTERID_WPARAM(wparam);
  7048. pointerType = PT_POINTER;
  7049. if(!GetPointerType(pointerId, &pointerType)){
  7050. pointerType = PT_POINTER;
  7051. }
  7052. if(pointerType == PT_PEN){
  7053. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  7054. for (int i = peninfonum-1; i>=0; i--) {
  7055. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  7056. ScreenToClient(hwnd, &point);
  7057. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  7058. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  7059. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  7060. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  7061. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  7062. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  7063. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  7064. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  7065. }
  7066. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  7067. }
  7068. }
  7069. SkipPointerFrameMessages(pointerId);
  7070. return 0;
  7071. }
  7072. else if (pointerType == PT_TOUCH){
  7073. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  7074. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  7075. ScreenToClient(hwnd, &point);
  7076. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  7077. }
  7078. }
  7079. break;
  7080. case WM_SYSKEYDOWN:
  7081. //if (lparam & 0x40000000) break;
  7082. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  7083. break;
  7084. case WM_KEYDOWN:
  7085. //if (lparam & 0x40000000) break;
  7086. vkey = wparam;
  7087. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  7088. break;
  7089. case WM_KEYUP:
  7090. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  7091. break;
  7092. case WM_SYSKEYUP:
  7093. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  7094. break;
  7095. case WM_UNICHAR:
  7096. la_SendInputEvent(hwnd, wparam);
  7097. break;
  7098. case WM_IME_CHAR:
  7099. char character[3]; character[0]=(BYTE)(wparam>>8); character[1] = wparam; character[2]=0;
  7100. wchar_t buf[10]; MultiByteToWideChar(CP_ACP, 0, character, -1, buf, 9);
  7101. la_SendInputEvent(hwnd, buf[0]);
  7102. return 0;
  7103. case WM_CHAR:
  7104. la_SendInputEvent(hwnd, wparam);
  7105. break;
  7106. case WM_SHOWWINDOW:
  7107. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  7108. break;
  7109. case WM_CLOSE:
  7110. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  7111. break;
  7112. default:
  7113. return DefWindowProc(hwnd, message, wparam, lparam);
  7114. }
  7115. return DefWindowProc(hwnd, message, wparam, lparam);
  7116. }
  7117. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  7118. switch (message) {
  7119. case WM_CLOSE:
  7120. return 0;
  7121. case WM_DESTROY:
  7122. return 0;
  7123. case LA_PROGRESS_REPAINT_MESSAGE:
  7124. InvalidateRect(MAIN.Progress.w, 0, 1);
  7125. int w = GetSystemMetrics(SM_CXFULLSCREEN), h = GetSystemMetrics(SM_CYFULLSCREEN);
  7126. int ww = PROGRESSW + LA_RH * 2;
  7127. SetWindowPos(MAIN.Progress.w, HWND_TOPMOST,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2, 0);
  7128. return 0;
  7129. case WM_PAINT:
  7130. LA_ACQUIRE_DC
  7131. laBoxedTheme* bt = _LA_THEME_TAB; real* fg = laThemeColor(bt, LA_BT_TEXT); real* bg = laThemeColor(bt, LA_BT_NORMAL);
  7132. if (!MAIN.Progress.brush_bg) { MAIN.Progress.brush_bg = CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  7133. if (!MAIN.Progress.brush_fg) { MAIN.Progress.brush_fg = CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  7134. if (!MAIN.Progress.pen_fg) { MAIN.Progress.pen_fg = CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  7135. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  7136. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w, &ps);
  7137. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  7138. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  7139. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  7140. Rectangle(MAIN.Progress.hdc, LA_RH * 2, 0, LA_RH * 2 + PROGRESSW * MAIN.Progress.p1, LA_RH);
  7141. Rectangle(MAIN.Progress.hdc, LA_RH * 2, LA_RH, LA_RH * 2 + PROGRESSW * MAIN.Progress.p2, LA_RH + LA_RH);
  7142. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  7143. tnsDrawLCD7_ProgressSystem(LA_RH * 1.5, 0, MAIN.Progress.p1);
  7144. tnsDrawLCD7_ProgressSystem(LA_RH * 1.5, LA_RH, MAIN.Progress.p2);
  7145. EndPaint(MAIN.Progress.w, &ps);
  7146. LA_LEAVE_DC
  7147. }
  7148. return DefWindowProc(hwnd, message, wparam, lparam);
  7149. }
  7150. #endif
  7151. void la_UpdateOperatorHints(laWindow* w){
  7152. laSafeString* ss=0;
  7153. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  7154. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  7155. }
  7156. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  7157. }else{
  7158. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  7159. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  7160. }
  7161. strSafeDestroy(&ss);
  7162. }
  7163. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  7164. laOperator *a, *NextA = 0;
  7165. int Result = 0;
  7166. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  7167. la_SendSignalsFromEvent(e);
  7168. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  7169. a = Operators->pFirst;
  7170. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  7171. //la_PrintOperatorStack();
  7172. while (1){
  7173. if (!a) break;
  7174. if (a->StopNow){
  7175. NextA = a->Item.pNext;
  7176. if (a->Type->Exit) a->Type->Exit(a, Result);
  7177. ConfirmData = a->NextConfirmData;
  7178. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7179. NextConfirmData = ConfirmData;
  7180. a->ConfirmData = 0;
  7181. a->NextConfirmData = 0;
  7182. la_DestroyOperator(&a, Operators, 0);
  7183. a = NextA;
  7184. if (a){
  7185. a->ConfirmData = NextConfirmData;
  7186. }
  7187. continue;
  7188. }
  7189. a->Using = 1;
  7190. la_SetPropMathcerContext(a->ToPanel);
  7191. laSetOperatorLocalizer(a->ToPanel);
  7192. MAIN.CurrentPanel = a->ToPanel;
  7193. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7194. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  7195. e->Localized = 1;
  7196. }
  7197. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  7198. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7199. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  7200. e->Localized = 0;
  7201. }
  7202. la_SetPropMathcerContext(0);
  7203. laSetOperatorLocalizer(0);
  7204. MAIN.CurrentPanel = 0;
  7205. a->Using = 0;
  7206. if (Result & LA_PASS_ON){
  7207. laConfirmSameDataIfAny(a);
  7208. NextA = a->Item.pNext;
  7209. }else{
  7210. NextA = 0;
  7211. if (a->NextConfirmData){
  7212. la_DestroyConfirmData(&a->NextConfirmData);
  7213. }
  7214. }
  7215. ConfirmData = a->NextConfirmData;
  7216. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7217. NextConfirmData = ConfirmData;
  7218. a->ConfirmData = 0;
  7219. a->NextConfirmData = 0;
  7220. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  7221. if (a->Type->Exit) a->Type->Exit(a, Result);
  7222. la_DestroyOperator(&a, Operators, 0);
  7223. int found=0;
  7224. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  7225. if(!found){ NextA=0; }
  7226. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  7227. }
  7228. a = NextA;
  7229. if (a){
  7230. a->ConfirmData = NextConfirmData;
  7231. }
  7232. }
  7233. if (e->type==LA_PASTE && MAIN.PasteString) strSafeDestroy(&MAIN.PasteString);
  7234. return 1;
  7235. }
  7236. int la_HandleEvents(laWindow *w){
  7237. laEvent *e, *NextE;
  7238. laOperator *a;
  7239. laThreadNotifier *tn;
  7240. MAIN.CurrentWindow=w;
  7241. //laSpinLock(&MAIN.csNotifier);
  7242. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  7243. //laSpinUnlock(&MAIN.csNotifier);
  7244. laNotifyUsers(tn->Path);
  7245. FreeMem(tn);
  7246. //if (MAIN.ThreadNotifiers.pFirst)
  7247. //laSpinLock(&MAIN.csNotifier);
  7248. }
  7249. //laSpinUnlock(&MAIN.csNotifier);
  7250. while (1){
  7251. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  7252. while (w->EventList.pFirst){
  7253. while (w->PendingOperators.pLast){
  7254. a = w->PendingOperators.pLast;
  7255. if (a->OperatorPanel){
  7256. laSetOperatorLocalizer(a->OperatorPanel);
  7257. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  7258. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  7259. }
  7260. lstRemoveItem(&w->PendingOperators, a);
  7261. lstPushItem(&w->Operators, a);
  7262. }
  7263. e = lstPopItem(&w->EventList);
  7264. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  7265. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  7266. memFree(e);
  7267. }
  7268. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  7269. if (!MAIN.ReTriggerOperators) break;
  7270. }
  7271. la_UpdateOperatorHints(w);
  7272. return 1;
  7273. }
  7274. int la_AccpetedUnicodeInput(uint32_t ch){
  7275. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  7276. return 0;
  7277. }
  7278. int laCopyToClipboard(unsigned char * text){
  7279. #ifdef LA_LINUX
  7280. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  7281. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  7282. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  7283. strSafeSet(&MAIN.CopyPending, text);
  7284. return 1;
  7285. #endif
  7286. #ifdef _WIN32
  7287. OpenClipboard(GetDesktopWindow());
  7288. EmptyClipboard();
  7289. size_t allocsize = strlen(text) + 1;
  7290. HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, allocsize);
  7291. if (!hg){ CloseClipboard(); return 0; }
  7292. memcpy(GlobalLock(hg), text, allocsize);
  7293. GlobalUnlock(hg);
  7294. SetClipboardData(CF_TEXT, hg);
  7295. CloseClipboard();
  7296. GlobalFree(hg);
  7297. return 1;
  7298. #endif
  7299. return 0;
  7300. }
  7301. void laDisableIME(laWindow* w) {
  7302. #ifdef _WIN32
  7303. ImmAssociateContext(w->win, 0);
  7304. #endif
  7305. }
  7306. void laEnableIME(laWindow* w) {
  7307. #ifdef _WIN32
  7308. if(w->himc) ImmAssociateContext(w->win, w->himc);
  7309. #endif
  7310. }
  7311. int la_ProcessSysMessage(){
  7312. int SendDelay = 0, SendIdle = 0;
  7313. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  7314. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  7315. #ifdef LA_LINUX
  7316. XEvent e;
  7317. int type;
  7318. int InputCount = 0, CharCount=0;
  7319. KeySym InputKeysym = 0;
  7320. Status InputStatus = 0;
  7321. laWindow* wnd ;
  7322. while(XPending(MAIN.dpy)){
  7323. XGenericEventCookie *cookie = &e.xcookie;
  7324. XNextEvent(MAIN.dpy, &e);
  7325. if (XFilterEvent(&e, None)) continue;
  7326. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  7327. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  7328. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  7329. XFreeEventData(MAIN.dpy, cookie); continue;
  7330. }
  7331. switch(e.type){
  7332. case ConfigureNotify:
  7333. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  7334. break;
  7335. case Expose:
  7336. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  7337. if(!wnd) break;
  7338. laRefreshWindow(wnd);
  7339. break;
  7340. case MotionNotify:
  7341. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  7342. MAIN.IsPen=0;
  7343. break;
  7344. case ButtonPress:
  7345. type=LA_MOUSEDOWN;
  7346. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7347. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7348. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7349. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7350. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7351. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7352. MAIN.IsPen=0;
  7353. break;
  7354. case ButtonRelease:
  7355. type=LA_MOUSEUP;
  7356. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7357. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7358. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7359. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7360. MAIN.IsPen=0;
  7361. break;
  7362. case KeyPress:
  7363. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7364. MAIN.InputBuf[InputCount]=0;
  7365. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7366. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7367. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7368. for(int i=0;i<UCount;i++){ if(la_AccpetedUnicodeInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7369. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7370. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7371. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7372. #ifdef DEBUG
  7373. printf("pressed KEY: %d\n", (int)InputKeysym);
  7374. #endif
  7375. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7376. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7377. }
  7378. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7379. }
  7380. break;
  7381. case KeyRelease:
  7382. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7383. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7384. }
  7385. case ClientMessage:
  7386. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7387. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7388. }
  7389. break;
  7390. case SelectionNotify:
  7391. if(e.xselection.selection != MAIN.bufid) continue;
  7392. if (e.xselection.property){
  7393. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7394. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7395. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7396. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7397. else if(result) { strSafeSet(&MAIN.PasteString,result); }
  7398. XFree(result);
  7399. return True;
  7400. }
  7401. case SelectionRequest:
  7402. if(!MAIN.CopyPending){ break; }
  7403. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7404. if (e.xselectionrequest.selection != MAIN.selection) break;
  7405. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7406. XSelectionEvent ev = {0};
  7407. int R = 0;
  7408. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7409. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7410. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7411. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7412. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7413. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7414. else if (ev.target == MAIN.UTF8)
  7415. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7416. else ev.property = None;
  7417. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7418. break;
  7419. case SelectionClear:
  7420. break;
  7421. default:
  7422. break;
  7423. }
  7424. }
  7425. #endif //linux
  7426. #ifdef _WIN32
  7427. MSG msg; int Processed = 0;
  7428. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7429. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7430. //if (msg.wParam == VK_PROCESSKEY) {
  7431. // msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7432. //}
  7433. TranslateMessage(&msg); DispatchMessage(&msg);
  7434. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7435. };
  7436. if(!MAIN.Windows.pFirst){ return 0; }
  7437. #endif
  7438. #ifdef LAGUI_ANDROID
  7439. int pollResult = 0;
  7440. int pollEvents = 0;
  7441. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7442. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7443. // NOTE: Never close window, native activity is controlled by the system!
  7444. if (MAIN.app->destroyRequested != 0)
  7445. {
  7446. //CORE.Window.shouldClose = true;
  7447. //ANativeActivity_finish(MAIN.app->activity);
  7448. }
  7449. }
  7450. #endif
  7451. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7452. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7453. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7454. }
  7455. return 1;
  7456. };
  7457. void la_PrintOperatorStack(){
  7458. laWindow *w = MAIN.CurrentWindow;
  7459. laOperator *a;
  7460. printf("\n");
  7461. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7462. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7463. a->Type->Identifier, a->Instance,
  7464. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7465. }
  7466. }
  7467. void la_DrawWindow(laWindow *w){
  7468. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7469. MAIN.CurrentWindow = w;
  7470. la_WindowDefDraw(w, 0);
  7471. }
  7472. void laset_UiRowHeight(void* unused, int val);
  7473. int laFinalize(){
  7474. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7475. if(!MAIN.Themes.pFirst){
  7476. la_CreateClassicLightTheme();
  7477. la_CreateClassicDarkTheme();
  7478. }
  7479. la_RefreshThemeColor(MAIN.CurrentTheme);
  7480. laUiTemplate* uit;
  7481. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7482. laset_UiRowHeight(0, LA_RH0);
  7483. return 1;
  7484. }
  7485. void la_PreFrame(){
  7486. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7487. la_AnimationPreFrame();
  7488. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7489. }
  7490. void la_PostFrame(){
  7491. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7492. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7493. }
  7494. void laMainLoop(){
  7495. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7496. time_t t1, t2;
  7497. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7498. static int a = 0;
  7499. if(!laFinalize()) return;
  7500. laSetWindowCursor(LA_ARROW);
  7501. MAIN.DelayTriggered=1;
  7502. #ifdef LAGUI_ANDROID
  7503. while(!MAIN.AppReady){ usleep(1000); }
  7504. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7505. #endif
  7506. while (1){
  7507. laRecordTime(&MAIN.FrameStartTime);
  7508. la_PerfClear();
  7509. la_PreFrame();
  7510. if(!la_ProcessSysMessage()){ return; }
  7511. la_UpdateControllerStatus();
  7512. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7513. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7514. NextW = w->Item.pNext;
  7515. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7516. }
  7517. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7518. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7519. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7520. if(MAIN.GLDebugNeedsUpdate){
  7521. la_SetCurrentGLContextDebug();
  7522. }
  7523. la_DrawWindow(w);
  7524. }
  7525. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7526. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7527. #ifdef LA_LINUX
  7528. #ifdef LA_USE_GLES
  7529. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7530. #else
  7531. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7532. #endif
  7533. #endif
  7534. #ifdef _WIN32
  7535. SwapBuffers(w->hdc);
  7536. #endif
  7537. #ifdef LAGUI_ANDROID
  7538. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7539. #endif
  7540. }
  7541. MAIN.GLDebugNeedsUpdate=0;
  7542. la_PostFrame();
  7543. //t2 = clock();
  7544. laRecordTime(&MAIN.FrameEndTime);
  7545. TimeInterval = laTimeElapsedSecondsf(&MAIN.FrameEndTime, &MAIN.FrameStartTime);
  7546. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7547. if (Pause > 0){
  7548. int us = Pause * 1000000.0;
  7549. usleep(us);
  7550. }
  7551. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7552. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7553. la_AnimationPostFrame();
  7554. }
  7555. }
  7556. #ifdef LAGUI_ANDROID
  7557. int la_AndroidInitGraphics(void){
  7558. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7559. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7560. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7561. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7562. EGLint samples = 0;
  7563. EGLint sampleBuffer = 0;
  7564. const EGLint framebufferAttribs[] = {
  7565. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7566. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7567. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7568. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7569. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7570. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7571. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7572. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7573. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7574. EGL_NONE
  7575. };
  7576. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7577. EGLint numConfigs = 0;
  7578. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7579. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7580. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7581. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7582. eglBindAPI(EGL_OPENGL_API);
  7583. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7584. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7585. EGLint displayFormat = 0;
  7586. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7587. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7588. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7589. // There must be at least one frame displayed before the buffers are swapped
  7590. eglSwapInterval(MAIN.egl_dpy, 1);
  7591. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7592. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7593. MAIN.AppReady = 1;
  7594. return 0;
  7595. }
  7596. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7597. switch (cmd){
  7598. case APP_CMD_START: break;
  7599. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7600. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7601. case APP_CMD_RESUME:break;//InitPlatform();break;
  7602. case APP_CMD_INIT_WINDOW:
  7603. if (app->window != NULL){
  7604. if (MAIN.ContextRebindRequired){
  7605. // Reset screen scaling to full display size
  7606. EGLint displayFormat = 0;
  7607. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7608. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7609. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7610. // appropriate way to fix this
  7611. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7612. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7613. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7614. displayFormat);
  7615. // Recreate display surface and re-attach OpenGL context
  7616. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7617. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7618. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7619. //glClearColor(1,0.2,1,1);
  7620. //glClear(GL_COLOR_BUFFER_BIT);
  7621. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7622. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7623. MAIN.ContextRebindRequired = false;
  7624. }else{
  7625. la_AndroidInitGraphics();
  7626. }
  7627. }
  7628. break;
  7629. case APP_CMD_DESTROY:
  7630. case APP_CMD_TERM_WINDOW:
  7631. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7632. // 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.
  7633. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7634. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7635. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7636. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7637. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7638. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7639. MAIN.egl_surf = EGL_NO_SURFACE;
  7640. }
  7641. MAIN.ContextRebindRequired = true;
  7642. }
  7643. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7644. // this means that the user has already called 'CloseWindow()'
  7645. break;
  7646. case APP_CMD_SAVE_STATE: break;
  7647. case APP_CMD_STOP: break;
  7648. case APP_CMD_CONFIG_CHANGED:
  7649. case APP_CMD_WINDOW_RESIZED:
  7650. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7651. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7652. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7653. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7654. //print_cur_config(MAIN.app);
  7655. // Check screen orientation here!
  7656. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7657. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7658. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7659. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7660. MAIN.egl_surf = EGL_NO_SURFACE;
  7661. }
  7662. EGLint displayFormat = 0;
  7663. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7664. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7665. displayFormat);
  7666. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7667. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7668. }
  7669. break;
  7670. default: break;
  7671. }
  7672. }
  7673. #define KEYCODE_MAP_SIZE 162
  7674. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7675. 0, // AKEYCODE_UNKNOWN
  7676. 0, // AKEYCODE_SOFT_LEFT
  7677. 0, // AKEYCODE_SOFT_RIGHT
  7678. 0, // AKEYCODE_HOME
  7679. 0, // AKEYCODE_BACK
  7680. 0, // AKEYCODE_CALL
  7681. 0, // AKEYCODE_ENDCALL
  7682. '0', // AKEYCODE_0
  7683. '1', // AKEYCODE_1
  7684. '2', // AKEYCODE_2
  7685. '3', // AKEYCODE_3
  7686. '4', // AKEYCODE_4
  7687. '5', // AKEYCODE_5
  7688. '6', // AKEYCODE_6
  7689. '7', // AKEYCODE_7
  7690. '8', // AKEYCODE_8
  7691. '9', // AKEYCODE_9
  7692. 0, // AKEYCODE_STAR
  7693. 0, // AKEYCODE_POUND
  7694. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7695. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7696. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7697. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7698. 0, // AKEYCODE_DPAD_CENTER
  7699. 0, // AKEYCODE_VOLUME_UP
  7700. 0, // AKEYCODE_VOLUME_DOWN
  7701. 0, // AKEYCODE_POWER
  7702. 0, // AKEYCODE_CAMERA
  7703. 0, // AKEYCODE_CLEAR
  7704. 'a', // AKEYCODE_A
  7705. 'b', // AKEYCODE_B
  7706. 'c', // AKEYCODE_C
  7707. 'd', // AKEYCODE_D
  7708. 'e', // AKEYCODE_E
  7709. 'f', // AKEYCODE_F
  7710. 'g', // AKEYCODE_G
  7711. 'h', // AKEYCODE_H
  7712. 'i', // AKEYCODE_I
  7713. 'j', // AKEYCODE_J
  7714. 'k', // AKEYCODE_K
  7715. 'l', // AKEYCODE_L
  7716. 'm', // AKEYCODE_M
  7717. 'n', // AKEYCODE_N
  7718. 'o', // AKEYCODE_O
  7719. 'p', // AKEYCODE_P
  7720. 'q', // AKEYCODE_Q
  7721. 'r', // AKEYCODE_R
  7722. 's', // AKEYCODE_S
  7723. 't', // AKEYCODE_T
  7724. 'u', // AKEYCODE_U
  7725. 'v', // AKEYCODE_V
  7726. 'w', // AKEYCODE_W
  7727. 'x', // AKEYCODE_X
  7728. 'y', // AKEYCODE_Y
  7729. 'z', // AKEYCODE_Z
  7730. ',', // AKEYCODE_COMMA
  7731. '.', // AKEYCODE_PERIOD
  7732. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7733. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7734. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7735. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7736. LA_KEY_TAB, // AKEYCODE_TAB
  7737. ' ', // AKEYCODE_SPACE
  7738. 0, // AKEYCODE_SYM
  7739. 0, // AKEYCODE_EXPLORER
  7740. 0, // AKEYCODE_ENVELOPE
  7741. LA_KEY_ENTER, // AKEYCODE_ENTER
  7742. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7743. '`', // AKEYCODE_GRAVE
  7744. '-', // AKEYCODE_MINUS
  7745. '=', // AKEYCODE_EQUALS
  7746. '(', // AKEYCODE_LEFT_BRACKET
  7747. ')', // AKEYCODE_RIGHT_BRACKET
  7748. '\\', // AKEYCODE_BACKSLASH
  7749. ';', // AKEYCODE_SEMICOLON
  7750. '\'', // AKEYCODE_APOSTROPHE
  7751. '/', // AKEYCODE_SLASH
  7752. 0, // AKEYCODE_AT
  7753. 0, // AKEYCODE_NUM
  7754. 0, // AKEYCODE_HEADSETHOOK
  7755. 0, // AKEYCODE_FOCUS
  7756. 0, // AKEYCODE_PLUS
  7757. 0, // AKEYCODE_MENU
  7758. 0, // AKEYCODE_NOTIFICATION
  7759. 0, // AKEYCODE_SEARCH
  7760. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7761. 0, // AKEYCODE_MEDIA_STOP
  7762. 0, // AKEYCODE_MEDIA_NEXT
  7763. 0, // AKEYCODE_MEDIA_PREVIOUS
  7764. 0, // AKEYCODE_MEDIA_REWIND
  7765. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7766. 0, // AKEYCODE_MUTE
  7767. 0, // AKEYCODE_PAGE_UP
  7768. 0, // AKEYCODE_PAGE_DOWN
  7769. 0, // AKEYCODE_PICTSYMBOLS
  7770. 0, // AKEYCODE_SWITCH_CHARSET
  7771. 0, // AKEYCODE_BUTTON_A
  7772. 0, // AKEYCODE_BUTTON_B
  7773. 0, // AKEYCODE_BUTTON_C
  7774. 0, // AKEYCODE_BUTTON_X
  7775. 0, // AKEYCODE_BUTTON_Y
  7776. 0, // AKEYCODE_BUTTON_Z
  7777. 0, // AKEYCODE_BUTTON_L1
  7778. 0, // AKEYCODE_BUTTON_R1
  7779. 0, // AKEYCODE_BUTTON_L2
  7780. 0, // AKEYCODE_BUTTON_R2
  7781. 0, // AKEYCODE_BUTTON_THUMBL
  7782. 0, // AKEYCODE_BUTTON_THUMBR
  7783. 0, // AKEYCODE_BUTTON_START
  7784. 0, // AKEYCODE_BUTTON_SELECT
  7785. 0, // AKEYCODE_BUTTON_MODE
  7786. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7787. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7788. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7789. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7790. 0, // AKEYCODE_CAPS_LOCK
  7791. 0, // AKEYCODE_SCROLL_LOCK
  7792. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7793. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7794. 0, // AKEYCODE_FUNCTION
  7795. 0, // AKEYCODE_SYSRQ
  7796. 0, // AKEYCODE_BREAK
  7797. 0, // AKEYCODE_MOVE_HOME
  7798. 0, // AKEYCODE_MOVE_END
  7799. 0, // AKEYCODE_INSERT
  7800. 0, // AKEYCODE_FORWARD
  7801. 0, // AKEYCODE_MEDIA_PLAY
  7802. 0, // AKEYCODE_MEDIA_PAUSE
  7803. 0, // AKEYCODE_MEDIA_CLOSE
  7804. 0, // AKEYCODE_MEDIA_EJECT
  7805. 0, // AKEYCODE_MEDIA_RECORD
  7806. LA_KEY_F1, // AKEYCODE_F1
  7807. LA_KEY_F2, // AKEYCODE_F2
  7808. LA_KEY_F3, // AKEYCODE_F3
  7809. LA_KEY_F4, // AKEYCODE_F4
  7810. LA_KEY_F5, // AKEYCODE_F5
  7811. LA_KEY_F6, // AKEYCODE_F6
  7812. LA_KEY_F7, // AKEYCODE_F7
  7813. LA_KEY_F8, // AKEYCODE_F8
  7814. LA_KEY_F9, // AKEYCODE_F9
  7815. LA_KEY_F10, // AKEYCODE_F10
  7816. LA_KEY_F11, // AKEYCODE_F11
  7817. LA_KEY_F12, // AKEYCODE_F12
  7818. 0, // AKEYCODE_NUM_LOCK
  7819. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7820. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7821. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7822. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7823. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7824. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7825. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7826. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7827. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7828. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7829. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7830. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7831. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7832. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7833. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7834. 0, // AKEYCODE_NUMPAD_COMMA
  7835. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7836. '=' // AKEYCODE_NUMPAD_EQUALS
  7837. };
  7838. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7839. {
  7840. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7841. if(!MAIN.AppEnabled){return 0;}
  7842. //laRedrawAllWindows();
  7843. static int prev_button_state=0;
  7844. int type = AInputEvent_getType(event);
  7845. if(type == AINPUT_EVENT_TYPE_KEY){
  7846. int32_t keycode = AKeyEvent_getKeyCode(event);
  7847. //int32_t AKeyEvent_getMetaState(event);
  7848. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7849. if (key != 0){
  7850. // Save current key and its state
  7851. // NOTE: Android key action is 0 for down and 1 for up
  7852. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7853. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7854. if(key!=LA_KEY_BACKSPACE)
  7855. la_SendInputEvent(0,key);
  7856. }
  7857. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7858. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7859. la_SendInputEvent(0,key);
  7860. }
  7861. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7862. }
  7863. if (keycode == AKEYCODE_POWER)
  7864. {
  7865. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7866. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7867. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7868. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7869. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7870. return 0;
  7871. }
  7872. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7873. {
  7874. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7875. return 1;
  7876. }
  7877. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7878. {
  7879. // Set default OS behaviour
  7880. return 0;
  7881. }
  7882. return 0;
  7883. }
  7884. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7885. static real zoom_offset=1; static real temp_distance=0;
  7886. real zoom; int gesture_handled=0;
  7887. int pcount = AMotionEvent_getPointerCount(event); int x,y; static real cx=0,cy=0;
  7888. int32_t action = AMotionEvent_getAction(event);
  7889. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7890. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7891. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7892. if(pcount){
  7893. x=rx; y=ry;
  7894. int tool_type=AMotionEvent_getToolType(event,0);
  7895. real pressure = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_PRESSURE,0);
  7896. if(tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS || tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER){
  7897. MAIN.StylusPressure = MAIN.EraserPressure = pressure; MAIN.IsPen = 1;
  7898. MAIN.PointerIsEraser = (tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER);
  7899. }else{
  7900. MAIN.IsPen = 0;
  7901. }
  7902. if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
  7903. && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
  7904. real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
  7905. real ctx=(x+x2)/2, cty=(y+y2)/2;
  7906. real distance = tnsDistIdv2(x2,y2,rx,ry);
  7907. if(temp_distance){ zoom_offset*=(distance/temp_distance); }
  7908. temp_distance = distance;
  7909. while(zoom_offset > 1.1){ zoom_offset-=0.1;
  7910. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7911. la_SendMouseEvent(0, LA_MOUSEUP|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7912. }
  7913. while(zoom_offset < (1.0/1.1)){ zoom_offset+=(0.1/1.1);
  7914. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7915. la_SendMouseEvent(0, LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7916. }
  7917. if(cx || cy){
  7918. if(!gesture_handled){
  7919. real dist = tnsDistIdv2(ctx,cty,cx,cy);
  7920. while(dist > LA_RH){
  7921. int udlr = fabs(cty-cy) > fabs(ctx-cx);
  7922. int direction = udlr?(cty>cy?LA_KEY_ARRUP:LA_KEY_ARRDOWN):
  7923. (ctx>cx?LA_KEY_ARRLEFT:LA_KEY_ARRRIGHT);
  7924. real fac = (real)(LA_RH)/dist;
  7925. cx=tnsLinearItp(cx,ctx,fac); cy=tnsLinearItp(cy,cty,fac);
  7926. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7927. la_SendKeyboardEvent(0, LA_KEY_DOWN, direction|LA_KEYBOARD_EVENT|LA_KEY_PANNING);
  7928. gesture_handled=1;
  7929. dist = tnsDistIdv2(ctx,cty,cx,cy);
  7930. }
  7931. }
  7932. }else{
  7933. cx=ctx; cy=cty;
  7934. }
  7935. }else{
  7936. temp_distance = 0; cx=0; cy=0;
  7937. }
  7938. if(flags==AMOTION_EVENT_ACTION_HOVER_MOVE){
  7939. la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
  7940. }
  7941. }
  7942. if(!gesture_handled){
  7943. if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_BUTTON_PRESS){
  7944. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7945. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7946. int btn=AMotionEvent_getButtonState(event);
  7947. int evtype=LA_L_MOUSE_DOWN;
  7948. if(btn & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_DOWN; }
  7949. elif(btn & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_DOWN; }
  7950. la_SendMouseEvent(0,evtype,x,y);
  7951. prev_button_state = btn;
  7952. }
  7953. else if (flags == AMOTION_EVENT_ACTION_UP || flags == AMOTION_EVENT_ACTION_BUTTON_RELEASE){
  7954. int btn=AMotionEvent_getButtonState(event); int changed = (~btn)&prev_button_state;
  7955. int evtype=LA_L_MOUSE_UP;
  7956. if(changed & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_UP; }
  7957. elif(changed & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_UP; }
  7958. la_SendMouseEvent(0,evtype,x,y);
  7959. }
  7960. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7961. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7962. }
  7963. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7964. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7965. }
  7966. }
  7967. }
  7968. //static float r=0;
  7969. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7970. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7971. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7972. //glClear(GL_COLOR_BUFFER_BIT);
  7973. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7974. return 0;
  7975. }
  7976. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7977. MAIN.AssetManager = manager;
  7978. MAIN.InternalDataPath = dataPath;
  7979. MAIN.ExternalDataPath = externalDataPath;
  7980. }
  7981. static int android_read(void *cookie, char *data, int dataSize){
  7982. return AAsset_read((AAsset *)cookie, data, dataSize);
  7983. }
  7984. static int android_write(void *cookie, const char *data, int dataSize){
  7985. return 0;
  7986. }
  7987. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7988. return AAsset_seek((AAsset *)cookie, offset, whence);
  7989. }
  7990. static int android_close(void *cookie){
  7991. AAsset_close((AAsset *)cookie);
  7992. return 0;
  7993. }
  7994. // Replacement for fopen()
  7995. // Ref: https://developer.android.com/ndk/reference/group/asset
  7996. FILE *android_fopen(const char *fileName, const char *mode)
  7997. {
  7998. MAIN.AndroidLastPath=0;
  7999. if (mode[0] == 'w'){
  8000. // fopen() is mapped to android_fopen() that only grants read access to
  8001. // assets directory through AAssetManager but we want to also be able to
  8002. // write data when required using the standard stdio FILE access functions
  8003. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  8004. #undef fopen
  8005. char* valid_path=laAndroidEnsureValidFilePath(fileName,W_OK); if(!valid_path){ return 0; }
  8006. FILE* result=fopen(valid_path, mode); if(result){ MAIN.AndroidLastPath=valid_path; return result; }
  8007. return 0;
  8008. #define fopen(name, mode) android_fopen(name, mode)
  8009. }else{
  8010. // NOTE: AAsset provides access to read-only asset
  8011. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  8012. if (asset != NULL){
  8013. // Get pointer to file in the assets
  8014. return funopen(asset, android_read, android_write, android_seek, android_close);
  8015. }else{
  8016. #undef fopen
  8017. // Just do a regular open if file is not found in the assets
  8018. char* valid_path=laAndroidEnsureValidFilePath(fileName,R_OK); if(!valid_path){ return 0; }
  8019. FILE* result=fopen(valid_path, mode); if(result){ MAIN.AndroidLastPath=valid_path; return result; }
  8020. return 0;
  8021. #define fopen(name, mode) android_fopen(name, mode)
  8022. }
  8023. }
  8024. }
  8025. void la_HideNavBar(){
  8026. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8027. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8028. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8029. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  8030. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  8031. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  8032. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  8033. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  8034. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  8035. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  8036. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  8037. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  8038. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  8039. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  8040. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  8041. int flag = flagFullscreen | flagHideNavigation;
  8042. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  8043. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8044. }
  8045. void la_InitAndroidPlatform(struct android_app *app){
  8046. MAIN.app=app;
  8047. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  8048. //la_HideNavBar();
  8049. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  8050. MAIN.app->onInputEvent = la_AndroidInputCallback;
  8051. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  8052. int pollResult = 0;
  8053. int pollEvents = 0;
  8054. while (!MAIN.AppReady){
  8055. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  8056. // Process this event
  8057. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  8058. // NOTE: Never close window, native activity is controlled by the system!
  8059. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  8060. }
  8061. }
  8062. }
  8063. int main(int, char *[]);
  8064. void android_main(struct android_app *app){
  8065. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  8066. la_InitAndroidPlatform(app);
  8067. // NOTE: Return from main is ignored
  8068. (void)main(1, (char *[]) { arg0, NULL });
  8069. // Request to end the native activity
  8070. ANativeActivity_finish(app->activity);
  8071. // Android ALooper_pollAll() variables
  8072. int pollResult = 0;
  8073. int pollEvents = 0;
  8074. // Waiting for application events before complete finishing
  8075. while (!app->destroyRequested)
  8076. {
  8077. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  8078. {
  8079. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  8080. }
  8081. }
  8082. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "Application successfully ended.\n");
  8083. /* Unloads the native dynamic library so we can get clean restarts. */
  8084. exit(0);
  8085. }
  8086. void la_DisplayKeyboard(bool pShow) {
  8087. // Attaches the current thread to the JVM.
  8088. jint lResult;
  8089. jint lFlags = 0;
  8090. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8091. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8092. JavaVMAttachArgs lJavaVMAttachArgs;
  8093. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  8094. lJavaVMAttachArgs.name = "NativeThread";
  8095. lJavaVMAttachArgs.group = NULL;
  8096. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8097. if (lResult == JNI_ERR) {
  8098. return;
  8099. }
  8100. // Retrieves NativeActivity.
  8101. jobject lNativeActivity = MAIN.app->activity->clazz;
  8102. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  8103. // Retrieves Context.INPUT_METHOD_SERVICE.
  8104. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  8105. jfieldID FieldINPUT_METHOD_SERVICE =
  8106. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  8107. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  8108. jobject INPUT_METHOD_SERVICE =
  8109. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  8110. FieldINPUT_METHOD_SERVICE);
  8111. //jniCheck(INPUT_METHOD_SERVICE);
  8112. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  8113. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  8114. "android/view/inputmethod/InputMethodManager");
  8115. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8116. ClassNativeActivity, "getSystemService",
  8117. "(Ljava/lang/String;)Ljava/lang/Object;");
  8118. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  8119. lNativeActivity, MethodGetSystemService,
  8120. INPUT_METHOD_SERVICE);
  8121. // Runs getWindow().getDecorView().
  8122. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8123. ClassNativeActivity, "getWindow",
  8124. "()Landroid/view/Window;");
  8125. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  8126. MethodGetWindow);
  8127. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  8128. "android/view/Window");
  8129. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8130. ClassWindow, "getDecorView", "()Landroid/view/View;");
  8131. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  8132. MethodGetDecorView);
  8133. if (pShow) {
  8134. // Runs lInputMethodManager.showSoftInput(...).
  8135. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8136. ClassInputMethodManager, "showSoftInput",
  8137. "(Landroid/view/View;I)Z");
  8138. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  8139. lInputMethodManager, MethodShowSoftInput,
  8140. lDecorView, lFlags);
  8141. } else {
  8142. // Runs lWindow.getViewToken()
  8143. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  8144. "android/view/View");
  8145. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8146. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  8147. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  8148. MethodGetWindowToken);
  8149. // lInputMethodManager.hideSoftInput(...).
  8150. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8151. ClassInputMethodManager, "hideSoftInputFromWindow",
  8152. "(Landroid/os/IBinder;I)Z");
  8153. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  8154. lInputMethodManager, MethodHideSoftInput,
  8155. lBinder, lFlags);
  8156. }
  8157. // Finished with the JVM.
  8158. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8159. }
  8160. bool la_check_permission(const char* permission) {
  8161. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8162. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8163. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8164. jobject lNativeActivity = MAIN.app->activity->clazz;
  8165. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  8166. jmethodID activity_checkSelfPermission = (*lJNIEnv)->GetMethodID(lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  8167. jstring jobj_permission = (*lJNIEnv)->NewStringUTF(lJNIEnv,permission);
  8168. jint result = (*lJNIEnv)->CallIntMethod(lJNIEnv,ClassNativeActivity, activity_checkSelfPermission, jobj_permission);
  8169. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  8170. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8171. return result == 0;
  8172. }
  8173. void la_request_permission(const char* permission) {
  8174. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8175. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8176. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8177. jobject lNativeActivity = MAIN.app->activity->clazz;
  8178. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  8179. jmethodID contextCompat_checkSelfPermission = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  8180. jmethodID activity_requestPermissions = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "requestPermissions", "([Ljava/lang/String;I)V");
  8181. jstring jobj_permission = (*lJNIEnv)->NewStringUTF (lJNIEnv,permission);
  8182. jobjectArray jobj_permission_list = (*lJNIEnv)->NewObjectArray(lJNIEnv,1, (*lJNIEnv)->FindClass(lJNIEnv,"java/lang/String"), NULL);
  8183. (*lJNIEnv)->SetObjectArrayElement(lJNIEnv,jobj_permission_list, 0, jobj_permission);
  8184. (*lJNIEnv)->CallVoidMethod (lJNIEnv,lNativeActivity, activity_requestPermissions, jobj_permission_list, 0);
  8185. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  8186. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission_list);
  8187. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8188. }
  8189. #endif //android
  8190. #ifndef LAGUI_ANDROID
  8191. void la_DisplayKeyboard(bool pShow) {
  8192. if(pShow){ laEnableIME(MAIN.CurrentWindow); } else { laDisableIME(MAIN.CurrentWindow); }
  8193. return;
  8194. }
  8195. void la_HideNavBar(){
  8196. return;
  8197. }
  8198. #endif