*/}}

la_kernel.c 265 KB

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