*/}}
1
0

la_kernel.c 277 KB

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