*/}}

la_kernel.c 302 KB

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