*/}}

la_kernel.c 347 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  19. #define NANOVG_GLES3_IMPLEMENTATION
  20. #else
  21. #define NANOVG_GL3_IMPLEMENTATION
  22. #endif
  23. #include "la_5.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <time.h>
  28. #ifdef LA_LINUX
  29. #include <execinfo.h>
  30. #include <signal.h>
  31. #include <sys/time.h>
  32. #include <X11/Xlib.h>
  33. #include <X11/Xutil.h>
  34. #include <X11/Xos.h>
  35. #include <X11/keysymdef.h>
  36. #include <X11/XKBlib.h>
  37. #include <X11/extensions/XInput.h>
  38. #include <X11/extensions/XInput2.h>
  39. #include <X11/extensions/Xfixes.h>
  40. #include <X11/extensions/Xrandr.h>
  41. #include <X11/Xcursor/Xcursor.h>
  42. #include <X11/cursorfont.h>
  43. #include <GL/glx.h>
  44. #endif
  45. #ifdef _WIN32
  46. #include <GL/wglew.h>
  47. #include <GL/wgl.h>
  48. #include <shellscalingapi.h>
  49. #endif
  50. #ifdef LAGUI_ANDROID
  51. #include <GLES3/gl32.h>
  52. #include <jni.h>
  53. #include <android/log.h>
  54. #include <android/native_activity.h>
  55. #include <android/native_window.h>
  56. #include <android/native_window_jni.h>
  57. #include <android_native_app_glue.h>
  58. #include <android/window.h>
  59. #include <android/asset_manager.h>
  60. #include <android/input.h>
  61. #include <android/keycodes.h>
  62. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  63. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  64. static int android_read(void *cookie, char *buf, int size);
  65. static int android_write(void *cookie, const char *buf, int size);
  66. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  67. static int android_close(void *cookie);
  68. void la_InitAndroidPlatform(struct android_app *app);
  69. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  70. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  71. void la_InitAndroidPlatform(struct android_app *app);
  72. #endif
  73. LA MAIN={0};
  74. extern tnsMain *T;
  75. int deb = 0;
  76. laOperator *DEB;
  77. laColumn *DEBUG_C;
  78. #ifdef _WIN32
  79. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  80. #else
  81. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  82. #endif
  83. #ifdef LA_LINUX
  84. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  85. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  86. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  87. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  88. #endif
  89. #ifdef LA_LINUX
  90. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  91. int i;
  92. for (i = 0; i < num_classes; i++) {
  93. if (classes[i]->type == XIValuatorClass) {
  94. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  95. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  96. logPrint(" Range: %f - %f\n", v->min, v->max);
  97. logPrint(" Resolution: %d units/m\n", v->resolution);
  98. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  99. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  100. }
  101. }
  102. }
  103. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  104. XIDeviceInfo *info, *dev;
  105. int i, ndevices;
  106. dev = XIQueryDevice(display, deviceid, &ndevices);
  107. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  108. mask->deviceid = deviceid;
  109. mask->mask_len = XIMaskLen(XI_RawMotion);
  110. mask->mask=memAcquireSimple(mask->mask_len);
  111. memset(mask->mask, 0, mask->mask_len);
  112. XISetMask(mask->mask, XI_RawMotion);
  113. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  114. int FoundMax=0;
  115. for (i = 0; i < dev->num_classes; i++) {
  116. if (dev->classes[i]->type == XIValuatorClass) {
  117. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  118. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  119. }
  120. }
  121. if(!FoundMax){*max_pressure=65535;}
  122. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  123. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  124. XIFreeDeviceInfo(dev);
  125. }
  126. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  127. int axis=0;
  128. for (int i = 0; i < dev->num_classes; i++) {
  129. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  130. }
  131. return axis>=3;
  132. }
  133. #define LA_G_STYLUS(dev) \
  134. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  135. #define LA_G_ERASER \
  136. (!MAIN.WacomDeviceEraser)
  137. void la_ScanWacomDevices(Display *display, int deviceid){
  138. XIDeviceInfo *info, *dev;
  139. int ndevices;
  140. int i; char * word;
  141. int _event, _error;
  142. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  143. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  144. }
  145. info = XIQueryDevice(display, deviceid, &ndevices);
  146. for(i = 0; i < ndevices; i++) {
  147. dev = &info[i]; strToLower(dev->name);
  148. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  149. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  150. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  151. word = strtok (dev->name," ");
  152. while (1) {
  153. word = strtok (NULL, " "); if (!word) break;
  154. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  155. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  156. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  157. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  158. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  159. }
  160. }
  161. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  162. logPrintNew("Found wacom devices:\n");
  163. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  164. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  165. }else{
  166. logPrintNew("No wacom pen device connected.\n");
  167. }
  168. XIFreeDeviceInfo(info);
  169. }
  170. void laHideCursor(){
  171. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  172. }
  173. void laShowCursor(){
  174. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  175. }
  176. void la_XErrorHandler(Display *display, XErrorEvent *event){
  177. char buf[512];
  178. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  179. printf("X Error:\n%s\n",buf);
  180. }
  181. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  182. XSetWindowAttributes swa;
  183. XWindowAttributes wa;
  184. swa.event_mask =
  185. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  186. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  187. swa.colormap = MAIN.cmap;
  188. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  189. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  190. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  191. if(x>0||y>0){
  192. XSizeHints my_hints = {0};
  193. my_hints.flags = PPosition;
  194. my_hints.x = x; my_hints.y = y;
  195. XSetNormalHints(MAIN.dpy, win, &my_hints);
  196. }
  197. XStoreName(MAIN.dpy, win, title);
  198. #ifdef LA_USE_GLES
  199. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  200. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  201. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  202. EGLSurface* surf=egl_surf;
  203. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  204. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  205. tnsContextMakeCurrent((*r_glc),win,(*surf));
  206. #else
  207. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  208. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  209. printf("\n\tcannot create gl context\n\n"); exit(0);
  210. }
  211. tnsContextMakeCurrent((*r_glc),win,0);
  212. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  213. #endif
  214. XSetLocaleModifiers("");
  215. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  216. if(!MAIN.im){
  217. XSetLocaleModifiers("@im=local");
  218. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  219. }
  220. if(!MAIN.im){
  221. XSetLocaleModifiers("@im=none");
  222. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  223. }
  224. if(!MAIN.im){
  225. XSetLocaleModifiers("@im=");
  226. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  227. }
  228. if(!MAIN.im){
  229. logPrint("Can't open a input method.\n");
  230. }
  231. if(MAIN.im){
  232. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  233. XSetICFocus(MAIN.ic);
  234. }
  235. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  236. XSetClassHint(MAIN.dpy, win, &ch);
  237. #define _NET_WM_STATE_ADD 1
  238. if(w<0&&h<0){
  239. XEvent xev;
  240. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  241. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  242. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  243. memset(&xev, 0, sizeof(xev));
  244. xev.type = ClientMessage;
  245. xev.xclient.window = win;
  246. xev.xclient.message_type = wm_state;
  247. xev.xclient.format = 32;
  248. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  249. xev.xclient.data.l[1] = max_horz;
  250. xev.xclient.data.l[2] = max_vert;
  251. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  252. }
  253. return win;
  254. };
  255. void la_DestroySystemWindowX11(laWindow* w) {
  256. tnsContextMakeCurrent(0,0,0);
  257. tnsDeleteContext(w->glc);
  258. #ifdef LA_USE_GLES
  259. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  260. #endif
  261. XDestroyWindow(MAIN.dpy, w->win);
  262. };
  263. #endif //linux
  264. #ifdef _WIN32
  265. #include <msgdef.h>
  266. #include <wintab.h>
  267. #include <wintab_utils.h>
  268. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  269. #define PACKETMODE PK_BUTTONS
  270. #include <pktdef.h>
  271. void la_OpenWacomWinTab(HWND hwnd){
  272. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  273. static LOGCONTEXT glogContext = { 0 };
  274. HCTX hctx = NULL;
  275. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  276. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  277. glogContext.lcOptions |= CXO_SYSTEM;
  278. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  279. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  280. assert(glogContext.lcOptions & CXO_SYSTEM);
  281. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  282. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  283. glogContext.lcPktData = PACKETDATA;
  284. glogContext.lcPktMode = PACKETMODE;
  285. glogContext.lcMoveMask = PACKETDATA;
  286. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  290. assert(wWTInfoRetVal == sizeof(AXIS));
  291. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  292. if (wWTInfoRetVal) {
  293. assert(wWTInfoRetVal == sizeof(AXIS));
  294. MAIN.WinTabMaxHover = TabletZ.axMax;
  295. }
  296. AXIS tabletPressure = { 0 };
  297. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  298. //glogContext.lcInOrgX = 0;
  299. //glogContext.lcInOrgY = 0;
  300. //glogContext.lcInExtX = TabletX.axMax;
  301. //glogContext.lcInExtY = TabletY.axMax;
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  310. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  311. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  312. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  313. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  314. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  315. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  316. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  317. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  318. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  319. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  320. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  321. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  322. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  323. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  324. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  325. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  326. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  327. if (!hctx)return;
  328. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  329. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  330. }
  331. void laHideCursor() {
  332. if (!MAIN.CurrentWindow) return; //impl
  333. }
  334. void laShowCursor() {
  335. if (!MAIN.CurrentWindow) return; //impl
  336. }
  337. static PIXELFORMATDESCRIPTOR cpfd = {
  338. sizeof(PIXELFORMATDESCRIPTOR),1,
  339. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  340. PFD_TYPE_RGBA,
  341. 8,
  342. 0, 0, 0, 0, 0, 0,
  343. 0, 0, 0,
  344. 0, 0, 0, 0,
  345. 32,
  346. 8, 0,
  347. 0,
  348. 0, 0, 0, 0
  349. };
  350. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  351. int nBestMS = 0;
  352. int i;
  353. int iResults[9];
  354. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  355. WGL_ACCELERATION_ARB, // 1
  356. WGL_DRAW_TO_WINDOW_ARB, // 2
  357. WGL_DOUBLE_BUFFER_ARB, // 3
  358. WGL_PIXEL_TYPE_ARB, // 4
  359. WGL_DEPTH_BITS_ARB, // 5
  360. WGL_STENCIL_BITS_ARB, // 6
  361. WGL_SAMPLE_BUFFERS_ARB, // 7
  362. WGL_SAMPLES_ARB }; // 8
  363. // How many pixelformats are there?
  364. int nFormatCount[] = { 0 };
  365. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  366. if (!wglGetPixelFormatAttribivARB)
  367. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  368. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  369. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  370. for (i = 0; i < nFormatCount[0]; i++){
  371. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  372. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  373. if (iResults[3] == 1) // Double buffered
  374. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  375. if (iResults[5] >= 24) // Any Depth greater than 16
  376. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  377. }
  378. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  379. };
  380. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  381. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  382. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  383. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  384. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  385. 0 };
  386. HGLRC hglrc = 0;
  387. HDC hdc = 0;
  388. int a, b;
  389. hdc = GetDC(hwnd);
  390. la_SetupPxlFormat(hdc, &a, &b);
  391. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  392. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  393. tnsContextMakeCurrent(hglrc, hdc,0);
  394. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  395. wglSwapIntervalEXT(-1);
  396. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  397. };
  398. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  399. HINSTANCE* inst = &MAIN.hinstance;
  400. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  401. x, y, w, h, 0, 0, *inst, 0);
  402. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  403. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  404. return hwnd;
  405. };
  406. void la_DestroySystemWindowWin32(laWindow* w) {
  407. tnsContextMakeCurrent(0,0,0);
  408. tnsDeleteContext(w->glc);
  409. ReleaseDC(w->win, w->hdc);
  410. DestroyWindow(w->win);
  411. };
  412. #endif
  413. #ifdef LAGUI_ANDROID
  414. SYSWINDOW la_CreateWindowAndroid(){
  415. return 0;
  416. };
  417. void laShowCursor(){}
  418. void laHideCursor(){}
  419. #endif
  420. #ifdef LA_LINUX
  421. void la_HandlerSIGSEGV(int sig) {
  422. void *array[30];
  423. size_t sz;
  424. sz = backtrace(array, 30);
  425. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  426. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  427. exit(1);
  428. }
  429. #endif
  430. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  431. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  432. //#ifndef LAGUI_ANDROID
  433. // ignore non-significant error/warning codes
  434. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  435. logPrint("GL %d: %s\n", id, message);
  436. char* strsource="",*strtype="",*strseverity="";
  437. switch (source) {
  438. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  439. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  440. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  441. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  442. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  443. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  444. }
  445. switch (type) {
  446. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  447. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  448. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  449. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  450. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  451. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  452. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  453. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  454. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  455. }
  456. switch (severity) {
  457. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  458. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  459. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  460. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  461. }
  462. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  463. //#endif
  464. }
  465. void la_SetCurrentGLContextDebug(){
  466. //#ifndef LAGUI_ANDROID
  467. int force=MAIN.InitArgs.GLDebug;
  468. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  469. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  470. glDebugMessageCallback(la_glDebugOutput, 0);
  471. int sev=GL_DONT_CARE;
  472. if(!force){
  473. switch(MAIN.GLDebugLevel){
  474. default: sev=GL_DONT_CARE; break;
  475. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  476. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  477. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  478. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  479. }
  480. }
  481. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  482. //#endif
  483. }
  484. void la_NotifyGLDebugChanges(){
  485. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  486. }
  487. void la_SetupWindowGLStates(laWindow* w){
  488. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  489. if(w->GLDebugNeedsUpdate){
  490. tnsContextMakeWindowCurrent(w);
  491. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  492. }
  493. }
  494. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  495. SYSGLCONTEXT glc;
  496. #ifdef LA_LINUX
  497. void* egl_surf=0;
  498. #ifdef LA_USE_GLES
  499. egl_surf=&window->egl_surf;
  500. #endif
  501. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  502. #endif
  503. #ifdef _WIN32
  504. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  505. #endif
  506. #ifdef LAGUI_ANDROID
  507. la_CreateWindowAndroid();
  508. window->win = 1;
  509. window->glc = MAIN.glc;
  510. #else
  511. window->win = hwnd;
  512. window->glc = glc;
  513. #endif
  514. #ifdef _WIN32
  515. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  516. RECT rc; GetClientRect(window->win, &rc);
  517. window->CW = rc.right - rc.left;
  518. window->CH = rc.bottom - rc.top;
  519. #endif
  520. #ifdef LA_LINUX
  521. XWindowAttributes attr;
  522. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  523. window->CW =attr.width;
  524. window->CH = attr.height;
  525. #endif
  526. la_SetCurrentGLContextDebug();
  527. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  528. la_SetupWindowGLStates(window);
  529. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  530. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  531. #else
  532. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  533. #endif
  534. window->OutputShowStripes=1; window->Redraw=1;
  535. window->GLDebugNeedsUpdate=1;
  536. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  537. return 1;
  538. };
  539. int la_DestroySystemWindow(laWindow* wnd){
  540. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  541. nvgDeleteGLES3(wnd->nvg);
  542. #else
  543. nvgDeleteGL3(wnd->nvg);
  544. #endif
  545. #ifdef LA_LINUX
  546. la_DestroySystemWindowX11(wnd);
  547. #endif
  548. #ifdef _WIN32
  549. la_DestroySystemWindowWin32(wnd);
  550. #endif
  551. }
  552. void la_DestroyWindow(laWindow *wnd){
  553. laLayout *l; laPanel *p; if (!wnd) return;
  554. tnsSwitchToCurrentWindowContext(wnd);
  555. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  556. la_StopAllOperators();
  557. strSafeDestroy(&wnd->Title);
  558. //la_PrintUserList(wnd);
  559. //printf("----\n");
  560. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  561. while (l = lstPopItem(&wnd->Layouts)){
  562. laDestroyBlocksRecursive(l->FirstBlock);
  563. //la_PrintUserList(l);
  564. //printf("%x %s\n", l, l->ID->Ptr);
  565. strSafeDestroy(&l->ID);
  566. memFree(l);
  567. //la_PrintUserList(wnd);
  568. //printf("----\n");
  569. }
  570. //printf("----\n%x\n",wnd);
  571. //la_PrintUserList(wnd);
  572. la_DestroySystemWindow(wnd);
  573. lstRemoveItem(&MAIN.Windows, wnd);
  574. memFree(wnd);
  575. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  576. }
  577. void laRenameWindow(laWindow* wnd, char* name){
  578. if((!wnd)||MAIN.IsReadingUDF) return;
  579. strSafeSet(&wnd->Title, name);
  580. if(!wnd->win) return;
  581. #ifdef LA_LINUX
  582. XStoreName(MAIN.dpy, wnd->win, name);
  583. #endif
  584. #ifdef _WIN32
  585. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  586. SetWindowTextW(wnd->win, name);
  587. #endif
  588. }
  589. #ifdef LA_LINUX
  590. const char* la_ConvertCursorID(int id){
  591. switch (id) {
  592. case LA_ARROW: return "arrow";
  593. case LA_CROSS: return "cross";
  594. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  595. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  596. case LA_MOVE: return "diamond_cross";
  597. case LA_HAND: return "hand1";
  598. case LA_CORNER: return "bottom_right_corner";
  599. }
  600. return "arrow";
  601. }
  602. #endif
  603. #ifdef _WIN32
  604. HCURSOR la_ConvertCursorID(int id){
  605. switch (id){
  606. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  607. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  608. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  609. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  610. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  611. case LA_HAND: return LoadCursor(0, IDC_HAND);
  612. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  613. }
  614. return LoadCursor(0, IDC_ARROW);;
  615. }
  616. #endif
  617. void la_InitThreadEnviornment(){
  618. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  619. }
  620. laLogEntry* logEnsure(int Create){
  621. if(!MAIN.Logs.pFirst || Create){
  622. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  623. lstAppendItem(&MAIN.Logs, le);
  624. }
  625. return MAIN.Logs.pLast;
  626. }
  627. void logPrintTV(int Continued, char* format, va_list v){
  628. if(!format || !format[0]) return;
  629. laLogEntry* le=logEnsure(Continued);
  630. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  631. strSafePrintV(&le->Content, format, v);
  632. #ifdef LAGUI_ANDROID
  633. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  634. #endif
  635. laNotifyUsers("la.logs");
  636. }
  637. void logPrintT(int Continued, char* format, ...){
  638. if(!format || !format[0]) return;
  639. laLogEntry* le=logEnsure(Continued);
  640. va_list aptr; va_start(aptr, format);
  641. strSafePrint(&le->Content, format, aptr);
  642. va_end(aptr);
  643. #ifdef LAGUI_ANDROID
  644. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  645. #endif
  646. laNotifyUsers("la.logs");
  647. }
  648. void logPrint(char* format, ...){
  649. va_list aptr; va_start(aptr, format);
  650. logPrintTV(0, format, aptr);
  651. va_end(aptr);
  652. }
  653. void logPrintNew(char* format, ...){
  654. logEnsure(1);
  655. va_list aptr; va_start(aptr, format);
  656. logPrintTV(0, format, aptr);
  657. va_end(aptr);
  658. }
  659. void logClear(){
  660. laLogEntry*l;
  661. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  662. laNotifyUsers("la.logs");
  663. }
  664. laSafeString** la_PerfEnsure(){
  665. MAIN.NextPerfCounter++;
  666. if(MAIN.NextPerfCounter>=32){ MAIN.NextPerfCounter=0; }
  667. return &MAIN.PerfLogs[MAIN.NextPerfCounter];
  668. }
  669. void la_PerfClear(){
  670. if(!MAIN.ShowPerf){ return; }
  671. MAIN.NextPerfCounter=0; MAIN.NextPerfGroup++; if(MAIN.NextPerfGroup>=32){ MAIN.NextPerfGroup=0; }
  672. memset(&MAIN.PerfCounter[MAIN.NextPerfGroup],0,32*sizeof(real));
  673. for(int i=0;i<32;i++){ strSafeDestroy(&MAIN.PerfLogs[i]); }
  674. }
  675. void laPerfRecordV(char* format, va_list v){
  676. if(!format || !format[0]) return;
  677. laSafeString** ss=la_PerfEnsure();
  678. strSafePrintV(ss, format, v);
  679. laTimeRecorder tm; laRecordTime(&tm);
  680. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  681. }
  682. void laPerfRecord(char* format, ...){
  683. if(!format || !format[0]) return;
  684. laSafeString** ss=la_PerfEnsure();
  685. va_list aptr; va_start(aptr, format);
  686. strSafePrintV(ss, format, aptr);
  687. va_end(aptr);
  688. laTimeRecorder tm; laRecordTime(&tm);
  689. MAIN.PerfCounter[MAIN.NextPerfGroup][MAIN.NextPerfCounter] = laTimeElapsedSecondsf(&tm, &MAIN.FrameStartTime);
  690. }
  691. void la_PerfDraw(){
  692. tnsScale3d(0.75,0.75,0.75);
  693. int sy=0; laBoxedTheme* bt=_LA_THEME_LABEL; real* color=laThemeColor(bt,LA_BT_TEXT);
  694. int sl=LA_RH*4; char buf[16]; real totval=0; real vals[32];
  695. for(int i=0;i<32;i++){
  696. if(MAIN.PerfLogs[i]){
  697. real value = MAIN.PerfCounter[MAIN.NextPerfGroup][i]-(i>0?MAIN.PerfCounter[MAIN.NextPerfGroup][i-1]:0);
  698. sprintf(buf,"%0.2lf",value*1000); totval+=value; vals[i]=value;
  699. tnsDrawStringAuto(buf,color,0,10000,sy,LA_TEXT_SHADOW);
  700. tnsDrawStringAuto(SSTR(MAIN.PerfLogs[i]),color,sl,10000,sy,LA_TEXT_SHADOW);
  701. sy+=LA_RH;
  702. }
  703. }
  704. real SL=LA_RH*2,SR=LA_RH*3.5; sy=0; tnsColor4dv(color); tnsUseNoTexture();
  705. for(int i=0;i<32;i++){
  706. if(MAIN.PerfLogs[i]){
  707. real r=vals[i]/totval; real use_r=tnsInterpolate(SL,SR,r);
  708. tnsVertex2d(SL,sy); tnsVertex2d(SL,sy+LA_RH); tnsVertex2d(use_r,sy+LA_RH); tnsVertex2d(use_r,sy);
  709. tnsPackAs(GL_TRIANGLE_FAN);
  710. sy+=LA_RH;
  711. }
  712. }
  713. tnsFlush();
  714. }
  715. 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;
  716. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  717. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  718. }
  719. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  720. strSafeSet(&s->Name,Name);
  721. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  722. s->x=x;s->y=y;s->w=w;s->h=h;
  723. laNotifyUsers("la.user_preferences.screens");
  724. return s;
  725. }
  726. void la_RemoveScreen(laScreen*s){
  727. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  728. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  729. }
  730. void la_RemoveDuplicatedScreenConf(){
  731. laScreen* NextS;
  732. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  733. NextS = s->Item.pNext;
  734. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  735. 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; }
  736. }
  737. }
  738. }
  739. laScreen* laGetWindowScreen(laWindow* w){
  740. int l,r,u,b; int area=-1; laScreen* maxs=0;
  741. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  742. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  743. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  744. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  745. int a=w*h; if(a>area){ maxs = s; area = a; }
  746. }
  747. return maxs;
  748. }
  749. #ifdef LA_LINUX
  750. int la_GetDPI(Window* root_win){
  751. XRRScreenResources *screen;
  752. XRROutputInfo *info;
  753. XRRCrtcInfo *crtc_info;
  754. XRRCrtcInfo *crtc;
  755. int iscres, icrtc, dpi=0;
  756. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  757. for(iscres=0;iscres<screen->noutput;iscres++){
  758. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  759. if(!info->mm_width || !info->mm_height){ continue; }
  760. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  761. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  762. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  763. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  764. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  765. XRRFreeCrtcInfo(crtc);
  766. //if(info->connection==RR_Connected){
  767. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  768. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  769. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  770. // XRRFreeCrtcInfo(crtc_info);
  771. // }
  772. //}
  773. XRRFreeOutputInfo(info);
  774. }
  775. XRRFreeScreenResources(screen);
  776. return dpi;
  777. }
  778. #endif
  779. #ifdef _WIN32
  780. typedef struct laWin32MonitorEnumData {
  781. int id;
  782. }laWin32MonitorEnumData;
  783. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  784. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  785. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  786. return TRUE;
  787. }
  788. int la_GetDPI(HWND win){
  789. laWin32MonitorEnumData data = { 0 };
  790. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  791. return GetDpiForWindow(win);
  792. return 144;
  793. }
  794. #endif
  795. #define PROGRESSW (LA_RH*15)
  796. void laShowProgress(real p1, real p2){
  797. laSpinLock(&MAIN.OpsLock);
  798. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  799. if(!MAIN.Progress.Called){
  800. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  801. }
  802. laTimeRecorder tm; laRecordTime(&tm);
  803. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  804. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  805. if((!MAIN.Progress.Shown) && MAIN.Progress.Called){
  806. int ww=PROGRESSW+LA_RH*2;
  807. #ifdef LA_LINUX
  808. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  809. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  810. long a=LA_COLOR3_TO_HEX(bg);
  811. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  812. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  813. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  814. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  815. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  816. #endif
  817. #ifdef _WIN32
  818. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  819. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  820. ShowWindow(MAIN.Progress.w,SW_SHOW);
  821. #endif
  822. MAIN.Progress.Shown = 1;
  823. }
  824. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  825. #ifdef LA_LINUX
  826. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  827. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  828. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  829. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  830. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  831. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  832. #endif
  833. #ifdef _WIN32
  834. InvalidateRect(MAIN.Progress.w,0,1);
  835. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  836. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  837. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  838. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  839. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  840. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  841. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  842. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  843. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  844. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  845. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  846. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  847. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  848. EndPaint(MAIN.Progress.w,&ps);
  849. MSG msg;
  850. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  851. #endif
  852. #ifdef LAGUI_ANDROID
  853. laWindow* window=MAIN.CurrentWindow; int pw=window->CW;
  854. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  855. tnsViewportWithScissor(0,0,window->CW,window->CH);
  856. tnsOrtho(0,window->CW,-window->CH+LA_2RH,LA_2RH,-100,100);
  857. tnsClearColorv(bg); tnsClearAll(); tnsUseNoTexture(); tnsColor4dv(fg);
  858. tnsVertex2d(0,0);tnsVertex2d(pw*MAIN.Progress.p2,0);tnsVertex2d(pw*MAIN.Progress.p2,LA_RH);tnsVertex2d(0,LA_RH);
  859. tnsPackAs(GL_TRIANGLE_FAN);
  860. tnsVertex2d(0,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_RH);tnsVertex2d(pw*MAIN.Progress.p1,LA_2RH);tnsVertex2d(0,LA_2RH);
  861. tnsPackAs(GL_TRIANGLE_FAN);
  862. tnsFlush();
  863. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  864. eglMakeCurrent(MAIN.egl_dpy,0,0,0);
  865. #endif
  866. laSpinUnlock(&MAIN.OpsLock);
  867. }
  868. void laHideProgress(){
  869. laSpinLock(&MAIN.OpsLock);
  870. if(!MAIN.Progress.Shown){
  871. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  872. }
  873. laTimeRecorder tm; laRecordTime(&tm);
  874. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  875. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  876. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  877. #ifdef LA_LINUX
  878. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  879. #endif
  880. #ifdef _WIN32
  881. ShowWindow(MAIN.Progress.w,SW_HIDE);
  882. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  883. #endif
  884. #ifdef LAGUI_ANDROID
  885. laRedrawAllWindows();
  886. #endif
  887. laSpinUnlock(&MAIN.OpsLock);
  888. }
  889. //=======================
  890. void la_InitProgressWindow(){
  891. #ifdef LA_LINUX
  892. 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));
  893. if(!MAIN.Progress.w) return;
  894. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  895. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  896. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  897. if(MAIN.Progress.gc<0) return;
  898. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  899. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  900. XSync(MAIN.dpy,0);
  901. #endif
  902. #ifdef _WIN32
  903. WNDCLASSW wc;
  904. wc.hInstance = MAIN.hinstance;
  905. wc.lpfnWndProc = LA_ProgressWindowProc;
  906. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  907. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  908. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  909. wc.cbWndExtra = 0;
  910. wc.cbClsExtra = 0;
  911. wc.lpszClassName = L"_LAGUIPROGRESS";
  912. wc.lpszMenuName = NULL;
  913. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  914. if (!RegisterClassW(&wc)){ return; }
  915. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  916. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  917. #endif
  918. }
  919. void laSetFontFolderPath(char* absolute){
  920. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  921. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  922. }
  923. void laSetDefaultInitArguments(laInitArguments* ia){
  924. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  925. ia->UseColorManagement=0;
  926. ia->HasWorldObjects=0;
  927. ia->HasAction=0;
  928. ia->HasTextureInspector=0;
  929. ia->HasHistories=0;
  930. ia->HasTerminal=1;
  931. ia->HasAudio=0;
  932. }
  933. void laSetCompleteInitArguments(laInitArguments* ia){
  934. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  935. ia->UseColorManagement=1;
  936. ia->HasWorldObjects=1;
  937. ia->HasAction=1;
  938. ia->HasTextureInspector=1;
  939. ia->HasHistories=1;
  940. ia->HasTerminal=1;
  941. ia->HasAudio=1;
  942. }
  943. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  944. MAIN.GLMajor=MAIN.GLMinor=-1;
  945. char* arg = 0;
  946. printf("Initializing LaGUI...\n",argc);
  947. for(int i=0;i<argc;i++){
  948. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  949. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  950. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  951. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  952. }
  953. continue;
  954. }
  955. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  956. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  957. }
  958. }
  959. int laGetReadyWith(laInitArguments* ia){
  960. #ifdef LA_LINUX
  961. //signal(SIGSEGV,la_HandlerSIGSEGV);
  962. #endif
  963. laSpinInit(&MAIN.MemLock);
  964. laSpinInit(&MAIN.OpsLock);
  965. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  966. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  967. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  968. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  969. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  970. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  971. tnsInit();
  972. #ifdef LA_LINUX
  973. SYSWINDOW root, win;
  974. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  975. XSetWindowAttributes swa={0};
  976. XWindowAttributes wa={0};
  977. XEvent xev;
  978. logPrintNew("Initializing LaGUI...\n");
  979. setlocale(LC_CTYPE, "zh_CN.utf8");
  980. XSetErrorHandler(la_XErrorHandler);
  981. int i;
  982. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  983. printf("\n\tcannot connect to x server\n\n");
  984. exit(0);
  985. }
  986. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  987. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  988. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  989. #ifdef LA_USE_GLES
  990. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  991. #else
  992. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  993. #endif
  994. #ifdef LA_USE_GLES
  995. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  996. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  997. EGLint egl_major, egl_minor;
  998. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  999. printf("Error: eglInitialize() failed\n"); return -1;
  1000. }
  1001. int scrnum;
  1002. XSetWindowAttributes attr;
  1003. XVisualInfo *visInfo, visTemplate;
  1004. int num_visuals;
  1005. EGLContext ctx;
  1006. EGLint num_configs;
  1007. EGLint vid;
  1008. static const EGLint attribs[] = {
  1009. EGL_RED_SIZE, 8,
  1010. EGL_GREEN_SIZE, 8,
  1011. EGL_BLUE_SIZE, 8,
  1012. EGL_DEPTH_SIZE, 1,
  1013. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  1014. EGL_NONE
  1015. };
  1016. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  1017. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  1018. }
  1019. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  1020. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  1021. }
  1022. visTemplate.visualid = vid;
  1023. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  1024. if (!visInfo) {
  1025. printf("Error: couldn't get X visual\n"); exit(1);
  1026. }
  1027. MAIN.xvi=visInfo;
  1028. root = DefaultRootWindow(MAIN.dpy);
  1029. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1030. printf("\n\tcannot create colormap\n\n"); exit(1);
  1031. }
  1032. eglBindAPI(EGL_OPENGL_ES_API);
  1033. EGLint ctx_attribs[] = {
  1034. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  1035. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  1036. EGL_NONE
  1037. };
  1038. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  1039. if (!MAIN.glc) {
  1040. printf("Error: eglCreateContext failed\n"); exit(1);
  1041. }
  1042. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  1043. #else
  1044. int visual_attribs[] = {
  1045. GLX_X_RENDERABLE , True,
  1046. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  1047. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  1048. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  1049. GLX_RED_SIZE , 8,
  1050. GLX_GREEN_SIZE , 8,
  1051. GLX_BLUE_SIZE , 8,
  1052. GLX_ALPHA_SIZE , 8,
  1053. GLX_DEPTH_SIZE , 24,
  1054. //GLX_STENCIL_SIZE , 8,
  1055. GLX_DOUBLEBUFFER , True,
  1056. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  1057. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  1058. None
  1059. };
  1060. int fbcount = -1;
  1061. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  1062. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  1063. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  1064. MAIN.BestFBC = fbconfig[0];
  1065. int sample_buf,samples;
  1066. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  1067. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  1068. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  1069. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  1070. free(fbconfig);
  1071. root = DefaultRootWindow(MAIN.dpy);
  1072. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1073. printf("\n\tcannot create colormap\n\n"); exit(0);
  1074. }
  1075. swa.colormap = MAIN.cmap;
  1076. root = DefaultRootWindow(MAIN.dpy);
  1077. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1078. MAIN.win=win;
  1079. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1080. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1081. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1082. printf("\n\tcannot create gl context\n\n"); exit(0);
  1083. }
  1084. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1085. tnsContextMakeCurrent(MAIN.glc,win,0);
  1086. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1087. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1088. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1089. int err=0;
  1090. if((err=glewInit())!=GLEW_OK){
  1091. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1092. };
  1093. #endif /* gles or glx */
  1094. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1095. la_SetCurrentGLContextDebug();
  1096. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1097. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1098. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1099. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1100. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1101. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1102. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1103. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1104. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1105. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1106. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1107. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1108. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1109. #endif //linux
  1110. #ifdef _WIN32
  1111. logPrintNew("Initializing LaGUI...\n");
  1112. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1113. setlocale(LC_ALL, "zh_CN.utf8");
  1114. MAIN.hinstance = GetModuleHandle(NULL);
  1115. HINSTANCE* hInst = &MAIN.hinstance;
  1116. WNDCLASSEXW wt;
  1117. wt.cbSize = sizeof(WNDCLASSEXW);
  1118. wt.cbClsExtra = 0;
  1119. wt.cbWndExtra = 0;
  1120. wt.hbrBackground = 0;
  1121. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1122. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1123. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1124. wt.hInstance = *hInst;
  1125. wt.lpfnWndProc = LA_WindowProc;
  1126. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1127. wt.lpszMenuName = 0;
  1128. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1129. if (!RegisterClassExW(&wt)) return 0;
  1130. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1131. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1132. SetProcessDPIAware();
  1133. GLenum err;
  1134. PIXELFORMATDESCRIPTOR pfd;
  1135. HINSTANCE* hinst = &MAIN.hinstance;
  1136. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1137. "Temp Window For Accessing GLEW!",
  1138. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1139. 0, 0, *hinst, 0);
  1140. HDC hdc = GetDC(hwnd);
  1141. HGLRC hglrc = 0;
  1142. SetPixelFormat(hdc, 1, &cpfd);
  1143. hglrc = wglCreateContext(hdc);
  1144. tnsContextMakeCurrent(hglrc, hdc,0);
  1145. //MAIN.hdc = hdc;
  1146. // MAIN.tWND = hwnd;
  1147. MAIN.glc = hglrc;
  1148. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1149. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1150. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1151. if (err = glewInit()) {
  1152. printf("Init Glew Failed\n");
  1153. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1154. return 0;
  1155. }
  1156. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1157. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1158. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1159. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1160. #endif
  1161. la_GetWorkingDirectoryInternal();
  1162. MAIN.SavePreferenceOnExit=1;
  1163. MAIN.FontSize = 0.6;
  1164. int dpi=64;
  1165. #ifdef _WIN32
  1166. dpi=la_GetDPI(hwnd);
  1167. #endif
  1168. #ifdef LA_LINUX
  1169. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1170. #endif
  1171. #ifdef LAGUI_ANDROID
  1172. dpi = 72;
  1173. #endif
  1174. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1175. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1176. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1177. MAIN.UiScale=1;
  1178. MAIN.MarginSize = 1;
  1179. MAIN.ColorPickerGamma=1.5;
  1180. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1181. MAIN.ViewportHalftoneFactor=0.5;
  1182. MAIN.ViewportHalftoneSize=3.7;
  1183. tnsInitRenderKernel(64);
  1184. tnsInitBuiltinShaders();
  1185. tnsSetuptnsFontManager();
  1186. #define LOAD_FONT(font) \
  1187. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1188. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1189. LOAD_FONT("NotoEmoji-Regular.ttf");
  1190. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1191. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1192. //LOAD_FONT("NotoMusic-Regular.ttf");
  1193. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1194. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1195. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1196. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1197. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1198. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1199. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1200. MAIN.Audio=memAcquire(sizeof(laAudio));
  1201. #ifdef LA_WITH_LUAJIT
  1202. // starting lua
  1203. logPrint("Starting luajit...\n");
  1204. MAIN.L = lua_open();
  1205. la_luaLoadLibs(MAIN.L);
  1206. la_luaPrintStatus(MAIN.L);
  1207. tnsLuaInit(MAIN.L);
  1208. #endif
  1209. //interactions:
  1210. MAIN.TopFramerate = 60;
  1211. MAIN.ValuatorThreshold = 8;
  1212. MAIN.ScrollingSpeed = 3;
  1213. MAIN.AnimationSpeed = 0.4;
  1214. MAIN.PanelAnimationSpeed = 0.4;
  1215. MAIN.ZoomSpeed2D = 0.01;
  1216. MAIN.IdleTime = 0.75;
  1217. MAIN.TooltipCloseDistance = 30;
  1218. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1219. //display:
  1220. MAIN.FloatingAlpha = 0.35;
  1221. MAIN.SolidShadowLength = 20;
  1222. MAIN.WireColorSlices = 16;
  1223. MAIN.WireThickness = 5;
  1224. MAIN.WireSaggyness = 0.5;
  1225. MAIN.ManagerFilterInstances = 1;
  1226. #ifdef LAGUI_ANDROID
  1227. laAddResourceFolder("");
  1228. #else
  1229. laAddResourceFolder(".");
  1230. #endif
  1231. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1232. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1233. la_InitProgressWindow();
  1234. la_MakeTranslations_es_ES();
  1235. la_MakeTranslations_zh_hans();
  1236. //tns_RegisterResourcesForSoftwareRender();
  1237. la_RegisterDefaultSignals();
  1238. la_RegisterGeneralProps();
  1239. la_RegisterBuiltinTemplates();
  1240. la_RegisterMainThemes();
  1241. la_RegisterMainOperators();
  1242. la_RegisterMainUiTypes();
  1243. la_RegisterInternalProps();
  1244. la_RegisterAnimationResources();
  1245. la_RegisterWindowKeys();
  1246. if(MAIN.InitArgs.HasWorldObjects){
  1247. la_RegisterModellingOperators();
  1248. la_RegisterShapeOperators();
  1249. }
  1250. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1251. laFinalizeUiTemplates();
  1252. laFinalizeOperators();
  1253. la_RegisterControllerProps();
  1254. la_RefreshControllers();
  1255. la_RegisterBasicNodes();
  1256. tns_RegisterNodes();
  1257. la_InitThreadEnviornment();
  1258. laSetRootInstance(&MAIN);
  1259. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1260. laPushDifferences(0, 0);
  1261. la_MakeDummyManagedUDF();
  1262. la_RegenerateWireColors();
  1263. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1264. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1265. laSetProofingLut(DATA_LUT_PROOF_SRGB, 0);
  1266. laSetProofingLut(DATA_LUT_PROOF_CLAY, 1);
  1267. laSetProofingLut(DATA_LUT_PROOF_D65P3, 2);
  1268. logPrintNew("Initialization Completed\n");
  1269. MAIN.InitDone=1;
  1270. #ifdef LAGUI_ANDROID
  1271. MAIN.AutoSwitchColorSpace = 0;
  1272. MAIN.GotFilePermission = la_check_permission("android.permission.WRITE_EXTERNAL_STORAGE");
  1273. #else
  1274. MAIN.AutoSwitchColorSpace = 1;
  1275. #endif
  1276. return 1;
  1277. }
  1278. int laGetReady(){
  1279. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1280. return laGetReadyWith(&ia);
  1281. }
  1282. void la_DestroyUiType(laUiType* uit);
  1283. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1284. void laShutoff(int SavePrefereces){
  1285. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1286. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1287. // transLate(pc->Description);
  1288. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1289. // transLate(p->Description);
  1290. // }
  1291. //}
  1292. transDumpMissMatchRecord("TranslationDump.txt");
  1293. if(MAIN.Cleanup) MAIN.Cleanup();
  1294. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1295. strSafeDestroy(&MAIN.WorkingDirectory);
  1296. strSafeDestroy(&MAIN.example_string);
  1297. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1298. // (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. )
  1299. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1300. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1301. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1302. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1303. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1304. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1305. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1306. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1307. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1308. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1309. strSafeDestroy(&MAIN.CopyPending);
  1310. la_ClearUDFRegistryAndFolders();
  1311. laClearManagedUDF();
  1312. laClearSaveProp();
  1313. logClear();
  1314. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1315. #ifdef LA_LINUX
  1316. tnsContextMakeCurrent(0,0,0);
  1317. tnsDeleteContext(MAIN.glc);
  1318. #ifdef LA_USE_GLES
  1319. eglTerminate(MAIN.egl_dpy);
  1320. #endif
  1321. #endif
  1322. #ifdef _WIN32
  1323. tnsContextMakeCurrent(0,0,0);
  1324. tnsDeleteContext(MAIN.glc);
  1325. UnloadWintab();
  1326. #endif
  1327. tnsQuit();
  1328. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1329. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1330. strSafeDump();
  1331. hshFree(&MAIN.DBInstMemLeft);
  1332. memNoLonger();
  1333. laSpinDestroy(&MAIN.MemLock);
  1334. laSpinDestroy(&MAIN.OpsLock);
  1335. #ifdef LA_WITH_LUAJIT
  1336. lua_close(MAIN.L);
  1337. #endif
  1338. printf("LaGUI has cleaned up.\n");
  1339. }
  1340. int laRestoreFactorySettings(){
  1341. char path[1024];
  1342. #ifdef LAGUI_ANDROID
  1343. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1344. logPrintNew("%s", path);
  1345. if(!remove(path)){ return 1; }
  1346. sprintf(path,"%s/%s",MAIN.ExternalDataPath,"preferences.udf");
  1347. logPrintNew("%s", path);
  1348. if(!remove(path)){ return 1; }
  1349. return 0;
  1350. #else
  1351. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1352. #endif
  1353. if(remove(path)){ return 0; }
  1354. return 1;
  1355. }
  1356. void laSaveUserPreferences(){
  1357. char path[1024];
  1358. #ifdef LAGUI_ANDROID
  1359. sprintf(path,"%s","preferences.udf");
  1360. #else
  1361. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1362. #endif
  1363. laUDF* udf=laPrepareUDF(path);
  1364. laWriteProp(udf,"la.windows");
  1365. laWriteProp(udf,"la.user_preferences");
  1366. laWriteProp(udf,"la.input_mapping");
  1367. laWriteProp(udf,"la.controllers");
  1368. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1369. laWriteProp(udf,lip->p);
  1370. }
  1371. laPackUDF(udf,0,0);
  1372. }
  1373. void laEnsureUserPreferences(){
  1374. char path[1024];
  1375. #ifdef LAGUI_ANDROID
  1376. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1377. #else
  1378. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1379. #endif
  1380. laUDFRegistry* r=laFindUDFRegistry(path);
  1381. if(!r){ laSaveUserPreferences(); return; }
  1382. 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; }
  1383. laClearUDFRegistries();
  1384. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1385. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1386. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1387. laCloseUDF(udf);
  1388. la_RemoveDuplicatedScreenConf();
  1389. la_RemoveDuplicatedControllers();
  1390. laRefreshUDFRegistries();
  1391. //restore forced settings
  1392. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1393. }
  1394. void laAddExtraExtension(int FileType, ...){
  1395. va_list list; va_start(list,FileType);
  1396. char* ext;
  1397. while(ext=va_arg(list,char*)){ if(!ext) break;
  1398. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1399. et->FileType=FileType; et->Extension=ext;
  1400. lstAppendItem(&MAIN.ExtraExtensions, et);
  1401. logPrintNew("add ext %s",ext);
  1402. }
  1403. va_end(list);
  1404. }
  1405. void laAddExtraPreferencePath(const char* path){
  1406. if(!path) return;
  1407. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1408. }
  1409. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1410. if(!name || !Func) return;
  1411. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1412. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1413. }
  1414. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1415. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1416. }
  1417. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1418. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1419. }
  1420. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1421. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1422. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1423. }
  1424. void la_InputMappingGetKeyName(int key, int special, char* name){
  1425. char *_next=name; name[0]=0;
  1426. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1427. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1428. if(special&LA_KEY_ALT){ strcat(name,"Alt+"); }
  1429. switch(key){
  1430. case ' ': strcat(name,"Space"); break;
  1431. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1432. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1433. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1434. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1435. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1436. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1437. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1438. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1439. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1440. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1441. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1442. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1443. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1444. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1445. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1446. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1447. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1448. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1449. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1450. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1451. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1452. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1453. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1454. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1455. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1456. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1457. case LA_KEY_F1: strcat(name,"F1"); break;
  1458. case LA_KEY_F2: strcat(name,"F2"); break;
  1459. case LA_KEY_F3: strcat(name,"F3"); break;
  1460. case LA_KEY_F4: strcat(name,"F4"); break;
  1461. case LA_KEY_F5: strcat(name,"F5"); break;
  1462. case LA_KEY_F6: strcat(name,"F6"); break;
  1463. case LA_KEY_F7: strcat(name,"F7"); break;
  1464. case LA_KEY_F8: strcat(name,"F8"); break;
  1465. case LA_KEY_F9: strcat(name,"F9"); break;
  1466. case LA_KEY_F10: strcat(name,"F10"); break;
  1467. case LA_KEY_F11: strcat(name,"F11"); break;
  1468. case LA_KEY_F12: strcat(name,"F12"); break;
  1469. case LA_KEY_MOUSE_LEFT: strcat(name,"Mouse1"); break;
  1470. case LA_KEY_MOUSE_MIDDLE: strcat(name,"Mouse2"); break;
  1471. case LA_KEY_MOUSE_RIGHT: strcat(name,"Mouse3"); break;
  1472. case LA_KEY_MOUSE_SCROLL|LA_STATE_UP: strcat(name,"MouseWheelUp"); break;
  1473. case LA_KEY_MOUSE_SCROLL|LA_STATE_DOWN: strcat(name,"MouseWheelDown"); break;
  1474. default:
  1475. name = name+strlen(name); _next=name;
  1476. laToUTF8(key,name,&_next); *_next=0; break;
  1477. }
  1478. }
  1479. int la_InputMappingGetKeyFromName(char* name, int* special){
  1480. if(!name ||name[0]==0){ *special=0; return 0; }
  1481. *special=0;
  1482. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1483. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1484. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1485. char* p=name+strlen(name)-1;
  1486. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1487. while(*p=='+' || *p==' '){ p++; }
  1488. if(strSame(p,"Space")) return ' ';
  1489. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1490. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1491. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1492. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1493. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1494. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1495. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1496. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1497. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1498. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1499. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1500. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1501. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1502. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1503. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1504. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1505. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1506. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1507. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1508. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1509. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1510. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1511. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1512. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1513. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1514. if(strSame(p,"F1")) return LA_KEY_F1;
  1515. if(strSame(p,"F2")) return LA_KEY_F2;
  1516. if(strSame(p,"F3")) return LA_KEY_F3;
  1517. if(strSame(p,"F4")) return LA_KEY_F4;
  1518. if(strSame(p,"F5")) return LA_KEY_F5;
  1519. if(strSame(p,"F6")) return LA_KEY_F6;
  1520. if(strSame(p,"F7")) return LA_KEY_F7;
  1521. if(strSame(p,"F8")) return LA_KEY_F8;
  1522. if(strSame(p,"F9")) return LA_KEY_F9;
  1523. if(strSame(p,"F10")) return LA_KEY_F10;
  1524. if(strSame(p,"F11")) return LA_KEY_F11;
  1525. if(strSame(p,"F12")) return LA_KEY_F12;
  1526. if(strSame(p,"Mouse1")) return LA_KEY_MOUSE_LEFT;
  1527. if(strSame(p,"Mouse2")) return LA_KEY_MOUSE_MIDDLE;
  1528. if(strSame(p,"Mouse3")) return LA_KEY_MOUSE_RIGHT;
  1529. if(strSame(p,"MouseWheelUp")) return LA_KEY_MOUSE_SCROLL|LA_STATE_UP;
  1530. if(strSame(p,"MouseWheelDown")) return LA_KEY_MOUSE_SCROLL|LA_STATE_DOWN;
  1531. int adv;
  1532. return laToUnicode(p,&adv);
  1533. }
  1534. laCustomSignal* laFindSignal(char* Name){
  1535. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1536. return 0;
  1537. }
  1538. laCustomSignal* laFindSignalByID(int ID){
  1539. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1540. return 0;
  1541. }
  1542. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1543. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD || ime->DeviceType==LA_INPUT_DEVICE_MOUSE){ char* str=SSTR(ime->Key);
  1544. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1545. }
  1546. elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1547. char* signal = SSTR(ime->Signal);
  1548. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1549. }
  1550. laInputMapping* laNewInputMapping(char* Name){
  1551. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1552. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1553. strSafeSet(&im->Name,Name);
  1554. return im;
  1555. }
  1556. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1557. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1558. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1559. memAssignRef(e,&e->Parent,im);
  1560. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1561. laInputMappingUpdateSignal(e);
  1562. e->SpecialKeyBits=SpecialKeyBit;
  1563. char buf[64],*_next=buf;
  1564. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1565. return e;
  1566. }
  1567. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1568. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1569. return laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1570. }
  1571. laInputMappingEntry* laNewInputMappingMouseEntryP(laInputMapping* im, int MouseEventType, int SpecialKeyBit, int Signal){
  1572. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1573. char* Key="Mouse2";
  1574. if(MouseEventType&LA_KEY_MOUSE_LEFT){ Key="Mouse1"; }
  1575. elif(MouseEventType&LA_KEY_MOUSE_MIDDLE){ Key="Mouse2"; }
  1576. elif(MouseEventType&LA_KEY_MOUSE_RIGHT){ Key="Mouse3"; }
  1577. elif((MouseEventType&LA_KEY_MOUSE_SCROLL) && (MouseEventType&LA_STATE_UP)){ Key="MouseWheelUp"; }
  1578. elif((MouseEventType&LA_KEY_MOUSE_SCROLL) && (MouseEventType&LA_STATE_DOWN)){ Key="MouseWheelDown"; }
  1579. return laNewInputMappingEntry(im,LA_INPUT_DEVICE_MOUSE,0,Key,SpecialKeyBit,SSTR(cs->Name));
  1580. }
  1581. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1582. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1583. }
  1584. void laRemoveInputMapping(laInputMapping* im){
  1585. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1586. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1587. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1588. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1589. }
  1590. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1591. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1592. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1593. return cs;
  1594. }
  1595. void laRemoveCustomSignal(laCustomSignal* cs){
  1596. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1597. }
  1598. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1599. void la_SendOperatorEvent(SYSWINDOW* hwnd, laOperatorType* at, int use_base, char* instructions);
  1600. void la_SendInputMappingSignalsAuto(SYSWINDOW* hwnd, laInputMappingEntry* ime){
  1601. if(ime->UseOperator){ la_SendOperatorEvent(hwnd, ime->OperatorType, ime->OperatorBase, SSTR(ime->OperatorArguments)); }
  1602. else{ la_SendSignalEvent(hwnd, ime->SignalValue); }
  1603. }
  1604. void la_SendSignalsFromEvent(laEvent* e){
  1605. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1606. if(!im){return;}
  1607. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1608. if(ime->Disabled) continue;
  1609. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1610. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1611. la_SendInputMappingSignalsAuto(e->window->win,ime);
  1612. }
  1613. }elif((e->type&LA_MOUSE_EVENT) && ime->DeviceType == LA_INPUT_DEVICE_MOUSE){
  1614. int matchkey; if(!(e->type&LA_KEY_MOUSE_SCROLL)){ matchkey = ((e->type&ime->KeyValue) && (e->type&LA_STATE_DOWN)); }
  1615. else{ matchkey = (e->type==(ime->KeyValue&LA_MOUSE_EVENT)); }
  1616. if(e->SpecialKeyBit == ime->SpecialKeyBits && matchkey){
  1617. la_SendInputMappingSignalsAuto(e->window->win,ime);
  1618. }
  1619. }
  1620. }
  1621. }
  1622. //MSG====================================================
  1623. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1624. if (wnd->win == hwnd) return 1;
  1625. else return 0;
  1626. };
  1627. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1628. if (p->SL){ int s=p->SL<0?0:p->SL;
  1629. if (p->TX != s) laRecalcPanel(p);
  1630. p->TX = s;
  1631. }
  1632. if (p->SR){ int s=p->SR<0?0:p->SR;
  1633. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1634. p->TW = CW - p->TX - s;
  1635. }
  1636. if (p->ST){ int s=p->ST<0?0:p->ST;
  1637. if (p->TY != s) laRecalcPanel(p);
  1638. p->TY = s;
  1639. }
  1640. if (p->SB){ int s=p->SB<0?0:p->SB;
  1641. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1642. p->TH = CH - p->TY - s;
  1643. }
  1644. }
  1645. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1646. laPanel *p = 0;
  1647. b->X = X;
  1648. b->Y = Y;
  1649. b->W = W;
  1650. b->H = H;
  1651. if (b->B1){
  1652. int SplitWidth;
  1653. if (b->Vertical){
  1654. SplitWidth = H * b->SplitRatio;
  1655. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1656. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1657. }else{
  1658. SplitWidth = W * b->SplitRatio;
  1659. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1660. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1661. }
  1662. }
  1663. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1664. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1665. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1666. }
  1667. if (p = b->CurrentPanel){
  1668. int TitleGap=b->Folded?0:LA_RH;
  1669. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1670. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1671. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1672. laRecalcPanel(p);
  1673. }
  1674. }
  1675. void la_UpdateUiPlacement(laWindow *w){
  1676. laLayout *l;
  1677. laPanel *p;
  1678. int CW = w->CW;
  1679. int CH = w->CH;
  1680. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1681. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1682. if(w->MaximizedUi && w->MaximizedUiPanel){
  1683. laRecalcPanel(w->MaximizedUiPanel);
  1684. }elif(w->MaximizedBlock){
  1685. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1686. }else{
  1687. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1688. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1689. }
  1690. }
  1691. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1692. if(p->IsMenuPanel){
  1693. p->TH=p->H=MenuHeight;
  1694. }
  1695. la_EnsurePanelSnapping(p, CW, CH);
  1696. laRecalcPanel(p);
  1697. }
  1698. }
  1699. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1700. laWindow *window;
  1701. #ifdef LAGUI_ANDROID
  1702. window = MAIN.Windows.pFirst; if (!window) return;
  1703. window->X=x;window->Y=y;window->W=w;window->H=h;
  1704. window->CW=w;window->CH=h;
  1705. la_UpdateUiPlacement(window); return;
  1706. #endif
  1707. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1708. if (!window) return;
  1709. #ifdef _WIN32
  1710. RECT rcc; GetClientRect(window->win, &rcc);
  1711. RECT rcw; GetWindowRect(window->win, &rcw);
  1712. window->CW = rcc.right - rcc.left;
  1713. window->CH = rcc.bottom - rcc.top;
  1714. window->W = rcw.right - rcw.left;
  1715. window->H = rcw.bottom - rcw.top;
  1716. window->X = rcw.left; window->Y = rcw.top;
  1717. if (MAIN.AutoSwitchColorSpace) {
  1718. laScreen* s = laGetWindowScreen(window);
  1719. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1720. }
  1721. #endif
  1722. #ifdef LA_LINUX
  1723. XWindowAttributes attr;
  1724. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1725. window->CW = w; window->CH = h;
  1726. window->W = w; window->H = h;
  1727. window->X = x; window->Y = y;
  1728. if(MAIN.AutoSwitchColorSpace){
  1729. laScreen* s = laGetWindowScreen(window);
  1730. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1731. }
  1732. #endif
  1733. la_UpdateUiPlacement(window);
  1734. }
  1735. int la_OnWindowDestroy(SYSWINDOW wnd){
  1736. laListHandle *hlst = &MAIN.Windows;
  1737. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1738. if (!w) return 0;
  1739. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1740. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1741. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1742. laShutoff(1);
  1743. return 1;
  1744. }
  1745. laListHandle h={0};laLayout*l=0;
  1746. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1747. la_DestroyWindow(w);
  1748. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1749. #ifdef LA_LINUX
  1750. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1751. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1752. #endif
  1753. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1754. }
  1755. return 0;
  1756. }
  1757. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1758. laListHandle *el = &wnd->EventList;
  1759. laEvent* last_e=el->pLast;
  1760. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1761. #ifdef LA_LINUX
  1762. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1763. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1764. #endif
  1765. #ifdef _WIN32
  1766. 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);
  1767. #endif
  1768. }
  1769. void laMappingRequestEval();
  1770. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1771. laListHandle *wl = &MAIN.Windows;
  1772. laWindow* wnd;
  1773. #ifdef LAGUI_ANDROID
  1774. wnd = MAIN.Windows.pFirst;
  1775. #else
  1776. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1777. #endif
  1778. if (!wnd){ memFree(e); return; }
  1779. laListHandle *el = &wnd->EventList;
  1780. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1781. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1782. e->window = wnd;
  1783. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1784. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1785. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1786. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1787. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1788. e->GoodPressure=MAIN.IsPen;
  1789. lstAppendItem(el, (laListItem *)e);
  1790. laMappingRequestEval();
  1791. };
  1792. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1793. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1794. la_SaveEvent(hwnd, e, 1);
  1795. };
  1796. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1797. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1798. e->type = LA_INPUT; e->Input=Input;
  1799. la_SaveEvent(hwnd, e, 1);
  1800. }
  1801. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1802. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1803. e->type = LA_EMPTY;
  1804. la_SaveEvent(hwnd, e, 1);
  1805. }
  1806. void laSendOperatorTriggerEvent(){
  1807. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1808. MAIN.ReTriggerOperators = 0;
  1809. }
  1810. int la_TranslateSpecialKey(int keysym){
  1811. #ifdef LA_LINUX
  1812. switch(keysym){
  1813. case XK_Return: return LA_KEY_ENTER;
  1814. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1815. case XK_Delete: return LA_KEY_DELETE;
  1816. case XK_Escape: return LA_KEY_ESCAPE;
  1817. case XK_Tab: return LA_KEY_TAB;
  1818. case XK_Left: return LA_KEY_ARRLEFT;
  1819. case XK_Right: return LA_KEY_ARRRIGHT;
  1820. case XK_Up: return LA_KEY_ARRUP;
  1821. case XK_Down: return LA_KEY_ARRDOWN;
  1822. case XK_Control_L: return LA_KEY_CTRL;
  1823. case XK_Control_R: return LA_KEY_CTRL;
  1824. case XK_Shift_L: return LA_KEY_SHIFT;
  1825. case XK_Shift_R: return LA_KEY_SHIFT;
  1826. case XK_Alt_L: return LA_KEY_ALT;
  1827. case XK_Alt_R: return LA_KEY_ALT;
  1828. case XK_KP_1: return LA_KEY_NUM1;
  1829. case XK_KP_2: return LA_KEY_NUM2;
  1830. case XK_KP_3: return LA_KEY_NUM3;
  1831. case XK_KP_4: return LA_KEY_NUM4;
  1832. case XK_KP_5: return LA_KEY_NUM5;
  1833. case XK_KP_6: return LA_KEY_NUM6;
  1834. case XK_KP_7: return LA_KEY_NUM7;
  1835. case XK_KP_8: return LA_KEY_NUM8;
  1836. case XK_KP_9: return LA_KEY_NUM9;
  1837. case XK_KP_0: return LA_KEY_NUM0;
  1838. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1839. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1840. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1841. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1842. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1843. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1844. default: return keysym;
  1845. }
  1846. #endif
  1847. #ifdef _WIN32
  1848. switch (keysym) {
  1849. case VK_RETURN: return LA_KEY_ENTER;
  1850. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1851. case VK_TAB: return LA_KEY_TAB;
  1852. case VK_LEFT: return LA_KEY_ARRLEFT;
  1853. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1854. case VK_UP: return LA_KEY_ARRUP;
  1855. case VK_DOWN: return LA_KEY_ARRDOWN;
  1856. case VK_CONTROL: return LA_KEY_CTRL;
  1857. case VK_SHIFT: return LA_KEY_SHIFT;
  1858. case VK_MENU: return LA_KEY_ALT;
  1859. case VK_F1: return LA_KEY_F1;
  1860. case VK_F2: return LA_KEY_F2;
  1861. case VK_F3: return LA_KEY_F3;
  1862. case VK_F4: return LA_KEY_F4;
  1863. case VK_F5: return LA_KEY_F5;
  1864. case VK_F6: return LA_KEY_F6;
  1865. case VK_F7: return LA_KEY_F7;
  1866. case VK_F8: return LA_KEY_F8;
  1867. case VK_F9: return LA_KEY_F9;
  1868. case VK_F10: return LA_KEY_F10;
  1869. case VK_F11: return LA_KEY_F11;
  1870. case VK_F12: return LA_KEY_F12;
  1871. case VK_NUMPAD0: return LA_KEY_NUM0;
  1872. case VK_NUMPAD1: return LA_KEY_NUM1;
  1873. case VK_NUMPAD2: return LA_KEY_NUM2;
  1874. case VK_NUMPAD3: return LA_KEY_NUM3;
  1875. case VK_NUMPAD4: return LA_KEY_NUM4;
  1876. case VK_NUMPAD5: return LA_KEY_NUM5;
  1877. case VK_NUMPAD6: return LA_KEY_NUM6;
  1878. case VK_NUMPAD7: return LA_KEY_NUM7;
  1879. case VK_NUMPAD8: return LA_KEY_NUM8;
  1880. case VK_NUMPAD9: return LA_KEY_NUM9;
  1881. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1882. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1883. case VK_ADD: return LA_KEY_NUMPLUS;
  1884. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1885. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1886. case VK_OEM_1: return ';';
  1887. case VK_OEM_2: return '/';
  1888. case VK_OEM_3: return '`';
  1889. case VK_OEM_4: return '[';
  1890. case VK_OEM_5: return '\\';
  1891. case VK_OEM_6: return ']';
  1892. case VK_OEM_7: return '\'';
  1893. case VK_OEM_COMMA: return ',';
  1894. case VK_OEM_PERIOD: return '.';
  1895. case VK_OEM_PLUS: return '+';
  1896. case VK_OEM_MINUS: return '-';
  1897. default: return keysym;
  1898. }
  1899. #endif
  1900. }
  1901. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1902. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1903. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1904. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1905. // la_SaveEvent(hwnd, e, 0);
  1906. //}
  1907. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1908. e->type = type; e->x = x; e->y = y;
  1909. la_SaveEvent(hwnd, e, 0);
  1910. MAIN.evLastX=x; MAIN.evLastY=y;
  1911. };
  1912. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1913. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1914. e->type = type;
  1915. la_SaveEvent(hwnd, e, 1);
  1916. };
  1917. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1918. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1919. e->type = LA_SIGNAL_EVENT;
  1920. e->key = signal;
  1921. la_SaveEvent(hwnd, e, 1);
  1922. };
  1923. void la_SendOperatorEvent(SYSWINDOW* hwnd, laOperatorType* at, int use_base, char* instructions){
  1924. if(!at){ return; }
  1925. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1926. e->type = LA_OPERATOR_EVENT;
  1927. e->Operator = at; e->OperatorBase = use_base; e->OperatorInstructions = instructions;
  1928. la_SaveEvent(hwnd, e, 1);
  1929. };
  1930. void laRetriggerOperators(){
  1931. MAIN.ReTriggerOperators = 1;
  1932. }
  1933. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1934. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1935. }
  1936. void laSetCleanupCallback(laCleanupF Cleanup){
  1937. MAIN.Cleanup=Cleanup;
  1938. }
  1939. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1940. MAIN.InputProcess=InputProcess;
  1941. }
  1942. //====================================================================================================
  1943. void la_DestroyTheme(laTheme* t){
  1944. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1945. strSafeDestroy(&t->Name);
  1946. strSafeDestroy(&t->Author);
  1947. }
  1948. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1949. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1950. strSafeSet(&t->Name, Name);
  1951. strSafeSet(&t->Author, AuthorName);
  1952. lstAppendItem(&MAIN.Themes, t);
  1953. MAIN.CurrentTheme = t;
  1954. return t;
  1955. }
  1956. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1957. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1958. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1959. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1960. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1961. strSafeSet(&bt->Name, Name);
  1962. bt->NormalY=NormalY;
  1963. bt->ActiveY=ActiveY;
  1964. bt->BorderY=BorderY;
  1965. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1966. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1967. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1968. bt->BackRef = BackRef;
  1969. lstAppendItem(&t->BoxedThemes, bt);
  1970. return bt;
  1971. }
  1972. laTheme *laGetTheme(const char *ThemeName){
  1973. laTheme *t = MAIN.Themes.pFirst;
  1974. for (t; t; t = t->Item.pNext){
  1975. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1976. }
  1977. return 0;
  1978. }
  1979. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1980. laTheme *t = MAIN.Themes.pFirst;
  1981. for (t; t; t = t->Item.pNext){
  1982. laBoxedTheme *bt;
  1983. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1984. bt = t->BoxedThemes.pFirst;
  1985. for (bt; bt; bt = bt->Item.pNext){
  1986. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1987. }
  1988. }
  1989. return 0;
  1990. }
  1991. real* laThemeColor(laBoxedTheme* bt, int which){
  1992. switch(which){
  1993. default:
  1994. case LA_BT_NORMAL: return bt->Normal;
  1995. case LA_UI_EDITING:
  1996. case LA_BT_ACTIVE: return bt->Active;
  1997. case LA_BT_BORDER: return bt->Border;
  1998. case LA_BT_TEXT: return bt->Text; break;
  1999. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  2000. case LA_BT_DISABLED: return bt->Inactive; break;
  2001. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  2002. }
  2003. return bt->Normal;
  2004. }
  2005. real* laAccentColor(int which){
  2006. switch(which){
  2007. default:
  2008. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  2009. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  2010. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  2011. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  2012. case LA_BT_FACE:
  2013. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  2014. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  2015. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  2016. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  2017. case LA_BT_SHADOW: return MAIN.CurrentTheme->ShadowColor;
  2018. }
  2019. return MAIN.CurrentTheme->SelectionColor;
  2020. }
  2021. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  2022. real hcy[3];
  2023. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  2024. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  2025. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  2026. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  2027. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  2028. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  2029. int *tm=&bt->LM,*tp=&bt->LP;
  2030. for(int i=0;i<4;i++){
  2031. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  2032. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  2033. }
  2034. }
  2035. void la_RefreshThemeColorSelf(laTheme* th){
  2036. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  2037. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  2038. real hcy[3], usehcy[3];
  2039. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  2040. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  2041. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  2042. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  2043. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  2044. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  2045. tnsVectorCopy3d(th->Color, th->ShadowColor); th->ShadowColor[3]=th->CursorAlpha;
  2046. }
  2047. void la_RefreshThemeColor(laTheme* th){
  2048. real hcy[3], usehcy[3], normalhcy[3];
  2049. tnsRGB2HCY(th->Color,hcy);
  2050. la_RefreshThemeColorSelf(th);
  2051. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  2052. la_RefreshBoxedThemeColor(bt);
  2053. (*bt->BackRef) = bt;
  2054. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  2055. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  2056. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  2057. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  2058. }
  2059. }
  2060. void laSetProofingLut(void* data, int which){
  2061. TNS_CLAMP(which,0,2);
  2062. MAIN.ProofingLUT[which]=data;
  2063. MAIN.LutNeedsRefreshing=1;
  2064. }
  2065. void la_RefreshProofingLut(){
  2066. if(!MAIN.CurrentWindow) return;
  2067. int table = MAIN.CurrentWindow->OutputColorSpace;
  2068. if(MAIN.CurrentLut != table+1){ MAIN.LutNeedsRefreshing=1; }
  2069. if(!MAIN.LutNeedsRefreshing) return;
  2070. tnsEnableShaderv(T->immShader);
  2071. tnsShader* s = T->immShader;
  2072. if(!MAIN.ProofingLUT[table] || !MAIN.CurrentWindow->OutputProofing){
  2073. return;
  2074. }
  2075. if(!MAIN.LutTexture) glGenTextures(1, &MAIN.LutTexture);
  2076. tnsActiveTexture(GL_TEXTURE3);
  2077. glBindTexture(GL_TEXTURE_3D, MAIN.LutTexture);
  2078. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  2079. glTexImage3D(GL_TEXTURE_3D,0,GL_RGB,LA_LUT_PRECISION,LA_LUT_PRECISION,LA_LUT_PRECISION,0,GL_RGB, GL_UNSIGNED_BYTE,MAIN.ProofingLUT[table]);
  2080. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  2081. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  2082. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  2083. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  2084. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  2085. //glBindTexture(GL_TEXTURE_3D,0);
  2086. tnsActiveTexture(GL_TEXTURE0);
  2087. MAIN.CurrentLut = table+1;
  2088. MAIN.LutNeedsRefreshing=0;
  2089. }
  2090. //I FUCKING HATE THIS STUPID FUNCTION
  2091. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  2092. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2093. laUiListDrawItem *last = uild->Items.pFirst;
  2094. int LimW=_R-_L;
  2095. int SL, SR, SU, SB;
  2096. int Target__B = Target->B;
  2097. int Target__R = Target->R;
  2098. uildi->Target = Target;
  2099. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  2100. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  2101. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  2102. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  2103. uildi->L = last ? Target->L - last->XP : Target->L;
  2104. uildi->R = last ? Target__R - last->XP : Target__R;
  2105. uildi->U = last ? Target->U - last->YP : Target->U;
  2106. uildi->B = last ? Target__B - last->YP : Target__B;
  2107. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  2108. uildi->L -= GlobalX;
  2109. uildi->R -= GlobalX;
  2110. uildi->U -= GlobalY;
  2111. uildi->B -= GlobalY;
  2112. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2113. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2114. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2115. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2116. uildi->DifX = SL - uildi->L;
  2117. uildi->DifY = SU - uildi->U;
  2118. uildi->L = SL;
  2119. uildi->R = SR+uildi->DifX;
  2120. uildi->U = SU;
  2121. uildi->B = SB;//+uildi->DifY;
  2122. if(uildi->R>_R){ uildi->R=_R; }
  2123. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  2124. //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);
  2125. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  2126. memFree(uildi);
  2127. return 0;
  2128. }
  2129. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  2130. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  2131. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  2132. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  2133. Target->U + Target->PanY + uildi->DifY+1,
  2134. -100, 100);
  2135. lstPushItem(&uild->Items, uildi);
  2136. return 1;
  2137. }
  2138. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  2139. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2140. laUiListDrawItem *last = uild->Items.pFirst;
  2141. int SL, SR, SU, SB;
  2142. if (B - U > LimH) B = U + LimH;
  2143. uildi->XP = last ? last->XP + PanX : PanX;
  2144. uildi->YP = last ? last->YP + PanY : PanY;
  2145. uildi->L = last ? L - last->XP : L;
  2146. uildi->R = last ? R - last->XP : R;
  2147. uildi->U = last ? U - last->YP : U;
  2148. uildi->B = last ? B - last->YP : B;
  2149. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  2150. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  2151. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  2152. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  2153. uildi->DifX = SL - uildi->L;
  2154. uildi->DifY = SU - uildi->U;
  2155. uildi->L = SL;
  2156. uildi->R = SR;
  2157. uildi->U = SU;
  2158. uildi->B = SB;
  2159. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2160. tnsOrtho(L + PanX + uildi->DifX,
  2161. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  2162. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  2163. U + PanY + uildi->DifY,
  2164. -100, 100);
  2165. lstPushItem(&uild->Items, uildi);
  2166. }
  2167. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2168. int* savel, int* saver, int* saveu, int* saveb){
  2169. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2170. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2171. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2172. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2173. real x,y,w,h;
  2174. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2175. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2176. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2177. }
  2178. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2179. laUiListDrawItem *uildi = uild->Items.pFirst;
  2180. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2181. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2182. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2183. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2184. Target->U + Target->PanY + uildi->DifY -1,
  2185. -100, 100);
  2186. }
  2187. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2188. laUiListDrawItem *uildi = lstPopItem(uild);
  2189. laUiList *Target;
  2190. memFree(uildi);
  2191. uildi = uild->Items.pFirst;
  2192. if (!uildi || !uildi->Target){
  2193. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2194. return;
  2195. }
  2196. Target = uildi->Target;
  2197. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2198. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2199. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2200. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2201. Target->U + Target->PanY + uildi->DifY -1,
  2202. -100, 100);
  2203. }
  2204. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2205. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2206. uildi->L = L;
  2207. uildi->R = R;
  2208. uildi->U = U;
  2209. uildi->B = B;
  2210. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2211. tnsOrtho(L, R, B, U, -100, 100);
  2212. lstPushItem(&uild->Items, uildi);
  2213. }
  2214. void la_ClearUiListMatrix(laUiListDraw *uild){
  2215. laUiListDrawItem *uildi;
  2216. while (uildi = lstPopItem(uild)){
  2217. memFree(uildi);
  2218. }
  2219. }
  2220. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2221. 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);
  2222. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2223. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2224. int la_TestUiListMinumWidth(laUiList *uil);
  2225. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2226. if (ui){
  2227. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2228. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2229. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2230. p->X = p->TX; p->Y = p->TY;
  2231. p->W = p->TW;
  2232. }
  2233. }
  2234. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2235. int cw = MAIN.CurrentWindow->CW;
  2236. int ch = MAIN.CurrentWindow->CH;
  2237. int PH = p->TH;
  2238. laBoxedTheme*bt = *p->BT;
  2239. int uih=uil->B + bt->BM;
  2240. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2241. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2242. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2243. else p->TH = PH;
  2244. p->H = p->TH;
  2245. if(p->BoundUi){
  2246. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2247. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2248. if (p->X < 0) p->X = 0;
  2249. if (p->Y < 0) p->Y = 0;
  2250. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2251. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2252. }else{
  2253. if (p->Y < 0) p->Y = 0;
  2254. if ((!p->Block)&&(!p->IsMenuPanel)){
  2255. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2256. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2257. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2258. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2259. }
  2260. }
  2261. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2262. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2263. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2264. }
  2265. if (p->ST) p->TY = p->ST;
  2266. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2267. if (p->SB) p->TH = ch - p->TY - p->SB;
  2268. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2269. p->TX = p->X; p->TY = p->Y;
  2270. p->TW = p->W; p->TH = p->H;
  2271. }
  2272. void laPlacePanelForCreation(laPanel *p){
  2273. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2274. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2275. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2276. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2277. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2278. p->TX=p->X; p->TY=p->Y;
  2279. }
  2280. }
  2281. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2282. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2283. tnsViewportWithScissor(0, 0, p->W, p->H);
  2284. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2285. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2286. }
  2287. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2288. tnsDrawToScreen();
  2289. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2290. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2291. }
  2292. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2293. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2294. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2295. }
  2296. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2297. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2298. tnsClearAll();
  2299. }
  2300. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2301. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2302. real Color[] = {1, 1, 1, 1};
  2303. real L, W, U, H;
  2304. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2305. if(MAIN.EnableColorManagement){
  2306. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2307. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2308. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2309. }else{
  2310. tnsUniformOutputColorSpace(T->immShader,0);
  2311. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2312. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2313. }
  2314. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2315. tnsUseNoTexture();
  2316. if (!p->IsMenuPanel){
  2317. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2318. }
  2319. tnsFlush();
  2320. }
  2321. if(p->ParentOperator){
  2322. tnsUseNoTexture();
  2323. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2324. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2325. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2326. }
  2327. switch (p->AnimationMode){
  2328. case 0: /* and */
  2329. case LA_PANEL_ANIMATION_FLASH:
  2330. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2331. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2332. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2333. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2334. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2335. tnsPackAs(GL_TRIANGLES);
  2336. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2337. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2338. }
  2339. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2340. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2341. if((int)(p->AnimationRatio*6)%2){
  2342. tnsUseNoTexture();
  2343. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2344. 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);
  2345. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2346. }
  2347. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2348. }
  2349. break;
  2350. case LA_PANEL_ANIMATION_DROP_DOWN:
  2351. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2352. tnsDraw2DTextureArg(
  2353. p->OffScr->pColor[0],
  2354. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2355. Color,
  2356. 0, 0, 1 - p->AnimationRatio, 0);
  2357. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2358. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2359. break;
  2360. case LA_PANEL_ANIMATION_EXPAND:
  2361. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2362. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2363. W = tnsLinearItp(0, p->W, 0.4);
  2364. H = tnsLinearItp(0, p->H, 0.4);
  2365. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2366. tnsDraw2DTextureArg(
  2367. p->OffScr->pColor[0],
  2368. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2369. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2370. Color,
  2371. 0, 0, 0, 0);
  2372. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2373. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2374. break;
  2375. case LA_PANEL_ANIMATION_DISSOVE:
  2376. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2377. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2378. W = tnsLinearItp(0, p->W, 1.4);
  2379. H = tnsLinearItp(0, p->H, 1.4);
  2380. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2381. if (p->OffScr) tnsDraw2DTextureArg(
  2382. p->OffScr->pColor[0],
  2383. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2384. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2385. Color,
  2386. 0, 0, 0, 0);
  2387. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2388. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2389. break;
  2390. case LA_PANEL_ANIMATION_COLLAPSE:
  2391. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2392. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2393. W = tnsLinearItp(0, p->W, 0.4);
  2394. H = tnsLinearItp(0, p->H, 0.4);
  2395. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2396. if (p->OffScr) tnsDraw2DTextureArg(
  2397. p->OffScr->pColor[0],
  2398. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2399. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2400. Color,
  2401. 0, 0, 0, 0);
  2402. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2403. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2404. break;
  2405. case LA_PANEL_ANIMATION_MINIMIZE:
  2406. L = tnsLinearItp(0, p->X, 0.3);
  2407. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2408. W = tnsLinearItp(0, p->W, 0.4);
  2409. H = tnsLinearItp(0, p->H, 0.4);
  2410. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2411. tnsDraw2DTextureArg(
  2412. p->OffScr->pColor[0],
  2413. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2414. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2415. Color,
  2416. 0, 0, 0, 0);
  2417. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2418. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2419. break;
  2420. }
  2421. tnsFlush();
  2422. tnsUniformOutputColorSpace(T->immShader,0);
  2423. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2424. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2425. }
  2426. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2427. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2428. else{
  2429. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:LA_PANEL_DEFAULT_GL_FORMAT;
  2430. if(p->MenuRefer && (p->MenuRefer->Flags&LA_UI_FLAGS_MENU_FLOAT16)){ GLFormat=GL_RGBA16F; }
  2431. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2432. }
  2433. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2434. }
  2435. void la_PanelRefreshDetachedProp(laPanel *panel){
  2436. laProp *p;
  2437. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2438. la_StepPropPack(&p->DetachedPP);
  2439. la_UsePropPack(&p->DetachedPP, 0);
  2440. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2441. // laUseDataBlock(
  2442. // p->DetachedPP.LastPs->UseInstance,
  2443. // p->DetachedPP.LastPs->p,
  2444. // MAIN.PropMatcherContextP->FrameDistinguish,
  2445. // MAIN.PropMatcherContextP,
  2446. // la_PropPanelUserRemover, 0);
  2447. //}
  2448. }
  2449. }
  2450. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2451. real* color=laThemeColor(bt,LA_BT_BORDER);
  2452. tnsColor4d(0,0,0,Alpha);
  2453. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2454. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2455. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2456. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2457. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2458. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2459. tnsPackAs(GL_TRIANGLE_STRIP);
  2460. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2461. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2462. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2463. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2464. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2465. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2466. }
  2467. int la_AnimateUiListRecursive(laUiList *uil);
  2468. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2469. int DrawState_ = 0;
  2470. laUiListDraw uild = {0}; int orig_refresh=p->Refresh;
  2471. if (p->Show){
  2472. la_SetPropMathcerContext(p);
  2473. MAIN.CurrentPanel = p;
  2474. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2475. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2476. //}
  2477. if (p->Refresh & LA_TAG_RECALC){
  2478. laRecalcPanelImmediate(p);
  2479. }
  2480. if (!p->MenuRefer){
  2481. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2482. if (p->Refresh || !p->OffScr){
  2483. la_PanelDrawToOffsceen(p, &p->UI);
  2484. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2485. la_PanelBackgroundInit(p, bt);
  2486. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2487. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2488. tnsFlush();
  2489. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2490. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2491. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2492. DrawState_++;
  2493. }
  2494. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2495. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2496. if(p->UI.PanY<0){p->UI.PanY=0;}
  2497. DrawState_++;
  2498. }
  2499. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2500. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2501. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2502. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2503. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2504. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2505. if(p!=w->MaximizedUiPanel){
  2506. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2507. }else{
  2508. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2509. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2510. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2511. tnsFlush();
  2512. }
  2513. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2514. }
  2515. }else{
  2516. if (p->Refresh || !p->OffScr){
  2517. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2518. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2519. la_PanelBackgroundInit(p, bt);
  2520. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2521. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2522. tnsFlush();
  2523. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2524. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2525. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2526. DrawState_++;
  2527. }
  2528. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2529. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2530. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2531. DrawState_++;
  2532. }
  2533. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2534. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2535. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2536. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2537. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2538. }
  2539. }
  2540. tnsDrawToScreen();
  2541. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2542. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2543. la_PanelDrawToWindow(p, w);
  2544. }elif (p->AnimationMode){
  2545. la_PanelDrawToWindow(p, w);
  2546. }
  2547. laPerfRecord("%s [%s]",(orig_refresh&LA_TAG_RECALC)?"🌑":
  2548. ((orig_refresh&LA_TAG_REDRAW)?"🌓":
  2549. ((orig_refresh&LA_TAG_ANIMATION)?"🌔":"🌕")), SSTR(p->Title));
  2550. }
  2551. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2552. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2553. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2554. laPanel *pi, *PrevPI;
  2555. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2556. PrevPI = pi->Item.pPrev;
  2557. if (pi->AnimationMode && pi->LaterDestroy){
  2558. lstRemoveItem(&p->SubPanels, pi);
  2559. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2560. continue;
  2561. }
  2562. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2563. la_AttachedPanelDefDraw(w,pi,bt);
  2564. }
  2565. }
  2566. }
  2567. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2568. real PanelSquare[] = {
  2569. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2570. b->X + 2, CH - (b->Y + b->H - 4),
  2571. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2572. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2573. real Center[] = {
  2574. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2575. real DraggingPlot[] = {
  2576. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2577. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2578. PanelSquare[0],
  2579. PanelSquare[1],
  2580. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2581. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2582. PanelSquare[2],
  2583. PanelSquare[3],
  2584. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2585. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2586. PanelSquare[4],
  2587. PanelSquare[5],
  2588. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2589. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2590. PanelSquare[6],
  2591. PanelSquare[7],
  2592. };
  2593. real Square[] = {
  2594. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2595. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2596. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2597. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2598. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2599. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2600. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2601. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2602. };
  2603. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2604. LA_COLOR3(BorderColor4dV), 0,
  2605. LA_COLOR3(BorderColor4dV), 0.8,
  2606. LA_COLOR3(BorderColor4dV), 0,
  2607. LA_COLOR3(BorderColor4dV), 0.8,
  2608. LA_COLOR3(BorderColor4dV), 0,
  2609. LA_COLOR3(BorderColor4dV), 0.8,
  2610. LA_COLOR3(BorderColor4dV), 0,
  2611. };
  2612. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2613. LA_COLOR3(FillColor4dv), 0,
  2614. LA_COLOR3(FillColor4dv), 0.8,
  2615. LA_COLOR3(FillColor4dv), 0,
  2616. LA_COLOR3(FillColor4dv), 0.8,
  2617. LA_COLOR3(FillColor4dv), 0,
  2618. LA_COLOR3(FillColor4dv), 0.8,
  2619. LA_COLOR3(FillColor4dv), 0,
  2620. };
  2621. tnsUseNoTexture();
  2622. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2623. int Index[4];
  2624. tnsVertexArray2d(DraggingPlot, 8);
  2625. tnsColorArray4d(FillColor, 8);
  2626. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2627. case 0:
  2628. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2629. break;
  2630. case LA_BLOCK_DROP_LOCATION_L:
  2631. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2632. break;
  2633. case LA_BLOCK_DROP_LOCATION_R:
  2634. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2635. break;
  2636. case LA_BLOCK_DROP_LOCATION_U:
  2637. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2638. break;
  2639. case LA_BLOCK_DROP_LOCATION_B:
  2640. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2641. break;
  2642. }
  2643. //glDisable(GL_CULL_FACE);
  2644. tnsIndexArray(Index, 4);
  2645. tnsPackAs(GL_TRIANGLE_FAN);
  2646. //tnsFlush();
  2647. }
  2648. tnsVertexArray2d(DraggingPlot, 8);
  2649. tnsColorArray4d(PlotColor, 8);
  2650. tnsPackAs(GL_LINES);
  2651. tnsVertexArray2d(Square, 4);
  2652. tnsColor4dv(BorderColor4dV);
  2653. tnsPackAs(GL_LINE_LOOP);
  2654. glLineWidth(LA_SEAM_W);
  2655. tnsFlush();
  2656. glLineWidth(1);
  2657. }
  2658. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2659. laBoxedTheme *bt = _LA_THEME_TAB;
  2660. laPanel *p;
  2661. real v[] = {
  2662. b->X, CH - b->Y,
  2663. b->X + LA_SEAM_W, CH - b->Y ,
  2664. b->X, CH - (b->Y + b->H),
  2665. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2666. b->X + b->W, CH - (b->Y + b->H),
  2667. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2668. b->X + b->W, CH - b->Y,
  2669. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2670. real tv[8];
  2671. real ratio = 1.0001f;
  2672. int tw = 0;
  2673. int L = LA_RH+LA_SEAM_W;
  2674. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2675. if(MAIN.EnableColorManagement){
  2676. laWindow* w=MAIN.CurrentWindow;
  2677. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2678. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2679. }else{
  2680. tnsUniformOutputColorSpace(T->immShader,0);
  2681. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2682. }
  2683. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2684. tw += p->TitleWidth + LA_SEAM_W*2;
  2685. }
  2686. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2687. tnsUseNoTexture();
  2688. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2689. tnsVertexArray2d(v, 8);
  2690. tnsPackAs(GL_TRIANGLE_STRIP);
  2691. int TitleGap=b->Folded?0:LA_RH;
  2692. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2693. b->X + b->W, (CH - b->Y),
  2694. b->X + b->W, (CH - b->Y - TitleGap),
  2695. b->X, (CH - b->Y - TitleGap));
  2696. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2697. tnsVertexArray2d(tv, 4);
  2698. tnsPackAs(GL_TRIANGLE_FAN);
  2699. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2700. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2701. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2702. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2703. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2704. tnsVertexArray2d(tv, 4);
  2705. tnsPackAs(GL_TRIANGLE_FAN);
  2706. if(b->Folded){
  2707. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2708. 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);
  2709. 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);
  2710. tnsFlush(); return;
  2711. }
  2712. int LT=0,RT=0;
  2713. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2714. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2715. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2716. b->X + L+RT * ratio, (CH - b->Y),
  2717. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2718. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2719. if (p == b->CurrentPanel){
  2720. tnsUseNoTexture();
  2721. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2722. tnsVertexArray2d(tv, 4);
  2723. tnsPackAs(GL_TRIANGLE_FAN);
  2724. 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);
  2725. }else{
  2726. 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);
  2727. }
  2728. LT =RT;
  2729. }
  2730. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2731. tnsFlush();
  2732. tnsUniformOutputColorSpace(T->immShader,0);
  2733. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2734. }
  2735. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2736. laBoxedTheme *bt = _LA_THEME_PANEL;
  2737. real tv[8];
  2738. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2739. if(MAIN.EnableColorManagement){
  2740. laWindow* w=MAIN.CurrentWindow;
  2741. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2742. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2743. }else{
  2744. tnsUniformOutputColorSpace(T->immShader,0);
  2745. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2746. }
  2747. tnsUseNoTexture();
  2748. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2749. b->X + b->W, (CH - b->Y),
  2750. b->X + b->W, (CH - b->Y-b->H),
  2751. b->X, (CH - b->Y-b->H));
  2752. tnsVertexArray2d(tv, 4);
  2753. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2754. tnsPackAs(GL_TRIANGLE_FAN);
  2755. 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,
  2756. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2757. tnsFlush();
  2758. tnsUniformOutputColorSpace(T->immShader,0);
  2759. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2760. }
  2761. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2762. if (b->B1){
  2763. la_BlockDefDrawRecursive(w, bt, b->B1);
  2764. la_BlockDefDrawRecursive(w, bt, b->B2);
  2765. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2766. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2767. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2768. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2769. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2770. la_BlockDefDrawSelf(b, w->CH);
  2771. }else{
  2772. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2773. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2774. la_BlockDefDrawSelfEmpty(b, w->CH);
  2775. }
  2776. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2777. tnsUseNoTexture();
  2778. int at; real tv[8];
  2779. if (b->Vertical){
  2780. at = b->H * b->SplitRatio + b->Y;
  2781. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2782. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2783. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2784. b->X, (w->CH - at - LA_SEAM_W));
  2785. }else{
  2786. at = b->X + b->W * b->SplitRatio;
  2787. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2788. at- LA_SEAM_W, (w->CH - b->Y),
  2789. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2790. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2791. }
  2792. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2793. tnsVertexArray2d(tv, 4);
  2794. tnsPackAs(GL_TRIANGLE_FAN);
  2795. }
  2796. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2797. tnsFlush();
  2798. }
  2799. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2800. if (b->B1){
  2801. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2802. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2803. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2804. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2805. }
  2806. tnsFlush();
  2807. }
  2808. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2809. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2810. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2811. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2812. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2813. if(p->OffScr){
  2814. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2815. }
  2816. }
  2817. }
  2818. void la_ClearUnusedFramebuffers(laWindow* w){
  2819. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2820. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2821. }
  2822. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2823. if(p->Show || p->AnimationMode) continue;
  2824. if(p->OffScr){
  2825. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2826. }
  2827. }
  2828. }
  2829. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2830. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2831. laPanel *p, *NextP;
  2832. laLayout *l = w->CurrentLayout;
  2833. if (!w->CH || !w->CW) return;
  2834. la_ClearUnusedFramebuffers(w);
  2835. tnsDrawToScreen();
  2836. la_RefreshProofingLut();
  2837. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2838. glClearColor(0.2, 0.2, 0.3, 1.0);
  2839. tnsClearAll();
  2840. tnsUseNoTexture();
  2841. if (l->Draw) l->Draw(w, l);
  2842. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2843. glEnable(GL_BLEND);
  2844. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2845. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2846. laUiItem* ui;
  2847. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2848. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2849. la_SetPropMathcerContext(p);
  2850. if(p->Refresh){
  2851. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2852. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2853. if(MAIN.EnableColorManagement){
  2854. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2855. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint,w->OutputProofing);
  2856. }else{
  2857. tnsUniformOutputColorSpace(T->immShader,0);
  2858. tnsUniformColorComposing(T->immShader,0,0,0,0);
  2859. }
  2860. if(p->Refresh&LA_TAG_RECALC){
  2861. laRecalcPanelImmediate(p);
  2862. }
  2863. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2864. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2865. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2866. }
  2867. tnsDrawToScreen();
  2868. tnsResetViewMatrix();
  2869. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2870. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2871. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2872. tnsFlush();
  2873. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2874. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2875. tnsFlush();
  2876. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2877. }
  2878. }
  2879. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2880. la_AttachedPanelDefDraw(w,p,*p->BT);
  2881. }else{
  2882. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2883. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2884. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2885. }
  2886. for (p = w->Panels.pLast; p; p = NextP){
  2887. NextP = p->Item.pPrev;
  2888. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2889. if (p->AnimationMode && p->LaterDestroy){
  2890. lstRemoveItem(&w->Panels, p);
  2891. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2892. continue;
  2893. }
  2894. la_PanelDefDraw(w, p, *p->BT);
  2895. }
  2896. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2897. la_AttachedPanelDefDraw(w,p,*p->BT);
  2898. }
  2899. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2900. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2901. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2902. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2903. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2904. tnsFlush();
  2905. }
  2906. for (p = w->FadingPanels.pLast; p; p = NextP){
  2907. NextP = p->Item.pPrev;
  2908. if (!p->AnimationMode){
  2909. lstRemoveItem(&w->FadingPanels, p);
  2910. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2911. laDeferredDestroyPanel(p, 0);
  2912. }else
  2913. la_PanelDrawToWindow(p, w);
  2914. }
  2915. if(MAIN.ShowPerf){
  2916. la_PerfDraw();
  2917. }
  2918. }
  2919. int laStartWindow(laWindow *w){
  2920. #ifdef LA_LINUX
  2921. XMapWindow(MAIN.dpy,w->win);
  2922. tnsContextMakeWindowCurrent(w);
  2923. #endif
  2924. #ifdef _WIN32
  2925. ShowWindow(w->win, SW_SHOWNORMAL);
  2926. #endif
  2927. MAIN.CurrentWindow = w;
  2928. if(!w->CurrentLayout){
  2929. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2930. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2931. }
  2932. laRedrawCurrentWindow();
  2933. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2934. w->Shown = 1;
  2935. }
  2936. void la_AssignWindowPP(laWindow* w){
  2937. w->PP.EndInstance = w;
  2938. w->PP.LastPs = &w->FakePS;
  2939. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2940. w->PP.LastPs->UseInstance = w;
  2941. w->PP.LastPs->Type = U'.';
  2942. }
  2943. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2944. #ifdef LAGUI_ANDROID
  2945. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2946. #endif
  2947. laWindow *n = memAcquire(sizeof(laWindow));
  2948. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2949. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2950. #ifdef LAGUI_ANDROID
  2951. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2952. #endif
  2953. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2954. lstAppendItem(&MAIN.Windows, n);
  2955. MAIN.CurrentWindow = n;
  2956. la_AssignWindowPP(n);
  2957. laui_DefaultMenuBar(n);
  2958. return n;
  2959. }
  2960. void laSetWindowCursor(int id){
  2961. MAIN.CurrentCursor = id;
  2962. #ifdef LA_LINUX
  2963. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2964. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2965. #endif
  2966. #ifdef _WIN32
  2967. SetCursor(la_ConvertCursorID(id));
  2968. #endif
  2969. };
  2970. void la_AssignBlockPP(laBlock* b){
  2971. b->PP.EndInstance = b;
  2972. b->PP.LastPs = &b->FakePS;
  2973. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2974. b->PP.LastPs->UseInstance = b;
  2975. b->PP.LastPs->Type = U'.';
  2976. }
  2977. void laDestroyLayout(laWindow *w, laLayout* l){
  2978. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2979. laDestroyBlocksRecursive(l->FirstBlock);
  2980. strSafeDestroy(&l->ID);
  2981. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2982. lstRemoveItem(&w->Layouts,l); memFree(l);
  2983. }
  2984. laLayout *laDesignLayout(laWindow *w, char *Title){
  2985. laLayout *l = memAcquire(sizeof(laLayout));
  2986. l->FirstBlock = memAcquire(sizeof(laBlock));
  2987. la_AssignBlockPP(l->FirstBlock);
  2988. lstAppendItem(&w->Layouts, l);
  2989. strSafeSet(&l->ID, Title);
  2990. memAssignRef(w, &w->CurrentLayout, l);
  2991. laRenameWindow(w, Title);
  2992. return l;
  2993. }
  2994. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2995. 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); }
  2996. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2997. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2998. laNotifyUsers("la.windows.maximized_block"); }
  2999. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  3000. laNotifyUsers("la.windows.maximized_block"); }
  3001. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  3002. laRestoreCanvasUI();
  3003. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  3004. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  3005. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  3006. UiParentPanel->Show=0;
  3007. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  3008. }
  3009. void laRestoreCanvasUI(){
  3010. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  3011. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  3012. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  3013. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  3014. }
  3015. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  3016. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  3017. }
  3018. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  3019. void laSplitBlockHorizon(laBlock *b, real Percentage){
  3020. laPanel *p;
  3021. b->SplitRatio = Percentage;
  3022. b->Vertical = 0;
  3023. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  3024. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  3025. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3026. p->Block = b->B1;
  3027. }
  3028. b->B1->Panels.pFirst = b->Panels.pFirst;
  3029. b->B1->Panels.pLast = b->Panels.pLast;
  3030. b->B1->CurrentPanel = b->CurrentPanel;
  3031. b->B1->parent = b->B2->parent=b;
  3032. b->Panels.pFirst = 0;
  3033. b->Panels.pLast = 0;
  3034. b->CurrentPanel = 0;
  3035. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3036. }
  3037. void laSplitBlockVertical(laBlock *b, real Percentage){
  3038. laPanel *p;
  3039. b->SplitRatio = Percentage;
  3040. b->Vertical = 1;
  3041. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  3042. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  3043. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3044. p->Block = b->B1;
  3045. }
  3046. b->B1->Panels.pFirst = b->Panels.pFirst;
  3047. b->B1->Panels.pLast = b->Panels.pLast;
  3048. b->B1->CurrentPanel = b->CurrentPanel;
  3049. b->B1->parent = b->B2->parent=b;
  3050. b->Panels.pFirst = 0;
  3051. b->Panels.pLast = 0;
  3052. b->CurrentPanel = 0;
  3053. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3054. }
  3055. void laCombineChildBlocks(laBlock *b){
  3056. laPanel *p; if(!b) return;
  3057. if (!b->B1->B1 && !b->B2->B1){
  3058. lstCombineLists(&b->Panels, &b->B1->Panels);
  3059. lstCombineLists(&b->Panels, &b->B2->Panels);
  3060. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  3061. p->Block = b;
  3062. }
  3063. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  3064. memFree(b->B1);
  3065. memFree(b->B2);
  3066. b->B1 = 0;
  3067. b->B2 = 0;
  3068. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3069. }elif(!b->B1->B1){
  3070. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  3071. b->Vertical = b->B2->Vertical;
  3072. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  3073. p->Block = b1;
  3074. }
  3075. lstCombineLists(&b1->Panels, &b->B1->Panels);
  3076. memFree(b->B1); memFree(b->B2);
  3077. b->B1 = b1; b->B2 = b2;
  3078. b1->parent = b; b2->parent = b;
  3079. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3080. }elif(!b->B2->B1){
  3081. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  3082. b->Vertical = b->B1->Vertical;
  3083. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  3084. p->Block = b1;
  3085. }
  3086. lstCombineLists(&b1->Panels, &b->B2->Panels);
  3087. memFree(b->B1); memFree(b->B2);
  3088. b->B1 = b1; b->B2 = b2;
  3089. b1->parent = b; b2->parent = b;
  3090. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3091. }
  3092. }
  3093. laBlock *laBlock1(laBlock *b){
  3094. return b->B1;
  3095. }
  3096. laBlock *laBlock2(laBlock *b){
  3097. return b->B2;
  3098. }
  3099. laBlock *laSwapSubBlocks(laBlock *b){
  3100. laBlock *tB;
  3101. tB = b->B2;
  3102. b->B2 = b->B1;
  3103. b->B1 = tB;
  3104. b->SplitRatio = 1 - b->SplitRatio;
  3105. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  3106. }
  3107. void laDestroyBlocksRecursive(laBlock *Root){
  3108. laPanel *p;
  3109. if (Root->B1){
  3110. laDestroyBlocksRecursive(Root->B1);
  3111. laDestroyBlocksRecursive(Root->B2);
  3112. }else{
  3113. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  3114. }
  3115. memFree(Root);
  3116. }
  3117. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  3118. if(!b->CurrentPanel ) return 0;
  3119. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  3120. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  3121. lstRemoveItem(&b->Panels, p);
  3122. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  3123. if(!p->TitleBar.UiItems.pFirst){
  3124. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  3125. }
  3126. p->Mode = LA_PANEL_FLOATING_TOP;
  3127. p->TY-=LA_RH; p->TH+=LA_RH;
  3128. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  3129. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  3130. p->Block = 0;
  3131. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  3132. laRecalcPanel(p);
  3133. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3134. p->BT = &_LA_THEME_FLOATING_PANEL;
  3135. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3136. laNotifyUsers("la.windows.panels");
  3137. return b->CurrentPanel;
  3138. }
  3139. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  3140. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  3141. lstRemoveItem(&from->Panels, p);
  3142. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3143. p->Mode = LA_PANEL_NORMAL;
  3144. p->Block=b;
  3145. b->CurrentPanel = p;
  3146. b->Folded = 0;
  3147. lstPushItem(&b->Panels, p);
  3148. laRecalcPanel(p);
  3149. p->BT = &_LA_THEME_PANEL;
  3150. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  3151. tnsFlush();
  3152. laNotifyUsers("la.windows.panels");
  3153. }
  3154. void laPopPanel(laPanel *p){
  3155. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  3156. lstRemoveItem(&p->Parent->SubPanels, p);
  3157. lstPushItem(&p->Parent->SubPanels, p);
  3158. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3159. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3160. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3161. laNotifyUsers("la.windows.panels");
  3162. }
  3163. }
  3164. void la_EnsurePanelExtras(laPanel *p){
  3165. laUiTemplate* uit=p->PanelTemplate;
  3166. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  3167. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  3168. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  3169. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  3170. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  3171. p->PropLinkFakeProp->Base.Offset = 0;
  3172. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  3173. p->PropLinkPP.EndInstance = p;
  3174. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  3175. p->PropLinkPP.LastPs->Type = U'.';
  3176. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3177. }
  3178. laPanel* la_GivePanelNode(){
  3179. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3180. return memAcquire(sizeof(laPanel));
  3181. }
  3182. void la_ReturnPanelNode(laPanel* p){
  3183. memset(p,0,sizeof(laPanel));
  3184. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3185. lstAppendItem(&MAIN.WastedPanels, p);
  3186. }
  3187. 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){
  3188. laPanel *p = la_GivePanelNode();
  3189. int CW = MAIN.CurrentWindow->CW;
  3190. int CH = MAIN.CurrentWindow->CH;
  3191. p->PanelTemplate = uit;
  3192. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3193. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3194. if (!MaxW) MaxW = 10000;
  3195. if (!MaxH) MaxH = 10000;
  3196. if (W > MaxW) W = MaxW;
  3197. if (H > MaxH) H = MaxH;
  3198. if (W < MinW) W = MinW;
  3199. if (H < MinH) H = MinH;
  3200. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3201. p->X = p->TX = (X < 0 ? 0 : X);
  3202. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3203. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3204. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3205. p->MaxW = MaxW; p->MaxH = MaxH;
  3206. p->MinW = MinW; p->MinH = MinH;
  3207. p->SL = SnapL; p->ST = SnapT;
  3208. p->SR = SnapR; p->SB = SnapB;
  3209. if (p->SR) p->X = CW - p->W - p->SR;
  3210. if (p->SB) p->Y = CH - p->H - p->SB;
  3211. la_EnsurePanelSnapping(p, CW, CH);
  3212. p->Show = 1;
  3213. p->PP.EndInstance = p;
  3214. p->PP.LastPs = &p->FakePS;
  3215. p->PP.LastPs->p = _LA_PROP_PANEL;
  3216. p->PP.LastPs->UseInstance = p;
  3217. p->PP.LastPs->Type = U'.';
  3218. la_EnsurePanelExtras(p);
  3219. laRecalcPanel(p);
  3220. p->FrameDistinguish = 100; //greater than 1 is ok
  3221. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3222. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3223. return p;
  3224. }
  3225. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3226. if(!uit) return 0;
  3227. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3228. strSafeSet(&p->Title, uit->Title->Ptr);
  3229. p->PanelTemplate = uit;
  3230. p->Show = 1;
  3231. p->PP.EndInstance = p;
  3232. p->PP.LastPs = &p->FakePS;
  3233. p->PP.LastPs->p = _LA_PROP_PANEL;
  3234. p->PP.LastPs->UseInstance = p;
  3235. p->PP.LastPs->Type = U'.';
  3236. la_EnsurePanelExtras(p);
  3237. laRecalcPanel(p);
  3238. p->FrameDistinguish = 100; //greater than 1 is ok
  3239. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3240. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3241. p->Block = b; b->CurrentPanel = p;
  3242. if(uit->PropFunc){ uit->PropFunc(p); }
  3243. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3244. laNotifyUsers("la.windows.panels");
  3245. return p;
  3246. }
  3247. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3248. laUiTemplate* uit=laFindUiTemplate(template_id);
  3249. return laCreatePanelT(b, uit);
  3250. }
  3251. 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){
  3252. laUiTemplate* uit=0;
  3253. if(template_id) uit=laFindUiTemplate(template_id);
  3254. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3255. p->Mode = LA_PANEL_FLOATING_TOP;
  3256. laPlacePanelForCreation(p);
  3257. if(uit){
  3258. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3259. }
  3260. if (w) lstPushItem(&w->Panels, p);
  3261. return p;
  3262. }
  3263. void laShowPanel(laPanel *p){
  3264. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3265. }
  3266. void laShowPanelWithDropDownEffect(laPanel *p){
  3267. laShowPanel(p);
  3268. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3269. p->AnimationRatio = 0;
  3270. }
  3271. void laShowPanelWithExpandEffect(laPanel *p){
  3272. laShowPanel(p);
  3273. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3274. p->AnimationRatio = 0;
  3275. }
  3276. void laHidePanel(laPanel *p){
  3277. if (!p->Mode) return;
  3278. p->Show = 0;
  3279. laNotifyUsers("la.windows.panels_hidden");
  3280. }
  3281. void laHidePanelWithDissoveEffect(laPanel *p){
  3282. if (!p->Mode) return;
  3283. laHidePanel(p);
  3284. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3285. p->AnimationRatio = 1;
  3286. }
  3287. void laHidePanelWithCollapseEffect(laPanel *p){
  3288. if (!p->Mode) return;
  3289. laHidePanel(p);
  3290. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3291. p->AnimationRatio = 1;
  3292. }
  3293. void laHidePanelWithMinimizeEffect(laPanel *p){
  3294. if (!p->Mode) return;
  3295. laHidePanel(p);
  3296. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3297. p->AnimationRatio = 1;
  3298. }
  3299. void laActivatePanel(char* TemplateID, int x, int y){
  3300. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3301. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3302. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3303. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3304. }
  3305. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3306. p->UI.PanX += DeltaX;
  3307. p->UI.PanY += DeltaY;
  3308. }
  3309. int laPanUiListFree(laUiList *uil, int X, int Y){
  3310. uil->PanX+=X; uil->PanY+=Y;
  3311. }
  3312. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3313. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3314. if(Y){X+=Y;Y=0;}
  3315. }
  3316. if (Y > 0){
  3317. if (uil->B - uil->PanY <= B) return 0;
  3318. else{
  3319. uil->PanY += Y;
  3320. if (uil->B - uil->PanY <= B){
  3321. uil->PanY = uil->B - B;
  3322. return 1;
  3323. }
  3324. }
  3325. }
  3326. if (Y < 0){
  3327. if (uil->U - uil->PanY >= U) return 0;
  3328. else{
  3329. uil->PanY += Y;
  3330. if (uil->U - uil->PanY >= U){
  3331. uil->PanY = uil->U - U;
  3332. return 1;
  3333. }
  3334. }
  3335. }
  3336. if(uil->AllowScale){
  3337. laPanUiListFree(uil, X, 0);
  3338. }else{
  3339. if (X > 0){
  3340. if (uil->R - uil->PanX <= R) return 0;
  3341. else{
  3342. uil->PanX += X;
  3343. if (uil->R - uil->PanX <= R){
  3344. uil->PanX = uil->R - R;
  3345. return 1;
  3346. }
  3347. }
  3348. }
  3349. if (X < 0){
  3350. if (uil->L - uil->PanX >= L) return 0;
  3351. else{
  3352. uil->PanX += X;
  3353. if (uil->L - uil->PanX >= L){
  3354. uil->PanX = uil->L - L;
  3355. return 1;
  3356. }
  3357. }
  3358. }
  3359. }
  3360. return 1;
  3361. }
  3362. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3363. int ret=1;
  3364. if(!uil->AllowScale){ return 0; }
  3365. real NewScale=uil->Scale*factor;
  3366. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3367. if(NewScale>5) {NewScale=5; ret=0;}
  3368. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3369. factor=NewScale/uil->Scale;
  3370. uil->Scale=NewScale;
  3371. real mx=(L+R)/2,my=(U+B)/2;
  3372. real dx= (mx+uil->PanX)*factor;
  3373. real dy= (my+uil->PanY)*factor;
  3374. uil->PanX=dx-mx;
  3375. uil->PanY=dy-my;
  3376. MAIN.CurrentPanel->FrameDistinguish=100;
  3377. return ret;
  3378. }
  3379. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3380. if(uil->AllowScale) return 0;
  3381. return laPanUiList(uil,X,Y,L,R,U,B);
  3382. }
  3383. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3384. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3385. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3386. strSafeSet(&p->Title, Title);
  3387. if (Define){
  3388. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3389. }
  3390. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3391. p->BT= &_LA_THEME_FLOATING_PANEL;
  3392. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3393. p->BoundUi = 1;
  3394. return p;
  3395. }
  3396. 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,
  3397. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3398. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3399. strSafeSet(&p->Title, Title);
  3400. if (Define){
  3401. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3402. }
  3403. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3404. p->BT= &_LA_THEME_FLOATING_PANEL;
  3405. p->Mode = LA_PANEL_FLOATING_TOP;
  3406. p->BoundUi = 1;
  3407. return p;
  3408. }
  3409. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3410. laPanel *ip;
  3411. tnsDelete2DOffscreen(p->OffScr);
  3412. p->OffScr = 0;
  3413. strSafeDestroy(&p->Title);
  3414. if (!p->AnimationMode){
  3415. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3416. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3417. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3418. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3419. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3420. }else if (p->Block){
  3421. lstRemoveItem(&p->Block->Panels, p);
  3422. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3423. }
  3424. laNotifyUsers("la.windows.panels");
  3425. }
  3426. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3427. //lstRemoveItem(&p->SubPanels, ip);
  3428. laDestroySinglePanel(ip, immediate);
  3429. laNotifyUsers("la.windows.panels");
  3430. }
  3431. la_ClearDetachedProp(p);
  3432. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3433. la_ReturnPanelNode(p);
  3434. }
  3435. void laDestroySinglePanel(laPanel *p, int immediate){
  3436. la_SetPropMathcerContext(p);
  3437. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3438. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3439. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3440. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3441. }
  3442. }
  3443. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3444. la_DestroyUiList(&p->UI, 1, 1, 0);
  3445. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3446. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3447. if (p->Mode){
  3448. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3449. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3450. }
  3451. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3452. if (la_UiStillInService(p)){
  3453. la_StopUiOperatorService(p);
  3454. }
  3455. if ((!p->AnimationMode) || immediate){
  3456. laDeferredDestroyPanel(p, immediate);
  3457. }else{
  3458. p->LaterDestroy = 1;
  3459. }
  3460. }
  3461. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3462. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3463. int MinW,MinWt=0;
  3464. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3465. int CW = MAIN.CurrentWindow->CW;
  3466. if(p->SL && p->SR){return 0;}
  3467. la_SetPropMathcerContext(p);
  3468. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3469. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3470. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3471. MinW = la_TestUiListMinumWidth(uil);
  3472. if (MinW<MinWt){MinW=MinWt;}
  3473. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3474. if (MinW > 20){
  3475. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3476. }
  3477. la_PanelValidateWidth(p,uil);
  3478. laEnsurePanelInBound(p,uil);
  3479. if(p->TW>CW){ p->TW=CW; }
  3480. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3481. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3482. laRedrawPanel(p);
  3483. return 1;
  3484. }
  3485. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3486. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3487. laOperator *ai = a;
  3488. laPanel *p;
  3489. int GX, GY, GW, t = 0;
  3490. int b;
  3491. laUiDefineFunc def = ReplaceUiDefine;
  3492. int MinW;
  3493. if (!def){ def=laui_DefaultPropDetails; }
  3494. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3495. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3496. laEnclosePanelContent(p, &p->UI);
  3497. laSetOperatorLocalizer(p);
  3498. p->CloseWhenMovedOut=1;
  3499. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3500. //laShowPanelWithDropDownEffect(p);
  3501. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3502. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3503. return p;
  3504. }
  3505. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3506. laPanel *p;
  3507. int GX, GY, GW, t = 0;
  3508. int b;
  3509. laUiDefineFunc def = ReplaceUiDefine;
  3510. int MinW;
  3511. if (!def) return 0;
  3512. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3513. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3514. p->Mode = LA_PANEL_FLOATING_TOP;
  3515. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3516. laEnclosePanelContent(p, &p->UI);
  3517. if(MAIN.CurrentWindow->Operators.pFirst){
  3518. laSetOperatorLocalizer(MAIN.PendingSplash);
  3519. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3520. MAIN.PendingSplash=0;
  3521. }
  3522. //laShowPanelWithExpandEffect(p);
  3523. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3524. return p;
  3525. }
  3526. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3527. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3528. laOperator *ai = a;
  3529. laPanel *p; laPropContainer* sub;
  3530. int GX, GY, GW, t = 0;
  3531. int b;
  3532. laUiDefineFunc def = ReplaceUiDefine;
  3533. int MinW;
  3534. if (!def){
  3535. if (This && This->LastPs->p){
  3536. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3537. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3538. }
  3539. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3540. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3541. }
  3542. GX = L; GY = B;
  3543. GW = (R - L) > MaxW ? MaxW : (R - L);
  3544. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3545. laEnclosePanelContent(p, &p->UI);
  3546. laSetOperatorLocalizer(p);
  3547. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3548. laShowPanelWithDropDownEffect(p);
  3549. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3550. if(Attachment){
  3551. p->Parent = Attachment;
  3552. lstAppendItem(&Attachment->SubPanels, p);
  3553. }
  3554. return p;
  3555. }
  3556. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3557. laPanel *p;
  3558. int t = 0;
  3559. int b;
  3560. //laLocalToWindow(0, Attachment, &L, &t);
  3561. //laLocalToWindow(0, Attachment, &R, &U);
  3562. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3563. laSetOperatorLocalizer(p);
  3564. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3565. laShowPanelWithDropDownEffect(p);
  3566. p->Parent = Attachment;
  3567. lstPushItem(&Attachment->SubPanels, p);
  3568. return p;
  3569. }
  3570. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3571. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3572. laOperator *ai = a;
  3573. laPanel *p;
  3574. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3575. int GX, GY, GW, t = 0;
  3576. int b;
  3577. int MinW;
  3578. //laLocalToWindow(0,Attachment, &L, &t);
  3579. //laLocalToWindow(0,Attachment, &R, &B);
  3580. GX = L;
  3581. GY = B;
  3582. GW = (R - L) > MaxW ? MaxW : (R - L);
  3583. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3584. p->MenuRefer = MenuRefer;
  3585. laEnclosePanelContent(p, MenuRefer);
  3586. laSetOperatorLocalizer(p);
  3587. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3588. laShowPanelWithDropDownEffect(p);
  3589. p->Parent = Attachment;
  3590. lstPushItem(&Attachment->SubPanels, p);
  3591. return p;
  3592. }
  3593. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3594. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3595. laOperator *ai = a;
  3596. laPanel *p;
  3597. int GX, GY, GW, t = 0;
  3598. int b;
  3599. GX = L;
  3600. GY = B;
  3601. GW = MaxW;
  3602. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3603. p->MenuRefer = &p->UI;
  3604. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3605. laSetOperatorLocalizer(p);
  3606. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3607. laShowPanelWithDropDownEffect(p);
  3608. if (Attachment){
  3609. p->Parent = Attachment;
  3610. lstPushItem(&Attachment->SubPanels, p);
  3611. }else{
  3612. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3613. }
  3614. return p;
  3615. }
  3616. 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){
  3617. laOperator *ai = For;
  3618. laPanel *p;
  3619. int b;
  3620. laUiDefineFunc def = 0;
  3621. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3622. else def = laui_DefaultPropUiDefine;
  3623. For->PP.EndInstance = For->CustomData;
  3624. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3625. laEnclosePanelContent(p, &p->UI);
  3626. MAIN.ToPanel = p;
  3627. laShowPanelWithExpandEffect(p);
  3628. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3629. ai->OperatorPanel = p;
  3630. p->ParentOperator = For;
  3631. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3632. return p;
  3633. }
  3634. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3635. laPanel *p; int b; laUiList *uil; laColumn* col;
  3636. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3637. strSafeSet(&p->Title, Title);
  3638. p->BoundUi = 1;
  3639. p->Mode = LA_PANEL_FLOATING_TOP;
  3640. p->BT = &_LA_THEME_FLOATING_PANEL;
  3641. MAIN.ToPanel = p;
  3642. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3643. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3644. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3645. laUiItem* r=laBeginRow(uil,col,0,0);
  3646. laShowSeparator(uil,col)->Expand=1;
  3647. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3648. laEndRow(uil,r);
  3649. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3650. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3651. laSetOperatorLocalizer(p);
  3652. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3653. return p;
  3654. }
  3655. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3656. laPanel *p; int b; laUiList *uil; laColumn* col;
  3657. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3658. strSafeSet(&p->Title, Title);
  3659. p->BoundUi = 1;
  3660. p->Mode = LA_PANEL_FLOATING_TOP;
  3661. p->BT = &_LA_THEME_FLOATING_PANEL;
  3662. MAIN.ToPanel = p;
  3663. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3664. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3665. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3666. laUiItem* r = laBeginRow(uil,col,0,0);
  3667. laShowSeparator(uil,col)->Expand=1;
  3668. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3669. laEndRow(uil, r);
  3670. laEnclosePanelContent(p,uil);
  3671. laShowPanelWithExpandEffect(p);
  3672. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3673. laSetOperatorLocalizer(p);
  3674. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3675. return p;
  3676. }
  3677. void laOperatorModalOver(laOperator* For){
  3678. For->ModalOver = 1;
  3679. }
  3680. void laDeferredRedraw(laPanel* p){
  3681. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3682. if(lip->p==p) return;
  3683. }
  3684. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3685. }
  3686. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3687. laWindow* cur=MAIN.CurrentWindow;
  3688. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3689. MAIN.CurrentWindow=w;
  3690. la_UpdateUiPlacement(w);
  3691. }
  3692. MAIN.CurrentWindow=cur;
  3693. }
  3694. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3695. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3696. }
  3697. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3698. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3699. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3700. void laRedrawCurrentPanel(){
  3701. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3702. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3703. }
  3704. void laRecalcCurrentPanel(){
  3705. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3706. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3707. }
  3708. void laRecalcPanelImmediate(laPanel* p){
  3709. p->FrameDistinguish++;
  3710. laBoxedTheme* bt = (*p->BT);
  3711. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3712. la_PanelRefreshDetachedProp(p);
  3713. int enclosed=0;
  3714. if(p->BoundUi || p->MenuRefer){
  3715. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3716. else enclosed=laEnclosePanelContent(p, &p->UI);
  3717. }
  3718. if(!enclosed){
  3719. la_PanelValidateWidth(p,&p->UI);
  3720. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3721. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3722. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3723. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3724. }
  3725. laWindow* w=MAIN.CurrentWindow;
  3726. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3727. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3728. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3729. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3730. }
  3731. }
  3732. void laRecalcCurrentPanelImmediate(){
  3733. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3734. }
  3735. int laNonFixedPanelExists(laPanel *p){
  3736. laPanel *ip;
  3737. if (!p) return 0;
  3738. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3739. // if (ip == p) return 1;
  3740. //}
  3741. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3742. if (ip == p) return 1;
  3743. }
  3744. return 0;
  3745. }
  3746. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3747. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3748. return 1;
  3749. }
  3750. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3751. int tt=MAIN.TooltipCloseDistance;
  3752. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3753. return 1;
  3754. }
  3755. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3756. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3757. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3758. return 0;
  3759. return 1;
  3760. }
  3761. void laUnlinkSharedPanel(laPanel *p){
  3762. laWindow *w;
  3763. laPanel *ip;
  3764. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3765. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3766. if (ip == p){
  3767. lstRemoveItem(&w->Panels, ip);
  3768. return;
  3769. }
  3770. }
  3771. }
  3772. }
  3773. int laIsPanelCovered(laPanel *p){
  3774. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3775. laPanel *ip;
  3776. laPanel *resp;
  3777. int in1 = 0, in2 = 0, in3 = 0;
  3778. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3779. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3780. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3781. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3782. //}
  3783. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3784. if (ip == p){
  3785. in3 = 1;
  3786. d3 = 0;
  3787. continue;
  3788. }
  3789. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3790. }
  3791. if (!in2 && !in3) in1 = 1;
  3792. if (in1){
  3793. if (d1 || d2 || d3) return 1;
  3794. }else{
  3795. if (in2){
  3796. if (d2 || d3) return 1;
  3797. }else if (in3)
  3798. if (d3) return 1;
  3799. }
  3800. return 0;
  3801. }
  3802. int laIsTopPanel(laPanel *p){
  3803. //if (!p->Item.pPrev) return 1;
  3804. //else {
  3805. if (!laIsPanelCovered(p)){
  3806. //laPopPanel(p);
  3807. return 1;
  3808. }
  3809. return 0;
  3810. //}
  3811. return 0;
  3812. }
  3813. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3814. if(!p) return;
  3815. int ix = *x, iy = *y;
  3816. laListItemPointer *lip;
  3817. laOperator *ai = a;
  3818. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3819. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3820. if (a){
  3821. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3822. laUiList *uil = lip->p;
  3823. (*x) += uil->PanX;
  3824. (*y) += uil->PanY;
  3825. }
  3826. }
  3827. }
  3828. void laPanelToLocal(laOperator *a, int *x, int *y){
  3829. int ix = *x, iy = *y;
  3830. laListItemPointer *lip;
  3831. if (a){
  3832. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3833. laUiList *uil = lip->p;
  3834. (*x) += uil->PanX;
  3835. (*y) += uil->PanY;
  3836. }
  3837. }
  3838. }
  3839. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3840. if(!p) return;
  3841. int ix = *x, iy = *y;
  3842. laListItemPointer *lip;
  3843. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3844. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3845. if (a){
  3846. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3847. laUiList *uil = lip->p;
  3848. (*x) -= uil->PanX;
  3849. (*y) -= uil->PanY;
  3850. }
  3851. }
  3852. }
  3853. void laPanelToWindow(laPanel *p, int *x, int *y){
  3854. int ix = *x, iy = *y;
  3855. laListItemPointer *lip;
  3856. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3857. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3858. }
  3859. void laLocalToPanel(laOperator *a, int *x, int *y){
  3860. int ix = *x, iy = *y;
  3861. laListItemPointer *lip;
  3862. if (a){
  3863. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3864. laUiList *uil = lip->p;
  3865. (*x) -= uil->PanX;
  3866. (*y) -= uil->PanY;
  3867. }
  3868. }
  3869. }
  3870. void laSetNextMenuPos(int X, int Y, int W, int H){
  3871. MAIN.NextX = X;
  3872. MAIN.NextY = Y;
  3873. MAIN.NextW = W;
  3874. MAIN.NextH = H;
  3875. }
  3876. int laIsInBlock(laBlock *b, int X, int Y){
  3877. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3878. return 0;
  3879. }
  3880. 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; }
  3881. 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; }
  3882. 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; }
  3883. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3884. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3885. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3886. if (!b->B1 && !b->B2){
  3887. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3888. }
  3889. }
  3890. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3891. laPanel *p;
  3892. laBlock *sb = 0;
  3893. if (!laIsInBlock(b, X, Y)) return 0;
  3894. if (!b->B1 && !b->B2) return b;
  3895. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3896. return laDetectBlockRecursive(b->B2, X, Y);
  3897. }
  3898. laPanel *laDetectPanel(int X, int Y){
  3899. laPanel *p; laBlock *b;
  3900. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3901. int x = X, y = Y;
  3902. laWindowToLocal(0, p, &x, &y);
  3903. if (p->Show && laIsInPanel(p, x, y)){
  3904. return p;
  3905. }
  3906. }
  3907. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3908. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3909. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3910. return 0;
  3911. }
  3912. laUiList *laPrepareUi(laPanel *p){
  3913. return &p->UI;
  3914. }
  3915. laColumn *laFirstColumn(laUiList *uil){
  3916. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3917. else{
  3918. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3919. c->SP = 1;
  3920. c->PreWidth = 1;
  3921. lstAppendItem(&uil->Columns, c);
  3922. c->Top = c;
  3923. return uil->Columns.pFirst;
  3924. }
  3925. }
  3926. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3927. laColumn *lc, *rc;
  3928. if (c->LS || c->RS) return c;
  3929. lc = memAcquireSimple(sizeof(laColumn));
  3930. rc = memAcquireSimple(sizeof(laColumn));
  3931. c->LS = lc;
  3932. c->RS = rc;
  3933. c->LS->SP = Percent;
  3934. c->RS->SP = Percent;
  3935. c->LS->Top = c->Top;
  3936. c->RS->Top = c->Top;
  3937. if (uil){
  3938. lstAppendItem(&uil->Columns, lc);
  3939. lstAppendItem(&uil->Columns, rc);
  3940. }
  3941. if (c->LS && c->RS->MaxW == 0){
  3942. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3943. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3944. }else if (c->RS && c->LS->MaxW == 0){
  3945. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3946. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3947. }
  3948. return c;
  3949. }
  3950. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3951. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3952. return c->LS;
  3953. }
  3954. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3955. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3956. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3957. return c->RS;
  3958. }
  3959. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3960. lstRemoveItem(List, c);
  3961. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3962. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3963. memFree(c);
  3964. }
  3965. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3966. laUiList *uil = TopUil;
  3967. laUiList *sub;
  3968. laUiItem *ui;
  3969. laColumn *cc, *NextCC = 0;
  3970. int Occupied = 0;
  3971. int Removed = 0;
  3972. if (!c->LS) return 0;
  3973. else{
  3974. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3975. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3976. }
  3977. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3978. if (ui->C == c->LS || ui->C == c->RS){
  3979. if (DoMerge){
  3980. ui->C = c;
  3981. Occupied = 1;
  3982. }else
  3983. return 1;
  3984. }
  3985. if (ui->Subs.pFirst){
  3986. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3987. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3988. }
  3989. }
  3990. }
  3991. if (!Removed){
  3992. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3993. if (cc == c){
  3994. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3995. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3996. c->LS = 0;
  3997. c->RS = 0;
  3998. Removed = 1;
  3999. break;
  4000. }
  4001. }
  4002. }
  4003. return Occupied;
  4004. }
  4005. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  4006. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  4007. ut->FakeProp = memAcquire(sizeof(laSubProp));
  4008. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  4009. ut->FakeProp->Base.Identifier = ut->Identifier;
  4010. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  4011. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  4012. ut->FakeProp->Base.OffsetIsPointer = 1;
  4013. //ut->FakeProp->Base.Container = ut->ExtraProps;
  4014. return ut->ExtraProps;
  4015. }
  4016. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  4017. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  4018. ct->FakeProp = memAcquire(sizeof(laSubProp));
  4019. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  4020. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  4021. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  4022. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  4023. ct->FakeProp->Base.OffsetIsPointer = 1;
  4024. //ut->FakeProp->Base.Container = ut->ExtraProps;
  4025. return ct->ExtraProps;
  4026. }
  4027. void la_DestroyUiType(laUiType* uit){
  4028. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4029. memFree(uit);
  4030. }
  4031. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  4032. laUiType *ut = memAcquire(sizeof(laUiType));
  4033. ut->Identifier = Identifer;
  4034. ut->OperatorID = UseOperator;
  4035. ut->Draw = Draw;
  4036. ut->Theme = bt;
  4037. ut->ForType = ForType;
  4038. ut->OperatorType = laGetOperatorType(UseOperator);
  4039. ut->GetHeight = GetHeight;
  4040. ut->Init = Init;
  4041. ut->Destroy = Destroy;
  4042. la_UDFAppendSharedTypePointer(Identifer, ut);
  4043. lstAppendItem(&MAIN.UiTypes, ut);
  4044. return ut;
  4045. }
  4046. laUiType *la_GetUiTypeFromProperty(laProp *P){
  4047. laUiType *ut = MAIN.UiTypes.pFirst;
  4048. if (!P) return 0;
  4049. if (P->DefaultUiType) return P->DefaultUiType;
  4050. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  4051. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  4052. for (ut; ut; ut = ut->Item.pNext){
  4053. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  4054. return ut;
  4055. }
  4056. }
  4057. return 0;
  4058. }
  4059. laUiType *la_GetUiButtonType(){
  4060. laUiType *ut = MAIN.UiTypes.pFirst;
  4061. for (ut; ut; ut = ut->Item.pNext){
  4062. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  4063. }
  4064. return 0;
  4065. }
  4066. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  4067. laCanvasTemplate *vdt;
  4068. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  4069. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  4070. }
  4071. return 0;
  4072. }
  4073. void la_AssignPropExtras(laUiItem* ui){
  4074. if(!ui->Type || !ui->Type->FakeProp) return;
  4075. ui->FakePs.p = ui->Type->FakeProp;
  4076. ui->FakePs.Type = U'.';
  4077. ui->FakePs.UseInstance = ui;
  4078. ui->ExtraPP.LastPs = &ui->FakePs;
  4079. }
  4080. void la_AssignCanvasPropExtras(laUiItem* ui){
  4081. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  4082. laCanvasTemplate*ct=ui->CanvasTemplate;
  4083. ui->FakePs.p = ct->FakeProp;
  4084. ui->FakePs.Type = U'.';
  4085. ui->FakePs.UseInstance = ui;
  4086. ui->ExtraPP.EndInstance = ui->Extra;
  4087. ui->ExtraPP.LastPs = &ui->FakePs;
  4088. }
  4089. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  4090. int result;
  4091. if (!ui) return 0;
  4092. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  4093. if (Path){
  4094. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4095. if (!result){
  4096. ui->AT = laGetOperatorType(Path);
  4097. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  4098. ui->Type = la_GetUiButtonType();
  4099. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  4100. }else{
  4101. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4102. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4103. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  4104. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4105. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4106. }
  4107. if (Base){
  4108. ui->PP.RawThis = Base;
  4109. }
  4110. }else if (Base){
  4111. ui->PP.LastPs = Base->LastPs;
  4112. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  4113. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  4114. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  4115. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  4116. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4117. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  4118. }
  4119. la_AssignPropExtras(ui);
  4120. if(Widget){ ui->Flags|= Widget->Flags; }
  4121. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  4122. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  4123. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4124. return ui;
  4125. }
  4126. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  4127. ui->Type = _LA_UI_LABEL;
  4128. ui->Template = Template;
  4129. ui->State = LA_UI_NORMAL;
  4130. strSafeSet(&ui->Display, Content);
  4131. la_AssignPropExtras(ui);
  4132. return ui;
  4133. }
  4134. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  4135. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4136. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  4137. ui->State = LA_UI_NORMAL;
  4138. la_AssignPropExtras(ui);
  4139. return ui;
  4140. }
  4141. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4142. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4143. transLate(Content);
  4144. la_UpdateLabelDisplay(ui, Template, Content);
  4145. ui->C = c;
  4146. if (ui->Type->Init) ui->Type->Init(ui);
  4147. ui->ExtraPP.EndInstance = ui->Extra;
  4148. lstAppendItem(&uil->UiItems, ui);
  4149. return ui;
  4150. }
  4151. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  4152. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4153. la_UpdateLabelDisplay(ui, Template, Content);
  4154. ui->C = c;
  4155. if (ui->Type->Init) ui->Type->Init(ui);
  4156. ui->ExtraPP.EndInstance = ui->Extra;
  4157. lstAppendItem(&uil->UiItems, ui);
  4158. return ui;
  4159. }
  4160. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  4161. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4162. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  4163. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  4164. ui->C = c;
  4165. if (ui->Type->Init) ui->Type->Init(ui);
  4166. ui->ExtraPP.EndInstance = ui->Extra;
  4167. lstAppendItem(&uil->UiItems, ui);
  4168. return ui;
  4169. }
  4170. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4171. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  4172. }
  4173. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  4174. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  4175. }
  4176. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4177. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4178. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4179. ui->C = c;
  4180. ui->TemplateContext = TemplateContext;
  4181. if (ui->Type->Init) ui->Type->Init(ui);
  4182. ui->ExtraPP.EndInstance = ui->Extra;
  4183. lstAppendItem(&uil->UiItems, ui);
  4184. return ui;
  4185. }
  4186. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4187. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4188. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4189. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4190. ui->SymbolID=Height;
  4191. lstAppendItem(&uil->UiItems, ui);
  4192. return ui;
  4193. }
  4194. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4195. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4196. }
  4197. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4198. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4199. }
  4200. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4201. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4202. ui->Type = _LA_UI_CANVAS;
  4203. ui->State = LA_UI_NORMAL;
  4204. ui->C = c;
  4205. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4206. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4207. else{
  4208. 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); }
  4209. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4210. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4211. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4212. }
  4213. if (ui->Type->Init) ui->Type->Init(ui);
  4214. la_AssignCanvasPropExtras(ui);
  4215. if (Height) ui->Expand=Height; else ui->Expand=6;
  4216. lstAppendItem(&uil->UiItems, ui);
  4217. return ui;
  4218. }
  4219. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4220. laUiItem* ui=0;
  4221. #define ADD_CANVAS \
  4222. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4223. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4224. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4225. }laEndCondition(uil,b3);\
  4226. laEndRow(uil,b);
  4227. if(Detached){
  4228. laColumn* cl,*cll,*clr,*cr;
  4229. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4230. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4231. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4232. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4233. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4234. ADD_CANVAS
  4235. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4236. }laElse(uil,b2);{
  4237. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4238. ADD_CANVAS
  4239. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4240. }laEndCondition(uil,b2);
  4241. }else{
  4242. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4243. }
  4244. #undef ADD_CANVAS
  4245. }
  4246. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4247. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4248. laCanvasExtra *e;
  4249. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4250. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4251. ui->C = c;
  4252. if (ui->Type->Init) ui->Type->Init(ui);
  4253. ui->ExtraPP.EndInstance = ui->Extra;
  4254. lstAppendItem(&uil->UiItems, ui);
  4255. return ui;
  4256. }
  4257. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4258. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4259. ui->Type = _LA_UI_SYMBOL;
  4260. ui->SymbolID = SymbolID;
  4261. if (Height) ui->State = Height;
  4262. ui->C = c;
  4263. if (ui->Type->Init) ui->Type->Init(ui);
  4264. ui->ExtraPP.EndInstance = ui->Extra;
  4265. lstAppendItem(&uil->UiItems, ui);
  4266. return ui;
  4267. }
  4268. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4269. laPropPack PP={0}; int result;
  4270. if (Path){
  4271. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4272. if (!result){ return 0; }
  4273. if (Base){ PP.RawThis = Base; }
  4274. }else if (Base){
  4275. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4276. }
  4277. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4278. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4279. lstAppendItem(&ui->CompoundPPs,CPP);
  4280. return &CPP->PP;
  4281. }
  4282. laUiItem *laShowMouseActionReporter(laUiList* uil, laColumn* c, int Height, const char* Display, const char* instructions){
  4283. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4284. ui->C = c;
  4285. ui->Type=_LA_UI_MOUSE_ACTION_REPORTER;
  4286. ui->State=Height; if(!ui->State){ ui->State=1; }
  4287. if(Display) strSafeSet(&ui->Display, Display);
  4288. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  4289. lstAppendItem(&uil->UiItems, ui);
  4290. return ui;
  4291. }
  4292. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4293. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4294. ui->Type = &_LA_UI_ROW_BEGIN;
  4295. ui->State=Expand;
  4296. ui->Flags=Even;
  4297. ui->C = c;
  4298. if (ui->Type->Init) ui->Type->Init(ui);
  4299. ui->ExtraPP.EndInstance = ui->Extra;
  4300. lstAppendItem(&uil->UiItems, ui);
  4301. return ui;
  4302. }
  4303. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4304. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4305. ui->Type = &_LA_UI_ROW_END;
  4306. ui->C = Begin->C;
  4307. ui->Page = (laUiList*)Begin;
  4308. if (ui->Type->Init) ui->Type->Init(ui);
  4309. ui->ExtraPP.EndInstance = ui->Extra;
  4310. lstAppendItem(&uil->UiItems, ui);
  4311. return ui;
  4312. }
  4313. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4314. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4315. e->Expression = Expression;
  4316. ui->Extra = e;
  4317. la_AssignPropExtras(ui);
  4318. }
  4319. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4320. laUiItem *ui = la_CreateGroupHandle(Widget);
  4321. laUiList *nuil;
  4322. ui->C = c;
  4323. lstAppendItem(&uil->UiItems, ui);
  4324. nuil = memAcquireSimple(sizeof(laUiList));
  4325. strSafeSet(&nuil->TabName, Name);
  4326. ui->Page = nuil;
  4327. lstAppendItem(&ui->Subs, nuil);
  4328. if (ui->Type->Init) ui->Type->Init(ui);
  4329. ui->ExtraPP.EndInstance = ui->Extra;
  4330. return ui;
  4331. }
  4332. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4333. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4334. laUiList *sub = SubUi->Page;
  4335. laColumn *s = laFirstColumn(sub);
  4336. SubUi->State = LA_UI_ACTIVE;
  4337. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4338. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4339. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4340. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4341. laShowSeparator(sub, s);
  4342. return SubUi;
  4343. }
  4344. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4345. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4346. laUiList *sub = SubUi->Page;
  4347. laColumn *s = laFirstColumn(sub);
  4348. SubUi->State = LA_UI_ACTIVE;
  4349. return SubUi;
  4350. }
  4351. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4352. laEndCondition(sub, sub->UiItems.pFirst);
  4353. }
  4354. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4355. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4356. laUiList *nuil;
  4357. ui->C = c;
  4358. lstAppendItem(&uil->UiItems, ui);
  4359. if (ui->Type->Init) ui->Type->Init(ui);
  4360. ui->ExtraPP.EndInstance = ui->Extra;
  4361. return ui;
  4362. }
  4363. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4364. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4365. if (!ui->Page) ui->Page = uil;
  4366. lstAppendItem(&ui->Subs, uil);
  4367. strSafeSet(&uil->TabName, Name);
  4368. laFirstColumn(uil);
  4369. //laFirstColumn(uil);
  4370. return uil;
  4371. }
  4372. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4373. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4374. /*if (!ui->Page) */ ui->Page = uil;
  4375. lstAppendItem(&ui->Subs, uil);
  4376. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4377. return uil;
  4378. }
  4379. laUiConditionNode *laTrue(){
  4380. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4381. ucn->Type = LA_CONDITION_TRUE;
  4382. return ucn;
  4383. }
  4384. laUiConditionNode *laFalse(){
  4385. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4386. ucn->Type = LA_CONDITION_FALSE;
  4387. return ucn;
  4388. }
  4389. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4390. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4391. ucn->Type = LA_CONDITION_PROP;
  4392. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4393. strSafeSet(&ucn->String, Prop);
  4394. return ucn;
  4395. }
  4396. laUiConditionNode *laIntExpression(int Value){
  4397. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4398. ucn->Type = LA_CONDITION_INT;
  4399. ucn->IntValue = Value;
  4400. return ucn;
  4401. }
  4402. laUiConditionNode *laFloatExpression(real Value){
  4403. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4404. ucn->Type = LA_CONDITION_FLOAT;
  4405. ucn->FloatValue = Value;
  4406. return ucn;
  4407. }
  4408. laUiConditionNode *laStringExpression(char *Content){
  4409. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4410. ucn->Type = LA_CONDITION_STRING;
  4411. strSafeSet(&ucn->String, Content);
  4412. return ucn;
  4413. }
  4414. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4415. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4416. ucn->Type = LA_CONDITION_AND;
  4417. ucn->Expression1 = Expression1;
  4418. ucn->Expression2 = Expression2;
  4419. return ucn;
  4420. }
  4421. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4422. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4423. ucn->Type = LA_CONDITION_OR;
  4424. ucn->Expression1 = Expression1;
  4425. ucn->Expression2 = Expression2;
  4426. return ucn;
  4427. }
  4428. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4429. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4430. ucn->Type = LA_CONDITION_NOT;
  4431. ucn->Expression1 = Expression1;
  4432. return ucn;
  4433. }
  4434. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4435. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4436. ucn->Type = LA_CONDITION_EQ;
  4437. ucn->Expression1 = Expression1;
  4438. ucn->Expression2 = Expression2;
  4439. return ucn;
  4440. }
  4441. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4442. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4443. ucn->Type = LA_CONDITION_GT;
  4444. ucn->Expression1 = Expression1;
  4445. ucn->Expression2 = Expression2;
  4446. return ucn;
  4447. }
  4448. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4449. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4450. ucn->Type = LA_CONDITION_LT;
  4451. ucn->Expression1 = Expression1;
  4452. ucn->Expression2 = Expression2;
  4453. return ucn;
  4454. }
  4455. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4456. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4457. ucn->Type = LA_CONDITION_GE;
  4458. ucn->Expression1 = Expression1;
  4459. ucn->Expression2 = Expression2;
  4460. return ucn;
  4461. }
  4462. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4463. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4464. ucn->Type = LA_CONDITION_LE;
  4465. ucn->Expression1 = Expression1;
  4466. ucn->Expression2 = Expression2;
  4467. return ucn;
  4468. }
  4469. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4470. if (Expression->Type != LA_CONDITION_INT) return 0;
  4471. return Expression->IntValue;
  4472. }
  4473. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4474. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4475. return Expression->FloatValue;
  4476. }
  4477. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4478. return Expression->String->Ptr;
  4479. }
  4480. 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){
  4481. switch (Mode1){
  4482. case LA_PROP_ENUM:
  4483. case LA_PROP_INT:
  4484. case LA_CONDITION_INT:
  4485. switch (Mode2){
  4486. case LA_PROP_ENUM:
  4487. case LA_PROP_INT:
  4488. case LA_CONDITION_INT:
  4489. switch (CompMode){
  4490. case LA_CONDITION_GE:
  4491. return (i1 >= i2);
  4492. case LA_CONDITION_GT:
  4493. return (i1 > i2);
  4494. case LA_CONDITION_EQ:
  4495. return (i1 == i2);
  4496. case LA_CONDITION_LT:
  4497. return (i1 < i2);
  4498. case LA_CONDITION_LE:
  4499. return (i1 <= i2);
  4500. }
  4501. case LA_PROP_FLOAT:
  4502. case LA_CONDITION_FLOAT:
  4503. switch (CompMode){
  4504. case LA_CONDITION_GE:
  4505. return ((real)i1 >= f2);
  4506. case LA_CONDITION_GT:
  4507. return ((real)i1 > f2);
  4508. case LA_CONDITION_EQ:
  4509. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4510. case LA_CONDITION_LT:
  4511. return ((real)i1 < f2);
  4512. case LA_CONDITION_LE:
  4513. return ((real)i1 <= f2);
  4514. }
  4515. case LA_PROP_SUB:
  4516. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4517. default:
  4518. return 0;
  4519. }
  4520. case LA_PROP_FLOAT:
  4521. case LA_CONDITION_FLOAT:
  4522. switch (Mode2){
  4523. case LA_PROP_INT:
  4524. case LA_PROP_ENUM:
  4525. case LA_CONDITION_INT:
  4526. switch (CompMode){
  4527. case LA_CONDITION_GE:
  4528. return (f1 >= (real)i2);
  4529. case LA_CONDITION_GT:
  4530. return (f1 > (real)i2);
  4531. case LA_CONDITION_EQ:
  4532. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4533. case LA_CONDITION_LT:
  4534. return (f1 < (real)i2);
  4535. case LA_CONDITION_LE:
  4536. return (f1 <= (real)i2);
  4537. }
  4538. case LA_PROP_FLOAT:
  4539. case LA_CONDITION_FLOAT:
  4540. switch (CompMode){
  4541. case LA_CONDITION_GE:
  4542. return (f1 >= f2);
  4543. case LA_CONDITION_GT:
  4544. return (f1 > f2);
  4545. case LA_CONDITION_EQ:
  4546. return (f1 == f2);
  4547. case LA_CONDITION_LT:
  4548. return (f1 < f2);
  4549. case LA_CONDITION_LE:
  4550. return (f1 <= f2);
  4551. }
  4552. default:
  4553. return 0;
  4554. }
  4555. case LA_PROP_STRING:
  4556. case LA_CONDITION_STRING:
  4557. switch (Mode2){
  4558. case LA_PROP_STRING:
  4559. case LA_CONDITION_STRING:
  4560. return strSame(s1, s2);
  4561. default:
  4562. return 0;
  4563. }
  4564. case LA_PROP_SUB:
  4565. switch (Mode2){
  4566. case LA_PROP_SUB:
  4567. return p1 == p2;
  4568. case LA_CONDITION_INT:
  4569. case LA_PROP_INT:
  4570. case LA_PROP_ENUM:
  4571. return (int)p1 == i2;
  4572. default:
  4573. return 0;
  4574. }
  4575. default:
  4576. switch (CompMode){
  4577. case LA_CONDITION_GE:
  4578. return (i1 >= i2);
  4579. case LA_CONDITION_GT:
  4580. return (i1 > i2);
  4581. case LA_CONDITION_EQ:
  4582. return (i1 == i2);
  4583. case LA_CONDITION_LT:
  4584. return (i1 < i2);
  4585. case LA_CONDITION_LE:
  4586. return (i1 <= i2);
  4587. }
  4588. }
  4589. }
  4590. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4591. void *Instance = 0;
  4592. int IValue1 = 0, IValue2 = 0;
  4593. real FValue1 = 0, FValue2 = 0;
  4594. void *Ptr1 = 0, *Ptr2 = 0;
  4595. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4596. int Result1, Result2;
  4597. laEnumItem *ei; laSubProp*sp;
  4598. if (!Expression) return 0;
  4599. Str1[0] = 0;
  4600. Str2[0] = 0;
  4601. laPropIterator pi = {0};
  4602. switch (Expression->Type){
  4603. case LA_CONDITION_PROP:
  4604. if (!Expression->PP.LastPs){
  4605. (*IResult) = 0;
  4606. return 0;
  4607. }
  4608. switch (Expression->PP.LastPs->p->PropertyType){
  4609. case LA_PROP_INT:
  4610. *IResult = laGetInt(&Expression->PP);
  4611. if (*IResult) return LA_CONDITION_INT;
  4612. else return 0;
  4613. case LA_PROP_FLOAT:
  4614. *FResult = laGetFloat(&Expression->PP);
  4615. if (*FResult) return 1;
  4616. else return 0;
  4617. break;
  4618. case LA_PROP_STRING:
  4619. laGetString(&Expression->PP, _StrResult, &StrResult);
  4620. if (StrResult[0]) return 1;
  4621. else return 0;
  4622. break;
  4623. case LA_PROP_ENUM:
  4624. ei = laGetEnum(&Expression->PP);
  4625. if (!ei) return 0;
  4626. /*if(ei) */ *IResult = ei->Index;
  4627. if (*IResult) return LA_CONDITION_INT;
  4628. else return 0;
  4629. break;
  4630. case LA_PROP_SUB:
  4631. sp=Expression->PP.LastPs->p;
  4632. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4633. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4634. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4635. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4636. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4637. }
  4638. }
  4639. *PtrResult = Instance;
  4640. if (Instance) return 1;
  4641. break;
  4642. default:
  4643. return 0;
  4644. }
  4645. break;
  4646. case LA_CONDITION_INT:
  4647. *IResult = Expression->IntValue;
  4648. if (*IResult) return 1;
  4649. else
  4650. return 0;
  4651. case LA_CONDITION_FLOAT:
  4652. *FResult = Expression->FloatValue;
  4653. if (*FResult) return 1;
  4654. else
  4655. return 0;
  4656. case LA_CONDITION_STRING:
  4657. if (Expression->String){
  4658. strCopyFull(StrResult, Expression->String->Ptr);
  4659. return 1;
  4660. }else
  4661. return 0;
  4662. case LA_CONDITION_TRUE:
  4663. if (*IResult) *IResult = 1;
  4664. return 1;
  4665. case LA_CONDITION_FALSE:
  4666. if (*IResult) *IResult = 0;
  4667. return 0;
  4668. default:
  4669. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4670. switch (Expression->Type){
  4671. case LA_CONDITION_AND:
  4672. if (Result1){
  4673. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4674. if (Result2) *IResult = 1;
  4675. return (Result2);
  4676. }else
  4677. return 0;
  4678. case LA_CONDITION_OR:
  4679. if (!Result1){
  4680. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4681. if (Result2) *IResult = 1;
  4682. return (Result2);
  4683. }else
  4684. return 1;
  4685. case LA_CONDITION_NOT:
  4686. return !Result1;
  4687. default:
  4688. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4689. return la_DoCompare(Expression->Type,
  4690. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4691. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4692. }
  4693. break;
  4694. }
  4695. return 0;
  4696. }
  4697. int la_DoSingleExpression(laUiConditionNode *Expression){
  4698. int a;
  4699. real b;
  4700. char c[128]={0};
  4701. void *p;
  4702. if (!Expression) return 1;
  4703. c[0] = 0;
  4704. return la_DoExpression(Expression, &a, &b, c, &p);
  4705. }
  4706. void la_StepExpression(laUiConditionNode *e){
  4707. if (!e) return;
  4708. switch (e->Type){
  4709. case LA_CONDITION_AND:
  4710. case LA_CONDITION_OR:
  4711. case LA_CONDITION_GE:
  4712. case LA_CONDITION_GT:
  4713. case LA_CONDITION_EQ:
  4714. case LA_CONDITION_LT:
  4715. case LA_CONDITION_LE:
  4716. la_StepExpression(e->Expression1);
  4717. la_StepExpression(e->Expression2);
  4718. break;
  4719. case LA_CONDITION_NOT:
  4720. la_StepExpression(e->Expression1);
  4721. break;
  4722. case LA_CONDITION_PROP:
  4723. la_StepPropPack(&e->PP);
  4724. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4725. la_UsePropPack(&e->PP, 1);
  4726. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4727. //}
  4728. break;
  4729. default:
  4730. break;
  4731. }
  4732. }
  4733. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4734. if (!ucn) return;
  4735. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4736. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4737. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4738. if (ucn->String) strSafeDestroy(&ucn->String);
  4739. if (ucn) memFree(ucn);
  4740. }
  4741. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4742. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4743. ui->C = c;
  4744. ui->Type = &_LA_UI_CONDITION;
  4745. la_ConditionerInit(ui, Expression);
  4746. lstAppendItem(&uil->UiItems, ui);
  4747. return ui;
  4748. }
  4749. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4750. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4751. laConditionUiExtraData *cued;
  4752. ui->Type = &_LA_UI_CONDITION_ELSE;
  4753. la_ConditionerInit(ui, 0);
  4754. cued = ui->Extra;
  4755. cued->EndUi = Beginner;
  4756. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4757. ui->C = Beginner->C;
  4758. lstAppendItem(&uil->UiItems, ui);
  4759. return ui;
  4760. }
  4761. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4762. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4763. laConditionUiExtraData *cued;
  4764. ui->Template = define;
  4765. ui->C = col;
  4766. ui->PP.RawThis = ExtraBase;
  4767. ui->Page = ExtraThis;
  4768. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4769. la_ConditionerInit(ui, 0);
  4770. cued = ui->Extra;
  4771. //cued->Remove = Remove;
  4772. ui->State = LA_UI_NORMAL;
  4773. lstAppendItem(&uil->UiItems, ui);
  4774. return ui;
  4775. }
  4776. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4777. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4778. laConditionUiExtraData *cued;
  4779. ui->Type = &_LA_UI_CONDITION_END;
  4780. la_ConditionerInit(ui, 0);
  4781. cued = ui->Extra;
  4782. cued->EndUi = Beginner;
  4783. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4784. ui->C = Beginner->C;
  4785. lstAppendItem(&uil->UiItems, ui);
  4786. return ui;
  4787. }
  4788. laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags) {
  4789. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4790. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4791. ui->Type = _LA_UI_MENU_ROOT;
  4792. strSafeSet(&ui->Display, Title);
  4793. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4794. ui->C = c;
  4795. ui->Flags|=flags;
  4796. lstAppendItem(&uil->UiItems, ui);
  4797. muil->Flags|=flags;
  4798. lstAppendItem(&ui->Subs, muil);
  4799. return muil;
  4800. }
  4801. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4802. return laMakeMenuPageEx(uil,c,Title,0);
  4803. }
  4804. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4805. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4806. ui->Type = _LA_UI_ALIGN;
  4807. ui->C = widest;
  4808. lstAppendItem(&uil->UiItems, ui);
  4809. return ui;
  4810. }
  4811. void laFixHeight(laUiList *uil, short Rows){
  4812. if (!uil) return;
  4813. uil->HeightCoeff = Rows;
  4814. }
  4815. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4816. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4817. if (!ExtraColumns) return;
  4818. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4819. }
  4820. laUiTemplate *laFindUiTemplate(char *Identifier){
  4821. laUiTemplate *uit;
  4822. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4823. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4824. }
  4825. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4826. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4827. }
  4828. return 0;
  4829. }
  4830. void la_DestroyUiTemplate(laUiTemplate* uit){
  4831. strSafeDestroy(&uit->Identifier);
  4832. strSafeDestroy(&uit->Title);
  4833. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4834. memFree(uit);
  4835. }
  4836. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4837. strSafeDestroy(&uit->Identifier);
  4838. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4839. memFree(uit);
  4840. }
  4841. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4842. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4843. strSafeSet(&uit->Identifier, Identifier);
  4844. strSafeSet(&uit->Title, Title);
  4845. strSafeSet(&uit->CategoryName, NewCategory);
  4846. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4847. uit->DefaultGLFormat=DefaultGLFormat;
  4848. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4849. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4850. la_UDFAppendSharedTypePointer(Identifier, uit);
  4851. return uit;
  4852. }
  4853. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4854. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4855. strSafeSet(&t->Identifier, Identifier);
  4856. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4857. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4858. lstAppendItem(&MAIN.View2DTemplates, t);
  4859. la_UDFAppendSharedTypePointer(Identifier, t);
  4860. return t;
  4861. }
  4862. void laFinalizeUiTemplates(){
  4863. laUiTemplate *uit;
  4864. laCanvasTemplate *u2d;
  4865. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4866. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4867. }
  4868. }
  4869. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4870. laPanel *p;
  4871. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4872. if (p->PanelTemplate==uit){
  4873. return p;
  4874. }
  4875. }
  4876. return 0;
  4877. }
  4878. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4879. laUiList *uil, *NextUil;
  4880. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4881. NextUil = uil->Item.pNext;
  4882. lstRemoveItem(&ui->Subs, uil);
  4883. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4884. }
  4885. la_StopUiOperatorService(ui);
  4886. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4887. strSafeDestroy(&ui->Display);
  4888. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4889. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4890. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4891. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4892. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4893. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4894. }
  4895. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4896. memFree(ui);
  4897. }
  4898. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4899. laUiItem *ui, *NextUi;
  4900. laColumn *col, *NextCol;
  4901. if (!uil) return;
  4902. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4903. NextUi = ui->Item.pNext;
  4904. if(OnlyRemoveUser && RemoveUsers){
  4905. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4906. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4907. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4908. continue;
  4909. }
  4910. lstRemoveItem(&uil->UiItems, ui);
  4911. la_DestroyUiItem(ui, RemoveUsers);
  4912. }
  4913. if(OnlyRemoveUser){ return; }
  4914. for (col = uil->Columns.pFirst; col; col = NextCol){
  4915. NextCol = col->Item.pNext;
  4916. lstRemoveItem(&uil->Columns, col);
  4917. memFree(col);
  4918. }
  4919. strSafeDestroy(&uil->TabName);
  4920. if (!NoFree) memFree(uil);
  4921. }
  4922. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4923. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4924. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4925. }
  4926. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4927. laUiItem *Next = after->Item.pNext;
  4928. laUiItem *Last = uil->UiItems.pLast;
  4929. after->Item.pNext = 0;
  4930. uil->UiItems.pLast = after;
  4931. Define(uil, Base, This, ExtraColums, 0);
  4932. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4933. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4934. if (Next != Last) uil->UiItems.pLast = Last;
  4935. }
  4936. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4937. // int i = 0;
  4938. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4939. // if (!ui->ExtraColums) return;
  4940. // for (i; ui->ExtraColums[i]; i++) {
  4941. // laColumn* c = ui->ExtraColums[i];
  4942. // c->B = B;
  4943. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4944. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4945. // }
  4946. //}
  4947. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4948. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4949. }
  4950. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4951. laColumn *c = ui->C;
  4952. laColumn *ic = lst->pFirst;
  4953. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4954. for (ic; ic; ic = ic->Item.pNext){
  4955. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4956. ic->B = ic->B < c->B ? c->B : ic->B;
  4957. }
  4958. }
  4959. ic = ui->C;
  4960. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4961. ;
  4962. for (ic; ic; ic = ic->Item.pNext){
  4963. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4964. ic->B = ic->B < c->B ? c->B : ic->B;
  4965. }
  4966. }
  4967. }
  4968. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4969. laColumn *c = ui->C;
  4970. laColumn *ic = lst->pFirst;
  4971. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4972. for (ic; ic; ic = ic->Item.pNext){
  4973. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4974. ic->B = ic->B < c->B ? c->B : ic->B;
  4975. }
  4976. }
  4977. ic = ui->C;
  4978. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4979. ;
  4980. for (ic; ic; ic = ic->Item.pNext){
  4981. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4982. ic->B = ic->B < c->B ? c->B : ic->B;
  4983. }
  4984. }
  4985. }
  4986. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4987. int rep;
  4988. int sp;
  4989. int rev;
  4990. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4991. if (!c) return 0;
  4992. sp = (c->SP * (R - L)) + L;
  4993. rev = sp;
  4994. /*if (U)*/ c->B = U;
  4995. if (LR == 1){
  4996. c->IL = L;
  4997. c->IR = sp;
  4998. if (repos){
  4999. c->IR = repos;
  5000. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  5001. c->IR = c->IL + c->MaxW*LA_RH+M;
  5002. rev = c->IR;
  5003. }
  5004. }else if (LR == 2){
  5005. c->IL = sp;
  5006. c->IR = R;
  5007. if (repos){
  5008. c->IL = repos;
  5009. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  5010. c->IL = c->IR - c->MaxW*LA_RH-M;
  5011. rev = c->IL;
  5012. }
  5013. }else if (LR == 0){
  5014. c->IL = L;
  5015. c->IR = R;
  5016. }
  5017. if (c->LS && c->RS->MaxW == 0){
  5018. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  5019. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  5020. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  5021. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  5022. }else if (c->RS && c->LS->MaxW == 0){
  5023. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  5024. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  5025. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  5026. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  5027. }
  5028. return rev;
  5029. }
  5030. STRUCTURE(laRowInfo){
  5031. int MaxW;
  5032. int MinW;
  5033. int UnitMinW;
  5034. int NonExpandW;
  5035. int TotalPadding;
  5036. int Expand, Even;
  5037. int ExpandAccum;
  5038. int CountElements;
  5039. int U,MaxB,L;
  5040. laListHandle Elements;
  5041. int LastNoHeight;
  5042. };
  5043. STRUCTURE(laRowNode){
  5044. laListItem Item;
  5045. laUiItem* ui;
  5046. int GotW, LP, RP, H;
  5047. int Expand;
  5048. int UseLast;
  5049. int WaitAnimation;
  5050. };
  5051. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  5052. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  5053. ri->UnitMinW=LA_RH;
  5054. ri->Expand=ui->State?1:0;
  5055. ri->Even=ui->Flags?1:0;
  5056. ri->U=ui->TU; ri->L=ui->TL;
  5057. ri->MaxB=ui->TU;
  5058. }
  5059. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  5060. laRowNode* rn=CreateNew(laRowNode);
  5061. rn->LP=bt->LP;rn->RP=bt->RP;
  5062. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  5063. rn->ui=ui;
  5064. rn->H=H;
  5065. rn->Expand=ui->Expand;
  5066. rn->WaitAnimation=WaitAnimation;
  5067. lstAppendItem(&ri->Elements, rn);
  5068. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  5069. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  5070. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  5071. ri->TotalPadding += (bt->LP+bt->RP);
  5072. ri->MinW+=ri->UnitMinW;
  5073. ri->NonExpandW+=rn->GotW;
  5074. ri->ExpandAccum+=ui->Expand;
  5075. ri->CountElements++;
  5076. if(ui->Expand){ri->Expand=1;}
  5077. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  5078. }
  5079. int la_ShrinkableRowElements(laRowInfo* ri){
  5080. int count=0;
  5081. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5082. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  5083. count++;
  5084. }
  5085. return count;
  5086. }
  5087. void la_RecordSocketRuntimePosition(laUiItem* ui);
  5088. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  5089. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  5090. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  5091. if(Available<0){
  5092. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  5093. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  5094. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  5095. }else{
  5096. if(!ri->Expand && Available>0){Available=0;}
  5097. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  5098. }
  5099. if(!ShareCount) return 0;
  5100. int PerNode = Available/ShareCount;
  5101. int Remaining = Available-PerNode*ShareCount;
  5102. int L = ri->L; int i=0; laRowNode* rn;
  5103. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  5104. laUiItem* ui=rn->ui;
  5105. int NodeAdd, Node=rn->GotW;
  5106. if(rn->UseLast){
  5107. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  5108. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  5109. continue;
  5110. }
  5111. if(Available>=0){
  5112. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  5113. NodeAdd+=(i<Remaining?1:0);i++;
  5114. }else{
  5115. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  5116. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  5117. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  5118. }else{ Node=ri->UnitMinW;
  5119. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  5120. }
  5121. }
  5122. ui->TL = L + rn->LP;
  5123. ui->TR = ui->TL + Node+NodeAdd;
  5124. ui->TB = ui->TU + rn->H;
  5125. L=ui->TR+rn->RP;
  5126. if (!rn->WaitAnimation){
  5127. ui->L = ui->TL; ui->R = ui->TR;
  5128. ui->U = ui->TU; ui->B = ui->TB;
  5129. }
  5130. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5131. }
  5132. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  5133. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  5134. memset(ri, 0, sizeof(laRowInfo));
  5135. }
  5136. void la_RecordSocketRuntimePosition(laUiItem* ui){
  5137. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5138. int sl,sr,su,sb;
  5139. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  5140. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  5141. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  5142. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  5143. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  5144. if(pc==LA_PC_SOCKET_OUT){
  5145. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5146. }else{
  5147. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  5148. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  5149. }
  5150. }
  5151. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  5152. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  5153. }
  5154. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  5155. int laget_Hyper2InstanceModified(void* instance){
  5156. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  5157. if(level==2){
  5158. laManagedUDF* mu=m->FromFile;
  5159. int not_assigned = (!mu) || mu==MAIN.DummyManageUDF|| mu==MAIN.DummyManageUDFSingle || mu==MAIN.DummyManageUDFSingleForce;
  5160. return (m->Modified||not_assigned)?1:0;
  5161. }
  5162. return 1;
  5163. }
  5164. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  5165. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  5166. laBoxedTheme *bt;
  5167. int Lowest = 0;
  5168. int HyperValue = 0;
  5169. int WaitAnimation;
  5170. int RowMode=0; laRowInfo ri={0};
  5171. laBoxedTheme* pt=*(ParentPanel->BT);
  5172. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  5173. int MaxR=0;
  5174. if(!uil->Scale){uil->Scale=1;}
  5175. uil->SaveScale=MAIN.UiScale;
  5176. MAIN.UiScale*=uil->Scale;
  5177. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5178. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  5179. WaitAnimation = 0;
  5180. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  5181. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  5182. for (ui = uil->UiItems.pFirst; ui;){
  5183. int SubB = 0;
  5184. int H;
  5185. WaitAnimation = 0;
  5186. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5187. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  5188. //if (Fast && ui->C->B > B) {
  5189. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  5190. // ui = ui->Item.pNext;
  5191. // continue;
  5192. //}
  5193. if (!ui->Instructions){
  5194. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  5195. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  5196. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  5197. laOperatorProp *ap = ui->PP.LastPs->p;
  5198. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  5199. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5200. }
  5201. }
  5202. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5203. la_UsePropPack(&ui->PP, 0);
  5204. if (ui->CompoundPPs.pFirst){
  5205. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5206. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5207. }
  5208. }
  5209. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5210. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5211. // 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);
  5212. //}
  5213. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5214. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5215. WaitAnimation = 1;
  5216. }
  5217. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5218. bt = (*ui->Type->Theme);
  5219. if (ui->Type == &_LA_UI_CONDITION){
  5220. laConditionUiExtraData *cued = ui->Extra;
  5221. la_StepExpression(cued->Expression);
  5222. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5223. if (!cued->IsTrue){
  5224. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5225. }else{
  5226. ui = ui->Item.pNext;
  5227. }
  5228. continue;
  5229. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5230. ui = ui->Item.pNext;
  5231. continue;
  5232. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5233. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5234. if (cued->IsTrue) ui = cued->EndUi;
  5235. else
  5236. ui = ui->Item.pNext;
  5237. continue;
  5238. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5239. laConditionUiExtraData *cued = ui->Extra;
  5240. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5241. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5242. if (!WaitAnimation){
  5243. ui->L = ui->TL; ui->R = ui->TR;
  5244. ui->U = ui->TU; ui->B = ui->TB;
  5245. }
  5246. if(!RowMode){
  5247. la_CalcUiItemInfluence(&uil->Columns, ui);
  5248. }else{
  5249. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5250. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5251. }
  5252. if (ui->State == LA_UI_NORMAL){
  5253. cued->IsTrue = 0;
  5254. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5255. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5256. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5257. }else{
  5258. cued->IsTrue = 1;
  5259. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5260. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5261. //}
  5262. ui = ui->Item.pNext;
  5263. }
  5264. continue;
  5265. }
  5266. if (ui->Type == _LA_UI_ALIGN){
  5267. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5268. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5269. if (ui->TB > Lowest) Lowest = ui->TB;
  5270. if (!WaitAnimation){
  5271. ui->L = ui->TL; ui->R = ui->TR;
  5272. ui->U = ui->TU; ui->B = ui->TB;
  5273. }
  5274. if(!RowMode){
  5275. la_CalcUiItemInfluence(&uil->Columns, ui);
  5276. }else{
  5277. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5278. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5279. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5280. }
  5281. ui = ui->Item.pNext; continue;
  5282. }
  5283. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5284. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5285. la_InitRowNode(&ri, ui, bt);
  5286. RowMode=1; ui=ui->Item.pNext; continue;
  5287. }
  5288. if (ui->Type == &_LA_UI_ROW_END){
  5289. la_CalculateRowExpand(&ri, ui);
  5290. la_CalcUiItemInfluence(&uil->Columns, ui);
  5291. RowMode=0; ui=ui->Item.pNext; continue;
  5292. }
  5293. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5294. int GB=0;
  5295. 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; }
  5296. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5297. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5298. if (H < 0){
  5299. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5300. else{ H=LA_RH; }
  5301. }
  5302. else H *= LA_RH;
  5303. ui->TB = ui->TU;
  5304. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5305. 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
  5306. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5307. if (ui->Type == _LA_UI_COLLECTION){
  5308. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5309. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5310. ui->PP.EndInstance = TInstance;
  5311. laUiList *iuil = ui->Subs.pFirst;
  5312. laUiList *puil = iuil;
  5313. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5314. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5315. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5316. int Begin = ui->TB;
  5317. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5318. int ElementB = ui->TU;
  5319. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5320. int MaxB = ElementB;
  5321. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5322. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5323. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5324. if (!ElementLimit) RowPriority = 0;
  5325. if (!TInstance){
  5326. while (iuil){
  5327. puil = iuil->Item.pNext;
  5328. la_DestroyTabPage(ui, iuil, 0);
  5329. iuil = puil;
  5330. }
  5331. }
  5332. while (TInstance){
  5333. int UiFilterSkip = uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance));
  5334. int ManagerFilterSkip = MAIN.ManagerFilterInstances && (ui->Flags&LA_UI_COLLECTION_MANAGER_FILTER) && (!laget_Hyper2InstanceModified(TInstance));
  5335. if(UiFilterSkip || ManagerFilterSkip){
  5336. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5337. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5338. ui->PP.EndInstance = TInstance; continue;
  5339. }
  5340. if(CanGetTheme){
  5341. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5342. la_SwitchThemeQuick(t, OriginalTheme);
  5343. }
  5344. if(CanGetGap){
  5345. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5346. Gap=g*LA_RH;
  5347. }else Gap=0;
  5348. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5349. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5350. }else GotCategory=0;
  5351. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5352. if (RowPriority){
  5353. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5354. }
  5355. }
  5356. FirstIn=0;
  5357. if (ElementLimit){
  5358. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5359. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5360. }
  5361. while (iuil && iuil->Instance != TInstance){
  5362. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5363. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5364. }else{
  5365. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5366. }
  5367. iuil = puil;
  5368. }
  5369. if(!iuil){
  5370. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5371. }
  5372. if (!iuil){
  5373. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5374. la_CalcUiTopInfluence(&uil->Columns, ui);
  5375. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5376. 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);
  5377. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5378. iuil = ui->Page->Item.pNext;
  5379. }else{
  5380. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5381. 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);
  5382. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5383. la_CalcUiItemInfluence(&uil->Columns, ui);
  5384. iuil = iuil->Item.pNext;
  5385. }
  5386. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5387. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5388. ui->PP.EndInstance = TInstance;
  5389. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5390. if (RowPriority){
  5391. Col += 1;
  5392. if (Col >= ElementLimit){
  5393. Col = 0;
  5394. Row += 1;
  5395. Begin = ElementB + bt->TM;
  5396. }
  5397. }elif(Spread){
  5398. EL+=Spread*LA_RH;
  5399. ER+=Spread*LA_RH;
  5400. }else{
  5401. Row += 1;
  5402. Begin = ElementB + bt->TM;
  5403. if (ElementLimit && Row >= ElementLimit){
  5404. Row = 0;
  5405. Col += 1;
  5406. Begin = ui->TU + bt->TM;
  5407. }
  5408. }
  5409. ui->TB = ElementB;
  5410. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5411. }
  5412. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5413. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5414. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5415. ui->TB = MaxB;
  5416. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5417. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5418. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5419. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5420. ui->TB=ui->TU+LA_RH;
  5421. }else{
  5422. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5423. ui->PP.EndInstance = TInstance;
  5424. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5425. if(!Template) Template=laui_SubPropInfoDefault;
  5426. //ui->Template = Template;
  5427. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5428. if (!ui->Subs.pFirst && TInstance){
  5429. la_AddInstancePage(ui, TInstance, 0);
  5430. la_CalcUiTopInfluence(&uil->Columns, ui);
  5431. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5432. 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);
  5433. ui->TB = SubB + (NoDecal?0:bt->BM);
  5434. }else if (ui->Subs.pFirst){
  5435. if (!TInstance || TInstance != ui->Page->Instance){
  5436. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5437. ui->Page = 0;
  5438. if (TInstance){
  5439. la_AddInstancePage(ui, TInstance, 0);
  5440. la_CalcUiTopInfluence(&uil->Columns, ui);
  5441. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5442. 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);
  5443. ui->TB = SubB + (NoDecal?0:bt->TM);
  5444. }else
  5445. ui->TB = ui->TU + LA_RH + bt->BM;
  5446. }else{
  5447. 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);
  5448. ui->TB = SubB + (NoDecal?0:bt->BM);
  5449. }
  5450. }
  5451. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5452. ui->TB=ui->TU+LA_RH;
  5453. }
  5454. }
  5455. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5456. if (!WaitAnimation){
  5457. ui->L = ui->TL;
  5458. ui->R = ui->TR;
  5459. ui->U = ui->TU;
  5460. ui->B = ui->TB;
  5461. }
  5462. }
  5463. }else{
  5464. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5465. if (ui->Type != _LA_UI_CANVAS){
  5466. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5467. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5468. SubB = la_UpdateUiListRecursive(ui->Page,
  5469. 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);
  5470. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5471. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5472. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5473. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5474. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5475. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5476. }
  5477. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5478. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5479. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5480. if(ui->Page->HeightCoeff){
  5481. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5482. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5483. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5484. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5485. }
  5486. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5487. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5488. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5489. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5490. }
  5491. }
  5492. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5493. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5494. }else{
  5495. laUiList *suil;
  5496. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5497. la_CalcUiTopInfluence(&uil->Columns, ui);
  5498. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5499. 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);
  5500. }
  5501. }
  5502. ui->TB = ui->TU + H;
  5503. }
  5504. }else ui->TB = ui->TU + H;
  5505. }
  5506. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5507. if(!RowMode){
  5508. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5509. }else{
  5510. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5511. }
  5512. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5513. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5514. ui = ui->Item.pNext;
  5515. }
  5516. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5517. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5518. else uil->TB = Lowest;
  5519. if (!WaitAnimation){
  5520. uil->L = uil->TL;
  5521. uil->R = uil->TR;
  5522. uil->U = uil->TU;
  5523. uil->B = uil->TB;
  5524. }
  5525. MAIN.UiScale=uil->SaveScale;
  5526. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5527. return uil->TB;
  5528. }
  5529. int la_AnimateSingleUiSize(int To, int *Now){
  5530. int Delta;
  5531. if (To != *Now){
  5532. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5533. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5534. *Now += Delta;
  5535. return 1;
  5536. }else
  5537. return 0;
  5538. }
  5539. int la_AnimateUiListRecursive(laUiList *uil){
  5540. laUiItem *ui;
  5541. int Again = 0;
  5542. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5543. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5544. if(ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish){
  5545. ui->B=ui->TB; ui->L=ui->TL; ui->R=ui->TR; ui->U=ui->TU;
  5546. }else{
  5547. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5548. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5549. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5550. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5551. }
  5552. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5553. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5554. laUiList *suil;
  5555. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5556. Again += la_AnimateUiListRecursive(suil);
  5557. }
  5558. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5559. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5560. Again += la_AnimateUiListRecursive(ui->Page);
  5561. }
  5562. }
  5563. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5564. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5565. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5566. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5567. return Again;
  5568. }
  5569. int la_DrawUiItem(laUiItem *ui){
  5570. tnsUseNoTexture();
  5571. tnsColor4d(1, 1, 1, 1);
  5572. tnsVertex2d(ui->L, ui->U);
  5573. tnsVertex2d(ui->R, ui->U);
  5574. tnsVertex2d(ui->R, ui->B);
  5575. tnsVertex2d(ui->L, ui->B);
  5576. tnsPackAs(GL_LINE_LOOP);
  5577. }
  5578. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5579. tnsUseNoTexture();
  5580. tnsColor4d(1, 1, 1, 1);
  5581. tnsVertex2d(ui->L - 1, ui->U - 1);
  5582. tnsVertex2d(ui->R + 1, ui->U - 1);
  5583. tnsVertex2d(ui->R + 1, ui->B + 1);
  5584. tnsVertex2d(ui->L - 1, ui->B + 1);
  5585. tnsPackAs(GL_LINE_LOOP);
  5586. }
  5587. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5588. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5589. return 1;
  5590. }
  5591. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5592. laUiListDrawItem *uildi = uild->Items.pFirst;
  5593. laUiList *Target = uildi->Target;
  5594. int L, R, U, B;
  5595. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5596. L = Target->L + Target->PanX + uildi->DifX;
  5597. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5598. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5599. U = Target->U + Target->PanY + uildi->DifY;
  5600. return la_UiInBound(ui, L, R, U, B);
  5601. }
  5602. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5603. laUiListDrawItem *uildi = uild->Items.pFirst;
  5604. laUiList *Target = uildi->Target;
  5605. int L, R, U, B;
  5606. if (Target){
  5607. L = Target->L + Target->PanX + uildi->DifX;
  5608. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5609. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5610. U = Target->U + Target->PanY + uildi->DifY;
  5611. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5612. return 1;
  5613. }else{
  5614. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5615. return 1;
  5616. }
  5617. }
  5618. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5619. laUiItem *ui = uil->UiItems.pFirst;
  5620. while (!strGetArgument(ui->Instructions, mark))
  5621. ui = ui->Item.pNext;
  5622. return ui;
  5623. }
  5624. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5625. laUiList *uil;
  5626. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5627. if (uil->Instance == Instance) return uil;
  5628. }
  5629. return uil;
  5630. }
  5631. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5632. int mx=(L+R)/2; int my=(U+B)/2;
  5633. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5634. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5635. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5636. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5637. tnsFlush();
  5638. }
  5639. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5640. if(!uil->ScrollerShownV) return;
  5641. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5642. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5643. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5644. int U = uil->U + Offset;
  5645. int B = U + Len;
  5646. int L = UiR - RM*2 - W;
  5647. int R = L + W;
  5648. if (B > U + DisplayH) B = U + DisplayH;
  5649. if (U < uil->U) U = uil->U;
  5650. if (B <= uil->U || U >= uil->B) return;
  5651. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5652. if (U < uil->U) U = uil->U;
  5653. tnsUseNoTexture();
  5654. laBoxedTheme* bt=_LA_THEME_PANEL;
  5655. real* color=laThemeColor(bt, LA_BT_TEXT);
  5656. tnsColor4d(LA_COLOR3(color), 0.2);
  5657. tnsVertex2d(R-RM, uil->U);
  5658. tnsVertex2d(L+RM, uil->U);
  5659. tnsVertex2d(L+RM, uil->U + DisplayH);
  5660. tnsVertex2d(R-RM, uil->U + DisplayH);
  5661. tnsPackAs(GL_TRIANGLE_FAN);
  5662. tnsColor4d(LA_COLOR3(color), 0.5);
  5663. tnsVertex2d(R-RM, uil->U);
  5664. tnsVertex2d(L+RM, uil->U);
  5665. tnsVertex2d(L+RM, uil->U + DisplayH);
  5666. tnsVertex2d(R-RM, uil->U + DisplayH);
  5667. tnsPackAs(GL_LINE_LOOP);
  5668. tnsColor4d(LA_COLOR3(color), 1);
  5669. tnsVertex2d(R, U);
  5670. tnsVertex2d(L, U);
  5671. tnsVertex2d(L, B);
  5672. tnsVertex2d(R, B);
  5673. tnsPackAs(GL_TRIANGLE_FAN);
  5674. int HU=(U+B)/2+LA_RH2;
  5675. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5676. tnsFlush();
  5677. }
  5678. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5679. if(!uil->ScrollerShownH) return;
  5680. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5681. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5682. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5683. int L = uil->L + Offset;
  5684. int R = L + Len;
  5685. int U = UiB - RM - W;
  5686. int B = U + W;
  5687. if (B > U + DisplayW) B = U + DisplayW;
  5688. if (U < uil->U) U = uil->U;
  5689. if (R <= uil->L || L >= uil->R) return;
  5690. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5691. if (L < uil->L) L = uil->L;
  5692. tnsUseNoTexture();
  5693. laBoxedTheme* bt=_LA_THEME_PANEL;
  5694. real* color=laThemeColor(bt, LA_BT_TEXT);
  5695. tnsColor4d(LA_COLOR3(color), 0.2);
  5696. tnsVertex2d(uil->L,U+RM);
  5697. tnsVertex2d(uil->L,B-RM);
  5698. tnsVertex2d(uil->L + DisplayW,B-RM);
  5699. tnsVertex2d(uil->L + DisplayW,U+RM);
  5700. tnsPackAs(GL_TRIANGLE_FAN);
  5701. tnsColor4d(LA_COLOR3(color), 0.5);
  5702. tnsVertex2d(uil->L,U+RM);
  5703. tnsVertex2d(uil->L,B-RM);
  5704. tnsVertex2d(uil->L + DisplayW,B-RM);
  5705. tnsVertex2d(uil->L + DisplayW,U+RM);
  5706. tnsPackAs(GL_LINE_LOOP);
  5707. tnsColor4d(LA_COLOR3(color), 1);
  5708. tnsVertex2d(R, U);
  5709. tnsVertex2d(L, U);
  5710. tnsVertex2d(L, B);
  5711. tnsVertex2d(R, B);
  5712. tnsPackAs(GL_TRIANGLE_FAN);
  5713. int HU=(U+B)/2+LA_RH2;
  5714. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5715. tnsFlush();
  5716. }
  5717. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5718. tnsUseNoTexture();
  5719. tnsColor4dv(color);
  5720. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5721. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5722. tnsPackAs(GL_TRIANGLE_FAN);
  5723. }
  5724. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5725. laSocketRecord* sr;
  5726. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5727. uild->WiresContainer=container;
  5728. }
  5729. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5730. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5731. if(lip->Target==uild->WiresContainer) break;
  5732. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5733. }
  5734. }
  5735. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5736. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5737. int PanX, PanY;
  5738. if(pc==LA_PC_SOCKET_OUT){
  5739. laNodeOutSocket* s=ui->PP.EndInstance;
  5740. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5741. }else{
  5742. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5743. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5744. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5745. }
  5746. }
  5747. void la_RegenerateWireColors(){
  5748. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5749. laTheme* t=MAIN.CurrentTheme;
  5750. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5751. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5752. for(int i=0;i<MAIN.WireColorSlices;i++){
  5753. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5754. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5755. }
  5756. }
  5757. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5758. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5759. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5760. tnsInterpolate2dv(v1,v2,0.5,vi);
  5761. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5762. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5763. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5764. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5765. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5766. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5767. tnsVertex2d(v1[0],v1[1]);
  5768. for(int i=1;i<=steps;i++){
  5769. real ratio=i==steps?1.0f:step*i;
  5770. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5771. tnsVertex2d(v1s[0],v1s[1]);
  5772. }
  5773. }
  5774. void la_DrawNodeWires(laUiListDraw* uild){
  5775. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5776. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5777. tnsUseNoTexture();
  5778. #define _RSLICES 16
  5779. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5780. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5781. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5782. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5783. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5784. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5785. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5786. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5787. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5788. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5789. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5790. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5791. }
  5792. if(MAIN.tNodeIn->Source){
  5793. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5794. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5795. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5796. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5797. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5798. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5799. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5800. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5801. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5802. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5803. }
  5804. #undef _RSLICES
  5805. tnsFlush();
  5806. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5807. glLineWidth(ww);
  5808. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5809. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5810. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5811. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5812. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5813. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5814. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5815. }
  5816. if(MAIN.tNodeIn->Source){
  5817. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5818. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5819. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5820. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5821. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5822. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5823. }
  5824. tnsFlush();
  5825. glLineWidth(1);
  5826. la_InitSocketRecord(uild,0);
  5827. }
  5828. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5829. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5830. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5831. }
  5832. 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){
  5833. laUiItem *ui;
  5834. laBoxedTheme *bt;
  5835. laUiList *sub;
  5836. laUiListDrawItem *uildi;
  5837. int Ret = 0;
  5838. if (!uil) return 0;
  5839. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5840. ui = uil->UiItems.pFirst;
  5841. if(uil->PanY<0){uil->PanY=0;}
  5842. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5843. uil->SaveScale=MAIN.UiScale;
  5844. MAIN.UiScale*=uil->Scale;
  5845. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5846. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5847. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5848. if (ui->Type == &_LA_UI_CONDITION){
  5849. laConditionUiExtraData *cued = ui->Extra;
  5850. la_StepExpression(cued->Expression);
  5851. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5852. if (!cued->IsTrue){
  5853. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5854. }else{
  5855. ui = ui->Item.pNext;
  5856. }
  5857. continue;
  5858. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5859. ui = ui->Item.pNext;
  5860. continue;
  5861. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5862. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5863. if (cued->IsTrue) ui = cued->EndUi;
  5864. else
  5865. ui = ui->Item.pNext;
  5866. continue;
  5867. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5868. laConditionUiExtraData *cued = ui->Extra;
  5869. ui->Type->Draw(ui, LA_RH);
  5870. if (ui->State == LA_UI_NORMAL){
  5871. cued->IsTrue = 0;
  5872. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5873. }else{
  5874. cued->IsTrue = 1;
  5875. ui = ui->Item.pNext;
  5876. }
  5877. continue;
  5878. }
  5879. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5880. int NeedDraw=0;
  5881. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5882. if(NeedDraw){
  5883. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5884. }else{ ui->Type->Draw(ui, LA_RH); }
  5885. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5886. tnsFlush();
  5887. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5888. tnsResetViewMatrix();
  5889. }
  5890. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5891. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5892. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5893. tnsFlush();
  5894. }
  5895. }
  5896. if(NeedDraw || RegisterNodes){
  5897. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5898. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5899. ui->Type == _LA_UI_TAB ||
  5900. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5901. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5902. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5903. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5904. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5905. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5906. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5907. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5908. 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); }
  5909. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5910. 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);
  5911. 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)); }
  5912. }elif (ui->Type == _LA_UI_COLLECTION){
  5913. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5914. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5915. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5916. void* SaveInstance = ui->PP.EndInstance;
  5917. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5918. int State;
  5919. ui->PP.EndInstance = sub->Instance;
  5920. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5921. if(NeedDraw){ int drawn=0;
  5922. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5923. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5924. }
  5925. if (CanGetState && !drawn){
  5926. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5927. if(State >= 0){
  5928. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5929. }
  5930. }
  5931. }
  5932. if(sub->TabName && sub->TabName->Ptr){
  5933. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5934. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5935. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5936. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5937. tnsFlush();
  5938. }
  5939. if(CanGetTheme){
  5940. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5941. la_SwitchThemeQuick(t, OriginalTheme);
  5942. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5943. }
  5944. tnsFlush();
  5945. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5946. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5947. }
  5948. //ui->PP.EndInstance = Active;
  5949. ui->PP.EndInstance = SaveInstance;
  5950. }elif (ui->Type == _LA_UI_CANVAS){
  5951. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5952. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5953. tnsFlush();
  5954. 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);
  5955. }
  5956. }
  5957. }
  5958. ui = ui->Item.pNext;
  5959. }else{
  5960. ui = ui->Item.pNext;
  5961. }
  5962. }
  5963. tnsFlush();
  5964. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5965. la_RestoreLastUiListMatrix(uild, B - U);
  5966. MAIN.UiScale=uil->SaveScale;
  5967. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5968. return Ret;
  5969. }
  5970. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5971. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5972. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5973. tnsUseNoTexture();
  5974. tnsColor4d(1, 1, 1, 1);
  5975. tnsVertex2d(L, U);
  5976. tnsVertex2d(R, U);
  5977. tnsVertex2d(R, B);
  5978. tnsVertex2d(L, B);
  5979. tnsPackAs(GL_LINE_LOOP);
  5980. tnsVertex2d(L + 3, Begin);
  5981. tnsVertex2d(R - 3, Begin);
  5982. tnsVertex2d(R - 3, End);
  5983. tnsVertex2d(L + 3, End);
  5984. tnsPackAs(GL_LINE_LOOP);
  5985. }
  5986. int laIsInUiItem(laUiItem *ui, int x, int y){
  5987. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5988. return 1;
  5989. }
  5990. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5991. if (x < l || x > r || y < u || y > b) return 0;
  5992. return 1;
  5993. }
  5994. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5995. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5996. laUiItem *ui, *tui;
  5997. laBoxedTheme *bt;
  5998. laUiList *sub;
  5999. int CPB = 0;
  6000. if (!uil || (LimB && y > LimB)) return 0;
  6001. x += uil->PanX;
  6002. y += uil->PanY;
  6003. for (ui = uil->UiItems.pFirst; ui;){
  6004. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6005. if (ui->Type == &_LA_UI_CONDITION){
  6006. laConditionUiExtraData *cued = ui->Extra;
  6007. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  6008. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6009. if (!cued->IsTrue){
  6010. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6011. }else{
  6012. ui = ui->Item.pNext;
  6013. }
  6014. continue;
  6015. }else if (ui->Type == &_LA_UI_CONDITION_END){
  6016. ui = ui->Item.pNext;
  6017. continue;
  6018. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6019. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6020. if (cued->IsTrue) ui = cued->EndUi;
  6021. else
  6022. ui = ui->Item.pNext;
  6023. continue;
  6024. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6025. laConditionUiExtraData *cued = ui->Extra;
  6026. if (laIsInUiItem(ui, x, y)){
  6027. lstAppendPointer(LocalBuf, uil);
  6028. return ui;
  6029. }
  6030. if (ui->State == LA_UI_NORMAL){
  6031. cued->IsTrue = 0;
  6032. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6033. }else{
  6034. cued->IsTrue = 1;
  6035. ui = ui->Item.pNext;
  6036. }
  6037. continue;
  6038. }
  6039. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  6040. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  6041. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  6042. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  6043. if(!la_DetectSplit(ui->C, x)) Add=0;
  6044. }
  6045. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  6046. }
  6047. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6048. if (ui->Page->HeightCoeff) CPB = ui->B;
  6049. else CPB = ui->Page->B;
  6050. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6051. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  6052. lstAppendPointer(LocalBuf, uil);
  6053. return tui;
  6054. }
  6055. }else if (laIsInUiItem(ui, x, y)){
  6056. lstAppendPointer(LocalBuf, uil);return ui;
  6057. }
  6058. }
  6059. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  6060. if (laIsInUiItem(ui, x, y)){
  6061. lstAppendPointer(LocalBuf, uil);
  6062. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  6063. if(Deep){
  6064. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  6065. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  6066. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  6067. lstAppendPointer(LocalBuf, iuil);
  6068. return tui;
  6069. }
  6070. }
  6071. }
  6072. }
  6073. return ui;
  6074. }
  6075. }
  6076. if (ui->Type == _LA_UI_CANVAS){
  6077. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6078. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6079. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  6080. lstAppendPointer(LocalBuf, uil);
  6081. return tui;
  6082. }
  6083. }
  6084. }
  6085. if (laIsInUiItem(ui, x, y)){
  6086. lstAppendPointer(LocalBuf, uil);
  6087. return ui;
  6088. }
  6089. }
  6090. ui = ui->Item.pNext;
  6091. }
  6092. return 0;
  6093. }
  6094. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  6095. laListHandle Locals={0};
  6096. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  6097. while(lstPopPointer(&Locals));
  6098. //printf("%s\n", ui?ui->Type->Identifier:"?");
  6099. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  6100. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  6101. if(pc==PCInOrOut) return ui;
  6102. }
  6103. return 0;
  6104. }
  6105. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  6106. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  6107. laUiItem *ui = uil->UiItems.pFirst;
  6108. laBoxedTheme *bt;
  6109. laUiList *tuil;
  6110. laUiList *sub;
  6111. int CPB = 0;
  6112. x += uil->PanX;
  6113. y += uil->PanY;
  6114. if (y > LimH) return uil;
  6115. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  6116. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  6117. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6118. return uil;
  6119. }
  6120. for (ui = uil->UiItems.pFirst; ui;){
  6121. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6122. if (ui->Type == &_LA_UI_CONDITION){
  6123. laConditionUiExtraData *cued = ui->Extra;
  6124. //la_StepExpression(cued->Expression);
  6125. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6126. if (!cued->IsTrue){
  6127. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6128. }else{
  6129. ui = ui->Item.pNext;
  6130. }
  6131. continue;
  6132. }
  6133. if (ui->Type == &_LA_UI_CONDITION_END){
  6134. ui = ui->Item.pNext;
  6135. continue;
  6136. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6137. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6138. if (cued->IsTrue) ui = cued->EndUi;
  6139. else
  6140. ui = ui->Item.pNext;
  6141. continue;
  6142. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6143. laConditionUiExtraData *cued = ui->Extra;
  6144. if (ui->State == LA_UI_NORMAL){
  6145. cued->IsTrue = 0;
  6146. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6147. }else{
  6148. cued->IsTrue = 1;
  6149. ui = ui->Item.pNext;
  6150. }
  6151. continue;
  6152. }
  6153. if (InToContainerUI && ui != Exception){
  6154. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6155. if (ContainerParent) (*ContainerParent) = uil;
  6156. if (ParentUi) *ParentUi = ui;
  6157. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6158. //if (y > LimH) return uil;
  6159. 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))){
  6160. return tuil;
  6161. }
  6162. }
  6163. }
  6164. }
  6165. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6166. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  6167. else CPB = ui->Page->B;
  6168. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6169. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6170. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6171. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  6172. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6173. if (ParentUi) *ParentUi = ui;
  6174. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  6175. }
  6176. }
  6177. ui = ui->Item.pNext;
  6178. }
  6179. return uil;
  6180. }
  6181. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  6182. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  6183. laUiItem *ui = uil->UiItems.pFirst;
  6184. laBoxedTheme *bt;
  6185. laUiList *tuil;
  6186. laUiList *sub;
  6187. int CPB = 0;
  6188. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  6189. x += uil->PanX;
  6190. y += uil->PanY;
  6191. if (y > LimH) return uil;
  6192. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  6193. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  6194. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  6195. return uil;
  6196. }
  6197. for (ui = uil->UiItems.pFirst; ui;){
  6198. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6199. if (ui->Type == &_LA_UI_CONDITION){
  6200. laConditionUiExtraData *cued = ui->Extra;
  6201. //la_StepExpression(cued->Expression);
  6202. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  6203. if (!cued->IsTrue){
  6204. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6205. }else{
  6206. ui = ui->Item.pNext;
  6207. }
  6208. continue;
  6209. }
  6210. if (ui->Type == &_LA_UI_CONDITION_END){
  6211. ui = ui->Item.pNext;
  6212. continue;
  6213. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6214. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6215. if (cued->IsTrue) ui = cued->EndUi;
  6216. else
  6217. ui = ui->Item.pNext;
  6218. continue;
  6219. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6220. laConditionUiExtraData *cued = ui->Extra;
  6221. if (ui->State == LA_UI_NORMAL){
  6222. cued->IsTrue = 0;
  6223. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6224. }else{
  6225. cued->IsTrue = 1;
  6226. ui = ui->Item.pNext;
  6227. }
  6228. continue;
  6229. }
  6230. if (InToContainerUI && ui != Exception){
  6231. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6232. if (ContainerParent) (*ContainerParent) = uil;
  6233. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6234. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6235. //if (y > LimH) return uil;
  6236. 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))){
  6237. return tuil;
  6238. }
  6239. }
  6240. }
  6241. }
  6242. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6243. if (ui->Page->HeightCoeff) CPB = ui->B;
  6244. else CPB = ui->Page->B;
  6245. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6246. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6247. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6248. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6249. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6250. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6251. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6252. }
  6253. }
  6254. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6255. if (ui->Page->HeightCoeff) CPB = ui->B;
  6256. else
  6257. CPB = ui->Page->B;
  6258. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6259. if (ScrollUil) *ScrollUil = ui->Page;
  6260. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6261. }
  6262. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6263. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6264. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6265. }
  6266. }
  6267. ui = ui->Item.pNext;
  6268. }
  6269. return uil;
  6270. }
  6271. int la_TestUiListMinumWidth(laUiList *uil){
  6272. laUiItem *ui, *tui;
  6273. laBoxedTheme *bt;
  6274. laUiList *sub;
  6275. int CPB = 0;
  6276. int W = 0;
  6277. int tW, sW, RowMode=0, rW;
  6278. void *Restore;
  6279. for (ui = uil->UiItems.pFirst; ui;){
  6280. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6281. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6282. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6283. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6284. if (W < tW) W = tW;
  6285. }elif (ui->Type == _LA_UI_COLLECTION){
  6286. Restore = ui->PP.EndInstance;
  6287. tW = 0; sW = 0;
  6288. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6289. ui->PP.EndInstance = sub->Instance;
  6290. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6291. if (sW > tW) tW = sW;
  6292. }
  6293. ui->PP.EndInstance = Restore;
  6294. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6295. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6296. if (W < tW) W = tW;
  6297. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6298. RowMode=1; rW=0;
  6299. }elif (ui->Type==&_LA_UI_ROW_END){
  6300. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6301. }elif (ui->Type->GetMinWidth){
  6302. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6303. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6304. }
  6305. ui = ui->Item.pNext;
  6306. }
  6307. return W;
  6308. }
  6309. void la_InitLLVM(){
  6310. //LLVMLinkInMCJIT();
  6311. //LLVMInitializeNativeTarget();
  6312. //LLVMInitializeNativeAsmPrinter();
  6313. //LLVMInitializeNativeAsmParser();
  6314. // MAIN.llvmContext = LLVMGetGlobalContext();
  6315. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6316. }
  6317. //==================================================================================================
  6318. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6319. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6320. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6321. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6322. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6323. memFree(kmi);
  6324. }
  6325. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6326. laKeyMapItem *kmi;
  6327. if (!km) return 0;
  6328. kmi = memAcquire(sizeof(laKeyMapItem));
  6329. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6330. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6331. }else{
  6332. strSafeSet(&kmi->Operation, Operation);
  6333. }
  6334. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6335. kmi->SpecialKeyBits = SpecialKeyBits;
  6336. kmi->EventType = EventType;
  6337. kmi->Key = tolowerGuarded(Key);
  6338. kmi->SelectBase = SelectBase;
  6339. lstAppendItem(&km->Items, kmi);
  6340. return kmi;
  6341. }
  6342. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6343. laKeyMapItem *kmi; int inv=0;
  6344. char *instructions;
  6345. if(e->type==LA_MOUSEMOVE) return 0;
  6346. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6347. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6348. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6349. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6350. if (kmi->Operation)
  6351. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6352. else
  6353. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6354. inv = 1;
  6355. }
  6356. }
  6357. return inv;
  6358. }
  6359. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6360. laKeyMapItem *kmi;
  6361. char *instructions;
  6362. int inv = 0; int lx = -1, ly = -1;
  6363. if(e->type==LA_MOUSEMOVE) return 0;
  6364. if(e->type == LA_OPERATOR_EVENT && e->OperatorBase){
  6365. if (e->OperatorBase == LA_KM_SEL_UI_EXTRA){
  6366. laInvokeP(from, e->Operator, e, UiExtra, e->OperatorInstructions, 0);
  6367. }elif (e->OperatorBase == LA_KM_SEL_PANEL){
  6368. laInvokeP(from, e->Operator, e, &((laPanel *)MAIN.ToPanel)->PP, e->OperatorInstructions, 0);
  6369. }
  6370. return 1;
  6371. }
  6372. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6373. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6374. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6375. if (e->Localized){
  6376. lx = e->x;
  6377. ly = e->y;
  6378. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6379. e->Localized = 0;
  6380. }
  6381. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6382. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6383. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6384. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6385. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6386. }elif (kmi->Operation){
  6387. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6388. }else{
  6389. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6390. }
  6391. inv = 1;
  6392. if (lx >= 0){
  6393. e->x = lx;
  6394. e->y = ly;
  6395. e->Localized = 1;
  6396. }
  6397. }
  6398. }
  6399. return inv;
  6400. }
  6401. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6402. void la_DestroyOperatorType(laOperatorType* at){
  6403. //if(at->PC) la_FreePropertyContainer(at->PC);
  6404. memFree(at);
  6405. }
  6406. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6407. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6408. uint32_t IconID, int ExtraMark){
  6409. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6410. at->Identifier = ID;
  6411. at->Name = Name;
  6412. at->Description = Description;
  6413. at->Check = Check;
  6414. at->Invoke = Invoke;
  6415. at->Init = Init;
  6416. at->Exit = Exit;
  6417. at->Modal = Modal;
  6418. at->IconID = IconID;
  6419. at->ExtraMark = ExtraMark;
  6420. at->ParseArgs = la_DefaultOperatorParser;
  6421. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6422. lstAppendItem2(&MAIN.OperatorList, at);
  6423. return at;
  6424. }
  6425. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6426. ot->PC = memAcquire(sizeof(laPropContainer));
  6427. ot->PC->Identifier = ot->Identifier;
  6428. ot->PC->Hyper = HyperLevel;
  6429. return ot->PC;
  6430. }
  6431. laOperator *la_CreateOperator(laOperatorType *at){
  6432. laOperator *a = CreateNew(laOperator);
  6433. a->Type = at;
  6434. if (at->PC && at->PC->Props.pFirst){
  6435. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6436. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6437. a->PP.LastPs->p->SubProp = at->PC;
  6438. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6439. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6440. a->PP.LastPs->Type = U'.';
  6441. }
  6442. return a;
  6443. }
  6444. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6445. return (!strcmp(a->Identifier, id));
  6446. }
  6447. laOperatorType *laGetOperatorType(const char *ID){
  6448. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6449. }
  6450. int laOperatorExistsT(laOperatorType* at){
  6451. if (!at) return 0;
  6452. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6453. return 0;
  6454. }
  6455. int laOperatorExists(const char* ID){
  6456. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6457. return laOperatorExistsT(at);
  6458. }
  6459. int la_OperatorExists(laOperator *ac){
  6460. if (!ac) return 0;
  6461. laOperator *a;
  6462. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6463. return 0;
  6464. }
  6465. int la_UiOperatorExists(void *inst){
  6466. laOperator *a;
  6467. if (!inst) return 0;
  6468. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6469. if (((laUiItem *)a->Instance) == inst){
  6470. return 1;
  6471. }
  6472. }
  6473. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6474. if (a->Instance == inst){
  6475. return 1;
  6476. }
  6477. }
  6478. return 0;
  6479. }
  6480. int la_OperatorPending(laOperator *target){
  6481. laOperator *a;
  6482. if (!target) return 0;
  6483. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6484. if (a == target){
  6485. return 1;
  6486. }
  6487. }
  6488. return 0;
  6489. }
  6490. void laSetOperatorLocalizer(void *ToPanel){
  6491. MAIN.ToPanel = ToPanel;
  6492. }
  6493. void la_DestroyConfirmData(laConfirmData **cd);
  6494. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6495. laOperator *ai = (*a);
  6496. laOperator *ac = ((*a)->Child);
  6497. void *Ret = 0;
  6498. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6499. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6500. }
  6501. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6502. if ((*a)->PP.LastPs){
  6503. memFree((*a)->PP.LastPs->p);
  6504. memFree((*a)->PP.LastPs);
  6505. }
  6506. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6507. la_SetPropMathcerContext((*a)->OperatorPanel);
  6508. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6509. laDestroySinglePanel((*a)->OperatorPanel,0);
  6510. }
  6511. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6512. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6513. lstClearPointer(&(*a)->LocalUiLists);
  6514. if (Operators){
  6515. Ret = ai->Item.pNext;
  6516. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6517. else
  6518. lstRemoveItem(Operators, *a);
  6519. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6520. if (ai->Child == (*a)) ai->Child = 0;
  6521. }
  6522. }
  6523. strSafeDestroy(&(*a)->RuntimeHint);
  6524. free(*a);
  6525. return Ret;
  6526. }
  6527. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6528. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6529. if (!at) return 0;
  6530. if (!at->Check) return 1;
  6531. return (at->Check(This, Instructions));
  6532. }
  6533. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6534. if (!at) return 0;
  6535. if (!at->Check) return 1;
  6536. return (at->Check(This, Instructions));
  6537. }
  6538. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6539. laPropPack FakePP = {0};
  6540. laPropStep FakePs = {0};
  6541. if (!at) return 0;
  6542. if (!at->Check) return 1;
  6543. FakePP.LastPs = &FakePs;
  6544. FakePP.Go = FakePP.LastPs;
  6545. FakePP.LastPs->p = This->LastPs->p;
  6546. FakePP.LastPs->UseInstance = This->EndInstance;
  6547. FakePP.EndInstance = Real_FromInstance;
  6548. FakePP.LastIndex = This->LastIndex;
  6549. return (at->Check(&FakePP, Instructions));
  6550. }
  6551. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6552. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6553. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6554. }
  6555. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6556. laOperator *a, *f = From;
  6557. int rev;
  6558. if (!f && e&&e->Localized) return -1;
  6559. a = la_CreateOperator(at);
  6560. a->ToPanel = MAIN.ToPanel;
  6561. a->This = This;
  6562. a->ExtraInstructions = args;
  6563. strMakeInstructions(&a->ExtraInstructionsP, args);
  6564. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6565. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6566. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6567. la_DestroyOperator(&a, 0, 0);
  6568. return LA_CANCELED;
  6569. }
  6570. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6571. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6572. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6573. e->Localized = 1;
  6574. }
  6575. if (e&&e->Localized){
  6576. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6577. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6578. e->Localized = 0;
  6579. }else{
  6580. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6581. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6582. }
  6583. }
  6584. if (From) f->Child = a;
  6585. a->Using = 1;
  6586. if (at->Init) at->Init(a);
  6587. rev = at->Invoke(a, e);
  6588. a->Using = 0;
  6589. if (rev & LA_FINISH){
  6590. a->StopNow = 1; if(From)From->Child=0;
  6591. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6592. }
  6593. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6594. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6595. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6596. a->State = rev;
  6597. a->PP.EndInstance = a->CustomData;
  6598. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6599. }else
  6600. la_DestroyOperator(&a, 0, 0);
  6601. return rev;
  6602. }
  6603. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6604. laOperatorType *at; laOperator *a, *f = From;
  6605. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6606. if (!at) return -1;
  6607. return laInvokeP(From,at,e,This,args,args2);
  6608. }
  6609. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6610. laOperator *a, *f = From;
  6611. int rev;
  6612. laPropPack *created;
  6613. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6614. created = memAcquireSimple(sizeof(laPropPack));
  6615. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6616. created->Go = created->LastPs;
  6617. created->LastPs->p = OrigionalThis->LastPs->p;
  6618. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6619. created->EndInstance = FromInstance;
  6620. created->LastIndex = OrigionalThis->LastIndex;
  6621. a = la_CreateOperator(at);
  6622. a->ToPanel = MAIN.ToPanel;
  6623. a->This = created;
  6624. a->CreatedThis = created;
  6625. a->ExtraInstructions = args;
  6626. strMakeInstructions(&a->ExtraInstructionsP, args);
  6627. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6628. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6629. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6630. la_DestroyOperator(&a, 0, 0);
  6631. return LA_CANCELED;
  6632. }
  6633. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6634. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6635. if (From) f->Child = a;
  6636. a->Using = 1;
  6637. if (at->Init) at->Init(a);
  6638. rev = at->Invoke(a, e);
  6639. a->Using = 0;
  6640. if (rev & LA_FINISH){
  6641. a->StopNow = 1; if(From)From->Child=0;
  6642. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6643. }
  6644. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6645. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6646. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6647. a->State = rev;
  6648. a->PP.EndInstance = a->CustomData;
  6649. }else
  6650. la_DestroyOperator(&a, 0, 0);
  6651. return rev;
  6652. }
  6653. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6654. laOperator *a, *f = From;
  6655. int rev;
  6656. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6657. a = la_CreateOperator(at);
  6658. a->Instance = inst;
  6659. a->ToPanel = MAIN.ToPanel;
  6660. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6661. if (From) f->Child = a;
  6662. a->Using = 1;
  6663. if (at->Init) at->Init(a);
  6664. rev = at->Invoke(a, e);
  6665. a->Using = 0;
  6666. if (rev & LA_FINISH){
  6667. a->StopNow = 1; if(From)From->Child=0;
  6668. }
  6669. if (rev & LA_BLOCK){
  6670. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6671. a->State = rev;
  6672. }else la_DestroyOperator(&a, 0, 0);
  6673. DEB = a;
  6674. return rev;
  6675. }
  6676. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6677. laOperatorType *at;
  6678. laOperator *a, *f = From;
  6679. if (la_UiOperatorExists(inst)) return -1;
  6680. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6681. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6682. }
  6683. void laRequestDelayEvent(real Seconds){
  6684. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6685. int la_UiStillInService(void *UiInstance){
  6686. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6687. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6688. if (ai->Instance == UiInstance) return 1;
  6689. }
  6690. return 0;
  6691. }
  6692. void la_StopUiOperatorService(void *UiInstance){
  6693. laOperator *ai, *dai, *NextAi;
  6694. if (!MAIN.CurrentWindow) return;
  6695. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6696. NextAi = ai->Item.pNext;
  6697. if (ai->Instance == UiInstance){
  6698. if (ai->Child){
  6699. la_StopUiOperatorService(ai->Child->Instance);
  6700. ai->Child = 0;
  6701. }
  6702. laOperator *dai = ai;
  6703. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6704. continue;
  6705. }
  6706. }
  6707. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6708. NextAi = ai->Item.pNext;
  6709. if (ai->Instance == UiInstance){
  6710. if (ai->Instance == ai->ToPanel){
  6711. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6712. //ai->ToPanel->LaterDestroy = 1;
  6713. }
  6714. if (ai->Child && la_OperatorExists(ai->Child)){
  6715. la_StopUiOperatorService(ai->Child->Instance);
  6716. //ai->Child = 0;
  6717. }
  6718. if (!ai->Using){
  6719. laOperator *dai = ai;
  6720. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6721. }else
  6722. ai->StopNow = 1;
  6723. }
  6724. }
  6725. }
  6726. void la_StopAllOperators(){
  6727. laOperator *ai, *dai, *NextAi;
  6728. if (!MAIN.CurrentWindow) return;
  6729. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6730. NextAi = ai->Item.pNext;
  6731. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6732. continue;
  6733. }
  6734. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6735. NextAi = ai->Item.pNext;
  6736. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6737. laHidePanelWithDissoveEffect(ai->ToPanel);
  6738. ai->ToPanel->LaterDestroy = 1;
  6739. }
  6740. if (!ai->Using){
  6741. laOperator *dai = ai;
  6742. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6743. }else ai->StopNow = 1;
  6744. }
  6745. }
  6746. void la_DestroyConfirmData(laConfirmData **cd){
  6747. if((!cd)||!(*cd)) return;
  6748. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6749. if ((*cd)->StrData) free((*cd)->StrData);
  6750. FreeMem((*cd));
  6751. (*cd) = 0;
  6752. }
  6753. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6754. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6755. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6756. ai->NextConfirmData = cd; laRetriggerOperators();
  6757. }
  6758. void laConfirmInt(laOperator *a, int Data, int mode){
  6759. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6760. cd->IData = Data; cd->Mode = mode;
  6761. ai->NextConfirmData = cd; laRetriggerOperators();
  6762. }
  6763. void laConfirmFloat(laOperator *a, real Data, int mode){
  6764. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6765. cd->FData = Data; cd->Mode = mode;
  6766. ai->NextConfirmData = cd; laRetriggerOperators();
  6767. }
  6768. void laConfirmString(laOperator *a, char *Str, int mode){
  6769. laOperator *ai = a;
  6770. laConfirmData *cd = CreateNew(laConfirmData);
  6771. int len = strlen(Str);
  6772. char *buf = calloc(len + 1, sizeof(char));
  6773. strcpy(buf, Str);
  6774. cd->StrData = buf;
  6775. cd->Mode = mode;
  6776. cd->Destroy = free;
  6777. ai->NextConfirmData = cd;
  6778. laRetriggerOperators();
  6779. }
  6780. int laConfirmSameDataIfAny(laOperator *a){
  6781. laOperator *ai = a;
  6782. laConfirmData *cd;
  6783. char *buf = 0;
  6784. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6785. cd = CreateNew(laConfirmData);
  6786. if (ai->ConfirmData->StrData){
  6787. int len = strlen(ai->ConfirmData->StrData);
  6788. buf = calloc(len + 1, sizeof(char));
  6789. strcpy(buf, ai->ConfirmData->StrData);
  6790. }
  6791. //cd->CustomData = cd->CustomData;
  6792. cd->IData = ai->ConfirmData->IData;
  6793. cd->FData = ai->ConfirmData->FData;
  6794. cd->PointerData = ai->ConfirmData->PointerData;
  6795. cd->PointerType = a->ConfirmData->PointerType;
  6796. cd->StrData = buf;
  6797. cd->Mode = ai->ConfirmData->Mode;
  6798. cd->Destroy = ai->ConfirmData->Destroy;
  6799. ai->NextConfirmData = cd;
  6800. laRetriggerOperators();
  6801. return 1;
  6802. }
  6803. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6804. laOperator *ai = a;
  6805. laConfirmData *cd = CreateNew(laConfirmData);
  6806. cd->CustomData = UserData;
  6807. cd->Mode = mode;
  6808. cd->Destroy = Destroy;
  6809. ai->NextConfirmData = cd;
  6810. laRetriggerOperators();
  6811. }
  6812. int laGetConfirmMode(laOperator *a){
  6813. return ((laOperator *)a)->ConfirmData->Mode;
  6814. }
  6815. int laGetConfirmInt(laOperator *a){
  6816. laOperator *ai = a;
  6817. int rev = ai->ConfirmData->IData;
  6818. la_DestroyConfirmData(&ai->ConfirmData);
  6819. ai->ConfirmData = 0;
  6820. return rev;
  6821. }
  6822. real laGetConfirmFloat(laOperator *a){
  6823. laOperator *ai = a;
  6824. real rev = ai->ConfirmData->FData;
  6825. la_DestroyConfirmData(&ai->ConfirmData);
  6826. ai->ConfirmData = 0;
  6827. return rev;
  6828. }
  6829. void laGetConfirmString(laOperator *a, char *buf){
  6830. laOperator *ai = a;
  6831. strcpy(buf, ai->ConfirmData->StrData);
  6832. la_DestroyConfirmData(&ai->ConfirmData);
  6833. ai->ConfirmData = 0;
  6834. }
  6835. void *laGetConfirmUserData(laOperator *a){
  6836. laOperator *ai = a;
  6837. return ai->ConfirmData->CustomData;
  6838. }
  6839. void laFinalizeOperators(){
  6840. laOperatorType *at;
  6841. laListHandle *lst;
  6842. int i;
  6843. for (i = 0; i < 256; i++){
  6844. lst = &MAIN.OperatorTypeHash.Entries[i];
  6845. for (at = lst->pFirst; at; at = at->Item.pNext){
  6846. if (at->PC && at->PC->Props.pFirst){
  6847. lstAppendItem(&MAIN.PropContainers, at->PC);
  6848. }
  6849. }
  6850. }
  6851. }
  6852. //=================
  6853. #ifdef LA_LINUX
  6854. static void la_RecordWacomMotions(XIRawEvent *event)
  6855. {
  6856. double *valuator = event->valuators.values;
  6857. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6858. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6859. //SYSWINDOW root_return, child_return;
  6860. //int root_x_return, root_y_return;
  6861. //int win_x_return, win_y_return;
  6862. //unsigned int mask_return;
  6863. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6864. // &root_x_return, &root_y_return,
  6865. // &win_x_return, &win_y_return,
  6866. // &mask_return);
  6867. //
  6868. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6869. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6870. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6871. real x=valuator[3],y=valuator[4];
  6872. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6873. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6874. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6875. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6876. if(XIMaskIsSet(event->valuators.mask, 5)){
  6877. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6878. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6879. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6880. MAIN.IsPen=1;
  6881. }
  6882. #endif
  6883. #ifdef _WIN32
  6884. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6885. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6886. static uint32_t ch = 0; static int lead = 0;
  6887. static wchar_t buf[10] = { 0 }; int adv;
  6888. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6889. short wheelmark = 0;
  6890. int WheelDir = 0;
  6891. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6892. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6893. POINT point;
  6894. PACKET pkt;
  6895. static POINT ptOld, ptNew;
  6896. static UINT prsOld, prsNew, vkey;
  6897. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6898. switch (message) {
  6899. case WM_PAINT:
  6900. //SwapBuffers(GetDC(hwnd));
  6901. break;
  6902. case WM_MOUSEMOVE:
  6903. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6904. MAIN.IsPen = 0;
  6905. break;
  6906. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6907. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6908. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6909. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6910. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6911. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6912. case WM_MOUSEWHEEL:
  6913. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6914. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6915. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6916. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6917. break;
  6918. case WT_PACKET:
  6919. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6920. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6921. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6922. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6923. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6924. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6925. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6926. MAIN.StylusTwist = tw;
  6927. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6928. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6929. MAIN.EraserPressure = MAIN.StylusPressure;
  6930. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6931. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6932. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6933. }
  6934. return 0; break;
  6935. case WM_SYSCOMMAND:
  6936. switch (wparam) {
  6937. case SC_MAXIMIZE:
  6938. case SC_RESTORE:
  6939. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6940. break;
  6941. case SC_KEYMENU:
  6942. return 0;
  6943. case SC_MINIMIZE:
  6944. break;
  6945. }
  6946. break;
  6947. case WM_SIZE:
  6948. if (wparam == SIZE_MINIMIZED) break;
  6949. case WM_MOVE: /* And size */
  6950. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6951. break;
  6952. case WM_SETCURSOR:
  6953. if(MAIN.CurrentCursor) return 1;
  6954. break;
  6955. case WM_POINTERDOWN:
  6956. case WM_POINTERUP:
  6957. case WM_POINTERUPDATE:
  6958. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6959. pointerId = GET_POINTERID_WPARAM(wparam);
  6960. pointerType = PT_POINTER;
  6961. if(!GetPointerType(pointerId, &pointerType)){
  6962. pointerType = PT_POINTER;
  6963. }
  6964. if(pointerType == PT_PEN){
  6965. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6966. for (int i = peninfonum-1; i>=0; i--) {
  6967. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6968. ScreenToClient(hwnd, &point);
  6969. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6970. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6971. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6972. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6973. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6974. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6975. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6976. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6977. }
  6978. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6979. }
  6980. }
  6981. SkipPointerFrameMessages(pointerId);
  6982. return 0;
  6983. }
  6984. else if (pointerType == PT_TOUCH){
  6985. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6986. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6987. ScreenToClient(hwnd, &point);
  6988. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6989. }
  6990. }
  6991. break;
  6992. case WM_SYSKEYDOWN:
  6993. if (lparam & 0x40000000) break;
  6994. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6995. break;
  6996. case WM_KEYDOWN:
  6997. if (lparam & 0x40000000) break;
  6998. vkey = wparam;
  6999. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  7000. break;
  7001. case WM_KEYUP:
  7002. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  7003. break;
  7004. case WM_SYSKEYUP:
  7005. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  7006. break;
  7007. case WM_UNICHAR:
  7008. la_SendInputEvent(hwnd, wparam);
  7009. break;
  7010. case WM_IME_CHAR:
  7011. la_SendInputEvent(hwnd, wparam);
  7012. return 0;
  7013. case WM_CHAR:
  7014. la_SendInputEvent(hwnd, wparam);
  7015. break;
  7016. case WM_SHOWWINDOW:
  7017. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  7018. break;
  7019. case WM_CLOSE:
  7020. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  7021. break;
  7022. default:
  7023. return DefWindowProc(hwnd, message, wparam, lparam);
  7024. }
  7025. return DefWindowProc(hwnd, message, wparam, lparam);
  7026. }
  7027. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  7028. return DefWindowProc(hwnd, message, wparam, lparam);
  7029. }
  7030. #endif
  7031. int la_UpdateOperatorHints(laWindow* w){
  7032. laSafeString* ss=0;
  7033. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  7034. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  7035. }
  7036. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  7037. }else{
  7038. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  7039. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  7040. }
  7041. strSafeDestroy(&ss);
  7042. }
  7043. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  7044. laOperator *a, *NextA = 0;
  7045. int Result = 0;
  7046. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  7047. la_SendSignalsFromEvent(e);
  7048. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  7049. a = Operators->pFirst;
  7050. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  7051. while (1){
  7052. if (!a) break;
  7053. if (a->StopNow){
  7054. NextA = a->Item.pNext;
  7055. if (a->Type->Exit) a->Type->Exit(a, Result);
  7056. ConfirmData = a->NextConfirmData;
  7057. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7058. NextConfirmData = ConfirmData;
  7059. a->ConfirmData = 0;
  7060. a->NextConfirmData = 0;
  7061. la_DestroyOperator(&a, Operators, 0);
  7062. a = NextA;
  7063. if (a){
  7064. a->ConfirmData = NextConfirmData;
  7065. }
  7066. continue;
  7067. }
  7068. a->Using = 1;
  7069. la_SetPropMathcerContext(a->ToPanel);
  7070. laSetOperatorLocalizer(a->ToPanel);
  7071. MAIN.CurrentPanel = a->ToPanel;
  7072. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7073. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  7074. e->Localized = 1;
  7075. }
  7076. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  7077. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  7078. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  7079. e->Localized = 0;
  7080. }
  7081. la_SetPropMathcerContext(0);
  7082. laSetOperatorLocalizer(0);
  7083. MAIN.CurrentPanel = 0;
  7084. a->Using = 0;
  7085. if (Result & LA_PASS_ON){
  7086. laConfirmSameDataIfAny(a);
  7087. NextA = a->Item.pNext;
  7088. }else{
  7089. NextA = 0;
  7090. if (a->NextConfirmData){
  7091. la_DestroyConfirmData(&a->NextConfirmData);
  7092. }
  7093. }
  7094. ConfirmData = a->NextConfirmData;
  7095. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  7096. NextConfirmData = ConfirmData;
  7097. a->ConfirmData = 0;
  7098. a->NextConfirmData = 0;
  7099. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  7100. if (a->Type->Exit) a->Type->Exit(a, Result);
  7101. la_DestroyOperator(&a, Operators, 0);
  7102. int found=0;
  7103. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  7104. if(!found){ NextA=0; }
  7105. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  7106. }
  7107. a = NextA;
  7108. if (a){
  7109. a->ConfirmData = NextConfirmData;
  7110. }
  7111. }
  7112. return 1;
  7113. }
  7114. int la_HandleEvents(laWindow *w){
  7115. laEvent *e, *NextE;
  7116. laOperator *a;
  7117. laThreadNotifier *tn;
  7118. MAIN.CurrentWindow=w;
  7119. //laSpinLock(&MAIN.csNotifier);
  7120. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  7121. //laSpinUnlock(&MAIN.csNotifier);
  7122. laNotifyUsers(tn->Path);
  7123. FreeMem(tn);
  7124. //if (MAIN.ThreadNotifiers.pFirst)
  7125. //laSpinLock(&MAIN.csNotifier);
  7126. }
  7127. //laSpinUnlock(&MAIN.csNotifier);
  7128. while (1){
  7129. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  7130. while (w->EventList.pFirst){
  7131. while (w->PendingOperators.pLast){
  7132. a = w->PendingOperators.pLast;
  7133. if (a->OperatorPanel){
  7134. laSetOperatorLocalizer(a->OperatorPanel);
  7135. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  7136. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  7137. }
  7138. lstRemoveItem(&w->PendingOperators, a);
  7139. lstPushItem(&w->Operators, a);
  7140. }
  7141. e = lstPopItem(&w->EventList);
  7142. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  7143. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  7144. memFree(e);
  7145. }
  7146. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  7147. if (!MAIN.ReTriggerOperators) break;
  7148. }
  7149. la_UpdateOperatorHints(w);
  7150. return 1;
  7151. }
  7152. int la_AllowInput(uint32_t ch){
  7153. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  7154. return 0;
  7155. }
  7156. int laCopyToClipboard(unsigned char * text){
  7157. #ifdef LA_LINUX
  7158. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  7159. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  7160. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  7161. strSafeSet(&MAIN.CopyPending, text);
  7162. #endif
  7163. }
  7164. int la_ProcessSysMessage(){
  7165. int SendDelay = 0, SendIdle = 0;
  7166. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  7167. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  7168. #ifdef LA_LINUX
  7169. XEvent e;
  7170. int type;
  7171. int InputCount = 0, CharCount=0;
  7172. KeySym InputKeysym = 0;
  7173. Status InputStatus = 0;
  7174. laWindow* wnd ;
  7175. while(XPending(MAIN.dpy)){
  7176. XGenericEventCookie *cookie = &e.xcookie;
  7177. XNextEvent(MAIN.dpy, &e);
  7178. if (XFilterEvent(&e, None)) continue;
  7179. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  7180. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  7181. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  7182. XFreeEventData(MAIN.dpy, cookie); continue;
  7183. }
  7184. switch(e.type){
  7185. case ConfigureNotify:
  7186. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  7187. break;
  7188. case Expose:
  7189. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  7190. if(!wnd) break;
  7191. laRefreshWindow(wnd);
  7192. break;
  7193. case MotionNotify:
  7194. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  7195. MAIN.IsPen=0;
  7196. break;
  7197. case ButtonPress:
  7198. type=LA_MOUSEDOWN;
  7199. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7200. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7201. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7202. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7203. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7204. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7205. MAIN.IsPen=0;
  7206. break;
  7207. case ButtonRelease:
  7208. type=LA_MOUSEUP;
  7209. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7210. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7211. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7212. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7213. MAIN.IsPen=0;
  7214. break;
  7215. case KeyPress:
  7216. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7217. MAIN.InputBuf[InputCount]=0;
  7218. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7219. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7220. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7221. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7222. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7223. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7224. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7225. #ifdef DEBUG
  7226. printf("pressed KEY: %d\n", (int)InputKeysym);
  7227. #endif
  7228. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7229. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7230. }
  7231. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7232. }
  7233. break;
  7234. case KeyRelease:
  7235. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7236. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7237. }
  7238. case ClientMessage:
  7239. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7240. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7241. }
  7242. break;
  7243. case SelectionNotify:
  7244. if(e.xselection.selection != MAIN.bufid) continue;
  7245. if (e.xselection.property){
  7246. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7247. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7248. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7249. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7250. else if(result) {
  7251. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7252. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7253. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7254. }
  7255. XFree(result);
  7256. return True;
  7257. }
  7258. case SelectionRequest:
  7259. if(!MAIN.CopyPending){ break; }
  7260. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7261. if (e.xselectionrequest.selection != MAIN.selection) break;
  7262. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7263. XSelectionEvent ev = {0};
  7264. int R = 0;
  7265. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7266. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7267. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7268. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7269. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7270. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7271. else if (ev.target == MAIN.UTF8)
  7272. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7273. else ev.property = None;
  7274. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7275. break;
  7276. case SelectionClear:
  7277. break;
  7278. default:
  7279. break;
  7280. }
  7281. }
  7282. #endif //linux
  7283. #ifdef _WIN32
  7284. MSG msg; int Processed = 0;
  7285. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7286. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7287. if (msg.wParam == VK_PROCESSKEY) {
  7288. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7289. }
  7290. TranslateMessage(&msg); DispatchMessage(&msg);
  7291. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7292. };
  7293. if(!MAIN.Windows.pFirst){ return 0; }
  7294. #endif
  7295. #ifdef LAGUI_ANDROID
  7296. int pollResult = 0;
  7297. int pollEvents = 0;
  7298. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7299. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7300. // NOTE: Never close window, native activity is controlled by the system!
  7301. if (MAIN.app->destroyRequested != 0)
  7302. {
  7303. //CORE.Window.shouldClose = true;
  7304. //ANativeActivity_finish(MAIN.app->activity);
  7305. }
  7306. }
  7307. #endif
  7308. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7309. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7310. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7311. }
  7312. return 1;
  7313. };
  7314. void la_PrintOperatorStack(){
  7315. laWindow *w = MAIN.CurrentWindow;
  7316. laOperator *a;
  7317. printf("\n");
  7318. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7319. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7320. a->Type->Identifier, a->Instance,
  7321. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7322. }
  7323. }
  7324. void la_DrawWindow(laWindow *w){
  7325. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7326. MAIN.CurrentWindow = w;
  7327. la_WindowDefDraw(w, 0);
  7328. }
  7329. int laFinalize(){
  7330. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7331. laUiTemplate* uit;
  7332. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7333. return 1;
  7334. }
  7335. void la_PreFrame(){
  7336. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7337. la_AnimationPreFrame();
  7338. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7339. }
  7340. void la_PostFrame(){
  7341. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7342. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7343. }
  7344. void laMainLoop(){
  7345. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7346. time_t t1, t2;
  7347. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7348. static int a = 0;
  7349. if(!laFinalize()) return;
  7350. laSetWindowCursor(LA_ARROW);
  7351. MAIN.DelayTriggered=1;
  7352. #ifdef LAGUI_ANDROID
  7353. while(!MAIN.AppReady){ usleep(1000); }
  7354. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7355. #endif
  7356. while (1){
  7357. laRecordTime(&MAIN.FrameStartTime);
  7358. la_PerfClear();
  7359. la_PreFrame();
  7360. if(!la_ProcessSysMessage()){ return; }
  7361. la_UpdateControllerStatus();
  7362. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7363. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7364. NextW = w->Item.pNext;
  7365. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7366. }
  7367. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7368. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7369. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7370. if(MAIN.GLDebugNeedsUpdate){
  7371. la_SetCurrentGLContextDebug();
  7372. }
  7373. la_DrawWindow(w);
  7374. }
  7375. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7376. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7377. #ifdef LA_LINUX
  7378. #ifdef LA_USE_GLES
  7379. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7380. #else
  7381. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7382. #endif
  7383. #endif
  7384. #ifdef _WIN32
  7385. SwapBuffers(w->hdc);
  7386. #endif
  7387. #ifdef LAGUI_ANDROID
  7388. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7389. #endif
  7390. }
  7391. MAIN.GLDebugNeedsUpdate=0;
  7392. la_PostFrame();
  7393. //t2 = clock();
  7394. laRecordTime(&MAIN.FrameEndTime);
  7395. TimeInterval = laTimeElapsedSecondsf(&MAIN.FrameEndTime, &MAIN.FrameStartTime);
  7396. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7397. if (Pause > 0){
  7398. int us = Pause * 1000000.0;
  7399. usleep(us);
  7400. }
  7401. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7402. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7403. la_AnimationPostFrame();
  7404. }
  7405. }
  7406. #ifdef LAGUI_ANDROID
  7407. int la_AndroidInitGraphics(void){
  7408. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7409. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7410. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7411. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7412. EGLint samples = 0;
  7413. EGLint sampleBuffer = 0;
  7414. const EGLint framebufferAttribs[] = {
  7415. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7416. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7417. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7418. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7419. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7420. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7421. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7422. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7423. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7424. EGL_NONE
  7425. };
  7426. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7427. EGLint numConfigs = 0;
  7428. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7429. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7430. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7431. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7432. eglBindAPI(EGL_OPENGL_API);
  7433. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7434. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7435. EGLint displayFormat = 0;
  7436. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7437. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7438. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7439. // There must be at least one frame displayed before the buffers are swapped
  7440. eglSwapInterval(MAIN.egl_dpy, 1);
  7441. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7442. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7443. MAIN.AppReady = 1;
  7444. return 0;
  7445. }
  7446. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7447. switch (cmd){
  7448. case APP_CMD_START: break;
  7449. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7450. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7451. case APP_CMD_RESUME:break;//InitPlatform();break;
  7452. case APP_CMD_INIT_WINDOW:
  7453. if (app->window != NULL){
  7454. if (MAIN.ContextRebindRequired){
  7455. // Reset screen scaling to full display size
  7456. EGLint displayFormat = 0;
  7457. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7458. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7459. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7460. // appropriate way to fix this
  7461. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7462. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7463. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7464. displayFormat);
  7465. // Recreate display surface and re-attach OpenGL context
  7466. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7467. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7468. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7469. //glClearColor(1,0.2,1,1);
  7470. //glClear(GL_COLOR_BUFFER_BIT);
  7471. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7472. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7473. MAIN.ContextRebindRequired = false;
  7474. }else{
  7475. la_AndroidInitGraphics();
  7476. }
  7477. }
  7478. break;
  7479. case APP_CMD_DESTROY:
  7480. case APP_CMD_TERM_WINDOW:
  7481. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7482. // 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.
  7483. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7484. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7485. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7486. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7487. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7488. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7489. MAIN.egl_surf = EGL_NO_SURFACE;
  7490. }
  7491. MAIN.ContextRebindRequired = true;
  7492. }
  7493. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7494. // this means that the user has already called 'CloseWindow()'
  7495. break;
  7496. case APP_CMD_SAVE_STATE: break;
  7497. case APP_CMD_STOP: break;
  7498. case APP_CMD_CONFIG_CHANGED:
  7499. case APP_CMD_WINDOW_RESIZED:
  7500. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7501. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7502. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7503. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7504. //print_cur_config(MAIN.app);
  7505. // Check screen orientation here!
  7506. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7507. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7508. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7509. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7510. MAIN.egl_surf = EGL_NO_SURFACE;
  7511. }
  7512. EGLint displayFormat = 0;
  7513. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7514. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7515. displayFormat);
  7516. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7517. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7518. }
  7519. break;
  7520. default: break;
  7521. }
  7522. }
  7523. #define KEYCODE_MAP_SIZE 162
  7524. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7525. 0, // AKEYCODE_UNKNOWN
  7526. 0, // AKEYCODE_SOFT_LEFT
  7527. 0, // AKEYCODE_SOFT_RIGHT
  7528. 0, // AKEYCODE_HOME
  7529. 0, // AKEYCODE_BACK
  7530. 0, // AKEYCODE_CALL
  7531. 0, // AKEYCODE_ENDCALL
  7532. '0', // AKEYCODE_0
  7533. '1', // AKEYCODE_1
  7534. '2', // AKEYCODE_2
  7535. '3', // AKEYCODE_3
  7536. '4', // AKEYCODE_4
  7537. '5', // AKEYCODE_5
  7538. '6', // AKEYCODE_6
  7539. '7', // AKEYCODE_7
  7540. '8', // AKEYCODE_8
  7541. '9', // AKEYCODE_9
  7542. 0, // AKEYCODE_STAR
  7543. 0, // AKEYCODE_POUND
  7544. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7545. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7546. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7547. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7548. 0, // AKEYCODE_DPAD_CENTER
  7549. 0, // AKEYCODE_VOLUME_UP
  7550. 0, // AKEYCODE_VOLUME_DOWN
  7551. 0, // AKEYCODE_POWER
  7552. 0, // AKEYCODE_CAMERA
  7553. 0, // AKEYCODE_CLEAR
  7554. 'a', // AKEYCODE_A
  7555. 'b', // AKEYCODE_B
  7556. 'c', // AKEYCODE_C
  7557. 'd', // AKEYCODE_D
  7558. 'e', // AKEYCODE_E
  7559. 'f', // AKEYCODE_F
  7560. 'g', // AKEYCODE_G
  7561. 'h', // AKEYCODE_H
  7562. 'i', // AKEYCODE_I
  7563. 'j', // AKEYCODE_J
  7564. 'k', // AKEYCODE_K
  7565. 'l', // AKEYCODE_L
  7566. 'm', // AKEYCODE_M
  7567. 'n', // AKEYCODE_N
  7568. 'o', // AKEYCODE_O
  7569. 'p', // AKEYCODE_P
  7570. 'q', // AKEYCODE_Q
  7571. 'r', // AKEYCODE_R
  7572. 's', // AKEYCODE_S
  7573. 't', // AKEYCODE_T
  7574. 'u', // AKEYCODE_U
  7575. 'v', // AKEYCODE_V
  7576. 'w', // AKEYCODE_W
  7577. 'x', // AKEYCODE_X
  7578. 'y', // AKEYCODE_Y
  7579. 'z', // AKEYCODE_Z
  7580. ',', // AKEYCODE_COMMA
  7581. '.', // AKEYCODE_PERIOD
  7582. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7583. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7584. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7585. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7586. LA_KEY_TAB, // AKEYCODE_TAB
  7587. ' ', // AKEYCODE_SPACE
  7588. 0, // AKEYCODE_SYM
  7589. 0, // AKEYCODE_EXPLORER
  7590. 0, // AKEYCODE_ENVELOPE
  7591. LA_KEY_ENTER, // AKEYCODE_ENTER
  7592. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7593. '`', // AKEYCODE_GRAVE
  7594. '-', // AKEYCODE_MINUS
  7595. '=', // AKEYCODE_EQUALS
  7596. '(', // AKEYCODE_LEFT_BRACKET
  7597. ')', // AKEYCODE_RIGHT_BRACKET
  7598. '\\', // AKEYCODE_BACKSLASH
  7599. ';', // AKEYCODE_SEMICOLON
  7600. '\'', // AKEYCODE_APOSTROPHE
  7601. '/', // AKEYCODE_SLASH
  7602. 0, // AKEYCODE_AT
  7603. 0, // AKEYCODE_NUM
  7604. 0, // AKEYCODE_HEADSETHOOK
  7605. 0, // AKEYCODE_FOCUS
  7606. 0, // AKEYCODE_PLUS
  7607. 0, // AKEYCODE_MENU
  7608. 0, // AKEYCODE_NOTIFICATION
  7609. 0, // AKEYCODE_SEARCH
  7610. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7611. 0, // AKEYCODE_MEDIA_STOP
  7612. 0, // AKEYCODE_MEDIA_NEXT
  7613. 0, // AKEYCODE_MEDIA_PREVIOUS
  7614. 0, // AKEYCODE_MEDIA_REWIND
  7615. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7616. 0, // AKEYCODE_MUTE
  7617. 0, // AKEYCODE_PAGE_UP
  7618. 0, // AKEYCODE_PAGE_DOWN
  7619. 0, // AKEYCODE_PICTSYMBOLS
  7620. 0, // AKEYCODE_SWITCH_CHARSET
  7621. 0, // AKEYCODE_BUTTON_A
  7622. 0, // AKEYCODE_BUTTON_B
  7623. 0, // AKEYCODE_BUTTON_C
  7624. 0, // AKEYCODE_BUTTON_X
  7625. 0, // AKEYCODE_BUTTON_Y
  7626. 0, // AKEYCODE_BUTTON_Z
  7627. 0, // AKEYCODE_BUTTON_L1
  7628. 0, // AKEYCODE_BUTTON_R1
  7629. 0, // AKEYCODE_BUTTON_L2
  7630. 0, // AKEYCODE_BUTTON_R2
  7631. 0, // AKEYCODE_BUTTON_THUMBL
  7632. 0, // AKEYCODE_BUTTON_THUMBR
  7633. 0, // AKEYCODE_BUTTON_START
  7634. 0, // AKEYCODE_BUTTON_SELECT
  7635. 0, // AKEYCODE_BUTTON_MODE
  7636. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7637. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7638. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7639. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7640. 0, // AKEYCODE_CAPS_LOCK
  7641. 0, // AKEYCODE_SCROLL_LOCK
  7642. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7643. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7644. 0, // AKEYCODE_FUNCTION
  7645. 0, // AKEYCODE_SYSRQ
  7646. 0, // AKEYCODE_BREAK
  7647. 0, // AKEYCODE_MOVE_HOME
  7648. 0, // AKEYCODE_MOVE_END
  7649. 0, // AKEYCODE_INSERT
  7650. 0, // AKEYCODE_FORWARD
  7651. 0, // AKEYCODE_MEDIA_PLAY
  7652. 0, // AKEYCODE_MEDIA_PAUSE
  7653. 0, // AKEYCODE_MEDIA_CLOSE
  7654. 0, // AKEYCODE_MEDIA_EJECT
  7655. 0, // AKEYCODE_MEDIA_RECORD
  7656. LA_KEY_F1, // AKEYCODE_F1
  7657. LA_KEY_F2, // AKEYCODE_F2
  7658. LA_KEY_F3, // AKEYCODE_F3
  7659. LA_KEY_F4, // AKEYCODE_F4
  7660. LA_KEY_F5, // AKEYCODE_F5
  7661. LA_KEY_F6, // AKEYCODE_F6
  7662. LA_KEY_F7, // AKEYCODE_F7
  7663. LA_KEY_F8, // AKEYCODE_F8
  7664. LA_KEY_F9, // AKEYCODE_F9
  7665. LA_KEY_F10, // AKEYCODE_F10
  7666. LA_KEY_F11, // AKEYCODE_F11
  7667. LA_KEY_F12, // AKEYCODE_F12
  7668. 0, // AKEYCODE_NUM_LOCK
  7669. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7670. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7671. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7672. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7673. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7674. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7675. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7676. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7677. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7678. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7679. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7680. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7681. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7682. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7683. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7684. 0, // AKEYCODE_NUMPAD_COMMA
  7685. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7686. '=' // AKEYCODE_NUMPAD_EQUALS
  7687. };
  7688. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7689. {
  7690. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7691. if(!MAIN.AppEnabled){return 0;}
  7692. //laRedrawAllWindows();
  7693. static int prev_button_state=0;
  7694. int type = AInputEvent_getType(event);
  7695. if(type == AINPUT_EVENT_TYPE_KEY){
  7696. int32_t keycode = AKeyEvent_getKeyCode(event);
  7697. //int32_t AKeyEvent_getMetaState(event);
  7698. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7699. if (key != 0){
  7700. // Save current key and its state
  7701. // NOTE: Android key action is 0 for down and 1 for up
  7702. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7703. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7704. if(key!=LA_KEY_BACKSPACE)
  7705. la_SendInputEvent(0,key);
  7706. }
  7707. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7708. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7709. la_SendInputEvent(0,key);
  7710. }
  7711. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7712. }
  7713. if (keycode == AKEYCODE_POWER)
  7714. {
  7715. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7716. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7717. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7718. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7719. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7720. return 0;
  7721. }
  7722. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7723. {
  7724. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7725. return 1;
  7726. }
  7727. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7728. {
  7729. // Set default OS behaviour
  7730. return 0;
  7731. }
  7732. return 0;
  7733. }
  7734. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7735. static real zoom_offset=1; static real temp_distance=0;
  7736. real zoom; int gesture_handled=0;
  7737. int pcount = AMotionEvent_getPointerCount(event); int x,y; static real cx=0,cy=0;
  7738. int32_t action = AMotionEvent_getAction(event);
  7739. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7740. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7741. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7742. if(pcount){
  7743. x=rx; y=ry;
  7744. int tool_type=AMotionEvent_getToolType(event,0);
  7745. real pressure = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_PRESSURE,0);
  7746. if(tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS || tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER){
  7747. MAIN.StylusPressure = MAIN.EraserPressure = pressure; MAIN.IsPen = 1;
  7748. MAIN.PointerIsEraser = (tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER);
  7749. }else{
  7750. MAIN.IsPen = 0;
  7751. }
  7752. if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
  7753. && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
  7754. real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
  7755. real ctx=(x+x2)/2, cty=(y+y2)/2;
  7756. real distance = tnsDistIdv2(x2,y2,rx,ry);
  7757. if(temp_distance){ zoom_offset*=(distance/temp_distance); }
  7758. temp_distance = distance;
  7759. while(zoom_offset > 1.1){ zoom_offset-=0.1;
  7760. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7761. la_SendMouseEvent(0, LA_MOUSEUP|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7762. }
  7763. while(zoom_offset < (1.0/1.1)){ zoom_offset+=(0.1/1.1);
  7764. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7765. la_SendMouseEvent(0, LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
  7766. }
  7767. if(cx || cy){
  7768. if(!gesture_handled){
  7769. real dist = tnsDistIdv2(ctx,cty,cx,cy);
  7770. while(dist > LA_RH){
  7771. int udlr = fabs(cty-cy) > fabs(ctx-cx);
  7772. int direction = udlr?(cty>cy?LA_KEY_ARRUP:LA_KEY_ARRDOWN):
  7773. (ctx>cx?LA_KEY_ARRLEFT:LA_KEY_ARRRIGHT);
  7774. real fac = (real)(LA_RH)/dist;
  7775. cx=tnsLinearItp(cx,ctx,fac); cy=tnsLinearItp(cy,cty,fac);
  7776. la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
  7777. la_SendKeyboardEvent(0, LA_KEY_DOWN, direction|LA_KEYBOARD_EVENT|LA_KEY_PANNING);
  7778. gesture_handled=1;
  7779. dist = tnsDistIdv2(ctx,cty,cx,cy);
  7780. }
  7781. }
  7782. }else{
  7783. cx=ctx; cy=cty;
  7784. }
  7785. }else{
  7786. temp_distance = 0; cx=0; cy=0;
  7787. }
  7788. if(flags==AMOTION_EVENT_ACTION_HOVER_MOVE){
  7789. la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
  7790. }
  7791. }
  7792. if(!gesture_handled){
  7793. if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_BUTTON_PRESS){
  7794. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7795. int btn=AMotionEvent_getButtonState(event);
  7796. int evtype=LA_L_MOUSE_DOWN;
  7797. if(btn & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_DOWN; }
  7798. elif(btn & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_DOWN; }
  7799. la_SendMouseEvent(0,evtype,x,y);
  7800. prev_button_state = btn;
  7801. }
  7802. else if (flags == AMOTION_EVENT_ACTION_UP || flags == AMOTION_EVENT_ACTION_BUTTON_RELEASE){
  7803. int btn=AMotionEvent_getButtonState(event); int changed = (~btn)&prev_button_state;
  7804. int evtype=LA_L_MOUSE_UP;
  7805. if(changed & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_UP; }
  7806. elif(changed & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_UP; }
  7807. la_SendMouseEvent(0,evtype,x,y);
  7808. }
  7809. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7810. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7811. }
  7812. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7813. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7814. }
  7815. }
  7816. }
  7817. //static float r=0;
  7818. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7819. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7820. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7821. //glClear(GL_COLOR_BUFFER_BIT);
  7822. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7823. return 0;
  7824. }
  7825. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7826. MAIN.AssetManager = manager;
  7827. MAIN.InternalDataPath = dataPath;
  7828. MAIN.ExternalDataPath = externalDataPath;
  7829. }
  7830. static int android_read(void *cookie, char *data, int dataSize){
  7831. return AAsset_read((AAsset *)cookie, data, dataSize);
  7832. }
  7833. static int android_write(void *cookie, const char *data, int dataSize){
  7834. return 0;
  7835. }
  7836. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7837. return AAsset_seek((AAsset *)cookie, offset, whence);
  7838. }
  7839. static int android_close(void *cookie){
  7840. AAsset_close((AAsset *)cookie);
  7841. return 0;
  7842. }
  7843. // Replacement for fopen()
  7844. // Ref: https://developer.android.com/ndk/reference/group/asset
  7845. FILE *android_fopen(const char *fileName, const char *mode)
  7846. {
  7847. char buf[1024];
  7848. if (mode[0] == 'w')
  7849. {
  7850. // fopen() is mapped to android_fopen() that only grants read access to
  7851. // assets directory through AAssetManager but we want to also be able to
  7852. // write data when required using the standard stdio FILE access functions
  7853. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7854. #undef fopen
  7855. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7856. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7857. result=fopen(buf, mode); if(result) return result;
  7858. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7859. return fopen(buf, mode);
  7860. #define fopen(name, mode) android_fopen(name, mode)
  7861. }
  7862. else
  7863. {
  7864. // NOTE: AAsset provides access to read-only asset
  7865. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7866. if (asset != NULL)
  7867. {
  7868. // Get pointer to file in the assets
  7869. return funopen(asset, android_read, android_write, android_seek, android_close);
  7870. }
  7871. else
  7872. {
  7873. #undef fopen
  7874. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7875. // Just do a regular open if file is not found in the assets
  7876. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7877. result=fopen(buf, mode); if(result){ return result; }
  7878. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7879. return fopen(buf, mode);
  7880. #define fopen(name, mode) android_fopen(name, mode)
  7881. }
  7882. }
  7883. }
  7884. void la_HideNavBar(){
  7885. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7886. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7887. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7888. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7889. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7890. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7891. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7892. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7893. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7894. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7895. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7896. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7897. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7898. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7899. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7900. int flag = flagFullscreen | flagHideNavigation;
  7901. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7902. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7903. }
  7904. void la_InitAndroidPlatform(struct android_app *app){
  7905. MAIN.app=app;
  7906. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7907. //la_HideNavBar();
  7908. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7909. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7910. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7911. int pollResult = 0;
  7912. int pollEvents = 0;
  7913. while (!MAIN.AppReady){
  7914. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7915. // Process this event
  7916. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7917. // NOTE: Never close window, native activity is controlled by the system!
  7918. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7919. }
  7920. }
  7921. }
  7922. int main(int, char *[]);
  7923. void android_main(struct android_app *app){
  7924. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7925. la_InitAndroidPlatform(app);
  7926. // NOTE: Return from main is ignored
  7927. (void)main(1, (char *[]) { arg0, NULL });
  7928. // Request to end the native activity
  7929. ANativeActivity_finish(app->activity);
  7930. // Android ALooper_pollAll() variables
  7931. int pollResult = 0;
  7932. int pollEvents = 0;
  7933. // Waiting for application events before complete finishing
  7934. while (!app->destroyRequested)
  7935. {
  7936. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7937. {
  7938. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7939. }
  7940. }
  7941. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "Application successfully ended.\n");
  7942. /* Unloads the native dynamic library so we can get clean restarts. */
  7943. exit(0);
  7944. }
  7945. void la_DisplayKeyboard(bool pShow) {
  7946. // Attaches the current thread to the JVM.
  7947. jint lResult;
  7948. jint lFlags = 0;
  7949. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7950. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7951. JavaVMAttachArgs lJavaVMAttachArgs;
  7952. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7953. lJavaVMAttachArgs.name = "NativeThread";
  7954. lJavaVMAttachArgs.group = NULL;
  7955. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7956. if (lResult == JNI_ERR) {
  7957. return;
  7958. }
  7959. // Retrieves NativeActivity.
  7960. jobject lNativeActivity = MAIN.app->activity->clazz;
  7961. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7962. logPrintNew("jvm3");
  7963. // Retrieves Context.INPUT_METHOD_SERVICE.
  7964. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7965. jfieldID FieldINPUT_METHOD_SERVICE =
  7966. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7967. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7968. jobject INPUT_METHOD_SERVICE =
  7969. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7970. FieldINPUT_METHOD_SERVICE);
  7971. //jniCheck(INPUT_METHOD_SERVICE);
  7972. logPrintNew("jvm4");
  7973. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7974. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7975. "android/view/inputmethod/InputMethodManager");
  7976. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7977. ClassNativeActivity, "getSystemService",
  7978. "(Ljava/lang/String;)Ljava/lang/Object;");
  7979. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7980. lNativeActivity, MethodGetSystemService,
  7981. INPUT_METHOD_SERVICE);
  7982. // Runs getWindow().getDecorView().
  7983. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7984. ClassNativeActivity, "getWindow",
  7985. "()Landroid/view/Window;");
  7986. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7987. MethodGetWindow);
  7988. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7989. "android/view/Window");
  7990. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7991. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7992. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7993. MethodGetDecorView);
  7994. if (pShow) {
  7995. // Runs lInputMethodManager.showSoftInput(...).
  7996. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7997. ClassInputMethodManager, "showSoftInput",
  7998. "(Landroid/view/View;I)Z");
  7999. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  8000. lInputMethodManager, MethodShowSoftInput,
  8001. lDecorView, lFlags);
  8002. } else {
  8003. // Runs lWindow.getViewToken()
  8004. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  8005. "android/view/View");
  8006. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8007. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  8008. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  8009. MethodGetWindowToken);
  8010. // lInputMethodManager.hideSoftInput(...).
  8011. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  8012. ClassInputMethodManager, "hideSoftInputFromWindow",
  8013. "(Landroid/os/IBinder;I)Z");
  8014. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  8015. lInputMethodManager, MethodHideSoftInput,
  8016. lBinder, lFlags);
  8017. }
  8018. // Finished with the JVM.
  8019. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8020. }
  8021. bool la_check_permission(const char* permission) {
  8022. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8023. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8024. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8025. jobject lNativeActivity = MAIN.app->activity->clazz;
  8026. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  8027. jmethodID activity_checkSelfPermission = (*lJNIEnv)->GetMethodID(lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  8028. jstring jobj_permission = (*lJNIEnv)->NewStringUTF(lJNIEnv,permission);
  8029. jint result = (*lJNIEnv)->CallIntMethod(lJNIEnv,ClassNativeActivity, activity_checkSelfPermission, jobj_permission);
  8030. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  8031. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8032. return result == 0;
  8033. }
  8034. void la_request_permission(const char* permission) {
  8035. JavaVM* lJavaVM = MAIN.app->activity->vm;
  8036. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  8037. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  8038. jobject lNativeActivity = MAIN.app->activity->clazz;
  8039. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  8040. jmethodID contextCompat_checkSelfPermission = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "checkSelfPermission", "(Ljava/lang/String;)I");
  8041. jmethodID activity_requestPermissions = (*lJNIEnv)->GetMethodID (lJNIEnv, ClassNativeActivity, "requestPermissions", "([Ljava/lang/String;I)V");
  8042. jstring jobj_permission = (*lJNIEnv)->NewStringUTF (lJNIEnv,permission);
  8043. jobjectArray jobj_permission_list = (*lJNIEnv)->NewObjectArray(lJNIEnv,1, (*lJNIEnv)->FindClass(lJNIEnv,"java/lang/String"), NULL);
  8044. (*lJNIEnv)->SetObjectArrayElement(lJNIEnv,jobj_permission_list, 0, jobj_permission);
  8045. (*lJNIEnv)->CallVoidMethod (lJNIEnv,lNativeActivity, activity_requestPermissions, jobj_permission_list, 0);
  8046. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission);
  8047. (*lJNIEnv)->DeleteLocalRef(lJNIEnv,jobj_permission_list);
  8048. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  8049. }
  8050. #endif //android
  8051. #ifndef LAGUI_ANDROID
  8052. void la_DisplayKeyboard(bool pShow) {
  8053. return;
  8054. }
  8055. void la_HideNavBar(){
  8056. return;
  8057. }
  8058. #endif