*/}}

la_kernel.c 252 KB

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