*/}}

la_kernel.c 277 KB

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