*/}}
1
0

la_kernel.c 227 KB

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