*/}}

la_kernel.c 330 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756
  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. #ifdef LA_USE_GLES
  45. #include <GLES3/gl3.h>
  46. #endif
  47. #endif
  48. #ifdef _WIN32
  49. #include <GL/wglew.h>
  50. #include <GL/wgl.h>
  51. #include <shellscalingapi.h>
  52. #endif
  53. #ifdef LAGUI_ANDROID
  54. #include <GLES3/gl32.h>
  55. #include <jni.h>
  56. #include <android/log.h>
  57. #include <android/native_activity.h>
  58. #include <android/native_window.h>
  59. #include <android/native_window_jni.h>
  60. #include <android_native_app_glue.h>
  61. #include <android/window.h>
  62. #include <android/asset_manager.h>
  63. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  64. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  65. static int android_read(void *cookie, char *buf, int size);
  66. static int android_write(void *cookie, const char *buf, int size);
  67. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  68. static int android_close(void *cookie);
  69. void la_InitAndroidPlatform(struct android_app *app);
  70. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  71. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  72. void la_InitAndroidPlatform(struct android_app *app);
  73. #endif
  74. LA MAIN={0};
  75. extern tnsMain *T;
  76. int deb = 0;
  77. laOperator *DEB;
  78. laColumn *DEBUG_C;
  79. #ifdef _WIN32
  80. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  81. #else
  82. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  83. #endif
  84. #ifdef LA_LINUX
  85. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  86. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  87. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  88. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  89. #endif
  90. #ifdef LA_LINUX
  91. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  92. int i;
  93. for (i = 0; i < num_classes; i++) {
  94. if (classes[i]->type == XIValuatorClass) {
  95. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  96. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  97. logPrint(" Range: %f - %f\n", v->min, v->max);
  98. logPrint(" Resolution: %d units/m\n", v->resolution);
  99. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  100. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  101. }
  102. }
  103. }
  104. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  105. XIDeviceInfo *info, *dev;
  106. int i, ndevices;
  107. dev = XIQueryDevice(display, deviceid, &ndevices);
  108. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  109. mask->deviceid = deviceid;
  110. mask->mask_len = XIMaskLen(XI_RawMotion);
  111. mask->mask=memAcquireSimple(mask->mask_len);
  112. memset(mask->mask, 0, mask->mask_len);
  113. XISetMask(mask->mask, XI_RawMotion);
  114. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  115. int FoundMax=0;
  116. for (i = 0; i < dev->num_classes; i++) {
  117. if (dev->classes[i]->type == XIValuatorClass) {
  118. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  119. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  120. }
  121. }
  122. if(!FoundMax){*max_pressure=65535;}
  123. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  124. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  125. XIFreeDeviceInfo(dev);
  126. }
  127. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  128. int axis=0;
  129. for (int i = 0; i < dev->num_classes; i++) {
  130. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  131. }
  132. return axis>=3;
  133. }
  134. #define LA_G_STYLUS(dev) \
  135. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  136. #define LA_G_ERASER \
  137. (!MAIN.WacomDeviceEraser)
  138. void la_ScanWacomDevices(Display *display, int deviceid){
  139. XIDeviceInfo *info, *dev;
  140. int ndevices;
  141. int i; char * word;
  142. int _event, _error;
  143. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  144. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  145. }
  146. info = XIQueryDevice(display, deviceid, &ndevices);
  147. for(i = 0; i < ndevices; i++) {
  148. dev = &info[i]; strToLower(dev->name);
  149. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  150. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  151. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  152. word = strtok (dev->name," ");
  153. while (1) {
  154. word = strtok (NULL, " "); if (!word) break;
  155. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  156. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  157. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  158. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  159. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  160. }
  161. }
  162. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  163. logPrintNew("Found wacom devices:\n");
  164. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  165. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  166. }else{
  167. logPrintNew("No wacom pen device connected.\n");
  168. }
  169. XIFreeDeviceInfo(info);
  170. }
  171. void laHideCursor(){
  172. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  173. }
  174. void laShowCursor(){
  175. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  176. }
  177. void la_XErrorHandler(Display *display, XErrorEvent *event){
  178. char buf[512];
  179. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  180. printf("X Error:\n%s\n",buf);
  181. }
  182. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  183. XSetWindowAttributes swa;
  184. XWindowAttributes wa;
  185. swa.event_mask =
  186. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  187. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  188. swa.colormap = MAIN.cmap;
  189. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  190. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  191. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  192. if(x>0||y>0){
  193. XSizeHints my_hints = {0};
  194. my_hints.flags = PPosition;
  195. my_hints.x = x; my_hints.y = y;
  196. XSetNormalHints(MAIN.dpy, win, &my_hints);
  197. }
  198. XStoreName(MAIN.dpy, win, title);
  199. #ifdef LA_USE_GLES
  200. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
  201. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  202. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  203. EGLSurface* surf=egl_surf;
  204. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  205. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  206. tnsContextMakeCurrent((*r_glc),win,(*surf));
  207. #else
  208. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  209. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  210. printf("\n\tcannot create gl context\n\n"); exit(0);
  211. }
  212. tnsContextMakeCurrent((*r_glc),win,0);
  213. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  214. #endif
  215. XSetLocaleModifiers("");
  216. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  217. if(!MAIN.im){
  218. XSetLocaleModifiers("@im=local");
  219. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  220. }
  221. if(!MAIN.im){
  222. XSetLocaleModifiers("@im=none");
  223. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  224. }
  225. if(!MAIN.im){
  226. XSetLocaleModifiers("@im=");
  227. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  228. }
  229. if(!MAIN.im){
  230. logPrint("Can't open a input method.\n");
  231. }
  232. if(MAIN.im){
  233. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  234. XSetICFocus(MAIN.ic);
  235. }
  236. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  237. XSetClassHint(MAIN.dpy, win, &ch);
  238. #define _NET_WM_STATE_ADD 1
  239. if(w<0&&h<0){
  240. XEvent xev;
  241. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  242. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  243. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  244. memset(&xev, 0, sizeof(xev));
  245. xev.type = ClientMessage;
  246. xev.xclient.window = win;
  247. xev.xclient.message_type = wm_state;
  248. xev.xclient.format = 32;
  249. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  250. xev.xclient.data.l[1] = max_horz;
  251. xev.xclient.data.l[2] = max_vert;
  252. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  253. }
  254. return win;
  255. };
  256. void la_DestroySystemWindowX11(laWindow* w) {
  257. tnsContextMakeCurrent(0,0,0);
  258. tnsDeleteContext(w->glc);
  259. #ifdef LA_USE_GLES
  260. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  261. #endif
  262. XDestroyWindow(MAIN.dpy, w->win);
  263. };
  264. #endif //linux
  265. #ifdef _WIN32
  266. #include <msgdef.h>
  267. #include <wintab.h>
  268. #include <wintab_utils.h>
  269. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  270. #define PACKETMODE PK_BUTTONS
  271. #include <pktdef.h>
  272. void la_OpenWacomWinTab(HWND hwnd){
  273. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  274. static LOGCONTEXT glogContext = { 0 };
  275. HCTX hctx = NULL;
  276. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  277. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  278. glogContext.lcOptions |= CXO_SYSTEM;
  279. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  280. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  281. assert(glogContext.lcOptions & CXO_SYSTEM);
  282. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  283. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  284. glogContext.lcPktData = PACKETDATA;
  285. glogContext.lcPktMode = PACKETMODE;
  286. glogContext.lcMoveMask = PACKETDATA;
  287. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  288. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  289. assert(wWTInfoRetVal == sizeof(AXIS));
  290. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  291. assert(wWTInfoRetVal == sizeof(AXIS));
  292. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  293. assert(wWTInfoRetVal == sizeof(AXIS));
  294. MAIN.WinTabMaxHover = TabletZ.axMax;
  295. AXIS tabletPressure = { 0 };
  296. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  297. //glogContext.lcInOrgX = 0;
  298. //glogContext.lcInOrgY = 0;
  299. //glogContext.lcInExtX = TabletX.axMax;
  300. //glogContext.lcInExtY = TabletY.axMax;
  301. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  312. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  313. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  314. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  315. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  316. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  317. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  318. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  319. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  320. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  321. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  322. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  323. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  324. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  325. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  326. if (!hctx)return;
  327. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  328. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  329. }
  330. void laHideCursor() {
  331. if (!MAIN.CurrentWindow) return; //impl
  332. }
  333. void laShowCursor() {
  334. if (!MAIN.CurrentWindow) return; //impl
  335. }
  336. static PIXELFORMATDESCRIPTOR cpfd = {
  337. sizeof(PIXELFORMATDESCRIPTOR),1,
  338. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  339. PFD_TYPE_RGBA,
  340. 8,
  341. 0, 0, 0, 0, 0, 0,
  342. 0, 0, 0,
  343. 0, 0, 0, 0,
  344. 32,
  345. 8, 0,
  346. 0,
  347. 0, 0, 0, 0
  348. };
  349. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  350. int nBestMS = 0;
  351. int i;
  352. int iResults[9];
  353. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  354. WGL_ACCELERATION_ARB, // 1
  355. WGL_DRAW_TO_WINDOW_ARB, // 2
  356. WGL_DOUBLE_BUFFER_ARB, // 3
  357. WGL_PIXEL_TYPE_ARB, // 4
  358. WGL_DEPTH_BITS_ARB, // 5
  359. WGL_STENCIL_BITS_ARB, // 6
  360. WGL_SAMPLE_BUFFERS_ARB, // 7
  361. WGL_SAMPLES_ARB }; // 8
  362. // How many pixelformats are there?
  363. int nFormatCount[] = { 0 };
  364. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  365. if (!wglGetPixelFormatAttribivARB)
  366. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  367. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  368. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  369. for (i = 0; i < nFormatCount[0]; i++){
  370. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  371. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  372. if (iResults[3] == 1) // Double buffered
  373. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  374. if (iResults[5] >= 24) // Any Depth greater than 16
  375. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  376. }
  377. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  378. };
  379. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  380. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  381. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  382. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  383. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  384. 0 };
  385. HGLRC hglrc = 0;
  386. HDC hdc = 0;
  387. int a, b;
  388. hdc = GetDC(hwnd);
  389. la_SetupPxlFormat(hdc, &a, &b);
  390. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  391. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  392. tnsContextMakeCurrent(hglrc, hdc,0);
  393. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  394. wglSwapIntervalEXT(-1);
  395. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  396. };
  397. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  398. HINSTANCE* inst = &MAIN.hinstance;
  399. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  400. x, y, w, h, 0, 0, *inst, 0);
  401. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  402. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  403. return hwnd;
  404. };
  405. void la_DestroySystemWindowWin32(laWindow* w) {
  406. tnsContextMakeCurrent(0,0,0);
  407. tnsDeleteContext(w->glc);
  408. ReleaseDC(w->win, w->hdc);
  409. DestroyWindow(w->win);
  410. };
  411. #endif
  412. #ifdef LAGUI_ANDROID
  413. SYSWINDOW la_CreateWindowAndroid(){
  414. return 0;
  415. };
  416. void laShowCursor(){}
  417. void laHideCursor(){}
  418. #endif
  419. #ifdef LA_LINUX
  420. void la_HandlerSIGSEGV(int sig) {
  421. void *array[30];
  422. size_t sz;
  423. sz = backtrace(array, 30);
  424. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  425. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  426. exit(1);
  427. }
  428. #endif
  429. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  430. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  431. //#ifndef LAGUI_ANDROID
  432. // ignore non-significant error/warning codes
  433. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076) return;
  434. logPrint("GL %d: %s\n", id, message);
  435. char* strsource="",*strtype="",*strseverity="";
  436. switch (source) {
  437. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  438. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  439. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  440. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  441. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  442. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  443. }
  444. switch (type) {
  445. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  446. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  447. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  448. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  449. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  450. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  451. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  452. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  453. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  454. }
  455. switch (severity) {
  456. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  457. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  458. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  459. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  460. }
  461. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  462. //#endif
  463. }
  464. void la_SetCurrentGLContextDebug(){
  465. //#ifndef LAGUI_ANDROID
  466. int force=MAIN.InitArgs.GLDebug;
  467. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  468. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  469. glDebugMessageCallback(la_glDebugOutput, 0);
  470. int sev=GL_DONT_CARE;
  471. if(!force){
  472. switch(MAIN.GLDebugLevel){
  473. default: sev=GL_DONT_CARE; break;
  474. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  475. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  476. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  477. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  478. }
  479. }
  480. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  481. //#endif
  482. }
  483. void la_NotifyGLDebugChanges(){
  484. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  485. }
  486. void la_SetupWindowGLStates(laWindow* w){
  487. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  488. if(w->GLDebugNeedsUpdate){
  489. tnsContextMakeWindowCurrent(w);
  490. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  491. }
  492. }
  493. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  494. SYSGLCONTEXT glc;
  495. #ifdef LA_LINUX
  496. void* egl_surf=0;
  497. #ifdef LA_USE_GLES
  498. egl_surf=&window->egl_surf;
  499. #endif
  500. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  501. #endif
  502. #ifdef _WIN32
  503. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  504. #endif
  505. #ifdef LAGUI_ANDROID
  506. la_CreateWindowAndroid();
  507. window->win = 1;
  508. window->glc = MAIN.glc;
  509. #else
  510. window->win = hwnd;
  511. window->glc = glc;
  512. #endif
  513. #ifdef _WIN32
  514. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  515. RECT rc; GetClientRect(window->win, &rc);
  516. window->CW = rc.right - rc.left;
  517. window->CH = rc.bottom - rc.top;
  518. #endif
  519. #ifdef LA_LINUX
  520. XWindowAttributes attr;
  521. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  522. window->CW =attr.width;
  523. window->CH = attr.height;
  524. #endif
  525. la_SetCurrentGLContextDebug();
  526. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  527. la_SetupWindowGLStates(window);
  528. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  529. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  530. #else
  531. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  532. #endif
  533. window->OutputShowStripes=1; window->Redraw=1;
  534. window->GLDebugNeedsUpdate=1;
  535. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  536. return 1;
  537. };
  538. int la_DestroySystemWindow(laWindow* wnd){
  539. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  540. nvgDeleteGLES3(wnd->nvg);
  541. #else
  542. nvgDeleteGL3(wnd->nvg);
  543. #endif
  544. #ifdef LA_LINUX
  545. la_DestroySystemWindowX11(wnd);
  546. #endif
  547. #ifdef _WIN32
  548. la_DestroySystemWindowWin32(wnd);
  549. #endif
  550. }
  551. void la_DestroyWindow(laWindow *wnd){
  552. laLayout *l; laPanel *p; if (!wnd) return;
  553. tnsSwitchToCurrentWindowContext(wnd);
  554. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  555. la_StopAllOperators();
  556. strSafeDestroy(&wnd->Title);
  557. //la_PrintUserList(wnd);
  558. //printf("----\n");
  559. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  560. while (l = lstPopItem(&wnd->Layouts)){
  561. laDestroyBlocksRecursive(l->FirstBlock);
  562. //la_PrintUserList(l);
  563. //printf("%x %s\n", l, l->ID->Ptr);
  564. strSafeDestroy(&l->ID);
  565. memFree(l);
  566. //la_PrintUserList(wnd);
  567. //printf("----\n");
  568. }
  569. //printf("----\n%x\n",wnd);
  570. //la_PrintUserList(wnd);
  571. la_DestroySystemWindow(wnd);
  572. lstRemoveItem(&MAIN.Windows, wnd);
  573. memFree(wnd);
  574. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  575. }
  576. void laRenameWindow(laWindow* wnd, char* name){
  577. if((!wnd)||MAIN.IsReadingUDF) return;
  578. strSafeSet(&wnd->Title, name);
  579. if(!wnd->win) return;
  580. #ifdef LA_LINUX
  581. XStoreName(MAIN.dpy, wnd->win, name);
  582. #endif
  583. #ifdef _WIN32
  584. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  585. SetWindowTextW(wnd->win, name);
  586. #endif
  587. }
  588. #ifdef LA_LINUX
  589. const char* la_ConvertCursorID(int id){
  590. switch (id) {
  591. case LA_ARROW: return "arrow";
  592. case LA_CROSS: return "cross";
  593. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  594. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  595. case LA_MOVE: return "diamond_cross";
  596. case LA_HAND: return "hand1";
  597. case LA_CORNER: return "bottom_right_corner";
  598. }
  599. return "arrow";
  600. }
  601. #endif
  602. #ifdef _WIN32
  603. HCURSOR la_ConvertCursorID(int id){
  604. switch (id){
  605. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  606. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  607. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  608. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  609. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  610. case LA_HAND: return LoadCursor(0, IDC_HAND);
  611. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  612. }
  613. return LoadCursor(0, IDC_ARROW);;
  614. }
  615. #endif
  616. void la_InitThreadEnviornment(){
  617. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  618. }
  619. laLogEntry* logEnsure(int Create){
  620. if(!MAIN.Logs.pFirst || Create){
  621. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  622. lstAppendItem(&MAIN.Logs, le);
  623. }
  624. return MAIN.Logs.pLast;
  625. }
  626. void logPrintTV(int Continued, char* format, va_list v){
  627. if(!format || !format[0]) return;
  628. laLogEntry* le=logEnsure(Continued);
  629. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  630. strSafePrintV(&le->Content, format, v);
  631. #ifdef LAGUI_ANDROID
  632. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  633. #endif
  634. laNotifyUsers("la.logs");
  635. }
  636. void logPrintT(int Continued, char* format, ...){
  637. if(!format || !format[0]) return;
  638. laLogEntry* le=logEnsure(Continued);
  639. va_list aptr; va_start(aptr, format);
  640. strSafePrint(&le->Content, format, aptr);
  641. va_end(aptr);
  642. #ifdef LAGUI_ANDROID
  643. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  644. #endif
  645. laNotifyUsers("la.logs");
  646. }
  647. void logPrint(char* format, ...){
  648. va_list aptr; va_start(aptr, format);
  649. logPrintTV(0, format, aptr);
  650. va_end(aptr);
  651. }
  652. void logPrintNew(char* format, ...){
  653. logEnsure(1);
  654. va_list aptr; va_start(aptr, format);
  655. logPrintTV(0, format, aptr);
  656. va_end(aptr);
  657. }
  658. void logClear(){
  659. laLogEntry*l;
  660. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  661. laNotifyUsers("la.logs");
  662. }
  663. 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;
  664. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  665. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  666. }
  667. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  668. strSafeSet(&s->Name,Name);
  669. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  670. s->x=x;s->y=y;s->w=w;s->h=h;
  671. laNotifyUsers("la.user_preferences.screens");
  672. return s;
  673. }
  674. void la_RemoveScreen(laScreen*s){
  675. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  676. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  677. }
  678. void la_RemoveDuplicatedScreenConf(){
  679. laScreen* NextS;
  680. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  681. NextS = s->Item.pNext;
  682. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  683. 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; }
  684. }
  685. }
  686. }
  687. laScreen* laGetWindowScreen(laWindow* w){
  688. int l,r,u,b; int area=-1; laScreen* maxs=0;
  689. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  690. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  691. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  692. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  693. int a=w*h; if(a>area){ maxs = s; area = a; }
  694. }
  695. return maxs;
  696. }
  697. #ifdef LA_LINUX
  698. int la_GetDPI(Window* root_win){
  699. XRRScreenResources *screen;
  700. XRROutputInfo *info;
  701. XRRCrtcInfo *crtc_info;
  702. XRRCrtcInfo *crtc;
  703. int iscres, icrtc, dpi=0;
  704. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  705. for(iscres=0;iscres<screen->noutput;iscres++){
  706. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  707. if(!info->mm_width || !info->mm_height){ continue; }
  708. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  709. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  710. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  711. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  712. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  713. XRRFreeCrtcInfo(crtc);
  714. //if(info->connection==RR_Connected){
  715. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  716. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  717. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  718. // XRRFreeCrtcInfo(crtc_info);
  719. // }
  720. //}
  721. XRRFreeOutputInfo(info);
  722. }
  723. XRRFreeScreenResources(screen);
  724. return dpi;
  725. }
  726. #endif
  727. #ifdef _WIN32
  728. typedef struct laWin32MonitorEnumData {
  729. int id;
  730. }laWin32MonitorEnumData;
  731. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  732. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  733. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  734. return TRUE;
  735. }
  736. int la_GetDPI(HWND win){
  737. laWin32MonitorEnumData data = { 0 };
  738. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  739. return GetDpiForWindow(win);
  740. return 144;
  741. }
  742. #endif
  743. #define PROGRESSW (LA_RH*15)
  744. void laShowProgress(real p1, real p2){
  745. laSpinLock(&MAIN.OpsLock);
  746. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  747. if(!MAIN.Progress.Called){
  748. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  749. }else{
  750. laTimeRecorder tm; laRecordTime(&tm);
  751. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  752. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  753. if(!MAIN.Progress.Shown){
  754. int ww=PROGRESSW+LA_RH*2;
  755. #ifdef LA_LINUX
  756. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  757. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  758. long a=LA_COLOR3_TO_HEX(bg);
  759. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  760. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  761. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  762. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  763. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  764. #endif
  765. #ifdef _WIN32
  766. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  767. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  768. ShowWindow(MAIN.Progress.w,SW_SHOW);
  769. #endif
  770. MAIN.Progress.Shown = 1;
  771. }
  772. }
  773. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  774. #ifdef LA_LINUX
  775. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  776. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  777. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  778. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  779. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  780. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  781. #endif
  782. #ifdef _WIN32
  783. InvalidateRect(MAIN.Progress.w,0,1);
  784. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  785. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  786. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  787. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  788. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  789. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  790. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  791. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  792. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  793. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  794. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  795. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  796. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  797. EndPaint(MAIN.Progress.w,&ps);
  798. MSG msg;
  799. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  800. #endif
  801. laSpinUnlock(&MAIN.OpsLock);
  802. }
  803. void laHideProgress(){
  804. laSpinLock(&MAIN.OpsLock);
  805. if(!MAIN.Progress.Shown){
  806. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  807. }
  808. laTimeRecorder tm; laRecordTime(&tm);
  809. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  810. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  811. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  812. #ifdef LA_LINUX
  813. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  814. #endif
  815. #ifdef _WIN32
  816. ShowWindow(MAIN.Progress.w,SW_HIDE);
  817. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  818. #endif
  819. laSpinUnlock(&MAIN.OpsLock);
  820. }
  821. //=======================
  822. void la_InitProgressWindow(){
  823. #ifdef LA_LINUX
  824. 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));
  825. if(!MAIN.Progress.w) return;
  826. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  827. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  828. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  829. if(MAIN.Progress.gc<0) return;
  830. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  831. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  832. XSync(MAIN.dpy,0);
  833. #endif
  834. #ifdef _WIN32
  835. WNDCLASSW wc;
  836. wc.hInstance = MAIN.hinstance;
  837. wc.lpfnWndProc = LA_ProgressWindowProc;
  838. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  839. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  840. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  841. wc.cbWndExtra = 0;
  842. wc.cbClsExtra = 0;
  843. wc.lpszClassName = L"_LAGUIPROGRESS";
  844. wc.lpszMenuName = NULL;
  845. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  846. if (!RegisterClassW(&wc)){ return; }
  847. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  848. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  849. #endif
  850. }
  851. void laSetFontFolderPath(char* absolute){
  852. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  853. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  854. }
  855. void laSetDefaultInitArguments(laInitArguments* ia){
  856. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  857. ia->UseColorManagement=0;
  858. ia->HasWorldObjects=0;
  859. ia->HasAction=0;
  860. ia->HasTextureInspector=0;
  861. ia->HasHistories=0;
  862. ia->HasTerminal=1;
  863. ia->HasAudio=0;
  864. }
  865. void laSetCompleteInitArguments(laInitArguments* ia){
  866. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  867. ia->UseColorManagement=1;
  868. ia->HasWorldObjects=1;
  869. ia->HasAction=1;
  870. ia->HasTextureInspector=1;
  871. ia->HasHistories=1;
  872. ia->HasTerminal=1;
  873. ia->HasAudio=1;
  874. }
  875. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  876. MAIN.GLMajor=MAIN.GLMinor=-1;
  877. char* arg = 0;
  878. printf("Initializing LaGUI...\n",argc);
  879. for(int i=0;i<argc;i++){
  880. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  881. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  882. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  883. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  884. }
  885. continue;
  886. }
  887. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  888. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  889. }
  890. }
  891. int laGetReadyWith(laInitArguments* ia){
  892. #ifdef LA_LINUX
  893. //signal(SIGSEGV,la_HandlerSIGSEGV);
  894. #endif
  895. laSpinInit(&MAIN.MemLock);
  896. laSpinInit(&MAIN.OpsLock);
  897. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  898. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  899. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  900. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  901. tnsInit();
  902. #ifdef LA_LINUX
  903. SYSWINDOW root, win;
  904. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  905. XSetWindowAttributes swa={0};
  906. XWindowAttributes wa={0};
  907. XEvent xev;
  908. logPrintNew("Initializing LaGUI...\n");
  909. setlocale(LC_CTYPE, "zh_CN.utf8");
  910. XSetErrorHandler(la_XErrorHandler);
  911. int i;
  912. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  913. printf("\n\tcannot connect to x server\n\n");
  914. exit(0);
  915. }
  916. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  917. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  918. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  919. #ifdef LA_USE_GLES
  920. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  921. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  922. EGLint egl_major, egl_minor;
  923. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  924. printf("Error: eglInitialize() failed\n"); return -1;
  925. }
  926. int scrnum;
  927. XSetWindowAttributes attr;
  928. XVisualInfo *visInfo, visTemplate;
  929. int num_visuals;
  930. EGLContext ctx;
  931. EGLint num_configs;
  932. EGLint vid;
  933. static const EGLint attribs[] = {
  934. EGL_RED_SIZE, 8,
  935. EGL_GREEN_SIZE, 8,
  936. EGL_BLUE_SIZE, 8,
  937. EGL_DEPTH_SIZE, 1,
  938. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  939. EGL_NONE
  940. };
  941. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  942. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  943. }
  944. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  945. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  946. }
  947. visTemplate.visualid = vid;
  948. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  949. if (!visInfo) {
  950. printf("Error: couldn't get X visual\n"); exit(1);
  951. }
  952. MAIN.xvi=visInfo;
  953. root = DefaultRootWindow(MAIN.dpy);
  954. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  955. printf("\n\tcannot create colormap\n\n"); exit(1);
  956. }
  957. eglBindAPI(EGL_OPENGL_ES_API);
  958. static const EGLint ctx_attribs[] = {
  959. EGL_CONTEXT_CLIENT_VERSION, 3,
  960. EGL_CONTEXT_MINOR_VERSION, 2,
  961. EGL_NONE
  962. };
  963. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  964. if (!MAIN.glc) {
  965. printf("Error: eglCreateContext failed\n"); exit(1);
  966. }
  967. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  968. #else
  969. int visual_attribs[] = {
  970. GLX_X_RENDERABLE , True,
  971. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  972. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  973. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  974. GLX_RED_SIZE , 8,
  975. GLX_GREEN_SIZE , 8,
  976. GLX_BLUE_SIZE , 8,
  977. GLX_ALPHA_SIZE , 8,
  978. GLX_DEPTH_SIZE , 24,
  979. //GLX_STENCIL_SIZE , 8,
  980. GLX_DOUBLEBUFFER , True,
  981. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  982. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  983. None
  984. };
  985. int fbcount = -1;
  986. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  987. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  988. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  989. MAIN.BestFBC = fbconfig[0];
  990. int sample_buf,samples;
  991. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  992. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  993. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  994. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  995. free(fbconfig);
  996. root = DefaultRootWindow(MAIN.dpy);
  997. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  998. printf("\n\tcannot create colormap\n\n"); exit(0);
  999. }
  1000. swa.colormap = MAIN.cmap;
  1001. root = DefaultRootWindow(MAIN.dpy);
  1002. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1003. MAIN.win=win;
  1004. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1005. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1006. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1007. printf("\n\tcannot create gl context\n\n"); exit(0);
  1008. }
  1009. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1010. tnsContextMakeCurrent(MAIN.glc,win,0);
  1011. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1012. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1013. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1014. int err=0;
  1015. if((err=glewInit())!=GLEW_OK){
  1016. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1017. };
  1018. #endif /* gles or glx */
  1019. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1020. la_SetCurrentGLContextDebug();
  1021. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1022. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1023. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1024. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1025. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1026. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1027. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1028. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1029. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1030. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1031. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1032. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1033. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1034. #endif //linux
  1035. #ifdef _WIN32
  1036. logPrintNew("Initializing LaGUI...\n");
  1037. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1038. setlocale(LC_ALL, "zh_CN.utf8");
  1039. MAIN.hinstance = GetModuleHandle(NULL);
  1040. HINSTANCE* hInst = &MAIN.hinstance;
  1041. WNDCLASSEXW wt;
  1042. wt.cbSize = sizeof(WNDCLASSEXW);
  1043. wt.cbClsExtra = 0;
  1044. wt.cbWndExtra = 0;
  1045. wt.hbrBackground = 0;
  1046. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1047. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1048. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1049. wt.hInstance = *hInst;
  1050. wt.lpfnWndProc = LA_WindowProc;
  1051. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1052. wt.lpszMenuName = 0;
  1053. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1054. if (!RegisterClassExW(&wt)) return 0;
  1055. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1056. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1057. SetProcessDPIAware();
  1058. GLenum err;
  1059. PIXELFORMATDESCRIPTOR pfd;
  1060. HINSTANCE* hinst = &MAIN.hinstance;
  1061. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1062. "Temp Window For Accessing GLEW!",
  1063. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1064. 0, 0, *hinst, 0);
  1065. HDC hdc = GetDC(hwnd);
  1066. HGLRC hglrc = 0;
  1067. SetPixelFormat(hdc, 1, &cpfd);
  1068. hglrc = wglCreateContext(hdc);
  1069. tnsContextMakeCurrent(hglrc, hdc,0);
  1070. //MAIN.hdc = hdc;
  1071. // MAIN.tWND = hwnd;
  1072. MAIN.glc = hglrc;
  1073. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1074. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1075. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1076. if (err = glewInit()) {
  1077. printf("Init Glew Failed\n");
  1078. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1079. return 0;
  1080. }
  1081. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1082. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1083. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1084. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1085. #endif
  1086. la_GetWorkingDirectoryInternal();
  1087. MAIN.SavePreferenceOnExit=1;
  1088. MAIN.FontSize = 0.6;
  1089. int dpi=64;
  1090. #ifdef _WIN32
  1091. dpi=la_GetDPI(hwnd);
  1092. #endif
  1093. #ifdef LA_LINUX
  1094. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1095. #endif
  1096. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1097. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1098. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1099. MAIN.UiScale=1;
  1100. MAIN.MarginSize = 1;
  1101. MAIN.ColorPickerGamma=1.5;
  1102. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1103. MAIN.ViewportHalftoneFactor=0.5;
  1104. MAIN.ViewportHalftoneSize=3.7;
  1105. tnsInitRenderKernel(64);
  1106. tnsInitBuiltinShaders();
  1107. tnsSetuptnsFontManager();
  1108. #define LOAD_FONT(font) \
  1109. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1110. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1111. LOAD_FONT("NotoEmoji-Regular.ttf");
  1112. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1113. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1114. //LOAD_FONT("NotoMusic-Regular.ttf");
  1115. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1116. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1117. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1118. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1119. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1120. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1121. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1122. MAIN.Audio=memAcquire(sizeof(laAudio));
  1123. #ifdef LA_WITH_LUAJIT
  1124. // starting lua
  1125. logPrint("Starting luajit...\n");
  1126. MAIN.L = lua_open();
  1127. la_luaLoadLibs(MAIN.L);
  1128. la_luaPrintStatus(MAIN.L);
  1129. tnsLuaInit(MAIN.L);
  1130. #endif
  1131. //interactions:
  1132. MAIN.TopFramerate = 60;
  1133. MAIN.ValuatorThreshold = 8;
  1134. MAIN.ScrollingSpeed = 3;
  1135. MAIN.AnimationSpeed = 0.4;
  1136. MAIN.PanelAnimationSpeed = 0.4;
  1137. MAIN.ZoomSpeed2D = 0.01;
  1138. MAIN.IdleTime = 0.75;
  1139. MAIN.TooltipCloseDistance = 30;
  1140. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1141. //display:
  1142. MAIN.FloatingAlpha = 0.35;
  1143. MAIN.SolidShadowLength = 20;
  1144. MAIN.WireColorSlices = 16;
  1145. MAIN.WireThickness = 5;
  1146. MAIN.WireSaggyness = 0.5;
  1147. #ifdef LAGUI_ANDROID
  1148. laAddResourceFolder("");
  1149. #else
  1150. laAddResourceFolder(".");
  1151. #endif
  1152. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1153. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1154. la_InitProgressWindow();
  1155. la_MakeTranslations();
  1156. //tns_RegisterResourcesForSoftwareRender();
  1157. la_RegisterDefaultSignals();
  1158. la_RegisterGeneralProps();
  1159. la_RegisterBuiltinTemplates();
  1160. la_RegisterMainThemes();
  1161. la_RegisterMainOperators();
  1162. la_RegisterMainUiTypes();
  1163. la_RegisterModellingOperators();
  1164. la_RegisterShapeOperators();
  1165. la_RegisterInternalProps();
  1166. la_RegisterAnimationResources();
  1167. la_RegisterWindowKeys();
  1168. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1169. laFinalizeUiTemplates();
  1170. laFinalizeOperators();
  1171. la_RegisterControllerProps();
  1172. la_RefreshControllers();
  1173. la_RegisterBasicNodes();
  1174. tns_RegisterNodes();
  1175. la_InitThreadEnviornment();
  1176. laSetRootInstance(&MAIN);
  1177. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1178. laPushDifferences(0, 0);
  1179. la_MakeDummyManagedUDF();
  1180. la_RegenerateWireColors();
  1181. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1182. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1183. logPrintNew("Initialization Completed\n");
  1184. MAIN.InitDone=1;
  1185. return 1;
  1186. }
  1187. int laGetReady(){
  1188. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1189. return laGetReadyWith(&ia);
  1190. }
  1191. void la_DestroyUiType(laUiType* uit);
  1192. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1193. void laShutoff(int SavePrefereces){
  1194. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1195. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1196. // transLate(pc->Description);
  1197. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1198. // transLate(p->Description);
  1199. // }
  1200. //}
  1201. transDumpMissMatchRecord("TranslationDump.txt");
  1202. if(MAIN.Cleanup) MAIN.Cleanup();
  1203. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1204. strSafeDestroy(&MAIN.WorkingDirectory);
  1205. strSafeDestroy(&MAIN.example_string);
  1206. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1207. // (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. )
  1208. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1209. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1210. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1211. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1212. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1213. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1214. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1215. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1216. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1217. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1218. strSafeDestroy(&MAIN.CopyPending);
  1219. la_ClearUDFRegistryAndFolders();
  1220. laClearManagedUDF();
  1221. laClearSaveProp();
  1222. logClear();
  1223. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1224. #ifdef LA_LINUX
  1225. tnsContextMakeCurrent(0,0,0);
  1226. tnsDeleteContext(MAIN.glc);
  1227. #ifdef LA_USE_GLES
  1228. eglTerminate(MAIN.egl_dpy);
  1229. #endif
  1230. #endif
  1231. #ifdef _WIN32
  1232. tnsContextMakeCurrent(0,0,0);
  1233. tnsDeleteContext(MAIN.glc);
  1234. UnloadWintab();
  1235. #endif
  1236. tnsQuit();
  1237. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1238. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1239. strSafeDump();
  1240. hshFree(&MAIN.DBInstMemLeft);
  1241. memNoLonger();
  1242. laSpinDestroy(&MAIN.MemLock);
  1243. laSpinDestroy(&MAIN.OpsLock);
  1244. #ifdef LA_WITH_LUAJIT
  1245. lua_close(MAIN.L);
  1246. #endif
  1247. printf("LaGUI has cleaned up.\n");
  1248. }
  1249. int laRestoreFactorySettings(){
  1250. char path[1024];
  1251. #ifdef LAGUI_ANDROID
  1252. sprintf(path,"%s","preferences.udf");
  1253. #else
  1254. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1255. #endif
  1256. if(remove(path)){ return 0; }
  1257. return 1;
  1258. }
  1259. void laSaveUserPreferences(){
  1260. char path[1024];
  1261. #ifdef LAGUI_ANDROID
  1262. sprintf(path,"%s","preferences.udf");
  1263. #else
  1264. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1265. #endif
  1266. laUDF* udf=laPrepareUDF(path);
  1267. laWriteProp(udf,"la.windows");
  1268. laWriteProp(udf,"la.user_preferences");
  1269. laWriteProp(udf,"la.input_mapping");
  1270. laWriteProp(udf,"la.controllers");
  1271. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1272. laWriteProp(udf,lip->p);
  1273. }
  1274. laPackUDF(udf,0,0);
  1275. }
  1276. void laEnsureUserPreferences(){
  1277. char path[1024];
  1278. #ifdef LAGUI_ANDROID
  1279. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1280. #else
  1281. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1282. #endif
  1283. laUDFRegistry* r=laFindUDFRegistry(path);
  1284. if(!r){ laSaveUserPreferences(); return; }
  1285. 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; }
  1286. laClearUDFRegistries();
  1287. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1288. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1289. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1290. laCloseUDF(udf);
  1291. la_RemoveDuplicatedScreenConf();
  1292. la_RemoveDuplicatedControllers();
  1293. laRefreshUDFRegistries();
  1294. //restore forced settings
  1295. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1296. }
  1297. void laAddExtraExtension(int FileType, ...){
  1298. va_list list; va_start(list,FileType);
  1299. char* ext;
  1300. while(ext=va_arg(list,char*)){ if(!ext) break;
  1301. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1302. et->FileType=FileType; et->Extension=ext;
  1303. lstAppendItem(&MAIN.ExtraExtensions, et);
  1304. logPrintNew("add ext %s",ext);
  1305. }
  1306. va_end(list);
  1307. }
  1308. void laAddExtraPreferencePath(const char* path){
  1309. if(!path) return;
  1310. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1311. }
  1312. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1313. if(!name || !Func) return;
  1314. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1315. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1316. }
  1317. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1318. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1319. }
  1320. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1321. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1322. }
  1323. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1324. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1325. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1326. }
  1327. void la_InputMappingGetKeyName(int key, int special, char* name){
  1328. char *_next=name; name[0]=0;
  1329. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1330. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1331. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1332. switch(key){
  1333. case ' ': strcat(name,"Space"); break;
  1334. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1335. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1336. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1337. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1338. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1339. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1340. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1341. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1342. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1343. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1344. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1345. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1346. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1347. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1348. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1349. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1350. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1351. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1352. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1353. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1354. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1355. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1356. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1357. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1358. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1359. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1360. case LA_KEY_F1: strcat(name,"F1"); break;
  1361. case LA_KEY_F2: strcat(name,"F2"); break;
  1362. case LA_KEY_F3: strcat(name,"F3"); break;
  1363. case LA_KEY_F4: strcat(name,"F4"); break;
  1364. case LA_KEY_F5: strcat(name,"F5"); break;
  1365. case LA_KEY_F6: strcat(name,"F6"); break;
  1366. case LA_KEY_F7: strcat(name,"F7"); break;
  1367. case LA_KEY_F8: strcat(name,"F8"); break;
  1368. case LA_KEY_F9: strcat(name,"F9"); break;
  1369. case LA_KEY_F10: strcat(name,"F10"); break;
  1370. case LA_KEY_F11: strcat(name,"F11"); break;
  1371. case LA_KEY_F12: strcat(name,"F12"); break;
  1372. default:
  1373. name = name+strlen(name); _next=name;
  1374. laToUTF8(key,name,&_next); *_next=0; break;
  1375. }
  1376. }
  1377. int la_InputMappingGetKeyFromName(char* name, int* special){
  1378. if(!name ||name[0]==0){ *special=0; return 0; }
  1379. *special=0;
  1380. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1381. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1382. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1383. char* p=name+strlen(name)-1;
  1384. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1385. while(*p=='+' || *p==' '){ p++; }
  1386. if(strSame(p,"Space")) return ' ';
  1387. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1388. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1389. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1390. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1391. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1392. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1393. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1394. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1395. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1396. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1397. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1398. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1399. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1400. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1401. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1402. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1403. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1404. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1405. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1406. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1407. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1408. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1409. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1410. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1411. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1412. if(strSame(p,"F1")) return LA_KEY_F1;
  1413. if(strSame(p,"F2")) return LA_KEY_F2;
  1414. if(strSame(p,"F3")) return LA_KEY_F3;
  1415. if(strSame(p,"F4")) return LA_KEY_F4;
  1416. if(strSame(p,"F5")) return LA_KEY_F5;
  1417. if(strSame(p,"F6")) return LA_KEY_F6;
  1418. if(strSame(p,"F7")) return LA_KEY_F7;
  1419. if(strSame(p,"F8")) return LA_KEY_F8;
  1420. if(strSame(p,"F9")) return LA_KEY_F9;
  1421. if(strSame(p,"F10")) return LA_KEY_F10;
  1422. if(strSame(p,"F11")) return LA_KEY_F11;
  1423. if(strSame(p,"F12")) return LA_KEY_F12;
  1424. int adv;
  1425. return laToUnicode(p,&adv);
  1426. }
  1427. laCustomSignal* laFindSignal(char* Name){
  1428. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1429. return 0;
  1430. }
  1431. laCustomSignal* laFindSignalByID(int ID){
  1432. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1433. return 0;
  1434. }
  1435. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1436. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1437. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1438. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1439. char* signal = SSTR(ime->Signal);
  1440. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1441. }
  1442. laInputMapping* laNewInputMapping(char* Name){
  1443. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1444. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1445. strSafeSet(&im->Name,Name);
  1446. return im;
  1447. }
  1448. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1449. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1450. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1451. memAssignRef(e,&e->Parent,im);
  1452. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1453. laInputMappingUpdateSignal(e);
  1454. e->SpecialKeyBits=SpecialKeyBit;
  1455. char buf[64],*_next=buf;
  1456. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1457. }
  1458. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1459. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1460. laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1461. }
  1462. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1463. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1464. }
  1465. void laRemoveInputMapping(laInputMapping* im){
  1466. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1467. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1468. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1469. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1470. }
  1471. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1472. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1473. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1474. return cs;
  1475. }
  1476. void laRemoveCustomSignal(laCustomSignal* cs){
  1477. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1478. }
  1479. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1480. void la_SendSignalsFromEvent(laEvent* e){
  1481. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1482. if(!im){return;}
  1483. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1484. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1485. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1486. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1487. }
  1488. }
  1489. }
  1490. }
  1491. //MSG====================================================
  1492. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1493. if (wnd->win == hwnd) return 1;
  1494. else return 0;
  1495. };
  1496. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1497. if (p->SL){ int s=p->SL<0?0:p->SL;
  1498. if (p->TX != s) laRecalcPanel(p);
  1499. p->TX = s;
  1500. }
  1501. if (p->SR){ int s=p->SR<0?0:p->SR;
  1502. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1503. p->TW = CW - p->TX - s;
  1504. }
  1505. if (p->ST){ int s=p->ST<0?0:p->ST;
  1506. if (p->TY != s) laRecalcPanel(p);
  1507. p->TY = s;
  1508. }
  1509. if (p->SB){ int s=p->SB<0?0:p->SB;
  1510. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1511. p->TH = CH - p->TY - s;
  1512. }
  1513. }
  1514. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1515. laPanel *p = 0;
  1516. b->X = X;
  1517. b->Y = Y;
  1518. b->W = W;
  1519. b->H = H;
  1520. if (b->B1){
  1521. int SplitWidth;
  1522. if (b->Vertical){
  1523. SplitWidth = H * b->SplitRatio;
  1524. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1525. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1526. }else{
  1527. SplitWidth = W * b->SplitRatio;
  1528. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1529. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1530. }
  1531. }
  1532. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1533. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1534. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1535. }
  1536. if (p = b->CurrentPanel){
  1537. int TitleGap=b->Folded?0:LA_RH;
  1538. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1539. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1540. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1541. laRecalcPanel(p);
  1542. }
  1543. }
  1544. void la_UpdateUiPlacement(laWindow *w){
  1545. laLayout *l;
  1546. laPanel *p;
  1547. int CW = w->CW;
  1548. int CH = w->CH;
  1549. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1550. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1551. if(w->MaximizedUi && w->MaximizedUiPanel){
  1552. laRecalcPanel(w->MaximizedUiPanel);
  1553. }elif(w->MaximizedBlock){
  1554. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1555. }else{
  1556. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1557. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1558. }
  1559. }
  1560. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1561. if(p->IsMenuPanel){
  1562. p->TH=p->H=MenuHeight;
  1563. }
  1564. la_EnsurePanelSnapping(p, CW, CH);
  1565. laRecalcPanel(p);
  1566. }
  1567. }
  1568. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1569. laWindow *window;
  1570. #ifdef LAGUI_ANDROID
  1571. window = MAIN.Windows.pFirst; if (!window) return;
  1572. window->X=x;window->Y=y;window->W=w;window->H=h;
  1573. window->CW=w;window->CH=h;
  1574. la_UpdateUiPlacement(window); return;
  1575. #endif
  1576. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1577. if (!window) return;
  1578. #ifdef _WIN32
  1579. RECT rcc; GetClientRect(window->win, &rcc);
  1580. RECT rcw; GetWindowRect(window->win, &rcw);
  1581. window->CW = rcc.right - rcc.left;
  1582. window->CH = rcc.bottom - rcc.top;
  1583. window->W = rcw.right - rcw.left;
  1584. window->H = rcw.bottom - rcw.top;
  1585. window->X = rcw.left; window->Y = rcw.top;
  1586. if (MAIN.AutoSwitchColorSpace) {
  1587. laScreen* s = laGetWindowScreen(window);
  1588. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1589. }
  1590. #endif
  1591. #ifdef LA_LINUX
  1592. XWindowAttributes attr;
  1593. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1594. window->CW = w; window->CH = h;
  1595. window->W = w; window->H = h;
  1596. window->X = x; window->Y = y;
  1597. if(MAIN.AutoSwitchColorSpace){
  1598. laScreen* s = laGetWindowScreen(window);
  1599. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1600. }
  1601. #endif
  1602. la_UpdateUiPlacement(window);
  1603. }
  1604. int la_OnWindowDestroy(SYSWINDOW wnd){
  1605. laListHandle *hlst = &MAIN.Windows;
  1606. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1607. if (!w) return 0;
  1608. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1609. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1610. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1611. laShutoff(1);
  1612. return 1;
  1613. }
  1614. laListHandle h={0};laLayout*l=0;
  1615. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1616. la_DestroyWindow(w);
  1617. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1618. #ifdef LA_LINUX
  1619. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1620. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1621. #endif
  1622. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1623. }
  1624. return 0;
  1625. }
  1626. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1627. laListHandle *el = &wnd->EventList;
  1628. laEvent* last_e=el->pLast;
  1629. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1630. #ifdef LA_LINUX
  1631. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1632. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1633. #endif
  1634. #ifdef _WIN32
  1635. 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);
  1636. #endif
  1637. }
  1638. void laMappingRequestEval();
  1639. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1640. laListHandle *wl = &MAIN.Windows;
  1641. laWindow* wnd;
  1642. #ifdef LAGUI_ANDROID
  1643. wnd = MAIN.Windows.pFirst;
  1644. #else
  1645. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1646. #endif
  1647. if (!wnd){ memFree(e); return; }
  1648. laListHandle *el = &wnd->EventList;
  1649. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1650. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1651. e->window = wnd;
  1652. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1653. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1654. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1655. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1656. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1657. e->GoodPressure=MAIN.IsPen;
  1658. lstAppendItem(el, (laListItem *)e);
  1659. laMappingRequestEval();
  1660. };
  1661. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1662. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1663. la_SaveEvent(hwnd, e, 1);
  1664. };
  1665. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1666. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1667. e->type = LA_INPUT; e->Input=Input;
  1668. la_SaveEvent(hwnd, e, 1);
  1669. }
  1670. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1671. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1672. e->type = LA_EMPTY;
  1673. la_SaveEvent(hwnd, e, 1);
  1674. }
  1675. void laSendOperatorTriggerEvent(){
  1676. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1677. MAIN.ReTriggerOperators = 0;
  1678. }
  1679. int la_TranslateSpecialKey(int keysym){
  1680. #ifdef LA_LINUX
  1681. switch(keysym){
  1682. case XK_Return: return LA_KEY_ENTER;
  1683. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1684. case XK_Delete: return LA_KEY_DELETE;
  1685. case XK_Escape: return LA_KEY_ESCAPE;
  1686. case XK_Tab: return LA_KEY_TAB;
  1687. case XK_Left: return LA_KEY_ARRLEFT;
  1688. case XK_Right: return LA_KEY_ARRRIGHT;
  1689. case XK_Up: return LA_KEY_ARRUP;
  1690. case XK_Down: return LA_KEY_ARRDOWN;
  1691. case XK_Control_L: return LA_KEY_CTRL;
  1692. case XK_Control_R: return LA_KEY_CTRL;
  1693. case XK_Shift_L: return LA_KEY_SHIFT;
  1694. case XK_Shift_R: return LA_KEY_SHIFT;
  1695. case XK_Alt_L: return LA_KEY_ALT;
  1696. case XK_Alt_R: return LA_KEY_ALT;
  1697. case XK_KP_1: return LA_KEY_NUM1;
  1698. case XK_KP_2: return LA_KEY_NUM2;
  1699. case XK_KP_3: return LA_KEY_NUM3;
  1700. case XK_KP_4: return LA_KEY_NUM4;
  1701. case XK_KP_5: return LA_KEY_NUM5;
  1702. case XK_KP_6: return LA_KEY_NUM6;
  1703. case XK_KP_7: return LA_KEY_NUM7;
  1704. case XK_KP_8: return LA_KEY_NUM8;
  1705. case XK_KP_9: return LA_KEY_NUM9;
  1706. case XK_KP_0: return LA_KEY_NUM0;
  1707. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1708. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1709. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1710. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1711. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1712. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1713. default: return keysym;
  1714. }
  1715. #endif
  1716. #ifdef _WIN32
  1717. switch (keysym) {
  1718. case VK_RETURN: return LA_KEY_ENTER;
  1719. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1720. case VK_TAB: return LA_KEY_TAB;
  1721. case VK_LEFT: return LA_KEY_ARRLEFT;
  1722. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1723. case VK_UP: return LA_KEY_ARRUP;
  1724. case VK_DOWN: return LA_KEY_ARRDOWN;
  1725. case VK_CONTROL: return LA_KEY_CTRL;
  1726. case VK_SHIFT: return LA_KEY_SHIFT;
  1727. case VK_MENU: return LA_KEY_ALT;
  1728. case VK_F1: return LA_KEY_F1;
  1729. case VK_F2: return LA_KEY_F2;
  1730. case VK_F3: return LA_KEY_F3;
  1731. case VK_F4: return LA_KEY_F4;
  1732. case VK_F5: return LA_KEY_F5;
  1733. case VK_F6: return LA_KEY_F6;
  1734. case VK_F7: return LA_KEY_F7;
  1735. case VK_F8: return LA_KEY_F8;
  1736. case VK_F9: return LA_KEY_F9;
  1737. case VK_F10: return LA_KEY_F10;
  1738. case VK_F11: return LA_KEY_F11;
  1739. case VK_F12: return LA_KEY_F12;
  1740. case VK_NUMPAD0: return LA_KEY_NUM0;
  1741. case VK_NUMPAD1: return LA_KEY_NUM1;
  1742. case VK_NUMPAD2: return LA_KEY_NUM2;
  1743. case VK_NUMPAD3: return LA_KEY_NUM3;
  1744. case VK_NUMPAD4: return LA_KEY_NUM4;
  1745. case VK_NUMPAD5: return LA_KEY_NUM5;
  1746. case VK_NUMPAD6: return LA_KEY_NUM6;
  1747. case VK_NUMPAD7: return LA_KEY_NUM7;
  1748. case VK_NUMPAD8: return LA_KEY_NUM8;
  1749. case VK_NUMPAD9: return LA_KEY_NUM9;
  1750. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1751. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1752. case VK_ADD: return LA_KEY_NUMPLUS;
  1753. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1754. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1755. case VK_OEM_1: return ';';
  1756. case VK_OEM_2: return '/';
  1757. case VK_OEM_3: return '`';
  1758. case VK_OEM_4: return '[';
  1759. case VK_OEM_5: return '\\';
  1760. case VK_OEM_6: return ']';
  1761. case VK_OEM_7: return '\'';
  1762. case VK_OEM_COMMA: return ',';
  1763. case VK_OEM_PERIOD: return '.';
  1764. case VK_OEM_PLUS: return '+';
  1765. case VK_OEM_MINUS: return '-';
  1766. default: return keysym;
  1767. }
  1768. #endif
  1769. }
  1770. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1771. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1772. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1773. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1774. // la_SaveEvent(hwnd, e, 0);
  1775. //}
  1776. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1777. e->type = type; e->x = x; e->y = y;
  1778. la_SaveEvent(hwnd, e, 0);
  1779. MAIN.evLastX=x; MAIN.evLastY=y;
  1780. };
  1781. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1782. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1783. e->type = type;
  1784. la_SaveEvent(hwnd, e, 1);
  1785. };
  1786. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1787. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1788. e->type = LA_SIGNAL_EVENT;
  1789. e->key = signal;
  1790. la_SaveEvent(hwnd, e, 1);
  1791. };
  1792. void laRetriggerOperators(){
  1793. MAIN.ReTriggerOperators = 1;
  1794. }
  1795. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1796. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1797. }
  1798. void laSetCleanupCallback(laCleanupF Cleanup){
  1799. MAIN.Cleanup=Cleanup;
  1800. }
  1801. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1802. MAIN.InputProcess=InputProcess;
  1803. }
  1804. //====================================================================================================
  1805. void la_DestroyTheme(laTheme* t){
  1806. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1807. strSafeDestroy(&t->Name);
  1808. strSafeDestroy(&t->Author);
  1809. }
  1810. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1811. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1812. strSafeSet(&t->Name, Name);
  1813. strSafeSet(&t->Author, AuthorName);
  1814. lstAppendItem(&MAIN.Themes, t);
  1815. MAIN.CurrentTheme = t;
  1816. return t;
  1817. }
  1818. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1819. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1820. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1821. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1822. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1823. strSafeSet(&bt->Name, Name);
  1824. bt->NormalY=NormalY;
  1825. bt->ActiveY=ActiveY;
  1826. bt->BorderY=BorderY;
  1827. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1828. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1829. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1830. bt->BackRef = BackRef;
  1831. lstAppendItem(&t->BoxedThemes, bt);
  1832. return bt;
  1833. }
  1834. laTheme *laGetTheme(const char *ThemeName){
  1835. laTheme *t = MAIN.Themes.pFirst;
  1836. for (t; t; t = t->Item.pNext){
  1837. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1838. }
  1839. return 0;
  1840. }
  1841. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1842. laTheme *t = MAIN.Themes.pFirst;
  1843. for (t; t; t = t->Item.pNext){
  1844. laBoxedTheme *bt;
  1845. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1846. bt = t->BoxedThemes.pFirst;
  1847. for (bt; bt; bt = bt->Item.pNext){
  1848. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1849. }
  1850. }
  1851. return 0;
  1852. }
  1853. real* laThemeColor(laBoxedTheme* bt, int which){
  1854. switch(which){
  1855. default:
  1856. case LA_BT_NORMAL: return bt->Normal;
  1857. case LA_UI_EDITING:
  1858. case LA_BT_ACTIVE: return bt->Active;
  1859. case LA_BT_BORDER: return bt->Border;
  1860. case LA_BT_TEXT: return bt->Text; break;
  1861. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1862. case LA_BT_DISABLED: return bt->Inactive; break;
  1863. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1864. }
  1865. return bt->Normal;
  1866. }
  1867. real* laAccentColor(int which){
  1868. switch(which){
  1869. default:
  1870. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1871. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1872. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1873. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1874. case LA_BT_FACE:
  1875. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1876. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1877. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1878. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1879. }
  1880. return MAIN.CurrentTheme->SelectionColor;
  1881. }
  1882. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1883. real hcy[3];
  1884. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1885. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1886. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1887. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1888. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1889. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1890. int *tm=&bt->LM,*tp=&bt->LP;
  1891. for(int i=0;i<4;i++){
  1892. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1893. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1894. }
  1895. }
  1896. void la_RefreshThemeColorSelf(laTheme* th){
  1897. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1898. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1899. real hcy[3], usehcy[3];
  1900. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1901. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1902. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1903. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1904. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1905. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1906. }
  1907. void la_RefreshThemeColor(laTheme* th){
  1908. real hcy[3], usehcy[3], normalhcy[3];
  1909. tnsRGB2HCY(th->Color,hcy);
  1910. la_RefreshThemeColorSelf(th);
  1911. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1912. la_RefreshBoxedThemeColor(bt);
  1913. (*bt->BackRef) = bt;
  1914. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1915. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1916. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1917. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1918. }
  1919. }
  1920. //I FUCKING HATE THIS STUPID FUNCTION
  1921. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1922. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1923. laUiListDrawItem *last = uild->Items.pFirst;
  1924. int LimW=_R-_L;
  1925. int SL, SR, SU, SB;
  1926. int Target__B = Target->B;
  1927. int Target__R = Target->R;
  1928. uildi->Target = Target;
  1929. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1930. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1931. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1932. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1933. uildi->L = last ? Target->L - last->XP : Target->L;
  1934. uildi->R = last ? Target__R - last->XP : Target__R;
  1935. uildi->U = last ? Target->U - last->YP : Target->U;
  1936. uildi->B = last ? Target__B - last->YP : Target__B;
  1937. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1938. uildi->L -= GlobalX;
  1939. uildi->R -= GlobalX;
  1940. uildi->U -= GlobalY;
  1941. uildi->B -= GlobalY;
  1942. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1943. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1944. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1945. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1946. uildi->DifX = SL - uildi->L;
  1947. uildi->DifY = SU - uildi->U;
  1948. uildi->L = SL;
  1949. uildi->R = SR+uildi->DifX;
  1950. uildi->U = SU;
  1951. uildi->B = SB;//+uildi->DifY;
  1952. if(uildi->R>_R){ uildi->R=_R; }
  1953. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1954. //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);
  1955. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1956. memFree(uildi);
  1957. return 0;
  1958. }
  1959. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  1960. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  1961. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  1962. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  1963. Target->U + Target->PanY + uildi->DifY+1,
  1964. -100, 100);
  1965. lstPushItem(&uild->Items, uildi);
  1966. return 1;
  1967. }
  1968. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1969. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1970. laUiListDrawItem *last = uild->Items.pFirst;
  1971. int SL, SR, SU, SB;
  1972. if (B - U > LimH) B = U + LimH;
  1973. uildi->XP = last ? last->XP + PanX : PanX;
  1974. uildi->YP = last ? last->YP + PanY : PanY;
  1975. uildi->L = last ? L - last->XP : L;
  1976. uildi->R = last ? R - last->XP : R;
  1977. uildi->U = last ? U - last->YP : U;
  1978. uildi->B = last ? B - last->YP : B;
  1979. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1980. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1981. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1982. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1983. uildi->DifX = SL - uildi->L;
  1984. uildi->DifY = SU - uildi->U;
  1985. uildi->L = SL;
  1986. uildi->R = SR;
  1987. uildi->U = SU;
  1988. uildi->B = SB;
  1989. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1990. tnsOrtho(L + PanX + uildi->DifX,
  1991. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  1992. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  1993. U + PanY + uildi->DifY,
  1994. -100, 100);
  1995. lstPushItem(&uild->Items, uildi);
  1996. }
  1997. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  1998. int* savel, int* saver, int* saveu, int* saveb){
  1999. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2000. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2001. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2002. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2003. real x,y,w,h;
  2004. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2005. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2006. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2007. }
  2008. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2009. laUiListDrawItem *uildi = uild->Items.pFirst;
  2010. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2011. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2012. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2013. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2014. Target->U + Target->PanY + uildi->DifY -1,
  2015. -100, 100);
  2016. }
  2017. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2018. laUiListDrawItem *uildi = lstPopItem(uild);
  2019. laUiList *Target;
  2020. memFree(uildi);
  2021. uildi = uild->Items.pFirst;
  2022. if (!uildi || !uildi->Target){
  2023. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2024. return;
  2025. }
  2026. Target = uildi->Target;
  2027. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2028. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2029. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2030. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2031. Target->U + Target->PanY + uildi->DifY -1,
  2032. -100, 100);
  2033. }
  2034. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2035. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2036. uildi->L = L;
  2037. uildi->R = R;
  2038. uildi->U = U;
  2039. uildi->B = B;
  2040. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2041. tnsOrtho(L, R, B, U, -100, 100);
  2042. lstPushItem(&uild->Items, uildi);
  2043. }
  2044. void la_ClearUiListMatrix(laUiListDraw *uild){
  2045. laUiListDrawItem *uildi;
  2046. while (uildi = lstPopItem(uild)){
  2047. memFree(uildi);
  2048. }
  2049. }
  2050. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2051. 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);
  2052. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2053. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2054. int la_TestUiListMinumWidth(laUiList *uil);
  2055. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2056. if (ui){
  2057. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2058. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2059. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2060. p->X = p->TX; p->Y = p->TY;
  2061. p->W = p->TW;
  2062. }
  2063. }
  2064. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2065. int cw = MAIN.CurrentWindow->CW;
  2066. int ch = MAIN.CurrentWindow->CH;
  2067. int PH = p->TH;
  2068. laBoxedTheme*bt = *p->BT;
  2069. int uih=uil->B + bt->BM;
  2070. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2071. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2072. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2073. else p->TH = PH;
  2074. p->H = p->TH;
  2075. if(p->BoundUi){
  2076. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2077. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2078. if (p->X < 0) p->X = 0;
  2079. if (p->Y < 0) p->Y = 0;
  2080. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2081. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2082. }else{
  2083. if (p->Y < 0) p->Y = 0;
  2084. if ((!p->Block)&&(!p->IsMenuPanel)){
  2085. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2086. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2087. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2088. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2089. }
  2090. }
  2091. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2092. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2093. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2094. }
  2095. if (p->ST) p->TY = p->ST;
  2096. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2097. if (p->SB) p->TH = ch - p->TY - p->SB;
  2098. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2099. p->TX = p->X; p->TY = p->Y;
  2100. p->TW = p->W; p->TH = p->H;
  2101. }
  2102. void laPlacePanelForCreation(laPanel *p){
  2103. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2104. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2105. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2106. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2107. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2108. p->TX=p->X; p->TY=p->Y;
  2109. }
  2110. }
  2111. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2112. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2113. tnsViewportWithScissor(0, 0, p->W, p->H);
  2114. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2115. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2116. }
  2117. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2118. tnsDrawToScreen();
  2119. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2120. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2121. }
  2122. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2123. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2124. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2125. }
  2126. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2127. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2128. tnsClearAll();
  2129. }
  2130. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2131. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2132. real Color[] = {1, 1, 1, 1};
  2133. real L, W, U, H;
  2134. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2135. if(MAIN.EnableColorManagement){
  2136. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2137. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2138. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2139. }else{
  2140. tnsUniformOutputColorSpace(T->immShader,0);
  2141. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2142. tnsUniformColorComposing(T->immShader,0,0,0);
  2143. }
  2144. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2145. tnsUseNoTexture();
  2146. if (!p->IsMenuPanel){
  2147. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2148. }
  2149. tnsFlush();
  2150. }
  2151. if(p->ParentOperator){
  2152. tnsUseNoTexture();
  2153. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2154. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2155. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2156. }
  2157. switch (p->AnimationMode){
  2158. case 0: /* and */
  2159. case LA_PANEL_ANIMATION_FLASH:
  2160. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2161. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2162. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2163. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2164. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2165. tnsPackAs(GL_TRIANGLES);
  2166. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2167. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2168. }
  2169. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2170. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2171. if((int)(p->AnimationRatio*6)%2){
  2172. tnsUseNoTexture();
  2173. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2174. 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);
  2175. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2176. }
  2177. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2178. }
  2179. break;
  2180. case LA_PANEL_ANIMATION_DROP_DOWN:
  2181. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2182. tnsDraw2DTextureArg(
  2183. p->OffScr->pColor[0],
  2184. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2185. Color,
  2186. 0, 0, 1 - p->AnimationRatio, 0);
  2187. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2188. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2189. break;
  2190. case LA_PANEL_ANIMATION_EXPAND:
  2191. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2192. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2193. W = tnsLinearItp(0, p->W, 0.4);
  2194. H = tnsLinearItp(0, p->H, 0.4);
  2195. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2196. tnsDraw2DTextureArg(
  2197. p->OffScr->pColor[0],
  2198. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2199. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2200. Color,
  2201. 0, 0, 0, 0);
  2202. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2203. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2204. break;
  2205. case LA_PANEL_ANIMATION_DISSOVE:
  2206. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2207. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2208. W = tnsLinearItp(0, p->W, 1.4);
  2209. H = tnsLinearItp(0, p->H, 1.4);
  2210. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2211. if (p->OffScr) tnsDraw2DTextureArg(
  2212. p->OffScr->pColor[0],
  2213. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2214. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2215. Color,
  2216. 0, 0, 0, 0);
  2217. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2218. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2219. break;
  2220. case LA_PANEL_ANIMATION_COLLAPSE:
  2221. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2222. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2223. W = tnsLinearItp(0, p->W, 0.4);
  2224. H = tnsLinearItp(0, p->H, 0.4);
  2225. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2226. if (p->OffScr) tnsDraw2DTextureArg(
  2227. p->OffScr->pColor[0],
  2228. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2229. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2230. Color,
  2231. 0, 0, 0, 0);
  2232. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2233. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2234. break;
  2235. case LA_PANEL_ANIMATION_MINIMIZE:
  2236. L = tnsLinearItp(0, p->X, 0.3);
  2237. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2238. W = tnsLinearItp(0, p->W, 0.4);
  2239. H = tnsLinearItp(0, p->H, 0.4);
  2240. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2241. tnsDraw2DTextureArg(
  2242. p->OffScr->pColor[0],
  2243. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2244. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2245. Color,
  2246. 0, 0, 0, 0);
  2247. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2248. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2249. break;
  2250. }
  2251. tnsFlush();
  2252. tnsUniformOutputColorSpace(T->immShader,0);
  2253. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2254. tnsUniformColorComposing(T->immShader,0,0,0);
  2255. }
  2256. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2257. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2258. else{
  2259. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:GL_RGBA8;
  2260. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2261. }
  2262. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2263. }
  2264. void la_PanelRefreshDetachedProp(laPanel *panel){
  2265. laProp *p;
  2266. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2267. la_StepPropPack(&p->DetachedPP);
  2268. la_UsePropPack(&p->DetachedPP, 0);
  2269. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2270. // laUseDataBlock(
  2271. // p->DetachedPP.LastPs->UseInstance,
  2272. // p->DetachedPP.LastPs->p,
  2273. // MAIN.PropMatcherContextP->FrameDistinguish,
  2274. // MAIN.PropMatcherContextP,
  2275. // la_PropPanelUserRemover, 0);
  2276. //}
  2277. }
  2278. }
  2279. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2280. real* color=laThemeColor(bt,LA_BT_BORDER);
  2281. tnsColor4d(0,0,0,Alpha);
  2282. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2283. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2284. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2285. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2286. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2287. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2288. tnsPackAs(GL_TRIANGLE_STRIP);
  2289. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2290. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2291. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2292. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2293. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2294. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2295. }
  2296. int la_AnimateUiListRecursive(laUiList *uil);
  2297. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2298. int DrawState_ = 0;
  2299. laUiListDraw uild = {0};
  2300. if (p->Show){
  2301. la_SetPropMathcerContext(p);
  2302. MAIN.CurrentPanel = p;
  2303. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2304. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2305. //}
  2306. if (p->Refresh & LA_TAG_RECALC){
  2307. laRecalcPanelImmediate(p);
  2308. }
  2309. if (!p->MenuRefer){
  2310. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2311. if (p->Refresh || !p->OffScr){
  2312. la_PanelDrawToOffsceen(p, &p->UI);
  2313. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2314. la_PanelBackgroundInit(p, bt);
  2315. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2316. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2317. tnsFlush();
  2318. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2319. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2320. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2321. DrawState_++;
  2322. }
  2323. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2324. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2325. if(p->UI.PanY<0){p->UI.PanY=0;}
  2326. DrawState_++;
  2327. }
  2328. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2329. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2330. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2331. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2332. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2333. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2334. if(p!=w->MaximizedUiPanel){
  2335. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2336. }else{
  2337. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2338. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2339. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2340. tnsFlush();
  2341. }
  2342. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2343. }
  2344. }else{
  2345. if (p->Refresh || !p->OffScr){
  2346. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2347. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2348. la_PanelBackgroundInit(p, bt);
  2349. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2350. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2351. tnsFlush();
  2352. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2353. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2354. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2355. DrawState_++;
  2356. }
  2357. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2358. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2359. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2360. DrawState_++;
  2361. }
  2362. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2363. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2364. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2365. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2366. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2367. }
  2368. }
  2369. tnsDrawToScreen();
  2370. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2371. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2372. la_PanelDrawToWindow(p, w);
  2373. }elif (p->AnimationMode){
  2374. la_PanelDrawToWindow(p, w);
  2375. }
  2376. }
  2377. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2378. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2379. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2380. laPanel *pi, *PrevPI;
  2381. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2382. PrevPI = pi->Item.pPrev;
  2383. if (pi->AnimationMode && pi->LaterDestroy){
  2384. lstRemoveItem(&p->SubPanels, pi);
  2385. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2386. continue;
  2387. }
  2388. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2389. la_AttachedPanelDefDraw(w,pi,bt);
  2390. }
  2391. }
  2392. }
  2393. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2394. real PanelSquare[] = {
  2395. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2396. b->X + 2, CH - (b->Y + b->H - 4),
  2397. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2398. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2399. real Center[] = {
  2400. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2401. real DraggingPlot[] = {
  2402. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2403. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2404. PanelSquare[0],
  2405. PanelSquare[1],
  2406. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2407. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2408. PanelSquare[2],
  2409. PanelSquare[3],
  2410. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2411. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2412. PanelSquare[4],
  2413. PanelSquare[5],
  2414. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2415. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2416. PanelSquare[6],
  2417. PanelSquare[7],
  2418. };
  2419. real Square[] = {
  2420. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2421. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2422. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2423. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2424. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2425. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2426. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2427. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2428. };
  2429. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2430. LA_COLOR3(BorderColor4dV), 0,
  2431. LA_COLOR3(BorderColor4dV), 0.8,
  2432. LA_COLOR3(BorderColor4dV), 0,
  2433. LA_COLOR3(BorderColor4dV), 0.8,
  2434. LA_COLOR3(BorderColor4dV), 0,
  2435. LA_COLOR3(BorderColor4dV), 0.8,
  2436. LA_COLOR3(BorderColor4dV), 0,
  2437. };
  2438. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2439. LA_COLOR3(FillColor4dv), 0,
  2440. LA_COLOR3(FillColor4dv), 0.8,
  2441. LA_COLOR3(FillColor4dv), 0,
  2442. LA_COLOR3(FillColor4dv), 0.8,
  2443. LA_COLOR3(FillColor4dv), 0,
  2444. LA_COLOR3(FillColor4dv), 0.8,
  2445. LA_COLOR3(FillColor4dv), 0,
  2446. };
  2447. tnsUseNoTexture();
  2448. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2449. int Index[4];
  2450. tnsVertexArray2d(DraggingPlot, 8);
  2451. tnsColorArray4d(FillColor, 8);
  2452. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2453. case 0:
  2454. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2455. break;
  2456. case LA_BLOCK_DROP_LOCATION_L:
  2457. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2458. break;
  2459. case LA_BLOCK_DROP_LOCATION_R:
  2460. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2461. break;
  2462. case LA_BLOCK_DROP_LOCATION_U:
  2463. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2464. break;
  2465. case LA_BLOCK_DROP_LOCATION_B:
  2466. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2467. break;
  2468. }
  2469. //glDisable(GL_CULL_FACE);
  2470. tnsIndexArray(Index, 4);
  2471. tnsPackAs(GL_TRIANGLE_FAN);
  2472. //tnsFlush();
  2473. }
  2474. tnsVertexArray2d(DraggingPlot, 8);
  2475. tnsColorArray4d(PlotColor, 8);
  2476. tnsPackAs(GL_LINES);
  2477. tnsVertexArray2d(Square, 4);
  2478. tnsColor4dv(BorderColor4dV);
  2479. tnsPackAs(GL_LINE_LOOP);
  2480. glLineWidth(LA_SEAM_W);
  2481. tnsFlush();
  2482. glLineWidth(1);
  2483. }
  2484. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2485. laBoxedTheme *bt = _LA_THEME_TAB;
  2486. laPanel *p;
  2487. real v[] = {
  2488. b->X, CH - b->Y,
  2489. b->X + LA_SEAM_W, CH - b->Y ,
  2490. b->X, CH - (b->Y + b->H),
  2491. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2492. b->X + b->W, CH - (b->Y + b->H),
  2493. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2494. b->X + b->W, CH - b->Y,
  2495. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2496. real tv[8];
  2497. real ratio = 1.0001f;
  2498. int tw = 0;
  2499. int L = LA_RH+LA_SEAM_W;
  2500. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2501. if(MAIN.EnableColorManagement){
  2502. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2503. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2504. }else{
  2505. tnsUniformOutputColorSpace(T->immShader,0);
  2506. tnsUniformColorComposing(T->immShader,0,0,0);
  2507. }
  2508. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2509. tw += p->TitleWidth + LA_SEAM_W*2;
  2510. }
  2511. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2512. tnsUseNoTexture();
  2513. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2514. tnsVertexArray2d(v, 8);
  2515. tnsPackAs(GL_TRIANGLE_STRIP);
  2516. int TitleGap=b->Folded?0:LA_RH;
  2517. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2518. b->X + b->W, (CH - b->Y),
  2519. b->X + b->W, (CH - b->Y - TitleGap),
  2520. b->X, (CH - b->Y - TitleGap));
  2521. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2522. tnsVertexArray2d(tv, 4);
  2523. tnsPackAs(GL_TRIANGLE_FAN);
  2524. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2525. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2526. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2527. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2528. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2529. tnsVertexArray2d(tv, 4);
  2530. tnsPackAs(GL_TRIANGLE_FAN);
  2531. if(b->Folded){
  2532. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2533. 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);
  2534. 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);
  2535. tnsFlush(); return;
  2536. }
  2537. int LT=0,RT=0;
  2538. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2539. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2540. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2541. b->X + L+RT * ratio, (CH - b->Y),
  2542. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2543. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2544. if (p == b->CurrentPanel){
  2545. tnsUseNoTexture();
  2546. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2547. tnsVertexArray2d(tv, 4);
  2548. tnsPackAs(GL_TRIANGLE_FAN);
  2549. 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);
  2550. }else{
  2551. 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);
  2552. }
  2553. LT =RT;
  2554. }
  2555. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2556. tnsFlush();
  2557. tnsUniformOutputColorSpace(T->immShader,0);
  2558. tnsUniformColorComposing(T->immShader,0,0,0);
  2559. }
  2560. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2561. laBoxedTheme *bt = _LA_THEME_PANEL;
  2562. real tv[8];
  2563. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2564. if(MAIN.EnableColorManagement){
  2565. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2566. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2567. }else{
  2568. tnsUniformOutputColorSpace(T->immShader,0);
  2569. tnsUniformColorComposing(T->immShader,0,0,0);
  2570. }
  2571. tnsUseNoTexture();
  2572. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2573. b->X + b->W, (CH - b->Y),
  2574. b->X + b->W, (CH - b->Y-b->H),
  2575. b->X, (CH - b->Y-b->H));
  2576. tnsVertexArray2d(tv, 4);
  2577. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2578. tnsPackAs(GL_TRIANGLE_FAN);
  2579. 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,
  2580. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2581. tnsFlush();
  2582. tnsUniformOutputColorSpace(T->immShader,0);
  2583. tnsUniformColorComposing(T->immShader,0,0,0);
  2584. }
  2585. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2586. if (b->B1){
  2587. la_BlockDefDrawRecursive(w, bt, b->B1);
  2588. la_BlockDefDrawRecursive(w, bt, b->B2);
  2589. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2590. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2591. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2592. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2593. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2594. la_BlockDefDrawSelf(b, w->CH);
  2595. }else{
  2596. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2597. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2598. la_BlockDefDrawSelfEmpty(b, w->CH);
  2599. }
  2600. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2601. tnsUseNoTexture();
  2602. int at; real tv[8];
  2603. if (b->Vertical){
  2604. at = b->H * b->SplitRatio + b->Y;
  2605. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2606. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2607. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2608. b->X, (w->CH - at - LA_SEAM_W));
  2609. }else{
  2610. at = b->X + b->W * b->SplitRatio;
  2611. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2612. at- LA_SEAM_W, (w->CH - b->Y),
  2613. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2614. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2615. }
  2616. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2617. tnsVertexArray2d(tv, 4);
  2618. tnsPackAs(GL_TRIANGLE_FAN);
  2619. }
  2620. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2621. tnsFlush();
  2622. }
  2623. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2624. if (b->B1){
  2625. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2626. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2627. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2628. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2629. }
  2630. tnsFlush();
  2631. }
  2632. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2633. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2634. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2635. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2636. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2637. if(p->OffScr){
  2638. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2639. }
  2640. }
  2641. }
  2642. void la_ClearUnusedFramebuffers(laWindow* w){
  2643. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2644. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2645. }
  2646. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2647. if(p->Show || p->AnimationMode) continue;
  2648. if(p->OffScr){
  2649. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2650. }
  2651. }
  2652. }
  2653. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2654. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2655. laPanel *p, *NextP;
  2656. laLayout *l = w->CurrentLayout;
  2657. if (!w->CH || !w->CW) return;
  2658. la_ClearUnusedFramebuffers(w);
  2659. tnsDrawToScreen();
  2660. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2661. glClearColor(0.2, 0.2, 0.3, 1.0);
  2662. tnsClearAll();
  2663. tnsUseNoTexture();
  2664. if (l->Draw) l->Draw(w, l);
  2665. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2666. glEnable(GL_BLEND);
  2667. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2668. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2669. laUiItem* ui;
  2670. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2671. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2672. la_SetPropMathcerContext(p);
  2673. if(p->Refresh){
  2674. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2675. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2676. if(MAIN.EnableColorManagement){
  2677. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2678. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2679. }else{
  2680. tnsUniformOutputColorSpace(T->immShader,0);
  2681. tnsUniformColorComposing(T->immShader,0,0,0);
  2682. }
  2683. if(p->Refresh&LA_TAG_RECALC){
  2684. laRecalcPanelImmediate(p);
  2685. }
  2686. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2687. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2688. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2689. }
  2690. tnsDrawToScreen();
  2691. tnsResetViewMatrix();
  2692. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2693. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2694. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2695. tnsFlush();
  2696. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2697. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2698. tnsFlush();
  2699. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2700. }
  2701. }
  2702. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2703. la_AttachedPanelDefDraw(w,p,*p->BT);
  2704. }else{
  2705. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2706. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2707. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2708. }
  2709. for (p = w->Panels.pLast; p; p = NextP){
  2710. NextP = p->Item.pPrev;
  2711. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2712. if (p->AnimationMode && p->LaterDestroy){
  2713. lstRemoveItem(&w->Panels, p);
  2714. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2715. continue;
  2716. }
  2717. la_PanelDefDraw(w, p, *p->BT);
  2718. }
  2719. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2720. la_AttachedPanelDefDraw(w,p,*p->BT);
  2721. }
  2722. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2723. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2724. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2725. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2726. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2727. tnsFlush();
  2728. }
  2729. for (p = w->FadingPanels.pLast; p; p = NextP){
  2730. NextP = p->Item.pPrev;
  2731. if (!p->AnimationMode){
  2732. lstRemoveItem(&w->FadingPanels, p);
  2733. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2734. laDeferredDestroyPanel(p, 0);
  2735. }else
  2736. la_PanelDrawToWindow(p, w);
  2737. }
  2738. }
  2739. int laStartWindow(laWindow *w){
  2740. #ifdef LA_LINUX
  2741. XMapWindow(MAIN.dpy,w->win);
  2742. tnsContextMakeWindowCurrent(w);
  2743. #endif
  2744. #ifdef _WIN32
  2745. ShowWindow(w->win, SW_SHOWNORMAL);
  2746. #endif
  2747. MAIN.CurrentWindow = w;
  2748. if(!w->CurrentLayout){
  2749. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2750. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2751. }
  2752. laRedrawCurrentWindow();
  2753. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2754. w->Shown = 1;
  2755. }
  2756. void la_AssignWindowPP(laWindow* w){
  2757. w->PP.EndInstance = w;
  2758. w->PP.LastPs = &w->FakePS;
  2759. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2760. w->PP.LastPs->UseInstance = w;
  2761. w->PP.LastPs->Type = U'.';
  2762. }
  2763. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2764. #ifdef LAGUI_ANDROID
  2765. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2766. #endif
  2767. laWindow *n = memAcquire(sizeof(laWindow));
  2768. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2769. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2770. #ifdef LAGUI_ANDROID
  2771. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2772. #endif
  2773. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2774. lstAppendItem(&MAIN.Windows, n);
  2775. MAIN.CurrentWindow = n;
  2776. la_AssignWindowPP(n);
  2777. laui_DefaultMenuBar(n);
  2778. return n;
  2779. }
  2780. void laSetWindowCursor(int id){
  2781. MAIN.CurrentCursor = id;
  2782. #ifdef LA_LINUX
  2783. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2784. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2785. #endif
  2786. #ifdef _WIN32
  2787. SetCursor(la_ConvertCursorID(id));
  2788. #endif
  2789. };
  2790. void la_AssignBlockPP(laBlock* b){
  2791. b->PP.EndInstance = b;
  2792. b->PP.LastPs = &b->FakePS;
  2793. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2794. b->PP.LastPs->UseInstance = b;
  2795. b->PP.LastPs->Type = U'.';
  2796. }
  2797. void laDestroyLayout(laWindow *w, laLayout* l){
  2798. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2799. laDestroyBlocksRecursive(l->FirstBlock);
  2800. strSafeDestroy(&l->ID);
  2801. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2802. lstRemoveItem(&w->Layouts,l); memFree(l);
  2803. }
  2804. laLayout *laDesignLayout(laWindow *w, char *Title){
  2805. laLayout *l = memAcquire(sizeof(laLayout));
  2806. l->FirstBlock = memAcquire(sizeof(laBlock));
  2807. la_AssignBlockPP(l->FirstBlock);
  2808. lstAppendItem(&w->Layouts, l);
  2809. strSafeSet(&l->ID, Title);
  2810. memAssignRef(w, &w->CurrentLayout, l);
  2811. laRenameWindow(w, Title);
  2812. return l;
  2813. }
  2814. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2815. 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); }
  2816. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2817. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2818. laNotifyUsers("la.windows.maximized_block"); }
  2819. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2820. laNotifyUsers("la.windows.maximized_block"); }
  2821. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2822. laRestoreCanvasUI();
  2823. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2824. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2825. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2826. UiParentPanel->Show=0;
  2827. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2828. }
  2829. void laRestoreCanvasUI(){
  2830. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2831. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2832. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2833. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2834. }
  2835. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2836. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2837. }
  2838. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2839. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2840. laPanel *p;
  2841. b->SplitRatio = Percentage;
  2842. b->Vertical = 0;
  2843. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2844. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2845. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2846. p->Block = b->B1;
  2847. }
  2848. b->B1->Panels.pFirst = b->Panels.pFirst;
  2849. b->B1->Panels.pLast = b->Panels.pLast;
  2850. b->B1->CurrentPanel = b->CurrentPanel;
  2851. b->B1->parent = b->B2->parent=b;
  2852. b->Panels.pFirst = 0;
  2853. b->Panels.pLast = 0;
  2854. b->CurrentPanel = 0;
  2855. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2856. }
  2857. void laSplitBlockVertical(laBlock *b, real Percentage){
  2858. laPanel *p;
  2859. b->SplitRatio = Percentage;
  2860. b->Vertical = 1;
  2861. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2862. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2863. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2864. p->Block = b->B1;
  2865. }
  2866. b->B1->Panels.pFirst = b->Panels.pFirst;
  2867. b->B1->Panels.pLast = b->Panels.pLast;
  2868. b->B1->CurrentPanel = b->CurrentPanel;
  2869. b->B1->parent = b->B2->parent=b;
  2870. b->Panels.pFirst = 0;
  2871. b->Panels.pLast = 0;
  2872. b->CurrentPanel = 0;
  2873. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2874. }
  2875. void laCombineChildBlocks(laBlock *b){
  2876. laPanel *p; if(!b) return;
  2877. if (!b->B1->B1 && !b->B2->B1){
  2878. lstCombineLists(&b->Panels, &b->B1->Panels);
  2879. lstCombineLists(&b->Panels, &b->B2->Panels);
  2880. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2881. p->Block = b;
  2882. }
  2883. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2884. memFree(b->B1);
  2885. memFree(b->B2);
  2886. b->B1 = 0;
  2887. b->B2 = 0;
  2888. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2889. }elif(!b->B1->B1){
  2890. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2891. b->Vertical = b->B2->Vertical;
  2892. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2893. p->Block = b1;
  2894. }
  2895. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2896. memFree(b->B1); memFree(b->B2);
  2897. b->B1 = b1; b->B2 = b2;
  2898. b1->parent = b; b2->parent = b;
  2899. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2900. }elif(!b->B2->B1){
  2901. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2902. b->Vertical = b->B1->Vertical;
  2903. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2904. p->Block = b1;
  2905. }
  2906. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2907. memFree(b->B1); memFree(b->B2);
  2908. b->B1 = b1; b->B2 = b2;
  2909. b1->parent = b; b2->parent = b;
  2910. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2911. }
  2912. }
  2913. laBlock *laBlock1(laBlock *b){
  2914. return b->B1;
  2915. }
  2916. laBlock *laBlock2(laBlock *b){
  2917. return b->B2;
  2918. }
  2919. laBlock *laSwapSubBlocks(laBlock *b){
  2920. laBlock *tB;
  2921. tB = b->B2;
  2922. b->B2 = b->B1;
  2923. b->B1 = tB;
  2924. b->SplitRatio = 1 - b->SplitRatio;
  2925. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2926. }
  2927. void laDestroyBlocksRecursive(laBlock *Root){
  2928. laPanel *p;
  2929. if (Root->B1){
  2930. laDestroyBlocksRecursive(Root->B1);
  2931. laDestroyBlocksRecursive(Root->B2);
  2932. }else{
  2933. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2934. }
  2935. memFree(Root);
  2936. }
  2937. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2938. if(!b->CurrentPanel ) return 0;
  2939. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2940. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2941. lstRemoveItem(&b->Panels, p);
  2942. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  2943. if(!p->TitleBar.UiItems.pFirst){
  2944. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2945. }
  2946. p->Mode = LA_PANEL_FLOATING_TOP;
  2947. p->TY-=LA_RH; p->TH+=LA_RH;
  2948. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  2949. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  2950. p->Block = 0;
  2951. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  2952. laRecalcPanel(p);
  2953. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2954. p->BT = &_LA_THEME_FLOATING_PANEL;
  2955. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2956. laNotifyUsers("la.windows.panels");
  2957. return b->CurrentPanel;
  2958. }
  2959. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2960. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2961. lstRemoveItem(&from->Panels, p);
  2962. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2963. p->Mode = LA_PANEL_NORMAL;
  2964. p->Block=b;
  2965. b->CurrentPanel = p;
  2966. lstPushItem(&b->Panels, p);
  2967. laRecalcPanel(p);
  2968. p->BT = &_LA_THEME_PANEL;
  2969. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2970. tnsFlush();
  2971. laNotifyUsers("la.windows.panels");
  2972. }
  2973. void laPopPanel(laPanel *p){
  2974. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2975. lstRemoveItem(&p->Parent->SubPanels, p);
  2976. lstPushItem(&p->Parent->SubPanels, p);
  2977. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2978. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2979. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2980. laNotifyUsers("la.windows.panels");
  2981. }
  2982. }
  2983. void la_EnsurePanelExtras(laPanel *p){
  2984. laUiTemplate* uit=p->PanelTemplate;
  2985. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  2986. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  2987. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  2988. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  2989. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  2990. p->PropLinkFakeProp->Base.Offset = 0;
  2991. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  2992. p->PropLinkPP.EndInstance = p;
  2993. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  2994. p->PropLinkPP.LastPs->Type = U'.';
  2995. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  2996. }
  2997. laPanel* la_GivePanelNode(){
  2998. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  2999. return memAcquire(sizeof(laPanel));
  3000. }
  3001. void la_ReturnPanelNode(laPanel* p){
  3002. memset(p,0,sizeof(laPanel));
  3003. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3004. lstAppendItem(&MAIN.WastedPanels, p);
  3005. }
  3006. 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){
  3007. laPanel *p = la_GivePanelNode();
  3008. int CW = MAIN.CurrentWindow->CW;
  3009. int CH = MAIN.CurrentWindow->CH;
  3010. p->PanelTemplate = uit;
  3011. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3012. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3013. if (!MaxW) MaxW = 10000;
  3014. if (!MaxH) MaxH = 10000;
  3015. if (W > MaxW) W = MaxW;
  3016. if (H > MaxH) H = MaxH;
  3017. if (W < MinW) W = MinW;
  3018. if (H < MinH) H = MinH;
  3019. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3020. p->X = p->TX = (X < 0 ? 0 : X);
  3021. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3022. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3023. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3024. p->MaxW = MaxW; p->MaxH = MaxH;
  3025. p->MinW = MinW; p->MinH = MinH;
  3026. p->SL = SnapL; p->ST = SnapT;
  3027. p->SR = SnapR; p->SB = SnapB;
  3028. if (p->SR) p->X = CW - p->W - p->SR;
  3029. if (p->SB) p->Y = CH - p->H - p->SB;
  3030. la_EnsurePanelSnapping(p, CW, CH);
  3031. p->Show = 1;
  3032. p->PP.EndInstance = p;
  3033. p->PP.LastPs = &p->FakePS;
  3034. p->PP.LastPs->p = _LA_PROP_PANEL;
  3035. p->PP.LastPs->UseInstance = p;
  3036. p->PP.LastPs->Type = U'.';
  3037. la_EnsurePanelExtras(p);
  3038. laRecalcPanel(p);
  3039. p->FrameDistinguish = 100; //greater than 1 is ok
  3040. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3041. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3042. return p;
  3043. }
  3044. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3045. if(!uit) return 0;
  3046. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3047. strSafeSet(&p->Title, uit->Title->Ptr);
  3048. p->PanelTemplate = uit;
  3049. p->Show = 1;
  3050. p->PP.EndInstance = p;
  3051. p->PP.LastPs = &p->FakePS;
  3052. p->PP.LastPs->p = _LA_PROP_PANEL;
  3053. p->PP.LastPs->UseInstance = p;
  3054. p->PP.LastPs->Type = U'.';
  3055. la_EnsurePanelExtras(p);
  3056. laRecalcPanel(p);
  3057. p->FrameDistinguish = 100; //greater than 1 is ok
  3058. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3059. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3060. p->Block = b; b->CurrentPanel = p;
  3061. if(uit->PropFunc){ uit->PropFunc(p); }
  3062. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3063. laNotifyUsers("la.windows.panels");
  3064. return p;
  3065. }
  3066. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3067. laUiTemplate* uit=laFindUiTemplate(template_id);
  3068. return laCreatePanelT(b, uit);
  3069. }
  3070. 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){
  3071. laUiTemplate* uit=0;
  3072. if(template_id) uit=laFindUiTemplate(template_id);
  3073. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3074. p->Mode = LA_PANEL_FLOATING_TOP;
  3075. laPlacePanelForCreation(p);
  3076. if(uit){
  3077. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3078. }
  3079. if (w) lstPushItem(&w->Panels, p);
  3080. return p;
  3081. }
  3082. void laShowPanel(laPanel *p){
  3083. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3084. }
  3085. void laShowPanelWithDropDownEffect(laPanel *p){
  3086. laShowPanel(p);
  3087. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3088. p->AnimationRatio = 0;
  3089. }
  3090. void laShowPanelWithExpandEffect(laPanel *p){
  3091. laShowPanel(p);
  3092. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3093. p->AnimationRatio = 0;
  3094. }
  3095. void laHidePanel(laPanel *p){
  3096. if (!p->Mode) return;
  3097. p->Show = 0;
  3098. laNotifyUsers("la.windows.panels_hidden");
  3099. }
  3100. void laHidePanelWithDissoveEffect(laPanel *p){
  3101. if (!p->Mode) return;
  3102. laHidePanel(p);
  3103. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3104. p->AnimationRatio = 1;
  3105. }
  3106. void laHidePanelWithCollapseEffect(laPanel *p){
  3107. if (!p->Mode) return;
  3108. laHidePanel(p);
  3109. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3110. p->AnimationRatio = 1;
  3111. }
  3112. void laHidePanelWithMinimizeEffect(laPanel *p){
  3113. if (!p->Mode) return;
  3114. laHidePanel(p);
  3115. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3116. p->AnimationRatio = 1;
  3117. }
  3118. void laActivatePanel(char* TemplateID, int x, int y){
  3119. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3120. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3121. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3122. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3123. }
  3124. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3125. p->UI.PanX += DeltaX;
  3126. p->UI.PanY += DeltaY;
  3127. }
  3128. int laPanUiListFree(laUiList *uil, int X, int Y){
  3129. uil->PanX+=X; uil->PanY+=Y;
  3130. }
  3131. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3132. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3133. if(Y){X+=Y;Y=0;}
  3134. }
  3135. if (Y > 0){
  3136. if (uil->B - uil->PanY <= B) return 0;
  3137. else{
  3138. uil->PanY += Y;
  3139. if (uil->B - uil->PanY <= B){
  3140. uil->PanY = uil->B - B;
  3141. return 1;
  3142. }
  3143. }
  3144. }
  3145. if (Y < 0){
  3146. if (uil->U - uil->PanY >= U) return 0;
  3147. else{
  3148. uil->PanY += Y;
  3149. if (uil->U - uil->PanY >= U){
  3150. uil->PanY = uil->U - U;
  3151. return 1;
  3152. }
  3153. }
  3154. }
  3155. if(uil->AllowScale){
  3156. laPanUiListFree(uil, X, 0);
  3157. }else{
  3158. if (X > 0){
  3159. if (uil->R - uil->PanX <= R) return 0;
  3160. else{
  3161. uil->PanX += X;
  3162. if (uil->R - uil->PanX <= R){
  3163. uil->PanX = uil->R - R;
  3164. return 1;
  3165. }
  3166. }
  3167. }
  3168. if (X < 0){
  3169. if (uil->L - uil->PanX >= L) return 0;
  3170. else{
  3171. uil->PanX += X;
  3172. if (uil->L - uil->PanX >= L){
  3173. uil->PanX = uil->L - L;
  3174. return 1;
  3175. }
  3176. }
  3177. }
  3178. }
  3179. return 1;
  3180. }
  3181. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3182. int ret=1;
  3183. if(!uil->AllowScale){ return 0; }
  3184. real NewScale=uil->Scale*factor;
  3185. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3186. if(NewScale>5) {NewScale=5; ret=0;}
  3187. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3188. factor=NewScale/uil->Scale;
  3189. uil->Scale=NewScale;
  3190. real mx=(L+R)/2,my=(U+B)/2;
  3191. real dx= (mx+uil->PanX)*factor;
  3192. real dy= (my+uil->PanY)*factor;
  3193. uil->PanX=dx-mx;
  3194. uil->PanY=dy-my;
  3195. MAIN.CurrentPanel->FrameDistinguish=100;
  3196. return ret;
  3197. }
  3198. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3199. if(uil->AllowScale) return 0;
  3200. return laPanUiList(uil,X,Y,L,R,U,B);
  3201. }
  3202. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3203. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3204. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3205. strSafeSet(&p->Title, Title);
  3206. if (Define){
  3207. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3208. }
  3209. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3210. p->BT= &_LA_THEME_FLOATING_PANEL;
  3211. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3212. p->BoundUi = 1;
  3213. return p;
  3214. }
  3215. 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,
  3216. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3217. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3218. strSafeSet(&p->Title, Title);
  3219. if (Define){
  3220. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3221. }
  3222. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3223. p->BT= &_LA_THEME_FLOATING_PANEL;
  3224. p->Mode = LA_PANEL_FLOATING_TOP;
  3225. p->BoundUi = 1;
  3226. return p;
  3227. }
  3228. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3229. laPanel *ip;
  3230. tnsDelete2DOffscreen(p->OffScr);
  3231. p->OffScr = 0;
  3232. strSafeDestroy(&p->Title);
  3233. if (!p->AnimationMode){
  3234. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3235. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3236. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3237. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3238. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3239. }else if (p->Block){
  3240. lstRemoveItem(&p->Block->Panels, p);
  3241. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3242. }
  3243. laNotifyUsers("la.windows.panels");
  3244. }
  3245. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3246. //lstRemoveItem(&p->SubPanels, ip);
  3247. laDestroySinglePanel(ip, immediate);
  3248. laNotifyUsers("la.windows.panels");
  3249. }
  3250. la_ClearDetachedProp(p);
  3251. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3252. la_ReturnPanelNode(p);
  3253. }
  3254. void laDestroySinglePanel(laPanel *p, int immediate){
  3255. la_SetPropMathcerContext(p);
  3256. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3257. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3258. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3259. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3260. }
  3261. }
  3262. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3263. la_DestroyUiList(&p->UI, 1, 1, 0);
  3264. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3265. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3266. if (p->Mode){
  3267. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3268. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3269. }
  3270. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3271. if (la_UiStillInService(p)){
  3272. la_StopUiOperatorService(p);
  3273. }
  3274. if ((!p->AnimationMode) || immediate){
  3275. laDeferredDestroyPanel(p, immediate);
  3276. }else{
  3277. p->LaterDestroy = 1;
  3278. }
  3279. }
  3280. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3281. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3282. int MinW,MinWt=0;
  3283. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3284. int CW = MAIN.CurrentWindow->CW;
  3285. if(p->SL && p->SR){return 0;}
  3286. la_SetPropMathcerContext(p);
  3287. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3288. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3289. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3290. MinW = la_TestUiListMinumWidth(uil);
  3291. if (MinW<MinWt){MinW=MinWt;}
  3292. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3293. if (MinW > 20){
  3294. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3295. }
  3296. la_PanelValidateWidth(p,uil);
  3297. laEnsurePanelInBound(p,uil);
  3298. if(p->TW>CW){ p->TW=CW; }
  3299. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3300. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3301. laRedrawPanel(p);
  3302. return 1;
  3303. }
  3304. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3305. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3306. laOperator *ai = a;
  3307. laPanel *p;
  3308. int GX, GY, GW, t = 0;
  3309. int b;
  3310. laUiDefineFunc def = ReplaceUiDefine;
  3311. int MinW;
  3312. if (!def){ def=laui_DefaultPropDetails; }
  3313. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3314. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3315. laEnclosePanelContent(p, &p->UI);
  3316. laSetOperatorLocalizer(p);
  3317. p->CloseWhenMovedOut=1;
  3318. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3319. //laShowPanelWithDropDownEffect(p);
  3320. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3321. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3322. return p;
  3323. }
  3324. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3325. laPanel *p;
  3326. int GX, GY, GW, t = 0;
  3327. int b;
  3328. laUiDefineFunc def = ReplaceUiDefine;
  3329. int MinW;
  3330. if (!def) return 0;
  3331. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3332. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3333. p->Mode = LA_PANEL_FLOATING_TOP;
  3334. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3335. laEnclosePanelContent(p, &p->UI);
  3336. if(MAIN.CurrentWindow->Operators.pFirst){
  3337. laSetOperatorLocalizer(MAIN.PendingSplash);
  3338. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3339. MAIN.PendingSplash=0;
  3340. }
  3341. //laShowPanelWithExpandEffect(p);
  3342. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3343. return p;
  3344. }
  3345. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3346. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3347. laOperator *ai = a;
  3348. laPanel *p; laPropContainer* sub;
  3349. int GX, GY, GW, t = 0;
  3350. int b;
  3351. laUiDefineFunc def = ReplaceUiDefine;
  3352. int MinW;
  3353. if (!def){
  3354. if (This && This->LastPs->p){
  3355. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3356. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3357. }
  3358. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3359. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3360. }
  3361. GX = L; GY = B;
  3362. GW = (R - L) > MaxW ? MaxW : (R - L);
  3363. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3364. laEnclosePanelContent(p, &p->UI);
  3365. laSetOperatorLocalizer(p);
  3366. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3367. laShowPanelWithDropDownEffect(p);
  3368. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3369. if(Attachment){
  3370. p->Parent = Attachment;
  3371. lstAppendItem(&Attachment->SubPanels, p);
  3372. }
  3373. return p;
  3374. }
  3375. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3376. laPanel *p;
  3377. int t = 0;
  3378. int b;
  3379. //laLocalToWindow(0, Attachment, &L, &t);
  3380. //laLocalToWindow(0, Attachment, &R, &U);
  3381. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3382. laSetOperatorLocalizer(p);
  3383. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3384. laShowPanelWithDropDownEffect(p);
  3385. p->Parent = Attachment;
  3386. lstPushItem(&Attachment->SubPanels, p);
  3387. return p;
  3388. }
  3389. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3390. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3391. laOperator *ai = a;
  3392. laPanel *p;
  3393. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3394. int GX, GY, GW, t = 0;
  3395. int b;
  3396. int MinW;
  3397. //laLocalToWindow(0,Attachment, &L, &t);
  3398. //laLocalToWindow(0,Attachment, &R, &B);
  3399. GX = L;
  3400. GY = B;
  3401. GW = (R - L) > MaxW ? MaxW : (R - L);
  3402. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3403. p->MenuRefer = MenuRefer;
  3404. laEnclosePanelContent(p, MenuRefer);
  3405. laSetOperatorLocalizer(p);
  3406. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3407. laShowPanelWithDropDownEffect(p);
  3408. p->Parent = Attachment;
  3409. lstPushItem(&Attachment->SubPanels, p);
  3410. return p;
  3411. }
  3412. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3413. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3414. laOperator *ai = a;
  3415. laPanel *p;
  3416. int GX, GY, GW, t = 0;
  3417. int b;
  3418. GX = L;
  3419. GY = B;
  3420. GW = MaxW;
  3421. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3422. p->MenuRefer = &p->UI;
  3423. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3424. laSetOperatorLocalizer(p);
  3425. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3426. laShowPanelWithDropDownEffect(p);
  3427. if (Attachment){
  3428. p->Parent = Attachment;
  3429. lstPushItem(&Attachment->SubPanels, p);
  3430. }else{
  3431. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3432. }
  3433. return p;
  3434. }
  3435. 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){
  3436. laOperator *ai = For;
  3437. laPanel *p;
  3438. int b;
  3439. laUiDefineFunc def = 0;
  3440. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3441. else def = laui_DefaultPropUiDefine;
  3442. For->PP.EndInstance = For->CustomData;
  3443. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3444. laEnclosePanelContent(p, &p->UI);
  3445. MAIN.ToPanel = p;
  3446. laShowPanelWithExpandEffect(p);
  3447. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3448. ai->OperatorPanel = p;
  3449. p->ParentOperator = For;
  3450. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3451. return p;
  3452. }
  3453. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3454. laPanel *p; int b; laUiList *uil; laColumn* col;
  3455. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3456. strSafeSet(&p->Title, Title);
  3457. p->BoundUi = 1;
  3458. p->Mode = LA_PANEL_FLOATING_TOP;
  3459. p->BT = &_LA_THEME_FLOATING_PANEL;
  3460. MAIN.ToPanel = p;
  3461. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3462. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3463. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3464. laUiItem* r=laBeginRow(uil,col,0,0);
  3465. laShowSeparator(uil,col)->Expand=1;
  3466. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3467. laEndRow(uil,r);
  3468. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3469. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3470. laSetOperatorLocalizer(p);
  3471. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3472. return p;
  3473. }
  3474. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3475. laPanel *p; int b; laUiList *uil; laColumn* col;
  3476. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3477. strSafeSet(&p->Title, Title);
  3478. p->BoundUi = 1;
  3479. p->Mode = LA_PANEL_FLOATING_TOP;
  3480. p->BT = &_LA_THEME_FLOATING_PANEL;
  3481. MAIN.ToPanel = p;
  3482. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3483. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3484. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3485. laUiItem* r = laBeginRow(uil,col,0,0);
  3486. laShowSeparator(uil,col)->Expand=1;
  3487. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3488. laEndRow(uil, r);
  3489. laEnclosePanelContent(p,uil);
  3490. laShowPanelWithExpandEffect(p);
  3491. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3492. laSetOperatorLocalizer(p);
  3493. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3494. return p;
  3495. }
  3496. void laOperatorModalOver(laOperator* For){
  3497. For->ModalOver = 1;
  3498. }
  3499. void laDeferredRedraw(laPanel* p){
  3500. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3501. if(lip->p==p) return;
  3502. }
  3503. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3504. }
  3505. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3506. laWindow* cur=MAIN.CurrentWindow;
  3507. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3508. MAIN.CurrentWindow=w;
  3509. la_UpdateUiPlacement(w);
  3510. }
  3511. MAIN.CurrentWindow=cur;
  3512. }
  3513. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3514. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3515. }
  3516. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3517. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3518. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3519. void laRedrawCurrentPanel(){
  3520. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3521. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3522. }
  3523. void laRecalcCurrentPanel(){
  3524. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3525. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3526. }
  3527. void laRecalcPanelImmediate(laPanel* p){
  3528. p->FrameDistinguish++;
  3529. laBoxedTheme* bt = (*p->BT);
  3530. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3531. la_PanelRefreshDetachedProp(p);
  3532. int enclosed=0;
  3533. if(p->BoundUi || p->MenuRefer){
  3534. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3535. else enclosed=laEnclosePanelContent(p, &p->UI);
  3536. }
  3537. if(!enclosed){
  3538. la_PanelValidateWidth(p,&p->UI);
  3539. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3540. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3541. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3542. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3543. }
  3544. laWindow* w=MAIN.CurrentWindow;
  3545. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3546. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3547. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3548. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3549. }
  3550. }
  3551. void laRecalcCurrentPanelImmediate(){
  3552. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3553. }
  3554. int laNonFixedPanelExists(laPanel *p){
  3555. laPanel *ip;
  3556. if (!p) return 0;
  3557. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3558. // if (ip == p) return 1;
  3559. //}
  3560. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3561. if (ip == p) return 1;
  3562. }
  3563. return 0;
  3564. }
  3565. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3566. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3567. return 1;
  3568. }
  3569. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3570. int tt=MAIN.TooltipCloseDistance;
  3571. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3572. return 1;
  3573. }
  3574. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3575. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3576. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3577. return 0;
  3578. return 1;
  3579. }
  3580. void laUnlinkSharedPanel(laPanel *p){
  3581. laWindow *w;
  3582. laPanel *ip;
  3583. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3584. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3585. if (ip == p){
  3586. lstRemoveItem(&w->Panels, ip);
  3587. return;
  3588. }
  3589. }
  3590. }
  3591. }
  3592. int laIsPanelCovered(laPanel *p){
  3593. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3594. laPanel *ip;
  3595. laPanel *resp;
  3596. int in1 = 0, in2 = 0, in3 = 0;
  3597. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3598. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3599. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3600. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3601. //}
  3602. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3603. if (ip == p){
  3604. in3 = 1;
  3605. d3 = 0;
  3606. continue;
  3607. }
  3608. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3609. }
  3610. if (!in2 && !in3) in1 = 1;
  3611. if (in1){
  3612. if (d1 || d2 || d3) return 1;
  3613. }else{
  3614. if (in2){
  3615. if (d2 || d3) return 1;
  3616. }else if (in3)
  3617. if (d3) return 1;
  3618. }
  3619. return 0;
  3620. }
  3621. int laIsTopPanel(laPanel *p){
  3622. //if (!p->Item.pPrev) return 1;
  3623. //else {
  3624. if (!laIsPanelCovered(p)){
  3625. //laPopPanel(p);
  3626. return 1;
  3627. }
  3628. return 0;
  3629. //}
  3630. return 0;
  3631. }
  3632. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3633. if(!p) return;
  3634. int ix = *x, iy = *y;
  3635. laListItemPointer *lip;
  3636. laOperator *ai = a;
  3637. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3638. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3639. if (a){
  3640. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3641. laUiList *uil = lip->p;
  3642. (*x) += uil->PanX;
  3643. (*y) += uil->PanY;
  3644. }
  3645. }
  3646. }
  3647. void laPanelToLocal(laOperator *a, int *x, int *y){
  3648. int ix = *x, iy = *y;
  3649. laListItemPointer *lip;
  3650. if (a){
  3651. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3652. laUiList *uil = lip->p;
  3653. (*x) += uil->PanX;
  3654. (*y) += uil->PanY;
  3655. }
  3656. }
  3657. }
  3658. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3659. if(!p) return;
  3660. int ix = *x, iy = *y;
  3661. laListItemPointer *lip;
  3662. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3663. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3664. if (a){
  3665. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3666. laUiList *uil = lip->p;
  3667. (*x) -= uil->PanX;
  3668. (*y) -= uil->PanY;
  3669. }
  3670. }
  3671. }
  3672. void laPanelToWindow(laPanel *p, int *x, int *y){
  3673. int ix = *x, iy = *y;
  3674. laListItemPointer *lip;
  3675. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3676. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3677. }
  3678. void laLocalToPanel(laOperator *a, int *x, int *y){
  3679. int ix = *x, iy = *y;
  3680. laListItemPointer *lip;
  3681. if (a){
  3682. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3683. laUiList *uil = lip->p;
  3684. (*x) -= uil->PanX;
  3685. (*y) -= uil->PanY;
  3686. }
  3687. }
  3688. }
  3689. void laSetNextMenuPos(int X, int Y, int W, int H){
  3690. MAIN.NextX = X;
  3691. MAIN.NextY = Y;
  3692. MAIN.NextW = W;
  3693. MAIN.NextH = H;
  3694. }
  3695. int laIsInBlock(laBlock *b, int X, int Y){
  3696. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3697. return 0;
  3698. }
  3699. 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; }
  3700. 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; }
  3701. 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; }
  3702. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3703. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3704. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3705. if (!b->B1 && !b->B2){
  3706. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3707. }
  3708. }
  3709. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3710. laPanel *p;
  3711. laBlock *sb = 0;
  3712. if (!laIsInBlock(b, X, Y)) return 0;
  3713. if (!b->B1 && !b->B2) return b;
  3714. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3715. return laDetectBlockRecursive(b->B2, X, Y);
  3716. }
  3717. laPanel *laDetectPanel(int X, int Y){
  3718. laPanel *p; laBlock *b;
  3719. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3720. int x = X, y = Y;
  3721. laWindowToLocal(0, p, &x, &y);
  3722. if (p->Show && laIsInPanel(p, x, y)){
  3723. return p;
  3724. }
  3725. }
  3726. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3727. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3728. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3729. return 0;
  3730. }
  3731. laUiList *laPrepareUi(laPanel *p){
  3732. return &p->UI;
  3733. }
  3734. laColumn *laFirstColumn(laUiList *uil){
  3735. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3736. else{
  3737. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3738. c->SP = 1;
  3739. c->PreWidth = 1;
  3740. lstAppendItem(&uil->Columns, c);
  3741. c->Top = c;
  3742. return uil->Columns.pFirst;
  3743. }
  3744. }
  3745. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3746. laColumn *lc, *rc;
  3747. if (c->LS || c->RS) return c;
  3748. lc = memAcquireSimple(sizeof(laColumn));
  3749. rc = memAcquireSimple(sizeof(laColumn));
  3750. c->LS = lc;
  3751. c->RS = rc;
  3752. c->LS->SP = Percent;
  3753. c->RS->SP = Percent;
  3754. c->LS->Top = c->Top;
  3755. c->RS->Top = c->Top;
  3756. if (uil){
  3757. lstAppendItem(&uil->Columns, lc);
  3758. lstAppendItem(&uil->Columns, rc);
  3759. }
  3760. if (c->LS && c->RS->MaxW == 0){
  3761. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3762. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3763. }else if (c->RS && c->LS->MaxW == 0){
  3764. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3765. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3766. }
  3767. return c;
  3768. }
  3769. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3770. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3771. return c->LS;
  3772. }
  3773. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3774. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3775. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3776. return c->RS;
  3777. }
  3778. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3779. lstRemoveItem(List, c);
  3780. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3781. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3782. memFree(c);
  3783. }
  3784. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3785. laUiList *uil = TopUil;
  3786. laUiList *sub;
  3787. laUiItem *ui;
  3788. laColumn *cc, *NextCC = 0;
  3789. int Occupied = 0;
  3790. int Removed = 0;
  3791. if (!c->LS) return 0;
  3792. else{
  3793. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3794. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3795. }
  3796. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3797. if (ui->C == c->LS || ui->C == c->RS){
  3798. if (DoMerge){
  3799. ui->C = c;
  3800. Occupied = 1;
  3801. }else
  3802. return 1;
  3803. }
  3804. if (ui->Subs.pFirst){
  3805. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3806. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3807. }
  3808. }
  3809. }
  3810. if (!Removed){
  3811. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3812. if (cc == c){
  3813. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3814. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3815. c->LS = 0;
  3816. c->RS = 0;
  3817. Removed = 1;
  3818. break;
  3819. }
  3820. }
  3821. }
  3822. return Occupied;
  3823. }
  3824. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3825. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3826. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3827. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3828. ut->FakeProp->Base.Identifier = ut->Identifier;
  3829. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3830. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3831. ut->FakeProp->Base.OffsetIsPointer = 1;
  3832. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3833. return ut->ExtraProps;
  3834. }
  3835. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3836. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3837. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3838. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3839. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3840. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3841. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3842. ct->FakeProp->Base.OffsetIsPointer = 1;
  3843. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3844. return ct->ExtraProps;
  3845. }
  3846. void la_DestroyUiType(laUiType* uit){
  3847. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3848. memFree(uit);
  3849. }
  3850. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3851. laUiType *ut = memAcquire(sizeof(laUiType));
  3852. ut->Identifier = Identifer;
  3853. ut->OperatorID = UseOperator;
  3854. ut->Draw = Draw;
  3855. ut->Theme = bt;
  3856. ut->ForType = ForType;
  3857. ut->OperatorType = laGetOperatorType(UseOperator);
  3858. ut->GetHeight = GetHeight;
  3859. ut->Init = Init;
  3860. ut->Destroy = Destroy;
  3861. la_UDFAppendSharedTypePointer(Identifer, ut);
  3862. lstAppendItem(&MAIN.UiTypes, ut);
  3863. return ut;
  3864. }
  3865. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3866. laUiType *ut = MAIN.UiTypes.pFirst;
  3867. if (!P) return 0;
  3868. if (P->DefaultUiType) return P->DefaultUiType;
  3869. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3870. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3871. for (ut; ut; ut = ut->Item.pNext){
  3872. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3873. return ut;
  3874. }
  3875. }
  3876. return 0;
  3877. }
  3878. laUiType *la_GetUiButtonType(){
  3879. laUiType *ut = MAIN.UiTypes.pFirst;
  3880. for (ut; ut; ut = ut->Item.pNext){
  3881. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3882. }
  3883. return 0;
  3884. }
  3885. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3886. laCanvasTemplate *vdt;
  3887. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3888. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3889. }
  3890. return 0;
  3891. }
  3892. void la_AssignPropExtras(laUiItem* ui){
  3893. if(!ui->Type || !ui->Type->FakeProp) return;
  3894. ui->FakePs.p = ui->Type->FakeProp;
  3895. ui->FakePs.Type = U'.';
  3896. ui->FakePs.UseInstance = ui;
  3897. ui->ExtraPP.LastPs = &ui->FakePs;
  3898. }
  3899. void la_AssignCanvasPropExtras(laUiItem* ui){
  3900. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3901. laCanvasTemplate*ct=ui->CanvasTemplate;
  3902. ui->FakePs.p = ct->FakeProp;
  3903. ui->FakePs.Type = U'.';
  3904. ui->FakePs.UseInstance = ui;
  3905. ui->ExtraPP.EndInstance = ui->Extra;
  3906. ui->ExtraPP.LastPs = &ui->FakePs;
  3907. }
  3908. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3909. int result;
  3910. if (!ui) return 0;
  3911. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3912. if (Path){
  3913. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3914. if (!result){
  3915. ui->AT = laGetOperatorType(Path);
  3916. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3917. ui->Type = la_GetUiButtonType();
  3918. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3919. }else{
  3920. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3921. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3922. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3923. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3924. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3925. }
  3926. if (Base){
  3927. ui->PP.RawThis = Base;
  3928. }
  3929. }else if (Base){
  3930. ui->PP.LastPs = Base->LastPs;
  3931. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3932. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3933. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3934. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3935. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3936. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3937. }
  3938. la_AssignPropExtras(ui);
  3939. if(Widget){ ui->Flags|= Widget->Flags; }
  3940. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3941. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3942. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3943. return ui;
  3944. }
  3945. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3946. ui->Type = _LA_UI_LABEL;
  3947. ui->Template = Template;
  3948. ui->State = LA_UI_NORMAL;
  3949. strSafeSet(&ui->Display, Content);
  3950. la_AssignPropExtras(ui);
  3951. return ui;
  3952. }
  3953. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3954. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3955. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3956. ui->State = LA_UI_NORMAL;
  3957. la_AssignPropExtras(ui);
  3958. return ui;
  3959. }
  3960. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3961. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3962. transLate(Content);
  3963. la_UpdateLabelDisplay(ui, Template, Content);
  3964. ui->C = c;
  3965. if (ui->Type->Init) ui->Type->Init(ui);
  3966. ui->ExtraPP.EndInstance = ui->Extra;
  3967. lstAppendItem(&uil->UiItems, ui);
  3968. return ui;
  3969. }
  3970. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3971. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3972. la_UpdateLabelDisplay(ui, Template, Content);
  3973. ui->C = c;
  3974. if (ui->Type->Init) ui->Type->Init(ui);
  3975. ui->ExtraPP.EndInstance = ui->Extra;
  3976. lstAppendItem(&uil->UiItems, ui);
  3977. return ui;
  3978. }
  3979. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3980. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3981. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3982. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3983. ui->C = c;
  3984. if (ui->Type->Init) ui->Type->Init(ui);
  3985. ui->ExtraPP.EndInstance = ui->Extra;
  3986. lstAppendItem(&uil->UiItems, ui);
  3987. return ui;
  3988. }
  3989. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3990. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  3991. }
  3992. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3993. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  3994. }
  3995. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  3996. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3997. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  3998. ui->C = c;
  3999. ui->TemplateContext = TemplateContext;
  4000. if (ui->Type->Init) ui->Type->Init(ui);
  4001. ui->ExtraPP.EndInstance = ui->Extra;
  4002. lstAppendItem(&uil->UiItems, ui);
  4003. return ui;
  4004. }
  4005. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4006. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4007. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4008. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4009. ui->SymbolID=Height;
  4010. lstAppendItem(&uil->UiItems, ui);
  4011. return ui;
  4012. }
  4013. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4014. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4015. }
  4016. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4017. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4018. }
  4019. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4020. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4021. ui->Type = _LA_UI_CANVAS;
  4022. ui->State = LA_UI_NORMAL;
  4023. ui->C = c;
  4024. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4025. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4026. else{
  4027. 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); }
  4028. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4029. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4030. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4031. }
  4032. if (ui->Type->Init) ui->Type->Init(ui);
  4033. la_AssignCanvasPropExtras(ui);
  4034. if (Height) ui->Expand=Height; else ui->Expand=6;
  4035. lstAppendItem(&uil->UiItems, ui);
  4036. return ui;
  4037. }
  4038. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4039. laUiItem* ui=0;
  4040. #define ADD_CANVAS \
  4041. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4042. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4043. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4044. }laEndCondition(uil,b3);\
  4045. laEndRow(uil,b);
  4046. if(Detached){
  4047. laColumn* cl,*cll,*clr,*cr;
  4048. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4049. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4050. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4051. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4052. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4053. ADD_CANVAS
  4054. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4055. }laElse(uil,b2);{
  4056. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4057. ADD_CANVAS
  4058. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4059. }laEndCondition(uil,b2);
  4060. }else{
  4061. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4062. }
  4063. #undef ADD_CANVAS
  4064. }
  4065. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4066. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4067. laCanvasExtra *e;
  4068. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4069. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4070. ui->C = c;
  4071. if (ui->Type->Init) ui->Type->Init(ui);
  4072. ui->ExtraPP.EndInstance = ui->Extra;
  4073. lstAppendItem(&uil->UiItems, ui);
  4074. return ui;
  4075. }
  4076. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4077. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4078. ui->Type = _LA_UI_SYMBOL;
  4079. ui->SymbolID = SymbolID;
  4080. if (Height) ui->State = Height;
  4081. ui->C = c;
  4082. if (ui->Type->Init) ui->Type->Init(ui);
  4083. ui->ExtraPP.EndInstance = ui->Extra;
  4084. lstAppendItem(&uil->UiItems, ui);
  4085. return ui;
  4086. }
  4087. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4088. laPropPack PP={0}; int result;
  4089. if (Path){
  4090. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4091. if (!result){ return 0; }
  4092. if (Base){ PP.RawThis = Base; }
  4093. }else if (Base){
  4094. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4095. }
  4096. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4097. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4098. lstAppendItem(&ui->CompoundPPs,CPP);
  4099. return &CPP->PP;
  4100. }
  4101. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4102. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4103. ui->Type = &_LA_UI_ROW_BEGIN;
  4104. ui->State=Expand;
  4105. ui->Flags=Even;
  4106. ui->C = c;
  4107. if (ui->Type->Init) ui->Type->Init(ui);
  4108. ui->ExtraPP.EndInstance = ui->Extra;
  4109. lstAppendItem(&uil->UiItems, ui);
  4110. return ui;
  4111. }
  4112. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4113. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4114. ui->Type = &_LA_UI_ROW_END;
  4115. ui->C = Begin->C;
  4116. ui->Page = (laUiList*)Begin;
  4117. if (ui->Type->Init) ui->Type->Init(ui);
  4118. ui->ExtraPP.EndInstance = ui->Extra;
  4119. lstAppendItem(&uil->UiItems, ui);
  4120. return ui;
  4121. }
  4122. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4123. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4124. e->Expression = Expression;
  4125. ui->Extra = e;
  4126. la_AssignPropExtras(ui);
  4127. }
  4128. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4129. laUiItem *ui = la_CreateGroupHandle(Widget);
  4130. laUiList *nuil;
  4131. ui->C = c;
  4132. lstAppendItem(&uil->UiItems, ui);
  4133. nuil = memAcquireSimple(sizeof(laUiList));
  4134. strSafeSet(&nuil->TabName, Name);
  4135. ui->Page = nuil;
  4136. lstAppendItem(&ui->Subs, nuil);
  4137. if (ui->Type->Init) ui->Type->Init(ui);
  4138. ui->ExtraPP.EndInstance = ui->Extra;
  4139. return ui;
  4140. }
  4141. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4142. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4143. laUiList *sub = SubUi->Page;
  4144. laColumn *s = laFirstColumn(sub);
  4145. SubUi->State = LA_UI_ACTIVE;
  4146. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4147. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4148. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4149. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4150. laShowSeparator(sub, s);
  4151. return SubUi;
  4152. }
  4153. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4154. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4155. laUiList *sub = SubUi->Page;
  4156. laColumn *s = laFirstColumn(sub);
  4157. SubUi->State = LA_UI_ACTIVE;
  4158. return SubUi;
  4159. }
  4160. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4161. laEndCondition(sub, sub->UiItems.pFirst);
  4162. }
  4163. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4164. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4165. laUiList *nuil;
  4166. ui->C = c;
  4167. lstAppendItem(&uil->UiItems, ui);
  4168. if (ui->Type->Init) ui->Type->Init(ui);
  4169. ui->ExtraPP.EndInstance = ui->Extra;
  4170. return ui;
  4171. }
  4172. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4173. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4174. if (!ui->Page) ui->Page = uil;
  4175. lstAppendItem(&ui->Subs, uil);
  4176. strSafeSet(&uil->TabName, Name);
  4177. laFirstColumn(uil);
  4178. //laFirstColumn(uil);
  4179. return uil;
  4180. }
  4181. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4182. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4183. /*if (!ui->Page) */ ui->Page = uil;
  4184. lstAppendItem(&ui->Subs, uil);
  4185. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4186. return uil;
  4187. }
  4188. laUiConditionNode *laTrue(){
  4189. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4190. ucn->Type = LA_CONDITION_TRUE;
  4191. return ucn;
  4192. }
  4193. laUiConditionNode *laFalse(){
  4194. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4195. ucn->Type = LA_CONDITION_FALSE;
  4196. return ucn;
  4197. }
  4198. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4199. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4200. ucn->Type = LA_CONDITION_PROP;
  4201. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4202. strSafeSet(&ucn->String, Prop);
  4203. return ucn;
  4204. }
  4205. laUiConditionNode *laIntExpression(int Value){
  4206. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4207. ucn->Type = LA_CONDITION_INT;
  4208. ucn->IntValue = Value;
  4209. return ucn;
  4210. }
  4211. laUiConditionNode *laFloatExpression(real Value){
  4212. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4213. ucn->Type = LA_CONDITION_FLOAT;
  4214. ucn->FloatValue = Value;
  4215. return ucn;
  4216. }
  4217. laUiConditionNode *laStringExpression(char *Content){
  4218. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4219. ucn->Type = LA_CONDITION_STRING;
  4220. strSafeSet(&ucn->String, Content);
  4221. return ucn;
  4222. }
  4223. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4224. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4225. ucn->Type = LA_CONDITION_AND;
  4226. ucn->Expression1 = Expression1;
  4227. ucn->Expression2 = Expression2;
  4228. return ucn;
  4229. }
  4230. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4231. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4232. ucn->Type = LA_CONDITION_OR;
  4233. ucn->Expression1 = Expression1;
  4234. ucn->Expression2 = Expression2;
  4235. return ucn;
  4236. }
  4237. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4238. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4239. ucn->Type = LA_CONDITION_NOT;
  4240. ucn->Expression1 = Expression1;
  4241. return ucn;
  4242. }
  4243. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4244. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4245. ucn->Type = LA_CONDITION_EQ;
  4246. ucn->Expression1 = Expression1;
  4247. ucn->Expression2 = Expression2;
  4248. return ucn;
  4249. }
  4250. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4251. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4252. ucn->Type = LA_CONDITION_GT;
  4253. ucn->Expression1 = Expression1;
  4254. ucn->Expression2 = Expression2;
  4255. return ucn;
  4256. }
  4257. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4258. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4259. ucn->Type = LA_CONDITION_LT;
  4260. ucn->Expression1 = Expression1;
  4261. ucn->Expression2 = Expression2;
  4262. return ucn;
  4263. }
  4264. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4265. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4266. ucn->Type = LA_CONDITION_GE;
  4267. ucn->Expression1 = Expression1;
  4268. ucn->Expression2 = Expression2;
  4269. return ucn;
  4270. }
  4271. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4272. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4273. ucn->Type = LA_CONDITION_LE;
  4274. ucn->Expression1 = Expression1;
  4275. ucn->Expression2 = Expression2;
  4276. return ucn;
  4277. }
  4278. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4279. if (Expression->Type != LA_CONDITION_INT) return 0;
  4280. return Expression->IntValue;
  4281. }
  4282. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4283. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4284. return Expression->FloatValue;
  4285. }
  4286. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4287. return Expression->String->Ptr;
  4288. }
  4289. 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){
  4290. switch (Mode1){
  4291. case LA_PROP_ENUM:
  4292. case LA_PROP_INT:
  4293. case LA_CONDITION_INT:
  4294. switch (Mode2){
  4295. case LA_PROP_ENUM:
  4296. case LA_PROP_INT:
  4297. case LA_CONDITION_INT:
  4298. switch (CompMode){
  4299. case LA_CONDITION_GE:
  4300. return (i1 >= i2);
  4301. case LA_CONDITION_GT:
  4302. return (i1 > i2);
  4303. case LA_CONDITION_EQ:
  4304. return (i1 == i2);
  4305. case LA_CONDITION_LT:
  4306. return (i1 < i2);
  4307. case LA_CONDITION_LE:
  4308. return (i1 <= i2);
  4309. }
  4310. case LA_PROP_FLOAT:
  4311. case LA_CONDITION_FLOAT:
  4312. switch (CompMode){
  4313. case LA_CONDITION_GE:
  4314. return ((real)i1 >= f2);
  4315. case LA_CONDITION_GT:
  4316. return ((real)i1 > f2);
  4317. case LA_CONDITION_EQ:
  4318. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4319. case LA_CONDITION_LT:
  4320. return ((real)i1 < f2);
  4321. case LA_CONDITION_LE:
  4322. return ((real)i1 <= f2);
  4323. }
  4324. case LA_PROP_SUB:
  4325. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4326. default:
  4327. return 0;
  4328. }
  4329. case LA_PROP_FLOAT:
  4330. case LA_CONDITION_FLOAT:
  4331. switch (Mode2){
  4332. case LA_PROP_INT:
  4333. case LA_PROP_ENUM:
  4334. case LA_CONDITION_INT:
  4335. switch (CompMode){
  4336. case LA_CONDITION_GE:
  4337. return (f1 >= (real)i2);
  4338. case LA_CONDITION_GT:
  4339. return (f1 > (real)i2);
  4340. case LA_CONDITION_EQ:
  4341. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4342. case LA_CONDITION_LT:
  4343. return (f1 < (real)i2);
  4344. case LA_CONDITION_LE:
  4345. return (f1 <= (real)i2);
  4346. }
  4347. case LA_PROP_FLOAT:
  4348. case LA_CONDITION_FLOAT:
  4349. switch (CompMode){
  4350. case LA_CONDITION_GE:
  4351. return (f1 >= f2);
  4352. case LA_CONDITION_GT:
  4353. return (f1 > f2);
  4354. case LA_CONDITION_EQ:
  4355. return (f1 == f2);
  4356. case LA_CONDITION_LT:
  4357. return (f1 < f2);
  4358. case LA_CONDITION_LE:
  4359. return (f1 <= f2);
  4360. }
  4361. default:
  4362. return 0;
  4363. }
  4364. case LA_PROP_STRING:
  4365. case LA_CONDITION_STRING:
  4366. switch (Mode2){
  4367. case LA_PROP_STRING:
  4368. case LA_CONDITION_STRING:
  4369. return strSame(s1, s2);
  4370. default:
  4371. return 0;
  4372. }
  4373. case LA_PROP_SUB:
  4374. switch (Mode2){
  4375. case LA_PROP_SUB:
  4376. return p1 == p2;
  4377. case LA_CONDITION_INT:
  4378. case LA_PROP_INT:
  4379. case LA_PROP_ENUM:
  4380. return (int)p1 == i2;
  4381. default:
  4382. return 0;
  4383. }
  4384. default:
  4385. switch (CompMode){
  4386. case LA_CONDITION_GE:
  4387. return (i1 >= i2);
  4388. case LA_CONDITION_GT:
  4389. return (i1 > i2);
  4390. case LA_CONDITION_EQ:
  4391. return (i1 == i2);
  4392. case LA_CONDITION_LT:
  4393. return (i1 < i2);
  4394. case LA_CONDITION_LE:
  4395. return (i1 <= i2);
  4396. }
  4397. }
  4398. }
  4399. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4400. void *Instance = 0;
  4401. int IValue1 = 0, IValue2 = 0;
  4402. real FValue1 = 0, FValue2 = 0;
  4403. void *Ptr1 = 0, *Ptr2 = 0;
  4404. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4405. int Result1, Result2;
  4406. laEnumItem *ei; laSubProp*sp;
  4407. if (!Expression) return 0;
  4408. Str1[0] = 0;
  4409. Str2[0] = 0;
  4410. laPropIterator pi = {0};
  4411. switch (Expression->Type){
  4412. case LA_CONDITION_PROP:
  4413. if (!Expression->PP.LastPs){
  4414. (*IResult) = 0;
  4415. return 0;
  4416. }
  4417. switch (Expression->PP.LastPs->p->PropertyType){
  4418. case LA_PROP_INT:
  4419. *IResult = laGetInt(&Expression->PP);
  4420. if (*IResult) return LA_CONDITION_INT;
  4421. else return 0;
  4422. case LA_PROP_FLOAT:
  4423. *FResult = laGetFloat(&Expression->PP);
  4424. if (*FResult) return 1;
  4425. else return 0;
  4426. break;
  4427. case LA_PROP_STRING:
  4428. laGetString(&Expression->PP, _StrResult, &StrResult);
  4429. if (StrResult[0]) return 1;
  4430. else return 0;
  4431. break;
  4432. case LA_PROP_ENUM:
  4433. ei = laGetEnum(&Expression->PP);
  4434. if (!ei) return 0;
  4435. /*if(ei) */ *IResult = ei->Index;
  4436. if (*IResult) return LA_CONDITION_INT;
  4437. else return 0;
  4438. break;
  4439. case LA_PROP_SUB:
  4440. sp=Expression->PP.LastPs->p;
  4441. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4442. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4443. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4444. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4445. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4446. }
  4447. }
  4448. *PtrResult = Instance;
  4449. if (Instance) return 1;
  4450. break;
  4451. default:
  4452. return 0;
  4453. }
  4454. break;
  4455. case LA_CONDITION_INT:
  4456. *IResult = Expression->IntValue;
  4457. if (*IResult) return 1;
  4458. else
  4459. return 0;
  4460. case LA_CONDITION_FLOAT:
  4461. *FResult = Expression->FloatValue;
  4462. if (*FResult) return 1;
  4463. else
  4464. return 0;
  4465. case LA_CONDITION_STRING:
  4466. if (Expression->String){
  4467. strCopyFull(StrResult, Expression->String->Ptr);
  4468. return 1;
  4469. }else
  4470. return 0;
  4471. case LA_CONDITION_TRUE:
  4472. if (*IResult) *IResult = 1;
  4473. return 1;
  4474. case LA_CONDITION_FALSE:
  4475. if (*IResult) *IResult = 0;
  4476. return 0;
  4477. default:
  4478. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4479. switch (Expression->Type){
  4480. case LA_CONDITION_AND:
  4481. if (Result1){
  4482. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4483. if (Result2) *IResult = 1;
  4484. return (Result2);
  4485. }else
  4486. return 0;
  4487. case LA_CONDITION_OR:
  4488. if (!Result1){
  4489. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4490. if (Result2) *IResult = 1;
  4491. return (Result2);
  4492. }else
  4493. return 1;
  4494. case LA_CONDITION_NOT:
  4495. return !Result1;
  4496. default:
  4497. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4498. return la_DoCompare(Expression->Type,
  4499. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4500. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4501. }
  4502. break;
  4503. }
  4504. return 0;
  4505. }
  4506. int la_DoSingleExpression(laUiConditionNode *Expression){
  4507. int a;
  4508. real b;
  4509. char c[128]={0};
  4510. void *p;
  4511. if (!Expression) return 1;
  4512. c[0] = 0;
  4513. return la_DoExpression(Expression, &a, &b, c, &p);
  4514. }
  4515. void la_StepExpression(laUiConditionNode *e){
  4516. if (!e) return;
  4517. switch (e->Type){
  4518. case LA_CONDITION_AND:
  4519. case LA_CONDITION_OR:
  4520. case LA_CONDITION_GE:
  4521. case LA_CONDITION_GT:
  4522. case LA_CONDITION_EQ:
  4523. case LA_CONDITION_LT:
  4524. case LA_CONDITION_LE:
  4525. la_StepExpression(e->Expression1);
  4526. la_StepExpression(e->Expression2);
  4527. break;
  4528. case LA_CONDITION_NOT:
  4529. la_StepExpression(e->Expression1);
  4530. break;
  4531. case LA_CONDITION_PROP:
  4532. la_StepPropPack(&e->PP);
  4533. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4534. la_UsePropPack(&e->PP, 1);
  4535. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4536. //}
  4537. break;
  4538. default:
  4539. break;
  4540. }
  4541. }
  4542. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4543. if (!ucn) return;
  4544. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4545. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4546. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4547. if (ucn->String) strSafeDestroy(&ucn->String);
  4548. if (ucn) memFree(ucn);
  4549. }
  4550. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4551. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4552. ui->C = c;
  4553. ui->Type = &_LA_UI_CONDITION;
  4554. la_ConditionerInit(ui, Expression);
  4555. lstAppendItem(&uil->UiItems, ui);
  4556. return ui;
  4557. }
  4558. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4559. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4560. laConditionUiExtraData *cued;
  4561. ui->Type = &_LA_UI_CONDITION_ELSE;
  4562. la_ConditionerInit(ui, 0);
  4563. cued = ui->Extra;
  4564. cued->EndUi = Beginner;
  4565. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4566. ui->C = Beginner->C;
  4567. lstAppendItem(&uil->UiItems, ui);
  4568. return ui;
  4569. }
  4570. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4571. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4572. laConditionUiExtraData *cued;
  4573. ui->Template = define;
  4574. ui->C = col;
  4575. ui->PP.RawThis = ExtraBase;
  4576. ui->Page = ExtraThis;
  4577. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4578. la_ConditionerInit(ui, 0);
  4579. cued = ui->Extra;
  4580. //cued->Remove = Remove;
  4581. ui->State = LA_UI_NORMAL;
  4582. lstAppendItem(&uil->UiItems, ui);
  4583. return ui;
  4584. }
  4585. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4586. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4587. laConditionUiExtraData *cued;
  4588. ui->Type = &_LA_UI_CONDITION_END;
  4589. la_ConditionerInit(ui, 0);
  4590. cued = ui->Extra;
  4591. cued->EndUi = Beginner;
  4592. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4593. ui->C = Beginner->C;
  4594. lstAppendItem(&uil->UiItems, ui);
  4595. return ui;
  4596. }
  4597. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4598. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4599. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4600. ui->Type = _LA_UI_MENU_ROOT;
  4601. strSafeSet(&ui->Display, Title);
  4602. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4603. ui->C = c;
  4604. lstAppendItem(&uil->UiItems, ui);
  4605. lstAppendItem(&ui->Subs, muil);
  4606. return muil;
  4607. }
  4608. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4609. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4610. ui->Type = _LA_UI_ALIGN;
  4611. ui->C = widest;
  4612. lstAppendItem(&uil->UiItems, ui);
  4613. return ui;
  4614. }
  4615. void laFixHeight(laUiList *uil, short Rows){
  4616. if (!uil) return;
  4617. uil->HeightCoeff = Rows;
  4618. }
  4619. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4620. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4621. if (!ExtraColumns) return;
  4622. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4623. }
  4624. laUiTemplate *laFindUiTemplate(char *Identifier){
  4625. laUiTemplate *uit;
  4626. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4627. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4628. }
  4629. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4630. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4631. }
  4632. return 0;
  4633. }
  4634. void la_DestroyUiTemplate(laUiTemplate* uit){
  4635. strSafeDestroy(&uit->Identifier);
  4636. strSafeDestroy(&uit->Title);
  4637. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4638. memFree(uit);
  4639. }
  4640. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4641. strSafeDestroy(&uit->Identifier);
  4642. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4643. memFree(uit);
  4644. }
  4645. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4646. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4647. strSafeSet(&uit->Identifier, Identifier);
  4648. strSafeSet(&uit->Title, Title);
  4649. strSafeSet(&uit->CategoryName, NewCategory);
  4650. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4651. uit->DefaultGLFormat=DefaultGLFormat;
  4652. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4653. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4654. la_UDFAppendSharedTypePointer(Identifier, uit);
  4655. return uit;
  4656. }
  4657. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4658. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4659. strSafeSet(&t->Identifier, Identifier);
  4660. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4661. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4662. lstAppendItem(&MAIN.View2DTemplates, t);
  4663. la_UDFAppendSharedTypePointer(Identifier, t);
  4664. return t;
  4665. }
  4666. void laFinalizeUiTemplates(){
  4667. laUiTemplate *uit;
  4668. laCanvasTemplate *u2d;
  4669. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4670. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4671. }
  4672. }
  4673. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4674. laPanel *p;
  4675. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4676. if (p->PanelTemplate==uit){
  4677. return p;
  4678. }
  4679. }
  4680. return 0;
  4681. }
  4682. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4683. laUiList *uil, *NextUil;
  4684. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4685. NextUil = uil->Item.pNext;
  4686. lstRemoveItem(&ui->Subs, uil);
  4687. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4688. }
  4689. la_StopUiOperatorService(ui);
  4690. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4691. strSafeDestroy(&ui->Display);
  4692. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4693. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4694. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4695. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4696. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4697. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4698. }
  4699. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4700. memFree(ui);
  4701. }
  4702. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4703. laUiItem *ui, *NextUi;
  4704. laColumn *col, *NextCol;
  4705. if (!uil) return;
  4706. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4707. NextUi = ui->Item.pNext;
  4708. if(OnlyRemoveUser && RemoveUsers){
  4709. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4710. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4711. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4712. continue;
  4713. }
  4714. lstRemoveItem(&uil->UiItems, ui);
  4715. la_DestroyUiItem(ui, RemoveUsers);
  4716. }
  4717. if(OnlyRemoveUser){ return; }
  4718. for (col = uil->Columns.pFirst; col; col = NextCol){
  4719. NextCol = col->Item.pNext;
  4720. lstRemoveItem(&uil->Columns, col);
  4721. memFree(col);
  4722. }
  4723. strSafeDestroy(&uil->TabName);
  4724. if (!NoFree) memFree(uil);
  4725. }
  4726. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4727. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4728. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4729. }
  4730. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4731. laUiItem *Next = after->Item.pNext;
  4732. laUiItem *Last = uil->UiItems.pLast;
  4733. after->Item.pNext = 0;
  4734. uil->UiItems.pLast = after;
  4735. Define(uil, Base, This, ExtraColums, 0);
  4736. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4737. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4738. if (Next != Last) uil->UiItems.pLast = Last;
  4739. }
  4740. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4741. // int i = 0;
  4742. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4743. // if (!ui->ExtraColums) return;
  4744. // for (i; ui->ExtraColums[i]; i++) {
  4745. // laColumn* c = ui->ExtraColums[i];
  4746. // c->B = B;
  4747. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4748. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4749. // }
  4750. //}
  4751. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4752. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4753. }
  4754. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4755. laColumn *c = ui->C;
  4756. laColumn *ic = lst->pFirst;
  4757. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4758. for (ic; ic; ic = ic->Item.pNext){
  4759. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4760. ic->B = ic->B < c->B ? c->B : ic->B;
  4761. }
  4762. }
  4763. ic = ui->C;
  4764. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4765. ;
  4766. for (ic; ic; ic = ic->Item.pNext){
  4767. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4768. ic->B = ic->B < c->B ? c->B : ic->B;
  4769. }
  4770. }
  4771. }
  4772. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4773. laColumn *c = ui->C;
  4774. laColumn *ic = lst->pFirst;
  4775. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4776. for (ic; ic; ic = ic->Item.pNext){
  4777. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4778. ic->B = ic->B < c->B ? c->B : ic->B;
  4779. }
  4780. }
  4781. ic = ui->C;
  4782. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4783. ;
  4784. for (ic; ic; ic = ic->Item.pNext){
  4785. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4786. ic->B = ic->B < c->B ? c->B : ic->B;
  4787. }
  4788. }
  4789. }
  4790. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4791. int rep;
  4792. int sp;
  4793. int rev;
  4794. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4795. if (!c) return 0;
  4796. sp = (c->SP * (R - L)) + L;
  4797. rev = sp;
  4798. /*if (U)*/ c->B = U;
  4799. if (LR == 1){
  4800. c->IL = L;
  4801. c->IR = sp;
  4802. if (repos){
  4803. c->IR = repos;
  4804. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4805. c->IR = c->IL + c->MaxW*LA_RH+M;
  4806. rev = c->IR;
  4807. }
  4808. }else if (LR == 2){
  4809. c->IL = sp;
  4810. c->IR = R;
  4811. if (repos){
  4812. c->IL = repos;
  4813. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4814. c->IL = c->IR - c->MaxW*LA_RH-M;
  4815. rev = c->IL;
  4816. }
  4817. }else if (LR == 0){
  4818. c->IL = L;
  4819. c->IR = R;
  4820. }
  4821. if (c->LS && c->RS->MaxW == 0){
  4822. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4823. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4824. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4825. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4826. }else if (c->RS && c->LS->MaxW == 0){
  4827. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4828. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4829. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4830. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4831. }
  4832. return rev;
  4833. }
  4834. STRUCTURE(laRowInfo){
  4835. int MaxW;
  4836. int MinW;
  4837. int UnitMinW;
  4838. int NonExpandW;
  4839. int TotalPadding;
  4840. int Expand, Even;
  4841. int ExpandAccum;
  4842. int CountElements;
  4843. int U,MaxB,L;
  4844. laListHandle Elements;
  4845. int LastNoHeight;
  4846. };
  4847. STRUCTURE(laRowNode){
  4848. laListItem Item;
  4849. laUiItem* ui;
  4850. int GotW, LP, RP, H;
  4851. int Expand;
  4852. int UseLast;
  4853. int WaitAnimation;
  4854. };
  4855. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4856. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4857. ri->UnitMinW=LA_RH;
  4858. ri->Expand=ui->State?1:0;
  4859. ri->Even=ui->Flags?1:0;
  4860. ri->U=ui->TU; ri->L=ui->TL;
  4861. ri->MaxB=ui->TU;
  4862. }
  4863. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  4864. laRowNode* rn=CreateNew(laRowNode);
  4865. rn->LP=bt->LP;rn->RP=bt->RP;
  4866. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4867. rn->ui=ui;
  4868. rn->H=H;
  4869. rn->Expand=ui->Expand;
  4870. rn->WaitAnimation=WaitAnimation;
  4871. lstAppendItem(&ri->Elements, rn);
  4872. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4873. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4874. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4875. ri->TotalPadding += (bt->LP+bt->RP);
  4876. ri->MinW+=ri->UnitMinW;
  4877. ri->NonExpandW+=rn->GotW;
  4878. ri->ExpandAccum+=ui->Expand;
  4879. ri->CountElements++;
  4880. if(ui->Expand){ri->Expand=1;}
  4881. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4882. }
  4883. int la_ShrinkableRowElements(laRowInfo* ri){
  4884. int count=0;
  4885. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4886. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4887. count++;
  4888. }
  4889. return count;
  4890. }
  4891. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4892. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  4893. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4894. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4895. if(Available<0){
  4896. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4897. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4898. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4899. }else{
  4900. if(!ri->Expand && Available>0){Available=0;}
  4901. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4902. }
  4903. if(!ShareCount) return 0;
  4904. int PerNode = Available/ShareCount;
  4905. int Remaining = Available-PerNode*ShareCount;
  4906. int L = ri->L; int i=0; laRowNode* rn;
  4907. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4908. laUiItem* ui=rn->ui;
  4909. int NodeAdd, Node=rn->GotW;
  4910. if(rn->UseLast){
  4911. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4912. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4913. continue;
  4914. }
  4915. if(Available>=0){
  4916. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4917. NodeAdd+=(i<Remaining?1:0);i++;
  4918. }else{
  4919. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4920. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4921. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4922. }else{ Node=ri->UnitMinW;
  4923. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4924. }
  4925. }
  4926. ui->TL = L + rn->LP;
  4927. ui->TR = ui->TL + Node+NodeAdd;
  4928. ui->TB = ui->TU + rn->H;
  4929. L=ui->TR+rn->RP;
  4930. if (!rn->WaitAnimation){
  4931. ui->L = ui->TL; ui->R = ui->TR;
  4932. ui->U = ui->TU; ui->B = ui->TB;
  4933. }
  4934. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4935. }
  4936. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  4937. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  4938. memset(ri, 0, sizeof(laRowInfo));
  4939. }
  4940. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4941. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4942. int sl,sr,su,sb;
  4943. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4944. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4945. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4946. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4947. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4948. if(pc==LA_PC_SOCKET_OUT){
  4949. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4950. }else{
  4951. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4952. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4953. }
  4954. }
  4955. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4956. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4957. }
  4958. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4959. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4960. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4961. laBoxedTheme *bt;
  4962. int Lowest = 0;
  4963. int HyperValue = 0;
  4964. int WaitAnimation;
  4965. int RowMode=0; laRowInfo ri={0};
  4966. laBoxedTheme* pt=*(ParentPanel->BT);
  4967. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4968. int MaxR=0;
  4969. if(!uil->Scale){uil->Scale=1;}
  4970. uil->SaveScale=MAIN.UiScale;
  4971. MAIN.UiScale*=uil->Scale;
  4972. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4973. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4974. WaitAnimation = 0;
  4975. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4976. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4977. for (ui = uil->UiItems.pFirst; ui;){
  4978. int SubB = 0;
  4979. int H;
  4980. WaitAnimation = 0;
  4981. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4982. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4983. //if (Fast && ui->C->B > B) {
  4984. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4985. // ui = ui->Item.pNext;
  4986. // continue;
  4987. //}
  4988. if (!ui->Instructions){
  4989. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4990. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4991. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4992. laOperatorProp *ap = ui->PP.LastPs->p;
  4993. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  4994. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  4995. }
  4996. }
  4997. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  4998. la_UsePropPack(&ui->PP, 0);
  4999. if (ui->CompoundPPs.pFirst){
  5000. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5001. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5002. }
  5003. }
  5004. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5005. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5006. // 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);
  5007. //}
  5008. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5009. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5010. WaitAnimation = 1;
  5011. }
  5012. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5013. bt = (*ui->Type->Theme);
  5014. if (ui->Type == &_LA_UI_CONDITION){
  5015. laConditionUiExtraData *cued = ui->Extra;
  5016. la_StepExpression(cued->Expression);
  5017. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5018. if (!cued->IsTrue){
  5019. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5020. }else{
  5021. ui = ui->Item.pNext;
  5022. }
  5023. continue;
  5024. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5025. ui = ui->Item.pNext;
  5026. continue;
  5027. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5028. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5029. if (cued->IsTrue) ui = cued->EndUi;
  5030. else
  5031. ui = ui->Item.pNext;
  5032. continue;
  5033. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5034. laConditionUiExtraData *cued = ui->Extra;
  5035. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5036. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5037. if (!WaitAnimation){
  5038. ui->L = ui->TL; ui->R = ui->TR;
  5039. ui->U = ui->TU; ui->B = ui->TB;
  5040. }
  5041. if(!RowMode){
  5042. la_CalcUiItemInfluence(&uil->Columns, ui);
  5043. }else{
  5044. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5045. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5046. }
  5047. if (ui->State == LA_UI_NORMAL){
  5048. cued->IsTrue = 0;
  5049. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5050. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5051. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5052. }else{
  5053. cued->IsTrue = 1;
  5054. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5055. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5056. //}
  5057. ui = ui->Item.pNext;
  5058. }
  5059. continue;
  5060. }
  5061. if (ui->Type == _LA_UI_ALIGN){
  5062. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5063. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5064. if (ui->TB > Lowest) Lowest = ui->TB;
  5065. if (!WaitAnimation){
  5066. ui->L = ui->TL; ui->R = ui->TR;
  5067. ui->U = ui->TU; ui->B = ui->TB;
  5068. }
  5069. if(!RowMode){
  5070. la_CalcUiItemInfluence(&uil->Columns, ui);
  5071. }else{
  5072. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5073. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5074. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5075. }
  5076. ui = ui->Item.pNext; continue;
  5077. }
  5078. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5079. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5080. la_InitRowNode(&ri, ui, bt);
  5081. RowMode=1; ui=ui->Item.pNext; continue;
  5082. }
  5083. if (ui->Type == &_LA_UI_ROW_END){
  5084. la_CalculateRowExpand(&ri, ui);
  5085. la_CalcUiItemInfluence(&uil->Columns, ui);
  5086. RowMode=0; ui=ui->Item.pNext; continue;
  5087. }
  5088. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5089. int GB=0;
  5090. 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; }
  5091. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5092. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5093. if (H < 0){
  5094. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5095. else{ H=LA_RH; }
  5096. }
  5097. else H *= LA_RH;
  5098. ui->TB = ui->TU;
  5099. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5100. 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
  5101. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5102. if (ui->Type == _LA_UI_COLLECTION){
  5103. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5104. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5105. ui->PP.EndInstance = TInstance;
  5106. laUiList *iuil = ui->Subs.pFirst;
  5107. laUiList *puil = iuil;
  5108. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5109. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5110. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5111. int Begin = ui->TB;
  5112. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5113. int ElementB = ui->TU;
  5114. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5115. int MaxB = ElementB;
  5116. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5117. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5118. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5119. if (!ElementLimit) RowPriority = 0;
  5120. if (!TInstance){
  5121. while (iuil){
  5122. puil = iuil->Item.pNext;
  5123. la_DestroyTabPage(ui, iuil, 0);
  5124. iuil = puil;
  5125. }
  5126. }
  5127. while (TInstance){
  5128. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  5129. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5130. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5131. ui->PP.EndInstance = TInstance; continue;
  5132. }
  5133. if(CanGetTheme){
  5134. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5135. la_SwitchThemeQuick(t, OriginalTheme);
  5136. }
  5137. if(CanGetGap){
  5138. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5139. Gap=g*LA_RH;
  5140. }else Gap=0;
  5141. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5142. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5143. }else GotCategory=0;
  5144. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5145. if (RowPriority){
  5146. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5147. }
  5148. }
  5149. FirstIn=0;
  5150. if (ElementLimit){
  5151. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5152. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5153. }
  5154. while (iuil && iuil->Instance != TInstance){
  5155. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5156. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5157. }else{
  5158. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5159. }
  5160. iuil = puil;
  5161. }
  5162. if(!iuil){
  5163. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5164. }
  5165. if (!iuil){
  5166. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5167. la_CalcUiTopInfluence(&uil->Columns, ui);
  5168. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5169. 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);
  5170. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5171. iuil = ui->Page->Item.pNext;
  5172. }else{
  5173. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5174. 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);
  5175. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5176. la_CalcUiItemInfluence(&uil->Columns, ui);
  5177. iuil = iuil->Item.pNext;
  5178. }
  5179. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5180. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5181. ui->PP.EndInstance = TInstance;
  5182. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5183. if (RowPriority){
  5184. Col += 1;
  5185. if (Col >= ElementLimit){
  5186. Col = 0;
  5187. Row += 1;
  5188. Begin = ElementB + bt->TM;
  5189. }
  5190. }elif(Spread){
  5191. EL+=Spread*LA_RH;
  5192. ER+=Spread*LA_RH;
  5193. }else{
  5194. Row += 1;
  5195. Begin = ElementB + bt->TM;
  5196. if (ElementLimit && Row >= ElementLimit){
  5197. Row = 0;
  5198. Col += 1;
  5199. Begin = ui->TU + bt->TM;
  5200. }
  5201. }
  5202. ui->TB = ElementB;
  5203. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5204. }
  5205. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5206. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5207. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5208. ui->TB = MaxB;
  5209. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5210. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5211. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5212. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5213. ui->TB=ui->TU+LA_RH;
  5214. }else{
  5215. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5216. ui->PP.EndInstance = TInstance;
  5217. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5218. if(!Template) Template=laui_SubPropInfoDefault;
  5219. //ui->Template = Template;
  5220. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5221. if (!ui->Subs.pFirst && TInstance){
  5222. la_AddInstancePage(ui, TInstance, 0);
  5223. la_CalcUiTopInfluence(&uil->Columns, ui);
  5224. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5225. 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);
  5226. ui->TB = SubB + (NoDecal?0:bt->BM);
  5227. }else if (ui->Subs.pFirst){
  5228. if (!TInstance || TInstance != ui->Page->Instance){
  5229. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5230. ui->Page = 0;
  5231. if (TInstance){
  5232. la_AddInstancePage(ui, TInstance, 0);
  5233. la_CalcUiTopInfluence(&uil->Columns, ui);
  5234. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5235. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  5236. ui->TB = SubB + (NoDecal?0:bt->TM);
  5237. }else
  5238. ui->TB = ui->TU + LA_RH + bt->BM;
  5239. }else{
  5240. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  5241. ui->TB = SubB + (NoDecal?0:bt->BM);
  5242. }
  5243. }
  5244. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5245. ui->TB=ui->TU+LA_RH;
  5246. }
  5247. }
  5248. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5249. if (!WaitAnimation){
  5250. ui->L = ui->TL;
  5251. ui->R = ui->TR;
  5252. ui->U = ui->TU;
  5253. ui->B = ui->TB;
  5254. }
  5255. }
  5256. }else{
  5257. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5258. if (ui->Type != _LA_UI_CANVAS){
  5259. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5260. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5261. SubB = la_UpdateUiListRecursive(ui->Page,
  5262. 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);
  5263. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5264. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5265. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5266. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5267. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5268. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5269. }
  5270. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5271. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5272. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5273. if(ui->Page->HeightCoeff){
  5274. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5275. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5276. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5277. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5278. }
  5279. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5280. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5281. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5282. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5283. }
  5284. }
  5285. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5286. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5287. }else{
  5288. laUiList *suil;
  5289. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5290. la_CalcUiTopInfluence(&uil->Columns, ui);
  5291. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5292. 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);
  5293. }
  5294. }
  5295. ui->TB = ui->TU + H;
  5296. }
  5297. }else ui->TB = ui->TU + H;
  5298. }
  5299. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5300. if(!RowMode){
  5301. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5302. }else{
  5303. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5304. }
  5305. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5306. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5307. ui = ui->Item.pNext;
  5308. }
  5309. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5310. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5311. else uil->TB = Lowest;
  5312. if (!WaitAnimation){
  5313. uil->L = uil->TL;
  5314. uil->R = uil->TR;
  5315. uil->U = uil->TU;
  5316. uil->B = uil->TB;
  5317. }
  5318. MAIN.UiScale=uil->SaveScale;
  5319. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5320. return uil->TB;
  5321. }
  5322. int la_AnimateSingleUiSize(int To, int *Now){
  5323. int Delta;
  5324. if (To != *Now){
  5325. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5326. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5327. *Now += Delta;
  5328. return 1;
  5329. }else
  5330. return 0;
  5331. }
  5332. int la_AnimateUiListRecursive(laUiList *uil){
  5333. laUiItem *ui;
  5334. int Again = 0;
  5335. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5336. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5337. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5338. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5339. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5340. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5341. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5342. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5343. laUiList *suil;
  5344. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5345. Again += la_AnimateUiListRecursive(suil);
  5346. }
  5347. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5348. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5349. Again += la_AnimateUiListRecursive(ui->Page);
  5350. }
  5351. }
  5352. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5353. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5354. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5355. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5356. return Again;
  5357. }
  5358. int la_DrawUiItem(laUiItem *ui){
  5359. tnsUseNoTexture();
  5360. tnsColor4d(1, 1, 1, 1);
  5361. tnsVertex2d(ui->L, ui->U);
  5362. tnsVertex2d(ui->R, ui->U);
  5363. tnsVertex2d(ui->R, ui->B);
  5364. tnsVertex2d(ui->L, ui->B);
  5365. tnsPackAs(GL_LINE_LOOP);
  5366. }
  5367. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5368. tnsUseNoTexture();
  5369. tnsColor4d(1, 1, 1, 1);
  5370. tnsVertex2d(ui->L - 1, ui->U - 1);
  5371. tnsVertex2d(ui->R + 1, ui->U - 1);
  5372. tnsVertex2d(ui->R + 1, ui->B + 1);
  5373. tnsVertex2d(ui->L - 1, ui->B + 1);
  5374. tnsPackAs(GL_LINE_LOOP);
  5375. }
  5376. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5377. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5378. return 1;
  5379. }
  5380. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5381. laUiListDrawItem *uildi = uild->Items.pFirst;
  5382. laUiList *Target = uildi->Target;
  5383. int L, R, U, B;
  5384. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5385. L = Target->L + Target->PanX + uildi->DifX;
  5386. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5387. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5388. U = Target->U + Target->PanY + uildi->DifY;
  5389. return la_UiInBound(ui, L, R, U, B);
  5390. }
  5391. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5392. laUiListDrawItem *uildi = uild->Items.pFirst;
  5393. laUiList *Target = uildi->Target;
  5394. int L, R, U, B;
  5395. if (Target){
  5396. L = Target->L + Target->PanX + uildi->DifX;
  5397. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5398. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5399. U = Target->U + Target->PanY + uildi->DifY;
  5400. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5401. return 1;
  5402. }else{
  5403. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5404. return 1;
  5405. }
  5406. }
  5407. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5408. laUiItem *ui = uil->UiItems.pFirst;
  5409. while (!strGetArgument(ui->Instructions, mark))
  5410. ui = ui->Item.pNext;
  5411. return ui;
  5412. }
  5413. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5414. laUiList *uil;
  5415. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5416. if (uil->Instance == Instance) return uil;
  5417. }
  5418. return uil;
  5419. }
  5420. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5421. int mx=(L+R)/2; int my=(U+B)/2;
  5422. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5423. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5424. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5425. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5426. tnsFlush();
  5427. }
  5428. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5429. if(!uil->ScrollerShownV) return;
  5430. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5431. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5432. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5433. int U = uil->U + Offset;
  5434. int B = U + Len;
  5435. int L = UiR - RM*2 - W;
  5436. int R = L + W;
  5437. if (B > U + DisplayH) B = U + DisplayH;
  5438. if (U < uil->U) U = uil->U;
  5439. if (B <= uil->U || U >= uil->B) return;
  5440. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5441. if (U < uil->U) U = uil->U;
  5442. tnsUseNoTexture();
  5443. laBoxedTheme* bt=_LA_THEME_PANEL;
  5444. real* color=laThemeColor(bt, LA_BT_TEXT);
  5445. tnsColor4d(LA_COLOR3(color), 0.2);
  5446. tnsVertex2d(R-RM, uil->U);
  5447. tnsVertex2d(L+RM, uil->U);
  5448. tnsVertex2d(L+RM, uil->U + DisplayH);
  5449. tnsVertex2d(R-RM, uil->U + DisplayH);
  5450. tnsPackAs(GL_TRIANGLE_FAN);
  5451. tnsColor4d(LA_COLOR3(color), 0.5);
  5452. tnsVertex2d(R-RM, uil->U);
  5453. tnsVertex2d(L+RM, uil->U);
  5454. tnsVertex2d(L+RM, uil->U + DisplayH);
  5455. tnsVertex2d(R-RM, uil->U + DisplayH);
  5456. tnsPackAs(GL_LINE_LOOP);
  5457. tnsColor4d(LA_COLOR3(color), 1);
  5458. tnsVertex2d(R, U);
  5459. tnsVertex2d(L, U);
  5460. tnsVertex2d(L, B);
  5461. tnsVertex2d(R, B);
  5462. tnsPackAs(GL_TRIANGLE_FAN);
  5463. int HU=(U+B)/2+LA_RH2;
  5464. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5465. tnsFlush();
  5466. }
  5467. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5468. if(!uil->ScrollerShownH) return;
  5469. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5470. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5471. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5472. int L = uil->L + Offset;
  5473. int R = L + Len;
  5474. int U = UiB - RM - W;
  5475. int B = U + W;
  5476. if (B > U + DisplayW) B = U + DisplayW;
  5477. if (U < uil->U) U = uil->U;
  5478. if (R <= uil->L || L >= uil->R) return;
  5479. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5480. if (L < uil->L) L = uil->L;
  5481. tnsUseNoTexture();
  5482. laBoxedTheme* bt=_LA_THEME_PANEL;
  5483. real* color=laThemeColor(bt, LA_BT_TEXT);
  5484. tnsColor4d(LA_COLOR3(color), 0.2);
  5485. tnsVertex2d(uil->L,U+RM);
  5486. tnsVertex2d(uil->L,B-RM);
  5487. tnsVertex2d(uil->L + DisplayW,B-RM);
  5488. tnsVertex2d(uil->L + DisplayW,U+RM);
  5489. tnsPackAs(GL_TRIANGLE_FAN);
  5490. tnsColor4d(LA_COLOR3(color), 0.5);
  5491. tnsVertex2d(uil->L,U+RM);
  5492. tnsVertex2d(uil->L,B-RM);
  5493. tnsVertex2d(uil->L + DisplayW,B-RM);
  5494. tnsVertex2d(uil->L + DisplayW,U+RM);
  5495. tnsPackAs(GL_LINE_LOOP);
  5496. tnsColor4d(LA_COLOR3(color), 1);
  5497. tnsVertex2d(R, U);
  5498. tnsVertex2d(L, U);
  5499. tnsVertex2d(L, B);
  5500. tnsVertex2d(R, B);
  5501. tnsPackAs(GL_TRIANGLE_FAN);
  5502. int HU=(U+B)/2+LA_RH2;
  5503. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5504. tnsFlush();
  5505. }
  5506. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5507. tnsUseNoTexture();
  5508. tnsColor4dv(color);
  5509. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5510. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5511. tnsPackAs(GL_TRIANGLE_FAN);
  5512. }
  5513. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5514. laSocketRecord* sr;
  5515. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5516. uild->WiresContainer=container;
  5517. }
  5518. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5519. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5520. if(lip->Target==uild->WiresContainer) break;
  5521. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5522. }
  5523. }
  5524. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5525. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5526. int PanX, PanY;
  5527. if(pc==LA_PC_SOCKET_OUT){
  5528. laNodeOutSocket* s=ui->PP.EndInstance;
  5529. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5530. }else{
  5531. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5532. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5533. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5534. }
  5535. }
  5536. void la_RegenerateWireColors(){
  5537. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5538. laTheme* t=MAIN.CurrentTheme;
  5539. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5540. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5541. for(int i=0;i<MAIN.WireColorSlices;i++){
  5542. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5543. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5544. }
  5545. }
  5546. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5547. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5548. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5549. tnsInterpolate2dv(v1,v2,0.5,vi);
  5550. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5551. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5552. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5553. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5554. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5555. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5556. tnsVertex2d(v1[0],v1[1]);
  5557. for(int i=1;i<=steps;i++){
  5558. real ratio=i==steps?1.0f:step*i;
  5559. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5560. tnsVertex2d(v1s[0],v1s[1]);
  5561. }
  5562. }
  5563. void la_DrawNodeWires(laUiListDraw* uild){
  5564. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5565. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5566. tnsUseNoTexture();
  5567. #define _RSLICES 16
  5568. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5569. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5570. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5571. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5572. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5573. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5574. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, 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. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5578. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5579. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5580. }
  5581. if(MAIN.tNodeIn->Source){
  5582. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5583. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5584. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5585. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5586. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, 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. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5590. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5591. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5592. }
  5593. #undef _RSLICES
  5594. tnsFlush();
  5595. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5596. glLineWidth(ww);
  5597. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5598. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5599. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5600. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5601. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5602. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5603. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5604. }
  5605. if(MAIN.tNodeIn->Source){
  5606. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5607. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5608. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5609. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5610. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5611. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5612. }
  5613. tnsFlush();
  5614. glLineWidth(1);
  5615. la_InitSocketRecord(uild,0);
  5616. }
  5617. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5618. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5619. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5620. }
  5621. 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){
  5622. laUiItem *ui;
  5623. laBoxedTheme *bt;
  5624. laUiList *sub;
  5625. laUiListDrawItem *uildi;
  5626. int Ret = 0;
  5627. if (!uil) return 0;
  5628. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5629. ui = uil->UiItems.pFirst;
  5630. if(uil->PanY<0){uil->PanY=0;}
  5631. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5632. uil->SaveScale=MAIN.UiScale;
  5633. MAIN.UiScale*=uil->Scale;
  5634. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5635. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5636. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5637. if (ui->Type == &_LA_UI_CONDITION){
  5638. laConditionUiExtraData *cued = ui->Extra;
  5639. la_StepExpression(cued->Expression);
  5640. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5641. if (!cued->IsTrue){
  5642. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5643. }else{
  5644. ui = ui->Item.pNext;
  5645. }
  5646. continue;
  5647. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5648. ui = ui->Item.pNext;
  5649. continue;
  5650. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5651. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5652. if (cued->IsTrue) ui = cued->EndUi;
  5653. else
  5654. ui = ui->Item.pNext;
  5655. continue;
  5656. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5657. laConditionUiExtraData *cued = ui->Extra;
  5658. ui->Type->Draw(ui, LA_RH);
  5659. if (ui->State == LA_UI_NORMAL){
  5660. cued->IsTrue = 0;
  5661. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5662. }else{
  5663. cued->IsTrue = 1;
  5664. ui = ui->Item.pNext;
  5665. }
  5666. continue;
  5667. }
  5668. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5669. int NeedDraw=0;
  5670. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5671. if(NeedDraw){
  5672. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5673. }else{ ui->Type->Draw(ui, LA_RH); }
  5674. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5675. tnsFlush();
  5676. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5677. tnsResetViewMatrix();
  5678. }
  5679. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5680. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5681. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5682. tnsFlush();
  5683. }
  5684. }
  5685. if(NeedDraw || RegisterNodes){
  5686. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5687. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5688. ui->Type == _LA_UI_TAB ||
  5689. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5690. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5691. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5692. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5693. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5694. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5695. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5696. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5697. 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); }
  5698. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5699. 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);
  5700. 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)); }
  5701. }elif (ui->Type == _LA_UI_COLLECTION){
  5702. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5703. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5704. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5705. void* SaveInstance = ui->PP.EndInstance;
  5706. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5707. int State;
  5708. ui->PP.EndInstance = sub->Instance;
  5709. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5710. if(NeedDraw){ int drawn=0;
  5711. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5712. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5713. }
  5714. if (CanGetState && !drawn){
  5715. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5716. if(State >= 0){
  5717. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5718. }
  5719. }
  5720. }
  5721. if(sub->TabName && sub->TabName->Ptr){
  5722. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5723. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5724. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5725. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5726. tnsFlush();
  5727. }
  5728. if(CanGetTheme){
  5729. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5730. la_SwitchThemeQuick(t, OriginalTheme);
  5731. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5732. }
  5733. tnsFlush();
  5734. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5735. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5736. }
  5737. //ui->PP.EndInstance = Active;
  5738. ui->PP.EndInstance = SaveInstance;
  5739. }elif (ui->Type == _LA_UI_CANVAS){
  5740. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5741. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5742. tnsFlush();
  5743. 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);
  5744. }
  5745. }
  5746. }
  5747. ui = ui->Item.pNext;
  5748. }else{
  5749. ui = ui->Item.pNext;
  5750. }
  5751. }
  5752. tnsFlush();
  5753. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5754. la_RestoreLastUiListMatrix(uild, B - U);
  5755. MAIN.UiScale=uil->SaveScale;
  5756. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5757. return Ret;
  5758. }
  5759. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5760. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5761. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5762. tnsUseNoTexture();
  5763. tnsColor4d(1, 1, 1, 1);
  5764. tnsVertex2d(L, U);
  5765. tnsVertex2d(R, U);
  5766. tnsVertex2d(R, B);
  5767. tnsVertex2d(L, B);
  5768. tnsPackAs(GL_LINE_LOOP);
  5769. tnsVertex2d(L + 3, Begin);
  5770. tnsVertex2d(R - 3, Begin);
  5771. tnsVertex2d(R - 3, End);
  5772. tnsVertex2d(L + 3, End);
  5773. tnsPackAs(GL_LINE_LOOP);
  5774. }
  5775. int laIsInUiItem(laUiItem *ui, int x, int y){
  5776. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5777. return 1;
  5778. }
  5779. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5780. if (x < l || x > r || y < u || y > b) return 0;
  5781. return 1;
  5782. }
  5783. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5784. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5785. laUiItem *ui, *tui;
  5786. laBoxedTheme *bt;
  5787. laUiList *sub;
  5788. int CPB = 0;
  5789. if (!uil || (LimB && y > LimB)) return 0;
  5790. x += uil->PanX;
  5791. y += uil->PanY;
  5792. for (ui = uil->UiItems.pFirst; ui;){
  5793. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5794. if (ui->Type == &_LA_UI_CONDITION){
  5795. laConditionUiExtraData *cued = ui->Extra;
  5796. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5797. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5798. if (!cued->IsTrue){
  5799. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5800. }else{
  5801. ui = ui->Item.pNext;
  5802. }
  5803. continue;
  5804. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5805. ui = ui->Item.pNext;
  5806. continue;
  5807. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5808. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5809. if (cued->IsTrue) ui = cued->EndUi;
  5810. else
  5811. ui = ui->Item.pNext;
  5812. continue;
  5813. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5814. laConditionUiExtraData *cued = ui->Extra;
  5815. if (laIsInUiItem(ui, x, y)){
  5816. lstAppendPointer(LocalBuf, uil);
  5817. return ui;
  5818. }
  5819. if (ui->State == LA_UI_NORMAL){
  5820. cued->IsTrue = 0;
  5821. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5822. }else{
  5823. cued->IsTrue = 1;
  5824. ui = ui->Item.pNext;
  5825. }
  5826. continue;
  5827. }
  5828. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5829. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5830. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5831. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5832. if(!la_DetectSplit(ui->C, x)) Add=0;
  5833. }
  5834. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5835. }
  5836. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5837. if (ui->Page->HeightCoeff) CPB = ui->B;
  5838. else CPB = ui->Page->B;
  5839. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5840. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5841. lstAppendPointer(LocalBuf, uil);
  5842. return tui;
  5843. }
  5844. }else if (laIsInUiItem(ui, x, y)){
  5845. lstAppendPointer(LocalBuf, uil);return ui;
  5846. }
  5847. }
  5848. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5849. if (laIsInUiItem(ui, x, y)){
  5850. lstAppendPointer(LocalBuf, uil);
  5851. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5852. if(Deep){
  5853. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5854. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5855. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5856. lstAppendPointer(LocalBuf, iuil);
  5857. return tui;
  5858. }
  5859. }
  5860. }
  5861. }
  5862. return ui;
  5863. }
  5864. }
  5865. if (ui->Type == _LA_UI_CANVAS){
  5866. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5867. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5868. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5869. lstAppendPointer(LocalBuf, uil);
  5870. return tui;
  5871. }
  5872. }
  5873. }
  5874. if (laIsInUiItem(ui, x, y)){
  5875. lstAppendPointer(LocalBuf, uil);
  5876. return ui;
  5877. }
  5878. }
  5879. ui = ui->Item.pNext;
  5880. }
  5881. return 0;
  5882. }
  5883. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5884. laListHandle Locals={0};
  5885. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5886. while(lstPopPointer(&Locals));
  5887. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5888. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5889. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5890. if(pc==PCInOrOut) return ui;
  5891. }
  5892. return 0;
  5893. }
  5894. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5895. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5896. laUiItem *ui = uil->UiItems.pFirst;
  5897. laBoxedTheme *bt;
  5898. laUiList *tuil;
  5899. laUiList *sub;
  5900. int CPB = 0;
  5901. x += uil->PanX;
  5902. y += uil->PanY;
  5903. if (y > LimH) return uil;
  5904. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  5905. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  5906. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5907. return uil;
  5908. }
  5909. for (ui = uil->UiItems.pFirst; ui;){
  5910. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5911. if (ui->Type == &_LA_UI_CONDITION){
  5912. laConditionUiExtraData *cued = ui->Extra;
  5913. //la_StepExpression(cued->Expression);
  5914. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5915. if (!cued->IsTrue){
  5916. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5917. }else{
  5918. ui = ui->Item.pNext;
  5919. }
  5920. continue;
  5921. }
  5922. if (ui->Type == &_LA_UI_CONDITION_END){
  5923. ui = ui->Item.pNext;
  5924. continue;
  5925. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5926. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5927. if (cued->IsTrue) ui = cued->EndUi;
  5928. else
  5929. ui = ui->Item.pNext;
  5930. continue;
  5931. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5932. laConditionUiExtraData *cued = ui->Extra;
  5933. if (ui->State == LA_UI_NORMAL){
  5934. cued->IsTrue = 0;
  5935. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5936. }else{
  5937. cued->IsTrue = 1;
  5938. ui = ui->Item.pNext;
  5939. }
  5940. continue;
  5941. }
  5942. if (InToContainerUI && ui != Exception){
  5943. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5944. if (ContainerParent) (*ContainerParent) = uil;
  5945. if (ParentUi) *ParentUi = ui;
  5946. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5947. //if (y > LimH) return uil;
  5948. 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))){
  5949. return tuil;
  5950. }
  5951. }
  5952. }
  5953. }
  5954. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5955. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  5956. else CPB = ui->Page->B;
  5957. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5958. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5959. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5960. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5961. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5962. if (ParentUi) *ParentUi = ui;
  5963. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5964. }
  5965. }
  5966. ui = ui->Item.pNext;
  5967. }
  5968. return uil;
  5969. }
  5970. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5971. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5972. laUiItem *ui = uil->UiItems.pFirst;
  5973. laBoxedTheme *bt;
  5974. laUiList *tuil;
  5975. laUiList *sub;
  5976. int CPB = 0;
  5977. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5978. x += uil->PanX;
  5979. y += uil->PanY;
  5980. if (y > LimH) return uil;
  5981. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5982. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5983. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5984. return uil;
  5985. }
  5986. for (ui = uil->UiItems.pFirst; ui;){
  5987. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5988. if (ui->Type == &_LA_UI_CONDITION){
  5989. laConditionUiExtraData *cued = ui->Extra;
  5990. //la_StepExpression(cued->Expression);
  5991. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5992. if (!cued->IsTrue){
  5993. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5994. }else{
  5995. ui = ui->Item.pNext;
  5996. }
  5997. continue;
  5998. }
  5999. if (ui->Type == &_LA_UI_CONDITION_END){
  6000. ui = ui->Item.pNext;
  6001. continue;
  6002. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6003. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6004. if (cued->IsTrue) ui = cued->EndUi;
  6005. else
  6006. ui = ui->Item.pNext;
  6007. continue;
  6008. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6009. laConditionUiExtraData *cued = ui->Extra;
  6010. if (ui->State == LA_UI_NORMAL){
  6011. cued->IsTrue = 0;
  6012. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6013. }else{
  6014. cued->IsTrue = 1;
  6015. ui = ui->Item.pNext;
  6016. }
  6017. continue;
  6018. }
  6019. if (InToContainerUI && ui != Exception){
  6020. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6021. if (ContainerParent) (*ContainerParent) = uil;
  6022. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6023. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6024. //if (y > LimH) return uil;
  6025. 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))){
  6026. return tuil;
  6027. }
  6028. }
  6029. }
  6030. }
  6031. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6032. if (ui->Page->HeightCoeff) CPB = ui->B;
  6033. else CPB = ui->Page->B;
  6034. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6035. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6036. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6037. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6038. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6039. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6040. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6041. }
  6042. }
  6043. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6044. if (ui->Page->HeightCoeff) CPB = ui->B;
  6045. else
  6046. CPB = ui->Page->B;
  6047. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6048. if (ScrollUil) *ScrollUil = ui->Page;
  6049. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6050. }
  6051. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6052. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6053. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6054. }
  6055. }
  6056. ui = ui->Item.pNext;
  6057. }
  6058. return uil;
  6059. }
  6060. int la_TestUiListMinumWidth(laUiList *uil){
  6061. laUiItem *ui, *tui;
  6062. laBoxedTheme *bt;
  6063. laUiList *sub;
  6064. int CPB = 0;
  6065. int W = 0;
  6066. int tW, sW, RowMode=0, rW;
  6067. void *Restore;
  6068. for (ui = uil->UiItems.pFirst; ui;){
  6069. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6070. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6071. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6072. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6073. if (W < tW) W = tW;
  6074. }elif (ui->Type == _LA_UI_COLLECTION){
  6075. Restore = ui->PP.EndInstance;
  6076. tW = 0; sW = 0;
  6077. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6078. ui->PP.EndInstance = sub->Instance;
  6079. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6080. if (sW > tW) tW = sW;
  6081. }
  6082. ui->PP.EndInstance = Restore;
  6083. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6084. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6085. if (W < tW) W = tW;
  6086. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6087. RowMode=1; rW=0;
  6088. }elif (ui->Type==&_LA_UI_ROW_END){
  6089. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6090. }elif (ui->Type->GetMinWidth){
  6091. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6092. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6093. }
  6094. ui = ui->Item.pNext;
  6095. }
  6096. return W;
  6097. }
  6098. void la_InitLLVM(){
  6099. //LLVMLinkInMCJIT();
  6100. //LLVMInitializeNativeTarget();
  6101. //LLVMInitializeNativeAsmPrinter();
  6102. //LLVMInitializeNativeAsmParser();
  6103. // MAIN.llvmContext = LLVMGetGlobalContext();
  6104. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6105. }
  6106. //==================================================================================================
  6107. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6108. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6109. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6110. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6111. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6112. memFree(kmi);
  6113. }
  6114. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6115. laKeyMapItem *kmi;
  6116. if (!km) return 0;
  6117. kmi = memAcquire(sizeof(laKeyMapItem));
  6118. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6119. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6120. }else{
  6121. strSafeSet(&kmi->Operation, Operation);
  6122. }
  6123. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6124. kmi->SpecialKeyBits = SpecialKeyBits;
  6125. kmi->EventType = EventType;
  6126. kmi->Key = tolowerGuarded(Key);
  6127. kmi->SelectBase = SelectBase;
  6128. lstAppendItem(&km->Items, kmi);
  6129. return kmi;
  6130. }
  6131. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6132. laKeyMapItem *kmi; int inv=0;
  6133. char *instructions;
  6134. if(e->type==LA_MOUSEMOVE) return 0;
  6135. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6136. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6137. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6138. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6139. if (kmi->Operation)
  6140. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6141. else
  6142. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6143. inv = 1;
  6144. }
  6145. }
  6146. return inv;
  6147. }
  6148. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6149. laKeyMapItem *kmi;
  6150. char *instructions;
  6151. int inv = 0; int lx = -1, ly = -1;
  6152. if(e->type==LA_MOUSEMOVE) return 0;
  6153. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6154. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6155. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6156. if (e->Localized){
  6157. lx = e->x;
  6158. ly = e->y;
  6159. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6160. e->Localized = 0;
  6161. }
  6162. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6163. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6164. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6165. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6166. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6167. }elif (kmi->Operation){
  6168. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6169. }else{
  6170. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6171. }
  6172. inv = 1;
  6173. if (lx >= 0){
  6174. e->x = lx;
  6175. e->y = ly;
  6176. e->Localized = 1;
  6177. }
  6178. }
  6179. }
  6180. return inv;
  6181. }
  6182. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6183. void la_DestroyOperatorType(laOperatorType* at){
  6184. //if(at->PC) la_FreePropertyContainer(at->PC);
  6185. memFree(at);
  6186. }
  6187. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6188. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6189. uint32_t IconID, int ExtraMark){
  6190. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6191. at->Identifier = ID;
  6192. at->Name = Name;
  6193. at->Description = Description;
  6194. at->Check = Check;
  6195. at->Invoke = Invoke;
  6196. at->Init = Init;
  6197. at->Exit = Exit;
  6198. at->Modal = Modal;
  6199. at->IconID = IconID;
  6200. at->ExtraMark = ExtraMark;
  6201. at->ParseArgs = la_DefaultOperatorParser;
  6202. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6203. return at;
  6204. }
  6205. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6206. ot->PC = memAcquire(sizeof(laPropContainer));
  6207. ot->PC->Identifier = ot->Identifier;
  6208. ot->PC->Hyper = HyperLevel;
  6209. return ot->PC;
  6210. }
  6211. laOperator *la_CreateOperator(laOperatorType *at){
  6212. laOperator *a = CreateNew(laOperator);
  6213. a->Type = at;
  6214. if (at->PC && at->PC->Props.pFirst){
  6215. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6216. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6217. a->PP.LastPs->p->SubProp = at->PC;
  6218. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6219. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6220. a->PP.LastPs->Type = U'.';
  6221. }
  6222. return a;
  6223. }
  6224. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6225. return (!strcmp(a->Identifier, id));
  6226. }
  6227. laOperatorType *laGetOperatorType(const char *ID){
  6228. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6229. }
  6230. int laOperatorExistsT(laOperatorType* at){
  6231. if (!at) return 0;
  6232. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6233. return 0;
  6234. }
  6235. int laOperatorExists(const char* ID){
  6236. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6237. return laOperatorExistsT(at);
  6238. }
  6239. int la_OperatorExists(laOperator *ac){
  6240. if (!ac) return 0;
  6241. laOperator *a;
  6242. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6243. return 0;
  6244. }
  6245. int la_UiOperatorExists(void *inst){
  6246. laOperator *a;
  6247. if (!inst) return 0;
  6248. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6249. if (((laUiItem *)a->Instance) == inst){
  6250. return 1;
  6251. }
  6252. }
  6253. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6254. if (a->Instance == inst){
  6255. return 1;
  6256. }
  6257. }
  6258. return 0;
  6259. }
  6260. int la_OperatorPending(laOperator *target){
  6261. laOperator *a;
  6262. if (!target) return 0;
  6263. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6264. if (a == target){
  6265. return 1;
  6266. }
  6267. }
  6268. return 0;
  6269. }
  6270. void laSetOperatorLocalizer(void *ToPanel){
  6271. MAIN.ToPanel = ToPanel;
  6272. }
  6273. void la_DestroyConfirmData(laConfirmData **cd);
  6274. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6275. laOperator *ai = (*a);
  6276. laOperator *ac = ((*a)->Child);
  6277. void *Ret = 0;
  6278. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6279. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6280. }
  6281. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6282. if ((*a)->PP.LastPs){
  6283. memFree((*a)->PP.LastPs->p);
  6284. memFree((*a)->PP.LastPs);
  6285. }
  6286. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6287. la_SetPropMathcerContext((*a)->OperatorPanel);
  6288. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6289. laDestroySinglePanel((*a)->OperatorPanel,0);
  6290. }
  6291. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6292. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6293. lstClearPointer(&(*a)->LocalUiLists);
  6294. if (Operators){
  6295. Ret = ai->Item.pNext;
  6296. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6297. else
  6298. lstRemoveItem(Operators, *a);
  6299. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6300. if (ai->Child == (*a)) ai->Child = 0;
  6301. }
  6302. }
  6303. strSafeDestroy(&(*a)->RuntimeHint);
  6304. free(*a);
  6305. return Ret;
  6306. }
  6307. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6308. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6309. if (!at) return 0;
  6310. if (!at->Check) return 1;
  6311. return (at->Check(This, Instructions));
  6312. }
  6313. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6314. if (!at) return 0;
  6315. if (!at->Check) return 1;
  6316. return (at->Check(This, Instructions));
  6317. }
  6318. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6319. laPropPack FakePP = {0};
  6320. laPropStep FakePs = {0};
  6321. if (!at) return 0;
  6322. if (!at->Check) return 1;
  6323. FakePP.LastPs = &FakePs;
  6324. FakePP.Go = FakePP.LastPs;
  6325. FakePP.LastPs->p = This->LastPs->p;
  6326. FakePP.LastPs->UseInstance = This->EndInstance;
  6327. FakePP.EndInstance = Real_FromInstance;
  6328. FakePP.LastIndex = This->LastIndex;
  6329. return (at->Check(&FakePP, Instructions));
  6330. }
  6331. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6332. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6333. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6334. }
  6335. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6336. laOperator *a, *f = From;
  6337. int rev;
  6338. if (!f && e&&e->Localized) return -1;
  6339. a = la_CreateOperator(at);
  6340. a->ToPanel = MAIN.ToPanel;
  6341. a->This = This;
  6342. a->ExtraInstructions = args;
  6343. strMakeInstructions(&a->ExtraInstructionsP, args);
  6344. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6345. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6346. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6347. la_DestroyOperator(&a, 0, 0);
  6348. return LA_CANCELED;
  6349. }
  6350. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6351. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6352. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6353. e->Localized = 1;
  6354. }
  6355. if (e&&e->Localized){
  6356. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6357. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6358. e->Localized = 0;
  6359. }else{
  6360. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6361. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6362. }
  6363. }
  6364. if (From) f->Child = a;
  6365. a->Using = 1;
  6366. if (at->Init) at->Init(a);
  6367. rev = at->Invoke(a, e);
  6368. a->Using = 0;
  6369. if (rev & LA_FINISH){
  6370. a->StopNow = 1; if(From)From->Child=0;
  6371. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6372. }
  6373. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6374. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6375. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6376. a->State = rev;
  6377. a->PP.EndInstance = a->CustomData;
  6378. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6379. }else
  6380. la_DestroyOperator(&a, 0, 0);
  6381. return rev;
  6382. }
  6383. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6384. laOperatorType *at; laOperator *a, *f = From;
  6385. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6386. if (!at) return -1;
  6387. return laInvokeP(From,at,e,This,args,args2);
  6388. }
  6389. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6390. laOperator *a, *f = From;
  6391. int rev;
  6392. laPropPack *created;
  6393. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6394. created = memAcquireSimple(sizeof(laPropPack));
  6395. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6396. created->Go = created->LastPs;
  6397. created->LastPs->p = OrigionalThis->LastPs->p;
  6398. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6399. created->EndInstance = FromInstance;
  6400. created->LastIndex = OrigionalThis->LastIndex;
  6401. a = la_CreateOperator(at);
  6402. a->ToPanel = MAIN.ToPanel;
  6403. a->This = created;
  6404. a->CreatedThis = created;
  6405. a->ExtraInstructions = args;
  6406. strMakeInstructions(&a->ExtraInstructionsP, args);
  6407. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6408. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6409. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6410. la_DestroyOperator(&a, 0, 0);
  6411. return LA_CANCELED;
  6412. }
  6413. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6414. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6415. if (From) f->Child = a;
  6416. a->Using = 1;
  6417. if (at->Init) at->Init(a);
  6418. rev = at->Invoke(a, e);
  6419. a->Using = 0;
  6420. if (rev & LA_FINISH){
  6421. a->StopNow = 1; if(From)From->Child=0;
  6422. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6423. }
  6424. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6425. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6426. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6427. a->State = rev;
  6428. a->PP.EndInstance = a->CustomData;
  6429. }else
  6430. la_DestroyOperator(&a, 0, 0);
  6431. return rev;
  6432. }
  6433. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6434. laOperator *a, *f = From;
  6435. int rev;
  6436. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6437. a = la_CreateOperator(at);
  6438. a->Instance = inst;
  6439. a->ToPanel = MAIN.ToPanel;
  6440. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6441. if (From) f->Child = a;
  6442. a->Using = 1;
  6443. if (at->Init) at->Init(a);
  6444. rev = at->Invoke(a, e);
  6445. a->Using = 0;
  6446. if (rev & LA_FINISH){
  6447. a->StopNow = 1; if(From)From->Child=0;
  6448. }
  6449. if (rev & LA_BLOCK){
  6450. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6451. a->State = rev;
  6452. }else la_DestroyOperator(&a, 0, 0);
  6453. DEB = a;
  6454. return rev;
  6455. }
  6456. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6457. laOperatorType *at;
  6458. laOperator *a, *f = From;
  6459. if (la_UiOperatorExists(inst)) return -1;
  6460. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6461. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6462. }
  6463. void laRequestDelayEvent(real Seconds){
  6464. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6465. int la_UiStillInService(void *UiInstance){
  6466. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6467. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6468. if (ai->Instance == UiInstance) return 1;
  6469. }
  6470. return 0;
  6471. }
  6472. void la_StopUiOperatorService(void *UiInstance){
  6473. laOperator *ai, *dai, *NextAi;
  6474. if (!MAIN.CurrentWindow) return;
  6475. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6476. NextAi = ai->Item.pNext;
  6477. if (ai->Instance == UiInstance){
  6478. if (ai->Child){
  6479. la_StopUiOperatorService(ai->Child->Instance);
  6480. ai->Child = 0;
  6481. }
  6482. laOperator *dai = ai;
  6483. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6484. continue;
  6485. }
  6486. }
  6487. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6488. NextAi = ai->Item.pNext;
  6489. if (ai->Instance == UiInstance){
  6490. if (ai->Instance == ai->ToPanel){
  6491. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6492. //ai->ToPanel->LaterDestroy = 1;
  6493. }
  6494. if (ai->Child && la_OperatorExists(ai->Child)){
  6495. la_StopUiOperatorService(ai->Child->Instance);
  6496. //ai->Child = 0;
  6497. }
  6498. if (!ai->Using){
  6499. laOperator *dai = ai;
  6500. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6501. }else
  6502. ai->StopNow = 1;
  6503. }
  6504. }
  6505. }
  6506. void la_StopAllOperators(){
  6507. laOperator *ai, *dai, *NextAi;
  6508. if (!MAIN.CurrentWindow) return;
  6509. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6510. NextAi = ai->Item.pNext;
  6511. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6512. continue;
  6513. }
  6514. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6515. NextAi = ai->Item.pNext;
  6516. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6517. laHidePanelWithDissoveEffect(ai->ToPanel);
  6518. ai->ToPanel->LaterDestroy = 1;
  6519. }
  6520. if (!ai->Using){
  6521. laOperator *dai = ai;
  6522. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6523. }else ai->StopNow = 1;
  6524. }
  6525. }
  6526. void la_DestroyConfirmData(laConfirmData **cd){
  6527. if((!cd)||!(*cd)) return;
  6528. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6529. if ((*cd)->StrData) free((*cd)->StrData);
  6530. FreeMem((*cd));
  6531. (*cd) = 0;
  6532. }
  6533. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6534. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6535. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6536. ai->NextConfirmData = cd; laRetriggerOperators();
  6537. }
  6538. void laConfirmInt(laOperator *a, int Data, int mode){
  6539. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6540. cd->IData = Data; cd->Mode = mode;
  6541. ai->NextConfirmData = cd; laRetriggerOperators();
  6542. }
  6543. void laConfirmFloat(laOperator *a, real Data, int mode){
  6544. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6545. cd->FData = Data; cd->Mode = mode;
  6546. ai->NextConfirmData = cd; laRetriggerOperators();
  6547. }
  6548. void laConfirmString(laOperator *a, char *Str, int mode){
  6549. laOperator *ai = a;
  6550. laConfirmData *cd = CreateNew(laConfirmData);
  6551. int len = strlen(Str);
  6552. char *buf = calloc(len + 1, sizeof(char));
  6553. strcpy(buf, Str);
  6554. cd->StrData = buf;
  6555. cd->Mode = mode;
  6556. cd->Destroy = free;
  6557. ai->NextConfirmData = cd;
  6558. laRetriggerOperators();
  6559. }
  6560. int laConfirmSameDataIfAny(laOperator *a){
  6561. laOperator *ai = a;
  6562. laConfirmData *cd;
  6563. char *buf = 0;
  6564. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6565. cd = CreateNew(laConfirmData);
  6566. if (ai->ConfirmData->StrData){
  6567. int len = strlen(ai->ConfirmData->StrData);
  6568. buf = calloc(len + 1, sizeof(char));
  6569. strcpy(buf, ai->ConfirmData->StrData);
  6570. }
  6571. //cd->CustomData = cd->CustomData;
  6572. cd->IData = ai->ConfirmData->IData;
  6573. cd->FData = ai->ConfirmData->FData;
  6574. cd->PointerData = ai->ConfirmData->PointerData;
  6575. cd->PointerType = a->ConfirmData->PointerType;
  6576. cd->StrData = buf;
  6577. cd->Mode = ai->ConfirmData->Mode;
  6578. cd->Destroy = ai->ConfirmData->Destroy;
  6579. ai->NextConfirmData = cd;
  6580. laRetriggerOperators();
  6581. return 1;
  6582. }
  6583. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6584. laOperator *ai = a;
  6585. laConfirmData *cd = CreateNew(laConfirmData);
  6586. cd->CustomData = UserData;
  6587. cd->Mode = mode;
  6588. cd->Destroy = Destroy;
  6589. ai->NextConfirmData = cd;
  6590. laRetriggerOperators();
  6591. }
  6592. int laGetConfirmMode(laOperator *a){
  6593. return ((laOperator *)a)->ConfirmData->Mode;
  6594. }
  6595. int laGetConfirmInt(laOperator *a){
  6596. laOperator *ai = a;
  6597. int rev = ai->ConfirmData->IData;
  6598. la_DestroyConfirmData(&ai->ConfirmData);
  6599. ai->ConfirmData = 0;
  6600. return rev;
  6601. }
  6602. real laGetConfirmFloat(laOperator *a){
  6603. laOperator *ai = a;
  6604. real rev = ai->ConfirmData->FData;
  6605. la_DestroyConfirmData(&ai->ConfirmData);
  6606. ai->ConfirmData = 0;
  6607. return rev;
  6608. }
  6609. void laGetConfirmString(laOperator *a, char *buf){
  6610. laOperator *ai = a;
  6611. strcpy(buf, ai->ConfirmData->StrData);
  6612. la_DestroyConfirmData(&ai->ConfirmData);
  6613. ai->ConfirmData = 0;
  6614. }
  6615. void *laGetConfirmUserData(laOperator *a){
  6616. laOperator *ai = a;
  6617. return ai->ConfirmData->CustomData;
  6618. }
  6619. void laFinalizeOperators(){
  6620. laOperatorType *at;
  6621. laListHandle *lst;
  6622. int i;
  6623. for (i = 0; i < 256; i++){
  6624. lst = &MAIN.OperatorTypeHash.Entries[i];
  6625. for (at = lst->pFirst; at; at = at->Item.pNext){
  6626. if (at->PC && at->PC->Props.pFirst){
  6627. lstAppendItem(&MAIN.PropContainers, at->PC);
  6628. }
  6629. }
  6630. }
  6631. }
  6632. //=================
  6633. #ifdef LA_LINUX
  6634. static void la_RecordWacomMotions(XIRawEvent *event)
  6635. {
  6636. double *valuator = event->valuators.values;
  6637. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6638. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6639. //SYSWINDOW root_return, child_return;
  6640. //int root_x_return, root_y_return;
  6641. //int win_x_return, win_y_return;
  6642. //unsigned int mask_return;
  6643. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6644. // &root_x_return, &root_y_return,
  6645. // &win_x_return, &win_y_return,
  6646. // &mask_return);
  6647. //
  6648. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6649. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6650. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6651. real x=valuator[3],y=valuator[4];
  6652. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6653. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6654. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6655. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6656. if(XIMaskIsSet(event->valuators.mask, 5)){
  6657. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6658. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6659. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6660. MAIN.IsPen=1;
  6661. }
  6662. #endif
  6663. #ifdef _WIN32
  6664. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6665. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6666. static uint32_t ch = 0; static int lead = 0;
  6667. static wchar_t buf[10] = { 0 }; int adv;
  6668. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6669. short wheelmark = 0;
  6670. int WheelDir = 0;
  6671. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6672. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6673. POINT point;
  6674. PACKET pkt;
  6675. static POINT ptOld, ptNew;
  6676. static UINT prsOld, prsNew, vkey;
  6677. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6678. switch (message) {
  6679. case WM_PAINT:
  6680. //SwapBuffers(GetDC(hwnd));
  6681. break;
  6682. case WM_MOUSEMOVE:
  6683. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6684. MAIN.IsPen = 0;
  6685. break;
  6686. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6687. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6688. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6689. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6690. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6691. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6692. case WM_MOUSEWHEEL:
  6693. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6694. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6695. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6696. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6697. break;
  6698. case WT_PACKET:
  6699. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6700. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6701. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6702. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6703. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6704. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6705. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6706. MAIN.StylusTwist = tw;
  6707. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6708. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6709. MAIN.EraserPressure = MAIN.StylusPressure;
  6710. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6711. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6712. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6713. }
  6714. return 0; break;
  6715. case WM_SYSCOMMAND:
  6716. switch (wparam) {
  6717. case SC_MAXIMIZE:
  6718. case SC_RESTORE:
  6719. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6720. break;
  6721. case SC_KEYMENU:
  6722. return 0;
  6723. case SC_MINIMIZE:
  6724. break;
  6725. }
  6726. break;
  6727. case WM_SIZE:
  6728. if (wparam == SIZE_MINIMIZED) break;
  6729. case WM_MOVE: /* And size */
  6730. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6731. break;
  6732. case WM_SETCURSOR:
  6733. if(MAIN.CurrentCursor) return 1;
  6734. break;
  6735. case WM_POINTERDOWN:
  6736. case WM_POINTERUP:
  6737. case WM_POINTERUPDATE:
  6738. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6739. pointerId = GET_POINTERID_WPARAM(wparam);
  6740. pointerType = PT_POINTER;
  6741. if(!GetPointerType(pointerId, &pointerType)){
  6742. pointerType = PT_POINTER;
  6743. }
  6744. if(pointerType == PT_PEN){
  6745. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6746. for (int i = peninfonum-1; i>=0; i--) {
  6747. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6748. ScreenToClient(hwnd, &point);
  6749. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6750. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6751. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6752. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6753. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6754. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6755. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6756. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6757. }
  6758. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6759. }
  6760. }
  6761. SkipPointerFrameMessages(pointerId);
  6762. return 0;
  6763. }
  6764. else if (pointerType == PT_TOUCH){
  6765. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6766. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6767. ScreenToClient(hwnd, &point);
  6768. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6769. }
  6770. }
  6771. break;
  6772. case WM_SYSKEYDOWN:
  6773. if (lparam & 0x40000000) break;
  6774. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6775. break;
  6776. case WM_KEYDOWN:
  6777. if (lparam & 0x40000000) break;
  6778. vkey = wparam;
  6779. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6780. break;
  6781. case WM_KEYUP:
  6782. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6783. break;
  6784. case WM_SYSKEYUP:
  6785. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6786. break;
  6787. case WM_UNICHAR:
  6788. la_SendInputEvent(hwnd, wparam);
  6789. break;
  6790. case WM_IME_CHAR:
  6791. la_SendInputEvent(hwnd, wparam);
  6792. return 0;
  6793. case WM_CHAR:
  6794. la_SendInputEvent(hwnd, wparam);
  6795. break;
  6796. case WM_SHOWWINDOW:
  6797. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6798. break;
  6799. case WM_CLOSE:
  6800. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6801. break;
  6802. default:
  6803. return DefWindowProc(hwnd, message, wparam, lparam);
  6804. }
  6805. return DefWindowProc(hwnd, message, wparam, lparam);
  6806. }
  6807. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6808. return DefWindowProc(hwnd, message, wparam, lparam);
  6809. }
  6810. #endif
  6811. int la_UpdateOperatorHints(laWindow* w){
  6812. laSafeString* ss=0;
  6813. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6814. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6815. }
  6816. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6817. }else{
  6818. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6819. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6820. }
  6821. strSafeDestroy(&ss);
  6822. }
  6823. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6824. laOperator *a, *NextA = 0;
  6825. int Result = 0;
  6826. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6827. la_SendSignalsFromEvent(e);
  6828. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6829. a = Operators->pFirst;
  6830. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6831. while (1){
  6832. if (!a) break;
  6833. if (a->StopNow){
  6834. NextA = a->Item.pNext;
  6835. if (a->Type->Exit) a->Type->Exit(a, Result);
  6836. ConfirmData = a->NextConfirmData;
  6837. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6838. NextConfirmData = ConfirmData;
  6839. a->ConfirmData = 0;
  6840. a->NextConfirmData = 0;
  6841. la_DestroyOperator(&a, Operators, 0);
  6842. a = NextA;
  6843. if (a){
  6844. a->ConfirmData = NextConfirmData;
  6845. }
  6846. continue;
  6847. }
  6848. a->Using = 1;
  6849. la_SetPropMathcerContext(a->ToPanel);
  6850. laSetOperatorLocalizer(a->ToPanel);
  6851. MAIN.CurrentPanel = a->ToPanel;
  6852. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6853. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6854. e->Localized = 1;
  6855. }
  6856. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6857. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6858. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6859. e->Localized = 0;
  6860. }
  6861. la_SetPropMathcerContext(0);
  6862. laSetOperatorLocalizer(0);
  6863. MAIN.CurrentPanel = 0;
  6864. a->Using = 0;
  6865. if (Result & LA_PASS_ON){
  6866. laConfirmSameDataIfAny(a);
  6867. NextA = a->Item.pNext;
  6868. }else{
  6869. NextA = 0;
  6870. if (a->NextConfirmData){
  6871. la_DestroyConfirmData(&a->NextConfirmData);
  6872. }
  6873. }
  6874. ConfirmData = a->NextConfirmData;
  6875. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6876. NextConfirmData = ConfirmData;
  6877. a->ConfirmData = 0;
  6878. a->NextConfirmData = 0;
  6879. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6880. if (a->Type->Exit) a->Type->Exit(a, Result);
  6881. la_DestroyOperator(&a, Operators, 0);
  6882. int found=0;
  6883. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6884. if(!found){ NextA=0; }
  6885. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6886. }
  6887. a = NextA;
  6888. if (a){
  6889. a->ConfirmData = NextConfirmData;
  6890. }
  6891. }
  6892. return 1;
  6893. }
  6894. int la_HandleEvents(laWindow *w){
  6895. laEvent *e, *NextE;
  6896. laOperator *a;
  6897. laThreadNotifier *tn;
  6898. MAIN.CurrentWindow=w;
  6899. //laSpinLock(&MAIN.csNotifier);
  6900. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6901. //laSpinUnlock(&MAIN.csNotifier);
  6902. laNotifyUsers(tn->Path);
  6903. FreeMem(tn);
  6904. //if (MAIN.ThreadNotifiers.pFirst)
  6905. //laSpinLock(&MAIN.csNotifier);
  6906. }
  6907. //laSpinUnlock(&MAIN.csNotifier);
  6908. while (1){
  6909. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6910. while (w->EventList.pFirst){
  6911. while (w->PendingOperators.pLast){
  6912. a = w->PendingOperators.pLast;
  6913. if (a->OperatorPanel){
  6914. laSetOperatorLocalizer(a->OperatorPanel);
  6915. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6916. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6917. }
  6918. lstRemoveItem(&w->PendingOperators, a);
  6919. lstPushItem(&w->Operators, a);
  6920. }
  6921. e = lstPopItem(&w->EventList);
  6922. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6923. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6924. memFree(e);
  6925. }
  6926. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  6927. if (!MAIN.ReTriggerOperators) break;
  6928. }
  6929. la_UpdateOperatorHints(w);
  6930. return 1;
  6931. }
  6932. int la_AllowInput(uint32_t ch){
  6933. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6934. return 0;
  6935. }
  6936. int laCopyToClipboard(unsigned char * text){
  6937. #ifdef LA_LINUX
  6938. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6939. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6940. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6941. strSafeSet(&MAIN.CopyPending, text);
  6942. #endif
  6943. }
  6944. int la_ProcessSysMessage(){
  6945. int SendDelay = 0, SendIdle = 0;
  6946. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6947. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6948. #ifdef LA_LINUX
  6949. XEvent e;
  6950. int type;
  6951. int InputCount = 0, CharCount=0;
  6952. KeySym InputKeysym = 0;
  6953. Status InputStatus = 0;
  6954. laWindow* wnd ;
  6955. while(XPending(MAIN.dpy)){
  6956. XGenericEventCookie *cookie = &e.xcookie;
  6957. XNextEvent(MAIN.dpy, &e);
  6958. if (XFilterEvent(&e, None)) continue;
  6959. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6960. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6961. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6962. XFreeEventData(MAIN.dpy, cookie); continue;
  6963. }
  6964. switch(e.type){
  6965. case ConfigureNotify:
  6966. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6967. break;
  6968. case Expose:
  6969. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6970. if(!wnd) break;
  6971. laRefreshWindow(wnd);
  6972. break;
  6973. case MotionNotify:
  6974. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6975. MAIN.IsPen=0;
  6976. break;
  6977. case ButtonPress:
  6978. type=LA_MOUSEDOWN;
  6979. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6980. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6981. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6982. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  6983. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  6984. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6985. MAIN.IsPen=0;
  6986. break;
  6987. case ButtonRelease:
  6988. type=LA_MOUSEUP;
  6989. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6990. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6991. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6992. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6993. MAIN.IsPen=0;
  6994. break;
  6995. case KeyPress:
  6996. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  6997. MAIN.InputBuf[InputCount]=0;
  6998. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  6999. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7000. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7001. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7002. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7003. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7004. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7005. #ifdef DEBUG
  7006. printf("pressed KEY: %d\n", (int)InputKeysym);
  7007. #endif
  7008. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7009. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7010. }
  7011. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7012. }
  7013. break;
  7014. case KeyRelease:
  7015. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7016. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7017. }
  7018. case ClientMessage:
  7019. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7020. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7021. }
  7022. break;
  7023. case SelectionNotify:
  7024. if(e.xselection.selection != MAIN.bufid) continue;
  7025. if (e.xselection.property){
  7026. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7027. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7028. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7029. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7030. else if(result) {
  7031. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7032. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7033. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7034. }
  7035. XFree(result);
  7036. return True;
  7037. }
  7038. case SelectionRequest:
  7039. if(!MAIN.CopyPending){ break; }
  7040. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7041. if (e.xselectionrequest.selection != MAIN.selection) break;
  7042. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7043. XSelectionEvent ev = {0};
  7044. int R = 0;
  7045. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7046. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7047. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7048. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7049. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7050. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7051. else if (ev.target == MAIN.UTF8)
  7052. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7053. else ev.property = None;
  7054. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7055. break;
  7056. case SelectionClear:
  7057. break;
  7058. default:
  7059. break;
  7060. }
  7061. }
  7062. #endif //linux
  7063. #ifdef _WIN32
  7064. MSG msg; int Processed = 0;
  7065. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7066. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7067. if (msg.wParam == VK_PROCESSKEY) {
  7068. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7069. }
  7070. TranslateMessage(&msg); DispatchMessage(&msg);
  7071. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7072. };
  7073. if(!MAIN.Windows.pFirst){ return 0; }
  7074. #endif
  7075. #ifdef LAGUI_ANDROID
  7076. int pollResult = 0;
  7077. int pollEvents = 0;
  7078. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7079. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7080. // NOTE: Never close window, native activity is controlled by the system!
  7081. if (MAIN.app->destroyRequested != 0)
  7082. {
  7083. //CORE.Window.shouldClose = true;
  7084. //ANativeActivity_finish(MAIN.app->activity);
  7085. }
  7086. }
  7087. #endif
  7088. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7089. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7090. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7091. }
  7092. return 1;
  7093. };
  7094. void la_PrintOperatorStack(){
  7095. laWindow *w = MAIN.CurrentWindow;
  7096. laOperator *a;
  7097. printf("\n");
  7098. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7099. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7100. a->Type->Identifier, a->Instance,
  7101. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7102. }
  7103. }
  7104. void la_DrawWindow(laWindow *w){
  7105. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7106. MAIN.CurrentWindow = w;
  7107. la_WindowDefDraw(w, 0);
  7108. }
  7109. int laFinalize(){
  7110. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7111. laUiTemplate* uit;
  7112. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7113. return 1;
  7114. }
  7115. void la_PreFrame(){
  7116. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7117. la_AnimationPreFrame();
  7118. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7119. }
  7120. void la_PostFrame(){
  7121. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7122. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7123. }
  7124. void laMainLoop(){
  7125. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7126. laTimeRecorder FrameStartTime, FrameEndTime;
  7127. time_t t1, t2;
  7128. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7129. static int a = 0;
  7130. if(!laFinalize()) return;
  7131. laSetWindowCursor(LA_ARROW);
  7132. MAIN.DelayTriggered=1;
  7133. #ifdef LAGUI_ANDROID
  7134. while(!MAIN.AppReady){ usleep(1000); }
  7135. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7136. #endif
  7137. while (1){
  7138. laRecordTime(&FrameStartTime);
  7139. la_PreFrame();
  7140. if(!la_ProcessSysMessage()){ return; }
  7141. la_UpdateControllerStatus();
  7142. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7143. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7144. NextW = w->Item.pNext;
  7145. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7146. }
  7147. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7148. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7149. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7150. if(MAIN.GLDebugNeedsUpdate){
  7151. la_SetCurrentGLContextDebug();
  7152. }
  7153. la_DrawWindow(w);
  7154. }
  7155. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7156. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7157. #ifdef LA_LINUX
  7158. #ifdef LA_USE_GLES
  7159. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7160. #else
  7161. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7162. #endif
  7163. #endif
  7164. #ifdef _WIN32
  7165. SwapBuffers(w->hdc);
  7166. #endif
  7167. #ifdef LAGUI_ANDROID
  7168. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7169. #endif
  7170. }
  7171. MAIN.GLDebugNeedsUpdate=0;
  7172. la_PostFrame();
  7173. //t2 = clock();
  7174. laRecordTime(&FrameEndTime);
  7175. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  7176. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7177. if (Pause > 0){
  7178. int us = Pause * 1000000.0;
  7179. usleep(us);
  7180. }
  7181. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7182. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7183. la_AnimationPostFrame();
  7184. }
  7185. }
  7186. #ifdef LAGUI_ANDROID
  7187. int la_AndroidInitGraphics(void){
  7188. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7189. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7190. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7191. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7192. EGLint samples = 0;
  7193. EGLint sampleBuffer = 0;
  7194. const EGLint framebufferAttribs[] = {
  7195. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7196. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7197. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7198. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7199. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7200. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7201. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7202. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7203. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7204. EGL_NONE
  7205. };
  7206. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7207. EGLint numConfigs = 0;
  7208. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7209. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7210. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7211. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7212. eglBindAPI(EGL_OPENGL_API);
  7213. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7214. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7215. EGLint displayFormat = 0;
  7216. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7217. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7218. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7219. // There must be at least one frame displayed before the buffers are swapped
  7220. eglSwapInterval(MAIN.egl_dpy, 1);
  7221. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7222. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7223. MAIN.AppReady = 1;
  7224. return 0;
  7225. }
  7226. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7227. switch (cmd){
  7228. case APP_CMD_START: break;
  7229. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7230. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7231. case APP_CMD_RESUME:break;//InitPlatform();break;
  7232. case APP_CMD_INIT_WINDOW:
  7233. if (app->window != NULL){
  7234. if (MAIN.ContextRebindRequired){
  7235. // Reset screen scaling to full display size
  7236. EGLint displayFormat = 0;
  7237. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7238. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7239. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7240. // appropriate way to fix this
  7241. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7242. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7243. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7244. displayFormat);
  7245. // Recreate display surface and re-attach OpenGL context
  7246. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7247. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7248. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7249. //glClearColor(1,0.2,1,1);
  7250. //glClear(GL_COLOR_BUFFER_BIT);
  7251. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7252. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7253. MAIN.ContextRebindRequired = false;
  7254. }else{
  7255. la_AndroidInitGraphics();
  7256. }
  7257. }
  7258. break;
  7259. case APP_CMD_TERM_WINDOW:
  7260. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7261. // 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.
  7262. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7263. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7264. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7265. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7266. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7267. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7268. MAIN.egl_surf = EGL_NO_SURFACE;
  7269. }
  7270. MAIN.ContextRebindRequired = true;
  7271. }
  7272. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7273. // this means that the user has already called 'CloseWindow()'
  7274. break;
  7275. case APP_CMD_SAVE_STATE: break;
  7276. case APP_CMD_STOP: break;
  7277. case APP_CMD_DESTROY: break;
  7278. case APP_CMD_CONFIG_CHANGED:
  7279. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7280. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7281. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7282. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7283. //print_cur_config(MAIN.app);
  7284. // Check screen orientation here!
  7285. break;
  7286. default: break;
  7287. }
  7288. }
  7289. #define KEYCODE_MAP_SIZE 162
  7290. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7291. 0, // AKEYCODE_UNKNOWN
  7292. 0, // AKEYCODE_SOFT_LEFT
  7293. 0, // AKEYCODE_SOFT_RIGHT
  7294. 0, // AKEYCODE_HOME
  7295. 0, // AKEYCODE_BACK
  7296. 0, // AKEYCODE_CALL
  7297. 0, // AKEYCODE_ENDCALL
  7298. '0', // AKEYCODE_0
  7299. '1', // AKEYCODE_1
  7300. '2', // AKEYCODE_2
  7301. '3', // AKEYCODE_3
  7302. '4', // AKEYCODE_4
  7303. '5', // AKEYCODE_5
  7304. '6', // AKEYCODE_6
  7305. '7', // AKEYCODE_7
  7306. '8', // AKEYCODE_8
  7307. '9', // AKEYCODE_9
  7308. 0, // AKEYCODE_STAR
  7309. 0, // AKEYCODE_POUND
  7310. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7311. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7312. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7313. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7314. 0, // AKEYCODE_DPAD_CENTER
  7315. 0, // AKEYCODE_VOLUME_UP
  7316. 0, // AKEYCODE_VOLUME_DOWN
  7317. 0, // AKEYCODE_POWER
  7318. 0, // AKEYCODE_CAMERA
  7319. 0, // AKEYCODE_CLEAR
  7320. 'a', // AKEYCODE_A
  7321. 'b', // AKEYCODE_B
  7322. 'c', // AKEYCODE_C
  7323. 'd', // AKEYCODE_D
  7324. 'e', // AKEYCODE_E
  7325. 'f', // AKEYCODE_F
  7326. 'g', // AKEYCODE_G
  7327. 'h', // AKEYCODE_H
  7328. 'i', // AKEYCODE_I
  7329. 'j', // AKEYCODE_J
  7330. 'k', // AKEYCODE_K
  7331. 'l', // AKEYCODE_L
  7332. 'm', // AKEYCODE_M
  7333. 'n', // AKEYCODE_N
  7334. 'o', // AKEYCODE_O
  7335. 'p', // AKEYCODE_P
  7336. 'q', // AKEYCODE_Q
  7337. 'r', // AKEYCODE_R
  7338. 's', // AKEYCODE_S
  7339. 't', // AKEYCODE_T
  7340. 'u', // AKEYCODE_U
  7341. 'v', // AKEYCODE_V
  7342. 'w', // AKEYCODE_W
  7343. 'x', // AKEYCODE_X
  7344. 'y', // AKEYCODE_Y
  7345. 'z', // AKEYCODE_Z
  7346. ',', // AKEYCODE_COMMA
  7347. '.', // AKEYCODE_PERIOD
  7348. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7349. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7350. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7351. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7352. LA_KEY_TAB, // AKEYCODE_TAB
  7353. ' ', // AKEYCODE_SPACE
  7354. 0, // AKEYCODE_SYM
  7355. 0, // AKEYCODE_EXPLORER
  7356. 0, // AKEYCODE_ENVELOPE
  7357. LA_KEY_ENTER, // AKEYCODE_ENTER
  7358. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7359. '`', // AKEYCODE_GRAVE
  7360. '-', // AKEYCODE_MINUS
  7361. '=', // AKEYCODE_EQUALS
  7362. '(', // AKEYCODE_LEFT_BRACKET
  7363. ')', // AKEYCODE_RIGHT_BRACKET
  7364. '\\', // AKEYCODE_BACKSLASH
  7365. ';', // AKEYCODE_SEMICOLON
  7366. '\'', // AKEYCODE_APOSTROPHE
  7367. '/', // AKEYCODE_SLASH
  7368. 0, // AKEYCODE_AT
  7369. 0, // AKEYCODE_NUM
  7370. 0, // AKEYCODE_HEADSETHOOK
  7371. 0, // AKEYCODE_FOCUS
  7372. 0, // AKEYCODE_PLUS
  7373. 0, // AKEYCODE_MENU
  7374. 0, // AKEYCODE_NOTIFICATION
  7375. 0, // AKEYCODE_SEARCH
  7376. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7377. 0, // AKEYCODE_MEDIA_STOP
  7378. 0, // AKEYCODE_MEDIA_NEXT
  7379. 0, // AKEYCODE_MEDIA_PREVIOUS
  7380. 0, // AKEYCODE_MEDIA_REWIND
  7381. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7382. 0, // AKEYCODE_MUTE
  7383. 0, // AKEYCODE_PAGE_UP
  7384. 0, // AKEYCODE_PAGE_DOWN
  7385. 0, // AKEYCODE_PICTSYMBOLS
  7386. 0, // AKEYCODE_SWITCH_CHARSET
  7387. 0, // AKEYCODE_BUTTON_A
  7388. 0, // AKEYCODE_BUTTON_B
  7389. 0, // AKEYCODE_BUTTON_C
  7390. 0, // AKEYCODE_BUTTON_X
  7391. 0, // AKEYCODE_BUTTON_Y
  7392. 0, // AKEYCODE_BUTTON_Z
  7393. 0, // AKEYCODE_BUTTON_L1
  7394. 0, // AKEYCODE_BUTTON_R1
  7395. 0, // AKEYCODE_BUTTON_L2
  7396. 0, // AKEYCODE_BUTTON_R2
  7397. 0, // AKEYCODE_BUTTON_THUMBL
  7398. 0, // AKEYCODE_BUTTON_THUMBR
  7399. 0, // AKEYCODE_BUTTON_START
  7400. 0, // AKEYCODE_BUTTON_SELECT
  7401. 0, // AKEYCODE_BUTTON_MODE
  7402. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7403. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7404. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7405. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7406. 0, // AKEYCODE_CAPS_LOCK
  7407. 0, // AKEYCODE_SCROLL_LOCK
  7408. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7409. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7410. 0, // AKEYCODE_FUNCTION
  7411. 0, // AKEYCODE_SYSRQ
  7412. 0, // AKEYCODE_BREAK
  7413. 0, // AKEYCODE_MOVE_HOME
  7414. 0, // AKEYCODE_MOVE_END
  7415. 0, // AKEYCODE_INSERT
  7416. 0, // AKEYCODE_FORWARD
  7417. 0, // AKEYCODE_MEDIA_PLAY
  7418. 0, // AKEYCODE_MEDIA_PAUSE
  7419. 0, // AKEYCODE_MEDIA_CLOSE
  7420. 0, // AKEYCODE_MEDIA_EJECT
  7421. 0, // AKEYCODE_MEDIA_RECORD
  7422. LA_KEY_F1, // AKEYCODE_F1
  7423. LA_KEY_F2, // AKEYCODE_F2
  7424. LA_KEY_F3, // AKEYCODE_F3
  7425. LA_KEY_F4, // AKEYCODE_F4
  7426. LA_KEY_F5, // AKEYCODE_F5
  7427. LA_KEY_F6, // AKEYCODE_F6
  7428. LA_KEY_F7, // AKEYCODE_F7
  7429. LA_KEY_F8, // AKEYCODE_F8
  7430. LA_KEY_F9, // AKEYCODE_F9
  7431. LA_KEY_F10, // AKEYCODE_F10
  7432. LA_KEY_F11, // AKEYCODE_F11
  7433. LA_KEY_F12, // AKEYCODE_F12
  7434. 0, // AKEYCODE_NUM_LOCK
  7435. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7436. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7437. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7438. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7439. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7440. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7441. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7442. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7443. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7444. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7445. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7446. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7447. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7448. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7449. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7450. 0, // AKEYCODE_NUMPAD_COMMA
  7451. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7452. '=' // AKEYCODE_NUMPAD_EQUALS
  7453. };
  7454. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7455. {
  7456. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7457. if(!MAIN.AppEnabled){return 0;}
  7458. //laRedrawAllWindows();
  7459. int type = AInputEvent_getType(event);
  7460. if(type == AINPUT_EVENT_TYPE_KEY){
  7461. int32_t keycode = AKeyEvent_getKeyCode(event);
  7462. //int32_t AKeyEvent_getMetaState(event);
  7463. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7464. if (key != 0){
  7465. // Save current key and its state
  7466. // NOTE: Android key action is 0 for down and 1 for up
  7467. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7468. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7469. if(key!=LA_KEY_BACKSPACE)
  7470. la_SendInputEvent(0,key);
  7471. }
  7472. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7473. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7474. la_SendInputEvent(0,key);
  7475. }
  7476. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7477. }
  7478. if (keycode == AKEYCODE_POWER)
  7479. {
  7480. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7481. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7482. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7483. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7484. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7485. return 0;
  7486. }
  7487. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7488. {
  7489. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7490. return 1;
  7491. }
  7492. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7493. {
  7494. // Set default OS behaviour
  7495. return 0;
  7496. }
  7497. return 0;
  7498. }
  7499. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7500. int pcount = AMotionEvent_getPointerCount(event); int x,y;
  7501. if(pcount){
  7502. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7503. x=rx; y=ry;
  7504. }
  7505. int32_t action = AMotionEvent_getAction(event);
  7506. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7507. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7508. if (flags == AMOTION_EVENT_ACTION_DOWN){
  7509. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7510. la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
  7511. }
  7512. else if (flags == AMOTION_EVENT_ACTION_UP){
  7513. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7514. }
  7515. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7516. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7517. }
  7518. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7519. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7520. }
  7521. }
  7522. //static float r=0;
  7523. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7524. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7525. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7526. //glClear(GL_COLOR_BUFFER_BIT);
  7527. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7528. return 0;
  7529. }
  7530. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7531. MAIN.AssetManager = manager;
  7532. MAIN.InternalDataPath = dataPath;
  7533. MAIN.ExternalDataPath = externalDataPath;
  7534. }
  7535. static int android_read(void *cookie, char *data, int dataSize){
  7536. return AAsset_read((AAsset *)cookie, data, dataSize);
  7537. }
  7538. static int android_write(void *cookie, const char *data, int dataSize){
  7539. return 0;
  7540. }
  7541. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7542. return AAsset_seek((AAsset *)cookie, offset, whence);
  7543. }
  7544. static int android_close(void *cookie){
  7545. AAsset_close((AAsset *)cookie);
  7546. return 0;
  7547. }
  7548. // Replacement for fopen()
  7549. // Ref: https://developer.android.com/ndk/reference/group/asset
  7550. FILE *android_fopen(const char *fileName, const char *mode)
  7551. {
  7552. char buf[1024];
  7553. if (mode[0] == 'w')
  7554. {
  7555. // fopen() is mapped to android_fopen() that only grants read access to
  7556. // assets directory through AAssetManager but we want to also be able to
  7557. // write data when required using the standard stdio FILE access functions
  7558. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7559. #undef fopen
  7560. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7561. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7562. result=fopen(buf, mode); if(result) return result;
  7563. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7564. return fopen(buf, mode);
  7565. #define fopen(name, mode) android_fopen(name, mode)
  7566. }
  7567. else
  7568. {
  7569. // NOTE: AAsset provides access to read-only asset
  7570. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7571. if (asset != NULL)
  7572. {
  7573. // Get pointer to file in the assets
  7574. return funopen(asset, android_read, android_write, android_seek, android_close);
  7575. }
  7576. else
  7577. {
  7578. #undef fopen
  7579. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7580. // Just do a regular open if file is not found in the assets
  7581. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7582. result=fopen(buf, mode); if(result){ return result; }
  7583. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7584. return fopen(buf, mode);
  7585. #define fopen(name, mode) android_fopen(name, mode)
  7586. }
  7587. }
  7588. }
  7589. void la_HideNavBar(){
  7590. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7591. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7592. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7593. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7594. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7595. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7596. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7597. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7598. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7599. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7600. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7601. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7602. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7603. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7604. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7605. int flag = flagFullscreen | flagHideNavigation;
  7606. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7607. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7608. }
  7609. void la_InitAndroidPlatform(struct android_app *app){
  7610. MAIN.app=app;
  7611. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7612. //la_HideNavBar();
  7613. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7614. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7615. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7616. int pollResult = 0;
  7617. int pollEvents = 0;
  7618. while (!MAIN.AppReady){
  7619. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7620. // Process this event
  7621. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7622. // NOTE: Never close window, native activity is controlled by the system!
  7623. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7624. }
  7625. }
  7626. }
  7627. int main(int, char *[]);
  7628. void android_main(struct android_app *app){
  7629. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7630. la_InitAndroidPlatform(app);
  7631. // NOTE: Return from main is ignored
  7632. (void)main(1, (char *[]) { arg0, NULL });
  7633. // Request to end the native activity
  7634. ANativeActivity_finish(app->activity);
  7635. // Android ALooper_pollAll() variables
  7636. int pollResult = 0;
  7637. int pollEvents = 0;
  7638. // Waiting for application events before complete finishing
  7639. while (!app->destroyRequested)
  7640. {
  7641. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7642. {
  7643. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7644. }
  7645. }
  7646. }
  7647. void la_DisplayKeyboard(bool pShow) {
  7648. // Attaches the current thread to the JVM.
  7649. jint lResult;
  7650. jint lFlags = 0;
  7651. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7652. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7653. JavaVMAttachArgs lJavaVMAttachArgs;
  7654. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7655. lJavaVMAttachArgs.name = "NativeThread";
  7656. lJavaVMAttachArgs.group = NULL;
  7657. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7658. if (lResult == JNI_ERR) {
  7659. return;
  7660. }
  7661. // Retrieves NativeActivity.
  7662. jobject lNativeActivity = MAIN.app->activity->clazz;
  7663. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7664. logPrintNew("jvm3");
  7665. // Retrieves Context.INPUT_METHOD_SERVICE.
  7666. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7667. jfieldID FieldINPUT_METHOD_SERVICE =
  7668. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7669. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7670. jobject INPUT_METHOD_SERVICE =
  7671. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7672. FieldINPUT_METHOD_SERVICE);
  7673. //jniCheck(INPUT_METHOD_SERVICE);
  7674. logPrintNew("jvm4");
  7675. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7676. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7677. "android/view/inputmethod/InputMethodManager");
  7678. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7679. ClassNativeActivity, "getSystemService",
  7680. "(Ljava/lang/String;)Ljava/lang/Object;");
  7681. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7682. lNativeActivity, MethodGetSystemService,
  7683. INPUT_METHOD_SERVICE);
  7684. // Runs getWindow().getDecorView().
  7685. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7686. ClassNativeActivity, "getWindow",
  7687. "()Landroid/view/Window;");
  7688. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7689. MethodGetWindow);
  7690. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7691. "android/view/Window");
  7692. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7693. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7694. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7695. MethodGetDecorView);
  7696. if (pShow) {
  7697. // Runs lInputMethodManager.showSoftInput(...).
  7698. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7699. ClassInputMethodManager, "showSoftInput",
  7700. "(Landroid/view/View;I)Z");
  7701. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7702. lInputMethodManager, MethodShowSoftInput,
  7703. lDecorView, lFlags);
  7704. } else {
  7705. // Runs lWindow.getViewToken()
  7706. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7707. "android/view/View");
  7708. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7709. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7710. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7711. MethodGetWindowToken);
  7712. // lInputMethodManager.hideSoftInput(...).
  7713. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7714. ClassInputMethodManager, "hideSoftInputFromWindow",
  7715. "(Landroid/os/IBinder;I)Z");
  7716. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7717. lInputMethodManager, MethodHideSoftInput,
  7718. lBinder, lFlags);
  7719. }
  7720. // Finished with the JVM.
  7721. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7722. }
  7723. #endif //android
  7724. #ifndef LAGUI_ANDROID
  7725. void la_DisplayKeyboard(bool pShow) {
  7726. return;
  7727. }
  7728. void la_HideNavBar(){
  7729. return;
  7730. }
  7731. #endif