*/}}

la_kernel.c 282 KB

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