*/}}

la_kernel.c 344 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  19. #define NANOVG_GLES3_IMPLEMENTATION
  20. #else
  21. #define NANOVG_GL3_IMPLEMENTATION
  22. #endif
  23. #include "la_5.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <time.h>
  28. #ifdef LA_LINUX
  29. #include <execinfo.h>
  30. #include <signal.h>
  31. #include <sys/time.h>
  32. #include <X11/Xlib.h>
  33. #include <X11/Xutil.h>
  34. #include <X11/Xos.h>
  35. #include <X11/keysymdef.h>
  36. #include <X11/XKBlib.h>
  37. #include <X11/extensions/XInput.h>
  38. #include <X11/extensions/XInput2.h>
  39. #include <X11/extensions/Xfixes.h>
  40. #include <X11/extensions/Xrandr.h>
  41. #include <X11/Xcursor/Xcursor.h>
  42. #include <X11/cursorfont.h>
  43. #include <GL/glx.h>
  44. #endif
  45. #ifdef _WIN32
  46. #include <GL/wglew.h>
  47. #include <GL/wgl.h>
  48. #include <shellscalingapi.h>
  49. #endif
  50. #ifdef LAGUI_ANDROID
  51. #include <GLES3/gl32.h>
  52. #include <jni.h>
  53. #include <android/log.h>
  54. #include <android/native_activity.h>
  55. #include <android/native_window.h>
  56. #include <android/native_window_jni.h>
  57. #include <android_native_app_glue.h>
  58. #include <android/window.h>
  59. #include <android/asset_manager.h>
  60. #include <android/input.h>
  61. #include <android/keycodes.h>
  62. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  63. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  64. static int android_read(void *cookie, char *buf, int size);
  65. static int android_write(void *cookie, const char *buf, int size);
  66. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  67. static int android_close(void *cookie);
  68. void la_InitAndroidPlatform(struct android_app *app);
  69. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  70. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  71. void la_InitAndroidPlatform(struct android_app *app);
  72. #endif
  73. LA MAIN={0};
  74. extern tnsMain *T;
  75. int deb = 0;
  76. laOperator *DEB;
  77. laColumn *DEBUG_C;
  78. #ifdef _WIN32
  79. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  80. #else
  81. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  82. #endif
  83. #ifdef LA_LINUX
  84. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  85. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  86. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  87. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  88. #endif
  89. #ifdef LA_LINUX
  90. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  91. int i;
  92. for (i = 0; i < num_classes; i++) {
  93. if (classes[i]->type == XIValuatorClass) {
  94. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  95. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  96. logPrint(" Range: %f - %f\n", v->min, v->max);
  97. logPrint(" Resolution: %d units/m\n", v->resolution);
  98. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  99. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  100. }
  101. }
  102. }
  103. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  104. XIDeviceInfo *info, *dev;
  105. int i, ndevices;
  106. dev = XIQueryDevice(display, deviceid, &ndevices);
  107. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  108. mask->deviceid = deviceid;
  109. mask->mask_len = XIMaskLen(XI_RawMotion);
  110. mask->mask=memAcquireSimple(mask->mask_len);
  111. memset(mask->mask, 0, mask->mask_len);
  112. XISetMask(mask->mask, XI_RawMotion);
  113. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  114. int FoundMax=0;
  115. for (i = 0; i < dev->num_classes; i++) {
  116. if (dev->classes[i]->type == XIValuatorClass) {
  117. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  118. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  119. }
  120. }
  121. if(!FoundMax){*max_pressure=65535;}
  122. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  123. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  124. XIFreeDeviceInfo(dev);
  125. }
  126. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  127. int axis=0;
  128. for (int i = 0; i < dev->num_classes; i++) {
  129. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  130. }
  131. return axis>=3;
  132. }
  133. #define LA_G_STYLUS(dev) \
  134. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  135. #define LA_G_ERASER \
  136. (!MAIN.WacomDeviceEraser)
  137. void la_ScanWacomDevices(Display *display, int deviceid){
  138. XIDeviceInfo *info, *dev;
  139. int ndevices;
  140. int i; char * word;
  141. int _event, _error;
  142. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  143. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  144. }
  145. info = XIQueryDevice(display, deviceid, &ndevices);
  146. for(i = 0; i < ndevices; i++) {
  147. dev = &info[i]; strToLower(dev->name);
  148. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  149. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  150. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  151. word = strtok (dev->name," ");
  152. while (1) {
  153. word = strtok (NULL, " "); if (!word) break;
  154. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  155. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  156. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  157. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  158. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  159. }
  160. }
  161. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  162. logPrintNew("Found wacom devices:\n");
  163. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  164. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  165. }else{
  166. logPrintNew("No wacom pen device connected.\n");
  167. }
  168. XIFreeDeviceInfo(info);
  169. }
  170. void laHideCursor(){
  171. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  172. }
  173. void laShowCursor(){
  174. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  175. }
  176. void la_XErrorHandler(Display *display, XErrorEvent *event){
  177. char buf[512];
  178. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  179. printf("X Error:\n%s\n",buf);
  180. }
  181. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  182. XSetWindowAttributes swa;
  183. XWindowAttributes wa;
  184. swa.event_mask =
  185. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  186. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  187. swa.colormap = MAIN.cmap;
  188. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  189. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  190. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  191. if(x>0||y>0){
  192. XSizeHints my_hints = {0};
  193. my_hints.flags = PPosition;
  194. my_hints.x = x; my_hints.y = y;
  195. XSetNormalHints(MAIN.dpy, win, &my_hints);
  196. }
  197. XStoreName(MAIN.dpy, win, title);
  198. #ifdef LA_USE_GLES
  199. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  200. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  201. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  202. EGLSurface* surf=egl_surf;
  203. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  204. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  205. tnsContextMakeCurrent((*r_glc),win,(*surf));
  206. #else
  207. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  208. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  209. printf("\n\tcannot create gl context\n\n"); exit(0);
  210. }
  211. tnsContextMakeCurrent((*r_glc),win,0);
  212. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  213. #endif
  214. XSetLocaleModifiers("");
  215. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  216. if(!MAIN.im){
  217. XSetLocaleModifiers("@im=local");
  218. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  219. }
  220. if(!MAIN.im){
  221. XSetLocaleModifiers("@im=none");
  222. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  223. }
  224. if(!MAIN.im){
  225. XSetLocaleModifiers("@im=");
  226. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  227. }
  228. if(!MAIN.im){
  229. logPrint("Can't open a input method.\n");
  230. }
  231. if(MAIN.im){
  232. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  233. XSetICFocus(MAIN.ic);
  234. }
  235. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  236. XSetClassHint(MAIN.dpy, win, &ch);
  237. #define _NET_WM_STATE_ADD 1
  238. if(w<0&&h<0){
  239. XEvent xev;
  240. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  241. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  242. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  243. memset(&xev, 0, sizeof(xev));
  244. xev.type = ClientMessage;
  245. xev.xclient.window = win;
  246. xev.xclient.message_type = wm_state;
  247. xev.xclient.format = 32;
  248. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  249. xev.xclient.data.l[1] = max_horz;
  250. xev.xclient.data.l[2] = max_vert;
  251. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  252. }
  253. return win;
  254. };
  255. void la_DestroySystemWindowX11(laWindow* w) {
  256. tnsContextMakeCurrent(0,0,0);
  257. tnsDeleteContext(w->glc);
  258. #ifdef LA_USE_GLES
  259. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  260. #endif
  261. XDestroyWindow(MAIN.dpy, w->win);
  262. };
  263. #endif //linux
  264. #ifdef _WIN32
  265. #include <msgdef.h>
  266. #include <wintab.h>
  267. #include <wintab_utils.h>
  268. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  269. #define PACKETMODE PK_BUTTONS
  270. #include <pktdef.h>
  271. void la_OpenWacomWinTab(HWND hwnd){
  272. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  273. static LOGCONTEXT glogContext = { 0 };
  274. HCTX hctx = NULL;
  275. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  276. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  277. glogContext.lcOptions |= CXO_SYSTEM;
  278. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  279. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  280. assert(glogContext.lcOptions & CXO_SYSTEM);
  281. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  282. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  283. glogContext.lcPktData = PACKETDATA;
  284. glogContext.lcPktMode = PACKETMODE;
  285. glogContext.lcMoveMask = PACKETDATA;
  286. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  290. assert(wWTInfoRetVal == sizeof(AXIS));
  291. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  292. if (wWTInfoRetVal) {
  293. assert(wWTInfoRetVal == sizeof(AXIS));
  294. MAIN.WinTabMaxHover = TabletZ.axMax;
  295. }
  296. AXIS tabletPressure = { 0 };
  297. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  298. //glogContext.lcInOrgX = 0;
  299. //glogContext.lcInOrgY = 0;
  300. //glogContext.lcInExtX = TabletX.axMax;
  301. //glogContext.lcInExtY = TabletY.axMax;
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  312. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  313. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  314. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  315. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  316. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  317. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  318. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  319. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  320. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  321. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  322. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  323. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  324. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  325. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  326. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  327. if (!hctx)return;
  328. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  329. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  330. }
  331. void laHideCursor() {
  332. if (!MAIN.CurrentWindow) return; //impl
  333. }
  334. void laShowCursor() {
  335. if (!MAIN.CurrentWindow) return; //impl
  336. }
  337. static PIXELFORMATDESCRIPTOR cpfd = {
  338. sizeof(PIXELFORMATDESCRIPTOR),1,
  339. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  340. PFD_TYPE_RGBA,
  341. 8,
  342. 0, 0, 0, 0, 0, 0,
  343. 0, 0, 0,
  344. 0, 0, 0, 0,
  345. 32,
  346. 8, 0,
  347. 0,
  348. 0, 0, 0, 0
  349. };
  350. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  351. int nBestMS = 0;
  352. int i;
  353. int iResults[9];
  354. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  355. WGL_ACCELERATION_ARB, // 1
  356. WGL_DRAW_TO_WINDOW_ARB, // 2
  357. WGL_DOUBLE_BUFFER_ARB, // 3
  358. WGL_PIXEL_TYPE_ARB, // 4
  359. WGL_DEPTH_BITS_ARB, // 5
  360. WGL_STENCIL_BITS_ARB, // 6
  361. WGL_SAMPLE_BUFFERS_ARB, // 7
  362. WGL_SAMPLES_ARB }; // 8
  363. // How many pixelformats are there?
  364. int nFormatCount[] = { 0 };
  365. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  366. if (!wglGetPixelFormatAttribivARB)
  367. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  368. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  369. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  370. for (i = 0; i < nFormatCount[0]; i++){
  371. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  372. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  373. if (iResults[3] == 1) // Double buffered
  374. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  375. if (iResults[5] >= 24) // Any Depth greater than 16
  376. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  377. }
  378. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  379. };
  380. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  381. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  382. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  383. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  384. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  385. 0 };
  386. HGLRC hglrc = 0;
  387. HDC hdc = 0;
  388. int a, b;
  389. hdc = GetDC(hwnd);
  390. la_SetupPxlFormat(hdc, &a, &b);
  391. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  392. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  393. tnsContextMakeCurrent(hglrc, hdc,0);
  394. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  395. wglSwapIntervalEXT(-1);
  396. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  397. };
  398. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  399. HINSTANCE* inst = &MAIN.hinstance;
  400. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  401. x, y, w, h, 0, 0, *inst, 0);
  402. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  403. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  404. return hwnd;
  405. };
  406. void la_DestroySystemWindowWin32(laWindow* w) {
  407. tnsContextMakeCurrent(0,0,0);
  408. tnsDeleteContext(w->glc);
  409. ReleaseDC(w->win, w->hdc);
  410. DestroyWindow(w->win);
  411. };
  412. #endif
  413. #ifdef LAGUI_ANDROID
  414. SYSWINDOW la_CreateWindowAndroid(){
  415. return 0;
  416. };
  417. void laShowCursor(){}
  418. void laHideCursor(){}
  419. #endif
  420. #ifdef LA_LINUX
  421. void la_HandlerSIGSEGV(int sig) {
  422. void *array[30];
  423. size_t sz;
  424. sz = backtrace(array, 30);
  425. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  426. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  427. exit(1);
  428. }
  429. #endif
  430. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  431. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  432. //#ifndef LAGUI_ANDROID
  433. // ignore non-significant error/warning codes
  434. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  435. logPrint("GL %d: %s\n", id, message);
  436. char* strsource="",*strtype="",*strseverity="";
  437. switch (source) {
  438. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  439. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  440. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  441. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  442. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  443. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  444. }
  445. switch (type) {
  446. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  447. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  448. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  449. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  450. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  451. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  452. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  453. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  454. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  455. }
  456. switch (severity) {
  457. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  458. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  459. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  460. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  461. }
  462. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  463. //#endif
  464. }
  465. void la_SetCurrentGLContextDebug(){
  466. //#ifndef LAGUI_ANDROID
  467. int force=MAIN.InitArgs.GLDebug;
  468. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  469. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  470. glDebugMessageCallback(la_glDebugOutput, 0);
  471. int sev=GL_DONT_CARE;
  472. if(!force){
  473. switch(MAIN.GLDebugLevel){
  474. default: sev=GL_DONT_CARE; break;
  475. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  476. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  477. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  478. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  479. }
  480. }
  481. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  482. //#endif
  483. }
  484. void la_NotifyGLDebugChanges(){
  485. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  486. }
  487. void la_SetupWindowGLStates(laWindow* w){
  488. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  489. if(w->GLDebugNeedsUpdate){
  490. tnsContextMakeWindowCurrent(w);
  491. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  492. }
  493. }
  494. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  495. SYSGLCONTEXT glc;
  496. #ifdef LA_LINUX
  497. void* egl_surf=0;
  498. #ifdef LA_USE_GLES
  499. egl_surf=&window->egl_surf;
  500. #endif
  501. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  502. #endif
  503. #ifdef _WIN32
  504. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  505. #endif
  506. #ifdef LAGUI_ANDROID
  507. la_CreateWindowAndroid();
  508. window->win = 1;
  509. window->glc = MAIN.glc;
  510. #else
  511. window->win = hwnd;
  512. window->glc = glc;
  513. #endif
  514. #ifdef _WIN32
  515. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  516. RECT rc; GetClientRect(window->win, &rc);
  517. window->CW = rc.right - rc.left;
  518. window->CH = rc.bottom - rc.top;
  519. #endif
  520. #ifdef LA_LINUX
  521. XWindowAttributes attr;
  522. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  523. window->CW =attr.width;
  524. window->CH = attr.height;
  525. #endif
  526. la_SetCurrentGLContextDebug();
  527. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  528. la_SetupWindowGLStates(window);
  529. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  530. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #else
  532. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  533. #endif
  534. window->OutputShowStripes=1; window->Redraw=1;
  535. window->GLDebugNeedsUpdate=1;
  536. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  537. return 1;
  538. };
  539. int la_DestroySystemWindow(laWindow* wnd){
  540. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  541. nvgDeleteGLES3(wnd->nvg);
  542. #else
  543. nvgDeleteGL3(wnd->nvg);
  544. #endif
  545. #ifdef LA_LINUX
  546. la_DestroySystemWindowX11(wnd);
  547. #endif
  548. #ifdef _WIN32
  549. la_DestroySystemWindowWin32(wnd);
  550. #endif
  551. }
  552. void la_DestroyWindow(laWindow *wnd){
  553. laLayout *l; laPanel *p; if (!wnd) return;
  554. tnsSwitchToCurrentWindowContext(wnd);
  555. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  556. la_StopAllOperators();
  557. strSafeDestroy(&wnd->Title);
  558. //la_PrintUserList(wnd);
  559. //printf("----\n");
  560. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  561. while (l = lstPopItem(&wnd->Layouts)){
  562. laDestroyBlocksRecursive(l->FirstBlock);
  563. //la_PrintUserList(l);
  564. //printf("%x %s\n", l, l->ID->Ptr);
  565. strSafeDestroy(&l->ID);
  566. memFree(l);
  567. //la_PrintUserList(wnd);
  568. //printf("----\n");
  569. }
  570. //printf("----\n%x\n",wnd);
  571. //la_PrintUserList(wnd);
  572. la_DestroySystemWindow(wnd);
  573. lstRemoveItem(&MAIN.Windows, wnd);
  574. memFree(wnd);
  575. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  576. }
  577. void laRenameWindow(laWindow* wnd, char* name){
  578. if((!wnd)||MAIN.IsReadingUDF) return;
  579. strSafeSet(&wnd->Title, name);
  580. if(!wnd->win) return;
  581. #ifdef LA_LINUX
  582. XStoreName(MAIN.dpy, wnd->win, name);
  583. #endif
  584. #ifdef _WIN32
  585. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  586. SetWindowTextW(wnd->win, name);
  587. #endif
  588. }
  589. #ifdef LA_LINUX
  590. const char* la_ConvertCursorID(int id){
  591. switch (id) {
  592. case LA_ARROW: return "arrow";
  593. case LA_CROSS: return "cross";
  594. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  595. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  596. case LA_MOVE: return "diamond_cross";
  597. case LA_HAND: return "hand1";
  598. case LA_CORNER: return "bottom_right_corner";
  599. }
  600. return "arrow";
  601. }
  602. #endif
  603. #ifdef _WIN32
  604. HCURSOR la_ConvertCursorID(int id){
  605. switch (id){
  606. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  607. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  608. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  609. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  610. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  611. case LA_HAND: return LoadCursor(0, IDC_HAND);
  612. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  613. }
  614. return LoadCursor(0, IDC_ARROW);;
  615. }
  616. #endif
  617. void la_InitThreadEnviornment(){
  618. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  619. }
  620. laLogEntry* logEnsure(int Create){
  621. if(!MAIN.Logs.pFirst || Create){
  622. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  623. lstAppendItem(&MAIN.Logs, le);
  624. }
  625. return MAIN.Logs.pLast;
  626. }
  627. void logPrintTV(int Continued, char* format, va_list v){
  628. if(!format || !format[0]) return;
  629. laLogEntry* le=logEnsure(Continued);
  630. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  631. strSafePrintV(&le->Content, format, v);
  632. #ifdef LAGUI_ANDROID
  633. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  634. #endif
  635. laNotifyUsers("la.logs");
  636. }
  637. void logPrintT(int Continued, char* format, ...){
  638. if(!format || !format[0]) return;
  639. laLogEntry* le=logEnsure(Continued);
  640. va_list aptr; va_start(aptr, format);
  641. strSafePrint(&le->Content, format, aptr);
  642. va_end(aptr);
  643. #ifdef LAGUI_ANDROID
  644. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  645. #endif
  646. laNotifyUsers("la.logs");
  647. }
  648. void logPrint(char* format, ...){
  649. va_list aptr; va_start(aptr, format);
  650. logPrintTV(0, format, aptr);
  651. va_end(aptr);
  652. }
  653. void logPrintNew(char* format, ...){
  654. logEnsure(1);
  655. va_list aptr; va_start(aptr, format);
  656. logPrintTV(0, format, aptr);
  657. va_end(aptr);
  658. }
  659. void logClear(){
  660. laLogEntry*l;
  661. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  662. laNotifyUsers("la.logs");
  663. }
  664. laSafeString** la_PerfEnsure(){
  665. MAIN.NextPerfCounter++;
  666. if(MAIN.NextPerfCounter>=32){ MAIN.NextPerfCounter=0; }
  667. return &MAIN.PerfLogs[MAIN.NextPerfCounter];
  668. }
  669. void la_PerfClear(){
  670. if(!MAIN.ShowPerf){ return; }
  671. MAIN.NextPerfCounter=0; MAIN.NextPerfGroup++; if(MAIN.NextPerfGroup>=32){ MAIN.NextPerfGroup=0; }
  672. memset(&MAIN.PerfCounter[MAIN.NextPerfGroup],0,32*sizeof(real));
  673. for(int i=0;i<32;i++){ strSafeDestroy(&MAIN.PerfLogs[i]); }
  674. }
  675. void laPerfRecordV(char* format, va_list v){
  676. if(!format || !format[0]) return;
  677. laSafeString** ss=la_PerfEnsure();
  678. strSafePrintV(ss, format, v);
  679. laTimeRecorder tm; laRecordTime(&tm);
  680. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  681. }
  682. void laPerfRecord(char* format, ...){
  683. if(!format || !format[0]) return;
  684. laSafeString** ss=la_PerfEnsure();
  685. va_list aptr; va_start(aptr, format);
  686. strSafePrintV(ss, format, aptr);
  687. va_end(aptr);
  688. laTimeRecorder tm; laRecordTime(&tm);
  689. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  690. }
  691. void la_PerfDraw(){
  692. tnsScale3d(0.75,0.75,0.75);
  693. int sy=0; laBoxedTheme* bt=_LA_THEME_LABEL; real* color=laThemeColor(bt,LA_BT_TEXT);
  694. int sl=LA_RH*4; char buf[16]; real totval=0; real vals[32];
  695. for(int i=0;i<32;i++){
  696. if(MAIN.PerfLogs[i]){
  697. real value = MAIN.PerfCounter[MAIN.NextPerfGroup][i]-(i>0?MAIN.PerfCounter[MAIN.NextPerfGroup][i-1]:0);
  698. sprintf(buf,"%0.2lf",value*1000); totval+=value; vals[i]=value;
  699. tnsDrawStringAuto(buf,color,0,10000,sy,LA_TEXT_SHADOW);
  700. tnsDrawStringAuto(SSTR(MAIN.PerfLogs[i]),color,sl,10000,sy,LA_TEXT_SHADOW);
  701. sy+=LA_RH;
  702. }
  703. }
  704. real SL=LA_RH*2,SR=LA_RH*3.5; sy=0; tnsColor4dv(color); tnsUseNoTexture();
  705. for(int i=0;i<32;i++){
  706. if(MAIN.PerfLogs[i]){
  707. real r=vals[i]/totval; real use_r=tnsInterpolate(SL,SR,r);
  708. tnsVertex2d(SL,sy); tnsVertex2d(SL,sy+LA_RH); tnsVertex2d(use_r,sy+LA_RH); tnsVertex2d(use_r,sy);
  709. tnsPackAs(GL_TRIANGLE_FAN);
  710. sy+=LA_RH;
  711. }
  712. }
  713. tnsFlush();
  714. }
  715. 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;
  716. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  717. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  718. }
  719. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  720. strSafeSet(&s->Name,Name);
  721. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  722. s->x=x;s->y=y;s->w=w;s->h=h;
  723. laNotifyUsers("la.user_preferences.screens");
  724. return s;
  725. }
  726. void la_RemoveScreen(laScreen*s){
  727. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  728. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  729. }
  730. void la_RemoveDuplicatedScreenConf(){
  731. laScreen* NextS;
  732. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  733. NextS = s->Item.pNext;
  734. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  735. 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; }
  736. }
  737. }
  738. }
  739. laScreen* laGetWindowScreen(laWindow* w){
  740. int l,r,u,b; int area=-1; laScreen* maxs=0;
  741. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  742. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  743. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  744. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  745. int a=w*h; if(a>area){ maxs = s; area = a; }
  746. }
  747. return maxs;
  748. }
  749. #ifdef LA_LINUX
  750. int la_GetDPI(Window* root_win){
  751. XRRScreenResources *screen;
  752. XRROutputInfo *info;
  753. XRRCrtcInfo *crtc_info;
  754. XRRCrtcInfo *crtc;
  755. int iscres, icrtc, dpi=0;
  756. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  757. for(iscres=0;iscres<screen->noutput;iscres++){
  758. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  759. if(!info->mm_width || !info->mm_height){ continue; }
  760. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  761. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  762. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  763. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  764. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  765. XRRFreeCrtcInfo(crtc);
  766. //if(info->connection==RR_Connected){
  767. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  768. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  769. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  770. // XRRFreeCrtcInfo(crtc_info);
  771. // }
  772. //}
  773. XRRFreeOutputInfo(info);
  774. }
  775. XRRFreeScreenResources(screen);
  776. return dpi;
  777. }
  778. #endif
  779. #ifdef _WIN32
  780. typedef struct laWin32MonitorEnumData {
  781. int id;
  782. }laWin32MonitorEnumData;
  783. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  784. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  785. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  786. return TRUE;
  787. }
  788. int la_GetDPI(HWND win){
  789. laWin32MonitorEnumData data = { 0 };
  790. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  791. return GetDpiForWindow(win);
  792. return 144;
  793. }
  794. #endif
  795. #define PROGRESSW (LA_RH*15)
  796. void laShowProgress(real p1, real p2){
  797. laSpinLock(&MAIN.OpsLock);
  798. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  799. if(!MAIN.Progress.Called){
  800. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  801. }
  802. laTimeRecorder tm; laRecordTime(&tm);
  803. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  804. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  805. if((!MAIN.Progress.Shown) && MAIN.Progress.Called){
  806. int ww=PROGRESSW+LA_RH*2;
  807. #ifdef LA_LINUX
  808. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  809. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  810. long a=LA_COLOR3_TO_HEX(bg);
  811. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  812. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  813. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  814. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  815. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  816. #endif
  817. #ifdef _WIN32
  818. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  819. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  820. ShowWindow(MAIN.Progress.w,SW_SHOW);
  821. #endif
  822. MAIN.Progress.Shown = 1;
  823. }
  824. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  825. #ifdef LA_LINUX
  826. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  827. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  828. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  829. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  830. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  831. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  832. #endif
  833. #ifdef _WIN32
  834. InvalidateRect(MAIN.Progress.w,0,1);
  835. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  836. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  837. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  838. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  839. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  840. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  841. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  842. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  843. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  844. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  845. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  846. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  847. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  848. EndPaint(MAIN.Progress.w,&ps);
  849. MSG msg;
  850. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  851. #endif
  852. #ifdef LAGUI_ANDROID
  853. laWindow* window=MAIN.CurrentWindow; int pw=window->CW;
  854. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  855. tnsViewportWithScissor(0,0,window->CW,window->CH);
  856. tnsOrtho(0,window->CW,-window->CH+LA_2RH,LA_2RH,-100,100);
  857. tnsClearColorv(bg); tnsClearAll(); tnsUseNoTexture(); tnsColor4dv(fg);
  858. tnsVertex2d(0,0);tnsVertex2d(pw*MAIN.Progress.p2,0);tnsVertex2d(pw*MAIN.Progress.p2,LA_RH);tnsVertex2d(0,LA_RH);
  859. tnsPackAs(GL_TRIANGLE_FAN);
  860. tnsVertex2d(0,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_2RH);tnsVertex2d(0,LA_2RH);
  861. tnsPackAs(GL_TRIANGLE_FAN);
  862. tnsFlush();
  863. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  864. eglMakeCurrent(MAIN.egl_dpy,0,0,0);
  865. #endif
  866. laSpinUnlock(&MAIN.OpsLock);
  867. }
  868. void laHideProgress(){
  869. laSpinLock(&MAIN.OpsLock);
  870. if(!MAIN.Progress.Shown){
  871. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  872. }
  873. laTimeRecorder tm; laRecordTime(&tm);
  874. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  875. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  876. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  877. #ifdef LA_LINUX
  878. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  879. #endif
  880. #ifdef _WIN32
  881. ShowWindow(MAIN.Progress.w,SW_HIDE);
  882. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  883. #endif
  884. #ifdef LAGUI_ANDROID
  885. laRedrawAllWindows();
  886. #endif
  887. laSpinUnlock(&MAIN.OpsLock);
  888. }
  889. //=======================
  890. void la_InitProgressWindow(){
  891. #ifdef LA_LINUX
  892. 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));
  893. if(!MAIN.Progress.w) return;
  894. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  895. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  896. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  897. if(MAIN.Progress.gc<0) return;
  898. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  899. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  900. XSync(MAIN.dpy,0);
  901. #endif
  902. #ifdef _WIN32
  903. WNDCLASSW wc;
  904. wc.hInstance = MAIN.hinstance;
  905. wc.lpfnWndProc = LA_ProgressWindowProc;
  906. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  907. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  908. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  909. wc.cbWndExtra = 0;
  910. wc.cbClsExtra = 0;
  911. wc.lpszClassName = L"_LAGUIPROGRESS";
  912. wc.lpszMenuName = NULL;
  913. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  914. if (!RegisterClassW(&wc)){ return; }
  915. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  916. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  917. #endif
  918. }
  919. void laSetFontFolderPath(char* absolute){
  920. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  921. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  922. }
  923. void laSetDefaultInitArguments(laInitArguments* ia){
  924. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  925. ia->UseColorManagement=0;
  926. ia->HasWorldObjects=0;
  927. ia->HasAction=0;
  928. ia->HasTextureInspector=0;
  929. ia->HasHistories=0;
  930. ia->HasTerminal=1;
  931. ia->HasAudio=0;
  932. }
  933. void laSetCompleteInitArguments(laInitArguments* ia){
  934. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  935. ia->UseColorManagement=1;
  936. ia->HasWorldObjects=1;
  937. ia->HasAction=1;
  938. ia->HasTextureInspector=1;
  939. ia->HasHistories=1;
  940. ia->HasTerminal=1;
  941. ia->HasAudio=1;
  942. }
  943. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  944. MAIN.GLMajor=MAIN.GLMinor=-1;
  945. char* arg = 0;
  946. printf("Initializing LaGUI...\n",argc);
  947. for(int i=0;i<argc;i++){
  948. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  949. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  950. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  951. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  952. }
  953. continue;
  954. }
  955. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  956. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  957. }
  958. }
  959. int laGetReadyWith(laInitArguments* ia){
  960. #ifdef LA_LINUX
  961. //signal(SIGSEGV,la_HandlerSIGSEGV);
  962. #endif
  963. laSpinInit(&MAIN.MemLock);
  964. laSpinInit(&MAIN.OpsLock);
  965. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  966. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  967. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  968. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  969. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  970. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  971. tnsInit();
  972. #ifdef LA_LINUX
  973. SYSWINDOW root, win;
  974. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  975. XSetWindowAttributes swa={0};
  976. XWindowAttributes wa={0};
  977. XEvent xev;
  978. logPrintNew("Initializing LaGUI...\n");
  979. setlocale(LC_CTYPE, "zh_CN.utf8");
  980. XSetErrorHandler(la_XErrorHandler);
  981. int i;
  982. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  983. printf("\n\tcannot connect to x server\n\n");
  984. exit(0);
  985. }
  986. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  987. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  988. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  989. #ifdef LA_USE_GLES
  990. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  991. #else
  992. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  993. #endif
  994. #ifdef LA_USE_GLES
  995. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  996. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  997. EGLint egl_major, egl_minor;
  998. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  999. printf("Error: eglInitialize() failed\n"); return -1;
  1000. }
  1001. int scrnum;
  1002. XSetWindowAttributes attr;
  1003. XVisualInfo *visInfo, visTemplate;
  1004. int num_visuals;
  1005. EGLContext ctx;
  1006. EGLint num_configs;
  1007. EGLint vid;
  1008. static const EGLint attribs[] = {
  1009. EGL_RED_SIZE, 8,
  1010. EGL_GREEN_SIZE, 8,
  1011. EGL_BLUE_SIZE, 8,
  1012. EGL_DEPTH_SIZE, 1,
  1013. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  1014. EGL_NONE
  1015. };
  1016. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  1017. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  1018. }
  1019. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  1020. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  1021. }
  1022. visTemplate.visualid = vid;
  1023. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  1024. if (!visInfo) {
  1025. printf("Error: couldn't get X visual\n"); exit(1);
  1026. }
  1027. MAIN.xvi=visInfo;
  1028. root = DefaultRootWindow(MAIN.dpy);
  1029. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1030. printf("\n\tcannot create colormap\n\n"); exit(1);
  1031. }
  1032. eglBindAPI(EGL_OPENGL_ES_API);
  1033. EGLint ctx_attribs[] = {
  1034. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  1035. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  1036. EGL_NONE
  1037. };
  1038. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  1039. if (!MAIN.glc) {
  1040. printf("Error: eglCreateContext failed\n"); exit(1);
  1041. }
  1042. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  1043. #else
  1044. int visual_attribs[] = {
  1045. GLX_X_RENDERABLE , True,
  1046. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  1047. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  1048. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  1049. GLX_RED_SIZE , 8,
  1050. GLX_GREEN_SIZE , 8,
  1051. GLX_BLUE_SIZE , 8,
  1052. GLX_ALPHA_SIZE , 8,
  1053. GLX_DEPTH_SIZE , 24,
  1054. //GLX_STENCIL_SIZE , 8,
  1055. GLX_DOUBLEBUFFER , True,
  1056. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  1057. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  1058. None
  1059. };
  1060. int fbcount = -1;
  1061. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  1062. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  1063. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  1064. MAIN.BestFBC = fbconfig[0];
  1065. int sample_buf,samples;
  1066. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  1067. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  1068. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1069. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1070. free(fbconfig);
  1071. root = DefaultRootWindow(MAIN.dpy);
  1072. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1073. printf("\n\tcannot create colormap\n\n"); exit(0);
  1074. }
  1075. swa.colormap = MAIN.cmap;
  1076. root = DefaultRootWindow(MAIN.dpy);
  1077. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1078. MAIN.win=win;
  1079. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1080. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1081. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1082. printf("\n\tcannot create gl context\n\n"); exit(0);
  1083. }
  1084. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1085. tnsContextMakeCurrent(MAIN.glc,win,0);
  1086. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1087. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1088. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1089. int err=0;
  1090. if((err=glewInit())!=GLEW_OK){
  1091. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1092. };
  1093. #endif /* gles or glx */
  1094. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1095. la_SetCurrentGLContextDebug();
  1096. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1097. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1098. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1099. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1100. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1101. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1102. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1103. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1104. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1105. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1106. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1107. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1108. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1109. #endif //linux
  1110. #ifdef _WIN32
  1111. logPrintNew("Initializing LaGUI...\n");
  1112. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1113. setlocale(LC_ALL, "zh_CN.utf8");
  1114. MAIN.hinstance = GetModuleHandle(NULL);
  1115. HINSTANCE* hInst = &MAIN.hinstance;
  1116. WNDCLASSEXW wt;
  1117. wt.cbSize = sizeof(WNDCLASSEXW);
  1118. wt.cbClsExtra = 0;
  1119. wt.cbWndExtra = 0;
  1120. wt.hbrBackground = 0;
  1121. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1122. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1123. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1124. wt.hInstance = *hInst;
  1125. wt.lpfnWndProc = LA_WindowProc;
  1126. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1127. wt.lpszMenuName = 0;
  1128. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1129. if (!RegisterClassExW(&wt)) return 0;
  1130. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1131. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1132. SetProcessDPIAware();
  1133. GLenum err;
  1134. PIXELFORMATDESCRIPTOR pfd;
  1135. HINSTANCE* hinst = &MAIN.hinstance;
  1136. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1137. "Temp Window For Accessing GLEW!",
  1138. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1139. 0, 0, *hinst, 0);
  1140. HDC hdc = GetDC(hwnd);
  1141. HGLRC hglrc = 0;
  1142. SetPixelFormat(hdc, 1, &cpfd);
  1143. hglrc = wglCreateContext(hdc);
  1144. tnsContextMakeCurrent(hglrc, hdc,0);
  1145. //MAIN.hdc = hdc;
  1146. // MAIN.tWND = hwnd;
  1147. MAIN.glc = hglrc;
  1148. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1149. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1150. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1151. if (err = glewInit()) {
  1152. printf("Init Glew Failed\n");
  1153. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1154. return 0;
  1155. }
  1156. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1157. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1158. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1159. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1160. #endif
  1161. la_GetWorkingDirectoryInternal();
  1162. MAIN.SavePreferenceOnExit=1;
  1163. MAIN.FontSize = 0.6;
  1164. int dpi=64;
  1165. #ifdef _WIN32
  1166. dpi=la_GetDPI(hwnd);
  1167. #endif
  1168. #ifdef LA_LINUX
  1169. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1170. #endif
  1171. #ifdef LAGUI_ANDROID
  1172. dpi = 72;
  1173. #endif
  1174. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1175. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1176. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1177. MAIN.UiScale=1;
  1178. MAIN.MarginSize = 1;
  1179. MAIN.ColorPickerGamma=1.5;
  1180. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1181. MAIN.ViewportHalftoneFactor=0.5;
  1182. MAIN.ViewportHalftoneSize=3.7;
  1183. tnsInitRenderKernel(64);
  1184. tnsInitBuiltinShaders();
  1185. tnsSetuptnsFontManager();
  1186. #define LOAD_FONT(font) \
  1187. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1188. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1189. LOAD_FONT("NotoEmoji-Regular.ttf");
  1190. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1191. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1192. //LOAD_FONT("NotoMusic-Regular.ttf");
  1193. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1194. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1195. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1196. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1197. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1198. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1199. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1200. MAIN.Audio=memAcquire(sizeof(laAudio));
  1201. #ifdef LA_WITH_LUAJIT
  1202. // starting lua
  1203. logPrint("Starting luajit...\n");
  1204. MAIN.L = lua_open();
  1205. la_luaLoadLibs(MAIN.L);
  1206. la_luaPrintStatus(MAIN.L);
  1207. tnsLuaInit(MAIN.L);
  1208. #endif
  1209. //interactions:
  1210. MAIN.TopFramerate = 60;
  1211. MAIN.ValuatorThreshold = 8;
  1212. MAIN.ScrollingSpeed = 3;
  1213. MAIN.AnimationSpeed = 0.4;
  1214. MAIN.PanelAnimationSpeed = 0.4;
  1215. MAIN.ZoomSpeed2D = 0.01;
  1216. MAIN.IdleTime = 0.75;
  1217. MAIN.TooltipCloseDistance = 30;
  1218. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1219. //display:
  1220. MAIN.FloatingAlpha = 0.35;
  1221. MAIN.SolidShadowLength = 20;
  1222. MAIN.WireColorSlices = 16;
  1223. MAIN.WireThickness = 5;
  1224. MAIN.WireSaggyness = 0.5;
  1225. MAIN.ManagerFilterInstances = 1;
  1226. #ifdef LAGUI_ANDROID
  1227. laAddResourceFolder("");
  1228. #else
  1229. laAddResourceFolder(".");
  1230. #endif
  1231. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1232. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1233. la_InitProgressWindow();
  1234. la_MakeTranslations_es_ES();
  1235. la_MakeTranslations_zh_hans();
  1236. //tns_RegisterResourcesForSoftwareRender();
  1237. la_RegisterDefaultSignals();
  1238. la_RegisterGeneralProps();
  1239. la_RegisterBuiltinTemplates();
  1240. la_RegisterMainThemes();
  1241. la_RegisterMainOperators();
  1242. la_RegisterMainUiTypes();
  1243. la_RegisterInternalProps();
  1244. la_RegisterAnimationResources();
  1245. la_RegisterWindowKeys();
  1246. if(MAIN.InitArgs.HasWorldObjects){
  1247. la_RegisterModellingOperators();
  1248. la_RegisterShapeOperators();
  1249. }
  1250. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1251. laFinalizeUiTemplates();
  1252. laFinalizeOperators();
  1253. la_RegisterControllerProps();
  1254. la_RefreshControllers();
  1255. la_RegisterBasicNodes();
  1256. tns_RegisterNodes();
  1257. la_InitThreadEnviornment();
  1258. laSetRootInstance(&MAIN);
  1259. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1260. laPushDifferences(0, 0);
  1261. la_MakeDummyManagedUDF();
  1262. la_RegenerateWireColors();
  1263. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1264. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1265. laSetProofingLut(DATA_LUT_PROOF_SRGB, 0);
  1266. laSetProofingLut(DATA_LUT_PROOF_CLAY, 1);
  1267. laSetProofingLut(DATA_LUT_PROOF_D65P3, 2);
  1268. logPrintNew("Initialization Completed\n");
  1269. MAIN.InitDone=1;
  1270. #ifdef LAGUI_ANDROID
  1271. MAIN.AutoSwitchColorSpace = 0;
  1272. MAIN.GotFilePermission = la_check_permission("android.permission.WRITE_EXTERNAL_STORAGE");
  1273. #else
  1274. MAIN.AutoSwitchColorSpace = 1;
  1275. #endif
  1276. return 1;
  1277. }
  1278. int laGetReady(){
  1279. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1280. return laGetReadyWith(&ia);
  1281. }
  1282. void la_DestroyUiType(laUiType* uit);
  1283. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1284. void laShutoff(int SavePrefereces){
  1285. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1286. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1287. // transLate(pc->Description);
  1288. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1289. // transLate(p->Description);
  1290. // }
  1291. //}
  1292. transDumpMissMatchRecord("TranslationDump.txt");
  1293. if(MAIN.Cleanup) MAIN.Cleanup();
  1294. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1295. strSafeDestroy(&MAIN.WorkingDirectory);
  1296. strSafeDestroy(&MAIN.example_string);
  1297. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1298. // (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. )
  1299. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1300. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1301. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1302. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1303. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1304. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1305. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1306. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1307. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1308. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1309. strSafeDestroy(&MAIN.CopyPending);
  1310. la_ClearUDFRegistryAndFolders();
  1311. laClearManagedUDF();
  1312. laClearSaveProp();
  1313. logClear();
  1314. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1315. #ifdef LA_LINUX
  1316. tnsContextMakeCurrent(0,0,0);
  1317. tnsDeleteContext(MAIN.glc);
  1318. #ifdef LA_USE_GLES
  1319. eglTerminate(MAIN.egl_dpy);
  1320. #endif
  1321. #endif
  1322. #ifdef _WIN32
  1323. tnsContextMakeCurrent(0,0,0);
  1324. tnsDeleteContext(MAIN.glc);
  1325. UnloadWintab();
  1326. #endif
  1327. tnsQuit();
  1328. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1329. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1330. strSafeDump();
  1331. hshFree(&MAIN.DBInstMemLeft);
  1332. memNoLonger();
  1333. laSpinDestroy(&MAIN.MemLock);
  1334. laSpinDestroy(&MAIN.OpsLock);
  1335. #ifdef LA_WITH_LUAJIT
  1336. lua_close(MAIN.L);
  1337. #endif
  1338. printf("LaGUI has cleaned up.\n");
  1339. }
  1340. int laRestoreFactorySettings(){
  1341. char path[1024];
  1342. #ifdef LAGUI_ANDROID
  1343. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1344. logPrintNew("%s", path);
  1345. if(!remove(path)){ return 1; }
  1346. sprintf(path,"%s/%s",MAIN.ExternalDataPath,"preferences.udf");
  1347. logPrintNew("%s", path);
  1348. if(!remove(path)){ return 1; }
  1349. return 0;
  1350. #else
  1351. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1352. #endif
  1353. if(remove(path)){ return 0; }
  1354. return 1;
  1355. }
  1356. void laSaveUserPreferences(){
  1357. char path[1024];
  1358. #ifdef LAGUI_ANDROID
  1359. sprintf(path,"%s","preferences.udf");
  1360. #else
  1361. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1362. #endif
  1363. laUDF* udf=laPrepareUDF(path);
  1364. laWriteProp(udf,"la.windows");
  1365. laWriteProp(udf,"la.user_preferences");
  1366. laWriteProp(udf,"la.input_mapping");
  1367. laWriteProp(udf,"la.controllers");
  1368. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1369. laWriteProp(udf,lip->p);
  1370. }
  1371. laPackUDF(udf,0,0);
  1372. }
  1373. void laEnsureUserPreferences(){
  1374. char path[1024];
  1375. #ifdef LAGUI_ANDROID
  1376. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1377. #else
  1378. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1379. #endif
  1380. laUDFRegistry* r=laFindUDFRegistry(path);
  1381. if(!r){ laSaveUserPreferences(); return; }
  1382. 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; }
  1383. laClearUDFRegistries();
  1384. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1385. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1386. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1387. laCloseUDF(udf);
  1388. la_RemoveDuplicatedScreenConf();
  1389. la_RemoveDuplicatedControllers();
  1390. laRefreshUDFRegistries();
  1391. //restore forced settings
  1392. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1393. }
  1394. void laAddExtraExtension(int FileType, ...){
  1395. va_list list; va_start(list,FileType);
  1396. char* ext;
  1397. while(ext=va_arg(list,char*)){ if(!ext) break;
  1398. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1399. et->FileType=FileType; et->Extension=ext;
  1400. lstAppendItem(&MAIN.ExtraExtensions, et);
  1401. logPrintNew("add ext %s",ext);
  1402. }
  1403. va_end(list);
  1404. }
  1405. void laAddExtraPreferencePath(const char* path){
  1406. if(!path) return;
  1407. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1408. }
  1409. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1410. if(!name || !Func) return;
  1411. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1412. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1413. }
  1414. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1415. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1416. }
  1417. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1418. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1419. }
  1420. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1421. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1422. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1423. }
  1424. void la_InputMappingGetKeyName(int key, int special, char* name){
  1425. char *_next=name; name[0]=0;
  1426. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1427. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1428. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1429. switch(key){
  1430. case ' ': strcat(name,"Space"); break;
  1431. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1432. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1433. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1434. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1435. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1436. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1437. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1438. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1439. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1440. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1441. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1442. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1443. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1444. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1445. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1446. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1447. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1448. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1449. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1450. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1451. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1452. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1453. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1454. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1455. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1456. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1457. case LA_KEY_F1: strcat(name,"F1"); break;
  1458. case LA_KEY_F2: strcat(name,"F2"); break;
  1459. case LA_KEY_F3: strcat(name,"F3"); break;
  1460. case LA_KEY_F4: strcat(name,"F4"); break;
  1461. case LA_KEY_F5: strcat(name,"F5"); break;
  1462. case LA_KEY_F6: strcat(name,"F6"); break;
  1463. case LA_KEY_F7: strcat(name,"F7"); break;
  1464. case LA_KEY_F8: strcat(name,"F8"); break;
  1465. case LA_KEY_F9: strcat(name,"F9"); break;
  1466. case LA_KEY_F10: strcat(name,"F10"); break;
  1467. case LA_KEY_F11: strcat(name,"F11"); break;
  1468. case LA_KEY_F12: strcat(name,"F12"); break;
  1469. default:
  1470. name = name+strlen(name); _next=name;
  1471. laToUTF8(key,name,&_next); *_next=0; break;
  1472. }
  1473. }
  1474. int la_InputMappingGetKeyFromName(char* name, int* special){
  1475. if(!name ||name[0]==0){ *special=0; return 0; }
  1476. *special=0;
  1477. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1478. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1479. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1480. char* p=name+strlen(name)-1;
  1481. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1482. while(*p=='+' || *p==' '){ p++; }
  1483. if(strSame(p,"Space")) return ' ';
  1484. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1485. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1486. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1487. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1488. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1489. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1490. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1491. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1492. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1493. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1494. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1495. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1496. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1497. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1498. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1499. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1500. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1501. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1502. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1503. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1504. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1505. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1506. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1507. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1508. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1509. if(strSame(p,"F1")) return LA_KEY_F1;
  1510. if(strSame(p,"F2")) return LA_KEY_F2;
  1511. if(strSame(p,"F3")) return LA_KEY_F3;
  1512. if(strSame(p,"F4")) return LA_KEY_F4;
  1513. if(strSame(p,"F5")) return LA_KEY_F5;
  1514. if(strSame(p,"F6")) return LA_KEY_F6;
  1515. if(strSame(p,"F7")) return LA_KEY_F7;
  1516. if(strSame(p,"F8")) return LA_KEY_F8;
  1517. if(strSame(p,"F9")) return LA_KEY_F9;
  1518. if(strSame(p,"F10")) return LA_KEY_F10;
  1519. if(strSame(p,"F11")) return LA_KEY_F11;
  1520. if(strSame(p,"F12")) return LA_KEY_F12;
  1521. int adv;
  1522. return laToUnicode(p,&adv);
  1523. }
  1524. laCustomSignal* laFindSignal(char* Name){
  1525. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1526. return 0;
  1527. }
  1528. laCustomSignal* laFindSignalByID(int ID){
  1529. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1530. return 0;
  1531. }
  1532. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1533. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1534. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1535. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1536. char* signal = SSTR(ime->Signal);
  1537. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1538. }
  1539. laInputMapping* laNewInputMapping(char* Name){
  1540. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1541. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1542. strSafeSet(&im->Name,Name);
  1543. return im;
  1544. }
  1545. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1546. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1547. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1548. memAssignRef(e,&e->Parent,im);
  1549. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1550. laInputMappingUpdateSignal(e);
  1551. e->SpecialKeyBits=SpecialKeyBit;
  1552. char buf[64],*_next=buf;
  1553. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1554. return e;
  1555. }
  1556. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1557. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1558. return laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1559. }
  1560. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1561. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1562. }
  1563. void laRemoveInputMapping(laInputMapping* im){
  1564. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1565. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1566. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1567. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1568. }
  1569. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1570. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1571. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1572. return cs;
  1573. }
  1574. void laRemoveCustomSignal(laCustomSignal* cs){
  1575. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1576. }
  1577. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1578. void la_SendSignalsFromEvent(laEvent* e){
  1579. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1580. if(!im){return;}
  1581. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1582. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1583. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1584. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1585. }
  1586. }
  1587. }
  1588. }
  1589. //MSG====================================================
  1590. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1591. if (wnd->win == hwnd) return 1;
  1592. else return 0;
  1593. };
  1594. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1595. if (p->SL){ int s=p->SL<0?0:p->SL;
  1596. if (p->TX != s) laRecalcPanel(p);
  1597. p->TX = s;
  1598. }
  1599. if (p->SR){ int s=p->SR<0?0:p->SR;
  1600. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1601. p->TW = CW - p->TX - s;
  1602. }
  1603. if (p->ST){ int s=p->ST<0?0:p->ST;
  1604. if (p->TY != s) laRecalcPanel(p);
  1605. p->TY = s;
  1606. }
  1607. if (p->SB){ int s=p->SB<0?0:p->SB;
  1608. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1609. p->TH = CH - p->TY - s;
  1610. }
  1611. }
  1612. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1613. laPanel *p = 0;
  1614. b->X = X;
  1615. b->Y = Y;
  1616. b->W = W;
  1617. b->H = H;
  1618. if (b->B1){
  1619. int SplitWidth;
  1620. if (b->Vertical){
  1621. SplitWidth = H * b->SplitRatio;
  1622. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1623. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1624. }else{
  1625. SplitWidth = W * b->SplitRatio;
  1626. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1627. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1628. }
  1629. }
  1630. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1631. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1632. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1633. }
  1634. if (p = b->CurrentPanel){
  1635. int TitleGap=b->Folded?0:LA_RH;
  1636. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1637. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1638. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1639. laRecalcPanel(p);
  1640. }
  1641. }
  1642. void la_UpdateUiPlacement(laWindow *w){
  1643. laLayout *l;
  1644. laPanel *p;
  1645. int CW = w->CW;
  1646. int CH = w->CH;
  1647. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1648. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1649. if(w->MaximizedUi && w->MaximizedUiPanel){
  1650. laRecalcPanel(w->MaximizedUiPanel);
  1651. }elif(w->MaximizedBlock){
  1652. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1653. }else{
  1654. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1655. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1656. }
  1657. }
  1658. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1659. if(p->IsMenuPanel){
  1660. p->TH=p->H=MenuHeight;
  1661. }
  1662. la_EnsurePanelSnapping(p, CW, CH);
  1663. laRecalcPanel(p);
  1664. }
  1665. }
  1666. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1667. laWindow *window;
  1668. #ifdef LAGUI_ANDROID
  1669. window = MAIN.Windows.pFirst; if (!window) return;
  1670. window->X=x;window->Y=y;window->W=w;window->H=h;
  1671. window->CW=w;window->CH=h;
  1672. la_UpdateUiPlacement(window); return;
  1673. #endif
  1674. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1675. if (!window) return;
  1676. #ifdef _WIN32
  1677. RECT rcc; GetClientRect(window->win, &rcc);
  1678. RECT rcw; GetWindowRect(window->win, &rcw);
  1679. window->CW = rcc.right - rcc.left;
  1680. window->CH = rcc.bottom - rcc.top;
  1681. window->W = rcw.right - rcw.left;
  1682. window->H = rcw.bottom - rcw.top;
  1683. window->X = rcw.left; window->Y = rcw.top;
  1684. if (MAIN.AutoSwitchColorSpace) {
  1685. laScreen* s = laGetWindowScreen(window);
  1686. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1687. }
  1688. #endif
  1689. #ifdef LA_LINUX
  1690. XWindowAttributes attr;
  1691. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1692. window->CW = w; window->CH = h;
  1693. window->W = w; window->H = h;
  1694. window->X = x; window->Y = y;
  1695. if(MAIN.AutoSwitchColorSpace){
  1696. laScreen* s = laGetWindowScreen(window);
  1697. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1698. }
  1699. #endif
  1700. la_UpdateUiPlacement(window);
  1701. }
  1702. int la_OnWindowDestroy(SYSWINDOW wnd){
  1703. laListHandle *hlst = &MAIN.Windows;
  1704. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1705. if (!w) return 0;
  1706. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1707. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1708. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1709. laShutoff(1);
  1710. return 1;
  1711. }
  1712. laListHandle h={0};laLayout*l=0;
  1713. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1714. la_DestroyWindow(w);
  1715. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1716. #ifdef LA_LINUX
  1717. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1718. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1719. #endif
  1720. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1721. }
  1722. return 0;
  1723. }
  1724. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1725. laListHandle *el = &wnd->EventList;
  1726. laEvent* last_e=el->pLast;
  1727. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1728. #ifdef LA_LINUX
  1729. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1730. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1731. #endif
  1732. #ifdef _WIN32
  1733. 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);
  1734. #endif
  1735. }
  1736. void laMappingRequestEval();
  1737. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1738. laListHandle *wl = &MAIN.Windows;
  1739. laWindow* wnd;
  1740. #ifdef LAGUI_ANDROID
  1741. wnd = MAIN.Windows.pFirst;
  1742. #else
  1743. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1744. #endif
  1745. if (!wnd){ memFree(e); return; }
  1746. laListHandle *el = &wnd->EventList;
  1747. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1748. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1749. e->window = wnd;
  1750. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1751. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1752. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1753. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1754. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1755. e->GoodPressure=MAIN.IsPen;
  1756. lstAppendItem(el, (laListItem *)e);
  1757. laMappingRequestEval();
  1758. };
  1759. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1760. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1761. la_SaveEvent(hwnd, e, 1);
  1762. };
  1763. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1764. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1765. e->type = LA_INPUT; e->Input=Input;
  1766. la_SaveEvent(hwnd, e, 1);
  1767. }
  1768. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1769. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1770. e->type = LA_EMPTY;
  1771. la_SaveEvent(hwnd, e, 1);
  1772. }
  1773. void laSendOperatorTriggerEvent(){
  1774. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1775. MAIN.ReTriggerOperators = 0;
  1776. }
  1777. int la_TranslateSpecialKey(int keysym){
  1778. #ifdef LA_LINUX
  1779. switch(keysym){
  1780. case XK_Return: return LA_KEY_ENTER;
  1781. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1782. case XK_Delete: return LA_KEY_DELETE;
  1783. case XK_Escape: return LA_KEY_ESCAPE;
  1784. case XK_Tab: return LA_KEY_TAB;
  1785. case XK_Left: return LA_KEY_ARRLEFT;
  1786. case XK_Right: return LA_KEY_ARRRIGHT;
  1787. case XK_Up: return LA_KEY_ARRUP;
  1788. case XK_Down: return LA_KEY_ARRDOWN;
  1789. case XK_Control_L: return LA_KEY_CTRL;
  1790. case XK_Control_R: return LA_KEY_CTRL;
  1791. case XK_Shift_L: return LA_KEY_SHIFT;
  1792. case XK_Shift_R: return LA_KEY_SHIFT;
  1793. case XK_Alt_L: return LA_KEY_ALT;
  1794. case XK_Alt_R: return LA_KEY_ALT;
  1795. case XK_KP_1: return LA_KEY_NUM1;
  1796. case XK_KP_2: return LA_KEY_NUM2;
  1797. case XK_KP_3: return LA_KEY_NUM3;
  1798. case XK_KP_4: return LA_KEY_NUM4;
  1799. case XK_KP_5: return LA_KEY_NUM5;
  1800. case XK_KP_6: return LA_KEY_NUM6;
  1801. case XK_KP_7: return LA_KEY_NUM7;
  1802. case XK_KP_8: return LA_KEY_NUM8;
  1803. case XK_KP_9: return LA_KEY_NUM9;
  1804. case XK_KP_0: return LA_KEY_NUM0;
  1805. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1806. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1807. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1808. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1809. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1810. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1811. default: return keysym;
  1812. }
  1813. #endif
  1814. #ifdef _WIN32
  1815. switch (keysym) {
  1816. case VK_RETURN: return LA_KEY_ENTER;
  1817. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1818. case VK_TAB: return LA_KEY_TAB;
  1819. case VK_LEFT: return LA_KEY_ARRLEFT;
  1820. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1821. case VK_UP: return LA_KEY_ARRUP;
  1822. case VK_DOWN: return LA_KEY_ARRDOWN;
  1823. case VK_CONTROL: return LA_KEY_CTRL;
  1824. case VK_SHIFT: return LA_KEY_SHIFT;
  1825. case VK_MENU: return LA_KEY_ALT;
  1826. case VK_F1: return LA_KEY_F1;
  1827. case VK_F2: return LA_KEY_F2;
  1828. case VK_F3: return LA_KEY_F3;
  1829. case VK_F4: return LA_KEY_F4;
  1830. case VK_F5: return LA_KEY_F5;
  1831. case VK_F6: return LA_KEY_F6;
  1832. case VK_F7: return LA_KEY_F7;
  1833. case VK_F8: return LA_KEY_F8;
  1834. case VK_F9: return LA_KEY_F9;
  1835. case VK_F10: return LA_KEY_F10;
  1836. case VK_F11: return LA_KEY_F11;
  1837. case VK_F12: return LA_KEY_F12;
  1838. case VK_NUMPAD0: return LA_KEY_NUM0;
  1839. case VK_NUMPAD1: return LA_KEY_NUM1;
  1840. case VK_NUMPAD2: return LA_KEY_NUM2;
  1841. case VK_NUMPAD3: return LA_KEY_NUM3;
  1842. case VK_NUMPAD4: return LA_KEY_NUM4;
  1843. case VK_NUMPAD5: return LA_KEY_NUM5;
  1844. case VK_NUMPAD6: return LA_KEY_NUM6;
  1845. case VK_NUMPAD7: return LA_KEY_NUM7;
  1846. case VK_NUMPAD8: return LA_KEY_NUM8;
  1847. case VK_NUMPAD9: return LA_KEY_NUM9;
  1848. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1849. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1850. case VK_ADD: return LA_KEY_NUMPLUS;
  1851. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1852. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1853. case VK_OEM_1: return ';';
  1854. case VK_OEM_2: return '/';
  1855. case VK_OEM_3: return '`';
  1856. case VK_OEM_4: return '[';
  1857. case VK_OEM_5: return '\\';
  1858. case VK_OEM_6: return ']';
  1859. case VK_OEM_7: return '\'';
  1860. case VK_OEM_COMMA: return ',';
  1861. case VK_OEM_PERIOD: return '.';
  1862. case VK_OEM_PLUS: return '+';
  1863. case VK_OEM_MINUS: return '-';
  1864. default: return keysym;
  1865. }
  1866. #endif
  1867. }
  1868. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1869. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1870. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1871. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1872. // la_SaveEvent(hwnd, e, 0);
  1873. //}
  1874. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1875. e->type = type; e->x = x; e->y = y;
  1876. la_SaveEvent(hwnd, e, 0);
  1877. MAIN.evLastX=x; MAIN.evLastY=y;
  1878. };
  1879. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1880. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1881. e->type = type;
  1882. la_SaveEvent(hwnd, e, 1);
  1883. };
  1884. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1885. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1886. e->type = LA_SIGNAL_EVENT;
  1887. e->key = signal;
  1888. la_SaveEvent(hwnd, e, 1);
  1889. };
  1890. void laRetriggerOperators(){
  1891. MAIN.ReTriggerOperators = 1;
  1892. }
  1893. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1894. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1895. }
  1896. void laSetCleanupCallback(laCleanupF Cleanup){
  1897. MAIN.Cleanup=Cleanup;
  1898. }
  1899. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1900. MAIN.InputProcess=InputProcess;
  1901. }
  1902. //====================================================================================================
  1903. void la_DestroyTheme(laTheme* t){
  1904. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1905. strSafeDestroy(&t->Name);
  1906. strSafeDestroy(&t->Author);
  1907. }
  1908. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1909. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1910. strSafeSet(&t->Name, Name);
  1911. strSafeSet(&t->Author, AuthorName);
  1912. lstAppendItem(&MAIN.Themes, t);
  1913. MAIN.CurrentTheme = t;
  1914. return t;
  1915. }
  1916. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1917. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1918. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1919. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1920. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1921. strSafeSet(&bt->Name, Name);
  1922. bt->NormalY=NormalY;
  1923. bt->ActiveY=ActiveY;
  1924. bt->BorderY=BorderY;
  1925. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1926. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1927. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1928. bt->BackRef = BackRef;
  1929. lstAppendItem(&t->BoxedThemes, bt);
  1930. return bt;
  1931. }
  1932. laTheme *laGetTheme(const char *ThemeName){
  1933. laTheme *t = MAIN.Themes.pFirst;
  1934. for (t; t; t = t->Item.pNext){
  1935. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1936. }
  1937. return 0;
  1938. }
  1939. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1940. laTheme *t = MAIN.Themes.pFirst;
  1941. for (t; t; t = t->Item.pNext){
  1942. laBoxedTheme *bt;
  1943. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1944. bt = t->BoxedThemes.pFirst;
  1945. for (bt; bt; bt = bt->Item.pNext){
  1946. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1947. }
  1948. }
  1949. return 0;
  1950. }
  1951. real* laThemeColor(laBoxedTheme* bt, int which){
  1952. switch(which){
  1953. default:
  1954. case LA_BT_NORMAL: return bt->Normal;
  1955. case LA_UI_EDITING:
  1956. case LA_BT_ACTIVE: return bt->Active;
  1957. case LA_BT_BORDER: return bt->Border;
  1958. case LA_BT_TEXT: return bt->Text; break;
  1959. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1960. case LA_BT_DISABLED: return bt->Inactive; break;
  1961. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1962. }
  1963. return bt->Normal;
  1964. }
  1965. real* laAccentColor(int which){
  1966. switch(which){
  1967. default:
  1968. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1969. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1970. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1971. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1972. case LA_BT_FACE:
  1973. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1974. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1975. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1976. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1977. case LA_BT_SHADOW: return MAIN.CurrentTheme->ShadowColor;
  1978. }
  1979. return MAIN.CurrentTheme->SelectionColor;
  1980. }
  1981. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1982. real hcy[3];
  1983. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1984. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1985. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1986. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1987. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1988. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1989. int *tm=&bt->LM,*tp=&bt->LP;
  1990. for(int i=0;i<4;i++){
  1991. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1992. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1993. }
  1994. }
  1995. void la_RefreshThemeColorSelf(laTheme* th){
  1996. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1997. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1998. real hcy[3], usehcy[3];
  1999. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  2000. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  2001. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  2002. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  2003. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  2004. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  2005. tnsVectorCopy3d(th->Color, th->ShadowColor); th->ShadowColor[3]=th->CursorAlpha;
  2006. }
  2007. void la_RefreshThemeColor(laTheme* th){
  2008. real hcy[3], usehcy[3], normalhcy[3];
  2009. tnsRGB2HCY(th->Color,hcy);
  2010. la_RefreshThemeColorSelf(th);
  2011. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  2012. la_RefreshBoxedThemeColor(bt);
  2013. (*bt->BackRef) = bt;
  2014. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  2015. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  2016. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  2017. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  2018. }
  2019. }
  2020. void laSetProofingLut(void* data, int which){
  2021. TNS_CLAMP(which,0,2);
  2022. MAIN.ProofingLUT[which]=data;
  2023. MAIN.LutNeedsRefreshing=1;
  2024. }
  2025. void la_RefreshProofingLut(){
  2026. if(!MAIN.CurrentWindow) return;
  2027. int table = MAIN.CurrentWindow->OutputColorSpace;
  2028. if(MAIN.CurrentLut != table+1){ MAIN.LutNeedsRefreshing=1; }
  2029. if(!MAIN.LutNeedsRefreshing) return;
  2030. tnsEnableShaderv(T->immShader);
  2031. tnsShader* s = T->immShader;
  2032. if(!MAIN.ProofingLUT[table] || !MAIN.CurrentWindow->OutputProofing){
  2033. return;
  2034. }
  2035. if(!MAIN.LutTexture) glGenTextures(1, &MAIN.LutTexture);
  2036. tnsActiveTexture(GL_TEXTURE3);
  2037. glBindTexture(GL_TEXTURE_3D, MAIN.LutTexture);
  2038. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  2039. glTexImage3D(GL_TEXTURE_3D,0,GL_RGB,LA_LUT_PRECISION,LA_LUT_PRECISION,LA_LUT_PRECISION,0,GL_RGB, GL_UNSIGNED_BYTE,MAIN.ProofingLUT[table]);
  2040. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  2041. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  2042. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  2043. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  2044. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  2045. //glBindTexture(GL_TEXTURE_3D,0);
  2046. tnsActiveTexture(GL_TEXTURE0);
  2047. MAIN.CurrentLut = table+1;
  2048. MAIN.LutNeedsRefreshing=0;
  2049. }
  2050. //I FUCKING HATE THIS STUPID FUNCTION
  2051. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  2052. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2053. laUiListDrawItem *last = uild->Items.pFirst;
  2054. int LimW=_R-_L;
  2055. int SL, SR, SU, SB;
  2056. int Target__B = Target->B;
  2057. int Target__R = Target->R;
  2058. uildi->Target = Target;
  2059. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  2060. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  2061. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  2062. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  2063. uildi->L = last ? Target->L - last->XP : Target->L;
  2064. uildi->R = last ? Target__R - last->XP : Target__R;
  2065. uildi->U = last ? Target->U - last->YP : Target->U;
  2066. uildi->B = last ? Target__B - last->YP : Target__B;
  2067. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  2068. uildi->L -= GlobalX;
  2069. uildi->R -= GlobalX;
  2070. uildi->U -= GlobalY;
  2071. uildi->B -= GlobalY;
  2072. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2073. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2074. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2075. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2076. uildi->DifX = SL - uildi->L;
  2077. uildi->DifY = SU - uildi->U;
  2078. uildi->L = SL;
  2079. uildi->R = SR+uildi->DifX;
  2080. uildi->U = SU;
  2081. uildi->B = SB;//+uildi->DifY;
  2082. if(uildi->R>_R){ uildi->R=_R; }
  2083. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  2084. //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);
  2085. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  2086. memFree(uildi);
  2087. return 0;
  2088. }
  2089. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  2090. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  2091. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  2092. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  2093. Target->U + Target->PanY + uildi->DifY+1,
  2094. -100, 100);
  2095. lstPushItem(&uild->Items, uildi);
  2096. return 1;
  2097. }
  2098. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  2099. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2100. laUiListDrawItem *last = uild->Items.pFirst;
  2101. int SL, SR, SU, SB;
  2102. if (B - U > LimH) B = U + LimH;
  2103. uildi->XP = last ? last->XP + PanX : PanX;
  2104. uildi->YP = last ? last->YP + PanY : PanY;
  2105. uildi->L = last ? L - last->XP : L;
  2106. uildi->R = last ? R - last->XP : R;
  2107. uildi->U = last ? U - last->YP : U;
  2108. uildi->B = last ? B - last->YP : B;
  2109. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2110. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2111. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2112. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2113. uildi->DifX = SL - uildi->L;
  2114. uildi->DifY = SU - uildi->U;
  2115. uildi->L = SL;
  2116. uildi->R = SR;
  2117. uildi->U = SU;
  2118. uildi->B = SB;
  2119. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2120. tnsOrtho(L + PanX + uildi->DifX,
  2121. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  2122. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2123. U + PanY + uildi->DifY,
  2124. -100, 100);
  2125. lstPushItem(&uild->Items, uildi);
  2126. }
  2127. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2128. int* savel, int* saver, int* saveu, int* saveb){
  2129. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2130. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2131. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2132. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2133. real x,y,w,h;
  2134. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2135. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2136. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2137. }
  2138. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2139. laUiListDrawItem *uildi = uild->Items.pFirst;
  2140. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2141. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2142. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2143. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2144. Target->U + Target->PanY + uildi->DifY -1,
  2145. -100, 100);
  2146. }
  2147. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2148. laUiListDrawItem *uildi = lstPopItem(uild);
  2149. laUiList *Target;
  2150. memFree(uildi);
  2151. uildi = uild->Items.pFirst;
  2152. if (!uildi || !uildi->Target){
  2153. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2154. return;
  2155. }
  2156. Target = uildi->Target;
  2157. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2158. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2159. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2160. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2161. Target->U + Target->PanY + uildi->DifY -1,
  2162. -100, 100);
  2163. }
  2164. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2165. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2166. uildi->L = L;
  2167. uildi->R = R;
  2168. uildi->U = U;
  2169. uildi->B = B;
  2170. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2171. tnsOrtho(L, R, B, U, -100, 100);
  2172. lstPushItem(&uild->Items, uildi);
  2173. }
  2174. void la_ClearUiListMatrix(laUiListDraw *uild){
  2175. laUiListDrawItem *uildi;
  2176. while (uildi = lstPopItem(uild)){
  2177. memFree(uildi);
  2178. }
  2179. }
  2180. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2181. 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);
  2182. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2183. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2184. int la_TestUiListMinumWidth(laUiList *uil);
  2185. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2186. if (ui){
  2187. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2188. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2189. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2190. p->X = p->TX; p->Y = p->TY;
  2191. p->W = p->TW;
  2192. }
  2193. }
  2194. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2195. int cw = MAIN.CurrentWindow->CW;
  2196. int ch = MAIN.CurrentWindow->CH;
  2197. int PH = p->TH;
  2198. laBoxedTheme*bt = *p->BT;
  2199. int uih=uil->B + bt->BM;
  2200. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2201. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2202. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2203. else p->TH = PH;
  2204. p->H = p->TH;
  2205. if(p->BoundUi){
  2206. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2207. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2208. if (p->X < 0) p->X = 0;
  2209. if (p->Y < 0) p->Y = 0;
  2210. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2211. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2212. }else{
  2213. if (p->Y < 0) p->Y = 0;
  2214. if ((!p->Block)&&(!p->IsMenuPanel)){
  2215. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2216. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2217. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2218. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2219. }
  2220. }
  2221. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2222. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2223. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2224. }
  2225. if (p->ST) p->TY = p->ST;
  2226. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2227. if (p->SB) p->TH = ch - p->TY - p->SB;
  2228. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2229. p->TX = p->X; p->TY = p->Y;
  2230. p->TW = p->W; p->TH = p->H;
  2231. }
  2232. void laPlacePanelForCreation(laPanel *p){
  2233. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2234. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2235. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2236. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2237. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2238. p->TX=p->X; p->TY=p->Y;
  2239. }
  2240. }
  2241. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2242. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2243. tnsViewportWithScissor(0, 0, p->W, p->H);
  2244. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2245. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2246. }
  2247. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2248. tnsDrawToScreen();
  2249. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2250. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2251. }
  2252. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2253. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2254. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2255. }
  2256. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2257. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2258. tnsClearAll();
  2259. }
  2260. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2261. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2262. real Color[] = {1, 1, 1, 1};
  2263. real L, W, U, H;
  2264. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2265. if(MAIN.EnableColorManagement){
  2266. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2267. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2268. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2269. }else{
  2270. tnsUniformOutputColorSpace(T->immShader,0);
  2271. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2272. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2273. }
  2274. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2275. tnsUseNoTexture();
  2276. if (!p->IsMenuPanel){
  2277. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2278. }
  2279. tnsFlush();
  2280. }
  2281. if(p->ParentOperator){
  2282. tnsUseNoTexture();
  2283. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2284. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2285. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2286. }
  2287. switch (p->AnimationMode){
  2288. case 0: /* and */
  2289. case LA_PANEL_ANIMATION_FLASH:
  2290. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2291. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2292. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2293. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2294. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2295. tnsPackAs(GL_TRIANGLES);
  2296. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2297. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2298. }
  2299. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2300. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2301. if((int)(p->AnimationRatio*6)%2){
  2302. tnsUseNoTexture();
  2303. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2304. 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);
  2305. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2306. }
  2307. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2308. }
  2309. break;
  2310. case LA_PANEL_ANIMATION_DROP_DOWN:
  2311. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2312. tnsDraw2DTextureArg(
  2313. p->OffScr->pColor[0],
  2314. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2315. Color,
  2316. 0, 0, 1 - p->AnimationRatio, 0);
  2317. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2318. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2319. break;
  2320. case LA_PANEL_ANIMATION_EXPAND:
  2321. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2322. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2323. W = tnsLinearItp(0, p->W, 0.4);
  2324. H = tnsLinearItp(0, p->H, 0.4);
  2325. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2326. tnsDraw2DTextureArg(
  2327. p->OffScr->pColor[0],
  2328. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2329. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2330. Color,
  2331. 0, 0, 0, 0);
  2332. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2333. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2334. break;
  2335. case LA_PANEL_ANIMATION_DISSOVE:
  2336. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2337. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2338. W = tnsLinearItp(0, p->W, 1.4);
  2339. H = tnsLinearItp(0, p->H, 1.4);
  2340. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2341. if (p->OffScr) tnsDraw2DTextureArg(
  2342. p->OffScr->pColor[0],
  2343. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2344. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2345. Color,
  2346. 0, 0, 0, 0);
  2347. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2348. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2349. break;
  2350. case LA_PANEL_ANIMATION_COLLAPSE:
  2351. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2352. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2353. W = tnsLinearItp(0, p->W, 0.4);
  2354. H = tnsLinearItp(0, p->H, 0.4);
  2355. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2356. if (p->OffScr) tnsDraw2DTextureArg(
  2357. p->OffScr->pColor[0],
  2358. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2359. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2360. Color,
  2361. 0, 0, 0, 0);
  2362. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2363. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2364. break;
  2365. case LA_PANEL_ANIMATION_MINIMIZE:
  2366. L = tnsLinearItp(0, p->X, 0.3);
  2367. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2368. W = tnsLinearItp(0, p->W, 0.4);
  2369. H = tnsLinearItp(0, p->H, 0.4);
  2370. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2371. tnsDraw2DTextureArg(
  2372. p->OffScr->pColor[0],
  2373. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2374. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2375. Color,
  2376. 0, 0, 0, 0);
  2377. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2378. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2379. break;
  2380. }
  2381. tnsFlush();
  2382. tnsUniformOutputColorSpace(T->immShader,0);
  2383. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2384. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2385. }
  2386. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2387. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2388. else{
  2389. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:LA_PANEL_DEFAULT_GL_FORMAT;
  2390. if(p->MenuRefer && (p->MenuRefer->Flags&LA_UI_FLAGS_MENU_FLOAT16)){ GLFormat=GL_RGBA16F; }
  2391. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2392. }
  2393. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2394. }
  2395. void la_PanelRefreshDetachedProp(laPanel *panel){
  2396. laProp *p;
  2397. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2398. la_StepPropPack(&p->DetachedPP);
  2399. la_UsePropPack(&p->DetachedPP, 0);
  2400. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2401. // laUseDataBlock(
  2402. // p->DetachedPP.LastPs->UseInstance,
  2403. // p->DetachedPP.LastPs->p,
  2404. // MAIN.PropMatcherContextP->FrameDistinguish,
  2405. // MAIN.PropMatcherContextP,
  2406. // la_PropPanelUserRemover, 0);
  2407. //}
  2408. }
  2409. }
  2410. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2411. real* color=laThemeColor(bt,LA_BT_BORDER);
  2412. tnsColor4d(0,0,0,Alpha);
  2413. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2414. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2415. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2416. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2417. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2418. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2419. tnsPackAs(GL_TRIANGLE_STRIP);
  2420. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2421. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2422. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2423. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2424. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2425. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2426. }
  2427. int la_AnimateUiListRecursive(laUiList *uil);
  2428. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2429. int DrawState_ = 0;
  2430. laUiListDraw uild = {0}; int orig_refresh=p->Refresh;
  2431. if (p->Show){
  2432. la_SetPropMathcerContext(p);
  2433. MAIN.CurrentPanel = p;
  2434. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2435. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2436. //}
  2437. if (p->Refresh & LA_TAG_RECALC){
  2438. laRecalcPanelImmediate(p);
  2439. }
  2440. if (!p->MenuRefer){
  2441. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2442. if (p->Refresh || !p->OffScr){
  2443. la_PanelDrawToOffsceen(p, &p->UI);
  2444. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2445. la_PanelBackgroundInit(p, bt);
  2446. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2447. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2448. tnsFlush();
  2449. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2450. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2451. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2452. DrawState_++;
  2453. }
  2454. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2455. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2456. if(p->UI.PanY<0){p->UI.PanY=0;}
  2457. DrawState_++;
  2458. }
  2459. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2460. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2461. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2462. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2463. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2464. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2465. if(p!=w->MaximizedUiPanel){
  2466. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2467. }else{
  2468. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2469. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2470. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2471. tnsFlush();
  2472. }
  2473. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2474. }
  2475. }else{
  2476. if (p->Refresh || !p->OffScr){
  2477. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2478. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2479. la_PanelBackgroundInit(p, bt);
  2480. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2481. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2482. tnsFlush();
  2483. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2484. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2485. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2486. DrawState_++;
  2487. }
  2488. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2489. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2490. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2491. DrawState_++;
  2492. }
  2493. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2494. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2495. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2496. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2497. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2498. }
  2499. }
  2500. tnsDrawToScreen();
  2501. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2502. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2503. la_PanelDrawToWindow(p, w);
  2504. }elif (p->AnimationMode){
  2505. la_PanelDrawToWindow(p, w);
  2506. }
  2507. laPerfRecord("%s [%s]",(orig_refresh&LA_TAG_RECALC)?"🌑":
  2508. ((orig_refresh&LA_TAG_REDRAW)?"🌓":
  2509. ((orig_refresh&LA_TAG_ANIMATION)?"🌔":"🌕")), SSTR(p->Title));
  2510. }
  2511. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2512. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2513. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2514. laPanel *pi, *PrevPI;
  2515. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2516. PrevPI = pi->Item.pPrev;
  2517. if (pi->AnimationMode && pi->LaterDestroy){
  2518. lstRemoveItem(&p->SubPanels, pi);
  2519. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2520. continue;
  2521. }
  2522. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2523. la_AttachedPanelDefDraw(w,pi,bt);
  2524. }
  2525. }
  2526. }
  2527. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2528. real PanelSquare[] = {
  2529. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2530. b->X + 2, CH - (b->Y + b->H - 4),
  2531. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2532. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2533. real Center[] = {
  2534. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2535. real DraggingPlot[] = {
  2536. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2537. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2538. PanelSquare[0],
  2539. PanelSquare[1],
  2540. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2541. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2542. PanelSquare[2],
  2543. PanelSquare[3],
  2544. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2545. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2546. PanelSquare[4],
  2547. PanelSquare[5],
  2548. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2549. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2550. PanelSquare[6],
  2551. PanelSquare[7],
  2552. };
  2553. real Square[] = {
  2554. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2555. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2556. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2557. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2558. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2559. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2560. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2561. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2562. };
  2563. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2564. LA_COLOR3(BorderColor4dV), 0,
  2565. LA_COLOR3(BorderColor4dV), 0.8,
  2566. LA_COLOR3(BorderColor4dV), 0,
  2567. LA_COLOR3(BorderColor4dV), 0.8,
  2568. LA_COLOR3(BorderColor4dV), 0,
  2569. LA_COLOR3(BorderColor4dV), 0.8,
  2570. LA_COLOR3(BorderColor4dV), 0,
  2571. };
  2572. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2573. LA_COLOR3(FillColor4dv), 0,
  2574. LA_COLOR3(FillColor4dv), 0.8,
  2575. LA_COLOR3(FillColor4dv), 0,
  2576. LA_COLOR3(FillColor4dv), 0.8,
  2577. LA_COLOR3(FillColor4dv), 0,
  2578. LA_COLOR3(FillColor4dv), 0.8,
  2579. LA_COLOR3(FillColor4dv), 0,
  2580. };
  2581. tnsUseNoTexture();
  2582. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2583. int Index[4];
  2584. tnsVertexArray2d(DraggingPlot, 8);
  2585. tnsColorArray4d(FillColor, 8);
  2586. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2587. case 0:
  2588. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2589. break;
  2590. case LA_BLOCK_DROP_LOCATION_L:
  2591. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2592. break;
  2593. case LA_BLOCK_DROP_LOCATION_R:
  2594. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2595. break;
  2596. case LA_BLOCK_DROP_LOCATION_U:
  2597. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2598. break;
  2599. case LA_BLOCK_DROP_LOCATION_B:
  2600. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2601. break;
  2602. }
  2603. //glDisable(GL_CULL_FACE);
  2604. tnsIndexArray(Index, 4);
  2605. tnsPackAs(GL_TRIANGLE_FAN);
  2606. //tnsFlush();
  2607. }
  2608. tnsVertexArray2d(DraggingPlot, 8);
  2609. tnsColorArray4d(PlotColor, 8);
  2610. tnsPackAs(GL_LINES);
  2611. tnsVertexArray2d(Square, 4);
  2612. tnsColor4dv(BorderColor4dV);
  2613. tnsPackAs(GL_LINE_LOOP);
  2614. glLineWidth(LA_SEAM_W);
  2615. tnsFlush();
  2616. glLineWidth(1);
  2617. }
  2618. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2619. laBoxedTheme *bt = _LA_THEME_TAB;
  2620. laPanel *p;
  2621. real v[] = {
  2622. b->X, CH - b->Y,
  2623. b->X + LA_SEAM_W, CH - b->Y ,
  2624. b->X, CH - (b->Y + b->H),
  2625. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2626. b->X + b->W, CH - (b->Y + b->H),
  2627. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2628. b->X + b->W, CH - b->Y,
  2629. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2630. real tv[8];
  2631. real ratio = 1.0001f;
  2632. int tw = 0;
  2633. int L = LA_RH+LA_SEAM_W;
  2634. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2635. if(MAIN.EnableColorManagement){
  2636. laWindow* w=MAIN.CurrentWindow;
  2637. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2638. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2639. }else{
  2640. tnsUniformOutputColorSpace(T->immShader,0);
  2641. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2642. }
  2643. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2644. tw += p->TitleWidth + LA_SEAM_W*2;
  2645. }
  2646. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2647. tnsUseNoTexture();
  2648. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2649. tnsVertexArray2d(v, 8);
  2650. tnsPackAs(GL_TRIANGLE_STRIP);
  2651. int TitleGap=b->Folded?0:LA_RH;
  2652. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2653. b->X + b->W, (CH - b->Y),
  2654. b->X + b->W, (CH - b->Y - TitleGap),
  2655. b->X, (CH - b->Y - TitleGap));
  2656. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2657. tnsVertexArray2d(tv, 4);
  2658. tnsPackAs(GL_TRIANGLE_FAN);
  2659. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2660. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2661. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2662. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2663. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2664. tnsVertexArray2d(tv, 4);
  2665. tnsPackAs(GL_TRIANGLE_FAN);
  2666. if(b->Folded){
  2667. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2668. 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);
  2669. 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);
  2670. tnsFlush(); return;
  2671. }
  2672. int LT=0,RT=0;
  2673. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2674. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2675. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2676. b->X + L+RT * ratio, (CH - b->Y),
  2677. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2678. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2679. if (p == b->CurrentPanel){
  2680. tnsUseNoTexture();
  2681. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2682. tnsVertexArray2d(tv, 4);
  2683. tnsPackAs(GL_TRIANGLE_FAN);
  2684. 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);
  2685. }else{
  2686. 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);
  2687. }
  2688. LT =RT;
  2689. }
  2690. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2691. tnsFlush();
  2692. tnsUniformOutputColorSpace(T->immShader,0);
  2693. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2694. }
  2695. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2696. laBoxedTheme *bt = _LA_THEME_PANEL;
  2697. real tv[8];
  2698. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2699. if(MAIN.EnableColorManagement){
  2700. laWindow* w=MAIN.CurrentWindow;
  2701. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2702. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2703. }else{
  2704. tnsUniformOutputColorSpace(T->immShader,0);
  2705. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2706. }
  2707. tnsUseNoTexture();
  2708. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2709. b->X + b->W, (CH - b->Y),
  2710. b->X + b->W, (CH - b->Y-b->H),
  2711. b->X, (CH - b->Y-b->H));
  2712. tnsVertexArray2d(tv, 4);
  2713. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2714. tnsPackAs(GL_TRIANGLE_FAN);
  2715. 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,
  2716. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2717. tnsFlush();
  2718. tnsUniformOutputColorSpace(T->immShader,0);
  2719. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2720. }
  2721. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2722. if (b->B1){
  2723. la_BlockDefDrawRecursive(w, bt, b->B1);
  2724. la_BlockDefDrawRecursive(w, bt, b->B2);
  2725. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2726. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2727. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2728. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2729. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2730. la_BlockDefDrawSelf(b, w->CH);
  2731. }else{
  2732. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2733. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2734. la_BlockDefDrawSelfEmpty(b, w->CH);
  2735. }
  2736. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2737. tnsUseNoTexture();
  2738. int at; real tv[8];
  2739. if (b->Vertical){
  2740. at = b->H * b->SplitRatio + b->Y;
  2741. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2742. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2743. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2744. b->X, (w->CH - at - LA_SEAM_W));
  2745. }else{
  2746. at = b->X + b->W * b->SplitRatio;
  2747. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2748. at- LA_SEAM_W, (w->CH - b->Y),
  2749. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2750. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2751. }
  2752. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2753. tnsVertexArray2d(tv, 4);
  2754. tnsPackAs(GL_TRIANGLE_FAN);
  2755. }
  2756. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2757. tnsFlush();
  2758. }
  2759. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2760. if (b->B1){
  2761. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2762. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2763. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2764. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2765. }
  2766. tnsFlush();
  2767. }
  2768. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2769. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2770. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2771. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2772. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2773. if(p->OffScr){
  2774. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2775. }
  2776. }
  2777. }
  2778. void la_ClearUnusedFramebuffers(laWindow* w){
  2779. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2780. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2781. }
  2782. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2783. if(p->Show || p->AnimationMode) continue;
  2784. if(p->OffScr){
  2785. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2786. }
  2787. }
  2788. }
  2789. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2790. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2791. laPanel *p, *NextP;
  2792. laLayout *l = w->CurrentLayout;
  2793. if (!w->CH || !w->CW) return;
  2794. la_ClearUnusedFramebuffers(w);
  2795. tnsDrawToScreen();
  2796. la_RefreshProofingLut();
  2797. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2798. glClearColor(0.2, 0.2, 0.3, 1.0);
  2799. tnsClearAll();
  2800. tnsUseNoTexture();
  2801. if (l->Draw) l->Draw(w, l);
  2802. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2803. glEnable(GL_BLEND);
  2804. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2805. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2806. laUiItem* ui;
  2807. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2808. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2809. la_SetPropMathcerContext(p);
  2810. if(p->Refresh){
  2811. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2812. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2813. if(MAIN.EnableColorManagement){
  2814. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2815. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2816. }else{
  2817. tnsUniformOutputColorSpace(T->immShader,0);
  2818. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2819. }
  2820. if(p->Refresh&LA_TAG_RECALC){
  2821. laRecalcPanelImmediate(p);
  2822. }
  2823. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2824. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2825. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2826. }
  2827. tnsDrawToScreen();
  2828. tnsResetViewMatrix();
  2829. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2830. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2831. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2832. tnsFlush();
  2833. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2834. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2835. tnsFlush();
  2836. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2837. }
  2838. }
  2839. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2840. la_AttachedPanelDefDraw(w,p,*p->BT);
  2841. }else{
  2842. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2843. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2844. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2845. }
  2846. for (p = w->Panels.pLast; p; p = NextP){
  2847. NextP = p->Item.pPrev;
  2848. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2849. if (p->AnimationMode && p->LaterDestroy){
  2850. lstRemoveItem(&w->Panels, p);
  2851. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2852. continue;
  2853. }
  2854. la_PanelDefDraw(w, p, *p->BT);
  2855. }
  2856. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2857. la_AttachedPanelDefDraw(w,p,*p->BT);
  2858. }
  2859. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2860. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2861. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2862. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2863. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2864. tnsFlush();
  2865. }
  2866. for (p = w->FadingPanels.pLast; p; p = NextP){
  2867. NextP = p->Item.pPrev;
  2868. if (!p->AnimationMode){
  2869. lstRemoveItem(&w->FadingPanels, p);
  2870. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2871. laDeferredDestroyPanel(p, 0);
  2872. }else
  2873. la_PanelDrawToWindow(p, w);
  2874. }
  2875. if(MAIN.ShowPerf){
  2876. la_PerfDraw();
  2877. }
  2878. }
  2879. int laStartWindow(laWindow *w){
  2880. #ifdef LA_LINUX
  2881. XMapWindow(MAIN.dpy,w->win);
  2882. tnsContextMakeWindowCurrent(w);
  2883. #endif
  2884. #ifdef _WIN32
  2885. ShowWindow(w->win, SW_SHOWNORMAL);
  2886. #endif
  2887. MAIN.CurrentWindow = w;
  2888. if(!w->CurrentLayout){
  2889. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2890. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2891. }
  2892. laRedrawCurrentWindow();
  2893. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2894. w->Shown = 1;
  2895. }
  2896. void la_AssignWindowPP(laWindow* w){
  2897. w->PP.EndInstance = w;
  2898. w->PP.LastPs = &w->FakePS;
  2899. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2900. w->PP.LastPs->UseInstance = w;
  2901. w->PP.LastPs->Type = U'.';
  2902. }
  2903. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2904. #ifdef LAGUI_ANDROID
  2905. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2906. #endif
  2907. laWindow *n = memAcquire(sizeof(laWindow));
  2908. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2909. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2910. #ifdef LAGUI_ANDROID
  2911. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2912. #endif
  2913. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2914. lstAppendItem(&MAIN.Windows, n);
  2915. MAIN.CurrentWindow = n;
  2916. la_AssignWindowPP(n);
  2917. laui_DefaultMenuBar(n);
  2918. return n;
  2919. }
  2920. void laSetWindowCursor(int id){
  2921. MAIN.CurrentCursor = id;
  2922. #ifdef LA_LINUX
  2923. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2924. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2925. #endif
  2926. #ifdef _WIN32
  2927. SetCursor(la_ConvertCursorID(id));
  2928. #endif
  2929. };
  2930. void la_AssignBlockPP(laBlock* b){
  2931. b->PP.EndInstance = b;
  2932. b->PP.LastPs = &b->FakePS;
  2933. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2934. b->PP.LastPs->UseInstance = b;
  2935. b->PP.LastPs->Type = U'.';
  2936. }
  2937. void laDestroyLayout(laWindow *w, laLayout* l){
  2938. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2939. laDestroyBlocksRecursive(l->FirstBlock);
  2940. strSafeDestroy(&l->ID);
  2941. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2942. lstRemoveItem(&w->Layouts,l); memFree(l);
  2943. }
  2944. laLayout *laDesignLayout(laWindow *w, char *Title){
  2945. laLayout *l = memAcquire(sizeof(laLayout));
  2946. l->FirstBlock = memAcquire(sizeof(laBlock));
  2947. la_AssignBlockPP(l->FirstBlock);
  2948. lstAppendItem(&w->Layouts, l);
  2949. strSafeSet(&l->ID, Title);
  2950. memAssignRef(w, &w->CurrentLayout, l);
  2951. laRenameWindow(w, Title);
  2952. return l;
  2953. }
  2954. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2955. 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); }
  2956. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2957. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2958. laNotifyUsers("la.windows.maximized_block"); }
  2959. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2960. laNotifyUsers("la.windows.maximized_block"); }
  2961. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2962. laRestoreCanvasUI();
  2963. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2964. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2965. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2966. UiParentPanel->Show=0;
  2967. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2968. }
  2969. void laRestoreCanvasUI(){
  2970. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2971. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2972. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2973. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2974. }
  2975. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2976. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2977. }
  2978. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2979. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2980. laPanel *p;
  2981. b->SplitRatio = Percentage;
  2982. b->Vertical = 0;
  2983. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2984. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2985. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2986. p->Block = b->B1;
  2987. }
  2988. b->B1->Panels.pFirst = b->Panels.pFirst;
  2989. b->B1->Panels.pLast = b->Panels.pLast;
  2990. b->B1->CurrentPanel = b->CurrentPanel;
  2991. b->B1->parent = b->B2->parent=b;
  2992. b->Panels.pFirst = 0;
  2993. b->Panels.pLast = 0;
  2994. b->CurrentPanel = 0;
  2995. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2996. }
  2997. void laSplitBlockVertical(laBlock *b, real Percentage){
  2998. laPanel *p;
  2999. b->SplitRatio = Percentage;
  3000. b->Vertical = 1;
  3001. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  3002. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  3003. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3004. p->Block = b->B1;
  3005. }
  3006. b->B1->Panels.pFirst = b->Panels.pFirst;
  3007. b->B1->Panels.pLast = b->Panels.pLast;
  3008. b->B1->CurrentPanel = b->CurrentPanel;
  3009. b->B1->parent = b->B2->parent=b;
  3010. b->Panels.pFirst = 0;
  3011. b->Panels.pLast = 0;
  3012. b->CurrentPanel = 0;
  3013. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3014. }
  3015. void laCombineChildBlocks(laBlock *b){
  3016. laPanel *p; if(!b) return;
  3017. if (!b->B1->B1 && !b->B2->B1){
  3018. lstCombineLists(&b->Panels, &b->B1->Panels);
  3019. lstCombineLists(&b->Panels, &b->B2->Panels);
  3020. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3021. p->Block = b;
  3022. }
  3023. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  3024. memFree(b->B1);
  3025. memFree(b->B2);
  3026. b->B1 = 0;
  3027. b->B2 = 0;
  3028. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3029. }elif(!b->B1->B1){
  3030. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  3031. b->Vertical = b->B2->Vertical;
  3032. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  3033. p->Block = b1;
  3034. }
  3035. lstCombineLists(&b1->Panels, &b->B1->Panels);
  3036. memFree(b->B1); memFree(b->B2);
  3037. b->B1 = b1; b->B2 = b2;
  3038. b1->parent = b; b2->parent = b;
  3039. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3040. }elif(!b->B2->B1){
  3041. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  3042. b->Vertical = b->B1->Vertical;
  3043. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  3044. p->Block = b1;
  3045. }
  3046. lstCombineLists(&b1->Panels, &b->B2->Panels);
  3047. memFree(b->B1); memFree(b->B2);
  3048. b->B1 = b1; b->B2 = b2;
  3049. b1->parent = b; b2->parent = b;
  3050. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3051. }
  3052. }
  3053. laBlock *laBlock1(laBlock *b){
  3054. return b->B1;
  3055. }
  3056. laBlock *laBlock2(laBlock *b){
  3057. return b->B2;
  3058. }
  3059. laBlock *laSwapSubBlocks(laBlock *b){
  3060. laBlock *tB;
  3061. tB = b->B2;
  3062. b->B2 = b->B1;
  3063. b->B1 = tB;
  3064. b->SplitRatio = 1 - b->SplitRatio;
  3065. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3066. }
  3067. void laDestroyBlocksRecursive(laBlock *Root){
  3068. laPanel *p;
  3069. if (Root->B1){
  3070. laDestroyBlocksRecursive(Root->B1);
  3071. laDestroyBlocksRecursive(Root->B2);
  3072. }else{
  3073. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  3074. }
  3075. memFree(Root);
  3076. }
  3077. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  3078. if(!b->CurrentPanel ) return 0;
  3079. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  3080. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  3081. lstRemoveItem(&b->Panels, p);
  3082. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  3083. if(!p->TitleBar.UiItems.pFirst){
  3084. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  3085. }
  3086. p->Mode = LA_PANEL_FLOATING_TOP;
  3087. p->TY-=LA_RH; p->TH+=LA_RH;
  3088. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  3089. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  3090. p->Block = 0;
  3091. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  3092. laRecalcPanel(p);
  3093. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3094. p->BT = &_LA_THEME_FLOATING_PANEL;
  3095. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3096. laNotifyUsers("la.windows.panels");
  3097. return b->CurrentPanel;
  3098. }
  3099. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  3100. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  3101. lstRemoveItem(&from->Panels, p);
  3102. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3103. p->Mode = LA_PANEL_NORMAL;
  3104. p->Block=b;
  3105. b->CurrentPanel = p;
  3106. b->Folded = 0;
  3107. lstPushItem(&b->Panels, p);
  3108. laRecalcPanel(p);
  3109. p->BT = &_LA_THEME_PANEL;
  3110. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3111. tnsFlush();
  3112. laNotifyUsers("la.windows.panels");
  3113. }
  3114. void laPopPanel(laPanel *p){
  3115. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  3116. lstRemoveItem(&p->Parent->SubPanels, p);
  3117. lstPushItem(&p->Parent->SubPanels, p);
  3118. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3119. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3120. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3121. laNotifyUsers("la.windows.panels");
  3122. }
  3123. }
  3124. void la_EnsurePanelExtras(laPanel *p){
  3125. laUiTemplate* uit=p->PanelTemplate;
  3126. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  3127. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  3128. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  3129. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  3130. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  3131. p->PropLinkFakeProp->Base.Offset = 0;
  3132. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  3133. p->PropLinkPP.EndInstance = p;
  3134. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3135. p->PropLinkPP.LastPs->Type = U'.';
  3136. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3137. }
  3138. laPanel* la_GivePanelNode(){
  3139. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3140. return memAcquire(sizeof(laPanel));
  3141. }
  3142. void la_ReturnPanelNode(laPanel* p){
  3143. memset(p,0,sizeof(laPanel));
  3144. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3145. lstAppendItem(&MAIN.WastedPanels, p);
  3146. }
  3147. 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){
  3148. laPanel *p = la_GivePanelNode();
  3149. int CW = MAIN.CurrentWindow->CW;
  3150. int CH = MAIN.CurrentWindow->CH;
  3151. p->PanelTemplate = uit;
  3152. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3153. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3154. if (!MaxW) MaxW = 10000;
  3155. if (!MaxH) MaxH = 10000;
  3156. if (W > MaxW) W = MaxW;
  3157. if (H > MaxH) H = MaxH;
  3158. if (W < MinW) W = MinW;
  3159. if (H < MinH) H = MinH;
  3160. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3161. p->X = p->TX = (X < 0 ? 0 : X);
  3162. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3163. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3164. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3165. p->MaxW = MaxW; p->MaxH = MaxH;
  3166. p->MinW = MinW; p->MinH = MinH;
  3167. p->SL = SnapL; p->ST = SnapT;
  3168. p->SR = SnapR; p->SB = SnapB;
  3169. if (p->SR) p->X = CW - p->W - p->SR;
  3170. if (p->SB) p->Y = CH - p->H - p->SB;
  3171. la_EnsurePanelSnapping(p, CW, CH);
  3172. p->Show = 1;
  3173. p->PP.EndInstance = p;
  3174. p->PP.LastPs = &p->FakePS;
  3175. p->PP.LastPs->p = _LA_PROP_PANEL;
  3176. p->PP.LastPs->UseInstance = p;
  3177. p->PP.LastPs->Type = U'.';
  3178. la_EnsurePanelExtras(p);
  3179. laRecalcPanel(p);
  3180. p->FrameDistinguish = 100; //greater than 1 is ok
  3181. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3182. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3183. return p;
  3184. }
  3185. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3186. if(!uit) return 0;
  3187. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3188. strSafeSet(&p->Title, uit->Title->Ptr);
  3189. p->PanelTemplate = uit;
  3190. p->Show = 1;
  3191. p->PP.EndInstance = p;
  3192. p->PP.LastPs = &p->FakePS;
  3193. p->PP.LastPs->p = _LA_PROP_PANEL;
  3194. p->PP.LastPs->UseInstance = p;
  3195. p->PP.LastPs->Type = U'.';
  3196. la_EnsurePanelExtras(p);
  3197. laRecalcPanel(p);
  3198. p->FrameDistinguish = 100; //greater than 1 is ok
  3199. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3200. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3201. p->Block = b; b->CurrentPanel = p;
  3202. if(uit->PropFunc){ uit->PropFunc(p); }
  3203. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3204. laNotifyUsers("la.windows.panels");
  3205. return p;
  3206. }
  3207. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3208. laUiTemplate* uit=laFindUiTemplate(template_id);
  3209. return laCreatePanelT(b, uit);
  3210. }
  3211. 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){
  3212. laUiTemplate* uit=0;
  3213. if(template_id) uit=laFindUiTemplate(template_id);
  3214. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3215. p->Mode = LA_PANEL_FLOATING_TOP;
  3216. laPlacePanelForCreation(p);
  3217. if(uit){
  3218. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3219. }
  3220. if (w) lstPushItem(&w->Panels, p);
  3221. return p;
  3222. }
  3223. void laShowPanel(laPanel *p){
  3224. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3225. }
  3226. void laShowPanelWithDropDownEffect(laPanel *p){
  3227. laShowPanel(p);
  3228. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3229. p->AnimationRatio = 0;
  3230. }
  3231. void laShowPanelWithExpandEffect(laPanel *p){
  3232. laShowPanel(p);
  3233. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3234. p->AnimationRatio = 0;
  3235. }
  3236. void laHidePanel(laPanel *p){
  3237. if (!p->Mode) return;
  3238. p->Show = 0;
  3239. laNotifyUsers("la.windows.panels_hidden");
  3240. }
  3241. void laHidePanelWithDissoveEffect(laPanel *p){
  3242. if (!p->Mode) return;
  3243. laHidePanel(p);
  3244. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3245. p->AnimationRatio = 1;
  3246. }
  3247. void laHidePanelWithCollapseEffect(laPanel *p){
  3248. if (!p->Mode) return;
  3249. laHidePanel(p);
  3250. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3251. p->AnimationRatio = 1;
  3252. }
  3253. void laHidePanelWithMinimizeEffect(laPanel *p){
  3254. if (!p->Mode) return;
  3255. laHidePanel(p);
  3256. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3257. p->AnimationRatio = 1;
  3258. }
  3259. void laActivatePanel(char* TemplateID, int x, int y){
  3260. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3261. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3262. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3263. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3264. }
  3265. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3266. p->UI.PanX += DeltaX;
  3267. p->UI.PanY += DeltaY;
  3268. }
  3269. int laPanUiListFree(laUiList *uil, int X, int Y){
  3270. uil->PanX+=X; uil->PanY+=Y;
  3271. }
  3272. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3273. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3274. if(Y){X+=Y;Y=0;}
  3275. }
  3276. if (Y > 0){
  3277. if (uil->B - uil->PanY <= B) return 0;
  3278. else{
  3279. uil->PanY += Y;
  3280. if (uil->B - uil->PanY <= B){
  3281. uil->PanY = uil->B - B;
  3282. return 1;
  3283. }
  3284. }
  3285. }
  3286. if (Y < 0){
  3287. if (uil->U - uil->PanY >= U) return 0;
  3288. else{
  3289. uil->PanY += Y;
  3290. if (uil->U - uil->PanY >= U){
  3291. uil->PanY = uil->U - U;
  3292. return 1;
  3293. }
  3294. }
  3295. }
  3296. if(uil->AllowScale){
  3297. laPanUiListFree(uil, X, 0);
  3298. }else{
  3299. if (X > 0){
  3300. if (uil->R - uil->PanX <= R) return 0;
  3301. else{
  3302. uil->PanX += X;
  3303. if (uil->R - uil->PanX <= R){
  3304. uil->PanX = uil->R - R;
  3305. return 1;
  3306. }
  3307. }
  3308. }
  3309. if (X < 0){
  3310. if (uil->L - uil->PanX >= L) return 0;
  3311. else{
  3312. uil->PanX += X;
  3313. if (uil->L - uil->PanX >= L){
  3314. uil->PanX = uil->L - L;
  3315. return 1;
  3316. }
  3317. }
  3318. }
  3319. }
  3320. return 1;
  3321. }
  3322. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3323. int ret=1;
  3324. if(!uil->AllowScale){ return 0; }
  3325. real NewScale=uil->Scale*factor;
  3326. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3327. if(NewScale>5) {NewScale=5; ret=0;}
  3328. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3329. factor=NewScale/uil->Scale;
  3330. uil->Scale=NewScale;
  3331. real mx=(L+R)/2,my=(U+B)/2;
  3332. real dx= (mx+uil->PanX)*factor;
  3333. real dy= (my+uil->PanY)*factor;
  3334. uil->PanX=dx-mx;
  3335. uil->PanY=dy-my;
  3336. MAIN.CurrentPanel->FrameDistinguish=100;
  3337. return ret;
  3338. }
  3339. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3340. if(uil->AllowScale) return 0;
  3341. return laPanUiList(uil,X,Y,L,R,U,B);
  3342. }
  3343. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3344. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3345. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3346. strSafeSet(&p->Title, Title);
  3347. if (Define){
  3348. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3349. }
  3350. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3351. p->BT= &_LA_THEME_FLOATING_PANEL;
  3352. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3353. p->BoundUi = 1;
  3354. return p;
  3355. }
  3356. 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,
  3357. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3358. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3359. strSafeSet(&p->Title, Title);
  3360. if (Define){
  3361. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3362. }
  3363. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3364. p->BT= &_LA_THEME_FLOATING_PANEL;
  3365. p->Mode = LA_PANEL_FLOATING_TOP;
  3366. p->BoundUi = 1;
  3367. return p;
  3368. }
  3369. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3370. laPanel *ip;
  3371. tnsDelete2DOffscreen(p->OffScr);
  3372. p->OffScr = 0;
  3373. strSafeDestroy(&p->Title);
  3374. if (!p->AnimationMode){
  3375. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3376. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3377. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3378. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3379. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3380. }else if (p->Block){
  3381. lstRemoveItem(&p->Block->Panels, p);
  3382. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3383. }
  3384. laNotifyUsers("la.windows.panels");
  3385. }
  3386. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3387. //lstRemoveItem(&p->SubPanels, ip);
  3388. laDestroySinglePanel(ip, immediate);
  3389. laNotifyUsers("la.windows.panels");
  3390. }
  3391. la_ClearDetachedProp(p);
  3392. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3393. la_ReturnPanelNode(p);
  3394. }
  3395. void laDestroySinglePanel(laPanel *p, int immediate){
  3396. la_SetPropMathcerContext(p);
  3397. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3398. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3399. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3400. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3401. }
  3402. }
  3403. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3404. la_DestroyUiList(&p->UI, 1, 1, 0);
  3405. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3406. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3407. if (p->Mode){
  3408. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3409. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3410. }
  3411. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3412. if (la_UiStillInService(p)){
  3413. la_StopUiOperatorService(p);
  3414. }
  3415. if ((!p->AnimationMode) || immediate){
  3416. laDeferredDestroyPanel(p, immediate);
  3417. }else{
  3418. p->LaterDestroy = 1;
  3419. }
  3420. }
  3421. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3422. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3423. int MinW,MinWt=0;
  3424. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3425. int CW = MAIN.CurrentWindow->CW;
  3426. if(p->SL && p->SR){return 0;}
  3427. la_SetPropMathcerContext(p);
  3428. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3429. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3430. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3431. MinW = la_TestUiListMinumWidth(uil);
  3432. if (MinW<MinWt){MinW=MinWt;}
  3433. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3434. if (MinW > 20){
  3435. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3436. }
  3437. la_PanelValidateWidth(p,uil);
  3438. laEnsurePanelInBound(p,uil);
  3439. if(p->TW>CW){ p->TW=CW; }
  3440. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3441. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3442. laRedrawPanel(p);
  3443. return 1;
  3444. }
  3445. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3446. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3447. laOperator *ai = a;
  3448. laPanel *p;
  3449. int GX, GY, GW, t = 0;
  3450. int b;
  3451. laUiDefineFunc def = ReplaceUiDefine;
  3452. int MinW;
  3453. if (!def){ def=laui_DefaultPropDetails; }
  3454. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3455. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3456. laEnclosePanelContent(p, &p->UI);
  3457. laSetOperatorLocalizer(p);
  3458. p->CloseWhenMovedOut=1;
  3459. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3460. //laShowPanelWithDropDownEffect(p);
  3461. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3462. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3463. return p;
  3464. }
  3465. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3466. laPanel *p;
  3467. int GX, GY, GW, t = 0;
  3468. int b;
  3469. laUiDefineFunc def = ReplaceUiDefine;
  3470. int MinW;
  3471. if (!def) return 0;
  3472. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3473. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3474. p->Mode = LA_PANEL_FLOATING_TOP;
  3475. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3476. laEnclosePanelContent(p, &p->UI);
  3477. if(MAIN.CurrentWindow->Operators.pFirst){
  3478. laSetOperatorLocalizer(MAIN.PendingSplash);
  3479. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3480. MAIN.PendingSplash=0;
  3481. }
  3482. //laShowPanelWithExpandEffect(p);
  3483. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3484. return p;
  3485. }
  3486. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3487. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3488. laOperator *ai = a;
  3489. laPanel *p; laPropContainer* sub;
  3490. int GX, GY, GW, t = 0;
  3491. int b;
  3492. laUiDefineFunc def = ReplaceUiDefine;
  3493. int MinW;
  3494. if (!def){
  3495. if (This && This->LastPs->p){
  3496. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3497. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3498. }
  3499. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3500. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3501. }
  3502. GX = L; GY = B;
  3503. GW = (R - L) > MaxW ? MaxW : (R - L);
  3504. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3505. laEnclosePanelContent(p, &p->UI);
  3506. laSetOperatorLocalizer(p);
  3507. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3508. laShowPanelWithDropDownEffect(p);
  3509. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3510. if(Attachment){
  3511. p->Parent = Attachment;
  3512. lstAppendItem(&Attachment->SubPanels, p);
  3513. }
  3514. return p;
  3515. }
  3516. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3517. laPanel *p;
  3518. int t = 0;
  3519. int b;
  3520. //laLocalToWindow(0, Attachment, &L, &t);
  3521. //laLocalToWindow(0, Attachment, &R, &U);
  3522. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3523. laSetOperatorLocalizer(p);
  3524. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3525. laShowPanelWithDropDownEffect(p);
  3526. p->Parent = Attachment;
  3527. lstPushItem(&Attachment->SubPanels, p);
  3528. return p;
  3529. }
  3530. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3531. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3532. laOperator *ai = a;
  3533. laPanel *p;
  3534. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3535. int GX, GY, GW, t = 0;
  3536. int b;
  3537. int MinW;
  3538. //laLocalToWindow(0,Attachment, &L, &t);
  3539. //laLocalToWindow(0,Attachment, &R, &B);
  3540. GX = L;
  3541. GY = B;
  3542. GW = (R - L) > MaxW ? MaxW : (R - L);
  3543. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3544. p->MenuRefer = MenuRefer;
  3545. laEnclosePanelContent(p, MenuRefer);
  3546. laSetOperatorLocalizer(p);
  3547. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3548. laShowPanelWithDropDownEffect(p);
  3549. p->Parent = Attachment;
  3550. lstPushItem(&Attachment->SubPanels, p);
  3551. return p;
  3552. }
  3553. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3554. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3555. laOperator *ai = a;
  3556. laPanel *p;
  3557. int GX, GY, GW, t = 0;
  3558. int b;
  3559. GX = L;
  3560. GY = B;
  3561. GW = MaxW;
  3562. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3563. p->MenuRefer = &p->UI;
  3564. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3565. laSetOperatorLocalizer(p);
  3566. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3567. laShowPanelWithDropDownEffect(p);
  3568. if (Attachment){
  3569. p->Parent = Attachment;
  3570. lstPushItem(&Attachment->SubPanels, p);
  3571. }else{
  3572. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3573. }
  3574. return p;
  3575. }
  3576. 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){
  3577. laOperator *ai = For;
  3578. laPanel *p;
  3579. int b;
  3580. laUiDefineFunc def = 0;
  3581. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3582. else def = laui_DefaultPropUiDefine;
  3583. For->PP.EndInstance = For->CustomData;
  3584. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3585. laEnclosePanelContent(p, &p->UI);
  3586. MAIN.ToPanel = p;
  3587. laShowPanelWithExpandEffect(p);
  3588. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3589. ai->OperatorPanel = p;
  3590. p->ParentOperator = For;
  3591. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3592. return p;
  3593. }
  3594. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3595. laPanel *p; int b; laUiList *uil; laColumn* col;
  3596. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3597. strSafeSet(&p->Title, Title);
  3598. p->BoundUi = 1;
  3599. p->Mode = LA_PANEL_FLOATING_TOP;
  3600. p->BT = &_LA_THEME_FLOATING_PANEL;
  3601. MAIN.ToPanel = p;
  3602. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3603. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3604. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3605. laUiItem* r=laBeginRow(uil,col,0,0);
  3606. laShowSeparator(uil,col)->Expand=1;
  3607. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3608. laEndRow(uil,r);
  3609. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3610. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3611. laSetOperatorLocalizer(p);
  3612. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3613. return p;
  3614. }
  3615. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3616. laPanel *p; int b; laUiList *uil; laColumn* col;
  3617. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3618. strSafeSet(&p->Title, Title);
  3619. p->BoundUi = 1;
  3620. p->Mode = LA_PANEL_FLOATING_TOP;
  3621. p->BT = &_LA_THEME_FLOATING_PANEL;
  3622. MAIN.ToPanel = p;
  3623. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3624. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3625. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3626. laUiItem* r = laBeginRow(uil,col,0,0);
  3627. laShowSeparator(uil,col)->Expand=1;
  3628. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3629. laEndRow(uil, r);
  3630. laEnclosePanelContent(p,uil);
  3631. laShowPanelWithExpandEffect(p);
  3632. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3633. laSetOperatorLocalizer(p);
  3634. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3635. return p;
  3636. }
  3637. void laOperatorModalOver(laOperator* For){
  3638. For->ModalOver = 1;
  3639. }
  3640. void laDeferredRedraw(laPanel* p){
  3641. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3642. if(lip->p==p) return;
  3643. }
  3644. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3645. }
  3646. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3647. laWindow* cur=MAIN.CurrentWindow;
  3648. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3649. MAIN.CurrentWindow=w;
  3650. la_UpdateUiPlacement(w);
  3651. }
  3652. MAIN.CurrentWindow=cur;
  3653. }
  3654. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3655. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3656. }
  3657. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3658. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3659. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3660. void laRedrawCurrentPanel(){
  3661. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3662. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3663. }
  3664. void laRecalcCurrentPanel(){
  3665. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3666. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3667. }
  3668. void laRecalcPanelImmediate(laPanel* p){
  3669. p->FrameDistinguish++;
  3670. laBoxedTheme* bt = (*p->BT);
  3671. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3672. la_PanelRefreshDetachedProp(p);
  3673. int enclosed=0;
  3674. if(p->BoundUi || p->MenuRefer){
  3675. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3676. else enclosed=laEnclosePanelContent(p, &p->UI);
  3677. }
  3678. if(!enclosed){
  3679. la_PanelValidateWidth(p,&p->UI);
  3680. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3681. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3682. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3683. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3684. }
  3685. laWindow* w=MAIN.CurrentWindow;
  3686. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3687. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3688. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3689. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3690. }
  3691. }
  3692. void laRecalcCurrentPanelImmediate(){
  3693. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3694. }
  3695. int laNonFixedPanelExists(laPanel *p){
  3696. laPanel *ip;
  3697. if (!p) return 0;
  3698. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3699. // if (ip == p) return 1;
  3700. //}
  3701. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3702. if (ip == p) return 1;
  3703. }
  3704. return 0;
  3705. }
  3706. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3707. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3708. return 1;
  3709. }
  3710. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3711. int tt=MAIN.TooltipCloseDistance;
  3712. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3713. return 1;
  3714. }
  3715. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3716. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3717. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3718. return 0;
  3719. return 1;
  3720. }
  3721. void laUnlinkSharedPanel(laPanel *p){
  3722. laWindow *w;
  3723. laPanel *ip;
  3724. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3725. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3726. if (ip == p){
  3727. lstRemoveItem(&w->Panels, ip);
  3728. return;
  3729. }
  3730. }
  3731. }
  3732. }
  3733. int laIsPanelCovered(laPanel *p){
  3734. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3735. laPanel *ip;
  3736. laPanel *resp;
  3737. int in1 = 0, in2 = 0, in3 = 0;
  3738. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3739. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3740. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3741. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3742. //}
  3743. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3744. if (ip == p){
  3745. in3 = 1;
  3746. d3 = 0;
  3747. continue;
  3748. }
  3749. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3750. }
  3751. if (!in2 && !in3) in1 = 1;
  3752. if (in1){
  3753. if (d1 || d2 || d3) return 1;
  3754. }else{
  3755. if (in2){
  3756. if (d2 || d3) return 1;
  3757. }else if (in3)
  3758. if (d3) return 1;
  3759. }
  3760. return 0;
  3761. }
  3762. int laIsTopPanel(laPanel *p){
  3763. //if (!p->Item.pPrev) return 1;
  3764. //else {
  3765. if (!laIsPanelCovered(p)){
  3766. //laPopPanel(p);
  3767. return 1;
  3768. }
  3769. return 0;
  3770. //}
  3771. return 0;
  3772. }
  3773. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3774. if(!p) return;
  3775. int ix = *x, iy = *y;
  3776. laListItemPointer *lip;
  3777. laOperator *ai = a;
  3778. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3779. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3780. if (a){
  3781. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3782. laUiList *uil = lip->p;
  3783. (*x) += uil->PanX;
  3784. (*y) += uil->PanY;
  3785. }
  3786. }
  3787. }
  3788. void laPanelToLocal(laOperator *a, int *x, int *y){
  3789. int ix = *x, iy = *y;
  3790. laListItemPointer *lip;
  3791. if (a){
  3792. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3793. laUiList *uil = lip->p;
  3794. (*x) += uil->PanX;
  3795. (*y) += uil->PanY;
  3796. }
  3797. }
  3798. }
  3799. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3800. if(!p) return;
  3801. int ix = *x, iy = *y;
  3802. laListItemPointer *lip;
  3803. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3804. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3805. if (a){
  3806. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3807. laUiList *uil = lip->p;
  3808. (*x) -= uil->PanX;
  3809. (*y) -= uil->PanY;
  3810. }
  3811. }
  3812. }
  3813. void laPanelToWindow(laPanel *p, int *x, int *y){
  3814. int ix = *x, iy = *y;
  3815. laListItemPointer *lip;
  3816. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3817. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3818. }
  3819. void laLocalToPanel(laOperator *a, int *x, int *y){
  3820. int ix = *x, iy = *y;
  3821. laListItemPointer *lip;
  3822. if (a){
  3823. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3824. laUiList *uil = lip->p;
  3825. (*x) -= uil->PanX;
  3826. (*y) -= uil->PanY;
  3827. }
  3828. }
  3829. }
  3830. void laSetNextMenuPos(int X, int Y, int W, int H){
  3831. MAIN.NextX = X;
  3832. MAIN.NextY = Y;
  3833. MAIN.NextW = W;
  3834. MAIN.NextH = H;
  3835. }
  3836. int laIsInBlock(laBlock *b, int X, int Y){
  3837. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3838. return 0;
  3839. }
  3840. 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; }
  3841. 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; }
  3842. 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; }
  3843. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3844. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3845. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3846. if (!b->B1 && !b->B2){
  3847. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3848. }
  3849. }
  3850. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3851. laPanel *p;
  3852. laBlock *sb = 0;
  3853. if (!laIsInBlock(b, X, Y)) return 0;
  3854. if (!b->B1 && !b->B2) return b;
  3855. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3856. return laDetectBlockRecursive(b->B2, X, Y);
  3857. }
  3858. laPanel *laDetectPanel(int X, int Y){
  3859. laPanel *p; laBlock *b;
  3860. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3861. int x = X, y = Y;
  3862. laWindowToLocal(0, p, &x, &y);
  3863. if (p->Show && laIsInPanel(p, x, y)){
  3864. return p;
  3865. }
  3866. }
  3867. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3868. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3869. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3870. return 0;
  3871. }
  3872. laUiList *laPrepareUi(laPanel *p){
  3873. return &p->UI;
  3874. }
  3875. laColumn *laFirstColumn(laUiList *uil){
  3876. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3877. else{
  3878. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3879. c->SP = 1;
  3880. c->PreWidth = 1;
  3881. lstAppendItem(&uil->Columns, c);
  3882. c->Top = c;
  3883. return uil->Columns.pFirst;
  3884. }
  3885. }
  3886. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3887. laColumn *lc, *rc;
  3888. if (c->LS || c->RS) return c;
  3889. lc = memAcquireSimple(sizeof(laColumn));
  3890. rc = memAcquireSimple(sizeof(laColumn));
  3891. c->LS = lc;
  3892. c->RS = rc;
  3893. c->LS->SP = Percent;
  3894. c->RS->SP = Percent;
  3895. c->LS->Top = c->Top;
  3896. c->RS->Top = c->Top;
  3897. if (uil){
  3898. lstAppendItem(&uil->Columns, lc);
  3899. lstAppendItem(&uil->Columns, rc);
  3900. }
  3901. if (c->LS && c->RS->MaxW == 0){
  3902. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3903. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3904. }else if (c->RS && c->LS->MaxW == 0){
  3905. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3906. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3907. }
  3908. return c;
  3909. }
  3910. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3911. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3912. return c->LS;
  3913. }
  3914. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3915. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3916. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3917. return c->RS;
  3918. }
  3919. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3920. lstRemoveItem(List, c);
  3921. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3922. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3923. memFree(c);
  3924. }
  3925. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3926. laUiList *uil = TopUil;
  3927. laUiList *sub;
  3928. laUiItem *ui;
  3929. laColumn *cc, *NextCC = 0;
  3930. int Occupied = 0;
  3931. int Removed = 0;
  3932. if (!c->LS) return 0;
  3933. else{
  3934. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3935. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3936. }
  3937. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3938. if (ui->C == c->LS || ui->C == c->RS){
  3939. if (DoMerge){
  3940. ui->C = c;
  3941. Occupied = 1;
  3942. }else
  3943. return 1;
  3944. }
  3945. if (ui->Subs.pFirst){
  3946. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3947. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3948. }
  3949. }
  3950. }
  3951. if (!Removed){
  3952. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3953. if (cc == c){
  3954. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3955. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3956. c->LS = 0;
  3957. c->RS = 0;
  3958. Removed = 1;
  3959. break;
  3960. }
  3961. }
  3962. }
  3963. return Occupied;
  3964. }
  3965. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3966. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3967. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3968. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3969. ut->FakeProp->Base.Identifier = ut->Identifier;
  3970. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3971. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3972. ut->FakeProp->Base.OffsetIsPointer = 1;
  3973. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3974. return ut->ExtraProps;
  3975. }
  3976. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3977. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3978. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3979. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3980. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3981. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3982. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3983. ct->FakeProp->Base.OffsetIsPointer = 1;
  3984. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3985. return ct->ExtraProps;
  3986. }
  3987. void la_DestroyUiType(laUiType* uit){
  3988. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3989. memFree(uit);
  3990. }
  3991. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3992. laUiType *ut = memAcquire(sizeof(laUiType));
  3993. ut->Identifier = Identifer;
  3994. ut->OperatorID = UseOperator;
  3995. ut->Draw = Draw;
  3996. ut->Theme = bt;
  3997. ut->ForType = ForType;
  3998. ut->OperatorType = laGetOperatorType(UseOperator);
  3999. ut->GetHeight = GetHeight;
  4000. ut->Init = Init;
  4001. ut->Destroy = Destroy;
  4002. la_UDFAppendSharedTypePointer(Identifer, ut);
  4003. lstAppendItem(&MAIN.UiTypes, ut);
  4004. return ut;
  4005. }
  4006. laUiType *la_GetUiTypeFromProperty(laProp *P){
  4007. laUiType *ut = MAIN.UiTypes.pFirst;
  4008. if (!P) return 0;
  4009. if (P->DefaultUiType) return P->DefaultUiType;
  4010. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  4011. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  4012. for (ut; ut; ut = ut->Item.pNext){
  4013. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  4014. return ut;
  4015. }
  4016. }
  4017. return 0;
  4018. }
  4019. laUiType *la_GetUiButtonType(){
  4020. laUiType *ut = MAIN.UiTypes.pFirst;
  4021. for (ut; ut; ut = ut->Item.pNext){
  4022. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  4023. }
  4024. return 0;
  4025. }
  4026. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  4027. laCanvasTemplate *vdt;
  4028. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  4029. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  4030. }
  4031. return 0;
  4032. }
  4033. void la_AssignPropExtras(laUiItem* ui){
  4034. if(!ui->Type || !ui->Type->FakeProp) return;
  4035. ui->FakePs.p = ui->Type->FakeProp;
  4036. ui->FakePs.Type = U'.';
  4037. ui->FakePs.UseInstance = ui;
  4038. ui->ExtraPP.LastPs = &ui->FakePs;
  4039. }
  4040. void la_AssignCanvasPropExtras(laUiItem* ui){
  4041. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  4042. laCanvasTemplate*ct=ui->CanvasTemplate;
  4043. ui->FakePs.p = ct->FakeProp;
  4044. ui->FakePs.Type = U'.';
  4045. ui->FakePs.UseInstance = ui;
  4046. ui->ExtraPP.EndInstance = ui->Extra;
  4047. ui->ExtraPP.LastPs = &ui->FakePs;
  4048. }
  4049. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  4050. int result;
  4051. if (!ui) return 0;
  4052. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  4053. if (Path){
  4054. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4055. if (!result){
  4056. ui->AT = laGetOperatorType(Path);
  4057. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  4058. ui->Type = la_GetUiButtonType();
  4059. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  4060. }else{
  4061. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4062. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4063. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  4064. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4065. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4066. }
  4067. if (Base){
  4068. ui->PP.RawThis = Base;
  4069. }
  4070. }else if (Base){
  4071. ui->PP.LastPs = Base->LastPs;
  4072. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4073. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4074. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  4075. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4076. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4077. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4078. }
  4079. la_AssignPropExtras(ui);
  4080. if(Widget){ ui->Flags|= Widget->Flags; }
  4081. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  4082. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  4083. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4084. return ui;
  4085. }
  4086. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  4087. ui->Type = _LA_UI_LABEL;
  4088. ui->Template = Template;
  4089. ui->State = LA_UI_NORMAL;
  4090. strSafeSet(&ui->Display, Content);
  4091. la_AssignPropExtras(ui);
  4092. return ui;
  4093. }
  4094. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  4095. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4096. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  4097. ui->State = LA_UI_NORMAL;
  4098. la_AssignPropExtras(ui);
  4099. return ui;
  4100. }
  4101. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4102. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4103. transLate(Content);
  4104. la_UpdateLabelDisplay(ui, Template, Content);
  4105. ui->C = c;
  4106. if (ui->Type->Init) ui->Type->Init(ui);
  4107. ui->ExtraPP.EndInstance = ui->Extra;
  4108. lstAppendItem(&uil->UiItems, ui);
  4109. return ui;
  4110. }
  4111. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4112. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4113. la_UpdateLabelDisplay(ui, Template, Content);
  4114. ui->C = c;
  4115. if (ui->Type->Init) ui->Type->Init(ui);
  4116. ui->ExtraPP.EndInstance = ui->Extra;
  4117. lstAppendItem(&uil->UiItems, ui);
  4118. return ui;
  4119. }
  4120. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  4121. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4122. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  4123. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  4124. ui->C = c;
  4125. if (ui->Type->Init) ui->Type->Init(ui);
  4126. ui->ExtraPP.EndInstance = ui->Extra;
  4127. lstAppendItem(&uil->UiItems, ui);
  4128. return ui;
  4129. }
  4130. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4131. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  4132. }
  4133. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4134. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4135. }
  4136. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4137. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4138. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4139. ui->C = c;
  4140. ui->TemplateContext = TemplateContext;
  4141. if (ui->Type->Init) ui->Type->Init(ui);
  4142. ui->ExtraPP.EndInstance = ui->Extra;
  4143. lstAppendItem(&uil->UiItems, ui);
  4144. return ui;
  4145. }
  4146. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4147. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4148. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4149. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4150. ui->SymbolID=Height;
  4151. lstAppendItem(&uil->UiItems, ui);
  4152. return ui;
  4153. }
  4154. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4155. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4156. }
  4157. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4158. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4159. }
  4160. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4161. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4162. ui->Type = _LA_UI_CANVAS;
  4163. ui->State = LA_UI_NORMAL;
  4164. ui->C = c;
  4165. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4166. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4167. else{
  4168. 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); }
  4169. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4170. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4171. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4172. }
  4173. if (ui->Type->Init) ui->Type->Init(ui);
  4174. la_AssignCanvasPropExtras(ui);
  4175. if (Height) ui->Expand=Height; else ui->Expand=6;
  4176. lstAppendItem(&uil->UiItems, ui);
  4177. return ui;
  4178. }
  4179. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4180. laUiItem* ui=0;
  4181. #define ADD_CANVAS \
  4182. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4183. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4184. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4185. }laEndCondition(uil,b3);\
  4186. laEndRow(uil,b);
  4187. if(Detached){
  4188. laColumn* cl,*cll,*clr,*cr;
  4189. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4190. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4191. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4192. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4193. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4194. ADD_CANVAS
  4195. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4196. }laElse(uil,b2);{
  4197. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4198. ADD_CANVAS
  4199. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4200. }laEndCondition(uil,b2);
  4201. }else{
  4202. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4203. }
  4204. #undef ADD_CANVAS
  4205. }
  4206. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4207. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4208. laCanvasExtra *e;
  4209. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4210. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4211. ui->C = c;
  4212. if (ui->Type->Init) ui->Type->Init(ui);
  4213. ui->ExtraPP.EndInstance = ui->Extra;
  4214. lstAppendItem(&uil->UiItems, ui);
  4215. return ui;
  4216. }
  4217. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4218. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4219. ui->Type = _LA_UI_SYMBOL;
  4220. ui->SymbolID = SymbolID;
  4221. if (Height) ui->State = Height;
  4222. ui->C = c;
  4223. if (ui->Type->Init) ui->Type->Init(ui);
  4224. ui->ExtraPP.EndInstance = ui->Extra;
  4225. lstAppendItem(&uil->UiItems, ui);
  4226. return ui;
  4227. }
  4228. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4229. laPropPack PP={0}; int result;
  4230. if (Path){
  4231. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4232. if (!result){ return 0; }
  4233. if (Base){ PP.RawThis = Base; }
  4234. }else if (Base){
  4235. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4236. }
  4237. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4238. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4239. lstAppendItem(&ui->CompoundPPs,CPP);
  4240. return &CPP->PP;
  4241. }
  4242. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4243. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4244. ui->Type = &_LA_UI_ROW_BEGIN;
  4245. ui->State=Expand;
  4246. ui->Flags=Even;
  4247. ui->C = c;
  4248. if (ui->Type->Init) ui->Type->Init(ui);
  4249. ui->ExtraPP.EndInstance = ui->Extra;
  4250. lstAppendItem(&uil->UiItems, ui);
  4251. return ui;
  4252. }
  4253. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4254. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4255. ui->Type = &_LA_UI_ROW_END;
  4256. ui->C = Begin->C;
  4257. ui->Page = (laUiList*)Begin;
  4258. if (ui->Type->Init) ui->Type->Init(ui);
  4259. ui->ExtraPP.EndInstance = ui->Extra;
  4260. lstAppendItem(&uil->UiItems, ui);
  4261. return ui;
  4262. }
  4263. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4264. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4265. e->Expression = Expression;
  4266. ui->Extra = e;
  4267. la_AssignPropExtras(ui);
  4268. }
  4269. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4270. laUiItem *ui = la_CreateGroupHandle(Widget);
  4271. laUiList *nuil;
  4272. ui->C = c;
  4273. lstAppendItem(&uil->UiItems, ui);
  4274. nuil = memAcquireSimple(sizeof(laUiList));
  4275. strSafeSet(&nuil->TabName, Name);
  4276. ui->Page = nuil;
  4277. lstAppendItem(&ui->Subs, nuil);
  4278. if (ui->Type->Init) ui->Type->Init(ui);
  4279. ui->ExtraPP.EndInstance = ui->Extra;
  4280. return ui;
  4281. }
  4282. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4283. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4284. laUiList *sub = SubUi->Page;
  4285. laColumn *s = laFirstColumn(sub);
  4286. SubUi->State = LA_UI_ACTIVE;
  4287. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4288. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4289. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4290. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4291. laShowSeparator(sub, s);
  4292. return SubUi;
  4293. }
  4294. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4295. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4296. laUiList *sub = SubUi->Page;
  4297. laColumn *s = laFirstColumn(sub);
  4298. SubUi->State = LA_UI_ACTIVE;
  4299. return SubUi;
  4300. }
  4301. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4302. laEndCondition(sub, sub->UiItems.pFirst);
  4303. }
  4304. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4305. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4306. laUiList *nuil;
  4307. ui->C = c;
  4308. lstAppendItem(&uil->UiItems, ui);
  4309. if (ui->Type->Init) ui->Type->Init(ui);
  4310. ui->ExtraPP.EndInstance = ui->Extra;
  4311. return ui;
  4312. }
  4313. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4314. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4315. if (!ui->Page) ui->Page = uil;
  4316. lstAppendItem(&ui->Subs, uil);
  4317. strSafeSet(&uil->TabName, Name);
  4318. laFirstColumn(uil);
  4319. //laFirstColumn(uil);
  4320. return uil;
  4321. }
  4322. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4323. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4324. /*if (!ui->Page) */ ui->Page = uil;
  4325. lstAppendItem(&ui->Subs, uil);
  4326. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4327. return uil;
  4328. }
  4329. laUiConditionNode *laTrue(){
  4330. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4331. ucn->Type = LA_CONDITION_TRUE;
  4332. return ucn;
  4333. }
  4334. laUiConditionNode *laFalse(){
  4335. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4336. ucn->Type = LA_CONDITION_FALSE;
  4337. return ucn;
  4338. }
  4339. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4340. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4341. ucn->Type = LA_CONDITION_PROP;
  4342. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4343. strSafeSet(&ucn->String, Prop);
  4344. return ucn;
  4345. }
  4346. laUiConditionNode *laIntExpression(int Value){
  4347. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4348. ucn->Type = LA_CONDITION_INT;
  4349. ucn->IntValue = Value;
  4350. return ucn;
  4351. }
  4352. laUiConditionNode *laFloatExpression(real Value){
  4353. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4354. ucn->Type = LA_CONDITION_FLOAT;
  4355. ucn->FloatValue = Value;
  4356. return ucn;
  4357. }
  4358. laUiConditionNode *laStringExpression(char *Content){
  4359. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4360. ucn->Type = LA_CONDITION_STRING;
  4361. strSafeSet(&ucn->String, Content);
  4362. return ucn;
  4363. }
  4364. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4365. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4366. ucn->Type = LA_CONDITION_AND;
  4367. ucn->Expression1 = Expression1;
  4368. ucn->Expression2 = Expression2;
  4369. return ucn;
  4370. }
  4371. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4372. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4373. ucn->Type = LA_CONDITION_OR;
  4374. ucn->Expression1 = Expression1;
  4375. ucn->Expression2 = Expression2;
  4376. return ucn;
  4377. }
  4378. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4379. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4380. ucn->Type = LA_CONDITION_NOT;
  4381. ucn->Expression1 = Expression1;
  4382. return ucn;
  4383. }
  4384. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4385. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4386. ucn->Type = LA_CONDITION_EQ;
  4387. ucn->Expression1 = Expression1;
  4388. ucn->Expression2 = Expression2;
  4389. return ucn;
  4390. }
  4391. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4392. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4393. ucn->Type = LA_CONDITION_GT;
  4394. ucn->Expression1 = Expression1;
  4395. ucn->Expression2 = Expression2;
  4396. return ucn;
  4397. }
  4398. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4399. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4400. ucn->Type = LA_CONDITION_LT;
  4401. ucn->Expression1 = Expression1;
  4402. ucn->Expression2 = Expression2;
  4403. return ucn;
  4404. }
  4405. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4406. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4407. ucn->Type = LA_CONDITION_GE;
  4408. ucn->Expression1 = Expression1;
  4409. ucn->Expression2 = Expression2;
  4410. return ucn;
  4411. }
  4412. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4413. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4414. ucn->Type = LA_CONDITION_LE;
  4415. ucn->Expression1 = Expression1;
  4416. ucn->Expression2 = Expression2;
  4417. return ucn;
  4418. }
  4419. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4420. if (Expression->Type != LA_CONDITION_INT) return 0;
  4421. return Expression->IntValue;
  4422. }
  4423. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4424. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4425. return Expression->FloatValue;
  4426. }
  4427. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4428. return Expression->String->Ptr;
  4429. }
  4430. 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){
  4431. switch (Mode1){
  4432. case LA_PROP_ENUM:
  4433. case LA_PROP_INT:
  4434. case LA_CONDITION_INT:
  4435. switch (Mode2){
  4436. case LA_PROP_ENUM:
  4437. case LA_PROP_INT:
  4438. case LA_CONDITION_INT:
  4439. switch (CompMode){
  4440. case LA_CONDITION_GE:
  4441. return (i1 >= i2);
  4442. case LA_CONDITION_GT:
  4443. return (i1 > i2);
  4444. case LA_CONDITION_EQ:
  4445. return (i1 == i2);
  4446. case LA_CONDITION_LT:
  4447. return (i1 < i2);
  4448. case LA_CONDITION_LE:
  4449. return (i1 <= i2);
  4450. }
  4451. case LA_PROP_FLOAT:
  4452. case LA_CONDITION_FLOAT:
  4453. switch (CompMode){
  4454. case LA_CONDITION_GE:
  4455. return ((real)i1 >= f2);
  4456. case LA_CONDITION_GT:
  4457. return ((real)i1 > f2);
  4458. case LA_CONDITION_EQ:
  4459. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4460. case LA_CONDITION_LT:
  4461. return ((real)i1 < f2);
  4462. case LA_CONDITION_LE:
  4463. return ((real)i1 <= f2);
  4464. }
  4465. case LA_PROP_SUB:
  4466. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4467. default:
  4468. return 0;
  4469. }
  4470. case LA_PROP_FLOAT:
  4471. case LA_CONDITION_FLOAT:
  4472. switch (Mode2){
  4473. case LA_PROP_INT:
  4474. case LA_PROP_ENUM:
  4475. case LA_CONDITION_INT:
  4476. switch (CompMode){
  4477. case LA_CONDITION_GE:
  4478. return (f1 >= (real)i2);
  4479. case LA_CONDITION_GT:
  4480. return (f1 > (real)i2);
  4481. case LA_CONDITION_EQ:
  4482. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4483. case LA_CONDITION_LT:
  4484. return (f1 < (real)i2);
  4485. case LA_CONDITION_LE:
  4486. return (f1 <= (real)i2);
  4487. }
  4488. case LA_PROP_FLOAT:
  4489. case LA_CONDITION_FLOAT:
  4490. switch (CompMode){
  4491. case LA_CONDITION_GE:
  4492. return (f1 >= f2);
  4493. case LA_CONDITION_GT:
  4494. return (f1 > f2);
  4495. case LA_CONDITION_EQ:
  4496. return (f1 == f2);
  4497. case LA_CONDITION_LT:
  4498. return (f1 < f2);
  4499. case LA_CONDITION_LE:
  4500. return (f1 <= f2);
  4501. }
  4502. default:
  4503. return 0;
  4504. }
  4505. case LA_PROP_STRING:
  4506. case LA_CONDITION_STRING:
  4507. switch (Mode2){
  4508. case LA_PROP_STRING:
  4509. case LA_CONDITION_STRING:
  4510. return strSame(s1, s2);
  4511. default:
  4512. return 0;
  4513. }
  4514. case LA_PROP_SUB:
  4515. switch (Mode2){
  4516. case LA_PROP_SUB:
  4517. return p1 == p2;
  4518. case LA_CONDITION_INT:
  4519. case LA_PROP_INT:
  4520. case LA_PROP_ENUM:
  4521. return (int)p1 == i2;
  4522. default:
  4523. return 0;
  4524. }
  4525. default:
  4526. switch (CompMode){
  4527. case LA_CONDITION_GE:
  4528. return (i1 >= i2);
  4529. case LA_CONDITION_GT:
  4530. return (i1 > i2);
  4531. case LA_CONDITION_EQ:
  4532. return (i1 == i2);
  4533. case LA_CONDITION_LT:
  4534. return (i1 < i2);
  4535. case LA_CONDITION_LE:
  4536. return (i1 <= i2);
  4537. }
  4538. }
  4539. }
  4540. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4541. void *Instance = 0;
  4542. int IValue1 = 0, IValue2 = 0;
  4543. real FValue1 = 0, FValue2 = 0;
  4544. void *Ptr1 = 0, *Ptr2 = 0;
  4545. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4546. int Result1, Result2;
  4547. laEnumItem *ei; laSubProp*sp;
  4548. if (!Expression) return 0;
  4549. Str1[0] = 0;
  4550. Str2[0] = 0;
  4551. laPropIterator pi = {0};
  4552. switch (Expression->Type){
  4553. case LA_CONDITION_PROP:
  4554. if (!Expression->PP.LastPs){
  4555. (*IResult) = 0;
  4556. return 0;
  4557. }
  4558. switch (Expression->PP.LastPs->p->PropertyType){
  4559. case LA_PROP_INT:
  4560. *IResult = laGetInt(&Expression->PP);
  4561. if (*IResult) return LA_CONDITION_INT;
  4562. else return 0;
  4563. case LA_PROP_FLOAT:
  4564. *FResult = laGetFloat(&Expression->PP);
  4565. if (*FResult) return 1;
  4566. else return 0;
  4567. break;
  4568. case LA_PROP_STRING:
  4569. laGetString(&Expression->PP, _StrResult, &StrResult);
  4570. if (StrResult[0]) return 1;
  4571. else return 0;
  4572. break;
  4573. case LA_PROP_ENUM:
  4574. ei = laGetEnum(&Expression->PP);
  4575. if (!ei) return 0;
  4576. /*if(ei) */ *IResult = ei->Index;
  4577. if (*IResult) return LA_CONDITION_INT;
  4578. else return 0;
  4579. break;
  4580. case LA_PROP_SUB:
  4581. sp=Expression->PP.LastPs->p;
  4582. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4583. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4584. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4585. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4586. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4587. }
  4588. }
  4589. *PtrResult = Instance;
  4590. if (Instance) return 1;
  4591. break;
  4592. default:
  4593. return 0;
  4594. }
  4595. break;
  4596. case LA_CONDITION_INT:
  4597. *IResult = Expression->IntValue;
  4598. if (*IResult) return 1;
  4599. else
  4600. return 0;
  4601. case LA_CONDITION_FLOAT:
  4602. *FResult = Expression->FloatValue;
  4603. if (*FResult) return 1;
  4604. else
  4605. return 0;
  4606. case LA_CONDITION_STRING:
  4607. if (Expression->String){
  4608. strCopyFull(StrResult, Expression->String->Ptr);
  4609. return 1;
  4610. }else
  4611. return 0;
  4612. case LA_CONDITION_TRUE:
  4613. if (*IResult) *IResult = 1;
  4614. return 1;
  4615. case LA_CONDITION_FALSE:
  4616. if (*IResult) *IResult = 0;
  4617. return 0;
  4618. default:
  4619. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4620. switch (Expression->Type){
  4621. case LA_CONDITION_AND:
  4622. if (Result1){
  4623. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4624. if (Result2) *IResult = 1;
  4625. return (Result2);
  4626. }else
  4627. return 0;
  4628. case LA_CONDITION_OR:
  4629. if (!Result1){
  4630. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4631. if (Result2) *IResult = 1;
  4632. return (Result2);
  4633. }else
  4634. return 1;
  4635. case LA_CONDITION_NOT:
  4636. return !Result1;
  4637. default:
  4638. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4639. return la_DoCompare(Expression->Type,
  4640. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4641. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4642. }
  4643. break;
  4644. }
  4645. return 0;
  4646. }
  4647. int la_DoSingleExpression(laUiConditionNode *Expression){
  4648. int a;
  4649. real b;
  4650. char c[128]={0};
  4651. void *p;
  4652. if (!Expression) return 1;
  4653. c[0] = 0;
  4654. return la_DoExpression(Expression, &a, &b, c, &p);
  4655. }
  4656. void la_StepExpression(laUiConditionNode *e){
  4657. if (!e) return;
  4658. switch (e->Type){
  4659. case LA_CONDITION_AND:
  4660. case LA_CONDITION_OR:
  4661. case LA_CONDITION_GE:
  4662. case LA_CONDITION_GT:
  4663. case LA_CONDITION_EQ:
  4664. case LA_CONDITION_LT:
  4665. case LA_CONDITION_LE:
  4666. la_StepExpression(e->Expression1);
  4667. la_StepExpression(e->Expression2);
  4668. break;
  4669. case LA_CONDITION_NOT:
  4670. la_StepExpression(e->Expression1);
  4671. break;
  4672. case LA_CONDITION_PROP:
  4673. la_StepPropPack(&e->PP);
  4674. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4675. la_UsePropPack(&e->PP, 1);
  4676. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4677. //}
  4678. break;
  4679. default:
  4680. break;
  4681. }
  4682. }
  4683. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4684. if (!ucn) return;
  4685. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4686. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4687. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4688. if (ucn->String) strSafeDestroy(&ucn->String);
  4689. if (ucn) memFree(ucn);
  4690. }
  4691. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4692. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4693. ui->C = c;
  4694. ui->Type = &_LA_UI_CONDITION;
  4695. la_ConditionerInit(ui, Expression);
  4696. lstAppendItem(&uil->UiItems, ui);
  4697. return ui;
  4698. }
  4699. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4700. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4701. laConditionUiExtraData *cued;
  4702. ui->Type = &_LA_UI_CONDITION_ELSE;
  4703. la_ConditionerInit(ui, 0);
  4704. cued = ui->Extra;
  4705. cued->EndUi = Beginner;
  4706. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4707. ui->C = Beginner->C;
  4708. lstAppendItem(&uil->UiItems, ui);
  4709. return ui;
  4710. }
  4711. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4712. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4713. laConditionUiExtraData *cued;
  4714. ui->Template = define;
  4715. ui->C = col;
  4716. ui->PP.RawThis = ExtraBase;
  4717. ui->Page = ExtraThis;
  4718. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4719. la_ConditionerInit(ui, 0);
  4720. cued = ui->Extra;
  4721. //cued->Remove = Remove;
  4722. ui->State = LA_UI_NORMAL;
  4723. lstAppendItem(&uil->UiItems, ui);
  4724. return ui;
  4725. }
  4726. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4727. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4728. laConditionUiExtraData *cued;
  4729. ui->Type = &_LA_UI_CONDITION_END;
  4730. la_ConditionerInit(ui, 0);
  4731. cued = ui->Extra;
  4732. cued->EndUi = Beginner;
  4733. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4734. ui->C = Beginner->C;
  4735. lstAppendItem(&uil->UiItems, ui);
  4736. return ui;
  4737. }
  4738. laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags) {
  4739. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4740. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4741. ui->Type = _LA_UI_MENU_ROOT;
  4742. strSafeSet(&ui->Display, Title);
  4743. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4744. ui->C = c;
  4745. ui->Flags|=flags;
  4746. lstAppendItem(&uil->UiItems, ui);
  4747. muil->Flags|=flags;
  4748. lstAppendItem(&ui->Subs, muil);
  4749. return muil;
  4750. }
  4751. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4752. return laMakeMenuPageEx(uil,c,Title,0);
  4753. }
  4754. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4755. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4756. ui->Type = _LA_UI_ALIGN;
  4757. ui->C = widest;
  4758. lstAppendItem(&uil->UiItems, ui);
  4759. return ui;
  4760. }
  4761. void laFixHeight(laUiList *uil, short Rows){
  4762. if (!uil) return;
  4763. uil->HeightCoeff = Rows;
  4764. }
  4765. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4766. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4767. if (!ExtraColumns) return;
  4768. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4769. }
  4770. laUiTemplate *laFindUiTemplate(char *Identifier){
  4771. laUiTemplate *uit;
  4772. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4773. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4774. }
  4775. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4776. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4777. }
  4778. return 0;
  4779. }
  4780. void la_DestroyUiTemplate(laUiTemplate* uit){
  4781. strSafeDestroy(&uit->Identifier);
  4782. strSafeDestroy(&uit->Title);
  4783. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4784. memFree(uit);
  4785. }
  4786. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4787. strSafeDestroy(&uit->Identifier);
  4788. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4789. memFree(uit);
  4790. }
  4791. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4792. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4793. strSafeSet(&uit->Identifier, Identifier);
  4794. strSafeSet(&uit->Title, Title);
  4795. strSafeSet(&uit->CategoryName, NewCategory);
  4796. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4797. uit->DefaultGLFormat=DefaultGLFormat;
  4798. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4799. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4800. la_UDFAppendSharedTypePointer(Identifier, uit);
  4801. return uit;
  4802. }
  4803. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4804. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4805. strSafeSet(&t->Identifier, Identifier);
  4806. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4807. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4808. lstAppendItem(&MAIN.View2DTemplates, t);
  4809. la_UDFAppendSharedTypePointer(Identifier, t);
  4810. return t;
  4811. }
  4812. void laFinalizeUiTemplates(){
  4813. laUiTemplate *uit;
  4814. laCanvasTemplate *u2d;
  4815. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4816. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4817. }
  4818. }
  4819. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4820. laPanel *p;
  4821. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4822. if (p->PanelTemplate==uit){
  4823. return p;
  4824. }
  4825. }
  4826. return 0;
  4827. }
  4828. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4829. laUiList *uil, *NextUil;
  4830. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4831. NextUil = uil->Item.pNext;
  4832. lstRemoveItem(&ui->Subs, uil);
  4833. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4834. }
  4835. la_StopUiOperatorService(ui);
  4836. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4837. strSafeDestroy(&ui->Display);
  4838. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4839. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4840. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4841. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4842. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4843. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4844. }
  4845. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4846. memFree(ui);
  4847. }
  4848. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4849. laUiItem *ui, *NextUi;
  4850. laColumn *col, *NextCol;
  4851. if (!uil) return;
  4852. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4853. NextUi = ui->Item.pNext;
  4854. if(OnlyRemoveUser && RemoveUsers){
  4855. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4856. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4857. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4858. continue;
  4859. }
  4860. lstRemoveItem(&uil->UiItems, ui);
  4861. la_DestroyUiItem(ui, RemoveUsers);
  4862. }
  4863. if(OnlyRemoveUser){ return; }
  4864. for (col = uil->Columns.pFirst; col; col = NextCol){
  4865. NextCol = col->Item.pNext;
  4866. lstRemoveItem(&uil->Columns, col);
  4867. memFree(col);
  4868. }
  4869. strSafeDestroy(&uil->TabName);
  4870. if (!NoFree) memFree(uil);
  4871. }
  4872. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4873. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4874. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4875. }
  4876. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4877. laUiItem *Next = after->Item.pNext;
  4878. laUiItem *Last = uil->UiItems.pLast;
  4879. after->Item.pNext = 0;
  4880. uil->UiItems.pLast = after;
  4881. Define(uil, Base, This, ExtraColums, 0);
  4882. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4883. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4884. if (Next != Last) uil->UiItems.pLast = Last;
  4885. }
  4886. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4887. // int i = 0;
  4888. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4889. // if (!ui->ExtraColums) return;
  4890. // for (i; ui->ExtraColums[i]; i++) {
  4891. // laColumn* c = ui->ExtraColums[i];
  4892. // c->B = B;
  4893. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4894. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4895. // }
  4896. //}
  4897. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4898. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4899. }
  4900. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4901. laColumn *c = ui->C;
  4902. laColumn *ic = lst->pFirst;
  4903. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4904. for (ic; ic; ic = ic->Item.pNext){
  4905. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4906. ic->B = ic->B < c->B ? c->B : ic->B;
  4907. }
  4908. }
  4909. ic = ui->C;
  4910. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4911. ;
  4912. for (ic; ic; ic = ic->Item.pNext){
  4913. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4914. ic->B = ic->B < c->B ? c->B : ic->B;
  4915. }
  4916. }
  4917. }
  4918. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4919. laColumn *c = ui->C;
  4920. laColumn *ic = lst->pFirst;
  4921. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4922. for (ic; ic; ic = ic->Item.pNext){
  4923. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4924. ic->B = ic->B < c->B ? c->B : ic->B;
  4925. }
  4926. }
  4927. ic = ui->C;
  4928. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4929. ;
  4930. for (ic; ic; ic = ic->Item.pNext){
  4931. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4932. ic->B = ic->B < c->B ? c->B : ic->B;
  4933. }
  4934. }
  4935. }
  4936. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4937. int rep;
  4938. int sp;
  4939. int rev;
  4940. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4941. if (!c) return 0;
  4942. sp = (c->SP * (R - L)) + L;
  4943. rev = sp;
  4944. /*if (U)*/ c->B = U;
  4945. if (LR == 1){
  4946. c->IL = L;
  4947. c->IR = sp;
  4948. if (repos){
  4949. c->IR = repos;
  4950. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4951. c->IR = c->IL + c->MaxW*LA_RH+M;
  4952. rev = c->IR;
  4953. }
  4954. }else if (LR == 2){
  4955. c->IL = sp;
  4956. c->IR = R;
  4957. if (repos){
  4958. c->IL = repos;
  4959. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4960. c->IL = c->IR - c->MaxW*LA_RH-M;
  4961. rev = c->IL;
  4962. }
  4963. }else if (LR == 0){
  4964. c->IL = L;
  4965. c->IR = R;
  4966. }
  4967. if (c->LS && c->RS->MaxW == 0){
  4968. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4969. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4970. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4971. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4972. }else if (c->RS && c->LS->MaxW == 0){
  4973. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4974. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4975. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4976. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4977. }
  4978. return rev;
  4979. }
  4980. STRUCTURE(laRowInfo){
  4981. int MaxW;
  4982. int MinW;
  4983. int UnitMinW;
  4984. int NonExpandW;
  4985. int TotalPadding;
  4986. int Expand, Even;
  4987. int ExpandAccum;
  4988. int CountElements;
  4989. int U,MaxB,L;
  4990. laListHandle Elements;
  4991. int LastNoHeight;
  4992. };
  4993. STRUCTURE(laRowNode){
  4994. laListItem Item;
  4995. laUiItem* ui;
  4996. int GotW, LP, RP, H;
  4997. int Expand;
  4998. int UseLast;
  4999. int WaitAnimation;
  5000. };
  5001. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  5002. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  5003. ri->UnitMinW=LA_RH;
  5004. ri->Expand=ui->State?1:0;
  5005. ri->Even=ui->Flags?1:0;
  5006. ri->U=ui->TU; ri->L=ui->TL;
  5007. ri->MaxB=ui->TU;
  5008. }
  5009. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  5010. laRowNode* rn=CreateNew(laRowNode);
  5011. rn->LP=bt->LP;rn->RP=bt->RP;
  5012. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  5013. rn->ui=ui;
  5014. rn->H=H;
  5015. rn->Expand=ui->Expand;
  5016. rn->WaitAnimation=WaitAnimation;
  5017. lstAppendItem(&ri->Elements, rn);
  5018. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  5019. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  5020. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  5021. ri->TotalPadding += (bt->LP+bt->RP);
  5022. ri->MinW+=ri->UnitMinW;
  5023. ri->NonExpandW+=rn->GotW;
  5024. ri->ExpandAccum+=ui->Expand;
  5025. ri->CountElements++;
  5026. if(ui->Expand){ri->Expand=1;}
  5027. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  5028. }
  5029. int la_ShrinkableRowElements(laRowInfo* ri){
  5030. int count=0;
  5031. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5032. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  5033. count++;
  5034. }
  5035. return count;
  5036. }
  5037. void la_RecordSocketRuntimePosition(laUiItem* ui);
  5038. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  5039. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  5040. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  5041. if(Available<0){
  5042. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  5043. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  5044. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  5045. }else{
  5046. if(!ri->Expand && Available>0){Available=0;}
  5047. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  5048. }
  5049. if(!ShareCount) return 0;
  5050. int PerNode = Available/ShareCount;
  5051. int Remaining = Available-PerNode*ShareCount;
  5052. int L = ri->L; int i=0; laRowNode* rn;
  5053. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5054. laUiItem* ui=rn->ui;
  5055. int NodeAdd, Node=rn->GotW;
  5056. if(rn->UseLast){
  5057. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  5058. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  5059. continue;
  5060. }
  5061. if(Available>=0){
  5062. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  5063. NodeAdd+=(i<Remaining?1:0);i++;
  5064. }else{
  5065. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  5066. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  5067. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  5068. }else{ Node=ri->UnitMinW;
  5069. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  5070. }
  5071. }
  5072. ui->TL = L + rn->LP;
  5073. ui->TR = ui->TL + Node+NodeAdd;
  5074. ui->TB = ui->TU + rn->H;
  5075. L=ui->TR+rn->RP;
  5076. if (!rn->WaitAnimation){
  5077. ui->L = ui->TL; ui->R = ui->TR;
  5078. ui->U = ui->TU; ui->B = ui->TB;
  5079. }
  5080. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5081. }
  5082. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  5083. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  5084. memset(ri, 0, sizeof(laRowInfo));
  5085. }
  5086. void la_RecordSocketRuntimePosition(laUiItem* ui){
  5087. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5088. int sl,sr,su,sb;
  5089. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  5090. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  5091. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  5092. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  5093. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  5094. if(pc==LA_PC_SOCKET_OUT){
  5095. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5096. }else{
  5097. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5098. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  5099. }
  5100. }
  5101. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  5102. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  5103. }
  5104. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  5105. int laget_Hyper2InstanceModified(void* instance){
  5106. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  5107. if(level==2){
  5108. laManagedUDF* mu=m->FromFile;
  5109. int not_assigned = (!mu) || mu==MAIN.DummyManageUDF|| mu==MAIN.DummyManageUDFSingle || mu==MAIN.DummyManageUDFSingleForce;
  5110. return (m->Modified||not_assigned)?1:0;
  5111. }
  5112. return 1;
  5113. }
  5114. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  5115. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  5116. laBoxedTheme *bt;
  5117. int Lowest = 0;
  5118. int HyperValue = 0;
  5119. int WaitAnimation;
  5120. int RowMode=0; laRowInfo ri={0};
  5121. laBoxedTheme* pt=*(ParentPanel->BT);
  5122. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  5123. int MaxR=0;
  5124. if(!uil->Scale){uil->Scale=1;}
  5125. uil->SaveScale=MAIN.UiScale;
  5126. MAIN.UiScale*=uil->Scale;
  5127. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5128. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  5129. WaitAnimation = 0;
  5130. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  5131. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  5132. for (ui = uil->UiItems.pFirst; ui;){
  5133. int SubB = 0;
  5134. int H;
  5135. WaitAnimation = 0;
  5136. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5137. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  5138. //if (Fast && ui->C->B > B) {
  5139. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  5140. // ui = ui->Item.pNext;
  5141. // continue;
  5142. //}
  5143. if (!ui->Instructions){
  5144. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  5145. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  5146. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  5147. laOperatorProp *ap = ui->PP.LastPs->p;
  5148. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5149. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5150. }
  5151. }
  5152. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5153. la_UsePropPack(&ui->PP, 0);
  5154. if (ui->CompoundPPs.pFirst){
  5155. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5156. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5157. }
  5158. }
  5159. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5160. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5161. // 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);
  5162. //}
  5163. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5164. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5165. WaitAnimation = 1;
  5166. }
  5167. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5168. bt = (*ui->Type->Theme);
  5169. if (ui->Type == &_LA_UI_CONDITION){
  5170. laConditionUiExtraData *cued = ui->Extra;
  5171. la_StepExpression(cued->Expression);
  5172. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5173. if (!cued->IsTrue){
  5174. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5175. }else{
  5176. ui = ui->Item.pNext;
  5177. }
  5178. continue;
  5179. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5180. ui = ui->Item.pNext;
  5181. continue;
  5182. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5183. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5184. if (cued->IsTrue) ui = cued->EndUi;
  5185. else
  5186. ui = ui->Item.pNext;
  5187. continue;
  5188. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5189. laConditionUiExtraData *cued = ui->Extra;
  5190. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5191. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5192. if (!WaitAnimation){
  5193. ui->L = ui->TL; ui->R = ui->TR;
  5194. ui->U = ui->TU; ui->B = ui->TB;
  5195. }
  5196. if(!RowMode){
  5197. la_CalcUiItemInfluence(&uil->Columns, ui);
  5198. }else{
  5199. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5200. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5201. }
  5202. if (ui->State == LA_UI_NORMAL){
  5203. cued->IsTrue = 0;
  5204. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5205. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5206. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5207. }else{
  5208. cued->IsTrue = 1;
  5209. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5210. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5211. //}
  5212. ui = ui->Item.pNext;
  5213. }
  5214. continue;
  5215. }
  5216. if (ui->Type == _LA_UI_ALIGN){
  5217. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5218. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5219. if (ui->TB > Lowest) Lowest = ui->TB;
  5220. if (!WaitAnimation){
  5221. ui->L = ui->TL; ui->R = ui->TR;
  5222. ui->U = ui->TU; ui->B = ui->TB;
  5223. }
  5224. if(!RowMode){
  5225. la_CalcUiItemInfluence(&uil->Columns, ui);
  5226. }else{
  5227. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5228. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5229. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5230. }
  5231. ui = ui->Item.pNext; continue;
  5232. }
  5233. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5234. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5235. la_InitRowNode(&ri, ui, bt);
  5236. RowMode=1; ui=ui->Item.pNext; continue;
  5237. }
  5238. if (ui->Type == &_LA_UI_ROW_END){
  5239. la_CalculateRowExpand(&ri, ui);
  5240. la_CalcUiItemInfluence(&uil->Columns, ui);
  5241. RowMode=0; ui=ui->Item.pNext; continue;
  5242. }
  5243. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5244. int GB=0;
  5245. 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; }
  5246. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5247. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5248. if (H < 0){
  5249. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5250. else{ H=LA_RH; }
  5251. }
  5252. else H *= LA_RH;
  5253. ui->TB = ui->TU;
  5254. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5255. 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
  5256. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5257. if (ui->Type == _LA_UI_COLLECTION){
  5258. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5259. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5260. ui->PP.EndInstance = TInstance;
  5261. laUiList *iuil = ui->Subs.pFirst;
  5262. laUiList *puil = iuil;
  5263. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5264. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5265. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5266. int Begin = ui->TB;
  5267. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5268. int ElementB = ui->TU;
  5269. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5270. int MaxB = ElementB;
  5271. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5272. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5273. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5274. if (!ElementLimit) RowPriority = 0;
  5275. if (!TInstance){
  5276. while (iuil){
  5277. puil = iuil->Item.pNext;
  5278. la_DestroyTabPage(ui, iuil, 0);
  5279. iuil = puil;
  5280. }
  5281. }
  5282. while (TInstance){
  5283. int UiFilterSkip = uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance));
  5284. int ManagerFilterSkip = MAIN.ManagerFilterInstances && (ui->Flags&LA_UI_COLLECTION_MANAGER_FILTER) && (!laget_Hyper2InstanceModified(TInstance));
  5285. if(UiFilterSkip || ManagerFilterSkip){
  5286. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5287. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5288. ui->PP.EndInstance = TInstance; continue;
  5289. }
  5290. if(CanGetTheme){
  5291. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5292. la_SwitchThemeQuick(t, OriginalTheme);
  5293. }
  5294. if(CanGetGap){
  5295. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5296. Gap=g*LA_RH;
  5297. }else Gap=0;
  5298. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5299. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5300. }else GotCategory=0;
  5301. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5302. if (RowPriority){
  5303. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5304. }
  5305. }
  5306. FirstIn=0;
  5307. if (ElementLimit){
  5308. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5309. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5310. }
  5311. while (iuil && iuil->Instance != TInstance){
  5312. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5313. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5314. }else{
  5315. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5316. }
  5317. iuil = puil;
  5318. }
  5319. if(!iuil){
  5320. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5321. }
  5322. if (!iuil){
  5323. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5324. la_CalcUiTopInfluence(&uil->Columns, ui);
  5325. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5326. 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);
  5327. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5328. iuil = ui->Page->Item.pNext;
  5329. }else{
  5330. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5331. 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);
  5332. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5333. la_CalcUiItemInfluence(&uil->Columns, ui);
  5334. iuil = iuil->Item.pNext;
  5335. }
  5336. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5337. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5338. ui->PP.EndInstance = TInstance;
  5339. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5340. if (RowPriority){
  5341. Col += 1;
  5342. if (Col >= ElementLimit){
  5343. Col = 0;
  5344. Row += 1;
  5345. Begin = ElementB + bt->TM;
  5346. }
  5347. }elif(Spread){
  5348. EL+=Spread*LA_RH;
  5349. ER+=Spread*LA_RH;
  5350. }else{
  5351. Row += 1;
  5352. Begin = ElementB + bt->TM;
  5353. if (ElementLimit && Row >= ElementLimit){
  5354. Row = 0;
  5355. Col += 1;
  5356. Begin = ui->TU + bt->TM;
  5357. }
  5358. }
  5359. ui->TB = ElementB;
  5360. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5361. }
  5362. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5363. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5364. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5365. ui->TB = MaxB;
  5366. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5367. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5368. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5369. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5370. ui->TB=ui->TU+LA_RH;
  5371. }else{
  5372. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5373. ui->PP.EndInstance = TInstance;
  5374. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5375. if(!Template) Template=laui_SubPropInfoDefault;
  5376. //ui->Template = Template;
  5377. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5378. if (!ui->Subs.pFirst && TInstance){
  5379. la_AddInstancePage(ui, TInstance, 0);
  5380. la_CalcUiTopInfluence(&uil->Columns, ui);
  5381. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5382. 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);
  5383. ui->TB = SubB + (NoDecal?0:bt->BM);
  5384. }else if (ui->Subs.pFirst){
  5385. if (!TInstance || TInstance != ui->Page->Instance){
  5386. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5387. ui->Page = 0;
  5388. if (TInstance){
  5389. la_AddInstancePage(ui, TInstance, 0);
  5390. la_CalcUiTopInfluence(&uil->Columns, ui);
  5391. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5392. 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);
  5393. ui->TB = SubB + (NoDecal?0:bt->TM);
  5394. }else
  5395. ui->TB = ui->TU + LA_RH + bt->BM;
  5396. }else{
  5397. 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);
  5398. ui->TB = SubB + (NoDecal?0:bt->BM);
  5399. }
  5400. }
  5401. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5402. ui->TB=ui->TU+LA_RH;
  5403. }
  5404. }
  5405. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5406. if (!WaitAnimation){
  5407. ui->L = ui->TL;
  5408. ui->R = ui->TR;
  5409. ui->U = ui->TU;
  5410. ui->B = ui->TB;
  5411. }
  5412. }
  5413. }else{
  5414. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5415. if (ui->Type != _LA_UI_CANVAS){
  5416. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5417. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5418. SubB = la_UpdateUiListRecursive(ui->Page,
  5419. 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);
  5420. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5421. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5422. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5423. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5424. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5425. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5426. }
  5427. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5428. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5429. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5430. if(ui->Page->HeightCoeff){
  5431. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5432. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5433. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5434. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5435. }
  5436. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5437. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5438. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5439. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5440. }
  5441. }
  5442. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5443. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5444. }else{
  5445. laUiList *suil;
  5446. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5447. la_CalcUiTopInfluence(&uil->Columns, ui);
  5448. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5449. 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);
  5450. }
  5451. }
  5452. ui->TB = ui->TU + H;
  5453. }
  5454. }else ui->TB = ui->TU + H;
  5455. }
  5456. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5457. if(!RowMode){
  5458. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5459. }else{
  5460. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5461. }
  5462. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5463. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5464. ui = ui->Item.pNext;
  5465. }
  5466. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5467. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5468. else uil->TB = Lowest;
  5469. if (!WaitAnimation){
  5470. uil->L = uil->TL;
  5471. uil->R = uil->TR;
  5472. uil->U = uil->TU;
  5473. uil->B = uil->TB;
  5474. }
  5475. MAIN.UiScale=uil->SaveScale;
  5476. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5477. return uil->TB;
  5478. }
  5479. int la_AnimateSingleUiSize(int To, int *Now){
  5480. int Delta;
  5481. if (To != *Now){
  5482. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5483. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5484. *Now += Delta;
  5485. return 1;
  5486. }else
  5487. return 0;
  5488. }
  5489. int la_AnimateUiListRecursive(laUiList *uil){
  5490. laUiItem *ui;
  5491. int Again = 0;
  5492. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5493. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5494. if(ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish){
  5495. ui->B=ui->TB; ui->L=ui->TL; ui->R=ui->TR; ui->U=ui->TU;
  5496. }else{
  5497. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5498. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5499. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5500. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5501. }
  5502. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5503. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5504. laUiList *suil;
  5505. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5506. Again += la_AnimateUiListRecursive(suil);
  5507. }
  5508. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5509. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5510. Again += la_AnimateUiListRecursive(ui->Page);
  5511. }
  5512. }
  5513. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5514. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5515. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5516. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5517. return Again;
  5518. }
  5519. int la_DrawUiItem(laUiItem *ui){
  5520. tnsUseNoTexture();
  5521. tnsColor4d(1, 1, 1, 1);
  5522. tnsVertex2d(ui->L, ui->U);
  5523. tnsVertex2d(ui->R, ui->U);
  5524. tnsVertex2d(ui->R, ui->B);
  5525. tnsVertex2d(ui->L, ui->B);
  5526. tnsPackAs(GL_LINE_LOOP);
  5527. }
  5528. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5529. tnsUseNoTexture();
  5530. tnsColor4d(1, 1, 1, 1);
  5531. tnsVertex2d(ui->L - 1, ui->U - 1);
  5532. tnsVertex2d(ui->R + 1, ui->U - 1);
  5533. tnsVertex2d(ui->R + 1, ui->B + 1);
  5534. tnsVertex2d(ui->L - 1, ui->B + 1);
  5535. tnsPackAs(GL_LINE_LOOP);
  5536. }
  5537. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5538. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5539. return 1;
  5540. }
  5541. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5542. laUiListDrawItem *uildi = uild->Items.pFirst;
  5543. laUiList *Target = uildi->Target;
  5544. int L, R, U, B;
  5545. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5546. L = Target->L + Target->PanX + uildi->DifX;
  5547. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5548. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5549. U = Target->U + Target->PanY + uildi->DifY;
  5550. return la_UiInBound(ui, L, R, U, B);
  5551. }
  5552. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5553. laUiListDrawItem *uildi = uild->Items.pFirst;
  5554. laUiList *Target = uildi->Target;
  5555. int L, R, U, B;
  5556. if (Target){
  5557. L = Target->L + Target->PanX + uildi->DifX;
  5558. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5559. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5560. U = Target->U + Target->PanY + uildi->DifY;
  5561. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5562. return 1;
  5563. }else{
  5564. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5565. return 1;
  5566. }
  5567. }
  5568. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5569. laUiItem *ui = uil->UiItems.pFirst;
  5570. while (!strGetArgument(ui->Instructions, mark))
  5571. ui = ui->Item.pNext;
  5572. return ui;
  5573. }
  5574. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5575. laUiList *uil;
  5576. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5577. if (uil->Instance == Instance) return uil;
  5578. }
  5579. return uil;
  5580. }
  5581. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5582. int mx=(L+R)/2; int my=(U+B)/2;
  5583. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5584. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5585. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5586. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5587. tnsFlush();
  5588. }
  5589. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5590. if(!uil->ScrollerShownV) return;
  5591. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5592. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5593. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5594. int U = uil->U + Offset;
  5595. int B = U + Len;
  5596. int L = UiR - RM*2 - W;
  5597. int R = L + W;
  5598. if (B > U + DisplayH) B = U + DisplayH;
  5599. if (U < uil->U) U = uil->U;
  5600. if (B <= uil->U || U >= uil->B) return;
  5601. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5602. if (U < uil->U) U = uil->U;
  5603. tnsUseNoTexture();
  5604. laBoxedTheme* bt=_LA_THEME_PANEL;
  5605. real* color=laThemeColor(bt, LA_BT_TEXT);
  5606. tnsColor4d(LA_COLOR3(color), 0.2);
  5607. tnsVertex2d(R-RM, uil->U);
  5608. tnsVertex2d(L+RM, uil->U);
  5609. tnsVertex2d(L+RM, uil->U + DisplayH);
  5610. tnsVertex2d(R-RM, uil->U + DisplayH);
  5611. tnsPackAs(GL_TRIANGLE_FAN);
  5612. tnsColor4d(LA_COLOR3(color), 0.5);
  5613. tnsVertex2d(R-RM, uil->U);
  5614. tnsVertex2d(L+RM, uil->U);
  5615. tnsVertex2d(L+RM, uil->U + DisplayH);
  5616. tnsVertex2d(R-RM, uil->U + DisplayH);
  5617. tnsPackAs(GL_LINE_LOOP);
  5618. tnsColor4d(LA_COLOR3(color), 1);
  5619. tnsVertex2d(R, U);
  5620. tnsVertex2d(L, U);
  5621. tnsVertex2d(L, B);
  5622. tnsVertex2d(R, B);
  5623. tnsPackAs(GL_TRIANGLE_FAN);
  5624. int HU=(U+B)/2+LA_RH2;
  5625. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5626. tnsFlush();
  5627. }
  5628. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5629. if(!uil->ScrollerShownH) return;
  5630. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5631. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5632. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5633. int L = uil->L + Offset;
  5634. int R = L + Len;
  5635. int U = UiB - RM - W;
  5636. int B = U + W;
  5637. if (B > U + DisplayW) B = U + DisplayW;
  5638. if (U < uil->U) U = uil->U;
  5639. if (R <= uil->L || L >= uil->R) return;
  5640. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5641. if (L < uil->L) L = uil->L;
  5642. tnsUseNoTexture();
  5643. laBoxedTheme* bt=_LA_THEME_PANEL;
  5644. real* color=laThemeColor(bt, LA_BT_TEXT);
  5645. tnsColor4d(LA_COLOR3(color), 0.2);
  5646. tnsVertex2d(uil->L,U+RM);
  5647. tnsVertex2d(uil->L,B-RM);
  5648. tnsVertex2d(uil->L + DisplayW,B-RM);
  5649. tnsVertex2d(uil->L + DisplayW,U+RM);
  5650. tnsPackAs(GL_TRIANGLE_FAN);
  5651. tnsColor4d(LA_COLOR3(color), 0.5);
  5652. tnsVertex2d(uil->L,U+RM);
  5653. tnsVertex2d(uil->L,B-RM);
  5654. tnsVertex2d(uil->L + DisplayW,B-RM);
  5655. tnsVertex2d(uil->L + DisplayW,U+RM);
  5656. tnsPackAs(GL_LINE_LOOP);
  5657. tnsColor4d(LA_COLOR3(color), 1);
  5658. tnsVertex2d(R, U);
  5659. tnsVertex2d(L, U);
  5660. tnsVertex2d(L, B);
  5661. tnsVertex2d(R, B);
  5662. tnsPackAs(GL_TRIANGLE_FAN);
  5663. int HU=(U+B)/2+LA_RH2;
  5664. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5665. tnsFlush();
  5666. }
  5667. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5668. tnsUseNoTexture();
  5669. tnsColor4dv(color);
  5670. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5671. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5672. tnsPackAs(GL_TRIANGLE_FAN);
  5673. }
  5674. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5675. laSocketRecord* sr;
  5676. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5677. uild->WiresContainer=container;
  5678. }
  5679. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5680. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5681. if(lip->Target==uild->WiresContainer) break;
  5682. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5683. }
  5684. }
  5685. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5686. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5687. int PanX, PanY;
  5688. if(pc==LA_PC_SOCKET_OUT){
  5689. laNodeOutSocket* s=ui->PP.EndInstance;
  5690. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5691. }else{
  5692. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5693. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5694. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5695. }
  5696. }
  5697. void la_RegenerateWireColors(){
  5698. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5699. laTheme* t=MAIN.CurrentTheme;
  5700. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5701. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5702. for(int i=0;i<MAIN.WireColorSlices;i++){
  5703. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5704. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5705. }
  5706. }
  5707. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5708. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5709. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5710. tnsInterpolate2dv(v1,v2,0.5,vi);
  5711. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5712. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5713. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5714. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5715. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5716. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5717. tnsVertex2d(v1[0],v1[1]);
  5718. for(int i=1;i<=steps;i++){
  5719. real ratio=i==steps?1.0f:step*i;
  5720. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5721. tnsVertex2d(v1s[0],v1s[1]);
  5722. }
  5723. }
  5724. void la_DrawNodeWires(laUiListDraw* uild){
  5725. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5726. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5727. tnsUseNoTexture();
  5728. #define _RSLICES 16
  5729. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5730. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5731. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5732. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5733. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5734. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5735. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5736. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5737. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5738. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5739. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5740. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5741. }
  5742. if(MAIN.tNodeIn->Source){
  5743. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5744. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5745. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5746. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5747. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5748. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5749. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5750. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5751. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5752. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5753. }
  5754. #undef _RSLICES
  5755. tnsFlush();
  5756. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5757. glLineWidth(ww);
  5758. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5759. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5760. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5761. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5762. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5763. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5764. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5765. }
  5766. if(MAIN.tNodeIn->Source){
  5767. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5768. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5769. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5770. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5771. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5772. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5773. }
  5774. tnsFlush();
  5775. glLineWidth(1);
  5776. la_InitSocketRecord(uild,0);
  5777. }
  5778. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5779. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5780. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5781. }
  5782. 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){
  5783. laUiItem *ui;
  5784. laBoxedTheme *bt;
  5785. laUiList *sub;
  5786. laUiListDrawItem *uildi;
  5787. int Ret = 0;
  5788. if (!uil) return 0;
  5789. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5790. ui = uil->UiItems.pFirst;
  5791. if(uil->PanY<0){uil->PanY=0;}
  5792. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5793. uil->SaveScale=MAIN.UiScale;
  5794. MAIN.UiScale*=uil->Scale;
  5795. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5796. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5797. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5798. if (ui->Type == &_LA_UI_CONDITION){
  5799. laConditionUiExtraData *cued = ui->Extra;
  5800. la_StepExpression(cued->Expression);
  5801. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5802. if (!cued->IsTrue){
  5803. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5804. }else{
  5805. ui = ui->Item.pNext;
  5806. }
  5807. continue;
  5808. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5809. ui = ui->Item.pNext;
  5810. continue;
  5811. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5812. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5813. if (cued->IsTrue) ui = cued->EndUi;
  5814. else
  5815. ui = ui->Item.pNext;
  5816. continue;
  5817. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5818. laConditionUiExtraData *cued = ui->Extra;
  5819. ui->Type->Draw(ui, LA_RH);
  5820. if (ui->State == LA_UI_NORMAL){
  5821. cued->IsTrue = 0;
  5822. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5823. }else{
  5824. cued->IsTrue = 1;
  5825. ui = ui->Item.pNext;
  5826. }
  5827. continue;
  5828. }
  5829. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5830. int NeedDraw=0;
  5831. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5832. if(NeedDraw){
  5833. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5834. }else{ ui->Type->Draw(ui, LA_RH); }
  5835. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5836. tnsFlush();
  5837. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5838. tnsResetViewMatrix();
  5839. }
  5840. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5841. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5842. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5843. tnsFlush();
  5844. }
  5845. }
  5846. if(NeedDraw || RegisterNodes){
  5847. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5848. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5849. ui->Type == _LA_UI_TAB ||
  5850. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5851. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5852. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5853. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5854. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5855. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5856. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5857. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5858. 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); }
  5859. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5860. 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);
  5861. 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)); }
  5862. }elif (ui->Type == _LA_UI_COLLECTION){
  5863. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5864. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5865. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5866. void* SaveInstance = ui->PP.EndInstance;
  5867. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5868. int State;
  5869. ui->PP.EndInstance = sub->Instance;
  5870. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5871. if(NeedDraw){ int drawn=0;
  5872. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5873. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5874. }
  5875. if (CanGetState && !drawn){
  5876. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5877. if(State >= 0){
  5878. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5879. }
  5880. }
  5881. }
  5882. if(sub->TabName && sub->TabName->Ptr){
  5883. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5884. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5885. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5886. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5887. tnsFlush();
  5888. }
  5889. if(CanGetTheme){
  5890. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5891. la_SwitchThemeQuick(t, OriginalTheme);
  5892. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5893. }
  5894. tnsFlush();
  5895. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5896. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5897. }
  5898. //ui->PP.EndInstance = Active;
  5899. ui->PP.EndInstance = SaveInstance;
  5900. }elif (ui->Type == _LA_UI_CANVAS){
  5901. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5902. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5903. tnsFlush();
  5904. 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);
  5905. }
  5906. }
  5907. }
  5908. ui = ui->Item.pNext;
  5909. }else{
  5910. ui = ui->Item.pNext;
  5911. }
  5912. }
  5913. tnsFlush();
  5914. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5915. la_RestoreLastUiListMatrix(uild, B - U);
  5916. MAIN.UiScale=uil->SaveScale;
  5917. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5918. return Ret;
  5919. }
  5920. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5921. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5922. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5923. tnsUseNoTexture();
  5924. tnsColor4d(1, 1, 1, 1);
  5925. tnsVertex2d(L, U);
  5926. tnsVertex2d(R, U);
  5927. tnsVertex2d(R, B);
  5928. tnsVertex2d(L, B);
  5929. tnsPackAs(GL_LINE_LOOP);
  5930. tnsVertex2d(L + 3, Begin);
  5931. tnsVertex2d(R - 3, Begin);
  5932. tnsVertex2d(R - 3, End);
  5933. tnsVertex2d(L + 3, End);
  5934. tnsPackAs(GL_LINE_LOOP);
  5935. }
  5936. int laIsInUiItem(laUiItem *ui, int x, int y){
  5937. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5938. return 1;
  5939. }
  5940. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5941. if (x < l || x > r || y < u || y > b) return 0;
  5942. return 1;
  5943. }
  5944. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5945. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5946. laUiItem *ui, *tui;
  5947. laBoxedTheme *bt;
  5948. laUiList *sub;
  5949. int CPB = 0;
  5950. if (!uil || (LimB && y > LimB)) return 0;
  5951. x += uil->PanX;
  5952. y += uil->PanY;
  5953. for (ui = uil->UiItems.pFirst; ui;){
  5954. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5955. if (ui->Type == &_LA_UI_CONDITION){
  5956. laConditionUiExtraData *cued = ui->Extra;
  5957. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5958. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5959. if (!cued->IsTrue){
  5960. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5961. }else{
  5962. ui = ui->Item.pNext;
  5963. }
  5964. continue;
  5965. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5966. ui = ui->Item.pNext;
  5967. continue;
  5968. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5969. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5970. if (cued->IsTrue) ui = cued->EndUi;
  5971. else
  5972. ui = ui->Item.pNext;
  5973. continue;
  5974. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5975. laConditionUiExtraData *cued = ui->Extra;
  5976. if (laIsInUiItem(ui, x, y)){
  5977. lstAppendPointer(LocalBuf, uil);
  5978. return ui;
  5979. }
  5980. if (ui->State == LA_UI_NORMAL){
  5981. cued->IsTrue = 0;
  5982. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5983. }else{
  5984. cued->IsTrue = 1;
  5985. ui = ui->Item.pNext;
  5986. }
  5987. continue;
  5988. }
  5989. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5990. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5991. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5992. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5993. if(!la_DetectSplit(ui->C, x)) Add=0;
  5994. }
  5995. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5996. }
  5997. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5998. if (ui->Page->HeightCoeff) CPB = ui->B;
  5999. else CPB = ui->Page->B;
  6000. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6001. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  6002. lstAppendPointer(LocalBuf, uil);
  6003. return tui;
  6004. }
  6005. }else if (laIsInUiItem(ui, x, y)){
  6006. lstAppendPointer(LocalBuf, uil);return ui;
  6007. }
  6008. }
  6009. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  6010. if (laIsInUiItem(ui, x, y)){
  6011. lstAppendPointer(LocalBuf, uil);
  6012. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  6013. if(Deep){
  6014. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  6015. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  6016. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  6017. lstAppendPointer(LocalBuf, iuil);
  6018. return tui;
  6019. }
  6020. }
  6021. }
  6022. }
  6023. return ui;
  6024. }
  6025. }
  6026. if (ui->Type == _LA_UI_CANVAS){
  6027. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6028. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6029. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  6030. lstAppendPointer(LocalBuf, uil);
  6031. return tui;
  6032. }
  6033. }
  6034. }
  6035. if (laIsInUiItem(ui, x, y)){
  6036. lstAppendPointer(LocalBuf, uil);
  6037. return ui;
  6038. }
  6039. }
  6040. ui = ui->Item.pNext;
  6041. }
  6042. return 0;
  6043. }
  6044. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  6045. laListHandle Locals={0};
  6046. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  6047. while(lstPopPointer(&Locals));
  6048. //printf("%s\n", ui?ui->Type->Identifier:"?");
  6049. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  6050. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  6051. if(pc==PCInOrOut) return ui;
  6052. }
  6053. return 0;
  6054. }
  6055. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  6056. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  6057. laUiItem *ui = uil->UiItems.pFirst;
  6058. laBoxedTheme *bt;
  6059. laUiList *tuil;
  6060. laUiList *sub;
  6061. int CPB = 0;
  6062. x += uil->PanX;
  6063. y += uil->PanY;
  6064. if (y > LimH) return uil;
  6065. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  6066. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  6067. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6068. return uil;
  6069. }
  6070. for (ui = uil->UiItems.pFirst; ui;){
  6071. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6072. if (ui->Type == &_LA_UI_CONDITION){
  6073. laConditionUiExtraData *cued = ui->Extra;
  6074. //la_StepExpression(cued->Expression);
  6075. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6076. if (!cued->IsTrue){
  6077. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6078. }else{
  6079. ui = ui->Item.pNext;
  6080. }
  6081. continue;
  6082. }
  6083. if (ui->Type == &_LA_UI_CONDITION_END){
  6084. ui = ui->Item.pNext;
  6085. continue;
  6086. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6087. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6088. if (cued->IsTrue) ui = cued->EndUi;
  6089. else
  6090. ui = ui->Item.pNext;
  6091. continue;
  6092. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6093. laConditionUiExtraData *cued = ui->Extra;
  6094. if (ui->State == LA_UI_NORMAL){
  6095. cued->IsTrue = 0;
  6096. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6097. }else{
  6098. cued->IsTrue = 1;
  6099. ui = ui->Item.pNext;
  6100. }
  6101. continue;
  6102. }
  6103. if (InToContainerUI && ui != Exception){
  6104. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6105. if (ContainerParent) (*ContainerParent) = uil;
  6106. if (ParentUi) *ParentUi = ui;
  6107. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6108. //if (y > LimH) return uil;
  6109. 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))){
  6110. return tuil;
  6111. }
  6112. }
  6113. }
  6114. }
  6115. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6116. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  6117. else CPB = ui->Page->B;
  6118. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6119. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6120. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6121. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6122. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6123. if (ParentUi) *ParentUi = ui;
  6124. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  6125. }
  6126. }
  6127. ui = ui->Item.pNext;
  6128. }
  6129. return uil;
  6130. }
  6131. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  6132. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  6133. laUiItem *ui = uil->UiItems.pFirst;
  6134. laBoxedTheme *bt;
  6135. laUiList *tuil;
  6136. laUiList *sub;
  6137. int CPB = 0;
  6138. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  6139. x += uil->PanX;
  6140. y += uil->PanY;
  6141. if (y > LimH) return uil;
  6142. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  6143. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  6144. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6145. return uil;
  6146. }
  6147. for (ui = uil->UiItems.pFirst; ui;){
  6148. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6149. if (ui->Type == &_LA_UI_CONDITION){
  6150. laConditionUiExtraData *cued = ui->Extra;
  6151. //la_StepExpression(cued->Expression);
  6152. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6153. if (!cued->IsTrue){
  6154. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6155. }else{
  6156. ui = ui->Item.pNext;
  6157. }
  6158. continue;
  6159. }
  6160. if (ui->Type == &_LA_UI_CONDITION_END){
  6161. ui = ui->Item.pNext;
  6162. continue;
  6163. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6164. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6165. if (cued->IsTrue) ui = cued->EndUi;
  6166. else
  6167. ui = ui->Item.pNext;
  6168. continue;
  6169. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6170. laConditionUiExtraData *cued = ui->Extra;
  6171. if (ui->State == LA_UI_NORMAL){
  6172. cued->IsTrue = 0;
  6173. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6174. }else{
  6175. cued->IsTrue = 1;
  6176. ui = ui->Item.pNext;
  6177. }
  6178. continue;
  6179. }
  6180. if (InToContainerUI && ui != Exception){
  6181. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6182. if (ContainerParent) (*ContainerParent) = uil;
  6183. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6184. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6185. //if (y > LimH) return uil;
  6186. 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))){
  6187. return tuil;
  6188. }
  6189. }
  6190. }
  6191. }
  6192. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6193. if (ui->Page->HeightCoeff) CPB = ui->B;
  6194. else CPB = ui->Page->B;
  6195. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6196. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6197. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6198. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6199. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6200. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6201. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6202. }
  6203. }
  6204. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6205. if (ui->Page->HeightCoeff) CPB = ui->B;
  6206. else
  6207. CPB = ui->Page->B;
  6208. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6209. if (ScrollUil) *ScrollUil = ui->Page;
  6210. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6211. }
  6212. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6213. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6214. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6215. }
  6216. }
  6217. ui = ui->Item.pNext;
  6218. }
  6219. return uil;
  6220. }
  6221. int la_TestUiListMinumWidth(laUiList *uil){
  6222. laUiItem *ui, *tui;
  6223. laBoxedTheme *bt;
  6224. laUiList *sub;
  6225. int CPB = 0;
  6226. int W = 0;
  6227. int tW, sW, RowMode=0, rW;
  6228. void *Restore;
  6229. for (ui = uil->UiItems.pFirst; ui;){
  6230. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6231. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6232. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6233. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6234. if (W < tW) W = tW;
  6235. }elif (ui->Type == _LA_UI_COLLECTION){
  6236. Restore = ui->PP.EndInstance;
  6237. tW = 0; sW = 0;
  6238. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6239. ui->PP.EndInstance = sub->Instance;
  6240. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6241. if (sW > tW) tW = sW;
  6242. }
  6243. ui->PP.EndInstance = Restore;
  6244. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6245. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6246. if (W < tW) W = tW;
  6247. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6248. RowMode=1; rW=0;
  6249. }elif (ui->Type==&_LA_UI_ROW_END){
  6250. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6251. }elif (ui->Type->GetMinWidth){
  6252. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6253. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6254. }
  6255. ui = ui->Item.pNext;
  6256. }
  6257. return W;
  6258. }
  6259. void la_InitLLVM(){
  6260. //LLVMLinkInMCJIT();
  6261. //LLVMInitializeNativeTarget();
  6262. //LLVMInitializeNativeAsmPrinter();
  6263. //LLVMInitializeNativeAsmParser();
  6264. // MAIN.llvmContext = LLVMGetGlobalContext();
  6265. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6266. }
  6267. //==================================================================================================
  6268. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6269. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6270. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6271. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6272. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6273. memFree(kmi);
  6274. }
  6275. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6276. laKeyMapItem *kmi;
  6277. if (!km) return 0;
  6278. kmi = memAcquire(sizeof(laKeyMapItem));
  6279. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6280. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6281. }else{
  6282. strSafeSet(&kmi->Operation, Operation);
  6283. }
  6284. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6285. kmi->SpecialKeyBits = SpecialKeyBits;
  6286. kmi->EventType = EventType;
  6287. kmi->Key = tolowerGuarded(Key);
  6288. kmi->SelectBase = SelectBase;
  6289. lstAppendItem(&km->Items, kmi);
  6290. return kmi;
  6291. }
  6292. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6293. laKeyMapItem *kmi; int inv=0;
  6294. char *instructions;
  6295. if(e->type==LA_MOUSEMOVE) return 0;
  6296. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6297. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6298. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6299. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6300. if (kmi->Operation)
  6301. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6302. else
  6303. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6304. inv = 1;
  6305. }
  6306. }
  6307. return inv;
  6308. }
  6309. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6310. laKeyMapItem *kmi;
  6311. char *instructions;
  6312. int inv = 0; int lx = -1, ly = -1;
  6313. if(e->type==LA_MOUSEMOVE) return 0;
  6314. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6315. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6316. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6317. if (e->Localized){
  6318. lx = e->x;
  6319. ly = e->y;
  6320. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6321. e->Localized = 0;
  6322. }
  6323. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6324. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6325. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6326. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6327. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6328. }elif (kmi->Operation){
  6329. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6330. }else{
  6331. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6332. }
  6333. inv = 1;
  6334. if (lx >= 0){
  6335. e->x = lx;
  6336. e->y = ly;
  6337. e->Localized = 1;
  6338. }
  6339. }
  6340. }
  6341. return inv;
  6342. }
  6343. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6344. void la_DestroyOperatorType(laOperatorType* at){
  6345. //if(at->PC) la_FreePropertyContainer(at->PC);
  6346. memFree(at);
  6347. }
  6348. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6349. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6350. uint32_t IconID, int ExtraMark){
  6351. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6352. at->Identifier = ID;
  6353. at->Name = Name;
  6354. at->Description = Description;
  6355. at->Check = Check;
  6356. at->Invoke = Invoke;
  6357. at->Init = Init;
  6358. at->Exit = Exit;
  6359. at->Modal = Modal;
  6360. at->IconID = IconID;
  6361. at->ExtraMark = ExtraMark;
  6362. at->ParseArgs = la_DefaultOperatorParser;
  6363. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6364. lstAppendItem2(&MAIN.OperatorList, at);
  6365. return at;
  6366. }
  6367. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6368. ot->PC = memAcquire(sizeof(laPropContainer));
  6369. ot->PC->Identifier = ot->Identifier;
  6370. ot->PC->Hyper = HyperLevel;
  6371. return ot->PC;
  6372. }
  6373. laOperator *la_CreateOperator(laOperatorType *at){
  6374. laOperator *a = CreateNew(laOperator);
  6375. a->Type = at;
  6376. if (at->PC && at->PC->Props.pFirst){
  6377. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6378. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6379. a->PP.LastPs->p->SubProp = at->PC;
  6380. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6381. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6382. a->PP.LastPs->Type = U'.';
  6383. }
  6384. return a;
  6385. }
  6386. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6387. return (!strcmp(a->Identifier, id));
  6388. }
  6389. laOperatorType *laGetOperatorType(const char *ID){
  6390. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6391. }
  6392. int laOperatorExistsT(laOperatorType* at){
  6393. if (!at) return 0;
  6394. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6395. return 0;
  6396. }
  6397. int laOperatorExists(const char* ID){
  6398. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6399. return laOperatorExistsT(at);
  6400. }
  6401. int la_OperatorExists(laOperator *ac){
  6402. if (!ac) return 0;
  6403. laOperator *a;
  6404. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6405. return 0;
  6406. }
  6407. int la_UiOperatorExists(void *inst){
  6408. laOperator *a;
  6409. if (!inst) return 0;
  6410. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6411. if (((laUiItem *)a->Instance) == inst){
  6412. return 1;
  6413. }
  6414. }
  6415. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6416. if (a->Instance == inst){
  6417. return 1;
  6418. }
  6419. }
  6420. return 0;
  6421. }
  6422. int la_OperatorPending(laOperator *target){
  6423. laOperator *a;
  6424. if (!target) return 0;
  6425. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6426. if (a == target){
  6427. return 1;
  6428. }
  6429. }
  6430. return 0;
  6431. }
  6432. void laSetOperatorLocalizer(void *ToPanel){
  6433. MAIN.ToPanel = ToPanel;
  6434. }
  6435. void la_DestroyConfirmData(laConfirmData **cd);
  6436. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6437. laOperator *ai = (*a);
  6438. laOperator *ac = ((*a)->Child);
  6439. void *Ret = 0;
  6440. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6441. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6442. }
  6443. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6444. if ((*a)->PP.LastPs){
  6445. memFree((*a)->PP.LastPs->p);
  6446. memFree((*a)->PP.LastPs);
  6447. }
  6448. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6449. la_SetPropMathcerContext((*a)->OperatorPanel);
  6450. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6451. laDestroySinglePanel((*a)->OperatorPanel,0);
  6452. }
  6453. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6454. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6455. lstClearPointer(&(*a)->LocalUiLists);
  6456. if (Operators){
  6457. Ret = ai->Item.pNext;
  6458. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6459. else
  6460. lstRemoveItem(Operators, *a);
  6461. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6462. if (ai->Child == (*a)) ai->Child = 0;
  6463. }
  6464. }
  6465. strSafeDestroy(&(*a)->RuntimeHint);
  6466. free(*a);
  6467. return Ret;
  6468. }
  6469. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6470. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6471. if (!at) return 0;
  6472. if (!at->Check) return 1;
  6473. return (at->Check(This, Instructions));
  6474. }
  6475. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6476. if (!at) return 0;
  6477. if (!at->Check) return 1;
  6478. return (at->Check(This, Instructions));
  6479. }
  6480. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6481. laPropPack FakePP = {0};
  6482. laPropStep FakePs = {0};
  6483. if (!at) return 0;
  6484. if (!at->Check) return 1;
  6485. FakePP.LastPs = &FakePs;
  6486. FakePP.Go = FakePP.LastPs;
  6487. FakePP.LastPs->p = This->LastPs->p;
  6488. FakePP.LastPs->UseInstance = This->EndInstance;
  6489. FakePP.EndInstance = Real_FromInstance;
  6490. FakePP.LastIndex = This->LastIndex;
  6491. return (at->Check(&FakePP, Instructions));
  6492. }
  6493. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6494. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6495. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6496. }
  6497. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6498. laOperator *a, *f = From;
  6499. int rev;
  6500. if (!f && e&&e->Localized) return -1;
  6501. a = la_CreateOperator(at);
  6502. a->ToPanel = MAIN.ToPanel;
  6503. a->This = This;
  6504. a->ExtraInstructions = args;
  6505. strMakeInstructions(&a->ExtraInstructionsP, args);
  6506. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6507. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6508. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6509. la_DestroyOperator(&a, 0, 0);
  6510. return LA_CANCELED;
  6511. }
  6512. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6513. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6514. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6515. e->Localized = 1;
  6516. }
  6517. if (e&&e->Localized){
  6518. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6519. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6520. e->Localized = 0;
  6521. }else{
  6522. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6523. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6524. }
  6525. }
  6526. if (From) f->Child = a;
  6527. a->Using = 1;
  6528. if (at->Init) at->Init(a);
  6529. rev = at->Invoke(a, e);
  6530. a->Using = 0;
  6531. if (rev & LA_FINISH){
  6532. a->StopNow = 1; if(From)From->Child=0;
  6533. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6534. }
  6535. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6536. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6537. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6538. a->State = rev;
  6539. a->PP.EndInstance = a->CustomData;
  6540. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6541. }else
  6542. la_DestroyOperator(&a, 0, 0);
  6543. return rev;
  6544. }
  6545. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6546. laOperatorType *at; laOperator *a, *f = From;
  6547. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6548. if (!at) return -1;
  6549. return laInvokeP(From,at,e,This,args,args2);
  6550. }
  6551. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6552. laOperator *a, *f = From;
  6553. int rev;
  6554. laPropPack *created;
  6555. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6556. created = memAcquireSimple(sizeof(laPropPack));
  6557. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6558. created->Go = created->LastPs;
  6559. created->LastPs->p = OrigionalThis->LastPs->p;
  6560. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6561. created->EndInstance = FromInstance;
  6562. created->LastIndex = OrigionalThis->LastIndex;
  6563. a = la_CreateOperator(at);
  6564. a->ToPanel = MAIN.ToPanel;
  6565. a->This = created;
  6566. a->CreatedThis = created;
  6567. a->ExtraInstructions = args;
  6568. strMakeInstructions(&a->ExtraInstructionsP, args);
  6569. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6570. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6571. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6572. la_DestroyOperator(&a, 0, 0);
  6573. return LA_CANCELED;
  6574. }
  6575. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6576. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6577. if (From) f->Child = a;
  6578. a->Using = 1;
  6579. if (at->Init) at->Init(a);
  6580. rev = at->Invoke(a, e);
  6581. a->Using = 0;
  6582. if (rev & LA_FINISH){
  6583. a->StopNow = 1; if(From)From->Child=0;
  6584. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6585. }
  6586. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6587. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6588. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6589. a->State = rev;
  6590. a->PP.EndInstance = a->CustomData;
  6591. }else
  6592. la_DestroyOperator(&a, 0, 0);
  6593. return rev;
  6594. }
  6595. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6596. laOperator *a, *f = From;
  6597. int rev;
  6598. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6599. a = la_CreateOperator(at);
  6600. a->Instance = inst;
  6601. a->ToPanel = MAIN.ToPanel;
  6602. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6603. if (From) f->Child = a;
  6604. a->Using = 1;
  6605. if (at->Init) at->Init(a);
  6606. rev = at->Invoke(a, e);
  6607. a->Using = 0;
  6608. if (rev & LA_FINISH){
  6609. a->StopNow = 1; if(From)From->Child=0;
  6610. }
  6611. if (rev & LA_BLOCK){
  6612. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6613. a->State = rev;
  6614. }else la_DestroyOperator(&a, 0, 0);
  6615. DEB = a;
  6616. return rev;
  6617. }
  6618. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6619. laOperatorType *at;
  6620. laOperator *a, *f = From;
  6621. if (la_UiOperatorExists(inst)) return -1;
  6622. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6623. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6624. }
  6625. void laRequestDelayEvent(real Seconds){
  6626. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6627. int la_UiStillInService(void *UiInstance){
  6628. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6629. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6630. if (ai->Instance == UiInstance) return 1;
  6631. }
  6632. return 0;
  6633. }
  6634. void la_StopUiOperatorService(void *UiInstance){
  6635. laOperator *ai, *dai, *NextAi;
  6636. if (!MAIN.CurrentWindow) return;
  6637. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6638. NextAi = ai->Item.pNext;
  6639. if (ai->Instance == UiInstance){
  6640. if (ai->Child){
  6641. la_StopUiOperatorService(ai->Child->Instance);
  6642. ai->Child = 0;
  6643. }
  6644. laOperator *dai = ai;
  6645. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6646. continue;
  6647. }
  6648. }
  6649. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6650. NextAi = ai->Item.pNext;
  6651. if (ai->Instance == UiInstance){
  6652. if (ai->Instance == ai->ToPanel){
  6653. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6654. //ai->ToPanel->LaterDestroy = 1;
  6655. }
  6656. if (ai->Child && la_OperatorExists(ai->Child)){
  6657. la_StopUiOperatorService(ai->Child->Instance);
  6658. //ai->Child = 0;
  6659. }
  6660. if (!ai->Using){
  6661. laOperator *dai = ai;
  6662. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6663. }else
  6664. ai->StopNow = 1;
  6665. }
  6666. }
  6667. }
  6668. void la_StopAllOperators(){
  6669. laOperator *ai, *dai, *NextAi;
  6670. if (!MAIN.CurrentWindow) return;
  6671. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6672. NextAi = ai->Item.pNext;
  6673. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6674. continue;
  6675. }
  6676. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6677. NextAi = ai->Item.pNext;
  6678. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6679. laHidePanelWithDissoveEffect(ai->ToPanel);
  6680. ai->ToPanel->LaterDestroy = 1;
  6681. }
  6682. if (!ai->Using){
  6683. laOperator *dai = ai;
  6684. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6685. }else ai->StopNow = 1;
  6686. }
  6687. }
  6688. void la_DestroyConfirmData(laConfirmData **cd){
  6689. if((!cd)||!(*cd)) return;
  6690. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6691. if ((*cd)->StrData) free((*cd)->StrData);
  6692. FreeMem((*cd));
  6693. (*cd) = 0;
  6694. }
  6695. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6696. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6697. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6698. ai->NextConfirmData = cd; laRetriggerOperators();
  6699. }
  6700. void laConfirmInt(laOperator *a, int Data, int mode){
  6701. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6702. cd->IData = Data; cd->Mode = mode;
  6703. ai->NextConfirmData = cd; laRetriggerOperators();
  6704. }
  6705. void laConfirmFloat(laOperator *a, real Data, int mode){
  6706. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6707. cd->FData = Data; cd->Mode = mode;
  6708. ai->NextConfirmData = cd; laRetriggerOperators();
  6709. }
  6710. void laConfirmString(laOperator *a, char *Str, int mode){
  6711. laOperator *ai = a;
  6712. laConfirmData *cd = CreateNew(laConfirmData);
  6713. int len = strlen(Str);
  6714. char *buf = calloc(len + 1, sizeof(char));
  6715. strcpy(buf, Str);
  6716. cd->StrData = buf;
  6717. cd->Mode = mode;
  6718. cd->Destroy = free;
  6719. ai->NextConfirmData = cd;
  6720. laRetriggerOperators();
  6721. }
  6722. int laConfirmSameDataIfAny(laOperator *a){
  6723. laOperator *ai = a;
  6724. laConfirmData *cd;
  6725. char *buf = 0;
  6726. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6727. cd = CreateNew(laConfirmData);
  6728. if (ai->ConfirmData->StrData){
  6729. int len = strlen(ai->ConfirmData->StrData);
  6730. buf = calloc(len + 1, sizeof(char));
  6731. strcpy(buf, ai->ConfirmData->StrData);
  6732. }
  6733. //cd->CustomData = cd->CustomData;
  6734. cd->IData = ai->ConfirmData->IData;
  6735. cd->FData = ai->ConfirmData->FData;
  6736. cd->PointerData = ai->ConfirmData->PointerData;
  6737. cd->PointerType = a->ConfirmData->PointerType;
  6738. cd->StrData = buf;
  6739. cd->Mode = ai->ConfirmData->Mode;
  6740. cd->Destroy = ai->ConfirmData->Destroy;
  6741. ai->NextConfirmData = cd;
  6742. laRetriggerOperators();
  6743. return 1;
  6744. }
  6745. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6746. laOperator *ai = a;
  6747. laConfirmData *cd = CreateNew(laConfirmData);
  6748. cd->CustomData = UserData;
  6749. cd->Mode = mode;
  6750. cd->Destroy = Destroy;
  6751. ai->NextConfirmData = cd;
  6752. laRetriggerOperators();
  6753. }
  6754. int laGetConfirmMode(laOperator *a){
  6755. return ((laOperator *)a)->ConfirmData->Mode;
  6756. }
  6757. int laGetConfirmInt(laOperator *a){
  6758. laOperator *ai = a;
  6759. int rev = ai->ConfirmData->IData;
  6760. la_DestroyConfirmData(&ai->ConfirmData);
  6761. ai->ConfirmData = 0;
  6762. return rev;
  6763. }
  6764. real laGetConfirmFloat(laOperator *a){
  6765. laOperator *ai = a;
  6766. real rev = ai->ConfirmData->FData;
  6767. la_DestroyConfirmData(&ai->ConfirmData);
  6768. ai->ConfirmData = 0;
  6769. return rev;
  6770. }
  6771. void laGetConfirmString(laOperator *a, char *buf){
  6772. laOperator *ai = a;
  6773. strcpy(buf, ai->ConfirmData->StrData);
  6774. la_DestroyConfirmData(&ai->ConfirmData);
  6775. ai->ConfirmData = 0;
  6776. }
  6777. void *laGetConfirmUserData(laOperator *a){
  6778. laOperator *ai = a;
  6779. return ai->ConfirmData->CustomData;
  6780. }
  6781. void laFinalizeOperators(){
  6782. laOperatorType *at;
  6783. laListHandle *lst;
  6784. int i;
  6785. for (i = 0; i < 256; i++){
  6786. lst = &MAIN.OperatorTypeHash.Entries[i];
  6787. for (at = lst->pFirst; at; at = at->Item.pNext){
  6788. if (at->PC && at->PC->Props.pFirst){
  6789. lstAppendItem(&MAIN.PropContainers, at->PC);
  6790. }
  6791. }
  6792. }
  6793. }
  6794. //=================
  6795. #ifdef LA_LINUX
  6796. static void la_RecordWacomMotions(XIRawEvent *event)
  6797. {
  6798. double *valuator = event->valuators.values;
  6799. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6800. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6801. //SYSWINDOW root_return, child_return;
  6802. //int root_x_return, root_y_return;
  6803. //int win_x_return, win_y_return;
  6804. //unsigned int mask_return;
  6805. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6806. // &root_x_return, &root_y_return,
  6807. // &win_x_return, &win_y_return,
  6808. // &mask_return);
  6809. //
  6810. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6811. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6812. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6813. real x=valuator[3],y=valuator[4];
  6814. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6815. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6816. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6817. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6818. if(XIMaskIsSet(event->valuators.mask, 5)){
  6819. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6820. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6821. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6822. MAIN.IsPen=1;
  6823. }
  6824. #endif
  6825. #ifdef _WIN32
  6826. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6827. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6828. static uint32_t ch = 0; static int lead = 0;
  6829. static wchar_t buf[10] = { 0 }; int adv;
  6830. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6831. short wheelmark = 0;
  6832. int WheelDir = 0;
  6833. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6834. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6835. POINT point;
  6836. PACKET pkt;
  6837. static POINT ptOld, ptNew;
  6838. static UINT prsOld, prsNew, vkey;
  6839. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6840. switch (message) {
  6841. case WM_PAINT:
  6842. //SwapBuffers(GetDC(hwnd));
  6843. break;
  6844. case WM_MOUSEMOVE:
  6845. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6846. MAIN.IsPen = 0;
  6847. break;
  6848. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6849. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6850. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6851. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6852. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6853. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6854. case WM_MOUSEWHEEL:
  6855. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6856. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6857. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6858. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6859. break;
  6860. case WT_PACKET:
  6861. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6862. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6863. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6864. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6865. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6866. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6867. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6868. MAIN.StylusTwist = tw;
  6869. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6870. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6871. MAIN.EraserPressure = MAIN.StylusPressure;
  6872. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6873. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6874. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6875. }
  6876. return 0; break;
  6877. case WM_SYSCOMMAND:
  6878. switch (wparam) {
  6879. case SC_MAXIMIZE:
  6880. case SC_RESTORE:
  6881. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6882. break;
  6883. case SC_KEYMENU:
  6884. return 0;
  6885. case SC_MINIMIZE:
  6886. break;
  6887. }
  6888. break;
  6889. case WM_SIZE:
  6890. if (wparam == SIZE_MINIMIZED) break;
  6891. case WM_MOVE: /* And size */
  6892. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6893. break;
  6894. case WM_SETCURSOR:
  6895. if(MAIN.CurrentCursor) return 1;
  6896. break;
  6897. case WM_POINTERDOWN:
  6898. case WM_POINTERUP:
  6899. case WM_POINTERUPDATE:
  6900. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6901. pointerId = GET_POINTERID_WPARAM(wparam);
  6902. pointerType = PT_POINTER;
  6903. if(!GetPointerType(pointerId, &pointerType)){
  6904. pointerType = PT_POINTER;
  6905. }
  6906. if(pointerType == PT_PEN){
  6907. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6908. for (int i = peninfonum-1; i>=0; i--) {
  6909. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6910. ScreenToClient(hwnd, &point);
  6911. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6912. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6913. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6914. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6915. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6916. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6917. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6918. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6919. }
  6920. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6921. }
  6922. }
  6923. SkipPointerFrameMessages(pointerId);
  6924. return 0;
  6925. }
  6926. else if (pointerType == PT_TOUCH){
  6927. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6928. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6929. ScreenToClient(hwnd, &point);
  6930. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6931. }
  6932. }
  6933. break;
  6934. case WM_SYSKEYDOWN:
  6935. if (lparam & 0x40000000) break;
  6936. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6937. break;
  6938. case WM_KEYDOWN:
  6939. if (lparam & 0x40000000) break;
  6940. vkey = wparam;
  6941. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6942. break;
  6943. case WM_KEYUP:
  6944. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6945. break;
  6946. case WM_SYSKEYUP:
  6947. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6948. break;
  6949. case WM_UNICHAR:
  6950. la_SendInputEvent(hwnd, wparam);
  6951. break;
  6952. case WM_IME_CHAR:
  6953. la_SendInputEvent(hwnd, wparam);
  6954. return 0;
  6955. case WM_CHAR:
  6956. la_SendInputEvent(hwnd, wparam);
  6957. break;
  6958. case WM_SHOWWINDOW:
  6959. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6960. break;
  6961. case WM_CLOSE:
  6962. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6963. break;
  6964. default:
  6965. return DefWindowProc(hwnd, message, wparam, lparam);
  6966. }
  6967. return DefWindowProc(hwnd, message, wparam, lparam);
  6968. }
  6969. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6970. return DefWindowProc(hwnd, message, wparam, lparam);
  6971. }
  6972. #endif
  6973. int la_UpdateOperatorHints(laWindow* w){
  6974. laSafeString* ss=0;
  6975. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6976. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6977. }
  6978. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6979. }else{
  6980. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6981. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6982. }
  6983. strSafeDestroy(&ss);
  6984. }
  6985. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6986. laOperator *a, *NextA = 0;
  6987. int Result = 0;
  6988. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6989. la_SendSignalsFromEvent(e);
  6990. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6991. a = Operators->pFirst;
  6992. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6993. while (1){
  6994. if (!a) break;
  6995. if (a->StopNow){
  6996. NextA = a->Item.pNext;
  6997. if (a->Type->Exit) a->Type->Exit(a, Result);
  6998. ConfirmData = a->NextConfirmData;
  6999. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7000. NextConfirmData = ConfirmData;
  7001. a->ConfirmData = 0;
  7002. a->NextConfirmData = 0;
  7003. la_DestroyOperator(&a, Operators, 0);
  7004. a = NextA;
  7005. if (a){
  7006. a->ConfirmData = NextConfirmData;
  7007. }
  7008. continue;
  7009. }
  7010. a->Using = 1;
  7011. la_SetPropMathcerContext(a->ToPanel);
  7012. laSetOperatorLocalizer(a->ToPanel);
  7013. MAIN.CurrentPanel = a->ToPanel;
  7014. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7015. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  7016. e->Localized = 1;
  7017. }
  7018. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  7019. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7020. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  7021. e->Localized = 0;
  7022. }
  7023. la_SetPropMathcerContext(0);
  7024. laSetOperatorLocalizer(0);
  7025. MAIN.CurrentPanel = 0;
  7026. a->Using = 0;
  7027. if (Result & LA_PASS_ON){
  7028. laConfirmSameDataIfAny(a);
  7029. NextA = a->Item.pNext;
  7030. }else{
  7031. NextA = 0;
  7032. if (a->NextConfirmData){
  7033. la_DestroyConfirmData(&a->NextConfirmData);
  7034. }
  7035. }
  7036. ConfirmData = a->NextConfirmData;
  7037. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7038. NextConfirmData = ConfirmData;
  7039. a->ConfirmData = 0;
  7040. a->NextConfirmData = 0;
  7041. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  7042. if (a->Type->Exit) a->Type->Exit(a, Result);
  7043. la_DestroyOperator(&a, Operators, 0);
  7044. int found=0;
  7045. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  7046. if(!found){ NextA=0; }
  7047. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  7048. }
  7049. a = NextA;
  7050. if (a){
  7051. a->ConfirmData = NextConfirmData;
  7052. }
  7053. }
  7054. return 1;
  7055. }
  7056. int la_HandleEvents(laWindow *w){
  7057. laEvent *e, *NextE;
  7058. laOperator *a;
  7059. laThreadNotifier *tn;
  7060. MAIN.CurrentWindow=w;
  7061. //laSpinLock(&MAIN.csNotifier);
  7062. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  7063. //laSpinUnlock(&MAIN.csNotifier);
  7064. laNotifyUsers(tn->Path);
  7065. FreeMem(tn);
  7066. //if (MAIN.ThreadNotifiers.pFirst)
  7067. //laSpinLock(&MAIN.csNotifier);
  7068. }
  7069. //laSpinUnlock(&MAIN.csNotifier);
  7070. while (1){
  7071. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  7072. while (w->EventList.pFirst){
  7073. while (w->PendingOperators.pLast){
  7074. a = w->PendingOperators.pLast;
  7075. if (a->OperatorPanel){
  7076. laSetOperatorLocalizer(a->OperatorPanel);
  7077. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  7078. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  7079. }
  7080. lstRemoveItem(&w->PendingOperators, a);
  7081. lstPushItem(&w->Operators, a);
  7082. }
  7083. e = lstPopItem(&w->EventList);
  7084. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  7085. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  7086. memFree(e);
  7087. }
  7088. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  7089. if (!MAIN.ReTriggerOperators) break;
  7090. }
  7091. la_UpdateOperatorHints(w);
  7092. return 1;
  7093. }
  7094. int la_AllowInput(uint32_t ch){
  7095. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  7096. return 0;
  7097. }
  7098. int laCopyToClipboard(unsigned char * text){
  7099. #ifdef LA_LINUX
  7100. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  7101. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  7102. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  7103. strSafeSet(&MAIN.CopyPending, text);
  7104. #endif
  7105. }
  7106. int la_ProcessSysMessage(){
  7107. int SendDelay = 0, SendIdle = 0;
  7108. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  7109. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  7110. #ifdef LA_LINUX
  7111. XEvent e;
  7112. int type;
  7113. int InputCount = 0, CharCount=0;
  7114. KeySym InputKeysym = 0;
  7115. Status InputStatus = 0;
  7116. laWindow* wnd ;
  7117. while(XPending(MAIN.dpy)){
  7118. XGenericEventCookie *cookie = &e.xcookie;
  7119. XNextEvent(MAIN.dpy, &e);
  7120. if (XFilterEvent(&e, None)) continue;
  7121. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  7122. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  7123. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  7124. XFreeEventData(MAIN.dpy, cookie); continue;
  7125. }
  7126. switch(e.type){
  7127. case ConfigureNotify:
  7128. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  7129. break;
  7130. case Expose:
  7131. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  7132. if(!wnd) break;
  7133. laRefreshWindow(wnd);
  7134. break;
  7135. case MotionNotify:
  7136. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  7137. MAIN.IsPen=0;
  7138. break;
  7139. case ButtonPress:
  7140. type=LA_MOUSEDOWN;
  7141. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7142. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7143. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7144. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7145. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7146. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7147. MAIN.IsPen=0;
  7148. break;
  7149. case ButtonRelease:
  7150. type=LA_MOUSEUP;
  7151. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7152. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7153. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7154. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7155. MAIN.IsPen=0;
  7156. break;
  7157. case KeyPress:
  7158. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7159. MAIN.InputBuf[InputCount]=0;
  7160. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7161. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7162. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7163. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7164. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7165. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7166. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7167. #ifdef DEBUG
  7168. printf("pressed KEY: %d\n", (int)InputKeysym);
  7169. #endif
  7170. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7171. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7172. }
  7173. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7174. }
  7175. break;
  7176. case KeyRelease:
  7177. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7178. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7179. }
  7180. case ClientMessage:
  7181. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7182. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7183. }
  7184. break;
  7185. case SelectionNotify:
  7186. if(e.xselection.selection != MAIN.bufid) continue;
  7187. if (e.xselection.property){
  7188. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7189. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7190. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7191. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7192. else if(result) {
  7193. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7194. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7195. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7196. }
  7197. XFree(result);
  7198. return True;
  7199. }
  7200. case SelectionRequest:
  7201. if(!MAIN.CopyPending){ break; }
  7202. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7203. if (e.xselectionrequest.selection != MAIN.selection) break;
  7204. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7205. XSelectionEvent ev = {0};
  7206. int R = 0;
  7207. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7208. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7209. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7210. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7211. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7212. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7213. else if (ev.target == MAIN.UTF8)
  7214. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7215. else ev.property = None;
  7216. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7217. break;
  7218. case SelectionClear:
  7219. break;
  7220. default:
  7221. break;
  7222. }
  7223. }
  7224. #endif //linux
  7225. #ifdef _WIN32
  7226. MSG msg; int Processed = 0;
  7227. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7228. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7229. if (msg.wParam == VK_PROCESSKEY) {
  7230. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7231. }
  7232. TranslateMessage(&msg); DispatchMessage(&msg);
  7233. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7234. };
  7235. if(!MAIN.Windows.pFirst){ return 0; }
  7236. #endif
  7237. #ifdef LAGUI_ANDROID
  7238. int pollResult = 0;
  7239. int pollEvents = 0;
  7240. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7241. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7242. // NOTE: Never close window, native activity is controlled by the system!
  7243. if (MAIN.app->destroyRequested != 0)
  7244. {
  7245. //CORE.Window.shouldClose = true;
  7246. //ANativeActivity_finish(MAIN.app->activity);
  7247. }
  7248. }
  7249. #endif
  7250. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7251. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7252. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7253. }
  7254. return 1;
  7255. };
  7256. void la_PrintOperatorStack(){
  7257. laWindow *w = MAIN.CurrentWindow;
  7258. laOperator *a;
  7259. printf("\n");
  7260. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7261. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7262. a->Type->Identifier, a->Instance,
  7263. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7264. }
  7265. }
  7266. void la_DrawWindow(laWindow *w){
  7267. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7268. MAIN.CurrentWindow = w;
  7269. la_WindowDefDraw(w, 0);
  7270. }
  7271. int laFinalize(){
  7272. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7273. laUiTemplate* uit;
  7274. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7275. return 1;
  7276. }
  7277. void la_PreFrame(){
  7278. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7279. la_AnimationPreFrame();
  7280. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7281. }
  7282. void la_PostFrame(){
  7283. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7284. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7285. }
  7286. void laMainLoop(){
  7287. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7288. time_t t1, t2;
  7289. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7290. static int a = 0;
  7291. if(!laFinalize()) return;
  7292. laSetWindowCursor(LA_ARROW);
  7293. MAIN.DelayTriggered=1;
  7294. #ifdef LAGUI_ANDROID
  7295. while(!MAIN.AppReady){ usleep(1000); }
  7296. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7297. #endif
  7298. while (1){
  7299. laRecordTime(&MAIN.FrameStartTime);
  7300. la_PerfClear();
  7301. la_PreFrame();
  7302. if(!la_ProcessSysMessage()){ return; }
  7303. la_UpdateControllerStatus();
  7304. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7305. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7306. NextW = w->Item.pNext;
  7307. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7308. }
  7309. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7310. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7311. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7312. if(MAIN.GLDebugNeedsUpdate){
  7313. la_SetCurrentGLContextDebug();
  7314. }
  7315. la_DrawWindow(w);
  7316. }
  7317. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7318. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7319. #ifdef LA_LINUX
  7320. #ifdef LA_USE_GLES
  7321. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7322. #else
  7323. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7324. #endif
  7325. #endif
  7326. #ifdef _WIN32
  7327. SwapBuffers(w->hdc);
  7328. #endif
  7329. #ifdef LAGUI_ANDROID
  7330. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7331. #endif
  7332. }
  7333. MAIN.GLDebugNeedsUpdate=0;
  7334. la_PostFrame();
  7335. //t2 = clock();
  7336. laRecordTime(&MAIN.FrameEndTime);
  7337. TimeInterval = laTimeElapsedSecondsf(&MAIN.FrameEndTime, &MAIN.FrameStartTime);
  7338. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7339. if (Pause > 0){
  7340. int us = Pause * 1000000.0;
  7341. usleep(us);
  7342. }
  7343. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7344. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7345. la_AnimationPostFrame();
  7346. }
  7347. }
  7348. #ifdef LAGUI_ANDROID
  7349. int la_AndroidInitGraphics(void){
  7350. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7351. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7352. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7353. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7354. EGLint samples = 0;
  7355. EGLint sampleBuffer = 0;
  7356. const EGLint framebufferAttribs[] = {
  7357. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7358. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7359. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7360. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7361. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7362. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7363. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7364. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7365. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7366. EGL_NONE
  7367. };
  7368. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7369. EGLint numConfigs = 0;
  7370. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7371. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7372. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7373. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7374. eglBindAPI(EGL_OPENGL_API);
  7375. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7376. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7377. EGLint displayFormat = 0;
  7378. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7379. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7380. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7381. // There must be at least one frame displayed before the buffers are swapped
  7382. eglSwapInterval(MAIN.egl_dpy, 1);
  7383. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7384. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7385. MAIN.AppReady = 1;
  7386. return 0;
  7387. }
  7388. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7389. switch (cmd){
  7390. case APP_CMD_START: break;
  7391. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7392. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7393. case APP_CMD_RESUME:break;//InitPlatform();break;
  7394. case APP_CMD_INIT_WINDOW:
  7395. if (app->window != NULL){
  7396. if (MAIN.ContextRebindRequired){
  7397. // Reset screen scaling to full display size
  7398. EGLint displayFormat = 0;
  7399. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7400. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7401. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7402. // appropriate way to fix this
  7403. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7404. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7405. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7406. displayFormat);
  7407. // Recreate display surface and re-attach OpenGL context
  7408. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7409. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7410. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7411. //glClearColor(1,0.2,1,1);
  7412. //glClear(GL_COLOR_BUFFER_BIT);
  7413. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7414. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7415. MAIN.ContextRebindRequired = false;
  7416. }else{
  7417. la_AndroidInitGraphics();
  7418. }
  7419. }
  7420. break;
  7421. case APP_CMD_DESTROY:
  7422. case APP_CMD_TERM_WINDOW:
  7423. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7424. // 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.
  7425. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7426. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7427. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7428. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7429. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7430. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7431. MAIN.egl_surf = EGL_NO_SURFACE;
  7432. }
  7433. MAIN.ContextRebindRequired = true;
  7434. }
  7435. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7436. // this means that the user has already called 'CloseWindow()'
  7437. break;
  7438. case APP_CMD_SAVE_STATE: break;
  7439. case APP_CMD_STOP: break;
  7440. case APP_CMD_CONFIG_CHANGED:
  7441. case APP_CMD_WINDOW_RESIZED:
  7442. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7443. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7444. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7445. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7446. //print_cur_config(MAIN.app);
  7447. // Check screen orientation here!
  7448. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7449. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7450. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7451. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7452. MAIN.egl_surf = EGL_NO_SURFACE;
  7453. }
  7454. EGLint displayFormat = 0;
  7455. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7456. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7457. displayFormat);
  7458. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7459. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7460. }
  7461. break;
  7462. default: break;
  7463. }
  7464. }
  7465. #define KEYCODE_MAP_SIZE 162
  7466. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7467. 0, // AKEYCODE_UNKNOWN
  7468. 0, // AKEYCODE_SOFT_LEFT
  7469. 0, // AKEYCODE_SOFT_RIGHT
  7470. 0, // AKEYCODE_HOME
  7471. 0, // AKEYCODE_BACK
  7472. 0, // AKEYCODE_CALL
  7473. 0, // AKEYCODE_ENDCALL
  7474. '0', // AKEYCODE_0
  7475. '1', // AKEYCODE_1
  7476. '2', // AKEYCODE_2
  7477. '3', // AKEYCODE_3
  7478. '4', // AKEYCODE_4
  7479. '5', // AKEYCODE_5
  7480. '6', // AKEYCODE_6
  7481. '7', // AKEYCODE_7
  7482. '8', // AKEYCODE_8
  7483. '9', // AKEYCODE_9
  7484. 0, // AKEYCODE_STAR
  7485. 0, // AKEYCODE_POUND
  7486. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7487. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7488. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7489. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7490. 0, // AKEYCODE_DPAD_CENTER
  7491. 0, // AKEYCODE_VOLUME_UP
  7492. 0, // AKEYCODE_VOLUME_DOWN
  7493. 0, // AKEYCODE_POWER
  7494. 0, // AKEYCODE_CAMERA
  7495. 0, // AKEYCODE_CLEAR
  7496. 'a', // AKEYCODE_A
  7497. 'b', // AKEYCODE_B
  7498. 'c', // AKEYCODE_C
  7499. 'd', // AKEYCODE_D
  7500. 'e', // AKEYCODE_E
  7501. 'f', // AKEYCODE_F
  7502. 'g', // AKEYCODE_G
  7503. 'h', // AKEYCODE_H
  7504. 'i', // AKEYCODE_I
  7505. 'j', // AKEYCODE_J
  7506. 'k', // AKEYCODE_K
  7507. 'l', // AKEYCODE_L
  7508. 'm', // AKEYCODE_M
  7509. 'n', // AKEYCODE_N
  7510. 'o', // AKEYCODE_O
  7511. 'p', // AKEYCODE_P
  7512. 'q', // AKEYCODE_Q
  7513. 'r', // AKEYCODE_R
  7514. 's', // AKEYCODE_S
  7515. 't', // AKEYCODE_T
  7516. 'u', // AKEYCODE_U
  7517. 'v', // AKEYCODE_V
  7518. 'w', // AKEYCODE_W
  7519. 'x', // AKEYCODE_X
  7520. 'y', // AKEYCODE_Y
  7521. 'z', // AKEYCODE_Z
  7522. ',', // AKEYCODE_COMMA
  7523. '.', // AKEYCODE_PERIOD
  7524. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7525. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7526. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7527. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7528. LA_KEY_TAB, // AKEYCODE_TAB
  7529. ' ', // AKEYCODE_SPACE
  7530. 0, // AKEYCODE_SYM
  7531. 0, // AKEYCODE_EXPLORER
  7532. 0, // AKEYCODE_ENVELOPE
  7533. LA_KEY_ENTER, // AKEYCODE_ENTER
  7534. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7535. '`', // AKEYCODE_GRAVE
  7536. '-', // AKEYCODE_MINUS
  7537. '=', // AKEYCODE_EQUALS
  7538. '(', // AKEYCODE_LEFT_BRACKET
  7539. ')', // AKEYCODE_RIGHT_BRACKET
  7540. '\\', // AKEYCODE_BACKSLASH
  7541. ';', // AKEYCODE_SEMICOLON
  7542. '\'', // AKEYCODE_APOSTROPHE
  7543. '/', // AKEYCODE_SLASH
  7544. 0, // AKEYCODE_AT
  7545. 0, // AKEYCODE_NUM
  7546. 0, // AKEYCODE_HEADSETHOOK
  7547. 0, // AKEYCODE_FOCUS
  7548. 0, // AKEYCODE_PLUS
  7549. 0, // AKEYCODE_MENU
  7550. 0, // AKEYCODE_NOTIFICATION
  7551. 0, // AKEYCODE_SEARCH
  7552. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7553. 0, // AKEYCODE_MEDIA_STOP
  7554. 0, // AKEYCODE_MEDIA_NEXT
  7555. 0, // AKEYCODE_MEDIA_PREVIOUS
  7556. 0, // AKEYCODE_MEDIA_REWIND
  7557. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7558. 0, // AKEYCODE_MUTE
  7559. 0, // AKEYCODE_PAGE_UP
  7560. 0, // AKEYCODE_PAGE_DOWN
  7561. 0, // AKEYCODE_PICTSYMBOLS
  7562. 0, // AKEYCODE_SWITCH_CHARSET
  7563. 0, // AKEYCODE_BUTTON_A
  7564. 0, // AKEYCODE_BUTTON_B
  7565. 0, // AKEYCODE_BUTTON_C
  7566. 0, // AKEYCODE_BUTTON_X
  7567. 0, // AKEYCODE_BUTTON_Y
  7568. 0, // AKEYCODE_BUTTON_Z
  7569. 0, // AKEYCODE_BUTTON_L1
  7570. 0, // AKEYCODE_BUTTON_R1
  7571. 0, // AKEYCODE_BUTTON_L2
  7572. 0, // AKEYCODE_BUTTON_R2
  7573. 0, // AKEYCODE_BUTTON_THUMBL
  7574. 0, // AKEYCODE_BUTTON_THUMBR
  7575. 0, // AKEYCODE_BUTTON_START
  7576. 0, // AKEYCODE_BUTTON_SELECT
  7577. 0, // AKEYCODE_BUTTON_MODE
  7578. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7579. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7580. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7581. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7582. 0, // AKEYCODE_CAPS_LOCK
  7583. 0, // AKEYCODE_SCROLL_LOCK
  7584. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7585. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7586. 0, // AKEYCODE_FUNCTION
  7587. 0, // AKEYCODE_SYSRQ
  7588. 0, // AKEYCODE_BREAK
  7589. 0, // AKEYCODE_MOVE_HOME
  7590. 0, // AKEYCODE_MOVE_END
  7591. 0, // AKEYCODE_INSERT
  7592. 0, // AKEYCODE_FORWARD
  7593. 0, // AKEYCODE_MEDIA_PLAY
  7594. 0, // AKEYCODE_MEDIA_PAUSE
  7595. 0, // AKEYCODE_MEDIA_CLOSE
  7596. 0, // AKEYCODE_MEDIA_EJECT
  7597. 0, // AKEYCODE_MEDIA_RECORD
  7598. LA_KEY_F1, // AKEYCODE_F1
  7599. LA_KEY_F2, // AKEYCODE_F2
  7600. LA_KEY_F3, // AKEYCODE_F3
  7601. LA_KEY_F4, // AKEYCODE_F4
  7602. LA_KEY_F5, // AKEYCODE_F5
  7603. LA_KEY_F6, // AKEYCODE_F6
  7604. LA_KEY_F7, // AKEYCODE_F7
  7605. LA_KEY_F8, // AKEYCODE_F8
  7606. LA_KEY_F9, // AKEYCODE_F9
  7607. LA_KEY_F10, // AKEYCODE_F10
  7608. LA_KEY_F11, // AKEYCODE_F11
  7609. LA_KEY_F12, // AKEYCODE_F12
  7610. 0, // AKEYCODE_NUM_LOCK
  7611. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7612. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7613. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7614. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7615. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7616. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7617. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7618. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7619. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7620. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7621. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7622. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7623. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7624. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7625. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7626. 0, // AKEYCODE_NUMPAD_COMMA
  7627. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7628. '=' // AKEYCODE_NUMPAD_EQUALS
  7629. };
  7630. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7631. {
  7632. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7633. if(!MAIN.AppEnabled){return 0;}
  7634. //laRedrawAllWindows();
  7635. static int prev_button_state=0;
  7636. int type = AInputEvent_getType(event);
  7637. if(type == AINPUT_EVENT_TYPE_KEY){
  7638. int32_t keycode = AKeyEvent_getKeyCode(event);
  7639. //int32_t AKeyEvent_getMetaState(event);
  7640. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7641. if (key != 0){
  7642. // Save current key and its state
  7643. // NOTE: Android key action is 0 for down and 1 for up
  7644. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7645. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7646. if(key!=LA_KEY_BACKSPACE)
  7647. la_SendInputEvent(0,key);
  7648. }
  7649. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7650. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7651. la_SendInputEvent(0,key);
  7652. }
  7653. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7654. }
  7655. if (keycode == AKEYCODE_POWER)
  7656. {
  7657. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7658. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7659. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7660. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7661. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7662. return 0;
  7663. }
  7664. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7665. {
  7666. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7667. return 1;
  7668. }
  7669. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7670. {
  7671. // Set default OS behaviour
  7672. return 0;
  7673. }
  7674. return 0;
  7675. }
  7676. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7677. static real zoom_offset=1; static real temp_distance=0;
  7678. real zoom; int gesture_handled=0;
  7679. int pcount = AMotionEvent_getPointerCount(event); int x,y; static real cx=0,cy=0;
  7680. int32_t action = AMotionEvent_getAction(event);
  7681. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7682. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7683. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7684. if(pcount){
  7685. x=rx; y=ry;
  7686. int tool_type=AMotionEvent_getToolType(event,0);
  7687. real pressure = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_PRESSURE,0);
  7688. if(tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS || tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER){
  7689. MAIN.StylusPressure = MAIN.EraserPressure = pressure; MAIN.IsPen = 1;
  7690. MAIN.PointerIsEraser = (tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER);
  7691. }else{
  7692. MAIN.IsPen = 0;
  7693. }
  7694. if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
  7695. && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
  7696. real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
  7697. real ctx=(x+x2)/2, cty=(y+y2)/2;
  7698. real distance = tnsDistIdv2(x2,y2,rx,ry);
  7699. if(temp_distance){ zoom_offset*=(distance/temp_distance); }
  7700. temp_distance = distance;
  7701. while(zoom_offset > 1.1){ zoom_offset-=0.1;
  7702. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7703. la_SendMouseEvent(0, LA_MOUSEUP|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7704. }
  7705. while(zoom_offset < (1.0/1.1)){ zoom_offset+=(0.1/1.1);
  7706. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7707. la_SendMouseEvent(0, LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7708. }
  7709. if(cx || cy){
  7710. if(!gesture_handled){
  7711. real dist = tnsDistIdv2(ctx,cty,cx,cy);
  7712. while(dist > LA_RH){
  7713. int udlr = fabs(cty-cy) > fabs(ctx-cx);
  7714. int direction = udlr?(cty>cy?LA_KEY_ARRUP:LA_KEY_ARRDOWN):
  7715. (ctx>cx?LA_KEY_ARRLEFT:LA_KEY_ARRRIGHT);
  7716. real fac = (real)(LA_RH)/dist;
  7717. cx=tnsLinearItp(cx,ctx,fac); cy=tnsLinearItp(cy,cty,fac);
  7718. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7719. la_SendKeyboardEvent(0, LA_KEY_DOWN, direction|LA_KEYBOARD_EVENT|LA_KEY_PANNING);
  7720. gesture_handled=1;
  7721. dist = tnsDistIdv2(ctx,cty,cx,cy);
  7722. }
  7723. }
  7724. }else{
  7725. cx=ctx; cy=cty;
  7726. }
  7727. }else{
  7728. temp_distance = 0; cx=0; cy=0;
  7729. }
  7730. if(flags==AMOTION_EVENT_ACTION_HOVER_MOVE){
  7731. la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
  7732. }
  7733. }
  7734. if(!gesture_handled){
  7735. if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_BUTTON_PRESS){
  7736. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7737. int btn=AMotionEvent_getButtonState(event);
  7738. int evtype=LA_L_MOUSE_DOWN;
  7739. if(btn & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_DOWN; }
  7740. elif(btn & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_DOWN; }
  7741. la_SendMouseEvent(0,evtype,x,y);
  7742. prev_button_state = btn;
  7743. }
  7744. else if (flags == AMOTION_EVENT_ACTION_UP || flags == AMOTION_EVENT_ACTION_BUTTON_RELEASE){
  7745. int btn=AMotionEvent_getButtonState(event); int changed = (~btn)&prev_button_state;
  7746. int evtype=LA_L_MOUSE_UP;
  7747. if(changed & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_UP; }
  7748. elif(changed & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_UP; }
  7749. la_SendMouseEvent(0,evtype,x,y);
  7750. }
  7751. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7752. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7753. }
  7754. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7755. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7756. }
  7757. }
  7758. }
  7759. //static float r=0;
  7760. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7761. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7762. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7763. //glClear(GL_COLOR_BUFFER_BIT);
  7764. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7765. return 0;
  7766. }
  7767. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7768. MAIN.AssetManager = manager;
  7769. MAIN.InternalDataPath = dataPath;
  7770. MAIN.ExternalDataPath = externalDataPath;
  7771. }
  7772. static int android_read(void *cookie, char *data, int dataSize){
  7773. return AAsset_read((AAsset *)cookie, data, dataSize);
  7774. }
  7775. static int android_write(void *cookie, const char *data, int dataSize){
  7776. return 0;
  7777. }
  7778. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7779. return AAsset_seek((AAsset *)cookie, offset, whence);
  7780. }
  7781. static int android_close(void *cookie){
  7782. AAsset_close((AAsset *)cookie);
  7783. return 0;
  7784. }
  7785. // Replacement for fopen()
  7786. // Ref: https://developer.android.com/ndk/reference/group/asset
  7787. FILE *android_fopen(const char *fileName, const char *mode)
  7788. {
  7789. char buf[1024];
  7790. if (mode[0] == 'w')
  7791. {
  7792. // fopen() is mapped to android_fopen() that only grants read access to
  7793. // assets directory through AAssetManager but we want to also be able to
  7794. // write data when required using the standard stdio FILE access functions
  7795. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7796. #undef fopen
  7797. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7798. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7799. result=fopen(buf, mode); if(result) return result;
  7800. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7801. return fopen(buf, mode);
  7802. #define fopen(name, mode) android_fopen(name, mode)
  7803. }
  7804. else
  7805. {
  7806. // NOTE: AAsset provides access to read-only asset
  7807. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7808. if (asset != NULL)
  7809. {
  7810. // Get pointer to file in the assets
  7811. return funopen(asset, android_read, android_write, android_seek, android_close);
  7812. }
  7813. else
  7814. {
  7815. #undef fopen
  7816. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7817. // Just do a regular open if file is not found in the assets
  7818. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7819. result=fopen(buf, mode); if(result){ return result; }
  7820. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7821. return fopen(buf, mode);
  7822. #define fopen(name, mode) android_fopen(name, mode)
  7823. }
  7824. }
  7825. }
  7826. void la_HideNavBar(){
  7827. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7828. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7829. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7830. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7831. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7832. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7833. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7834. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7835. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7836. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7837. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7838. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7839. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7840. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7841. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7842. int flag = flagFullscreen | flagHideNavigation;
  7843. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7844. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7845. }
  7846. void la_InitAndroidPlatform(struct android_app *app){
  7847. MAIN.app=app;
  7848. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7849. //la_HideNavBar();
  7850. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7851. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7852. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7853. int pollResult = 0;
  7854. int pollEvents = 0;
  7855. while (!MAIN.AppReady){
  7856. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7857. // Process this event
  7858. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7859. // NOTE: Never close window, native activity is controlled by the system!
  7860. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7861. }
  7862. }
  7863. }
  7864. int main(int, char *[]);
  7865. void android_main(struct android_app *app){
  7866. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7867. la_InitAndroidPlatform(app);
  7868. // NOTE: Return from main is ignored
  7869. (void)main(1, (char *[]) { arg0, NULL });
  7870. // Request to end the native activity
  7871. ANativeActivity_finish(app->activity);
  7872. // Android ALooper_pollAll() variables
  7873. int pollResult = 0;
  7874. int pollEvents = 0;
  7875. // Waiting for application events before complete finishing
  7876. while (!app->destroyRequested)
  7877. {
  7878. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7879. {
  7880. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7881. }
  7882. }
  7883. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "Application successfully ended.\n");
  7884. /* Unloads the native dynamic library so we can get clean restarts. */
  7885. exit(0);
  7886. }
  7887. void la_DisplayKeyboard(bool pShow) {
  7888. // Attaches the current thread to the JVM.
  7889. jint lResult;
  7890. jint lFlags = 0;
  7891. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7892. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7893. JavaVMAttachArgs lJavaVMAttachArgs;
  7894. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7895. lJavaVMAttachArgs.name = "NativeThread";
  7896. lJavaVMAttachArgs.group = NULL;
  7897. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7898. if (lResult == JNI_ERR) {
  7899. return;
  7900. }
  7901. // Retrieves NativeActivity.
  7902. jobject lNativeActivity = MAIN.app->activity->clazz;
  7903. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7904. logPrintNew("jvm3");
  7905. // Retrieves Context.INPUT_METHOD_SERVICE.
  7906. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7907. jfieldID FieldINPUT_METHOD_SERVICE =
  7908. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7909. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7910. jobject INPUT_METHOD_SERVICE =
  7911. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7912. FieldINPUT_METHOD_SERVICE);
  7913. //jniCheck(INPUT_METHOD_SERVICE);
  7914. logPrintNew("jvm4");
  7915. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7916. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7917. "android/view/inputmethod/InputMethodManager");
  7918. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7919. ClassNativeActivity, "getSystemService",
  7920. "(Ljava/lang/String;)Ljava/lang/Object;");
  7921. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7922. lNativeActivity, MethodGetSystemService,
  7923. INPUT_METHOD_SERVICE);
  7924. // Runs getWindow().getDecorView().
  7925. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7926. ClassNativeActivity, "getWindow",
  7927. "()Landroid/view/Window;");
  7928. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7929. MethodGetWindow);
  7930. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7931. "android/view/Window");
  7932. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7933. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7934. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7935. MethodGetDecorView);
  7936. if (pShow) {
  7937. // Runs lInputMethodManager.showSoftInput(...).
  7938. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7939. ClassInputMethodManager, "showSoftInput",
  7940. "(Landroid/view/View;I)Z");
  7941. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7942. lInputMethodManager, MethodShowSoftInput,
  7943. lDecorView, lFlags);
  7944. } else {
  7945. // Runs lWindow.getViewToken()
  7946. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7947. "android/view/View");
  7948. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7949. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7950. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7951. MethodGetWindowToken);
  7952. // lInputMethodManager.hideSoftInput(...).
  7953. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7954. ClassInputMethodManager, "hideSoftInputFromWindow",
  7955. "(Landroid/os/IBinder;I)Z");
  7956. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7957. lInputMethodManager, MethodHideSoftInput,
  7958. lBinder, lFlags);
  7959. }
  7960. // Finished with the JVM.
  7961. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7962. }
  7963. bool la_check_permission(const char* permission) {
  7964. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7965. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7966. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7967. jobject lNativeActivity = MAIN.app->activity->clazz;
  7968. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7969. jmethodID activity_checkSelfPermission = (*lJNIEnv)->GetMethodID(lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  7970. jstring jobj_permission = (*lJNIEnv)->NewStringUTF(lJNIEnv,permission);
  7971. jint result = (*lJNIEnv)->CallIntMethod(lJNIEnv,ClassNativeActivity, activity_checkSelfPermission, jobj_permission);
  7972. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  7973. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7974. return result == 0;
  7975. }
  7976. void la_request_permission(const char* permission) {
  7977. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7978. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7979. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7980. jobject lNativeActivity = MAIN.app->activity->clazz;
  7981. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7982. jmethodID contextCompat_checkSelfPermission = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  7983. jmethodID activity_requestPermissions = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "requestPermissions", "([Ljava/lang/String;I)V");
  7984. jstring jobj_permission = (*lJNIEnv)->NewStringUTF (lJNIEnv,permission);
  7985. jobjectArray jobj_permission_list = (*lJNIEnv)->NewObjectArray(lJNIEnv,1, (*lJNIEnv)->FindClass(lJNIEnv,"java/lang/String"), NULL);
  7986. (*lJNIEnv)->SetObjectArrayElement(lJNIEnv,jobj_permission_list, 0, jobj_permission);
  7987. (*lJNIEnv)->CallVoidMethod (lJNIEnv,lNativeActivity, activity_requestPermissions, jobj_permission_list, 0);
  7988. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  7989. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission_list);
  7990. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7991. }
  7992. #endif //android
  7993. #ifndef LAGUI_ANDROID
  7994. void la_DisplayKeyboard(bool pShow) {
  7995. return;
  7996. }
  7997. void la_HideNavBar(){
  7998. return;
  7999. }
  8000. #endif