*/}}

la_kernel.c 291 KB

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