*/}}

la_kernel.c 330 KB

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