*/}}

la_kernel.c 241 KB

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