*/}}

la_kernel.c 235 KB

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