*/}}

la_kernel.c 330 KB

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