*/}}

la_kernel.c 276 KB

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