*/}}

la_kernel.c 331 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782
  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. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  61. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  62. static int android_read(void *cookie, char *buf, int size);
  63. static int android_write(void *cookie, const char *buf, int size);
  64. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  65. static int android_close(void *cookie);
  66. void la_InitAndroidPlatform(struct android_app *app);
  67. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  68. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  69. void la_InitAndroidPlatform(struct android_app *app);
  70. #endif
  71. LA MAIN={0};
  72. extern tnsMain *T;
  73. int deb = 0;
  74. laOperator *DEB;
  75. laColumn *DEBUG_C;
  76. #ifdef _WIN32
  77. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  78. #else
  79. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  80. #endif
  81. #ifdef LA_LINUX
  82. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  83. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  84. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  85. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  86. #endif
  87. #ifdef LA_LINUX
  88. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  89. int i;
  90. for (i = 0; i < num_classes; i++) {
  91. if (classes[i]->type == XIValuatorClass) {
  92. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  93. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  94. logPrint(" Range: %f - %f\n", v->min, v->max);
  95. logPrint(" Resolution: %d units/m\n", v->resolution);
  96. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  97. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  98. }
  99. }
  100. }
  101. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  102. XIDeviceInfo *info, *dev;
  103. int i, ndevices;
  104. dev = XIQueryDevice(display, deviceid, &ndevices);
  105. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  106. mask->deviceid = deviceid;
  107. mask->mask_len = XIMaskLen(XI_RawMotion);
  108. mask->mask=memAcquireSimple(mask->mask_len);
  109. memset(mask->mask, 0, mask->mask_len);
  110. XISetMask(mask->mask, XI_RawMotion);
  111. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  112. int FoundMax=0;
  113. for (i = 0; i < dev->num_classes; i++) {
  114. if (dev->classes[i]->type == XIValuatorClass) {
  115. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  116. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  117. }
  118. }
  119. if(!FoundMax){*max_pressure=65535;}
  120. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  121. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  122. XIFreeDeviceInfo(dev);
  123. }
  124. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  125. int axis=0;
  126. for (int i = 0; i < dev->num_classes; i++) {
  127. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  128. }
  129. return axis>=3;
  130. }
  131. #define LA_G_STYLUS(dev) \
  132. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  133. #define LA_G_ERASER \
  134. (!MAIN.WacomDeviceEraser)
  135. void la_ScanWacomDevices(Display *display, int deviceid){
  136. XIDeviceInfo *info, *dev;
  137. int ndevices;
  138. int i; char * word;
  139. int _event, _error;
  140. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  141. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  142. }
  143. info = XIQueryDevice(display, deviceid, &ndevices);
  144. for(i = 0; i < ndevices; i++) {
  145. dev = &info[i]; strToLower(dev->name);
  146. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  147. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  148. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  149. word = strtok (dev->name," ");
  150. while (1) {
  151. word = strtok (NULL, " "); if (!word) break;
  152. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  153. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  154. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  155. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  156. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  157. }
  158. }
  159. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  160. logPrintNew("Found wacom devices:\n");
  161. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  162. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  163. }else{
  164. logPrintNew("No wacom pen device connected.\n");
  165. }
  166. XIFreeDeviceInfo(info);
  167. }
  168. void laHideCursor(){
  169. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  170. }
  171. void laShowCursor(){
  172. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  173. }
  174. void la_XErrorHandler(Display *display, XErrorEvent *event){
  175. char buf[512];
  176. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  177. printf("X Error:\n%s\n",buf);
  178. }
  179. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  180. XSetWindowAttributes swa;
  181. XWindowAttributes wa;
  182. swa.event_mask =
  183. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  184. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  185. swa.colormap = MAIN.cmap;
  186. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  187. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  188. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  189. if(x>0||y>0){
  190. XSizeHints my_hints = {0};
  191. my_hints.flags = PPosition;
  192. my_hints.x = x; my_hints.y = y;
  193. XSetNormalHints(MAIN.dpy, win, &my_hints);
  194. }
  195. XStoreName(MAIN.dpy, win, title);
  196. #ifdef LA_USE_GLES
  197. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  198. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  199. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  200. EGLSurface* surf=egl_surf;
  201. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  202. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  203. tnsContextMakeCurrent((*r_glc),win,(*surf));
  204. #else
  205. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  206. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  207. printf("\n\tcannot create gl context\n\n"); exit(0);
  208. }
  209. tnsContextMakeCurrent((*r_glc),win,0);
  210. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  211. #endif
  212. XSetLocaleModifiers("");
  213. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  214. if(!MAIN.im){
  215. XSetLocaleModifiers("@im=local");
  216. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  217. }
  218. if(!MAIN.im){
  219. XSetLocaleModifiers("@im=none");
  220. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  221. }
  222. if(!MAIN.im){
  223. XSetLocaleModifiers("@im=");
  224. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  225. }
  226. if(!MAIN.im){
  227. logPrint("Can't open a input method.\n");
  228. }
  229. if(MAIN.im){
  230. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  231. XSetICFocus(MAIN.ic);
  232. }
  233. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  234. XSetClassHint(MAIN.dpy, win, &ch);
  235. #define _NET_WM_STATE_ADD 1
  236. if(w<0&&h<0){
  237. XEvent xev;
  238. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  239. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  240. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  241. memset(&xev, 0, sizeof(xev));
  242. xev.type = ClientMessage;
  243. xev.xclient.window = win;
  244. xev.xclient.message_type = wm_state;
  245. xev.xclient.format = 32;
  246. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  247. xev.xclient.data.l[1] = max_horz;
  248. xev.xclient.data.l[2] = max_vert;
  249. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  250. }
  251. return win;
  252. };
  253. void la_DestroySystemWindowX11(laWindow* w) {
  254. tnsContextMakeCurrent(0,0,0);
  255. tnsDeleteContext(w->glc);
  256. #ifdef LA_USE_GLES
  257. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  258. #endif
  259. XDestroyWindow(MAIN.dpy, w->win);
  260. };
  261. #endif //linux
  262. #ifdef _WIN32
  263. #include <msgdef.h>
  264. #include <wintab.h>
  265. #include <wintab_utils.h>
  266. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  267. #define PACKETMODE PK_BUTTONS
  268. #include <pktdef.h>
  269. void la_OpenWacomWinTab(HWND hwnd){
  270. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  271. static LOGCONTEXT glogContext = { 0 };
  272. HCTX hctx = NULL;
  273. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  274. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  275. glogContext.lcOptions |= CXO_SYSTEM;
  276. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  277. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  278. assert(glogContext.lcOptions & CXO_SYSTEM);
  279. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  280. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  281. glogContext.lcPktData = PACKETDATA;
  282. glogContext.lcPktMode = PACKETMODE;
  283. glogContext.lcMoveMask = PACKETDATA;
  284. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  285. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  286. assert(wWTInfoRetVal == sizeof(AXIS));
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  290. if (wWTInfoRetVal) {
  291. assert(wWTInfoRetVal == sizeof(AXIS));
  292. MAIN.WinTabMaxHover = TabletZ.axMax;
  293. }
  294. AXIS tabletPressure = { 0 };
  295. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  296. //glogContext.lcInOrgX = 0;
  297. //glogContext.lcInOrgY = 0;
  298. //glogContext.lcInExtX = TabletX.axMax;
  299. //glogContext.lcInExtY = TabletY.axMax;
  300. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  301. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  312. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  313. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  314. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  315. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  316. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  317. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  318. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  319. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  320. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  321. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  322. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  323. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  324. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  325. if (!hctx)return;
  326. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  327. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  328. }
  329. void laHideCursor() {
  330. if (!MAIN.CurrentWindow) return; //impl
  331. }
  332. void laShowCursor() {
  333. if (!MAIN.CurrentWindow) return; //impl
  334. }
  335. static PIXELFORMATDESCRIPTOR cpfd = {
  336. sizeof(PIXELFORMATDESCRIPTOR),1,
  337. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  338. PFD_TYPE_RGBA,
  339. 8,
  340. 0, 0, 0, 0, 0, 0,
  341. 0, 0, 0,
  342. 0, 0, 0, 0,
  343. 32,
  344. 8, 0,
  345. 0,
  346. 0, 0, 0, 0
  347. };
  348. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  349. int nBestMS = 0;
  350. int i;
  351. int iResults[9];
  352. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  353. WGL_ACCELERATION_ARB, // 1
  354. WGL_DRAW_TO_WINDOW_ARB, // 2
  355. WGL_DOUBLE_BUFFER_ARB, // 3
  356. WGL_PIXEL_TYPE_ARB, // 4
  357. WGL_DEPTH_BITS_ARB, // 5
  358. WGL_STENCIL_BITS_ARB, // 6
  359. WGL_SAMPLE_BUFFERS_ARB, // 7
  360. WGL_SAMPLES_ARB }; // 8
  361. // How many pixelformats are there?
  362. int nFormatCount[] = { 0 };
  363. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  364. if (!wglGetPixelFormatAttribivARB)
  365. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  366. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  367. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  368. for (i = 0; i < nFormatCount[0]; i++){
  369. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  370. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  371. if (iResults[3] == 1) // Double buffered
  372. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  373. if (iResults[5] >= 24) // Any Depth greater than 16
  374. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  375. }
  376. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  377. };
  378. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  379. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  380. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  381. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  382. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  383. 0 };
  384. HGLRC hglrc = 0;
  385. HDC hdc = 0;
  386. int a, b;
  387. hdc = GetDC(hwnd);
  388. la_SetupPxlFormat(hdc, &a, &b);
  389. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  390. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  391. tnsContextMakeCurrent(hglrc, hdc,0);
  392. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  393. wglSwapIntervalEXT(-1);
  394. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  395. };
  396. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  397. HINSTANCE* inst = &MAIN.hinstance;
  398. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  399. x, y, w, h, 0, 0, *inst, 0);
  400. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  401. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  402. return hwnd;
  403. };
  404. void la_DestroySystemWindowWin32(laWindow* w) {
  405. tnsContextMakeCurrent(0,0,0);
  406. tnsDeleteContext(w->glc);
  407. ReleaseDC(w->win, w->hdc);
  408. DestroyWindow(w->win);
  409. };
  410. #endif
  411. #ifdef LAGUI_ANDROID
  412. SYSWINDOW la_CreateWindowAndroid(){
  413. return 0;
  414. };
  415. void laShowCursor(){}
  416. void laHideCursor(){}
  417. #endif
  418. #ifdef LA_LINUX
  419. void la_HandlerSIGSEGV(int sig) {
  420. void *array[30];
  421. size_t sz;
  422. sz = backtrace(array, 30);
  423. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  424. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  425. exit(1);
  426. }
  427. #endif
  428. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  429. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  430. //#ifndef LAGUI_ANDROID
  431. // ignore non-significant error/warning codes
  432. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  433. logPrint("GL %d: %s\n", id, message);
  434. char* strsource="",*strtype="",*strseverity="";
  435. switch (source) {
  436. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  437. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  438. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  439. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  440. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  441. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  442. }
  443. switch (type) {
  444. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  445. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  446. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  447. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  448. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  449. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  450. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  451. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  452. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  453. }
  454. switch (severity) {
  455. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  456. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  457. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  458. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  459. }
  460. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  461. //#endif
  462. }
  463. void la_SetCurrentGLContextDebug(){
  464. //#ifndef LAGUI_ANDROID
  465. int force=MAIN.InitArgs.GLDebug;
  466. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  467. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  468. glDebugMessageCallback(la_glDebugOutput, 0);
  469. int sev=GL_DONT_CARE;
  470. if(!force){
  471. switch(MAIN.GLDebugLevel){
  472. default: sev=GL_DONT_CARE; break;
  473. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  474. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  475. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  476. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  477. }
  478. }
  479. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  480. //#endif
  481. }
  482. void la_NotifyGLDebugChanges(){
  483. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  484. }
  485. void la_SetupWindowGLStates(laWindow* w){
  486. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  487. if(w->GLDebugNeedsUpdate){
  488. tnsContextMakeWindowCurrent(w);
  489. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  490. }
  491. }
  492. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  493. SYSGLCONTEXT glc;
  494. #ifdef LA_LINUX
  495. void* egl_surf=0;
  496. #ifdef LA_USE_GLES
  497. egl_surf=&window->egl_surf;
  498. #endif
  499. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  500. #endif
  501. #ifdef _WIN32
  502. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  503. #endif
  504. #ifdef LAGUI_ANDROID
  505. la_CreateWindowAndroid();
  506. window->win = 1;
  507. window->glc = MAIN.glc;
  508. #else
  509. window->win = hwnd;
  510. window->glc = glc;
  511. #endif
  512. #ifdef _WIN32
  513. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  514. RECT rc; GetClientRect(window->win, &rc);
  515. window->CW = rc.right - rc.left;
  516. window->CH = rc.bottom - rc.top;
  517. #endif
  518. #ifdef LA_LINUX
  519. XWindowAttributes attr;
  520. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  521. window->CW =attr.width;
  522. window->CH = attr.height;
  523. #endif
  524. la_SetCurrentGLContextDebug();
  525. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  526. la_SetupWindowGLStates(window);
  527. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  528. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  529. #else
  530. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #endif
  532. window->OutputShowStripes=1; window->Redraw=1;
  533. window->GLDebugNeedsUpdate=1;
  534. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  535. return 1;
  536. };
  537. int la_DestroySystemWindow(laWindow* wnd){
  538. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  539. nvgDeleteGLES3(wnd->nvg);
  540. #else
  541. nvgDeleteGL3(wnd->nvg);
  542. #endif
  543. #ifdef LA_LINUX
  544. la_DestroySystemWindowX11(wnd);
  545. #endif
  546. #ifdef _WIN32
  547. la_DestroySystemWindowWin32(wnd);
  548. #endif
  549. }
  550. void la_DestroyWindow(laWindow *wnd){
  551. laLayout *l; laPanel *p; if (!wnd) return;
  552. tnsSwitchToCurrentWindowContext(wnd);
  553. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  554. la_StopAllOperators();
  555. strSafeDestroy(&wnd->Title);
  556. //la_PrintUserList(wnd);
  557. //printf("----\n");
  558. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  559. while (l = lstPopItem(&wnd->Layouts)){
  560. laDestroyBlocksRecursive(l->FirstBlock);
  561. //la_PrintUserList(l);
  562. //printf("%x %s\n", l, l->ID->Ptr);
  563. strSafeDestroy(&l->ID);
  564. memFree(l);
  565. //la_PrintUserList(wnd);
  566. //printf("----\n");
  567. }
  568. //printf("----\n%x\n",wnd);
  569. //la_PrintUserList(wnd);
  570. la_DestroySystemWindow(wnd);
  571. lstRemoveItem(&MAIN.Windows, wnd);
  572. memFree(wnd);
  573. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  574. }
  575. void laRenameWindow(laWindow* wnd, char* name){
  576. if((!wnd)||MAIN.IsReadingUDF) return;
  577. strSafeSet(&wnd->Title, name);
  578. if(!wnd->win) return;
  579. #ifdef LA_LINUX
  580. XStoreName(MAIN.dpy, wnd->win, name);
  581. #endif
  582. #ifdef _WIN32
  583. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  584. SetWindowTextW(wnd->win, name);
  585. #endif
  586. }
  587. #ifdef LA_LINUX
  588. const char* la_ConvertCursorID(int id){
  589. switch (id) {
  590. case LA_ARROW: return "arrow";
  591. case LA_CROSS: return "cross";
  592. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  593. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  594. case LA_MOVE: return "diamond_cross";
  595. case LA_HAND: return "hand1";
  596. case LA_CORNER: return "bottom_right_corner";
  597. }
  598. return "arrow";
  599. }
  600. #endif
  601. #ifdef _WIN32
  602. HCURSOR la_ConvertCursorID(int id){
  603. switch (id){
  604. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  605. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  606. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  607. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  608. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  609. case LA_HAND: return LoadCursor(0, IDC_HAND);
  610. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  611. }
  612. return LoadCursor(0, IDC_ARROW);;
  613. }
  614. #endif
  615. void la_InitThreadEnviornment(){
  616. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  617. }
  618. laLogEntry* logEnsure(int Create){
  619. if(!MAIN.Logs.pFirst || Create){
  620. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  621. lstAppendItem(&MAIN.Logs, le);
  622. }
  623. return MAIN.Logs.pLast;
  624. }
  625. void logPrintTV(int Continued, char* format, va_list v){
  626. if(!format || !format[0]) return;
  627. laLogEntry* le=logEnsure(Continued);
  628. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  629. strSafePrintV(&le->Content, format, v);
  630. #ifdef LAGUI_ANDROID
  631. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  632. #endif
  633. laNotifyUsers("la.logs");
  634. }
  635. void logPrintT(int Continued, char* format, ...){
  636. if(!format || !format[0]) return;
  637. laLogEntry* le=logEnsure(Continued);
  638. va_list aptr; va_start(aptr, format);
  639. strSafePrint(&le->Content, format, aptr);
  640. va_end(aptr);
  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 logPrint(char* format, ...){
  647. va_list aptr; va_start(aptr, format);
  648. logPrintTV(0, format, aptr);
  649. va_end(aptr);
  650. }
  651. void logPrintNew(char* format, ...){
  652. logEnsure(1);
  653. va_list aptr; va_start(aptr, format);
  654. logPrintTV(0, format, aptr);
  655. va_end(aptr);
  656. }
  657. void logClear(){
  658. laLogEntry*l;
  659. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  660. laNotifyUsers("la.logs");
  661. }
  662. 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;
  663. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  664. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  665. }
  666. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  667. strSafeSet(&s->Name,Name);
  668. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  669. s->x=x;s->y=y;s->w=w;s->h=h;
  670. laNotifyUsers("la.user_preferences.screens");
  671. return s;
  672. }
  673. void la_RemoveScreen(laScreen*s){
  674. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  675. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  676. }
  677. void la_RemoveDuplicatedScreenConf(){
  678. laScreen* NextS;
  679. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  680. NextS = s->Item.pNext;
  681. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  682. 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; }
  683. }
  684. }
  685. }
  686. laScreen* laGetWindowScreen(laWindow* w){
  687. int l,r,u,b; int area=-1; laScreen* maxs=0;
  688. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  689. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  690. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  691. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  692. int a=w*h; if(a>area){ maxs = s; area = a; }
  693. }
  694. return maxs;
  695. }
  696. #ifdef LA_LINUX
  697. int la_GetDPI(Window* root_win){
  698. XRRScreenResources *screen;
  699. XRROutputInfo *info;
  700. XRRCrtcInfo *crtc_info;
  701. XRRCrtcInfo *crtc;
  702. int iscres, icrtc, dpi=0;
  703. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  704. for(iscres=0;iscres<screen->noutput;iscres++){
  705. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  706. if(!info->mm_width || !info->mm_height){ continue; }
  707. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  708. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  709. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  710. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  711. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  712. XRRFreeCrtcInfo(crtc);
  713. //if(info->connection==RR_Connected){
  714. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  715. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  716. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  717. // XRRFreeCrtcInfo(crtc_info);
  718. // }
  719. //}
  720. XRRFreeOutputInfo(info);
  721. }
  722. XRRFreeScreenResources(screen);
  723. return dpi;
  724. }
  725. #endif
  726. #ifdef _WIN32
  727. typedef struct laWin32MonitorEnumData {
  728. int id;
  729. }laWin32MonitorEnumData;
  730. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  731. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  732. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  733. return TRUE;
  734. }
  735. int la_GetDPI(HWND win){
  736. laWin32MonitorEnumData data = { 0 };
  737. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  738. return GetDpiForWindow(win);
  739. return 144;
  740. }
  741. #endif
  742. #define PROGRESSW (LA_RH*15)
  743. void laShowProgress(real p1, real p2){
  744. laSpinLock(&MAIN.OpsLock);
  745. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  746. if(!MAIN.Progress.Called){
  747. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  748. }else{
  749. laTimeRecorder tm; laRecordTime(&tm);
  750. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  751. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  752. if(!MAIN.Progress.Shown){
  753. int ww=PROGRESSW+LA_RH*2;
  754. #ifdef LA_LINUX
  755. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  756. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  757. long a=LA_COLOR3_TO_HEX(bg);
  758. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  759. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  760. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  761. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  762. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  763. #endif
  764. #ifdef _WIN32
  765. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  766. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  767. ShowWindow(MAIN.Progress.w,SW_SHOW);
  768. #endif
  769. MAIN.Progress.Shown = 1;
  770. }
  771. }
  772. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  773. #ifdef LA_LINUX
  774. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  775. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  776. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  777. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  778. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  779. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  780. #endif
  781. #ifdef _WIN32
  782. InvalidateRect(MAIN.Progress.w,0,1);
  783. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  784. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  785. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  786. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  787. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  788. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  789. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  790. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  791. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  792. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  793. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  794. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  795. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  796. EndPaint(MAIN.Progress.w,&ps);
  797. MSG msg;
  798. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  799. #endif
  800. laSpinUnlock(&MAIN.OpsLock);
  801. }
  802. void laHideProgress(){
  803. laSpinLock(&MAIN.OpsLock);
  804. if(!MAIN.Progress.Shown){
  805. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  806. }
  807. laTimeRecorder tm; laRecordTime(&tm);
  808. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  809. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  810. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  811. #ifdef LA_LINUX
  812. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  813. #endif
  814. #ifdef _WIN32
  815. ShowWindow(MAIN.Progress.w,SW_HIDE);
  816. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  817. #endif
  818. laSpinUnlock(&MAIN.OpsLock);
  819. }
  820. //=======================
  821. void la_InitProgressWindow(){
  822. #ifdef LA_LINUX
  823. 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));
  824. if(!MAIN.Progress.w) return;
  825. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  826. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  827. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  828. if(MAIN.Progress.gc<0) return;
  829. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  830. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  831. XSync(MAIN.dpy,0);
  832. #endif
  833. #ifdef _WIN32
  834. WNDCLASSW wc;
  835. wc.hInstance = MAIN.hinstance;
  836. wc.lpfnWndProc = LA_ProgressWindowProc;
  837. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  838. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  839. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  840. wc.cbWndExtra = 0;
  841. wc.cbClsExtra = 0;
  842. wc.lpszClassName = L"_LAGUIPROGRESS";
  843. wc.lpszMenuName = NULL;
  844. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  845. if (!RegisterClassW(&wc)){ return; }
  846. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  847. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  848. #endif
  849. }
  850. void laSetFontFolderPath(char* absolute){
  851. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  852. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  853. }
  854. void laSetDefaultInitArguments(laInitArguments* ia){
  855. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  856. ia->UseColorManagement=0;
  857. ia->HasWorldObjects=0;
  858. ia->HasAction=0;
  859. ia->HasTextureInspector=0;
  860. ia->HasHistories=0;
  861. ia->HasTerminal=1;
  862. ia->HasAudio=0;
  863. }
  864. void laSetCompleteInitArguments(laInitArguments* ia){
  865. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  866. ia->UseColorManagement=1;
  867. ia->HasWorldObjects=1;
  868. ia->HasAction=1;
  869. ia->HasTextureInspector=1;
  870. ia->HasHistories=1;
  871. ia->HasTerminal=1;
  872. ia->HasAudio=1;
  873. }
  874. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  875. MAIN.GLMajor=MAIN.GLMinor=-1;
  876. char* arg = 0;
  877. printf("Initializing LaGUI...\n",argc);
  878. for(int i=0;i<argc;i++){
  879. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  880. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  881. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  882. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  883. }
  884. continue;
  885. }
  886. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  887. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  888. }
  889. }
  890. int laGetReadyWith(laInitArguments* ia){
  891. #ifdef LA_LINUX
  892. //signal(SIGSEGV,la_HandlerSIGSEGV);
  893. #endif
  894. laSpinInit(&MAIN.MemLock);
  895. laSpinInit(&MAIN.OpsLock);
  896. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  897. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  898. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  899. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  900. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  901. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  902. tnsInit();
  903. #ifdef LA_LINUX
  904. SYSWINDOW root, win;
  905. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  906. XSetWindowAttributes swa={0};
  907. XWindowAttributes wa={0};
  908. XEvent xev;
  909. logPrintNew("Initializing LaGUI...\n");
  910. setlocale(LC_CTYPE, "zh_CN.utf8");
  911. XSetErrorHandler(la_XErrorHandler);
  912. int i;
  913. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  914. printf("\n\tcannot connect to x server\n\n");
  915. exit(0);
  916. }
  917. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  918. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  919. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  920. #ifdef LA_USE_GLES
  921. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  922. #else
  923. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  924. #endif
  925. #ifdef LA_USE_GLES
  926. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  927. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  928. EGLint egl_major, egl_minor;
  929. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  930. printf("Error: eglInitialize() failed\n"); return -1;
  931. }
  932. int scrnum;
  933. XSetWindowAttributes attr;
  934. XVisualInfo *visInfo, visTemplate;
  935. int num_visuals;
  936. EGLContext ctx;
  937. EGLint num_configs;
  938. EGLint vid;
  939. static const EGLint attribs[] = {
  940. EGL_RED_SIZE, 8,
  941. EGL_GREEN_SIZE, 8,
  942. EGL_BLUE_SIZE, 8,
  943. EGL_DEPTH_SIZE, 1,
  944. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  945. EGL_NONE
  946. };
  947. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  948. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  949. }
  950. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  951. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  952. }
  953. visTemplate.visualid = vid;
  954. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  955. if (!visInfo) {
  956. printf("Error: couldn't get X visual\n"); exit(1);
  957. }
  958. MAIN.xvi=visInfo;
  959. root = DefaultRootWindow(MAIN.dpy);
  960. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  961. printf("\n\tcannot create colormap\n\n"); exit(1);
  962. }
  963. eglBindAPI(EGL_OPENGL_ES_API);
  964. EGLint ctx_attribs[] = {
  965. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  966. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  967. EGL_NONE
  968. };
  969. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  970. if (!MAIN.glc) {
  971. printf("Error: eglCreateContext failed\n"); exit(1);
  972. }
  973. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  974. #else
  975. int visual_attribs[] = {
  976. GLX_X_RENDERABLE , True,
  977. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  978. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  979. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  980. GLX_RED_SIZE , 8,
  981. GLX_GREEN_SIZE , 8,
  982. GLX_BLUE_SIZE , 8,
  983. GLX_ALPHA_SIZE , 8,
  984. GLX_DEPTH_SIZE , 24,
  985. //GLX_STENCIL_SIZE , 8,
  986. GLX_DOUBLEBUFFER , True,
  987. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  988. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  989. None
  990. };
  991. int fbcount = -1;
  992. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  993. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  994. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  995. MAIN.BestFBC = fbconfig[0];
  996. int sample_buf,samples;
  997. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  998. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  999. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1000. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1001. free(fbconfig);
  1002. root = DefaultRootWindow(MAIN.dpy);
  1003. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1004. printf("\n\tcannot create colormap\n\n"); exit(0);
  1005. }
  1006. swa.colormap = MAIN.cmap;
  1007. root = DefaultRootWindow(MAIN.dpy);
  1008. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1009. MAIN.win=win;
  1010. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1011. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1012. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1013. printf("\n\tcannot create gl context\n\n"); exit(0);
  1014. }
  1015. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1016. tnsContextMakeCurrent(MAIN.glc,win,0);
  1017. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1018. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1019. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1020. int err=0;
  1021. if((err=glewInit())!=GLEW_OK){
  1022. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1023. };
  1024. #endif /* gles or glx */
  1025. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1026. la_SetCurrentGLContextDebug();
  1027. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1028. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1029. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1030. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1031. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1032. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1033. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1034. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1035. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1036. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1037. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1038. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1039. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1040. #endif //linux
  1041. #ifdef _WIN32
  1042. logPrintNew("Initializing LaGUI...\n");
  1043. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1044. setlocale(LC_ALL, "zh_CN.utf8");
  1045. MAIN.hinstance = GetModuleHandle(NULL);
  1046. HINSTANCE* hInst = &MAIN.hinstance;
  1047. WNDCLASSEXW wt;
  1048. wt.cbSize = sizeof(WNDCLASSEXW);
  1049. wt.cbClsExtra = 0;
  1050. wt.cbWndExtra = 0;
  1051. wt.hbrBackground = 0;
  1052. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1053. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1054. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1055. wt.hInstance = *hInst;
  1056. wt.lpfnWndProc = LA_WindowProc;
  1057. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1058. wt.lpszMenuName = 0;
  1059. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1060. if (!RegisterClassExW(&wt)) return 0;
  1061. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1062. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1063. SetProcessDPIAware();
  1064. GLenum err;
  1065. PIXELFORMATDESCRIPTOR pfd;
  1066. HINSTANCE* hinst = &MAIN.hinstance;
  1067. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1068. "Temp Window For Accessing GLEW!",
  1069. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1070. 0, 0, *hinst, 0);
  1071. HDC hdc = GetDC(hwnd);
  1072. HGLRC hglrc = 0;
  1073. SetPixelFormat(hdc, 1, &cpfd);
  1074. hglrc = wglCreateContext(hdc);
  1075. tnsContextMakeCurrent(hglrc, hdc,0);
  1076. //MAIN.hdc = hdc;
  1077. // MAIN.tWND = hwnd;
  1078. MAIN.glc = hglrc;
  1079. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1080. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1081. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1082. if (err = glewInit()) {
  1083. printf("Init Glew Failed\n");
  1084. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1085. return 0;
  1086. }
  1087. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1088. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1089. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1090. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1091. #endif
  1092. la_GetWorkingDirectoryInternal();
  1093. MAIN.SavePreferenceOnExit=1;
  1094. MAIN.FontSize = 0.6;
  1095. int dpi=64;
  1096. #ifdef _WIN32
  1097. dpi=la_GetDPI(hwnd);
  1098. #endif
  1099. #ifdef LA_LINUX
  1100. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1101. #endif
  1102. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1103. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1104. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1105. MAIN.UiScale=1;
  1106. MAIN.MarginSize = 1;
  1107. MAIN.ColorPickerGamma=1.5;
  1108. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1109. MAIN.ViewportHalftoneFactor=0.5;
  1110. MAIN.ViewportHalftoneSize=3.7;
  1111. tnsInitRenderKernel(64);
  1112. tnsInitBuiltinShaders();
  1113. tnsSetuptnsFontManager();
  1114. #define LOAD_FONT(font) \
  1115. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1116. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1117. LOAD_FONT("NotoEmoji-Regular.ttf");
  1118. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1119. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1120. //LOAD_FONT("NotoMusic-Regular.ttf");
  1121. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1122. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1123. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1124. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1125. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1126. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1127. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1128. MAIN.Audio=memAcquire(sizeof(laAudio));
  1129. #ifdef LA_WITH_LUAJIT
  1130. // starting lua
  1131. logPrint("Starting luajit...\n");
  1132. MAIN.L = lua_open();
  1133. la_luaLoadLibs(MAIN.L);
  1134. la_luaPrintStatus(MAIN.L);
  1135. tnsLuaInit(MAIN.L);
  1136. #endif
  1137. //interactions:
  1138. MAIN.TopFramerate = 60;
  1139. MAIN.ValuatorThreshold = 8;
  1140. MAIN.ScrollingSpeed = 3;
  1141. MAIN.AnimationSpeed = 0.4;
  1142. MAIN.PanelAnimationSpeed = 0.4;
  1143. MAIN.ZoomSpeed2D = 0.01;
  1144. MAIN.IdleTime = 0.75;
  1145. MAIN.TooltipCloseDistance = 30;
  1146. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1147. //display:
  1148. MAIN.FloatingAlpha = 0.35;
  1149. MAIN.SolidShadowLength = 20;
  1150. MAIN.WireColorSlices = 16;
  1151. MAIN.WireThickness = 5;
  1152. MAIN.WireSaggyness = 0.5;
  1153. #ifdef LAGUI_ANDROID
  1154. laAddResourceFolder("");
  1155. #else
  1156. laAddResourceFolder(".");
  1157. #endif
  1158. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1159. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1160. la_InitProgressWindow();
  1161. la_MakeTranslations_es_ES();
  1162. la_MakeTranslations_zh_hans();
  1163. //tns_RegisterResourcesForSoftwareRender();
  1164. la_RegisterDefaultSignals();
  1165. la_RegisterGeneralProps();
  1166. la_RegisterBuiltinTemplates();
  1167. la_RegisterMainThemes();
  1168. la_RegisterMainOperators();
  1169. la_RegisterMainUiTypes();
  1170. la_RegisterModellingOperators();
  1171. la_RegisterShapeOperators();
  1172. la_RegisterInternalProps();
  1173. la_RegisterAnimationResources();
  1174. la_RegisterWindowKeys();
  1175. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1176. laFinalizeUiTemplates();
  1177. laFinalizeOperators();
  1178. la_RegisterControllerProps();
  1179. la_RefreshControllers();
  1180. la_RegisterBasicNodes();
  1181. tns_RegisterNodes();
  1182. la_InitThreadEnviornment();
  1183. laSetRootInstance(&MAIN);
  1184. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1185. laPushDifferences(0, 0);
  1186. la_MakeDummyManagedUDF();
  1187. la_RegenerateWireColors();
  1188. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1189. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1190. logPrintNew("Initialization Completed\n");
  1191. MAIN.InitDone=1;
  1192. return 1;
  1193. }
  1194. int laGetReady(){
  1195. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1196. return laGetReadyWith(&ia);
  1197. }
  1198. void la_DestroyUiType(laUiType* uit);
  1199. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1200. void laShutoff(int SavePrefereces){
  1201. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1202. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1203. // transLate(pc->Description);
  1204. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1205. // transLate(p->Description);
  1206. // }
  1207. //}
  1208. transDumpMissMatchRecord("TranslationDump.txt");
  1209. if(MAIN.Cleanup) MAIN.Cleanup();
  1210. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1211. strSafeDestroy(&MAIN.WorkingDirectory);
  1212. strSafeDestroy(&MAIN.example_string);
  1213. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1214. // (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. )
  1215. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1216. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1217. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1218. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1219. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1220. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1221. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1222. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1223. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1224. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1225. strSafeDestroy(&MAIN.CopyPending);
  1226. la_ClearUDFRegistryAndFolders();
  1227. laClearManagedUDF();
  1228. laClearSaveProp();
  1229. logClear();
  1230. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1231. #ifdef LA_LINUX
  1232. tnsContextMakeCurrent(0,0,0);
  1233. tnsDeleteContext(MAIN.glc);
  1234. #ifdef LA_USE_GLES
  1235. eglTerminate(MAIN.egl_dpy);
  1236. #endif
  1237. #endif
  1238. #ifdef _WIN32
  1239. tnsContextMakeCurrent(0,0,0);
  1240. tnsDeleteContext(MAIN.glc);
  1241. UnloadWintab();
  1242. #endif
  1243. tnsQuit();
  1244. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1245. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1246. strSafeDump();
  1247. hshFree(&MAIN.DBInstMemLeft);
  1248. memNoLonger();
  1249. laSpinDestroy(&MAIN.MemLock);
  1250. laSpinDestroy(&MAIN.OpsLock);
  1251. #ifdef LA_WITH_LUAJIT
  1252. lua_close(MAIN.L);
  1253. #endif
  1254. printf("LaGUI has cleaned up.\n");
  1255. }
  1256. int laRestoreFactorySettings(){
  1257. char path[1024];
  1258. #ifdef LAGUI_ANDROID
  1259. sprintf(path,"%s","preferences.udf");
  1260. #else
  1261. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1262. #endif
  1263. if(remove(path)){ return 0; }
  1264. return 1;
  1265. }
  1266. void laSaveUserPreferences(){
  1267. char path[1024];
  1268. #ifdef LAGUI_ANDROID
  1269. sprintf(path,"%s","preferences.udf");
  1270. #else
  1271. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1272. #endif
  1273. laUDF* udf=laPrepareUDF(path);
  1274. laWriteProp(udf,"la.windows");
  1275. laWriteProp(udf,"la.user_preferences");
  1276. laWriteProp(udf,"la.input_mapping");
  1277. laWriteProp(udf,"la.controllers");
  1278. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1279. laWriteProp(udf,lip->p);
  1280. }
  1281. laPackUDF(udf,0,0);
  1282. }
  1283. void laEnsureUserPreferences(){
  1284. char path[1024];
  1285. #ifdef LAGUI_ANDROID
  1286. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1287. #else
  1288. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1289. #endif
  1290. laUDFRegistry* r=laFindUDFRegistry(path);
  1291. if(!r){ laSaveUserPreferences(); return; }
  1292. 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; }
  1293. laClearUDFRegistries();
  1294. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1295. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1296. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1297. laCloseUDF(udf);
  1298. la_RemoveDuplicatedScreenConf();
  1299. la_RemoveDuplicatedControllers();
  1300. laRefreshUDFRegistries();
  1301. //restore forced settings
  1302. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1303. }
  1304. void laAddExtraExtension(int FileType, ...){
  1305. va_list list; va_start(list,FileType);
  1306. char* ext;
  1307. while(ext=va_arg(list,char*)){ if(!ext) break;
  1308. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1309. et->FileType=FileType; et->Extension=ext;
  1310. lstAppendItem(&MAIN.ExtraExtensions, et);
  1311. logPrintNew("add ext %s",ext);
  1312. }
  1313. va_end(list);
  1314. }
  1315. void laAddExtraPreferencePath(const char* path){
  1316. if(!path) return;
  1317. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1318. }
  1319. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1320. if(!name || !Func) return;
  1321. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1322. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1323. }
  1324. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1325. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1326. }
  1327. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1328. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1329. }
  1330. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1331. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1332. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1333. }
  1334. void la_InputMappingGetKeyName(int key, int special, char* name){
  1335. char *_next=name; name[0]=0;
  1336. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1337. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1338. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1339. switch(key){
  1340. case ' ': strcat(name,"Space"); break;
  1341. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1342. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1343. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1344. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1345. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1346. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1347. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1348. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1349. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1350. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1351. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1352. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1353. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1354. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1355. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1356. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1357. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1358. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1359. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1360. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1361. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1362. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1363. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1364. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1365. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1366. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1367. case LA_KEY_F1: strcat(name,"F1"); break;
  1368. case LA_KEY_F2: strcat(name,"F2"); break;
  1369. case LA_KEY_F3: strcat(name,"F3"); break;
  1370. case LA_KEY_F4: strcat(name,"F4"); break;
  1371. case LA_KEY_F5: strcat(name,"F5"); break;
  1372. case LA_KEY_F6: strcat(name,"F6"); break;
  1373. case LA_KEY_F7: strcat(name,"F7"); break;
  1374. case LA_KEY_F8: strcat(name,"F8"); break;
  1375. case LA_KEY_F9: strcat(name,"F9"); break;
  1376. case LA_KEY_F10: strcat(name,"F10"); break;
  1377. case LA_KEY_F11: strcat(name,"F11"); break;
  1378. case LA_KEY_F12: strcat(name,"F12"); break;
  1379. default:
  1380. name = name+strlen(name); _next=name;
  1381. laToUTF8(key,name,&_next); *_next=0; break;
  1382. }
  1383. }
  1384. int la_InputMappingGetKeyFromName(char* name, int* special){
  1385. if(!name ||name[0]==0){ *special=0; return 0; }
  1386. *special=0;
  1387. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1388. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1389. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1390. char* p=name+strlen(name)-1;
  1391. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1392. while(*p=='+' || *p==' '){ p++; }
  1393. if(strSame(p,"Space")) return ' ';
  1394. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1395. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1396. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1397. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1398. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1399. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1400. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1401. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1402. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1403. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1404. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1405. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1406. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1407. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1408. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1409. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1410. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1411. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1412. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1413. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1414. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1415. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1416. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1417. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1418. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1419. if(strSame(p,"F1")) return LA_KEY_F1;
  1420. if(strSame(p,"F2")) return LA_KEY_F2;
  1421. if(strSame(p,"F3")) return LA_KEY_F3;
  1422. if(strSame(p,"F4")) return LA_KEY_F4;
  1423. if(strSame(p,"F5")) return LA_KEY_F5;
  1424. if(strSame(p,"F6")) return LA_KEY_F6;
  1425. if(strSame(p,"F7")) return LA_KEY_F7;
  1426. if(strSame(p,"F8")) return LA_KEY_F8;
  1427. if(strSame(p,"F9")) return LA_KEY_F9;
  1428. if(strSame(p,"F10")) return LA_KEY_F10;
  1429. if(strSame(p,"F11")) return LA_KEY_F11;
  1430. if(strSame(p,"F12")) return LA_KEY_F12;
  1431. int adv;
  1432. return laToUnicode(p,&adv);
  1433. }
  1434. laCustomSignal* laFindSignal(char* Name){
  1435. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1436. return 0;
  1437. }
  1438. laCustomSignal* laFindSignalByID(int ID){
  1439. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1440. return 0;
  1441. }
  1442. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1443. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1444. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1445. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1446. char* signal = SSTR(ime->Signal);
  1447. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1448. }
  1449. laInputMapping* laNewInputMapping(char* Name){
  1450. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1451. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1452. strSafeSet(&im->Name,Name);
  1453. return im;
  1454. }
  1455. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1456. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1457. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1458. memAssignRef(e,&e->Parent,im);
  1459. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1460. laInputMappingUpdateSignal(e);
  1461. e->SpecialKeyBits=SpecialKeyBit;
  1462. char buf[64],*_next=buf;
  1463. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1464. }
  1465. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1466. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1467. laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1468. }
  1469. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1470. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1471. }
  1472. void laRemoveInputMapping(laInputMapping* im){
  1473. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1474. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1475. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1476. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1477. }
  1478. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1479. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1480. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1481. return cs;
  1482. }
  1483. void laRemoveCustomSignal(laCustomSignal* cs){
  1484. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1485. }
  1486. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1487. void la_SendSignalsFromEvent(laEvent* e){
  1488. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1489. if(!im){return;}
  1490. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1491. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1492. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1493. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1494. }
  1495. }
  1496. }
  1497. }
  1498. //MSG====================================================
  1499. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1500. if (wnd->win == hwnd) return 1;
  1501. else return 0;
  1502. };
  1503. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1504. if (p->SL){ int s=p->SL<0?0:p->SL;
  1505. if (p->TX != s) laRecalcPanel(p);
  1506. p->TX = s;
  1507. }
  1508. if (p->SR){ int s=p->SR<0?0:p->SR;
  1509. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1510. p->TW = CW - p->TX - s;
  1511. }
  1512. if (p->ST){ int s=p->ST<0?0:p->ST;
  1513. if (p->TY != s) laRecalcPanel(p);
  1514. p->TY = s;
  1515. }
  1516. if (p->SB){ int s=p->SB<0?0:p->SB;
  1517. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1518. p->TH = CH - p->TY - s;
  1519. }
  1520. }
  1521. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1522. laPanel *p = 0;
  1523. b->X = X;
  1524. b->Y = Y;
  1525. b->W = W;
  1526. b->H = H;
  1527. if (b->B1){
  1528. int SplitWidth;
  1529. if (b->Vertical){
  1530. SplitWidth = H * b->SplitRatio;
  1531. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1532. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1533. }else{
  1534. SplitWidth = W * b->SplitRatio;
  1535. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1536. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1537. }
  1538. }
  1539. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1540. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1541. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1542. }
  1543. if (p = b->CurrentPanel){
  1544. int TitleGap=b->Folded?0:LA_RH;
  1545. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1546. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1547. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1548. laRecalcPanel(p);
  1549. }
  1550. }
  1551. void la_UpdateUiPlacement(laWindow *w){
  1552. laLayout *l;
  1553. laPanel *p;
  1554. int CW = w->CW;
  1555. int CH = w->CH;
  1556. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1557. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1558. if(w->MaximizedUi && w->MaximizedUiPanel){
  1559. laRecalcPanel(w->MaximizedUiPanel);
  1560. }elif(w->MaximizedBlock){
  1561. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1562. }else{
  1563. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1564. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1565. }
  1566. }
  1567. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1568. if(p->IsMenuPanel){
  1569. p->TH=p->H=MenuHeight;
  1570. }
  1571. la_EnsurePanelSnapping(p, CW, CH);
  1572. laRecalcPanel(p);
  1573. }
  1574. }
  1575. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1576. laWindow *window;
  1577. #ifdef LAGUI_ANDROID
  1578. window = MAIN.Windows.pFirst; if (!window) return;
  1579. window->X=x;window->Y=y;window->W=w;window->H=h;
  1580. window->CW=w;window->CH=h;
  1581. la_UpdateUiPlacement(window); return;
  1582. #endif
  1583. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1584. if (!window) return;
  1585. #ifdef _WIN32
  1586. RECT rcc; GetClientRect(window->win, &rcc);
  1587. RECT rcw; GetWindowRect(window->win, &rcw);
  1588. window->CW = rcc.right - rcc.left;
  1589. window->CH = rcc.bottom - rcc.top;
  1590. window->W = rcw.right - rcw.left;
  1591. window->H = rcw.bottom - rcw.top;
  1592. window->X = rcw.left; window->Y = rcw.top;
  1593. if (MAIN.AutoSwitchColorSpace) {
  1594. laScreen* s = laGetWindowScreen(window);
  1595. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1596. }
  1597. #endif
  1598. #ifdef LA_LINUX
  1599. XWindowAttributes attr;
  1600. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1601. window->CW = w; window->CH = h;
  1602. window->W = w; window->H = h;
  1603. window->X = x; window->Y = y;
  1604. if(MAIN.AutoSwitchColorSpace){
  1605. laScreen* s = laGetWindowScreen(window);
  1606. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1607. }
  1608. #endif
  1609. la_UpdateUiPlacement(window);
  1610. }
  1611. int la_OnWindowDestroy(SYSWINDOW wnd){
  1612. laListHandle *hlst = &MAIN.Windows;
  1613. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1614. if (!w) return 0;
  1615. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1616. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1617. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1618. laShutoff(1);
  1619. return 1;
  1620. }
  1621. laListHandle h={0};laLayout*l=0;
  1622. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1623. la_DestroyWindow(w);
  1624. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1625. #ifdef LA_LINUX
  1626. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1627. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1628. #endif
  1629. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1630. }
  1631. return 0;
  1632. }
  1633. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1634. laListHandle *el = &wnd->EventList;
  1635. laEvent* last_e=el->pLast;
  1636. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1637. #ifdef LA_LINUX
  1638. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1639. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1640. #endif
  1641. #ifdef _WIN32
  1642. 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);
  1643. #endif
  1644. }
  1645. void laMappingRequestEval();
  1646. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1647. laListHandle *wl = &MAIN.Windows;
  1648. laWindow* wnd;
  1649. #ifdef LAGUI_ANDROID
  1650. wnd = MAIN.Windows.pFirst;
  1651. #else
  1652. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1653. #endif
  1654. if (!wnd){ memFree(e); return; }
  1655. laListHandle *el = &wnd->EventList;
  1656. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1657. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1658. e->window = wnd;
  1659. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1660. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1661. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1662. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1663. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1664. e->GoodPressure=MAIN.IsPen;
  1665. lstAppendItem(el, (laListItem *)e);
  1666. laMappingRequestEval();
  1667. };
  1668. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1669. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1670. la_SaveEvent(hwnd, e, 1);
  1671. };
  1672. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1673. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1674. e->type = LA_INPUT; e->Input=Input;
  1675. la_SaveEvent(hwnd, e, 1);
  1676. }
  1677. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1678. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1679. e->type = LA_EMPTY;
  1680. la_SaveEvent(hwnd, e, 1);
  1681. }
  1682. void laSendOperatorTriggerEvent(){
  1683. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1684. MAIN.ReTriggerOperators = 0;
  1685. }
  1686. int la_TranslateSpecialKey(int keysym){
  1687. #ifdef LA_LINUX
  1688. switch(keysym){
  1689. case XK_Return: return LA_KEY_ENTER;
  1690. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1691. case XK_Delete: return LA_KEY_DELETE;
  1692. case XK_Escape: return LA_KEY_ESCAPE;
  1693. case XK_Tab: return LA_KEY_TAB;
  1694. case XK_Left: return LA_KEY_ARRLEFT;
  1695. case XK_Right: return LA_KEY_ARRRIGHT;
  1696. case XK_Up: return LA_KEY_ARRUP;
  1697. case XK_Down: return LA_KEY_ARRDOWN;
  1698. case XK_Control_L: return LA_KEY_CTRL;
  1699. case XK_Control_R: return LA_KEY_CTRL;
  1700. case XK_Shift_L: return LA_KEY_SHIFT;
  1701. case XK_Shift_R: return LA_KEY_SHIFT;
  1702. case XK_Alt_L: return LA_KEY_ALT;
  1703. case XK_Alt_R: return LA_KEY_ALT;
  1704. case XK_KP_1: return LA_KEY_NUM1;
  1705. case XK_KP_2: return LA_KEY_NUM2;
  1706. case XK_KP_3: return LA_KEY_NUM3;
  1707. case XK_KP_4: return LA_KEY_NUM4;
  1708. case XK_KP_5: return LA_KEY_NUM5;
  1709. case XK_KP_6: return LA_KEY_NUM6;
  1710. case XK_KP_7: return LA_KEY_NUM7;
  1711. case XK_KP_8: return LA_KEY_NUM8;
  1712. case XK_KP_9: return LA_KEY_NUM9;
  1713. case XK_KP_0: return LA_KEY_NUM0;
  1714. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1715. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1716. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1717. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1718. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1719. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1720. default: return keysym;
  1721. }
  1722. #endif
  1723. #ifdef _WIN32
  1724. switch (keysym) {
  1725. case VK_RETURN: return LA_KEY_ENTER;
  1726. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1727. case VK_TAB: return LA_KEY_TAB;
  1728. case VK_LEFT: return LA_KEY_ARRLEFT;
  1729. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1730. case VK_UP: return LA_KEY_ARRUP;
  1731. case VK_DOWN: return LA_KEY_ARRDOWN;
  1732. case VK_CONTROL: return LA_KEY_CTRL;
  1733. case VK_SHIFT: return LA_KEY_SHIFT;
  1734. case VK_MENU: return LA_KEY_ALT;
  1735. case VK_F1: return LA_KEY_F1;
  1736. case VK_F2: return LA_KEY_F2;
  1737. case VK_F3: return LA_KEY_F3;
  1738. case VK_F4: return LA_KEY_F4;
  1739. case VK_F5: return LA_KEY_F5;
  1740. case VK_F6: return LA_KEY_F6;
  1741. case VK_F7: return LA_KEY_F7;
  1742. case VK_F8: return LA_KEY_F8;
  1743. case VK_F9: return LA_KEY_F9;
  1744. case VK_F10: return LA_KEY_F10;
  1745. case VK_F11: return LA_KEY_F11;
  1746. case VK_F12: return LA_KEY_F12;
  1747. case VK_NUMPAD0: return LA_KEY_NUM0;
  1748. case VK_NUMPAD1: return LA_KEY_NUM1;
  1749. case VK_NUMPAD2: return LA_KEY_NUM2;
  1750. case VK_NUMPAD3: return LA_KEY_NUM3;
  1751. case VK_NUMPAD4: return LA_KEY_NUM4;
  1752. case VK_NUMPAD5: return LA_KEY_NUM5;
  1753. case VK_NUMPAD6: return LA_KEY_NUM6;
  1754. case VK_NUMPAD7: return LA_KEY_NUM7;
  1755. case VK_NUMPAD8: return LA_KEY_NUM8;
  1756. case VK_NUMPAD9: return LA_KEY_NUM9;
  1757. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1758. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1759. case VK_ADD: return LA_KEY_NUMPLUS;
  1760. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1761. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1762. case VK_OEM_1: return ';';
  1763. case VK_OEM_2: return '/';
  1764. case VK_OEM_3: return '`';
  1765. case VK_OEM_4: return '[';
  1766. case VK_OEM_5: return '\\';
  1767. case VK_OEM_6: return ']';
  1768. case VK_OEM_7: return '\'';
  1769. case VK_OEM_COMMA: return ',';
  1770. case VK_OEM_PERIOD: return '.';
  1771. case VK_OEM_PLUS: return '+';
  1772. case VK_OEM_MINUS: return '-';
  1773. default: return keysym;
  1774. }
  1775. #endif
  1776. }
  1777. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1778. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1779. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1780. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1781. // la_SaveEvent(hwnd, e, 0);
  1782. //}
  1783. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1784. e->type = type; e->x = x; e->y = y;
  1785. la_SaveEvent(hwnd, e, 0);
  1786. MAIN.evLastX=x; MAIN.evLastY=y;
  1787. };
  1788. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1789. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1790. e->type = type;
  1791. la_SaveEvent(hwnd, e, 1);
  1792. };
  1793. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1794. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1795. e->type = LA_SIGNAL_EVENT;
  1796. e->key = signal;
  1797. la_SaveEvent(hwnd, e, 1);
  1798. };
  1799. void laRetriggerOperators(){
  1800. MAIN.ReTriggerOperators = 1;
  1801. }
  1802. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1803. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1804. }
  1805. void laSetCleanupCallback(laCleanupF Cleanup){
  1806. MAIN.Cleanup=Cleanup;
  1807. }
  1808. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1809. MAIN.InputProcess=InputProcess;
  1810. }
  1811. //====================================================================================================
  1812. void la_DestroyTheme(laTheme* t){
  1813. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1814. strSafeDestroy(&t->Name);
  1815. strSafeDestroy(&t->Author);
  1816. }
  1817. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1818. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1819. strSafeSet(&t->Name, Name);
  1820. strSafeSet(&t->Author, AuthorName);
  1821. lstAppendItem(&MAIN.Themes, t);
  1822. MAIN.CurrentTheme = t;
  1823. return t;
  1824. }
  1825. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1826. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1827. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1828. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1829. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1830. strSafeSet(&bt->Name, Name);
  1831. bt->NormalY=NormalY;
  1832. bt->ActiveY=ActiveY;
  1833. bt->BorderY=BorderY;
  1834. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1835. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1836. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1837. bt->BackRef = BackRef;
  1838. lstAppendItem(&t->BoxedThemes, bt);
  1839. return bt;
  1840. }
  1841. laTheme *laGetTheme(const char *ThemeName){
  1842. laTheme *t = MAIN.Themes.pFirst;
  1843. for (t; t; t = t->Item.pNext){
  1844. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1845. }
  1846. return 0;
  1847. }
  1848. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1849. laTheme *t = MAIN.Themes.pFirst;
  1850. for (t; t; t = t->Item.pNext){
  1851. laBoxedTheme *bt;
  1852. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1853. bt = t->BoxedThemes.pFirst;
  1854. for (bt; bt; bt = bt->Item.pNext){
  1855. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1856. }
  1857. }
  1858. return 0;
  1859. }
  1860. real* laThemeColor(laBoxedTheme* bt, int which){
  1861. switch(which){
  1862. default:
  1863. case LA_BT_NORMAL: return bt->Normal;
  1864. case LA_UI_EDITING:
  1865. case LA_BT_ACTIVE: return bt->Active;
  1866. case LA_BT_BORDER: return bt->Border;
  1867. case LA_BT_TEXT: return bt->Text; break;
  1868. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1869. case LA_BT_DISABLED: return bt->Inactive; break;
  1870. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1871. }
  1872. return bt->Normal;
  1873. }
  1874. real* laAccentColor(int which){
  1875. switch(which){
  1876. default:
  1877. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1878. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1879. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1880. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1881. case LA_BT_FACE:
  1882. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1883. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1884. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1885. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1886. }
  1887. return MAIN.CurrentTheme->SelectionColor;
  1888. }
  1889. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1890. real hcy[3];
  1891. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1892. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1893. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1894. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1895. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1896. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1897. int *tm=&bt->LM,*tp=&bt->LP;
  1898. for(int i=0;i<4;i++){
  1899. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1900. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1901. }
  1902. }
  1903. void la_RefreshThemeColorSelf(laTheme* th){
  1904. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1905. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1906. real hcy[3], usehcy[3];
  1907. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1908. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1909. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1910. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1911. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1912. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1913. }
  1914. void la_RefreshThemeColor(laTheme* th){
  1915. real hcy[3], usehcy[3], normalhcy[3];
  1916. tnsRGB2HCY(th->Color,hcy);
  1917. la_RefreshThemeColorSelf(th);
  1918. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1919. la_RefreshBoxedThemeColor(bt);
  1920. (*bt->BackRef) = bt;
  1921. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1922. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1923. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1924. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1925. }
  1926. }
  1927. //I FUCKING HATE THIS STUPID FUNCTION
  1928. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1929. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1930. laUiListDrawItem *last = uild->Items.pFirst;
  1931. int LimW=_R-_L;
  1932. int SL, SR, SU, SB;
  1933. int Target__B = Target->B;
  1934. int Target__R = Target->R;
  1935. uildi->Target = Target;
  1936. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1937. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1938. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1939. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1940. uildi->L = last ? Target->L - last->XP : Target->L;
  1941. uildi->R = last ? Target__R - last->XP : Target__R;
  1942. uildi->U = last ? Target->U - last->YP : Target->U;
  1943. uildi->B = last ? Target__B - last->YP : Target__B;
  1944. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1945. uildi->L -= GlobalX;
  1946. uildi->R -= GlobalX;
  1947. uildi->U -= GlobalY;
  1948. uildi->B -= GlobalY;
  1949. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1950. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1951. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1952. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1953. uildi->DifX = SL - uildi->L;
  1954. uildi->DifY = SU - uildi->U;
  1955. uildi->L = SL;
  1956. uildi->R = SR+uildi->DifX;
  1957. uildi->U = SU;
  1958. uildi->B = SB;//+uildi->DifY;
  1959. if(uildi->R>_R){ uildi->R=_R; }
  1960. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1961. //printf("py %f %d lb %d b %d limh %d sb%d\n",Target->PanY,uildi->U,last?last->B:0,uildi->B,LimH,SB);
  1962. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1963. memFree(uildi);
  1964. return 0;
  1965. }
  1966. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  1967. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  1968. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  1969. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  1970. Target->U + Target->PanY + uildi->DifY+1,
  1971. -100, 100);
  1972. lstPushItem(&uild->Items, uildi);
  1973. return 1;
  1974. }
  1975. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1976. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1977. laUiListDrawItem *last = uild->Items.pFirst;
  1978. int SL, SR, SU, SB;
  1979. if (B - U > LimH) B = U + LimH;
  1980. uildi->XP = last ? last->XP + PanX : PanX;
  1981. uildi->YP = last ? last->YP + PanY : PanY;
  1982. uildi->L = last ? L - last->XP : L;
  1983. uildi->R = last ? R - last->XP : R;
  1984. uildi->U = last ? U - last->YP : U;
  1985. uildi->B = last ? B - last->YP : B;
  1986. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1987. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1988. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1989. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1990. uildi->DifX = SL - uildi->L;
  1991. uildi->DifY = SU - uildi->U;
  1992. uildi->L = SL;
  1993. uildi->R = SR;
  1994. uildi->U = SU;
  1995. uildi->B = SB;
  1996. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1997. tnsOrtho(L + PanX + uildi->DifX,
  1998. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  1999. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2000. U + PanY + uildi->DifY,
  2001. -100, 100);
  2002. lstPushItem(&uild->Items, uildi);
  2003. }
  2004. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2005. int* savel, int* saver, int* saveu, int* saveb){
  2006. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2007. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2008. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2009. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2010. real x,y,w,h;
  2011. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2012. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2013. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2014. }
  2015. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2016. laUiListDrawItem *uildi = uild->Items.pFirst;
  2017. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2018. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2019. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2020. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2021. Target->U + Target->PanY + uildi->DifY -1,
  2022. -100, 100);
  2023. }
  2024. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2025. laUiListDrawItem *uildi = lstPopItem(uild);
  2026. laUiList *Target;
  2027. memFree(uildi);
  2028. uildi = uild->Items.pFirst;
  2029. if (!uildi || !uildi->Target){
  2030. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2031. return;
  2032. }
  2033. Target = uildi->Target;
  2034. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2035. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2036. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2037. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2038. Target->U + Target->PanY + uildi->DifY -1,
  2039. -100, 100);
  2040. }
  2041. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2042. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2043. uildi->L = L;
  2044. uildi->R = R;
  2045. uildi->U = U;
  2046. uildi->B = B;
  2047. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2048. tnsOrtho(L, R, B, U, -100, 100);
  2049. lstPushItem(&uild->Items, uildi);
  2050. }
  2051. void la_ClearUiListMatrix(laUiListDraw *uild){
  2052. laUiListDrawItem *uildi;
  2053. while (uildi = lstPopItem(uild)){
  2054. memFree(uildi);
  2055. }
  2056. }
  2057. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2058. int la_DrawUiListRecursive(laUiListDraw *uild, laUiList *uil, int L, int R, int U, int B, int LimH, int ConditionStackLevel, int GlobalX, int GlobalY, int RegisterNodes);
  2059. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2060. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2061. int la_TestUiListMinumWidth(laUiList *uil);
  2062. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2063. if (ui){
  2064. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2065. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2066. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2067. p->X = p->TX; p->Y = p->TY;
  2068. p->W = p->TW;
  2069. }
  2070. }
  2071. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2072. int cw = MAIN.CurrentWindow->CW;
  2073. int ch = MAIN.CurrentWindow->CH;
  2074. int PH = p->TH;
  2075. laBoxedTheme*bt = *p->BT;
  2076. int uih=uil->B + bt->BM;
  2077. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2078. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2079. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2080. else p->TH = PH;
  2081. p->H = p->TH;
  2082. if(p->BoundUi){
  2083. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2084. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2085. if (p->X < 0) p->X = 0;
  2086. if (p->Y < 0) p->Y = 0;
  2087. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2088. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2089. }else{
  2090. if (p->Y < 0) p->Y = 0;
  2091. if ((!p->Block)&&(!p->IsMenuPanel)){
  2092. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2093. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2094. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2095. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2096. }
  2097. }
  2098. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2099. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2100. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2101. }
  2102. if (p->ST) p->TY = p->ST;
  2103. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2104. if (p->SB) p->TH = ch - p->TY - p->SB;
  2105. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2106. p->TX = p->X; p->TY = p->Y;
  2107. p->TW = p->W; p->TH = p->H;
  2108. }
  2109. void laPlacePanelForCreation(laPanel *p){
  2110. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2111. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2112. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2113. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2114. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2115. p->TX=p->X; p->TY=p->Y;
  2116. }
  2117. }
  2118. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2119. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2120. tnsViewportWithScissor(0, 0, p->W, p->H);
  2121. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2122. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2123. }
  2124. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2125. tnsDrawToScreen();
  2126. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2127. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2128. }
  2129. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2130. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2131. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2132. }
  2133. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2134. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2135. tnsClearAll();
  2136. }
  2137. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2138. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2139. real Color[] = {1, 1, 1, 1};
  2140. real L, W, U, H;
  2141. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2142. if(MAIN.EnableColorManagement){
  2143. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2144. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2145. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2146. }else{
  2147. tnsUniformOutputColorSpace(T->immShader,0);
  2148. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2149. tnsUniformColorComposing(T->immShader,0,0,0);
  2150. }
  2151. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2152. tnsUseNoTexture();
  2153. if (!p->IsMenuPanel){
  2154. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2155. }
  2156. tnsFlush();
  2157. }
  2158. if(p->ParentOperator){
  2159. tnsUseNoTexture();
  2160. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2161. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2162. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2163. }
  2164. switch (p->AnimationMode){
  2165. case 0: /* and */
  2166. case LA_PANEL_ANIMATION_FLASH:
  2167. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2168. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2169. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2170. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2171. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2172. tnsPackAs(GL_TRIANGLES);
  2173. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2174. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2175. }
  2176. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2177. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2178. if((int)(p->AnimationRatio*6)%2){
  2179. tnsUseNoTexture();
  2180. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2181. 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);
  2182. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2183. }
  2184. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2185. }
  2186. break;
  2187. case LA_PANEL_ANIMATION_DROP_DOWN:
  2188. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2189. tnsDraw2DTextureArg(
  2190. p->OffScr->pColor[0],
  2191. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2192. Color,
  2193. 0, 0, 1 - p->AnimationRatio, 0);
  2194. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2195. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2196. break;
  2197. case LA_PANEL_ANIMATION_EXPAND:
  2198. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2199. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2200. W = tnsLinearItp(0, p->W, 0.4);
  2201. H = tnsLinearItp(0, p->H, 0.4);
  2202. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2203. tnsDraw2DTextureArg(
  2204. p->OffScr->pColor[0],
  2205. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2206. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2207. Color,
  2208. 0, 0, 0, 0);
  2209. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2210. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2211. break;
  2212. case LA_PANEL_ANIMATION_DISSOVE:
  2213. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2214. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2215. W = tnsLinearItp(0, p->W, 1.4);
  2216. H = tnsLinearItp(0, p->H, 1.4);
  2217. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2218. if (p->OffScr) tnsDraw2DTextureArg(
  2219. p->OffScr->pColor[0],
  2220. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2221. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2222. Color,
  2223. 0, 0, 0, 0);
  2224. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2225. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2226. break;
  2227. case LA_PANEL_ANIMATION_COLLAPSE:
  2228. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2229. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2230. W = tnsLinearItp(0, p->W, 0.4);
  2231. H = tnsLinearItp(0, p->H, 0.4);
  2232. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2233. if (p->OffScr) tnsDraw2DTextureArg(
  2234. p->OffScr->pColor[0],
  2235. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2236. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2237. Color,
  2238. 0, 0, 0, 0);
  2239. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2240. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2241. break;
  2242. case LA_PANEL_ANIMATION_MINIMIZE:
  2243. L = tnsLinearItp(0, p->X, 0.3);
  2244. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2245. W = tnsLinearItp(0, p->W, 0.4);
  2246. H = tnsLinearItp(0, p->H, 0.4);
  2247. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2248. tnsDraw2DTextureArg(
  2249. p->OffScr->pColor[0],
  2250. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2251. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2252. Color,
  2253. 0, 0, 0, 0);
  2254. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2255. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2256. break;
  2257. }
  2258. tnsFlush();
  2259. tnsUniformOutputColorSpace(T->immShader,0);
  2260. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2261. tnsUniformColorComposing(T->immShader,0,0,0);
  2262. }
  2263. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2264. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2265. else{
  2266. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:GL_RGBA8;
  2267. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2268. }
  2269. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2270. }
  2271. void la_PanelRefreshDetachedProp(laPanel *panel){
  2272. laProp *p;
  2273. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2274. la_StepPropPack(&p->DetachedPP);
  2275. la_UsePropPack(&p->DetachedPP, 0);
  2276. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2277. // laUseDataBlock(
  2278. // p->DetachedPP.LastPs->UseInstance,
  2279. // p->DetachedPP.LastPs->p,
  2280. // MAIN.PropMatcherContextP->FrameDistinguish,
  2281. // MAIN.PropMatcherContextP,
  2282. // la_PropPanelUserRemover, 0);
  2283. //}
  2284. }
  2285. }
  2286. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2287. real* color=laThemeColor(bt,LA_BT_BORDER);
  2288. tnsColor4d(0,0,0,Alpha);
  2289. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2290. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2291. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2292. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2293. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2294. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2295. tnsPackAs(GL_TRIANGLE_STRIP);
  2296. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2297. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2298. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2299. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2300. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2301. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2302. }
  2303. int la_AnimateUiListRecursive(laUiList *uil);
  2304. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2305. int DrawState_ = 0;
  2306. laUiListDraw uild = {0};
  2307. if (p->Show){
  2308. la_SetPropMathcerContext(p);
  2309. MAIN.CurrentPanel = p;
  2310. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2311. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2312. //}
  2313. if (p->Refresh & LA_TAG_RECALC){
  2314. laRecalcPanelImmediate(p);
  2315. }
  2316. if (!p->MenuRefer){
  2317. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2318. if (p->Refresh || !p->OffScr){
  2319. la_PanelDrawToOffsceen(p, &p->UI);
  2320. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2321. la_PanelBackgroundInit(p, bt);
  2322. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2323. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2324. tnsFlush();
  2325. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2326. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2327. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2328. DrawState_++;
  2329. }
  2330. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2331. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2332. if(p->UI.PanY<0){p->UI.PanY=0;}
  2333. DrawState_++;
  2334. }
  2335. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2336. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2337. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2338. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2339. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2340. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2341. if(p!=w->MaximizedUiPanel){
  2342. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2343. }else{
  2344. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2345. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2346. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2347. tnsFlush();
  2348. }
  2349. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2350. }
  2351. }else{
  2352. if (p->Refresh || !p->OffScr){
  2353. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2354. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2355. la_PanelBackgroundInit(p, bt);
  2356. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2357. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2358. tnsFlush();
  2359. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2360. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2361. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2362. DrawState_++;
  2363. }
  2364. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2365. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2366. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2367. DrawState_++;
  2368. }
  2369. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2370. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2371. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2372. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2373. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2374. }
  2375. }
  2376. tnsDrawToScreen();
  2377. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2378. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2379. la_PanelDrawToWindow(p, w);
  2380. }elif (p->AnimationMode){
  2381. la_PanelDrawToWindow(p, w);
  2382. }
  2383. }
  2384. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2385. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2386. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2387. laPanel *pi, *PrevPI;
  2388. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2389. PrevPI = pi->Item.pPrev;
  2390. if (pi->AnimationMode && pi->LaterDestroy){
  2391. lstRemoveItem(&p->SubPanels, pi);
  2392. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2393. continue;
  2394. }
  2395. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2396. la_AttachedPanelDefDraw(w,pi,bt);
  2397. }
  2398. }
  2399. }
  2400. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2401. real PanelSquare[] = {
  2402. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2403. b->X + 2, CH - (b->Y + b->H - 4),
  2404. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2405. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2406. real Center[] = {
  2407. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2408. real DraggingPlot[] = {
  2409. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2410. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2411. PanelSquare[0],
  2412. PanelSquare[1],
  2413. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2414. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2415. PanelSquare[2],
  2416. PanelSquare[3],
  2417. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2418. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2419. PanelSquare[4],
  2420. PanelSquare[5],
  2421. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2422. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2423. PanelSquare[6],
  2424. PanelSquare[7],
  2425. };
  2426. real Square[] = {
  2427. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2428. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2429. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2430. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2431. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2432. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2433. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2434. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2435. };
  2436. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2437. LA_COLOR3(BorderColor4dV), 0,
  2438. LA_COLOR3(BorderColor4dV), 0.8,
  2439. LA_COLOR3(BorderColor4dV), 0,
  2440. LA_COLOR3(BorderColor4dV), 0.8,
  2441. LA_COLOR3(BorderColor4dV), 0,
  2442. LA_COLOR3(BorderColor4dV), 0.8,
  2443. LA_COLOR3(BorderColor4dV), 0,
  2444. };
  2445. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2446. LA_COLOR3(FillColor4dv), 0,
  2447. LA_COLOR3(FillColor4dv), 0.8,
  2448. LA_COLOR3(FillColor4dv), 0,
  2449. LA_COLOR3(FillColor4dv), 0.8,
  2450. LA_COLOR3(FillColor4dv), 0,
  2451. LA_COLOR3(FillColor4dv), 0.8,
  2452. LA_COLOR3(FillColor4dv), 0,
  2453. };
  2454. tnsUseNoTexture();
  2455. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2456. int Index[4];
  2457. tnsVertexArray2d(DraggingPlot, 8);
  2458. tnsColorArray4d(FillColor, 8);
  2459. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2460. case 0:
  2461. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2462. break;
  2463. case LA_BLOCK_DROP_LOCATION_L:
  2464. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2465. break;
  2466. case LA_BLOCK_DROP_LOCATION_R:
  2467. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2468. break;
  2469. case LA_BLOCK_DROP_LOCATION_U:
  2470. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2471. break;
  2472. case LA_BLOCK_DROP_LOCATION_B:
  2473. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2474. break;
  2475. }
  2476. //glDisable(GL_CULL_FACE);
  2477. tnsIndexArray(Index, 4);
  2478. tnsPackAs(GL_TRIANGLE_FAN);
  2479. //tnsFlush();
  2480. }
  2481. tnsVertexArray2d(DraggingPlot, 8);
  2482. tnsColorArray4d(PlotColor, 8);
  2483. tnsPackAs(GL_LINES);
  2484. tnsVertexArray2d(Square, 4);
  2485. tnsColor4dv(BorderColor4dV);
  2486. tnsPackAs(GL_LINE_LOOP);
  2487. glLineWidth(LA_SEAM_W);
  2488. tnsFlush();
  2489. glLineWidth(1);
  2490. }
  2491. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2492. laBoxedTheme *bt = _LA_THEME_TAB;
  2493. laPanel *p;
  2494. real v[] = {
  2495. b->X, CH - b->Y,
  2496. b->X + LA_SEAM_W, CH - b->Y ,
  2497. b->X, CH - (b->Y + b->H),
  2498. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2499. b->X + b->W, CH - (b->Y + b->H),
  2500. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2501. b->X + b->W, CH - b->Y,
  2502. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2503. real tv[8];
  2504. real ratio = 1.0001f;
  2505. int tw = 0;
  2506. int L = LA_RH+LA_SEAM_W;
  2507. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2508. if(MAIN.EnableColorManagement){
  2509. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2510. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2511. }else{
  2512. tnsUniformOutputColorSpace(T->immShader,0);
  2513. tnsUniformColorComposing(T->immShader,0,0,0);
  2514. }
  2515. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2516. tw += p->TitleWidth + LA_SEAM_W*2;
  2517. }
  2518. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2519. tnsUseNoTexture();
  2520. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2521. tnsVertexArray2d(v, 8);
  2522. tnsPackAs(GL_TRIANGLE_STRIP);
  2523. int TitleGap=b->Folded?0:LA_RH;
  2524. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2525. b->X + b->W, (CH - b->Y),
  2526. b->X + b->W, (CH - b->Y - TitleGap),
  2527. b->X, (CH - b->Y - TitleGap));
  2528. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2529. tnsVertexArray2d(tv, 4);
  2530. tnsPackAs(GL_TRIANGLE_FAN);
  2531. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2532. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2533. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2534. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2535. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2536. tnsVertexArray2d(tv, 4);
  2537. tnsPackAs(GL_TRIANGLE_FAN);
  2538. if(b->Folded){
  2539. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2540. tnsDrawStringAuto("⯆",Color, b->X+LA_SEAM_W,b->X+LA_SEAM_W+LA_RH, CH-b->Y, LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  2541. tnsDrawStringAuto("⮼",Color, b->X+LA_SEAM_W+LA_RH,b->X+LA_SEAM_W+LA_2RH, CH-b->Y, LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  2542. tnsFlush(); return;
  2543. }
  2544. int LT=0,RT=0;
  2545. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2546. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2547. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2548. b->X + L+RT * ratio, (CH - b->Y),
  2549. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2550. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2551. if (p == b->CurrentPanel){
  2552. tnsUseNoTexture();
  2553. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2554. tnsVertexArray2d(tv, 4);
  2555. tnsPackAs(GL_TRIANGLE_FAN);
  2556. 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);
  2557. }else{
  2558. 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);
  2559. }
  2560. LT =RT;
  2561. }
  2562. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2563. tnsFlush();
  2564. tnsUniformOutputColorSpace(T->immShader,0);
  2565. tnsUniformColorComposing(T->immShader,0,0,0);
  2566. }
  2567. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2568. laBoxedTheme *bt = _LA_THEME_PANEL;
  2569. real tv[8];
  2570. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2571. if(MAIN.EnableColorManagement){
  2572. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2573. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2574. }else{
  2575. tnsUniformOutputColorSpace(T->immShader,0);
  2576. tnsUniformColorComposing(T->immShader,0,0,0);
  2577. }
  2578. tnsUseNoTexture();
  2579. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2580. b->X + b->W, (CH - b->Y),
  2581. b->X + b->W, (CH - b->Y-b->H),
  2582. b->X, (CH - b->Y-b->H));
  2583. tnsVertexArray2d(tv, 4);
  2584. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2585. tnsPackAs(GL_TRIANGLE_FAN);
  2586. 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,
  2587. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2588. tnsFlush();
  2589. tnsUniformOutputColorSpace(T->immShader,0);
  2590. tnsUniformColorComposing(T->immShader,0,0,0);
  2591. }
  2592. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2593. if (b->B1){
  2594. la_BlockDefDrawRecursive(w, bt, b->B1);
  2595. la_BlockDefDrawRecursive(w, bt, b->B2);
  2596. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2597. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2598. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2599. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2600. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2601. la_BlockDefDrawSelf(b, w->CH);
  2602. }else{
  2603. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2604. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2605. la_BlockDefDrawSelfEmpty(b, w->CH);
  2606. }
  2607. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2608. tnsUseNoTexture();
  2609. int at; real tv[8];
  2610. if (b->Vertical){
  2611. at = b->H * b->SplitRatio + b->Y;
  2612. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2613. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2614. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2615. b->X, (w->CH - at - LA_SEAM_W));
  2616. }else{
  2617. at = b->X + b->W * b->SplitRatio;
  2618. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2619. at- LA_SEAM_W, (w->CH - b->Y),
  2620. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2621. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2622. }
  2623. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2624. tnsVertexArray2d(tv, 4);
  2625. tnsPackAs(GL_TRIANGLE_FAN);
  2626. }
  2627. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2628. tnsFlush();
  2629. }
  2630. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2631. if (b->B1){
  2632. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2633. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2634. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2635. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2636. }
  2637. tnsFlush();
  2638. }
  2639. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2640. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2641. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2642. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2643. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2644. if(p->OffScr){
  2645. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2646. }
  2647. }
  2648. }
  2649. void la_ClearUnusedFramebuffers(laWindow* w){
  2650. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2651. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2652. }
  2653. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2654. if(p->Show || p->AnimationMode) continue;
  2655. if(p->OffScr){
  2656. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2657. }
  2658. }
  2659. }
  2660. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2661. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2662. laPanel *p, *NextP;
  2663. laLayout *l = w->CurrentLayout;
  2664. if (!w->CH || !w->CW) return;
  2665. la_ClearUnusedFramebuffers(w);
  2666. tnsDrawToScreen();
  2667. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2668. glClearColor(0.2, 0.2, 0.3, 1.0);
  2669. tnsClearAll();
  2670. tnsUseNoTexture();
  2671. if (l->Draw) l->Draw(w, l);
  2672. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2673. glEnable(GL_BLEND);
  2674. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2675. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2676. laUiItem* ui;
  2677. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2678. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2679. la_SetPropMathcerContext(p);
  2680. if(p->Refresh){
  2681. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2682. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2683. if(MAIN.EnableColorManagement){
  2684. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2685. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2686. }else{
  2687. tnsUniformOutputColorSpace(T->immShader,0);
  2688. tnsUniformColorComposing(T->immShader,0,0,0);
  2689. }
  2690. if(p->Refresh&LA_TAG_RECALC){
  2691. laRecalcPanelImmediate(p);
  2692. }
  2693. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2694. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2695. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2696. }
  2697. tnsDrawToScreen();
  2698. tnsResetViewMatrix();
  2699. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2700. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2701. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2702. tnsFlush();
  2703. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2704. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2705. tnsFlush();
  2706. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2707. }
  2708. }
  2709. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2710. la_AttachedPanelDefDraw(w,p,*p->BT);
  2711. }else{
  2712. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2713. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2714. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2715. }
  2716. for (p = w->Panels.pLast; p; p = NextP){
  2717. NextP = p->Item.pPrev;
  2718. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2719. if (p->AnimationMode && p->LaterDestroy){
  2720. lstRemoveItem(&w->Panels, p);
  2721. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2722. continue;
  2723. }
  2724. la_PanelDefDraw(w, p, *p->BT);
  2725. }
  2726. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2727. la_AttachedPanelDefDraw(w,p,*p->BT);
  2728. }
  2729. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2730. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2731. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2732. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2733. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2734. tnsFlush();
  2735. }
  2736. for (p = w->FadingPanels.pLast; p; p = NextP){
  2737. NextP = p->Item.pPrev;
  2738. if (!p->AnimationMode){
  2739. lstRemoveItem(&w->FadingPanels, p);
  2740. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2741. laDeferredDestroyPanel(p, 0);
  2742. }else
  2743. la_PanelDrawToWindow(p, w);
  2744. }
  2745. }
  2746. int laStartWindow(laWindow *w){
  2747. #ifdef LA_LINUX
  2748. XMapWindow(MAIN.dpy,w->win);
  2749. tnsContextMakeWindowCurrent(w);
  2750. #endif
  2751. #ifdef _WIN32
  2752. ShowWindow(w->win, SW_SHOWNORMAL);
  2753. #endif
  2754. MAIN.CurrentWindow = w;
  2755. if(!w->CurrentLayout){
  2756. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2757. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2758. }
  2759. laRedrawCurrentWindow();
  2760. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2761. w->Shown = 1;
  2762. }
  2763. void la_AssignWindowPP(laWindow* w){
  2764. w->PP.EndInstance = w;
  2765. w->PP.LastPs = &w->FakePS;
  2766. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2767. w->PP.LastPs->UseInstance = w;
  2768. w->PP.LastPs->Type = U'.';
  2769. }
  2770. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2771. #ifdef LAGUI_ANDROID
  2772. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2773. #endif
  2774. laWindow *n = memAcquire(sizeof(laWindow));
  2775. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2776. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2777. #ifdef LAGUI_ANDROID
  2778. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2779. #endif
  2780. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2781. lstAppendItem(&MAIN.Windows, n);
  2782. MAIN.CurrentWindow = n;
  2783. la_AssignWindowPP(n);
  2784. laui_DefaultMenuBar(n);
  2785. return n;
  2786. }
  2787. void laSetWindowCursor(int id){
  2788. MAIN.CurrentCursor = id;
  2789. #ifdef LA_LINUX
  2790. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2791. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2792. #endif
  2793. #ifdef _WIN32
  2794. SetCursor(la_ConvertCursorID(id));
  2795. #endif
  2796. };
  2797. void la_AssignBlockPP(laBlock* b){
  2798. b->PP.EndInstance = b;
  2799. b->PP.LastPs = &b->FakePS;
  2800. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2801. b->PP.LastPs->UseInstance = b;
  2802. b->PP.LastPs->Type = U'.';
  2803. }
  2804. void laDestroyLayout(laWindow *w, laLayout* l){
  2805. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2806. laDestroyBlocksRecursive(l->FirstBlock);
  2807. strSafeDestroy(&l->ID);
  2808. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2809. lstRemoveItem(&w->Layouts,l); memFree(l);
  2810. }
  2811. laLayout *laDesignLayout(laWindow *w, char *Title){
  2812. laLayout *l = memAcquire(sizeof(laLayout));
  2813. l->FirstBlock = memAcquire(sizeof(laBlock));
  2814. la_AssignBlockPP(l->FirstBlock);
  2815. lstAppendItem(&w->Layouts, l);
  2816. strSafeSet(&l->ID, Title);
  2817. memAssignRef(w, &w->CurrentLayout, l);
  2818. laRenameWindow(w, Title);
  2819. return l;
  2820. }
  2821. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2822. void laUnfoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=0; b->OnButton=0; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2823. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2824. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2825. laNotifyUsers("la.windows.maximized_block"); }
  2826. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2827. laNotifyUsers("la.windows.maximized_block"); }
  2828. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2829. laRestoreCanvasUI();
  2830. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2831. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2832. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2833. UiParentPanel->Show=0;
  2834. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2835. }
  2836. void laRestoreCanvasUI(){
  2837. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2838. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2839. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2840. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2841. }
  2842. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2843. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2844. }
  2845. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2846. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2847. laPanel *p;
  2848. b->SplitRatio = Percentage;
  2849. b->Vertical = 0;
  2850. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2851. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2852. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2853. p->Block = b->B1;
  2854. }
  2855. b->B1->Panels.pFirst = b->Panels.pFirst;
  2856. b->B1->Panels.pLast = b->Panels.pLast;
  2857. b->B1->CurrentPanel = b->CurrentPanel;
  2858. b->B1->parent = b->B2->parent=b;
  2859. b->Panels.pFirst = 0;
  2860. b->Panels.pLast = 0;
  2861. b->CurrentPanel = 0;
  2862. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2863. }
  2864. void laSplitBlockVertical(laBlock *b, real Percentage){
  2865. laPanel *p;
  2866. b->SplitRatio = Percentage;
  2867. b->Vertical = 1;
  2868. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2869. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2870. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2871. p->Block = b->B1;
  2872. }
  2873. b->B1->Panels.pFirst = b->Panels.pFirst;
  2874. b->B1->Panels.pLast = b->Panels.pLast;
  2875. b->B1->CurrentPanel = b->CurrentPanel;
  2876. b->B1->parent = b->B2->parent=b;
  2877. b->Panels.pFirst = 0;
  2878. b->Panels.pLast = 0;
  2879. b->CurrentPanel = 0;
  2880. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2881. }
  2882. void laCombineChildBlocks(laBlock *b){
  2883. laPanel *p; if(!b) return;
  2884. if (!b->B1->B1 && !b->B2->B1){
  2885. lstCombineLists(&b->Panels, &b->B1->Panels);
  2886. lstCombineLists(&b->Panels, &b->B2->Panels);
  2887. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2888. p->Block = b;
  2889. }
  2890. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2891. memFree(b->B1);
  2892. memFree(b->B2);
  2893. b->B1 = 0;
  2894. b->B2 = 0;
  2895. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2896. }elif(!b->B1->B1){
  2897. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2898. b->Vertical = b->B2->Vertical;
  2899. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2900. p->Block = b1;
  2901. }
  2902. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2903. memFree(b->B1); memFree(b->B2);
  2904. b->B1 = b1; b->B2 = b2;
  2905. b1->parent = b; b2->parent = b;
  2906. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2907. }elif(!b->B2->B1){
  2908. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2909. b->Vertical = b->B1->Vertical;
  2910. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2911. p->Block = b1;
  2912. }
  2913. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2914. memFree(b->B1); memFree(b->B2);
  2915. b->B1 = b1; b->B2 = b2;
  2916. b1->parent = b; b2->parent = b;
  2917. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2918. }
  2919. }
  2920. laBlock *laBlock1(laBlock *b){
  2921. return b->B1;
  2922. }
  2923. laBlock *laBlock2(laBlock *b){
  2924. return b->B2;
  2925. }
  2926. laBlock *laSwapSubBlocks(laBlock *b){
  2927. laBlock *tB;
  2928. tB = b->B2;
  2929. b->B2 = b->B1;
  2930. b->B1 = tB;
  2931. b->SplitRatio = 1 - b->SplitRatio;
  2932. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2933. }
  2934. void laDestroyBlocksRecursive(laBlock *Root){
  2935. laPanel *p;
  2936. if (Root->B1){
  2937. laDestroyBlocksRecursive(Root->B1);
  2938. laDestroyBlocksRecursive(Root->B2);
  2939. }else{
  2940. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2941. }
  2942. memFree(Root);
  2943. }
  2944. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2945. if(!b->CurrentPanel ) return 0;
  2946. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2947. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2948. lstRemoveItem(&b->Panels, p);
  2949. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  2950. if(!p->TitleBar.UiItems.pFirst){
  2951. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2952. }
  2953. p->Mode = LA_PANEL_FLOATING_TOP;
  2954. p->TY-=LA_RH; p->TH+=LA_RH;
  2955. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  2956. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  2957. p->Block = 0;
  2958. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  2959. laRecalcPanel(p);
  2960. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2961. p->BT = &_LA_THEME_FLOATING_PANEL;
  2962. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2963. laNotifyUsers("la.windows.panels");
  2964. return b->CurrentPanel;
  2965. }
  2966. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2967. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2968. lstRemoveItem(&from->Panels, p);
  2969. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2970. p->Mode = LA_PANEL_NORMAL;
  2971. p->Block=b;
  2972. b->CurrentPanel = p;
  2973. lstPushItem(&b->Panels, p);
  2974. laRecalcPanel(p);
  2975. p->BT = &_LA_THEME_PANEL;
  2976. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2977. tnsFlush();
  2978. laNotifyUsers("la.windows.panels");
  2979. }
  2980. void laPopPanel(laPanel *p){
  2981. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2982. lstRemoveItem(&p->Parent->SubPanels, p);
  2983. lstPushItem(&p->Parent->SubPanels, p);
  2984. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2985. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2986. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2987. laNotifyUsers("la.windows.panels");
  2988. }
  2989. }
  2990. void la_EnsurePanelExtras(laPanel *p){
  2991. laUiTemplate* uit=p->PanelTemplate;
  2992. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  2993. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  2994. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  2995. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  2996. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  2997. p->PropLinkFakeProp->Base.Offset = 0;
  2998. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  2999. p->PropLinkPP.EndInstance = p;
  3000. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3001. p->PropLinkPP.LastPs->Type = U'.';
  3002. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3003. }
  3004. laPanel* la_GivePanelNode(){
  3005. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3006. return memAcquire(sizeof(laPanel));
  3007. }
  3008. void la_ReturnPanelNode(laPanel* p){
  3009. memset(p,0,sizeof(laPanel));
  3010. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3011. lstAppendItem(&MAIN.WastedPanels, p);
  3012. }
  3013. 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){
  3014. laPanel *p = la_GivePanelNode();
  3015. int CW = MAIN.CurrentWindow->CW;
  3016. int CH = MAIN.CurrentWindow->CH;
  3017. p->PanelTemplate = uit;
  3018. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3019. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3020. if (!MaxW) MaxW = 10000;
  3021. if (!MaxH) MaxH = 10000;
  3022. if (W > MaxW) W = MaxW;
  3023. if (H > MaxH) H = MaxH;
  3024. if (W < MinW) W = MinW;
  3025. if (H < MinH) H = MinH;
  3026. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3027. p->X = p->TX = (X < 0 ? 0 : X);
  3028. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3029. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3030. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3031. p->MaxW = MaxW; p->MaxH = MaxH;
  3032. p->MinW = MinW; p->MinH = MinH;
  3033. p->SL = SnapL; p->ST = SnapT;
  3034. p->SR = SnapR; p->SB = SnapB;
  3035. if (p->SR) p->X = CW - p->W - p->SR;
  3036. if (p->SB) p->Y = CH - p->H - p->SB;
  3037. la_EnsurePanelSnapping(p, CW, CH);
  3038. p->Show = 1;
  3039. p->PP.EndInstance = p;
  3040. p->PP.LastPs = &p->FakePS;
  3041. p->PP.LastPs->p = _LA_PROP_PANEL;
  3042. p->PP.LastPs->UseInstance = p;
  3043. p->PP.LastPs->Type = U'.';
  3044. la_EnsurePanelExtras(p);
  3045. laRecalcPanel(p);
  3046. p->FrameDistinguish = 100; //greater than 1 is ok
  3047. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3048. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3049. return p;
  3050. }
  3051. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3052. if(!uit) return 0;
  3053. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3054. strSafeSet(&p->Title, uit->Title->Ptr);
  3055. p->PanelTemplate = uit;
  3056. p->Show = 1;
  3057. p->PP.EndInstance = p;
  3058. p->PP.LastPs = &p->FakePS;
  3059. p->PP.LastPs->p = _LA_PROP_PANEL;
  3060. p->PP.LastPs->UseInstance = p;
  3061. p->PP.LastPs->Type = U'.';
  3062. la_EnsurePanelExtras(p);
  3063. laRecalcPanel(p);
  3064. p->FrameDistinguish = 100; //greater than 1 is ok
  3065. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3066. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3067. p->Block = b; b->CurrentPanel = p;
  3068. if(uit->PropFunc){ uit->PropFunc(p); }
  3069. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3070. laNotifyUsers("la.windows.panels");
  3071. return p;
  3072. }
  3073. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3074. laUiTemplate* uit=laFindUiTemplate(template_id);
  3075. return laCreatePanelT(b, uit);
  3076. }
  3077. 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){
  3078. laUiTemplate* uit=0;
  3079. if(template_id) uit=laFindUiTemplate(template_id);
  3080. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3081. p->Mode = LA_PANEL_FLOATING_TOP;
  3082. laPlacePanelForCreation(p);
  3083. if(uit){
  3084. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3085. }
  3086. if (w) lstPushItem(&w->Panels, p);
  3087. return p;
  3088. }
  3089. void laShowPanel(laPanel *p){
  3090. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3091. }
  3092. void laShowPanelWithDropDownEffect(laPanel *p){
  3093. laShowPanel(p);
  3094. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3095. p->AnimationRatio = 0;
  3096. }
  3097. void laShowPanelWithExpandEffect(laPanel *p){
  3098. laShowPanel(p);
  3099. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3100. p->AnimationRatio = 0;
  3101. }
  3102. void laHidePanel(laPanel *p){
  3103. if (!p->Mode) return;
  3104. p->Show = 0;
  3105. laNotifyUsers("la.windows.panels_hidden");
  3106. }
  3107. void laHidePanelWithDissoveEffect(laPanel *p){
  3108. if (!p->Mode) return;
  3109. laHidePanel(p);
  3110. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3111. p->AnimationRatio = 1;
  3112. }
  3113. void laHidePanelWithCollapseEffect(laPanel *p){
  3114. if (!p->Mode) return;
  3115. laHidePanel(p);
  3116. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3117. p->AnimationRatio = 1;
  3118. }
  3119. void laHidePanelWithMinimizeEffect(laPanel *p){
  3120. if (!p->Mode) return;
  3121. laHidePanel(p);
  3122. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3123. p->AnimationRatio = 1;
  3124. }
  3125. void laActivatePanel(char* TemplateID, int x, int y){
  3126. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3127. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3128. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3129. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3130. }
  3131. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3132. p->UI.PanX += DeltaX;
  3133. p->UI.PanY += DeltaY;
  3134. }
  3135. int laPanUiListFree(laUiList *uil, int X, int Y){
  3136. uil->PanX+=X; uil->PanY+=Y;
  3137. }
  3138. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3139. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3140. if(Y){X+=Y;Y=0;}
  3141. }
  3142. if (Y > 0){
  3143. if (uil->B - uil->PanY <= B) return 0;
  3144. else{
  3145. uil->PanY += Y;
  3146. if (uil->B - uil->PanY <= B){
  3147. uil->PanY = uil->B - B;
  3148. return 1;
  3149. }
  3150. }
  3151. }
  3152. if (Y < 0){
  3153. if (uil->U - uil->PanY >= U) return 0;
  3154. else{
  3155. uil->PanY += Y;
  3156. if (uil->U - uil->PanY >= U){
  3157. uil->PanY = uil->U - U;
  3158. return 1;
  3159. }
  3160. }
  3161. }
  3162. if(uil->AllowScale){
  3163. laPanUiListFree(uil, X, 0);
  3164. }else{
  3165. if (X > 0){
  3166. if (uil->R - uil->PanX <= R) return 0;
  3167. else{
  3168. uil->PanX += X;
  3169. if (uil->R - uil->PanX <= R){
  3170. uil->PanX = uil->R - R;
  3171. return 1;
  3172. }
  3173. }
  3174. }
  3175. if (X < 0){
  3176. if (uil->L - uil->PanX >= L) return 0;
  3177. else{
  3178. uil->PanX += X;
  3179. if (uil->L - uil->PanX >= L){
  3180. uil->PanX = uil->L - L;
  3181. return 1;
  3182. }
  3183. }
  3184. }
  3185. }
  3186. return 1;
  3187. }
  3188. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3189. int ret=1;
  3190. if(!uil->AllowScale){ return 0; }
  3191. real NewScale=uil->Scale*factor;
  3192. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3193. if(NewScale>5) {NewScale=5; ret=0;}
  3194. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3195. factor=NewScale/uil->Scale;
  3196. uil->Scale=NewScale;
  3197. real mx=(L+R)/2,my=(U+B)/2;
  3198. real dx= (mx+uil->PanX)*factor;
  3199. real dy= (my+uil->PanY)*factor;
  3200. uil->PanX=dx-mx;
  3201. uil->PanY=dy-my;
  3202. MAIN.CurrentPanel->FrameDistinguish=100;
  3203. return ret;
  3204. }
  3205. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3206. if(uil->AllowScale) return 0;
  3207. return laPanUiList(uil,X,Y,L,R,U,B);
  3208. }
  3209. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3210. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3211. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3212. strSafeSet(&p->Title, Title);
  3213. if (Define){
  3214. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3215. }
  3216. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3217. p->BT= &_LA_THEME_FLOATING_PANEL;
  3218. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3219. p->BoundUi = 1;
  3220. return p;
  3221. }
  3222. 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,
  3223. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3224. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3225. strSafeSet(&p->Title, Title);
  3226. if (Define){
  3227. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3228. }
  3229. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3230. p->BT= &_LA_THEME_FLOATING_PANEL;
  3231. p->Mode = LA_PANEL_FLOATING_TOP;
  3232. p->BoundUi = 1;
  3233. return p;
  3234. }
  3235. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3236. laPanel *ip;
  3237. tnsDelete2DOffscreen(p->OffScr);
  3238. p->OffScr = 0;
  3239. strSafeDestroy(&p->Title);
  3240. if (!p->AnimationMode){
  3241. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3242. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3243. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3244. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3245. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3246. }else if (p->Block){
  3247. lstRemoveItem(&p->Block->Panels, p);
  3248. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3249. }
  3250. laNotifyUsers("la.windows.panels");
  3251. }
  3252. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3253. //lstRemoveItem(&p->SubPanels, ip);
  3254. laDestroySinglePanel(ip, immediate);
  3255. laNotifyUsers("la.windows.panels");
  3256. }
  3257. la_ClearDetachedProp(p);
  3258. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3259. la_ReturnPanelNode(p);
  3260. }
  3261. void laDestroySinglePanel(laPanel *p, int immediate){
  3262. la_SetPropMathcerContext(p);
  3263. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3264. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3265. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3266. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3267. }
  3268. }
  3269. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3270. la_DestroyUiList(&p->UI, 1, 1, 0);
  3271. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3272. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3273. if (p->Mode){
  3274. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3275. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3276. }
  3277. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3278. if (la_UiStillInService(p)){
  3279. la_StopUiOperatorService(p);
  3280. }
  3281. if ((!p->AnimationMode) || immediate){
  3282. laDeferredDestroyPanel(p, immediate);
  3283. }else{
  3284. p->LaterDestroy = 1;
  3285. }
  3286. }
  3287. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3288. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3289. int MinW,MinWt=0;
  3290. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3291. int CW = MAIN.CurrentWindow->CW;
  3292. if(p->SL && p->SR){return 0;}
  3293. la_SetPropMathcerContext(p);
  3294. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3295. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3296. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3297. MinW = la_TestUiListMinumWidth(uil);
  3298. if (MinW<MinWt){MinW=MinWt;}
  3299. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3300. if (MinW > 20){
  3301. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3302. }
  3303. la_PanelValidateWidth(p,uil);
  3304. laEnsurePanelInBound(p,uil);
  3305. if(p->TW>CW){ p->TW=CW; }
  3306. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3307. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3308. laRedrawPanel(p);
  3309. return 1;
  3310. }
  3311. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3312. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3313. laOperator *ai = a;
  3314. laPanel *p;
  3315. int GX, GY, GW, t = 0;
  3316. int b;
  3317. laUiDefineFunc def = ReplaceUiDefine;
  3318. int MinW;
  3319. if (!def){ def=laui_DefaultPropDetails; }
  3320. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3321. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3322. laEnclosePanelContent(p, &p->UI);
  3323. laSetOperatorLocalizer(p);
  3324. p->CloseWhenMovedOut=1;
  3325. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3326. //laShowPanelWithDropDownEffect(p);
  3327. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3328. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3329. return p;
  3330. }
  3331. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3332. laPanel *p;
  3333. int GX, GY, GW, t = 0;
  3334. int b;
  3335. laUiDefineFunc def = ReplaceUiDefine;
  3336. int MinW;
  3337. if (!def) return 0;
  3338. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3339. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3340. p->Mode = LA_PANEL_FLOATING_TOP;
  3341. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3342. laEnclosePanelContent(p, &p->UI);
  3343. if(MAIN.CurrentWindow->Operators.pFirst){
  3344. laSetOperatorLocalizer(MAIN.PendingSplash);
  3345. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3346. MAIN.PendingSplash=0;
  3347. }
  3348. //laShowPanelWithExpandEffect(p);
  3349. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3350. return p;
  3351. }
  3352. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3353. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3354. laOperator *ai = a;
  3355. laPanel *p; laPropContainer* sub;
  3356. int GX, GY, GW, t = 0;
  3357. int b;
  3358. laUiDefineFunc def = ReplaceUiDefine;
  3359. int MinW;
  3360. if (!def){
  3361. if (This && This->LastPs->p){
  3362. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3363. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3364. }
  3365. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3366. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3367. }
  3368. GX = L; GY = B;
  3369. GW = (R - L) > MaxW ? MaxW : (R - L);
  3370. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3371. laEnclosePanelContent(p, &p->UI);
  3372. laSetOperatorLocalizer(p);
  3373. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3374. laShowPanelWithDropDownEffect(p);
  3375. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3376. if(Attachment){
  3377. p->Parent = Attachment;
  3378. lstAppendItem(&Attachment->SubPanels, p);
  3379. }
  3380. return p;
  3381. }
  3382. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3383. laPanel *p;
  3384. int t = 0;
  3385. int b;
  3386. //laLocalToWindow(0, Attachment, &L, &t);
  3387. //laLocalToWindow(0, Attachment, &R, &U);
  3388. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3389. laSetOperatorLocalizer(p);
  3390. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3391. laShowPanelWithDropDownEffect(p);
  3392. p->Parent = Attachment;
  3393. lstPushItem(&Attachment->SubPanels, p);
  3394. return p;
  3395. }
  3396. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3397. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3398. laOperator *ai = a;
  3399. laPanel *p;
  3400. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3401. int GX, GY, GW, t = 0;
  3402. int b;
  3403. int MinW;
  3404. //laLocalToWindow(0,Attachment, &L, &t);
  3405. //laLocalToWindow(0,Attachment, &R, &B);
  3406. GX = L;
  3407. GY = B;
  3408. GW = (R - L) > MaxW ? MaxW : (R - L);
  3409. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3410. p->MenuRefer = MenuRefer;
  3411. laEnclosePanelContent(p, MenuRefer);
  3412. laSetOperatorLocalizer(p);
  3413. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3414. laShowPanelWithDropDownEffect(p);
  3415. p->Parent = Attachment;
  3416. lstPushItem(&Attachment->SubPanels, p);
  3417. return p;
  3418. }
  3419. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3420. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3421. laOperator *ai = a;
  3422. laPanel *p;
  3423. int GX, GY, GW, t = 0;
  3424. int b;
  3425. GX = L;
  3426. GY = B;
  3427. GW = MaxW;
  3428. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3429. p->MenuRefer = &p->UI;
  3430. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3431. laSetOperatorLocalizer(p);
  3432. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3433. laShowPanelWithDropDownEffect(p);
  3434. if (Attachment){
  3435. p->Parent = Attachment;
  3436. lstPushItem(&Attachment->SubPanels, p);
  3437. }else{
  3438. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3439. }
  3440. return p;
  3441. }
  3442. 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){
  3443. laOperator *ai = For;
  3444. laPanel *p;
  3445. int b;
  3446. laUiDefineFunc def = 0;
  3447. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3448. else def = laui_DefaultPropUiDefine;
  3449. For->PP.EndInstance = For->CustomData;
  3450. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3451. laEnclosePanelContent(p, &p->UI);
  3452. MAIN.ToPanel = p;
  3453. laShowPanelWithExpandEffect(p);
  3454. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3455. ai->OperatorPanel = p;
  3456. p->ParentOperator = For;
  3457. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3458. return p;
  3459. }
  3460. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3461. laPanel *p; int b; laUiList *uil; laColumn* col;
  3462. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3463. strSafeSet(&p->Title, Title);
  3464. p->BoundUi = 1;
  3465. p->Mode = LA_PANEL_FLOATING_TOP;
  3466. p->BT = &_LA_THEME_FLOATING_PANEL;
  3467. MAIN.ToPanel = p;
  3468. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3469. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3470. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3471. laUiItem* r=laBeginRow(uil,col,0,0);
  3472. laShowSeparator(uil,col)->Expand=1;
  3473. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3474. laEndRow(uil,r);
  3475. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3476. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3477. laSetOperatorLocalizer(p);
  3478. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3479. return p;
  3480. }
  3481. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3482. laPanel *p; int b; laUiList *uil; laColumn* col;
  3483. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3484. strSafeSet(&p->Title, Title);
  3485. p->BoundUi = 1;
  3486. p->Mode = LA_PANEL_FLOATING_TOP;
  3487. p->BT = &_LA_THEME_FLOATING_PANEL;
  3488. MAIN.ToPanel = p;
  3489. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3490. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3491. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3492. laUiItem* r = laBeginRow(uil,col,0,0);
  3493. laShowSeparator(uil,col)->Expand=1;
  3494. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3495. laEndRow(uil, r);
  3496. laEnclosePanelContent(p,uil);
  3497. laShowPanelWithExpandEffect(p);
  3498. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3499. laSetOperatorLocalizer(p);
  3500. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3501. return p;
  3502. }
  3503. void laOperatorModalOver(laOperator* For){
  3504. For->ModalOver = 1;
  3505. }
  3506. void laDeferredRedraw(laPanel* p){
  3507. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3508. if(lip->p==p) return;
  3509. }
  3510. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3511. }
  3512. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3513. laWindow* cur=MAIN.CurrentWindow;
  3514. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3515. MAIN.CurrentWindow=w;
  3516. la_UpdateUiPlacement(w);
  3517. }
  3518. MAIN.CurrentWindow=cur;
  3519. }
  3520. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3521. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3522. }
  3523. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3524. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3525. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3526. void laRedrawCurrentPanel(){
  3527. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3528. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3529. }
  3530. void laRecalcCurrentPanel(){
  3531. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3532. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3533. }
  3534. void laRecalcPanelImmediate(laPanel* p){
  3535. p->FrameDistinguish++;
  3536. laBoxedTheme* bt = (*p->BT);
  3537. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3538. la_PanelRefreshDetachedProp(p);
  3539. int enclosed=0;
  3540. if(p->BoundUi || p->MenuRefer){
  3541. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3542. else enclosed=laEnclosePanelContent(p, &p->UI);
  3543. }
  3544. if(!enclosed){
  3545. la_PanelValidateWidth(p,&p->UI);
  3546. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3547. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3548. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3549. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3550. }
  3551. laWindow* w=MAIN.CurrentWindow;
  3552. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3553. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3554. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3555. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3556. }
  3557. }
  3558. void laRecalcCurrentPanelImmediate(){
  3559. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3560. }
  3561. int laNonFixedPanelExists(laPanel *p){
  3562. laPanel *ip;
  3563. if (!p) return 0;
  3564. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3565. // if (ip == p) return 1;
  3566. //}
  3567. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3568. if (ip == p) return 1;
  3569. }
  3570. return 0;
  3571. }
  3572. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3573. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3574. return 1;
  3575. }
  3576. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3577. int tt=MAIN.TooltipCloseDistance;
  3578. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3579. return 1;
  3580. }
  3581. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3582. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3583. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3584. return 0;
  3585. return 1;
  3586. }
  3587. void laUnlinkSharedPanel(laPanel *p){
  3588. laWindow *w;
  3589. laPanel *ip;
  3590. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3591. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3592. if (ip == p){
  3593. lstRemoveItem(&w->Panels, ip);
  3594. return;
  3595. }
  3596. }
  3597. }
  3598. }
  3599. int laIsPanelCovered(laPanel *p){
  3600. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3601. laPanel *ip;
  3602. laPanel *resp;
  3603. int in1 = 0, in2 = 0, in3 = 0;
  3604. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3605. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3606. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3607. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3608. //}
  3609. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3610. if (ip == p){
  3611. in3 = 1;
  3612. d3 = 0;
  3613. continue;
  3614. }
  3615. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3616. }
  3617. if (!in2 && !in3) in1 = 1;
  3618. if (in1){
  3619. if (d1 || d2 || d3) return 1;
  3620. }else{
  3621. if (in2){
  3622. if (d2 || d3) return 1;
  3623. }else if (in3)
  3624. if (d3) return 1;
  3625. }
  3626. return 0;
  3627. }
  3628. int laIsTopPanel(laPanel *p){
  3629. //if (!p->Item.pPrev) return 1;
  3630. //else {
  3631. if (!laIsPanelCovered(p)){
  3632. //laPopPanel(p);
  3633. return 1;
  3634. }
  3635. return 0;
  3636. //}
  3637. return 0;
  3638. }
  3639. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3640. if(!p) return;
  3641. int ix = *x, iy = *y;
  3642. laListItemPointer *lip;
  3643. laOperator *ai = a;
  3644. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3645. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3646. if (a){
  3647. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3648. laUiList *uil = lip->p;
  3649. (*x) += uil->PanX;
  3650. (*y) += uil->PanY;
  3651. }
  3652. }
  3653. }
  3654. void laPanelToLocal(laOperator *a, int *x, int *y){
  3655. int ix = *x, iy = *y;
  3656. laListItemPointer *lip;
  3657. if (a){
  3658. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3659. laUiList *uil = lip->p;
  3660. (*x) += uil->PanX;
  3661. (*y) += uil->PanY;
  3662. }
  3663. }
  3664. }
  3665. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3666. if(!p) return;
  3667. int ix = *x, iy = *y;
  3668. laListItemPointer *lip;
  3669. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3670. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3671. if (a){
  3672. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3673. laUiList *uil = lip->p;
  3674. (*x) -= uil->PanX;
  3675. (*y) -= uil->PanY;
  3676. }
  3677. }
  3678. }
  3679. void laPanelToWindow(laPanel *p, int *x, int *y){
  3680. int ix = *x, iy = *y;
  3681. laListItemPointer *lip;
  3682. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3683. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3684. }
  3685. void laLocalToPanel(laOperator *a, int *x, int *y){
  3686. int ix = *x, iy = *y;
  3687. laListItemPointer *lip;
  3688. if (a){
  3689. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3690. laUiList *uil = lip->p;
  3691. (*x) -= uil->PanX;
  3692. (*y) -= uil->PanY;
  3693. }
  3694. }
  3695. }
  3696. void laSetNextMenuPos(int X, int Y, int W, int H){
  3697. MAIN.NextX = X;
  3698. MAIN.NextY = Y;
  3699. MAIN.NextW = W;
  3700. MAIN.NextH = H;
  3701. }
  3702. int laIsInBlock(laBlock *b, int X, int Y){
  3703. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3704. return 0;
  3705. }
  3706. 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; }
  3707. 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; }
  3708. 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; }
  3709. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3710. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3711. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3712. if (!b->B1 && !b->B2){
  3713. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3714. }
  3715. }
  3716. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3717. laPanel *p;
  3718. laBlock *sb = 0;
  3719. if (!laIsInBlock(b, X, Y)) return 0;
  3720. if (!b->B1 && !b->B2) return b;
  3721. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3722. return laDetectBlockRecursive(b->B2, X, Y);
  3723. }
  3724. laPanel *laDetectPanel(int X, int Y){
  3725. laPanel *p; laBlock *b;
  3726. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3727. int x = X, y = Y;
  3728. laWindowToLocal(0, p, &x, &y);
  3729. if (p->Show && laIsInPanel(p, x, y)){
  3730. return p;
  3731. }
  3732. }
  3733. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3734. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3735. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3736. return 0;
  3737. }
  3738. laUiList *laPrepareUi(laPanel *p){
  3739. return &p->UI;
  3740. }
  3741. laColumn *laFirstColumn(laUiList *uil){
  3742. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3743. else{
  3744. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3745. c->SP = 1;
  3746. c->PreWidth = 1;
  3747. lstAppendItem(&uil->Columns, c);
  3748. c->Top = c;
  3749. return uil->Columns.pFirst;
  3750. }
  3751. }
  3752. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3753. laColumn *lc, *rc;
  3754. if (c->LS || c->RS) return c;
  3755. lc = memAcquireSimple(sizeof(laColumn));
  3756. rc = memAcquireSimple(sizeof(laColumn));
  3757. c->LS = lc;
  3758. c->RS = rc;
  3759. c->LS->SP = Percent;
  3760. c->RS->SP = Percent;
  3761. c->LS->Top = c->Top;
  3762. c->RS->Top = c->Top;
  3763. if (uil){
  3764. lstAppendItem(&uil->Columns, lc);
  3765. lstAppendItem(&uil->Columns, rc);
  3766. }
  3767. if (c->LS && c->RS->MaxW == 0){
  3768. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3769. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3770. }else if (c->RS && c->LS->MaxW == 0){
  3771. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3772. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3773. }
  3774. return c;
  3775. }
  3776. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3777. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3778. return c->LS;
  3779. }
  3780. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3781. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3782. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3783. return c->RS;
  3784. }
  3785. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3786. lstRemoveItem(List, c);
  3787. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3788. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3789. memFree(c);
  3790. }
  3791. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3792. laUiList *uil = TopUil;
  3793. laUiList *sub;
  3794. laUiItem *ui;
  3795. laColumn *cc, *NextCC = 0;
  3796. int Occupied = 0;
  3797. int Removed = 0;
  3798. if (!c->LS) return 0;
  3799. else{
  3800. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3801. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3802. }
  3803. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3804. if (ui->C == c->LS || ui->C == c->RS){
  3805. if (DoMerge){
  3806. ui->C = c;
  3807. Occupied = 1;
  3808. }else
  3809. return 1;
  3810. }
  3811. if (ui->Subs.pFirst){
  3812. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3813. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3814. }
  3815. }
  3816. }
  3817. if (!Removed){
  3818. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3819. if (cc == c){
  3820. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3821. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3822. c->LS = 0;
  3823. c->RS = 0;
  3824. Removed = 1;
  3825. break;
  3826. }
  3827. }
  3828. }
  3829. return Occupied;
  3830. }
  3831. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3832. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3833. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3834. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3835. ut->FakeProp->Base.Identifier = ut->Identifier;
  3836. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3837. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3838. ut->FakeProp->Base.OffsetIsPointer = 1;
  3839. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3840. return ut->ExtraProps;
  3841. }
  3842. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3843. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3844. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3845. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3846. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3847. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3848. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3849. ct->FakeProp->Base.OffsetIsPointer = 1;
  3850. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3851. return ct->ExtraProps;
  3852. }
  3853. void la_DestroyUiType(laUiType* uit){
  3854. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3855. memFree(uit);
  3856. }
  3857. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3858. laUiType *ut = memAcquire(sizeof(laUiType));
  3859. ut->Identifier = Identifer;
  3860. ut->OperatorID = UseOperator;
  3861. ut->Draw = Draw;
  3862. ut->Theme = bt;
  3863. ut->ForType = ForType;
  3864. ut->OperatorType = laGetOperatorType(UseOperator);
  3865. ut->GetHeight = GetHeight;
  3866. ut->Init = Init;
  3867. ut->Destroy = Destroy;
  3868. la_UDFAppendSharedTypePointer(Identifer, ut);
  3869. lstAppendItem(&MAIN.UiTypes, ut);
  3870. return ut;
  3871. }
  3872. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3873. laUiType *ut = MAIN.UiTypes.pFirst;
  3874. if (!P) return 0;
  3875. if (P->DefaultUiType) return P->DefaultUiType;
  3876. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3877. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3878. for (ut; ut; ut = ut->Item.pNext){
  3879. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3880. return ut;
  3881. }
  3882. }
  3883. return 0;
  3884. }
  3885. laUiType *la_GetUiButtonType(){
  3886. laUiType *ut = MAIN.UiTypes.pFirst;
  3887. for (ut; ut; ut = ut->Item.pNext){
  3888. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3889. }
  3890. return 0;
  3891. }
  3892. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3893. laCanvasTemplate *vdt;
  3894. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3895. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3896. }
  3897. return 0;
  3898. }
  3899. void la_AssignPropExtras(laUiItem* ui){
  3900. if(!ui->Type || !ui->Type->FakeProp) return;
  3901. ui->FakePs.p = ui->Type->FakeProp;
  3902. ui->FakePs.Type = U'.';
  3903. ui->FakePs.UseInstance = ui;
  3904. ui->ExtraPP.LastPs = &ui->FakePs;
  3905. }
  3906. void la_AssignCanvasPropExtras(laUiItem* ui){
  3907. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3908. laCanvasTemplate*ct=ui->CanvasTemplate;
  3909. ui->FakePs.p = ct->FakeProp;
  3910. ui->FakePs.Type = U'.';
  3911. ui->FakePs.UseInstance = ui;
  3912. ui->ExtraPP.EndInstance = ui->Extra;
  3913. ui->ExtraPP.LastPs = &ui->FakePs;
  3914. }
  3915. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3916. int result;
  3917. if (!ui) return 0;
  3918. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3919. if (Path){
  3920. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3921. if (!result){
  3922. ui->AT = laGetOperatorType(Path);
  3923. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3924. ui->Type = la_GetUiButtonType();
  3925. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3926. }else{
  3927. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3928. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3929. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3930. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3931. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3932. }
  3933. if (Base){
  3934. ui->PP.RawThis = Base;
  3935. }
  3936. }else if (Base){
  3937. ui->PP.LastPs = Base->LastPs;
  3938. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3939. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3940. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3941. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3942. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3943. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3944. }
  3945. la_AssignPropExtras(ui);
  3946. if(Widget){ ui->Flags|= Widget->Flags; }
  3947. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3948. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3949. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3950. return ui;
  3951. }
  3952. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3953. ui->Type = _LA_UI_LABEL;
  3954. ui->Template = Template;
  3955. ui->State = LA_UI_NORMAL;
  3956. strSafeSet(&ui->Display, Content);
  3957. la_AssignPropExtras(ui);
  3958. return ui;
  3959. }
  3960. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3961. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3962. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3963. ui->State = LA_UI_NORMAL;
  3964. la_AssignPropExtras(ui);
  3965. return ui;
  3966. }
  3967. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3968. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3969. transLate(Content);
  3970. la_UpdateLabelDisplay(ui, Template, Content);
  3971. ui->C = c;
  3972. if (ui->Type->Init) ui->Type->Init(ui);
  3973. ui->ExtraPP.EndInstance = ui->Extra;
  3974. lstAppendItem(&uil->UiItems, ui);
  3975. return ui;
  3976. }
  3977. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3978. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3979. la_UpdateLabelDisplay(ui, Template, Content);
  3980. ui->C = c;
  3981. if (ui->Type->Init) ui->Type->Init(ui);
  3982. ui->ExtraPP.EndInstance = ui->Extra;
  3983. lstAppendItem(&uil->UiItems, ui);
  3984. return ui;
  3985. }
  3986. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3987. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3988. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3989. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3990. ui->C = c;
  3991. if (ui->Type->Init) ui->Type->Init(ui);
  3992. ui->ExtraPP.EndInstance = ui->Extra;
  3993. lstAppendItem(&uil->UiItems, ui);
  3994. return ui;
  3995. }
  3996. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3997. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  3998. }
  3999. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4000. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4001. }
  4002. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4003. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4004. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4005. ui->C = c;
  4006. ui->TemplateContext = TemplateContext;
  4007. if (ui->Type->Init) ui->Type->Init(ui);
  4008. ui->ExtraPP.EndInstance = ui->Extra;
  4009. lstAppendItem(&uil->UiItems, ui);
  4010. return ui;
  4011. }
  4012. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4013. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4014. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4015. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4016. ui->SymbolID=Height;
  4017. lstAppendItem(&uil->UiItems, ui);
  4018. return ui;
  4019. }
  4020. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4021. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4022. }
  4023. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4024. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4025. }
  4026. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4027. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4028. ui->Type = _LA_UI_CANVAS;
  4029. ui->State = LA_UI_NORMAL;
  4030. ui->C = c;
  4031. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4032. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4033. else{
  4034. 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); }
  4035. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4036. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4037. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4038. }
  4039. if (ui->Type->Init) ui->Type->Init(ui);
  4040. la_AssignCanvasPropExtras(ui);
  4041. if (Height) ui->Expand=Height; else ui->Expand=6;
  4042. lstAppendItem(&uil->UiItems, ui);
  4043. return ui;
  4044. }
  4045. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4046. laUiItem* ui=0;
  4047. #define ADD_CANVAS \
  4048. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4049. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4050. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4051. }laEndCondition(uil,b3);\
  4052. laEndRow(uil,b);
  4053. if(Detached){
  4054. laColumn* cl,*cll,*clr,*cr;
  4055. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4056. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4057. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4058. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4059. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4060. ADD_CANVAS
  4061. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4062. }laElse(uil,b2);{
  4063. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4064. ADD_CANVAS
  4065. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4066. }laEndCondition(uil,b2);
  4067. }else{
  4068. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4069. }
  4070. #undef ADD_CANVAS
  4071. }
  4072. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4073. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4074. laCanvasExtra *e;
  4075. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4076. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4077. ui->C = c;
  4078. if (ui->Type->Init) ui->Type->Init(ui);
  4079. ui->ExtraPP.EndInstance = ui->Extra;
  4080. lstAppendItem(&uil->UiItems, ui);
  4081. return ui;
  4082. }
  4083. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4084. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4085. ui->Type = _LA_UI_SYMBOL;
  4086. ui->SymbolID = SymbolID;
  4087. if (Height) ui->State = Height;
  4088. ui->C = c;
  4089. if (ui->Type->Init) ui->Type->Init(ui);
  4090. ui->ExtraPP.EndInstance = ui->Extra;
  4091. lstAppendItem(&uil->UiItems, ui);
  4092. return ui;
  4093. }
  4094. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4095. laPropPack PP={0}; int result;
  4096. if (Path){
  4097. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4098. if (!result){ return 0; }
  4099. if (Base){ PP.RawThis = Base; }
  4100. }else if (Base){
  4101. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4102. }
  4103. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4104. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4105. lstAppendItem(&ui->CompoundPPs,CPP);
  4106. return &CPP->PP;
  4107. }
  4108. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4109. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4110. ui->Type = &_LA_UI_ROW_BEGIN;
  4111. ui->State=Expand;
  4112. ui->Flags=Even;
  4113. ui->C = c;
  4114. if (ui->Type->Init) ui->Type->Init(ui);
  4115. ui->ExtraPP.EndInstance = ui->Extra;
  4116. lstAppendItem(&uil->UiItems, ui);
  4117. return ui;
  4118. }
  4119. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4120. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4121. ui->Type = &_LA_UI_ROW_END;
  4122. ui->C = Begin->C;
  4123. ui->Page = (laUiList*)Begin;
  4124. if (ui->Type->Init) ui->Type->Init(ui);
  4125. ui->ExtraPP.EndInstance = ui->Extra;
  4126. lstAppendItem(&uil->UiItems, ui);
  4127. return ui;
  4128. }
  4129. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4130. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4131. e->Expression = Expression;
  4132. ui->Extra = e;
  4133. la_AssignPropExtras(ui);
  4134. }
  4135. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4136. laUiItem *ui = la_CreateGroupHandle(Widget);
  4137. laUiList *nuil;
  4138. ui->C = c;
  4139. lstAppendItem(&uil->UiItems, ui);
  4140. nuil = memAcquireSimple(sizeof(laUiList));
  4141. strSafeSet(&nuil->TabName, Name);
  4142. ui->Page = nuil;
  4143. lstAppendItem(&ui->Subs, nuil);
  4144. if (ui->Type->Init) ui->Type->Init(ui);
  4145. ui->ExtraPP.EndInstance = ui->Extra;
  4146. return ui;
  4147. }
  4148. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4149. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4150. laUiList *sub = SubUi->Page;
  4151. laColumn *s = laFirstColumn(sub);
  4152. SubUi->State = LA_UI_ACTIVE;
  4153. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4154. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4155. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4156. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4157. laShowSeparator(sub, s);
  4158. return SubUi;
  4159. }
  4160. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4161. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4162. laUiList *sub = SubUi->Page;
  4163. laColumn *s = laFirstColumn(sub);
  4164. SubUi->State = LA_UI_ACTIVE;
  4165. return SubUi;
  4166. }
  4167. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4168. laEndCondition(sub, sub->UiItems.pFirst);
  4169. }
  4170. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4171. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4172. laUiList *nuil;
  4173. ui->C = c;
  4174. lstAppendItem(&uil->UiItems, ui);
  4175. if (ui->Type->Init) ui->Type->Init(ui);
  4176. ui->ExtraPP.EndInstance = ui->Extra;
  4177. return ui;
  4178. }
  4179. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4180. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4181. if (!ui->Page) ui->Page = uil;
  4182. lstAppendItem(&ui->Subs, uil);
  4183. strSafeSet(&uil->TabName, Name);
  4184. laFirstColumn(uil);
  4185. //laFirstColumn(uil);
  4186. return uil;
  4187. }
  4188. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4189. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4190. /*if (!ui->Page) */ ui->Page = uil;
  4191. lstAppendItem(&ui->Subs, uil);
  4192. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4193. return uil;
  4194. }
  4195. laUiConditionNode *laTrue(){
  4196. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4197. ucn->Type = LA_CONDITION_TRUE;
  4198. return ucn;
  4199. }
  4200. laUiConditionNode *laFalse(){
  4201. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4202. ucn->Type = LA_CONDITION_FALSE;
  4203. return ucn;
  4204. }
  4205. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4206. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4207. ucn->Type = LA_CONDITION_PROP;
  4208. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4209. strSafeSet(&ucn->String, Prop);
  4210. return ucn;
  4211. }
  4212. laUiConditionNode *laIntExpression(int Value){
  4213. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4214. ucn->Type = LA_CONDITION_INT;
  4215. ucn->IntValue = Value;
  4216. return ucn;
  4217. }
  4218. laUiConditionNode *laFloatExpression(real Value){
  4219. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4220. ucn->Type = LA_CONDITION_FLOAT;
  4221. ucn->FloatValue = Value;
  4222. return ucn;
  4223. }
  4224. laUiConditionNode *laStringExpression(char *Content){
  4225. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4226. ucn->Type = LA_CONDITION_STRING;
  4227. strSafeSet(&ucn->String, Content);
  4228. return ucn;
  4229. }
  4230. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4231. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4232. ucn->Type = LA_CONDITION_AND;
  4233. ucn->Expression1 = Expression1;
  4234. ucn->Expression2 = Expression2;
  4235. return ucn;
  4236. }
  4237. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4238. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4239. ucn->Type = LA_CONDITION_OR;
  4240. ucn->Expression1 = Expression1;
  4241. ucn->Expression2 = Expression2;
  4242. return ucn;
  4243. }
  4244. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4245. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4246. ucn->Type = LA_CONDITION_NOT;
  4247. ucn->Expression1 = Expression1;
  4248. return ucn;
  4249. }
  4250. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4251. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4252. ucn->Type = LA_CONDITION_EQ;
  4253. ucn->Expression1 = Expression1;
  4254. ucn->Expression2 = Expression2;
  4255. return ucn;
  4256. }
  4257. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4258. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4259. ucn->Type = LA_CONDITION_GT;
  4260. ucn->Expression1 = Expression1;
  4261. ucn->Expression2 = Expression2;
  4262. return ucn;
  4263. }
  4264. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4265. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4266. ucn->Type = LA_CONDITION_LT;
  4267. ucn->Expression1 = Expression1;
  4268. ucn->Expression2 = Expression2;
  4269. return ucn;
  4270. }
  4271. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4272. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4273. ucn->Type = LA_CONDITION_GE;
  4274. ucn->Expression1 = Expression1;
  4275. ucn->Expression2 = Expression2;
  4276. return ucn;
  4277. }
  4278. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4279. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4280. ucn->Type = LA_CONDITION_LE;
  4281. ucn->Expression1 = Expression1;
  4282. ucn->Expression2 = Expression2;
  4283. return ucn;
  4284. }
  4285. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4286. if (Expression->Type != LA_CONDITION_INT) return 0;
  4287. return Expression->IntValue;
  4288. }
  4289. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4290. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4291. return Expression->FloatValue;
  4292. }
  4293. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4294. return Expression->String->Ptr;
  4295. }
  4296. 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){
  4297. switch (Mode1){
  4298. case LA_PROP_ENUM:
  4299. case LA_PROP_INT:
  4300. case LA_CONDITION_INT:
  4301. switch (Mode2){
  4302. case LA_PROP_ENUM:
  4303. case LA_PROP_INT:
  4304. case LA_CONDITION_INT:
  4305. switch (CompMode){
  4306. case LA_CONDITION_GE:
  4307. return (i1 >= i2);
  4308. case LA_CONDITION_GT:
  4309. return (i1 > i2);
  4310. case LA_CONDITION_EQ:
  4311. return (i1 == i2);
  4312. case LA_CONDITION_LT:
  4313. return (i1 < i2);
  4314. case LA_CONDITION_LE:
  4315. return (i1 <= i2);
  4316. }
  4317. case LA_PROP_FLOAT:
  4318. case LA_CONDITION_FLOAT:
  4319. switch (CompMode){
  4320. case LA_CONDITION_GE:
  4321. return ((real)i1 >= f2);
  4322. case LA_CONDITION_GT:
  4323. return ((real)i1 > f2);
  4324. case LA_CONDITION_EQ:
  4325. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4326. case LA_CONDITION_LT:
  4327. return ((real)i1 < f2);
  4328. case LA_CONDITION_LE:
  4329. return ((real)i1 <= f2);
  4330. }
  4331. case LA_PROP_SUB:
  4332. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4333. default:
  4334. return 0;
  4335. }
  4336. case LA_PROP_FLOAT:
  4337. case LA_CONDITION_FLOAT:
  4338. switch (Mode2){
  4339. case LA_PROP_INT:
  4340. case LA_PROP_ENUM:
  4341. case LA_CONDITION_INT:
  4342. switch (CompMode){
  4343. case LA_CONDITION_GE:
  4344. return (f1 >= (real)i2);
  4345. case LA_CONDITION_GT:
  4346. return (f1 > (real)i2);
  4347. case LA_CONDITION_EQ:
  4348. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4349. case LA_CONDITION_LT:
  4350. return (f1 < (real)i2);
  4351. case LA_CONDITION_LE:
  4352. return (f1 <= (real)i2);
  4353. }
  4354. case LA_PROP_FLOAT:
  4355. case LA_CONDITION_FLOAT:
  4356. switch (CompMode){
  4357. case LA_CONDITION_GE:
  4358. return (f1 >= f2);
  4359. case LA_CONDITION_GT:
  4360. return (f1 > f2);
  4361. case LA_CONDITION_EQ:
  4362. return (f1 == f2);
  4363. case LA_CONDITION_LT:
  4364. return (f1 < f2);
  4365. case LA_CONDITION_LE:
  4366. return (f1 <= f2);
  4367. }
  4368. default:
  4369. return 0;
  4370. }
  4371. case LA_PROP_STRING:
  4372. case LA_CONDITION_STRING:
  4373. switch (Mode2){
  4374. case LA_PROP_STRING:
  4375. case LA_CONDITION_STRING:
  4376. return strSame(s1, s2);
  4377. default:
  4378. return 0;
  4379. }
  4380. case LA_PROP_SUB:
  4381. switch (Mode2){
  4382. case LA_PROP_SUB:
  4383. return p1 == p2;
  4384. case LA_CONDITION_INT:
  4385. case LA_PROP_INT:
  4386. case LA_PROP_ENUM:
  4387. return (int)p1 == i2;
  4388. default:
  4389. return 0;
  4390. }
  4391. default:
  4392. switch (CompMode){
  4393. case LA_CONDITION_GE:
  4394. return (i1 >= i2);
  4395. case LA_CONDITION_GT:
  4396. return (i1 > i2);
  4397. case LA_CONDITION_EQ:
  4398. return (i1 == i2);
  4399. case LA_CONDITION_LT:
  4400. return (i1 < i2);
  4401. case LA_CONDITION_LE:
  4402. return (i1 <= i2);
  4403. }
  4404. }
  4405. }
  4406. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4407. void *Instance = 0;
  4408. int IValue1 = 0, IValue2 = 0;
  4409. real FValue1 = 0, FValue2 = 0;
  4410. void *Ptr1 = 0, *Ptr2 = 0;
  4411. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4412. int Result1, Result2;
  4413. laEnumItem *ei; laSubProp*sp;
  4414. if (!Expression) return 0;
  4415. Str1[0] = 0;
  4416. Str2[0] = 0;
  4417. laPropIterator pi = {0};
  4418. switch (Expression->Type){
  4419. case LA_CONDITION_PROP:
  4420. if (!Expression->PP.LastPs){
  4421. (*IResult) = 0;
  4422. return 0;
  4423. }
  4424. switch (Expression->PP.LastPs->p->PropertyType){
  4425. case LA_PROP_INT:
  4426. *IResult = laGetInt(&Expression->PP);
  4427. if (*IResult) return LA_CONDITION_INT;
  4428. else return 0;
  4429. case LA_PROP_FLOAT:
  4430. *FResult = laGetFloat(&Expression->PP);
  4431. if (*FResult) return 1;
  4432. else return 0;
  4433. break;
  4434. case LA_PROP_STRING:
  4435. laGetString(&Expression->PP, _StrResult, &StrResult);
  4436. if (StrResult[0]) return 1;
  4437. else return 0;
  4438. break;
  4439. case LA_PROP_ENUM:
  4440. ei = laGetEnum(&Expression->PP);
  4441. if (!ei) return 0;
  4442. /*if(ei) */ *IResult = ei->Index;
  4443. if (*IResult) return LA_CONDITION_INT;
  4444. else return 0;
  4445. break;
  4446. case LA_PROP_SUB:
  4447. sp=Expression->PP.LastPs->p;
  4448. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4449. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4450. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4451. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4452. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4453. }
  4454. }
  4455. *PtrResult = Instance;
  4456. if (Instance) return 1;
  4457. break;
  4458. default:
  4459. return 0;
  4460. }
  4461. break;
  4462. case LA_CONDITION_INT:
  4463. *IResult = Expression->IntValue;
  4464. if (*IResult) return 1;
  4465. else
  4466. return 0;
  4467. case LA_CONDITION_FLOAT:
  4468. *FResult = Expression->FloatValue;
  4469. if (*FResult) return 1;
  4470. else
  4471. return 0;
  4472. case LA_CONDITION_STRING:
  4473. if (Expression->String){
  4474. strCopyFull(StrResult, Expression->String->Ptr);
  4475. return 1;
  4476. }else
  4477. return 0;
  4478. case LA_CONDITION_TRUE:
  4479. if (*IResult) *IResult = 1;
  4480. return 1;
  4481. case LA_CONDITION_FALSE:
  4482. if (*IResult) *IResult = 0;
  4483. return 0;
  4484. default:
  4485. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4486. switch (Expression->Type){
  4487. case LA_CONDITION_AND:
  4488. if (Result1){
  4489. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4490. if (Result2) *IResult = 1;
  4491. return (Result2);
  4492. }else
  4493. return 0;
  4494. case LA_CONDITION_OR:
  4495. if (!Result1){
  4496. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4497. if (Result2) *IResult = 1;
  4498. return (Result2);
  4499. }else
  4500. return 1;
  4501. case LA_CONDITION_NOT:
  4502. return !Result1;
  4503. default:
  4504. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4505. return la_DoCompare(Expression->Type,
  4506. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4507. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4508. }
  4509. break;
  4510. }
  4511. return 0;
  4512. }
  4513. int la_DoSingleExpression(laUiConditionNode *Expression){
  4514. int a;
  4515. real b;
  4516. char c[128]={0};
  4517. void *p;
  4518. if (!Expression) return 1;
  4519. c[0] = 0;
  4520. return la_DoExpression(Expression, &a, &b, c, &p);
  4521. }
  4522. void la_StepExpression(laUiConditionNode *e){
  4523. if (!e) return;
  4524. switch (e->Type){
  4525. case LA_CONDITION_AND:
  4526. case LA_CONDITION_OR:
  4527. case LA_CONDITION_GE:
  4528. case LA_CONDITION_GT:
  4529. case LA_CONDITION_EQ:
  4530. case LA_CONDITION_LT:
  4531. case LA_CONDITION_LE:
  4532. la_StepExpression(e->Expression1);
  4533. la_StepExpression(e->Expression2);
  4534. break;
  4535. case LA_CONDITION_NOT:
  4536. la_StepExpression(e->Expression1);
  4537. break;
  4538. case LA_CONDITION_PROP:
  4539. la_StepPropPack(&e->PP);
  4540. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4541. la_UsePropPack(&e->PP, 1);
  4542. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4543. //}
  4544. break;
  4545. default:
  4546. break;
  4547. }
  4548. }
  4549. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4550. if (!ucn) return;
  4551. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4552. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4553. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4554. if (ucn->String) strSafeDestroy(&ucn->String);
  4555. if (ucn) memFree(ucn);
  4556. }
  4557. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4558. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4559. ui->C = c;
  4560. ui->Type = &_LA_UI_CONDITION;
  4561. la_ConditionerInit(ui, Expression);
  4562. lstAppendItem(&uil->UiItems, ui);
  4563. return ui;
  4564. }
  4565. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4566. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4567. laConditionUiExtraData *cued;
  4568. ui->Type = &_LA_UI_CONDITION_ELSE;
  4569. la_ConditionerInit(ui, 0);
  4570. cued = ui->Extra;
  4571. cued->EndUi = Beginner;
  4572. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4573. ui->C = Beginner->C;
  4574. lstAppendItem(&uil->UiItems, ui);
  4575. return ui;
  4576. }
  4577. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4578. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4579. laConditionUiExtraData *cued;
  4580. ui->Template = define;
  4581. ui->C = col;
  4582. ui->PP.RawThis = ExtraBase;
  4583. ui->Page = ExtraThis;
  4584. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4585. la_ConditionerInit(ui, 0);
  4586. cued = ui->Extra;
  4587. //cued->Remove = Remove;
  4588. ui->State = LA_UI_NORMAL;
  4589. lstAppendItem(&uil->UiItems, ui);
  4590. return ui;
  4591. }
  4592. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4593. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4594. laConditionUiExtraData *cued;
  4595. ui->Type = &_LA_UI_CONDITION_END;
  4596. la_ConditionerInit(ui, 0);
  4597. cued = ui->Extra;
  4598. cued->EndUi = Beginner;
  4599. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4600. ui->C = Beginner->C;
  4601. lstAppendItem(&uil->UiItems, ui);
  4602. return ui;
  4603. }
  4604. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4605. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4606. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4607. ui->Type = _LA_UI_MENU_ROOT;
  4608. strSafeSet(&ui->Display, Title);
  4609. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4610. ui->C = c;
  4611. lstAppendItem(&uil->UiItems, ui);
  4612. lstAppendItem(&ui->Subs, muil);
  4613. return muil;
  4614. }
  4615. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4616. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4617. ui->Type = _LA_UI_ALIGN;
  4618. ui->C = widest;
  4619. lstAppendItem(&uil->UiItems, ui);
  4620. return ui;
  4621. }
  4622. void laFixHeight(laUiList *uil, short Rows){
  4623. if (!uil) return;
  4624. uil->HeightCoeff = Rows;
  4625. }
  4626. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4627. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4628. if (!ExtraColumns) return;
  4629. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4630. }
  4631. laUiTemplate *laFindUiTemplate(char *Identifier){
  4632. laUiTemplate *uit;
  4633. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4634. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4635. }
  4636. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4637. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4638. }
  4639. return 0;
  4640. }
  4641. void la_DestroyUiTemplate(laUiTemplate* uit){
  4642. strSafeDestroy(&uit->Identifier);
  4643. strSafeDestroy(&uit->Title);
  4644. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4645. memFree(uit);
  4646. }
  4647. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4648. strSafeDestroy(&uit->Identifier);
  4649. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4650. memFree(uit);
  4651. }
  4652. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4653. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4654. strSafeSet(&uit->Identifier, Identifier);
  4655. strSafeSet(&uit->Title, Title);
  4656. strSafeSet(&uit->CategoryName, NewCategory);
  4657. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4658. uit->DefaultGLFormat=DefaultGLFormat;
  4659. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4660. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4661. la_UDFAppendSharedTypePointer(Identifier, uit);
  4662. return uit;
  4663. }
  4664. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4665. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4666. strSafeSet(&t->Identifier, Identifier);
  4667. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4668. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4669. lstAppendItem(&MAIN.View2DTemplates, t);
  4670. la_UDFAppendSharedTypePointer(Identifier, t);
  4671. return t;
  4672. }
  4673. void laFinalizeUiTemplates(){
  4674. laUiTemplate *uit;
  4675. laCanvasTemplate *u2d;
  4676. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4677. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4678. }
  4679. }
  4680. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4681. laPanel *p;
  4682. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4683. if (p->PanelTemplate==uit){
  4684. return p;
  4685. }
  4686. }
  4687. return 0;
  4688. }
  4689. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4690. laUiList *uil, *NextUil;
  4691. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4692. NextUil = uil->Item.pNext;
  4693. lstRemoveItem(&ui->Subs, uil);
  4694. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4695. }
  4696. la_StopUiOperatorService(ui);
  4697. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4698. strSafeDestroy(&ui->Display);
  4699. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4700. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4701. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4702. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4703. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4704. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4705. }
  4706. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4707. memFree(ui);
  4708. }
  4709. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4710. laUiItem *ui, *NextUi;
  4711. laColumn *col, *NextCol;
  4712. if (!uil) return;
  4713. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4714. NextUi = ui->Item.pNext;
  4715. if(OnlyRemoveUser && RemoveUsers){
  4716. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4717. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4718. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4719. continue;
  4720. }
  4721. lstRemoveItem(&uil->UiItems, ui);
  4722. la_DestroyUiItem(ui, RemoveUsers);
  4723. }
  4724. if(OnlyRemoveUser){ return; }
  4725. for (col = uil->Columns.pFirst; col; col = NextCol){
  4726. NextCol = col->Item.pNext;
  4727. lstRemoveItem(&uil->Columns, col);
  4728. memFree(col);
  4729. }
  4730. strSafeDestroy(&uil->TabName);
  4731. if (!NoFree) memFree(uil);
  4732. }
  4733. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4734. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4735. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4736. }
  4737. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4738. laUiItem *Next = after->Item.pNext;
  4739. laUiItem *Last = uil->UiItems.pLast;
  4740. after->Item.pNext = 0;
  4741. uil->UiItems.pLast = after;
  4742. Define(uil, Base, This, ExtraColums, 0);
  4743. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4744. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4745. if (Next != Last) uil->UiItems.pLast = Last;
  4746. }
  4747. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4748. // int i = 0;
  4749. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4750. // if (!ui->ExtraColums) return;
  4751. // for (i; ui->ExtraColums[i]; i++) {
  4752. // laColumn* c = ui->ExtraColums[i];
  4753. // c->B = B;
  4754. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4755. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4756. // }
  4757. //}
  4758. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4759. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4760. }
  4761. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4762. laColumn *c = ui->C;
  4763. laColumn *ic = lst->pFirst;
  4764. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4765. for (ic; ic; ic = ic->Item.pNext){
  4766. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4767. ic->B = ic->B < c->B ? c->B : ic->B;
  4768. }
  4769. }
  4770. ic = ui->C;
  4771. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4772. ;
  4773. for (ic; ic; ic = ic->Item.pNext){
  4774. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4775. ic->B = ic->B < c->B ? c->B : ic->B;
  4776. }
  4777. }
  4778. }
  4779. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4780. laColumn *c = ui->C;
  4781. laColumn *ic = lst->pFirst;
  4782. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4783. for (ic; ic; ic = ic->Item.pNext){
  4784. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4785. ic->B = ic->B < c->B ? c->B : ic->B;
  4786. }
  4787. }
  4788. ic = ui->C;
  4789. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4790. ;
  4791. for (ic; ic; ic = ic->Item.pNext){
  4792. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4793. ic->B = ic->B < c->B ? c->B : ic->B;
  4794. }
  4795. }
  4796. }
  4797. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4798. int rep;
  4799. int sp;
  4800. int rev;
  4801. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4802. if (!c) return 0;
  4803. sp = (c->SP * (R - L)) + L;
  4804. rev = sp;
  4805. /*if (U)*/ c->B = U;
  4806. if (LR == 1){
  4807. c->IL = L;
  4808. c->IR = sp;
  4809. if (repos){
  4810. c->IR = repos;
  4811. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4812. c->IR = c->IL + c->MaxW*LA_RH+M;
  4813. rev = c->IR;
  4814. }
  4815. }else if (LR == 2){
  4816. c->IL = sp;
  4817. c->IR = R;
  4818. if (repos){
  4819. c->IL = repos;
  4820. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4821. c->IL = c->IR - c->MaxW*LA_RH-M;
  4822. rev = c->IL;
  4823. }
  4824. }else if (LR == 0){
  4825. c->IL = L;
  4826. c->IR = R;
  4827. }
  4828. if (c->LS && c->RS->MaxW == 0){
  4829. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4830. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4831. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4832. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4833. }else if (c->RS && c->LS->MaxW == 0){
  4834. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4835. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4836. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4837. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4838. }
  4839. return rev;
  4840. }
  4841. STRUCTURE(laRowInfo){
  4842. int MaxW;
  4843. int MinW;
  4844. int UnitMinW;
  4845. int NonExpandW;
  4846. int TotalPadding;
  4847. int Expand, Even;
  4848. int ExpandAccum;
  4849. int CountElements;
  4850. int U,MaxB,L;
  4851. laListHandle Elements;
  4852. int LastNoHeight;
  4853. };
  4854. STRUCTURE(laRowNode){
  4855. laListItem Item;
  4856. laUiItem* ui;
  4857. int GotW, LP, RP, H;
  4858. int Expand;
  4859. int UseLast;
  4860. int WaitAnimation;
  4861. };
  4862. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4863. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4864. ri->UnitMinW=LA_RH;
  4865. ri->Expand=ui->State?1:0;
  4866. ri->Even=ui->Flags?1:0;
  4867. ri->U=ui->TU; ri->L=ui->TL;
  4868. ri->MaxB=ui->TU;
  4869. }
  4870. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  4871. laRowNode* rn=CreateNew(laRowNode);
  4872. rn->LP=bt->LP;rn->RP=bt->RP;
  4873. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4874. rn->ui=ui;
  4875. rn->H=H;
  4876. rn->Expand=ui->Expand;
  4877. rn->WaitAnimation=WaitAnimation;
  4878. lstAppendItem(&ri->Elements, rn);
  4879. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4880. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4881. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4882. ri->TotalPadding += (bt->LP+bt->RP);
  4883. ri->MinW+=ri->UnitMinW;
  4884. ri->NonExpandW+=rn->GotW;
  4885. ri->ExpandAccum+=ui->Expand;
  4886. ri->CountElements++;
  4887. if(ui->Expand){ri->Expand=1;}
  4888. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4889. }
  4890. int la_ShrinkableRowElements(laRowInfo* ri){
  4891. int count=0;
  4892. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4893. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4894. count++;
  4895. }
  4896. return count;
  4897. }
  4898. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4899. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  4900. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4901. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4902. if(Available<0){
  4903. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4904. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4905. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4906. }else{
  4907. if(!ri->Expand && Available>0){Available=0;}
  4908. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4909. }
  4910. if(!ShareCount) return 0;
  4911. int PerNode = Available/ShareCount;
  4912. int Remaining = Available-PerNode*ShareCount;
  4913. int L = ri->L; int i=0; laRowNode* rn;
  4914. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4915. laUiItem* ui=rn->ui;
  4916. int NodeAdd, Node=rn->GotW;
  4917. if(rn->UseLast){
  4918. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4919. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4920. continue;
  4921. }
  4922. if(Available>=0){
  4923. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4924. NodeAdd+=(i<Remaining?1:0);i++;
  4925. }else{
  4926. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4927. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4928. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4929. }else{ Node=ri->UnitMinW;
  4930. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4931. }
  4932. }
  4933. ui->TL = L + rn->LP;
  4934. ui->TR = ui->TL + Node+NodeAdd;
  4935. ui->TB = ui->TU + rn->H;
  4936. L=ui->TR+rn->RP;
  4937. if (!rn->WaitAnimation){
  4938. ui->L = ui->TL; ui->R = ui->TR;
  4939. ui->U = ui->TU; ui->B = ui->TB;
  4940. }
  4941. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4942. }
  4943. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  4944. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  4945. memset(ri, 0, sizeof(laRowInfo));
  4946. }
  4947. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4948. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4949. int sl,sr,su,sb;
  4950. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4951. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4952. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4953. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4954. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4955. if(pc==LA_PC_SOCKET_OUT){
  4956. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4957. }else{
  4958. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4959. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4960. }
  4961. }
  4962. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4963. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4964. }
  4965. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4966. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4967. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4968. laBoxedTheme *bt;
  4969. int Lowest = 0;
  4970. int HyperValue = 0;
  4971. int WaitAnimation;
  4972. int RowMode=0; laRowInfo ri={0};
  4973. laBoxedTheme* pt=*(ParentPanel->BT);
  4974. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4975. int MaxR=0;
  4976. if(!uil->Scale){uil->Scale=1;}
  4977. uil->SaveScale=MAIN.UiScale;
  4978. MAIN.UiScale*=uil->Scale;
  4979. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4980. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4981. WaitAnimation = 0;
  4982. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4983. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4984. for (ui = uil->UiItems.pFirst; ui;){
  4985. int SubB = 0;
  4986. int H;
  4987. WaitAnimation = 0;
  4988. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4989. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4990. //if (Fast && ui->C->B > B) {
  4991. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4992. // ui = ui->Item.pNext;
  4993. // continue;
  4994. //}
  4995. if (!ui->Instructions){
  4996. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4997. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4998. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4999. laOperatorProp *ap = ui->PP.LastPs->p;
  5000. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5001. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5002. }
  5003. }
  5004. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5005. la_UsePropPack(&ui->PP, 0);
  5006. if (ui->CompoundPPs.pFirst){
  5007. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5008. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5009. }
  5010. }
  5011. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5012. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5013. // 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);
  5014. //}
  5015. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5016. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5017. WaitAnimation = 1;
  5018. }
  5019. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5020. bt = (*ui->Type->Theme);
  5021. if (ui->Type == &_LA_UI_CONDITION){
  5022. laConditionUiExtraData *cued = ui->Extra;
  5023. la_StepExpression(cued->Expression);
  5024. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5025. if (!cued->IsTrue){
  5026. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5027. }else{
  5028. ui = ui->Item.pNext;
  5029. }
  5030. continue;
  5031. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5032. ui = ui->Item.pNext;
  5033. continue;
  5034. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5035. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5036. if (cued->IsTrue) ui = cued->EndUi;
  5037. else
  5038. ui = ui->Item.pNext;
  5039. continue;
  5040. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5041. laConditionUiExtraData *cued = ui->Extra;
  5042. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5043. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5044. if (!WaitAnimation){
  5045. ui->L = ui->TL; ui->R = ui->TR;
  5046. ui->U = ui->TU; ui->B = ui->TB;
  5047. }
  5048. if(!RowMode){
  5049. la_CalcUiItemInfluence(&uil->Columns, ui);
  5050. }else{
  5051. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5052. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5053. }
  5054. if (ui->State == LA_UI_NORMAL){
  5055. cued->IsTrue = 0;
  5056. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5057. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5058. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5059. }else{
  5060. cued->IsTrue = 1;
  5061. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5062. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5063. //}
  5064. ui = ui->Item.pNext;
  5065. }
  5066. continue;
  5067. }
  5068. if (ui->Type == _LA_UI_ALIGN){
  5069. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5070. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5071. if (ui->TB > Lowest) Lowest = ui->TB;
  5072. if (!WaitAnimation){
  5073. ui->L = ui->TL; ui->R = ui->TR;
  5074. ui->U = ui->TU; ui->B = ui->TB;
  5075. }
  5076. if(!RowMode){
  5077. la_CalcUiItemInfluence(&uil->Columns, ui);
  5078. }else{
  5079. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5080. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5081. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5082. }
  5083. ui = ui->Item.pNext; continue;
  5084. }
  5085. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5086. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5087. la_InitRowNode(&ri, ui, bt);
  5088. RowMode=1; ui=ui->Item.pNext; continue;
  5089. }
  5090. if (ui->Type == &_LA_UI_ROW_END){
  5091. la_CalculateRowExpand(&ri, ui);
  5092. la_CalcUiItemInfluence(&uil->Columns, ui);
  5093. RowMode=0; ui=ui->Item.pNext; continue;
  5094. }
  5095. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5096. int GB=0;
  5097. 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; }
  5098. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5099. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5100. if (H < 0){
  5101. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5102. else{ H=LA_RH; }
  5103. }
  5104. else H *= LA_RH;
  5105. ui->TB = ui->TU;
  5106. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5107. 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
  5108. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5109. if (ui->Type == _LA_UI_COLLECTION){
  5110. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5111. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5112. ui->PP.EndInstance = TInstance;
  5113. laUiList *iuil = ui->Subs.pFirst;
  5114. laUiList *puil = iuil;
  5115. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5116. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5117. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5118. int Begin = ui->TB;
  5119. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5120. int ElementB = ui->TU;
  5121. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5122. int MaxB = ElementB;
  5123. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5124. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5125. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5126. if (!ElementLimit) RowPriority = 0;
  5127. if (!TInstance){
  5128. while (iuil){
  5129. puil = iuil->Item.pNext;
  5130. la_DestroyTabPage(ui, iuil, 0);
  5131. iuil = puil;
  5132. }
  5133. }
  5134. while (TInstance){
  5135. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  5136. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5137. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5138. ui->PP.EndInstance = TInstance; continue;
  5139. }
  5140. if(CanGetTheme){
  5141. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5142. la_SwitchThemeQuick(t, OriginalTheme);
  5143. }
  5144. if(CanGetGap){
  5145. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5146. Gap=g*LA_RH;
  5147. }else Gap=0;
  5148. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5149. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5150. }else GotCategory=0;
  5151. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5152. if (RowPriority){
  5153. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5154. }
  5155. }
  5156. FirstIn=0;
  5157. if (ElementLimit){
  5158. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5159. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5160. }
  5161. while (iuil && iuil->Instance != TInstance){
  5162. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5163. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5164. }else{
  5165. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5166. }
  5167. iuil = puil;
  5168. }
  5169. if(!iuil){
  5170. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5171. }
  5172. if (!iuil){
  5173. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5174. la_CalcUiTopInfluence(&uil->Columns, ui);
  5175. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5176. SubB = la_UpdateUiListRecursive(ui->Page, Gap+Begin+(NoDecal?0:bt->TM), EL+(NoDecal?0:bt->LM), ER-(NoDecal?0:bt->RM), B, Fast, ParentPanel) +(NoDecal?0:bt->TM);
  5177. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5178. iuil = ui->Page->Item.pNext;
  5179. }else{
  5180. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5181. SubB = la_UpdateUiListRecursive(iuil, Gap+Begin+(NoDecal?0:bt->TM), EL+(NoDecal?0:bt->LM), ER-(NoDecal?0:bt->RM), B, Fast, ParentPanel) + (NoDecal?0:bt->TM);
  5182. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5183. la_CalcUiItemInfluence(&uil->Columns, ui);
  5184. iuil = iuil->Item.pNext;
  5185. }
  5186. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5187. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5188. ui->PP.EndInstance = TInstance;
  5189. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5190. if (RowPriority){
  5191. Col += 1;
  5192. if (Col >= ElementLimit){
  5193. Col = 0;
  5194. Row += 1;
  5195. Begin = ElementB + bt->TM;
  5196. }
  5197. }elif(Spread){
  5198. EL+=Spread*LA_RH;
  5199. ER+=Spread*LA_RH;
  5200. }else{
  5201. Row += 1;
  5202. Begin = ElementB + bt->TM;
  5203. if (ElementLimit && Row >= ElementLimit){
  5204. Row = 0;
  5205. Col += 1;
  5206. Begin = ui->TU + bt->TM;
  5207. }
  5208. }
  5209. ui->TB = ElementB;
  5210. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5211. }
  5212. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5213. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5214. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5215. ui->TB = MaxB;
  5216. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5217. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5218. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5219. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5220. ui->TB=ui->TU+LA_RH;
  5221. }else{
  5222. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5223. ui->PP.EndInstance = TInstance;
  5224. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5225. if(!Template) Template=laui_SubPropInfoDefault;
  5226. //ui->Template = Template;
  5227. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5228. if (!ui->Subs.pFirst && TInstance){
  5229. la_AddInstancePage(ui, TInstance, 0);
  5230. la_CalcUiTopInfluence(&uil->Columns, ui);
  5231. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5232. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  5233. ui->TB = SubB + (NoDecal?0:bt->BM);
  5234. }else if (ui->Subs.pFirst){
  5235. if (!TInstance || TInstance != ui->Page->Instance){
  5236. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5237. ui->Page = 0;
  5238. if (TInstance){
  5239. la_AddInstancePage(ui, TInstance, 0);
  5240. la_CalcUiTopInfluence(&uil->Columns, ui);
  5241. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5242. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  5243. ui->TB = SubB + (NoDecal?0:bt->TM);
  5244. }else
  5245. ui->TB = ui->TU + LA_RH + bt->BM;
  5246. }else{
  5247. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  5248. ui->TB = SubB + (NoDecal?0:bt->BM);
  5249. }
  5250. }
  5251. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5252. ui->TB=ui->TU+LA_RH;
  5253. }
  5254. }
  5255. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5256. if (!WaitAnimation){
  5257. ui->L = ui->TL;
  5258. ui->R = ui->TR;
  5259. ui->U = ui->TU;
  5260. ui->B = ui->TB;
  5261. }
  5262. }
  5263. }else{
  5264. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5265. if (ui->Type != _LA_UI_CANVAS){
  5266. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5267. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5268. SubB = la_UpdateUiListRecursive(ui->Page,
  5269. ui->TB + (ui->State == LA_UI_ACTIVE ? 0 : LA_RH)+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-scrollw, B, Fast, ParentPanel);
  5270. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5271. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5272. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5273. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5274. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5275. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5276. }
  5277. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5278. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5279. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5280. if(ui->Page->HeightCoeff){
  5281. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5282. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5283. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5284. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5285. }
  5286. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5287. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5288. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5289. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5290. }
  5291. }
  5292. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5293. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5294. }else{
  5295. laUiList *suil;
  5296. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5297. la_CalcUiTopInfluence(&uil->Columns, ui);
  5298. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5299. SubB = la_UpdateUiListRecursive(suil, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), ui->TU+H, Fast, ParentPanel);
  5300. }
  5301. }
  5302. ui->TB = ui->TU + H;
  5303. }
  5304. }else ui->TB = ui->TU + H;
  5305. }
  5306. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5307. if(!RowMode){
  5308. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5309. }else{
  5310. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5311. }
  5312. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5313. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5314. ui = ui->Item.pNext;
  5315. }
  5316. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5317. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5318. else uil->TB = Lowest;
  5319. if (!WaitAnimation){
  5320. uil->L = uil->TL;
  5321. uil->R = uil->TR;
  5322. uil->U = uil->TU;
  5323. uil->B = uil->TB;
  5324. }
  5325. MAIN.UiScale=uil->SaveScale;
  5326. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5327. return uil->TB;
  5328. }
  5329. int la_AnimateSingleUiSize(int To, int *Now){
  5330. int Delta;
  5331. if (To != *Now){
  5332. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5333. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5334. *Now += Delta;
  5335. return 1;
  5336. }else
  5337. return 0;
  5338. }
  5339. int la_AnimateUiListRecursive(laUiList *uil){
  5340. laUiItem *ui;
  5341. int Again = 0;
  5342. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5343. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5344. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5345. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5346. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5347. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5348. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5349. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5350. laUiList *suil;
  5351. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5352. Again += la_AnimateUiListRecursive(suil);
  5353. }
  5354. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5355. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5356. Again += la_AnimateUiListRecursive(ui->Page);
  5357. }
  5358. }
  5359. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5360. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5361. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5362. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5363. return Again;
  5364. }
  5365. int la_DrawUiItem(laUiItem *ui){
  5366. tnsUseNoTexture();
  5367. tnsColor4d(1, 1, 1, 1);
  5368. tnsVertex2d(ui->L, ui->U);
  5369. tnsVertex2d(ui->R, ui->U);
  5370. tnsVertex2d(ui->R, ui->B);
  5371. tnsVertex2d(ui->L, ui->B);
  5372. tnsPackAs(GL_LINE_LOOP);
  5373. }
  5374. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5375. tnsUseNoTexture();
  5376. tnsColor4d(1, 1, 1, 1);
  5377. tnsVertex2d(ui->L - 1, ui->U - 1);
  5378. tnsVertex2d(ui->R + 1, ui->U - 1);
  5379. tnsVertex2d(ui->R + 1, ui->B + 1);
  5380. tnsVertex2d(ui->L - 1, ui->B + 1);
  5381. tnsPackAs(GL_LINE_LOOP);
  5382. }
  5383. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5384. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5385. return 1;
  5386. }
  5387. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5388. laUiListDrawItem *uildi = uild->Items.pFirst;
  5389. laUiList *Target = uildi->Target;
  5390. int L, R, U, B;
  5391. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5392. L = Target->L + Target->PanX + uildi->DifX;
  5393. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5394. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5395. U = Target->U + Target->PanY + uildi->DifY;
  5396. return la_UiInBound(ui, L, R, U, B);
  5397. }
  5398. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5399. laUiListDrawItem *uildi = uild->Items.pFirst;
  5400. laUiList *Target = uildi->Target;
  5401. int L, R, U, B;
  5402. if (Target){
  5403. L = Target->L + Target->PanX + uildi->DifX;
  5404. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5405. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5406. U = Target->U + Target->PanY + uildi->DifY;
  5407. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5408. return 1;
  5409. }else{
  5410. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5411. return 1;
  5412. }
  5413. }
  5414. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5415. laUiItem *ui = uil->UiItems.pFirst;
  5416. while (!strGetArgument(ui->Instructions, mark))
  5417. ui = ui->Item.pNext;
  5418. return ui;
  5419. }
  5420. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5421. laUiList *uil;
  5422. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5423. if (uil->Instance == Instance) return uil;
  5424. }
  5425. return uil;
  5426. }
  5427. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5428. int mx=(L+R)/2; int my=(U+B)/2;
  5429. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5430. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5431. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5432. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5433. tnsFlush();
  5434. }
  5435. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5436. if(!uil->ScrollerShownV) return;
  5437. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5438. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5439. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5440. int U = uil->U + Offset;
  5441. int B = U + Len;
  5442. int L = UiR - RM*2 - W;
  5443. int R = L + W;
  5444. if (B > U + DisplayH) B = U + DisplayH;
  5445. if (U < uil->U) U = uil->U;
  5446. if (B <= uil->U || U >= uil->B) return;
  5447. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5448. if (U < uil->U) U = uil->U;
  5449. tnsUseNoTexture();
  5450. laBoxedTheme* bt=_LA_THEME_PANEL;
  5451. real* color=laThemeColor(bt, LA_BT_TEXT);
  5452. tnsColor4d(LA_COLOR3(color), 0.2);
  5453. tnsVertex2d(R-RM, uil->U);
  5454. tnsVertex2d(L+RM, uil->U);
  5455. tnsVertex2d(L+RM, uil->U + DisplayH);
  5456. tnsVertex2d(R-RM, uil->U + DisplayH);
  5457. tnsPackAs(GL_TRIANGLE_FAN);
  5458. tnsColor4d(LA_COLOR3(color), 0.5);
  5459. tnsVertex2d(R-RM, uil->U);
  5460. tnsVertex2d(L+RM, uil->U);
  5461. tnsVertex2d(L+RM, uil->U + DisplayH);
  5462. tnsVertex2d(R-RM, uil->U + DisplayH);
  5463. tnsPackAs(GL_LINE_LOOP);
  5464. tnsColor4d(LA_COLOR3(color), 1);
  5465. tnsVertex2d(R, U);
  5466. tnsVertex2d(L, U);
  5467. tnsVertex2d(L, B);
  5468. tnsVertex2d(R, B);
  5469. tnsPackAs(GL_TRIANGLE_FAN);
  5470. int HU=(U+B)/2+LA_RH2;
  5471. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5472. tnsFlush();
  5473. }
  5474. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5475. if(!uil->ScrollerShownH) return;
  5476. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5477. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5478. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5479. int L = uil->L + Offset;
  5480. int R = L + Len;
  5481. int U = UiB - RM - W;
  5482. int B = U + W;
  5483. if (B > U + DisplayW) B = U + DisplayW;
  5484. if (U < uil->U) U = uil->U;
  5485. if (R <= uil->L || L >= uil->R) return;
  5486. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5487. if (L < uil->L) L = uil->L;
  5488. tnsUseNoTexture();
  5489. laBoxedTheme* bt=_LA_THEME_PANEL;
  5490. real* color=laThemeColor(bt, LA_BT_TEXT);
  5491. tnsColor4d(LA_COLOR3(color), 0.2);
  5492. tnsVertex2d(uil->L,U+RM);
  5493. tnsVertex2d(uil->L,B-RM);
  5494. tnsVertex2d(uil->L + DisplayW,B-RM);
  5495. tnsVertex2d(uil->L + DisplayW,U+RM);
  5496. tnsPackAs(GL_TRIANGLE_FAN);
  5497. tnsColor4d(LA_COLOR3(color), 0.5);
  5498. tnsVertex2d(uil->L,U+RM);
  5499. tnsVertex2d(uil->L,B-RM);
  5500. tnsVertex2d(uil->L + DisplayW,B-RM);
  5501. tnsVertex2d(uil->L + DisplayW,U+RM);
  5502. tnsPackAs(GL_LINE_LOOP);
  5503. tnsColor4d(LA_COLOR3(color), 1);
  5504. tnsVertex2d(R, U);
  5505. tnsVertex2d(L, U);
  5506. tnsVertex2d(L, B);
  5507. tnsVertex2d(R, B);
  5508. tnsPackAs(GL_TRIANGLE_FAN);
  5509. int HU=(U+B)/2+LA_RH2;
  5510. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5511. tnsFlush();
  5512. }
  5513. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5514. tnsUseNoTexture();
  5515. tnsColor4dv(color);
  5516. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5517. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5518. tnsPackAs(GL_TRIANGLE_FAN);
  5519. }
  5520. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5521. laSocketRecord* sr;
  5522. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5523. uild->WiresContainer=container;
  5524. }
  5525. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5526. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5527. if(lip->Target==uild->WiresContainer) break;
  5528. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5529. }
  5530. }
  5531. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5532. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5533. int PanX, PanY;
  5534. if(pc==LA_PC_SOCKET_OUT){
  5535. laNodeOutSocket* s=ui->PP.EndInstance;
  5536. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5537. }else{
  5538. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5539. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5540. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5541. }
  5542. }
  5543. void la_RegenerateWireColors(){
  5544. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5545. laTheme* t=MAIN.CurrentTheme;
  5546. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5547. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5548. for(int i=0;i<MAIN.WireColorSlices;i++){
  5549. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5550. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5551. }
  5552. }
  5553. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5554. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5555. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5556. tnsInterpolate2dv(v1,v2,0.5,vi);
  5557. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5558. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5559. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5560. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5561. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5562. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5563. tnsVertex2d(v1[0],v1[1]);
  5564. for(int i=1;i<=steps;i++){
  5565. real ratio=i==steps?1.0f:step*i;
  5566. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5567. tnsVertex2d(v1s[0],v1s[1]);
  5568. }
  5569. }
  5570. void la_DrawNodeWires(laUiListDraw* uild){
  5571. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5572. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5573. tnsUseNoTexture();
  5574. #define _RSLICES 16
  5575. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5576. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5577. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5578. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5579. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5580. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5581. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5582. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5583. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5584. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5585. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5586. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5587. }
  5588. if(MAIN.tNodeIn->Source){
  5589. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5590. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5591. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5592. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5593. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5594. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5595. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5596. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5597. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5598. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5599. }
  5600. #undef _RSLICES
  5601. tnsFlush();
  5602. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5603. glLineWidth(ww);
  5604. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5605. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5606. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5607. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5608. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5609. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5610. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5611. }
  5612. if(MAIN.tNodeIn->Source){
  5613. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5614. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5615. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5616. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5617. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5618. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5619. }
  5620. tnsFlush();
  5621. glLineWidth(1);
  5622. la_InitSocketRecord(uild,0);
  5623. }
  5624. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5625. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5626. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5627. }
  5628. int la_DrawUiListRecursive(laUiListDraw *uild, laUiList *uil, int L, int R, int U, int B, int LimH, int ConditionStackLevel, int GlobalX, int GlobalY, int RegisterNodes){
  5629. laUiItem *ui;
  5630. laBoxedTheme *bt;
  5631. laUiList *sub;
  5632. laUiListDrawItem *uildi;
  5633. int Ret = 0;
  5634. if (!uil) return 0;
  5635. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5636. ui = uil->UiItems.pFirst;
  5637. if(uil->PanY<0){uil->PanY=0;}
  5638. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5639. uil->SaveScale=MAIN.UiScale;
  5640. MAIN.UiScale*=uil->Scale;
  5641. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5642. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5643. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5644. if (ui->Type == &_LA_UI_CONDITION){
  5645. laConditionUiExtraData *cued = ui->Extra;
  5646. la_StepExpression(cued->Expression);
  5647. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5648. if (!cued->IsTrue){
  5649. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5650. }else{
  5651. ui = ui->Item.pNext;
  5652. }
  5653. continue;
  5654. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5655. ui = ui->Item.pNext;
  5656. continue;
  5657. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5658. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5659. if (cued->IsTrue) ui = cued->EndUi;
  5660. else
  5661. ui = ui->Item.pNext;
  5662. continue;
  5663. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5664. laConditionUiExtraData *cued = ui->Extra;
  5665. ui->Type->Draw(ui, LA_RH);
  5666. if (ui->State == LA_UI_NORMAL){
  5667. cued->IsTrue = 0;
  5668. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5669. }else{
  5670. cued->IsTrue = 1;
  5671. ui = ui->Item.pNext;
  5672. }
  5673. continue;
  5674. }
  5675. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5676. int NeedDraw=0;
  5677. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5678. if(NeedDraw){
  5679. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5680. }else{ ui->Type->Draw(ui, LA_RH); }
  5681. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5682. tnsFlush();
  5683. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5684. tnsResetViewMatrix();
  5685. }
  5686. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5687. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5688. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5689. tnsFlush();
  5690. }
  5691. }
  5692. if(NeedDraw || RegisterNodes){
  5693. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5694. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5695. ui->Type == _LA_UI_TAB ||
  5696. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5697. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5698. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5699. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5700. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5701. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5702. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5703. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5704. ui->Page->R-ui->Page->L-bt->RM-bt->LM, ui->R-ui->Page->L-bt->RM-bt->LM-(ui->Page->ScrollerShownV?LA_SCROLL_W:0),ui->B); }
  5705. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5706. ui->Page->B-ui->Page->U-(NoDecal?0:bt->TM-bt->BM), ui->B-ui->Page->U-(NoDecal?0:bt->TM-bt->BM)-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->RM:0),ui->R);
  5707. if (ui->Page->AllowScale){ la_DrawUiListArrows(ui->Page,ui->L, ui->R, ui->Page->U, ui->B-LA_SCROLL_W-bt->BM*2, laThemeColor(bt, LA_BT_BORDER)); }
  5708. }elif (ui->Type == _LA_UI_COLLECTION){
  5709. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5710. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5711. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5712. void* SaveInstance = ui->PP.EndInstance;
  5713. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5714. int State;
  5715. ui->PP.EndInstance = sub->Instance;
  5716. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5717. if(NeedDraw){ int drawn=0;
  5718. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5719. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5720. }
  5721. if (CanGetState && !drawn){
  5722. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5723. if(State >= 0){
  5724. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5725. }
  5726. }
  5727. }
  5728. if(sub->TabName && sub->TabName->Ptr){
  5729. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5730. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5731. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5732. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5733. tnsFlush();
  5734. }
  5735. if(CanGetTheme){
  5736. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5737. la_SwitchThemeQuick(t, OriginalTheme);
  5738. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5739. }
  5740. tnsFlush();
  5741. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5742. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5743. }
  5744. //ui->PP.EndInstance = Active;
  5745. ui->PP.EndInstance = SaveInstance;
  5746. }elif (ui->Type == _LA_UI_CANVAS){
  5747. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5748. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5749. tnsFlush();
  5750. Ret += la_DrawUiListRecursive(uild, sub, L-1, R+1, U-1, B+1, ui->B-bt->TP-bt->BP-bt->BM-bt->TM, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5751. }
  5752. }
  5753. }
  5754. ui = ui->Item.pNext;
  5755. }else{
  5756. ui = ui->Item.pNext;
  5757. }
  5758. }
  5759. tnsFlush();
  5760. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5761. la_RestoreLastUiListMatrix(uild, B - U);
  5762. MAIN.UiScale=uil->SaveScale;
  5763. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5764. return Ret;
  5765. }
  5766. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5767. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5768. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5769. tnsUseNoTexture();
  5770. tnsColor4d(1, 1, 1, 1);
  5771. tnsVertex2d(L, U);
  5772. tnsVertex2d(R, U);
  5773. tnsVertex2d(R, B);
  5774. tnsVertex2d(L, B);
  5775. tnsPackAs(GL_LINE_LOOP);
  5776. tnsVertex2d(L + 3, Begin);
  5777. tnsVertex2d(R - 3, Begin);
  5778. tnsVertex2d(R - 3, End);
  5779. tnsVertex2d(L + 3, End);
  5780. tnsPackAs(GL_LINE_LOOP);
  5781. }
  5782. int laIsInUiItem(laUiItem *ui, int x, int y){
  5783. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5784. return 1;
  5785. }
  5786. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5787. if (x < l || x > r || y < u || y > b) return 0;
  5788. return 1;
  5789. }
  5790. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5791. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5792. laUiItem *ui, *tui;
  5793. laBoxedTheme *bt;
  5794. laUiList *sub;
  5795. int CPB = 0;
  5796. if (!uil || (LimB && y > LimB)) return 0;
  5797. x += uil->PanX;
  5798. y += uil->PanY;
  5799. for (ui = uil->UiItems.pFirst; ui;){
  5800. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5801. if (ui->Type == &_LA_UI_CONDITION){
  5802. laConditionUiExtraData *cued = ui->Extra;
  5803. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5804. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5805. if (!cued->IsTrue){
  5806. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5807. }else{
  5808. ui = ui->Item.pNext;
  5809. }
  5810. continue;
  5811. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5812. ui = ui->Item.pNext;
  5813. continue;
  5814. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5815. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5816. if (cued->IsTrue) ui = cued->EndUi;
  5817. else
  5818. ui = ui->Item.pNext;
  5819. continue;
  5820. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5821. laConditionUiExtraData *cued = ui->Extra;
  5822. if (laIsInUiItem(ui, x, y)){
  5823. lstAppendPointer(LocalBuf, uil);
  5824. return ui;
  5825. }
  5826. if (ui->State == LA_UI_NORMAL){
  5827. cued->IsTrue = 0;
  5828. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5829. }else{
  5830. cued->IsTrue = 1;
  5831. ui = ui->Item.pNext;
  5832. }
  5833. continue;
  5834. }
  5835. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5836. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5837. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5838. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5839. if(!la_DetectSplit(ui->C, x)) Add=0;
  5840. }
  5841. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5842. }
  5843. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5844. if (ui->Page->HeightCoeff) CPB = ui->B;
  5845. else CPB = ui->Page->B;
  5846. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5847. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5848. lstAppendPointer(LocalBuf, uil);
  5849. return tui;
  5850. }
  5851. }else if (laIsInUiItem(ui, x, y)){
  5852. lstAppendPointer(LocalBuf, uil);return ui;
  5853. }
  5854. }
  5855. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5856. if (laIsInUiItem(ui, x, y)){
  5857. lstAppendPointer(LocalBuf, uil);
  5858. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5859. if(Deep){
  5860. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5861. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5862. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5863. lstAppendPointer(LocalBuf, iuil);
  5864. return tui;
  5865. }
  5866. }
  5867. }
  5868. }
  5869. return ui;
  5870. }
  5871. }
  5872. if (ui->Type == _LA_UI_CANVAS){
  5873. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5874. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5875. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5876. lstAppendPointer(LocalBuf, uil);
  5877. return tui;
  5878. }
  5879. }
  5880. }
  5881. if (laIsInUiItem(ui, x, y)){
  5882. lstAppendPointer(LocalBuf, uil);
  5883. return ui;
  5884. }
  5885. }
  5886. ui = ui->Item.pNext;
  5887. }
  5888. return 0;
  5889. }
  5890. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5891. laListHandle Locals={0};
  5892. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5893. while(lstPopPointer(&Locals));
  5894. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5895. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5896. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5897. if(pc==PCInOrOut) return ui;
  5898. }
  5899. return 0;
  5900. }
  5901. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5902. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5903. laUiItem *ui = uil->UiItems.pFirst;
  5904. laBoxedTheme *bt;
  5905. laUiList *tuil;
  5906. laUiList *sub;
  5907. int CPB = 0;
  5908. x += uil->PanX;
  5909. y += uil->PanY;
  5910. if (y > LimH) return uil;
  5911. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  5912. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  5913. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5914. return uil;
  5915. }
  5916. for (ui = uil->UiItems.pFirst; ui;){
  5917. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5918. if (ui->Type == &_LA_UI_CONDITION){
  5919. laConditionUiExtraData *cued = ui->Extra;
  5920. //la_StepExpression(cued->Expression);
  5921. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5922. if (!cued->IsTrue){
  5923. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5924. }else{
  5925. ui = ui->Item.pNext;
  5926. }
  5927. continue;
  5928. }
  5929. 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. if (ui->State == LA_UI_NORMAL){
  5941. cued->IsTrue = 0;
  5942. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5943. }else{
  5944. cued->IsTrue = 1;
  5945. ui = ui->Item.pNext;
  5946. }
  5947. continue;
  5948. }
  5949. if (InToContainerUI && ui != Exception){
  5950. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5951. if (ContainerParent) (*ContainerParent) = uil;
  5952. if (ParentUi) *ParentUi = ui;
  5953. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5954. //if (y > LimH) return uil;
  5955. 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))){
  5956. return tuil;
  5957. }
  5958. }
  5959. }
  5960. }
  5961. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5962. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  5963. else CPB = ui->Page->B;
  5964. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5965. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5966. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5967. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5968. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5969. if (ParentUi) *ParentUi = ui;
  5970. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5971. }
  5972. }
  5973. ui = ui->Item.pNext;
  5974. }
  5975. return uil;
  5976. }
  5977. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5978. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5979. laUiItem *ui = uil->UiItems.pFirst;
  5980. laBoxedTheme *bt;
  5981. laUiList *tuil;
  5982. laUiList *sub;
  5983. int CPB = 0;
  5984. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5985. x += uil->PanX;
  5986. y += uil->PanY;
  5987. if (y > LimH) return uil;
  5988. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5989. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5990. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5991. return uil;
  5992. }
  5993. for (ui = uil->UiItems.pFirst; ui;){
  5994. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5995. if (ui->Type == &_LA_UI_CONDITION){
  5996. laConditionUiExtraData *cued = ui->Extra;
  5997. //la_StepExpression(cued->Expression);
  5998. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5999. if (!cued->IsTrue){
  6000. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6001. }else{
  6002. ui = ui->Item.pNext;
  6003. }
  6004. continue;
  6005. }
  6006. if (ui->Type == &_LA_UI_CONDITION_END){
  6007. ui = ui->Item.pNext;
  6008. continue;
  6009. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6010. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6011. if (cued->IsTrue) ui = cued->EndUi;
  6012. else
  6013. ui = ui->Item.pNext;
  6014. continue;
  6015. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6016. laConditionUiExtraData *cued = ui->Extra;
  6017. if (ui->State == LA_UI_NORMAL){
  6018. cued->IsTrue = 0;
  6019. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6020. }else{
  6021. cued->IsTrue = 1;
  6022. ui = ui->Item.pNext;
  6023. }
  6024. continue;
  6025. }
  6026. if (InToContainerUI && ui != Exception){
  6027. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6028. if (ContainerParent) (*ContainerParent) = uil;
  6029. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6030. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6031. //if (y > LimH) return uil;
  6032. 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))){
  6033. return tuil;
  6034. }
  6035. }
  6036. }
  6037. }
  6038. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6039. if (ui->Page->HeightCoeff) CPB = ui->B;
  6040. else CPB = ui->Page->B;
  6041. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6042. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6043. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6044. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6045. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6046. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6047. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6048. }
  6049. }
  6050. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6051. if (ui->Page->HeightCoeff) CPB = ui->B;
  6052. else
  6053. CPB = ui->Page->B;
  6054. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6055. if (ScrollUil) *ScrollUil = ui->Page;
  6056. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6057. }
  6058. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6059. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6060. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6061. }
  6062. }
  6063. ui = ui->Item.pNext;
  6064. }
  6065. return uil;
  6066. }
  6067. int la_TestUiListMinumWidth(laUiList *uil){
  6068. laUiItem *ui, *tui;
  6069. laBoxedTheme *bt;
  6070. laUiList *sub;
  6071. int CPB = 0;
  6072. int W = 0;
  6073. int tW, sW, RowMode=0, rW;
  6074. void *Restore;
  6075. for (ui = uil->UiItems.pFirst; ui;){
  6076. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6077. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6078. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6079. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6080. if (W < tW) W = tW;
  6081. }elif (ui->Type == _LA_UI_COLLECTION){
  6082. Restore = ui->PP.EndInstance;
  6083. tW = 0; sW = 0;
  6084. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6085. ui->PP.EndInstance = sub->Instance;
  6086. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6087. if (sW > tW) tW = sW;
  6088. }
  6089. ui->PP.EndInstance = Restore;
  6090. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6091. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6092. if (W < tW) W = tW;
  6093. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6094. RowMode=1; rW=0;
  6095. }elif (ui->Type==&_LA_UI_ROW_END){
  6096. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6097. }elif (ui->Type->GetMinWidth){
  6098. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6099. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6100. }
  6101. ui = ui->Item.pNext;
  6102. }
  6103. return W;
  6104. }
  6105. void la_InitLLVM(){
  6106. //LLVMLinkInMCJIT();
  6107. //LLVMInitializeNativeTarget();
  6108. //LLVMInitializeNativeAsmPrinter();
  6109. //LLVMInitializeNativeAsmParser();
  6110. // MAIN.llvmContext = LLVMGetGlobalContext();
  6111. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6112. }
  6113. //==================================================================================================
  6114. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6115. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6116. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6117. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6118. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6119. memFree(kmi);
  6120. }
  6121. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6122. laKeyMapItem *kmi;
  6123. if (!km) return 0;
  6124. kmi = memAcquire(sizeof(laKeyMapItem));
  6125. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6126. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6127. }else{
  6128. strSafeSet(&kmi->Operation, Operation);
  6129. }
  6130. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6131. kmi->SpecialKeyBits = SpecialKeyBits;
  6132. kmi->EventType = EventType;
  6133. kmi->Key = tolowerGuarded(Key);
  6134. kmi->SelectBase = SelectBase;
  6135. lstAppendItem(&km->Items, kmi);
  6136. return kmi;
  6137. }
  6138. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6139. laKeyMapItem *kmi; int inv=0;
  6140. char *instructions;
  6141. if(e->type==LA_MOUSEMOVE) return 0;
  6142. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6143. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6144. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6145. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6146. if (kmi->Operation)
  6147. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6148. else
  6149. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6150. inv = 1;
  6151. }
  6152. }
  6153. return inv;
  6154. }
  6155. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6156. laKeyMapItem *kmi;
  6157. char *instructions;
  6158. int inv = 0; int lx = -1, ly = -1;
  6159. if(e->type==LA_MOUSEMOVE) return 0;
  6160. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6161. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6162. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6163. if (e->Localized){
  6164. lx = e->x;
  6165. ly = e->y;
  6166. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6167. e->Localized = 0;
  6168. }
  6169. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6170. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6171. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6172. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6173. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6174. }elif (kmi->Operation){
  6175. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6176. }else{
  6177. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6178. }
  6179. inv = 1;
  6180. if (lx >= 0){
  6181. e->x = lx;
  6182. e->y = ly;
  6183. e->Localized = 1;
  6184. }
  6185. }
  6186. }
  6187. return inv;
  6188. }
  6189. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6190. void la_DestroyOperatorType(laOperatorType* at){
  6191. //if(at->PC) la_FreePropertyContainer(at->PC);
  6192. memFree(at);
  6193. }
  6194. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6195. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6196. uint32_t IconID, int ExtraMark){
  6197. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6198. at->Identifier = ID;
  6199. at->Name = Name;
  6200. at->Description = Description;
  6201. at->Check = Check;
  6202. at->Invoke = Invoke;
  6203. at->Init = Init;
  6204. at->Exit = Exit;
  6205. at->Modal = Modal;
  6206. at->IconID = IconID;
  6207. at->ExtraMark = ExtraMark;
  6208. at->ParseArgs = la_DefaultOperatorParser;
  6209. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6210. return at;
  6211. }
  6212. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6213. ot->PC = memAcquire(sizeof(laPropContainer));
  6214. ot->PC->Identifier = ot->Identifier;
  6215. ot->PC->Hyper = HyperLevel;
  6216. return ot->PC;
  6217. }
  6218. laOperator *la_CreateOperator(laOperatorType *at){
  6219. laOperator *a = CreateNew(laOperator);
  6220. a->Type = at;
  6221. if (at->PC && at->PC->Props.pFirst){
  6222. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6223. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6224. a->PP.LastPs->p->SubProp = at->PC;
  6225. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6226. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6227. a->PP.LastPs->Type = U'.';
  6228. }
  6229. return a;
  6230. }
  6231. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6232. return (!strcmp(a->Identifier, id));
  6233. }
  6234. laOperatorType *laGetOperatorType(const char *ID){
  6235. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6236. }
  6237. int laOperatorExistsT(laOperatorType* at){
  6238. if (!at) return 0;
  6239. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6240. return 0;
  6241. }
  6242. int laOperatorExists(const char* ID){
  6243. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6244. return laOperatorExistsT(at);
  6245. }
  6246. int la_OperatorExists(laOperator *ac){
  6247. if (!ac) return 0;
  6248. laOperator *a;
  6249. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6250. return 0;
  6251. }
  6252. int la_UiOperatorExists(void *inst){
  6253. laOperator *a;
  6254. if (!inst) return 0;
  6255. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6256. if (((laUiItem *)a->Instance) == inst){
  6257. return 1;
  6258. }
  6259. }
  6260. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6261. if (a->Instance == inst){
  6262. return 1;
  6263. }
  6264. }
  6265. return 0;
  6266. }
  6267. int la_OperatorPending(laOperator *target){
  6268. laOperator *a;
  6269. if (!target) return 0;
  6270. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6271. if (a == target){
  6272. return 1;
  6273. }
  6274. }
  6275. return 0;
  6276. }
  6277. void laSetOperatorLocalizer(void *ToPanel){
  6278. MAIN.ToPanel = ToPanel;
  6279. }
  6280. void la_DestroyConfirmData(laConfirmData **cd);
  6281. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6282. laOperator *ai = (*a);
  6283. laOperator *ac = ((*a)->Child);
  6284. void *Ret = 0;
  6285. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6286. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6287. }
  6288. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6289. if ((*a)->PP.LastPs){
  6290. memFree((*a)->PP.LastPs->p);
  6291. memFree((*a)->PP.LastPs);
  6292. }
  6293. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6294. la_SetPropMathcerContext((*a)->OperatorPanel);
  6295. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6296. laDestroySinglePanel((*a)->OperatorPanel,0);
  6297. }
  6298. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6299. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6300. lstClearPointer(&(*a)->LocalUiLists);
  6301. if (Operators){
  6302. Ret = ai->Item.pNext;
  6303. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6304. else
  6305. lstRemoveItem(Operators, *a);
  6306. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6307. if (ai->Child == (*a)) ai->Child = 0;
  6308. }
  6309. }
  6310. strSafeDestroy(&(*a)->RuntimeHint);
  6311. free(*a);
  6312. return Ret;
  6313. }
  6314. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6315. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6316. if (!at) return 0;
  6317. if (!at->Check) return 1;
  6318. return (at->Check(This, Instructions));
  6319. }
  6320. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6321. if (!at) return 0;
  6322. if (!at->Check) return 1;
  6323. return (at->Check(This, Instructions));
  6324. }
  6325. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6326. laPropPack FakePP = {0};
  6327. laPropStep FakePs = {0};
  6328. if (!at) return 0;
  6329. if (!at->Check) return 1;
  6330. FakePP.LastPs = &FakePs;
  6331. FakePP.Go = FakePP.LastPs;
  6332. FakePP.LastPs->p = This->LastPs->p;
  6333. FakePP.LastPs->UseInstance = This->EndInstance;
  6334. FakePP.EndInstance = Real_FromInstance;
  6335. FakePP.LastIndex = This->LastIndex;
  6336. return (at->Check(&FakePP, Instructions));
  6337. }
  6338. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6339. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6340. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6341. }
  6342. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6343. laOperator *a, *f = From;
  6344. int rev;
  6345. if (!f && e&&e->Localized) return -1;
  6346. a = la_CreateOperator(at);
  6347. a->ToPanel = MAIN.ToPanel;
  6348. a->This = This;
  6349. a->ExtraInstructions = args;
  6350. strMakeInstructions(&a->ExtraInstructionsP, args);
  6351. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6352. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6353. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6354. la_DestroyOperator(&a, 0, 0);
  6355. return LA_CANCELED;
  6356. }
  6357. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6358. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6359. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6360. e->Localized = 1;
  6361. }
  6362. if (e&&e->Localized){
  6363. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6364. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6365. e->Localized = 0;
  6366. }else{
  6367. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6368. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6369. }
  6370. }
  6371. if (From) f->Child = a;
  6372. a->Using = 1;
  6373. if (at->Init) at->Init(a);
  6374. rev = at->Invoke(a, e);
  6375. a->Using = 0;
  6376. if (rev & LA_FINISH){
  6377. a->StopNow = 1; if(From)From->Child=0;
  6378. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6379. }
  6380. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6381. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6382. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6383. a->State = rev;
  6384. a->PP.EndInstance = a->CustomData;
  6385. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6386. }else
  6387. la_DestroyOperator(&a, 0, 0);
  6388. return rev;
  6389. }
  6390. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6391. laOperatorType *at; laOperator *a, *f = From;
  6392. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6393. if (!at) return -1;
  6394. return laInvokeP(From,at,e,This,args,args2);
  6395. }
  6396. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6397. laOperator *a, *f = From;
  6398. int rev;
  6399. laPropPack *created;
  6400. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6401. created = memAcquireSimple(sizeof(laPropPack));
  6402. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6403. created->Go = created->LastPs;
  6404. created->LastPs->p = OrigionalThis->LastPs->p;
  6405. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6406. created->EndInstance = FromInstance;
  6407. created->LastIndex = OrigionalThis->LastIndex;
  6408. a = la_CreateOperator(at);
  6409. a->ToPanel = MAIN.ToPanel;
  6410. a->This = created;
  6411. a->CreatedThis = created;
  6412. a->ExtraInstructions = args;
  6413. strMakeInstructions(&a->ExtraInstructionsP, args);
  6414. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6415. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6416. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6417. la_DestroyOperator(&a, 0, 0);
  6418. return LA_CANCELED;
  6419. }
  6420. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6421. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6422. if (From) f->Child = a;
  6423. a->Using = 1;
  6424. if (at->Init) at->Init(a);
  6425. rev = at->Invoke(a, e);
  6426. a->Using = 0;
  6427. if (rev & LA_FINISH){
  6428. a->StopNow = 1; if(From)From->Child=0;
  6429. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6430. }
  6431. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6432. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6433. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6434. a->State = rev;
  6435. a->PP.EndInstance = a->CustomData;
  6436. }else
  6437. la_DestroyOperator(&a, 0, 0);
  6438. return rev;
  6439. }
  6440. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6441. laOperator *a, *f = From;
  6442. int rev;
  6443. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6444. a = la_CreateOperator(at);
  6445. a->Instance = inst;
  6446. a->ToPanel = MAIN.ToPanel;
  6447. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6448. if (From) f->Child = a;
  6449. a->Using = 1;
  6450. if (at->Init) at->Init(a);
  6451. rev = at->Invoke(a, e);
  6452. a->Using = 0;
  6453. if (rev & LA_FINISH){
  6454. a->StopNow = 1; if(From)From->Child=0;
  6455. }
  6456. if (rev & LA_BLOCK){
  6457. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6458. a->State = rev;
  6459. }else la_DestroyOperator(&a, 0, 0);
  6460. DEB = a;
  6461. return rev;
  6462. }
  6463. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6464. laOperatorType *at;
  6465. laOperator *a, *f = From;
  6466. if (la_UiOperatorExists(inst)) return -1;
  6467. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6468. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6469. }
  6470. void laRequestDelayEvent(real Seconds){
  6471. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6472. int la_UiStillInService(void *UiInstance){
  6473. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6474. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6475. if (ai->Instance == UiInstance) return 1;
  6476. }
  6477. return 0;
  6478. }
  6479. void la_StopUiOperatorService(void *UiInstance){
  6480. laOperator *ai, *dai, *NextAi;
  6481. if (!MAIN.CurrentWindow) return;
  6482. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6483. NextAi = ai->Item.pNext;
  6484. if (ai->Instance == UiInstance){
  6485. if (ai->Child){
  6486. la_StopUiOperatorService(ai->Child->Instance);
  6487. ai->Child = 0;
  6488. }
  6489. laOperator *dai = ai;
  6490. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6491. continue;
  6492. }
  6493. }
  6494. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6495. NextAi = ai->Item.pNext;
  6496. if (ai->Instance == UiInstance){
  6497. if (ai->Instance == ai->ToPanel){
  6498. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6499. //ai->ToPanel->LaterDestroy = 1;
  6500. }
  6501. if (ai->Child && la_OperatorExists(ai->Child)){
  6502. la_StopUiOperatorService(ai->Child->Instance);
  6503. //ai->Child = 0;
  6504. }
  6505. if (!ai->Using){
  6506. laOperator *dai = ai;
  6507. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6508. }else
  6509. ai->StopNow = 1;
  6510. }
  6511. }
  6512. }
  6513. void la_StopAllOperators(){
  6514. laOperator *ai, *dai, *NextAi;
  6515. if (!MAIN.CurrentWindow) return;
  6516. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6517. NextAi = ai->Item.pNext;
  6518. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6519. continue;
  6520. }
  6521. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6522. NextAi = ai->Item.pNext;
  6523. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6524. laHidePanelWithDissoveEffect(ai->ToPanel);
  6525. ai->ToPanel->LaterDestroy = 1;
  6526. }
  6527. if (!ai->Using){
  6528. laOperator *dai = ai;
  6529. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6530. }else ai->StopNow = 1;
  6531. }
  6532. }
  6533. void la_DestroyConfirmData(laConfirmData **cd){
  6534. if((!cd)||!(*cd)) return;
  6535. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6536. if ((*cd)->StrData) free((*cd)->StrData);
  6537. FreeMem((*cd));
  6538. (*cd) = 0;
  6539. }
  6540. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6541. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6542. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6543. ai->NextConfirmData = cd; laRetriggerOperators();
  6544. }
  6545. void laConfirmInt(laOperator *a, int Data, int mode){
  6546. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6547. cd->IData = Data; cd->Mode = mode;
  6548. ai->NextConfirmData = cd; laRetriggerOperators();
  6549. }
  6550. void laConfirmFloat(laOperator *a, real Data, int mode){
  6551. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6552. cd->FData = Data; cd->Mode = mode;
  6553. ai->NextConfirmData = cd; laRetriggerOperators();
  6554. }
  6555. void laConfirmString(laOperator *a, char *Str, int mode){
  6556. laOperator *ai = a;
  6557. laConfirmData *cd = CreateNew(laConfirmData);
  6558. int len = strlen(Str);
  6559. char *buf = calloc(len + 1, sizeof(char));
  6560. strcpy(buf, Str);
  6561. cd->StrData = buf;
  6562. cd->Mode = mode;
  6563. cd->Destroy = free;
  6564. ai->NextConfirmData = cd;
  6565. laRetriggerOperators();
  6566. }
  6567. int laConfirmSameDataIfAny(laOperator *a){
  6568. laOperator *ai = a;
  6569. laConfirmData *cd;
  6570. char *buf = 0;
  6571. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6572. cd = CreateNew(laConfirmData);
  6573. if (ai->ConfirmData->StrData){
  6574. int len = strlen(ai->ConfirmData->StrData);
  6575. buf = calloc(len + 1, sizeof(char));
  6576. strcpy(buf, ai->ConfirmData->StrData);
  6577. }
  6578. //cd->CustomData = cd->CustomData;
  6579. cd->IData = ai->ConfirmData->IData;
  6580. cd->FData = ai->ConfirmData->FData;
  6581. cd->PointerData = ai->ConfirmData->PointerData;
  6582. cd->PointerType = a->ConfirmData->PointerType;
  6583. cd->StrData = buf;
  6584. cd->Mode = ai->ConfirmData->Mode;
  6585. cd->Destroy = ai->ConfirmData->Destroy;
  6586. ai->NextConfirmData = cd;
  6587. laRetriggerOperators();
  6588. return 1;
  6589. }
  6590. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6591. laOperator *ai = a;
  6592. laConfirmData *cd = CreateNew(laConfirmData);
  6593. cd->CustomData = UserData;
  6594. cd->Mode = mode;
  6595. cd->Destroy = Destroy;
  6596. ai->NextConfirmData = cd;
  6597. laRetriggerOperators();
  6598. }
  6599. int laGetConfirmMode(laOperator *a){
  6600. return ((laOperator *)a)->ConfirmData->Mode;
  6601. }
  6602. int laGetConfirmInt(laOperator *a){
  6603. laOperator *ai = a;
  6604. int rev = ai->ConfirmData->IData;
  6605. la_DestroyConfirmData(&ai->ConfirmData);
  6606. ai->ConfirmData = 0;
  6607. return rev;
  6608. }
  6609. real laGetConfirmFloat(laOperator *a){
  6610. laOperator *ai = a;
  6611. real rev = ai->ConfirmData->FData;
  6612. la_DestroyConfirmData(&ai->ConfirmData);
  6613. ai->ConfirmData = 0;
  6614. return rev;
  6615. }
  6616. void laGetConfirmString(laOperator *a, char *buf){
  6617. laOperator *ai = a;
  6618. strcpy(buf, ai->ConfirmData->StrData);
  6619. la_DestroyConfirmData(&ai->ConfirmData);
  6620. ai->ConfirmData = 0;
  6621. }
  6622. void *laGetConfirmUserData(laOperator *a){
  6623. laOperator *ai = a;
  6624. return ai->ConfirmData->CustomData;
  6625. }
  6626. void laFinalizeOperators(){
  6627. laOperatorType *at;
  6628. laListHandle *lst;
  6629. int i;
  6630. for (i = 0; i < 256; i++){
  6631. lst = &MAIN.OperatorTypeHash.Entries[i];
  6632. for (at = lst->pFirst; at; at = at->Item.pNext){
  6633. if (at->PC && at->PC->Props.pFirst){
  6634. lstAppendItem(&MAIN.PropContainers, at->PC);
  6635. }
  6636. }
  6637. }
  6638. }
  6639. //=================
  6640. #ifdef LA_LINUX
  6641. static void la_RecordWacomMotions(XIRawEvent *event)
  6642. {
  6643. double *valuator = event->valuators.values;
  6644. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6645. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6646. //SYSWINDOW root_return, child_return;
  6647. //int root_x_return, root_y_return;
  6648. //int win_x_return, win_y_return;
  6649. //unsigned int mask_return;
  6650. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6651. // &root_x_return, &root_y_return,
  6652. // &win_x_return, &win_y_return,
  6653. // &mask_return);
  6654. //
  6655. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6656. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6657. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6658. real x=valuator[3],y=valuator[4];
  6659. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6660. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6661. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6662. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6663. if(XIMaskIsSet(event->valuators.mask, 5)){
  6664. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6665. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6666. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6667. MAIN.IsPen=1;
  6668. }
  6669. #endif
  6670. #ifdef _WIN32
  6671. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6672. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6673. static uint32_t ch = 0; static int lead = 0;
  6674. static wchar_t buf[10] = { 0 }; int adv;
  6675. static DWORD LastMove = 0;
  6676. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6677. short wheelmark = 0;
  6678. int WheelDir = 0;
  6679. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6680. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6681. POINT point;
  6682. PACKET pkt;
  6683. static POINT ptOld, ptNew;
  6684. static UINT prsOld, prsNew, vkey;
  6685. MOUSEMOVEPOINT mmp = { 0 }; POINT pt; static POINT ptLast={0};
  6686. MOUSEMOVEPOINT mmpBuf[64];
  6687. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6688. switch (message) {
  6689. case WM_PAINT:
  6690. //SwapBuffers(GetDC(hwnd));
  6691. break;
  6692. case WM_MOUSEMOVE:
  6693. pt.x= LOWORD(lparam); pt.y = HIWORD(lparam);
  6694. ClientToScreen(hwnd, &pt);
  6695. mmp.x = pt.x; mmp.y = pt.y;
  6696. int numPoints = GetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &mmp, mmpBuf, 64, GMMP_USE_DISPLAY_POINTS);
  6697. int i;
  6698. for(i = 0; i < numPoints; i++){
  6699. if(mmpBuf[i].time < LastMove){ break; }
  6700. if(mmpBuf[i].time == LastMove && mmpBuf[i].x==ptLast.x && mmpBuf[i].y==ptLast.y){ break; }
  6701. }
  6702. while(i){
  6703. pt.x = mmpBuf[i].x; pt.y = mmpBuf[i].y; ptLast = pt;
  6704. ScreenToClient(hwnd, &pt);
  6705. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, pt.x, pt.y);
  6706. i--;
  6707. }
  6708. //la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6709. MAIN.IsPen = 0;
  6710. LastMove = GetMessageTime();
  6711. break;
  6712. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6713. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6714. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6715. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6716. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6717. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6718. case WM_MOUSEWHEEL:
  6719. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6720. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6721. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6722. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6723. break;
  6724. case WT_PACKET:
  6725. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6726. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6727. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6728. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6729. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6730. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6731. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6732. MAIN.StylusTwist = tw;
  6733. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6734. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6735. MAIN.EraserPressure = MAIN.StylusPressure;
  6736. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6737. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6738. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6739. }
  6740. return 0; break;
  6741. case WM_SYSCOMMAND:
  6742. switch (wparam) {
  6743. case SC_MAXIMIZE:
  6744. case SC_RESTORE:
  6745. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6746. break;
  6747. case SC_KEYMENU:
  6748. return 0;
  6749. case SC_MINIMIZE:
  6750. break;
  6751. }
  6752. break;
  6753. case WM_SIZE:
  6754. if (wparam == SIZE_MINIMIZED) break;
  6755. case WM_MOVE: /* And size */
  6756. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6757. break;
  6758. case WM_SETCURSOR:
  6759. if(MAIN.CurrentCursor) return 1;
  6760. break;
  6761. case WM_POINTERDOWN:
  6762. case WM_POINTERUP:
  6763. case WM_POINTERUPDATE:
  6764. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6765. pointerId = GET_POINTERID_WPARAM(wparam);
  6766. pointerType = PT_POINTER;
  6767. if(!GetPointerType(pointerId, &pointerType)){
  6768. pointerType = PT_POINTER;
  6769. }
  6770. if(pointerType == PT_PEN){
  6771. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6772. for (int i = peninfonum-1; i>=0; i--) {
  6773. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6774. ScreenToClient(hwnd, &point);
  6775. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6776. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6777. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6778. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6779. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6780. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6781. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6782. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6783. }
  6784. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6785. }
  6786. }
  6787. SkipPointerFrameMessages(pointerId);
  6788. return 0;
  6789. }
  6790. else if (pointerType == PT_TOUCH){
  6791. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6792. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6793. ScreenToClient(hwnd, &point);
  6794. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6795. }
  6796. }
  6797. break;
  6798. case WM_SYSKEYDOWN:
  6799. if (lparam & 0x40000000) break;
  6800. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6801. break;
  6802. case WM_KEYDOWN:
  6803. if (lparam & 0x40000000) break;
  6804. vkey = wparam;
  6805. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6806. break;
  6807. case WM_KEYUP:
  6808. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6809. break;
  6810. case WM_SYSKEYUP:
  6811. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6812. break;
  6813. case WM_UNICHAR:
  6814. la_SendInputEvent(hwnd, wparam);
  6815. break;
  6816. case WM_IME_CHAR:
  6817. la_SendInputEvent(hwnd, wparam);
  6818. return 0;
  6819. case WM_CHAR:
  6820. la_SendInputEvent(hwnd, wparam);
  6821. break;
  6822. case WM_SHOWWINDOW:
  6823. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6824. break;
  6825. case WM_CLOSE:
  6826. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6827. break;
  6828. default:
  6829. return DefWindowProc(hwnd, message, wparam, lparam);
  6830. }
  6831. return DefWindowProc(hwnd, message, wparam, lparam);
  6832. }
  6833. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6834. return DefWindowProc(hwnd, message, wparam, lparam);
  6835. }
  6836. #endif
  6837. int la_UpdateOperatorHints(laWindow* w){
  6838. laSafeString* ss=0;
  6839. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6840. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6841. }
  6842. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6843. }else{
  6844. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6845. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6846. }
  6847. strSafeDestroy(&ss);
  6848. }
  6849. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6850. laOperator *a, *NextA = 0;
  6851. int Result = 0;
  6852. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6853. la_SendSignalsFromEvent(e);
  6854. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6855. a = Operators->pFirst;
  6856. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6857. while (1){
  6858. if (!a) break;
  6859. if (a->StopNow){
  6860. NextA = a->Item.pNext;
  6861. if (a->Type->Exit) a->Type->Exit(a, Result);
  6862. ConfirmData = a->NextConfirmData;
  6863. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6864. NextConfirmData = ConfirmData;
  6865. a->ConfirmData = 0;
  6866. a->NextConfirmData = 0;
  6867. la_DestroyOperator(&a, Operators, 0);
  6868. a = NextA;
  6869. if (a){
  6870. a->ConfirmData = NextConfirmData;
  6871. }
  6872. continue;
  6873. }
  6874. a->Using = 1;
  6875. la_SetPropMathcerContext(a->ToPanel);
  6876. laSetOperatorLocalizer(a->ToPanel);
  6877. MAIN.CurrentPanel = a->ToPanel;
  6878. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6879. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6880. e->Localized = 1;
  6881. }
  6882. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6883. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6884. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6885. e->Localized = 0;
  6886. }
  6887. la_SetPropMathcerContext(0);
  6888. laSetOperatorLocalizer(0);
  6889. MAIN.CurrentPanel = 0;
  6890. a->Using = 0;
  6891. if (Result & LA_PASS_ON){
  6892. laConfirmSameDataIfAny(a);
  6893. NextA = a->Item.pNext;
  6894. }else{
  6895. NextA = 0;
  6896. if (a->NextConfirmData){
  6897. la_DestroyConfirmData(&a->NextConfirmData);
  6898. }
  6899. }
  6900. ConfirmData = a->NextConfirmData;
  6901. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6902. NextConfirmData = ConfirmData;
  6903. a->ConfirmData = 0;
  6904. a->NextConfirmData = 0;
  6905. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6906. if (a->Type->Exit) a->Type->Exit(a, Result);
  6907. la_DestroyOperator(&a, Operators, 0);
  6908. int found=0;
  6909. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6910. if(!found){ NextA=0; }
  6911. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6912. }
  6913. a = NextA;
  6914. if (a){
  6915. a->ConfirmData = NextConfirmData;
  6916. }
  6917. }
  6918. return 1;
  6919. }
  6920. int la_HandleEvents(laWindow *w){
  6921. laEvent *e, *NextE;
  6922. laOperator *a;
  6923. laThreadNotifier *tn;
  6924. MAIN.CurrentWindow=w;
  6925. //laSpinLock(&MAIN.csNotifier);
  6926. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6927. //laSpinUnlock(&MAIN.csNotifier);
  6928. laNotifyUsers(tn->Path);
  6929. FreeMem(tn);
  6930. //if (MAIN.ThreadNotifiers.pFirst)
  6931. //laSpinLock(&MAIN.csNotifier);
  6932. }
  6933. //laSpinUnlock(&MAIN.csNotifier);
  6934. while (1){
  6935. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6936. while (w->EventList.pFirst){
  6937. while (w->PendingOperators.pLast){
  6938. a = w->PendingOperators.pLast;
  6939. if (a->OperatorPanel){
  6940. laSetOperatorLocalizer(a->OperatorPanel);
  6941. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6942. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6943. }
  6944. lstRemoveItem(&w->PendingOperators, a);
  6945. lstPushItem(&w->Operators, a);
  6946. }
  6947. e = lstPopItem(&w->EventList);
  6948. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6949. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6950. memFree(e);
  6951. }
  6952. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  6953. if (!MAIN.ReTriggerOperators) break;
  6954. }
  6955. la_UpdateOperatorHints(w);
  6956. return 1;
  6957. }
  6958. int la_AllowInput(uint32_t ch){
  6959. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6960. return 0;
  6961. }
  6962. int laCopyToClipboard(unsigned char * text){
  6963. #ifdef LA_LINUX
  6964. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6965. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6966. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6967. strSafeSet(&MAIN.CopyPending, text);
  6968. #endif
  6969. }
  6970. int la_ProcessSysMessage(){
  6971. int SendDelay = 0, SendIdle = 0;
  6972. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6973. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6974. #ifdef LA_LINUX
  6975. XEvent e;
  6976. int type;
  6977. int InputCount = 0, CharCount=0;
  6978. KeySym InputKeysym = 0;
  6979. Status InputStatus = 0;
  6980. laWindow* wnd ;
  6981. while(XPending(MAIN.dpy)){
  6982. XGenericEventCookie *cookie = &e.xcookie;
  6983. XNextEvent(MAIN.dpy, &e);
  6984. if (XFilterEvent(&e, None)) continue;
  6985. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6986. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6987. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6988. XFreeEventData(MAIN.dpy, cookie); continue;
  6989. }
  6990. switch(e.type){
  6991. case ConfigureNotify:
  6992. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6993. break;
  6994. case Expose:
  6995. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6996. if(!wnd) break;
  6997. laRefreshWindow(wnd);
  6998. break;
  6999. case MotionNotify:
  7000. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  7001. MAIN.IsPen=0;
  7002. break;
  7003. case ButtonPress:
  7004. type=LA_MOUSEDOWN;
  7005. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7006. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7007. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7008. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7009. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7010. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7011. MAIN.IsPen=0;
  7012. break;
  7013. case ButtonRelease:
  7014. type=LA_MOUSEUP;
  7015. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7016. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7017. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7018. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7019. MAIN.IsPen=0;
  7020. break;
  7021. case KeyPress:
  7022. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7023. MAIN.InputBuf[InputCount]=0;
  7024. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7025. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7026. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7027. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7028. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7029. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7030. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7031. #ifdef DEBUG
  7032. printf("pressed KEY: %d\n", (int)InputKeysym);
  7033. #endif
  7034. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7035. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7036. }
  7037. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7038. }
  7039. break;
  7040. case KeyRelease:
  7041. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7042. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7043. }
  7044. case ClientMessage:
  7045. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7046. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7047. }
  7048. break;
  7049. case SelectionNotify:
  7050. if(e.xselection.selection != MAIN.bufid) continue;
  7051. if (e.xselection.property){
  7052. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7053. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7054. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7055. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7056. else if(result) {
  7057. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7058. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7059. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7060. }
  7061. XFree(result);
  7062. return True;
  7063. }
  7064. case SelectionRequest:
  7065. if(!MAIN.CopyPending){ break; }
  7066. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7067. if (e.xselectionrequest.selection != MAIN.selection) break;
  7068. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7069. XSelectionEvent ev = {0};
  7070. int R = 0;
  7071. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7072. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7073. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7074. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7075. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7076. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7077. else if (ev.target == MAIN.UTF8)
  7078. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7079. else ev.property = None;
  7080. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7081. break;
  7082. case SelectionClear:
  7083. break;
  7084. default:
  7085. break;
  7086. }
  7087. }
  7088. #endif //linux
  7089. #ifdef _WIN32
  7090. MSG msg; int Processed = 0;
  7091. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7092. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7093. if (msg.wParam == VK_PROCESSKEY) {
  7094. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7095. }
  7096. TranslateMessage(&msg); DispatchMessage(&msg);
  7097. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7098. };
  7099. if(!MAIN.Windows.pFirst){ return 0; }
  7100. #endif
  7101. #ifdef LAGUI_ANDROID
  7102. int pollResult = 0;
  7103. int pollEvents = 0;
  7104. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7105. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7106. // NOTE: Never close window, native activity is controlled by the system!
  7107. if (MAIN.app->destroyRequested != 0)
  7108. {
  7109. //CORE.Window.shouldClose = true;
  7110. //ANativeActivity_finish(MAIN.app->activity);
  7111. }
  7112. }
  7113. #endif
  7114. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7115. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7116. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7117. }
  7118. return 1;
  7119. };
  7120. void la_PrintOperatorStack(){
  7121. laWindow *w = MAIN.CurrentWindow;
  7122. laOperator *a;
  7123. printf("\n");
  7124. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7125. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7126. a->Type->Identifier, a->Instance,
  7127. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7128. }
  7129. }
  7130. void la_DrawWindow(laWindow *w){
  7131. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7132. MAIN.CurrentWindow = w;
  7133. la_WindowDefDraw(w, 0);
  7134. }
  7135. int laFinalize(){
  7136. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7137. laUiTemplate* uit;
  7138. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7139. return 1;
  7140. }
  7141. void la_PreFrame(){
  7142. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7143. la_AnimationPreFrame();
  7144. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7145. }
  7146. void la_PostFrame(){
  7147. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7148. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7149. }
  7150. void laMainLoop(){
  7151. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7152. laTimeRecorder FrameStartTime, FrameEndTime;
  7153. time_t t1, t2;
  7154. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7155. static int a = 0;
  7156. if(!laFinalize()) return;
  7157. laSetWindowCursor(LA_ARROW);
  7158. MAIN.DelayTriggered=1;
  7159. #ifdef LAGUI_ANDROID
  7160. while(!MAIN.AppReady){ usleep(1000); }
  7161. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7162. #endif
  7163. while (1){
  7164. laRecordTime(&FrameStartTime);
  7165. la_PreFrame();
  7166. if(!la_ProcessSysMessage()){ return; }
  7167. la_UpdateControllerStatus();
  7168. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7169. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7170. NextW = w->Item.pNext;
  7171. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7172. }
  7173. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7174. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7175. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7176. if(MAIN.GLDebugNeedsUpdate){
  7177. la_SetCurrentGLContextDebug();
  7178. }
  7179. la_DrawWindow(w);
  7180. }
  7181. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7182. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7183. #ifdef LA_LINUX
  7184. #ifdef LA_USE_GLES
  7185. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7186. #else
  7187. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7188. #endif
  7189. #endif
  7190. #ifdef _WIN32
  7191. SwapBuffers(w->hdc);
  7192. #endif
  7193. #ifdef LAGUI_ANDROID
  7194. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7195. #endif
  7196. }
  7197. MAIN.GLDebugNeedsUpdate=0;
  7198. la_PostFrame();
  7199. //t2 = clock();
  7200. laRecordTime(&FrameEndTime);
  7201. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  7202. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7203. if (Pause > 0){
  7204. int us = Pause * 1000000.0;
  7205. usleep(us);
  7206. }
  7207. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7208. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7209. la_AnimationPostFrame();
  7210. }
  7211. }
  7212. #ifdef LAGUI_ANDROID
  7213. int la_AndroidInitGraphics(void){
  7214. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7215. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7216. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7217. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7218. EGLint samples = 0;
  7219. EGLint sampleBuffer = 0;
  7220. const EGLint framebufferAttribs[] = {
  7221. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7222. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7223. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7224. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7225. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7226. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7227. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7228. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7229. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7230. EGL_NONE
  7231. };
  7232. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7233. EGLint numConfigs = 0;
  7234. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7235. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7236. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7237. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7238. eglBindAPI(EGL_OPENGL_API);
  7239. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7240. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7241. EGLint displayFormat = 0;
  7242. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7243. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7244. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7245. // There must be at least one frame displayed before the buffers are swapped
  7246. eglSwapInterval(MAIN.egl_dpy, 1);
  7247. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7248. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7249. MAIN.AppReady = 1;
  7250. return 0;
  7251. }
  7252. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7253. switch (cmd){
  7254. case APP_CMD_START: break;
  7255. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7256. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7257. case APP_CMD_RESUME:break;//InitPlatform();break;
  7258. case APP_CMD_INIT_WINDOW:
  7259. if (app->window != NULL){
  7260. if (MAIN.ContextRebindRequired){
  7261. // Reset screen scaling to full display size
  7262. EGLint displayFormat = 0;
  7263. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7264. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7265. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7266. // appropriate way to fix this
  7267. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7268. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7269. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7270. displayFormat);
  7271. // Recreate display surface and re-attach OpenGL context
  7272. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7273. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7274. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7275. //glClearColor(1,0.2,1,1);
  7276. //glClear(GL_COLOR_BUFFER_BIT);
  7277. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7278. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7279. MAIN.ContextRebindRequired = false;
  7280. }else{
  7281. la_AndroidInitGraphics();
  7282. }
  7283. }
  7284. break;
  7285. case APP_CMD_TERM_WINDOW:
  7286. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7287. // 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.
  7288. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7289. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7290. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7291. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7292. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7293. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7294. MAIN.egl_surf = EGL_NO_SURFACE;
  7295. }
  7296. MAIN.ContextRebindRequired = true;
  7297. }
  7298. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7299. // this means that the user has already called 'CloseWindow()'
  7300. break;
  7301. case APP_CMD_SAVE_STATE: break;
  7302. case APP_CMD_STOP: break;
  7303. case APP_CMD_DESTROY: break;
  7304. case APP_CMD_CONFIG_CHANGED:
  7305. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7306. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7307. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7308. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7309. //print_cur_config(MAIN.app);
  7310. // Check screen orientation here!
  7311. break;
  7312. default: break;
  7313. }
  7314. }
  7315. #define KEYCODE_MAP_SIZE 162
  7316. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7317. 0, // AKEYCODE_UNKNOWN
  7318. 0, // AKEYCODE_SOFT_LEFT
  7319. 0, // AKEYCODE_SOFT_RIGHT
  7320. 0, // AKEYCODE_HOME
  7321. 0, // AKEYCODE_BACK
  7322. 0, // AKEYCODE_CALL
  7323. 0, // AKEYCODE_ENDCALL
  7324. '0', // AKEYCODE_0
  7325. '1', // AKEYCODE_1
  7326. '2', // AKEYCODE_2
  7327. '3', // AKEYCODE_3
  7328. '4', // AKEYCODE_4
  7329. '5', // AKEYCODE_5
  7330. '6', // AKEYCODE_6
  7331. '7', // AKEYCODE_7
  7332. '8', // AKEYCODE_8
  7333. '9', // AKEYCODE_9
  7334. 0, // AKEYCODE_STAR
  7335. 0, // AKEYCODE_POUND
  7336. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7337. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7338. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7339. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7340. 0, // AKEYCODE_DPAD_CENTER
  7341. 0, // AKEYCODE_VOLUME_UP
  7342. 0, // AKEYCODE_VOLUME_DOWN
  7343. 0, // AKEYCODE_POWER
  7344. 0, // AKEYCODE_CAMERA
  7345. 0, // AKEYCODE_CLEAR
  7346. 'a', // AKEYCODE_A
  7347. 'b', // AKEYCODE_B
  7348. 'c', // AKEYCODE_C
  7349. 'd', // AKEYCODE_D
  7350. 'e', // AKEYCODE_E
  7351. 'f', // AKEYCODE_F
  7352. 'g', // AKEYCODE_G
  7353. 'h', // AKEYCODE_H
  7354. 'i', // AKEYCODE_I
  7355. 'j', // AKEYCODE_J
  7356. 'k', // AKEYCODE_K
  7357. 'l', // AKEYCODE_L
  7358. 'm', // AKEYCODE_M
  7359. 'n', // AKEYCODE_N
  7360. 'o', // AKEYCODE_O
  7361. 'p', // AKEYCODE_P
  7362. 'q', // AKEYCODE_Q
  7363. 'r', // AKEYCODE_R
  7364. 's', // AKEYCODE_S
  7365. 't', // AKEYCODE_T
  7366. 'u', // AKEYCODE_U
  7367. 'v', // AKEYCODE_V
  7368. 'w', // AKEYCODE_W
  7369. 'x', // AKEYCODE_X
  7370. 'y', // AKEYCODE_Y
  7371. 'z', // AKEYCODE_Z
  7372. ',', // AKEYCODE_COMMA
  7373. '.', // AKEYCODE_PERIOD
  7374. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7375. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7376. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7377. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7378. LA_KEY_TAB, // AKEYCODE_TAB
  7379. ' ', // AKEYCODE_SPACE
  7380. 0, // AKEYCODE_SYM
  7381. 0, // AKEYCODE_EXPLORER
  7382. 0, // AKEYCODE_ENVELOPE
  7383. LA_KEY_ENTER, // AKEYCODE_ENTER
  7384. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7385. '`', // AKEYCODE_GRAVE
  7386. '-', // AKEYCODE_MINUS
  7387. '=', // AKEYCODE_EQUALS
  7388. '(', // AKEYCODE_LEFT_BRACKET
  7389. ')', // AKEYCODE_RIGHT_BRACKET
  7390. '\\', // AKEYCODE_BACKSLASH
  7391. ';', // AKEYCODE_SEMICOLON
  7392. '\'', // AKEYCODE_APOSTROPHE
  7393. '/', // AKEYCODE_SLASH
  7394. 0, // AKEYCODE_AT
  7395. 0, // AKEYCODE_NUM
  7396. 0, // AKEYCODE_HEADSETHOOK
  7397. 0, // AKEYCODE_FOCUS
  7398. 0, // AKEYCODE_PLUS
  7399. 0, // AKEYCODE_MENU
  7400. 0, // AKEYCODE_NOTIFICATION
  7401. 0, // AKEYCODE_SEARCH
  7402. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7403. 0, // AKEYCODE_MEDIA_STOP
  7404. 0, // AKEYCODE_MEDIA_NEXT
  7405. 0, // AKEYCODE_MEDIA_PREVIOUS
  7406. 0, // AKEYCODE_MEDIA_REWIND
  7407. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7408. 0, // AKEYCODE_MUTE
  7409. 0, // AKEYCODE_PAGE_UP
  7410. 0, // AKEYCODE_PAGE_DOWN
  7411. 0, // AKEYCODE_PICTSYMBOLS
  7412. 0, // AKEYCODE_SWITCH_CHARSET
  7413. 0, // AKEYCODE_BUTTON_A
  7414. 0, // AKEYCODE_BUTTON_B
  7415. 0, // AKEYCODE_BUTTON_C
  7416. 0, // AKEYCODE_BUTTON_X
  7417. 0, // AKEYCODE_BUTTON_Y
  7418. 0, // AKEYCODE_BUTTON_Z
  7419. 0, // AKEYCODE_BUTTON_L1
  7420. 0, // AKEYCODE_BUTTON_R1
  7421. 0, // AKEYCODE_BUTTON_L2
  7422. 0, // AKEYCODE_BUTTON_R2
  7423. 0, // AKEYCODE_BUTTON_THUMBL
  7424. 0, // AKEYCODE_BUTTON_THUMBR
  7425. 0, // AKEYCODE_BUTTON_START
  7426. 0, // AKEYCODE_BUTTON_SELECT
  7427. 0, // AKEYCODE_BUTTON_MODE
  7428. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7429. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7430. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7431. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7432. 0, // AKEYCODE_CAPS_LOCK
  7433. 0, // AKEYCODE_SCROLL_LOCK
  7434. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7435. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7436. 0, // AKEYCODE_FUNCTION
  7437. 0, // AKEYCODE_SYSRQ
  7438. 0, // AKEYCODE_BREAK
  7439. 0, // AKEYCODE_MOVE_HOME
  7440. 0, // AKEYCODE_MOVE_END
  7441. 0, // AKEYCODE_INSERT
  7442. 0, // AKEYCODE_FORWARD
  7443. 0, // AKEYCODE_MEDIA_PLAY
  7444. 0, // AKEYCODE_MEDIA_PAUSE
  7445. 0, // AKEYCODE_MEDIA_CLOSE
  7446. 0, // AKEYCODE_MEDIA_EJECT
  7447. 0, // AKEYCODE_MEDIA_RECORD
  7448. LA_KEY_F1, // AKEYCODE_F1
  7449. LA_KEY_F2, // AKEYCODE_F2
  7450. LA_KEY_F3, // AKEYCODE_F3
  7451. LA_KEY_F4, // AKEYCODE_F4
  7452. LA_KEY_F5, // AKEYCODE_F5
  7453. LA_KEY_F6, // AKEYCODE_F6
  7454. LA_KEY_F7, // AKEYCODE_F7
  7455. LA_KEY_F8, // AKEYCODE_F8
  7456. LA_KEY_F9, // AKEYCODE_F9
  7457. LA_KEY_F10, // AKEYCODE_F10
  7458. LA_KEY_F11, // AKEYCODE_F11
  7459. LA_KEY_F12, // AKEYCODE_F12
  7460. 0, // AKEYCODE_NUM_LOCK
  7461. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7462. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7463. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7464. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7465. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7466. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7467. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7468. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7469. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7470. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7471. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7472. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7473. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7474. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7475. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7476. 0, // AKEYCODE_NUMPAD_COMMA
  7477. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7478. '=' // AKEYCODE_NUMPAD_EQUALS
  7479. };
  7480. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7481. {
  7482. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7483. if(!MAIN.AppEnabled){return 0;}
  7484. //laRedrawAllWindows();
  7485. int type = AInputEvent_getType(event);
  7486. if(type == AINPUT_EVENT_TYPE_KEY){
  7487. int32_t keycode = AKeyEvent_getKeyCode(event);
  7488. //int32_t AKeyEvent_getMetaState(event);
  7489. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7490. if (key != 0){
  7491. // Save current key and its state
  7492. // NOTE: Android key action is 0 for down and 1 for up
  7493. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7494. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7495. if(key!=LA_KEY_BACKSPACE)
  7496. la_SendInputEvent(0,key);
  7497. }
  7498. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7499. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7500. la_SendInputEvent(0,key);
  7501. }
  7502. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7503. }
  7504. if (keycode == AKEYCODE_POWER)
  7505. {
  7506. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7507. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7508. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7509. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7510. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7511. return 0;
  7512. }
  7513. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7514. {
  7515. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7516. return 1;
  7517. }
  7518. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7519. {
  7520. // Set default OS behaviour
  7521. return 0;
  7522. }
  7523. return 0;
  7524. }
  7525. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7526. int pcount = AMotionEvent_getPointerCount(event); int x,y;
  7527. if(pcount){
  7528. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7529. x=rx; y=ry;
  7530. }
  7531. int32_t action = AMotionEvent_getAction(event);
  7532. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7533. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7534. if (flags == AMOTION_EVENT_ACTION_DOWN){
  7535. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7536. la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
  7537. }
  7538. else if (flags == AMOTION_EVENT_ACTION_UP){
  7539. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7540. }
  7541. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7542. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7543. }
  7544. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7545. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7546. }
  7547. }
  7548. //static float r=0;
  7549. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7550. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7551. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7552. //glClear(GL_COLOR_BUFFER_BIT);
  7553. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7554. return 0;
  7555. }
  7556. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7557. MAIN.AssetManager = manager;
  7558. MAIN.InternalDataPath = dataPath;
  7559. MAIN.ExternalDataPath = externalDataPath;
  7560. }
  7561. static int android_read(void *cookie, char *data, int dataSize){
  7562. return AAsset_read((AAsset *)cookie, data, dataSize);
  7563. }
  7564. static int android_write(void *cookie, const char *data, int dataSize){
  7565. return 0;
  7566. }
  7567. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7568. return AAsset_seek((AAsset *)cookie, offset, whence);
  7569. }
  7570. static int android_close(void *cookie){
  7571. AAsset_close((AAsset *)cookie);
  7572. return 0;
  7573. }
  7574. // Replacement for fopen()
  7575. // Ref: https://developer.android.com/ndk/reference/group/asset
  7576. FILE *android_fopen(const char *fileName, const char *mode)
  7577. {
  7578. char buf[1024];
  7579. if (mode[0] == 'w')
  7580. {
  7581. // fopen() is mapped to android_fopen() that only grants read access to
  7582. // assets directory through AAssetManager but we want to also be able to
  7583. // write data when required using the standard stdio FILE access functions
  7584. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7585. #undef fopen
  7586. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7587. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7588. result=fopen(buf, mode); if(result) return result;
  7589. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7590. return fopen(buf, mode);
  7591. #define fopen(name, mode) android_fopen(name, mode)
  7592. }
  7593. else
  7594. {
  7595. // NOTE: AAsset provides access to read-only asset
  7596. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7597. if (asset != NULL)
  7598. {
  7599. // Get pointer to file in the assets
  7600. return funopen(asset, android_read, android_write, android_seek, android_close);
  7601. }
  7602. else
  7603. {
  7604. #undef fopen
  7605. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7606. // Just do a regular open if file is not found in the assets
  7607. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7608. result=fopen(buf, mode); if(result){ return result; }
  7609. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7610. return fopen(buf, mode);
  7611. #define fopen(name, mode) android_fopen(name, mode)
  7612. }
  7613. }
  7614. }
  7615. void la_HideNavBar(){
  7616. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7617. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7618. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7619. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7620. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7621. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7622. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7623. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7624. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7625. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7626. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7627. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7628. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7629. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7630. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7631. int flag = flagFullscreen | flagHideNavigation;
  7632. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7633. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7634. }
  7635. void la_InitAndroidPlatform(struct android_app *app){
  7636. MAIN.app=app;
  7637. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7638. //la_HideNavBar();
  7639. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7640. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7641. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7642. int pollResult = 0;
  7643. int pollEvents = 0;
  7644. while (!MAIN.AppReady){
  7645. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7646. // Process this event
  7647. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7648. // NOTE: Never close window, native activity is controlled by the system!
  7649. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7650. }
  7651. }
  7652. }
  7653. int main(int, char *[]);
  7654. void android_main(struct android_app *app){
  7655. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7656. la_InitAndroidPlatform(app);
  7657. // NOTE: Return from main is ignored
  7658. (void)main(1, (char *[]) { arg0, NULL });
  7659. // Request to end the native activity
  7660. ANativeActivity_finish(app->activity);
  7661. // Android ALooper_pollAll() variables
  7662. int pollResult = 0;
  7663. int pollEvents = 0;
  7664. // Waiting for application events before complete finishing
  7665. while (!app->destroyRequested)
  7666. {
  7667. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7668. {
  7669. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7670. }
  7671. }
  7672. }
  7673. void la_DisplayKeyboard(bool pShow) {
  7674. // Attaches the current thread to the JVM.
  7675. jint lResult;
  7676. jint lFlags = 0;
  7677. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7678. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7679. JavaVMAttachArgs lJavaVMAttachArgs;
  7680. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7681. lJavaVMAttachArgs.name = "NativeThread";
  7682. lJavaVMAttachArgs.group = NULL;
  7683. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7684. if (lResult == JNI_ERR) {
  7685. return;
  7686. }
  7687. // Retrieves NativeActivity.
  7688. jobject lNativeActivity = MAIN.app->activity->clazz;
  7689. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7690. logPrintNew("jvm3");
  7691. // Retrieves Context.INPUT_METHOD_SERVICE.
  7692. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7693. jfieldID FieldINPUT_METHOD_SERVICE =
  7694. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7695. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7696. jobject INPUT_METHOD_SERVICE =
  7697. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7698. FieldINPUT_METHOD_SERVICE);
  7699. //jniCheck(INPUT_METHOD_SERVICE);
  7700. logPrintNew("jvm4");
  7701. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7702. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7703. "android/view/inputmethod/InputMethodManager");
  7704. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7705. ClassNativeActivity, "getSystemService",
  7706. "(Ljava/lang/String;)Ljava/lang/Object;");
  7707. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7708. lNativeActivity, MethodGetSystemService,
  7709. INPUT_METHOD_SERVICE);
  7710. // Runs getWindow().getDecorView().
  7711. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7712. ClassNativeActivity, "getWindow",
  7713. "()Landroid/view/Window;");
  7714. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7715. MethodGetWindow);
  7716. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7717. "android/view/Window");
  7718. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7719. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7720. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7721. MethodGetDecorView);
  7722. if (pShow) {
  7723. // Runs lInputMethodManager.showSoftInput(...).
  7724. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7725. ClassInputMethodManager, "showSoftInput",
  7726. "(Landroid/view/View;I)Z");
  7727. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7728. lInputMethodManager, MethodShowSoftInput,
  7729. lDecorView, lFlags);
  7730. } else {
  7731. // Runs lWindow.getViewToken()
  7732. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7733. "android/view/View");
  7734. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7735. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7736. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7737. MethodGetWindowToken);
  7738. // lInputMethodManager.hideSoftInput(...).
  7739. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7740. ClassInputMethodManager, "hideSoftInputFromWindow",
  7741. "(Landroid/os/IBinder;I)Z");
  7742. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7743. lInputMethodManager, MethodHideSoftInput,
  7744. lBinder, lFlags);
  7745. }
  7746. // Finished with the JVM.
  7747. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7748. }
  7749. #endif //android
  7750. #ifndef LAGUI_ANDROID
  7751. void la_DisplayKeyboard(bool pShow) {
  7752. return;
  7753. }
  7754. void la_HideNavBar(){
  7755. return;
  7756. }
  7757. #endif