*/}}
1
0

la_kernel.c 234 KB

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