*/}}

la_kernel.c 226 KB

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