*/}}

la_kernel.c 237 KB

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