*/}}

la_kernel.c 301 KB

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