*/}}
1
0

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