*/}}
1
0

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