*/}}
1
0

la_kernel.c 281 KB

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