*/}}

la_kernel.c 342 KB

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