*/}}

la_kernel.c 277 KB

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