*/}}

la_kernel.c 315 KB

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