*/}}

la_kernel.c 277 KB

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