*/}}

la_kernel.c 226 KB

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