*/}}
1
0

la_kernel.c 277 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501
  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){
  2823. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  2824. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->UiDefine) def = This->LastPs->p->SubProp->UiDefine;
  2825. }
  2826. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  2827. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  2828. }
  2829. GX = L; GY = B;
  2830. GW = (R - L) > MaxW ? MaxW : (R - L);
  2831. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  2832. laEnclosePanelContent(p, &p->UI);
  2833. laSetOperatorLocalizer(p);
  2834. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2835. laShowPanelWithDropDownEffect(p);
  2836. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  2837. if(Attachment){
  2838. p->Parent = Attachment;
  2839. lstAppendItem(&Attachment->SubPanels, p);
  2840. }
  2841. return p;
  2842. }
  2843. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  2844. laPanel *p;
  2845. int t = 0;
  2846. int b;
  2847. //laLocalToWindow(0, Attachment, &L, &t);
  2848. //laLocalToWindow(0, Attachment, &R, &U);
  2849. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  2850. laSetOperatorLocalizer(p);
  2851. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2852. laShowPanelWithDropDownEffect(p);
  2853. p->Parent = Attachment;
  2854. lstPushItem(&Attachment->SubPanels, p);
  2855. return p;
  2856. }
  2857. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  2858. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2859. laOperator *ai = a;
  2860. laPanel *p;
  2861. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2862. int GX, GY, GW, t = 0;
  2863. int b;
  2864. int MinW;
  2865. //laLocalToWindow(0,Attachment, &L, &t);
  2866. //laLocalToWindow(0,Attachment, &R, &B);
  2867. GX = L;
  2868. GY = B;
  2869. GW = (R - L) > MaxW ? MaxW : (R - L);
  2870. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2871. p->MenuRefer = MenuRefer;
  2872. laEnclosePanelContent(p, MenuRefer);
  2873. laSetOperatorLocalizer(p);
  2874. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2875. laShowPanelWithDropDownEffect(p);
  2876. p->Parent = Attachment;
  2877. lstPushItem(&Attachment->SubPanels, p);
  2878. return p;
  2879. }
  2880. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  2881. int L, int B, int MaxGH, int MaxW, laEvent *e){
  2882. laOperator *ai = a;
  2883. laPanel *p;
  2884. int GX, GY, GW, t = 0;
  2885. int b;
  2886. GX = L;
  2887. GY = B;
  2888. GW = MaxW;
  2889. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2890. p->MenuRefer = &p->UI;
  2891. p->Mode = LA_PANEL_NO_PARENT_MENU;
  2892. laSetOperatorLocalizer(p);
  2893. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2894. laShowPanelWithDropDownEffect(p);
  2895. if (Attachment){
  2896. p->Parent = Attachment;
  2897. lstPushItem(&Attachment->SubPanels, p);
  2898. }else{
  2899. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2900. }
  2901. return p;
  2902. }
  2903. 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){
  2904. laOperator *ai = For;
  2905. laPanel *p;
  2906. int b;
  2907. laUiDefineFunc def = 0;
  2908. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  2909. else def = laui_DefaultPropUiDefine;
  2910. For->PP.EndInstance = For->CustomData;
  2911. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  2912. laEnclosePanelContent(p, &p->UI);
  2913. MAIN.ToPanel = p;
  2914. laShowPanelWithExpandEffect(p);
  2915. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2916. ai->OperatorPanel = p;
  2917. p->ParentOperator = For;
  2918. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  2919. return p;
  2920. }
  2921. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2922. laPanel *p; int b; laUiList *uil; laColumn* col;
  2923. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  2924. strSafeSet(&p->Title, Title);
  2925. p->BoundUi = 1;
  2926. p->Mode = LA_PANEL_FLOATING_TOP;
  2927. p->BT = &_LA_THEME_FLOATING_PANEL;
  2928. MAIN.ToPanel = p;
  2929. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2930. uil = laPrepareUi(p); col = laFirstColumn(uil);
  2931. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  2932. laUiItem* r=laBeginRow(uil,col,0,0);
  2933. laShowSeparator(uil,col)->Expand=1;
  2934. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  2935. laEndRow(uil,r);
  2936. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  2937. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2938. laSetOperatorLocalizer(p);
  2939. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2940. return p;
  2941. }
  2942. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2943. laPanel *p; int b; laUiList *uil; laColumn* col;
  2944. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  2945. strSafeSet(&p->Title, Title);
  2946. p->BoundUi = 1;
  2947. p->Mode = LA_PANEL_FLOATING_TOP;
  2948. p->BT = &_LA_THEME_FLOATING_PANEL;
  2949. MAIN.ToPanel = p;
  2950. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2951. uil = laPrepareUi(p); col = laFirstColumn(uil);
  2952. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  2953. laUiItem* r = laBeginRow(uil,col,0,0);
  2954. laShowSeparator(uil,col)->Expand=1;
  2955. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  2956. laEndRow(uil, r);
  2957. laEnclosePanelContent(p,uil);
  2958. laShowPanelWithExpandEffect(p);
  2959. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2960. laSetOperatorLocalizer(p);
  2961. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2962. return p;
  2963. }
  2964. void laDeferredRedraw(laPanel* p){
  2965. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  2966. if(lip->p==p) return;
  2967. }
  2968. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  2969. }
  2970. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2971. laWindow* cur=MAIN.CurrentWindow;
  2972. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  2973. MAIN.CurrentWindow=w;
  2974. la_UpdateUiPlacement(w);
  2975. }
  2976. MAIN.CurrentWindow=cur;
  2977. }
  2978. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2979. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  2980. }
  2981. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  2982. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  2983. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  2984. void laRedrawCurrentPanel(){
  2985. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  2986. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2987. }
  2988. void laRecalcCurrentPanel(){
  2989. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  2990. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2991. }
  2992. void laRecalcPanelImmediate(laPanel* p){
  2993. p->FrameDistinguish++;
  2994. laBoxedTheme* bt = (*p->BT);
  2995. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  2996. la_PanelRefreshDetachedProp(p);
  2997. int enclosed=0;
  2998. if(p->BoundUi || p->MenuRefer){
  2999. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3000. else enclosed=laEnclosePanelContent(p, &p->UI);
  3001. }
  3002. if(!enclosed){
  3003. la_PanelValidateWidth(p,&p->UI);
  3004. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3005. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3006. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3007. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3008. }
  3009. laWindow* w=MAIN.CurrentWindow;
  3010. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3011. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3012. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3013. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3014. }
  3015. }
  3016. void laRecalcCurrentPanelImmediate(){
  3017. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3018. }
  3019. int laNonFixedPanelExists(laPanel *p){
  3020. laPanel *ip;
  3021. if (!p) return 0;
  3022. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3023. // if (ip == p) return 1;
  3024. //}
  3025. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3026. if (ip == p) return 1;
  3027. }
  3028. return 0;
  3029. }
  3030. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3031. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3032. return 1;
  3033. }
  3034. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3035. int tt=MAIN.TooltipCloseDistance;
  3036. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3037. return 1;
  3038. }
  3039. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3040. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3041. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3042. return 0;
  3043. return 1;
  3044. }
  3045. void laUnlinkSharedPanel(laPanel *p){
  3046. laWindow *w;
  3047. laPanel *ip;
  3048. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3049. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3050. if (ip == p){
  3051. lstRemoveItem(&w->Panels, ip);
  3052. return;
  3053. }
  3054. }
  3055. }
  3056. }
  3057. int laIsPanelCovered(laPanel *p){
  3058. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3059. laPanel *ip;
  3060. laPanel *resp;
  3061. int in1 = 0, in2 = 0, in3 = 0;
  3062. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3063. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3064. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3065. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3066. //}
  3067. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3068. if (ip == p){
  3069. in3 = 1;
  3070. d3 = 0;
  3071. continue;
  3072. }
  3073. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3074. }
  3075. if (!in2 && !in3) in1 = 1;
  3076. if (in1){
  3077. if (d1 || d2 || d3) return 1;
  3078. }else{
  3079. if (in2){
  3080. if (d2 || d3) return 1;
  3081. }else if (in3)
  3082. if (d3) return 1;
  3083. }
  3084. return 0;
  3085. }
  3086. int laIsTopPanel(laPanel *p){
  3087. //if (!p->Item.pPrev) return 1;
  3088. //else {
  3089. if (!laIsPanelCovered(p)){
  3090. //laPopPanel(p);
  3091. return 1;
  3092. }
  3093. return 0;
  3094. //}
  3095. return 0;
  3096. }
  3097. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3098. if(!p) return;
  3099. int ix = *x, iy = *y;
  3100. laListItemPointer *lip;
  3101. laOperator *ai = a;
  3102. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3103. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3104. if (a){
  3105. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3106. laUiList *uil = lip->p;
  3107. (*x) += uil->PanX;
  3108. (*y) += uil->PanY;
  3109. }
  3110. }
  3111. }
  3112. void laPanelToLocal(laOperator *a, int *x, int *y){
  3113. int ix = *x, iy = *y;
  3114. laListItemPointer *lip;
  3115. if (a){
  3116. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3117. laUiList *uil = lip->p;
  3118. (*x) += uil->PanX;
  3119. (*y) += uil->PanY;
  3120. }
  3121. }
  3122. }
  3123. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3124. if(!p) return;
  3125. int ix = *x, iy = *y;
  3126. laListItemPointer *lip;
  3127. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3128. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3129. if (a){
  3130. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3131. laUiList *uil = lip->p;
  3132. (*x) -= uil->PanX;
  3133. (*y) -= uil->PanY;
  3134. }
  3135. }
  3136. }
  3137. void laPanelToWindow(laPanel *p, int *x, int *y){
  3138. int ix = *x, iy = *y;
  3139. laListItemPointer *lip;
  3140. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3141. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3142. }
  3143. void laLocalToPanel(laOperator *a, int *x, int *y){
  3144. int ix = *x, iy = *y;
  3145. laListItemPointer *lip;
  3146. if (a){
  3147. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3148. laUiList *uil = lip->p;
  3149. (*x) -= uil->PanX;
  3150. (*y) -= uil->PanY;
  3151. }
  3152. }
  3153. }
  3154. void laSetNextMenuPos(int X, int Y, int W, int H){
  3155. MAIN.NextX = X;
  3156. MAIN.NextY = Y;
  3157. MAIN.NextW = W;
  3158. MAIN.NextH = H;
  3159. }
  3160. int laIsInBlock(laBlock *b, int X, int Y){
  3161. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3162. return 0;
  3163. }
  3164. 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; }
  3165. 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; }
  3166. 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; }
  3167. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3168. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3169. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3170. if (!b->B1 && !b->B2){
  3171. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3172. }
  3173. }
  3174. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3175. laPanel *p;
  3176. laBlock *sb = 0;
  3177. if (!laIsInBlock(b, X, Y)) return 0;
  3178. if (!b->B1 && !b->B2) return b;
  3179. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3180. return laDetectBlockRecursive(b->B2, X, Y);
  3181. }
  3182. laPanel *laDetectPanel(int X, int Y){
  3183. laPanel *p; laBlock *b;
  3184. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3185. int x = X, y = Y;
  3186. laWindowToLocal(0, p, &x, &y);
  3187. if (p->Show && laIsInPanel(p, x, y)){
  3188. return p;
  3189. }
  3190. }
  3191. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3192. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3193. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3194. return 0;
  3195. }
  3196. laUiList *laPrepareUi(laPanel *p){
  3197. return &p->UI;
  3198. }
  3199. laColumn *laFirstColumn(laUiList *uil){
  3200. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3201. else{
  3202. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3203. c->SP = 1;
  3204. c->PreWidth = 1;
  3205. lstAppendItem(&uil->Columns, c);
  3206. c->Top = c;
  3207. return uil->Columns.pFirst;
  3208. }
  3209. }
  3210. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3211. laColumn *lc, *rc;
  3212. if (c->LS || c->RS) return c;
  3213. lc = memAcquireSimple(sizeof(laColumn));
  3214. rc = memAcquireSimple(sizeof(laColumn));
  3215. c->LS = lc;
  3216. c->RS = rc;
  3217. c->LS->SP = Percent;
  3218. c->RS->SP = Percent;
  3219. c->LS->Top = c->Top;
  3220. c->RS->Top = c->Top;
  3221. if (uil){
  3222. lstAppendItem(&uil->Columns, lc);
  3223. lstAppendItem(&uil->Columns, rc);
  3224. }
  3225. if (c->LS && c->RS->MaxW == 0){
  3226. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3227. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3228. }else if (c->RS && c->LS->MaxW == 0){
  3229. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3230. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3231. }
  3232. return c;
  3233. }
  3234. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3235. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3236. return c->LS;
  3237. }
  3238. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3239. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3240. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3241. return c->RS;
  3242. }
  3243. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3244. lstRemoveItem(List, c);
  3245. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3246. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3247. memFree(c);
  3248. }
  3249. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3250. laUiList *uil = TopUil;
  3251. laUiList *sub;
  3252. laUiItem *ui;
  3253. laColumn *cc, *NextCC = 0;
  3254. int Occupied = 0;
  3255. int Removed = 0;
  3256. if (!c->LS) return 0;
  3257. else{
  3258. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3259. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3260. }
  3261. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3262. if (ui->C == c->LS || ui->C == c->RS){
  3263. if (DoMerge){
  3264. ui->C = c;
  3265. Occupied = 1;
  3266. }else
  3267. return 1;
  3268. }
  3269. if (ui->Subs.pFirst){
  3270. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3271. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3272. }
  3273. }
  3274. }
  3275. if (!Removed){
  3276. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3277. if (cc == c){
  3278. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3279. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3280. c->LS = 0;
  3281. c->RS = 0;
  3282. Removed = 1;
  3283. break;
  3284. }
  3285. }
  3286. }
  3287. return Occupied;
  3288. }
  3289. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3290. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3291. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3292. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3293. ut->FakeProp->Base.Identifier = ut->Identifier;
  3294. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3295. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3296. ut->FakeProp->Base.OffsetIsPointer = 1;
  3297. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3298. return ut->ExtraProps;
  3299. }
  3300. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3301. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3302. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3303. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3304. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3305. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3306. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3307. ct->FakeProp->Base.OffsetIsPointer = 1;
  3308. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3309. return ct->ExtraProps;
  3310. }
  3311. void la_DestroyUiType(laUiType* uit){
  3312. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3313. memFree(uit);
  3314. }
  3315. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3316. laUiType *ut = memAcquire(sizeof(laUiType));
  3317. ut->Identifier = Identifer;
  3318. ut->OperatorID = UseOperator;
  3319. ut->Draw = Draw;
  3320. ut->Theme = bt;
  3321. ut->ForType = ForType;
  3322. ut->OperatorType = laGetOperatorType(UseOperator);
  3323. ut->GetHeight = GetHeight;
  3324. ut->Init = Init;
  3325. ut->Destroy = Destroy;
  3326. la_UDFAppendSharedTypePointer(Identifer, ut);
  3327. lstAppendItem(&MAIN.UiTypes, ut);
  3328. return ut;
  3329. }
  3330. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3331. laUiType *ut = MAIN.UiTypes.pFirst;
  3332. if (!P) return 0;
  3333. if (P->DefaultUiType) return P->DefaultUiType;
  3334. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3335. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3336. for (ut; ut; ut = ut->Item.pNext){
  3337. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3338. return ut;
  3339. }
  3340. }
  3341. return 0;
  3342. }
  3343. laUiType *la_GetUiButtonType(){
  3344. laUiType *ut = MAIN.UiTypes.pFirst;
  3345. for (ut; ut; ut = ut->Item.pNext){
  3346. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3347. }
  3348. return 0;
  3349. }
  3350. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3351. laCanvasTemplate *vdt;
  3352. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3353. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3354. }
  3355. return 0;
  3356. }
  3357. void la_AssignPropExtras(laUiItem* ui){
  3358. if(!ui->Type || !ui->Type->FakeProp) return;
  3359. ui->FakePs.p = ui->Type->FakeProp;
  3360. ui->FakePs.Type = U'.';
  3361. ui->FakePs.UseInstance = ui;
  3362. ui->ExtraPP.LastPs = &ui->FakePs;
  3363. }
  3364. void la_AssignCanvasPropExtras(laUiItem* ui){
  3365. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3366. laCanvasTemplate*ct=ui->CanvasTemplate;
  3367. ui->FakePs.p = ct->FakeProp;
  3368. ui->FakePs.Type = U'.';
  3369. ui->FakePs.UseInstance = ui;
  3370. ui->ExtraPP.EndInstance = ui->Extra;
  3371. ui->ExtraPP.LastPs = &ui->FakePs;
  3372. }
  3373. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3374. int result;
  3375. if (!ui) return 0;
  3376. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3377. if (Path){
  3378. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3379. if (!result){
  3380. ui->AT = laGetOperatorType(Path);
  3381. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3382. ui->Type = la_GetUiButtonType();
  3383. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3384. }else{
  3385. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3386. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3387. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3388. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3389. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3390. }
  3391. if (Base){
  3392. ui->PP.RawThis = Base;
  3393. }
  3394. }else if (Base){
  3395. ui->PP.LastPs = Base->LastPs;
  3396. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3397. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3398. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3399. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3400. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3401. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3402. }
  3403. la_AssignPropExtras(ui);
  3404. if(Widget){ ui->Flags|= Widget->Flags; }
  3405. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3406. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3407. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3408. return ui;
  3409. }
  3410. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3411. ui->Type = _LA_UI_LABEL;
  3412. ui->Template = Template;
  3413. ui->State = LA_UI_NORMAL;
  3414. strSafeSet(&ui->Display, Content);
  3415. la_AssignPropExtras(ui);
  3416. return ui;
  3417. }
  3418. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3419. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3420. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3421. ui->State = LA_UI_NORMAL;
  3422. la_AssignPropExtras(ui);
  3423. return ui;
  3424. }
  3425. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3426. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3427. transLate(Content);
  3428. la_UpdateLabelDisplay(ui, Template, Content);
  3429. ui->C = c;
  3430. if (ui->Type->Init) ui->Type->Init(ui);
  3431. ui->ExtraPP.EndInstance = ui->Extra;
  3432. lstAppendItem(&uil->UiItems, ui);
  3433. return ui;
  3434. }
  3435. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3436. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3437. la_UpdateLabelDisplay(ui, Template, Content);
  3438. ui->C = c;
  3439. if (ui->Type->Init) ui->Type->Init(ui);
  3440. ui->ExtraPP.EndInstance = ui->Extra;
  3441. lstAppendItem(&uil->UiItems, ui);
  3442. return ui;
  3443. }
  3444. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3445. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3446. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3447. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3448. ui->C = c;
  3449. if (ui->Type->Init) ui->Type->Init(ui);
  3450. ui->ExtraPP.EndInstance = ui->Extra;
  3451. lstAppendItem(&uil->UiItems, ui);
  3452. return ui;
  3453. }
  3454. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3455. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  3456. }
  3457. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3458. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  3459. }
  3460. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  3461. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3462. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  3463. ui->C = c;
  3464. ui->TemplateContext = TemplateContext;
  3465. if (ui->Type->Init) ui->Type->Init(ui);
  3466. ui->ExtraPP.EndInstance = ui->Extra;
  3467. lstAppendItem(&uil->UiItems, ui);
  3468. return ui;
  3469. }
  3470. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  3471. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3472. ui->C = c; ui->Extra=Image;
  3473. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  3474. ui->SymbolID=Height;
  3475. lstAppendItem(&uil->UiItems, ui);
  3476. return ui;
  3477. }
  3478. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3479. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  3480. }
  3481. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3482. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  3483. }
  3484. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  3485. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3486. ui->Type = _LA_UI_CANVAS;
  3487. ui->State = LA_UI_NORMAL;
  3488. ui->C = c;
  3489. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3490. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  3491. else{
  3492. 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); }
  3493. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  3494. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  3495. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  3496. }
  3497. if (ui->Type->Init) ui->Type->Init(ui);
  3498. la_AssignCanvasPropExtras(ui);
  3499. if (Height) ui->Expand=Height; else ui->Expand=6;
  3500. lstAppendItem(&uil->UiItems, ui);
  3501. return ui;
  3502. }
  3503. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  3504. laUiItem* ui=0;
  3505. #define ADD_CANVAS \
  3506. laUiItem* b=laBeginRow(uil,cr,0,0);\
  3507. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  3508. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  3509. }laEndCondition(uil,b3);\
  3510. laEndRow(uil,b);
  3511. if(Detached){
  3512. laColumn* cl,*cll,*clr,*cr;
  3513. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  3514. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  3515. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  3516. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  3517. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  3518. ADD_CANVAS
  3519. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  3520. }laElse(uil,b2);{
  3521. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  3522. ADD_CANVAS
  3523. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  3524. }laEndCondition(uil,b2);
  3525. }else{
  3526. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  3527. }
  3528. #undef ADD_CANVAS
  3529. }
  3530. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  3531. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3532. laCanvasExtra *e;
  3533. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  3534. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  3535. ui->C = c;
  3536. if (ui->Type->Init) ui->Type->Init(ui);
  3537. ui->ExtraPP.EndInstance = ui->Extra;
  3538. lstAppendItem(&uil->UiItems, ui);
  3539. return ui;
  3540. }
  3541. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  3542. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3543. ui->Type = _LA_UI_SYMBOL;
  3544. ui->SymbolID = SymbolID;
  3545. if (Height) ui->State = Height;
  3546. ui->C = c;
  3547. if (ui->Type->Init) ui->Type->Init(ui);
  3548. ui->ExtraPP.EndInstance = ui->Extra;
  3549. lstAppendItem(&uil->UiItems, ui);
  3550. return ui;
  3551. }
  3552. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  3553. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3554. ui->Type = &_LA_UI_ROW_BEGIN;
  3555. ui->State=Expand;
  3556. ui->Flags=Even;
  3557. ui->C = c;
  3558. if (ui->Type->Init) ui->Type->Init(ui);
  3559. ui->ExtraPP.EndInstance = ui->Extra;
  3560. lstAppendItem(&uil->UiItems, ui);
  3561. return ui;
  3562. }
  3563. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  3564. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3565. ui->Type = &_LA_UI_ROW_END;
  3566. ui->C = Begin->C;
  3567. ui->Page = (laUiList*)Begin;
  3568. if (ui->Type->Init) ui->Type->Init(ui);
  3569. ui->ExtraPP.EndInstance = ui->Extra;
  3570. lstAppendItem(&uil->UiItems, ui);
  3571. return ui;
  3572. }
  3573. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  3574. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  3575. e->Expression = Expression;
  3576. ui->Extra = e;
  3577. la_AssignPropExtras(ui);
  3578. }
  3579. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3580. laUiItem *ui = la_CreateGroupHandle(Widget);
  3581. laUiList *nuil;
  3582. ui->C = c;
  3583. lstAppendItem(&uil->UiItems, ui);
  3584. nuil = memAcquireSimple(sizeof(laUiList));
  3585. strSafeSet(&nuil->TabName, Name);
  3586. ui->Page = nuil;
  3587. lstAppendItem(&ui->Subs, nuil);
  3588. if (ui->Type->Init) ui->Type->Init(ui);
  3589. ui->ExtraPP.EndInstance = ui->Extra;
  3590. return ui;
  3591. }
  3592. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  3593. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  3594. laUiList *sub = SubUi->Page;
  3595. laColumn *s = laFirstColumn(sub);
  3596. SubUi->State = LA_UI_ACTIVE;
  3597. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  3598. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  3599. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  3600. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  3601. laShowSeparator(sub, s);
  3602. return SubUi;
  3603. }
  3604. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3605. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  3606. laUiList *sub = SubUi->Page;
  3607. laColumn *s = laFirstColumn(sub);
  3608. SubUi->State = LA_UI_ACTIVE;
  3609. return SubUi;
  3610. }
  3611. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  3612. laEndCondition(sub, sub->UiItems.pFirst);
  3613. }
  3614. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  3615. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  3616. laUiList *nuil;
  3617. ui->C = c;
  3618. lstAppendItem(&uil->UiItems, ui);
  3619. if (ui->Type->Init) ui->Type->Init(ui);
  3620. ui->ExtraPP.EndInstance = ui->Extra;
  3621. return ui;
  3622. }
  3623. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  3624. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3625. if (!ui->Page) ui->Page = uil;
  3626. lstAppendItem(&ui->Subs, uil);
  3627. strSafeSet(&uil->TabName, Name);
  3628. laFirstColumn(uil);
  3629. //laFirstColumn(uil);
  3630. return uil;
  3631. }
  3632. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  3633. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3634. /*if (!ui->Page) */ ui->Page = uil;
  3635. lstAppendItem(&ui->Subs, uil);
  3636. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  3637. return uil;
  3638. }
  3639. laUiConditionNode *laTrue(){
  3640. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3641. ucn->Type = LA_CONDITION_TRUE;
  3642. return ucn;
  3643. }
  3644. laUiConditionNode *laFalse(){
  3645. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3646. ucn->Type = LA_CONDITION_FALSE;
  3647. return ucn;
  3648. }
  3649. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  3650. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3651. ucn->Type = LA_CONDITION_PROP;
  3652. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  3653. strSafeSet(&ucn->String, Prop);
  3654. return ucn;
  3655. }
  3656. laUiConditionNode *laIntExpression(int Value){
  3657. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3658. ucn->Type = LA_CONDITION_INT;
  3659. ucn->IntValue = Value;
  3660. return ucn;
  3661. }
  3662. laUiConditionNode *laFloatExpression(real Value){
  3663. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3664. ucn->Type = LA_CONDITION_FLOAT;
  3665. ucn->FloatValue = Value;
  3666. return ucn;
  3667. }
  3668. laUiConditionNode *laStringExpression(char *Content){
  3669. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3670. ucn->Type = LA_CONDITION_STRING;
  3671. strSafeSet(&ucn->String, Content);
  3672. return ucn;
  3673. }
  3674. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3675. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3676. ucn->Type = LA_CONDITION_AND;
  3677. ucn->Expression1 = Expression1;
  3678. ucn->Expression2 = Expression2;
  3679. return ucn;
  3680. }
  3681. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3682. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3683. ucn->Type = LA_CONDITION_OR;
  3684. ucn->Expression1 = Expression1;
  3685. ucn->Expression2 = Expression2;
  3686. return ucn;
  3687. }
  3688. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  3689. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3690. ucn->Type = LA_CONDITION_NOT;
  3691. ucn->Expression1 = Expression1;
  3692. return ucn;
  3693. }
  3694. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3695. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3696. ucn->Type = LA_CONDITION_EQ;
  3697. ucn->Expression1 = Expression1;
  3698. ucn->Expression2 = Expression2;
  3699. return ucn;
  3700. }
  3701. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3702. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3703. ucn->Type = LA_CONDITION_GT;
  3704. ucn->Expression1 = Expression1;
  3705. ucn->Expression2 = Expression2;
  3706. return ucn;
  3707. }
  3708. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3709. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3710. ucn->Type = LA_CONDITION_LT;
  3711. ucn->Expression1 = Expression1;
  3712. ucn->Expression2 = Expression2;
  3713. return ucn;
  3714. }
  3715. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3716. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3717. ucn->Type = LA_CONDITION_GE;
  3718. ucn->Expression1 = Expression1;
  3719. ucn->Expression2 = Expression2;
  3720. return ucn;
  3721. }
  3722. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3723. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3724. ucn->Type = LA_CONDITION_LE;
  3725. ucn->Expression1 = Expression1;
  3726. ucn->Expression2 = Expression2;
  3727. return ucn;
  3728. }
  3729. int la_GetIntConditionValue(laUiConditionNode *Expression){
  3730. if (Expression->Type != LA_CONDITION_INT) return 0;
  3731. return Expression->IntValue;
  3732. }
  3733. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  3734. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  3735. return Expression->FloatValue;
  3736. }
  3737. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  3738. return Expression->String->Ptr;
  3739. }
  3740. 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){
  3741. switch (Mode1){
  3742. case LA_PROP_ENUM:
  3743. case LA_PROP_INT:
  3744. case LA_CONDITION_INT:
  3745. switch (Mode2){
  3746. case LA_PROP_ENUM:
  3747. case LA_PROP_INT:
  3748. case LA_CONDITION_INT:
  3749. switch (CompMode){
  3750. case LA_CONDITION_GE:
  3751. return (i1 >= i2);
  3752. case LA_CONDITION_GT:
  3753. return (i1 > i2);
  3754. case LA_CONDITION_EQ:
  3755. return (i1 == i2);
  3756. case LA_CONDITION_LT:
  3757. return (i1 < i2);
  3758. case LA_CONDITION_LE:
  3759. return (i1 <= i2);
  3760. }
  3761. case LA_PROP_FLOAT:
  3762. case LA_CONDITION_FLOAT:
  3763. switch (CompMode){
  3764. case LA_CONDITION_GE:
  3765. return ((real)i1 >= f2);
  3766. case LA_CONDITION_GT:
  3767. return ((real)i1 > f2);
  3768. case LA_CONDITION_EQ:
  3769. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  3770. case LA_CONDITION_LT:
  3771. return ((real)i1 < f2);
  3772. case LA_CONDITION_LE:
  3773. return ((real)i1 <= f2);
  3774. }
  3775. case LA_PROP_SUB:
  3776. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  3777. default:
  3778. return 0;
  3779. }
  3780. case LA_PROP_FLOAT:
  3781. case LA_CONDITION_FLOAT:
  3782. switch (Mode2){
  3783. case LA_PROP_INT:
  3784. case LA_PROP_ENUM:
  3785. case LA_CONDITION_INT:
  3786. switch (CompMode){
  3787. case LA_CONDITION_GE:
  3788. return (f1 >= (real)i2);
  3789. case LA_CONDITION_GT:
  3790. return (f1 > (real)i2);
  3791. case LA_CONDITION_EQ:
  3792. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  3793. case LA_CONDITION_LT:
  3794. return (f1 < (real)i2);
  3795. case LA_CONDITION_LE:
  3796. return (f1 <= (real)i2);
  3797. }
  3798. case LA_PROP_FLOAT:
  3799. case LA_CONDITION_FLOAT:
  3800. switch (CompMode){
  3801. case LA_CONDITION_GE:
  3802. return (f1 >= f2);
  3803. case LA_CONDITION_GT:
  3804. return (f1 > f2);
  3805. case LA_CONDITION_EQ:
  3806. return (f1 == f2);
  3807. case LA_CONDITION_LT:
  3808. return (f1 < f2);
  3809. case LA_CONDITION_LE:
  3810. return (f1 <= f2);
  3811. }
  3812. default:
  3813. return 0;
  3814. }
  3815. case LA_PROP_STRING:
  3816. case LA_CONDITION_STRING:
  3817. switch (Mode2){
  3818. case LA_PROP_STRING:
  3819. case LA_CONDITION_STRING:
  3820. return strSame(s1, s2);
  3821. default:
  3822. return 0;
  3823. }
  3824. case LA_PROP_SUB:
  3825. switch (Mode2){
  3826. case LA_PROP_SUB:
  3827. return p1 == p2;
  3828. case LA_CONDITION_INT:
  3829. case LA_PROP_INT:
  3830. case LA_PROP_ENUM:
  3831. return (int)p1 == i2;
  3832. default:
  3833. return 0;
  3834. }
  3835. default:
  3836. switch (CompMode){
  3837. case LA_CONDITION_GE:
  3838. return (i1 >= i2);
  3839. case LA_CONDITION_GT:
  3840. return (i1 > i2);
  3841. case LA_CONDITION_EQ:
  3842. return (i1 == i2);
  3843. case LA_CONDITION_LT:
  3844. return (i1 < i2);
  3845. case LA_CONDITION_LE:
  3846. return (i1 <= i2);
  3847. }
  3848. }
  3849. }
  3850. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  3851. void *Instance = 0;
  3852. int IValue1 = 0, IValue2 = 0;
  3853. real FValue1 = 0, FValue2 = 0;
  3854. void *Ptr1 = 0, *Ptr2 = 0;
  3855. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  3856. int Result1, Result2;
  3857. laEnumItem *ei; laSubProp*sp;
  3858. if (!Expression) return 0;
  3859. Str1[0] = 0;
  3860. Str2[0] = 0;
  3861. laPropIterator pi = {0};
  3862. switch (Expression->Type){
  3863. case LA_CONDITION_PROP:
  3864. if (!Expression->PP.LastPs){
  3865. (*IResult) = 0;
  3866. return 0;
  3867. }
  3868. switch (Expression->PP.LastPs->p->PropertyType){
  3869. case LA_PROP_INT:
  3870. *IResult = laGetInt(&Expression->PP);
  3871. if (*IResult) return LA_CONDITION_INT;
  3872. else return 0;
  3873. case LA_PROP_FLOAT:
  3874. *FResult = laGetFloat(&Expression->PP);
  3875. if (*FResult) return 1;
  3876. else return 0;
  3877. break;
  3878. case LA_PROP_STRING:
  3879. laGetString(&Expression->PP, _StrResult, &StrResult);
  3880. if (StrResult[0]) return 1;
  3881. else return 0;
  3882. break;
  3883. case LA_PROP_ENUM:
  3884. ei = laGetEnum(&Expression->PP);
  3885. if (!ei) return 0;
  3886. /*if(ei) */ *IResult = ei->Index;
  3887. if (*IResult) return LA_CONDITION_INT;
  3888. else return 0;
  3889. break;
  3890. case LA_PROP_SUB:
  3891. sp=Expression->PP.LastPs->p;
  3892. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  3893. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  3894. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  3895. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  3896. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  3897. }
  3898. }
  3899. *PtrResult = Instance;
  3900. if (Instance) return 1;
  3901. break;
  3902. default:
  3903. return 0;
  3904. }
  3905. break;
  3906. case LA_CONDITION_INT:
  3907. *IResult = Expression->IntValue;
  3908. if (*IResult) return 1;
  3909. else
  3910. return 0;
  3911. case LA_CONDITION_FLOAT:
  3912. *FResult = Expression->FloatValue;
  3913. if (*FResult) return 1;
  3914. else
  3915. return 0;
  3916. case LA_CONDITION_STRING:
  3917. if (Expression->String){
  3918. strCopyFull(StrResult, Expression->String->Ptr);
  3919. return 1;
  3920. }else
  3921. return 0;
  3922. case LA_CONDITION_TRUE:
  3923. if (*IResult) *IResult = 1;
  3924. return 1;
  3925. case LA_CONDITION_FALSE:
  3926. if (*IResult) *IResult = 0;
  3927. return 0;
  3928. default:
  3929. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  3930. switch (Expression->Type){
  3931. case LA_CONDITION_AND:
  3932. if (Result1){
  3933. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3934. if (Result2) *IResult = 1;
  3935. return (Result2);
  3936. }else
  3937. return 0;
  3938. case LA_CONDITION_OR:
  3939. if (!Result1){
  3940. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3941. if (Result2) *IResult = 1;
  3942. return (Result2);
  3943. }else
  3944. return 1;
  3945. case LA_CONDITION_NOT:
  3946. return !Result1;
  3947. default:
  3948. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3949. return la_DoCompare(Expression->Type,
  3950. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  3951. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  3952. }
  3953. break;
  3954. }
  3955. return 0;
  3956. }
  3957. int la_DoSingleExpression(laUiConditionNode *Expression){
  3958. int a;
  3959. real b;
  3960. char c[128]={0};
  3961. void *p;
  3962. if (!Expression) return 1;
  3963. c[0] = 0;
  3964. return la_DoExpression(Expression, &a, &b, c, &p);
  3965. }
  3966. void la_StepExpression(laUiConditionNode *e){
  3967. if (!e) return;
  3968. switch (e->Type){
  3969. case LA_CONDITION_AND:
  3970. case LA_CONDITION_OR:
  3971. case LA_CONDITION_GE:
  3972. case LA_CONDITION_GT:
  3973. case LA_CONDITION_EQ:
  3974. case LA_CONDITION_LT:
  3975. case LA_CONDITION_LE:
  3976. la_StepExpression(e->Expression1);
  3977. la_StepExpression(e->Expression2);
  3978. break;
  3979. case LA_CONDITION_NOT:
  3980. la_StepExpression(e->Expression1);
  3981. break;
  3982. case LA_CONDITION_PROP:
  3983. la_StepPropPack(&e->PP);
  3984. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  3985. la_UsePropPack(&e->PP, 1);
  3986. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  3987. //}
  3988. break;
  3989. default:
  3990. break;
  3991. }
  3992. }
  3993. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  3994. if (!ucn) return;
  3995. la_ConditionNodeFreeRecursive(ucn->Expression1);
  3996. la_ConditionNodeFreeRecursive(ucn->Expression2);
  3997. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  3998. if (ucn->String) strSafeDestroy(&ucn->String);
  3999. if (ucn) memFree(ucn);
  4000. }
  4001. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4002. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4003. ui->C = c;
  4004. ui->Type = &_LA_UI_CONDITION;
  4005. la_ConditionerInit(ui, Expression);
  4006. lstAppendItem(&uil->UiItems, ui);
  4007. return ui;
  4008. }
  4009. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4010. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4011. laConditionUiExtraData *cued;
  4012. ui->Type = &_LA_UI_CONDITION_ELSE;
  4013. la_ConditionerInit(ui, 0);
  4014. cued = ui->Extra;
  4015. cued->EndUi = Beginner;
  4016. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4017. ui->C = Beginner->C;
  4018. lstAppendItem(&uil->UiItems, ui);
  4019. return ui;
  4020. }
  4021. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4022. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4023. laConditionUiExtraData *cued;
  4024. ui->Template = define;
  4025. ui->C = col;
  4026. ui->PP.RawThis = ExtraBase;
  4027. ui->Page = ExtraThis;
  4028. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4029. la_ConditionerInit(ui, 0);
  4030. cued = ui->Extra;
  4031. //cued->Remove = Remove;
  4032. ui->State = LA_UI_NORMAL;
  4033. lstAppendItem(&uil->UiItems, ui);
  4034. return ui;
  4035. }
  4036. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4037. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4038. laConditionUiExtraData *cued;
  4039. ui->Type = &_LA_UI_CONDITION_END;
  4040. la_ConditionerInit(ui, 0);
  4041. cued = ui->Extra;
  4042. cued->EndUi = Beginner;
  4043. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4044. ui->C = Beginner->C;
  4045. lstAppendItem(&uil->UiItems, ui);
  4046. return ui;
  4047. }
  4048. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4049. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4050. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4051. ui->Type = _LA_UI_MENU_ROOT;
  4052. strSafeSet(&ui->Display, Title);
  4053. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4054. ui->C = c;
  4055. lstAppendItem(&uil->UiItems, ui);
  4056. lstAppendItem(&ui->Subs, muil);
  4057. return muil;
  4058. }
  4059. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4060. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4061. ui->Type = _LA_UI_ALIGN;
  4062. ui->C = widest;
  4063. lstAppendItem(&uil->UiItems, ui);
  4064. return ui;
  4065. }
  4066. void laFixHeight(laUiList *uil, short Rows){
  4067. if (!uil) return;
  4068. uil->HeightCoeff = Rows;
  4069. }
  4070. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4071. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4072. if (!ExtraColumns) return;
  4073. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4074. }
  4075. laUiTemplate *laFindUiTemplate(char *Identifier){
  4076. laUiTemplate *uit;
  4077. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4078. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4079. }
  4080. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4081. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4082. }
  4083. return 0;
  4084. }
  4085. void la_DestroyUiTemplate(laUiTemplate* uit){
  4086. strSafeDestroy(&uit->Identifier);
  4087. strSafeDestroy(&uit->Title);
  4088. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4089. memFree(uit);
  4090. }
  4091. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4092. strSafeDestroy(&uit->Identifier);
  4093. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4094. memFree(uit);
  4095. }
  4096. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4097. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4098. strSafeSet(&uit->Identifier, Identifier);
  4099. strSafeSet(&uit->Title, Title);
  4100. strSafeSet(&uit->CategoryName, NewCategory);
  4101. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4102. uit->DefaultGLFormat=DefaultGLFormat;
  4103. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4104. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4105. la_UDFAppendSharedTypePointer(Identifier, uit);
  4106. return uit;
  4107. }
  4108. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4109. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4110. strSafeSet(&t->Identifier, Identifier);
  4111. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4112. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4113. lstAppendItem(&MAIN.View2DTemplates, t);
  4114. la_UDFAppendSharedTypePointer(Identifier, t);
  4115. return t;
  4116. }
  4117. void laFinalizeUiTemplates(){
  4118. laUiTemplate *uit;
  4119. laCanvasTemplate *u2d;
  4120. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4121. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4122. }
  4123. }
  4124. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4125. laPanel *p;
  4126. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4127. if (p->PanelTemplate==uit){
  4128. return p;
  4129. }
  4130. }
  4131. return 0;
  4132. }
  4133. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4134. laUiList *uil, *NextUil;
  4135. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4136. NextUil = uil->Item.pNext;
  4137. lstRemoveItem(&ui->Subs, uil);
  4138. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4139. }
  4140. la_StopUiOperatorService(ui);
  4141. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4142. strSafeDestroy(&ui->Display);
  4143. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4144. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4145. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4146. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4147. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4148. memFree(ui);
  4149. }
  4150. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4151. laUiItem *ui, *NextUi;
  4152. laColumn *col, *NextCol;
  4153. if (!uil) return;
  4154. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4155. NextUi = ui->Item.pNext;
  4156. if(OnlyRemoveUser && RemoveUsers){
  4157. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4158. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4159. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4160. continue;
  4161. }
  4162. lstRemoveItem(&uil->UiItems, ui);
  4163. la_DestroyUiItem(ui, RemoveUsers);
  4164. }
  4165. if(OnlyRemoveUser){ return; }
  4166. for (col = uil->Columns.pFirst; col; col = NextCol){
  4167. NextCol = col->Item.pNext;
  4168. lstRemoveItem(&uil->Columns, col);
  4169. memFree(col);
  4170. }
  4171. strSafeDestroy(&uil->TabName);
  4172. if (!NoFree) memFree(uil);
  4173. }
  4174. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4175. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4176. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4177. }
  4178. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4179. laUiItem *Next = after->Item.pNext;
  4180. laUiItem *Last = uil->UiItems.pLast;
  4181. after->Item.pNext = 0;
  4182. uil->UiItems.pLast = after;
  4183. Define(uil, Base, This, ExtraColums, 0);
  4184. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4185. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4186. if (Next != Last) uil->UiItems.pLast = Last;
  4187. }
  4188. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4189. // int i = 0;
  4190. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4191. // if (!ui->ExtraColums) return;
  4192. // for (i; ui->ExtraColums[i]; i++) {
  4193. // laColumn* c = ui->ExtraColums[i];
  4194. // c->B = B;
  4195. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4196. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4197. // }
  4198. //}
  4199. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4200. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4201. }
  4202. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4203. laColumn *c = ui->C;
  4204. laColumn *ic = lst->pFirst;
  4205. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4206. for (ic; ic; ic = ic->Item.pNext){
  4207. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4208. ic->B = ic->B < c->B ? c->B : ic->B;
  4209. }
  4210. }
  4211. ic = ui->C;
  4212. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4213. ;
  4214. for (ic; ic; ic = ic->Item.pNext){
  4215. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4216. ic->B = ic->B < c->B ? c->B : ic->B;
  4217. }
  4218. }
  4219. }
  4220. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4221. laColumn *c = ui->C;
  4222. laColumn *ic = lst->pFirst;
  4223. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4224. for (ic; ic; ic = ic->Item.pNext){
  4225. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4226. ic->B = ic->B < c->B ? c->B : ic->B;
  4227. }
  4228. }
  4229. ic = ui->C;
  4230. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4231. ;
  4232. for (ic; ic; ic = ic->Item.pNext){
  4233. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4234. ic->B = ic->B < c->B ? c->B : ic->B;
  4235. }
  4236. }
  4237. }
  4238. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4239. int rep;
  4240. int sp;
  4241. int rev;
  4242. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4243. if (!c) return 0;
  4244. sp = (c->SP * (R - L)) + L;
  4245. rev = sp;
  4246. /*if (U)*/ c->B = U;
  4247. if (LR == 1){
  4248. c->IL = L;
  4249. c->IR = sp;
  4250. if (repos){
  4251. c->IR = repos;
  4252. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4253. c->IR = c->IL + c->MaxW*LA_RH+M;
  4254. rev = c->IR;
  4255. }
  4256. }else if (LR == 2){
  4257. c->IL = sp;
  4258. c->IR = R;
  4259. if (repos){
  4260. c->IL = repos;
  4261. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4262. c->IL = c->IR - c->MaxW*LA_RH-M;
  4263. rev = c->IL;
  4264. }
  4265. }else if (LR == 0){
  4266. c->IL = L;
  4267. c->IR = R;
  4268. }
  4269. if (c->LS && c->RS->MaxW == 0){
  4270. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4271. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4272. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4273. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4274. }else if (c->RS && c->LS->MaxW == 0){
  4275. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4276. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4277. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4278. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4279. }
  4280. return rev;
  4281. }
  4282. STRUCTURE(laRowInfo){
  4283. int MaxW;
  4284. int MinW;
  4285. int UnitMinW;
  4286. int NonExpandW;
  4287. int TotalPadding;
  4288. int Expand, Even;
  4289. int ExpandAccum;
  4290. int CountElements;
  4291. int U,MaxB,L;
  4292. laListHandle Elements;
  4293. int LastNoHeight;
  4294. };
  4295. STRUCTURE(laRowNode){
  4296. laListItem Item;
  4297. laUiItem* ui;
  4298. int GotW, LP, RP, H;
  4299. int Expand;
  4300. int UseLast;
  4301. };
  4302. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4303. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4304. ri->UnitMinW=LA_RH;
  4305. ri->Expand=ui->State?1:0;
  4306. ri->Even=ui->Flags?1:0;
  4307. ri->U=ui->TU; ri->L=ui->TL;
  4308. ri->MaxB=ui->TU;
  4309. }
  4310. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H){
  4311. laRowNode* rn=CreateNew(laRowNode);
  4312. rn->LP=bt->LP;rn->RP=bt->RP;
  4313. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4314. rn->ui=ui;
  4315. rn->H=H;
  4316. rn->Expand=ui->Expand;
  4317. lstAppendItem(&ri->Elements, rn);
  4318. if(ri->LastNoHeight){
  4319. ri->LastNoHeight=0; rn->UseLast=1; return; }
  4320. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){
  4321. ri->LastNoHeight=1; };
  4322. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4323. ri->TotalPadding += (bt->LP+bt->RP);
  4324. ri->MinW+=ri->UnitMinW;
  4325. ri->NonExpandW+=rn->GotW;
  4326. ri->ExpandAccum+=ui->Expand;
  4327. ri->CountElements++;
  4328. if(ui->Expand){ri->Expand=1;}
  4329. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4330. }
  4331. int la_ShrinkableRowElements(laRowInfo* ri){
  4332. int count=0;
  4333. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4334. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4335. count++;
  4336. }
  4337. return count;
  4338. }
  4339. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4340. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end, int WaitAnimation){
  4341. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4342. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4343. if(Available<0){
  4344. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4345. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4346. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4347. }else{
  4348. if(!ri->Expand && Available>0){Available=0;}
  4349. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4350. }
  4351. if(!ShareCount) return 0;
  4352. int PerNode = Available/ShareCount;
  4353. int Remaining = Available-PerNode*ShareCount;
  4354. int L = ri->L; int i=0; laRowNode* rn;
  4355. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4356. laUiItem* ui=rn->ui;
  4357. int NodeAdd, Node=rn->GotW;
  4358. if(rn->UseLast){
  4359. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4360. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4361. continue;
  4362. }
  4363. if(Available>=0){
  4364. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4365. NodeAdd+=(i<Remaining?1:0);i++;
  4366. }else{
  4367. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4368. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4369. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4370. }else{ Node=ri->UnitMinW;
  4371. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4372. }
  4373. }
  4374. ui->TL = L + rn->LP;
  4375. ui->TR = ui->TL + Node+NodeAdd;
  4376. ui->TB = ui->TU + rn->H;
  4377. L=ui->TR+rn->RP;
  4378. if (!WaitAnimation){
  4379. ui->L = ui->TL; ui->R = ui->TR;
  4380. ui->U = ui->TU; ui->B = ui->TB;
  4381. }
  4382. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4383. }
  4384. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ui_end->TU:ri->MaxB;
  4385. while(rn=lstPopItem(&ri->Elements)){
  4386. FreeMem(rn);
  4387. }
  4388. memset(ri, 0, sizeof(laRowInfo));
  4389. }
  4390. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4391. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4392. int sl,sr,su,sb;
  4393. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4394. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4395. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4396. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4397. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4398. if(pc==LA_PC_SOCKET_OUT){
  4399. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4400. }else{
  4401. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4402. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4403. }
  4404. }
  4405. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4406. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4407. }
  4408. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4409. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4410. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4411. laBoxedTheme *bt;
  4412. int Lowest = 0;
  4413. int HyperValue = 0;
  4414. int WaitAnimation;
  4415. int RowMode=0; laRowInfo ri={0};
  4416. laBoxedTheme* pt=*(ParentPanel->BT);
  4417. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4418. int MaxR=0;
  4419. if(!uil->Scale){uil->Scale=1;}
  4420. uil->SaveScale=MAIN.UiScale;
  4421. MAIN.UiScale*=uil->Scale;
  4422. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4423. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4424. WaitAnimation = 0;
  4425. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4426. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4427. for (ui = uil->UiItems.pFirst; ui;){
  4428. int SubB = 0;
  4429. int H;
  4430. WaitAnimation = 0;
  4431. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4432. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4433. //if (Fast && ui->C->B > B) {
  4434. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4435. // ui = ui->Item.pNext;
  4436. // continue;
  4437. //}
  4438. if (!ui->Instructions){
  4439. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4440. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4441. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4442. laOperatorProp *ap = ui->PP.LastPs->p;
  4443. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  4444. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  4445. }
  4446. }
  4447. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  4448. la_UsePropPack(&ui->PP, 0);
  4449. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  4450. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  4451. // 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);
  4452. //}
  4453. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  4454. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  4455. WaitAnimation = 1;
  4456. }
  4457. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  4458. bt = (*ui->Type->Theme);
  4459. if (ui->Type == &_LA_UI_CONDITION){
  4460. laConditionUiExtraData *cued = ui->Extra;
  4461. la_StepExpression(cued->Expression);
  4462. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4463. if (!cued->IsTrue){
  4464. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4465. }else{
  4466. ui = ui->Item.pNext;
  4467. }
  4468. continue;
  4469. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4470. ui = ui->Item.pNext;
  4471. continue;
  4472. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4473. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4474. if (cued->IsTrue) ui = cued->EndUi;
  4475. else
  4476. ui = ui->Item.pNext;
  4477. continue;
  4478. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4479. laConditionUiExtraData *cued = ui->Extra;
  4480. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  4481. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  4482. if (!WaitAnimation){
  4483. ui->L = ui->TL; ui->R = ui->TR;
  4484. ui->U = ui->TU; ui->B = ui->TB;
  4485. }
  4486. if(!RowMode){
  4487. la_CalcUiItemInfluence(&uil->Columns, ui);
  4488. }else{
  4489. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4490. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4491. }
  4492. if (ui->State == LA_UI_NORMAL){
  4493. cued->IsTrue = 0;
  4494. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  4495. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  4496. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4497. }else{
  4498. cued->IsTrue = 1;
  4499. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  4500. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  4501. //}
  4502. ui = ui->Item.pNext;
  4503. }
  4504. continue;
  4505. }
  4506. if (ui->Type == _LA_UI_ALIGN){
  4507. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  4508. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4509. if (ui->TB > Lowest) Lowest = ui->TB;
  4510. if (!WaitAnimation){
  4511. ui->L = ui->TL; ui->R = ui->TR;
  4512. ui->U = ui->TU; ui->B = ui->TB;
  4513. }
  4514. if(!RowMode){
  4515. la_CalcUiItemInfluence(&uil->Columns, ui);
  4516. }else{
  4517. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  4518. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4519. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4520. }
  4521. ui = ui->Item.pNext; continue;
  4522. }
  4523. if (ui->Type == &_LA_UI_ROW_BEGIN){
  4524. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4525. la_InitRowNode(&ri, ui, bt);
  4526. RowMode=1; ui=ui->Item.pNext; continue;
  4527. }
  4528. if (ui->Type == &_LA_UI_ROW_END){
  4529. la_CalculateRowExpand(&ri, ui, WaitAnimation);
  4530. la_CalcUiItemInfluence(&uil->Columns, ui);
  4531. RowMode=0; ui=ui->Item.pNext; continue;
  4532. }
  4533. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  4534. int GB=0;
  4535. 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; }
  4536. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4537. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  4538. if (H < 0){
  4539. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  4540. else{ H=LA_RH; }
  4541. }
  4542. else H *= LA_RH;
  4543. ui->TB = ui->TU;
  4544. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4545. 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
  4546. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  4547. if (ui->Type == _LA_UI_COLLECTION){
  4548. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  4549. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4550. ui->PP.EndInstance = TInstance;
  4551. laUiList *iuil = ui->Subs.pFirst;
  4552. laUiList *puil = iuil;
  4553. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  4554. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  4555. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4556. int Begin = ui->TB;
  4557. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  4558. int ElementB = ui->TU;
  4559. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  4560. int MaxB = ElementB;
  4561. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4562. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  4563. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  4564. if (!ElementLimit) RowPriority = 0;
  4565. if (!TInstance){
  4566. while (iuil){
  4567. puil = iuil->Item.pNext;
  4568. la_DestroyTabPage(ui, iuil, 0);
  4569. iuil = puil;
  4570. }
  4571. }
  4572. while (TInstance){
  4573. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  4574. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4575. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4576. ui->PP.EndInstance = TInstance; continue;
  4577. }
  4578. if(CanGetTheme){
  4579. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4580. la_SwitchThemeQuick(t, OriginalTheme);
  4581. }
  4582. if(CanGetGap){
  4583. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  4584. Gap=g*LA_RH;
  4585. }else Gap=0;
  4586. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  4587. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  4588. }else GotCategory=0;
  4589. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  4590. if (RowPriority){
  4591. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  4592. }
  4593. }
  4594. FirstIn=0;
  4595. if (ElementLimit){
  4596. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  4597. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  4598. }
  4599. while (iuil && iuil->Instance != TInstance){
  4600. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  4601. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  4602. }else{
  4603. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  4604. }
  4605. iuil = puil;
  4606. }
  4607. if(!iuil){
  4608. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  4609. }
  4610. if (!iuil){
  4611. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  4612. la_CalcUiTopInfluence(&uil->Columns, ui);
  4613. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4614. 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);
  4615. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4616. iuil = ui->Page->Item.pNext;
  4617. }else{
  4618. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  4619. 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);
  4620. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4621. la_CalcUiItemInfluence(&uil->Columns, ui);
  4622. iuil = iuil->Item.pNext;
  4623. }
  4624. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4625. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4626. ui->PP.EndInstance = TInstance;
  4627. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4628. if (RowPriority){
  4629. Col += 1;
  4630. if (Col >= ElementLimit){
  4631. Col = 0;
  4632. Row += 1;
  4633. Begin = ElementB + bt->TM;
  4634. }
  4635. }elif(Spread){
  4636. EL+=Spread*LA_RH;
  4637. ER+=Spread*LA_RH;
  4638. }else{
  4639. Row += 1;
  4640. Begin = ElementB + bt->TM;
  4641. if (ElementLimit && Row >= ElementLimit){
  4642. Row = 0;
  4643. Col += 1;
  4644. Begin = ui->TU + bt->TM;
  4645. }
  4646. }
  4647. ui->TB = ElementB;
  4648. MaxB = MaxB < ElementB ? ElementB : MaxB;
  4649. }
  4650. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  4651. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  4652. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4653. ui->TB = MaxB;
  4654. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  4655. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  4656. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  4657. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  4658. ui->TB=ui->TU+LA_RH;
  4659. }else{
  4660. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4661. ui->PP.EndInstance = TInstance;
  4662. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4663. if(!Template) Template=laui_SubPropInfoDefault;
  4664. //ui->Template = Template;
  4665. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  4666. if (!ui->Subs.pFirst && TInstance){
  4667. la_AddInstancePage(ui, TInstance, 0);
  4668. la_CalcUiTopInfluence(&uil->Columns, ui);
  4669. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4670. 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);
  4671. ui->TB = SubB + (NoDecal?0:bt->BM);
  4672. }else if (ui->Subs.pFirst){
  4673. if (!TInstance || TInstance != ui->Page->Instance){
  4674. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  4675. ui->Page = 0;
  4676. if (TInstance){
  4677. la_AddInstancePage(ui, TInstance, 0);
  4678. la_CalcUiTopInfluence(&uil->Columns, ui);
  4679. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4680. 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);
  4681. ui->TB = SubB + (NoDecal?0:bt->TM);
  4682. }else
  4683. ui->TB = ui->TU + LA_RH + bt->BM;
  4684. }else{
  4685. 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);
  4686. ui->TB = SubB + (NoDecal?0:bt->BM);
  4687. }
  4688. }
  4689. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  4690. ui->TB=ui->TU+LA_RH;
  4691. }
  4692. }
  4693. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  4694. if (!WaitAnimation){
  4695. ui->L = ui->TL;
  4696. ui->R = ui->TR;
  4697. ui->U = ui->TU;
  4698. ui->B = ui->TB;
  4699. }
  4700. }
  4701. }else{
  4702. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4703. if (ui->Type != _LA_UI_CANVAS){
  4704. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  4705. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  4706. SubB = la_UpdateUiListRecursive(ui->Page,
  4707. 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);
  4708. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  4709. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT) : SubB)) + (NoDecal?0:bt->BM);
  4710. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  4711. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  4712. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  4713. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  4714. }
  4715. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  4716. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  4717. 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; }
  4718. if(ui->Page->HeightCoeff){
  4719. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  4720. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  4721. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  4722. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  4723. }
  4724. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  4725. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  4726. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  4727. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  4728. }
  4729. }
  4730. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  4731. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  4732. }else{
  4733. laUiList *suil;
  4734. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  4735. la_CalcUiTopInfluence(&uil->Columns, ui);
  4736. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4737. 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);
  4738. }
  4739. }
  4740. ui->TB = ui->TU + H;
  4741. }
  4742. }else ui->TB = ui->TU + H;
  4743. }
  4744. if (ui->TB > Lowest) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  4745. if(!RowMode){
  4746. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  4747. }else{
  4748. la_AddRowNode(&ri, ui, bt, H);
  4749. }
  4750. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  4751. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4752. ui = ui->Item.pNext;
  4753. }
  4754. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  4755. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  4756. else uil->TB = Lowest;
  4757. if (!WaitAnimation){
  4758. uil->L = uil->TL;
  4759. uil->R = uil->TR;
  4760. uil->U = uil->TU;
  4761. uil->B = uil->TB;
  4762. }
  4763. MAIN.UiScale=uil->SaveScale;
  4764. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4765. return uil->TB;
  4766. }
  4767. int la_AnimateSingleUiSize(int To, int *Now){
  4768. int Delta;
  4769. if (To != *Now){
  4770. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  4771. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  4772. *Now += Delta;
  4773. return 1;
  4774. }else
  4775. return 0;
  4776. }
  4777. int la_AnimateUiListRecursive(laUiList *uil){
  4778. laUiItem *ui;
  4779. int Again = 0;
  4780. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  4781. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  4782. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  4783. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  4784. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  4785. la_AnimateSingleUiSize(ui->TR, &ui->R));
  4786. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4787. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  4788. laUiList *suil;
  4789. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4790. Again += la_AnimateUiListRecursive(suil);
  4791. }
  4792. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  4793. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4794. Again += la_AnimateUiListRecursive(ui->Page);
  4795. }
  4796. }
  4797. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  4798. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  4799. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  4800. la_AnimateSingleUiSize(uil->TR, &uil->R));
  4801. return Again;
  4802. }
  4803. int la_DrawUiItem(laUiItem *ui){
  4804. tnsUseNoTexture();
  4805. tnsColor4d(1, 1, 1, 1);
  4806. tnsVertex2d(ui->L, ui->U);
  4807. tnsVertex2d(ui->R, ui->U);
  4808. tnsVertex2d(ui->R, ui->B);
  4809. tnsVertex2d(ui->L, ui->B);
  4810. tnsPackAs(GL_LINE_LOOP);
  4811. }
  4812. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  4813. tnsUseNoTexture();
  4814. tnsColor4d(1, 1, 1, 1);
  4815. tnsVertex2d(ui->L - 1, ui->U - 1);
  4816. tnsVertex2d(ui->R + 1, ui->U - 1);
  4817. tnsVertex2d(ui->R + 1, ui->B + 1);
  4818. tnsVertex2d(ui->L - 1, ui->B + 1);
  4819. tnsPackAs(GL_LINE_LOOP);
  4820. }
  4821. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  4822. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  4823. return 1;
  4824. }
  4825. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  4826. laUiListDrawItem *uildi = uild->Items.pFirst;
  4827. laUiList *Target = uildi->Target;
  4828. int L, R, U, B;
  4829. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  4830. L = Target->L + Target->PanX + uildi->DifX;
  4831. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4832. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4833. U = Target->U + Target->PanY + uildi->DifY;
  4834. return la_UiInBound(ui, L, R, U, B);
  4835. }
  4836. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  4837. laUiListDrawItem *uildi = uild->Items.pFirst;
  4838. laUiList *Target = uildi->Target;
  4839. int L, R, U, B;
  4840. if (Target){
  4841. L = Target->L + Target->PanX + uildi->DifX;
  4842. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4843. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4844. U = Target->U + Target->PanY + uildi->DifY;
  4845. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  4846. return 1;
  4847. }else{
  4848. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  4849. return 1;
  4850. }
  4851. }
  4852. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  4853. laUiItem *ui = uil->UiItems.pFirst;
  4854. while (!strGetArgument(ui->Instructions, mark))
  4855. ui = ui->Item.pNext;
  4856. return ui;
  4857. }
  4858. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  4859. laUiList *uil;
  4860. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  4861. if (uil->Instance == Instance) return uil;
  4862. }
  4863. return uil;
  4864. }
  4865. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  4866. int mx=(L+R)/2; int my=(U+B)/2;
  4867. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  4868. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  4869. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  4870. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  4871. tnsFlush();
  4872. }
  4873. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  4874. if(!uil->ScrollerShownV) return;
  4875. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  4876. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  4877. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  4878. int U = uil->U + Offset;
  4879. int B = U + Len;
  4880. int L = UiR - RM*2 - W;
  4881. int R = L + W;
  4882. if (B > U + DisplayH) B = U + DisplayH;
  4883. if (U < uil->U) U = uil->U;
  4884. if (B <= uil->U || U >= uil->B) return;
  4885. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  4886. if (U < uil->U) U = uil->U;
  4887. tnsUseNoTexture();
  4888. laBoxedTheme* bt=_LA_THEME_PANEL;
  4889. real* color=laThemeColor(bt, LA_BT_TEXT);
  4890. tnsColor4d(LA_COLOR3(color), 0.2);
  4891. tnsVertex2d(R-RM, uil->U);
  4892. tnsVertex2d(L+RM, uil->U);
  4893. tnsVertex2d(L+RM, uil->U + DisplayH);
  4894. tnsVertex2d(R-RM, uil->U + DisplayH);
  4895. tnsPackAs(GL_TRIANGLE_FAN);
  4896. tnsColor4d(LA_COLOR3(color), 0.5);
  4897. tnsVertex2d(R-RM, uil->U);
  4898. tnsVertex2d(L+RM, uil->U);
  4899. tnsVertex2d(L+RM, uil->U + DisplayH);
  4900. tnsVertex2d(R-RM, uil->U + DisplayH);
  4901. tnsPackAs(GL_LINE_LOOP);
  4902. tnsColor4d(LA_COLOR3(color), 1);
  4903. tnsVertex2d(R, U);
  4904. tnsVertex2d(L, U);
  4905. tnsVertex2d(L, B);
  4906. tnsVertex2d(R, B);
  4907. tnsPackAs(GL_TRIANGLE_FAN);
  4908. int HU=(U+B)/2+LA_RH2;
  4909. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4910. tnsFlush();
  4911. }
  4912. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  4913. if(!uil->ScrollerShownH) return;
  4914. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  4915. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  4916. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  4917. int L = uil->L + Offset;
  4918. int R = L + Len;
  4919. int U = UiB - RM - W;
  4920. int B = U + W;
  4921. if (B > U + DisplayW) B = U + DisplayW;
  4922. if (U < uil->U) U = uil->U;
  4923. if (R <= uil->L || L >= uil->R) return;
  4924. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  4925. if (L < uil->L) L = uil->L;
  4926. tnsUseNoTexture();
  4927. laBoxedTheme* bt=_LA_THEME_PANEL;
  4928. real* color=laThemeColor(bt, LA_BT_TEXT);
  4929. tnsColor4d(LA_COLOR3(color), 0.2);
  4930. tnsVertex2d(uil->L,U+RM);
  4931. tnsVertex2d(uil->L,B-RM);
  4932. tnsVertex2d(uil->L + DisplayW,B-RM);
  4933. tnsVertex2d(uil->L + DisplayW,U+RM);
  4934. tnsPackAs(GL_TRIANGLE_FAN);
  4935. tnsColor4d(LA_COLOR3(color), 0.5);
  4936. tnsVertex2d(uil->L,U+RM);
  4937. tnsVertex2d(uil->L,B-RM);
  4938. tnsVertex2d(uil->L + DisplayW,B-RM);
  4939. tnsVertex2d(uil->L + DisplayW,U+RM);
  4940. tnsPackAs(GL_LINE_LOOP);
  4941. tnsColor4d(LA_COLOR3(color), 1);
  4942. tnsVertex2d(R, U);
  4943. tnsVertex2d(L, U);
  4944. tnsVertex2d(L, B);
  4945. tnsVertex2d(R, B);
  4946. tnsPackAs(GL_TRIANGLE_FAN);
  4947. int HU=(U+B)/2+LA_RH2;
  4948. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4949. tnsFlush();
  4950. }
  4951. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  4952. tnsUseNoTexture();
  4953. tnsColor4dv(color);
  4954. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  4955. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  4956. tnsPackAs(GL_TRIANGLE_FAN);
  4957. }
  4958. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  4959. laSocketRecord* sr;
  4960. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  4961. uild->WiresContainer=container;
  4962. }
  4963. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  4964. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  4965. if(lip->Target==uild->WiresContainer) break;
  4966. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  4967. }
  4968. }
  4969. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  4970. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4971. int PanX, PanY;
  4972. if(pc==LA_PC_SOCKET_OUT){
  4973. laNodeOutSocket* s=ui->PP.EndInstance;
  4974. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  4975. }else{
  4976. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  4977. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  4978. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  4979. }
  4980. }
  4981. void la_RegenerateWireColors(){
  4982. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  4983. laTheme* t=MAIN.CurrentTheme;
  4984. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  4985. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  4986. for(int i=0;i<MAIN.WireColorSlices;i++){
  4987. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  4988. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  4989. }
  4990. }
  4991. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  4992. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  4993. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  4994. tnsInterpolate2dv(v1,v2,0.5,vi);
  4995. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=log(dist+1)*MAIN.WireSaggyness; }
  4996. tnsVectorMinus2d(v1s,vi,v1); tnsNormalizeSelf2d(v1s); tnsVectorMultiSelf2d(v1s,circle_r);
  4997. tnsVectorMinus2d(v2s,vi,v2); tnsNormalizeSelf2d(v2s); tnsVectorMultiSelf2d(v2s,circle_r);
  4998. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  4999. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5000. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5001. tnsVertex2d(v1[0],v1[1]);
  5002. for(int i=1;i<=steps;i++){
  5003. real ratio=i==steps?1.0f:step*i;
  5004. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5005. tnsVertex2d(v1s[0],v1s[1]);
  5006. }
  5007. }
  5008. void la_DrawNodeWires(laUiListDraw* uild){
  5009. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5010. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5011. tnsUseNoTexture();
  5012. #define _RSLICES 16
  5013. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5014. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5015. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5016. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5017. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5018. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5019. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, 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. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5023. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5024. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5025. }
  5026. if(MAIN.tNodeIn->Source){
  5027. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5028. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5029. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5030. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5031. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, 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. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5035. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5036. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5037. }
  5038. #undef _RSLICES
  5039. tnsFlush();
  5040. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5041. glLineWidth(ww);
  5042. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5043. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5044. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5045. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5046. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5047. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5048. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5049. }
  5050. if(MAIN.tNodeIn->Source){
  5051. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5052. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5053. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5054. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5055. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5056. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5057. }
  5058. tnsFlush();
  5059. glLineWidth(1);
  5060. la_InitSocketRecord(uild,0);
  5061. }
  5062. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5063. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5064. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5065. }
  5066. 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){
  5067. laUiItem *ui;
  5068. laBoxedTheme *bt;
  5069. laUiList *sub;
  5070. laUiListDrawItem *uildi;
  5071. int Ret = 0;
  5072. if (!uil) return 0;
  5073. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5074. ui = uil->UiItems.pFirst;
  5075. if(uil->PanY<0){uil->PanY=0;}
  5076. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5077. uil->SaveScale=MAIN.UiScale;
  5078. MAIN.UiScale*=uil->Scale;
  5079. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5080. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5081. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5082. if (ui->Type == &_LA_UI_CONDITION){
  5083. laConditionUiExtraData *cued = ui->Extra;
  5084. la_StepExpression(cued->Expression);
  5085. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5086. if (!cued->IsTrue){
  5087. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5088. }else{
  5089. ui = ui->Item.pNext;
  5090. }
  5091. continue;
  5092. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5093. ui = ui->Item.pNext;
  5094. continue;
  5095. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5096. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5097. if (cued->IsTrue) ui = cued->EndUi;
  5098. else
  5099. ui = ui->Item.pNext;
  5100. continue;
  5101. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5102. laConditionUiExtraData *cued = ui->Extra;
  5103. ui->Type->Draw(ui, LA_RH);
  5104. if (ui->State == LA_UI_NORMAL){
  5105. cued->IsTrue = 0;
  5106. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5107. }else{
  5108. cued->IsTrue = 1;
  5109. ui = ui->Item.pNext;
  5110. }
  5111. continue;
  5112. }
  5113. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5114. int NeedDraw=0;
  5115. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5116. if(NeedDraw){
  5117. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5118. }else{ ui->Type->Draw(ui, LA_RH); }
  5119. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5120. tnsFlush();
  5121. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5122. tnsResetViewMatrix();
  5123. }
  5124. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5125. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5126. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5127. tnsFlush();
  5128. }
  5129. }
  5130. if(NeedDraw || RegisterNodes){
  5131. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5132. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5133. ui->Type == _LA_UI_TAB ||
  5134. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5135. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5136. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5137. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5138. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5139. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5140. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5141. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5142. 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); }
  5143. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5144. 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);
  5145. 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)); }
  5146. }elif (ui->Type == _LA_UI_COLLECTION){
  5147. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5148. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5149. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5150. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5151. int State;
  5152. ui->PP.EndInstance = sub->Instance;
  5153. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5154. if(!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && NeedDraw){
  5155. if (CanGetState){
  5156. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5157. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP);
  5158. }elif (sub->Instance == Active){
  5159. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP);
  5160. }
  5161. }
  5162. if(sub->TabName && sub->TabName->Ptr){
  5163. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5164. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5165. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5166. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5167. tnsFlush();
  5168. }
  5169. if(CanGetTheme){
  5170. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5171. la_SwitchThemeQuick(t, OriginalTheme);
  5172. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5173. }
  5174. tnsFlush();
  5175. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5176. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5177. }
  5178. ui->PP.EndInstance = Active;
  5179. }elif (ui->Type == _LA_UI_CANVAS){
  5180. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5181. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5182. tnsFlush();
  5183. 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);
  5184. }
  5185. }
  5186. }
  5187. ui = ui->Item.pNext;
  5188. }else{
  5189. ui = ui->Item.pNext;
  5190. }
  5191. }
  5192. tnsFlush();
  5193. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5194. la_RestoreLastUiListMatrix(uild, B - U);
  5195. MAIN.UiScale=uil->SaveScale;
  5196. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5197. return Ret;
  5198. }
  5199. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5200. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5201. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5202. tnsUseNoTexture();
  5203. tnsColor4d(1, 1, 1, 1);
  5204. tnsVertex2d(L, U);
  5205. tnsVertex2d(R, U);
  5206. tnsVertex2d(R, B);
  5207. tnsVertex2d(L, B);
  5208. tnsPackAs(GL_LINE_LOOP);
  5209. tnsVertex2d(L + 3, Begin);
  5210. tnsVertex2d(R - 3, Begin);
  5211. tnsVertex2d(R - 3, End);
  5212. tnsVertex2d(L + 3, End);
  5213. tnsPackAs(GL_LINE_LOOP);
  5214. }
  5215. int laIsInUiItem(laUiItem *ui, int x, int y){
  5216. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5217. return 1;
  5218. }
  5219. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5220. if (x < l || x > r || y < u || y > b) return 0;
  5221. return 1;
  5222. }
  5223. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5224. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5225. laUiItem *ui, *tui;
  5226. laBoxedTheme *bt;
  5227. laUiList *sub;
  5228. int CPB = 0;
  5229. if (!uil || (LimB && y > LimB)) return 0;
  5230. x += uil->PanX;
  5231. y += uil->PanY;
  5232. for (ui = uil->UiItems.pFirst; ui;){
  5233. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5234. if (ui->Type == &_LA_UI_CONDITION){
  5235. laConditionUiExtraData *cued = ui->Extra;
  5236. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5237. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5238. if (!cued->IsTrue){
  5239. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5240. }else{
  5241. ui = ui->Item.pNext;
  5242. }
  5243. continue;
  5244. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5245. ui = ui->Item.pNext;
  5246. continue;
  5247. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5248. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5249. if (cued->IsTrue) ui = cued->EndUi;
  5250. else
  5251. ui = ui->Item.pNext;
  5252. continue;
  5253. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5254. laConditionUiExtraData *cued = ui->Extra;
  5255. if (laIsInUiItem(ui, x, y)){
  5256. lstAppendPointer(LocalBuf, uil);
  5257. return ui;
  5258. }
  5259. if (ui->State == LA_UI_NORMAL){
  5260. cued->IsTrue = 0;
  5261. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5262. }else{
  5263. cued->IsTrue = 1;
  5264. ui = ui->Item.pNext;
  5265. }
  5266. continue;
  5267. }
  5268. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5269. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5270. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5271. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5272. if(!la_DetectSplit(ui->C, x)) Add=0;
  5273. }
  5274. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5275. }
  5276. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5277. if (ui->Page->HeightCoeff) CPB = ui->B;
  5278. else CPB = ui->Page->B;
  5279. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5280. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5281. lstAppendPointer(LocalBuf, uil);
  5282. return tui;
  5283. }
  5284. }else if (laIsInUiItem(ui, x, y)){
  5285. lstAppendPointer(LocalBuf, uil);return ui;
  5286. }
  5287. }
  5288. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5289. if (laIsInUiItem(ui, x, y)){
  5290. lstAppendPointer(LocalBuf, uil);
  5291. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5292. if(Deep){
  5293. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5294. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5295. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5296. lstAppendPointer(LocalBuf, iuil);
  5297. return tui;
  5298. }
  5299. }
  5300. }
  5301. }
  5302. return ui;
  5303. }
  5304. }
  5305. if (ui->Type == _LA_UI_CANVAS){
  5306. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5307. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5308. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5309. lstAppendPointer(LocalBuf, uil);
  5310. return tui;
  5311. }
  5312. }
  5313. }
  5314. if (laIsInUiItem(ui, x, y)){
  5315. lstAppendPointer(LocalBuf, uil);
  5316. return ui;
  5317. }
  5318. }
  5319. ui = ui->Item.pNext;
  5320. }
  5321. return 0;
  5322. }
  5323. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5324. laListHandle Locals={0};
  5325. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5326. while(lstPopPointer(&Locals));
  5327. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5328. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5329. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5330. if(pc==PCInOrOut) return ui;
  5331. }
  5332. return 0;
  5333. }
  5334. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5335. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5336. laUiItem *ui = uil->UiItems.pFirst;
  5337. laBoxedTheme *bt;
  5338. laUiList *tuil;
  5339. laUiList *sub;
  5340. int CPB = 0;
  5341. x += uil->PanX;
  5342. y += uil->PanY;
  5343. if (y > LimH) return uil;
  5344. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5345. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5346. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5347. return uil;
  5348. }
  5349. for (ui = uil->UiItems.pFirst; ui;){
  5350. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5351. if (ui->Type == &_LA_UI_CONDITION){
  5352. laConditionUiExtraData *cued = ui->Extra;
  5353. //la_StepExpression(cued->Expression);
  5354. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5355. if (!cued->IsTrue){
  5356. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5357. }else{
  5358. ui = ui->Item.pNext;
  5359. }
  5360. continue;
  5361. }
  5362. if (ui->Type == &_LA_UI_CONDITION_END){
  5363. ui = ui->Item.pNext;
  5364. continue;
  5365. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5366. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5367. if (cued->IsTrue) ui = cued->EndUi;
  5368. else
  5369. ui = ui->Item.pNext;
  5370. continue;
  5371. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5372. laConditionUiExtraData *cued = ui->Extra;
  5373. if (ui->State == LA_UI_NORMAL){
  5374. cued->IsTrue = 0;
  5375. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5376. }else{
  5377. cued->IsTrue = 1;
  5378. ui = ui->Item.pNext;
  5379. }
  5380. continue;
  5381. }
  5382. if (InToContainerUI && ui != Exception){
  5383. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5384. if (ContainerParent) (*ContainerParent) = uil;
  5385. if (ParentUi) *ParentUi = ui;
  5386. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5387. //if (y > LimH) return uil;
  5388. 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))){
  5389. return tuil;
  5390. }
  5391. }
  5392. }
  5393. }
  5394. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5395. if (ui->Page->HeightCoeff) CPB = ui->B;
  5396. else CPB = ui->Page->B;
  5397. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5398. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5399. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5400. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5401. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5402. if (ParentUi) *ParentUi = ui;
  5403. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5404. }
  5405. }
  5406. ui = ui->Item.pNext;
  5407. }
  5408. return uil;
  5409. }
  5410. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5411. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5412. laUiItem *ui = uil->UiItems.pFirst;
  5413. laBoxedTheme *bt;
  5414. laUiList *tuil;
  5415. laUiList *sub;
  5416. int CPB = 0;
  5417. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5418. x += uil->PanX;
  5419. y += uil->PanY;
  5420. if (y > LimH) return uil;
  5421. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5422. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5423. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5424. return uil;
  5425. }
  5426. for (ui = uil->UiItems.pFirst; ui;){
  5427. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5428. if (ui->Type == &_LA_UI_CONDITION){
  5429. laConditionUiExtraData *cued = ui->Extra;
  5430. //la_StepExpression(cued->Expression);
  5431. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5432. if (!cued->IsTrue){
  5433. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5434. }else{
  5435. ui = ui->Item.pNext;
  5436. }
  5437. continue;
  5438. }
  5439. if (ui->Type == &_LA_UI_CONDITION_END){
  5440. ui = ui->Item.pNext;
  5441. continue;
  5442. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5443. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5444. if (cued->IsTrue) ui = cued->EndUi;
  5445. else
  5446. ui = ui->Item.pNext;
  5447. continue;
  5448. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5449. laConditionUiExtraData *cued = ui->Extra;
  5450. if (ui->State == LA_UI_NORMAL){
  5451. cued->IsTrue = 0;
  5452. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5453. }else{
  5454. cued->IsTrue = 1;
  5455. ui = ui->Item.pNext;
  5456. }
  5457. continue;
  5458. }
  5459. if (InToContainerUI && ui != Exception){
  5460. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5461. if (ContainerParent) (*ContainerParent) = uil;
  5462. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5463. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5464. //if (y > LimH) return uil;
  5465. 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))){
  5466. return tuil;
  5467. }
  5468. }
  5469. }
  5470. }
  5471. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5472. if (ui->Page->HeightCoeff) CPB = ui->B;
  5473. else CPB = ui->Page->B;
  5474. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5475. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5476. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5477. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5478. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5479. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5480. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5481. }
  5482. }
  5483. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  5484. if (ui->Page->HeightCoeff) CPB = ui->B;
  5485. else
  5486. CPB = ui->Page->B;
  5487. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  5488. if (ScrollUil) *ScrollUil = ui->Page;
  5489. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5490. }
  5491. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5492. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5493. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5494. }
  5495. }
  5496. ui = ui->Item.pNext;
  5497. }
  5498. return uil;
  5499. }
  5500. int la_TestUiListMinumWidth(laUiList *uil){
  5501. laUiItem *ui, *tui;
  5502. laBoxedTheme *bt;
  5503. laUiList *sub;
  5504. int CPB = 0;
  5505. int W = 0;
  5506. int tW, sW, RowMode=0, rW;
  5507. void *Restore;
  5508. for (ui = uil->UiItems.pFirst; ui;){
  5509. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5510. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5511. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  5512. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5513. if (W < tW) W = tW;
  5514. }elif (ui->Type == _LA_UI_COLLECTION){
  5515. Restore = ui->PP.EndInstance;
  5516. tW = 0; sW = 0;
  5517. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5518. ui->PP.EndInstance = sub->Instance;
  5519. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  5520. if (sW > tW) tW = sW;
  5521. }
  5522. ui->PP.EndInstance = Restore;
  5523. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5524. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  5525. if (W < tW) W = tW;
  5526. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  5527. RowMode=1; rW=0;
  5528. }elif (ui->Type==&_LA_UI_ROW_END){
  5529. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  5530. }elif (ui->Type->GetMinWidth){
  5531. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  5532. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  5533. }
  5534. ui = ui->Item.pNext;
  5535. }
  5536. return W;
  5537. }
  5538. void la_InitLLVM(){
  5539. //LLVMLinkInMCJIT();
  5540. //LLVMInitializeNativeTarget();
  5541. //LLVMInitializeNativeAsmPrinter();
  5542. //LLVMInitializeNativeAsmParser();
  5543. // MAIN.llvmContext = LLVMGetGlobalContext();
  5544. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  5545. }
  5546. //==================================================================================================
  5547. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  5548. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  5549. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  5550. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  5551. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  5552. memFree(kmi);
  5553. }
  5554. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  5555. laKeyMapItem *kmi;
  5556. if (!km) return 0;
  5557. kmi = memAcquire(sizeof(laKeyMapItem));
  5558. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  5559. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  5560. }else{
  5561. strSafeSet(&kmi->Operation, Operation);
  5562. }
  5563. strSafeSet(&kmi->Instructions, ExtraInstructions);
  5564. kmi->SpecialKeyBits = SpecialKeyBits;
  5565. kmi->EventType = EventType;
  5566. kmi->Key = tolowerGuarded(Key);
  5567. kmi->SelectBase = SelectBase;
  5568. lstAppendItem(&km->Items, kmi);
  5569. return kmi;
  5570. }
  5571. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  5572. laKeyMapItem *kmi; int inv=0;
  5573. char *instructions;
  5574. if(e->Type==LA_MOUSEMOVE) return 0;
  5575. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5576. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5577. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5578. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5579. if (kmi->Operation)
  5580. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5581. else
  5582. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5583. inv = 1;
  5584. }
  5585. }
  5586. return inv;
  5587. }
  5588. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  5589. laKeyMapItem *kmi;
  5590. char *instructions;
  5591. int inv = 0; int lx = -1, ly = -1;
  5592. if(e->Type==LA_MOUSEMOVE) return 0;
  5593. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5594. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5595. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5596. if (e->Localized){
  5597. lx = e->x;
  5598. ly = e->y;
  5599. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  5600. e->Localized = 0;
  5601. }
  5602. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5603. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  5604. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  5605. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  5606. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  5607. }elif (kmi->Operation){
  5608. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5609. }else{
  5610. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5611. }
  5612. inv = 1;
  5613. if (lx >= 0){
  5614. e->x = lx;
  5615. e->y = ly;
  5616. e->Localized = 1;
  5617. }
  5618. }
  5619. }
  5620. return inv;
  5621. }
  5622. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  5623. void la_DestroyOperatorType(laOperatorType* at){
  5624. //if(at->PC) la_FreePropertyContainer(at->PC);
  5625. memFree(at);
  5626. }
  5627. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  5628. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  5629. uint32_t IconID, int ExtraMark){
  5630. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  5631. at->Identifier = ID;
  5632. at->Name = Name;
  5633. at->Description = Description;
  5634. at->Check = Check;
  5635. at->Invoke = Invoke;
  5636. at->Init = Init;
  5637. at->Exit = Exit;
  5638. at->Modal = Modal;
  5639. at->IconID = IconID;
  5640. at->ExtraMark = ExtraMark;
  5641. at->ParseArgs = la_DefaultOperatorParser;
  5642. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  5643. return at;
  5644. }
  5645. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  5646. ot->PC = memAcquire(sizeof(laPropContainer));
  5647. ot->PC->Identifier = ot->Identifier;
  5648. ot->PC->Hyper = HyperLevel;
  5649. return ot->PC;
  5650. }
  5651. laOperator *la_CreateOperator(laOperatorType *at){
  5652. laOperator *a = CreateNew(laOperator);
  5653. a->Type = at;
  5654. if (at->PC && at->PC->Props.pFirst){
  5655. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  5656. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  5657. a->PP.LastPs->p->SubProp = at->PC;
  5658. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  5659. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  5660. a->PP.LastPs->Type = U'.';
  5661. }
  5662. return a;
  5663. }
  5664. int la_OperatorTypeByID(laOperatorType *a, char *id){
  5665. return (!strcmp(a->Identifier, id));
  5666. }
  5667. laOperatorType *laGetOperatorType(const char *ID){
  5668. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5669. }
  5670. int laOperatorExistsT(laOperatorType* at){
  5671. if (!at) return 0;
  5672. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  5673. return 0;
  5674. }
  5675. int laOperatorExists(const char* ID){
  5676. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  5677. return laOperatorExistsT(at);
  5678. }
  5679. int la_OperatorExists(laOperator *ac){
  5680. if (!ac) return 0;
  5681. laOperator *a;
  5682. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  5683. return 0;
  5684. }
  5685. int la_UiOperatorExists(void *inst){
  5686. laOperator *a;
  5687. if (!inst) return 0;
  5688. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  5689. if (((laUiItem *)a->Instance) == inst){
  5690. return 1;
  5691. }
  5692. }
  5693. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5694. if (a->Instance == inst){
  5695. return 1;
  5696. }
  5697. }
  5698. return 0;
  5699. }
  5700. int la_OperatorPending(laOperator *target){
  5701. laOperator *a;
  5702. if (!target) return 0;
  5703. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5704. if (a == target){
  5705. return 1;
  5706. }
  5707. }
  5708. return 0;
  5709. }
  5710. void laSetOperatorLocalizer(void *ToPanel){
  5711. MAIN.ToPanel = ToPanel;
  5712. }
  5713. void la_DestroyConfirmData(laConfirmData **cd);
  5714. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  5715. laOperator *ai = (*a);
  5716. laOperator *ac = ((*a)->Child);
  5717. void *Ret = 0;
  5718. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using){
  5719. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  5720. }
  5721. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  5722. if ((*a)->PP.LastPs){
  5723. memFree((*a)->PP.LastPs->p);
  5724. memFree((*a)->PP.LastPs);
  5725. }
  5726. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  5727. la_SetPropMathcerContext((*a)->OperatorPanel);
  5728. MAIN.CurrentPanel = (*a)->OperatorPanel;
  5729. laDestroySinglePanel((*a)->OperatorPanel,0);
  5730. }
  5731. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  5732. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  5733. lstClearPointer(&(*a)->LocalUiLists);
  5734. if (Operators){
  5735. Ret = ai->Item.pNext;
  5736. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  5737. else
  5738. lstRemoveItem(Operators, *a);
  5739. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  5740. if (ai->Child == (*a)) ai->Child = 0;
  5741. }
  5742. }
  5743. strSafeDestroy(&(*a)->RuntimeHint);
  5744. free(*a);
  5745. return Ret;
  5746. }
  5747. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  5748. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5749. if (!at) return 0;
  5750. if (!at->Check) return 1;
  5751. return (at->Check(This, Instructions));
  5752. }
  5753. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  5754. if (!at) return 0;
  5755. if (!at->Check) return 1;
  5756. return (at->Check(This, Instructions));
  5757. }
  5758. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5759. laPropPack FakePP = {0};
  5760. laPropStep FakePs = {0};
  5761. if (!at) return 0;
  5762. if (!at->Check) return 1;
  5763. FakePP.LastPs = &FakePs;
  5764. FakePP.Go = FakePP.LastPs;
  5765. FakePP.LastPs->p = This->LastPs->p;
  5766. FakePP.LastPs->UseInstance = This->EndInstance;
  5767. FakePP.EndInstance = Real_FromInstance;
  5768. FakePP.LastIndex = This->LastIndex;
  5769. return (at->Check(&FakePP, Instructions));
  5770. }
  5771. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5772. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5773. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  5774. }
  5775. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  5776. laOperator *a, *f = From;
  5777. int rev;
  5778. if (!f && e&&e->Localized) return -1;
  5779. a = la_CreateOperator(at);
  5780. a->ToPanel = MAIN.ToPanel;
  5781. a->This = This;
  5782. a->ExtraInstructions = args;
  5783. strMakeInstructions(&a->ExtraInstructionsP, args);
  5784. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5785. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5786. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  5787. la_DestroyOperator(&a, 0, 0);
  5788. return LA_CANCELED;
  5789. }
  5790. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5791. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  5792. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5793. e->Localized = 1;
  5794. }
  5795. if (e&&e->Localized){
  5796. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  5797. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5798. e->Localized = 0;
  5799. }else{
  5800. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5801. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5802. }
  5803. }
  5804. if (From) f->Child = a;
  5805. a->Using = 1;
  5806. if (at->Init) at->Init(a);
  5807. rev = at->Invoke(a, e);
  5808. a->Using = 0;
  5809. if (rev & LA_FINISH){
  5810. a->StopNow = 1; if(From)From->Child=0;
  5811. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5812. }
  5813. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5814. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5815. a->State = rev;
  5816. a->PP.EndInstance = a->CustomData;
  5817. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  5818. }else
  5819. la_DestroyOperator(&a, 0, 0);
  5820. return rev;
  5821. }
  5822. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  5823. laOperatorType *at; laOperator *a, *f = From;
  5824. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5825. if (!at) return -1;
  5826. return laInvokeP(From,at,e,This,args,args2);
  5827. }
  5828. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  5829. laOperator *a, *f = From;
  5830. int rev;
  5831. laPropPack *created;
  5832. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  5833. created = memAcquireSimple(sizeof(laPropPack));
  5834. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  5835. created->Go = created->LastPs;
  5836. created->LastPs->p = OrigionalThis->LastPs->p;
  5837. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  5838. created->EndInstance = FromInstance;
  5839. created->LastIndex = OrigionalThis->LastIndex;
  5840. a = la_CreateOperator(at);
  5841. a->ToPanel = MAIN.ToPanel;
  5842. a->This = created;
  5843. a->CreatedThis = created;
  5844. a->ExtraInstructions = args;
  5845. strMakeInstructions(&a->ExtraInstructionsP, args);
  5846. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5847. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5848. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  5849. la_DestroyOperator(&a, 0, 0);
  5850. return LA_CANCELED;
  5851. }
  5852. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5853. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5854. if (From) f->Child = a;
  5855. a->Using = 1;
  5856. if (at->Init) at->Init(a);
  5857. rev = at->Invoke(a, e);
  5858. a->Using = 0;
  5859. if (rev & LA_FINISH){
  5860. a->StopNow = 1; if(From)From->Child=0;
  5861. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5862. }
  5863. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5864. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5865. a->State = rev;
  5866. a->PP.EndInstance = a->CustomData;
  5867. }else
  5868. la_DestroyOperator(&a, 0, 0);
  5869. return rev;
  5870. }
  5871. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5872. laOperator *a, *f = From;
  5873. int rev;
  5874. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  5875. a = la_CreateOperator(at);
  5876. a->Instance = inst;
  5877. a->ToPanel = MAIN.ToPanel;
  5878. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  5879. if (From) f->Child = a;
  5880. a->Using = 1;
  5881. if (at->Init) at->Init(a);
  5882. rev = at->Invoke(a, e);
  5883. a->Using = 0;
  5884. if (rev & LA_FINISH){
  5885. a->StopNow = 1; if(From)From->Child=0;
  5886. }
  5887. if (rev & LA_BLOCK){
  5888. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5889. a->State = rev;
  5890. }else la_DestroyOperator(&a, 0, 0);
  5891. DEB = a;
  5892. return rev;
  5893. }
  5894. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5895. laOperatorType *at;
  5896. laOperator *a, *f = From;
  5897. if (la_UiOperatorExists(inst)) return -1;
  5898. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  5899. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  5900. }
  5901. void laRequestDelayEvent(real Seconds){
  5902. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  5903. int la_UiStillInService(void *UiInstance){
  5904. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  5905. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  5906. if (ai->Instance == UiInstance) return 1;
  5907. }
  5908. return 0;
  5909. }
  5910. void la_StopUiOperatorService(void *UiInstance){
  5911. laOperator *ai, *dai, *NextAi;
  5912. if (!MAIN.CurrentWindow) return;
  5913. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5914. NextAi = ai->Item.pNext;
  5915. if (ai->Instance == UiInstance){
  5916. if (ai->Child){
  5917. la_StopUiOperatorService(ai->Child->Instance);
  5918. ai->Child = 0;
  5919. }
  5920. laOperator *dai = ai;
  5921. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  5922. continue;
  5923. }
  5924. }
  5925. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5926. NextAi = ai->Item.pNext;
  5927. if (ai->Instance == UiInstance){
  5928. if (ai->Instance == ai->ToPanel){
  5929. //laHidePanelWithDissoveEffect(ai->ToPanel);
  5930. //ai->ToPanel->LaterDestroy = 1;
  5931. }
  5932. if (ai->Child && la_OperatorExists(ai->Child)){
  5933. la_StopUiOperatorService(ai->Child->Instance);
  5934. //ai->Child = 0;
  5935. }
  5936. if (!ai->Using){
  5937. laOperator *dai = ai;
  5938. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5939. }else
  5940. ai->StopNow = 1;
  5941. }
  5942. }
  5943. }
  5944. void la_StopAllOperators(){
  5945. laOperator *ai, *dai, *NextAi;
  5946. if (!MAIN.CurrentWindow) return;
  5947. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5948. NextAi = ai->Item.pNext;
  5949. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  5950. continue;
  5951. }
  5952. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5953. NextAi = ai->Item.pNext;
  5954. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  5955. laHidePanelWithDissoveEffect(ai->ToPanel);
  5956. ai->ToPanel->LaterDestroy = 1;
  5957. }
  5958. if (!ai->Using){
  5959. laOperator *dai = ai;
  5960. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5961. }else ai->StopNow = 1;
  5962. }
  5963. }
  5964. void la_DestroyConfirmData(laConfirmData **cd){
  5965. if((!cd)||!(*cd)) return;
  5966. if ((*cd)->CustomData) (*cd)->Destroy((*cd)->CustomData);
  5967. if ((*cd)->StrData) free((*cd)->StrData);
  5968. FreeMem((*cd));
  5969. (*cd) = 0;
  5970. }
  5971. void laConfirmInt(laOperator *a, int Data, int mode){
  5972. laOperator *ai = a;
  5973. laConfirmData *cd = CreateNew(laConfirmData);
  5974. cd->IData = Data;
  5975. cd->Mode = mode;
  5976. ai->NextConfirmData = cd;
  5977. laRetriggerOperators();
  5978. }
  5979. void laConfirmFloat(laOperator *a, real Data, int mode){
  5980. laOperator *ai = a;
  5981. laConfirmData *cd = CreateNew(laConfirmData);
  5982. cd->FData = Data;
  5983. cd->Mode = mode;
  5984. ai->NextConfirmData = cd;
  5985. laRetriggerOperators();
  5986. }
  5987. void laConfirmString(laOperator *a, char *Str, int mode){
  5988. laOperator *ai = a;
  5989. laConfirmData *cd = CreateNew(laConfirmData);
  5990. int len = strlen(Str);
  5991. char *buf = calloc(len + 1, sizeof(char));
  5992. strcpy(buf, Str);
  5993. cd->StrData = buf;
  5994. cd->Mode = mode;
  5995. cd->Destroy = free;
  5996. ai->NextConfirmData = cd;
  5997. laRetriggerOperators();
  5998. }
  5999. int laConfirmSameDataIfAny(laOperator *a){
  6000. laOperator *ai = a;
  6001. laConfirmData *cd;
  6002. char *buf = 0;
  6003. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6004. cd = CreateNew(laConfirmData);
  6005. if (ai->ConfirmData->StrData){
  6006. int len = strlen(ai->ConfirmData->StrData);
  6007. buf = calloc(len + 1, sizeof(char));
  6008. strcpy(buf, ai->ConfirmData->StrData);
  6009. }
  6010. //cd->CustomData = cd->CustomData;
  6011. cd->IData = ai->ConfirmData->IData;
  6012. cd->FData = ai->ConfirmData->FData;
  6013. cd->StrData = buf;
  6014. cd->Mode = ai->ConfirmData->Mode;
  6015. cd->Destroy = ai->ConfirmData->Destroy;
  6016. ai->NextConfirmData = cd;
  6017. laRetriggerOperators();
  6018. return 1;
  6019. }
  6020. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6021. laOperator *ai = a;
  6022. laConfirmData *cd = CreateNew(laConfirmData);
  6023. cd->CustomData = UserData;
  6024. cd->Mode = mode;
  6025. cd->Destroy = Destroy;
  6026. ai->NextConfirmData = cd;
  6027. laRetriggerOperators();
  6028. }
  6029. int laGetConfirmMode(laOperator *a){
  6030. return ((laOperator *)a)->ConfirmData->Mode;
  6031. }
  6032. int laGetConfirmInt(laOperator *a){
  6033. laOperator *ai = a;
  6034. int rev = ai->ConfirmData->IData;
  6035. la_DestroyConfirmData(&ai->ConfirmData);
  6036. ai->ConfirmData = 0;
  6037. return rev;
  6038. }
  6039. real laGetConfirmFloat(laOperator *a){
  6040. laOperator *ai = a;
  6041. real rev = ai->ConfirmData->FData;
  6042. la_DestroyConfirmData(&ai->ConfirmData);
  6043. ai->ConfirmData = 0;
  6044. return rev;
  6045. }
  6046. void laGetConfirmString(laOperator *a, char *buf){
  6047. laOperator *ai = a;
  6048. strcpy(buf, ai->ConfirmData->StrData);
  6049. la_DestroyConfirmData(&ai->ConfirmData);
  6050. ai->ConfirmData = 0;
  6051. }
  6052. void *laGetConfirmUserData(laOperator *a){
  6053. laOperator *ai = a;
  6054. return ai->ConfirmData->CustomData;
  6055. }
  6056. void laFinalizeOperators(){
  6057. laOperatorType *at;
  6058. laListHandle *lst;
  6059. int i;
  6060. for (i = 0; i < 256; i++){
  6061. lst = &MAIN.OperatorTypeHash.Entries[i];
  6062. for (at = lst->pFirst; at; at = at->Item.pNext){
  6063. if (at->PC && at->PC->Props.pFirst){
  6064. lstAppendItem(&MAIN.PropContainers, at->PC);
  6065. }
  6066. }
  6067. }
  6068. }
  6069. //=================
  6070. #ifdef __linux__
  6071. static void la_RecordWacomMotions(XIRawEvent *event)
  6072. {
  6073. double *valuator = event->valuators.values;
  6074. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6075. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6076. //SYSWINDOW root_return, child_return;
  6077. //int root_x_return, root_y_return;
  6078. //int win_x_return, win_y_return;
  6079. //unsigned int mask_return;
  6080. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6081. // &root_x_return, &root_y_return,
  6082. // &win_x_return, &win_y_return,
  6083. // &mask_return);
  6084. //
  6085. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6086. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6087. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6088. real x=valuator[3],y=valuator[4];
  6089. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6090. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6091. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6092. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6093. if(XIMaskIsSet(event->valuators.mask, 5)){
  6094. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6095. printf("a %lf\n",angle);
  6096. }else{ MAIN.StylusTwist=0; }
  6097. MAIN.IsPen=1;
  6098. }
  6099. #endif
  6100. #ifdef _WIN32
  6101. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6102. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6103. static uint32_t ch = 0; static int lead = 0;
  6104. static wchar_t buf[10] = { 0 }; int adv;
  6105. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6106. short wheelmark = 0;
  6107. int WheelDir = 0;
  6108. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6109. POINTER_PEN_INFO penInfo; POINTER_TOUCH_INFO touchInfo;
  6110. POINT point;
  6111. PACKET pkt;
  6112. static POINT ptOld, ptNew;
  6113. static UINT prsOld, prsNew;
  6114. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6115. switch (message) {
  6116. case WM_PAINT:
  6117. //SwapBuffers(GetDC(hwnd));
  6118. break;
  6119. case WM_MOUSEMOVE:
  6120. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6121. MAIN.IsPen = 0;
  6122. break;
  6123. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6124. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6125. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6126. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6127. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6128. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6129. case WM_MOUSEWHEEL:
  6130. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6131. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6132. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6133. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6134. break;
  6135. case WT_PACKET:
  6136. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6137. if (gpWTPacket((HCTX)lparam, wparam, &pkt)){
  6138. MAIN.StylusPressure = (real)pkt.pkNormalPressure/MAIN.WinTabMaxPenPressure;
  6139. real angle = (real)pkt.pkOrientation.orAzimuth / 3600*TNS_PI*2+TNS_PI/2;
  6140. MAIN.StylusOrientation = angle; MAIN.StylusDeviation=rad((90.0f-(real)pkt.pkOrientation.orAltitude/10.0f));
  6141. real tw=(real)pkt.pkOrientation.orTwist; tw=rad(tw/10);
  6142. MAIN.StylusTwist = tw;
  6143. MAIN.EraserDeviation=MAIN.StylusDeviation;MAIN.EraserOrientation=MAIN.StylusOrientation;
  6144. MAIN.EraserPressure=MAIN.StylusPressure;
  6145. MAIN.IsPen = 1; MAIN.PointerIsEraser=((pkt.pkStatus & TPS_INVERT)==TPS_INVERT);
  6146. }
  6147. break;
  6148. case WM_SYSCOMMAND:
  6149. switch (wparam) {
  6150. case SC_MAXIMIZE:
  6151. case SC_RESTORE:
  6152. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6153. break;
  6154. case SC_KEYMENU:
  6155. return 0;
  6156. }
  6157. break;
  6158. case WM_SIZE:
  6159. if (wparam == SIZE_MINIMIZED) break;
  6160. case WM_MOVE: /* And size */
  6161. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6162. break;
  6163. case WM_SETCURSOR:
  6164. if(MAIN.CurrentCursor) return 1;
  6165. break;
  6166. case WM_POINTERUPDATE:
  6167. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6168. pointerId = GET_POINTERID_WPARAM(wparam);
  6169. pointerType = PT_POINTER;
  6170. if(!GetPointerType(pointerId, &pointerType)){
  6171. pointerType = PT_POINTER;
  6172. printf("is pointer\n");
  6173. }
  6174. if(pointerType == PT_PEN){
  6175. if(GetPointerPenInfo(pointerId, &penInfo)){
  6176. point.x = penInfo.pointerInfo.ptPixelLocation.x; point.y = penInfo.pointerInfo.ptPixelLocation.y;
  6177. ScreenToClient(hwnd, &point);
  6178. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo.pressure / 1024; MAIN.PointerIsEraser = 0;
  6179. }
  6180. }
  6181. else if (pointerType == PT_TOUCH){
  6182. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6183. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6184. ScreenToClient(hwnd, &point);
  6185. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6186. }
  6187. }
  6188. break;
  6189. case WM_SYSKEYDOWN:
  6190. if (lparam & 0x40000000) break;
  6191. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6192. break;
  6193. case WM_KEYDOWN:
  6194. if (lparam & 0x40000000) break;
  6195. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6196. break;
  6197. case WM_KEYUP:
  6198. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6199. break;
  6200. case WM_SYSKEYUP:
  6201. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6202. break;
  6203. case WM_UNICHAR:
  6204. la_SendInputEvent(hwnd, wparam);
  6205. break;
  6206. case WM_IME_CHAR:
  6207. la_SendInputEvent(hwnd, wparam);
  6208. return 0;
  6209. case WM_CHAR:
  6210. la_SendInputEvent(hwnd, wparam);
  6211. break;
  6212. case WM_SHOWWINDOW:
  6213. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6214. break;
  6215. case WM_CLOSE:
  6216. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6217. break;
  6218. default:
  6219. return DefWindowProc(hwnd, message, wparam, lparam);
  6220. }
  6221. return DefWindowProc(hwnd, message, wparam, lparam);
  6222. }
  6223. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6224. return DefWindowProc(hwnd, message, wparam, lparam);
  6225. }
  6226. #endif
  6227. int la_UpdateOperatorHints(laWindow* w){
  6228. laSafeString* ss=0;
  6229. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6230. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6231. }
  6232. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6233. }else{
  6234. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6235. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6236. }
  6237. strSafeDestroy(&ss);
  6238. }
  6239. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6240. laOperator *a, *NextA = 0;
  6241. int Result = 0;
  6242. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6243. a = Operators->pFirst;
  6244. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6245. while (1){
  6246. if (!a) break;
  6247. if (a->StopNow){
  6248. NextA = a->Item.pNext;
  6249. if (a->Type->Exit) a->Type->Exit(a, Result);
  6250. ConfirmData = a->NextConfirmData;
  6251. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6252. NextConfirmData = ConfirmData;
  6253. a->ConfirmData = 0;
  6254. a->NextConfirmData = 0;
  6255. la_DestroyOperator(&a, Operators, 0);
  6256. a = NextA;
  6257. if (a){
  6258. a->ConfirmData = NextConfirmData;
  6259. }
  6260. continue;
  6261. }
  6262. a->Using = 1;
  6263. la_SetPropMathcerContext(a->ToPanel);
  6264. laSetOperatorLocalizer(a->ToPanel);
  6265. MAIN.CurrentPanel = a->ToPanel;
  6266. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6267. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6268. e->Localized = 1;
  6269. }
  6270. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6271. //la_PrintOperatorStack();
  6272. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6273. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6274. e->Localized = 0;
  6275. }
  6276. la_SetPropMathcerContext(0);
  6277. laSetOperatorLocalizer(0);
  6278. MAIN.CurrentPanel = 0;
  6279. a->Using = 0;
  6280. if (Result & LA_PASS_ON){
  6281. laConfirmSameDataIfAny(a);
  6282. NextA = a->Item.pNext;
  6283. }else{
  6284. NextA = 0;
  6285. if (a->NextConfirmData){
  6286. la_DestroyConfirmData(&a->NextConfirmData);
  6287. }
  6288. }
  6289. ConfirmData = a->NextConfirmData;
  6290. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6291. NextConfirmData = ConfirmData;
  6292. a->ConfirmData = 0;
  6293. a->NextConfirmData = 0;
  6294. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6295. if (a->Type->Exit) a->Type->Exit(a, Result);
  6296. la_DestroyOperator(&a, Operators, 0);
  6297. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6298. }
  6299. a = NextA;
  6300. if (a){
  6301. a->ConfirmData = NextConfirmData;
  6302. }
  6303. }
  6304. return 1;
  6305. }
  6306. int la_HandleEvents(laWindow *w){
  6307. laEvent *e, *NextE;
  6308. laOperator *a;
  6309. laThreadNotifier *tn;
  6310. MAIN.CurrentWindow=w;
  6311. //laSpinLock(&MAIN.csNotifier);
  6312. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6313. //laSpinUnlock(&MAIN.csNotifier);
  6314. laNotifyUsers(tn->Path);
  6315. FreeMem(tn);
  6316. //if (MAIN.ThreadNotifiers.pFirst)
  6317. //laSpinLock(&MAIN.csNotifier);
  6318. }
  6319. //laSpinUnlock(&MAIN.csNotifier);
  6320. while (1){
  6321. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6322. while (w->EventList.pFirst){
  6323. while (w->PendingOperators.pLast){
  6324. a = w->PendingOperators.pLast;
  6325. if (a->OperatorPanel){
  6326. laSetOperatorLocalizer(a->OperatorPanel);
  6327. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6328. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6329. }
  6330. lstRemoveItem(&w->PendingOperators, a);
  6331. lstPushItem(&w->Operators, a);
  6332. }
  6333. e = lstPopItem(&w->EventList);
  6334. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6335. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6336. memFree(e);
  6337. }
  6338. if (!MAIN.ReTriggerOperators) break;
  6339. }
  6340. la_UpdateOperatorHints(w);
  6341. return 1;
  6342. }
  6343. int la_AllowInput(uint32_t ch){
  6344. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6345. return 0;
  6346. }
  6347. int laCopyToClipboard(unsigned char * text){
  6348. #ifdef __linux__
  6349. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6350. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6351. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6352. strSafeSet(&MAIN.CopyPending, text);
  6353. #endif
  6354. }
  6355. int la_ProcessSysMessage(){
  6356. int SendDelay = 0, SendIdle = 0;
  6357. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6358. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6359. #ifdef __linux__
  6360. XEvent e;
  6361. int type;
  6362. int InputCount = 0, CharCount=0;
  6363. KeySym InputKeysym = 0;
  6364. Status InputStatus = 0;
  6365. laWindow* wnd ;
  6366. while(XPending(MAIN.dpy)){
  6367. XGenericEventCookie *cookie = &e.xcookie;
  6368. XNextEvent(MAIN.dpy, &e);
  6369. if (XFilterEvent(&e, None)) continue;
  6370. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6371. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6372. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6373. XFreeEventData(MAIN.dpy, cookie); continue;
  6374. }
  6375. switch(e.type){
  6376. case ConfigureNotify:
  6377. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6378. break;
  6379. case Expose:
  6380. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6381. if(!wnd) break;
  6382. laRefreshWindow(wnd);
  6383. break;
  6384. case MotionNotify:
  6385. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6386. MAIN.IsPen=0;
  6387. break;
  6388. case ButtonPress:
  6389. type=LA_MOUSEDOWN;
  6390. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6391. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6392. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6393. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  6394. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  6395. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6396. MAIN.IsPen=0;
  6397. break;
  6398. case ButtonRelease:
  6399. type=LA_MOUSEUP;
  6400. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6401. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6402. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6403. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6404. MAIN.IsPen=0;
  6405. break;
  6406. case KeyPress:
  6407. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  6408. MAIN.InputBuf[InputCount]=0;
  6409. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  6410. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  6411. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  6412. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6413. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6414. #ifdef DEBUG
  6415. printf("pressed KEY: %d\n", (int)InputKeysym);
  6416. #endif
  6417. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  6418. }
  6419. break;
  6420. case KeyRelease:
  6421. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6422. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  6423. }
  6424. case ClientMessage:
  6425. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  6426. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  6427. }
  6428. break;
  6429. case SelectionNotify:
  6430. if(e.xselection.selection != MAIN.bufid) continue;
  6431. if (e.xselection.property){
  6432. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  6433. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  6434. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  6435. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  6436. else if(result) {
  6437. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  6438. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  6439. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6440. }
  6441. XFree(result);
  6442. return True;
  6443. }
  6444. case SelectionRequest:
  6445. if(!MAIN.CopyPending){ break; }
  6446. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  6447. if (e.xselectionrequest.selection != MAIN.selection) break;
  6448. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  6449. XSelectionEvent ev = {0};
  6450. int R = 0;
  6451. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  6452. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  6453. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  6454. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  6455. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  6456. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  6457. else if (ev.target == MAIN.UTF8)
  6458. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  6459. else ev.property = None;
  6460. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  6461. break;
  6462. case SelectionClear:
  6463. break;
  6464. default:
  6465. break;
  6466. }
  6467. }
  6468. #endif //linux
  6469. #ifdef _WIN32
  6470. MSG msg; int Processed = 0;
  6471. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  6472. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  6473. TranslateMessage(&msg); DispatchMessage(&msg);
  6474. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  6475. };
  6476. if(!MAIN.Windows.pFirst){ return 0; }
  6477. #endif
  6478. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6479. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  6480. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  6481. }
  6482. return 1;
  6483. };
  6484. void la_PrintOperatorStack(){
  6485. laWindow *w = MAIN.CurrentWindow;
  6486. laOperator *a;
  6487. printf("\n");
  6488. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  6489. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  6490. a->Type->Identifier, a->Instance,
  6491. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  6492. }
  6493. }
  6494. void la_DrawWindow(laWindow *w){
  6495. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  6496. MAIN.CurrentWindow = w;
  6497. la_WindowDefDraw(w, 0);
  6498. }
  6499. int laFinalize(){
  6500. if(!laValidateProperties()){ laShutoff(0); return 0; }
  6501. laUiTemplate* uit;
  6502. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  6503. return 1;
  6504. }
  6505. void la_PreFrame(){
  6506. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  6507. la_AnimationPreFrame();
  6508. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  6509. }
  6510. void la_PostFrame(){
  6511. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  6512. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  6513. }
  6514. void laMainLoop(){
  6515. laWindow *w = MAIN.Windows.pFirst, *NextW;
  6516. laTimeRecorder FrameStartTime, FrameEndTime;
  6517. time_t t1, t2;
  6518. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  6519. static int a = 0;
  6520. if(!laFinalize()) return;
  6521. laSetWindowCursor(LA_ARROW);
  6522. MAIN.DelayTriggered=1;
  6523. while (1){
  6524. laRecordTime(&FrameStartTime);
  6525. if(MAIN.GLDebugNeedsUpdate){
  6526. #ifdef __linux__
  6527. tnsContextMakeCurrent(MAIN.glc,MAIN.win);
  6528. #endif
  6529. #ifdef _WIN32
  6530. tnsContextMakeCurrent(MAIN.glc,MAIN.hdc);
  6531. #endif
  6532. la_SetCurrentGLContextDebug(); MAIN.GLDebugNeedsUpdate=0;
  6533. }
  6534. la_PreFrame();
  6535. if(!la_ProcessSysMessage()){ return; }
  6536. la_UpdateControllerStatus();
  6537. if(MAIN.GraphNeedsRebuild){ la_RebuildInputMapping(); MAIN.GraphNeedsRebuild = 0; }
  6538. if(MAIN.InputNeedsEval){ la_RunInputMapping(); }
  6539. for (w=MAIN.Windows.pFirst;w;w = NextW){
  6540. NextW = w->Item.pNext;
  6541. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  6542. }
  6543. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  6544. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6545. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  6546. la_DrawWindow(w);
  6547. }
  6548. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6549. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  6550. #ifdef __linux__
  6551. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  6552. #endif
  6553. #ifdef _WIN32
  6554. SwapBuffers(w->hdc);
  6555. #endif
  6556. }
  6557. la_PostFrame();
  6558. //t2 = clock();
  6559. laRecordTime(&FrameEndTime);
  6560. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  6561. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  6562. if (Pause > 0){
  6563. int us = Pause * 1000000.0;
  6564. usleep(us);
  6565. }
  6566. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  6567. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  6568. la_AnimationPostFrame();
  6569. }
  6570. }