*/}}

la_kernel.c 330 KB

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