*/}}

la_kernel.c 267 KB

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