*/}}

la_kernel.c 281 KB

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