*/}}

la_kernel.c 335 KB

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