*/}}

la_kernel.c 291 KB

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