*/}}

la_kernel.c 338 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918
  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 <jni.h>
  53. #include <android/log.h>
  54. #include <android/native_activity.h>
  55. #include <android/native_window.h>
  56. #include <android/native_window_jni.h>
  57. #include <android_native_app_glue.h>
  58. #include <android/window.h>
  59. #include <android/asset_manager.h>
  60. #include <android/input.h>
  61. #include <android/keycodes.h>
  62. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  63. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  64. static int android_read(void *cookie, char *buf, int size);
  65. static int android_write(void *cookie, const char *buf, int size);
  66. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  67. static int android_close(void *cookie);
  68. void la_InitAndroidPlatform(struct android_app *app);
  69. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  70. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  71. void la_InitAndroidPlatform(struct android_app *app);
  72. #endif
  73. LA MAIN={0};
  74. extern tnsMain *T;
  75. int deb = 0;
  76. laOperator *DEB;
  77. laColumn *DEBUG_C;
  78. #ifdef _WIN32
  79. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  80. #else
  81. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  82. #endif
  83. #ifdef LA_LINUX
  84. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  85. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  86. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  87. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  88. #endif
  89. #ifdef LA_LINUX
  90. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  91. int i;
  92. for (i = 0; i < num_classes; i++) {
  93. if (classes[i]->type == XIValuatorClass) {
  94. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  95. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  96. logPrint(" Range: %f - %f\n", v->min, v->max);
  97. logPrint(" Resolution: %d units/m\n", v->resolution);
  98. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  99. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  100. }
  101. }
  102. }
  103. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  104. XIDeviceInfo *info, *dev;
  105. int i, ndevices;
  106. dev = XIQueryDevice(display, deviceid, &ndevices);
  107. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  108. mask->deviceid = deviceid;
  109. mask->mask_len = XIMaskLen(XI_RawMotion);
  110. mask->mask=memAcquireSimple(mask->mask_len);
  111. memset(mask->mask, 0, mask->mask_len);
  112. XISetMask(mask->mask, XI_RawMotion);
  113. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  114. int FoundMax=0;
  115. for (i = 0; i < dev->num_classes; i++) {
  116. if (dev->classes[i]->type == XIValuatorClass) {
  117. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  118. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  119. }
  120. }
  121. if(!FoundMax){*max_pressure=65535;}
  122. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  123. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  124. XIFreeDeviceInfo(dev);
  125. }
  126. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  127. int axis=0;
  128. for (int i = 0; i < dev->num_classes; i++) {
  129. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  130. }
  131. return axis>=3;
  132. }
  133. #define LA_G_STYLUS(dev) \
  134. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  135. #define LA_G_ERASER \
  136. (!MAIN.WacomDeviceEraser)
  137. void la_ScanWacomDevices(Display *display, int deviceid){
  138. XIDeviceInfo *info, *dev;
  139. int ndevices;
  140. int i; char * word;
  141. int _event, _error;
  142. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  143. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  144. }
  145. info = XIQueryDevice(display, deviceid, &ndevices);
  146. for(i = 0; i < ndevices; i++) {
  147. dev = &info[i]; strToLower(dev->name);
  148. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  149. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  150. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  151. word = strtok (dev->name," ");
  152. while (1) {
  153. word = strtok (NULL, " "); if (!word) break;
  154. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  155. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  156. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  157. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  158. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  159. }
  160. }
  161. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  162. logPrintNew("Found wacom devices:\n");
  163. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  164. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  165. }else{
  166. logPrintNew("No wacom pen device connected.\n");
  167. }
  168. XIFreeDeviceInfo(info);
  169. }
  170. void laHideCursor(){
  171. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  172. }
  173. void laShowCursor(){
  174. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  175. }
  176. void la_XErrorHandler(Display *display, XErrorEvent *event){
  177. char buf[512];
  178. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  179. printf("X Error:\n%s\n",buf);
  180. }
  181. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  182. XSetWindowAttributes swa;
  183. XWindowAttributes wa;
  184. swa.event_mask =
  185. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  186. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  187. swa.colormap = MAIN.cmap;
  188. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  189. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  190. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  191. if(x>0||y>0){
  192. XSizeHints my_hints = {0};
  193. my_hints.flags = PPosition;
  194. my_hints.x = x; my_hints.y = y;
  195. XSetNormalHints(MAIN.dpy, win, &my_hints);
  196. }
  197. XStoreName(MAIN.dpy, win, title);
  198. #ifdef LA_USE_GLES
  199. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  200. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  201. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  202. EGLSurface* surf=egl_surf;
  203. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  204. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  205. tnsContextMakeCurrent((*r_glc),win,(*surf));
  206. #else
  207. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  208. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  209. printf("\n\tcannot create gl context\n\n"); exit(0);
  210. }
  211. tnsContextMakeCurrent((*r_glc),win,0);
  212. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  213. #endif
  214. XSetLocaleModifiers("");
  215. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  216. if(!MAIN.im){
  217. XSetLocaleModifiers("@im=local");
  218. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  219. }
  220. if(!MAIN.im){
  221. XSetLocaleModifiers("@im=none");
  222. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  223. }
  224. if(!MAIN.im){
  225. XSetLocaleModifiers("@im=");
  226. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  227. }
  228. if(!MAIN.im){
  229. logPrint("Can't open a input method.\n");
  230. }
  231. if(MAIN.im){
  232. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  233. XSetICFocus(MAIN.ic);
  234. }
  235. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  236. XSetClassHint(MAIN.dpy, win, &ch);
  237. #define _NET_WM_STATE_ADD 1
  238. if(w<0&&h<0){
  239. XEvent xev;
  240. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  241. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  242. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  243. memset(&xev, 0, sizeof(xev));
  244. xev.type = ClientMessage;
  245. xev.xclient.window = win;
  246. xev.xclient.message_type = wm_state;
  247. xev.xclient.format = 32;
  248. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  249. xev.xclient.data.l[1] = max_horz;
  250. xev.xclient.data.l[2] = max_vert;
  251. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  252. }
  253. return win;
  254. };
  255. void la_DestroySystemWindowX11(laWindow* w) {
  256. tnsContextMakeCurrent(0,0,0);
  257. tnsDeleteContext(w->glc);
  258. #ifdef LA_USE_GLES
  259. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  260. #endif
  261. XDestroyWindow(MAIN.dpy, w->win);
  262. };
  263. #endif //linux
  264. #ifdef _WIN32
  265. #include <msgdef.h>
  266. #include <wintab.h>
  267. #include <wintab_utils.h>
  268. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  269. #define PACKETMODE PK_BUTTONS
  270. #include <pktdef.h>
  271. void la_OpenWacomWinTab(HWND hwnd){
  272. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  273. static LOGCONTEXT glogContext = { 0 };
  274. HCTX hctx = NULL;
  275. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  276. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  277. glogContext.lcOptions |= CXO_SYSTEM;
  278. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  279. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  280. assert(glogContext.lcOptions & CXO_SYSTEM);
  281. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  282. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  283. glogContext.lcPktData = PACKETDATA;
  284. glogContext.lcPktMode = PACKETMODE;
  285. glogContext.lcMoveMask = PACKETDATA;
  286. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  290. assert(wWTInfoRetVal == sizeof(AXIS));
  291. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  292. if (wWTInfoRetVal) {
  293. assert(wWTInfoRetVal == sizeof(AXIS));
  294. MAIN.WinTabMaxHover = TabletZ.axMax;
  295. }
  296. AXIS tabletPressure = { 0 };
  297. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  298. //glogContext.lcInOrgX = 0;
  299. //glogContext.lcInOrgY = 0;
  300. //glogContext.lcInExtX = TabletX.axMax;
  301. //glogContext.lcInExtY = TabletY.axMax;
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  312. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  313. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  314. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  315. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  316. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  317. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  318. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  319. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  320. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  321. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  322. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  323. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  324. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  325. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  326. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  327. if (!hctx)return;
  328. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  329. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  330. }
  331. void laHideCursor() {
  332. if (!MAIN.CurrentWindow) return; //impl
  333. }
  334. void laShowCursor() {
  335. if (!MAIN.CurrentWindow) return; //impl
  336. }
  337. static PIXELFORMATDESCRIPTOR cpfd = {
  338. sizeof(PIXELFORMATDESCRIPTOR),1,
  339. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  340. PFD_TYPE_RGBA,
  341. 8,
  342. 0, 0, 0, 0, 0, 0,
  343. 0, 0, 0,
  344. 0, 0, 0, 0,
  345. 32,
  346. 8, 0,
  347. 0,
  348. 0, 0, 0, 0
  349. };
  350. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  351. int nBestMS = 0;
  352. int i;
  353. int iResults[9];
  354. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  355. WGL_ACCELERATION_ARB, // 1
  356. WGL_DRAW_TO_WINDOW_ARB, // 2
  357. WGL_DOUBLE_BUFFER_ARB, // 3
  358. WGL_PIXEL_TYPE_ARB, // 4
  359. WGL_DEPTH_BITS_ARB, // 5
  360. WGL_STENCIL_BITS_ARB, // 6
  361. WGL_SAMPLE_BUFFERS_ARB, // 7
  362. WGL_SAMPLES_ARB }; // 8
  363. // How many pixelformats are there?
  364. int nFormatCount[] = { 0 };
  365. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  366. if (!wglGetPixelFormatAttribivARB)
  367. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  368. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  369. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  370. for (i = 0; i < nFormatCount[0]; i++){
  371. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  372. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  373. if (iResults[3] == 1) // Double buffered
  374. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  375. if (iResults[5] >= 24) // Any Depth greater than 16
  376. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  377. }
  378. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  379. };
  380. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  381. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  382. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  383. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  384. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  385. 0 };
  386. HGLRC hglrc = 0;
  387. HDC hdc = 0;
  388. int a, b;
  389. hdc = GetDC(hwnd);
  390. la_SetupPxlFormat(hdc, &a, &b);
  391. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  392. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  393. tnsContextMakeCurrent(hglrc, hdc,0);
  394. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  395. wglSwapIntervalEXT(-1);
  396. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  397. };
  398. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  399. HINSTANCE* inst = &MAIN.hinstance;
  400. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  401. x, y, w, h, 0, 0, *inst, 0);
  402. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  403. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  404. return hwnd;
  405. };
  406. void la_DestroySystemWindowWin32(laWindow* w) {
  407. tnsContextMakeCurrent(0,0,0);
  408. tnsDeleteContext(w->glc);
  409. ReleaseDC(w->win, w->hdc);
  410. DestroyWindow(w->win);
  411. };
  412. #endif
  413. #ifdef LAGUI_ANDROID
  414. SYSWINDOW la_CreateWindowAndroid(){
  415. return 0;
  416. };
  417. void laShowCursor(){}
  418. void laHideCursor(){}
  419. #endif
  420. #ifdef LA_LINUX
  421. void la_HandlerSIGSEGV(int sig) {
  422. void *array[30];
  423. size_t sz;
  424. sz = backtrace(array, 30);
  425. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  426. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  427. exit(1);
  428. }
  429. #endif
  430. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  431. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  432. //#ifndef LAGUI_ANDROID
  433. // ignore non-significant error/warning codes
  434. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  435. logPrint("GL %d: %s\n", id, message);
  436. char* strsource="",*strtype="",*strseverity="";
  437. switch (source) {
  438. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  439. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  440. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  441. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  442. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  443. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  444. }
  445. switch (type) {
  446. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  447. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  448. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  449. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  450. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  451. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  452. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  453. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  454. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  455. }
  456. switch (severity) {
  457. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  458. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  459. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  460. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  461. }
  462. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  463. //#endif
  464. }
  465. void la_SetCurrentGLContextDebug(){
  466. //#ifndef LAGUI_ANDROID
  467. int force=MAIN.InitArgs.GLDebug;
  468. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  469. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  470. glDebugMessageCallback(la_glDebugOutput, 0);
  471. int sev=GL_DONT_CARE;
  472. if(!force){
  473. switch(MAIN.GLDebugLevel){
  474. default: sev=GL_DONT_CARE; break;
  475. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  476. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  477. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  478. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  479. }
  480. }
  481. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  482. //#endif
  483. }
  484. void la_NotifyGLDebugChanges(){
  485. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  486. }
  487. void la_SetupWindowGLStates(laWindow* w){
  488. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  489. if(w->GLDebugNeedsUpdate){
  490. tnsContextMakeWindowCurrent(w);
  491. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  492. }
  493. }
  494. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  495. SYSGLCONTEXT glc;
  496. #ifdef LA_LINUX
  497. void* egl_surf=0;
  498. #ifdef LA_USE_GLES
  499. egl_surf=&window->egl_surf;
  500. #endif
  501. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  502. #endif
  503. #ifdef _WIN32
  504. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  505. #endif
  506. #ifdef LAGUI_ANDROID
  507. la_CreateWindowAndroid();
  508. window->win = 1;
  509. window->glc = MAIN.glc;
  510. #else
  511. window->win = hwnd;
  512. window->glc = glc;
  513. #endif
  514. #ifdef _WIN32
  515. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  516. RECT rc; GetClientRect(window->win, &rc);
  517. window->CW = rc.right - rc.left;
  518. window->CH = rc.bottom - rc.top;
  519. #endif
  520. #ifdef LA_LINUX
  521. XWindowAttributes attr;
  522. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  523. window->CW =attr.width;
  524. window->CH = attr.height;
  525. #endif
  526. la_SetCurrentGLContextDebug();
  527. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  528. la_SetupWindowGLStates(window);
  529. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  530. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #else
  532. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  533. #endif
  534. window->OutputShowStripes=1; window->Redraw=1;
  535. window->GLDebugNeedsUpdate=1;
  536. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  537. return 1;
  538. };
  539. int la_DestroySystemWindow(laWindow* wnd){
  540. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  541. nvgDeleteGLES3(wnd->nvg);
  542. #else
  543. nvgDeleteGL3(wnd->nvg);
  544. #endif
  545. #ifdef LA_LINUX
  546. la_DestroySystemWindowX11(wnd);
  547. #endif
  548. #ifdef _WIN32
  549. la_DestroySystemWindowWin32(wnd);
  550. #endif
  551. }
  552. void la_DestroyWindow(laWindow *wnd){
  553. laLayout *l; laPanel *p; if (!wnd) return;
  554. tnsSwitchToCurrentWindowContext(wnd);
  555. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  556. la_StopAllOperators();
  557. strSafeDestroy(&wnd->Title);
  558. //la_PrintUserList(wnd);
  559. //printf("----\n");
  560. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  561. while (l = lstPopItem(&wnd->Layouts)){
  562. laDestroyBlocksRecursive(l->FirstBlock);
  563. //la_PrintUserList(l);
  564. //printf("%x %s\n", l, l->ID->Ptr);
  565. strSafeDestroy(&l->ID);
  566. memFree(l);
  567. //la_PrintUserList(wnd);
  568. //printf("----\n");
  569. }
  570. //printf("----\n%x\n",wnd);
  571. //la_PrintUserList(wnd);
  572. la_DestroySystemWindow(wnd);
  573. lstRemoveItem(&MAIN.Windows, wnd);
  574. memFree(wnd);
  575. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  576. }
  577. void laRenameWindow(laWindow* wnd, char* name){
  578. if((!wnd)||MAIN.IsReadingUDF) return;
  579. strSafeSet(&wnd->Title, name);
  580. if(!wnd->win) return;
  581. #ifdef LA_LINUX
  582. XStoreName(MAIN.dpy, wnd->win, name);
  583. #endif
  584. #ifdef _WIN32
  585. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  586. SetWindowTextW(wnd->win, name);
  587. #endif
  588. }
  589. #ifdef LA_LINUX
  590. const char* la_ConvertCursorID(int id){
  591. switch (id) {
  592. case LA_ARROW: return "arrow";
  593. case LA_CROSS: return "cross";
  594. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  595. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  596. case LA_MOVE: return "diamond_cross";
  597. case LA_HAND: return "hand1";
  598. case LA_CORNER: return "bottom_right_corner";
  599. }
  600. return "arrow";
  601. }
  602. #endif
  603. #ifdef _WIN32
  604. HCURSOR la_ConvertCursorID(int id){
  605. switch (id){
  606. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  607. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  608. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  609. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  610. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  611. case LA_HAND: return LoadCursor(0, IDC_HAND);
  612. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  613. }
  614. return LoadCursor(0, IDC_ARROW);;
  615. }
  616. #endif
  617. void la_InitThreadEnviornment(){
  618. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  619. }
  620. laLogEntry* logEnsure(int Create){
  621. if(!MAIN.Logs.pFirst || Create){
  622. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  623. lstAppendItem(&MAIN.Logs, le);
  624. }
  625. return MAIN.Logs.pLast;
  626. }
  627. void logPrintTV(int Continued, char* format, va_list v){
  628. if(!format || !format[0]) return;
  629. laLogEntry* le=logEnsure(Continued);
  630. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  631. strSafePrintV(&le->Content, format, v);
  632. #ifdef LAGUI_ANDROID
  633. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  634. #endif
  635. laNotifyUsers("la.logs");
  636. }
  637. void logPrintT(int Continued, char* format, ...){
  638. if(!format || !format[0]) return;
  639. laLogEntry* le=logEnsure(Continued);
  640. va_list aptr; va_start(aptr, format);
  641. strSafePrint(&le->Content, format, aptr);
  642. va_end(aptr);
  643. #ifdef LAGUI_ANDROID
  644. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  645. #endif
  646. laNotifyUsers("la.logs");
  647. }
  648. void logPrint(char* format, ...){
  649. va_list aptr; va_start(aptr, format);
  650. logPrintTV(0, format, aptr);
  651. va_end(aptr);
  652. }
  653. void logPrintNew(char* format, ...){
  654. logEnsure(1);
  655. va_list aptr; va_start(aptr, format);
  656. logPrintTV(0, format, aptr);
  657. va_end(aptr);
  658. }
  659. void logClear(){
  660. laLogEntry*l;
  661. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  662. laNotifyUsers("la.logs");
  663. }
  664. laSafeString** la_PerfEnsure(){
  665. MAIN.NextPerfCounter++;
  666. if(MAIN.NextPerfCounter>=32){ MAIN.NextPerfCounter=0; }
  667. return &MAIN.PerfLogs[MAIN.NextPerfCounter];
  668. }
  669. void la_PerfClear(){
  670. if(!MAIN.ShowPerf){ return; }
  671. MAIN.NextPerfCounter=0; MAIN.NextPerfGroup++; if(MAIN.NextPerfGroup>=32){ MAIN.NextPerfGroup=0; }
  672. memset(&MAIN.PerfCounter[MAIN.NextPerfGroup],0,32*sizeof(real));
  673. for(int i=0;i<32;i++){ strSafeDestroy(&MAIN.PerfLogs[i]); }
  674. }
  675. void laPerfRecordV(char* format, va_list v){
  676. if(!format || !format[0]) return;
  677. laSafeString** ss=la_PerfEnsure();
  678. strSafePrintV(ss, format, v);
  679. laTimeRecorder tm; laRecordTime(&tm);
  680. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  681. }
  682. void laPerfRecord(char* format, ...){
  683. if(!format || !format[0]) return;
  684. laSafeString** ss=la_PerfEnsure();
  685. va_list aptr; va_start(aptr, format);
  686. strSafePrintV(ss, format, aptr);
  687. va_end(aptr);
  688. laTimeRecorder tm; laRecordTime(&tm);
  689. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  690. }
  691. void la_PerfDraw(){
  692. tnsScale3d(0.75,0.75,0.75);
  693. int sy=0; laBoxedTheme* bt=_LA_THEME_LABEL; real* color=laThemeColor(bt,LA_BT_TEXT);
  694. int sl=LA_RH*4; char buf[16]; real totval=0; real vals[32];
  695. for(int i=0;i<32;i++){
  696. if(MAIN.PerfLogs[i]){
  697. real value = MAIN.PerfCounter[MAIN.NextPerfGroup][i]-(i>0?MAIN.PerfCounter[MAIN.NextPerfGroup][i-1]:0);
  698. sprintf(buf,"%0.2lf",value*1000); totval+=value; vals[i]=value;
  699. tnsDrawStringAuto(buf,color,0,10000,sy,LA_TEXT_SHADOW);
  700. tnsDrawStringAuto(SSTR(MAIN.PerfLogs[i]),color,sl,10000,sy,LA_TEXT_SHADOW);
  701. sy+=LA_RH;
  702. }
  703. }
  704. real SL=LA_RH*2,SR=LA_RH*3.5; sy=0; tnsColor4dv(color); tnsUseNoTexture();
  705. for(int i=0;i<32;i++){
  706. if(MAIN.PerfLogs[i]){
  707. real r=vals[i]/totval; real use_r=tnsInterpolate(SL,SR,r);
  708. tnsVertex2d(SL,sy); tnsVertex2d(SL,sy+LA_RH); tnsVertex2d(use_r,sy+LA_RH); tnsVertex2d(use_r,sy);
  709. tnsPackAs(GL_TRIANGLE_FAN);
  710. sy+=LA_RH;
  711. }
  712. }
  713. tnsFlush();
  714. }
  715. 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;
  716. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  717. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  718. }
  719. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  720. strSafeSet(&s->Name,Name);
  721. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  722. s->x=x;s->y=y;s->w=w;s->h=h;
  723. laNotifyUsers("la.user_preferences.screens");
  724. return s;
  725. }
  726. void la_RemoveScreen(laScreen*s){
  727. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  728. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  729. }
  730. void la_RemoveDuplicatedScreenConf(){
  731. laScreen* NextS;
  732. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  733. NextS = s->Item.pNext;
  734. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  735. 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; }
  736. }
  737. }
  738. }
  739. laScreen* laGetWindowScreen(laWindow* w){
  740. int l,r,u,b; int area=-1; laScreen* maxs=0;
  741. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  742. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  743. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  744. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  745. int a=w*h; if(a>area){ maxs = s; area = a; }
  746. }
  747. return maxs;
  748. }
  749. #ifdef LA_LINUX
  750. int la_GetDPI(Window* root_win){
  751. XRRScreenResources *screen;
  752. XRROutputInfo *info;
  753. XRRCrtcInfo *crtc_info;
  754. XRRCrtcInfo *crtc;
  755. int iscres, icrtc, dpi=0;
  756. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  757. for(iscres=0;iscres<screen->noutput;iscres++){
  758. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  759. if(!info->mm_width || !info->mm_height){ continue; }
  760. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  761. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  762. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  763. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  764. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  765. XRRFreeCrtcInfo(crtc);
  766. //if(info->connection==RR_Connected){
  767. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  768. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  769. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  770. // XRRFreeCrtcInfo(crtc_info);
  771. // }
  772. //}
  773. XRRFreeOutputInfo(info);
  774. }
  775. XRRFreeScreenResources(screen);
  776. return dpi;
  777. }
  778. #endif
  779. #ifdef _WIN32
  780. typedef struct laWin32MonitorEnumData {
  781. int id;
  782. }laWin32MonitorEnumData;
  783. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  784. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  785. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  786. return TRUE;
  787. }
  788. int la_GetDPI(HWND win){
  789. laWin32MonitorEnumData data = { 0 };
  790. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  791. return GetDpiForWindow(win);
  792. return 144;
  793. }
  794. #endif
  795. #define PROGRESSW (LA_RH*15)
  796. void laShowProgress(real p1, real p2){
  797. laSpinLock(&MAIN.OpsLock);
  798. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  799. if(!MAIN.Progress.Called){
  800. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  801. }else{
  802. laTimeRecorder tm; laRecordTime(&tm);
  803. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  804. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  805. if(!MAIN.Progress.Shown){
  806. int ww=PROGRESSW+LA_RH*2;
  807. #ifdef LA_LINUX
  808. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  809. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  810. long a=LA_COLOR3_TO_HEX(bg);
  811. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  812. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  813. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  814. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  815. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  816. #endif
  817. #ifdef _WIN32
  818. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  819. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  820. ShowWindow(MAIN.Progress.w,SW_SHOW);
  821. #endif
  822. MAIN.Progress.Shown = 1;
  823. }
  824. }
  825. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  826. #ifdef LA_LINUX
  827. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  828. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  829. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  830. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  831. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  832. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  833. #endif
  834. #ifdef _WIN32
  835. InvalidateRect(MAIN.Progress.w,0,1);
  836. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  837. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  838. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  839. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  840. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  841. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  842. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  843. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  844. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  845. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  846. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  847. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  848. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  849. EndPaint(MAIN.Progress.w,&ps);
  850. MSG msg;
  851. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  852. #endif
  853. laSpinUnlock(&MAIN.OpsLock);
  854. }
  855. void laHideProgress(){
  856. laSpinLock(&MAIN.OpsLock);
  857. if(!MAIN.Progress.Shown){
  858. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  859. }
  860. laTimeRecorder tm; laRecordTime(&tm);
  861. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  862. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  863. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  864. #ifdef LA_LINUX
  865. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  866. #endif
  867. #ifdef _WIN32
  868. ShowWindow(MAIN.Progress.w,SW_HIDE);
  869. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  870. #endif
  871. laSpinUnlock(&MAIN.OpsLock);
  872. }
  873. //=======================
  874. void la_InitProgressWindow(){
  875. #ifdef LA_LINUX
  876. 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));
  877. if(!MAIN.Progress.w) return;
  878. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  879. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  880. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  881. if(MAIN.Progress.gc<0) return;
  882. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  883. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  884. XSync(MAIN.dpy,0);
  885. #endif
  886. #ifdef _WIN32
  887. WNDCLASSW wc;
  888. wc.hInstance = MAIN.hinstance;
  889. wc.lpfnWndProc = LA_ProgressWindowProc;
  890. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  891. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  892. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  893. wc.cbWndExtra = 0;
  894. wc.cbClsExtra = 0;
  895. wc.lpszClassName = L"_LAGUIPROGRESS";
  896. wc.lpszMenuName = NULL;
  897. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  898. if (!RegisterClassW(&wc)){ return; }
  899. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  900. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  901. #endif
  902. }
  903. void laSetFontFolderPath(char* absolute){
  904. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  905. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  906. }
  907. void laSetDefaultInitArguments(laInitArguments* ia){
  908. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  909. ia->UseColorManagement=0;
  910. ia->HasWorldObjects=0;
  911. ia->HasAction=0;
  912. ia->HasTextureInspector=0;
  913. ia->HasHistories=0;
  914. ia->HasTerminal=1;
  915. ia->HasAudio=0;
  916. }
  917. void laSetCompleteInitArguments(laInitArguments* ia){
  918. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  919. ia->UseColorManagement=1;
  920. ia->HasWorldObjects=1;
  921. ia->HasAction=1;
  922. ia->HasTextureInspector=1;
  923. ia->HasHistories=1;
  924. ia->HasTerminal=1;
  925. ia->HasAudio=1;
  926. }
  927. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  928. MAIN.GLMajor=MAIN.GLMinor=-1;
  929. char* arg = 0;
  930. printf("Initializing LaGUI...\n",argc);
  931. for(int i=0;i<argc;i++){
  932. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  933. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  934. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  935. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  936. }
  937. continue;
  938. }
  939. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  940. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  941. }
  942. }
  943. int laGetReadyWith(laInitArguments* ia){
  944. #ifdef LA_LINUX
  945. //signal(SIGSEGV,la_HandlerSIGSEGV);
  946. #endif
  947. laSpinInit(&MAIN.MemLock);
  948. laSpinInit(&MAIN.OpsLock);
  949. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  950. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  951. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  952. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  953. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  954. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  955. tnsInit();
  956. #ifdef LA_LINUX
  957. SYSWINDOW root, win;
  958. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  959. XSetWindowAttributes swa={0};
  960. XWindowAttributes wa={0};
  961. XEvent xev;
  962. logPrintNew("Initializing LaGUI...\n");
  963. setlocale(LC_CTYPE, "zh_CN.utf8");
  964. XSetErrorHandler(la_XErrorHandler);
  965. int i;
  966. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  967. printf("\n\tcannot connect to x server\n\n");
  968. exit(0);
  969. }
  970. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  971. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  972. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  973. #ifdef LA_USE_GLES
  974. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  975. #else
  976. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  977. #endif
  978. #ifdef LA_USE_GLES
  979. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  980. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  981. EGLint egl_major, egl_minor;
  982. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  983. printf("Error: eglInitialize() failed\n"); return -1;
  984. }
  985. int scrnum;
  986. XSetWindowAttributes attr;
  987. XVisualInfo *visInfo, visTemplate;
  988. int num_visuals;
  989. EGLContext ctx;
  990. EGLint num_configs;
  991. EGLint vid;
  992. static const EGLint attribs[] = {
  993. EGL_RED_SIZE, 8,
  994. EGL_GREEN_SIZE, 8,
  995. EGL_BLUE_SIZE, 8,
  996. EGL_DEPTH_SIZE, 1,
  997. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  998. EGL_NONE
  999. };
  1000. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  1001. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  1002. }
  1003. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  1004. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  1005. }
  1006. visTemplate.visualid = vid;
  1007. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  1008. if (!visInfo) {
  1009. printf("Error: couldn't get X visual\n"); exit(1);
  1010. }
  1011. MAIN.xvi=visInfo;
  1012. root = DefaultRootWindow(MAIN.dpy);
  1013. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1014. printf("\n\tcannot create colormap\n\n"); exit(1);
  1015. }
  1016. eglBindAPI(EGL_OPENGL_ES_API);
  1017. EGLint ctx_attribs[] = {
  1018. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  1019. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  1020. EGL_NONE
  1021. };
  1022. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  1023. if (!MAIN.glc) {
  1024. printf("Error: eglCreateContext failed\n"); exit(1);
  1025. }
  1026. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  1027. #else
  1028. int visual_attribs[] = {
  1029. GLX_X_RENDERABLE , True,
  1030. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  1031. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  1032. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  1033. GLX_RED_SIZE , 8,
  1034. GLX_GREEN_SIZE , 8,
  1035. GLX_BLUE_SIZE , 8,
  1036. GLX_ALPHA_SIZE , 8,
  1037. GLX_DEPTH_SIZE , 24,
  1038. //GLX_STENCIL_SIZE , 8,
  1039. GLX_DOUBLEBUFFER , True,
  1040. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  1041. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  1042. None
  1043. };
  1044. int fbcount = -1;
  1045. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  1046. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  1047. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  1048. MAIN.BestFBC = fbconfig[0];
  1049. int sample_buf,samples;
  1050. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  1051. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  1052. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1053. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1054. free(fbconfig);
  1055. root = DefaultRootWindow(MAIN.dpy);
  1056. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1057. printf("\n\tcannot create colormap\n\n"); exit(0);
  1058. }
  1059. swa.colormap = MAIN.cmap;
  1060. root = DefaultRootWindow(MAIN.dpy);
  1061. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1062. MAIN.win=win;
  1063. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1064. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1065. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1066. printf("\n\tcannot create gl context\n\n"); exit(0);
  1067. }
  1068. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1069. tnsContextMakeCurrent(MAIN.glc,win,0);
  1070. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1071. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1072. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1073. int err=0;
  1074. if((err=glewInit())!=GLEW_OK){
  1075. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1076. };
  1077. #endif /* gles or glx */
  1078. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1079. la_SetCurrentGLContextDebug();
  1080. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1081. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1082. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1083. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1084. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1085. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1086. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1087. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1088. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1089. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1090. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1091. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1092. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1093. #endif //linux
  1094. #ifdef _WIN32
  1095. logPrintNew("Initializing LaGUI...\n");
  1096. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1097. setlocale(LC_ALL, "zh_CN.utf8");
  1098. MAIN.hinstance = GetModuleHandle(NULL);
  1099. HINSTANCE* hInst = &MAIN.hinstance;
  1100. WNDCLASSEXW wt;
  1101. wt.cbSize = sizeof(WNDCLASSEXW);
  1102. wt.cbClsExtra = 0;
  1103. wt.cbWndExtra = 0;
  1104. wt.hbrBackground = 0;
  1105. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1106. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1107. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1108. wt.hInstance = *hInst;
  1109. wt.lpfnWndProc = LA_WindowProc;
  1110. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1111. wt.lpszMenuName = 0;
  1112. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1113. if (!RegisterClassExW(&wt)) return 0;
  1114. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1115. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1116. SetProcessDPIAware();
  1117. GLenum err;
  1118. PIXELFORMATDESCRIPTOR pfd;
  1119. HINSTANCE* hinst = &MAIN.hinstance;
  1120. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1121. "Temp Window For Accessing GLEW!",
  1122. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1123. 0, 0, *hinst, 0);
  1124. HDC hdc = GetDC(hwnd);
  1125. HGLRC hglrc = 0;
  1126. SetPixelFormat(hdc, 1, &cpfd);
  1127. hglrc = wglCreateContext(hdc);
  1128. tnsContextMakeCurrent(hglrc, hdc,0);
  1129. //MAIN.hdc = hdc;
  1130. // MAIN.tWND = hwnd;
  1131. MAIN.glc = hglrc;
  1132. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1133. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1134. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1135. if (err = glewInit()) {
  1136. printf("Init Glew Failed\n");
  1137. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1138. return 0;
  1139. }
  1140. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1141. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1142. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1143. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1144. #endif
  1145. la_GetWorkingDirectoryInternal();
  1146. MAIN.SavePreferenceOnExit=1;
  1147. MAIN.FontSize = 0.6;
  1148. int dpi=64;
  1149. #ifdef _WIN32
  1150. dpi=la_GetDPI(hwnd);
  1151. #endif
  1152. #ifdef LA_LINUX
  1153. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1154. #endif
  1155. #ifdef LAGUI_ANDROID
  1156. dpi = 144;
  1157. #endif
  1158. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1159. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1160. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1161. MAIN.UiScale=1;
  1162. MAIN.MarginSize = 1;
  1163. MAIN.ColorPickerGamma=1.5;
  1164. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1165. MAIN.ViewportHalftoneFactor=0.5;
  1166. MAIN.ViewportHalftoneSize=3.7;
  1167. tnsInitRenderKernel(64);
  1168. tnsInitBuiltinShaders();
  1169. tnsSetuptnsFontManager();
  1170. #define LOAD_FONT(font) \
  1171. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1172. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1173. LOAD_FONT("NotoEmoji-Regular.ttf");
  1174. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1175. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1176. //LOAD_FONT("NotoMusic-Regular.ttf");
  1177. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1178. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1179. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1180. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1181. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1182. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1183. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1184. MAIN.Audio=memAcquire(sizeof(laAudio));
  1185. #ifdef LA_WITH_LUAJIT
  1186. // starting lua
  1187. logPrint("Starting luajit...\n");
  1188. MAIN.L = lua_open();
  1189. la_luaLoadLibs(MAIN.L);
  1190. la_luaPrintStatus(MAIN.L);
  1191. tnsLuaInit(MAIN.L);
  1192. #endif
  1193. //interactions:
  1194. MAIN.TopFramerate = 60;
  1195. MAIN.ValuatorThreshold = 8;
  1196. MAIN.ScrollingSpeed = 3;
  1197. MAIN.AnimationSpeed = 0.4;
  1198. MAIN.PanelAnimationSpeed = 0.4;
  1199. MAIN.ZoomSpeed2D = 0.01;
  1200. MAIN.IdleTime = 0.75;
  1201. MAIN.TooltipCloseDistance = 30;
  1202. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1203. //display:
  1204. MAIN.FloatingAlpha = 0.35;
  1205. MAIN.SolidShadowLength = 20;
  1206. MAIN.WireColorSlices = 16;
  1207. MAIN.WireThickness = 5;
  1208. MAIN.WireSaggyness = 0.5;
  1209. #ifdef LAGUI_ANDROID
  1210. laAddResourceFolder("");
  1211. #else
  1212. laAddResourceFolder(".");
  1213. #endif
  1214. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1215. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1216. la_InitProgressWindow();
  1217. la_MakeTranslations_es_ES();
  1218. la_MakeTranslations_zh_hans();
  1219. //tns_RegisterResourcesForSoftwareRender();
  1220. la_RegisterDefaultSignals();
  1221. la_RegisterGeneralProps();
  1222. la_RegisterBuiltinTemplates();
  1223. la_RegisterMainThemes();
  1224. la_RegisterMainOperators();
  1225. la_RegisterMainUiTypes();
  1226. la_RegisterModellingOperators();
  1227. la_RegisterShapeOperators();
  1228. la_RegisterInternalProps();
  1229. la_RegisterAnimationResources();
  1230. la_RegisterWindowKeys();
  1231. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1232. laFinalizeUiTemplates();
  1233. laFinalizeOperators();
  1234. la_RegisterControllerProps();
  1235. la_RefreshControllers();
  1236. la_RegisterBasicNodes();
  1237. tns_RegisterNodes();
  1238. la_InitThreadEnviornment();
  1239. laSetRootInstance(&MAIN);
  1240. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1241. laPushDifferences(0, 0);
  1242. la_MakeDummyManagedUDF();
  1243. la_RegenerateWireColors();
  1244. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1245. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1246. logPrintNew("Initialization Completed\n");
  1247. MAIN.InitDone=1;
  1248. return 1;
  1249. }
  1250. int laGetReady(){
  1251. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1252. return laGetReadyWith(&ia);
  1253. }
  1254. void la_DestroyUiType(laUiType* uit);
  1255. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1256. void laShutoff(int SavePrefereces){
  1257. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1258. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1259. // transLate(pc->Description);
  1260. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1261. // transLate(p->Description);
  1262. // }
  1263. //}
  1264. transDumpMissMatchRecord("TranslationDump.txt");
  1265. if(MAIN.Cleanup) MAIN.Cleanup();
  1266. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1267. strSafeDestroy(&MAIN.WorkingDirectory);
  1268. strSafeDestroy(&MAIN.example_string);
  1269. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1270. // (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. )
  1271. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1272. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1273. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1274. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1275. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1276. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1277. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1278. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1279. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1280. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1281. strSafeDestroy(&MAIN.CopyPending);
  1282. la_ClearUDFRegistryAndFolders();
  1283. laClearManagedUDF();
  1284. laClearSaveProp();
  1285. logClear();
  1286. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1287. #ifdef LA_LINUX
  1288. tnsContextMakeCurrent(0,0,0);
  1289. tnsDeleteContext(MAIN.glc);
  1290. #ifdef LA_USE_GLES
  1291. eglTerminate(MAIN.egl_dpy);
  1292. #endif
  1293. #endif
  1294. #ifdef _WIN32
  1295. tnsContextMakeCurrent(0,0,0);
  1296. tnsDeleteContext(MAIN.glc);
  1297. UnloadWintab();
  1298. #endif
  1299. tnsQuit();
  1300. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1301. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1302. strSafeDump();
  1303. hshFree(&MAIN.DBInstMemLeft);
  1304. memNoLonger();
  1305. laSpinDestroy(&MAIN.MemLock);
  1306. laSpinDestroy(&MAIN.OpsLock);
  1307. #ifdef LA_WITH_LUAJIT
  1308. lua_close(MAIN.L);
  1309. #endif
  1310. printf("LaGUI has cleaned up.\n");
  1311. }
  1312. int laRestoreFactorySettings(){
  1313. char path[1024];
  1314. #ifdef LAGUI_ANDROID
  1315. sprintf(path,"%s","preferences.udf");
  1316. #else
  1317. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1318. #endif
  1319. if(remove(path)){ return 0; }
  1320. return 1;
  1321. }
  1322. void laSaveUserPreferences(){
  1323. char path[1024];
  1324. #ifdef LAGUI_ANDROID
  1325. sprintf(path,"%s","preferences.udf");
  1326. #else
  1327. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1328. #endif
  1329. laUDF* udf=laPrepareUDF(path);
  1330. laWriteProp(udf,"la.windows");
  1331. laWriteProp(udf,"la.user_preferences");
  1332. laWriteProp(udf,"la.input_mapping");
  1333. laWriteProp(udf,"la.controllers");
  1334. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1335. laWriteProp(udf,lip->p);
  1336. }
  1337. laPackUDF(udf,0,0);
  1338. }
  1339. void laEnsureUserPreferences(){
  1340. char path[1024];
  1341. #ifdef LAGUI_ANDROID
  1342. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1343. #else
  1344. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1345. #endif
  1346. laUDFRegistry* r=laFindUDFRegistry(path);
  1347. if(!r){ laSaveUserPreferences(); return; }
  1348. laUDF* udf=laOpenUDF(SSTR(r->Path),1,0,0); if(!udf){ logPrint("Can't read preferences on %s. Using default settings.",SSTR(r->Path)); return; }
  1349. laClearUDFRegistries();
  1350. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1351. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1352. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1353. laCloseUDF(udf);
  1354. la_RemoveDuplicatedScreenConf();
  1355. la_RemoveDuplicatedControllers();
  1356. laRefreshUDFRegistries();
  1357. //restore forced settings
  1358. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1359. }
  1360. void laAddExtraExtension(int FileType, ...){
  1361. va_list list; va_start(list,FileType);
  1362. char* ext;
  1363. while(ext=va_arg(list,char*)){ if(!ext) break;
  1364. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1365. et->FileType=FileType; et->Extension=ext;
  1366. lstAppendItem(&MAIN.ExtraExtensions, et);
  1367. logPrintNew("add ext %s",ext);
  1368. }
  1369. va_end(list);
  1370. }
  1371. void laAddExtraPreferencePath(const char* path){
  1372. if(!path) return;
  1373. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1374. }
  1375. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1376. if(!name || !Func) return;
  1377. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1378. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1379. }
  1380. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1381. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1382. }
  1383. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1384. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1385. }
  1386. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1387. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1388. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1389. }
  1390. void la_InputMappingGetKeyName(int key, int special, char* name){
  1391. char *_next=name; name[0]=0;
  1392. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1393. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1394. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1395. switch(key){
  1396. case ' ': strcat(name,"Space"); break;
  1397. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1398. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1399. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1400. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1401. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1402. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1403. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1404. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1405. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1406. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1407. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1408. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1409. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1410. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1411. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1412. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1413. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1414. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1415. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1416. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1417. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1418. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1419. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1420. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1421. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1422. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1423. case LA_KEY_F1: strcat(name,"F1"); break;
  1424. case LA_KEY_F2: strcat(name,"F2"); break;
  1425. case LA_KEY_F3: strcat(name,"F3"); break;
  1426. case LA_KEY_F4: strcat(name,"F4"); break;
  1427. case LA_KEY_F5: strcat(name,"F5"); break;
  1428. case LA_KEY_F6: strcat(name,"F6"); break;
  1429. case LA_KEY_F7: strcat(name,"F7"); break;
  1430. case LA_KEY_F8: strcat(name,"F8"); break;
  1431. case LA_KEY_F9: strcat(name,"F9"); break;
  1432. case LA_KEY_F10: strcat(name,"F10"); break;
  1433. case LA_KEY_F11: strcat(name,"F11"); break;
  1434. case LA_KEY_F12: strcat(name,"F12"); break;
  1435. default:
  1436. name = name+strlen(name); _next=name;
  1437. laToUTF8(key,name,&_next); *_next=0; break;
  1438. }
  1439. }
  1440. int la_InputMappingGetKeyFromName(char* name, int* special){
  1441. if(!name ||name[0]==0){ *special=0; return 0; }
  1442. *special=0;
  1443. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1444. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1445. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1446. char* p=name+strlen(name)-1;
  1447. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1448. while(*p=='+' || *p==' '){ p++; }
  1449. if(strSame(p,"Space")) return ' ';
  1450. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1451. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1452. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1453. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1454. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1455. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1456. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1457. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1458. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1459. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1460. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1461. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1462. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1463. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1464. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1465. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1466. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1467. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1468. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1469. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1470. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1471. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1472. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1473. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1474. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1475. if(strSame(p,"F1")) return LA_KEY_F1;
  1476. if(strSame(p,"F2")) return LA_KEY_F2;
  1477. if(strSame(p,"F3")) return LA_KEY_F3;
  1478. if(strSame(p,"F4")) return LA_KEY_F4;
  1479. if(strSame(p,"F5")) return LA_KEY_F5;
  1480. if(strSame(p,"F6")) return LA_KEY_F6;
  1481. if(strSame(p,"F7")) return LA_KEY_F7;
  1482. if(strSame(p,"F8")) return LA_KEY_F8;
  1483. if(strSame(p,"F9")) return LA_KEY_F9;
  1484. if(strSame(p,"F10")) return LA_KEY_F10;
  1485. if(strSame(p,"F11")) return LA_KEY_F11;
  1486. if(strSame(p,"F12")) return LA_KEY_F12;
  1487. int adv;
  1488. return laToUnicode(p,&adv);
  1489. }
  1490. laCustomSignal* laFindSignal(char* Name){
  1491. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1492. return 0;
  1493. }
  1494. laCustomSignal* laFindSignalByID(int ID){
  1495. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1496. return 0;
  1497. }
  1498. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1499. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1500. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1501. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1502. char* signal = SSTR(ime->Signal);
  1503. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1504. }
  1505. laInputMapping* laNewInputMapping(char* Name){
  1506. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1507. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1508. strSafeSet(&im->Name,Name);
  1509. return im;
  1510. }
  1511. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1512. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1513. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1514. memAssignRef(e,&e->Parent,im);
  1515. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1516. laInputMappingUpdateSignal(e);
  1517. e->SpecialKeyBits=SpecialKeyBit;
  1518. char buf[64],*_next=buf;
  1519. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1520. }
  1521. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1522. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1523. laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1524. }
  1525. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1526. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1527. }
  1528. void laRemoveInputMapping(laInputMapping* im){
  1529. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1530. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1531. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1532. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1533. }
  1534. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1535. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1536. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1537. return cs;
  1538. }
  1539. void laRemoveCustomSignal(laCustomSignal* cs){
  1540. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1541. }
  1542. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1543. void la_SendSignalsFromEvent(laEvent* e){
  1544. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1545. if(!im){return;}
  1546. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1547. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1548. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1549. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1550. }
  1551. }
  1552. }
  1553. }
  1554. //MSG====================================================
  1555. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1556. if (wnd->win == hwnd) return 1;
  1557. else return 0;
  1558. };
  1559. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1560. if (p->SL){ int s=p->SL<0?0:p->SL;
  1561. if (p->TX != s) laRecalcPanel(p);
  1562. p->TX = s;
  1563. }
  1564. if (p->SR){ int s=p->SR<0?0:p->SR;
  1565. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1566. p->TW = CW - p->TX - s;
  1567. }
  1568. if (p->ST){ int s=p->ST<0?0:p->ST;
  1569. if (p->TY != s) laRecalcPanel(p);
  1570. p->TY = s;
  1571. }
  1572. if (p->SB){ int s=p->SB<0?0:p->SB;
  1573. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1574. p->TH = CH - p->TY - s;
  1575. }
  1576. }
  1577. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1578. laPanel *p = 0;
  1579. b->X = X;
  1580. b->Y = Y;
  1581. b->W = W;
  1582. b->H = H;
  1583. if (b->B1){
  1584. int SplitWidth;
  1585. if (b->Vertical){
  1586. SplitWidth = H * b->SplitRatio;
  1587. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1588. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1589. }else{
  1590. SplitWidth = W * b->SplitRatio;
  1591. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1592. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1593. }
  1594. }
  1595. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1596. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1597. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1598. }
  1599. if (p = b->CurrentPanel){
  1600. int TitleGap=b->Folded?0:LA_RH;
  1601. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1602. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1603. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1604. laRecalcPanel(p);
  1605. }
  1606. }
  1607. void la_UpdateUiPlacement(laWindow *w){
  1608. laLayout *l;
  1609. laPanel *p;
  1610. int CW = w->CW;
  1611. int CH = w->CH;
  1612. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1613. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1614. if(w->MaximizedUi && w->MaximizedUiPanel){
  1615. laRecalcPanel(w->MaximizedUiPanel);
  1616. }elif(w->MaximizedBlock){
  1617. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1618. }else{
  1619. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1620. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1621. }
  1622. }
  1623. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1624. if(p->IsMenuPanel){
  1625. p->TH=p->H=MenuHeight;
  1626. }
  1627. la_EnsurePanelSnapping(p, CW, CH);
  1628. laRecalcPanel(p);
  1629. }
  1630. }
  1631. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1632. laWindow *window;
  1633. #ifdef LAGUI_ANDROID
  1634. window = MAIN.Windows.pFirst; if (!window) return;
  1635. window->X=x;window->Y=y;window->W=w;window->H=h;
  1636. window->CW=w;window->CH=h;
  1637. la_UpdateUiPlacement(window); return;
  1638. #endif
  1639. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1640. if (!window) return;
  1641. #ifdef _WIN32
  1642. RECT rcc; GetClientRect(window->win, &rcc);
  1643. RECT rcw; GetWindowRect(window->win, &rcw);
  1644. window->CW = rcc.right - rcc.left;
  1645. window->CH = rcc.bottom - rcc.top;
  1646. window->W = rcw.right - rcw.left;
  1647. window->H = rcw.bottom - rcw.top;
  1648. window->X = rcw.left; window->Y = rcw.top;
  1649. if (MAIN.AutoSwitchColorSpace) {
  1650. laScreen* s = laGetWindowScreen(window);
  1651. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1652. }
  1653. #endif
  1654. #ifdef LA_LINUX
  1655. XWindowAttributes attr;
  1656. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1657. window->CW = w; window->CH = h;
  1658. window->W = w; window->H = h;
  1659. window->X = x; window->Y = y;
  1660. if(MAIN.AutoSwitchColorSpace){
  1661. laScreen* s = laGetWindowScreen(window);
  1662. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1663. }
  1664. #endif
  1665. la_UpdateUiPlacement(window);
  1666. }
  1667. int la_OnWindowDestroy(SYSWINDOW wnd){
  1668. laListHandle *hlst = &MAIN.Windows;
  1669. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1670. if (!w) return 0;
  1671. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1672. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1673. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1674. laShutoff(1);
  1675. return 1;
  1676. }
  1677. laListHandle h={0};laLayout*l=0;
  1678. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1679. la_DestroyWindow(w);
  1680. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1681. #ifdef LA_LINUX
  1682. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1683. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1684. #endif
  1685. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1686. }
  1687. return 0;
  1688. }
  1689. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1690. laListHandle *el = &wnd->EventList;
  1691. laEvent* last_e=el->pLast;
  1692. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1693. #ifdef LA_LINUX
  1694. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1695. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1696. #endif
  1697. #ifdef _WIN32
  1698. 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);
  1699. #endif
  1700. }
  1701. void laMappingRequestEval();
  1702. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1703. laListHandle *wl = &MAIN.Windows;
  1704. laWindow* wnd;
  1705. #ifdef LAGUI_ANDROID
  1706. wnd = MAIN.Windows.pFirst;
  1707. #else
  1708. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1709. #endif
  1710. if (!wnd){ memFree(e); return; }
  1711. laListHandle *el = &wnd->EventList;
  1712. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1713. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1714. e->window = wnd;
  1715. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1716. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1717. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1718. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1719. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1720. e->GoodPressure=MAIN.IsPen;
  1721. lstAppendItem(el, (laListItem *)e);
  1722. laMappingRequestEval();
  1723. };
  1724. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1725. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1726. la_SaveEvent(hwnd, e, 1);
  1727. };
  1728. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1729. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1730. e->type = LA_INPUT; e->Input=Input;
  1731. la_SaveEvent(hwnd, e, 1);
  1732. }
  1733. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1734. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1735. e->type = LA_EMPTY;
  1736. la_SaveEvent(hwnd, e, 1);
  1737. }
  1738. void laSendOperatorTriggerEvent(){
  1739. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1740. MAIN.ReTriggerOperators = 0;
  1741. }
  1742. int la_TranslateSpecialKey(int keysym){
  1743. #ifdef LA_LINUX
  1744. switch(keysym){
  1745. case XK_Return: return LA_KEY_ENTER;
  1746. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1747. case XK_Delete: return LA_KEY_DELETE;
  1748. case XK_Escape: return LA_KEY_ESCAPE;
  1749. case XK_Tab: return LA_KEY_TAB;
  1750. case XK_Left: return LA_KEY_ARRLEFT;
  1751. case XK_Right: return LA_KEY_ARRRIGHT;
  1752. case XK_Up: return LA_KEY_ARRUP;
  1753. case XK_Down: return LA_KEY_ARRDOWN;
  1754. case XK_Control_L: return LA_KEY_CTRL;
  1755. case XK_Control_R: return LA_KEY_CTRL;
  1756. case XK_Shift_L: return LA_KEY_SHIFT;
  1757. case XK_Shift_R: return LA_KEY_SHIFT;
  1758. case XK_Alt_L: return LA_KEY_ALT;
  1759. case XK_Alt_R: return LA_KEY_ALT;
  1760. case XK_KP_1: return LA_KEY_NUM1;
  1761. case XK_KP_2: return LA_KEY_NUM2;
  1762. case XK_KP_3: return LA_KEY_NUM3;
  1763. case XK_KP_4: return LA_KEY_NUM4;
  1764. case XK_KP_5: return LA_KEY_NUM5;
  1765. case XK_KP_6: return LA_KEY_NUM6;
  1766. case XK_KP_7: return LA_KEY_NUM7;
  1767. case XK_KP_8: return LA_KEY_NUM8;
  1768. case XK_KP_9: return LA_KEY_NUM9;
  1769. case XK_KP_0: return LA_KEY_NUM0;
  1770. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1771. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1772. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1773. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1774. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1775. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1776. default: return keysym;
  1777. }
  1778. #endif
  1779. #ifdef _WIN32
  1780. switch (keysym) {
  1781. case VK_RETURN: return LA_KEY_ENTER;
  1782. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1783. case VK_TAB: return LA_KEY_TAB;
  1784. case VK_LEFT: return LA_KEY_ARRLEFT;
  1785. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1786. case VK_UP: return LA_KEY_ARRUP;
  1787. case VK_DOWN: return LA_KEY_ARRDOWN;
  1788. case VK_CONTROL: return LA_KEY_CTRL;
  1789. case VK_SHIFT: return LA_KEY_SHIFT;
  1790. case VK_MENU: return LA_KEY_ALT;
  1791. case VK_F1: return LA_KEY_F1;
  1792. case VK_F2: return LA_KEY_F2;
  1793. case VK_F3: return LA_KEY_F3;
  1794. case VK_F4: return LA_KEY_F4;
  1795. case VK_F5: return LA_KEY_F5;
  1796. case VK_F6: return LA_KEY_F6;
  1797. case VK_F7: return LA_KEY_F7;
  1798. case VK_F8: return LA_KEY_F8;
  1799. case VK_F9: return LA_KEY_F9;
  1800. case VK_F10: return LA_KEY_F10;
  1801. case VK_F11: return LA_KEY_F11;
  1802. case VK_F12: return LA_KEY_F12;
  1803. case VK_NUMPAD0: return LA_KEY_NUM0;
  1804. case VK_NUMPAD1: return LA_KEY_NUM1;
  1805. case VK_NUMPAD2: return LA_KEY_NUM2;
  1806. case VK_NUMPAD3: return LA_KEY_NUM3;
  1807. case VK_NUMPAD4: return LA_KEY_NUM4;
  1808. case VK_NUMPAD5: return LA_KEY_NUM5;
  1809. case VK_NUMPAD6: return LA_KEY_NUM6;
  1810. case VK_NUMPAD7: return LA_KEY_NUM7;
  1811. case VK_NUMPAD8: return LA_KEY_NUM8;
  1812. case VK_NUMPAD9: return LA_KEY_NUM9;
  1813. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1814. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1815. case VK_ADD: return LA_KEY_NUMPLUS;
  1816. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1817. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1818. case VK_OEM_1: return ';';
  1819. case VK_OEM_2: return '/';
  1820. case VK_OEM_3: return '`';
  1821. case VK_OEM_4: return '[';
  1822. case VK_OEM_5: return '\\';
  1823. case VK_OEM_6: return ']';
  1824. case VK_OEM_7: return '\'';
  1825. case VK_OEM_COMMA: return ',';
  1826. case VK_OEM_PERIOD: return '.';
  1827. case VK_OEM_PLUS: return '+';
  1828. case VK_OEM_MINUS: return '-';
  1829. default: return keysym;
  1830. }
  1831. #endif
  1832. }
  1833. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1834. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1835. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1836. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1837. // la_SaveEvent(hwnd, e, 0);
  1838. //}
  1839. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1840. e->type = type; e->x = x; e->y = y;
  1841. la_SaveEvent(hwnd, e, 0);
  1842. MAIN.evLastX=x; MAIN.evLastY=y;
  1843. };
  1844. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1845. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1846. e->type = type;
  1847. la_SaveEvent(hwnd, e, 1);
  1848. };
  1849. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1850. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1851. e->type = LA_SIGNAL_EVENT;
  1852. e->key = signal;
  1853. la_SaveEvent(hwnd, e, 1);
  1854. };
  1855. void laRetriggerOperators(){
  1856. MAIN.ReTriggerOperators = 1;
  1857. }
  1858. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1859. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1860. }
  1861. void laSetCleanupCallback(laCleanupF Cleanup){
  1862. MAIN.Cleanup=Cleanup;
  1863. }
  1864. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1865. MAIN.InputProcess=InputProcess;
  1866. }
  1867. //====================================================================================================
  1868. void la_DestroyTheme(laTheme* t){
  1869. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1870. strSafeDestroy(&t->Name);
  1871. strSafeDestroy(&t->Author);
  1872. }
  1873. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1874. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1875. strSafeSet(&t->Name, Name);
  1876. strSafeSet(&t->Author, AuthorName);
  1877. lstAppendItem(&MAIN.Themes, t);
  1878. MAIN.CurrentTheme = t;
  1879. return t;
  1880. }
  1881. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1882. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1883. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1884. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1885. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1886. strSafeSet(&bt->Name, Name);
  1887. bt->NormalY=NormalY;
  1888. bt->ActiveY=ActiveY;
  1889. bt->BorderY=BorderY;
  1890. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1891. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1892. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1893. bt->BackRef = BackRef;
  1894. lstAppendItem(&t->BoxedThemes, bt);
  1895. return bt;
  1896. }
  1897. laTheme *laGetTheme(const char *ThemeName){
  1898. laTheme *t = MAIN.Themes.pFirst;
  1899. for (t; t; t = t->Item.pNext){
  1900. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1901. }
  1902. return 0;
  1903. }
  1904. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1905. laTheme *t = MAIN.Themes.pFirst;
  1906. for (t; t; t = t->Item.pNext){
  1907. laBoxedTheme *bt;
  1908. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1909. bt = t->BoxedThemes.pFirst;
  1910. for (bt; bt; bt = bt->Item.pNext){
  1911. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1912. }
  1913. }
  1914. return 0;
  1915. }
  1916. real* laThemeColor(laBoxedTheme* bt, int which){
  1917. switch(which){
  1918. default:
  1919. case LA_BT_NORMAL: return bt->Normal;
  1920. case LA_UI_EDITING:
  1921. case LA_BT_ACTIVE: return bt->Active;
  1922. case LA_BT_BORDER: return bt->Border;
  1923. case LA_BT_TEXT: return bt->Text; break;
  1924. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1925. case LA_BT_DISABLED: return bt->Inactive; break;
  1926. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1927. }
  1928. return bt->Normal;
  1929. }
  1930. real* laAccentColor(int which){
  1931. switch(which){
  1932. default:
  1933. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1934. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1935. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1936. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1937. case LA_BT_FACE:
  1938. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1939. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1940. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1941. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1942. case LA_BT_SHADOW: return MAIN.CurrentTheme->ShadowColor;
  1943. }
  1944. return MAIN.CurrentTheme->SelectionColor;
  1945. }
  1946. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1947. real hcy[3];
  1948. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1949. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1950. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1951. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1952. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1953. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1954. int *tm=&bt->LM,*tp=&bt->LP;
  1955. for(int i=0;i<4;i++){
  1956. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1957. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1958. }
  1959. }
  1960. void la_RefreshThemeColorSelf(laTheme* th){
  1961. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1962. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1963. real hcy[3], usehcy[3];
  1964. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1965. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1966. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1967. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1968. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1969. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1970. tnsVectorCopy3d(th->Color, th->ShadowColor); th->ShadowColor[3]=th->CursorAlpha;
  1971. }
  1972. void la_RefreshThemeColor(laTheme* th){
  1973. real hcy[3], usehcy[3], normalhcy[3];
  1974. tnsRGB2HCY(th->Color,hcy);
  1975. la_RefreshThemeColorSelf(th);
  1976. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1977. la_RefreshBoxedThemeColor(bt);
  1978. (*bt->BackRef) = bt;
  1979. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1980. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1981. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1982. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1983. }
  1984. }
  1985. //I FUCKING HATE THIS STUPID FUNCTION
  1986. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1987. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1988. laUiListDrawItem *last = uild->Items.pFirst;
  1989. int LimW=_R-_L;
  1990. int SL, SR, SU, SB;
  1991. int Target__B = Target->B;
  1992. int Target__R = Target->R;
  1993. uildi->Target = Target;
  1994. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1995. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1996. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1997. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1998. uildi->L = last ? Target->L - last->XP : Target->L;
  1999. uildi->R = last ? Target__R - last->XP : Target__R;
  2000. uildi->U = last ? Target->U - last->YP : Target->U;
  2001. uildi->B = last ? Target__B - last->YP : Target__B;
  2002. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  2003. uildi->L -= GlobalX;
  2004. uildi->R -= GlobalX;
  2005. uildi->U -= GlobalY;
  2006. uildi->B -= GlobalY;
  2007. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2008. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2009. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2010. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2011. uildi->DifX = SL - uildi->L;
  2012. uildi->DifY = SU - uildi->U;
  2013. uildi->L = SL;
  2014. uildi->R = SR+uildi->DifX;
  2015. uildi->U = SU;
  2016. uildi->B = SB;//+uildi->DifY;
  2017. if(uildi->R>_R){ uildi->R=_R; }
  2018. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  2019. //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);
  2020. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  2021. memFree(uildi);
  2022. return 0;
  2023. }
  2024. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  2025. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  2026. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  2027. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  2028. Target->U + Target->PanY + uildi->DifY+1,
  2029. -100, 100);
  2030. lstPushItem(&uild->Items, uildi);
  2031. return 1;
  2032. }
  2033. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  2034. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2035. laUiListDrawItem *last = uild->Items.pFirst;
  2036. int SL, SR, SU, SB;
  2037. if (B - U > LimH) B = U + LimH;
  2038. uildi->XP = last ? last->XP + PanX : PanX;
  2039. uildi->YP = last ? last->YP + PanY : PanY;
  2040. uildi->L = last ? L - last->XP : L;
  2041. uildi->R = last ? R - last->XP : R;
  2042. uildi->U = last ? U - last->YP : U;
  2043. uildi->B = last ? B - last->YP : B;
  2044. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2045. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2046. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2047. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2048. uildi->DifX = SL - uildi->L;
  2049. uildi->DifY = SU - uildi->U;
  2050. uildi->L = SL;
  2051. uildi->R = SR;
  2052. uildi->U = SU;
  2053. uildi->B = SB;
  2054. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2055. tnsOrtho(L + PanX + uildi->DifX,
  2056. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  2057. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2058. U + PanY + uildi->DifY,
  2059. -100, 100);
  2060. lstPushItem(&uild->Items, uildi);
  2061. }
  2062. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2063. int* savel, int* saver, int* saveu, int* saveb){
  2064. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2065. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2066. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2067. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2068. real x,y,w,h;
  2069. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2070. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2071. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2072. }
  2073. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2074. laUiListDrawItem *uildi = uild->Items.pFirst;
  2075. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2076. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2077. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2078. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2079. Target->U + Target->PanY + uildi->DifY -1,
  2080. -100, 100);
  2081. }
  2082. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2083. laUiListDrawItem *uildi = lstPopItem(uild);
  2084. laUiList *Target;
  2085. memFree(uildi);
  2086. uildi = uild->Items.pFirst;
  2087. if (!uildi || !uildi->Target){
  2088. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2089. return;
  2090. }
  2091. Target = uildi->Target;
  2092. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2093. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2094. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2095. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2096. Target->U + Target->PanY + uildi->DifY -1,
  2097. -100, 100);
  2098. }
  2099. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2100. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2101. uildi->L = L;
  2102. uildi->R = R;
  2103. uildi->U = U;
  2104. uildi->B = B;
  2105. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2106. tnsOrtho(L, R, B, U, -100, 100);
  2107. lstPushItem(&uild->Items, uildi);
  2108. }
  2109. void la_ClearUiListMatrix(laUiListDraw *uild){
  2110. laUiListDrawItem *uildi;
  2111. while (uildi = lstPopItem(uild)){
  2112. memFree(uildi);
  2113. }
  2114. }
  2115. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2116. 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);
  2117. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2118. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2119. int la_TestUiListMinumWidth(laUiList *uil);
  2120. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2121. if (ui){
  2122. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2123. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2124. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2125. p->X = p->TX; p->Y = p->TY;
  2126. p->W = p->TW;
  2127. }
  2128. }
  2129. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2130. int cw = MAIN.CurrentWindow->CW;
  2131. int ch = MAIN.CurrentWindow->CH;
  2132. int PH = p->TH;
  2133. laBoxedTheme*bt = *p->BT;
  2134. int uih=uil->B + bt->BM;
  2135. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2136. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2137. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2138. else p->TH = PH;
  2139. p->H = p->TH;
  2140. if(p->BoundUi){
  2141. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2142. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2143. if (p->X < 0) p->X = 0;
  2144. if (p->Y < 0) p->Y = 0;
  2145. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2146. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2147. }else{
  2148. if (p->Y < 0) p->Y = 0;
  2149. if ((!p->Block)&&(!p->IsMenuPanel)){
  2150. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2151. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2152. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2153. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2154. }
  2155. }
  2156. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2157. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2158. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2159. }
  2160. if (p->ST) p->TY = p->ST;
  2161. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2162. if (p->SB) p->TH = ch - p->TY - p->SB;
  2163. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2164. p->TX = p->X; p->TY = p->Y;
  2165. p->TW = p->W; p->TH = p->H;
  2166. }
  2167. void laPlacePanelForCreation(laPanel *p){
  2168. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2169. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2170. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2171. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2172. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2173. p->TX=p->X; p->TY=p->Y;
  2174. }
  2175. }
  2176. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2177. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2178. tnsViewportWithScissor(0, 0, p->W, p->H);
  2179. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2180. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2181. }
  2182. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2183. tnsDrawToScreen();
  2184. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2185. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2186. }
  2187. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2188. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2189. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2190. }
  2191. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2192. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2193. tnsClearAll();
  2194. }
  2195. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2196. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2197. real Color[] = {1, 1, 1, 1};
  2198. real L, W, U, H;
  2199. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2200. if(MAIN.EnableColorManagement){
  2201. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2202. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2203. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2204. }else{
  2205. tnsUniformOutputColorSpace(T->immShader,0);
  2206. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2207. tnsUniformColorComposing(T->immShader,0,0,0);
  2208. }
  2209. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2210. tnsUseNoTexture();
  2211. if (!p->IsMenuPanel){
  2212. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2213. }
  2214. tnsFlush();
  2215. }
  2216. if(p->ParentOperator){
  2217. tnsUseNoTexture();
  2218. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2219. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2220. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2221. }
  2222. switch (p->AnimationMode){
  2223. case 0: /* and */
  2224. case LA_PANEL_ANIMATION_FLASH:
  2225. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2226. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2227. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2228. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2229. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2230. tnsPackAs(GL_TRIANGLES);
  2231. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2232. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2233. }
  2234. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2235. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2236. if((int)(p->AnimationRatio*6)%2){
  2237. tnsUseNoTexture();
  2238. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2239. 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);
  2240. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2241. }
  2242. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2243. }
  2244. break;
  2245. case LA_PANEL_ANIMATION_DROP_DOWN:
  2246. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2247. tnsDraw2DTextureArg(
  2248. p->OffScr->pColor[0],
  2249. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2250. Color,
  2251. 0, 0, 1 - p->AnimationRatio, 0);
  2252. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2253. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2254. break;
  2255. case LA_PANEL_ANIMATION_EXPAND:
  2256. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2257. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2258. W = tnsLinearItp(0, p->W, 0.4);
  2259. H = tnsLinearItp(0, p->H, 0.4);
  2260. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2261. tnsDraw2DTextureArg(
  2262. p->OffScr->pColor[0],
  2263. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2264. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2265. Color,
  2266. 0, 0, 0, 0);
  2267. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2268. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2269. break;
  2270. case LA_PANEL_ANIMATION_DISSOVE:
  2271. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2272. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2273. W = tnsLinearItp(0, p->W, 1.4);
  2274. H = tnsLinearItp(0, p->H, 1.4);
  2275. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2276. if (p->OffScr) tnsDraw2DTextureArg(
  2277. p->OffScr->pColor[0],
  2278. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2279. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2280. Color,
  2281. 0, 0, 0, 0);
  2282. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2283. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2284. break;
  2285. case LA_PANEL_ANIMATION_COLLAPSE:
  2286. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2287. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2288. W = tnsLinearItp(0, p->W, 0.4);
  2289. H = tnsLinearItp(0, p->H, 0.4);
  2290. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2291. if (p->OffScr) tnsDraw2DTextureArg(
  2292. p->OffScr->pColor[0],
  2293. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2294. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2295. Color,
  2296. 0, 0, 0, 0);
  2297. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2298. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2299. break;
  2300. case LA_PANEL_ANIMATION_MINIMIZE:
  2301. L = tnsLinearItp(0, p->X, 0.3);
  2302. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2303. W = tnsLinearItp(0, p->W, 0.4);
  2304. H = tnsLinearItp(0, p->H, 0.4);
  2305. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2306. tnsDraw2DTextureArg(
  2307. p->OffScr->pColor[0],
  2308. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2309. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2310. Color,
  2311. 0, 0, 0, 0);
  2312. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2313. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2314. break;
  2315. }
  2316. tnsFlush();
  2317. tnsUniformOutputColorSpace(T->immShader,0);
  2318. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2319. tnsUniformColorComposing(T->immShader,0,0,0);
  2320. }
  2321. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2322. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2323. else{
  2324. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:LA_PANEL_DEFAULT_GL_FORMAT;
  2325. if(p->MenuRefer && (p->MenuRefer->Flags&LA_UI_FLAGS_MENU_FLOAT16)){ GLFormat=GL_RGBA16F; }
  2326. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2327. }
  2328. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2329. }
  2330. void la_PanelRefreshDetachedProp(laPanel *panel){
  2331. laProp *p;
  2332. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2333. la_StepPropPack(&p->DetachedPP);
  2334. la_UsePropPack(&p->DetachedPP, 0);
  2335. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2336. // laUseDataBlock(
  2337. // p->DetachedPP.LastPs->UseInstance,
  2338. // p->DetachedPP.LastPs->p,
  2339. // MAIN.PropMatcherContextP->FrameDistinguish,
  2340. // MAIN.PropMatcherContextP,
  2341. // la_PropPanelUserRemover, 0);
  2342. //}
  2343. }
  2344. }
  2345. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2346. real* color=laThemeColor(bt,LA_BT_BORDER);
  2347. tnsColor4d(0,0,0,Alpha);
  2348. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2349. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2350. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2351. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2352. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2353. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2354. tnsPackAs(GL_TRIANGLE_STRIP);
  2355. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2356. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2357. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2358. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2359. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2360. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2361. }
  2362. int la_AnimateUiListRecursive(laUiList *uil);
  2363. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2364. int DrawState_ = 0;
  2365. laUiListDraw uild = {0}; int orig_refresh=p->Refresh;
  2366. if (p->Show){
  2367. la_SetPropMathcerContext(p);
  2368. MAIN.CurrentPanel = p;
  2369. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2370. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2371. //}
  2372. if (p->Refresh & LA_TAG_RECALC){
  2373. laRecalcPanelImmediate(p);
  2374. }
  2375. if (!p->MenuRefer){
  2376. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2377. if (p->Refresh || !p->OffScr){
  2378. la_PanelDrawToOffsceen(p, &p->UI);
  2379. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2380. la_PanelBackgroundInit(p, bt);
  2381. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2382. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2383. tnsFlush();
  2384. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2385. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2386. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2387. DrawState_++;
  2388. }
  2389. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2390. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2391. if(p->UI.PanY<0){p->UI.PanY=0;}
  2392. DrawState_++;
  2393. }
  2394. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2395. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2396. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2397. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2398. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2399. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2400. if(p!=w->MaximizedUiPanel){
  2401. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2402. }else{
  2403. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2404. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2405. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2406. tnsFlush();
  2407. }
  2408. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2409. }
  2410. }else{
  2411. if (p->Refresh || !p->OffScr){
  2412. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2413. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2414. la_PanelBackgroundInit(p, bt);
  2415. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2416. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2417. tnsFlush();
  2418. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2419. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2420. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2421. DrawState_++;
  2422. }
  2423. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2424. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2425. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2426. DrawState_++;
  2427. }
  2428. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2429. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2430. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2431. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2432. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2433. }
  2434. }
  2435. tnsDrawToScreen();
  2436. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2437. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2438. la_PanelDrawToWindow(p, w);
  2439. }elif (p->AnimationMode){
  2440. la_PanelDrawToWindow(p, w);
  2441. }
  2442. laPerfRecord("%s [%s]",(orig_refresh&LA_TAG_RECALC)?"🌑":
  2443. ((orig_refresh&LA_TAG_REDRAW)?"🌓":
  2444. ((orig_refresh&LA_TAG_ANIMATION)?"🌔":"🌕")), SSTR(p->Title));
  2445. }
  2446. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2447. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2448. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2449. laPanel *pi, *PrevPI;
  2450. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2451. PrevPI = pi->Item.pPrev;
  2452. if (pi->AnimationMode && pi->LaterDestroy){
  2453. lstRemoveItem(&p->SubPanels, pi);
  2454. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2455. continue;
  2456. }
  2457. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2458. la_AttachedPanelDefDraw(w,pi,bt);
  2459. }
  2460. }
  2461. }
  2462. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2463. real PanelSquare[] = {
  2464. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2465. b->X + 2, CH - (b->Y + b->H - 4),
  2466. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2467. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2468. real Center[] = {
  2469. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2470. real DraggingPlot[] = {
  2471. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2472. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2473. PanelSquare[0],
  2474. PanelSquare[1],
  2475. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2476. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2477. PanelSquare[2],
  2478. PanelSquare[3],
  2479. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2480. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2481. PanelSquare[4],
  2482. PanelSquare[5],
  2483. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2484. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2485. PanelSquare[6],
  2486. PanelSquare[7],
  2487. };
  2488. real Square[] = {
  2489. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2490. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2491. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2492. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2493. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2494. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2495. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2496. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2497. };
  2498. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2499. LA_COLOR3(BorderColor4dV), 0,
  2500. LA_COLOR3(BorderColor4dV), 0.8,
  2501. LA_COLOR3(BorderColor4dV), 0,
  2502. LA_COLOR3(BorderColor4dV), 0.8,
  2503. LA_COLOR3(BorderColor4dV), 0,
  2504. LA_COLOR3(BorderColor4dV), 0.8,
  2505. LA_COLOR3(BorderColor4dV), 0,
  2506. };
  2507. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2508. LA_COLOR3(FillColor4dv), 0,
  2509. LA_COLOR3(FillColor4dv), 0.8,
  2510. LA_COLOR3(FillColor4dv), 0,
  2511. LA_COLOR3(FillColor4dv), 0.8,
  2512. LA_COLOR3(FillColor4dv), 0,
  2513. LA_COLOR3(FillColor4dv), 0.8,
  2514. LA_COLOR3(FillColor4dv), 0,
  2515. };
  2516. tnsUseNoTexture();
  2517. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2518. int Index[4];
  2519. tnsVertexArray2d(DraggingPlot, 8);
  2520. tnsColorArray4d(FillColor, 8);
  2521. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2522. case 0:
  2523. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2524. break;
  2525. case LA_BLOCK_DROP_LOCATION_L:
  2526. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2527. break;
  2528. case LA_BLOCK_DROP_LOCATION_R:
  2529. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2530. break;
  2531. case LA_BLOCK_DROP_LOCATION_U:
  2532. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2533. break;
  2534. case LA_BLOCK_DROP_LOCATION_B:
  2535. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2536. break;
  2537. }
  2538. //glDisable(GL_CULL_FACE);
  2539. tnsIndexArray(Index, 4);
  2540. tnsPackAs(GL_TRIANGLE_FAN);
  2541. //tnsFlush();
  2542. }
  2543. tnsVertexArray2d(DraggingPlot, 8);
  2544. tnsColorArray4d(PlotColor, 8);
  2545. tnsPackAs(GL_LINES);
  2546. tnsVertexArray2d(Square, 4);
  2547. tnsColor4dv(BorderColor4dV);
  2548. tnsPackAs(GL_LINE_LOOP);
  2549. glLineWidth(LA_SEAM_W);
  2550. tnsFlush();
  2551. glLineWidth(1);
  2552. }
  2553. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2554. laBoxedTheme *bt = _LA_THEME_TAB;
  2555. laPanel *p;
  2556. real v[] = {
  2557. b->X, CH - b->Y,
  2558. b->X + LA_SEAM_W, CH - b->Y ,
  2559. b->X, CH - (b->Y + b->H),
  2560. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2561. b->X + b->W, CH - (b->Y + b->H),
  2562. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2563. b->X + b->W, CH - b->Y,
  2564. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2565. real tv[8];
  2566. real ratio = 1.0001f;
  2567. int tw = 0;
  2568. int L = LA_RH+LA_SEAM_W;
  2569. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2570. if(MAIN.EnableColorManagement){
  2571. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2572. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2573. }else{
  2574. tnsUniformOutputColorSpace(T->immShader,0);
  2575. tnsUniformColorComposing(T->immShader,0,0,0);
  2576. }
  2577. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2578. tw += p->TitleWidth + LA_SEAM_W*2;
  2579. }
  2580. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2581. tnsUseNoTexture();
  2582. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2583. tnsVertexArray2d(v, 8);
  2584. tnsPackAs(GL_TRIANGLE_STRIP);
  2585. int TitleGap=b->Folded?0:LA_RH;
  2586. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2587. b->X + b->W, (CH - b->Y),
  2588. b->X + b->W, (CH - b->Y - TitleGap),
  2589. b->X, (CH - b->Y - TitleGap));
  2590. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2591. tnsVertexArray2d(tv, 4);
  2592. tnsPackAs(GL_TRIANGLE_FAN);
  2593. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2594. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2595. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2596. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2597. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2598. tnsVertexArray2d(tv, 4);
  2599. tnsPackAs(GL_TRIANGLE_FAN);
  2600. if(b->Folded){
  2601. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2602. 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);
  2603. 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);
  2604. tnsFlush(); return;
  2605. }
  2606. int LT=0,RT=0;
  2607. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2608. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2609. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2610. b->X + L+RT * ratio, (CH - b->Y),
  2611. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2612. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2613. if (p == b->CurrentPanel){
  2614. tnsUseNoTexture();
  2615. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2616. tnsVertexArray2d(tv, 4);
  2617. tnsPackAs(GL_TRIANGLE_FAN);
  2618. 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);
  2619. }else{
  2620. 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);
  2621. }
  2622. LT =RT;
  2623. }
  2624. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2625. tnsFlush();
  2626. tnsUniformOutputColorSpace(T->immShader,0);
  2627. tnsUniformColorComposing(T->immShader,0,0,0);
  2628. }
  2629. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2630. laBoxedTheme *bt = _LA_THEME_PANEL;
  2631. real tv[8];
  2632. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2633. if(MAIN.EnableColorManagement){
  2634. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2635. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2636. }else{
  2637. tnsUniformOutputColorSpace(T->immShader,0);
  2638. tnsUniformColorComposing(T->immShader,0,0,0);
  2639. }
  2640. tnsUseNoTexture();
  2641. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2642. b->X + b->W, (CH - b->Y),
  2643. b->X + b->W, (CH - b->Y-b->H),
  2644. b->X, (CH - b->Y-b->H));
  2645. tnsVertexArray2d(tv, 4);
  2646. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2647. tnsPackAs(GL_TRIANGLE_FAN);
  2648. 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,
  2649. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2650. tnsFlush();
  2651. tnsUniformOutputColorSpace(T->immShader,0);
  2652. tnsUniformColorComposing(T->immShader,0,0,0);
  2653. }
  2654. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2655. if (b->B1){
  2656. la_BlockDefDrawRecursive(w, bt, b->B1);
  2657. la_BlockDefDrawRecursive(w, bt, b->B2);
  2658. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2659. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2660. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2661. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2662. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2663. la_BlockDefDrawSelf(b, w->CH);
  2664. }else{
  2665. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2666. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2667. la_BlockDefDrawSelfEmpty(b, w->CH);
  2668. }
  2669. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2670. tnsUseNoTexture();
  2671. int at; real tv[8];
  2672. if (b->Vertical){
  2673. at = b->H * b->SplitRatio + b->Y;
  2674. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2675. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2676. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2677. b->X, (w->CH - at - LA_SEAM_W));
  2678. }else{
  2679. at = b->X + b->W * b->SplitRatio;
  2680. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2681. at- LA_SEAM_W, (w->CH - b->Y),
  2682. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2683. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2684. }
  2685. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2686. tnsVertexArray2d(tv, 4);
  2687. tnsPackAs(GL_TRIANGLE_FAN);
  2688. }
  2689. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2690. tnsFlush();
  2691. }
  2692. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2693. if (b->B1){
  2694. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2695. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2696. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2697. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2698. }
  2699. tnsFlush();
  2700. }
  2701. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2702. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2703. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2704. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2705. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2706. if(p->OffScr){
  2707. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2708. }
  2709. }
  2710. }
  2711. void la_ClearUnusedFramebuffers(laWindow* w){
  2712. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2713. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2714. }
  2715. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2716. if(p->Show || p->AnimationMode) continue;
  2717. if(p->OffScr){
  2718. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2719. }
  2720. }
  2721. }
  2722. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2723. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2724. laPanel *p, *NextP;
  2725. laLayout *l = w->CurrentLayout;
  2726. if (!w->CH || !w->CW) return;
  2727. la_ClearUnusedFramebuffers(w);
  2728. tnsDrawToScreen();
  2729. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2730. glClearColor(0.2, 0.2, 0.3, 1.0);
  2731. tnsClearAll();
  2732. tnsUseNoTexture();
  2733. if (l->Draw) l->Draw(w, l);
  2734. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2735. glEnable(GL_BLEND);
  2736. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2737. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2738. laUiItem* ui;
  2739. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2740. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2741. la_SetPropMathcerContext(p);
  2742. if(p->Refresh){
  2743. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2744. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2745. if(MAIN.EnableColorManagement){
  2746. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2747. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2748. }else{
  2749. tnsUniformOutputColorSpace(T->immShader,0);
  2750. tnsUniformColorComposing(T->immShader,0,0,0);
  2751. }
  2752. if(p->Refresh&LA_TAG_RECALC){
  2753. laRecalcPanelImmediate(p);
  2754. }
  2755. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2756. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2757. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2758. }
  2759. tnsDrawToScreen();
  2760. tnsResetViewMatrix();
  2761. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2762. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2763. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2764. tnsFlush();
  2765. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2766. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2767. tnsFlush();
  2768. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2769. }
  2770. }
  2771. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2772. la_AttachedPanelDefDraw(w,p,*p->BT);
  2773. }else{
  2774. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2775. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2776. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2777. }
  2778. for (p = w->Panels.pLast; p; p = NextP){
  2779. NextP = p->Item.pPrev;
  2780. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2781. if (p->AnimationMode && p->LaterDestroy){
  2782. lstRemoveItem(&w->Panels, p);
  2783. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2784. continue;
  2785. }
  2786. la_PanelDefDraw(w, p, *p->BT);
  2787. }
  2788. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2789. la_AttachedPanelDefDraw(w,p,*p->BT);
  2790. }
  2791. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2792. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2793. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2794. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2795. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2796. tnsFlush();
  2797. }
  2798. for (p = w->FadingPanels.pLast; p; p = NextP){
  2799. NextP = p->Item.pPrev;
  2800. if (!p->AnimationMode){
  2801. lstRemoveItem(&w->FadingPanels, p);
  2802. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2803. laDeferredDestroyPanel(p, 0);
  2804. }else
  2805. la_PanelDrawToWindow(p, w);
  2806. }
  2807. if(MAIN.ShowPerf){
  2808. la_PerfDraw();
  2809. }
  2810. }
  2811. int laStartWindow(laWindow *w){
  2812. #ifdef LA_LINUX
  2813. XMapWindow(MAIN.dpy,w->win);
  2814. tnsContextMakeWindowCurrent(w);
  2815. #endif
  2816. #ifdef _WIN32
  2817. ShowWindow(w->win, SW_SHOWNORMAL);
  2818. #endif
  2819. MAIN.CurrentWindow = w;
  2820. if(!w->CurrentLayout){
  2821. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2822. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2823. }
  2824. laRedrawCurrentWindow();
  2825. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2826. w->Shown = 1;
  2827. }
  2828. void la_AssignWindowPP(laWindow* w){
  2829. w->PP.EndInstance = w;
  2830. w->PP.LastPs = &w->FakePS;
  2831. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2832. w->PP.LastPs->UseInstance = w;
  2833. w->PP.LastPs->Type = U'.';
  2834. }
  2835. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2836. #ifdef LAGUI_ANDROID
  2837. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2838. #endif
  2839. laWindow *n = memAcquire(sizeof(laWindow));
  2840. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2841. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2842. #ifdef LAGUI_ANDROID
  2843. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2844. #endif
  2845. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2846. lstAppendItem(&MAIN.Windows, n);
  2847. MAIN.CurrentWindow = n;
  2848. la_AssignWindowPP(n);
  2849. laui_DefaultMenuBar(n);
  2850. return n;
  2851. }
  2852. void laSetWindowCursor(int id){
  2853. MAIN.CurrentCursor = id;
  2854. #ifdef LA_LINUX
  2855. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2856. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2857. #endif
  2858. #ifdef _WIN32
  2859. SetCursor(la_ConvertCursorID(id));
  2860. #endif
  2861. };
  2862. void la_AssignBlockPP(laBlock* b){
  2863. b->PP.EndInstance = b;
  2864. b->PP.LastPs = &b->FakePS;
  2865. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2866. b->PP.LastPs->UseInstance = b;
  2867. b->PP.LastPs->Type = U'.';
  2868. }
  2869. void laDestroyLayout(laWindow *w, laLayout* l){
  2870. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2871. laDestroyBlocksRecursive(l->FirstBlock);
  2872. strSafeDestroy(&l->ID);
  2873. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2874. lstRemoveItem(&w->Layouts,l); memFree(l);
  2875. }
  2876. laLayout *laDesignLayout(laWindow *w, char *Title){
  2877. laLayout *l = memAcquire(sizeof(laLayout));
  2878. l->FirstBlock = memAcquire(sizeof(laBlock));
  2879. la_AssignBlockPP(l->FirstBlock);
  2880. lstAppendItem(&w->Layouts, l);
  2881. strSafeSet(&l->ID, Title);
  2882. memAssignRef(w, &w->CurrentLayout, l);
  2883. laRenameWindow(w, Title);
  2884. return l;
  2885. }
  2886. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2887. 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); }
  2888. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2889. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2890. laNotifyUsers("la.windows.maximized_block"); }
  2891. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2892. laNotifyUsers("la.windows.maximized_block"); }
  2893. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2894. laRestoreCanvasUI();
  2895. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2896. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2897. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2898. UiParentPanel->Show=0;
  2899. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2900. }
  2901. void laRestoreCanvasUI(){
  2902. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2903. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2904. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2905. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2906. }
  2907. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2908. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2909. }
  2910. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2911. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2912. laPanel *p;
  2913. b->SplitRatio = Percentage;
  2914. b->Vertical = 0;
  2915. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2916. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2917. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2918. p->Block = b->B1;
  2919. }
  2920. b->B1->Panels.pFirst = b->Panels.pFirst;
  2921. b->B1->Panels.pLast = b->Panels.pLast;
  2922. b->B1->CurrentPanel = b->CurrentPanel;
  2923. b->B1->parent = b->B2->parent=b;
  2924. b->Panels.pFirst = 0;
  2925. b->Panels.pLast = 0;
  2926. b->CurrentPanel = 0;
  2927. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2928. }
  2929. void laSplitBlockVertical(laBlock *b, real Percentage){
  2930. laPanel *p;
  2931. b->SplitRatio = Percentage;
  2932. b->Vertical = 1;
  2933. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2934. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2935. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2936. p->Block = b->B1;
  2937. }
  2938. b->B1->Panels.pFirst = b->Panels.pFirst;
  2939. b->B1->Panels.pLast = b->Panels.pLast;
  2940. b->B1->CurrentPanel = b->CurrentPanel;
  2941. b->B1->parent = b->B2->parent=b;
  2942. b->Panels.pFirst = 0;
  2943. b->Panels.pLast = 0;
  2944. b->CurrentPanel = 0;
  2945. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2946. }
  2947. void laCombineChildBlocks(laBlock *b){
  2948. laPanel *p; if(!b) return;
  2949. if (!b->B1->B1 && !b->B2->B1){
  2950. lstCombineLists(&b->Panels, &b->B1->Panels);
  2951. lstCombineLists(&b->Panels, &b->B2->Panels);
  2952. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2953. p->Block = b;
  2954. }
  2955. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2956. memFree(b->B1);
  2957. memFree(b->B2);
  2958. b->B1 = 0;
  2959. b->B2 = 0;
  2960. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2961. }elif(!b->B1->B1){
  2962. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2963. b->Vertical = b->B2->Vertical;
  2964. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2965. p->Block = b1;
  2966. }
  2967. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2968. memFree(b->B1); memFree(b->B2);
  2969. b->B1 = b1; b->B2 = b2;
  2970. b1->parent = b; b2->parent = b;
  2971. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2972. }elif(!b->B2->B1){
  2973. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2974. b->Vertical = b->B1->Vertical;
  2975. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2976. p->Block = b1;
  2977. }
  2978. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2979. memFree(b->B1); memFree(b->B2);
  2980. b->B1 = b1; b->B2 = b2;
  2981. b1->parent = b; b2->parent = b;
  2982. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2983. }
  2984. }
  2985. laBlock *laBlock1(laBlock *b){
  2986. return b->B1;
  2987. }
  2988. laBlock *laBlock2(laBlock *b){
  2989. return b->B2;
  2990. }
  2991. laBlock *laSwapSubBlocks(laBlock *b){
  2992. laBlock *tB;
  2993. tB = b->B2;
  2994. b->B2 = b->B1;
  2995. b->B1 = tB;
  2996. b->SplitRatio = 1 - b->SplitRatio;
  2997. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2998. }
  2999. void laDestroyBlocksRecursive(laBlock *Root){
  3000. laPanel *p;
  3001. if (Root->B1){
  3002. laDestroyBlocksRecursive(Root->B1);
  3003. laDestroyBlocksRecursive(Root->B2);
  3004. }else{
  3005. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  3006. }
  3007. memFree(Root);
  3008. }
  3009. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  3010. if(!b->CurrentPanel ) return 0;
  3011. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  3012. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  3013. lstRemoveItem(&b->Panels, p);
  3014. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  3015. if(!p->TitleBar.UiItems.pFirst){
  3016. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  3017. }
  3018. p->Mode = LA_PANEL_FLOATING_TOP;
  3019. p->TY-=LA_RH; p->TH+=LA_RH;
  3020. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  3021. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  3022. p->Block = 0;
  3023. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  3024. laRecalcPanel(p);
  3025. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3026. p->BT = &_LA_THEME_FLOATING_PANEL;
  3027. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3028. laNotifyUsers("la.windows.panels");
  3029. return b->CurrentPanel;
  3030. }
  3031. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  3032. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  3033. lstRemoveItem(&from->Panels, p);
  3034. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3035. p->Mode = LA_PANEL_NORMAL;
  3036. p->Block=b;
  3037. b->CurrentPanel = p;
  3038. lstPushItem(&b->Panels, p);
  3039. laRecalcPanel(p);
  3040. p->BT = &_LA_THEME_PANEL;
  3041. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3042. tnsFlush();
  3043. laNotifyUsers("la.windows.panels");
  3044. }
  3045. void laPopPanel(laPanel *p){
  3046. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  3047. lstRemoveItem(&p->Parent->SubPanels, p);
  3048. lstPushItem(&p->Parent->SubPanels, p);
  3049. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3050. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3051. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3052. laNotifyUsers("la.windows.panels");
  3053. }
  3054. }
  3055. void la_EnsurePanelExtras(laPanel *p){
  3056. laUiTemplate* uit=p->PanelTemplate;
  3057. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  3058. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  3059. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  3060. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  3061. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  3062. p->PropLinkFakeProp->Base.Offset = 0;
  3063. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  3064. p->PropLinkPP.EndInstance = p;
  3065. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3066. p->PropLinkPP.LastPs->Type = U'.';
  3067. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3068. }
  3069. laPanel* la_GivePanelNode(){
  3070. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3071. return memAcquire(sizeof(laPanel));
  3072. }
  3073. void la_ReturnPanelNode(laPanel* p){
  3074. memset(p,0,sizeof(laPanel));
  3075. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3076. lstAppendItem(&MAIN.WastedPanels, p);
  3077. }
  3078. 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){
  3079. laPanel *p = la_GivePanelNode();
  3080. int CW = MAIN.CurrentWindow->CW;
  3081. int CH = MAIN.CurrentWindow->CH;
  3082. p->PanelTemplate = uit;
  3083. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3084. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3085. if (!MaxW) MaxW = 10000;
  3086. if (!MaxH) MaxH = 10000;
  3087. if (W > MaxW) W = MaxW;
  3088. if (H > MaxH) H = MaxH;
  3089. if (W < MinW) W = MinW;
  3090. if (H < MinH) H = MinH;
  3091. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3092. p->X = p->TX = (X < 0 ? 0 : X);
  3093. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3094. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3095. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3096. p->MaxW = MaxW; p->MaxH = MaxH;
  3097. p->MinW = MinW; p->MinH = MinH;
  3098. p->SL = SnapL; p->ST = SnapT;
  3099. p->SR = SnapR; p->SB = SnapB;
  3100. if (p->SR) p->X = CW - p->W - p->SR;
  3101. if (p->SB) p->Y = CH - p->H - p->SB;
  3102. la_EnsurePanelSnapping(p, CW, CH);
  3103. p->Show = 1;
  3104. p->PP.EndInstance = p;
  3105. p->PP.LastPs = &p->FakePS;
  3106. p->PP.LastPs->p = _LA_PROP_PANEL;
  3107. p->PP.LastPs->UseInstance = p;
  3108. p->PP.LastPs->Type = U'.';
  3109. la_EnsurePanelExtras(p);
  3110. laRecalcPanel(p);
  3111. p->FrameDistinguish = 100; //greater than 1 is ok
  3112. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3113. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3114. return p;
  3115. }
  3116. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3117. if(!uit) return 0;
  3118. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3119. strSafeSet(&p->Title, uit->Title->Ptr);
  3120. p->PanelTemplate = uit;
  3121. p->Show = 1;
  3122. p->PP.EndInstance = p;
  3123. p->PP.LastPs = &p->FakePS;
  3124. p->PP.LastPs->p = _LA_PROP_PANEL;
  3125. p->PP.LastPs->UseInstance = p;
  3126. p->PP.LastPs->Type = U'.';
  3127. la_EnsurePanelExtras(p);
  3128. laRecalcPanel(p);
  3129. p->FrameDistinguish = 100; //greater than 1 is ok
  3130. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3131. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3132. p->Block = b; b->CurrentPanel = p;
  3133. if(uit->PropFunc){ uit->PropFunc(p); }
  3134. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3135. laNotifyUsers("la.windows.panels");
  3136. return p;
  3137. }
  3138. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3139. laUiTemplate* uit=laFindUiTemplate(template_id);
  3140. return laCreatePanelT(b, uit);
  3141. }
  3142. 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){
  3143. laUiTemplate* uit=0;
  3144. if(template_id) uit=laFindUiTemplate(template_id);
  3145. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3146. p->Mode = LA_PANEL_FLOATING_TOP;
  3147. laPlacePanelForCreation(p);
  3148. if(uit){
  3149. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3150. }
  3151. if (w) lstPushItem(&w->Panels, p);
  3152. return p;
  3153. }
  3154. void laShowPanel(laPanel *p){
  3155. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3156. }
  3157. void laShowPanelWithDropDownEffect(laPanel *p){
  3158. laShowPanel(p);
  3159. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3160. p->AnimationRatio = 0;
  3161. }
  3162. void laShowPanelWithExpandEffect(laPanel *p){
  3163. laShowPanel(p);
  3164. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3165. p->AnimationRatio = 0;
  3166. }
  3167. void laHidePanel(laPanel *p){
  3168. if (!p->Mode) return;
  3169. p->Show = 0;
  3170. laNotifyUsers("la.windows.panels_hidden");
  3171. }
  3172. void laHidePanelWithDissoveEffect(laPanel *p){
  3173. if (!p->Mode) return;
  3174. laHidePanel(p);
  3175. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3176. p->AnimationRatio = 1;
  3177. }
  3178. void laHidePanelWithCollapseEffect(laPanel *p){
  3179. if (!p->Mode) return;
  3180. laHidePanel(p);
  3181. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3182. p->AnimationRatio = 1;
  3183. }
  3184. void laHidePanelWithMinimizeEffect(laPanel *p){
  3185. if (!p->Mode) return;
  3186. laHidePanel(p);
  3187. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3188. p->AnimationRatio = 1;
  3189. }
  3190. void laActivatePanel(char* TemplateID, int x, int y){
  3191. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3192. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3193. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3194. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3195. }
  3196. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3197. p->UI.PanX += DeltaX;
  3198. p->UI.PanY += DeltaY;
  3199. }
  3200. int laPanUiListFree(laUiList *uil, int X, int Y){
  3201. uil->PanX+=X; uil->PanY+=Y;
  3202. }
  3203. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3204. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3205. if(Y){X+=Y;Y=0;}
  3206. }
  3207. if (Y > 0){
  3208. if (uil->B - uil->PanY <= B) return 0;
  3209. else{
  3210. uil->PanY += Y;
  3211. if (uil->B - uil->PanY <= B){
  3212. uil->PanY = uil->B - B;
  3213. return 1;
  3214. }
  3215. }
  3216. }
  3217. if (Y < 0){
  3218. if (uil->U - uil->PanY >= U) return 0;
  3219. else{
  3220. uil->PanY += Y;
  3221. if (uil->U - uil->PanY >= U){
  3222. uil->PanY = uil->U - U;
  3223. return 1;
  3224. }
  3225. }
  3226. }
  3227. if(uil->AllowScale){
  3228. laPanUiListFree(uil, X, 0);
  3229. }else{
  3230. if (X > 0){
  3231. if (uil->R - uil->PanX <= R) return 0;
  3232. else{
  3233. uil->PanX += X;
  3234. if (uil->R - uil->PanX <= R){
  3235. uil->PanX = uil->R - R;
  3236. return 1;
  3237. }
  3238. }
  3239. }
  3240. if (X < 0){
  3241. if (uil->L - uil->PanX >= L) return 0;
  3242. else{
  3243. uil->PanX += X;
  3244. if (uil->L - uil->PanX >= L){
  3245. uil->PanX = uil->L - L;
  3246. return 1;
  3247. }
  3248. }
  3249. }
  3250. }
  3251. return 1;
  3252. }
  3253. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3254. int ret=1;
  3255. if(!uil->AllowScale){ return 0; }
  3256. real NewScale=uil->Scale*factor;
  3257. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3258. if(NewScale>5) {NewScale=5; ret=0;}
  3259. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3260. factor=NewScale/uil->Scale;
  3261. uil->Scale=NewScale;
  3262. real mx=(L+R)/2,my=(U+B)/2;
  3263. real dx= (mx+uil->PanX)*factor;
  3264. real dy= (my+uil->PanY)*factor;
  3265. uil->PanX=dx-mx;
  3266. uil->PanY=dy-my;
  3267. MAIN.CurrentPanel->FrameDistinguish=100;
  3268. return ret;
  3269. }
  3270. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3271. if(uil->AllowScale) return 0;
  3272. return laPanUiList(uil,X,Y,L,R,U,B);
  3273. }
  3274. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3275. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3276. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3277. strSafeSet(&p->Title, Title);
  3278. if (Define){
  3279. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3280. }
  3281. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3282. p->BT= &_LA_THEME_FLOATING_PANEL;
  3283. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3284. p->BoundUi = 1;
  3285. return p;
  3286. }
  3287. 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,
  3288. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3289. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3290. strSafeSet(&p->Title, Title);
  3291. if (Define){
  3292. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3293. }
  3294. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3295. p->BT= &_LA_THEME_FLOATING_PANEL;
  3296. p->Mode = LA_PANEL_FLOATING_TOP;
  3297. p->BoundUi = 1;
  3298. return p;
  3299. }
  3300. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3301. laPanel *ip;
  3302. tnsDelete2DOffscreen(p->OffScr);
  3303. p->OffScr = 0;
  3304. strSafeDestroy(&p->Title);
  3305. if (!p->AnimationMode){
  3306. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3307. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3308. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3309. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3310. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3311. }else if (p->Block){
  3312. lstRemoveItem(&p->Block->Panels, p);
  3313. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3314. }
  3315. laNotifyUsers("la.windows.panels");
  3316. }
  3317. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3318. //lstRemoveItem(&p->SubPanels, ip);
  3319. laDestroySinglePanel(ip, immediate);
  3320. laNotifyUsers("la.windows.panels");
  3321. }
  3322. la_ClearDetachedProp(p);
  3323. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3324. la_ReturnPanelNode(p);
  3325. }
  3326. void laDestroySinglePanel(laPanel *p, int immediate){
  3327. la_SetPropMathcerContext(p);
  3328. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3329. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3330. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3331. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3332. }
  3333. }
  3334. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3335. la_DestroyUiList(&p->UI, 1, 1, 0);
  3336. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3337. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3338. if (p->Mode){
  3339. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3340. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3341. }
  3342. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3343. if (la_UiStillInService(p)){
  3344. la_StopUiOperatorService(p);
  3345. }
  3346. if ((!p->AnimationMode) || immediate){
  3347. laDeferredDestroyPanel(p, immediate);
  3348. }else{
  3349. p->LaterDestroy = 1;
  3350. }
  3351. }
  3352. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3353. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3354. int MinW,MinWt=0;
  3355. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3356. int CW = MAIN.CurrentWindow->CW;
  3357. if(p->SL && p->SR){return 0;}
  3358. la_SetPropMathcerContext(p);
  3359. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3360. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3361. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3362. MinW = la_TestUiListMinumWidth(uil);
  3363. if (MinW<MinWt){MinW=MinWt;}
  3364. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3365. if (MinW > 20){
  3366. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3367. }
  3368. la_PanelValidateWidth(p,uil);
  3369. laEnsurePanelInBound(p,uil);
  3370. if(p->TW>CW){ p->TW=CW; }
  3371. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3372. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3373. laRedrawPanel(p);
  3374. return 1;
  3375. }
  3376. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3377. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3378. laOperator *ai = a;
  3379. laPanel *p;
  3380. int GX, GY, GW, t = 0;
  3381. int b;
  3382. laUiDefineFunc def = ReplaceUiDefine;
  3383. int MinW;
  3384. if (!def){ def=laui_DefaultPropDetails; }
  3385. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3386. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3387. laEnclosePanelContent(p, &p->UI);
  3388. laSetOperatorLocalizer(p);
  3389. p->CloseWhenMovedOut=1;
  3390. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3391. //laShowPanelWithDropDownEffect(p);
  3392. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3393. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3394. return p;
  3395. }
  3396. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3397. laPanel *p;
  3398. int GX, GY, GW, t = 0;
  3399. int b;
  3400. laUiDefineFunc def = ReplaceUiDefine;
  3401. int MinW;
  3402. if (!def) return 0;
  3403. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3404. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3405. p->Mode = LA_PANEL_FLOATING_TOP;
  3406. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3407. laEnclosePanelContent(p, &p->UI);
  3408. if(MAIN.CurrentWindow->Operators.pFirst){
  3409. laSetOperatorLocalizer(MAIN.PendingSplash);
  3410. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3411. MAIN.PendingSplash=0;
  3412. }
  3413. //laShowPanelWithExpandEffect(p);
  3414. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3415. return p;
  3416. }
  3417. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3418. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3419. laOperator *ai = a;
  3420. laPanel *p; laPropContainer* sub;
  3421. int GX, GY, GW, t = 0;
  3422. int b;
  3423. laUiDefineFunc def = ReplaceUiDefine;
  3424. int MinW;
  3425. if (!def){
  3426. if (This && This->LastPs->p){
  3427. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3428. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3429. }
  3430. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3431. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3432. }
  3433. GX = L; GY = B;
  3434. GW = (R - L) > MaxW ? MaxW : (R - L);
  3435. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3436. laEnclosePanelContent(p, &p->UI);
  3437. laSetOperatorLocalizer(p);
  3438. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3439. laShowPanelWithDropDownEffect(p);
  3440. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3441. if(Attachment){
  3442. p->Parent = Attachment;
  3443. lstAppendItem(&Attachment->SubPanels, p);
  3444. }
  3445. return p;
  3446. }
  3447. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3448. laPanel *p;
  3449. int t = 0;
  3450. int b;
  3451. //laLocalToWindow(0, Attachment, &L, &t);
  3452. //laLocalToWindow(0, Attachment, &R, &U);
  3453. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3454. laSetOperatorLocalizer(p);
  3455. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3456. laShowPanelWithDropDownEffect(p);
  3457. p->Parent = Attachment;
  3458. lstPushItem(&Attachment->SubPanels, p);
  3459. return p;
  3460. }
  3461. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3462. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3463. laOperator *ai = a;
  3464. laPanel *p;
  3465. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3466. int GX, GY, GW, t = 0;
  3467. int b;
  3468. int MinW;
  3469. //laLocalToWindow(0,Attachment, &L, &t);
  3470. //laLocalToWindow(0,Attachment, &R, &B);
  3471. GX = L;
  3472. GY = B;
  3473. GW = (R - L) > MaxW ? MaxW : (R - L);
  3474. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3475. p->MenuRefer = MenuRefer;
  3476. laEnclosePanelContent(p, MenuRefer);
  3477. laSetOperatorLocalizer(p);
  3478. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3479. laShowPanelWithDropDownEffect(p);
  3480. p->Parent = Attachment;
  3481. lstPushItem(&Attachment->SubPanels, p);
  3482. return p;
  3483. }
  3484. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3485. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3486. laOperator *ai = a;
  3487. laPanel *p;
  3488. int GX, GY, GW, t = 0;
  3489. int b;
  3490. GX = L;
  3491. GY = B;
  3492. GW = MaxW;
  3493. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3494. p->MenuRefer = &p->UI;
  3495. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3496. laSetOperatorLocalizer(p);
  3497. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3498. laShowPanelWithDropDownEffect(p);
  3499. if (Attachment){
  3500. p->Parent = Attachment;
  3501. lstPushItem(&Attachment->SubPanels, p);
  3502. }else{
  3503. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3504. }
  3505. return p;
  3506. }
  3507. 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){
  3508. laOperator *ai = For;
  3509. laPanel *p;
  3510. int b;
  3511. laUiDefineFunc def = 0;
  3512. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3513. else def = laui_DefaultPropUiDefine;
  3514. For->PP.EndInstance = For->CustomData;
  3515. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3516. laEnclosePanelContent(p, &p->UI);
  3517. MAIN.ToPanel = p;
  3518. laShowPanelWithExpandEffect(p);
  3519. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3520. ai->OperatorPanel = p;
  3521. p->ParentOperator = For;
  3522. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3523. return p;
  3524. }
  3525. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3526. laPanel *p; int b; laUiList *uil; laColumn* col;
  3527. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3528. strSafeSet(&p->Title, Title);
  3529. p->BoundUi = 1;
  3530. p->Mode = LA_PANEL_FLOATING_TOP;
  3531. p->BT = &_LA_THEME_FLOATING_PANEL;
  3532. MAIN.ToPanel = p;
  3533. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3534. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3535. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3536. laUiItem* r=laBeginRow(uil,col,0,0);
  3537. laShowSeparator(uil,col)->Expand=1;
  3538. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3539. laEndRow(uil,r);
  3540. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3541. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3542. laSetOperatorLocalizer(p);
  3543. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3544. return p;
  3545. }
  3546. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3547. laPanel *p; int b; laUiList *uil; laColumn* col;
  3548. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3549. strSafeSet(&p->Title, Title);
  3550. p->BoundUi = 1;
  3551. p->Mode = LA_PANEL_FLOATING_TOP;
  3552. p->BT = &_LA_THEME_FLOATING_PANEL;
  3553. MAIN.ToPanel = p;
  3554. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3555. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3556. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3557. laUiItem* r = laBeginRow(uil,col,0,0);
  3558. laShowSeparator(uil,col)->Expand=1;
  3559. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3560. laEndRow(uil, r);
  3561. laEnclosePanelContent(p,uil);
  3562. laShowPanelWithExpandEffect(p);
  3563. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3564. laSetOperatorLocalizer(p);
  3565. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3566. return p;
  3567. }
  3568. void laOperatorModalOver(laOperator* For){
  3569. For->ModalOver = 1;
  3570. }
  3571. void laDeferredRedraw(laPanel* p){
  3572. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3573. if(lip->p==p) return;
  3574. }
  3575. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3576. }
  3577. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3578. laWindow* cur=MAIN.CurrentWindow;
  3579. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3580. MAIN.CurrentWindow=w;
  3581. la_UpdateUiPlacement(w);
  3582. }
  3583. MAIN.CurrentWindow=cur;
  3584. }
  3585. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3586. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3587. }
  3588. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3589. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3590. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3591. void laRedrawCurrentPanel(){
  3592. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3593. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3594. }
  3595. void laRecalcCurrentPanel(){
  3596. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3597. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3598. }
  3599. void laRecalcPanelImmediate(laPanel* p){
  3600. p->FrameDistinguish++;
  3601. laBoxedTheme* bt = (*p->BT);
  3602. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3603. la_PanelRefreshDetachedProp(p);
  3604. int enclosed=0;
  3605. if(p->BoundUi || p->MenuRefer){
  3606. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3607. else enclosed=laEnclosePanelContent(p, &p->UI);
  3608. }
  3609. if(!enclosed){
  3610. la_PanelValidateWidth(p,&p->UI);
  3611. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3612. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3613. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3614. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3615. }
  3616. laWindow* w=MAIN.CurrentWindow;
  3617. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3618. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3619. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3620. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3621. }
  3622. }
  3623. void laRecalcCurrentPanelImmediate(){
  3624. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3625. }
  3626. int laNonFixedPanelExists(laPanel *p){
  3627. laPanel *ip;
  3628. if (!p) return 0;
  3629. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3630. // if (ip == p) return 1;
  3631. //}
  3632. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3633. if (ip == p) return 1;
  3634. }
  3635. return 0;
  3636. }
  3637. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3638. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3639. return 1;
  3640. }
  3641. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3642. int tt=MAIN.TooltipCloseDistance;
  3643. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3644. return 1;
  3645. }
  3646. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3647. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3648. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3649. return 0;
  3650. return 1;
  3651. }
  3652. void laUnlinkSharedPanel(laPanel *p){
  3653. laWindow *w;
  3654. laPanel *ip;
  3655. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3656. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3657. if (ip == p){
  3658. lstRemoveItem(&w->Panels, ip);
  3659. return;
  3660. }
  3661. }
  3662. }
  3663. }
  3664. int laIsPanelCovered(laPanel *p){
  3665. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3666. laPanel *ip;
  3667. laPanel *resp;
  3668. int in1 = 0, in2 = 0, in3 = 0;
  3669. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3670. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3671. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3672. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3673. //}
  3674. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3675. if (ip == p){
  3676. in3 = 1;
  3677. d3 = 0;
  3678. continue;
  3679. }
  3680. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3681. }
  3682. if (!in2 && !in3) in1 = 1;
  3683. if (in1){
  3684. if (d1 || d2 || d3) return 1;
  3685. }else{
  3686. if (in2){
  3687. if (d2 || d3) return 1;
  3688. }else if (in3)
  3689. if (d3) return 1;
  3690. }
  3691. return 0;
  3692. }
  3693. int laIsTopPanel(laPanel *p){
  3694. //if (!p->Item.pPrev) return 1;
  3695. //else {
  3696. if (!laIsPanelCovered(p)){
  3697. //laPopPanel(p);
  3698. return 1;
  3699. }
  3700. return 0;
  3701. //}
  3702. return 0;
  3703. }
  3704. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3705. if(!p) return;
  3706. int ix = *x, iy = *y;
  3707. laListItemPointer *lip;
  3708. laOperator *ai = a;
  3709. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3710. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3711. if (a){
  3712. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3713. laUiList *uil = lip->p;
  3714. (*x) += uil->PanX;
  3715. (*y) += uil->PanY;
  3716. }
  3717. }
  3718. }
  3719. void laPanelToLocal(laOperator *a, int *x, int *y){
  3720. int ix = *x, iy = *y;
  3721. laListItemPointer *lip;
  3722. if (a){
  3723. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3724. laUiList *uil = lip->p;
  3725. (*x) += uil->PanX;
  3726. (*y) += uil->PanY;
  3727. }
  3728. }
  3729. }
  3730. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3731. if(!p) return;
  3732. int ix = *x, iy = *y;
  3733. laListItemPointer *lip;
  3734. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3735. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3736. if (a){
  3737. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3738. laUiList *uil = lip->p;
  3739. (*x) -= uil->PanX;
  3740. (*y) -= uil->PanY;
  3741. }
  3742. }
  3743. }
  3744. void laPanelToWindow(laPanel *p, int *x, int *y){
  3745. int ix = *x, iy = *y;
  3746. laListItemPointer *lip;
  3747. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3748. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3749. }
  3750. void laLocalToPanel(laOperator *a, int *x, int *y){
  3751. int ix = *x, iy = *y;
  3752. laListItemPointer *lip;
  3753. if (a){
  3754. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3755. laUiList *uil = lip->p;
  3756. (*x) -= uil->PanX;
  3757. (*y) -= uil->PanY;
  3758. }
  3759. }
  3760. }
  3761. void laSetNextMenuPos(int X, int Y, int W, int H){
  3762. MAIN.NextX = X;
  3763. MAIN.NextY = Y;
  3764. MAIN.NextW = W;
  3765. MAIN.NextH = H;
  3766. }
  3767. int laIsInBlock(laBlock *b, int X, int Y){
  3768. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3769. return 0;
  3770. }
  3771. 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; }
  3772. 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; }
  3773. 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; }
  3774. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3775. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3776. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3777. if (!b->B1 && !b->B2){
  3778. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3779. }
  3780. }
  3781. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3782. laPanel *p;
  3783. laBlock *sb = 0;
  3784. if (!laIsInBlock(b, X, Y)) return 0;
  3785. if (!b->B1 && !b->B2) return b;
  3786. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3787. return laDetectBlockRecursive(b->B2, X, Y);
  3788. }
  3789. laPanel *laDetectPanel(int X, int Y){
  3790. laPanel *p; laBlock *b;
  3791. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3792. int x = X, y = Y;
  3793. laWindowToLocal(0, p, &x, &y);
  3794. if (p->Show && laIsInPanel(p, x, y)){
  3795. return p;
  3796. }
  3797. }
  3798. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3799. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3800. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3801. return 0;
  3802. }
  3803. laUiList *laPrepareUi(laPanel *p){
  3804. return &p->UI;
  3805. }
  3806. laColumn *laFirstColumn(laUiList *uil){
  3807. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3808. else{
  3809. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3810. c->SP = 1;
  3811. c->PreWidth = 1;
  3812. lstAppendItem(&uil->Columns, c);
  3813. c->Top = c;
  3814. return uil->Columns.pFirst;
  3815. }
  3816. }
  3817. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3818. laColumn *lc, *rc;
  3819. if (c->LS || c->RS) return c;
  3820. lc = memAcquireSimple(sizeof(laColumn));
  3821. rc = memAcquireSimple(sizeof(laColumn));
  3822. c->LS = lc;
  3823. c->RS = rc;
  3824. c->LS->SP = Percent;
  3825. c->RS->SP = Percent;
  3826. c->LS->Top = c->Top;
  3827. c->RS->Top = c->Top;
  3828. if (uil){
  3829. lstAppendItem(&uil->Columns, lc);
  3830. lstAppendItem(&uil->Columns, rc);
  3831. }
  3832. if (c->LS && c->RS->MaxW == 0){
  3833. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3834. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3835. }else if (c->RS && c->LS->MaxW == 0){
  3836. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3837. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3838. }
  3839. return c;
  3840. }
  3841. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3842. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3843. return c->LS;
  3844. }
  3845. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3846. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3847. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3848. return c->RS;
  3849. }
  3850. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3851. lstRemoveItem(List, c);
  3852. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3853. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3854. memFree(c);
  3855. }
  3856. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3857. laUiList *uil = TopUil;
  3858. laUiList *sub;
  3859. laUiItem *ui;
  3860. laColumn *cc, *NextCC = 0;
  3861. int Occupied = 0;
  3862. int Removed = 0;
  3863. if (!c->LS) return 0;
  3864. else{
  3865. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3866. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3867. }
  3868. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3869. if (ui->C == c->LS || ui->C == c->RS){
  3870. if (DoMerge){
  3871. ui->C = c;
  3872. Occupied = 1;
  3873. }else
  3874. return 1;
  3875. }
  3876. if (ui->Subs.pFirst){
  3877. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3878. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3879. }
  3880. }
  3881. }
  3882. if (!Removed){
  3883. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3884. if (cc == c){
  3885. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3886. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3887. c->LS = 0;
  3888. c->RS = 0;
  3889. Removed = 1;
  3890. break;
  3891. }
  3892. }
  3893. }
  3894. return Occupied;
  3895. }
  3896. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3897. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3898. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3899. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3900. ut->FakeProp->Base.Identifier = ut->Identifier;
  3901. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3902. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3903. ut->FakeProp->Base.OffsetIsPointer = 1;
  3904. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3905. return ut->ExtraProps;
  3906. }
  3907. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3908. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3909. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3910. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3911. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3912. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3913. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3914. ct->FakeProp->Base.OffsetIsPointer = 1;
  3915. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3916. return ct->ExtraProps;
  3917. }
  3918. void la_DestroyUiType(laUiType* uit){
  3919. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3920. memFree(uit);
  3921. }
  3922. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3923. laUiType *ut = memAcquire(sizeof(laUiType));
  3924. ut->Identifier = Identifer;
  3925. ut->OperatorID = UseOperator;
  3926. ut->Draw = Draw;
  3927. ut->Theme = bt;
  3928. ut->ForType = ForType;
  3929. ut->OperatorType = laGetOperatorType(UseOperator);
  3930. ut->GetHeight = GetHeight;
  3931. ut->Init = Init;
  3932. ut->Destroy = Destroy;
  3933. la_UDFAppendSharedTypePointer(Identifer, ut);
  3934. lstAppendItem(&MAIN.UiTypes, ut);
  3935. return ut;
  3936. }
  3937. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3938. laUiType *ut = MAIN.UiTypes.pFirst;
  3939. if (!P) return 0;
  3940. if (P->DefaultUiType) return P->DefaultUiType;
  3941. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3942. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3943. for (ut; ut; ut = ut->Item.pNext){
  3944. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3945. return ut;
  3946. }
  3947. }
  3948. return 0;
  3949. }
  3950. laUiType *la_GetUiButtonType(){
  3951. laUiType *ut = MAIN.UiTypes.pFirst;
  3952. for (ut; ut; ut = ut->Item.pNext){
  3953. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3954. }
  3955. return 0;
  3956. }
  3957. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3958. laCanvasTemplate *vdt;
  3959. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3960. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3961. }
  3962. return 0;
  3963. }
  3964. void la_AssignPropExtras(laUiItem* ui){
  3965. if(!ui->Type || !ui->Type->FakeProp) return;
  3966. ui->FakePs.p = ui->Type->FakeProp;
  3967. ui->FakePs.Type = U'.';
  3968. ui->FakePs.UseInstance = ui;
  3969. ui->ExtraPP.LastPs = &ui->FakePs;
  3970. }
  3971. void la_AssignCanvasPropExtras(laUiItem* ui){
  3972. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3973. laCanvasTemplate*ct=ui->CanvasTemplate;
  3974. ui->FakePs.p = ct->FakeProp;
  3975. ui->FakePs.Type = U'.';
  3976. ui->FakePs.UseInstance = ui;
  3977. ui->ExtraPP.EndInstance = ui->Extra;
  3978. ui->ExtraPP.LastPs = &ui->FakePs;
  3979. }
  3980. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3981. int result;
  3982. if (!ui) return 0;
  3983. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3984. if (Path){
  3985. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3986. if (!result){
  3987. ui->AT = laGetOperatorType(Path);
  3988. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3989. ui->Type = la_GetUiButtonType();
  3990. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3991. }else{
  3992. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3993. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3994. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3995. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3996. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3997. }
  3998. if (Base){
  3999. ui->PP.RawThis = Base;
  4000. }
  4001. }else if (Base){
  4002. ui->PP.LastPs = Base->LastPs;
  4003. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4004. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4005. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  4006. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4007. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4008. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4009. }
  4010. la_AssignPropExtras(ui);
  4011. if(Widget){ ui->Flags|= Widget->Flags; }
  4012. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  4013. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  4014. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4015. return ui;
  4016. }
  4017. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  4018. ui->Type = _LA_UI_LABEL;
  4019. ui->Template = Template;
  4020. ui->State = LA_UI_NORMAL;
  4021. strSafeSet(&ui->Display, Content);
  4022. la_AssignPropExtras(ui);
  4023. return ui;
  4024. }
  4025. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  4026. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4027. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  4028. ui->State = LA_UI_NORMAL;
  4029. la_AssignPropExtras(ui);
  4030. return ui;
  4031. }
  4032. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4033. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4034. transLate(Content);
  4035. la_UpdateLabelDisplay(ui, Template, Content);
  4036. ui->C = c;
  4037. if (ui->Type->Init) ui->Type->Init(ui);
  4038. ui->ExtraPP.EndInstance = ui->Extra;
  4039. lstAppendItem(&uil->UiItems, ui);
  4040. return ui;
  4041. }
  4042. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4043. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4044. la_UpdateLabelDisplay(ui, Template, Content);
  4045. ui->C = c;
  4046. if (ui->Type->Init) ui->Type->Init(ui);
  4047. ui->ExtraPP.EndInstance = ui->Extra;
  4048. lstAppendItem(&uil->UiItems, ui);
  4049. return ui;
  4050. }
  4051. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  4052. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4053. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  4054. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  4055. ui->C = c;
  4056. if (ui->Type->Init) ui->Type->Init(ui);
  4057. ui->ExtraPP.EndInstance = ui->Extra;
  4058. lstAppendItem(&uil->UiItems, ui);
  4059. return ui;
  4060. }
  4061. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4062. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  4063. }
  4064. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4065. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4066. }
  4067. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4068. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4069. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4070. ui->C = c;
  4071. ui->TemplateContext = TemplateContext;
  4072. if (ui->Type->Init) ui->Type->Init(ui);
  4073. ui->ExtraPP.EndInstance = ui->Extra;
  4074. lstAppendItem(&uil->UiItems, ui);
  4075. return ui;
  4076. }
  4077. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4078. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4079. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4080. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4081. ui->SymbolID=Height;
  4082. lstAppendItem(&uil->UiItems, ui);
  4083. return ui;
  4084. }
  4085. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4086. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4087. }
  4088. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4089. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4090. }
  4091. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4092. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4093. ui->Type = _LA_UI_CANVAS;
  4094. ui->State = LA_UI_NORMAL;
  4095. ui->C = c;
  4096. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4097. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4098. else{
  4099. 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); }
  4100. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4101. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4102. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4103. }
  4104. if (ui->Type->Init) ui->Type->Init(ui);
  4105. la_AssignCanvasPropExtras(ui);
  4106. if (Height) ui->Expand=Height; else ui->Expand=6;
  4107. lstAppendItem(&uil->UiItems, ui);
  4108. return ui;
  4109. }
  4110. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4111. laUiItem* ui=0;
  4112. #define ADD_CANVAS \
  4113. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4114. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4115. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4116. }laEndCondition(uil,b3);\
  4117. laEndRow(uil,b);
  4118. if(Detached){
  4119. laColumn* cl,*cll,*clr,*cr;
  4120. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4121. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4122. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4123. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4124. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4125. ADD_CANVAS
  4126. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4127. }laElse(uil,b2);{
  4128. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4129. ADD_CANVAS
  4130. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4131. }laEndCondition(uil,b2);
  4132. }else{
  4133. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4134. }
  4135. #undef ADD_CANVAS
  4136. }
  4137. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4138. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4139. laCanvasExtra *e;
  4140. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4141. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4142. ui->C = c;
  4143. if (ui->Type->Init) ui->Type->Init(ui);
  4144. ui->ExtraPP.EndInstance = ui->Extra;
  4145. lstAppendItem(&uil->UiItems, ui);
  4146. return ui;
  4147. }
  4148. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4149. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4150. ui->Type = _LA_UI_SYMBOL;
  4151. ui->SymbolID = SymbolID;
  4152. if (Height) ui->State = Height;
  4153. ui->C = c;
  4154. if (ui->Type->Init) ui->Type->Init(ui);
  4155. ui->ExtraPP.EndInstance = ui->Extra;
  4156. lstAppendItem(&uil->UiItems, ui);
  4157. return ui;
  4158. }
  4159. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4160. laPropPack PP={0}; int result;
  4161. if (Path){
  4162. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4163. if (!result){ return 0; }
  4164. if (Base){ PP.RawThis = Base; }
  4165. }else if (Base){
  4166. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4167. }
  4168. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4169. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4170. lstAppendItem(&ui->CompoundPPs,CPP);
  4171. return &CPP->PP;
  4172. }
  4173. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4174. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4175. ui->Type = &_LA_UI_ROW_BEGIN;
  4176. ui->State=Expand;
  4177. ui->Flags=Even;
  4178. ui->C = c;
  4179. if (ui->Type->Init) ui->Type->Init(ui);
  4180. ui->ExtraPP.EndInstance = ui->Extra;
  4181. lstAppendItem(&uil->UiItems, ui);
  4182. return ui;
  4183. }
  4184. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4185. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4186. ui->Type = &_LA_UI_ROW_END;
  4187. ui->C = Begin->C;
  4188. ui->Page = (laUiList*)Begin;
  4189. if (ui->Type->Init) ui->Type->Init(ui);
  4190. ui->ExtraPP.EndInstance = ui->Extra;
  4191. lstAppendItem(&uil->UiItems, ui);
  4192. return ui;
  4193. }
  4194. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4195. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4196. e->Expression = Expression;
  4197. ui->Extra = e;
  4198. la_AssignPropExtras(ui);
  4199. }
  4200. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4201. laUiItem *ui = la_CreateGroupHandle(Widget);
  4202. laUiList *nuil;
  4203. ui->C = c;
  4204. lstAppendItem(&uil->UiItems, ui);
  4205. nuil = memAcquireSimple(sizeof(laUiList));
  4206. strSafeSet(&nuil->TabName, Name);
  4207. ui->Page = nuil;
  4208. lstAppendItem(&ui->Subs, nuil);
  4209. if (ui->Type->Init) ui->Type->Init(ui);
  4210. ui->ExtraPP.EndInstance = ui->Extra;
  4211. return ui;
  4212. }
  4213. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4214. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4215. laUiList *sub = SubUi->Page;
  4216. laColumn *s = laFirstColumn(sub);
  4217. SubUi->State = LA_UI_ACTIVE;
  4218. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4219. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4220. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4221. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4222. laShowSeparator(sub, s);
  4223. return SubUi;
  4224. }
  4225. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4226. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4227. laUiList *sub = SubUi->Page;
  4228. laColumn *s = laFirstColumn(sub);
  4229. SubUi->State = LA_UI_ACTIVE;
  4230. return SubUi;
  4231. }
  4232. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4233. laEndCondition(sub, sub->UiItems.pFirst);
  4234. }
  4235. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4236. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4237. laUiList *nuil;
  4238. ui->C = c;
  4239. lstAppendItem(&uil->UiItems, ui);
  4240. if (ui->Type->Init) ui->Type->Init(ui);
  4241. ui->ExtraPP.EndInstance = ui->Extra;
  4242. return ui;
  4243. }
  4244. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4245. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4246. if (!ui->Page) ui->Page = uil;
  4247. lstAppendItem(&ui->Subs, uil);
  4248. strSafeSet(&uil->TabName, Name);
  4249. laFirstColumn(uil);
  4250. //laFirstColumn(uil);
  4251. return uil;
  4252. }
  4253. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4254. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4255. /*if (!ui->Page) */ ui->Page = uil;
  4256. lstAppendItem(&ui->Subs, uil);
  4257. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4258. return uil;
  4259. }
  4260. laUiConditionNode *laTrue(){
  4261. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4262. ucn->Type = LA_CONDITION_TRUE;
  4263. return ucn;
  4264. }
  4265. laUiConditionNode *laFalse(){
  4266. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4267. ucn->Type = LA_CONDITION_FALSE;
  4268. return ucn;
  4269. }
  4270. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4271. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4272. ucn->Type = LA_CONDITION_PROP;
  4273. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4274. strSafeSet(&ucn->String, Prop);
  4275. return ucn;
  4276. }
  4277. laUiConditionNode *laIntExpression(int Value){
  4278. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4279. ucn->Type = LA_CONDITION_INT;
  4280. ucn->IntValue = Value;
  4281. return ucn;
  4282. }
  4283. laUiConditionNode *laFloatExpression(real Value){
  4284. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4285. ucn->Type = LA_CONDITION_FLOAT;
  4286. ucn->FloatValue = Value;
  4287. return ucn;
  4288. }
  4289. laUiConditionNode *laStringExpression(char *Content){
  4290. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4291. ucn->Type = LA_CONDITION_STRING;
  4292. strSafeSet(&ucn->String, Content);
  4293. return ucn;
  4294. }
  4295. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4296. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4297. ucn->Type = LA_CONDITION_AND;
  4298. ucn->Expression1 = Expression1;
  4299. ucn->Expression2 = Expression2;
  4300. return ucn;
  4301. }
  4302. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4303. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4304. ucn->Type = LA_CONDITION_OR;
  4305. ucn->Expression1 = Expression1;
  4306. ucn->Expression2 = Expression2;
  4307. return ucn;
  4308. }
  4309. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4310. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4311. ucn->Type = LA_CONDITION_NOT;
  4312. ucn->Expression1 = Expression1;
  4313. return ucn;
  4314. }
  4315. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4316. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4317. ucn->Type = LA_CONDITION_EQ;
  4318. ucn->Expression1 = Expression1;
  4319. ucn->Expression2 = Expression2;
  4320. return ucn;
  4321. }
  4322. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4323. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4324. ucn->Type = LA_CONDITION_GT;
  4325. ucn->Expression1 = Expression1;
  4326. ucn->Expression2 = Expression2;
  4327. return ucn;
  4328. }
  4329. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4330. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4331. ucn->Type = LA_CONDITION_LT;
  4332. ucn->Expression1 = Expression1;
  4333. ucn->Expression2 = Expression2;
  4334. return ucn;
  4335. }
  4336. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4337. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4338. ucn->Type = LA_CONDITION_GE;
  4339. ucn->Expression1 = Expression1;
  4340. ucn->Expression2 = Expression2;
  4341. return ucn;
  4342. }
  4343. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4344. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4345. ucn->Type = LA_CONDITION_LE;
  4346. ucn->Expression1 = Expression1;
  4347. ucn->Expression2 = Expression2;
  4348. return ucn;
  4349. }
  4350. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4351. if (Expression->Type != LA_CONDITION_INT) return 0;
  4352. return Expression->IntValue;
  4353. }
  4354. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4355. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4356. return Expression->FloatValue;
  4357. }
  4358. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4359. return Expression->String->Ptr;
  4360. }
  4361. 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){
  4362. switch (Mode1){
  4363. case LA_PROP_ENUM:
  4364. case LA_PROP_INT:
  4365. case LA_CONDITION_INT:
  4366. switch (Mode2){
  4367. case LA_PROP_ENUM:
  4368. case LA_PROP_INT:
  4369. case LA_CONDITION_INT:
  4370. switch (CompMode){
  4371. case LA_CONDITION_GE:
  4372. return (i1 >= i2);
  4373. case LA_CONDITION_GT:
  4374. return (i1 > i2);
  4375. case LA_CONDITION_EQ:
  4376. return (i1 == i2);
  4377. case LA_CONDITION_LT:
  4378. return (i1 < i2);
  4379. case LA_CONDITION_LE:
  4380. return (i1 <= i2);
  4381. }
  4382. case LA_PROP_FLOAT:
  4383. case LA_CONDITION_FLOAT:
  4384. switch (CompMode){
  4385. case LA_CONDITION_GE:
  4386. return ((real)i1 >= f2);
  4387. case LA_CONDITION_GT:
  4388. return ((real)i1 > f2);
  4389. case LA_CONDITION_EQ:
  4390. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4391. case LA_CONDITION_LT:
  4392. return ((real)i1 < f2);
  4393. case LA_CONDITION_LE:
  4394. return ((real)i1 <= f2);
  4395. }
  4396. case LA_PROP_SUB:
  4397. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4398. default:
  4399. return 0;
  4400. }
  4401. case LA_PROP_FLOAT:
  4402. case LA_CONDITION_FLOAT:
  4403. switch (Mode2){
  4404. case LA_PROP_INT:
  4405. case LA_PROP_ENUM:
  4406. case LA_CONDITION_INT:
  4407. switch (CompMode){
  4408. case LA_CONDITION_GE:
  4409. return (f1 >= (real)i2);
  4410. case LA_CONDITION_GT:
  4411. return (f1 > (real)i2);
  4412. case LA_CONDITION_EQ:
  4413. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4414. case LA_CONDITION_LT:
  4415. return (f1 < (real)i2);
  4416. case LA_CONDITION_LE:
  4417. return (f1 <= (real)i2);
  4418. }
  4419. case LA_PROP_FLOAT:
  4420. case LA_CONDITION_FLOAT:
  4421. switch (CompMode){
  4422. case LA_CONDITION_GE:
  4423. return (f1 >= f2);
  4424. case LA_CONDITION_GT:
  4425. return (f1 > f2);
  4426. case LA_CONDITION_EQ:
  4427. return (f1 == f2);
  4428. case LA_CONDITION_LT:
  4429. return (f1 < f2);
  4430. case LA_CONDITION_LE:
  4431. return (f1 <= f2);
  4432. }
  4433. default:
  4434. return 0;
  4435. }
  4436. case LA_PROP_STRING:
  4437. case LA_CONDITION_STRING:
  4438. switch (Mode2){
  4439. case LA_PROP_STRING:
  4440. case LA_CONDITION_STRING:
  4441. return strSame(s1, s2);
  4442. default:
  4443. return 0;
  4444. }
  4445. case LA_PROP_SUB:
  4446. switch (Mode2){
  4447. case LA_PROP_SUB:
  4448. return p1 == p2;
  4449. case LA_CONDITION_INT:
  4450. case LA_PROP_INT:
  4451. case LA_PROP_ENUM:
  4452. return (int)p1 == i2;
  4453. default:
  4454. return 0;
  4455. }
  4456. default:
  4457. switch (CompMode){
  4458. case LA_CONDITION_GE:
  4459. return (i1 >= i2);
  4460. case LA_CONDITION_GT:
  4461. return (i1 > i2);
  4462. case LA_CONDITION_EQ:
  4463. return (i1 == i2);
  4464. case LA_CONDITION_LT:
  4465. return (i1 < i2);
  4466. case LA_CONDITION_LE:
  4467. return (i1 <= i2);
  4468. }
  4469. }
  4470. }
  4471. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4472. void *Instance = 0;
  4473. int IValue1 = 0, IValue2 = 0;
  4474. real FValue1 = 0, FValue2 = 0;
  4475. void *Ptr1 = 0, *Ptr2 = 0;
  4476. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4477. int Result1, Result2;
  4478. laEnumItem *ei; laSubProp*sp;
  4479. if (!Expression) return 0;
  4480. Str1[0] = 0;
  4481. Str2[0] = 0;
  4482. laPropIterator pi = {0};
  4483. switch (Expression->Type){
  4484. case LA_CONDITION_PROP:
  4485. if (!Expression->PP.LastPs){
  4486. (*IResult) = 0;
  4487. return 0;
  4488. }
  4489. switch (Expression->PP.LastPs->p->PropertyType){
  4490. case LA_PROP_INT:
  4491. *IResult = laGetInt(&Expression->PP);
  4492. if (*IResult) return LA_CONDITION_INT;
  4493. else return 0;
  4494. case LA_PROP_FLOAT:
  4495. *FResult = laGetFloat(&Expression->PP);
  4496. if (*FResult) return 1;
  4497. else return 0;
  4498. break;
  4499. case LA_PROP_STRING:
  4500. laGetString(&Expression->PP, _StrResult, &StrResult);
  4501. if (StrResult[0]) return 1;
  4502. else return 0;
  4503. break;
  4504. case LA_PROP_ENUM:
  4505. ei = laGetEnum(&Expression->PP);
  4506. if (!ei) return 0;
  4507. /*if(ei) */ *IResult = ei->Index;
  4508. if (*IResult) return LA_CONDITION_INT;
  4509. else return 0;
  4510. break;
  4511. case LA_PROP_SUB:
  4512. sp=Expression->PP.LastPs->p;
  4513. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4514. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4515. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4516. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4517. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4518. }
  4519. }
  4520. *PtrResult = Instance;
  4521. if (Instance) return 1;
  4522. break;
  4523. default:
  4524. return 0;
  4525. }
  4526. break;
  4527. case LA_CONDITION_INT:
  4528. *IResult = Expression->IntValue;
  4529. if (*IResult) return 1;
  4530. else
  4531. return 0;
  4532. case LA_CONDITION_FLOAT:
  4533. *FResult = Expression->FloatValue;
  4534. if (*FResult) return 1;
  4535. else
  4536. return 0;
  4537. case LA_CONDITION_STRING:
  4538. if (Expression->String){
  4539. strCopyFull(StrResult, Expression->String->Ptr);
  4540. return 1;
  4541. }else
  4542. return 0;
  4543. case LA_CONDITION_TRUE:
  4544. if (*IResult) *IResult = 1;
  4545. return 1;
  4546. case LA_CONDITION_FALSE:
  4547. if (*IResult) *IResult = 0;
  4548. return 0;
  4549. default:
  4550. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4551. switch (Expression->Type){
  4552. case LA_CONDITION_AND:
  4553. if (Result1){
  4554. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4555. if (Result2) *IResult = 1;
  4556. return (Result2);
  4557. }else
  4558. return 0;
  4559. case LA_CONDITION_OR:
  4560. if (!Result1){
  4561. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4562. if (Result2) *IResult = 1;
  4563. return (Result2);
  4564. }else
  4565. return 1;
  4566. case LA_CONDITION_NOT:
  4567. return !Result1;
  4568. default:
  4569. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4570. return la_DoCompare(Expression->Type,
  4571. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4572. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4573. }
  4574. break;
  4575. }
  4576. return 0;
  4577. }
  4578. int la_DoSingleExpression(laUiConditionNode *Expression){
  4579. int a;
  4580. real b;
  4581. char c[128]={0};
  4582. void *p;
  4583. if (!Expression) return 1;
  4584. c[0] = 0;
  4585. return la_DoExpression(Expression, &a, &b, c, &p);
  4586. }
  4587. void la_StepExpression(laUiConditionNode *e){
  4588. if (!e) return;
  4589. switch (e->Type){
  4590. case LA_CONDITION_AND:
  4591. case LA_CONDITION_OR:
  4592. case LA_CONDITION_GE:
  4593. case LA_CONDITION_GT:
  4594. case LA_CONDITION_EQ:
  4595. case LA_CONDITION_LT:
  4596. case LA_CONDITION_LE:
  4597. la_StepExpression(e->Expression1);
  4598. la_StepExpression(e->Expression2);
  4599. break;
  4600. case LA_CONDITION_NOT:
  4601. la_StepExpression(e->Expression1);
  4602. break;
  4603. case LA_CONDITION_PROP:
  4604. la_StepPropPack(&e->PP);
  4605. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4606. la_UsePropPack(&e->PP, 1);
  4607. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4608. //}
  4609. break;
  4610. default:
  4611. break;
  4612. }
  4613. }
  4614. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4615. if (!ucn) return;
  4616. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4617. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4618. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4619. if (ucn->String) strSafeDestroy(&ucn->String);
  4620. if (ucn) memFree(ucn);
  4621. }
  4622. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4623. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4624. ui->C = c;
  4625. ui->Type = &_LA_UI_CONDITION;
  4626. la_ConditionerInit(ui, Expression);
  4627. lstAppendItem(&uil->UiItems, ui);
  4628. return ui;
  4629. }
  4630. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4631. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4632. laConditionUiExtraData *cued;
  4633. ui->Type = &_LA_UI_CONDITION_ELSE;
  4634. la_ConditionerInit(ui, 0);
  4635. cued = ui->Extra;
  4636. cued->EndUi = Beginner;
  4637. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4638. ui->C = Beginner->C;
  4639. lstAppendItem(&uil->UiItems, ui);
  4640. return ui;
  4641. }
  4642. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4643. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4644. laConditionUiExtraData *cued;
  4645. ui->Template = define;
  4646. ui->C = col;
  4647. ui->PP.RawThis = ExtraBase;
  4648. ui->Page = ExtraThis;
  4649. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4650. la_ConditionerInit(ui, 0);
  4651. cued = ui->Extra;
  4652. //cued->Remove = Remove;
  4653. ui->State = LA_UI_NORMAL;
  4654. lstAppendItem(&uil->UiItems, ui);
  4655. return ui;
  4656. }
  4657. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4658. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4659. laConditionUiExtraData *cued;
  4660. ui->Type = &_LA_UI_CONDITION_END;
  4661. la_ConditionerInit(ui, 0);
  4662. cued = ui->Extra;
  4663. cued->EndUi = Beginner;
  4664. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4665. ui->C = Beginner->C;
  4666. lstAppendItem(&uil->UiItems, ui);
  4667. return ui;
  4668. }
  4669. laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags) {
  4670. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4671. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4672. ui->Type = _LA_UI_MENU_ROOT;
  4673. strSafeSet(&ui->Display, Title);
  4674. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4675. ui->C = c;
  4676. ui->Flags|=flags;
  4677. lstAppendItem(&uil->UiItems, ui);
  4678. muil->Flags|=flags;
  4679. lstAppendItem(&ui->Subs, muil);
  4680. return muil;
  4681. }
  4682. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4683. return laMakeMenuPageEx(uil,c,Title,0);
  4684. }
  4685. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4686. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4687. ui->Type = _LA_UI_ALIGN;
  4688. ui->C = widest;
  4689. lstAppendItem(&uil->UiItems, ui);
  4690. return ui;
  4691. }
  4692. void laFixHeight(laUiList *uil, short Rows){
  4693. if (!uil) return;
  4694. uil->HeightCoeff = Rows;
  4695. }
  4696. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4697. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4698. if (!ExtraColumns) return;
  4699. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4700. }
  4701. laUiTemplate *laFindUiTemplate(char *Identifier){
  4702. laUiTemplate *uit;
  4703. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4704. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4705. }
  4706. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4707. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4708. }
  4709. return 0;
  4710. }
  4711. void la_DestroyUiTemplate(laUiTemplate* uit){
  4712. strSafeDestroy(&uit->Identifier);
  4713. strSafeDestroy(&uit->Title);
  4714. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4715. memFree(uit);
  4716. }
  4717. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4718. strSafeDestroy(&uit->Identifier);
  4719. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4720. memFree(uit);
  4721. }
  4722. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4723. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4724. strSafeSet(&uit->Identifier, Identifier);
  4725. strSafeSet(&uit->Title, Title);
  4726. strSafeSet(&uit->CategoryName, NewCategory);
  4727. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4728. uit->DefaultGLFormat=DefaultGLFormat;
  4729. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4730. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4731. la_UDFAppendSharedTypePointer(Identifier, uit);
  4732. return uit;
  4733. }
  4734. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4735. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4736. strSafeSet(&t->Identifier, Identifier);
  4737. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4738. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4739. lstAppendItem(&MAIN.View2DTemplates, t);
  4740. la_UDFAppendSharedTypePointer(Identifier, t);
  4741. return t;
  4742. }
  4743. void laFinalizeUiTemplates(){
  4744. laUiTemplate *uit;
  4745. laCanvasTemplate *u2d;
  4746. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4747. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4748. }
  4749. }
  4750. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4751. laPanel *p;
  4752. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4753. if (p->PanelTemplate==uit){
  4754. return p;
  4755. }
  4756. }
  4757. return 0;
  4758. }
  4759. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4760. laUiList *uil, *NextUil;
  4761. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4762. NextUil = uil->Item.pNext;
  4763. lstRemoveItem(&ui->Subs, uil);
  4764. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4765. }
  4766. la_StopUiOperatorService(ui);
  4767. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4768. strSafeDestroy(&ui->Display);
  4769. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4770. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4771. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4772. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4773. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4774. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4775. }
  4776. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4777. memFree(ui);
  4778. }
  4779. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4780. laUiItem *ui, *NextUi;
  4781. laColumn *col, *NextCol;
  4782. if (!uil) return;
  4783. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4784. NextUi = ui->Item.pNext;
  4785. if(OnlyRemoveUser && RemoveUsers){
  4786. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4787. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4788. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4789. continue;
  4790. }
  4791. lstRemoveItem(&uil->UiItems, ui);
  4792. la_DestroyUiItem(ui, RemoveUsers);
  4793. }
  4794. if(OnlyRemoveUser){ return; }
  4795. for (col = uil->Columns.pFirst; col; col = NextCol){
  4796. NextCol = col->Item.pNext;
  4797. lstRemoveItem(&uil->Columns, col);
  4798. memFree(col);
  4799. }
  4800. strSafeDestroy(&uil->TabName);
  4801. if (!NoFree) memFree(uil);
  4802. }
  4803. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4804. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4805. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4806. }
  4807. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4808. laUiItem *Next = after->Item.pNext;
  4809. laUiItem *Last = uil->UiItems.pLast;
  4810. after->Item.pNext = 0;
  4811. uil->UiItems.pLast = after;
  4812. Define(uil, Base, This, ExtraColums, 0);
  4813. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4814. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4815. if (Next != Last) uil->UiItems.pLast = Last;
  4816. }
  4817. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4818. // int i = 0;
  4819. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4820. // if (!ui->ExtraColums) return;
  4821. // for (i; ui->ExtraColums[i]; i++) {
  4822. // laColumn* c = ui->ExtraColums[i];
  4823. // c->B = B;
  4824. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4825. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4826. // }
  4827. //}
  4828. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4829. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4830. }
  4831. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4832. laColumn *c = ui->C;
  4833. laColumn *ic = lst->pFirst;
  4834. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4835. for (ic; ic; ic = ic->Item.pNext){
  4836. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4837. ic->B = ic->B < c->B ? c->B : ic->B;
  4838. }
  4839. }
  4840. ic = ui->C;
  4841. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4842. ;
  4843. for (ic; ic; ic = ic->Item.pNext){
  4844. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4845. ic->B = ic->B < c->B ? c->B : ic->B;
  4846. }
  4847. }
  4848. }
  4849. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4850. laColumn *c = ui->C;
  4851. laColumn *ic = lst->pFirst;
  4852. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4853. for (ic; ic; ic = ic->Item.pNext){
  4854. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4855. ic->B = ic->B < c->B ? c->B : ic->B;
  4856. }
  4857. }
  4858. ic = ui->C;
  4859. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4860. ;
  4861. for (ic; ic; ic = ic->Item.pNext){
  4862. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4863. ic->B = ic->B < c->B ? c->B : ic->B;
  4864. }
  4865. }
  4866. }
  4867. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4868. int rep;
  4869. int sp;
  4870. int rev;
  4871. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4872. if (!c) return 0;
  4873. sp = (c->SP * (R - L)) + L;
  4874. rev = sp;
  4875. /*if (U)*/ c->B = U;
  4876. if (LR == 1){
  4877. c->IL = L;
  4878. c->IR = sp;
  4879. if (repos){
  4880. c->IR = repos;
  4881. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4882. c->IR = c->IL + c->MaxW*LA_RH+M;
  4883. rev = c->IR;
  4884. }
  4885. }else if (LR == 2){
  4886. c->IL = sp;
  4887. c->IR = R;
  4888. if (repos){
  4889. c->IL = repos;
  4890. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4891. c->IL = c->IR - c->MaxW*LA_RH-M;
  4892. rev = c->IL;
  4893. }
  4894. }else if (LR == 0){
  4895. c->IL = L;
  4896. c->IR = R;
  4897. }
  4898. if (c->LS && c->RS->MaxW == 0){
  4899. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4900. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4901. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4902. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4903. }else if (c->RS && c->LS->MaxW == 0){
  4904. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4905. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4906. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4907. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4908. }
  4909. return rev;
  4910. }
  4911. STRUCTURE(laRowInfo){
  4912. int MaxW;
  4913. int MinW;
  4914. int UnitMinW;
  4915. int NonExpandW;
  4916. int TotalPadding;
  4917. int Expand, Even;
  4918. int ExpandAccum;
  4919. int CountElements;
  4920. int U,MaxB,L;
  4921. laListHandle Elements;
  4922. int LastNoHeight;
  4923. };
  4924. STRUCTURE(laRowNode){
  4925. laListItem Item;
  4926. laUiItem* ui;
  4927. int GotW, LP, RP, H;
  4928. int Expand;
  4929. int UseLast;
  4930. int WaitAnimation;
  4931. };
  4932. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4933. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4934. ri->UnitMinW=LA_RH;
  4935. ri->Expand=ui->State?1:0;
  4936. ri->Even=ui->Flags?1:0;
  4937. ri->U=ui->TU; ri->L=ui->TL;
  4938. ri->MaxB=ui->TU;
  4939. }
  4940. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  4941. laRowNode* rn=CreateNew(laRowNode);
  4942. rn->LP=bt->LP;rn->RP=bt->RP;
  4943. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4944. rn->ui=ui;
  4945. rn->H=H;
  4946. rn->Expand=ui->Expand;
  4947. rn->WaitAnimation=WaitAnimation;
  4948. lstAppendItem(&ri->Elements, rn);
  4949. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4950. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4951. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4952. ri->TotalPadding += (bt->LP+bt->RP);
  4953. ri->MinW+=ri->UnitMinW;
  4954. ri->NonExpandW+=rn->GotW;
  4955. ri->ExpandAccum+=ui->Expand;
  4956. ri->CountElements++;
  4957. if(ui->Expand){ri->Expand=1;}
  4958. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4959. }
  4960. int la_ShrinkableRowElements(laRowInfo* ri){
  4961. int count=0;
  4962. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4963. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4964. count++;
  4965. }
  4966. return count;
  4967. }
  4968. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4969. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  4970. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4971. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4972. if(Available<0){
  4973. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4974. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4975. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4976. }else{
  4977. if(!ri->Expand && Available>0){Available=0;}
  4978. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4979. }
  4980. if(!ShareCount) return 0;
  4981. int PerNode = Available/ShareCount;
  4982. int Remaining = Available-PerNode*ShareCount;
  4983. int L = ri->L; int i=0; laRowNode* rn;
  4984. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4985. laUiItem* ui=rn->ui;
  4986. int NodeAdd, Node=rn->GotW;
  4987. if(rn->UseLast){
  4988. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4989. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4990. continue;
  4991. }
  4992. if(Available>=0){
  4993. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4994. NodeAdd+=(i<Remaining?1:0);i++;
  4995. }else{
  4996. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4997. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4998. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4999. }else{ Node=ri->UnitMinW;
  5000. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  5001. }
  5002. }
  5003. ui->TL = L + rn->LP;
  5004. ui->TR = ui->TL + Node+NodeAdd;
  5005. ui->TB = ui->TU + rn->H;
  5006. L=ui->TR+rn->RP;
  5007. if (!rn->WaitAnimation){
  5008. ui->L = ui->TL; ui->R = ui->TR;
  5009. ui->U = ui->TU; ui->B = ui->TB;
  5010. }
  5011. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5012. }
  5013. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  5014. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  5015. memset(ri, 0, sizeof(laRowInfo));
  5016. }
  5017. void la_RecordSocketRuntimePosition(laUiItem* ui){
  5018. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5019. int sl,sr,su,sb;
  5020. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  5021. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  5022. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  5023. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  5024. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  5025. if(pc==LA_PC_SOCKET_OUT){
  5026. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5027. }else{
  5028. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5029. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  5030. }
  5031. }
  5032. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  5033. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  5034. }
  5035. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  5036. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  5037. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  5038. laBoxedTheme *bt;
  5039. int Lowest = 0;
  5040. int HyperValue = 0;
  5041. int WaitAnimation;
  5042. int RowMode=0; laRowInfo ri={0};
  5043. laBoxedTheme* pt=*(ParentPanel->BT);
  5044. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  5045. int MaxR=0;
  5046. if(!uil->Scale){uil->Scale=1;}
  5047. uil->SaveScale=MAIN.UiScale;
  5048. MAIN.UiScale*=uil->Scale;
  5049. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5050. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  5051. WaitAnimation = 0;
  5052. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  5053. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  5054. for (ui = uil->UiItems.pFirst; ui;){
  5055. int SubB = 0;
  5056. int H;
  5057. WaitAnimation = 0;
  5058. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5059. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  5060. //if (Fast && ui->C->B > B) {
  5061. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  5062. // ui = ui->Item.pNext;
  5063. // continue;
  5064. //}
  5065. if (!ui->Instructions){
  5066. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  5067. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  5068. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  5069. laOperatorProp *ap = ui->PP.LastPs->p;
  5070. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5071. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5072. }
  5073. }
  5074. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5075. la_UsePropPack(&ui->PP, 0);
  5076. if (ui->CompoundPPs.pFirst){
  5077. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5078. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5079. }
  5080. }
  5081. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5082. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5083. // 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);
  5084. //}
  5085. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5086. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5087. WaitAnimation = 1;
  5088. }
  5089. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5090. bt = (*ui->Type->Theme);
  5091. if (ui->Type == &_LA_UI_CONDITION){
  5092. laConditionUiExtraData *cued = ui->Extra;
  5093. la_StepExpression(cued->Expression);
  5094. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5095. if (!cued->IsTrue){
  5096. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5097. }else{
  5098. ui = ui->Item.pNext;
  5099. }
  5100. continue;
  5101. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5102. ui = ui->Item.pNext;
  5103. continue;
  5104. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5105. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5106. if (cued->IsTrue) ui = cued->EndUi;
  5107. else
  5108. ui = ui->Item.pNext;
  5109. continue;
  5110. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5111. laConditionUiExtraData *cued = ui->Extra;
  5112. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5113. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5114. if (!WaitAnimation){
  5115. ui->L = ui->TL; ui->R = ui->TR;
  5116. ui->U = ui->TU; ui->B = ui->TB;
  5117. }
  5118. if(!RowMode){
  5119. la_CalcUiItemInfluence(&uil->Columns, ui);
  5120. }else{
  5121. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5122. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5123. }
  5124. if (ui->State == LA_UI_NORMAL){
  5125. cued->IsTrue = 0;
  5126. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5127. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5128. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5129. }else{
  5130. cued->IsTrue = 1;
  5131. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5132. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5133. //}
  5134. ui = ui->Item.pNext;
  5135. }
  5136. continue;
  5137. }
  5138. if (ui->Type == _LA_UI_ALIGN){
  5139. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5140. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5141. if (ui->TB > Lowest) Lowest = ui->TB;
  5142. if (!WaitAnimation){
  5143. ui->L = ui->TL; ui->R = ui->TR;
  5144. ui->U = ui->TU; ui->B = ui->TB;
  5145. }
  5146. if(!RowMode){
  5147. la_CalcUiItemInfluence(&uil->Columns, ui);
  5148. }else{
  5149. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5150. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5151. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5152. }
  5153. ui = ui->Item.pNext; continue;
  5154. }
  5155. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5156. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5157. la_InitRowNode(&ri, ui, bt);
  5158. RowMode=1; ui=ui->Item.pNext; continue;
  5159. }
  5160. if (ui->Type == &_LA_UI_ROW_END){
  5161. la_CalculateRowExpand(&ri, ui);
  5162. la_CalcUiItemInfluence(&uil->Columns, ui);
  5163. RowMode=0; ui=ui->Item.pNext; continue;
  5164. }
  5165. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5166. int GB=0;
  5167. 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; }
  5168. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5169. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5170. if (H < 0){
  5171. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5172. else{ H=LA_RH; }
  5173. }
  5174. else H *= LA_RH;
  5175. ui->TB = ui->TU;
  5176. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5177. 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
  5178. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5179. if (ui->Type == _LA_UI_COLLECTION){
  5180. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5181. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5182. ui->PP.EndInstance = TInstance;
  5183. laUiList *iuil = ui->Subs.pFirst;
  5184. laUiList *puil = iuil;
  5185. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5186. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5187. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5188. int Begin = ui->TB;
  5189. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5190. int ElementB = ui->TU;
  5191. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5192. int MaxB = ElementB;
  5193. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5194. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5195. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5196. if (!ElementLimit) RowPriority = 0;
  5197. if (!TInstance){
  5198. while (iuil){
  5199. puil = iuil->Item.pNext;
  5200. la_DestroyTabPage(ui, iuil, 0);
  5201. iuil = puil;
  5202. }
  5203. }
  5204. while (TInstance){
  5205. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  5206. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5207. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5208. ui->PP.EndInstance = TInstance; continue;
  5209. }
  5210. if(CanGetTheme){
  5211. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5212. la_SwitchThemeQuick(t, OriginalTheme);
  5213. }
  5214. if(CanGetGap){
  5215. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5216. Gap=g*LA_RH;
  5217. }else Gap=0;
  5218. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5219. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5220. }else GotCategory=0;
  5221. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5222. if (RowPriority){
  5223. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5224. }
  5225. }
  5226. FirstIn=0;
  5227. if (ElementLimit){
  5228. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5229. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5230. }
  5231. while (iuil && iuil->Instance != TInstance){
  5232. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5233. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5234. }else{
  5235. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5236. }
  5237. iuil = puil;
  5238. }
  5239. if(!iuil){
  5240. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5241. }
  5242. if (!iuil){
  5243. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5244. la_CalcUiTopInfluence(&uil->Columns, ui);
  5245. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5246. 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);
  5247. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5248. iuil = ui->Page->Item.pNext;
  5249. }else{
  5250. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5251. 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);
  5252. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5253. la_CalcUiItemInfluence(&uil->Columns, ui);
  5254. iuil = iuil->Item.pNext;
  5255. }
  5256. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5257. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5258. ui->PP.EndInstance = TInstance;
  5259. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5260. if (RowPriority){
  5261. Col += 1;
  5262. if (Col >= ElementLimit){
  5263. Col = 0;
  5264. Row += 1;
  5265. Begin = ElementB + bt->TM;
  5266. }
  5267. }elif(Spread){
  5268. EL+=Spread*LA_RH;
  5269. ER+=Spread*LA_RH;
  5270. }else{
  5271. Row += 1;
  5272. Begin = ElementB + bt->TM;
  5273. if (ElementLimit && Row >= ElementLimit){
  5274. Row = 0;
  5275. Col += 1;
  5276. Begin = ui->TU + bt->TM;
  5277. }
  5278. }
  5279. ui->TB = ElementB;
  5280. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5281. }
  5282. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5283. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5284. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5285. ui->TB = MaxB;
  5286. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5287. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5288. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5289. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5290. ui->TB=ui->TU+LA_RH;
  5291. }else{
  5292. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5293. ui->PP.EndInstance = TInstance;
  5294. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5295. if(!Template) Template=laui_SubPropInfoDefault;
  5296. //ui->Template = Template;
  5297. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5298. if (!ui->Subs.pFirst && TInstance){
  5299. la_AddInstancePage(ui, TInstance, 0);
  5300. la_CalcUiTopInfluence(&uil->Columns, ui);
  5301. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5302. 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);
  5303. ui->TB = SubB + (NoDecal?0:bt->BM);
  5304. }else if (ui->Subs.pFirst){
  5305. if (!TInstance || TInstance != ui->Page->Instance){
  5306. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5307. ui->Page = 0;
  5308. if (TInstance){
  5309. la_AddInstancePage(ui, TInstance, 0);
  5310. la_CalcUiTopInfluence(&uil->Columns, ui);
  5311. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5312. 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);
  5313. ui->TB = SubB + (NoDecal?0:bt->TM);
  5314. }else
  5315. ui->TB = ui->TU + LA_RH + bt->BM;
  5316. }else{
  5317. 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);
  5318. ui->TB = SubB + (NoDecal?0:bt->BM);
  5319. }
  5320. }
  5321. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5322. ui->TB=ui->TU+LA_RH;
  5323. }
  5324. }
  5325. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5326. if (!WaitAnimation){
  5327. ui->L = ui->TL;
  5328. ui->R = ui->TR;
  5329. ui->U = ui->TU;
  5330. ui->B = ui->TB;
  5331. }
  5332. }
  5333. }else{
  5334. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5335. if (ui->Type != _LA_UI_CANVAS){
  5336. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5337. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5338. SubB = la_UpdateUiListRecursive(ui->Page,
  5339. 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);
  5340. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5341. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5342. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5343. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5344. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5345. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5346. }
  5347. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5348. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5349. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5350. if(ui->Page->HeightCoeff){
  5351. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5352. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5353. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5354. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5355. }
  5356. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5357. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5358. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5359. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5360. }
  5361. }
  5362. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5363. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5364. }else{
  5365. laUiList *suil;
  5366. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5367. la_CalcUiTopInfluence(&uil->Columns, ui);
  5368. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5369. 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);
  5370. }
  5371. }
  5372. ui->TB = ui->TU + H;
  5373. }
  5374. }else ui->TB = ui->TU + H;
  5375. }
  5376. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5377. if(!RowMode){
  5378. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5379. }else{
  5380. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5381. }
  5382. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5383. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5384. ui = ui->Item.pNext;
  5385. }
  5386. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5387. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5388. else uil->TB = Lowest;
  5389. if (!WaitAnimation){
  5390. uil->L = uil->TL;
  5391. uil->R = uil->TR;
  5392. uil->U = uil->TU;
  5393. uil->B = uil->TB;
  5394. }
  5395. MAIN.UiScale=uil->SaveScale;
  5396. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5397. return uil->TB;
  5398. }
  5399. int la_AnimateSingleUiSize(int To, int *Now){
  5400. int Delta;
  5401. if (To != *Now){
  5402. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5403. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5404. *Now += Delta;
  5405. return 1;
  5406. }else
  5407. return 0;
  5408. }
  5409. int la_AnimateUiListRecursive(laUiList *uil){
  5410. laUiItem *ui;
  5411. int Again = 0;
  5412. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5413. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5414. if(ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish){
  5415. ui->B=ui->TB; ui->L=ui->TL; ui->R=ui->TR; ui->U=ui->TU;
  5416. }else{
  5417. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5418. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5419. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5420. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5421. }
  5422. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5423. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5424. laUiList *suil;
  5425. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5426. Again += la_AnimateUiListRecursive(suil);
  5427. }
  5428. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5429. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5430. Again += la_AnimateUiListRecursive(ui->Page);
  5431. }
  5432. }
  5433. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5434. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5435. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5436. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5437. return Again;
  5438. }
  5439. int la_DrawUiItem(laUiItem *ui){
  5440. tnsUseNoTexture();
  5441. tnsColor4d(1, 1, 1, 1);
  5442. tnsVertex2d(ui->L, ui->U);
  5443. tnsVertex2d(ui->R, ui->U);
  5444. tnsVertex2d(ui->R, ui->B);
  5445. tnsVertex2d(ui->L, ui->B);
  5446. tnsPackAs(GL_LINE_LOOP);
  5447. }
  5448. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5449. tnsUseNoTexture();
  5450. tnsColor4d(1, 1, 1, 1);
  5451. tnsVertex2d(ui->L - 1, ui->U - 1);
  5452. tnsVertex2d(ui->R + 1, ui->U - 1);
  5453. tnsVertex2d(ui->R + 1, ui->B + 1);
  5454. tnsVertex2d(ui->L - 1, ui->B + 1);
  5455. tnsPackAs(GL_LINE_LOOP);
  5456. }
  5457. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5458. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5459. return 1;
  5460. }
  5461. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5462. laUiListDrawItem *uildi = uild->Items.pFirst;
  5463. laUiList *Target = uildi->Target;
  5464. int L, R, U, B;
  5465. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5466. L = Target->L + Target->PanX + uildi->DifX;
  5467. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5468. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5469. U = Target->U + Target->PanY + uildi->DifY;
  5470. return la_UiInBound(ui, L, R, U, B);
  5471. }
  5472. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5473. laUiListDrawItem *uildi = uild->Items.pFirst;
  5474. laUiList *Target = uildi->Target;
  5475. int L, R, U, B;
  5476. if (Target){
  5477. L = Target->L + Target->PanX + uildi->DifX;
  5478. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5479. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5480. U = Target->U + Target->PanY + uildi->DifY;
  5481. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5482. return 1;
  5483. }else{
  5484. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5485. return 1;
  5486. }
  5487. }
  5488. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5489. laUiItem *ui = uil->UiItems.pFirst;
  5490. while (!strGetArgument(ui->Instructions, mark))
  5491. ui = ui->Item.pNext;
  5492. return ui;
  5493. }
  5494. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5495. laUiList *uil;
  5496. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5497. if (uil->Instance == Instance) return uil;
  5498. }
  5499. return uil;
  5500. }
  5501. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5502. int mx=(L+R)/2; int my=(U+B)/2;
  5503. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5504. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5505. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5506. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5507. tnsFlush();
  5508. }
  5509. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5510. if(!uil->ScrollerShownV) return;
  5511. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5512. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5513. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5514. int U = uil->U + Offset;
  5515. int B = U + Len;
  5516. int L = UiR - RM*2 - W;
  5517. int R = L + W;
  5518. if (B > U + DisplayH) B = U + DisplayH;
  5519. if (U < uil->U) U = uil->U;
  5520. if (B <= uil->U || U >= uil->B) return;
  5521. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5522. if (U < uil->U) U = uil->U;
  5523. tnsUseNoTexture();
  5524. laBoxedTheme* bt=_LA_THEME_PANEL;
  5525. real* color=laThemeColor(bt, LA_BT_TEXT);
  5526. tnsColor4d(LA_COLOR3(color), 0.2);
  5527. tnsVertex2d(R-RM, uil->U);
  5528. tnsVertex2d(L+RM, uil->U);
  5529. tnsVertex2d(L+RM, uil->U + DisplayH);
  5530. tnsVertex2d(R-RM, uil->U + DisplayH);
  5531. tnsPackAs(GL_TRIANGLE_FAN);
  5532. tnsColor4d(LA_COLOR3(color), 0.5);
  5533. tnsVertex2d(R-RM, uil->U);
  5534. tnsVertex2d(L+RM, uil->U);
  5535. tnsVertex2d(L+RM, uil->U + DisplayH);
  5536. tnsVertex2d(R-RM, uil->U + DisplayH);
  5537. tnsPackAs(GL_LINE_LOOP);
  5538. tnsColor4d(LA_COLOR3(color), 1);
  5539. tnsVertex2d(R, U);
  5540. tnsVertex2d(L, U);
  5541. tnsVertex2d(L, B);
  5542. tnsVertex2d(R, B);
  5543. tnsPackAs(GL_TRIANGLE_FAN);
  5544. int HU=(U+B)/2+LA_RH2;
  5545. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5546. tnsFlush();
  5547. }
  5548. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5549. if(!uil->ScrollerShownH) return;
  5550. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5551. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5552. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5553. int L = uil->L + Offset;
  5554. int R = L + Len;
  5555. int U = UiB - RM - W;
  5556. int B = U + W;
  5557. if (B > U + DisplayW) B = U + DisplayW;
  5558. if (U < uil->U) U = uil->U;
  5559. if (R <= uil->L || L >= uil->R) return;
  5560. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5561. if (L < uil->L) L = uil->L;
  5562. tnsUseNoTexture();
  5563. laBoxedTheme* bt=_LA_THEME_PANEL;
  5564. real* color=laThemeColor(bt, LA_BT_TEXT);
  5565. tnsColor4d(LA_COLOR3(color), 0.2);
  5566. tnsVertex2d(uil->L,U+RM);
  5567. tnsVertex2d(uil->L,B-RM);
  5568. tnsVertex2d(uil->L + DisplayW,B-RM);
  5569. tnsVertex2d(uil->L + DisplayW,U+RM);
  5570. tnsPackAs(GL_TRIANGLE_FAN);
  5571. tnsColor4d(LA_COLOR3(color), 0.5);
  5572. tnsVertex2d(uil->L,U+RM);
  5573. tnsVertex2d(uil->L,B-RM);
  5574. tnsVertex2d(uil->L + DisplayW,B-RM);
  5575. tnsVertex2d(uil->L + DisplayW,U+RM);
  5576. tnsPackAs(GL_LINE_LOOP);
  5577. tnsColor4d(LA_COLOR3(color), 1);
  5578. tnsVertex2d(R, U);
  5579. tnsVertex2d(L, U);
  5580. tnsVertex2d(L, B);
  5581. tnsVertex2d(R, B);
  5582. tnsPackAs(GL_TRIANGLE_FAN);
  5583. int HU=(U+B)/2+LA_RH2;
  5584. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5585. tnsFlush();
  5586. }
  5587. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5588. tnsUseNoTexture();
  5589. tnsColor4dv(color);
  5590. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5591. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5592. tnsPackAs(GL_TRIANGLE_FAN);
  5593. }
  5594. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5595. laSocketRecord* sr;
  5596. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5597. uild->WiresContainer=container;
  5598. }
  5599. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5600. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5601. if(lip->Target==uild->WiresContainer) break;
  5602. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5603. }
  5604. }
  5605. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5606. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5607. int PanX, PanY;
  5608. if(pc==LA_PC_SOCKET_OUT){
  5609. laNodeOutSocket* s=ui->PP.EndInstance;
  5610. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5611. }else{
  5612. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5613. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5614. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5615. }
  5616. }
  5617. void la_RegenerateWireColors(){
  5618. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5619. laTheme* t=MAIN.CurrentTheme;
  5620. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5621. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5622. for(int i=0;i<MAIN.WireColorSlices;i++){
  5623. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5624. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5625. }
  5626. }
  5627. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5628. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5629. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5630. tnsInterpolate2dv(v1,v2,0.5,vi);
  5631. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5632. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5633. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5634. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5635. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5636. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5637. tnsVertex2d(v1[0],v1[1]);
  5638. for(int i=1;i<=steps;i++){
  5639. real ratio=i==steps?1.0f:step*i;
  5640. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5641. tnsVertex2d(v1s[0],v1s[1]);
  5642. }
  5643. }
  5644. void la_DrawNodeWires(laUiListDraw* uild){
  5645. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5646. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5647. tnsUseNoTexture();
  5648. #define _RSLICES 16
  5649. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5650. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5651. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5652. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5653. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5654. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5655. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5656. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5657. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5658. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5659. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5660. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5661. }
  5662. if(MAIN.tNodeIn->Source){
  5663. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5664. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5665. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5666. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5667. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5668. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5669. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5670. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5671. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5672. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5673. }
  5674. #undef _RSLICES
  5675. tnsFlush();
  5676. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5677. glLineWidth(ww);
  5678. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5679. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5680. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5681. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5682. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5683. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5684. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5685. }
  5686. if(MAIN.tNodeIn->Source){
  5687. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5688. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5689. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5690. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5691. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5692. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5693. }
  5694. tnsFlush();
  5695. glLineWidth(1);
  5696. la_InitSocketRecord(uild,0);
  5697. }
  5698. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5699. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5700. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5701. }
  5702. 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){
  5703. laUiItem *ui;
  5704. laBoxedTheme *bt;
  5705. laUiList *sub;
  5706. laUiListDrawItem *uildi;
  5707. int Ret = 0;
  5708. if (!uil) return 0;
  5709. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5710. ui = uil->UiItems.pFirst;
  5711. if(uil->PanY<0){uil->PanY=0;}
  5712. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5713. uil->SaveScale=MAIN.UiScale;
  5714. MAIN.UiScale*=uil->Scale;
  5715. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5716. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5717. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5718. if (ui->Type == &_LA_UI_CONDITION){
  5719. laConditionUiExtraData *cued = ui->Extra;
  5720. la_StepExpression(cued->Expression);
  5721. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5722. if (!cued->IsTrue){
  5723. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5724. }else{
  5725. ui = ui->Item.pNext;
  5726. }
  5727. continue;
  5728. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5729. ui = ui->Item.pNext;
  5730. continue;
  5731. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5732. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5733. if (cued->IsTrue) ui = cued->EndUi;
  5734. else
  5735. ui = ui->Item.pNext;
  5736. continue;
  5737. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5738. laConditionUiExtraData *cued = ui->Extra;
  5739. ui->Type->Draw(ui, LA_RH);
  5740. if (ui->State == LA_UI_NORMAL){
  5741. cued->IsTrue = 0;
  5742. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5743. }else{
  5744. cued->IsTrue = 1;
  5745. ui = ui->Item.pNext;
  5746. }
  5747. continue;
  5748. }
  5749. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5750. int NeedDraw=0;
  5751. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5752. if(NeedDraw){
  5753. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5754. }else{ ui->Type->Draw(ui, LA_RH); }
  5755. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5756. tnsFlush();
  5757. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5758. tnsResetViewMatrix();
  5759. }
  5760. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5761. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5762. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5763. tnsFlush();
  5764. }
  5765. }
  5766. if(NeedDraw || RegisterNodes){
  5767. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5768. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5769. ui->Type == _LA_UI_TAB ||
  5770. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5771. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5772. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5773. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5774. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5775. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5776. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5777. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5778. 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); }
  5779. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5780. 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);
  5781. 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)); }
  5782. }elif (ui->Type == _LA_UI_COLLECTION){
  5783. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5784. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5785. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5786. void* SaveInstance = ui->PP.EndInstance;
  5787. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5788. int State;
  5789. ui->PP.EndInstance = sub->Instance;
  5790. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5791. if(NeedDraw){ int drawn=0;
  5792. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5793. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5794. }
  5795. if (CanGetState && !drawn){
  5796. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5797. if(State >= 0){
  5798. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5799. }
  5800. }
  5801. }
  5802. if(sub->TabName && sub->TabName->Ptr){
  5803. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5804. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5805. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5806. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5807. tnsFlush();
  5808. }
  5809. if(CanGetTheme){
  5810. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5811. la_SwitchThemeQuick(t, OriginalTheme);
  5812. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5813. }
  5814. tnsFlush();
  5815. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5816. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5817. }
  5818. //ui->PP.EndInstance = Active;
  5819. ui->PP.EndInstance = SaveInstance;
  5820. }elif (ui->Type == _LA_UI_CANVAS){
  5821. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5822. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5823. tnsFlush();
  5824. 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);
  5825. }
  5826. }
  5827. }
  5828. ui = ui->Item.pNext;
  5829. }else{
  5830. ui = ui->Item.pNext;
  5831. }
  5832. }
  5833. tnsFlush();
  5834. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5835. la_RestoreLastUiListMatrix(uild, B - U);
  5836. MAIN.UiScale=uil->SaveScale;
  5837. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5838. return Ret;
  5839. }
  5840. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5841. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5842. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5843. tnsUseNoTexture();
  5844. tnsColor4d(1, 1, 1, 1);
  5845. tnsVertex2d(L, U);
  5846. tnsVertex2d(R, U);
  5847. tnsVertex2d(R, B);
  5848. tnsVertex2d(L, B);
  5849. tnsPackAs(GL_LINE_LOOP);
  5850. tnsVertex2d(L + 3, Begin);
  5851. tnsVertex2d(R - 3, Begin);
  5852. tnsVertex2d(R - 3, End);
  5853. tnsVertex2d(L + 3, End);
  5854. tnsPackAs(GL_LINE_LOOP);
  5855. }
  5856. int laIsInUiItem(laUiItem *ui, int x, int y){
  5857. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5858. return 1;
  5859. }
  5860. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5861. if (x < l || x > r || y < u || y > b) return 0;
  5862. return 1;
  5863. }
  5864. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5865. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5866. laUiItem *ui, *tui;
  5867. laBoxedTheme *bt;
  5868. laUiList *sub;
  5869. int CPB = 0;
  5870. if (!uil || (LimB && y > LimB)) return 0;
  5871. x += uil->PanX;
  5872. y += uil->PanY;
  5873. for (ui = uil->UiItems.pFirst; ui;){
  5874. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5875. if (ui->Type == &_LA_UI_CONDITION){
  5876. laConditionUiExtraData *cued = ui->Extra;
  5877. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5878. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5879. if (!cued->IsTrue){
  5880. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5881. }else{
  5882. ui = ui->Item.pNext;
  5883. }
  5884. continue;
  5885. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5886. ui = ui->Item.pNext;
  5887. continue;
  5888. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5889. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5890. if (cued->IsTrue) ui = cued->EndUi;
  5891. else
  5892. ui = ui->Item.pNext;
  5893. continue;
  5894. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5895. laConditionUiExtraData *cued = ui->Extra;
  5896. if (laIsInUiItem(ui, x, y)){
  5897. lstAppendPointer(LocalBuf, uil);
  5898. return ui;
  5899. }
  5900. if (ui->State == LA_UI_NORMAL){
  5901. cued->IsTrue = 0;
  5902. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5903. }else{
  5904. cued->IsTrue = 1;
  5905. ui = ui->Item.pNext;
  5906. }
  5907. continue;
  5908. }
  5909. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5910. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5911. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5912. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5913. if(!la_DetectSplit(ui->C, x)) Add=0;
  5914. }
  5915. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5916. }
  5917. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5918. if (ui->Page->HeightCoeff) CPB = ui->B;
  5919. else CPB = ui->Page->B;
  5920. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5921. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5922. lstAppendPointer(LocalBuf, uil);
  5923. return tui;
  5924. }
  5925. }else if (laIsInUiItem(ui, x, y)){
  5926. lstAppendPointer(LocalBuf, uil);return ui;
  5927. }
  5928. }
  5929. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5930. if (laIsInUiItem(ui, x, y)){
  5931. lstAppendPointer(LocalBuf, uil);
  5932. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5933. if(Deep){
  5934. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5935. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5936. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5937. lstAppendPointer(LocalBuf, iuil);
  5938. return tui;
  5939. }
  5940. }
  5941. }
  5942. }
  5943. return ui;
  5944. }
  5945. }
  5946. if (ui->Type == _LA_UI_CANVAS){
  5947. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5948. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5949. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5950. lstAppendPointer(LocalBuf, uil);
  5951. return tui;
  5952. }
  5953. }
  5954. }
  5955. if (laIsInUiItem(ui, x, y)){
  5956. lstAppendPointer(LocalBuf, uil);
  5957. return ui;
  5958. }
  5959. }
  5960. ui = ui->Item.pNext;
  5961. }
  5962. return 0;
  5963. }
  5964. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5965. laListHandle Locals={0};
  5966. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5967. while(lstPopPointer(&Locals));
  5968. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5969. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5970. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5971. if(pc==PCInOrOut) return ui;
  5972. }
  5973. return 0;
  5974. }
  5975. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5976. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5977. laUiItem *ui = uil->UiItems.pFirst;
  5978. laBoxedTheme *bt;
  5979. laUiList *tuil;
  5980. laUiList *sub;
  5981. int CPB = 0;
  5982. x += uil->PanX;
  5983. y += uil->PanY;
  5984. if (y > LimH) return uil;
  5985. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  5986. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  5987. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5988. return uil;
  5989. }
  5990. for (ui = uil->UiItems.pFirst; ui;){
  5991. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5992. if (ui->Type == &_LA_UI_CONDITION){
  5993. laConditionUiExtraData *cued = ui->Extra;
  5994. //la_StepExpression(cued->Expression);
  5995. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5996. if (!cued->IsTrue){
  5997. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5998. }else{
  5999. ui = ui->Item.pNext;
  6000. }
  6001. continue;
  6002. }
  6003. if (ui->Type == &_LA_UI_CONDITION_END){
  6004. ui = ui->Item.pNext;
  6005. continue;
  6006. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6007. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6008. if (cued->IsTrue) ui = cued->EndUi;
  6009. else
  6010. ui = ui->Item.pNext;
  6011. continue;
  6012. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6013. laConditionUiExtraData *cued = ui->Extra;
  6014. if (ui->State == LA_UI_NORMAL){
  6015. cued->IsTrue = 0;
  6016. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6017. }else{
  6018. cued->IsTrue = 1;
  6019. ui = ui->Item.pNext;
  6020. }
  6021. continue;
  6022. }
  6023. if (InToContainerUI && ui != Exception){
  6024. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6025. if (ContainerParent) (*ContainerParent) = uil;
  6026. if (ParentUi) *ParentUi = ui;
  6027. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6028. //if (y > LimH) return uil;
  6029. 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))){
  6030. return tuil;
  6031. }
  6032. }
  6033. }
  6034. }
  6035. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6036. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  6037. else CPB = ui->Page->B;
  6038. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6039. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6040. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6041. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6042. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6043. if (ParentUi) *ParentUi = ui;
  6044. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  6045. }
  6046. }
  6047. ui = ui->Item.pNext;
  6048. }
  6049. return uil;
  6050. }
  6051. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  6052. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  6053. laUiItem *ui = uil->UiItems.pFirst;
  6054. laBoxedTheme *bt;
  6055. laUiList *tuil;
  6056. laUiList *sub;
  6057. int CPB = 0;
  6058. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  6059. x += uil->PanX;
  6060. y += uil->PanY;
  6061. if (y > LimH) return uil;
  6062. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  6063. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  6064. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6065. return uil;
  6066. }
  6067. for (ui = uil->UiItems.pFirst; ui;){
  6068. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6069. if (ui->Type == &_LA_UI_CONDITION){
  6070. laConditionUiExtraData *cued = ui->Extra;
  6071. //la_StepExpression(cued->Expression);
  6072. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6073. if (!cued->IsTrue){
  6074. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6075. }else{
  6076. ui = ui->Item.pNext;
  6077. }
  6078. continue;
  6079. }
  6080. if (ui->Type == &_LA_UI_CONDITION_END){
  6081. ui = ui->Item.pNext;
  6082. continue;
  6083. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6084. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6085. if (cued->IsTrue) ui = cued->EndUi;
  6086. else
  6087. ui = ui->Item.pNext;
  6088. continue;
  6089. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6090. laConditionUiExtraData *cued = ui->Extra;
  6091. if (ui->State == LA_UI_NORMAL){
  6092. cued->IsTrue = 0;
  6093. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6094. }else{
  6095. cued->IsTrue = 1;
  6096. ui = ui->Item.pNext;
  6097. }
  6098. continue;
  6099. }
  6100. if (InToContainerUI && ui != Exception){
  6101. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6102. if (ContainerParent) (*ContainerParent) = uil;
  6103. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6104. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6105. //if (y > LimH) return uil;
  6106. 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))){
  6107. return tuil;
  6108. }
  6109. }
  6110. }
  6111. }
  6112. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6113. if (ui->Page->HeightCoeff) CPB = ui->B;
  6114. else CPB = ui->Page->B;
  6115. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6116. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6117. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6118. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6119. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6120. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6121. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6122. }
  6123. }
  6124. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6125. if (ui->Page->HeightCoeff) CPB = ui->B;
  6126. else
  6127. CPB = ui->Page->B;
  6128. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6129. if (ScrollUil) *ScrollUil = ui->Page;
  6130. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6131. }
  6132. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6133. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6134. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6135. }
  6136. }
  6137. ui = ui->Item.pNext;
  6138. }
  6139. return uil;
  6140. }
  6141. int la_TestUiListMinumWidth(laUiList *uil){
  6142. laUiItem *ui, *tui;
  6143. laBoxedTheme *bt;
  6144. laUiList *sub;
  6145. int CPB = 0;
  6146. int W = 0;
  6147. int tW, sW, RowMode=0, rW;
  6148. void *Restore;
  6149. for (ui = uil->UiItems.pFirst; ui;){
  6150. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6151. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6152. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6153. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6154. if (W < tW) W = tW;
  6155. }elif (ui->Type == _LA_UI_COLLECTION){
  6156. Restore = ui->PP.EndInstance;
  6157. tW = 0; sW = 0;
  6158. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6159. ui->PP.EndInstance = sub->Instance;
  6160. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6161. if (sW > tW) tW = sW;
  6162. }
  6163. ui->PP.EndInstance = Restore;
  6164. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6165. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6166. if (W < tW) W = tW;
  6167. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6168. RowMode=1; rW=0;
  6169. }elif (ui->Type==&_LA_UI_ROW_END){
  6170. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6171. }elif (ui->Type->GetMinWidth){
  6172. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6173. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6174. }
  6175. ui = ui->Item.pNext;
  6176. }
  6177. return W;
  6178. }
  6179. void la_InitLLVM(){
  6180. //LLVMLinkInMCJIT();
  6181. //LLVMInitializeNativeTarget();
  6182. //LLVMInitializeNativeAsmPrinter();
  6183. //LLVMInitializeNativeAsmParser();
  6184. // MAIN.llvmContext = LLVMGetGlobalContext();
  6185. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6186. }
  6187. //==================================================================================================
  6188. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6189. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6190. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6191. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6192. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6193. memFree(kmi);
  6194. }
  6195. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6196. laKeyMapItem *kmi;
  6197. if (!km) return 0;
  6198. kmi = memAcquire(sizeof(laKeyMapItem));
  6199. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6200. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6201. }else{
  6202. strSafeSet(&kmi->Operation, Operation);
  6203. }
  6204. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6205. kmi->SpecialKeyBits = SpecialKeyBits;
  6206. kmi->EventType = EventType;
  6207. kmi->Key = tolowerGuarded(Key);
  6208. kmi->SelectBase = SelectBase;
  6209. lstAppendItem(&km->Items, kmi);
  6210. return kmi;
  6211. }
  6212. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6213. laKeyMapItem *kmi; int inv=0;
  6214. char *instructions;
  6215. if(e->type==LA_MOUSEMOVE) return 0;
  6216. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6217. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6218. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6219. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6220. if (kmi->Operation)
  6221. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6222. else
  6223. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6224. inv = 1;
  6225. }
  6226. }
  6227. return inv;
  6228. }
  6229. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6230. laKeyMapItem *kmi;
  6231. char *instructions;
  6232. int inv = 0; int lx = -1, ly = -1;
  6233. if(e->type==LA_MOUSEMOVE) return 0;
  6234. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6235. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6236. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6237. if (e->Localized){
  6238. lx = e->x;
  6239. ly = e->y;
  6240. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6241. e->Localized = 0;
  6242. }
  6243. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6244. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6245. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6246. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6247. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6248. }elif (kmi->Operation){
  6249. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6250. }else{
  6251. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6252. }
  6253. inv = 1;
  6254. if (lx >= 0){
  6255. e->x = lx;
  6256. e->y = ly;
  6257. e->Localized = 1;
  6258. }
  6259. }
  6260. }
  6261. return inv;
  6262. }
  6263. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6264. void la_DestroyOperatorType(laOperatorType* at){
  6265. //if(at->PC) la_FreePropertyContainer(at->PC);
  6266. memFree(at);
  6267. }
  6268. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6269. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6270. uint32_t IconID, int ExtraMark){
  6271. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6272. at->Identifier = ID;
  6273. at->Name = Name;
  6274. at->Description = Description;
  6275. at->Check = Check;
  6276. at->Invoke = Invoke;
  6277. at->Init = Init;
  6278. at->Exit = Exit;
  6279. at->Modal = Modal;
  6280. at->IconID = IconID;
  6281. at->ExtraMark = ExtraMark;
  6282. at->ParseArgs = la_DefaultOperatorParser;
  6283. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6284. return at;
  6285. }
  6286. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6287. ot->PC = memAcquire(sizeof(laPropContainer));
  6288. ot->PC->Identifier = ot->Identifier;
  6289. ot->PC->Hyper = HyperLevel;
  6290. return ot->PC;
  6291. }
  6292. laOperator *la_CreateOperator(laOperatorType *at){
  6293. laOperator *a = CreateNew(laOperator);
  6294. a->Type = at;
  6295. if (at->PC && at->PC->Props.pFirst){
  6296. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6297. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6298. a->PP.LastPs->p->SubProp = at->PC;
  6299. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6300. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6301. a->PP.LastPs->Type = U'.';
  6302. }
  6303. return a;
  6304. }
  6305. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6306. return (!strcmp(a->Identifier, id));
  6307. }
  6308. laOperatorType *laGetOperatorType(const char *ID){
  6309. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6310. }
  6311. int laOperatorExistsT(laOperatorType* at){
  6312. if (!at) return 0;
  6313. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6314. return 0;
  6315. }
  6316. int laOperatorExists(const char* ID){
  6317. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6318. return laOperatorExistsT(at);
  6319. }
  6320. int la_OperatorExists(laOperator *ac){
  6321. if (!ac) return 0;
  6322. laOperator *a;
  6323. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6324. return 0;
  6325. }
  6326. int la_UiOperatorExists(void *inst){
  6327. laOperator *a;
  6328. if (!inst) return 0;
  6329. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6330. if (((laUiItem *)a->Instance) == inst){
  6331. return 1;
  6332. }
  6333. }
  6334. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6335. if (a->Instance == inst){
  6336. return 1;
  6337. }
  6338. }
  6339. return 0;
  6340. }
  6341. int la_OperatorPending(laOperator *target){
  6342. laOperator *a;
  6343. if (!target) return 0;
  6344. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6345. if (a == target){
  6346. return 1;
  6347. }
  6348. }
  6349. return 0;
  6350. }
  6351. void laSetOperatorLocalizer(void *ToPanel){
  6352. MAIN.ToPanel = ToPanel;
  6353. }
  6354. void la_DestroyConfirmData(laConfirmData **cd);
  6355. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6356. laOperator *ai = (*a);
  6357. laOperator *ac = ((*a)->Child);
  6358. void *Ret = 0;
  6359. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6360. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6361. }
  6362. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6363. if ((*a)->PP.LastPs){
  6364. memFree((*a)->PP.LastPs->p);
  6365. memFree((*a)->PP.LastPs);
  6366. }
  6367. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6368. la_SetPropMathcerContext((*a)->OperatorPanel);
  6369. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6370. laDestroySinglePanel((*a)->OperatorPanel,0);
  6371. }
  6372. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6373. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6374. lstClearPointer(&(*a)->LocalUiLists);
  6375. if (Operators){
  6376. Ret = ai->Item.pNext;
  6377. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6378. else
  6379. lstRemoveItem(Operators, *a);
  6380. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6381. if (ai->Child == (*a)) ai->Child = 0;
  6382. }
  6383. }
  6384. strSafeDestroy(&(*a)->RuntimeHint);
  6385. free(*a);
  6386. return Ret;
  6387. }
  6388. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6389. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6390. if (!at) return 0;
  6391. if (!at->Check) return 1;
  6392. return (at->Check(This, Instructions));
  6393. }
  6394. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6395. if (!at) return 0;
  6396. if (!at->Check) return 1;
  6397. return (at->Check(This, Instructions));
  6398. }
  6399. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6400. laPropPack FakePP = {0};
  6401. laPropStep FakePs = {0};
  6402. if (!at) return 0;
  6403. if (!at->Check) return 1;
  6404. FakePP.LastPs = &FakePs;
  6405. FakePP.Go = FakePP.LastPs;
  6406. FakePP.LastPs->p = This->LastPs->p;
  6407. FakePP.LastPs->UseInstance = This->EndInstance;
  6408. FakePP.EndInstance = Real_FromInstance;
  6409. FakePP.LastIndex = This->LastIndex;
  6410. return (at->Check(&FakePP, Instructions));
  6411. }
  6412. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6413. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6414. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6415. }
  6416. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6417. laOperator *a, *f = From;
  6418. int rev;
  6419. if (!f && e&&e->Localized) return -1;
  6420. a = la_CreateOperator(at);
  6421. a->ToPanel = MAIN.ToPanel;
  6422. a->This = This;
  6423. a->ExtraInstructions = args;
  6424. strMakeInstructions(&a->ExtraInstructionsP, args);
  6425. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6426. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6427. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6428. la_DestroyOperator(&a, 0, 0);
  6429. return LA_CANCELED;
  6430. }
  6431. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6432. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6433. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6434. e->Localized = 1;
  6435. }
  6436. if (e&&e->Localized){
  6437. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6438. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6439. e->Localized = 0;
  6440. }else{
  6441. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6442. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6443. }
  6444. }
  6445. if (From) f->Child = a;
  6446. a->Using = 1;
  6447. if (at->Init) at->Init(a);
  6448. rev = at->Invoke(a, e);
  6449. a->Using = 0;
  6450. if (rev & LA_FINISH){
  6451. a->StopNow = 1; if(From)From->Child=0;
  6452. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6453. }
  6454. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6455. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6456. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6457. a->State = rev;
  6458. a->PP.EndInstance = a->CustomData;
  6459. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6460. }else
  6461. la_DestroyOperator(&a, 0, 0);
  6462. return rev;
  6463. }
  6464. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6465. laOperatorType *at; laOperator *a, *f = From;
  6466. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6467. if (!at) return -1;
  6468. return laInvokeP(From,at,e,This,args,args2);
  6469. }
  6470. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6471. laOperator *a, *f = From;
  6472. int rev;
  6473. laPropPack *created;
  6474. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6475. created = memAcquireSimple(sizeof(laPropPack));
  6476. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6477. created->Go = created->LastPs;
  6478. created->LastPs->p = OrigionalThis->LastPs->p;
  6479. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6480. created->EndInstance = FromInstance;
  6481. created->LastIndex = OrigionalThis->LastIndex;
  6482. a = la_CreateOperator(at);
  6483. a->ToPanel = MAIN.ToPanel;
  6484. a->This = created;
  6485. a->CreatedThis = created;
  6486. a->ExtraInstructions = args;
  6487. strMakeInstructions(&a->ExtraInstructionsP, args);
  6488. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6489. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6490. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6491. la_DestroyOperator(&a, 0, 0);
  6492. return LA_CANCELED;
  6493. }
  6494. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6495. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6496. if (From) f->Child = a;
  6497. a->Using = 1;
  6498. if (at->Init) at->Init(a);
  6499. rev = at->Invoke(a, e);
  6500. a->Using = 0;
  6501. if (rev & LA_FINISH){
  6502. a->StopNow = 1; if(From)From->Child=0;
  6503. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6504. }
  6505. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6506. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6507. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6508. a->State = rev;
  6509. a->PP.EndInstance = a->CustomData;
  6510. }else
  6511. la_DestroyOperator(&a, 0, 0);
  6512. return rev;
  6513. }
  6514. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6515. laOperator *a, *f = From;
  6516. int rev;
  6517. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6518. a = la_CreateOperator(at);
  6519. a->Instance = inst;
  6520. a->ToPanel = MAIN.ToPanel;
  6521. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6522. if (From) f->Child = a;
  6523. a->Using = 1;
  6524. if (at->Init) at->Init(a);
  6525. rev = at->Invoke(a, e);
  6526. a->Using = 0;
  6527. if (rev & LA_FINISH){
  6528. a->StopNow = 1; if(From)From->Child=0;
  6529. }
  6530. if (rev & LA_BLOCK){
  6531. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6532. a->State = rev;
  6533. }else la_DestroyOperator(&a, 0, 0);
  6534. DEB = a;
  6535. return rev;
  6536. }
  6537. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6538. laOperatorType *at;
  6539. laOperator *a, *f = From;
  6540. if (la_UiOperatorExists(inst)) return -1;
  6541. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6542. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6543. }
  6544. void laRequestDelayEvent(real Seconds){
  6545. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6546. int la_UiStillInService(void *UiInstance){
  6547. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6548. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6549. if (ai->Instance == UiInstance) return 1;
  6550. }
  6551. return 0;
  6552. }
  6553. void la_StopUiOperatorService(void *UiInstance){
  6554. laOperator *ai, *dai, *NextAi;
  6555. if (!MAIN.CurrentWindow) return;
  6556. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6557. NextAi = ai->Item.pNext;
  6558. if (ai->Instance == UiInstance){
  6559. if (ai->Child){
  6560. la_StopUiOperatorService(ai->Child->Instance);
  6561. ai->Child = 0;
  6562. }
  6563. laOperator *dai = ai;
  6564. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6565. continue;
  6566. }
  6567. }
  6568. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6569. NextAi = ai->Item.pNext;
  6570. if (ai->Instance == UiInstance){
  6571. if (ai->Instance == ai->ToPanel){
  6572. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6573. //ai->ToPanel->LaterDestroy = 1;
  6574. }
  6575. if (ai->Child && la_OperatorExists(ai->Child)){
  6576. la_StopUiOperatorService(ai->Child->Instance);
  6577. //ai->Child = 0;
  6578. }
  6579. if (!ai->Using){
  6580. laOperator *dai = ai;
  6581. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6582. }else
  6583. ai->StopNow = 1;
  6584. }
  6585. }
  6586. }
  6587. void la_StopAllOperators(){
  6588. laOperator *ai, *dai, *NextAi;
  6589. if (!MAIN.CurrentWindow) return;
  6590. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6591. NextAi = ai->Item.pNext;
  6592. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6593. continue;
  6594. }
  6595. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6596. NextAi = ai->Item.pNext;
  6597. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6598. laHidePanelWithDissoveEffect(ai->ToPanel);
  6599. ai->ToPanel->LaterDestroy = 1;
  6600. }
  6601. if (!ai->Using){
  6602. laOperator *dai = ai;
  6603. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6604. }else ai->StopNow = 1;
  6605. }
  6606. }
  6607. void la_DestroyConfirmData(laConfirmData **cd){
  6608. if((!cd)||!(*cd)) return;
  6609. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6610. if ((*cd)->StrData) free((*cd)->StrData);
  6611. FreeMem((*cd));
  6612. (*cd) = 0;
  6613. }
  6614. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6615. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6616. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6617. ai->NextConfirmData = cd; laRetriggerOperators();
  6618. }
  6619. void laConfirmInt(laOperator *a, int Data, int mode){
  6620. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6621. cd->IData = Data; cd->Mode = mode;
  6622. ai->NextConfirmData = cd; laRetriggerOperators();
  6623. }
  6624. void laConfirmFloat(laOperator *a, real Data, int mode){
  6625. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6626. cd->FData = Data; cd->Mode = mode;
  6627. ai->NextConfirmData = cd; laRetriggerOperators();
  6628. }
  6629. void laConfirmString(laOperator *a, char *Str, int mode){
  6630. laOperator *ai = a;
  6631. laConfirmData *cd = CreateNew(laConfirmData);
  6632. int len = strlen(Str);
  6633. char *buf = calloc(len + 1, sizeof(char));
  6634. strcpy(buf, Str);
  6635. cd->StrData = buf;
  6636. cd->Mode = mode;
  6637. cd->Destroy = free;
  6638. ai->NextConfirmData = cd;
  6639. laRetriggerOperators();
  6640. }
  6641. int laConfirmSameDataIfAny(laOperator *a){
  6642. laOperator *ai = a;
  6643. laConfirmData *cd;
  6644. char *buf = 0;
  6645. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6646. cd = CreateNew(laConfirmData);
  6647. if (ai->ConfirmData->StrData){
  6648. int len = strlen(ai->ConfirmData->StrData);
  6649. buf = calloc(len + 1, sizeof(char));
  6650. strcpy(buf, ai->ConfirmData->StrData);
  6651. }
  6652. //cd->CustomData = cd->CustomData;
  6653. cd->IData = ai->ConfirmData->IData;
  6654. cd->FData = ai->ConfirmData->FData;
  6655. cd->PointerData = ai->ConfirmData->PointerData;
  6656. cd->PointerType = a->ConfirmData->PointerType;
  6657. cd->StrData = buf;
  6658. cd->Mode = ai->ConfirmData->Mode;
  6659. cd->Destroy = ai->ConfirmData->Destroy;
  6660. ai->NextConfirmData = cd;
  6661. laRetriggerOperators();
  6662. return 1;
  6663. }
  6664. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6665. laOperator *ai = a;
  6666. laConfirmData *cd = CreateNew(laConfirmData);
  6667. cd->CustomData = UserData;
  6668. cd->Mode = mode;
  6669. cd->Destroy = Destroy;
  6670. ai->NextConfirmData = cd;
  6671. laRetriggerOperators();
  6672. }
  6673. int laGetConfirmMode(laOperator *a){
  6674. return ((laOperator *)a)->ConfirmData->Mode;
  6675. }
  6676. int laGetConfirmInt(laOperator *a){
  6677. laOperator *ai = a;
  6678. int rev = ai->ConfirmData->IData;
  6679. la_DestroyConfirmData(&ai->ConfirmData);
  6680. ai->ConfirmData = 0;
  6681. return rev;
  6682. }
  6683. real laGetConfirmFloat(laOperator *a){
  6684. laOperator *ai = a;
  6685. real rev = ai->ConfirmData->FData;
  6686. la_DestroyConfirmData(&ai->ConfirmData);
  6687. ai->ConfirmData = 0;
  6688. return rev;
  6689. }
  6690. void laGetConfirmString(laOperator *a, char *buf){
  6691. laOperator *ai = a;
  6692. strcpy(buf, ai->ConfirmData->StrData);
  6693. la_DestroyConfirmData(&ai->ConfirmData);
  6694. ai->ConfirmData = 0;
  6695. }
  6696. void *laGetConfirmUserData(laOperator *a){
  6697. laOperator *ai = a;
  6698. return ai->ConfirmData->CustomData;
  6699. }
  6700. void laFinalizeOperators(){
  6701. laOperatorType *at;
  6702. laListHandle *lst;
  6703. int i;
  6704. for (i = 0; i < 256; i++){
  6705. lst = &MAIN.OperatorTypeHash.Entries[i];
  6706. for (at = lst->pFirst; at; at = at->Item.pNext){
  6707. if (at->PC && at->PC->Props.pFirst){
  6708. lstAppendItem(&MAIN.PropContainers, at->PC);
  6709. }
  6710. }
  6711. }
  6712. }
  6713. //=================
  6714. #ifdef LA_LINUX
  6715. static void la_RecordWacomMotions(XIRawEvent *event)
  6716. {
  6717. double *valuator = event->valuators.values;
  6718. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6719. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6720. //SYSWINDOW root_return, child_return;
  6721. //int root_x_return, root_y_return;
  6722. //int win_x_return, win_y_return;
  6723. //unsigned int mask_return;
  6724. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6725. // &root_x_return, &root_y_return,
  6726. // &win_x_return, &win_y_return,
  6727. // &mask_return);
  6728. //
  6729. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6730. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6731. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6732. real x=valuator[3],y=valuator[4];
  6733. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6734. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6735. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6736. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6737. if(XIMaskIsSet(event->valuators.mask, 5)){
  6738. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6739. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6740. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6741. MAIN.IsPen=1;
  6742. }
  6743. #endif
  6744. #ifdef _WIN32
  6745. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6746. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6747. static uint32_t ch = 0; static int lead = 0;
  6748. static wchar_t buf[10] = { 0 }; int adv;
  6749. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6750. short wheelmark = 0;
  6751. int WheelDir = 0;
  6752. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6753. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6754. POINT point;
  6755. PACKET pkt;
  6756. static POINT ptOld, ptNew;
  6757. static UINT prsOld, prsNew, vkey;
  6758. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6759. switch (message) {
  6760. case WM_PAINT:
  6761. //SwapBuffers(GetDC(hwnd));
  6762. break;
  6763. case WM_MOUSEMOVE:
  6764. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6765. MAIN.IsPen = 0;
  6766. break;
  6767. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6768. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6769. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6770. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6771. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6772. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6773. case WM_MOUSEWHEEL:
  6774. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6775. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6776. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6777. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6778. break;
  6779. case WT_PACKET:
  6780. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6781. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6782. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6783. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6784. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6785. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6786. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6787. MAIN.StylusTwist = tw;
  6788. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6789. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6790. MAIN.EraserPressure = MAIN.StylusPressure;
  6791. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6792. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6793. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6794. }
  6795. return 0; break;
  6796. case WM_SYSCOMMAND:
  6797. switch (wparam) {
  6798. case SC_MAXIMIZE:
  6799. case SC_RESTORE:
  6800. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6801. break;
  6802. case SC_KEYMENU:
  6803. return 0;
  6804. case SC_MINIMIZE:
  6805. break;
  6806. }
  6807. break;
  6808. case WM_SIZE:
  6809. if (wparam == SIZE_MINIMIZED) break;
  6810. case WM_MOVE: /* And size */
  6811. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6812. break;
  6813. case WM_SETCURSOR:
  6814. if(MAIN.CurrentCursor) return 1;
  6815. break;
  6816. case WM_POINTERDOWN:
  6817. case WM_POINTERUP:
  6818. case WM_POINTERUPDATE:
  6819. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6820. pointerId = GET_POINTERID_WPARAM(wparam);
  6821. pointerType = PT_POINTER;
  6822. if(!GetPointerType(pointerId, &pointerType)){
  6823. pointerType = PT_POINTER;
  6824. }
  6825. if(pointerType == PT_PEN){
  6826. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6827. for (int i = peninfonum-1; i>=0; i--) {
  6828. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6829. ScreenToClient(hwnd, &point);
  6830. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6831. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6832. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6833. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6834. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6835. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6836. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6837. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6838. }
  6839. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6840. }
  6841. }
  6842. SkipPointerFrameMessages(pointerId);
  6843. return 0;
  6844. }
  6845. else if (pointerType == PT_TOUCH){
  6846. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6847. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6848. ScreenToClient(hwnd, &point);
  6849. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6850. }
  6851. }
  6852. break;
  6853. case WM_SYSKEYDOWN:
  6854. if (lparam & 0x40000000) break;
  6855. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6856. break;
  6857. case WM_KEYDOWN:
  6858. if (lparam & 0x40000000) break;
  6859. vkey = wparam;
  6860. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6861. break;
  6862. case WM_KEYUP:
  6863. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6864. break;
  6865. case WM_SYSKEYUP:
  6866. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6867. break;
  6868. case WM_UNICHAR:
  6869. la_SendInputEvent(hwnd, wparam);
  6870. break;
  6871. case WM_IME_CHAR:
  6872. la_SendInputEvent(hwnd, wparam);
  6873. return 0;
  6874. case WM_CHAR:
  6875. la_SendInputEvent(hwnd, wparam);
  6876. break;
  6877. case WM_SHOWWINDOW:
  6878. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6879. break;
  6880. case WM_CLOSE:
  6881. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6882. break;
  6883. default:
  6884. return DefWindowProc(hwnd, message, wparam, lparam);
  6885. }
  6886. return DefWindowProc(hwnd, message, wparam, lparam);
  6887. }
  6888. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6889. return DefWindowProc(hwnd, message, wparam, lparam);
  6890. }
  6891. #endif
  6892. int la_UpdateOperatorHints(laWindow* w){
  6893. laSafeString* ss=0;
  6894. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6895. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6896. }
  6897. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6898. }else{
  6899. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6900. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6901. }
  6902. strSafeDestroy(&ss);
  6903. }
  6904. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6905. laOperator *a, *NextA = 0;
  6906. int Result = 0;
  6907. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6908. la_SendSignalsFromEvent(e);
  6909. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6910. a = Operators->pFirst;
  6911. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6912. while (1){
  6913. if (!a) break;
  6914. if (a->StopNow){
  6915. NextA = a->Item.pNext;
  6916. if (a->Type->Exit) a->Type->Exit(a, Result);
  6917. ConfirmData = a->NextConfirmData;
  6918. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6919. NextConfirmData = ConfirmData;
  6920. a->ConfirmData = 0;
  6921. a->NextConfirmData = 0;
  6922. la_DestroyOperator(&a, Operators, 0);
  6923. a = NextA;
  6924. if (a){
  6925. a->ConfirmData = NextConfirmData;
  6926. }
  6927. continue;
  6928. }
  6929. a->Using = 1;
  6930. la_SetPropMathcerContext(a->ToPanel);
  6931. laSetOperatorLocalizer(a->ToPanel);
  6932. MAIN.CurrentPanel = a->ToPanel;
  6933. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6934. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6935. e->Localized = 1;
  6936. }
  6937. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6938. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6939. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6940. e->Localized = 0;
  6941. }
  6942. la_SetPropMathcerContext(0);
  6943. laSetOperatorLocalizer(0);
  6944. MAIN.CurrentPanel = 0;
  6945. a->Using = 0;
  6946. if (Result & LA_PASS_ON){
  6947. laConfirmSameDataIfAny(a);
  6948. NextA = a->Item.pNext;
  6949. }else{
  6950. NextA = 0;
  6951. if (a->NextConfirmData){
  6952. la_DestroyConfirmData(&a->NextConfirmData);
  6953. }
  6954. }
  6955. ConfirmData = a->NextConfirmData;
  6956. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6957. NextConfirmData = ConfirmData;
  6958. a->ConfirmData = 0;
  6959. a->NextConfirmData = 0;
  6960. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6961. if (a->Type->Exit) a->Type->Exit(a, Result);
  6962. la_DestroyOperator(&a, Operators, 0);
  6963. int found=0;
  6964. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6965. if(!found){ NextA=0; }
  6966. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6967. }
  6968. a = NextA;
  6969. if (a){
  6970. a->ConfirmData = NextConfirmData;
  6971. }
  6972. }
  6973. return 1;
  6974. }
  6975. int la_HandleEvents(laWindow *w){
  6976. laEvent *e, *NextE;
  6977. laOperator *a;
  6978. laThreadNotifier *tn;
  6979. MAIN.CurrentWindow=w;
  6980. //laSpinLock(&MAIN.csNotifier);
  6981. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6982. //laSpinUnlock(&MAIN.csNotifier);
  6983. laNotifyUsers(tn->Path);
  6984. FreeMem(tn);
  6985. //if (MAIN.ThreadNotifiers.pFirst)
  6986. //laSpinLock(&MAIN.csNotifier);
  6987. }
  6988. //laSpinUnlock(&MAIN.csNotifier);
  6989. while (1){
  6990. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6991. while (w->EventList.pFirst){
  6992. while (w->PendingOperators.pLast){
  6993. a = w->PendingOperators.pLast;
  6994. if (a->OperatorPanel){
  6995. laSetOperatorLocalizer(a->OperatorPanel);
  6996. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6997. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6998. }
  6999. lstRemoveItem(&w->PendingOperators, a);
  7000. lstPushItem(&w->Operators, a);
  7001. }
  7002. e = lstPopItem(&w->EventList);
  7003. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  7004. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  7005. memFree(e);
  7006. }
  7007. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  7008. if (!MAIN.ReTriggerOperators) break;
  7009. }
  7010. la_UpdateOperatorHints(w);
  7011. return 1;
  7012. }
  7013. int la_AllowInput(uint32_t ch){
  7014. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  7015. return 0;
  7016. }
  7017. int laCopyToClipboard(unsigned char * text){
  7018. #ifdef LA_LINUX
  7019. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  7020. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  7021. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  7022. strSafeSet(&MAIN.CopyPending, text);
  7023. #endif
  7024. }
  7025. int la_ProcessSysMessage(){
  7026. int SendDelay = 0, SendIdle = 0;
  7027. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  7028. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  7029. #ifdef LA_LINUX
  7030. XEvent e;
  7031. int type;
  7032. int InputCount = 0, CharCount=0;
  7033. KeySym InputKeysym = 0;
  7034. Status InputStatus = 0;
  7035. laWindow* wnd ;
  7036. while(XPending(MAIN.dpy)){
  7037. XGenericEventCookie *cookie = &e.xcookie;
  7038. XNextEvent(MAIN.dpy, &e);
  7039. if (XFilterEvent(&e, None)) continue;
  7040. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  7041. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  7042. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  7043. XFreeEventData(MAIN.dpy, cookie); continue;
  7044. }
  7045. switch(e.type){
  7046. case ConfigureNotify:
  7047. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  7048. break;
  7049. case Expose:
  7050. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  7051. if(!wnd) break;
  7052. laRefreshWindow(wnd);
  7053. break;
  7054. case MotionNotify:
  7055. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  7056. MAIN.IsPen=0;
  7057. break;
  7058. case ButtonPress:
  7059. type=LA_MOUSEDOWN;
  7060. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7061. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7062. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7063. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7064. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7065. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7066. MAIN.IsPen=0;
  7067. break;
  7068. case ButtonRelease:
  7069. type=LA_MOUSEUP;
  7070. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7071. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7072. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7073. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7074. MAIN.IsPen=0;
  7075. break;
  7076. case KeyPress:
  7077. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7078. MAIN.InputBuf[InputCount]=0;
  7079. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7080. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7081. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7082. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7083. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7084. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7085. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7086. #ifdef DEBUG
  7087. printf("pressed KEY: %d\n", (int)InputKeysym);
  7088. #endif
  7089. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7090. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7091. }
  7092. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7093. }
  7094. break;
  7095. case KeyRelease:
  7096. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7097. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7098. }
  7099. case ClientMessage:
  7100. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7101. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7102. }
  7103. break;
  7104. case SelectionNotify:
  7105. if(e.xselection.selection != MAIN.bufid) continue;
  7106. if (e.xselection.property){
  7107. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7108. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7109. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7110. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7111. else if(result) {
  7112. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7113. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7114. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7115. }
  7116. XFree(result);
  7117. return True;
  7118. }
  7119. case SelectionRequest:
  7120. if(!MAIN.CopyPending){ break; }
  7121. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7122. if (e.xselectionrequest.selection != MAIN.selection) break;
  7123. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7124. XSelectionEvent ev = {0};
  7125. int R = 0;
  7126. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7127. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7128. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7129. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7130. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7131. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7132. else if (ev.target == MAIN.UTF8)
  7133. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7134. else ev.property = None;
  7135. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7136. break;
  7137. case SelectionClear:
  7138. break;
  7139. default:
  7140. break;
  7141. }
  7142. }
  7143. #endif //linux
  7144. #ifdef _WIN32
  7145. MSG msg; int Processed = 0;
  7146. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7147. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7148. if (msg.wParam == VK_PROCESSKEY) {
  7149. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7150. }
  7151. TranslateMessage(&msg); DispatchMessage(&msg);
  7152. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7153. };
  7154. if(!MAIN.Windows.pFirst){ return 0; }
  7155. #endif
  7156. #ifdef LAGUI_ANDROID
  7157. int pollResult = 0;
  7158. int pollEvents = 0;
  7159. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7160. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7161. // NOTE: Never close window, native activity is controlled by the system!
  7162. if (MAIN.app->destroyRequested != 0)
  7163. {
  7164. //CORE.Window.shouldClose = true;
  7165. //ANativeActivity_finish(MAIN.app->activity);
  7166. }
  7167. }
  7168. #endif
  7169. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7170. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7171. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7172. }
  7173. return 1;
  7174. };
  7175. void la_PrintOperatorStack(){
  7176. laWindow *w = MAIN.CurrentWindow;
  7177. laOperator *a;
  7178. printf("\n");
  7179. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7180. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7181. a->Type->Identifier, a->Instance,
  7182. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7183. }
  7184. }
  7185. void la_DrawWindow(laWindow *w){
  7186. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7187. MAIN.CurrentWindow = w;
  7188. la_WindowDefDraw(w, 0);
  7189. }
  7190. int laFinalize(){
  7191. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7192. laUiTemplate* uit;
  7193. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7194. return 1;
  7195. }
  7196. void la_PreFrame(){
  7197. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7198. la_AnimationPreFrame();
  7199. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7200. }
  7201. void la_PostFrame(){
  7202. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7203. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7204. }
  7205. void laMainLoop(){
  7206. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7207. time_t t1, t2;
  7208. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7209. static int a = 0;
  7210. if(!laFinalize()) return;
  7211. laSetWindowCursor(LA_ARROW);
  7212. MAIN.DelayTriggered=1;
  7213. #ifdef LAGUI_ANDROID
  7214. while(!MAIN.AppReady){ usleep(1000); }
  7215. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7216. #endif
  7217. while (1){
  7218. laRecordTime(&MAIN.FrameStartTime);
  7219. la_PerfClear();
  7220. la_PreFrame();
  7221. if(!la_ProcessSysMessage()){ return; }
  7222. la_UpdateControllerStatus();
  7223. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7224. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7225. NextW = w->Item.pNext;
  7226. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7227. }
  7228. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7229. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7230. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7231. if(MAIN.GLDebugNeedsUpdate){
  7232. la_SetCurrentGLContextDebug();
  7233. }
  7234. la_DrawWindow(w);
  7235. }
  7236. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7237. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7238. #ifdef LA_LINUX
  7239. #ifdef LA_USE_GLES
  7240. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7241. #else
  7242. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7243. #endif
  7244. #endif
  7245. #ifdef _WIN32
  7246. SwapBuffers(w->hdc);
  7247. #endif
  7248. #ifdef LAGUI_ANDROID
  7249. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7250. #endif
  7251. }
  7252. MAIN.GLDebugNeedsUpdate=0;
  7253. la_PostFrame();
  7254. //t2 = clock();
  7255. laRecordTime(&MAIN.FrameEndTime);
  7256. TimeInterval = laTimeElapsedSecondsf(&MAIN.FrameEndTime, &MAIN.FrameStartTime);
  7257. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7258. if (Pause > 0){
  7259. int us = Pause * 1000000.0;
  7260. usleep(us);
  7261. }
  7262. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7263. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7264. la_AnimationPostFrame();
  7265. }
  7266. }
  7267. #ifdef LAGUI_ANDROID
  7268. int la_AndroidInitGraphics(void){
  7269. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7270. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7271. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7272. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7273. EGLint samples = 0;
  7274. EGLint sampleBuffer = 0;
  7275. const EGLint framebufferAttribs[] = {
  7276. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7277. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7278. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7279. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7280. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7281. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7282. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7283. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7284. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7285. EGL_NONE
  7286. };
  7287. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7288. EGLint numConfigs = 0;
  7289. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7290. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7291. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7292. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7293. eglBindAPI(EGL_OPENGL_API);
  7294. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7295. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7296. EGLint displayFormat = 0;
  7297. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7298. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7299. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7300. // There must be at least one frame displayed before the buffers are swapped
  7301. eglSwapInterval(MAIN.egl_dpy, 1);
  7302. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7303. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7304. MAIN.AppReady = 1;
  7305. return 0;
  7306. }
  7307. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7308. switch (cmd){
  7309. case APP_CMD_START: break;
  7310. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7311. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7312. case APP_CMD_RESUME:break;//InitPlatform();break;
  7313. case APP_CMD_INIT_WINDOW:
  7314. if (app->window != NULL){
  7315. if (MAIN.ContextRebindRequired){
  7316. // Reset screen scaling to full display size
  7317. EGLint displayFormat = 0;
  7318. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7319. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7320. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7321. // appropriate way to fix this
  7322. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7323. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7324. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7325. displayFormat);
  7326. // Recreate display surface and re-attach OpenGL context
  7327. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7328. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7329. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7330. //glClearColor(1,0.2,1,1);
  7331. //glClear(GL_COLOR_BUFFER_BIT);
  7332. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7333. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7334. MAIN.ContextRebindRequired = false;
  7335. }else{
  7336. la_AndroidInitGraphics();
  7337. }
  7338. }
  7339. break;
  7340. case APP_CMD_DESTROY:
  7341. case APP_CMD_TERM_WINDOW:
  7342. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7343. // 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.
  7344. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7345. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7346. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7347. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7348. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7349. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7350. MAIN.egl_surf = EGL_NO_SURFACE;
  7351. }
  7352. MAIN.ContextRebindRequired = true;
  7353. }
  7354. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7355. // this means that the user has already called 'CloseWindow()'
  7356. break;
  7357. case APP_CMD_SAVE_STATE: break;
  7358. case APP_CMD_STOP: break;
  7359. case APP_CMD_CONFIG_CHANGED:
  7360. case APP_CMD_WINDOW_RESIZED:
  7361. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7362. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7363. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7364. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7365. //print_cur_config(MAIN.app);
  7366. // Check screen orientation here!
  7367. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7368. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7369. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7370. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7371. MAIN.egl_surf = EGL_NO_SURFACE;
  7372. }
  7373. EGLint displayFormat = 0;
  7374. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7375. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7376. displayFormat);
  7377. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7378. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7379. }
  7380. break;
  7381. default: break;
  7382. }
  7383. }
  7384. #define KEYCODE_MAP_SIZE 162
  7385. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7386. 0, // AKEYCODE_UNKNOWN
  7387. 0, // AKEYCODE_SOFT_LEFT
  7388. 0, // AKEYCODE_SOFT_RIGHT
  7389. 0, // AKEYCODE_HOME
  7390. 0, // AKEYCODE_BACK
  7391. 0, // AKEYCODE_CALL
  7392. 0, // AKEYCODE_ENDCALL
  7393. '0', // AKEYCODE_0
  7394. '1', // AKEYCODE_1
  7395. '2', // AKEYCODE_2
  7396. '3', // AKEYCODE_3
  7397. '4', // AKEYCODE_4
  7398. '5', // AKEYCODE_5
  7399. '6', // AKEYCODE_6
  7400. '7', // AKEYCODE_7
  7401. '8', // AKEYCODE_8
  7402. '9', // AKEYCODE_9
  7403. 0, // AKEYCODE_STAR
  7404. 0, // AKEYCODE_POUND
  7405. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7406. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7407. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7408. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7409. 0, // AKEYCODE_DPAD_CENTER
  7410. 0, // AKEYCODE_VOLUME_UP
  7411. 0, // AKEYCODE_VOLUME_DOWN
  7412. 0, // AKEYCODE_POWER
  7413. 0, // AKEYCODE_CAMERA
  7414. 0, // AKEYCODE_CLEAR
  7415. 'a', // AKEYCODE_A
  7416. 'b', // AKEYCODE_B
  7417. 'c', // AKEYCODE_C
  7418. 'd', // AKEYCODE_D
  7419. 'e', // AKEYCODE_E
  7420. 'f', // AKEYCODE_F
  7421. 'g', // AKEYCODE_G
  7422. 'h', // AKEYCODE_H
  7423. 'i', // AKEYCODE_I
  7424. 'j', // AKEYCODE_J
  7425. 'k', // AKEYCODE_K
  7426. 'l', // AKEYCODE_L
  7427. 'm', // AKEYCODE_M
  7428. 'n', // AKEYCODE_N
  7429. 'o', // AKEYCODE_O
  7430. 'p', // AKEYCODE_P
  7431. 'q', // AKEYCODE_Q
  7432. 'r', // AKEYCODE_R
  7433. 's', // AKEYCODE_S
  7434. 't', // AKEYCODE_T
  7435. 'u', // AKEYCODE_U
  7436. 'v', // AKEYCODE_V
  7437. 'w', // AKEYCODE_W
  7438. 'x', // AKEYCODE_X
  7439. 'y', // AKEYCODE_Y
  7440. 'z', // AKEYCODE_Z
  7441. ',', // AKEYCODE_COMMA
  7442. '.', // AKEYCODE_PERIOD
  7443. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7444. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7445. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7446. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7447. LA_KEY_TAB, // AKEYCODE_TAB
  7448. ' ', // AKEYCODE_SPACE
  7449. 0, // AKEYCODE_SYM
  7450. 0, // AKEYCODE_EXPLORER
  7451. 0, // AKEYCODE_ENVELOPE
  7452. LA_KEY_ENTER, // AKEYCODE_ENTER
  7453. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7454. '`', // AKEYCODE_GRAVE
  7455. '-', // AKEYCODE_MINUS
  7456. '=', // AKEYCODE_EQUALS
  7457. '(', // AKEYCODE_LEFT_BRACKET
  7458. ')', // AKEYCODE_RIGHT_BRACKET
  7459. '\\', // AKEYCODE_BACKSLASH
  7460. ';', // AKEYCODE_SEMICOLON
  7461. '\'', // AKEYCODE_APOSTROPHE
  7462. '/', // AKEYCODE_SLASH
  7463. 0, // AKEYCODE_AT
  7464. 0, // AKEYCODE_NUM
  7465. 0, // AKEYCODE_HEADSETHOOK
  7466. 0, // AKEYCODE_FOCUS
  7467. 0, // AKEYCODE_PLUS
  7468. 0, // AKEYCODE_MENU
  7469. 0, // AKEYCODE_NOTIFICATION
  7470. 0, // AKEYCODE_SEARCH
  7471. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7472. 0, // AKEYCODE_MEDIA_STOP
  7473. 0, // AKEYCODE_MEDIA_NEXT
  7474. 0, // AKEYCODE_MEDIA_PREVIOUS
  7475. 0, // AKEYCODE_MEDIA_REWIND
  7476. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7477. 0, // AKEYCODE_MUTE
  7478. 0, // AKEYCODE_PAGE_UP
  7479. 0, // AKEYCODE_PAGE_DOWN
  7480. 0, // AKEYCODE_PICTSYMBOLS
  7481. 0, // AKEYCODE_SWITCH_CHARSET
  7482. 0, // AKEYCODE_BUTTON_A
  7483. 0, // AKEYCODE_BUTTON_B
  7484. 0, // AKEYCODE_BUTTON_C
  7485. 0, // AKEYCODE_BUTTON_X
  7486. 0, // AKEYCODE_BUTTON_Y
  7487. 0, // AKEYCODE_BUTTON_Z
  7488. 0, // AKEYCODE_BUTTON_L1
  7489. 0, // AKEYCODE_BUTTON_R1
  7490. 0, // AKEYCODE_BUTTON_L2
  7491. 0, // AKEYCODE_BUTTON_R2
  7492. 0, // AKEYCODE_BUTTON_THUMBL
  7493. 0, // AKEYCODE_BUTTON_THUMBR
  7494. 0, // AKEYCODE_BUTTON_START
  7495. 0, // AKEYCODE_BUTTON_SELECT
  7496. 0, // AKEYCODE_BUTTON_MODE
  7497. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7498. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7499. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7500. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7501. 0, // AKEYCODE_CAPS_LOCK
  7502. 0, // AKEYCODE_SCROLL_LOCK
  7503. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7504. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7505. 0, // AKEYCODE_FUNCTION
  7506. 0, // AKEYCODE_SYSRQ
  7507. 0, // AKEYCODE_BREAK
  7508. 0, // AKEYCODE_MOVE_HOME
  7509. 0, // AKEYCODE_MOVE_END
  7510. 0, // AKEYCODE_INSERT
  7511. 0, // AKEYCODE_FORWARD
  7512. 0, // AKEYCODE_MEDIA_PLAY
  7513. 0, // AKEYCODE_MEDIA_PAUSE
  7514. 0, // AKEYCODE_MEDIA_CLOSE
  7515. 0, // AKEYCODE_MEDIA_EJECT
  7516. 0, // AKEYCODE_MEDIA_RECORD
  7517. LA_KEY_F1, // AKEYCODE_F1
  7518. LA_KEY_F2, // AKEYCODE_F2
  7519. LA_KEY_F3, // AKEYCODE_F3
  7520. LA_KEY_F4, // AKEYCODE_F4
  7521. LA_KEY_F5, // AKEYCODE_F5
  7522. LA_KEY_F6, // AKEYCODE_F6
  7523. LA_KEY_F7, // AKEYCODE_F7
  7524. LA_KEY_F8, // AKEYCODE_F8
  7525. LA_KEY_F9, // AKEYCODE_F9
  7526. LA_KEY_F10, // AKEYCODE_F10
  7527. LA_KEY_F11, // AKEYCODE_F11
  7528. LA_KEY_F12, // AKEYCODE_F12
  7529. 0, // AKEYCODE_NUM_LOCK
  7530. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7531. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7532. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7533. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7534. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7535. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7536. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7537. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7538. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7539. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7540. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7541. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7542. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7543. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7544. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7545. 0, // AKEYCODE_NUMPAD_COMMA
  7546. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7547. '=' // AKEYCODE_NUMPAD_EQUALS
  7548. };
  7549. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7550. {
  7551. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7552. if(!MAIN.AppEnabled){return 0;}
  7553. //laRedrawAllWindows();
  7554. static int prev_button_state=0;
  7555. int type = AInputEvent_getType(event);
  7556. if(type == AINPUT_EVENT_TYPE_KEY){
  7557. int32_t keycode = AKeyEvent_getKeyCode(event);
  7558. //int32_t AKeyEvent_getMetaState(event);
  7559. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7560. if (key != 0){
  7561. // Save current key and its state
  7562. // NOTE: Android key action is 0 for down and 1 for up
  7563. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7564. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7565. if(key!=LA_KEY_BACKSPACE)
  7566. la_SendInputEvent(0,key);
  7567. }
  7568. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7569. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7570. la_SendInputEvent(0,key);
  7571. }
  7572. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7573. }
  7574. if (keycode == AKEYCODE_POWER)
  7575. {
  7576. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7577. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7578. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7579. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7580. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7581. return 0;
  7582. }
  7583. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7584. {
  7585. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7586. return 1;
  7587. }
  7588. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7589. {
  7590. // Set default OS behaviour
  7591. return 0;
  7592. }
  7593. return 0;
  7594. }
  7595. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7596. static real zoom_offset=1; static real temp_distance=0;
  7597. real zoom; int gesture_handled=0;
  7598. int pcount = AMotionEvent_getPointerCount(event); int x,y; static real cx=0,cy=0;
  7599. int32_t action = AMotionEvent_getAction(event);
  7600. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7601. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7602. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7603. if(pcount){
  7604. x=rx; y=ry;
  7605. int tool_type=AMotionEvent_getToolType(event,0);
  7606. real pressure = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_PRESSURE,0);
  7607. if(tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS || tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER){
  7608. MAIN.StylusPressure = MAIN.EraserPressure = pressure; MAIN.IsPen = 1;
  7609. MAIN.PointerIsEraser = (tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER);
  7610. }else{
  7611. MAIN.IsPen = 0;
  7612. }
  7613. if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
  7614. && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
  7615. real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
  7616. real ctx=(x+x2)/2, cty=(y+y2)/2;
  7617. real distance = tnsDistIdv2(x2,y2,rx,ry);
  7618. if(temp_distance){ zoom_offset*=(distance/temp_distance); }
  7619. temp_distance = distance;
  7620. while(zoom_offset > 1.1){ zoom_offset-=0.1;
  7621. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7622. la_SendMouseEvent(0, LA_MOUSEUP|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7623. }
  7624. while(zoom_offset < (1.0/1.1)){ zoom_offset+=(0.1/1.1);
  7625. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7626. la_SendMouseEvent(0, LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7627. }
  7628. if(cx || cy){
  7629. if(!gesture_handled){
  7630. real dist = tnsDistIdv2(ctx,cty,cx,cy);
  7631. while(dist > LA_RH){
  7632. int udlr = fabs(cty-cy) > fabs(ctx-cx);
  7633. int direction = udlr?(cty>cy?LA_KEY_ARRUP:LA_KEY_ARRDOWN):
  7634. (ctx>cx?LA_KEY_ARRLEFT:LA_KEY_ARRRIGHT);
  7635. real fac = (real)(LA_RH)/dist;
  7636. cx=tnsLinearItp(cx,ctx,fac); cy=tnsLinearItp(cy,cty,fac);
  7637. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7638. la_SendKeyboardEvent(0, LA_KEY_DOWN, direction|LA_KEYBOARD_EVENT|LA_KEY_PANNING);
  7639. gesture_handled=1;
  7640. dist = tnsDistIdv2(ctx,cty,cx,cy);
  7641. }
  7642. }
  7643. }else{
  7644. cx=ctx; cy=cty;
  7645. }
  7646. }else{
  7647. temp_distance = 0; cx=0; cy=0;
  7648. }
  7649. if(flags==AMOTION_EVENT_ACTION_HOVER_MOVE){
  7650. la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
  7651. }
  7652. }
  7653. if(!gesture_handled){
  7654. if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_BUTTON_PRESS){
  7655. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7656. int btn=AMotionEvent_getButtonState(event);
  7657. int evtype=LA_L_MOUSE_DOWN;
  7658. if(btn & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_DOWN; }
  7659. elif(btn & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_DOWN; }
  7660. la_SendMouseEvent(0,evtype,x,y);
  7661. prev_button_state = btn;
  7662. }
  7663. else if (flags == AMOTION_EVENT_ACTION_UP || flags == AMOTION_EVENT_ACTION_BUTTON_RELEASE){
  7664. int btn=AMotionEvent_getButtonState(event); int changed = (~btn)&prev_button_state;
  7665. int evtype=LA_L_MOUSE_UP;
  7666. if(changed & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_UP; }
  7667. elif(changed & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_UP; }
  7668. la_SendMouseEvent(0,evtype,x,y);
  7669. }
  7670. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7671. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7672. }
  7673. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7674. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7675. }
  7676. }
  7677. }
  7678. //static float r=0;
  7679. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7680. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7681. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7682. //glClear(GL_COLOR_BUFFER_BIT);
  7683. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7684. return 0;
  7685. }
  7686. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7687. MAIN.AssetManager = manager;
  7688. MAIN.InternalDataPath = dataPath;
  7689. MAIN.ExternalDataPath = externalDataPath;
  7690. }
  7691. static int android_read(void *cookie, char *data, int dataSize){
  7692. return AAsset_read((AAsset *)cookie, data, dataSize);
  7693. }
  7694. static int android_write(void *cookie, const char *data, int dataSize){
  7695. return 0;
  7696. }
  7697. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7698. return AAsset_seek((AAsset *)cookie, offset, whence);
  7699. }
  7700. static int android_close(void *cookie){
  7701. AAsset_close((AAsset *)cookie);
  7702. return 0;
  7703. }
  7704. // Replacement for fopen()
  7705. // Ref: https://developer.android.com/ndk/reference/group/asset
  7706. FILE *android_fopen(const char *fileName, const char *mode)
  7707. {
  7708. char buf[1024];
  7709. if (mode[0] == 'w')
  7710. {
  7711. // fopen() is mapped to android_fopen() that only grants read access to
  7712. // assets directory through AAssetManager but we want to also be able to
  7713. // write data when required using the standard stdio FILE access functions
  7714. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7715. #undef fopen
  7716. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7717. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7718. result=fopen(buf, mode); if(result) return result;
  7719. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7720. return fopen(buf, mode);
  7721. #define fopen(name, mode) android_fopen(name, mode)
  7722. }
  7723. else
  7724. {
  7725. // NOTE: AAsset provides access to read-only asset
  7726. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7727. if (asset != NULL)
  7728. {
  7729. // Get pointer to file in the assets
  7730. return funopen(asset, android_read, android_write, android_seek, android_close);
  7731. }
  7732. else
  7733. {
  7734. #undef fopen
  7735. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7736. // Just do a regular open if file is not found in the assets
  7737. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7738. result=fopen(buf, mode); if(result){ return result; }
  7739. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7740. return fopen(buf, mode);
  7741. #define fopen(name, mode) android_fopen(name, mode)
  7742. }
  7743. }
  7744. }
  7745. void la_HideNavBar(){
  7746. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7747. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7748. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7749. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7750. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7751. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7752. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7753. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7754. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7755. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7756. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7757. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7758. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7759. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7760. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7761. int flag = flagFullscreen | flagHideNavigation;
  7762. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7763. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7764. }
  7765. void la_InitAndroidPlatform(struct android_app *app){
  7766. MAIN.app=app;
  7767. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7768. //la_HideNavBar();
  7769. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7770. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7771. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7772. int pollResult = 0;
  7773. int pollEvents = 0;
  7774. while (!MAIN.AppReady){
  7775. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7776. // Process this event
  7777. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7778. // NOTE: Never close window, native activity is controlled by the system!
  7779. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7780. }
  7781. }
  7782. }
  7783. int main(int, char *[]);
  7784. void android_main(struct android_app *app){
  7785. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7786. la_InitAndroidPlatform(app);
  7787. // NOTE: Return from main is ignored
  7788. (void)main(1, (char *[]) { arg0, NULL });
  7789. // Request to end the native activity
  7790. ANativeActivity_finish(app->activity);
  7791. // Android ALooper_pollAll() variables
  7792. int pollResult = 0;
  7793. int pollEvents = 0;
  7794. // Waiting for application events before complete finishing
  7795. while (!app->destroyRequested)
  7796. {
  7797. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7798. {
  7799. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7800. }
  7801. }
  7802. }
  7803. void la_DisplayKeyboard(bool pShow) {
  7804. // Attaches the current thread to the JVM.
  7805. jint lResult;
  7806. jint lFlags = 0;
  7807. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7808. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7809. JavaVMAttachArgs lJavaVMAttachArgs;
  7810. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7811. lJavaVMAttachArgs.name = "NativeThread";
  7812. lJavaVMAttachArgs.group = NULL;
  7813. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7814. if (lResult == JNI_ERR) {
  7815. return;
  7816. }
  7817. // Retrieves NativeActivity.
  7818. jobject lNativeActivity = MAIN.app->activity->clazz;
  7819. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7820. logPrintNew("jvm3");
  7821. // Retrieves Context.INPUT_METHOD_SERVICE.
  7822. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7823. jfieldID FieldINPUT_METHOD_SERVICE =
  7824. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7825. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7826. jobject INPUT_METHOD_SERVICE =
  7827. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7828. FieldINPUT_METHOD_SERVICE);
  7829. //jniCheck(INPUT_METHOD_SERVICE);
  7830. logPrintNew("jvm4");
  7831. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7832. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7833. "android/view/inputmethod/InputMethodManager");
  7834. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7835. ClassNativeActivity, "getSystemService",
  7836. "(Ljava/lang/String;)Ljava/lang/Object;");
  7837. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7838. lNativeActivity, MethodGetSystemService,
  7839. INPUT_METHOD_SERVICE);
  7840. // Runs getWindow().getDecorView().
  7841. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7842. ClassNativeActivity, "getWindow",
  7843. "()Landroid/view/Window;");
  7844. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7845. MethodGetWindow);
  7846. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7847. "android/view/Window");
  7848. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7849. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7850. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7851. MethodGetDecorView);
  7852. if (pShow) {
  7853. // Runs lInputMethodManager.showSoftInput(...).
  7854. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7855. ClassInputMethodManager, "showSoftInput",
  7856. "(Landroid/view/View;I)Z");
  7857. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7858. lInputMethodManager, MethodShowSoftInput,
  7859. lDecorView, lFlags);
  7860. } else {
  7861. // Runs lWindow.getViewToken()
  7862. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7863. "android/view/View");
  7864. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7865. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7866. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7867. MethodGetWindowToken);
  7868. // lInputMethodManager.hideSoftInput(...).
  7869. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7870. ClassInputMethodManager, "hideSoftInputFromWindow",
  7871. "(Landroid/os/IBinder;I)Z");
  7872. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7873. lInputMethodManager, MethodHideSoftInput,
  7874. lBinder, lFlags);
  7875. }
  7876. // Finished with the JVM.
  7877. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7878. }
  7879. #endif //android
  7880. #ifndef LAGUI_ANDROID
  7881. void la_DisplayKeyboard(bool pShow) {
  7882. return;
  7883. }
  7884. void la_HideNavBar(){
  7885. return;
  7886. }
  7887. #endif