*/}}

la_kernel.c 330 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765
  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. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  61. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  62. static int android_read(void *cookie, char *buf, int size);
  63. static int android_write(void *cookie, const char *buf, int size);
  64. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  65. static int android_close(void *cookie);
  66. void la_InitAndroidPlatform(struct android_app *app);
  67. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  68. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  69. void la_InitAndroidPlatform(struct android_app *app);
  70. #endif
  71. LA MAIN={0};
  72. extern tnsMain *T;
  73. int deb = 0;
  74. laOperator *DEB;
  75. laColumn *DEBUG_C;
  76. #ifdef _WIN32
  77. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  78. #else
  79. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  80. #endif
  81. #ifdef LA_LINUX
  82. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  83. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  84. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  85. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  86. #endif
  87. #ifdef LA_LINUX
  88. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  89. int i;
  90. for (i = 0; i < num_classes; i++) {
  91. if (classes[i]->type == XIValuatorClass) {
  92. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  93. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  94. logPrint(" Range: %f - %f\n", v->min, v->max);
  95. logPrint(" Resolution: %d units/m\n", v->resolution);
  96. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  97. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  98. }
  99. }
  100. }
  101. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  102. XIDeviceInfo *info, *dev;
  103. int i, ndevices;
  104. dev = XIQueryDevice(display, deviceid, &ndevices);
  105. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  106. mask->deviceid = deviceid;
  107. mask->mask_len = XIMaskLen(XI_RawMotion);
  108. mask->mask=memAcquireSimple(mask->mask_len);
  109. memset(mask->mask, 0, mask->mask_len);
  110. XISetMask(mask->mask, XI_RawMotion);
  111. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  112. int FoundMax=0;
  113. for (i = 0; i < dev->num_classes; i++) {
  114. if (dev->classes[i]->type == XIValuatorClass) {
  115. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  116. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  117. }
  118. }
  119. if(!FoundMax){*max_pressure=65535;}
  120. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  121. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  122. XIFreeDeviceInfo(dev);
  123. }
  124. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  125. int axis=0;
  126. for (int i = 0; i < dev->num_classes; i++) {
  127. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  128. }
  129. return axis>=3;
  130. }
  131. #define LA_G_STYLUS(dev) \
  132. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  133. #define LA_G_ERASER \
  134. (!MAIN.WacomDeviceEraser)
  135. void la_ScanWacomDevices(Display *display, int deviceid){
  136. XIDeviceInfo *info, *dev;
  137. int ndevices;
  138. int i; char * word;
  139. int _event, _error;
  140. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  141. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  142. }
  143. info = XIQueryDevice(display, deviceid, &ndevices);
  144. for(i = 0; i < ndevices; i++) {
  145. dev = &info[i]; strToLower(dev->name);
  146. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  147. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  148. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  149. word = strtok (dev->name," ");
  150. while (1) {
  151. word = strtok (NULL, " "); if (!word) break;
  152. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  153. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  154. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  155. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  156. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  157. }
  158. }
  159. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  160. logPrintNew("Found wacom devices:\n");
  161. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  162. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  163. }else{
  164. logPrintNew("No wacom pen device connected.\n");
  165. }
  166. XIFreeDeviceInfo(info);
  167. }
  168. void laHideCursor(){
  169. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  170. }
  171. void laShowCursor(){
  172. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  173. }
  174. void la_XErrorHandler(Display *display, XErrorEvent *event){
  175. char buf[512];
  176. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  177. printf("X Error:\n%s\n",buf);
  178. }
  179. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  180. XSetWindowAttributes swa;
  181. XWindowAttributes wa;
  182. swa.event_mask =
  183. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  184. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  185. swa.colormap = MAIN.cmap;
  186. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  187. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  188. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  189. if(x>0||y>0){
  190. XSizeHints my_hints = {0};
  191. my_hints.flags = PPosition;
  192. my_hints.x = x; my_hints.y = y;
  193. XSetNormalHints(MAIN.dpy, win, &my_hints);
  194. }
  195. XStoreName(MAIN.dpy, win, title);
  196. #ifdef LA_USE_GLES
  197. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  198. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  199. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  200. EGLSurface* surf=egl_surf;
  201. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  202. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  203. tnsContextMakeCurrent((*r_glc),win,(*surf));
  204. #else
  205. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  206. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  207. printf("\n\tcannot create gl context\n\n"); exit(0);
  208. }
  209. tnsContextMakeCurrent((*r_glc),win,0);
  210. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  211. #endif
  212. XSetLocaleModifiers("");
  213. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  214. if(!MAIN.im){
  215. XSetLocaleModifiers("@im=local");
  216. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  217. }
  218. if(!MAIN.im){
  219. XSetLocaleModifiers("@im=none");
  220. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  221. }
  222. if(!MAIN.im){
  223. XSetLocaleModifiers("@im=");
  224. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  225. }
  226. if(!MAIN.im){
  227. logPrint("Can't open a input method.\n");
  228. }
  229. if(MAIN.im){
  230. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  231. XSetICFocus(MAIN.ic);
  232. }
  233. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  234. XSetClassHint(MAIN.dpy, win, &ch);
  235. #define _NET_WM_STATE_ADD 1
  236. if(w<0&&h<0){
  237. XEvent xev;
  238. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  239. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  240. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  241. memset(&xev, 0, sizeof(xev));
  242. xev.type = ClientMessage;
  243. xev.xclient.window = win;
  244. xev.xclient.message_type = wm_state;
  245. xev.xclient.format = 32;
  246. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  247. xev.xclient.data.l[1] = max_horz;
  248. xev.xclient.data.l[2] = max_vert;
  249. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  250. }
  251. return win;
  252. };
  253. void la_DestroySystemWindowX11(laWindow* w) {
  254. tnsContextMakeCurrent(0,0,0);
  255. tnsDeleteContext(w->glc);
  256. #ifdef LA_USE_GLES
  257. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  258. #endif
  259. XDestroyWindow(MAIN.dpy, w->win);
  260. };
  261. #endif //linux
  262. #ifdef _WIN32
  263. #include <msgdef.h>
  264. #include <wintab.h>
  265. #include <wintab_utils.h>
  266. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  267. #define PACKETMODE PK_BUTTONS
  268. #include <pktdef.h>
  269. void la_OpenWacomWinTab(HWND hwnd){
  270. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  271. static LOGCONTEXT glogContext = { 0 };
  272. HCTX hctx = NULL;
  273. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  274. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  275. glogContext.lcOptions |= CXO_SYSTEM;
  276. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  277. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  278. assert(glogContext.lcOptions & CXO_SYSTEM);
  279. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  280. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  281. glogContext.lcPktData = PACKETDATA;
  282. glogContext.lcPktMode = PACKETMODE;
  283. glogContext.lcMoveMask = PACKETDATA;
  284. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  285. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  286. assert(wWTInfoRetVal == sizeof(AXIS));
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  290. if (wWTInfoRetVal) {
  291. assert(wWTInfoRetVal == sizeof(AXIS));
  292. MAIN.WinTabMaxHover = TabletZ.axMax;
  293. }
  294. AXIS tabletPressure = { 0 };
  295. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  296. //glogContext.lcInOrgX = 0;
  297. //glogContext.lcInOrgY = 0;
  298. //glogContext.lcInExtX = TabletX.axMax;
  299. //glogContext.lcInExtY = TabletY.axMax;
  300. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  301. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  312. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  313. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  314. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  315. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  316. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  317. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  318. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  319. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  320. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  321. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  322. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  323. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  324. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  325. if (!hctx)return;
  326. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  327. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  328. }
  329. void laHideCursor() {
  330. if (!MAIN.CurrentWindow) return; //impl
  331. }
  332. void laShowCursor() {
  333. if (!MAIN.CurrentWindow) return; //impl
  334. }
  335. static PIXELFORMATDESCRIPTOR cpfd = {
  336. sizeof(PIXELFORMATDESCRIPTOR),1,
  337. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  338. PFD_TYPE_RGBA,
  339. 8,
  340. 0, 0, 0, 0, 0, 0,
  341. 0, 0, 0,
  342. 0, 0, 0, 0,
  343. 32,
  344. 8, 0,
  345. 0,
  346. 0, 0, 0, 0
  347. };
  348. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  349. int nBestMS = 0;
  350. int i;
  351. int iResults[9];
  352. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  353. WGL_ACCELERATION_ARB, // 1
  354. WGL_DRAW_TO_WINDOW_ARB, // 2
  355. WGL_DOUBLE_BUFFER_ARB, // 3
  356. WGL_PIXEL_TYPE_ARB, // 4
  357. WGL_DEPTH_BITS_ARB, // 5
  358. WGL_STENCIL_BITS_ARB, // 6
  359. WGL_SAMPLE_BUFFERS_ARB, // 7
  360. WGL_SAMPLES_ARB }; // 8
  361. // How many pixelformats are there?
  362. int nFormatCount[] = { 0 };
  363. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  364. if (!wglGetPixelFormatAttribivARB)
  365. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  366. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  367. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  368. for (i = 0; i < nFormatCount[0]; i++){
  369. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  370. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  371. if (iResults[3] == 1) // Double buffered
  372. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  373. if (iResults[5] >= 24) // Any Depth greater than 16
  374. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  375. }
  376. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  377. };
  378. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  379. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  380. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  381. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  382. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  383. 0 };
  384. HGLRC hglrc = 0;
  385. HDC hdc = 0;
  386. int a, b;
  387. hdc = GetDC(hwnd);
  388. la_SetupPxlFormat(hdc, &a, &b);
  389. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  390. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  391. tnsContextMakeCurrent(hglrc, hdc,0);
  392. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  393. wglSwapIntervalEXT(-1);
  394. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  395. };
  396. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  397. HINSTANCE* inst = &MAIN.hinstance;
  398. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  399. x, y, w, h, 0, 0, *inst, 0);
  400. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  401. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  402. return hwnd;
  403. };
  404. void la_DestroySystemWindowWin32(laWindow* w) {
  405. tnsContextMakeCurrent(0,0,0);
  406. tnsDeleteContext(w->glc);
  407. ReleaseDC(w->win, w->hdc);
  408. DestroyWindow(w->win);
  409. };
  410. #endif
  411. #ifdef LAGUI_ANDROID
  412. SYSWINDOW la_CreateWindowAndroid(){
  413. return 0;
  414. };
  415. void laShowCursor(){}
  416. void laHideCursor(){}
  417. #endif
  418. #ifdef LA_LINUX
  419. void la_HandlerSIGSEGV(int sig) {
  420. void *array[30];
  421. size_t sz;
  422. sz = backtrace(array, 30);
  423. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  424. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  425. exit(1);
  426. }
  427. #endif
  428. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  429. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  430. //#ifndef LAGUI_ANDROID
  431. // ignore non-significant error/warning codes
  432. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  433. logPrint("GL %d: %s\n", id, message);
  434. char* strsource="",*strtype="",*strseverity="";
  435. switch (source) {
  436. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  437. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  438. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  439. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  440. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  441. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  442. }
  443. switch (type) {
  444. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  445. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  446. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  447. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  448. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  449. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  450. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  451. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  452. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  453. }
  454. switch (severity) {
  455. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  456. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  457. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  458. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  459. }
  460. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  461. //#endif
  462. }
  463. void la_SetCurrentGLContextDebug(){
  464. //#ifndef LAGUI_ANDROID
  465. int force=MAIN.InitArgs.GLDebug;
  466. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  467. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  468. glDebugMessageCallback(la_glDebugOutput, 0);
  469. int sev=GL_DONT_CARE;
  470. if(!force){
  471. switch(MAIN.GLDebugLevel){
  472. default: sev=GL_DONT_CARE; break;
  473. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  474. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  475. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  476. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  477. }
  478. }
  479. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  480. //#endif
  481. }
  482. void la_NotifyGLDebugChanges(){
  483. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  484. }
  485. void la_SetupWindowGLStates(laWindow* w){
  486. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  487. if(w->GLDebugNeedsUpdate){
  488. tnsContextMakeWindowCurrent(w);
  489. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  490. }
  491. }
  492. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  493. SYSGLCONTEXT glc;
  494. #ifdef LA_LINUX
  495. void* egl_surf=0;
  496. #ifdef LA_USE_GLES
  497. egl_surf=&window->egl_surf;
  498. #endif
  499. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  500. #endif
  501. #ifdef _WIN32
  502. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  503. #endif
  504. #ifdef LAGUI_ANDROID
  505. la_CreateWindowAndroid();
  506. window->win = 1;
  507. window->glc = MAIN.glc;
  508. #else
  509. window->win = hwnd;
  510. window->glc = glc;
  511. #endif
  512. #ifdef _WIN32
  513. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  514. RECT rc; GetClientRect(window->win, &rc);
  515. window->CW = rc.right - rc.left;
  516. window->CH = rc.bottom - rc.top;
  517. #endif
  518. #ifdef LA_LINUX
  519. XWindowAttributes attr;
  520. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  521. window->CW =attr.width;
  522. window->CH = attr.height;
  523. #endif
  524. la_SetCurrentGLContextDebug();
  525. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  526. la_SetupWindowGLStates(window);
  527. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  528. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  529. #else
  530. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #endif
  532. window->OutputShowStripes=1; window->Redraw=1;
  533. window->GLDebugNeedsUpdate=1;
  534. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  535. return 1;
  536. };
  537. int la_DestroySystemWindow(laWindow* wnd){
  538. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  539. nvgDeleteGLES3(wnd->nvg);
  540. #else
  541. nvgDeleteGL3(wnd->nvg);
  542. #endif
  543. #ifdef LA_LINUX
  544. la_DestroySystemWindowX11(wnd);
  545. #endif
  546. #ifdef _WIN32
  547. la_DestroySystemWindowWin32(wnd);
  548. #endif
  549. }
  550. void la_DestroyWindow(laWindow *wnd){
  551. laLayout *l; laPanel *p; if (!wnd) return;
  552. tnsSwitchToCurrentWindowContext(wnd);
  553. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  554. la_StopAllOperators();
  555. strSafeDestroy(&wnd->Title);
  556. //la_PrintUserList(wnd);
  557. //printf("----\n");
  558. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  559. while (l = lstPopItem(&wnd->Layouts)){
  560. laDestroyBlocksRecursive(l->FirstBlock);
  561. //la_PrintUserList(l);
  562. //printf("%x %s\n", l, l->ID->Ptr);
  563. strSafeDestroy(&l->ID);
  564. memFree(l);
  565. //la_PrintUserList(wnd);
  566. //printf("----\n");
  567. }
  568. //printf("----\n%x\n",wnd);
  569. //la_PrintUserList(wnd);
  570. la_DestroySystemWindow(wnd);
  571. lstRemoveItem(&MAIN.Windows, wnd);
  572. memFree(wnd);
  573. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  574. }
  575. void laRenameWindow(laWindow* wnd, char* name){
  576. if((!wnd)||MAIN.IsReadingUDF) return;
  577. strSafeSet(&wnd->Title, name);
  578. if(!wnd->win) return;
  579. #ifdef LA_LINUX
  580. XStoreName(MAIN.dpy, wnd->win, name);
  581. #endif
  582. #ifdef _WIN32
  583. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  584. SetWindowTextW(wnd->win, name);
  585. #endif
  586. }
  587. #ifdef LA_LINUX
  588. const char* la_ConvertCursorID(int id){
  589. switch (id) {
  590. case LA_ARROW: return "arrow";
  591. case LA_CROSS: return "cross";
  592. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  593. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  594. case LA_MOVE: return "diamond_cross";
  595. case LA_HAND: return "hand1";
  596. case LA_CORNER: return "bottom_right_corner";
  597. }
  598. return "arrow";
  599. }
  600. #endif
  601. #ifdef _WIN32
  602. HCURSOR la_ConvertCursorID(int id){
  603. switch (id){
  604. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  605. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  606. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  607. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  608. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  609. case LA_HAND: return LoadCursor(0, IDC_HAND);
  610. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  611. }
  612. return LoadCursor(0, IDC_ARROW);;
  613. }
  614. #endif
  615. void la_InitThreadEnviornment(){
  616. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  617. }
  618. laLogEntry* logEnsure(int Create){
  619. if(!MAIN.Logs.pFirst || Create){
  620. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  621. lstAppendItem(&MAIN.Logs, le);
  622. }
  623. return MAIN.Logs.pLast;
  624. }
  625. void logPrintTV(int Continued, char* format, va_list v){
  626. if(!format || !format[0]) return;
  627. laLogEntry* le=logEnsure(Continued);
  628. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  629. strSafePrintV(&le->Content, format, v);
  630. #ifdef LAGUI_ANDROID
  631. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  632. #endif
  633. laNotifyUsers("la.logs");
  634. }
  635. void logPrintT(int Continued, char* format, ...){
  636. if(!format || !format[0]) return;
  637. laLogEntry* le=logEnsure(Continued);
  638. va_list aptr; va_start(aptr, format);
  639. strSafePrint(&le->Content, format, aptr);
  640. va_end(aptr);
  641. #ifdef LAGUI_ANDROID
  642. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  643. #endif
  644. laNotifyUsers("la.logs");
  645. }
  646. void logPrint(char* format, ...){
  647. va_list aptr; va_start(aptr, format);
  648. logPrintTV(0, format, aptr);
  649. va_end(aptr);
  650. }
  651. void logPrintNew(char* format, ...){
  652. logEnsure(1);
  653. va_list aptr; va_start(aptr, format);
  654. logPrintTV(0, format, aptr);
  655. va_end(aptr);
  656. }
  657. void logClear(){
  658. laLogEntry*l;
  659. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  660. laNotifyUsers("la.logs");
  661. }
  662. 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;
  663. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  664. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  665. }
  666. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  667. strSafeSet(&s->Name,Name);
  668. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  669. s->x=x;s->y=y;s->w=w;s->h=h;
  670. laNotifyUsers("la.user_preferences.screens");
  671. return s;
  672. }
  673. void la_RemoveScreen(laScreen*s){
  674. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  675. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  676. }
  677. void la_RemoveDuplicatedScreenConf(){
  678. laScreen* NextS;
  679. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  680. NextS = s->Item.pNext;
  681. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  682. 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; }
  683. }
  684. }
  685. }
  686. laScreen* laGetWindowScreen(laWindow* w){
  687. int l,r,u,b; int area=-1; laScreen* maxs=0;
  688. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  689. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  690. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  691. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  692. int a=w*h; if(a>area){ maxs = s; area = a; }
  693. }
  694. return maxs;
  695. }
  696. #ifdef LA_LINUX
  697. int la_GetDPI(Window* root_win){
  698. XRRScreenResources *screen;
  699. XRROutputInfo *info;
  700. XRRCrtcInfo *crtc_info;
  701. XRRCrtcInfo *crtc;
  702. int iscres, icrtc, dpi=0;
  703. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  704. for(iscres=0;iscres<screen->noutput;iscres++){
  705. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  706. if(!info->mm_width || !info->mm_height){ continue; }
  707. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  708. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  709. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  710. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  711. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  712. XRRFreeCrtcInfo(crtc);
  713. //if(info->connection==RR_Connected){
  714. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  715. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  716. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  717. // XRRFreeCrtcInfo(crtc_info);
  718. // }
  719. //}
  720. XRRFreeOutputInfo(info);
  721. }
  722. XRRFreeScreenResources(screen);
  723. return dpi;
  724. }
  725. #endif
  726. #ifdef _WIN32
  727. typedef struct laWin32MonitorEnumData {
  728. int id;
  729. }laWin32MonitorEnumData;
  730. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  731. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  732. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  733. return TRUE;
  734. }
  735. int la_GetDPI(HWND win){
  736. laWin32MonitorEnumData data = { 0 };
  737. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  738. return GetDpiForWindow(win);
  739. return 144;
  740. }
  741. #endif
  742. #define PROGRESSW (LA_RH*15)
  743. void laShowProgress(real p1, real p2){
  744. laSpinLock(&MAIN.OpsLock);
  745. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  746. if(!MAIN.Progress.Called){
  747. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  748. }else{
  749. laTimeRecorder tm; laRecordTime(&tm);
  750. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  751. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  752. if(!MAIN.Progress.Shown){
  753. int ww=PROGRESSW+LA_RH*2;
  754. #ifdef LA_LINUX
  755. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  756. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  757. long a=LA_COLOR3_TO_HEX(bg);
  758. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  759. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  760. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  761. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  762. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  763. #endif
  764. #ifdef _WIN32
  765. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  766. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  767. ShowWindow(MAIN.Progress.w,SW_SHOW);
  768. #endif
  769. MAIN.Progress.Shown = 1;
  770. }
  771. }
  772. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  773. #ifdef LA_LINUX
  774. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  775. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  776. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  777. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  778. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  779. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  780. #endif
  781. #ifdef _WIN32
  782. InvalidateRect(MAIN.Progress.w,0,1);
  783. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  784. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  785. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  786. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  787. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  788. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  789. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  790. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  791. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  792. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  793. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  794. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  795. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  796. EndPaint(MAIN.Progress.w,&ps);
  797. MSG msg;
  798. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  799. #endif
  800. laSpinUnlock(&MAIN.OpsLock);
  801. }
  802. void laHideProgress(){
  803. laSpinLock(&MAIN.OpsLock);
  804. if(!MAIN.Progress.Shown){
  805. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  806. }
  807. laTimeRecorder tm; laRecordTime(&tm);
  808. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  809. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  810. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  811. #ifdef LA_LINUX
  812. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  813. #endif
  814. #ifdef _WIN32
  815. ShowWindow(MAIN.Progress.w,SW_HIDE);
  816. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  817. #endif
  818. laSpinUnlock(&MAIN.OpsLock);
  819. }
  820. //=======================
  821. void la_InitProgressWindow(){
  822. #ifdef LA_LINUX
  823. 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));
  824. if(!MAIN.Progress.w) return;
  825. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  826. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  827. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  828. if(MAIN.Progress.gc<0) return;
  829. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  830. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  831. XSync(MAIN.dpy,0);
  832. #endif
  833. #ifdef _WIN32
  834. WNDCLASSW wc;
  835. wc.hInstance = MAIN.hinstance;
  836. wc.lpfnWndProc = LA_ProgressWindowProc;
  837. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  838. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  839. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  840. wc.cbWndExtra = 0;
  841. wc.cbClsExtra = 0;
  842. wc.lpszClassName = L"_LAGUIPROGRESS";
  843. wc.lpszMenuName = NULL;
  844. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  845. if (!RegisterClassW(&wc)){ return; }
  846. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  847. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  848. #endif
  849. }
  850. void laSetFontFolderPath(char* absolute){
  851. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  852. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  853. }
  854. void laSetDefaultInitArguments(laInitArguments* ia){
  855. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  856. ia->UseColorManagement=0;
  857. ia->HasWorldObjects=0;
  858. ia->HasAction=0;
  859. ia->HasTextureInspector=0;
  860. ia->HasHistories=0;
  861. ia->HasTerminal=1;
  862. ia->HasAudio=0;
  863. }
  864. void laSetCompleteInitArguments(laInitArguments* ia){
  865. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  866. ia->UseColorManagement=1;
  867. ia->HasWorldObjects=1;
  868. ia->HasAction=1;
  869. ia->HasTextureInspector=1;
  870. ia->HasHistories=1;
  871. ia->HasTerminal=1;
  872. ia->HasAudio=1;
  873. }
  874. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  875. MAIN.GLMajor=MAIN.GLMinor=-1;
  876. char* arg = 0;
  877. printf("Initializing LaGUI...\n",argc);
  878. for(int i=0;i<argc;i++){
  879. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  880. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  881. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  882. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  883. }
  884. continue;
  885. }
  886. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  887. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  888. }
  889. }
  890. int laGetReadyWith(laInitArguments* ia){
  891. #ifdef LA_LINUX
  892. //signal(SIGSEGV,la_HandlerSIGSEGV);
  893. #endif
  894. laSpinInit(&MAIN.MemLock);
  895. laSpinInit(&MAIN.OpsLock);
  896. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  897. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  898. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  899. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  900. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  901. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  902. tnsInit();
  903. #ifdef LA_LINUX
  904. SYSWINDOW root, win;
  905. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  906. XSetWindowAttributes swa={0};
  907. XWindowAttributes wa={0};
  908. XEvent xev;
  909. logPrintNew("Initializing LaGUI...\n");
  910. setlocale(LC_CTYPE, "zh_CN.utf8");
  911. XSetErrorHandler(la_XErrorHandler);
  912. int i;
  913. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  914. printf("\n\tcannot connect to x server\n\n");
  915. exit(0);
  916. }
  917. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  918. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  919. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  920. #ifdef LA_USE_GLES
  921. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  922. #else
  923. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  924. #endif
  925. #ifdef LA_USE_GLES
  926. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  927. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  928. EGLint egl_major, egl_minor;
  929. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  930. printf("Error: eglInitialize() failed\n"); return -1;
  931. }
  932. int scrnum;
  933. XSetWindowAttributes attr;
  934. XVisualInfo *visInfo, visTemplate;
  935. int num_visuals;
  936. EGLContext ctx;
  937. EGLint num_configs;
  938. EGLint vid;
  939. static const EGLint attribs[] = {
  940. EGL_RED_SIZE, 8,
  941. EGL_GREEN_SIZE, 8,
  942. EGL_BLUE_SIZE, 8,
  943. EGL_DEPTH_SIZE, 1,
  944. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  945. EGL_NONE
  946. };
  947. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  948. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  949. }
  950. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  951. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  952. }
  953. visTemplate.visualid = vid;
  954. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  955. if (!visInfo) {
  956. printf("Error: couldn't get X visual\n"); exit(1);
  957. }
  958. MAIN.xvi=visInfo;
  959. root = DefaultRootWindow(MAIN.dpy);
  960. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  961. printf("\n\tcannot create colormap\n\n"); exit(1);
  962. }
  963. eglBindAPI(EGL_OPENGL_ES_API);
  964. EGLint ctx_attribs[] = {
  965. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  966. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  967. EGL_NONE
  968. };
  969. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  970. if (!MAIN.glc) {
  971. printf("Error: eglCreateContext failed\n"); exit(1);
  972. }
  973. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  974. #else
  975. int visual_attribs[] = {
  976. GLX_X_RENDERABLE , True,
  977. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  978. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  979. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  980. GLX_RED_SIZE , 8,
  981. GLX_GREEN_SIZE , 8,
  982. GLX_BLUE_SIZE , 8,
  983. GLX_ALPHA_SIZE , 8,
  984. GLX_DEPTH_SIZE , 24,
  985. //GLX_STENCIL_SIZE , 8,
  986. GLX_DOUBLEBUFFER , True,
  987. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  988. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  989. None
  990. };
  991. int fbcount = -1;
  992. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  993. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  994. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  995. MAIN.BestFBC = fbconfig[0];
  996. int sample_buf,samples;
  997. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  998. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  999. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1000. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1001. free(fbconfig);
  1002. root = DefaultRootWindow(MAIN.dpy);
  1003. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1004. printf("\n\tcannot create colormap\n\n"); exit(0);
  1005. }
  1006. swa.colormap = MAIN.cmap;
  1007. root = DefaultRootWindow(MAIN.dpy);
  1008. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1009. MAIN.win=win;
  1010. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1011. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1012. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1013. printf("\n\tcannot create gl context\n\n"); exit(0);
  1014. }
  1015. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1016. tnsContextMakeCurrent(MAIN.glc,win,0);
  1017. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1018. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1019. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1020. int err=0;
  1021. if((err=glewInit())!=GLEW_OK){
  1022. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1023. };
  1024. #endif /* gles or glx */
  1025. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1026. la_SetCurrentGLContextDebug();
  1027. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1028. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1029. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1030. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1031. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1032. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1033. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1034. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1035. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1036. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1037. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1038. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1039. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1040. #endif //linux
  1041. #ifdef _WIN32
  1042. logPrintNew("Initializing LaGUI...\n");
  1043. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1044. setlocale(LC_ALL, "zh_CN.utf8");
  1045. MAIN.hinstance = GetModuleHandle(NULL);
  1046. HINSTANCE* hInst = &MAIN.hinstance;
  1047. WNDCLASSEXW wt;
  1048. wt.cbSize = sizeof(WNDCLASSEXW);
  1049. wt.cbClsExtra = 0;
  1050. wt.cbWndExtra = 0;
  1051. wt.hbrBackground = 0;
  1052. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1053. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1054. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1055. wt.hInstance = *hInst;
  1056. wt.lpfnWndProc = LA_WindowProc;
  1057. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1058. wt.lpszMenuName = 0;
  1059. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1060. if (!RegisterClassExW(&wt)) return 0;
  1061. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1062. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1063. SetProcessDPIAware();
  1064. GLenum err;
  1065. PIXELFORMATDESCRIPTOR pfd;
  1066. HINSTANCE* hinst = &MAIN.hinstance;
  1067. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1068. "Temp Window For Accessing GLEW!",
  1069. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1070. 0, 0, *hinst, 0);
  1071. HDC hdc = GetDC(hwnd);
  1072. HGLRC hglrc = 0;
  1073. SetPixelFormat(hdc, 1, &cpfd);
  1074. hglrc = wglCreateContext(hdc);
  1075. tnsContextMakeCurrent(hglrc, hdc,0);
  1076. //MAIN.hdc = hdc;
  1077. // MAIN.tWND = hwnd;
  1078. MAIN.glc = hglrc;
  1079. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1080. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1081. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1082. if (err = glewInit()) {
  1083. printf("Init Glew Failed\n");
  1084. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1085. return 0;
  1086. }
  1087. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1088. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1089. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1090. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1091. #endif
  1092. la_GetWorkingDirectoryInternal();
  1093. MAIN.SavePreferenceOnExit=1;
  1094. MAIN.FontSize = 0.6;
  1095. int dpi=64;
  1096. #ifdef _WIN32
  1097. dpi=la_GetDPI(hwnd);
  1098. #endif
  1099. #ifdef LA_LINUX
  1100. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1101. #endif
  1102. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1103. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1104. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1105. MAIN.UiScale=1;
  1106. MAIN.MarginSize = 1;
  1107. MAIN.ColorPickerGamma=1.5;
  1108. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1109. MAIN.ViewportHalftoneFactor=0.5;
  1110. MAIN.ViewportHalftoneSize=3.7;
  1111. tnsInitRenderKernel(64);
  1112. tnsInitBuiltinShaders();
  1113. tnsSetuptnsFontManager();
  1114. #define LOAD_FONT(font) \
  1115. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1116. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1117. LOAD_FONT("NotoEmoji-Regular.ttf");
  1118. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1119. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1120. //LOAD_FONT("NotoMusic-Regular.ttf");
  1121. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1122. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1123. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1124. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1125. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1126. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1127. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1128. MAIN.Audio=memAcquire(sizeof(laAudio));
  1129. #ifdef LA_WITH_LUAJIT
  1130. // starting lua
  1131. logPrint("Starting luajit...\n");
  1132. MAIN.L = lua_open();
  1133. la_luaLoadLibs(MAIN.L);
  1134. la_luaPrintStatus(MAIN.L);
  1135. tnsLuaInit(MAIN.L);
  1136. #endif
  1137. //interactions:
  1138. MAIN.TopFramerate = 60;
  1139. MAIN.ValuatorThreshold = 8;
  1140. MAIN.ScrollingSpeed = 3;
  1141. MAIN.AnimationSpeed = 0.4;
  1142. MAIN.PanelAnimationSpeed = 0.4;
  1143. MAIN.ZoomSpeed2D = 0.01;
  1144. MAIN.IdleTime = 0.75;
  1145. MAIN.TooltipCloseDistance = 30;
  1146. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1147. //display:
  1148. MAIN.FloatingAlpha = 0.35;
  1149. MAIN.SolidShadowLength = 20;
  1150. MAIN.WireColorSlices = 16;
  1151. MAIN.WireThickness = 5;
  1152. MAIN.WireSaggyness = 0.5;
  1153. #ifdef LAGUI_ANDROID
  1154. laAddResourceFolder("");
  1155. #else
  1156. laAddResourceFolder(".");
  1157. #endif
  1158. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1159. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1160. la_InitProgressWindow();
  1161. la_MakeTranslations_es_ES();
  1162. la_MakeTranslations_zh_hans();
  1163. //tns_RegisterResourcesForSoftwareRender();
  1164. la_RegisterDefaultSignals();
  1165. la_RegisterGeneralProps();
  1166. la_RegisterBuiltinTemplates();
  1167. la_RegisterMainThemes();
  1168. la_RegisterMainOperators();
  1169. la_RegisterMainUiTypes();
  1170. la_RegisterModellingOperators();
  1171. la_RegisterShapeOperators();
  1172. la_RegisterInternalProps();
  1173. la_RegisterAnimationResources();
  1174. la_RegisterWindowKeys();
  1175. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1176. laFinalizeUiTemplates();
  1177. laFinalizeOperators();
  1178. la_RegisterControllerProps();
  1179. la_RefreshControllers();
  1180. la_RegisterBasicNodes();
  1181. tns_RegisterNodes();
  1182. la_InitThreadEnviornment();
  1183. laSetRootInstance(&MAIN);
  1184. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1185. laPushDifferences(0, 0);
  1186. la_MakeDummyManagedUDF();
  1187. la_RegenerateWireColors();
  1188. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1189. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1190. logPrintNew("Initialization Completed\n");
  1191. MAIN.InitDone=1;
  1192. return 1;
  1193. }
  1194. int laGetReady(){
  1195. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1196. return laGetReadyWith(&ia);
  1197. }
  1198. void la_DestroyUiType(laUiType* uit);
  1199. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1200. void laShutoff(int SavePrefereces){
  1201. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1202. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1203. // transLate(pc->Description);
  1204. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1205. // transLate(p->Description);
  1206. // }
  1207. //}
  1208. transDumpMissMatchRecord("TranslationDump.txt");
  1209. if(MAIN.Cleanup) MAIN.Cleanup();
  1210. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1211. strSafeDestroy(&MAIN.WorkingDirectory);
  1212. strSafeDestroy(&MAIN.example_string);
  1213. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1214. // (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. )
  1215. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1216. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1217. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1218. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1219. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1220. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1221. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1222. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1223. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1224. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1225. strSafeDestroy(&MAIN.CopyPending);
  1226. la_ClearUDFRegistryAndFolders();
  1227. laClearManagedUDF();
  1228. laClearSaveProp();
  1229. logClear();
  1230. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1231. #ifdef LA_LINUX
  1232. tnsContextMakeCurrent(0,0,0);
  1233. tnsDeleteContext(MAIN.glc);
  1234. #ifdef LA_USE_GLES
  1235. eglTerminate(MAIN.egl_dpy);
  1236. #endif
  1237. #endif
  1238. #ifdef _WIN32
  1239. tnsContextMakeCurrent(0,0,0);
  1240. tnsDeleteContext(MAIN.glc);
  1241. UnloadWintab();
  1242. #endif
  1243. tnsQuit();
  1244. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1245. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1246. strSafeDump();
  1247. hshFree(&MAIN.DBInstMemLeft);
  1248. memNoLonger();
  1249. laSpinDestroy(&MAIN.MemLock);
  1250. laSpinDestroy(&MAIN.OpsLock);
  1251. #ifdef LA_WITH_LUAJIT
  1252. lua_close(MAIN.L);
  1253. #endif
  1254. printf("LaGUI has cleaned up.\n");
  1255. }
  1256. int laRestoreFactorySettings(){
  1257. char path[1024];
  1258. #ifdef LAGUI_ANDROID
  1259. sprintf(path,"%s","preferences.udf");
  1260. #else
  1261. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1262. #endif
  1263. if(remove(path)){ return 0; }
  1264. return 1;
  1265. }
  1266. void laSaveUserPreferences(){
  1267. char path[1024];
  1268. #ifdef LAGUI_ANDROID
  1269. sprintf(path,"%s","preferences.udf");
  1270. #else
  1271. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1272. #endif
  1273. laUDF* udf=laPrepareUDF(path);
  1274. laWriteProp(udf,"la.windows");
  1275. laWriteProp(udf,"la.user_preferences");
  1276. laWriteProp(udf,"la.input_mapping");
  1277. laWriteProp(udf,"la.controllers");
  1278. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1279. laWriteProp(udf,lip->p);
  1280. }
  1281. laPackUDF(udf,0,0);
  1282. }
  1283. void laEnsureUserPreferences(){
  1284. char path[1024];
  1285. #ifdef LAGUI_ANDROID
  1286. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1287. #else
  1288. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1289. #endif
  1290. laUDFRegistry* r=laFindUDFRegistry(path);
  1291. if(!r){ laSaveUserPreferences(); return; }
  1292. 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; }
  1293. laClearUDFRegistries();
  1294. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1295. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1296. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1297. laCloseUDF(udf);
  1298. la_RemoveDuplicatedScreenConf();
  1299. la_RemoveDuplicatedControllers();
  1300. laRefreshUDFRegistries();
  1301. //restore forced settings
  1302. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1303. }
  1304. void laAddExtraExtension(int FileType, ...){
  1305. va_list list; va_start(list,FileType);
  1306. char* ext;
  1307. while(ext=va_arg(list,char*)){ if(!ext) break;
  1308. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1309. et->FileType=FileType; et->Extension=ext;
  1310. lstAppendItem(&MAIN.ExtraExtensions, et);
  1311. logPrintNew("add ext %s",ext);
  1312. }
  1313. va_end(list);
  1314. }
  1315. void laAddExtraPreferencePath(const char* path){
  1316. if(!path) return;
  1317. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1318. }
  1319. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1320. if(!name || !Func) return;
  1321. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1322. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1323. }
  1324. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1325. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1326. }
  1327. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1328. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1329. }
  1330. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1331. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1332. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1333. }
  1334. void la_InputMappingGetKeyName(int key, int special, char* name){
  1335. char *_next=name; name[0]=0;
  1336. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1337. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1338. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1339. switch(key){
  1340. case ' ': strcat(name,"Space"); break;
  1341. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1342. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1343. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1344. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1345. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1346. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1347. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1348. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1349. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1350. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1351. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1352. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1353. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1354. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1355. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1356. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1357. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1358. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1359. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1360. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1361. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1362. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1363. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1364. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1365. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1366. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1367. case LA_KEY_F1: strcat(name,"F1"); break;
  1368. case LA_KEY_F2: strcat(name,"F2"); break;
  1369. case LA_KEY_F3: strcat(name,"F3"); break;
  1370. case LA_KEY_F4: strcat(name,"F4"); break;
  1371. case LA_KEY_F5: strcat(name,"F5"); break;
  1372. case LA_KEY_F6: strcat(name,"F6"); break;
  1373. case LA_KEY_F7: strcat(name,"F7"); break;
  1374. case LA_KEY_F8: strcat(name,"F8"); break;
  1375. case LA_KEY_F9: strcat(name,"F9"); break;
  1376. case LA_KEY_F10: strcat(name,"F10"); break;
  1377. case LA_KEY_F11: strcat(name,"F11"); break;
  1378. case LA_KEY_F12: strcat(name,"F12"); break;
  1379. default:
  1380. name = name+strlen(name); _next=name;
  1381. laToUTF8(key,name,&_next); *_next=0; break;
  1382. }
  1383. }
  1384. int la_InputMappingGetKeyFromName(char* name, int* special){
  1385. if(!name ||name[0]==0){ *special=0; return 0; }
  1386. *special=0;
  1387. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1388. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1389. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1390. char* p=name+strlen(name)-1;
  1391. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1392. while(*p=='+' || *p==' '){ p++; }
  1393. if(strSame(p,"Space")) return ' ';
  1394. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1395. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1396. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1397. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1398. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1399. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1400. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1401. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1402. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1403. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1404. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1405. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1406. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1407. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1408. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1409. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1410. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1411. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1412. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1413. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1414. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1415. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1416. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1417. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1418. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1419. if(strSame(p,"F1")) return LA_KEY_F1;
  1420. if(strSame(p,"F2")) return LA_KEY_F2;
  1421. if(strSame(p,"F3")) return LA_KEY_F3;
  1422. if(strSame(p,"F4")) return LA_KEY_F4;
  1423. if(strSame(p,"F5")) return LA_KEY_F5;
  1424. if(strSame(p,"F6")) return LA_KEY_F6;
  1425. if(strSame(p,"F7")) return LA_KEY_F7;
  1426. if(strSame(p,"F8")) return LA_KEY_F8;
  1427. if(strSame(p,"F9")) return LA_KEY_F9;
  1428. if(strSame(p,"F10")) return LA_KEY_F10;
  1429. if(strSame(p,"F11")) return LA_KEY_F11;
  1430. if(strSame(p,"F12")) return LA_KEY_F12;
  1431. int adv;
  1432. return laToUnicode(p,&adv);
  1433. }
  1434. laCustomSignal* laFindSignal(char* Name){
  1435. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1436. return 0;
  1437. }
  1438. laCustomSignal* laFindSignalByID(int ID){
  1439. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1440. return 0;
  1441. }
  1442. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1443. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1444. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1445. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1446. char* signal = SSTR(ime->Signal);
  1447. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1448. }
  1449. laInputMapping* laNewInputMapping(char* Name){
  1450. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1451. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1452. strSafeSet(&im->Name,Name);
  1453. return im;
  1454. }
  1455. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1456. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1457. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1458. memAssignRef(e,&e->Parent,im);
  1459. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1460. laInputMappingUpdateSignal(e);
  1461. e->SpecialKeyBits=SpecialKeyBit;
  1462. char buf[64],*_next=buf;
  1463. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1464. }
  1465. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1466. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1467. laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1468. }
  1469. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1470. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1471. }
  1472. void laRemoveInputMapping(laInputMapping* im){
  1473. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1474. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1475. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1476. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1477. }
  1478. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1479. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1480. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1481. return cs;
  1482. }
  1483. void laRemoveCustomSignal(laCustomSignal* cs){
  1484. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1485. }
  1486. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1487. void la_SendSignalsFromEvent(laEvent* e){
  1488. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1489. if(!im){return;}
  1490. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1491. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1492. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1493. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1494. }
  1495. }
  1496. }
  1497. }
  1498. //MSG====================================================
  1499. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1500. if (wnd->win == hwnd) return 1;
  1501. else return 0;
  1502. };
  1503. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1504. if (p->SL){ int s=p->SL<0?0:p->SL;
  1505. if (p->TX != s) laRecalcPanel(p);
  1506. p->TX = s;
  1507. }
  1508. if (p->SR){ int s=p->SR<0?0:p->SR;
  1509. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1510. p->TW = CW - p->TX - s;
  1511. }
  1512. if (p->ST){ int s=p->ST<0?0:p->ST;
  1513. if (p->TY != s) laRecalcPanel(p);
  1514. p->TY = s;
  1515. }
  1516. if (p->SB){ int s=p->SB<0?0:p->SB;
  1517. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1518. p->TH = CH - p->TY - s;
  1519. }
  1520. }
  1521. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1522. laPanel *p = 0;
  1523. b->X = X;
  1524. b->Y = Y;
  1525. b->W = W;
  1526. b->H = H;
  1527. if (b->B1){
  1528. int SplitWidth;
  1529. if (b->Vertical){
  1530. SplitWidth = H * b->SplitRatio;
  1531. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1532. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1533. }else{
  1534. SplitWidth = W * b->SplitRatio;
  1535. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1536. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1537. }
  1538. }
  1539. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1540. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1541. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1542. }
  1543. if (p = b->CurrentPanel){
  1544. int TitleGap=b->Folded?0:LA_RH;
  1545. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1546. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1547. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1548. laRecalcPanel(p);
  1549. }
  1550. }
  1551. void la_UpdateUiPlacement(laWindow *w){
  1552. laLayout *l;
  1553. laPanel *p;
  1554. int CW = w->CW;
  1555. int CH = w->CH;
  1556. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1557. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1558. if(w->MaximizedUi && w->MaximizedUiPanel){
  1559. laRecalcPanel(w->MaximizedUiPanel);
  1560. }elif(w->MaximizedBlock){
  1561. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1562. }else{
  1563. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1564. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1565. }
  1566. }
  1567. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1568. if(p->IsMenuPanel){
  1569. p->TH=p->H=MenuHeight;
  1570. }
  1571. la_EnsurePanelSnapping(p, CW, CH);
  1572. laRecalcPanel(p);
  1573. }
  1574. }
  1575. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1576. laWindow *window;
  1577. #ifdef LAGUI_ANDROID
  1578. window = MAIN.Windows.pFirst; if (!window) return;
  1579. window->X=x;window->Y=y;window->W=w;window->H=h;
  1580. window->CW=w;window->CH=h;
  1581. la_UpdateUiPlacement(window); return;
  1582. #endif
  1583. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1584. if (!window) return;
  1585. #ifdef _WIN32
  1586. RECT rcc; GetClientRect(window->win, &rcc);
  1587. RECT rcw; GetWindowRect(window->win, &rcw);
  1588. window->CW = rcc.right - rcc.left;
  1589. window->CH = rcc.bottom - rcc.top;
  1590. window->W = rcw.right - rcw.left;
  1591. window->H = rcw.bottom - rcw.top;
  1592. window->X = rcw.left; window->Y = rcw.top;
  1593. if (MAIN.AutoSwitchColorSpace) {
  1594. laScreen* s = laGetWindowScreen(window);
  1595. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1596. }
  1597. #endif
  1598. #ifdef LA_LINUX
  1599. XWindowAttributes attr;
  1600. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1601. window->CW = w; window->CH = h;
  1602. window->W = w; window->H = h;
  1603. window->X = x; window->Y = y;
  1604. if(MAIN.AutoSwitchColorSpace){
  1605. laScreen* s = laGetWindowScreen(window);
  1606. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1607. }
  1608. #endif
  1609. la_UpdateUiPlacement(window);
  1610. }
  1611. int la_OnWindowDestroy(SYSWINDOW wnd){
  1612. laListHandle *hlst = &MAIN.Windows;
  1613. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1614. if (!w) return 0;
  1615. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1616. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1617. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1618. laShutoff(1);
  1619. return 1;
  1620. }
  1621. laListHandle h={0};laLayout*l=0;
  1622. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1623. la_DestroyWindow(w);
  1624. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1625. #ifdef LA_LINUX
  1626. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1627. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1628. #endif
  1629. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1630. }
  1631. return 0;
  1632. }
  1633. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1634. laListHandle *el = &wnd->EventList;
  1635. laEvent* last_e=el->pLast;
  1636. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1637. #ifdef LA_LINUX
  1638. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1639. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1640. #endif
  1641. #ifdef _WIN32
  1642. 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);
  1643. #endif
  1644. }
  1645. void laMappingRequestEval();
  1646. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1647. laListHandle *wl = &MAIN.Windows;
  1648. laWindow* wnd;
  1649. #ifdef LAGUI_ANDROID
  1650. wnd = MAIN.Windows.pFirst;
  1651. #else
  1652. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1653. #endif
  1654. if (!wnd){ memFree(e); return; }
  1655. laListHandle *el = &wnd->EventList;
  1656. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1657. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1658. e->window = wnd;
  1659. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1660. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1661. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1662. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1663. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1664. e->GoodPressure=MAIN.IsPen;
  1665. lstAppendItem(el, (laListItem *)e);
  1666. laMappingRequestEval();
  1667. };
  1668. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1669. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1670. la_SaveEvent(hwnd, e, 1);
  1671. };
  1672. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1673. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1674. e->type = LA_INPUT; e->Input=Input;
  1675. la_SaveEvent(hwnd, e, 1);
  1676. }
  1677. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1678. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1679. e->type = LA_EMPTY;
  1680. la_SaveEvent(hwnd, e, 1);
  1681. }
  1682. void laSendOperatorTriggerEvent(){
  1683. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1684. MAIN.ReTriggerOperators = 0;
  1685. }
  1686. int la_TranslateSpecialKey(int keysym){
  1687. #ifdef LA_LINUX
  1688. switch(keysym){
  1689. case XK_Return: return LA_KEY_ENTER;
  1690. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1691. case XK_Delete: return LA_KEY_DELETE;
  1692. case XK_Escape: return LA_KEY_ESCAPE;
  1693. case XK_Tab: return LA_KEY_TAB;
  1694. case XK_Left: return LA_KEY_ARRLEFT;
  1695. case XK_Right: return LA_KEY_ARRRIGHT;
  1696. case XK_Up: return LA_KEY_ARRUP;
  1697. case XK_Down: return LA_KEY_ARRDOWN;
  1698. case XK_Control_L: return LA_KEY_CTRL;
  1699. case XK_Control_R: return LA_KEY_CTRL;
  1700. case XK_Shift_L: return LA_KEY_SHIFT;
  1701. case XK_Shift_R: return LA_KEY_SHIFT;
  1702. case XK_Alt_L: return LA_KEY_ALT;
  1703. case XK_Alt_R: return LA_KEY_ALT;
  1704. case XK_KP_1: return LA_KEY_NUM1;
  1705. case XK_KP_2: return LA_KEY_NUM2;
  1706. case XK_KP_3: return LA_KEY_NUM3;
  1707. case XK_KP_4: return LA_KEY_NUM4;
  1708. case XK_KP_5: return LA_KEY_NUM5;
  1709. case XK_KP_6: return LA_KEY_NUM6;
  1710. case XK_KP_7: return LA_KEY_NUM7;
  1711. case XK_KP_8: return LA_KEY_NUM8;
  1712. case XK_KP_9: return LA_KEY_NUM9;
  1713. case XK_KP_0: return LA_KEY_NUM0;
  1714. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1715. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1716. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1717. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1718. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1719. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1720. default: return keysym;
  1721. }
  1722. #endif
  1723. #ifdef _WIN32
  1724. switch (keysym) {
  1725. case VK_RETURN: return LA_KEY_ENTER;
  1726. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1727. case VK_TAB: return LA_KEY_TAB;
  1728. case VK_LEFT: return LA_KEY_ARRLEFT;
  1729. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1730. case VK_UP: return LA_KEY_ARRUP;
  1731. case VK_DOWN: return LA_KEY_ARRDOWN;
  1732. case VK_CONTROL: return LA_KEY_CTRL;
  1733. case VK_SHIFT: return LA_KEY_SHIFT;
  1734. case VK_MENU: return LA_KEY_ALT;
  1735. case VK_F1: return LA_KEY_F1;
  1736. case VK_F2: return LA_KEY_F2;
  1737. case VK_F3: return LA_KEY_F3;
  1738. case VK_F4: return LA_KEY_F4;
  1739. case VK_F5: return LA_KEY_F5;
  1740. case VK_F6: return LA_KEY_F6;
  1741. case VK_F7: return LA_KEY_F7;
  1742. case VK_F8: return LA_KEY_F8;
  1743. case VK_F9: return LA_KEY_F9;
  1744. case VK_F10: return LA_KEY_F10;
  1745. case VK_F11: return LA_KEY_F11;
  1746. case VK_F12: return LA_KEY_F12;
  1747. case VK_NUMPAD0: return LA_KEY_NUM0;
  1748. case VK_NUMPAD1: return LA_KEY_NUM1;
  1749. case VK_NUMPAD2: return LA_KEY_NUM2;
  1750. case VK_NUMPAD3: return LA_KEY_NUM3;
  1751. case VK_NUMPAD4: return LA_KEY_NUM4;
  1752. case VK_NUMPAD5: return LA_KEY_NUM5;
  1753. case VK_NUMPAD6: return LA_KEY_NUM6;
  1754. case VK_NUMPAD7: return LA_KEY_NUM7;
  1755. case VK_NUMPAD8: return LA_KEY_NUM8;
  1756. case VK_NUMPAD9: return LA_KEY_NUM9;
  1757. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1758. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1759. case VK_ADD: return LA_KEY_NUMPLUS;
  1760. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1761. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1762. case VK_OEM_1: return ';';
  1763. case VK_OEM_2: return '/';
  1764. case VK_OEM_3: return '`';
  1765. case VK_OEM_4: return '[';
  1766. case VK_OEM_5: return '\\';
  1767. case VK_OEM_6: return ']';
  1768. case VK_OEM_7: return '\'';
  1769. case VK_OEM_COMMA: return ',';
  1770. case VK_OEM_PERIOD: return '.';
  1771. case VK_OEM_PLUS: return '+';
  1772. case VK_OEM_MINUS: return '-';
  1773. default: return keysym;
  1774. }
  1775. #endif
  1776. }
  1777. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1778. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1779. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1780. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1781. // la_SaveEvent(hwnd, e, 0);
  1782. //}
  1783. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1784. e->type = type; e->x = x; e->y = y;
  1785. la_SaveEvent(hwnd, e, 0);
  1786. MAIN.evLastX=x; MAIN.evLastY=y;
  1787. };
  1788. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1789. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1790. e->type = type;
  1791. la_SaveEvent(hwnd, e, 1);
  1792. };
  1793. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1794. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1795. e->type = LA_SIGNAL_EVENT;
  1796. e->key = signal;
  1797. la_SaveEvent(hwnd, e, 1);
  1798. };
  1799. void laRetriggerOperators(){
  1800. MAIN.ReTriggerOperators = 1;
  1801. }
  1802. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1803. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1804. }
  1805. void laSetCleanupCallback(laCleanupF Cleanup){
  1806. MAIN.Cleanup=Cleanup;
  1807. }
  1808. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1809. MAIN.InputProcess=InputProcess;
  1810. }
  1811. //====================================================================================================
  1812. void la_DestroyTheme(laTheme* t){
  1813. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1814. strSafeDestroy(&t->Name);
  1815. strSafeDestroy(&t->Author);
  1816. }
  1817. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1818. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1819. strSafeSet(&t->Name, Name);
  1820. strSafeSet(&t->Author, AuthorName);
  1821. lstAppendItem(&MAIN.Themes, t);
  1822. MAIN.CurrentTheme = t;
  1823. return t;
  1824. }
  1825. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1826. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1827. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1828. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1829. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1830. strSafeSet(&bt->Name, Name);
  1831. bt->NormalY=NormalY;
  1832. bt->ActiveY=ActiveY;
  1833. bt->BorderY=BorderY;
  1834. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1835. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1836. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1837. bt->BackRef = BackRef;
  1838. lstAppendItem(&t->BoxedThemes, bt);
  1839. return bt;
  1840. }
  1841. laTheme *laGetTheme(const char *ThemeName){
  1842. laTheme *t = MAIN.Themes.pFirst;
  1843. for (t; t; t = t->Item.pNext){
  1844. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1845. }
  1846. return 0;
  1847. }
  1848. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1849. laTheme *t = MAIN.Themes.pFirst;
  1850. for (t; t; t = t->Item.pNext){
  1851. laBoxedTheme *bt;
  1852. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1853. bt = t->BoxedThemes.pFirst;
  1854. for (bt; bt; bt = bt->Item.pNext){
  1855. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1856. }
  1857. }
  1858. return 0;
  1859. }
  1860. real* laThemeColor(laBoxedTheme* bt, int which){
  1861. switch(which){
  1862. default:
  1863. case LA_BT_NORMAL: return bt->Normal;
  1864. case LA_UI_EDITING:
  1865. case LA_BT_ACTIVE: return bt->Active;
  1866. case LA_BT_BORDER: return bt->Border;
  1867. case LA_BT_TEXT: return bt->Text; break;
  1868. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1869. case LA_BT_DISABLED: return bt->Inactive; break;
  1870. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1871. }
  1872. return bt->Normal;
  1873. }
  1874. real* laAccentColor(int which){
  1875. switch(which){
  1876. default:
  1877. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1878. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1879. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1880. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1881. case LA_BT_FACE:
  1882. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1883. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1884. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1885. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1886. case LA_BT_SHADOW: return MAIN.CurrentTheme->ShadowColor;
  1887. }
  1888. return MAIN.CurrentTheme->SelectionColor;
  1889. }
  1890. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1891. real hcy[3];
  1892. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1893. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1894. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1895. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1896. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1897. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1898. int *tm=&bt->LM,*tp=&bt->LP;
  1899. for(int i=0;i<4;i++){
  1900. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1901. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1902. }
  1903. }
  1904. void la_RefreshThemeColorSelf(laTheme* th){
  1905. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1906. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1907. real hcy[3], usehcy[3];
  1908. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1909. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1910. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1911. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1912. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1913. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1914. tnsVectorCopy3d(th->Color, th->ShadowColor); th->ShadowColor[3]=th->CursorAlpha;
  1915. }
  1916. void la_RefreshThemeColor(laTheme* th){
  1917. real hcy[3], usehcy[3], normalhcy[3];
  1918. tnsRGB2HCY(th->Color,hcy);
  1919. la_RefreshThemeColorSelf(th);
  1920. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1921. la_RefreshBoxedThemeColor(bt);
  1922. (*bt->BackRef) = bt;
  1923. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1924. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1925. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1926. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1927. }
  1928. }
  1929. //I FUCKING HATE THIS STUPID FUNCTION
  1930. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1931. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1932. laUiListDrawItem *last = uild->Items.pFirst;
  1933. int LimW=_R-_L;
  1934. int SL, SR, SU, SB;
  1935. int Target__B = Target->B;
  1936. int Target__R = Target->R;
  1937. uildi->Target = Target;
  1938. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1939. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1940. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1941. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1942. uildi->L = last ? Target->L - last->XP : Target->L;
  1943. uildi->R = last ? Target__R - last->XP : Target__R;
  1944. uildi->U = last ? Target->U - last->YP : Target->U;
  1945. uildi->B = last ? Target__B - last->YP : Target__B;
  1946. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1947. uildi->L -= GlobalX;
  1948. uildi->R -= GlobalX;
  1949. uildi->U -= GlobalY;
  1950. uildi->B -= GlobalY;
  1951. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1952. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1953. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1954. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1955. uildi->DifX = SL - uildi->L;
  1956. uildi->DifY = SU - uildi->U;
  1957. uildi->L = SL;
  1958. uildi->R = SR+uildi->DifX;
  1959. uildi->U = SU;
  1960. uildi->B = SB;//+uildi->DifY;
  1961. if(uildi->R>_R){ uildi->R=_R; }
  1962. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1963. //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);
  1964. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1965. memFree(uildi);
  1966. return 0;
  1967. }
  1968. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  1969. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  1970. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  1971. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  1972. Target->U + Target->PanY + uildi->DifY+1,
  1973. -100, 100);
  1974. lstPushItem(&uild->Items, uildi);
  1975. return 1;
  1976. }
  1977. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1978. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1979. laUiListDrawItem *last = uild->Items.pFirst;
  1980. int SL, SR, SU, SB;
  1981. if (B - U > LimH) B = U + LimH;
  1982. uildi->XP = last ? last->XP + PanX : PanX;
  1983. uildi->YP = last ? last->YP + PanY : PanY;
  1984. uildi->L = last ? L - last->XP : L;
  1985. uildi->R = last ? R - last->XP : R;
  1986. uildi->U = last ? U - last->YP : U;
  1987. uildi->B = last ? B - last->YP : B;
  1988. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1989. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1990. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1991. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1992. uildi->DifX = SL - uildi->L;
  1993. uildi->DifY = SU - uildi->U;
  1994. uildi->L = SL;
  1995. uildi->R = SR;
  1996. uildi->U = SU;
  1997. uildi->B = SB;
  1998. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1999. tnsOrtho(L + PanX + uildi->DifX,
  2000. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  2001. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2002. U + PanY + uildi->DifY,
  2003. -100, 100);
  2004. lstPushItem(&uild->Items, uildi);
  2005. }
  2006. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2007. int* savel, int* saver, int* saveu, int* saveb){
  2008. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2009. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2010. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2011. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2012. real x,y,w,h;
  2013. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2014. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2015. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2016. }
  2017. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2018. laUiListDrawItem *uildi = uild->Items.pFirst;
  2019. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2020. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2021. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2022. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2023. Target->U + Target->PanY + uildi->DifY -1,
  2024. -100, 100);
  2025. }
  2026. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2027. laUiListDrawItem *uildi = lstPopItem(uild);
  2028. laUiList *Target;
  2029. memFree(uildi);
  2030. uildi = uild->Items.pFirst;
  2031. if (!uildi || !uildi->Target){
  2032. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2033. return;
  2034. }
  2035. Target = uildi->Target;
  2036. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2037. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2038. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2039. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2040. Target->U + Target->PanY + uildi->DifY -1,
  2041. -100, 100);
  2042. }
  2043. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2044. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2045. uildi->L = L;
  2046. uildi->R = R;
  2047. uildi->U = U;
  2048. uildi->B = B;
  2049. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2050. tnsOrtho(L, R, B, U, -100, 100);
  2051. lstPushItem(&uild->Items, uildi);
  2052. }
  2053. void la_ClearUiListMatrix(laUiListDraw *uild){
  2054. laUiListDrawItem *uildi;
  2055. while (uildi = lstPopItem(uild)){
  2056. memFree(uildi);
  2057. }
  2058. }
  2059. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2060. 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);
  2061. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2062. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2063. int la_TestUiListMinumWidth(laUiList *uil);
  2064. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2065. if (ui){
  2066. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2067. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2068. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2069. p->X = p->TX; p->Y = p->TY;
  2070. p->W = p->TW;
  2071. }
  2072. }
  2073. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2074. int cw = MAIN.CurrentWindow->CW;
  2075. int ch = MAIN.CurrentWindow->CH;
  2076. int PH = p->TH;
  2077. laBoxedTheme*bt = *p->BT;
  2078. int uih=uil->B + bt->BM;
  2079. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2080. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2081. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2082. else p->TH = PH;
  2083. p->H = p->TH;
  2084. if(p->BoundUi){
  2085. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2086. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2087. if (p->X < 0) p->X = 0;
  2088. if (p->Y < 0) p->Y = 0;
  2089. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2090. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2091. }else{
  2092. if (p->Y < 0) p->Y = 0;
  2093. if ((!p->Block)&&(!p->IsMenuPanel)){
  2094. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2095. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2096. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2097. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2098. }
  2099. }
  2100. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2101. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2102. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2103. }
  2104. if (p->ST) p->TY = p->ST;
  2105. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2106. if (p->SB) p->TH = ch - p->TY - p->SB;
  2107. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2108. p->TX = p->X; p->TY = p->Y;
  2109. p->TW = p->W; p->TH = p->H;
  2110. }
  2111. void laPlacePanelForCreation(laPanel *p){
  2112. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2113. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2114. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2115. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2116. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2117. p->TX=p->X; p->TY=p->Y;
  2118. }
  2119. }
  2120. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2121. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2122. tnsViewportWithScissor(0, 0, p->W, p->H);
  2123. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2124. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2125. }
  2126. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2127. tnsDrawToScreen();
  2128. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2129. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2130. }
  2131. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2132. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2133. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2134. }
  2135. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2136. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2137. tnsClearAll();
  2138. }
  2139. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2140. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2141. real Color[] = {1, 1, 1, 1};
  2142. real L, W, U, H;
  2143. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2144. if(MAIN.EnableColorManagement){
  2145. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2146. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2147. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2148. }else{
  2149. tnsUniformOutputColorSpace(T->immShader,0);
  2150. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2151. tnsUniformColorComposing(T->immShader,0,0,0);
  2152. }
  2153. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2154. tnsUseNoTexture();
  2155. if (!p->IsMenuPanel){
  2156. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2157. }
  2158. tnsFlush();
  2159. }
  2160. if(p->ParentOperator){
  2161. tnsUseNoTexture();
  2162. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2163. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2164. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2165. }
  2166. switch (p->AnimationMode){
  2167. case 0: /* and */
  2168. case LA_PANEL_ANIMATION_FLASH:
  2169. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2170. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2171. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2172. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2173. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2174. tnsPackAs(GL_TRIANGLES);
  2175. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2176. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2177. }
  2178. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2179. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2180. if((int)(p->AnimationRatio*6)%2){
  2181. tnsUseNoTexture();
  2182. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2183. 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);
  2184. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2185. }
  2186. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2187. }
  2188. break;
  2189. case LA_PANEL_ANIMATION_DROP_DOWN:
  2190. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2191. tnsDraw2DTextureArg(
  2192. p->OffScr->pColor[0],
  2193. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2194. Color,
  2195. 0, 0, 1 - p->AnimationRatio, 0);
  2196. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2197. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2198. break;
  2199. case LA_PANEL_ANIMATION_EXPAND:
  2200. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2201. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2202. W = tnsLinearItp(0, p->W, 0.4);
  2203. H = tnsLinearItp(0, p->H, 0.4);
  2204. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2205. tnsDraw2DTextureArg(
  2206. p->OffScr->pColor[0],
  2207. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2208. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2209. Color,
  2210. 0, 0, 0, 0);
  2211. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2212. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2213. break;
  2214. case LA_PANEL_ANIMATION_DISSOVE:
  2215. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2216. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2217. W = tnsLinearItp(0, p->W, 1.4);
  2218. H = tnsLinearItp(0, p->H, 1.4);
  2219. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2220. if (p->OffScr) tnsDraw2DTextureArg(
  2221. p->OffScr->pColor[0],
  2222. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2223. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2224. Color,
  2225. 0, 0, 0, 0);
  2226. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2227. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2228. break;
  2229. case LA_PANEL_ANIMATION_COLLAPSE:
  2230. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2231. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2232. W = tnsLinearItp(0, p->W, 0.4);
  2233. H = tnsLinearItp(0, p->H, 0.4);
  2234. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2235. if (p->OffScr) tnsDraw2DTextureArg(
  2236. p->OffScr->pColor[0],
  2237. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2238. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2239. Color,
  2240. 0, 0, 0, 0);
  2241. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2242. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2243. break;
  2244. case LA_PANEL_ANIMATION_MINIMIZE:
  2245. L = tnsLinearItp(0, p->X, 0.3);
  2246. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2247. W = tnsLinearItp(0, p->W, 0.4);
  2248. H = tnsLinearItp(0, p->H, 0.4);
  2249. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2250. tnsDraw2DTextureArg(
  2251. p->OffScr->pColor[0],
  2252. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2253. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2254. Color,
  2255. 0, 0, 0, 0);
  2256. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2257. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2258. break;
  2259. }
  2260. tnsFlush();
  2261. tnsUniformOutputColorSpace(T->immShader,0);
  2262. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2263. tnsUniformColorComposing(T->immShader,0,0,0);
  2264. }
  2265. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2266. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2267. else{
  2268. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:LA_PANEL_DEFAULT_GL_FORMAT;
  2269. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2270. }
  2271. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2272. }
  2273. void la_PanelRefreshDetachedProp(laPanel *panel){
  2274. laProp *p;
  2275. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2276. la_StepPropPack(&p->DetachedPP);
  2277. la_UsePropPack(&p->DetachedPP, 0);
  2278. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2279. // laUseDataBlock(
  2280. // p->DetachedPP.LastPs->UseInstance,
  2281. // p->DetachedPP.LastPs->p,
  2282. // MAIN.PropMatcherContextP->FrameDistinguish,
  2283. // MAIN.PropMatcherContextP,
  2284. // la_PropPanelUserRemover, 0);
  2285. //}
  2286. }
  2287. }
  2288. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2289. real* color=laThemeColor(bt,LA_BT_BORDER);
  2290. tnsColor4d(0,0,0,Alpha);
  2291. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2292. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2293. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2294. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2295. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2296. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2297. tnsPackAs(GL_TRIANGLE_STRIP);
  2298. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2299. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2300. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2301. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2302. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2303. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2304. }
  2305. int la_AnimateUiListRecursive(laUiList *uil);
  2306. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2307. int DrawState_ = 0;
  2308. laUiListDraw uild = {0};
  2309. if (p->Show){
  2310. la_SetPropMathcerContext(p);
  2311. MAIN.CurrentPanel = p;
  2312. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2313. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2314. //}
  2315. if (p->Refresh & LA_TAG_RECALC){
  2316. laRecalcPanelImmediate(p);
  2317. }
  2318. if (!p->MenuRefer){
  2319. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2320. if (p->Refresh || !p->OffScr){
  2321. la_PanelDrawToOffsceen(p, &p->UI);
  2322. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2323. la_PanelBackgroundInit(p, bt);
  2324. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2325. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2326. tnsFlush();
  2327. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2328. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2329. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2330. DrawState_++;
  2331. }
  2332. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2333. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2334. if(p->UI.PanY<0){p->UI.PanY=0;}
  2335. DrawState_++;
  2336. }
  2337. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2338. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2339. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2340. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2341. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2342. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2343. if(p!=w->MaximizedUiPanel){
  2344. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2345. }else{
  2346. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2347. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2348. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2349. tnsFlush();
  2350. }
  2351. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2352. }
  2353. }else{
  2354. if (p->Refresh || !p->OffScr){
  2355. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2356. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2357. la_PanelBackgroundInit(p, bt);
  2358. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2359. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2360. tnsFlush();
  2361. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2362. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2363. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2364. DrawState_++;
  2365. }
  2366. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2367. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2368. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2369. DrawState_++;
  2370. }
  2371. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2372. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2373. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2374. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2375. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2376. }
  2377. }
  2378. tnsDrawToScreen();
  2379. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2380. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2381. la_PanelDrawToWindow(p, w);
  2382. }elif (p->AnimationMode){
  2383. la_PanelDrawToWindow(p, w);
  2384. }
  2385. }
  2386. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2387. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2388. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2389. laPanel *pi, *PrevPI;
  2390. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2391. PrevPI = pi->Item.pPrev;
  2392. if (pi->AnimationMode && pi->LaterDestroy){
  2393. lstRemoveItem(&p->SubPanels, pi);
  2394. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2395. continue;
  2396. }
  2397. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2398. la_AttachedPanelDefDraw(w,pi,bt);
  2399. }
  2400. }
  2401. }
  2402. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2403. real PanelSquare[] = {
  2404. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2405. b->X + 2, CH - (b->Y + b->H - 4),
  2406. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2407. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2408. real Center[] = {
  2409. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2410. real DraggingPlot[] = {
  2411. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2412. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2413. PanelSquare[0],
  2414. PanelSquare[1],
  2415. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2416. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2417. PanelSquare[2],
  2418. PanelSquare[3],
  2419. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2420. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2421. PanelSquare[4],
  2422. PanelSquare[5],
  2423. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2424. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2425. PanelSquare[6],
  2426. PanelSquare[7],
  2427. };
  2428. real Square[] = {
  2429. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2430. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2431. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2432. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2433. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2434. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2435. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2436. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2437. };
  2438. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2439. LA_COLOR3(BorderColor4dV), 0,
  2440. 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. };
  2447. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2448. LA_COLOR3(FillColor4dv), 0,
  2449. 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. };
  2456. tnsUseNoTexture();
  2457. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2458. int Index[4];
  2459. tnsVertexArray2d(DraggingPlot, 8);
  2460. tnsColorArray4d(FillColor, 8);
  2461. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2462. case 0:
  2463. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2464. break;
  2465. case LA_BLOCK_DROP_LOCATION_L:
  2466. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2467. break;
  2468. case LA_BLOCK_DROP_LOCATION_R:
  2469. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2470. break;
  2471. case LA_BLOCK_DROP_LOCATION_U:
  2472. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2473. break;
  2474. case LA_BLOCK_DROP_LOCATION_B:
  2475. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2476. break;
  2477. }
  2478. //glDisable(GL_CULL_FACE);
  2479. tnsIndexArray(Index, 4);
  2480. tnsPackAs(GL_TRIANGLE_FAN);
  2481. //tnsFlush();
  2482. }
  2483. tnsVertexArray2d(DraggingPlot, 8);
  2484. tnsColorArray4d(PlotColor, 8);
  2485. tnsPackAs(GL_LINES);
  2486. tnsVertexArray2d(Square, 4);
  2487. tnsColor4dv(BorderColor4dV);
  2488. tnsPackAs(GL_LINE_LOOP);
  2489. glLineWidth(LA_SEAM_W);
  2490. tnsFlush();
  2491. glLineWidth(1);
  2492. }
  2493. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2494. laBoxedTheme *bt = _LA_THEME_TAB;
  2495. laPanel *p;
  2496. real v[] = {
  2497. b->X, CH - b->Y,
  2498. b->X + LA_SEAM_W, CH - b->Y ,
  2499. b->X, CH - (b->Y + b->H),
  2500. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2501. b->X + b->W, CH - (b->Y + b->H),
  2502. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2503. b->X + b->W, CH - b->Y,
  2504. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2505. real tv[8];
  2506. real ratio = 1.0001f;
  2507. int tw = 0;
  2508. int L = LA_RH+LA_SEAM_W;
  2509. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2510. if(MAIN.EnableColorManagement){
  2511. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2512. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2513. }else{
  2514. tnsUniformOutputColorSpace(T->immShader,0);
  2515. tnsUniformColorComposing(T->immShader,0,0,0);
  2516. }
  2517. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2518. tw += p->TitleWidth + LA_SEAM_W*2;
  2519. }
  2520. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2521. tnsUseNoTexture();
  2522. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2523. tnsVertexArray2d(v, 8);
  2524. tnsPackAs(GL_TRIANGLE_STRIP);
  2525. int TitleGap=b->Folded?0:LA_RH;
  2526. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2527. b->X + b->W, (CH - b->Y),
  2528. b->X + b->W, (CH - b->Y - TitleGap),
  2529. b->X, (CH - b->Y - TitleGap));
  2530. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2531. tnsVertexArray2d(tv, 4);
  2532. tnsPackAs(GL_TRIANGLE_FAN);
  2533. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2534. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2535. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2536. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2537. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2538. tnsVertexArray2d(tv, 4);
  2539. tnsPackAs(GL_TRIANGLE_FAN);
  2540. if(b->Folded){
  2541. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2542. 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);
  2543. 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);
  2544. tnsFlush(); return;
  2545. }
  2546. int LT=0,RT=0;
  2547. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2548. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2549. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2550. b->X + L+RT * ratio, (CH - b->Y),
  2551. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2552. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2553. if (p == b->CurrentPanel){
  2554. tnsUseNoTexture();
  2555. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2556. tnsVertexArray2d(tv, 4);
  2557. tnsPackAs(GL_TRIANGLE_FAN);
  2558. 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);
  2559. }else{
  2560. 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);
  2561. }
  2562. LT =RT;
  2563. }
  2564. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2565. tnsFlush();
  2566. tnsUniformOutputColorSpace(T->immShader,0);
  2567. tnsUniformColorComposing(T->immShader,0,0,0);
  2568. }
  2569. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2570. laBoxedTheme *bt = _LA_THEME_PANEL;
  2571. real tv[8];
  2572. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2573. if(MAIN.EnableColorManagement){
  2574. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2575. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2576. }else{
  2577. tnsUniformOutputColorSpace(T->immShader,0);
  2578. tnsUniformColorComposing(T->immShader,0,0,0);
  2579. }
  2580. tnsUseNoTexture();
  2581. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2582. b->X + b->W, (CH - b->Y),
  2583. b->X + b->W, (CH - b->Y-b->H),
  2584. b->X, (CH - b->Y-b->H));
  2585. tnsVertexArray2d(tv, 4);
  2586. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2587. tnsPackAs(GL_TRIANGLE_FAN);
  2588. 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,
  2589. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2590. tnsFlush();
  2591. tnsUniformOutputColorSpace(T->immShader,0);
  2592. tnsUniformColorComposing(T->immShader,0,0,0);
  2593. }
  2594. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2595. if (b->B1){
  2596. la_BlockDefDrawRecursive(w, bt, b->B1);
  2597. la_BlockDefDrawRecursive(w, bt, b->B2);
  2598. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2599. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2600. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2601. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2602. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2603. la_BlockDefDrawSelf(b, w->CH);
  2604. }else{
  2605. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2606. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2607. la_BlockDefDrawSelfEmpty(b, w->CH);
  2608. }
  2609. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2610. tnsUseNoTexture();
  2611. int at; real tv[8];
  2612. if (b->Vertical){
  2613. at = b->H * b->SplitRatio + b->Y;
  2614. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2615. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2616. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2617. b->X, (w->CH - at - LA_SEAM_W));
  2618. }else{
  2619. at = b->X + b->W * b->SplitRatio;
  2620. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2621. at- LA_SEAM_W, (w->CH - b->Y),
  2622. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2623. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2624. }
  2625. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2626. tnsVertexArray2d(tv, 4);
  2627. tnsPackAs(GL_TRIANGLE_FAN);
  2628. }
  2629. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2630. tnsFlush();
  2631. }
  2632. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2633. if (b->B1){
  2634. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2635. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2636. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2637. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2638. }
  2639. tnsFlush();
  2640. }
  2641. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2642. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2643. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2644. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2645. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2646. if(p->OffScr){
  2647. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2648. }
  2649. }
  2650. }
  2651. void la_ClearUnusedFramebuffers(laWindow* w){
  2652. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2653. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2654. }
  2655. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2656. if(p->Show || p->AnimationMode) continue;
  2657. if(p->OffScr){
  2658. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2659. }
  2660. }
  2661. }
  2662. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2663. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2664. laPanel *p, *NextP;
  2665. laLayout *l = w->CurrentLayout;
  2666. if (!w->CH || !w->CW) return;
  2667. la_ClearUnusedFramebuffers(w);
  2668. tnsDrawToScreen();
  2669. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2670. glClearColor(0.2, 0.2, 0.3, 1.0);
  2671. tnsClearAll();
  2672. tnsUseNoTexture();
  2673. if (l->Draw) l->Draw(w, l);
  2674. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2675. glEnable(GL_BLEND);
  2676. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2677. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2678. laUiItem* ui;
  2679. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2680. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2681. la_SetPropMathcerContext(p);
  2682. if(p->Refresh){
  2683. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2684. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2685. if(MAIN.EnableColorManagement){
  2686. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2687. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2688. }else{
  2689. tnsUniformOutputColorSpace(T->immShader,0);
  2690. tnsUniformColorComposing(T->immShader,0,0,0);
  2691. }
  2692. if(p->Refresh&LA_TAG_RECALC){
  2693. laRecalcPanelImmediate(p);
  2694. }
  2695. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2696. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2697. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2698. }
  2699. tnsDrawToScreen();
  2700. tnsResetViewMatrix();
  2701. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2702. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2703. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2704. tnsFlush();
  2705. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2706. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2707. tnsFlush();
  2708. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2709. }
  2710. }
  2711. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2712. la_AttachedPanelDefDraw(w,p,*p->BT);
  2713. }else{
  2714. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2715. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2716. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2717. }
  2718. for (p = w->Panels.pLast; p; p = NextP){
  2719. NextP = p->Item.pPrev;
  2720. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2721. if (p->AnimationMode && p->LaterDestroy){
  2722. lstRemoveItem(&w->Panels, p);
  2723. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2724. continue;
  2725. }
  2726. la_PanelDefDraw(w, p, *p->BT);
  2727. }
  2728. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2729. la_AttachedPanelDefDraw(w,p,*p->BT);
  2730. }
  2731. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2732. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2733. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2734. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2735. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2736. tnsFlush();
  2737. }
  2738. for (p = w->FadingPanels.pLast; p; p = NextP){
  2739. NextP = p->Item.pPrev;
  2740. if (!p->AnimationMode){
  2741. lstRemoveItem(&w->FadingPanels, p);
  2742. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2743. laDeferredDestroyPanel(p, 0);
  2744. }else
  2745. la_PanelDrawToWindow(p, w);
  2746. }
  2747. }
  2748. int laStartWindow(laWindow *w){
  2749. #ifdef LA_LINUX
  2750. XMapWindow(MAIN.dpy,w->win);
  2751. tnsContextMakeWindowCurrent(w);
  2752. #endif
  2753. #ifdef _WIN32
  2754. ShowWindow(w->win, SW_SHOWNORMAL);
  2755. #endif
  2756. MAIN.CurrentWindow = w;
  2757. if(!w->CurrentLayout){
  2758. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2759. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2760. }
  2761. laRedrawCurrentWindow();
  2762. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2763. w->Shown = 1;
  2764. }
  2765. void la_AssignWindowPP(laWindow* w){
  2766. w->PP.EndInstance = w;
  2767. w->PP.LastPs = &w->FakePS;
  2768. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2769. w->PP.LastPs->UseInstance = w;
  2770. w->PP.LastPs->Type = U'.';
  2771. }
  2772. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2773. #ifdef LAGUI_ANDROID
  2774. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2775. #endif
  2776. laWindow *n = memAcquire(sizeof(laWindow));
  2777. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2778. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2779. #ifdef LAGUI_ANDROID
  2780. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2781. #endif
  2782. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2783. lstAppendItem(&MAIN.Windows, n);
  2784. MAIN.CurrentWindow = n;
  2785. la_AssignWindowPP(n);
  2786. laui_DefaultMenuBar(n);
  2787. return n;
  2788. }
  2789. void laSetWindowCursor(int id){
  2790. MAIN.CurrentCursor = id;
  2791. #ifdef LA_LINUX
  2792. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2793. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2794. #endif
  2795. #ifdef _WIN32
  2796. SetCursor(la_ConvertCursorID(id));
  2797. #endif
  2798. };
  2799. void la_AssignBlockPP(laBlock* b){
  2800. b->PP.EndInstance = b;
  2801. b->PP.LastPs = &b->FakePS;
  2802. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2803. b->PP.LastPs->UseInstance = b;
  2804. b->PP.LastPs->Type = U'.';
  2805. }
  2806. void laDestroyLayout(laWindow *w, laLayout* l){
  2807. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2808. laDestroyBlocksRecursive(l->FirstBlock);
  2809. strSafeDestroy(&l->ID);
  2810. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2811. lstRemoveItem(&w->Layouts,l); memFree(l);
  2812. }
  2813. laLayout *laDesignLayout(laWindow *w, char *Title){
  2814. laLayout *l = memAcquire(sizeof(laLayout));
  2815. l->FirstBlock = memAcquire(sizeof(laBlock));
  2816. la_AssignBlockPP(l->FirstBlock);
  2817. lstAppendItem(&w->Layouts, l);
  2818. strSafeSet(&l->ID, Title);
  2819. memAssignRef(w, &w->CurrentLayout, l);
  2820. laRenameWindow(w, Title);
  2821. return l;
  2822. }
  2823. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2824. 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); }
  2825. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2826. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2827. laNotifyUsers("la.windows.maximized_block"); }
  2828. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2829. laNotifyUsers("la.windows.maximized_block"); }
  2830. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2831. laRestoreCanvasUI();
  2832. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2833. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2834. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2835. UiParentPanel->Show=0;
  2836. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2837. }
  2838. void laRestoreCanvasUI(){
  2839. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2840. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2841. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2842. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2843. }
  2844. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2845. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2846. }
  2847. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2848. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2849. laPanel *p;
  2850. b->SplitRatio = Percentage;
  2851. b->Vertical = 0;
  2852. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2853. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2854. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2855. p->Block = b->B1;
  2856. }
  2857. b->B1->Panels.pFirst = b->Panels.pFirst;
  2858. b->B1->Panels.pLast = b->Panels.pLast;
  2859. b->B1->CurrentPanel = b->CurrentPanel;
  2860. b->B1->parent = b->B2->parent=b;
  2861. b->Panels.pFirst = 0;
  2862. b->Panels.pLast = 0;
  2863. b->CurrentPanel = 0;
  2864. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2865. }
  2866. void laSplitBlockVertical(laBlock *b, real Percentage){
  2867. laPanel *p;
  2868. b->SplitRatio = Percentage;
  2869. b->Vertical = 1;
  2870. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2871. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2872. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2873. p->Block = b->B1;
  2874. }
  2875. b->B1->Panels.pFirst = b->Panels.pFirst;
  2876. b->B1->Panels.pLast = b->Panels.pLast;
  2877. b->B1->CurrentPanel = b->CurrentPanel;
  2878. b->B1->parent = b->B2->parent=b;
  2879. b->Panels.pFirst = 0;
  2880. b->Panels.pLast = 0;
  2881. b->CurrentPanel = 0;
  2882. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2883. }
  2884. void laCombineChildBlocks(laBlock *b){
  2885. laPanel *p; if(!b) return;
  2886. if (!b->B1->B1 && !b->B2->B1){
  2887. lstCombineLists(&b->Panels, &b->B1->Panels);
  2888. lstCombineLists(&b->Panels, &b->B2->Panels);
  2889. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2890. p->Block = b;
  2891. }
  2892. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2893. memFree(b->B1);
  2894. memFree(b->B2);
  2895. b->B1 = 0;
  2896. b->B2 = 0;
  2897. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2898. }elif(!b->B1->B1){
  2899. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2900. b->Vertical = b->B2->Vertical;
  2901. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2902. p->Block = b1;
  2903. }
  2904. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2905. memFree(b->B1); memFree(b->B2);
  2906. b->B1 = b1; b->B2 = b2;
  2907. b1->parent = b; b2->parent = b;
  2908. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2909. }elif(!b->B2->B1){
  2910. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2911. b->Vertical = b->B1->Vertical;
  2912. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2913. p->Block = b1;
  2914. }
  2915. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2916. memFree(b->B1); memFree(b->B2);
  2917. b->B1 = b1; b->B2 = b2;
  2918. b1->parent = b; b2->parent = b;
  2919. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2920. }
  2921. }
  2922. laBlock *laBlock1(laBlock *b){
  2923. return b->B1;
  2924. }
  2925. laBlock *laBlock2(laBlock *b){
  2926. return b->B2;
  2927. }
  2928. laBlock *laSwapSubBlocks(laBlock *b){
  2929. laBlock *tB;
  2930. tB = b->B2;
  2931. b->B2 = b->B1;
  2932. b->B1 = tB;
  2933. b->SplitRatio = 1 - b->SplitRatio;
  2934. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2935. }
  2936. void laDestroyBlocksRecursive(laBlock *Root){
  2937. laPanel *p;
  2938. if (Root->B1){
  2939. laDestroyBlocksRecursive(Root->B1);
  2940. laDestroyBlocksRecursive(Root->B2);
  2941. }else{
  2942. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2943. }
  2944. memFree(Root);
  2945. }
  2946. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2947. if(!b->CurrentPanel ) return 0;
  2948. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2949. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2950. lstRemoveItem(&b->Panels, p);
  2951. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  2952. if(!p->TitleBar.UiItems.pFirst){
  2953. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2954. }
  2955. p->Mode = LA_PANEL_FLOATING_TOP;
  2956. p->TY-=LA_RH; p->TH+=LA_RH;
  2957. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  2958. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  2959. p->Block = 0;
  2960. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  2961. laRecalcPanel(p);
  2962. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2963. p->BT = &_LA_THEME_FLOATING_PANEL;
  2964. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2965. laNotifyUsers("la.windows.panels");
  2966. return b->CurrentPanel;
  2967. }
  2968. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2969. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2970. lstRemoveItem(&from->Panels, p);
  2971. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2972. p->Mode = LA_PANEL_NORMAL;
  2973. p->Block=b;
  2974. b->CurrentPanel = p;
  2975. lstPushItem(&b->Panels, p);
  2976. laRecalcPanel(p);
  2977. p->BT = &_LA_THEME_PANEL;
  2978. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2979. tnsFlush();
  2980. laNotifyUsers("la.windows.panels");
  2981. }
  2982. void laPopPanel(laPanel *p){
  2983. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2984. lstRemoveItem(&p->Parent->SubPanels, p);
  2985. lstPushItem(&p->Parent->SubPanels, p);
  2986. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2987. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2988. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2989. laNotifyUsers("la.windows.panels");
  2990. }
  2991. }
  2992. void la_EnsurePanelExtras(laPanel *p){
  2993. laUiTemplate* uit=p->PanelTemplate;
  2994. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  2995. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  2996. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  2997. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  2998. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  2999. p->PropLinkFakeProp->Base.Offset = 0;
  3000. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  3001. p->PropLinkPP.EndInstance = p;
  3002. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3003. p->PropLinkPP.LastPs->Type = U'.';
  3004. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3005. }
  3006. laPanel* la_GivePanelNode(){
  3007. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3008. return memAcquire(sizeof(laPanel));
  3009. }
  3010. void la_ReturnPanelNode(laPanel* p){
  3011. memset(p,0,sizeof(laPanel));
  3012. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3013. lstAppendItem(&MAIN.WastedPanels, p);
  3014. }
  3015. 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){
  3016. laPanel *p = la_GivePanelNode();
  3017. int CW = MAIN.CurrentWindow->CW;
  3018. int CH = MAIN.CurrentWindow->CH;
  3019. p->PanelTemplate = uit;
  3020. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3021. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3022. if (!MaxW) MaxW = 10000;
  3023. if (!MaxH) MaxH = 10000;
  3024. if (W > MaxW) W = MaxW;
  3025. if (H > MaxH) H = MaxH;
  3026. if (W < MinW) W = MinW;
  3027. if (H < MinH) H = MinH;
  3028. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3029. p->X = p->TX = (X < 0 ? 0 : X);
  3030. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3031. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3032. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3033. p->MaxW = MaxW; p->MaxH = MaxH;
  3034. p->MinW = MinW; p->MinH = MinH;
  3035. p->SL = SnapL; p->ST = SnapT;
  3036. p->SR = SnapR; p->SB = SnapB;
  3037. if (p->SR) p->X = CW - p->W - p->SR;
  3038. if (p->SB) p->Y = CH - p->H - p->SB;
  3039. la_EnsurePanelSnapping(p, CW, CH);
  3040. p->Show = 1;
  3041. p->PP.EndInstance = p;
  3042. p->PP.LastPs = &p->FakePS;
  3043. p->PP.LastPs->p = _LA_PROP_PANEL;
  3044. p->PP.LastPs->UseInstance = p;
  3045. p->PP.LastPs->Type = U'.';
  3046. la_EnsurePanelExtras(p);
  3047. laRecalcPanel(p);
  3048. p->FrameDistinguish = 100; //greater than 1 is ok
  3049. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3050. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3051. return p;
  3052. }
  3053. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3054. if(!uit) return 0;
  3055. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3056. strSafeSet(&p->Title, uit->Title->Ptr);
  3057. p->PanelTemplate = uit;
  3058. p->Show = 1;
  3059. p->PP.EndInstance = p;
  3060. p->PP.LastPs = &p->FakePS;
  3061. p->PP.LastPs->p = _LA_PROP_PANEL;
  3062. p->PP.LastPs->UseInstance = p;
  3063. p->PP.LastPs->Type = U'.';
  3064. la_EnsurePanelExtras(p);
  3065. laRecalcPanel(p);
  3066. p->FrameDistinguish = 100; //greater than 1 is ok
  3067. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3068. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3069. p->Block = b; b->CurrentPanel = p;
  3070. if(uit->PropFunc){ uit->PropFunc(p); }
  3071. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3072. laNotifyUsers("la.windows.panels");
  3073. return p;
  3074. }
  3075. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3076. laUiTemplate* uit=laFindUiTemplate(template_id);
  3077. return laCreatePanelT(b, uit);
  3078. }
  3079. 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){
  3080. laUiTemplate* uit=0;
  3081. if(template_id) uit=laFindUiTemplate(template_id);
  3082. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3083. p->Mode = LA_PANEL_FLOATING_TOP;
  3084. laPlacePanelForCreation(p);
  3085. if(uit){
  3086. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3087. }
  3088. if (w) lstPushItem(&w->Panels, p);
  3089. return p;
  3090. }
  3091. void laShowPanel(laPanel *p){
  3092. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3093. }
  3094. void laShowPanelWithDropDownEffect(laPanel *p){
  3095. laShowPanel(p);
  3096. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3097. p->AnimationRatio = 0;
  3098. }
  3099. void laShowPanelWithExpandEffect(laPanel *p){
  3100. laShowPanel(p);
  3101. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3102. p->AnimationRatio = 0;
  3103. }
  3104. void laHidePanel(laPanel *p){
  3105. if (!p->Mode) return;
  3106. p->Show = 0;
  3107. laNotifyUsers("la.windows.panels_hidden");
  3108. }
  3109. void laHidePanelWithDissoveEffect(laPanel *p){
  3110. if (!p->Mode) return;
  3111. laHidePanel(p);
  3112. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3113. p->AnimationRatio = 1;
  3114. }
  3115. void laHidePanelWithCollapseEffect(laPanel *p){
  3116. if (!p->Mode) return;
  3117. laHidePanel(p);
  3118. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3119. p->AnimationRatio = 1;
  3120. }
  3121. void laHidePanelWithMinimizeEffect(laPanel *p){
  3122. if (!p->Mode) return;
  3123. laHidePanel(p);
  3124. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3125. p->AnimationRatio = 1;
  3126. }
  3127. void laActivatePanel(char* TemplateID, int x, int y){
  3128. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3129. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3130. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3131. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3132. }
  3133. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3134. p->UI.PanX += DeltaX;
  3135. p->UI.PanY += DeltaY;
  3136. }
  3137. int laPanUiListFree(laUiList *uil, int X, int Y){
  3138. uil->PanX+=X; uil->PanY+=Y;
  3139. }
  3140. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3141. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3142. if(Y){X+=Y;Y=0;}
  3143. }
  3144. if (Y > 0){
  3145. if (uil->B - uil->PanY <= B) return 0;
  3146. else{
  3147. uil->PanY += Y;
  3148. if (uil->B - uil->PanY <= B){
  3149. uil->PanY = uil->B - B;
  3150. return 1;
  3151. }
  3152. }
  3153. }
  3154. if (Y < 0){
  3155. if (uil->U - uil->PanY >= U) return 0;
  3156. else{
  3157. uil->PanY += Y;
  3158. if (uil->U - uil->PanY >= U){
  3159. uil->PanY = uil->U - U;
  3160. return 1;
  3161. }
  3162. }
  3163. }
  3164. if(uil->AllowScale){
  3165. laPanUiListFree(uil, X, 0);
  3166. }else{
  3167. if (X > 0){
  3168. if (uil->R - uil->PanX <= R) return 0;
  3169. else{
  3170. uil->PanX += X;
  3171. if (uil->R - uil->PanX <= R){
  3172. uil->PanX = uil->R - R;
  3173. return 1;
  3174. }
  3175. }
  3176. }
  3177. if (X < 0){
  3178. if (uil->L - uil->PanX >= L) return 0;
  3179. else{
  3180. uil->PanX += X;
  3181. if (uil->L - uil->PanX >= L){
  3182. uil->PanX = uil->L - L;
  3183. return 1;
  3184. }
  3185. }
  3186. }
  3187. }
  3188. return 1;
  3189. }
  3190. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3191. int ret=1;
  3192. if(!uil->AllowScale){ return 0; }
  3193. real NewScale=uil->Scale*factor;
  3194. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3195. if(NewScale>5) {NewScale=5; ret=0;}
  3196. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3197. factor=NewScale/uil->Scale;
  3198. uil->Scale=NewScale;
  3199. real mx=(L+R)/2,my=(U+B)/2;
  3200. real dx= (mx+uil->PanX)*factor;
  3201. real dy= (my+uil->PanY)*factor;
  3202. uil->PanX=dx-mx;
  3203. uil->PanY=dy-my;
  3204. MAIN.CurrentPanel->FrameDistinguish=100;
  3205. return ret;
  3206. }
  3207. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3208. if(uil->AllowScale) return 0;
  3209. return laPanUiList(uil,X,Y,L,R,U,B);
  3210. }
  3211. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3212. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3213. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3214. strSafeSet(&p->Title, Title);
  3215. if (Define){
  3216. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3217. }
  3218. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3219. p->BT= &_LA_THEME_FLOATING_PANEL;
  3220. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3221. p->BoundUi = 1;
  3222. return p;
  3223. }
  3224. 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,
  3225. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3226. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3227. strSafeSet(&p->Title, Title);
  3228. if (Define){
  3229. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3230. }
  3231. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3232. p->BT= &_LA_THEME_FLOATING_PANEL;
  3233. p->Mode = LA_PANEL_FLOATING_TOP;
  3234. p->BoundUi = 1;
  3235. return p;
  3236. }
  3237. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3238. laPanel *ip;
  3239. tnsDelete2DOffscreen(p->OffScr);
  3240. p->OffScr = 0;
  3241. strSafeDestroy(&p->Title);
  3242. if (!p->AnimationMode){
  3243. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3244. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3245. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3246. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3247. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3248. }else if (p->Block){
  3249. lstRemoveItem(&p->Block->Panels, p);
  3250. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3251. }
  3252. laNotifyUsers("la.windows.panels");
  3253. }
  3254. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3255. //lstRemoveItem(&p->SubPanels, ip);
  3256. laDestroySinglePanel(ip, immediate);
  3257. laNotifyUsers("la.windows.panels");
  3258. }
  3259. la_ClearDetachedProp(p);
  3260. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3261. la_ReturnPanelNode(p);
  3262. }
  3263. void laDestroySinglePanel(laPanel *p, int immediate){
  3264. la_SetPropMathcerContext(p);
  3265. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3266. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3267. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3268. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3269. }
  3270. }
  3271. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3272. la_DestroyUiList(&p->UI, 1, 1, 0);
  3273. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3274. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3275. if (p->Mode){
  3276. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3277. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3278. }
  3279. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3280. if (la_UiStillInService(p)){
  3281. la_StopUiOperatorService(p);
  3282. }
  3283. if ((!p->AnimationMode) || immediate){
  3284. laDeferredDestroyPanel(p, immediate);
  3285. }else{
  3286. p->LaterDestroy = 1;
  3287. }
  3288. }
  3289. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3290. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3291. int MinW,MinWt=0;
  3292. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3293. int CW = MAIN.CurrentWindow->CW;
  3294. if(p->SL && p->SR){return 0;}
  3295. la_SetPropMathcerContext(p);
  3296. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3297. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3298. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3299. MinW = la_TestUiListMinumWidth(uil);
  3300. if (MinW<MinWt){MinW=MinWt;}
  3301. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3302. if (MinW > 20){
  3303. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3304. }
  3305. la_PanelValidateWidth(p,uil);
  3306. laEnsurePanelInBound(p,uil);
  3307. if(p->TW>CW){ p->TW=CW; }
  3308. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3309. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3310. laRedrawPanel(p);
  3311. return 1;
  3312. }
  3313. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3314. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3315. laOperator *ai = a;
  3316. laPanel *p;
  3317. int GX, GY, GW, t = 0;
  3318. int b;
  3319. laUiDefineFunc def = ReplaceUiDefine;
  3320. int MinW;
  3321. if (!def){ def=laui_DefaultPropDetails; }
  3322. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3323. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3324. laEnclosePanelContent(p, &p->UI);
  3325. laSetOperatorLocalizer(p);
  3326. p->CloseWhenMovedOut=1;
  3327. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3328. //laShowPanelWithDropDownEffect(p);
  3329. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3330. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3331. return p;
  3332. }
  3333. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3334. laPanel *p;
  3335. int GX, GY, GW, t = 0;
  3336. int b;
  3337. laUiDefineFunc def = ReplaceUiDefine;
  3338. int MinW;
  3339. if (!def) return 0;
  3340. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3341. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3342. p->Mode = LA_PANEL_FLOATING_TOP;
  3343. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3344. laEnclosePanelContent(p, &p->UI);
  3345. if(MAIN.CurrentWindow->Operators.pFirst){
  3346. laSetOperatorLocalizer(MAIN.PendingSplash);
  3347. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3348. MAIN.PendingSplash=0;
  3349. }
  3350. //laShowPanelWithExpandEffect(p);
  3351. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3352. return p;
  3353. }
  3354. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3355. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3356. laOperator *ai = a;
  3357. laPanel *p; laPropContainer* sub;
  3358. int GX, GY, GW, t = 0;
  3359. int b;
  3360. laUiDefineFunc def = ReplaceUiDefine;
  3361. int MinW;
  3362. if (!def){
  3363. if (This && This->LastPs->p){
  3364. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3365. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3366. }
  3367. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3368. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3369. }
  3370. GX = L; GY = B;
  3371. GW = (R - L) > MaxW ? MaxW : (R - L);
  3372. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3373. laEnclosePanelContent(p, &p->UI);
  3374. laSetOperatorLocalizer(p);
  3375. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3376. laShowPanelWithDropDownEffect(p);
  3377. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3378. if(Attachment){
  3379. p->Parent = Attachment;
  3380. lstAppendItem(&Attachment->SubPanels, p);
  3381. }
  3382. return p;
  3383. }
  3384. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3385. laPanel *p;
  3386. int t = 0;
  3387. int b;
  3388. //laLocalToWindow(0, Attachment, &L, &t);
  3389. //laLocalToWindow(0, Attachment, &R, &U);
  3390. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3391. laSetOperatorLocalizer(p);
  3392. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3393. laShowPanelWithDropDownEffect(p);
  3394. p->Parent = Attachment;
  3395. lstPushItem(&Attachment->SubPanels, p);
  3396. return p;
  3397. }
  3398. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3399. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3400. laOperator *ai = a;
  3401. laPanel *p;
  3402. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3403. int GX, GY, GW, t = 0;
  3404. int b;
  3405. int MinW;
  3406. //laLocalToWindow(0,Attachment, &L, &t);
  3407. //laLocalToWindow(0,Attachment, &R, &B);
  3408. GX = L;
  3409. GY = B;
  3410. GW = (R - L) > MaxW ? MaxW : (R - L);
  3411. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3412. p->MenuRefer = MenuRefer;
  3413. laEnclosePanelContent(p, MenuRefer);
  3414. laSetOperatorLocalizer(p);
  3415. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3416. laShowPanelWithDropDownEffect(p);
  3417. p->Parent = Attachment;
  3418. lstPushItem(&Attachment->SubPanels, p);
  3419. return p;
  3420. }
  3421. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3422. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3423. laOperator *ai = a;
  3424. laPanel *p;
  3425. int GX, GY, GW, t = 0;
  3426. int b;
  3427. GX = L;
  3428. GY = B;
  3429. GW = MaxW;
  3430. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3431. p->MenuRefer = &p->UI;
  3432. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3433. laSetOperatorLocalizer(p);
  3434. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3435. laShowPanelWithDropDownEffect(p);
  3436. if (Attachment){
  3437. p->Parent = Attachment;
  3438. lstPushItem(&Attachment->SubPanels, p);
  3439. }else{
  3440. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3441. }
  3442. return p;
  3443. }
  3444. 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){
  3445. laOperator *ai = For;
  3446. laPanel *p;
  3447. int b;
  3448. laUiDefineFunc def = 0;
  3449. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3450. else def = laui_DefaultPropUiDefine;
  3451. For->PP.EndInstance = For->CustomData;
  3452. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3453. laEnclosePanelContent(p, &p->UI);
  3454. MAIN.ToPanel = p;
  3455. laShowPanelWithExpandEffect(p);
  3456. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3457. ai->OperatorPanel = p;
  3458. p->ParentOperator = For;
  3459. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3460. return p;
  3461. }
  3462. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3463. laPanel *p; int b; laUiList *uil; laColumn* col;
  3464. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3465. strSafeSet(&p->Title, Title);
  3466. p->BoundUi = 1;
  3467. p->Mode = LA_PANEL_FLOATING_TOP;
  3468. p->BT = &_LA_THEME_FLOATING_PANEL;
  3469. MAIN.ToPanel = p;
  3470. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3471. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3472. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3473. laUiItem* r=laBeginRow(uil,col,0,0);
  3474. laShowSeparator(uil,col)->Expand=1;
  3475. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3476. laEndRow(uil,r);
  3477. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3478. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3479. laSetOperatorLocalizer(p);
  3480. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3481. return p;
  3482. }
  3483. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3484. laPanel *p; int b; laUiList *uil; laColumn* col;
  3485. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3486. strSafeSet(&p->Title, Title);
  3487. p->BoundUi = 1;
  3488. p->Mode = LA_PANEL_FLOATING_TOP;
  3489. p->BT = &_LA_THEME_FLOATING_PANEL;
  3490. MAIN.ToPanel = p;
  3491. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3492. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3493. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3494. laUiItem* r = laBeginRow(uil,col,0,0);
  3495. laShowSeparator(uil,col)->Expand=1;
  3496. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3497. laEndRow(uil, r);
  3498. laEnclosePanelContent(p,uil);
  3499. laShowPanelWithExpandEffect(p);
  3500. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3501. laSetOperatorLocalizer(p);
  3502. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3503. return p;
  3504. }
  3505. void laOperatorModalOver(laOperator* For){
  3506. For->ModalOver = 1;
  3507. }
  3508. void laDeferredRedraw(laPanel* p){
  3509. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3510. if(lip->p==p) return;
  3511. }
  3512. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3513. }
  3514. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3515. laWindow* cur=MAIN.CurrentWindow;
  3516. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3517. MAIN.CurrentWindow=w;
  3518. la_UpdateUiPlacement(w);
  3519. }
  3520. MAIN.CurrentWindow=cur;
  3521. }
  3522. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3523. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3524. }
  3525. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3526. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3527. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3528. void laRedrawCurrentPanel(){
  3529. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3530. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3531. }
  3532. void laRecalcCurrentPanel(){
  3533. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3534. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3535. }
  3536. void laRecalcPanelImmediate(laPanel* p){
  3537. p->FrameDistinguish++;
  3538. laBoxedTheme* bt = (*p->BT);
  3539. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3540. la_PanelRefreshDetachedProp(p);
  3541. int enclosed=0;
  3542. if(p->BoundUi || p->MenuRefer){
  3543. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3544. else enclosed=laEnclosePanelContent(p, &p->UI);
  3545. }
  3546. if(!enclosed){
  3547. la_PanelValidateWidth(p,&p->UI);
  3548. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3549. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3550. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3551. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3552. }
  3553. laWindow* w=MAIN.CurrentWindow;
  3554. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3555. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3556. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3557. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3558. }
  3559. }
  3560. void laRecalcCurrentPanelImmediate(){
  3561. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3562. }
  3563. int laNonFixedPanelExists(laPanel *p){
  3564. laPanel *ip;
  3565. if (!p) return 0;
  3566. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3567. // if (ip == p) return 1;
  3568. //}
  3569. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3570. if (ip == p) return 1;
  3571. }
  3572. return 0;
  3573. }
  3574. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3575. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3576. return 1;
  3577. }
  3578. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3579. int tt=MAIN.TooltipCloseDistance;
  3580. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3581. return 1;
  3582. }
  3583. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3584. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3585. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3586. return 0;
  3587. return 1;
  3588. }
  3589. void laUnlinkSharedPanel(laPanel *p){
  3590. laWindow *w;
  3591. laPanel *ip;
  3592. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3593. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3594. if (ip == p){
  3595. lstRemoveItem(&w->Panels, ip);
  3596. return;
  3597. }
  3598. }
  3599. }
  3600. }
  3601. int laIsPanelCovered(laPanel *p){
  3602. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3603. laPanel *ip;
  3604. laPanel *resp;
  3605. int in1 = 0, in2 = 0, in3 = 0;
  3606. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3607. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3608. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3609. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3610. //}
  3611. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3612. if (ip == p){
  3613. in3 = 1;
  3614. d3 = 0;
  3615. continue;
  3616. }
  3617. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3618. }
  3619. if (!in2 && !in3) in1 = 1;
  3620. if (in1){
  3621. if (d1 || d2 || d3) return 1;
  3622. }else{
  3623. if (in2){
  3624. if (d2 || d3) return 1;
  3625. }else if (in3)
  3626. if (d3) return 1;
  3627. }
  3628. return 0;
  3629. }
  3630. int laIsTopPanel(laPanel *p){
  3631. //if (!p->Item.pPrev) return 1;
  3632. //else {
  3633. if (!laIsPanelCovered(p)){
  3634. //laPopPanel(p);
  3635. return 1;
  3636. }
  3637. return 0;
  3638. //}
  3639. return 0;
  3640. }
  3641. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3642. if(!p) return;
  3643. int ix = *x, iy = *y;
  3644. laListItemPointer *lip;
  3645. laOperator *ai = a;
  3646. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3647. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3648. if (a){
  3649. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3650. laUiList *uil = lip->p;
  3651. (*x) += uil->PanX;
  3652. (*y) += uil->PanY;
  3653. }
  3654. }
  3655. }
  3656. void laPanelToLocal(laOperator *a, int *x, int *y){
  3657. int ix = *x, iy = *y;
  3658. laListItemPointer *lip;
  3659. if (a){
  3660. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3661. laUiList *uil = lip->p;
  3662. (*x) += uil->PanX;
  3663. (*y) += uil->PanY;
  3664. }
  3665. }
  3666. }
  3667. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3668. if(!p) return;
  3669. int ix = *x, iy = *y;
  3670. laListItemPointer *lip;
  3671. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3672. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3673. if (a){
  3674. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3675. laUiList *uil = lip->p;
  3676. (*x) -= uil->PanX;
  3677. (*y) -= uil->PanY;
  3678. }
  3679. }
  3680. }
  3681. void laPanelToWindow(laPanel *p, int *x, int *y){
  3682. int ix = *x, iy = *y;
  3683. laListItemPointer *lip;
  3684. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3685. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3686. }
  3687. void laLocalToPanel(laOperator *a, int *x, int *y){
  3688. int ix = *x, iy = *y;
  3689. laListItemPointer *lip;
  3690. if (a){
  3691. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3692. laUiList *uil = lip->p;
  3693. (*x) -= uil->PanX;
  3694. (*y) -= uil->PanY;
  3695. }
  3696. }
  3697. }
  3698. void laSetNextMenuPos(int X, int Y, int W, int H){
  3699. MAIN.NextX = X;
  3700. MAIN.NextY = Y;
  3701. MAIN.NextW = W;
  3702. MAIN.NextH = H;
  3703. }
  3704. int laIsInBlock(laBlock *b, int X, int Y){
  3705. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3706. return 0;
  3707. }
  3708. 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; }
  3709. 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; }
  3710. 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; }
  3711. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3712. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3713. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3714. if (!b->B1 && !b->B2){
  3715. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3716. }
  3717. }
  3718. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3719. laPanel *p;
  3720. laBlock *sb = 0;
  3721. if (!laIsInBlock(b, X, Y)) return 0;
  3722. if (!b->B1 && !b->B2) return b;
  3723. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3724. return laDetectBlockRecursive(b->B2, X, Y);
  3725. }
  3726. laPanel *laDetectPanel(int X, int Y){
  3727. laPanel *p; laBlock *b;
  3728. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3729. int x = X, y = Y;
  3730. laWindowToLocal(0, p, &x, &y);
  3731. if (p->Show && laIsInPanel(p, x, y)){
  3732. return p;
  3733. }
  3734. }
  3735. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3736. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3737. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3738. return 0;
  3739. }
  3740. laUiList *laPrepareUi(laPanel *p){
  3741. return &p->UI;
  3742. }
  3743. laColumn *laFirstColumn(laUiList *uil){
  3744. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3745. else{
  3746. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3747. c->SP = 1;
  3748. c->PreWidth = 1;
  3749. lstAppendItem(&uil->Columns, c);
  3750. c->Top = c;
  3751. return uil->Columns.pFirst;
  3752. }
  3753. }
  3754. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3755. laColumn *lc, *rc;
  3756. if (c->LS || c->RS) return c;
  3757. lc = memAcquireSimple(sizeof(laColumn));
  3758. rc = memAcquireSimple(sizeof(laColumn));
  3759. c->LS = lc;
  3760. c->RS = rc;
  3761. c->LS->SP = Percent;
  3762. c->RS->SP = Percent;
  3763. c->LS->Top = c->Top;
  3764. c->RS->Top = c->Top;
  3765. if (uil){
  3766. lstAppendItem(&uil->Columns, lc);
  3767. lstAppendItem(&uil->Columns, rc);
  3768. }
  3769. if (c->LS && c->RS->MaxW == 0){
  3770. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3771. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3772. }else if (c->RS && c->LS->MaxW == 0){
  3773. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3774. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3775. }
  3776. return c;
  3777. }
  3778. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3779. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3780. return c->LS;
  3781. }
  3782. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3783. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3784. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3785. return c->RS;
  3786. }
  3787. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3788. lstRemoveItem(List, c);
  3789. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3790. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3791. memFree(c);
  3792. }
  3793. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3794. laUiList *uil = TopUil;
  3795. laUiList *sub;
  3796. laUiItem *ui;
  3797. laColumn *cc, *NextCC = 0;
  3798. int Occupied = 0;
  3799. int Removed = 0;
  3800. if (!c->LS) return 0;
  3801. else{
  3802. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3803. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3804. }
  3805. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3806. if (ui->C == c->LS || ui->C == c->RS){
  3807. if (DoMerge){
  3808. ui->C = c;
  3809. Occupied = 1;
  3810. }else
  3811. return 1;
  3812. }
  3813. if (ui->Subs.pFirst){
  3814. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3815. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3816. }
  3817. }
  3818. }
  3819. if (!Removed){
  3820. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3821. if (cc == c){
  3822. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3823. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3824. c->LS = 0;
  3825. c->RS = 0;
  3826. Removed = 1;
  3827. break;
  3828. }
  3829. }
  3830. }
  3831. return Occupied;
  3832. }
  3833. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3834. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3835. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3836. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3837. ut->FakeProp->Base.Identifier = ut->Identifier;
  3838. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3839. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3840. ut->FakeProp->Base.OffsetIsPointer = 1;
  3841. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3842. return ut->ExtraProps;
  3843. }
  3844. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3845. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3846. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3847. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3848. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3849. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3850. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3851. ct->FakeProp->Base.OffsetIsPointer = 1;
  3852. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3853. return ct->ExtraProps;
  3854. }
  3855. void la_DestroyUiType(laUiType* uit){
  3856. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3857. memFree(uit);
  3858. }
  3859. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3860. laUiType *ut = memAcquire(sizeof(laUiType));
  3861. ut->Identifier = Identifer;
  3862. ut->OperatorID = UseOperator;
  3863. ut->Draw = Draw;
  3864. ut->Theme = bt;
  3865. ut->ForType = ForType;
  3866. ut->OperatorType = laGetOperatorType(UseOperator);
  3867. ut->GetHeight = GetHeight;
  3868. ut->Init = Init;
  3869. ut->Destroy = Destroy;
  3870. la_UDFAppendSharedTypePointer(Identifer, ut);
  3871. lstAppendItem(&MAIN.UiTypes, ut);
  3872. return ut;
  3873. }
  3874. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3875. laUiType *ut = MAIN.UiTypes.pFirst;
  3876. if (!P) return 0;
  3877. if (P->DefaultUiType) return P->DefaultUiType;
  3878. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3879. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3880. for (ut; ut; ut = ut->Item.pNext){
  3881. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3882. return ut;
  3883. }
  3884. }
  3885. return 0;
  3886. }
  3887. laUiType *la_GetUiButtonType(){
  3888. laUiType *ut = MAIN.UiTypes.pFirst;
  3889. for (ut; ut; ut = ut->Item.pNext){
  3890. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3891. }
  3892. return 0;
  3893. }
  3894. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3895. laCanvasTemplate *vdt;
  3896. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3897. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3898. }
  3899. return 0;
  3900. }
  3901. void la_AssignPropExtras(laUiItem* ui){
  3902. if(!ui->Type || !ui->Type->FakeProp) return;
  3903. ui->FakePs.p = ui->Type->FakeProp;
  3904. ui->FakePs.Type = U'.';
  3905. ui->FakePs.UseInstance = ui;
  3906. ui->ExtraPP.LastPs = &ui->FakePs;
  3907. }
  3908. void la_AssignCanvasPropExtras(laUiItem* ui){
  3909. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3910. laCanvasTemplate*ct=ui->CanvasTemplate;
  3911. ui->FakePs.p = ct->FakeProp;
  3912. ui->FakePs.Type = U'.';
  3913. ui->FakePs.UseInstance = ui;
  3914. ui->ExtraPP.EndInstance = ui->Extra;
  3915. ui->ExtraPP.LastPs = &ui->FakePs;
  3916. }
  3917. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3918. int result;
  3919. if (!ui) return 0;
  3920. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3921. if (Path){
  3922. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3923. if (!result){
  3924. ui->AT = laGetOperatorType(Path);
  3925. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3926. ui->Type = la_GetUiButtonType();
  3927. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3928. }else{
  3929. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3930. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3931. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3932. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3933. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3934. }
  3935. if (Base){
  3936. ui->PP.RawThis = Base;
  3937. }
  3938. }else if (Base){
  3939. ui->PP.LastPs = Base->LastPs;
  3940. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3941. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3942. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3943. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3944. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3945. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3946. }
  3947. la_AssignPropExtras(ui);
  3948. if(Widget){ ui->Flags|= Widget->Flags; }
  3949. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3950. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3951. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3952. return ui;
  3953. }
  3954. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3955. ui->Type = _LA_UI_LABEL;
  3956. ui->Template = Template;
  3957. ui->State = LA_UI_NORMAL;
  3958. strSafeSet(&ui->Display, Content);
  3959. la_AssignPropExtras(ui);
  3960. return ui;
  3961. }
  3962. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3963. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3964. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3965. ui->State = LA_UI_NORMAL;
  3966. la_AssignPropExtras(ui);
  3967. return ui;
  3968. }
  3969. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3970. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3971. transLate(Content);
  3972. la_UpdateLabelDisplay(ui, Template, Content);
  3973. ui->C = c;
  3974. if (ui->Type->Init) ui->Type->Init(ui);
  3975. ui->ExtraPP.EndInstance = ui->Extra;
  3976. lstAppendItem(&uil->UiItems, ui);
  3977. return ui;
  3978. }
  3979. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3980. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3981. la_UpdateLabelDisplay(ui, Template, Content);
  3982. ui->C = c;
  3983. if (ui->Type->Init) ui->Type->Init(ui);
  3984. ui->ExtraPP.EndInstance = ui->Extra;
  3985. lstAppendItem(&uil->UiItems, ui);
  3986. return ui;
  3987. }
  3988. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3989. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3990. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3991. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3992. ui->C = c;
  3993. if (ui->Type->Init) ui->Type->Init(ui);
  3994. ui->ExtraPP.EndInstance = ui->Extra;
  3995. lstAppendItem(&uil->UiItems, ui);
  3996. return ui;
  3997. }
  3998. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3999. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  4000. }
  4001. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4002. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4003. }
  4004. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4005. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4006. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4007. ui->C = c;
  4008. ui->TemplateContext = TemplateContext;
  4009. if (ui->Type->Init) ui->Type->Init(ui);
  4010. ui->ExtraPP.EndInstance = ui->Extra;
  4011. lstAppendItem(&uil->UiItems, ui);
  4012. return ui;
  4013. }
  4014. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4015. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4016. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4017. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4018. ui->SymbolID=Height;
  4019. lstAppendItem(&uil->UiItems, ui);
  4020. return ui;
  4021. }
  4022. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4023. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4024. }
  4025. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4026. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4027. }
  4028. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4029. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4030. ui->Type = _LA_UI_CANVAS;
  4031. ui->State = LA_UI_NORMAL;
  4032. ui->C = c;
  4033. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4034. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4035. else{
  4036. 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); }
  4037. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4038. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4039. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4040. }
  4041. if (ui->Type->Init) ui->Type->Init(ui);
  4042. la_AssignCanvasPropExtras(ui);
  4043. if (Height) ui->Expand=Height; else ui->Expand=6;
  4044. lstAppendItem(&uil->UiItems, ui);
  4045. return ui;
  4046. }
  4047. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4048. laUiItem* ui=0;
  4049. #define ADD_CANVAS \
  4050. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4051. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4052. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4053. }laEndCondition(uil,b3);\
  4054. laEndRow(uil,b);
  4055. if(Detached){
  4056. laColumn* cl,*cll,*clr,*cr;
  4057. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4058. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4059. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4060. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4061. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4062. ADD_CANVAS
  4063. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4064. }laElse(uil,b2);{
  4065. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4066. ADD_CANVAS
  4067. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4068. }laEndCondition(uil,b2);
  4069. }else{
  4070. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4071. }
  4072. #undef ADD_CANVAS
  4073. }
  4074. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4075. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4076. laCanvasExtra *e;
  4077. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4078. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4079. ui->C = c;
  4080. if (ui->Type->Init) ui->Type->Init(ui);
  4081. ui->ExtraPP.EndInstance = ui->Extra;
  4082. lstAppendItem(&uil->UiItems, ui);
  4083. return ui;
  4084. }
  4085. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4086. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4087. ui->Type = _LA_UI_SYMBOL;
  4088. ui->SymbolID = SymbolID;
  4089. if (Height) ui->State = Height;
  4090. ui->C = c;
  4091. if (ui->Type->Init) ui->Type->Init(ui);
  4092. ui->ExtraPP.EndInstance = ui->Extra;
  4093. lstAppendItem(&uil->UiItems, ui);
  4094. return ui;
  4095. }
  4096. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4097. laPropPack PP={0}; int result;
  4098. if (Path){
  4099. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4100. if (!result){ return 0; }
  4101. if (Base){ PP.RawThis = Base; }
  4102. }else if (Base){
  4103. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4104. }
  4105. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4106. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4107. lstAppendItem(&ui->CompoundPPs,CPP);
  4108. return &CPP->PP;
  4109. }
  4110. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4111. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4112. ui->Type = &_LA_UI_ROW_BEGIN;
  4113. ui->State=Expand;
  4114. ui->Flags=Even;
  4115. ui->C = c;
  4116. if (ui->Type->Init) ui->Type->Init(ui);
  4117. ui->ExtraPP.EndInstance = ui->Extra;
  4118. lstAppendItem(&uil->UiItems, ui);
  4119. return ui;
  4120. }
  4121. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4122. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4123. ui->Type = &_LA_UI_ROW_END;
  4124. ui->C = Begin->C;
  4125. ui->Page = (laUiList*)Begin;
  4126. if (ui->Type->Init) ui->Type->Init(ui);
  4127. ui->ExtraPP.EndInstance = ui->Extra;
  4128. lstAppendItem(&uil->UiItems, ui);
  4129. return ui;
  4130. }
  4131. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4132. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4133. e->Expression = Expression;
  4134. ui->Extra = e;
  4135. la_AssignPropExtras(ui);
  4136. }
  4137. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4138. laUiItem *ui = la_CreateGroupHandle(Widget);
  4139. laUiList *nuil;
  4140. ui->C = c;
  4141. lstAppendItem(&uil->UiItems, ui);
  4142. nuil = memAcquireSimple(sizeof(laUiList));
  4143. strSafeSet(&nuil->TabName, Name);
  4144. ui->Page = nuil;
  4145. lstAppendItem(&ui->Subs, nuil);
  4146. if (ui->Type->Init) ui->Type->Init(ui);
  4147. ui->ExtraPP.EndInstance = ui->Extra;
  4148. return ui;
  4149. }
  4150. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4151. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4152. laUiList *sub = SubUi->Page;
  4153. laColumn *s = laFirstColumn(sub);
  4154. SubUi->State = LA_UI_ACTIVE;
  4155. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4156. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4157. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4158. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4159. laShowSeparator(sub, s);
  4160. return SubUi;
  4161. }
  4162. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4163. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4164. laUiList *sub = SubUi->Page;
  4165. laColumn *s = laFirstColumn(sub);
  4166. SubUi->State = LA_UI_ACTIVE;
  4167. return SubUi;
  4168. }
  4169. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4170. laEndCondition(sub, sub->UiItems.pFirst);
  4171. }
  4172. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4173. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4174. laUiList *nuil;
  4175. ui->C = c;
  4176. lstAppendItem(&uil->UiItems, ui);
  4177. if (ui->Type->Init) ui->Type->Init(ui);
  4178. ui->ExtraPP.EndInstance = ui->Extra;
  4179. return ui;
  4180. }
  4181. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4182. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4183. if (!ui->Page) ui->Page = uil;
  4184. lstAppendItem(&ui->Subs, uil);
  4185. strSafeSet(&uil->TabName, Name);
  4186. laFirstColumn(uil);
  4187. //laFirstColumn(uil);
  4188. return uil;
  4189. }
  4190. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4191. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4192. /*if (!ui->Page) */ ui->Page = uil;
  4193. lstAppendItem(&ui->Subs, uil);
  4194. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4195. return uil;
  4196. }
  4197. laUiConditionNode *laTrue(){
  4198. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4199. ucn->Type = LA_CONDITION_TRUE;
  4200. return ucn;
  4201. }
  4202. laUiConditionNode *laFalse(){
  4203. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4204. ucn->Type = LA_CONDITION_FALSE;
  4205. return ucn;
  4206. }
  4207. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4208. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4209. ucn->Type = LA_CONDITION_PROP;
  4210. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4211. strSafeSet(&ucn->String, Prop);
  4212. return ucn;
  4213. }
  4214. laUiConditionNode *laIntExpression(int Value){
  4215. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4216. ucn->Type = LA_CONDITION_INT;
  4217. ucn->IntValue = Value;
  4218. return ucn;
  4219. }
  4220. laUiConditionNode *laFloatExpression(real Value){
  4221. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4222. ucn->Type = LA_CONDITION_FLOAT;
  4223. ucn->FloatValue = Value;
  4224. return ucn;
  4225. }
  4226. laUiConditionNode *laStringExpression(char *Content){
  4227. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4228. ucn->Type = LA_CONDITION_STRING;
  4229. strSafeSet(&ucn->String, Content);
  4230. return ucn;
  4231. }
  4232. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4233. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4234. ucn->Type = LA_CONDITION_AND;
  4235. ucn->Expression1 = Expression1;
  4236. ucn->Expression2 = Expression2;
  4237. return ucn;
  4238. }
  4239. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4240. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4241. ucn->Type = LA_CONDITION_OR;
  4242. ucn->Expression1 = Expression1;
  4243. ucn->Expression2 = Expression2;
  4244. return ucn;
  4245. }
  4246. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4247. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4248. ucn->Type = LA_CONDITION_NOT;
  4249. ucn->Expression1 = Expression1;
  4250. return ucn;
  4251. }
  4252. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4253. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4254. ucn->Type = LA_CONDITION_EQ;
  4255. ucn->Expression1 = Expression1;
  4256. ucn->Expression2 = Expression2;
  4257. return ucn;
  4258. }
  4259. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4260. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4261. ucn->Type = LA_CONDITION_GT;
  4262. ucn->Expression1 = Expression1;
  4263. ucn->Expression2 = Expression2;
  4264. return ucn;
  4265. }
  4266. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4267. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4268. ucn->Type = LA_CONDITION_LT;
  4269. ucn->Expression1 = Expression1;
  4270. ucn->Expression2 = Expression2;
  4271. return ucn;
  4272. }
  4273. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4274. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4275. ucn->Type = LA_CONDITION_GE;
  4276. ucn->Expression1 = Expression1;
  4277. ucn->Expression2 = Expression2;
  4278. return ucn;
  4279. }
  4280. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4281. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4282. ucn->Type = LA_CONDITION_LE;
  4283. ucn->Expression1 = Expression1;
  4284. ucn->Expression2 = Expression2;
  4285. return ucn;
  4286. }
  4287. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4288. if (Expression->Type != LA_CONDITION_INT) return 0;
  4289. return Expression->IntValue;
  4290. }
  4291. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4292. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4293. return Expression->FloatValue;
  4294. }
  4295. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4296. return Expression->String->Ptr;
  4297. }
  4298. 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){
  4299. switch (Mode1){
  4300. case LA_PROP_ENUM:
  4301. case LA_PROP_INT:
  4302. case LA_CONDITION_INT:
  4303. switch (Mode2){
  4304. case LA_PROP_ENUM:
  4305. case LA_PROP_INT:
  4306. case LA_CONDITION_INT:
  4307. switch (CompMode){
  4308. case LA_CONDITION_GE:
  4309. return (i1 >= i2);
  4310. case LA_CONDITION_GT:
  4311. return (i1 > i2);
  4312. case LA_CONDITION_EQ:
  4313. return (i1 == i2);
  4314. case LA_CONDITION_LT:
  4315. return (i1 < i2);
  4316. case LA_CONDITION_LE:
  4317. return (i1 <= i2);
  4318. }
  4319. case LA_PROP_FLOAT:
  4320. case LA_CONDITION_FLOAT:
  4321. switch (CompMode){
  4322. case LA_CONDITION_GE:
  4323. return ((real)i1 >= f2);
  4324. case LA_CONDITION_GT:
  4325. return ((real)i1 > f2);
  4326. case LA_CONDITION_EQ:
  4327. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4328. case LA_CONDITION_LT:
  4329. return ((real)i1 < f2);
  4330. case LA_CONDITION_LE:
  4331. return ((real)i1 <= f2);
  4332. }
  4333. case LA_PROP_SUB:
  4334. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4335. default:
  4336. return 0;
  4337. }
  4338. case LA_PROP_FLOAT:
  4339. case LA_CONDITION_FLOAT:
  4340. switch (Mode2){
  4341. case LA_PROP_INT:
  4342. case LA_PROP_ENUM:
  4343. case LA_CONDITION_INT:
  4344. switch (CompMode){
  4345. case LA_CONDITION_GE:
  4346. return (f1 >= (real)i2);
  4347. case LA_CONDITION_GT:
  4348. return (f1 > (real)i2);
  4349. case LA_CONDITION_EQ:
  4350. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4351. case LA_CONDITION_LT:
  4352. return (f1 < (real)i2);
  4353. case LA_CONDITION_LE:
  4354. return (f1 <= (real)i2);
  4355. }
  4356. case LA_PROP_FLOAT:
  4357. case LA_CONDITION_FLOAT:
  4358. switch (CompMode){
  4359. case LA_CONDITION_GE:
  4360. return (f1 >= f2);
  4361. case LA_CONDITION_GT:
  4362. return (f1 > f2);
  4363. case LA_CONDITION_EQ:
  4364. return (f1 == f2);
  4365. case LA_CONDITION_LT:
  4366. return (f1 < f2);
  4367. case LA_CONDITION_LE:
  4368. return (f1 <= f2);
  4369. }
  4370. default:
  4371. return 0;
  4372. }
  4373. case LA_PROP_STRING:
  4374. case LA_CONDITION_STRING:
  4375. switch (Mode2){
  4376. case LA_PROP_STRING:
  4377. case LA_CONDITION_STRING:
  4378. return strSame(s1, s2);
  4379. default:
  4380. return 0;
  4381. }
  4382. case LA_PROP_SUB:
  4383. switch (Mode2){
  4384. case LA_PROP_SUB:
  4385. return p1 == p2;
  4386. case LA_CONDITION_INT:
  4387. case LA_PROP_INT:
  4388. case LA_PROP_ENUM:
  4389. return (int)p1 == i2;
  4390. default:
  4391. return 0;
  4392. }
  4393. default:
  4394. switch (CompMode){
  4395. case LA_CONDITION_GE:
  4396. return (i1 >= i2);
  4397. case LA_CONDITION_GT:
  4398. return (i1 > i2);
  4399. case LA_CONDITION_EQ:
  4400. return (i1 == i2);
  4401. case LA_CONDITION_LT:
  4402. return (i1 < i2);
  4403. case LA_CONDITION_LE:
  4404. return (i1 <= i2);
  4405. }
  4406. }
  4407. }
  4408. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4409. void *Instance = 0;
  4410. int IValue1 = 0, IValue2 = 0;
  4411. real FValue1 = 0, FValue2 = 0;
  4412. void *Ptr1 = 0, *Ptr2 = 0;
  4413. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4414. int Result1, Result2;
  4415. laEnumItem *ei; laSubProp*sp;
  4416. if (!Expression) return 0;
  4417. Str1[0] = 0;
  4418. Str2[0] = 0;
  4419. laPropIterator pi = {0};
  4420. switch (Expression->Type){
  4421. case LA_CONDITION_PROP:
  4422. if (!Expression->PP.LastPs){
  4423. (*IResult) = 0;
  4424. return 0;
  4425. }
  4426. switch (Expression->PP.LastPs->p->PropertyType){
  4427. case LA_PROP_INT:
  4428. *IResult = laGetInt(&Expression->PP);
  4429. if (*IResult) return LA_CONDITION_INT;
  4430. else return 0;
  4431. case LA_PROP_FLOAT:
  4432. *FResult = laGetFloat(&Expression->PP);
  4433. if (*FResult) return 1;
  4434. else return 0;
  4435. break;
  4436. case LA_PROP_STRING:
  4437. laGetString(&Expression->PP, _StrResult, &StrResult);
  4438. if (StrResult[0]) return 1;
  4439. else return 0;
  4440. break;
  4441. case LA_PROP_ENUM:
  4442. ei = laGetEnum(&Expression->PP);
  4443. if (!ei) return 0;
  4444. /*if(ei) */ *IResult = ei->Index;
  4445. if (*IResult) return LA_CONDITION_INT;
  4446. else return 0;
  4447. break;
  4448. case LA_PROP_SUB:
  4449. sp=Expression->PP.LastPs->p;
  4450. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4451. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4452. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4453. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4454. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4455. }
  4456. }
  4457. *PtrResult = Instance;
  4458. if (Instance) return 1;
  4459. break;
  4460. default:
  4461. return 0;
  4462. }
  4463. break;
  4464. case LA_CONDITION_INT:
  4465. *IResult = Expression->IntValue;
  4466. if (*IResult) return 1;
  4467. else
  4468. return 0;
  4469. case LA_CONDITION_FLOAT:
  4470. *FResult = Expression->FloatValue;
  4471. if (*FResult) return 1;
  4472. else
  4473. return 0;
  4474. case LA_CONDITION_STRING:
  4475. if (Expression->String){
  4476. strCopyFull(StrResult, Expression->String->Ptr);
  4477. return 1;
  4478. }else
  4479. return 0;
  4480. case LA_CONDITION_TRUE:
  4481. if (*IResult) *IResult = 1;
  4482. return 1;
  4483. case LA_CONDITION_FALSE:
  4484. if (*IResult) *IResult = 0;
  4485. return 0;
  4486. default:
  4487. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4488. switch (Expression->Type){
  4489. case LA_CONDITION_AND:
  4490. if (Result1){
  4491. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4492. if (Result2) *IResult = 1;
  4493. return (Result2);
  4494. }else
  4495. return 0;
  4496. case LA_CONDITION_OR:
  4497. if (!Result1){
  4498. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4499. if (Result2) *IResult = 1;
  4500. return (Result2);
  4501. }else
  4502. return 1;
  4503. case LA_CONDITION_NOT:
  4504. return !Result1;
  4505. default:
  4506. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4507. return la_DoCompare(Expression->Type,
  4508. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4509. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4510. }
  4511. break;
  4512. }
  4513. return 0;
  4514. }
  4515. int la_DoSingleExpression(laUiConditionNode *Expression){
  4516. int a;
  4517. real b;
  4518. char c[128]={0};
  4519. void *p;
  4520. if (!Expression) return 1;
  4521. c[0] = 0;
  4522. return la_DoExpression(Expression, &a, &b, c, &p);
  4523. }
  4524. void la_StepExpression(laUiConditionNode *e){
  4525. if (!e) return;
  4526. switch (e->Type){
  4527. case LA_CONDITION_AND:
  4528. case LA_CONDITION_OR:
  4529. case LA_CONDITION_GE:
  4530. case LA_CONDITION_GT:
  4531. case LA_CONDITION_EQ:
  4532. case LA_CONDITION_LT:
  4533. case LA_CONDITION_LE:
  4534. la_StepExpression(e->Expression1);
  4535. la_StepExpression(e->Expression2);
  4536. break;
  4537. case LA_CONDITION_NOT:
  4538. la_StepExpression(e->Expression1);
  4539. break;
  4540. case LA_CONDITION_PROP:
  4541. la_StepPropPack(&e->PP);
  4542. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4543. la_UsePropPack(&e->PP, 1);
  4544. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4545. //}
  4546. break;
  4547. default:
  4548. break;
  4549. }
  4550. }
  4551. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4552. if (!ucn) return;
  4553. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4554. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4555. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4556. if (ucn->String) strSafeDestroy(&ucn->String);
  4557. if (ucn) memFree(ucn);
  4558. }
  4559. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4560. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4561. ui->C = c;
  4562. ui->Type = &_LA_UI_CONDITION;
  4563. la_ConditionerInit(ui, Expression);
  4564. lstAppendItem(&uil->UiItems, ui);
  4565. return ui;
  4566. }
  4567. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4568. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4569. laConditionUiExtraData *cued;
  4570. ui->Type = &_LA_UI_CONDITION_ELSE;
  4571. la_ConditionerInit(ui, 0);
  4572. cued = ui->Extra;
  4573. cued->EndUi = Beginner;
  4574. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4575. ui->C = Beginner->C;
  4576. lstAppendItem(&uil->UiItems, ui);
  4577. return ui;
  4578. }
  4579. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4580. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4581. laConditionUiExtraData *cued;
  4582. ui->Template = define;
  4583. ui->C = col;
  4584. ui->PP.RawThis = ExtraBase;
  4585. ui->Page = ExtraThis;
  4586. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4587. la_ConditionerInit(ui, 0);
  4588. cued = ui->Extra;
  4589. //cued->Remove = Remove;
  4590. ui->State = LA_UI_NORMAL;
  4591. lstAppendItem(&uil->UiItems, ui);
  4592. return ui;
  4593. }
  4594. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4595. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4596. laConditionUiExtraData *cued;
  4597. ui->Type = &_LA_UI_CONDITION_END;
  4598. la_ConditionerInit(ui, 0);
  4599. cued = ui->Extra;
  4600. cued->EndUi = Beginner;
  4601. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4602. ui->C = Beginner->C;
  4603. lstAppendItem(&uil->UiItems, ui);
  4604. return ui;
  4605. }
  4606. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4607. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4608. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4609. ui->Type = _LA_UI_MENU_ROOT;
  4610. strSafeSet(&ui->Display, Title);
  4611. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4612. ui->C = c;
  4613. lstAppendItem(&uil->UiItems, ui);
  4614. lstAppendItem(&ui->Subs, muil);
  4615. return muil;
  4616. }
  4617. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4618. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4619. ui->Type = _LA_UI_ALIGN;
  4620. ui->C = widest;
  4621. lstAppendItem(&uil->UiItems, ui);
  4622. return ui;
  4623. }
  4624. void laFixHeight(laUiList *uil, short Rows){
  4625. if (!uil) return;
  4626. uil->HeightCoeff = Rows;
  4627. }
  4628. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4629. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4630. if (!ExtraColumns) return;
  4631. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4632. }
  4633. laUiTemplate *laFindUiTemplate(char *Identifier){
  4634. laUiTemplate *uit;
  4635. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4636. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4637. }
  4638. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4639. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4640. }
  4641. return 0;
  4642. }
  4643. void la_DestroyUiTemplate(laUiTemplate* uit){
  4644. strSafeDestroy(&uit->Identifier);
  4645. strSafeDestroy(&uit->Title);
  4646. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4647. memFree(uit);
  4648. }
  4649. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4650. strSafeDestroy(&uit->Identifier);
  4651. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4652. memFree(uit);
  4653. }
  4654. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4655. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4656. strSafeSet(&uit->Identifier, Identifier);
  4657. strSafeSet(&uit->Title, Title);
  4658. strSafeSet(&uit->CategoryName, NewCategory);
  4659. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4660. uit->DefaultGLFormat=DefaultGLFormat;
  4661. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4662. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4663. la_UDFAppendSharedTypePointer(Identifier, uit);
  4664. return uit;
  4665. }
  4666. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4667. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4668. strSafeSet(&t->Identifier, Identifier);
  4669. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4670. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4671. lstAppendItem(&MAIN.View2DTemplates, t);
  4672. la_UDFAppendSharedTypePointer(Identifier, t);
  4673. return t;
  4674. }
  4675. void laFinalizeUiTemplates(){
  4676. laUiTemplate *uit;
  4677. laCanvasTemplate *u2d;
  4678. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4679. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4680. }
  4681. }
  4682. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4683. laPanel *p;
  4684. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4685. if (p->PanelTemplate==uit){
  4686. return p;
  4687. }
  4688. }
  4689. return 0;
  4690. }
  4691. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4692. laUiList *uil, *NextUil;
  4693. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4694. NextUil = uil->Item.pNext;
  4695. lstRemoveItem(&ui->Subs, uil);
  4696. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4697. }
  4698. la_StopUiOperatorService(ui);
  4699. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4700. strSafeDestroy(&ui->Display);
  4701. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4702. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4703. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4704. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4705. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4706. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4707. }
  4708. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4709. memFree(ui);
  4710. }
  4711. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4712. laUiItem *ui, *NextUi;
  4713. laColumn *col, *NextCol;
  4714. if (!uil) return;
  4715. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4716. NextUi = ui->Item.pNext;
  4717. if(OnlyRemoveUser && RemoveUsers){
  4718. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4719. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4720. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4721. continue;
  4722. }
  4723. lstRemoveItem(&uil->UiItems, ui);
  4724. la_DestroyUiItem(ui, RemoveUsers);
  4725. }
  4726. if(OnlyRemoveUser){ return; }
  4727. for (col = uil->Columns.pFirst; col; col = NextCol){
  4728. NextCol = col->Item.pNext;
  4729. lstRemoveItem(&uil->Columns, col);
  4730. memFree(col);
  4731. }
  4732. strSafeDestroy(&uil->TabName);
  4733. if (!NoFree) memFree(uil);
  4734. }
  4735. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4736. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4737. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4738. }
  4739. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4740. laUiItem *Next = after->Item.pNext;
  4741. laUiItem *Last = uil->UiItems.pLast;
  4742. after->Item.pNext = 0;
  4743. uil->UiItems.pLast = after;
  4744. Define(uil, Base, This, ExtraColums, 0);
  4745. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4746. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4747. if (Next != Last) uil->UiItems.pLast = Last;
  4748. }
  4749. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4750. // int i = 0;
  4751. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4752. // if (!ui->ExtraColums) return;
  4753. // for (i; ui->ExtraColums[i]; i++) {
  4754. // laColumn* c = ui->ExtraColums[i];
  4755. // c->B = B;
  4756. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4757. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4758. // }
  4759. //}
  4760. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4761. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4762. }
  4763. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4764. laColumn *c = ui->C;
  4765. laColumn *ic = lst->pFirst;
  4766. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4767. for (ic; ic; ic = ic->Item.pNext){
  4768. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4769. ic->B = ic->B < c->B ? c->B : ic->B;
  4770. }
  4771. }
  4772. ic = ui->C;
  4773. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4774. ;
  4775. for (ic; ic; ic = ic->Item.pNext){
  4776. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4777. ic->B = ic->B < c->B ? c->B : ic->B;
  4778. }
  4779. }
  4780. }
  4781. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4782. laColumn *c = ui->C;
  4783. laColumn *ic = lst->pFirst;
  4784. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4785. for (ic; ic; ic = ic->Item.pNext){
  4786. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4787. ic->B = ic->B < c->B ? c->B : ic->B;
  4788. }
  4789. }
  4790. ic = ui->C;
  4791. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4792. ;
  4793. for (ic; ic; ic = ic->Item.pNext){
  4794. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4795. ic->B = ic->B < c->B ? c->B : ic->B;
  4796. }
  4797. }
  4798. }
  4799. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4800. int rep;
  4801. int sp;
  4802. int rev;
  4803. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4804. if (!c) return 0;
  4805. sp = (c->SP * (R - L)) + L;
  4806. rev = sp;
  4807. /*if (U)*/ c->B = U;
  4808. if (LR == 1){
  4809. c->IL = L;
  4810. c->IR = sp;
  4811. if (repos){
  4812. c->IR = repos;
  4813. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4814. c->IR = c->IL + c->MaxW*LA_RH+M;
  4815. rev = c->IR;
  4816. }
  4817. }else if (LR == 2){
  4818. c->IL = sp;
  4819. c->IR = R;
  4820. if (repos){
  4821. c->IL = repos;
  4822. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4823. c->IL = c->IR - c->MaxW*LA_RH-M;
  4824. rev = c->IL;
  4825. }
  4826. }else if (LR == 0){
  4827. c->IL = L;
  4828. c->IR = R;
  4829. }
  4830. if (c->LS && c->RS->MaxW == 0){
  4831. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4832. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4833. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4834. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4835. }else if (c->RS && c->LS->MaxW == 0){
  4836. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4837. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4838. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4839. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4840. }
  4841. return rev;
  4842. }
  4843. STRUCTURE(laRowInfo){
  4844. int MaxW;
  4845. int MinW;
  4846. int UnitMinW;
  4847. int NonExpandW;
  4848. int TotalPadding;
  4849. int Expand, Even;
  4850. int ExpandAccum;
  4851. int CountElements;
  4852. int U,MaxB,L;
  4853. laListHandle Elements;
  4854. int LastNoHeight;
  4855. };
  4856. STRUCTURE(laRowNode){
  4857. laListItem Item;
  4858. laUiItem* ui;
  4859. int GotW, LP, RP, H;
  4860. int Expand;
  4861. int UseLast;
  4862. int WaitAnimation;
  4863. };
  4864. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4865. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4866. ri->UnitMinW=LA_RH;
  4867. ri->Expand=ui->State?1:0;
  4868. ri->Even=ui->Flags?1:0;
  4869. ri->U=ui->TU; ri->L=ui->TL;
  4870. ri->MaxB=ui->TU;
  4871. }
  4872. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  4873. laRowNode* rn=CreateNew(laRowNode);
  4874. rn->LP=bt->LP;rn->RP=bt->RP;
  4875. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4876. rn->ui=ui;
  4877. rn->H=H;
  4878. rn->Expand=ui->Expand;
  4879. rn->WaitAnimation=WaitAnimation;
  4880. lstAppendItem(&ri->Elements, rn);
  4881. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4882. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4883. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4884. ri->TotalPadding += (bt->LP+bt->RP);
  4885. ri->MinW+=ri->UnitMinW;
  4886. ri->NonExpandW+=rn->GotW;
  4887. ri->ExpandAccum+=ui->Expand;
  4888. ri->CountElements++;
  4889. if(ui->Expand){ri->Expand=1;}
  4890. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4891. }
  4892. int la_ShrinkableRowElements(laRowInfo* ri){
  4893. int count=0;
  4894. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4895. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4896. count++;
  4897. }
  4898. return count;
  4899. }
  4900. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4901. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  4902. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4903. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4904. if(Available<0){
  4905. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4906. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4907. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4908. }else{
  4909. if(!ri->Expand && Available>0){Available=0;}
  4910. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4911. }
  4912. if(!ShareCount) return 0;
  4913. int PerNode = Available/ShareCount;
  4914. int Remaining = Available-PerNode*ShareCount;
  4915. int L = ri->L; int i=0; laRowNode* rn;
  4916. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4917. laUiItem* ui=rn->ui;
  4918. int NodeAdd, Node=rn->GotW;
  4919. if(rn->UseLast){
  4920. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4921. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4922. continue;
  4923. }
  4924. if(Available>=0){
  4925. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4926. NodeAdd+=(i<Remaining?1:0);i++;
  4927. }else{
  4928. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4929. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4930. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4931. }else{ Node=ri->UnitMinW;
  4932. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4933. }
  4934. }
  4935. ui->TL = L + rn->LP;
  4936. ui->TR = ui->TL + Node+NodeAdd;
  4937. ui->TB = ui->TU + rn->H;
  4938. L=ui->TR+rn->RP;
  4939. if (!rn->WaitAnimation){
  4940. ui->L = ui->TL; ui->R = ui->TR;
  4941. ui->U = ui->TU; ui->B = ui->TB;
  4942. }
  4943. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4944. }
  4945. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  4946. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  4947. memset(ri, 0, sizeof(laRowInfo));
  4948. }
  4949. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4950. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4951. int sl,sr,su,sb;
  4952. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4953. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4954. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4955. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4956. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4957. if(pc==LA_PC_SOCKET_OUT){
  4958. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4959. }else{
  4960. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4961. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4962. }
  4963. }
  4964. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4965. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4966. }
  4967. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4968. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4969. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4970. laBoxedTheme *bt;
  4971. int Lowest = 0;
  4972. int HyperValue = 0;
  4973. int WaitAnimation;
  4974. int RowMode=0; laRowInfo ri={0};
  4975. laBoxedTheme* pt=*(ParentPanel->BT);
  4976. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4977. int MaxR=0;
  4978. if(!uil->Scale){uil->Scale=1;}
  4979. uil->SaveScale=MAIN.UiScale;
  4980. MAIN.UiScale*=uil->Scale;
  4981. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4982. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4983. WaitAnimation = 0;
  4984. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4985. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4986. for (ui = uil->UiItems.pFirst; ui;){
  4987. int SubB = 0;
  4988. int H;
  4989. WaitAnimation = 0;
  4990. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4991. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4992. //if (Fast && ui->C->B > B) {
  4993. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4994. // ui = ui->Item.pNext;
  4995. // continue;
  4996. //}
  4997. if (!ui->Instructions){
  4998. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4999. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  5000. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  5001. laOperatorProp *ap = ui->PP.LastPs->p;
  5002. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5003. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5004. }
  5005. }
  5006. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5007. la_UsePropPack(&ui->PP, 0);
  5008. if (ui->CompoundPPs.pFirst){
  5009. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5010. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5011. }
  5012. }
  5013. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5014. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5015. // 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);
  5016. //}
  5017. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5018. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5019. WaitAnimation = 1;
  5020. }
  5021. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5022. bt = (*ui->Type->Theme);
  5023. if (ui->Type == &_LA_UI_CONDITION){
  5024. laConditionUiExtraData *cued = ui->Extra;
  5025. la_StepExpression(cued->Expression);
  5026. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5027. if (!cued->IsTrue){
  5028. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5029. }else{
  5030. ui = ui->Item.pNext;
  5031. }
  5032. continue;
  5033. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5034. ui = ui->Item.pNext;
  5035. continue;
  5036. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5037. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5038. if (cued->IsTrue) ui = cued->EndUi;
  5039. else
  5040. ui = ui->Item.pNext;
  5041. continue;
  5042. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5043. laConditionUiExtraData *cued = ui->Extra;
  5044. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5045. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5046. if (!WaitAnimation){
  5047. ui->L = ui->TL; ui->R = ui->TR;
  5048. ui->U = ui->TU; ui->B = ui->TB;
  5049. }
  5050. if(!RowMode){
  5051. la_CalcUiItemInfluence(&uil->Columns, ui);
  5052. }else{
  5053. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5054. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5055. }
  5056. if (ui->State == LA_UI_NORMAL){
  5057. cued->IsTrue = 0;
  5058. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5059. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5060. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5061. }else{
  5062. cued->IsTrue = 1;
  5063. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5064. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5065. //}
  5066. ui = ui->Item.pNext;
  5067. }
  5068. continue;
  5069. }
  5070. if (ui->Type == _LA_UI_ALIGN){
  5071. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5072. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5073. if (ui->TB > Lowest) Lowest = ui->TB;
  5074. if (!WaitAnimation){
  5075. ui->L = ui->TL; ui->R = ui->TR;
  5076. ui->U = ui->TU; ui->B = ui->TB;
  5077. }
  5078. if(!RowMode){
  5079. la_CalcUiItemInfluence(&uil->Columns, ui);
  5080. }else{
  5081. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5082. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5083. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5084. }
  5085. ui = ui->Item.pNext; continue;
  5086. }
  5087. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5088. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5089. la_InitRowNode(&ri, ui, bt);
  5090. RowMode=1; ui=ui->Item.pNext; continue;
  5091. }
  5092. if (ui->Type == &_LA_UI_ROW_END){
  5093. la_CalculateRowExpand(&ri, ui);
  5094. la_CalcUiItemInfluence(&uil->Columns, ui);
  5095. RowMode=0; ui=ui->Item.pNext; continue;
  5096. }
  5097. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5098. int GB=0;
  5099. 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; }
  5100. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5101. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5102. if (H < 0){
  5103. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5104. else{ H=LA_RH; }
  5105. }
  5106. else H *= LA_RH;
  5107. ui->TB = ui->TU;
  5108. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5109. 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
  5110. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5111. if (ui->Type == _LA_UI_COLLECTION){
  5112. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5113. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5114. ui->PP.EndInstance = TInstance;
  5115. laUiList *iuil = ui->Subs.pFirst;
  5116. laUiList *puil = iuil;
  5117. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5118. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5119. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5120. int Begin = ui->TB;
  5121. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5122. int ElementB = ui->TU;
  5123. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5124. int MaxB = ElementB;
  5125. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5126. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5127. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5128. if (!ElementLimit) RowPriority = 0;
  5129. if (!TInstance){
  5130. while (iuil){
  5131. puil = iuil->Item.pNext;
  5132. la_DestroyTabPage(ui, iuil, 0);
  5133. iuil = puil;
  5134. }
  5135. }
  5136. while (TInstance){
  5137. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  5138. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5139. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5140. ui->PP.EndInstance = TInstance; continue;
  5141. }
  5142. if(CanGetTheme){
  5143. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5144. la_SwitchThemeQuick(t, OriginalTheme);
  5145. }
  5146. if(CanGetGap){
  5147. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5148. Gap=g*LA_RH;
  5149. }else Gap=0;
  5150. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5151. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5152. }else GotCategory=0;
  5153. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5154. if (RowPriority){
  5155. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5156. }
  5157. }
  5158. FirstIn=0;
  5159. if (ElementLimit){
  5160. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5161. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5162. }
  5163. while (iuil && iuil->Instance != TInstance){
  5164. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5165. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5166. }else{
  5167. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5168. }
  5169. iuil = puil;
  5170. }
  5171. if(!iuil){
  5172. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5173. }
  5174. if (!iuil){
  5175. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5176. la_CalcUiTopInfluence(&uil->Columns, ui);
  5177. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5178. 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);
  5179. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5180. iuil = ui->Page->Item.pNext;
  5181. }else{
  5182. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5183. 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);
  5184. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5185. la_CalcUiItemInfluence(&uil->Columns, ui);
  5186. iuil = iuil->Item.pNext;
  5187. }
  5188. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5189. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5190. ui->PP.EndInstance = TInstance;
  5191. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5192. if (RowPriority){
  5193. Col += 1;
  5194. if (Col >= ElementLimit){
  5195. Col = 0;
  5196. Row += 1;
  5197. Begin = ElementB + bt->TM;
  5198. }
  5199. }elif(Spread){
  5200. EL+=Spread*LA_RH;
  5201. ER+=Spread*LA_RH;
  5202. }else{
  5203. Row += 1;
  5204. Begin = ElementB + bt->TM;
  5205. if (ElementLimit && Row >= ElementLimit){
  5206. Row = 0;
  5207. Col += 1;
  5208. Begin = ui->TU + bt->TM;
  5209. }
  5210. }
  5211. ui->TB = ElementB;
  5212. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5213. }
  5214. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5215. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5216. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5217. ui->TB = MaxB;
  5218. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5219. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5220. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5221. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5222. ui->TB=ui->TU+LA_RH;
  5223. }else{
  5224. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5225. ui->PP.EndInstance = TInstance;
  5226. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5227. if(!Template) Template=laui_SubPropInfoDefault;
  5228. //ui->Template = Template;
  5229. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5230. if (!ui->Subs.pFirst && TInstance){
  5231. la_AddInstancePage(ui, TInstance, 0);
  5232. la_CalcUiTopInfluence(&uil->Columns, ui);
  5233. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5234. 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);
  5235. ui->TB = SubB + (NoDecal?0:bt->BM);
  5236. }else if (ui->Subs.pFirst){
  5237. if (!TInstance || TInstance != ui->Page->Instance){
  5238. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5239. ui->Page = 0;
  5240. if (TInstance){
  5241. la_AddInstancePage(ui, TInstance, 0);
  5242. la_CalcUiTopInfluence(&uil->Columns, ui);
  5243. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5244. 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);
  5245. ui->TB = SubB + (NoDecal?0:bt->TM);
  5246. }else
  5247. ui->TB = ui->TU + LA_RH + bt->BM;
  5248. }else{
  5249. 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);
  5250. ui->TB = SubB + (NoDecal?0:bt->BM);
  5251. }
  5252. }
  5253. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5254. ui->TB=ui->TU+LA_RH;
  5255. }
  5256. }
  5257. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5258. if (!WaitAnimation){
  5259. ui->L = ui->TL;
  5260. ui->R = ui->TR;
  5261. ui->U = ui->TU;
  5262. ui->B = ui->TB;
  5263. }
  5264. }
  5265. }else{
  5266. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5267. if (ui->Type != _LA_UI_CANVAS){
  5268. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5269. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5270. SubB = la_UpdateUiListRecursive(ui->Page,
  5271. 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);
  5272. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5273. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5274. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5275. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5276. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5277. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5278. }
  5279. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5280. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5281. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5282. if(ui->Page->HeightCoeff){
  5283. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5284. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5285. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5286. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5287. }
  5288. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5289. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5290. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5291. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5292. }
  5293. }
  5294. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5295. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5296. }else{
  5297. laUiList *suil;
  5298. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5299. la_CalcUiTopInfluence(&uil->Columns, ui);
  5300. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5301. 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);
  5302. }
  5303. }
  5304. ui->TB = ui->TU + H;
  5305. }
  5306. }else ui->TB = ui->TU + H;
  5307. }
  5308. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5309. if(!RowMode){
  5310. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5311. }else{
  5312. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5313. }
  5314. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5315. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5316. ui = ui->Item.pNext;
  5317. }
  5318. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5319. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5320. else uil->TB = Lowest;
  5321. if (!WaitAnimation){
  5322. uil->L = uil->TL;
  5323. uil->R = uil->TR;
  5324. uil->U = uil->TU;
  5325. uil->B = uil->TB;
  5326. }
  5327. MAIN.UiScale=uil->SaveScale;
  5328. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5329. return uil->TB;
  5330. }
  5331. int la_AnimateSingleUiSize(int To, int *Now){
  5332. int Delta;
  5333. if (To != *Now){
  5334. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5335. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5336. *Now += Delta;
  5337. return 1;
  5338. }else
  5339. return 0;
  5340. }
  5341. int la_AnimateUiListRecursive(laUiList *uil){
  5342. laUiItem *ui;
  5343. int Again = 0;
  5344. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5345. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5346. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5347. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5348. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5349. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5350. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5351. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5352. laUiList *suil;
  5353. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5354. Again += la_AnimateUiListRecursive(suil);
  5355. }
  5356. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5357. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5358. Again += la_AnimateUiListRecursive(ui->Page);
  5359. }
  5360. }
  5361. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5362. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5363. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5364. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5365. return Again;
  5366. }
  5367. int la_DrawUiItem(laUiItem *ui){
  5368. tnsUseNoTexture();
  5369. tnsColor4d(1, 1, 1, 1);
  5370. tnsVertex2d(ui->L, ui->U);
  5371. tnsVertex2d(ui->R, ui->U);
  5372. tnsVertex2d(ui->R, ui->B);
  5373. tnsVertex2d(ui->L, ui->B);
  5374. tnsPackAs(GL_LINE_LOOP);
  5375. }
  5376. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5377. tnsUseNoTexture();
  5378. tnsColor4d(1, 1, 1, 1);
  5379. tnsVertex2d(ui->L - 1, ui->U - 1);
  5380. tnsVertex2d(ui->R + 1, ui->U - 1);
  5381. tnsVertex2d(ui->R + 1, ui->B + 1);
  5382. tnsVertex2d(ui->L - 1, ui->B + 1);
  5383. tnsPackAs(GL_LINE_LOOP);
  5384. }
  5385. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5386. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5387. return 1;
  5388. }
  5389. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5390. laUiListDrawItem *uildi = uild->Items.pFirst;
  5391. laUiList *Target = uildi->Target;
  5392. int L, R, U, B;
  5393. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5394. L = Target->L + Target->PanX + uildi->DifX;
  5395. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5396. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5397. U = Target->U + Target->PanY + uildi->DifY;
  5398. return la_UiInBound(ui, L, R, U, B);
  5399. }
  5400. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5401. laUiListDrawItem *uildi = uild->Items.pFirst;
  5402. laUiList *Target = uildi->Target;
  5403. int L, R, U, B;
  5404. if (Target){
  5405. L = Target->L + Target->PanX + uildi->DifX;
  5406. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5407. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5408. U = Target->U + Target->PanY + uildi->DifY;
  5409. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5410. return 1;
  5411. }else{
  5412. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5413. return 1;
  5414. }
  5415. }
  5416. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5417. laUiItem *ui = uil->UiItems.pFirst;
  5418. while (!strGetArgument(ui->Instructions, mark))
  5419. ui = ui->Item.pNext;
  5420. return ui;
  5421. }
  5422. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5423. laUiList *uil;
  5424. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5425. if (uil->Instance == Instance) return uil;
  5426. }
  5427. return uil;
  5428. }
  5429. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5430. int mx=(L+R)/2; int my=(U+B)/2;
  5431. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5432. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5433. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5434. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5435. tnsFlush();
  5436. }
  5437. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5438. if(!uil->ScrollerShownV) return;
  5439. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5440. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5441. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5442. int U = uil->U + Offset;
  5443. int B = U + Len;
  5444. int L = UiR - RM*2 - W;
  5445. int R = L + W;
  5446. if (B > U + DisplayH) B = U + DisplayH;
  5447. if (U < uil->U) U = uil->U;
  5448. if (B <= uil->U || U >= uil->B) return;
  5449. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5450. if (U < uil->U) U = uil->U;
  5451. tnsUseNoTexture();
  5452. laBoxedTheme* bt=_LA_THEME_PANEL;
  5453. real* color=laThemeColor(bt, LA_BT_TEXT);
  5454. tnsColor4d(LA_COLOR3(color), 0.2);
  5455. tnsVertex2d(R-RM, uil->U);
  5456. tnsVertex2d(L+RM, uil->U);
  5457. tnsVertex2d(L+RM, uil->U + DisplayH);
  5458. tnsVertex2d(R-RM, uil->U + DisplayH);
  5459. tnsPackAs(GL_TRIANGLE_FAN);
  5460. tnsColor4d(LA_COLOR3(color), 0.5);
  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_LINE_LOOP);
  5466. tnsColor4d(LA_COLOR3(color), 1);
  5467. tnsVertex2d(R, U);
  5468. tnsVertex2d(L, U);
  5469. tnsVertex2d(L, B);
  5470. tnsVertex2d(R, B);
  5471. tnsPackAs(GL_TRIANGLE_FAN);
  5472. int HU=(U+B)/2+LA_RH2;
  5473. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5474. tnsFlush();
  5475. }
  5476. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5477. if(!uil->ScrollerShownH) return;
  5478. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5479. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5480. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5481. int L = uil->L + Offset;
  5482. int R = L + Len;
  5483. int U = UiB - RM - W;
  5484. int B = U + W;
  5485. if (B > U + DisplayW) B = U + DisplayW;
  5486. if (U < uil->U) U = uil->U;
  5487. if (R <= uil->L || L >= uil->R) return;
  5488. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5489. if (L < uil->L) L = uil->L;
  5490. tnsUseNoTexture();
  5491. laBoxedTheme* bt=_LA_THEME_PANEL;
  5492. real* color=laThemeColor(bt, LA_BT_TEXT);
  5493. tnsColor4d(LA_COLOR3(color), 0.2);
  5494. tnsVertex2d(uil->L,U+RM);
  5495. tnsVertex2d(uil->L,B-RM);
  5496. tnsVertex2d(uil->L + DisplayW,B-RM);
  5497. tnsVertex2d(uil->L + DisplayW,U+RM);
  5498. tnsPackAs(GL_TRIANGLE_FAN);
  5499. tnsColor4d(LA_COLOR3(color), 0.5);
  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_LINE_LOOP);
  5505. tnsColor4d(LA_COLOR3(color), 1);
  5506. tnsVertex2d(R, U);
  5507. tnsVertex2d(L, U);
  5508. tnsVertex2d(L, B);
  5509. tnsVertex2d(R, B);
  5510. tnsPackAs(GL_TRIANGLE_FAN);
  5511. int HU=(U+B)/2+LA_RH2;
  5512. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5513. tnsFlush();
  5514. }
  5515. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5516. tnsUseNoTexture();
  5517. tnsColor4dv(color);
  5518. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5519. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5520. tnsPackAs(GL_TRIANGLE_FAN);
  5521. }
  5522. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5523. laSocketRecord* sr;
  5524. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5525. uild->WiresContainer=container;
  5526. }
  5527. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5528. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5529. if(lip->Target==uild->WiresContainer) break;
  5530. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5531. }
  5532. }
  5533. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5534. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5535. int PanX, PanY;
  5536. if(pc==LA_PC_SOCKET_OUT){
  5537. laNodeOutSocket* s=ui->PP.EndInstance;
  5538. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5539. }else{
  5540. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5541. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5542. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5543. }
  5544. }
  5545. void la_RegenerateWireColors(){
  5546. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5547. laTheme* t=MAIN.CurrentTheme;
  5548. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5549. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5550. for(int i=0;i<MAIN.WireColorSlices;i++){
  5551. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5552. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5553. }
  5554. }
  5555. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5556. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5557. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5558. tnsInterpolate2dv(v1,v2,0.5,vi);
  5559. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5560. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5561. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5562. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5563. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5564. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5565. tnsVertex2d(v1[0],v1[1]);
  5566. for(int i=1;i<=steps;i++){
  5567. real ratio=i==steps?1.0f:step*i;
  5568. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5569. tnsVertex2d(v1s[0],v1s[1]);
  5570. }
  5571. }
  5572. void la_DrawNodeWires(laUiListDraw* uild){
  5573. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5574. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5575. tnsUseNoTexture();
  5576. #define _RSLICES 16
  5577. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5578. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5579. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5580. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5581. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5582. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5583. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5584. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5585. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5586. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5587. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5588. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5589. }
  5590. if(MAIN.tNodeIn->Source){
  5591. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5592. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5593. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5594. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5595. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5596. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5597. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5598. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5599. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5600. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5601. }
  5602. #undef _RSLICES
  5603. tnsFlush();
  5604. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5605. glLineWidth(ww);
  5606. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5607. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5608. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5609. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5610. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5611. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5612. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5613. }
  5614. if(MAIN.tNodeIn->Source){
  5615. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5616. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5617. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5618. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5619. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5620. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5621. }
  5622. tnsFlush();
  5623. glLineWidth(1);
  5624. la_InitSocketRecord(uild,0);
  5625. }
  5626. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5627. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5628. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5629. }
  5630. 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){
  5631. laUiItem *ui;
  5632. laBoxedTheme *bt;
  5633. laUiList *sub;
  5634. laUiListDrawItem *uildi;
  5635. int Ret = 0;
  5636. if (!uil) return 0;
  5637. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5638. ui = uil->UiItems.pFirst;
  5639. if(uil->PanY<0){uil->PanY=0;}
  5640. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5641. uil->SaveScale=MAIN.UiScale;
  5642. MAIN.UiScale*=uil->Scale;
  5643. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5644. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5645. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5646. if (ui->Type == &_LA_UI_CONDITION){
  5647. laConditionUiExtraData *cued = ui->Extra;
  5648. la_StepExpression(cued->Expression);
  5649. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5650. if (!cued->IsTrue){
  5651. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5652. }else{
  5653. ui = ui->Item.pNext;
  5654. }
  5655. continue;
  5656. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5657. ui = ui->Item.pNext;
  5658. continue;
  5659. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5660. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5661. if (cued->IsTrue) ui = cued->EndUi;
  5662. else
  5663. ui = ui->Item.pNext;
  5664. continue;
  5665. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5666. laConditionUiExtraData *cued = ui->Extra;
  5667. ui->Type->Draw(ui, LA_RH);
  5668. if (ui->State == LA_UI_NORMAL){
  5669. cued->IsTrue = 0;
  5670. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5671. }else{
  5672. cued->IsTrue = 1;
  5673. ui = ui->Item.pNext;
  5674. }
  5675. continue;
  5676. }
  5677. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5678. int NeedDraw=0;
  5679. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5680. if(NeedDraw){
  5681. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5682. }else{ ui->Type->Draw(ui, LA_RH); }
  5683. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5684. tnsFlush();
  5685. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5686. tnsResetViewMatrix();
  5687. }
  5688. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5689. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5690. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5691. tnsFlush();
  5692. }
  5693. }
  5694. if(NeedDraw || RegisterNodes){
  5695. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5696. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5697. ui->Type == _LA_UI_TAB ||
  5698. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5699. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5700. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5701. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5702. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5703. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5704. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5705. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5706. 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); }
  5707. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5708. 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);
  5709. 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)); }
  5710. }elif (ui->Type == _LA_UI_COLLECTION){
  5711. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5712. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5713. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5714. void* SaveInstance = ui->PP.EndInstance;
  5715. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5716. int State;
  5717. ui->PP.EndInstance = sub->Instance;
  5718. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5719. if(NeedDraw){ int drawn=0;
  5720. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5721. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5722. }
  5723. if (CanGetState && !drawn){
  5724. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5725. if(State >= 0){
  5726. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5727. }
  5728. }
  5729. }
  5730. if(sub->TabName && sub->TabName->Ptr){
  5731. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5732. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5733. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5734. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5735. tnsFlush();
  5736. }
  5737. if(CanGetTheme){
  5738. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5739. la_SwitchThemeQuick(t, OriginalTheme);
  5740. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5741. }
  5742. tnsFlush();
  5743. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5744. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5745. }
  5746. //ui->PP.EndInstance = Active;
  5747. ui->PP.EndInstance = SaveInstance;
  5748. }elif (ui->Type == _LA_UI_CANVAS){
  5749. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5750. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5751. tnsFlush();
  5752. 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);
  5753. }
  5754. }
  5755. }
  5756. ui = ui->Item.pNext;
  5757. }else{
  5758. ui = ui->Item.pNext;
  5759. }
  5760. }
  5761. tnsFlush();
  5762. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5763. la_RestoreLastUiListMatrix(uild, B - U);
  5764. MAIN.UiScale=uil->SaveScale;
  5765. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5766. return Ret;
  5767. }
  5768. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5769. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5770. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5771. tnsUseNoTexture();
  5772. tnsColor4d(1, 1, 1, 1);
  5773. tnsVertex2d(L, U);
  5774. tnsVertex2d(R, U);
  5775. tnsVertex2d(R, B);
  5776. tnsVertex2d(L, B);
  5777. tnsPackAs(GL_LINE_LOOP);
  5778. tnsVertex2d(L + 3, Begin);
  5779. tnsVertex2d(R - 3, Begin);
  5780. tnsVertex2d(R - 3, End);
  5781. tnsVertex2d(L + 3, End);
  5782. tnsPackAs(GL_LINE_LOOP);
  5783. }
  5784. int laIsInUiItem(laUiItem *ui, int x, int y){
  5785. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5786. return 1;
  5787. }
  5788. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5789. if (x < l || x > r || y < u || y > b) return 0;
  5790. return 1;
  5791. }
  5792. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5793. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5794. laUiItem *ui, *tui;
  5795. laBoxedTheme *bt;
  5796. laUiList *sub;
  5797. int CPB = 0;
  5798. if (!uil || (LimB && y > LimB)) return 0;
  5799. x += uil->PanX;
  5800. y += uil->PanY;
  5801. for (ui = uil->UiItems.pFirst; ui;){
  5802. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5803. if (ui->Type == &_LA_UI_CONDITION){
  5804. laConditionUiExtraData *cued = ui->Extra;
  5805. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5806. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5807. if (!cued->IsTrue){
  5808. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5809. }else{
  5810. ui = ui->Item.pNext;
  5811. }
  5812. continue;
  5813. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5814. ui = ui->Item.pNext;
  5815. continue;
  5816. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5817. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5818. if (cued->IsTrue) ui = cued->EndUi;
  5819. else
  5820. ui = ui->Item.pNext;
  5821. continue;
  5822. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5823. laConditionUiExtraData *cued = ui->Extra;
  5824. if (laIsInUiItem(ui, x, y)){
  5825. lstAppendPointer(LocalBuf, uil);
  5826. return ui;
  5827. }
  5828. if (ui->State == LA_UI_NORMAL){
  5829. cued->IsTrue = 0;
  5830. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5831. }else{
  5832. cued->IsTrue = 1;
  5833. ui = ui->Item.pNext;
  5834. }
  5835. continue;
  5836. }
  5837. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5838. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5839. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5840. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5841. if(!la_DetectSplit(ui->C, x)) Add=0;
  5842. }
  5843. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5844. }
  5845. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5846. if (ui->Page->HeightCoeff) CPB = ui->B;
  5847. else CPB = ui->Page->B;
  5848. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5849. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5850. lstAppendPointer(LocalBuf, uil);
  5851. return tui;
  5852. }
  5853. }else if (laIsInUiItem(ui, x, y)){
  5854. lstAppendPointer(LocalBuf, uil);return ui;
  5855. }
  5856. }
  5857. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5858. if (laIsInUiItem(ui, x, y)){
  5859. lstAppendPointer(LocalBuf, uil);
  5860. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5861. if(Deep){
  5862. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5863. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5864. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5865. lstAppendPointer(LocalBuf, iuil);
  5866. return tui;
  5867. }
  5868. }
  5869. }
  5870. }
  5871. return ui;
  5872. }
  5873. }
  5874. if (ui->Type == _LA_UI_CANVAS){
  5875. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5876. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5877. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5878. lstAppendPointer(LocalBuf, uil);
  5879. return tui;
  5880. }
  5881. }
  5882. }
  5883. if (laIsInUiItem(ui, x, y)){
  5884. lstAppendPointer(LocalBuf, uil);
  5885. return ui;
  5886. }
  5887. }
  5888. ui = ui->Item.pNext;
  5889. }
  5890. return 0;
  5891. }
  5892. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5893. laListHandle Locals={0};
  5894. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5895. while(lstPopPointer(&Locals));
  5896. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5897. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5898. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5899. if(pc==PCInOrOut) return ui;
  5900. }
  5901. return 0;
  5902. }
  5903. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5904. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5905. laUiItem *ui = uil->UiItems.pFirst;
  5906. laBoxedTheme *bt;
  5907. laUiList *tuil;
  5908. laUiList *sub;
  5909. int CPB = 0;
  5910. x += uil->PanX;
  5911. y += uil->PanY;
  5912. if (y > LimH) return uil;
  5913. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  5914. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  5915. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5916. return uil;
  5917. }
  5918. for (ui = uil->UiItems.pFirst; ui;){
  5919. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5920. if (ui->Type == &_LA_UI_CONDITION){
  5921. laConditionUiExtraData *cued = ui->Extra;
  5922. //la_StepExpression(cued->Expression);
  5923. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5924. if (!cued->IsTrue){
  5925. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5926. }else{
  5927. ui = ui->Item.pNext;
  5928. }
  5929. continue;
  5930. }
  5931. if (ui->Type == &_LA_UI_CONDITION_END){
  5932. ui = ui->Item.pNext;
  5933. continue;
  5934. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5935. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5936. if (cued->IsTrue) ui = cued->EndUi;
  5937. else
  5938. ui = ui->Item.pNext;
  5939. continue;
  5940. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5941. laConditionUiExtraData *cued = ui->Extra;
  5942. if (ui->State == LA_UI_NORMAL){
  5943. cued->IsTrue = 0;
  5944. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5945. }else{
  5946. cued->IsTrue = 1;
  5947. ui = ui->Item.pNext;
  5948. }
  5949. continue;
  5950. }
  5951. if (InToContainerUI && ui != Exception){
  5952. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5953. if (ContainerParent) (*ContainerParent) = uil;
  5954. if (ParentUi) *ParentUi = ui;
  5955. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5956. //if (y > LimH) return uil;
  5957. 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))){
  5958. return tuil;
  5959. }
  5960. }
  5961. }
  5962. }
  5963. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5964. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  5965. else CPB = ui->Page->B;
  5966. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5967. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5968. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5969. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5970. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5971. if (ParentUi) *ParentUi = ui;
  5972. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5973. }
  5974. }
  5975. ui = ui->Item.pNext;
  5976. }
  5977. return uil;
  5978. }
  5979. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5980. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5981. laUiItem *ui = uil->UiItems.pFirst;
  5982. laBoxedTheme *bt;
  5983. laUiList *tuil;
  5984. laUiList *sub;
  5985. int CPB = 0;
  5986. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5987. x += uil->PanX;
  5988. y += uil->PanY;
  5989. if (y > LimH) return uil;
  5990. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5991. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5992. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5993. return uil;
  5994. }
  5995. for (ui = uil->UiItems.pFirst; ui;){
  5996. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5997. if (ui->Type == &_LA_UI_CONDITION){
  5998. laConditionUiExtraData *cued = ui->Extra;
  5999. //la_StepExpression(cued->Expression);
  6000. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6001. if (!cued->IsTrue){
  6002. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6003. }else{
  6004. ui = ui->Item.pNext;
  6005. }
  6006. continue;
  6007. }
  6008. if (ui->Type == &_LA_UI_CONDITION_END){
  6009. ui = ui->Item.pNext;
  6010. continue;
  6011. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6012. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6013. if (cued->IsTrue) ui = cued->EndUi;
  6014. else
  6015. ui = ui->Item.pNext;
  6016. continue;
  6017. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6018. laConditionUiExtraData *cued = ui->Extra;
  6019. if (ui->State == LA_UI_NORMAL){
  6020. cued->IsTrue = 0;
  6021. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6022. }else{
  6023. cued->IsTrue = 1;
  6024. ui = ui->Item.pNext;
  6025. }
  6026. continue;
  6027. }
  6028. if (InToContainerUI && ui != Exception){
  6029. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6030. if (ContainerParent) (*ContainerParent) = uil;
  6031. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6032. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6033. //if (y > LimH) return uil;
  6034. 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))){
  6035. return tuil;
  6036. }
  6037. }
  6038. }
  6039. }
  6040. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6041. if (ui->Page->HeightCoeff) CPB = ui->B;
  6042. else CPB = ui->Page->B;
  6043. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6044. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6045. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6046. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6047. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6048. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6049. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6050. }
  6051. }
  6052. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6053. if (ui->Page->HeightCoeff) CPB = ui->B;
  6054. else
  6055. CPB = ui->Page->B;
  6056. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6057. if (ScrollUil) *ScrollUil = ui->Page;
  6058. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6059. }
  6060. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6061. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6062. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6063. }
  6064. }
  6065. ui = ui->Item.pNext;
  6066. }
  6067. return uil;
  6068. }
  6069. int la_TestUiListMinumWidth(laUiList *uil){
  6070. laUiItem *ui, *tui;
  6071. laBoxedTheme *bt;
  6072. laUiList *sub;
  6073. int CPB = 0;
  6074. int W = 0;
  6075. int tW, sW, RowMode=0, rW;
  6076. void *Restore;
  6077. for (ui = uil->UiItems.pFirst; ui;){
  6078. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6079. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6080. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6081. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6082. if (W < tW) W = tW;
  6083. }elif (ui->Type == _LA_UI_COLLECTION){
  6084. Restore = ui->PP.EndInstance;
  6085. tW = 0; sW = 0;
  6086. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6087. ui->PP.EndInstance = sub->Instance;
  6088. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6089. if (sW > tW) tW = sW;
  6090. }
  6091. ui->PP.EndInstance = Restore;
  6092. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6093. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6094. if (W < tW) W = tW;
  6095. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6096. RowMode=1; rW=0;
  6097. }elif (ui->Type==&_LA_UI_ROW_END){
  6098. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6099. }elif (ui->Type->GetMinWidth){
  6100. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6101. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6102. }
  6103. ui = ui->Item.pNext;
  6104. }
  6105. return W;
  6106. }
  6107. void la_InitLLVM(){
  6108. //LLVMLinkInMCJIT();
  6109. //LLVMInitializeNativeTarget();
  6110. //LLVMInitializeNativeAsmPrinter();
  6111. //LLVMInitializeNativeAsmParser();
  6112. // MAIN.llvmContext = LLVMGetGlobalContext();
  6113. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6114. }
  6115. //==================================================================================================
  6116. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6117. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6118. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6119. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6120. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6121. memFree(kmi);
  6122. }
  6123. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6124. laKeyMapItem *kmi;
  6125. if (!km) return 0;
  6126. kmi = memAcquire(sizeof(laKeyMapItem));
  6127. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6128. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6129. }else{
  6130. strSafeSet(&kmi->Operation, Operation);
  6131. }
  6132. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6133. kmi->SpecialKeyBits = SpecialKeyBits;
  6134. kmi->EventType = EventType;
  6135. kmi->Key = tolowerGuarded(Key);
  6136. kmi->SelectBase = SelectBase;
  6137. lstAppendItem(&km->Items, kmi);
  6138. return kmi;
  6139. }
  6140. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6141. laKeyMapItem *kmi; int inv=0;
  6142. char *instructions;
  6143. if(e->type==LA_MOUSEMOVE) return 0;
  6144. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6145. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6146. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6147. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6148. if (kmi->Operation)
  6149. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6150. else
  6151. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6152. inv = 1;
  6153. }
  6154. }
  6155. return inv;
  6156. }
  6157. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6158. laKeyMapItem *kmi;
  6159. char *instructions;
  6160. int inv = 0; int lx = -1, ly = -1;
  6161. if(e->type==LA_MOUSEMOVE) return 0;
  6162. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6163. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6164. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6165. if (e->Localized){
  6166. lx = e->x;
  6167. ly = e->y;
  6168. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6169. e->Localized = 0;
  6170. }
  6171. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6172. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6173. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6174. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6175. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6176. }elif (kmi->Operation){
  6177. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6178. }else{
  6179. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6180. }
  6181. inv = 1;
  6182. if (lx >= 0){
  6183. e->x = lx;
  6184. e->y = ly;
  6185. e->Localized = 1;
  6186. }
  6187. }
  6188. }
  6189. return inv;
  6190. }
  6191. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6192. void la_DestroyOperatorType(laOperatorType* at){
  6193. //if(at->PC) la_FreePropertyContainer(at->PC);
  6194. memFree(at);
  6195. }
  6196. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6197. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6198. uint32_t IconID, int ExtraMark){
  6199. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6200. at->Identifier = ID;
  6201. at->Name = Name;
  6202. at->Description = Description;
  6203. at->Check = Check;
  6204. at->Invoke = Invoke;
  6205. at->Init = Init;
  6206. at->Exit = Exit;
  6207. at->Modal = Modal;
  6208. at->IconID = IconID;
  6209. at->ExtraMark = ExtraMark;
  6210. at->ParseArgs = la_DefaultOperatorParser;
  6211. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6212. return at;
  6213. }
  6214. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6215. ot->PC = memAcquire(sizeof(laPropContainer));
  6216. ot->PC->Identifier = ot->Identifier;
  6217. ot->PC->Hyper = HyperLevel;
  6218. return ot->PC;
  6219. }
  6220. laOperator *la_CreateOperator(laOperatorType *at){
  6221. laOperator *a = CreateNew(laOperator);
  6222. a->Type = at;
  6223. if (at->PC && at->PC->Props.pFirst){
  6224. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6225. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6226. a->PP.LastPs->p->SubProp = at->PC;
  6227. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6228. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6229. a->PP.LastPs->Type = U'.';
  6230. }
  6231. return a;
  6232. }
  6233. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6234. return (!strcmp(a->Identifier, id));
  6235. }
  6236. laOperatorType *laGetOperatorType(const char *ID){
  6237. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6238. }
  6239. int laOperatorExistsT(laOperatorType* at){
  6240. if (!at) return 0;
  6241. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6242. return 0;
  6243. }
  6244. int laOperatorExists(const char* ID){
  6245. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6246. return laOperatorExistsT(at);
  6247. }
  6248. int la_OperatorExists(laOperator *ac){
  6249. if (!ac) return 0;
  6250. laOperator *a;
  6251. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6252. return 0;
  6253. }
  6254. int la_UiOperatorExists(void *inst){
  6255. laOperator *a;
  6256. if (!inst) return 0;
  6257. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6258. if (((laUiItem *)a->Instance) == inst){
  6259. return 1;
  6260. }
  6261. }
  6262. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6263. if (a->Instance == inst){
  6264. return 1;
  6265. }
  6266. }
  6267. return 0;
  6268. }
  6269. int la_OperatorPending(laOperator *target){
  6270. laOperator *a;
  6271. if (!target) return 0;
  6272. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6273. if (a == target){
  6274. return 1;
  6275. }
  6276. }
  6277. return 0;
  6278. }
  6279. void laSetOperatorLocalizer(void *ToPanel){
  6280. MAIN.ToPanel = ToPanel;
  6281. }
  6282. void la_DestroyConfirmData(laConfirmData **cd);
  6283. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6284. laOperator *ai = (*a);
  6285. laOperator *ac = ((*a)->Child);
  6286. void *Ret = 0;
  6287. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6288. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6289. }
  6290. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6291. if ((*a)->PP.LastPs){
  6292. memFree((*a)->PP.LastPs->p);
  6293. memFree((*a)->PP.LastPs);
  6294. }
  6295. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6296. la_SetPropMathcerContext((*a)->OperatorPanel);
  6297. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6298. laDestroySinglePanel((*a)->OperatorPanel,0);
  6299. }
  6300. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6301. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6302. lstClearPointer(&(*a)->LocalUiLists);
  6303. if (Operators){
  6304. Ret = ai->Item.pNext;
  6305. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6306. else
  6307. lstRemoveItem(Operators, *a);
  6308. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6309. if (ai->Child == (*a)) ai->Child = 0;
  6310. }
  6311. }
  6312. strSafeDestroy(&(*a)->RuntimeHint);
  6313. free(*a);
  6314. return Ret;
  6315. }
  6316. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6317. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6318. if (!at) return 0;
  6319. if (!at->Check) return 1;
  6320. return (at->Check(This, Instructions));
  6321. }
  6322. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6323. if (!at) return 0;
  6324. if (!at->Check) return 1;
  6325. return (at->Check(This, Instructions));
  6326. }
  6327. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6328. laPropPack FakePP = {0};
  6329. laPropStep FakePs = {0};
  6330. if (!at) return 0;
  6331. if (!at->Check) return 1;
  6332. FakePP.LastPs = &FakePs;
  6333. FakePP.Go = FakePP.LastPs;
  6334. FakePP.LastPs->p = This->LastPs->p;
  6335. FakePP.LastPs->UseInstance = This->EndInstance;
  6336. FakePP.EndInstance = Real_FromInstance;
  6337. FakePP.LastIndex = This->LastIndex;
  6338. return (at->Check(&FakePP, Instructions));
  6339. }
  6340. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6341. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6342. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6343. }
  6344. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6345. laOperator *a, *f = From;
  6346. int rev;
  6347. if (!f && e&&e->Localized) return -1;
  6348. a = la_CreateOperator(at);
  6349. a->ToPanel = MAIN.ToPanel;
  6350. a->This = This;
  6351. a->ExtraInstructions = args;
  6352. strMakeInstructions(&a->ExtraInstructionsP, args);
  6353. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6354. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6355. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6356. la_DestroyOperator(&a, 0, 0);
  6357. return LA_CANCELED;
  6358. }
  6359. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6360. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6361. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6362. e->Localized = 1;
  6363. }
  6364. if (e&&e->Localized){
  6365. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6366. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6367. e->Localized = 0;
  6368. }else{
  6369. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6370. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6371. }
  6372. }
  6373. if (From) f->Child = a;
  6374. a->Using = 1;
  6375. if (at->Init) at->Init(a);
  6376. rev = at->Invoke(a, e);
  6377. a->Using = 0;
  6378. if (rev & LA_FINISH){
  6379. a->StopNow = 1; if(From)From->Child=0;
  6380. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6381. }
  6382. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6383. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6384. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6385. a->State = rev;
  6386. a->PP.EndInstance = a->CustomData;
  6387. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6388. }else
  6389. la_DestroyOperator(&a, 0, 0);
  6390. return rev;
  6391. }
  6392. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6393. laOperatorType *at; laOperator *a, *f = From;
  6394. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6395. if (!at) return -1;
  6396. return laInvokeP(From,at,e,This,args,args2);
  6397. }
  6398. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6399. laOperator *a, *f = From;
  6400. int rev;
  6401. laPropPack *created;
  6402. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6403. created = memAcquireSimple(sizeof(laPropPack));
  6404. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6405. created->Go = created->LastPs;
  6406. created->LastPs->p = OrigionalThis->LastPs->p;
  6407. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6408. created->EndInstance = FromInstance;
  6409. created->LastIndex = OrigionalThis->LastIndex;
  6410. a = la_CreateOperator(at);
  6411. a->ToPanel = MAIN.ToPanel;
  6412. a->This = created;
  6413. a->CreatedThis = created;
  6414. a->ExtraInstructions = args;
  6415. strMakeInstructions(&a->ExtraInstructionsP, args);
  6416. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6417. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6418. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6419. la_DestroyOperator(&a, 0, 0);
  6420. return LA_CANCELED;
  6421. }
  6422. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6423. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6424. if (From) f->Child = a;
  6425. a->Using = 1;
  6426. if (at->Init) at->Init(a);
  6427. rev = at->Invoke(a, e);
  6428. a->Using = 0;
  6429. if (rev & LA_FINISH){
  6430. a->StopNow = 1; if(From)From->Child=0;
  6431. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6432. }
  6433. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6434. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6435. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6436. a->State = rev;
  6437. a->PP.EndInstance = a->CustomData;
  6438. }else
  6439. la_DestroyOperator(&a, 0, 0);
  6440. return rev;
  6441. }
  6442. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6443. laOperator *a, *f = From;
  6444. int rev;
  6445. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6446. a = la_CreateOperator(at);
  6447. a->Instance = inst;
  6448. a->ToPanel = MAIN.ToPanel;
  6449. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6450. if (From) f->Child = a;
  6451. a->Using = 1;
  6452. if (at->Init) at->Init(a);
  6453. rev = at->Invoke(a, e);
  6454. a->Using = 0;
  6455. if (rev & LA_FINISH){
  6456. a->StopNow = 1; if(From)From->Child=0;
  6457. }
  6458. if (rev & LA_BLOCK){
  6459. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6460. a->State = rev;
  6461. }else la_DestroyOperator(&a, 0, 0);
  6462. DEB = a;
  6463. return rev;
  6464. }
  6465. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6466. laOperatorType *at;
  6467. laOperator *a, *f = From;
  6468. if (la_UiOperatorExists(inst)) return -1;
  6469. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6470. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6471. }
  6472. void laRequestDelayEvent(real Seconds){
  6473. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6474. int la_UiStillInService(void *UiInstance){
  6475. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6476. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6477. if (ai->Instance == UiInstance) return 1;
  6478. }
  6479. return 0;
  6480. }
  6481. void la_StopUiOperatorService(void *UiInstance){
  6482. laOperator *ai, *dai, *NextAi;
  6483. if (!MAIN.CurrentWindow) return;
  6484. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6485. NextAi = ai->Item.pNext;
  6486. if (ai->Instance == UiInstance){
  6487. if (ai->Child){
  6488. la_StopUiOperatorService(ai->Child->Instance);
  6489. ai->Child = 0;
  6490. }
  6491. laOperator *dai = ai;
  6492. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6493. continue;
  6494. }
  6495. }
  6496. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6497. NextAi = ai->Item.pNext;
  6498. if (ai->Instance == UiInstance){
  6499. if (ai->Instance == ai->ToPanel){
  6500. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6501. //ai->ToPanel->LaterDestroy = 1;
  6502. }
  6503. if (ai->Child && la_OperatorExists(ai->Child)){
  6504. la_StopUiOperatorService(ai->Child->Instance);
  6505. //ai->Child = 0;
  6506. }
  6507. if (!ai->Using){
  6508. laOperator *dai = ai;
  6509. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6510. }else
  6511. ai->StopNow = 1;
  6512. }
  6513. }
  6514. }
  6515. void la_StopAllOperators(){
  6516. laOperator *ai, *dai, *NextAi;
  6517. if (!MAIN.CurrentWindow) return;
  6518. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6519. NextAi = ai->Item.pNext;
  6520. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6521. continue;
  6522. }
  6523. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6524. NextAi = ai->Item.pNext;
  6525. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6526. laHidePanelWithDissoveEffect(ai->ToPanel);
  6527. ai->ToPanel->LaterDestroy = 1;
  6528. }
  6529. if (!ai->Using){
  6530. laOperator *dai = ai;
  6531. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6532. }else ai->StopNow = 1;
  6533. }
  6534. }
  6535. void la_DestroyConfirmData(laConfirmData **cd){
  6536. if((!cd)||!(*cd)) return;
  6537. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6538. if ((*cd)->StrData) free((*cd)->StrData);
  6539. FreeMem((*cd));
  6540. (*cd) = 0;
  6541. }
  6542. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6543. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6544. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6545. ai->NextConfirmData = cd; laRetriggerOperators();
  6546. }
  6547. void laConfirmInt(laOperator *a, int Data, int mode){
  6548. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6549. cd->IData = Data; cd->Mode = mode;
  6550. ai->NextConfirmData = cd; laRetriggerOperators();
  6551. }
  6552. void laConfirmFloat(laOperator *a, real Data, int mode){
  6553. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6554. cd->FData = Data; cd->Mode = mode;
  6555. ai->NextConfirmData = cd; laRetriggerOperators();
  6556. }
  6557. void laConfirmString(laOperator *a, char *Str, int mode){
  6558. laOperator *ai = a;
  6559. laConfirmData *cd = CreateNew(laConfirmData);
  6560. int len = strlen(Str);
  6561. char *buf = calloc(len + 1, sizeof(char));
  6562. strcpy(buf, Str);
  6563. cd->StrData = buf;
  6564. cd->Mode = mode;
  6565. cd->Destroy = free;
  6566. ai->NextConfirmData = cd;
  6567. laRetriggerOperators();
  6568. }
  6569. int laConfirmSameDataIfAny(laOperator *a){
  6570. laOperator *ai = a;
  6571. laConfirmData *cd;
  6572. char *buf = 0;
  6573. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6574. cd = CreateNew(laConfirmData);
  6575. if (ai->ConfirmData->StrData){
  6576. int len = strlen(ai->ConfirmData->StrData);
  6577. buf = calloc(len + 1, sizeof(char));
  6578. strcpy(buf, ai->ConfirmData->StrData);
  6579. }
  6580. //cd->CustomData = cd->CustomData;
  6581. cd->IData = ai->ConfirmData->IData;
  6582. cd->FData = ai->ConfirmData->FData;
  6583. cd->PointerData = ai->ConfirmData->PointerData;
  6584. cd->PointerType = a->ConfirmData->PointerType;
  6585. cd->StrData = buf;
  6586. cd->Mode = ai->ConfirmData->Mode;
  6587. cd->Destroy = ai->ConfirmData->Destroy;
  6588. ai->NextConfirmData = cd;
  6589. laRetriggerOperators();
  6590. return 1;
  6591. }
  6592. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6593. laOperator *ai = a;
  6594. laConfirmData *cd = CreateNew(laConfirmData);
  6595. cd->CustomData = UserData;
  6596. cd->Mode = mode;
  6597. cd->Destroy = Destroy;
  6598. ai->NextConfirmData = cd;
  6599. laRetriggerOperators();
  6600. }
  6601. int laGetConfirmMode(laOperator *a){
  6602. return ((laOperator *)a)->ConfirmData->Mode;
  6603. }
  6604. int laGetConfirmInt(laOperator *a){
  6605. laOperator *ai = a;
  6606. int rev = ai->ConfirmData->IData;
  6607. la_DestroyConfirmData(&ai->ConfirmData);
  6608. ai->ConfirmData = 0;
  6609. return rev;
  6610. }
  6611. real laGetConfirmFloat(laOperator *a){
  6612. laOperator *ai = a;
  6613. real rev = ai->ConfirmData->FData;
  6614. la_DestroyConfirmData(&ai->ConfirmData);
  6615. ai->ConfirmData = 0;
  6616. return rev;
  6617. }
  6618. void laGetConfirmString(laOperator *a, char *buf){
  6619. laOperator *ai = a;
  6620. strcpy(buf, ai->ConfirmData->StrData);
  6621. la_DestroyConfirmData(&ai->ConfirmData);
  6622. ai->ConfirmData = 0;
  6623. }
  6624. void *laGetConfirmUserData(laOperator *a){
  6625. laOperator *ai = a;
  6626. return ai->ConfirmData->CustomData;
  6627. }
  6628. void laFinalizeOperators(){
  6629. laOperatorType *at;
  6630. laListHandle *lst;
  6631. int i;
  6632. for (i = 0; i < 256; i++){
  6633. lst = &MAIN.OperatorTypeHash.Entries[i];
  6634. for (at = lst->pFirst; at; at = at->Item.pNext){
  6635. if (at->PC && at->PC->Props.pFirst){
  6636. lstAppendItem(&MAIN.PropContainers, at->PC);
  6637. }
  6638. }
  6639. }
  6640. }
  6641. //=================
  6642. #ifdef LA_LINUX
  6643. static void la_RecordWacomMotions(XIRawEvent *event)
  6644. {
  6645. double *valuator = event->valuators.values;
  6646. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6647. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6648. //SYSWINDOW root_return, child_return;
  6649. //int root_x_return, root_y_return;
  6650. //int win_x_return, win_y_return;
  6651. //unsigned int mask_return;
  6652. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6653. // &root_x_return, &root_y_return,
  6654. // &win_x_return, &win_y_return,
  6655. // &mask_return);
  6656. //
  6657. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6658. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6659. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6660. real x=valuator[3],y=valuator[4];
  6661. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6662. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6663. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6664. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6665. if(XIMaskIsSet(event->valuators.mask, 5)){
  6666. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6667. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6668. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6669. MAIN.IsPen=1;
  6670. }
  6671. #endif
  6672. #ifdef _WIN32
  6673. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6674. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6675. static uint32_t ch = 0; static int lead = 0;
  6676. static wchar_t buf[10] = { 0 }; int adv;
  6677. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6678. short wheelmark = 0;
  6679. int WheelDir = 0;
  6680. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6681. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6682. POINT point;
  6683. PACKET pkt;
  6684. static POINT ptOld, ptNew;
  6685. static UINT prsOld, prsNew, vkey;
  6686. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6687. switch (message) {
  6688. case WM_PAINT:
  6689. //SwapBuffers(GetDC(hwnd));
  6690. break;
  6691. case WM_MOUSEMOVE:
  6692. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6693. MAIN.IsPen = 0;
  6694. break;
  6695. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6696. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6697. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6698. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6699. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6700. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6701. case WM_MOUSEWHEEL:
  6702. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6703. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6704. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6705. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6706. break;
  6707. case WT_PACKET:
  6708. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6709. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6710. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6711. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6712. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6713. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6714. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6715. MAIN.StylusTwist = tw;
  6716. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6717. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6718. MAIN.EraserPressure = MAIN.StylusPressure;
  6719. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6720. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6721. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6722. }
  6723. return 0; break;
  6724. case WM_SYSCOMMAND:
  6725. switch (wparam) {
  6726. case SC_MAXIMIZE:
  6727. case SC_RESTORE:
  6728. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6729. break;
  6730. case SC_KEYMENU:
  6731. return 0;
  6732. case SC_MINIMIZE:
  6733. break;
  6734. }
  6735. break;
  6736. case WM_SIZE:
  6737. if (wparam == SIZE_MINIMIZED) break;
  6738. case WM_MOVE: /* And size */
  6739. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6740. break;
  6741. case WM_SETCURSOR:
  6742. if(MAIN.CurrentCursor) return 1;
  6743. break;
  6744. case WM_POINTERDOWN:
  6745. case WM_POINTERUP:
  6746. case WM_POINTERUPDATE:
  6747. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6748. pointerId = GET_POINTERID_WPARAM(wparam);
  6749. pointerType = PT_POINTER;
  6750. if(!GetPointerType(pointerId, &pointerType)){
  6751. pointerType = PT_POINTER;
  6752. }
  6753. if(pointerType == PT_PEN){
  6754. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6755. for (int i = peninfonum-1; i>=0; i--) {
  6756. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6757. ScreenToClient(hwnd, &point);
  6758. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6759. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6760. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6761. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6762. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6763. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6764. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6765. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6766. }
  6767. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6768. }
  6769. }
  6770. SkipPointerFrameMessages(pointerId);
  6771. return 0;
  6772. }
  6773. else if (pointerType == PT_TOUCH){
  6774. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6775. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6776. ScreenToClient(hwnd, &point);
  6777. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6778. }
  6779. }
  6780. break;
  6781. case WM_SYSKEYDOWN:
  6782. if (lparam & 0x40000000) break;
  6783. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6784. break;
  6785. case WM_KEYDOWN:
  6786. if (lparam & 0x40000000) break;
  6787. vkey = wparam;
  6788. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6789. break;
  6790. case WM_KEYUP:
  6791. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6792. break;
  6793. case WM_SYSKEYUP:
  6794. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6795. break;
  6796. case WM_UNICHAR:
  6797. la_SendInputEvent(hwnd, wparam);
  6798. break;
  6799. case WM_IME_CHAR:
  6800. la_SendInputEvent(hwnd, wparam);
  6801. return 0;
  6802. case WM_CHAR:
  6803. la_SendInputEvent(hwnd, wparam);
  6804. break;
  6805. case WM_SHOWWINDOW:
  6806. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6807. break;
  6808. case WM_CLOSE:
  6809. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6810. break;
  6811. default:
  6812. return DefWindowProc(hwnd, message, wparam, lparam);
  6813. }
  6814. return DefWindowProc(hwnd, message, wparam, lparam);
  6815. }
  6816. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6817. return DefWindowProc(hwnd, message, wparam, lparam);
  6818. }
  6819. #endif
  6820. int la_UpdateOperatorHints(laWindow* w){
  6821. laSafeString* ss=0;
  6822. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6823. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6824. }
  6825. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6826. }else{
  6827. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6828. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6829. }
  6830. strSafeDestroy(&ss);
  6831. }
  6832. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6833. laOperator *a, *NextA = 0;
  6834. int Result = 0;
  6835. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6836. la_SendSignalsFromEvent(e);
  6837. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6838. a = Operators->pFirst;
  6839. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6840. while (1){
  6841. if (!a) break;
  6842. if (a->StopNow){
  6843. NextA = a->Item.pNext;
  6844. if (a->Type->Exit) a->Type->Exit(a, Result);
  6845. ConfirmData = a->NextConfirmData;
  6846. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6847. NextConfirmData = ConfirmData;
  6848. a->ConfirmData = 0;
  6849. a->NextConfirmData = 0;
  6850. la_DestroyOperator(&a, Operators, 0);
  6851. a = NextA;
  6852. if (a){
  6853. a->ConfirmData = NextConfirmData;
  6854. }
  6855. continue;
  6856. }
  6857. a->Using = 1;
  6858. la_SetPropMathcerContext(a->ToPanel);
  6859. laSetOperatorLocalizer(a->ToPanel);
  6860. MAIN.CurrentPanel = a->ToPanel;
  6861. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6862. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6863. e->Localized = 1;
  6864. }
  6865. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6866. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6867. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6868. e->Localized = 0;
  6869. }
  6870. la_SetPropMathcerContext(0);
  6871. laSetOperatorLocalizer(0);
  6872. MAIN.CurrentPanel = 0;
  6873. a->Using = 0;
  6874. if (Result & LA_PASS_ON){
  6875. laConfirmSameDataIfAny(a);
  6876. NextA = a->Item.pNext;
  6877. }else{
  6878. NextA = 0;
  6879. if (a->NextConfirmData){
  6880. la_DestroyConfirmData(&a->NextConfirmData);
  6881. }
  6882. }
  6883. ConfirmData = a->NextConfirmData;
  6884. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6885. NextConfirmData = ConfirmData;
  6886. a->ConfirmData = 0;
  6887. a->NextConfirmData = 0;
  6888. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6889. if (a->Type->Exit) a->Type->Exit(a, Result);
  6890. la_DestroyOperator(&a, Operators, 0);
  6891. int found=0;
  6892. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6893. if(!found){ NextA=0; }
  6894. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6895. }
  6896. a = NextA;
  6897. if (a){
  6898. a->ConfirmData = NextConfirmData;
  6899. }
  6900. }
  6901. return 1;
  6902. }
  6903. int la_HandleEvents(laWindow *w){
  6904. laEvent *e, *NextE;
  6905. laOperator *a;
  6906. laThreadNotifier *tn;
  6907. MAIN.CurrentWindow=w;
  6908. //laSpinLock(&MAIN.csNotifier);
  6909. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6910. //laSpinUnlock(&MAIN.csNotifier);
  6911. laNotifyUsers(tn->Path);
  6912. FreeMem(tn);
  6913. //if (MAIN.ThreadNotifiers.pFirst)
  6914. //laSpinLock(&MAIN.csNotifier);
  6915. }
  6916. //laSpinUnlock(&MAIN.csNotifier);
  6917. while (1){
  6918. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6919. while (w->EventList.pFirst){
  6920. while (w->PendingOperators.pLast){
  6921. a = w->PendingOperators.pLast;
  6922. if (a->OperatorPanel){
  6923. laSetOperatorLocalizer(a->OperatorPanel);
  6924. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6925. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6926. }
  6927. lstRemoveItem(&w->PendingOperators, a);
  6928. lstPushItem(&w->Operators, a);
  6929. }
  6930. e = lstPopItem(&w->EventList);
  6931. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6932. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6933. memFree(e);
  6934. }
  6935. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  6936. if (!MAIN.ReTriggerOperators) break;
  6937. }
  6938. la_UpdateOperatorHints(w);
  6939. return 1;
  6940. }
  6941. int la_AllowInput(uint32_t ch){
  6942. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6943. return 0;
  6944. }
  6945. int laCopyToClipboard(unsigned char * text){
  6946. #ifdef LA_LINUX
  6947. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6948. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6949. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6950. strSafeSet(&MAIN.CopyPending, text);
  6951. #endif
  6952. }
  6953. int la_ProcessSysMessage(){
  6954. int SendDelay = 0, SendIdle = 0;
  6955. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6956. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6957. #ifdef LA_LINUX
  6958. XEvent e;
  6959. int type;
  6960. int InputCount = 0, CharCount=0;
  6961. KeySym InputKeysym = 0;
  6962. Status InputStatus = 0;
  6963. laWindow* wnd ;
  6964. while(XPending(MAIN.dpy)){
  6965. XGenericEventCookie *cookie = &e.xcookie;
  6966. XNextEvent(MAIN.dpy, &e);
  6967. if (XFilterEvent(&e, None)) continue;
  6968. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6969. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6970. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6971. XFreeEventData(MAIN.dpy, cookie); continue;
  6972. }
  6973. switch(e.type){
  6974. case ConfigureNotify:
  6975. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6976. break;
  6977. case Expose:
  6978. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6979. if(!wnd) break;
  6980. laRefreshWindow(wnd);
  6981. break;
  6982. case MotionNotify:
  6983. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6984. MAIN.IsPen=0;
  6985. break;
  6986. case ButtonPress:
  6987. type=LA_MOUSEDOWN;
  6988. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6989. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6990. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6991. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  6992. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  6993. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6994. MAIN.IsPen=0;
  6995. break;
  6996. case ButtonRelease:
  6997. type=LA_MOUSEUP;
  6998. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6999. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7000. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7001. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7002. MAIN.IsPen=0;
  7003. break;
  7004. case KeyPress:
  7005. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7006. MAIN.InputBuf[InputCount]=0;
  7007. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7008. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7009. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7010. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7011. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7012. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7013. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7014. #ifdef DEBUG
  7015. printf("pressed KEY: %d\n", (int)InputKeysym);
  7016. #endif
  7017. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7018. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7019. }
  7020. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7021. }
  7022. break;
  7023. case KeyRelease:
  7024. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7025. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7026. }
  7027. case ClientMessage:
  7028. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7029. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7030. }
  7031. break;
  7032. case SelectionNotify:
  7033. if(e.xselection.selection != MAIN.bufid) continue;
  7034. if (e.xselection.property){
  7035. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7036. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7037. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7038. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7039. else if(result) {
  7040. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7041. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7042. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7043. }
  7044. XFree(result);
  7045. return True;
  7046. }
  7047. case SelectionRequest:
  7048. if(!MAIN.CopyPending){ break; }
  7049. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7050. if (e.xselectionrequest.selection != MAIN.selection) break;
  7051. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7052. XSelectionEvent ev = {0};
  7053. int R = 0;
  7054. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7055. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7056. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7057. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7058. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7059. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7060. else if (ev.target == MAIN.UTF8)
  7061. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7062. else ev.property = None;
  7063. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7064. break;
  7065. case SelectionClear:
  7066. break;
  7067. default:
  7068. break;
  7069. }
  7070. }
  7071. #endif //linux
  7072. #ifdef _WIN32
  7073. MSG msg; int Processed = 0;
  7074. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7075. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7076. if (msg.wParam == VK_PROCESSKEY) {
  7077. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7078. }
  7079. TranslateMessage(&msg); DispatchMessage(&msg);
  7080. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7081. };
  7082. if(!MAIN.Windows.pFirst){ return 0; }
  7083. #endif
  7084. #ifdef LAGUI_ANDROID
  7085. int pollResult = 0;
  7086. int pollEvents = 0;
  7087. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7088. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7089. // NOTE: Never close window, native activity is controlled by the system!
  7090. if (MAIN.app->destroyRequested != 0)
  7091. {
  7092. //CORE.Window.shouldClose = true;
  7093. //ANativeActivity_finish(MAIN.app->activity);
  7094. }
  7095. }
  7096. #endif
  7097. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7098. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7099. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7100. }
  7101. return 1;
  7102. };
  7103. void la_PrintOperatorStack(){
  7104. laWindow *w = MAIN.CurrentWindow;
  7105. laOperator *a;
  7106. printf("\n");
  7107. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7108. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7109. a->Type->Identifier, a->Instance,
  7110. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7111. }
  7112. }
  7113. void la_DrawWindow(laWindow *w){
  7114. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7115. MAIN.CurrentWindow = w;
  7116. la_WindowDefDraw(w, 0);
  7117. }
  7118. int laFinalize(){
  7119. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7120. laUiTemplate* uit;
  7121. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7122. return 1;
  7123. }
  7124. void la_PreFrame(){
  7125. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7126. la_AnimationPreFrame();
  7127. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7128. }
  7129. void la_PostFrame(){
  7130. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7131. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7132. }
  7133. void laMainLoop(){
  7134. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7135. laTimeRecorder FrameStartTime, FrameEndTime;
  7136. time_t t1, t2;
  7137. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7138. static int a = 0;
  7139. if(!laFinalize()) return;
  7140. laSetWindowCursor(LA_ARROW);
  7141. MAIN.DelayTriggered=1;
  7142. #ifdef LAGUI_ANDROID
  7143. while(!MAIN.AppReady){ usleep(1000); }
  7144. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7145. #endif
  7146. while (1){
  7147. laRecordTime(&FrameStartTime);
  7148. la_PreFrame();
  7149. if(!la_ProcessSysMessage()){ return; }
  7150. la_UpdateControllerStatus();
  7151. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7152. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7153. NextW = w->Item.pNext;
  7154. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7155. }
  7156. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7157. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7158. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7159. if(MAIN.GLDebugNeedsUpdate){
  7160. la_SetCurrentGLContextDebug();
  7161. }
  7162. la_DrawWindow(w);
  7163. }
  7164. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7165. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7166. #ifdef LA_LINUX
  7167. #ifdef LA_USE_GLES
  7168. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7169. #else
  7170. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7171. #endif
  7172. #endif
  7173. #ifdef _WIN32
  7174. SwapBuffers(w->hdc);
  7175. #endif
  7176. #ifdef LAGUI_ANDROID
  7177. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7178. #endif
  7179. }
  7180. MAIN.GLDebugNeedsUpdate=0;
  7181. la_PostFrame();
  7182. //t2 = clock();
  7183. laRecordTime(&FrameEndTime);
  7184. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  7185. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7186. if (Pause > 0){
  7187. int us = Pause * 1000000.0;
  7188. usleep(us);
  7189. }
  7190. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7191. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7192. la_AnimationPostFrame();
  7193. }
  7194. }
  7195. #ifdef LAGUI_ANDROID
  7196. int la_AndroidInitGraphics(void){
  7197. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7198. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7199. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7200. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7201. EGLint samples = 0;
  7202. EGLint sampleBuffer = 0;
  7203. const EGLint framebufferAttribs[] = {
  7204. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7205. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7206. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7207. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7208. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7209. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7210. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7211. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7212. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7213. EGL_NONE
  7214. };
  7215. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7216. EGLint numConfigs = 0;
  7217. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7218. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7219. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7220. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7221. eglBindAPI(EGL_OPENGL_API);
  7222. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7223. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7224. EGLint displayFormat = 0;
  7225. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7226. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7227. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7228. // There must be at least one frame displayed before the buffers are swapped
  7229. eglSwapInterval(MAIN.egl_dpy, 1);
  7230. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7231. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7232. MAIN.AppReady = 1;
  7233. return 0;
  7234. }
  7235. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7236. switch (cmd){
  7237. case APP_CMD_START: break;
  7238. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7239. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7240. case APP_CMD_RESUME:break;//InitPlatform();break;
  7241. case APP_CMD_INIT_WINDOW:
  7242. if (app->window != NULL){
  7243. if (MAIN.ContextRebindRequired){
  7244. // Reset screen scaling to full display size
  7245. EGLint displayFormat = 0;
  7246. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7247. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7248. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7249. // appropriate way to fix this
  7250. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7251. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7252. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7253. displayFormat);
  7254. // Recreate display surface and re-attach OpenGL context
  7255. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7256. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7257. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7258. //glClearColor(1,0.2,1,1);
  7259. //glClear(GL_COLOR_BUFFER_BIT);
  7260. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7261. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7262. MAIN.ContextRebindRequired = false;
  7263. }else{
  7264. la_AndroidInitGraphics();
  7265. }
  7266. }
  7267. break;
  7268. case APP_CMD_TERM_WINDOW:
  7269. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7270. // 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.
  7271. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7272. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7273. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7274. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7275. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7276. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7277. MAIN.egl_surf = EGL_NO_SURFACE;
  7278. }
  7279. MAIN.ContextRebindRequired = true;
  7280. }
  7281. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7282. // this means that the user has already called 'CloseWindow()'
  7283. break;
  7284. case APP_CMD_SAVE_STATE: break;
  7285. case APP_CMD_STOP: break;
  7286. case APP_CMD_DESTROY: break;
  7287. case APP_CMD_CONFIG_CHANGED:
  7288. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7289. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7290. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7291. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7292. //print_cur_config(MAIN.app);
  7293. // Check screen orientation here!
  7294. break;
  7295. default: break;
  7296. }
  7297. }
  7298. #define KEYCODE_MAP_SIZE 162
  7299. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7300. 0, // AKEYCODE_UNKNOWN
  7301. 0, // AKEYCODE_SOFT_LEFT
  7302. 0, // AKEYCODE_SOFT_RIGHT
  7303. 0, // AKEYCODE_HOME
  7304. 0, // AKEYCODE_BACK
  7305. 0, // AKEYCODE_CALL
  7306. 0, // AKEYCODE_ENDCALL
  7307. '0', // AKEYCODE_0
  7308. '1', // AKEYCODE_1
  7309. '2', // AKEYCODE_2
  7310. '3', // AKEYCODE_3
  7311. '4', // AKEYCODE_4
  7312. '5', // AKEYCODE_5
  7313. '6', // AKEYCODE_6
  7314. '7', // AKEYCODE_7
  7315. '8', // AKEYCODE_8
  7316. '9', // AKEYCODE_9
  7317. 0, // AKEYCODE_STAR
  7318. 0, // AKEYCODE_POUND
  7319. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7320. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7321. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7322. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7323. 0, // AKEYCODE_DPAD_CENTER
  7324. 0, // AKEYCODE_VOLUME_UP
  7325. 0, // AKEYCODE_VOLUME_DOWN
  7326. 0, // AKEYCODE_POWER
  7327. 0, // AKEYCODE_CAMERA
  7328. 0, // AKEYCODE_CLEAR
  7329. 'a', // AKEYCODE_A
  7330. 'b', // AKEYCODE_B
  7331. 'c', // AKEYCODE_C
  7332. 'd', // AKEYCODE_D
  7333. 'e', // AKEYCODE_E
  7334. 'f', // AKEYCODE_F
  7335. 'g', // AKEYCODE_G
  7336. 'h', // AKEYCODE_H
  7337. 'i', // AKEYCODE_I
  7338. 'j', // AKEYCODE_J
  7339. 'k', // AKEYCODE_K
  7340. 'l', // AKEYCODE_L
  7341. 'm', // AKEYCODE_M
  7342. 'n', // AKEYCODE_N
  7343. 'o', // AKEYCODE_O
  7344. 'p', // AKEYCODE_P
  7345. 'q', // AKEYCODE_Q
  7346. 'r', // AKEYCODE_R
  7347. 's', // AKEYCODE_S
  7348. 't', // AKEYCODE_T
  7349. 'u', // AKEYCODE_U
  7350. 'v', // AKEYCODE_V
  7351. 'w', // AKEYCODE_W
  7352. 'x', // AKEYCODE_X
  7353. 'y', // AKEYCODE_Y
  7354. 'z', // AKEYCODE_Z
  7355. ',', // AKEYCODE_COMMA
  7356. '.', // AKEYCODE_PERIOD
  7357. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7358. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7359. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7360. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7361. LA_KEY_TAB, // AKEYCODE_TAB
  7362. ' ', // AKEYCODE_SPACE
  7363. 0, // AKEYCODE_SYM
  7364. 0, // AKEYCODE_EXPLORER
  7365. 0, // AKEYCODE_ENVELOPE
  7366. LA_KEY_ENTER, // AKEYCODE_ENTER
  7367. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7368. '`', // AKEYCODE_GRAVE
  7369. '-', // AKEYCODE_MINUS
  7370. '=', // AKEYCODE_EQUALS
  7371. '(', // AKEYCODE_LEFT_BRACKET
  7372. ')', // AKEYCODE_RIGHT_BRACKET
  7373. '\\', // AKEYCODE_BACKSLASH
  7374. ';', // AKEYCODE_SEMICOLON
  7375. '\'', // AKEYCODE_APOSTROPHE
  7376. '/', // AKEYCODE_SLASH
  7377. 0, // AKEYCODE_AT
  7378. 0, // AKEYCODE_NUM
  7379. 0, // AKEYCODE_HEADSETHOOK
  7380. 0, // AKEYCODE_FOCUS
  7381. 0, // AKEYCODE_PLUS
  7382. 0, // AKEYCODE_MENU
  7383. 0, // AKEYCODE_NOTIFICATION
  7384. 0, // AKEYCODE_SEARCH
  7385. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7386. 0, // AKEYCODE_MEDIA_STOP
  7387. 0, // AKEYCODE_MEDIA_NEXT
  7388. 0, // AKEYCODE_MEDIA_PREVIOUS
  7389. 0, // AKEYCODE_MEDIA_REWIND
  7390. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7391. 0, // AKEYCODE_MUTE
  7392. 0, // AKEYCODE_PAGE_UP
  7393. 0, // AKEYCODE_PAGE_DOWN
  7394. 0, // AKEYCODE_PICTSYMBOLS
  7395. 0, // AKEYCODE_SWITCH_CHARSET
  7396. 0, // AKEYCODE_BUTTON_A
  7397. 0, // AKEYCODE_BUTTON_B
  7398. 0, // AKEYCODE_BUTTON_C
  7399. 0, // AKEYCODE_BUTTON_X
  7400. 0, // AKEYCODE_BUTTON_Y
  7401. 0, // AKEYCODE_BUTTON_Z
  7402. 0, // AKEYCODE_BUTTON_L1
  7403. 0, // AKEYCODE_BUTTON_R1
  7404. 0, // AKEYCODE_BUTTON_L2
  7405. 0, // AKEYCODE_BUTTON_R2
  7406. 0, // AKEYCODE_BUTTON_THUMBL
  7407. 0, // AKEYCODE_BUTTON_THUMBR
  7408. 0, // AKEYCODE_BUTTON_START
  7409. 0, // AKEYCODE_BUTTON_SELECT
  7410. 0, // AKEYCODE_BUTTON_MODE
  7411. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7412. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7413. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7414. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7415. 0, // AKEYCODE_CAPS_LOCK
  7416. 0, // AKEYCODE_SCROLL_LOCK
  7417. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7418. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7419. 0, // AKEYCODE_FUNCTION
  7420. 0, // AKEYCODE_SYSRQ
  7421. 0, // AKEYCODE_BREAK
  7422. 0, // AKEYCODE_MOVE_HOME
  7423. 0, // AKEYCODE_MOVE_END
  7424. 0, // AKEYCODE_INSERT
  7425. 0, // AKEYCODE_FORWARD
  7426. 0, // AKEYCODE_MEDIA_PLAY
  7427. 0, // AKEYCODE_MEDIA_PAUSE
  7428. 0, // AKEYCODE_MEDIA_CLOSE
  7429. 0, // AKEYCODE_MEDIA_EJECT
  7430. 0, // AKEYCODE_MEDIA_RECORD
  7431. LA_KEY_F1, // AKEYCODE_F1
  7432. LA_KEY_F2, // AKEYCODE_F2
  7433. LA_KEY_F3, // AKEYCODE_F3
  7434. LA_KEY_F4, // AKEYCODE_F4
  7435. LA_KEY_F5, // AKEYCODE_F5
  7436. LA_KEY_F6, // AKEYCODE_F6
  7437. LA_KEY_F7, // AKEYCODE_F7
  7438. LA_KEY_F8, // AKEYCODE_F8
  7439. LA_KEY_F9, // AKEYCODE_F9
  7440. LA_KEY_F10, // AKEYCODE_F10
  7441. LA_KEY_F11, // AKEYCODE_F11
  7442. LA_KEY_F12, // AKEYCODE_F12
  7443. 0, // AKEYCODE_NUM_LOCK
  7444. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7445. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7446. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7447. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7448. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7449. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7450. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7451. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7452. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7453. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7454. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7455. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7456. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7457. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7458. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7459. 0, // AKEYCODE_NUMPAD_COMMA
  7460. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7461. '=' // AKEYCODE_NUMPAD_EQUALS
  7462. };
  7463. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7464. {
  7465. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7466. if(!MAIN.AppEnabled){return 0;}
  7467. //laRedrawAllWindows();
  7468. int type = AInputEvent_getType(event);
  7469. if(type == AINPUT_EVENT_TYPE_KEY){
  7470. int32_t keycode = AKeyEvent_getKeyCode(event);
  7471. //int32_t AKeyEvent_getMetaState(event);
  7472. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7473. if (key != 0){
  7474. // Save current key and its state
  7475. // NOTE: Android key action is 0 for down and 1 for up
  7476. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7477. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7478. if(key!=LA_KEY_BACKSPACE)
  7479. la_SendInputEvent(0,key);
  7480. }
  7481. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7482. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7483. la_SendInputEvent(0,key);
  7484. }
  7485. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7486. }
  7487. if (keycode == AKEYCODE_POWER)
  7488. {
  7489. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7490. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7491. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7492. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7493. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7494. return 0;
  7495. }
  7496. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7497. {
  7498. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7499. return 1;
  7500. }
  7501. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7502. {
  7503. // Set default OS behaviour
  7504. return 0;
  7505. }
  7506. return 0;
  7507. }
  7508. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7509. int pcount = AMotionEvent_getPointerCount(event); int x,y;
  7510. if(pcount){
  7511. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7512. x=rx; y=ry;
  7513. }
  7514. int32_t action = AMotionEvent_getAction(event);
  7515. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7516. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7517. if (flags == AMOTION_EVENT_ACTION_DOWN){
  7518. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7519. la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
  7520. }
  7521. else if (flags == AMOTION_EVENT_ACTION_UP){
  7522. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7523. }
  7524. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7525. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7526. }
  7527. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7528. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7529. }
  7530. }
  7531. //static float r=0;
  7532. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7533. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7534. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7535. //glClear(GL_COLOR_BUFFER_BIT);
  7536. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7537. return 0;
  7538. }
  7539. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7540. MAIN.AssetManager = manager;
  7541. MAIN.InternalDataPath = dataPath;
  7542. MAIN.ExternalDataPath = externalDataPath;
  7543. }
  7544. static int android_read(void *cookie, char *data, int dataSize){
  7545. return AAsset_read((AAsset *)cookie, data, dataSize);
  7546. }
  7547. static int android_write(void *cookie, const char *data, int dataSize){
  7548. return 0;
  7549. }
  7550. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7551. return AAsset_seek((AAsset *)cookie, offset, whence);
  7552. }
  7553. static int android_close(void *cookie){
  7554. AAsset_close((AAsset *)cookie);
  7555. return 0;
  7556. }
  7557. // Replacement for fopen()
  7558. // Ref: https://developer.android.com/ndk/reference/group/asset
  7559. FILE *android_fopen(const char *fileName, const char *mode)
  7560. {
  7561. char buf[1024];
  7562. if (mode[0] == 'w')
  7563. {
  7564. // fopen() is mapped to android_fopen() that only grants read access to
  7565. // assets directory through AAssetManager but we want to also be able to
  7566. // write data when required using the standard stdio FILE access functions
  7567. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7568. #undef fopen
  7569. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7570. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7571. result=fopen(buf, mode); if(result) return result;
  7572. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7573. return fopen(buf, mode);
  7574. #define fopen(name, mode) android_fopen(name, mode)
  7575. }
  7576. else
  7577. {
  7578. // NOTE: AAsset provides access to read-only asset
  7579. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7580. if (asset != NULL)
  7581. {
  7582. // Get pointer to file in the assets
  7583. return funopen(asset, android_read, android_write, android_seek, android_close);
  7584. }
  7585. else
  7586. {
  7587. #undef fopen
  7588. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7589. // Just do a regular open if file is not found in the assets
  7590. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7591. result=fopen(buf, mode); if(result){ return result; }
  7592. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7593. return fopen(buf, mode);
  7594. #define fopen(name, mode) android_fopen(name, mode)
  7595. }
  7596. }
  7597. }
  7598. void la_HideNavBar(){
  7599. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7600. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7601. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7602. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7603. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7604. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7605. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7606. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7607. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7608. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7609. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7610. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7611. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7612. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7613. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7614. int flag = flagFullscreen | flagHideNavigation;
  7615. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7616. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7617. }
  7618. void la_InitAndroidPlatform(struct android_app *app){
  7619. MAIN.app=app;
  7620. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7621. //la_HideNavBar();
  7622. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7623. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7624. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7625. int pollResult = 0;
  7626. int pollEvents = 0;
  7627. while (!MAIN.AppReady){
  7628. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7629. // Process this event
  7630. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7631. // NOTE: Never close window, native activity is controlled by the system!
  7632. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7633. }
  7634. }
  7635. }
  7636. int main(int, char *[]);
  7637. void android_main(struct android_app *app){
  7638. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7639. la_InitAndroidPlatform(app);
  7640. // NOTE: Return from main is ignored
  7641. (void)main(1, (char *[]) { arg0, NULL });
  7642. // Request to end the native activity
  7643. ANativeActivity_finish(app->activity);
  7644. // Android ALooper_pollAll() variables
  7645. int pollResult = 0;
  7646. int pollEvents = 0;
  7647. // Waiting for application events before complete finishing
  7648. while (!app->destroyRequested)
  7649. {
  7650. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7651. {
  7652. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7653. }
  7654. }
  7655. }
  7656. void la_DisplayKeyboard(bool pShow) {
  7657. // Attaches the current thread to the JVM.
  7658. jint lResult;
  7659. jint lFlags = 0;
  7660. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7661. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7662. JavaVMAttachArgs lJavaVMAttachArgs;
  7663. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7664. lJavaVMAttachArgs.name = "NativeThread";
  7665. lJavaVMAttachArgs.group = NULL;
  7666. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7667. if (lResult == JNI_ERR) {
  7668. return;
  7669. }
  7670. // Retrieves NativeActivity.
  7671. jobject lNativeActivity = MAIN.app->activity->clazz;
  7672. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7673. logPrintNew("jvm3");
  7674. // Retrieves Context.INPUT_METHOD_SERVICE.
  7675. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7676. jfieldID FieldINPUT_METHOD_SERVICE =
  7677. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7678. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7679. jobject INPUT_METHOD_SERVICE =
  7680. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7681. FieldINPUT_METHOD_SERVICE);
  7682. //jniCheck(INPUT_METHOD_SERVICE);
  7683. logPrintNew("jvm4");
  7684. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7685. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7686. "android/view/inputmethod/InputMethodManager");
  7687. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7688. ClassNativeActivity, "getSystemService",
  7689. "(Ljava/lang/String;)Ljava/lang/Object;");
  7690. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7691. lNativeActivity, MethodGetSystemService,
  7692. INPUT_METHOD_SERVICE);
  7693. // Runs getWindow().getDecorView().
  7694. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7695. ClassNativeActivity, "getWindow",
  7696. "()Landroid/view/Window;");
  7697. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7698. MethodGetWindow);
  7699. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7700. "android/view/Window");
  7701. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7702. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7703. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7704. MethodGetDecorView);
  7705. if (pShow) {
  7706. // Runs lInputMethodManager.showSoftInput(...).
  7707. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7708. ClassInputMethodManager, "showSoftInput",
  7709. "(Landroid/view/View;I)Z");
  7710. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7711. lInputMethodManager, MethodShowSoftInput,
  7712. lDecorView, lFlags);
  7713. } else {
  7714. // Runs lWindow.getViewToken()
  7715. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7716. "android/view/View");
  7717. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7718. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7719. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7720. MethodGetWindowToken);
  7721. // lInputMethodManager.hideSoftInput(...).
  7722. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7723. ClassInputMethodManager, "hideSoftInputFromWindow",
  7724. "(Landroid/os/IBinder;I)Z");
  7725. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7726. lInputMethodManager, MethodHideSoftInput,
  7727. lBinder, lFlags);
  7728. }
  7729. // Finished with the JVM.
  7730. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7731. }
  7732. #endif //android
  7733. #ifndef LAGUI_ANDROID
  7734. void la_DisplayKeyboard(bool pShow) {
  7735. return;
  7736. }
  7737. void la_HideNavBar(){
  7738. return;
  7739. }
  7740. #endif