*/}}

la_kernel.c 331 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  19. #define NANOVG_GLES3_IMPLEMENTATION
  20. #else
  21. #define NANOVG_GL3_IMPLEMENTATION
  22. #endif
  23. #include "la_5.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <time.h>
  28. #ifdef LA_LINUX
  29. #include <execinfo.h>
  30. #include <signal.h>
  31. #include <sys/time.h>
  32. #include <X11/Xlib.h>
  33. #include <X11/Xutil.h>
  34. #include <X11/Xos.h>
  35. #include <X11/keysymdef.h>
  36. #include <X11/XKBlib.h>
  37. #include <X11/extensions/XInput.h>
  38. #include <X11/extensions/XInput2.h>
  39. #include <X11/extensions/Xfixes.h>
  40. #include <X11/extensions/Xrandr.h>
  41. #include <X11/Xcursor/Xcursor.h>
  42. #include <X11/cursorfont.h>
  43. #include <GL/glx.h>
  44. #endif
  45. #ifdef _WIN32
  46. #include <GL/wglew.h>
  47. #include <GL/wgl.h>
  48. #include <shellscalingapi.h>
  49. #endif
  50. #ifdef LAGUI_ANDROID
  51. #include <GLES3/gl32.h>
  52. #include <jni.h>
  53. #include <android/log.h>
  54. #include <android/native_activity.h>
  55. #include <android/native_window.h>
  56. #include <android/native_window_jni.h>
  57. #include <android_native_app_glue.h>
  58. #include <android/window.h>
  59. #include <android/asset_manager.h>
  60. FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
  61. fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
  62. static int android_read(void *cookie, char *buf, int size);
  63. static int android_write(void *cookie, const char *buf, int size);
  64. static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
  65. static int android_close(void *cookie);
  66. void la_InitAndroidPlatform(struct android_app *app);
  67. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd);
  68. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event);
  69. void la_InitAndroidPlatform(struct android_app *app);
  70. #endif
  71. LA MAIN={0};
  72. extern tnsMain *T;
  73. int deb = 0;
  74. laOperator *DEB;
  75. laColumn *DEBUG_C;
  76. #ifdef _WIN32
  77. #define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
  78. #else
  79. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  80. #endif
  81. #ifdef LA_LINUX
  82. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);\
  83. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  84. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  85. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  86. #endif
  87. #ifdef LA_LINUX
  88. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  89. int i;
  90. for (i = 0; i < num_classes; i++) {
  91. if (classes[i]->type == XIValuatorClass) {
  92. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  93. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  94. logPrint(" Range: %f - %f\n", v->min, v->max);
  95. logPrint(" Resolution: %d units/m\n", v->resolution);
  96. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  97. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  98. }
  99. }
  100. }
  101. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  102. XIDeviceInfo *info, *dev;
  103. int i, ndevices;
  104. dev = XIQueryDevice(display, deviceid, &ndevices);
  105. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  106. mask->deviceid = deviceid;
  107. mask->mask_len = XIMaskLen(XI_RawMotion);
  108. mask->mask=memAcquireSimple(mask->mask_len);
  109. memset(mask->mask, 0, mask->mask_len);
  110. XISetMask(mask->mask, XI_RawMotion);
  111. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  112. int FoundMax=0;
  113. for (i = 0; i < dev->num_classes; i++) {
  114. if (dev->classes[i]->type == XIValuatorClass) {
  115. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  116. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  117. }
  118. }
  119. if(!FoundMax){*max_pressure=65535;}
  120. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  121. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  122. XIFreeDeviceInfo(dev);
  123. }
  124. int la_DeviceProbablyHasPressure(XIDeviceInfo* dev){
  125. int axis=0;
  126. for (int i = 0; i < dev->num_classes; i++) {
  127. if (dev->classes[i]->type == XIValuatorClass){ axis++; }
  128. }
  129. return axis>=3;
  130. }
  131. #define LA_G_STYLUS(dev) \
  132. (la_DeviceProbablyHasPressure(dev)&&(!MAIN.WacomDeviceStylus))
  133. #define LA_G_ERASER \
  134. (!MAIN.WacomDeviceEraser)
  135. void la_ScanWacomDevices(Display *display, int deviceid){
  136. XIDeviceInfo *info, *dev;
  137. int ndevices;
  138. int i; char * word;
  139. int _event, _error;
  140. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  141. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  142. }
  143. info = XIQueryDevice(display, deviceid, &ndevices);
  144. for(i = 0; i < ndevices; i++) {
  145. dev = &info[i]; strToLower(dev->name);
  146. if (strstr(dev->name, "pen pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some wacom tablets "wacom bamboo connect pen pen"
  147. elif (strstr(dev->name, "stylus pen")){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; } // some huion ones "HUION 256C PEN STYLUS Pen"
  148. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  149. word = strtok (dev->name," ");
  150. while (1) {
  151. word = strtok (NULL, " "); if (!word) break;
  152. if (strcmp("stylus", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// wacom
  153. elif (strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// wacom
  154. elif (is_ipts && strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// surface ipts
  155. elif (is_ipts && strcmp("eraser", word) == 0){ if(LA_G_ERASER) MAIN.WacomDeviceEraser = dev->deviceid; }// surface ipts
  156. elif (strcmp("pen", word) == 0){ if(LA_G_STYLUS(dev)) MAIN.WacomDeviceStylus = dev->deviceid; }// generic pen
  157. }
  158. }
  159. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  160. logPrintNew("Found wacom devices:\n");
  161. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  162. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  163. }else{
  164. logPrintNew("No wacom pen device connected.\n");
  165. }
  166. XIFreeDeviceInfo(info);
  167. }
  168. void laHideCursor(){
  169. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  170. }
  171. void laShowCursor(){
  172. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  173. }
  174. void la_XErrorHandler(Display *display, XErrorEvent *event){
  175. char buf[512];
  176. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  177. printf("X Error:\n%s\n",buf);
  178. }
  179. SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
  180. XSetWindowAttributes swa;
  181. XWindowAttributes wa;
  182. swa.event_mask =
  183. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  184. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  185. swa.colormap = MAIN.cmap;
  186. SYSWINDOW root = DefaultRootWindow(MAIN.dpy);
  187. SYSWINDOW win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  188. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  189. if(x>0||y>0){
  190. XSizeHints my_hints = {0};
  191. my_hints.flags = PPosition;
  192. my_hints.x = x; my_hints.y = y;
  193. XSetNormalHints(MAIN.dpy, win, &my_hints);
  194. }
  195. XStoreName(MAIN.dpy, win, title);
  196. #ifdef LA_USE_GLES
  197. static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  198. (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
  199. if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
  200. EGLSurface* surf=egl_surf;
  201. (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
  202. if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
  203. tnsContextMakeCurrent((*r_glc),win,(*surf));
  204. #else
  205. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  206. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  207. printf("\n\tcannot create gl context\n\n"); exit(0);
  208. }
  209. tnsContextMakeCurrent((*r_glc),win,0);
  210. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  211. #endif
  212. XSetLocaleModifiers("");
  213. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  214. if(!MAIN.im){
  215. XSetLocaleModifiers("@im=local");
  216. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  217. }
  218. if(!MAIN.im){
  219. XSetLocaleModifiers("@im=none");
  220. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  221. }
  222. if(!MAIN.im){
  223. XSetLocaleModifiers("@im=");
  224. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  225. }
  226. if(!MAIN.im){
  227. logPrint("Can't open a input method.\n");
  228. }
  229. if(MAIN.im){
  230. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  231. XSetICFocus(MAIN.ic);
  232. }
  233. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  234. XSetClassHint(MAIN.dpy, win, &ch);
  235. #define _NET_WM_STATE_ADD 1
  236. if(w<0&&h<0){
  237. XEvent xev;
  238. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  239. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  240. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  241. memset(&xev, 0, sizeof(xev));
  242. xev.type = ClientMessage;
  243. xev.xclient.window = win;
  244. xev.xclient.message_type = wm_state;
  245. xev.xclient.format = 32;
  246. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  247. xev.xclient.data.l[1] = max_horz;
  248. xev.xclient.data.l[2] = max_vert;
  249. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  250. }
  251. return win;
  252. };
  253. void la_DestroySystemWindowX11(laWindow* w) {
  254. tnsContextMakeCurrent(0,0,0);
  255. tnsDeleteContext(w->glc);
  256. #ifdef LA_USE_GLES
  257. eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
  258. #endif
  259. XDestroyWindow(MAIN.dpy, w->win);
  260. };
  261. #endif //linux
  262. #ifdef _WIN32
  263. #include <msgdef.h>
  264. #include <wintab.h>
  265. #include <wintab_utils.h>
  266. #define PACKETDATA (PK_X | PK_Y | PK_Z | PK_STATUS | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_TIME | PK_CURSOR)
  267. #define PACKETMODE PK_BUTTONS
  268. #include <pktdef.h>
  269. void la_OpenWacomWinTab(HWND hwnd){
  270. if((!MAIN.WinTabAvailable)||(MAIN.WinTabOpened)) return;
  271. static LOGCONTEXT glogContext = { 0 };
  272. HCTX hctx = NULL;
  273. UINT wDevice = 0; UINT wExtX = 0; UINT wExtY = 0;
  274. UINT wWTInfoRetVal = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; AXIS TabletZ = { 0 };
  275. glogContext.lcOptions |= CXO_SYSTEM;
  276. wWTInfoRetVal = gpWTInfoA(WTI_DEFSYSCTX, 0, &glogContext);
  277. assert(wWTInfoRetVal == sizeof(LOGCONTEXT));
  278. assert(glogContext.lcOptions & CXO_SYSTEM);
  279. wsprintf(glogContext.lcName, "PrsTest Digitizing %p", MAIN.hinstance);
  280. glogContext.lcOptions |= CXO_MESSAGES|CXO_CSRMESSAGES;
  281. glogContext.lcPktData = PACKETDATA;
  282. glogContext.lcPktMode = PACKETMODE;
  283. glogContext.lcMoveMask = PACKETDATA;
  284. glogContext.lcBtnUpMask = glogContext.lcBtnDnMask;
  285. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES + 0, DVC_X, &TabletX);
  286. assert(wWTInfoRetVal == sizeof(AXIS));
  287. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
  288. assert(wWTInfoRetVal == sizeof(AXIS));
  289. wWTInfoRetVal = gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
  290. assert(wWTInfoRetVal == sizeof(AXIS));
  291. MAIN.WinTabMaxHover = TabletZ.axMax;
  292. AXIS tabletPressure = { 0 };
  293. gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &tabletPressure); MAIN.WinTabMaxPenPressure = tabletPressure.axMax + 1;
  294. //glogContext.lcInOrgX = 0;
  295. //glogContext.lcInOrgY = 0;
  296. //glogContext.lcInExtX = TabletX.axMax;
  297. //glogContext.lcInExtY = TabletY.axMax;
  298. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGX, &glogContext.lcInOrgX);
  299. gpWTInfoA(WTI_DEFSYSCTX, CTX_INORGY, &glogContext.lcInOrgY);
  300. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTX, &glogContext.lcInExtX);
  301. gpWTInfoA(WTI_DEFSYSCTX, CTX_INEXTY, &glogContext.lcInExtY);
  302. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGX, &glogContext.lcOutOrgX);
  303. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTORGY, &glogContext.lcOutOrgY);
  304. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTX, &glogContext.lcOutExtX);
  305. gpWTInfoA(WTI_DEFSYSCTX, CTX_OUTEXTY, &glogContext.lcOutExtY);
  306. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGX, &glogContext.lcSysOrgX);
  307. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSORGY, &glogContext.lcSysOrgY);
  308. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTX, &glogContext.lcSysExtX);
  309. gpWTInfoA(WTI_DEFSYSCTX, CTX_SYSEXTY, &glogContext.lcSysExtY);
  310. //printf("%d %d\n", glogContext.lcInOrgX, glogContext.lcInOrgY);
  311. //printf("%d %d\n", glogContext.lcInExtX, glogContext.lcInExtY);
  312. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  313. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  314. //printf("%d %d\n", glogContext.lcSysOrgX, glogContext.lcSysOrgY);
  315. //printf("%d %d\n", glogContext.lcSysExtX, glogContext.lcSysExtY);
  316. glogContext.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN);
  317. glogContext.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN);
  318. glogContext.lcOutExtX = GetSystemMetrics(SM_CXVIRTUALSCREEN); //SM_CXSCREEN);
  319. glogContext.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); // lower left to upper left. SM_CYSCREEN);
  320. //printf("%d %d\n", glogContext.lcOutOrgX, glogContext.lcOutOrgY);
  321. //printf("%d %d\n", glogContext.lcOutExtX, glogContext.lcOutExtY);
  322. hctx = gpWTOpenA(hwnd, &glogContext, FALSE);
  323. if (!hctx)return;
  324. gpWTEnable(hctx, 1); MAIN.WinTabOpened = 1;
  325. logPrintNew("Successfully opened Wacom input device via WinTab.\n");
  326. }
  327. void laHideCursor() {
  328. if (!MAIN.CurrentWindow) return; //impl
  329. }
  330. void laShowCursor() {
  331. if (!MAIN.CurrentWindow) return; //impl
  332. }
  333. static PIXELFORMATDESCRIPTOR cpfd = {
  334. sizeof(PIXELFORMATDESCRIPTOR),1,
  335. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_COPY | PFD_DOUBLEBUFFER,
  336. PFD_TYPE_RGBA,
  337. 8,
  338. 0, 0, 0, 0, 0, 0,
  339. 0, 0, 0,
  340. 0, 0, 0, 0,
  341. 32,
  342. 8, 0,
  343. 0,
  344. 0, 0, 0, 0
  345. };
  346. void la_SetupPxlFormat(HDC hdc, int* nRegularFormat, int* nMSFormat) {
  347. int nBestMS = 0;
  348. int i;
  349. int iResults[9];
  350. int iAttributes[9] = { WGL_SUPPORT_OPENGL_ARB, // 0
  351. WGL_ACCELERATION_ARB, // 1
  352. WGL_DRAW_TO_WINDOW_ARB, // 2
  353. WGL_DOUBLE_BUFFER_ARB, // 3
  354. WGL_PIXEL_TYPE_ARB, // 4
  355. WGL_DEPTH_BITS_ARB, // 5
  356. WGL_STENCIL_BITS_ARB, // 6
  357. WGL_SAMPLE_BUFFERS_ARB, // 7
  358. WGL_SAMPLES_ARB }; // 8
  359. // How many pixelformats are there?
  360. int nFormatCount[] = { 0 };
  361. int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB };
  362. if (!wglGetPixelFormatAttribivARB)
  363. wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
  364. wglGetProcAddress("wglGetPixelFormatAttribivARB");
  365. wglGetPixelFormatAttribivARB(hdc, 1, 0, 1, attrib, nFormatCount);
  366. for (i = 0; i < nFormatCount[0]; i++){
  367. wglGetPixelFormatAttribivARB(hdc, i + 1, 0, 9, iAttributes, iResults);
  368. if (iResults[0] == 1 && iResults[1] == WGL_FULL_ACCELERATION_ARB && iResults[2] == 1)
  369. if (iResults[3] == 1) // Double buffered
  370. if (iResults[4] == WGL_TYPE_RGBA_ARB) // Full Color
  371. if (iResults[5] >= 24) // Any Depth greater than 16
  372. if (iResults[6] > 0) { *nRegularFormat = i; break; }
  373. }
  374. SetPixelFormat(hdc, *nRegularFormat, &cpfd);
  375. };
  376. void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
  377. GLint Attrib[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor,
  378. WGL_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor,
  379. WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  380. //WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
  381. 0 };
  382. HGLRC hglrc = 0;
  383. HDC hdc = 0;
  384. int a, b;
  385. hdc = GetDC(hwnd);
  386. la_SetupPxlFormat(hdc, &a, &b);
  387. hglrc = wglCreateContextAttribsARB(hdc, MAIN.glc, Attrib);
  388. if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
  389. tnsContextMakeCurrent(hglrc, hdc,0);
  390. //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
  391. wglSwapIntervalEXT(-1);
  392. window->win = hwnd; window->glc = hglrc; window->hdc = hdc;
  393. };
  394. SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int SyncToVBlank, SYSGLCONTEXT* r_glc) {
  395. HINSTANCE* inst = &MAIN.hinstance;
  396. HWND hwnd = CreateWindowW(LA_GUI_WNDCLASS_NAME, title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  397. x, y, w, h, 0, 0, *inst, 0);
  398. if (!hwnd) { int a = GetLastError(); printf("%d", a); return 0; }
  399. if (!MAIN.WinTabOpened) { la_OpenWacomWinTab(hwnd); }
  400. return hwnd;
  401. };
  402. void la_DestroySystemWindowWin32(laWindow* w) {
  403. tnsContextMakeCurrent(0,0,0);
  404. tnsDeleteContext(w->glc);
  405. ReleaseDC(w->win, w->hdc);
  406. DestroyWindow(w->win);
  407. };
  408. #endif
  409. #ifdef LAGUI_ANDROID
  410. SYSWINDOW la_CreateWindowAndroid(){
  411. return 0;
  412. };
  413. void laShowCursor(){}
  414. void laHideCursor(){}
  415. #endif
  416. #ifdef LA_LINUX
  417. void la_HandlerSIGSEGV(int sig) {
  418. void *array[30];
  419. size_t sz;
  420. sz = backtrace(array, 30);
  421. fprintf(stdout, "LaGUI recieved error signal %d:\n The program terminated unexpectedly.\n", sig);
  422. backtrace_symbols_fd(array, sz, STDERR_FILENO);
  423. exit(1);
  424. }
  425. #endif
  426. void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
  427. GLenum severity, GLsizei length, const char* message, const void* userParam) {
  428. //#ifndef LAGUI_ANDROID
  429. // ignore non-significant error/warning codes
  430. if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
  431. logPrint("GL %d: %s\n", id, message);
  432. char* strsource="",*strtype="",*strseverity="";
  433. switch (source) {
  434. case GL_DEBUG_SOURCE_API: strsource = "API"; break;
  435. case GL_DEBUG_SOURCE_WINDOW_SYSTEM: strsource = "Window System"; break;
  436. case GL_DEBUG_SOURCE_SHADER_COMPILER: strsource = "Shader Compiler"; break;
  437. case GL_DEBUG_SOURCE_THIRD_PARTY: strsource = "Third Party"; break;
  438. case GL_DEBUG_SOURCE_APPLICATION: strsource = "Application"; break;
  439. case GL_DEBUG_SOURCE_OTHER: strsource = "Other"; break;
  440. }
  441. switch (type) {
  442. case GL_DEBUG_TYPE_ERROR: strtype = "Error"; break;
  443. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: strtype = "Deprecated Behaviour"; break;
  444. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: strtype = "Undefined Behaviour"; break;
  445. case GL_DEBUG_TYPE_PORTABILITY: strtype = "Portability"; break;
  446. case GL_DEBUG_TYPE_PERFORMANCE: strtype = "Performance"; break;
  447. case GL_DEBUG_TYPE_MARKER: strtype = "Marker"; break;
  448. case GL_DEBUG_TYPE_PUSH_GROUP: strtype = "Push Group"; break;
  449. case GL_DEBUG_TYPE_POP_GROUP: strtype = "Pop Group"; break;
  450. case GL_DEBUG_TYPE_OTHER: strtype = "Other"; break;
  451. }
  452. switch (severity) {
  453. case GL_DEBUG_SEVERITY_HIGH: strseverity = "High"; break;
  454. case GL_DEBUG_SEVERITY_MEDIUM: strseverity = "Medium"; break;
  455. case GL_DEBUG_SEVERITY_LOW: strseverity = "Low"; break;
  456. case GL_DEBUG_SEVERITY_NOTIFICATION: strseverity = "Notification"; break;
  457. }
  458. logPrint("%s | %s | %s\n\n", strsource,strtype,strseverity);
  459. //#endif
  460. }
  461. void la_SetCurrentGLContextDebug(){
  462. //#ifndef LAGUI_ANDROID
  463. int force=MAIN.InitArgs.GLDebug;
  464. if(MAIN.EnableGLDebug || force){ glEnable(GL_DEBUG_OUTPUT); }else{ glDisable(GL_DEBUG_OUTPUT); }
  465. if(MAIN.GLDebugSync || force){ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }else{ glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); }
  466. glDebugMessageCallback(la_glDebugOutput, 0);
  467. int sev=GL_DONT_CARE;
  468. if(!force){
  469. switch(MAIN.GLDebugLevel){
  470. default: sev=GL_DONT_CARE; break;
  471. case 1: sev=GL_DEBUG_SEVERITY_NOTIFICATION; break;
  472. case 2: sev=GL_DEBUG_SEVERITY_LOW; break;
  473. case 3: sev=GL_DEBUG_SEVERITY_MEDIUM; break;
  474. case 4: sev=GL_DEBUG_SEVERITY_HIGH; break;
  475. }
  476. }
  477. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, sev, 0, 0, GL_TRUE);
  478. //#endif
  479. }
  480. void la_NotifyGLDebugChanges(){
  481. MAIN.GLDebugNeedsUpdate=1; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){ w->GLDebugNeedsUpdate=1; }
  482. }
  483. void la_SetupWindowGLStates(laWindow* w){
  484. tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  485. if(w->GLDebugNeedsUpdate){
  486. tnsContextMakeWindowCurrent(w);
  487. la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
  488. }
  489. }
  490. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  491. SYSGLCONTEXT glc;
  492. #ifdef LA_LINUX
  493. void* egl_surf=0;
  494. #ifdef LA_USE_GLES
  495. egl_surf=&window->egl_surf;
  496. #endif
  497. SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
  498. #endif
  499. #ifdef _WIN32
  500. SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  501. #endif
  502. #ifdef LAGUI_ANDROID
  503. la_CreateWindowAndroid();
  504. window->win = 1;
  505. window->glc = MAIN.glc;
  506. #else
  507. window->win = hwnd;
  508. window->glc = glc;
  509. #endif
  510. #ifdef _WIN32
  511. la_SetupGLEnviornment(window, hwnd, SyncToVBlank);
  512. RECT rc; GetClientRect(window->win, &rc);
  513. window->CW = rc.right - rc.left;
  514. window->CH = rc.bottom - rc.top;
  515. #endif
  516. #ifdef LA_LINUX
  517. XWindowAttributes attr;
  518. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  519. window->CW =attr.width;
  520. window->CH = attr.height;
  521. #endif
  522. la_SetCurrentGLContextDebug();
  523. glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
  524. la_SetupWindowGLStates(window);
  525. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  526. window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  527. #else
  528. window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
  529. #endif
  530. window->OutputShowStripes=1; window->Redraw=1;
  531. window->GLDebugNeedsUpdate=1;
  532. window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
  533. return 1;
  534. };
  535. int la_DestroySystemWindow(laWindow* wnd){
  536. #if defined(LA_USE_GLES) || defined(LAGUI_ANDROID)
  537. nvgDeleteGLES3(wnd->nvg);
  538. #else
  539. nvgDeleteGL3(wnd->nvg);
  540. #endif
  541. #ifdef LA_LINUX
  542. la_DestroySystemWindowX11(wnd);
  543. #endif
  544. #ifdef _WIN32
  545. la_DestroySystemWindowWin32(wnd);
  546. #endif
  547. }
  548. void la_DestroyWindow(laWindow *wnd){
  549. laLayout *l; laPanel *p; if (!wnd) return;
  550. tnsSwitchToCurrentWindowContext(wnd);
  551. tnsBindVertexArray(0); glDeleteVertexArrays(1,&wnd->vao);
  552. la_StopAllOperators();
  553. strSafeDestroy(&wnd->Title);
  554. //la_PrintUserList(wnd);
  555. //printf("----\n");
  556. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  557. while (l = lstPopItem(&wnd->Layouts)){
  558. laDestroyBlocksRecursive(l->FirstBlock);
  559. //la_PrintUserList(l);
  560. //printf("%x %s\n", l, l->ID->Ptr);
  561. strSafeDestroy(&l->ID);
  562. memFree(l);
  563. //la_PrintUserList(wnd);
  564. //printf("----\n");
  565. }
  566. //printf("----\n%x\n",wnd);
  567. //la_PrintUserList(wnd);
  568. la_DestroySystemWindow(wnd);
  569. lstRemoveItem(&MAIN.Windows, wnd);
  570. memFree(wnd);
  571. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  572. }
  573. void laRenameWindow(laWindow* wnd, char* name){
  574. if((!wnd)||MAIN.IsReadingUDF) return;
  575. strSafeSet(&wnd->Title, name);
  576. if(!wnd->win) return;
  577. #ifdef LA_LINUX
  578. XStoreName(MAIN.dpy, wnd->win, name);
  579. #endif
  580. #ifdef _WIN32
  581. //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
  582. SetWindowTextW(wnd->win, name);
  583. #endif
  584. }
  585. #ifdef LA_LINUX
  586. const char* la_ConvertCursorID(int id){
  587. switch (id) {
  588. case LA_ARROW: return "arrow";
  589. case LA_CROSS: return "cross";
  590. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  591. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  592. case LA_MOVE: return "diamond_cross";
  593. case LA_HAND: return "hand1";
  594. case LA_CORNER: return "bottom_right_corner";
  595. }
  596. return "arrow";
  597. }
  598. #endif
  599. #ifdef _WIN32
  600. HCURSOR la_ConvertCursorID(int id){
  601. switch (id){
  602. case LA_ARROW: return LoadCursor(0,IDC_ARROW);
  603. case LA_CROSS: return LoadCursor(0,IDC_CROSS);
  604. case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
  605. case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
  606. case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
  607. case LA_HAND: return LoadCursor(0, IDC_HAND);
  608. case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
  609. }
  610. return LoadCursor(0, IDC_ARROW);;
  611. }
  612. #endif
  613. void la_InitThreadEnviornment(){
  614. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  615. }
  616. laLogEntry* logEnsure(int Create){
  617. if(!MAIN.Logs.pFirst || Create){
  618. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  619. lstAppendItem(&MAIN.Logs, le);
  620. }
  621. return MAIN.Logs.pLast;
  622. }
  623. void logPrintTV(int Continued, char* format, va_list v){
  624. if(!format || !format[0]) return;
  625. laLogEntry* le=logEnsure(Continued);
  626. if(MAIN.EnableLogStdOut){ va_list v1; va_copy(v1,v); vprintf(format,v1); }
  627. strSafePrintV(&le->Content, format, v);
  628. #ifdef LAGUI_ANDROID
  629. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  630. #endif
  631. laNotifyUsers("la.logs");
  632. }
  633. void logPrintT(int Continued, char* format, ...){
  634. if(!format || !format[0]) return;
  635. laLogEntry* le=logEnsure(Continued);
  636. va_list aptr; va_start(aptr, format);
  637. strSafePrint(&le->Content, format, aptr);
  638. va_end(aptr);
  639. #ifdef LAGUI_ANDROID
  640. __android_log_print(ANDROID_LOG_DEBUG, "LAGUI", "%s",SSTR(le->Content));
  641. #endif
  642. laNotifyUsers("la.logs");
  643. }
  644. void logPrint(char* format, ...){
  645. va_list aptr; va_start(aptr, format);
  646. logPrintTV(0, format, aptr);
  647. va_end(aptr);
  648. }
  649. void logPrintNew(char* format, ...){
  650. logEnsure(1);
  651. va_list aptr; va_start(aptr, format);
  652. logPrintTV(0, format, aptr);
  653. va_end(aptr);
  654. }
  655. void logClear(){
  656. laLogEntry*l;
  657. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  658. laNotifyUsers("la.logs");
  659. }
  660. laScreen* la_EnsureScreen(char* Name, int mmw, int mmh, int x, int y, int w, int h,int dpi){ if(!Name || !Name[0]) return 0;
  661. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  662. if(strSame(SSTR(s->Name),Name)){ s->x=x;s->y=y;s->w=w;s->h=h; return s; }
  663. }
  664. laScreen* s=memAcquire(sizeof(laScreen)); lstAppendItem(&MAIN.Screens,s);
  665. strSafeSet(&s->Name,Name);
  666. strSafePrint(&s->Description,"%dmm x %dmm with %dx%d ~%ddpi",mmw,mmh,w,h,dpi); s->RoughDPI=dpi;
  667. s->x=x;s->y=y;s->w=w;s->h=h;
  668. laNotifyUsers("la.user_preferences.screens");
  669. return s;
  670. }
  671. void la_RemoveScreen(laScreen*s){
  672. strSafeDestroy(&s->Description); strSafeDestroy(&s->Name);
  673. lstRemoveItem(&MAIN.Screens,s); memFree(s);
  674. }
  675. void la_RemoveDuplicatedScreenConf(){
  676. laScreen* NextS;
  677. for(laScreen* s=MAIN.Screens.pFirst;s;s=NextS){
  678. NextS = s->Item.pNext;
  679. for(laScreen* fs=s->Item.pNext;fs;fs=fs->Item.pNext){
  680. if(strSame(SSTR(fs->Name),SSTR(s->Name))){ fs->x=s->x;fs->y=s->y;fs->w=s->w;fs->h=s->h; la_RemoveScreen(s); break; }
  681. }
  682. }
  683. }
  684. laScreen* laGetWindowScreen(laWindow* w){
  685. int l,r,u,b; int area=-1; laScreen* maxs=0;
  686. for(laScreen* s=MAIN.Screens.pFirst;s;s=s->Item.pNext){
  687. l=TNS_MAX2(s->x,w->X); r=TNS_MIN2(s->x+s->w,w->X+w->W);
  688. u=TNS_MAX2(s->y,w->Y); b=TNS_MIN2(s->y+s->h,w->Y+w->H);
  689. int w=(r-l); if(w<0){w=0;} int h=(b-u); if(h<0){h=0;}
  690. int a=w*h; if(a>area){ maxs = s; area = a; }
  691. }
  692. return maxs;
  693. }
  694. #ifdef LA_LINUX
  695. int la_GetDPI(Window* root_win){
  696. XRRScreenResources *screen;
  697. XRROutputInfo *info;
  698. XRRCrtcInfo *crtc_info;
  699. XRRCrtcInfo *crtc;
  700. int iscres, icrtc, dpi=0;
  701. screen=XRRGetScreenResources(MAIN.dpy, root_win);
  702. for(iscres=0;iscres<screen->noutput;iscres++){
  703. info=XRRGetOutputInfo(MAIN.dpy,screen,screen->outputs[iscres]);
  704. if(!info->mm_width || !info->mm_height){ continue; }
  705. logPrint(" Xrandr reported output size: %dmm x %dmm\n",info->mm_width,info->mm_height);
  706. crtc=XRRGetCrtcInfo(MAIN.dpy,screen,info->crtc);
  707. dpi=(real)crtc->width/(real)info->mm_width*25.4;
  708. logPrint(" CRTC: %d x %d, around %ddpi\n",crtc->width,crtc->height,dpi);
  709. laScreen* s=la_EnsureScreen(info->name,info->mm_width,info->mm_height,crtc->x,crtc->y,crtc->width,crtc->height,dpi);
  710. XRRFreeCrtcInfo(crtc);
  711. //if(info->connection==RR_Connected){
  712. // for (icrtc=0;icrtc<info->ncrtc;icrtc++) {
  713. // crtc_info=XRRGetCrtcInfo(MAIN.dpy,screen,screen->crtcs[icrtc]);
  714. // printf("==> %d,%d + %dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
  715. // XRRFreeCrtcInfo(crtc_info);
  716. // }
  717. //}
  718. XRRFreeOutputInfo(info);
  719. }
  720. XRRFreeScreenResources(screen);
  721. return dpi;
  722. }
  723. #endif
  724. #ifdef _WIN32
  725. typedef struct laWin32MonitorEnumData {
  726. int id;
  727. }laWin32MonitorEnumData;
  728. static BOOL CALLBACK la_Win32MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData){
  729. laWin32MonitorEnumData* data = pData; char str[32]; sprintf(str, "Display %d", data->id); data->id++;
  730. laScreen* s = la_EnsureScreen(str, 0,0, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right-lprcMonitor->left, lprcMonitor->bottom-lprcMonitor->top, 0);
  731. return TRUE;
  732. }
  733. int la_GetDPI(HWND win){
  734. laWin32MonitorEnumData data = { 0 };
  735. EnumDisplayMonitors(0, 0, la_Win32MonitorEnum, (LPARAM)&data);
  736. return GetDpiForWindow(win);
  737. return 144;
  738. }
  739. #endif
  740. #define PROGRESSW (LA_RH*15)
  741. void laShowProgress(real p1, real p2){
  742. laSpinLock(&MAIN.OpsLock);
  743. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  744. if(!MAIN.Progress.Called){
  745. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  746. }else{
  747. laTimeRecorder tm; laRecordTime(&tm);
  748. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1){ laSpinUnlock(&MAIN.OpsLock); return; }
  749. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  750. if(!MAIN.Progress.Shown){
  751. int ww=PROGRESSW+LA_RH*2;
  752. #ifdef LA_LINUX
  753. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0);
  754. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  755. long a=LA_COLOR3_TO_HEX(bg);
  756. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  757. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  758. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  759. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  760. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  761. #endif
  762. #ifdef _WIN32
  763. int w=GetSystemMetrics(SM_CXFULLSCREEN), h=GetSystemMetrics(SM_CYFULLSCREEN);
  764. SetWindowPos(MAIN.Progress.w, MAIN.CurrentWindow->win,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2,0);
  765. ShowWindow(MAIN.Progress.w,SW_SHOW);
  766. #endif
  767. MAIN.Progress.Shown = 1;
  768. }
  769. }
  770. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  771. #ifdef LA_LINUX
  772. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  773. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  774. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  775. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  776. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  777. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  778. #endif
  779. #ifdef _WIN32
  780. InvalidateRect(MAIN.Progress.w,0,1);
  781. if(!MAIN.Progress.brush_bg){ MAIN.Progress.brush_bg=CreateSolidBrush(LA_COLOR3_TO_RGB(bg)); }
  782. if(!MAIN.Progress.brush_fg){ MAIN.Progress.brush_fg=CreateSolidBrush(LA_COLOR3_TO_RGB(fg)); }
  783. if(!MAIN.Progress.pen_fg){ MAIN.Progress.pen_fg=CreatePen(PS_SOLID, 2, LA_COLOR3_TO_RGB(fg)); }
  784. RECT rect; GetClientRect(MAIN.Progress.w, &rect);
  785. PAINTSTRUCT ps; BeginPaint(MAIN.Progress.w,&ps);
  786. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_bg);
  787. Rectangle(MAIN.Progress.hdc, 0, 0, rect.right, rect.bottom);
  788. SelectObject(MAIN.Progress.hdc, MAIN.Progress.brush_fg);
  789. Rectangle(MAIN.Progress.hdc,LA_RH*2,0,LA_RH*2+PROGRESSW*MAIN.Progress.p1,LA_RH);
  790. Rectangle(MAIN.Progress.hdc,LA_RH*2,LA_RH,LA_RH*2+PROGRESSW*MAIN.Progress.p2,LA_RH+LA_RH);
  791. SelectObject(MAIN.Progress.hdc, MAIN.Progress.pen_fg);
  792. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,0,MAIN.Progress.p1);
  793. tnsDrawLCD7_ProgressSystem(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  794. EndPaint(MAIN.Progress.w,&ps);
  795. MSG msg;
  796. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); };
  797. #endif
  798. laSpinUnlock(&MAIN.OpsLock);
  799. }
  800. void laHideProgress(){
  801. laSpinLock(&MAIN.OpsLock);
  802. if(!MAIN.Progress.Shown){
  803. MAIN.Progress.Called=0; laSpinUnlock(&MAIN.OpsLock); return;
  804. }
  805. laTimeRecorder tm; laRecordTime(&tm);
  806. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  807. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  808. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  809. #ifdef LA_LINUX
  810. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  811. #endif
  812. #ifdef _WIN32
  813. ShowWindow(MAIN.Progress.w,SW_HIDE);
  814. if(MAIN.CurrentWindow) UpdateWindow(MAIN.CurrentWindow->win);
  815. #endif
  816. laSpinUnlock(&MAIN.OpsLock);
  817. }
  818. //=======================
  819. void la_InitProgressWindow(){
  820. #ifdef LA_LINUX
  821. MAIN.Progress.w=XCreateSimpleWindow(MAIN.dpy, RootWindow(MAIN.dpy, 0), 0, 0, PROGRESSW+LA_RH*2, LA_RH*2, 0, BlackPixel(MAIN.dpy, 0), WhitePixel(MAIN.dpy, 0));
  822. if(!MAIN.Progress.w) return;
  823. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  824. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  825. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  826. if(MAIN.Progress.gc<0) return;
  827. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  828. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  829. XSync(MAIN.dpy,0);
  830. #endif
  831. #ifdef _WIN32
  832. WNDCLASSW wc;
  833. wc.hInstance = MAIN.hinstance;
  834. wc.lpfnWndProc = LA_ProgressWindowProc;
  835. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  836. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  837. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  838. wc.cbWndExtra = 0;
  839. wc.cbClsExtra = 0;
  840. wc.lpszClassName = L"_LAGUIPROGRESS";
  841. wc.lpszMenuName = NULL;
  842. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  843. if (!RegisterClassW(&wc)){ return; }
  844. MAIN.Progress.w=CreateWindowW(L"_LAGUIPROGRESS",L"Progress", WS_POPUP, 0,0,PROGRESSW+LA_RH*2,LA_RH*2,0,0,MAIN.hinstance,0);
  845. MAIN.Progress.hdc=GetDC(MAIN.Progress.w);
  846. #endif
  847. }
  848. void laSetFontFolderPath(char* absolute){
  849. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  850. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  851. }
  852. void laSetDefaultInitArguments(laInitArguments* ia){
  853. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  854. ia->UseColorManagement=0;
  855. ia->HasWorldObjects=0;
  856. ia->HasAction=0;
  857. ia->HasTextureInspector=0;
  858. ia->HasHistories=0;
  859. ia->HasTerminal=1;
  860. ia->HasAudio=0;
  861. }
  862. void laSetCompleteInitArguments(laInitArguments* ia){
  863. ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
  864. ia->UseColorManagement=1;
  865. ia->HasWorldObjects=1;
  866. ia->HasAction=1;
  867. ia->HasTextureInspector=1;
  868. ia->HasHistories=1;
  869. ia->HasTerminal=1;
  870. ia->HasAudio=1;
  871. }
  872. void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia) {
  873. MAIN.GLMajor=MAIN.GLMinor=-1;
  874. char* arg = 0;
  875. printf("Initializing LaGUI...\n",argc);
  876. for(int i=0;i<argc;i++){
  877. if(strstr(argv[i], "--gl-version=")==argv[i]){ arg=&argv[i][strlen(argv[i])-3];
  878. if(arg[0]>='2'&&arg[0]<='4'&&arg[1]=='.'&&arg[2]>='0'&&arg[2]<='9'){
  879. ia->GLMajor=arg[0]-'0'; ia->GLMinor=arg[2]-'0';
  880. printf("Set gl-version = %d.%d\n",ia->GLMajor,ia->GLMinor);
  881. }
  882. continue;
  883. }
  884. if(strSame(argv[i], "--gl-debug")){ ia->GLDebug=1; printf("Enabled OpenGL Debug.\n"); }
  885. if(strSame(argv[i], "--log")){ ia->EnableLogStdOut=1; printf("Enabled log output to stdout.\n"); }
  886. }
  887. }
  888. int laGetReadyWith(laInitArguments* ia){
  889. #ifdef LA_LINUX
  890. //signal(SIGSEGV,la_HandlerSIGSEGV);
  891. #endif
  892. laSpinInit(&MAIN.MemLock);
  893. laSpinInit(&MAIN.OpsLock);
  894. memcpy(&MAIN.InitArgs,ia,sizeof(laInitArguments));
  895. if(MAIN.InitArgs.GLMajor>4||MAIN.InitArgs.GLMajor<1){ MAIN.InitArgs.GLMajor=3; }
  896. if(MAIN.InitArgs.GLMinor<1){ MAIN.InitArgs.GLMinor=3; }
  897. if(MAIN.InitArgs.GLESMajor>3||MAIN.InitArgs.GLESMajor<2){ MAIN.InitArgs.GLESMajor=3; }
  898. if(MAIN.InitArgs.GLESMinor<0){ MAIN.InitArgs.GLESMinor=0; }
  899. if(MAIN.BufferSamples==1){ MAIN.BufferSamples=0; }
  900. tnsInit();
  901. #ifdef LA_LINUX
  902. SYSWINDOW root, win;
  903. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  904. XSetWindowAttributes swa={0};
  905. XWindowAttributes wa={0};
  906. XEvent xev;
  907. logPrintNew("Initializing LaGUI...\n");
  908. setlocale(LC_CTYPE, "zh_CN.utf8");
  909. XSetErrorHandler(la_XErrorHandler);
  910. int i;
  911. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  912. printf("\n\tcannot connect to x server\n\n");
  913. exit(0);
  914. }
  915. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  916. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  917. MAIN.GLESMajor=MAIN.InitArgs.GLESMajor; MAIN.GLESMinor=MAIN.InitArgs.GLESMinor;
  918. #ifdef LA_USE_GLES
  919. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLESMajor,MAIN.GLESMinor);
  920. #else
  921. logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
  922. #endif
  923. #ifdef LA_USE_GLES
  924. MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
  925. if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
  926. EGLint egl_major, egl_minor;
  927. if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
  928. printf("Error: eglInitialize() failed\n"); return -1;
  929. }
  930. int scrnum;
  931. XSetWindowAttributes attr;
  932. XVisualInfo *visInfo, visTemplate;
  933. int num_visuals;
  934. EGLContext ctx;
  935. EGLint num_configs;
  936. EGLint vid;
  937. static const EGLint attribs[] = {
  938. EGL_RED_SIZE, 8,
  939. EGL_GREEN_SIZE, 8,
  940. EGL_BLUE_SIZE, 8,
  941. EGL_DEPTH_SIZE, 1,
  942. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  943. EGL_NONE
  944. };
  945. if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
  946. printf("Error: couldn't get an EGL visual config\n"); exit(1);
  947. }
  948. if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
  949. printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
  950. }
  951. visTemplate.visualid = vid;
  952. visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
  953. if (!visInfo) {
  954. printf("Error: couldn't get X visual\n"); exit(1);
  955. }
  956. MAIN.xvi=visInfo;
  957. root = DefaultRootWindow(MAIN.dpy);
  958. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  959. printf("\n\tcannot create colormap\n\n"); exit(1);
  960. }
  961. eglBindAPI(EGL_OPENGL_ES_API);
  962. EGLint ctx_attribs[] = {
  963. EGL_CONTEXT_CLIENT_VERSION, MAIN.GLESMajor,
  964. EGL_CONTEXT_MINOR_VERSION, MAIN.GLESMinor,
  965. EGL_NONE
  966. };
  967. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
  968. if (!MAIN.glc) {
  969. printf("Error: eglCreateContext failed\n"); exit(1);
  970. }
  971. eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
  972. #else
  973. int visual_attribs[] = {
  974. GLX_X_RENDERABLE , True,
  975. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  976. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  977. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  978. GLX_RED_SIZE , 8,
  979. GLX_GREEN_SIZE , 8,
  980. GLX_BLUE_SIZE , 8,
  981. GLX_ALPHA_SIZE , 8,
  982. GLX_DEPTH_SIZE , 24,
  983. //GLX_STENCIL_SIZE , 8,
  984. GLX_DOUBLEBUFFER , True,
  985. GLX_SAMPLE_BUFFERS , MAIN.BufferSamples?1:0,
  986. GLX_SAMPLES , MAIN.BufferSamples?MAIN.BufferSamples:0,
  987. None
  988. };
  989. int fbcount = -1;
  990. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  991. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  992. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  993. MAIN.BestFBC = fbconfig[0];
  994. int sample_buf,samples;
  995. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  996. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  997. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  998. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  999. free(fbconfig);
  1000. root = DefaultRootWindow(MAIN.dpy);
  1001. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  1002. printf("\n\tcannot create colormap\n\n"); exit(0);
  1003. }
  1004. swa.colormap = MAIN.cmap;
  1005. root = DefaultRootWindow(MAIN.dpy);
  1006. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
  1007. MAIN.win=win;
  1008. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
  1009. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  1010. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  1011. printf("\n\tcannot create gl context\n\n"); exit(0);
  1012. }
  1013. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  1014. tnsContextMakeCurrent(MAIN.glc,win,0);
  1015. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1016. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  1017. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  1018. int err=0;
  1019. if((err=glewInit())!=GLEW_OK){
  1020. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  1021. };
  1022. #endif /* gles or glx */
  1023. glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
  1024. la_SetCurrentGLContextDebug();
  1025. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  1026. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  1027. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  1028. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  1029. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  1030. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  1031. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  1032. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  1033. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  1034. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  1035. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  1036. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1037. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  1038. #endif //linux
  1039. #ifdef _WIN32
  1040. logPrintNew("Initializing LaGUI...\n");
  1041. SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
  1042. setlocale(LC_ALL, "zh_CN.utf8");
  1043. MAIN.hinstance = GetModuleHandle(NULL);
  1044. HINSTANCE* hInst = &MAIN.hinstance;
  1045. WNDCLASSEXW wt;
  1046. wt.cbSize = sizeof(WNDCLASSEXW);
  1047. wt.cbClsExtra = 0;
  1048. wt.cbWndExtra = 0;
  1049. wt.hbrBackground = 0;
  1050. wt.hCursor = LoadCursor(0, IDC_ARROW);
  1051. wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
  1052. wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
  1053. wt.hInstance = *hInst;
  1054. wt.lpfnWndProc = LA_WindowProc;
  1055. wt.lpszClassName = LA_GUI_WNDCLASS_NAME;
  1056. wt.lpszMenuName = 0;
  1057. wt.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  1058. if (!RegisterClassExW(&wt)) return 0;
  1059. MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
  1060. logPrint("Chosen OpenGL version %d.%d\n", MAIN.GLMajor, MAIN.GLMinor);
  1061. SetProcessDPIAware();
  1062. GLenum err;
  1063. PIXELFORMATDESCRIPTOR pfd;
  1064. HINSTANCE* hinst = &MAIN.hinstance;
  1065. HWND hwnd = CreateWindowExW(WS_EX_ACCEPTFILES, LA_GUI_WNDCLASS_NAME,
  1066. "Temp Window For Accessing GLEW!",
  1067. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 100, 100,
  1068. 0, 0, *hinst, 0);
  1069. HDC hdc = GetDC(hwnd);
  1070. HGLRC hglrc = 0;
  1071. SetPixelFormat(hdc, 1, &cpfd);
  1072. hglrc = wglCreateContext(hdc);
  1073. tnsContextMakeCurrent(hglrc, hdc,0);
  1074. //MAIN.hdc = hdc;
  1075. // MAIN.tWND = hwnd;
  1076. MAIN.glc = hglrc;
  1077. int major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  1078. logPrint(" OpenGL Version: %d.%d\n", major, minor);
  1079. logPrint(" OpenGL Renderer: %s\n", glGetString(GL_RENDERER));
  1080. if (err = glewInit()) {
  1081. printf("Init Glew Failed\n");
  1082. printf("glewGetErrorString: %s\n", glewGetErrorString(err));
  1083. return 0;
  1084. }
  1085. logPrint("Trying to load WinTab for stylus input...\n"); int WtAvailable=1;
  1086. if (!LoadWintab()){ logPrint("WinTab not available.\n"); WtAvailable=0; }
  1087. elif (!gpWTInfoA(0, 0, NULL)){ logPrint("WinTab service is not available. (gpWTInfoA() returns 0).\n"); WtAvailable=0; }
  1088. if (WtAvailable){ MAIN.WinTabAvailable=1; logPrint("WinTab service is available.\n"); }
  1089. #endif
  1090. la_GetWorkingDirectoryInternal();
  1091. MAIN.SavePreferenceOnExit=1;
  1092. MAIN.FontSize = 0.6;
  1093. int dpi=64;
  1094. #ifdef _WIN32
  1095. dpi=la_GetDPI(hwnd);
  1096. #endif
  1097. #ifdef LA_LINUX
  1098. dpi = la_GetDPI(DefaultRootWindow(MAIN.dpy));
  1099. #endif
  1100. if((!dpi) || dpi<144){ dpi=144; } if(dpi>300){ dpi=300; }
  1101. int UiSize=(int)(tnsLinearItp(16.0f,24.0f,tnsGetRatiod(96,144,dpi))+0.5);
  1102. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =UiSize;
  1103. MAIN.UiScale=1;
  1104. MAIN.MarginSize = 1;
  1105. MAIN.ColorPickerGamma=1.5;
  1106. MAIN.EnableColorManagement=MAIN.InitArgs.UseColorManagement;
  1107. MAIN.ViewportHalftoneFactor=0.5;
  1108. MAIN.ViewportHalftoneSize=3.7;
  1109. tnsInitRenderKernel(64);
  1110. tnsInitBuiltinShaders();
  1111. tnsSetuptnsFontManager();
  1112. #define LOAD_FONT(font) \
  1113. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  1114. LOAD_FONT("NotoSansCJK-Regular.ttc");
  1115. LOAD_FONT("NotoEmoji-Regular.ttf");
  1116. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  1117. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  1118. //LOAD_FONT("NotoMusic-Regular.ttf");
  1119. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  1120. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) logPrintNew("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  1121. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  1122. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  1123. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  1124. MAIN.InputMapping=memAcquire(sizeof(laInputMappingBundle));
  1125. MAIN.Animation=memAcquire(sizeof(laAnimation));
  1126. MAIN.Audio=memAcquire(sizeof(laAudio));
  1127. #ifdef LA_WITH_LUAJIT
  1128. // starting lua
  1129. logPrint("Starting luajit...\n");
  1130. MAIN.L = lua_open();
  1131. la_luaLoadLibs(MAIN.L);
  1132. la_luaPrintStatus(MAIN.L);
  1133. tnsLuaInit(MAIN.L);
  1134. #endif
  1135. //interactions:
  1136. MAIN.TopFramerate = 60;
  1137. MAIN.ValuatorThreshold = 8;
  1138. MAIN.ScrollingSpeed = 3;
  1139. MAIN.AnimationSpeed = 0.4;
  1140. MAIN.PanelAnimationSpeed = 0.4;
  1141. MAIN.ZoomSpeed2D = 0.01;
  1142. MAIN.IdleTime = 0.75;
  1143. MAIN.TooltipCloseDistance = 30;
  1144. MAIN.InkOrWinTab = 1; /* Default use wacom wintab input. */
  1145. //display:
  1146. MAIN.FloatingAlpha = 0.35;
  1147. MAIN.SolidShadowLength = 20;
  1148. MAIN.WireColorSlices = 16;
  1149. MAIN.WireThickness = 5;
  1150. MAIN.WireSaggyness = 0.5;
  1151. #ifdef LAGUI_ANDROID
  1152. laAddResourceFolder("");
  1153. #else
  1154. laAddResourceFolder(".");
  1155. #endif
  1156. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  1157. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0ll);
  1158. la_InitProgressWindow();
  1159. la_MakeTranslations_es_ES();
  1160. la_MakeTranslations_zh_hans();
  1161. //tns_RegisterResourcesForSoftwareRender();
  1162. la_RegisterDefaultSignals();
  1163. la_RegisterGeneralProps();
  1164. la_RegisterBuiltinTemplates();
  1165. la_RegisterMainThemes();
  1166. la_RegisterMainOperators();
  1167. la_RegisterMainUiTypes();
  1168. la_RegisterModellingOperators();
  1169. la_RegisterShapeOperators();
  1170. la_RegisterInternalProps();
  1171. la_RegisterAnimationResources();
  1172. la_RegisterWindowKeys();
  1173. if(MAIN.InitArgs.HasAudio) laInitAudio();
  1174. laFinalizeUiTemplates();
  1175. laFinalizeOperators();
  1176. la_RegisterControllerProps();
  1177. la_RefreshControllers();
  1178. la_RegisterBasicNodes();
  1179. tns_RegisterNodes();
  1180. la_InitThreadEnviornment();
  1181. laSetRootInstance(&MAIN);
  1182. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  1183. laPushDifferences(0, 0);
  1184. la_MakeDummyManagedUDF();
  1185. la_RegenerateWireColors();
  1186. laAnimationRegisterHolderPath("tns.world.root_objects_as_root");
  1187. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1188. logPrintNew("Initialization Completed\n");
  1189. MAIN.InitDone=1;
  1190. return 1;
  1191. }
  1192. int laGetReady(){
  1193. laInitArguments ia={0}; laSetDefaultInitArguments(&ia);
  1194. return laGetReadyWith(&ia);
  1195. }
  1196. void la_DestroyUiType(laUiType* uit);
  1197. void la_FreeKeyMapItem(laKeyMapItem* kmi);
  1198. void laShutoff(int SavePrefereces){
  1199. if(MAIN.SavePreferenceOnExit && SavePrefereces){ laSaveUserPreferences(); }
  1200. //for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  1201. // transLate(pc->Description);
  1202. // for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  1203. // transLate(p->Description);
  1204. // }
  1205. //}
  1206. transDumpMissMatchRecord("TranslationDump.txt");
  1207. if(MAIN.Cleanup) MAIN.Cleanup();
  1208. if(MAIN.InitArgs.HasAudio) laDeinitAudio();
  1209. strSafeDestroy(&MAIN.WorkingDirectory);
  1210. strSafeDestroy(&MAIN.example_string);
  1211. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  1212. // (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. )
  1213. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  1214. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  1215. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  1216. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  1217. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  1218. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  1219. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  1220. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  1221. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  1222. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  1223. strSafeDestroy(&MAIN.CopyPending);
  1224. la_ClearUDFRegistryAndFolders();
  1225. laClearManagedUDF();
  1226. laClearSaveProp();
  1227. logClear();
  1228. tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
  1229. #ifdef LA_LINUX
  1230. tnsContextMakeCurrent(0,0,0);
  1231. tnsDeleteContext(MAIN.glc);
  1232. #ifdef LA_USE_GLES
  1233. eglTerminate(MAIN.egl_dpy);
  1234. #endif
  1235. #endif
  1236. #ifdef _WIN32
  1237. tnsContextMakeCurrent(0,0,0);
  1238. tnsDeleteContext(MAIN.glc);
  1239. UnloadWintab();
  1240. #endif
  1241. tnsQuit();
  1242. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  1243. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  1244. strSafeDump();
  1245. hshFree(&MAIN.DBInstMemLeft);
  1246. memNoLonger();
  1247. laSpinDestroy(&MAIN.MemLock);
  1248. laSpinDestroy(&MAIN.OpsLock);
  1249. #ifdef LA_WITH_LUAJIT
  1250. lua_close(MAIN.L);
  1251. #endif
  1252. printf("LaGUI has cleaned up.\n");
  1253. }
  1254. int laRestoreFactorySettings(){
  1255. char path[1024];
  1256. #ifdef LAGUI_ANDROID
  1257. sprintf(path,"%s","preferences.udf");
  1258. #else
  1259. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1260. #endif
  1261. if(remove(path)){ return 0; }
  1262. return 1;
  1263. }
  1264. void laSaveUserPreferences(){
  1265. char path[1024];
  1266. #ifdef LAGUI_ANDROID
  1267. sprintf(path,"%s","preferences.udf");
  1268. #else
  1269. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1270. #endif
  1271. laUDF* udf=laPrepareUDF(path);
  1272. laWriteProp(udf,"la.windows");
  1273. laWriteProp(udf,"la.user_preferences");
  1274. laWriteProp(udf,"la.input_mapping");
  1275. laWriteProp(udf,"la.controllers");
  1276. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  1277. laWriteProp(udf,lip->p);
  1278. }
  1279. laPackUDF(udf,0,0);
  1280. }
  1281. void laEnsureUserPreferences(){
  1282. char path[1024];
  1283. #ifdef LAGUI_ANDROID
  1284. sprintf(path,"%s/%s",MAIN.InternalDataPath,"preferences.udf");
  1285. #else
  1286. sprintf(path,"%s%s",SSTR(MAIN.WorkingDirectory),"preferences.udf");
  1287. #endif
  1288. laUDFRegistry* r=laFindUDFRegistry(path);
  1289. if(!r){ laSaveUserPreferences(); return; }
  1290. 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; }
  1291. laClearUDFRegistries();
  1292. while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  1293. while(MAIN.InputMapping->InputMappings.pFirst){ laRemoveInputMapping(MAIN.InputMapping->InputMappings.pFirst); }
  1294. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE);
  1295. laCloseUDF(udf);
  1296. la_RemoveDuplicatedScreenConf();
  1297. la_RemoveDuplicatedControllers();
  1298. laRefreshUDFRegistries();
  1299. //restore forced settings
  1300. if(MAIN.InitArgs.EnableLogStdOut){ MAIN.EnableLogStdOut=1; }
  1301. }
  1302. void laAddExtraExtension(int FileType, ...){
  1303. va_list list; va_start(list,FileType);
  1304. char* ext;
  1305. while(ext=va_arg(list,char*)){ if(!ext) break;
  1306. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  1307. et->FileType=FileType; et->Extension=ext;
  1308. lstAppendItem(&MAIN.ExtraExtensions, et);
  1309. logPrintNew("add ext %s",ext);
  1310. }
  1311. va_end(list);
  1312. }
  1313. void laAddExtraPreferencePath(const char* path){
  1314. if(!path) return;
  1315. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  1316. }
  1317. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  1318. if(!name || !Func) return;
  1319. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  1320. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  1321. }
  1322. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  1323. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  1324. }
  1325. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  1326. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  1327. }
  1328. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  1329. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  1330. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  1331. }
  1332. void la_InputMappingGetKeyName(int key, int special, char* name){
  1333. char *_next=name; name[0]=0;
  1334. if(special&LA_KEY_CTRL){ strcat(name,"Ctrl+"); }
  1335. if(special&LA_KEY_SHIFT){ strcat(name,"Shift+"); }
  1336. if(special&LA_KEY_ALT){ strcat(name,"Shift+"); }
  1337. switch(key){
  1338. case ' ': strcat(name,"Space"); break;
  1339. case LA_KEY_BACKSPACE: strcat(name,"Backspace"); break;
  1340. case LA_KEY_ESCAPE: strcat(name,"Escape"); break;
  1341. case LA_KEY_ENTER: strcat(name,"Enter"); break;
  1342. case LA_KEY_ARRLEFT: strcat(name,"Left"); break;
  1343. case LA_KEY_ARRRIGHT: strcat(name,"Right"); break;
  1344. case LA_KEY_ARRUP: strcat(name,"Up"); break;
  1345. case LA_KEY_ARRDOWN: strcat(name,"Down"); break;
  1346. case LA_KEY_SHIFT: case LA_KEY_CTRL: case LA_KEY_ALT: break;
  1347. case LA_KEY_DELETE: strcat(name,"Delete"); break;
  1348. case LA_KEY_TAB: strcat(name,"Tab"); break;
  1349. case LA_KEY_NUM1: strcat(name,"Num1"); break;
  1350. case LA_KEY_NUM2: strcat(name,"Num2"); break;
  1351. case LA_KEY_NUM3: strcat(name,"Num3"); break;
  1352. case LA_KEY_NUM4: strcat(name,"Num4"); break;
  1353. case LA_KEY_NUM5: strcat(name,"Num5"); break;
  1354. case LA_KEY_NUM6: strcat(name,"Num6"); break;
  1355. case LA_KEY_NUM7: strcat(name,"Num7"); break;
  1356. case LA_KEY_NUM8: strcat(name,"Num8"); break;
  1357. case LA_KEY_NUM9: strcat(name,"Num9"); break;
  1358. case LA_KEY_NUM0: strcat(name,"Num0"); break;
  1359. case LA_KEY_NUMPLUS: strcat(name,"NumPlus"); break;
  1360. case LA_KEY_NUMMINUS: strcat(name,"NumMinus"); break;
  1361. case LA_KEY_NUMMULT: strcat(name,"NumMult"); break;
  1362. case LA_KEY_NUMDIVIDE: strcat(name,"NumDivide"); break;
  1363. case LA_KEY_NUMDOT: strcat(name,"NumDot"); break;
  1364. case LA_KEY_NUMENTER: strcat(name,"NumEnter"); break;
  1365. case LA_KEY_F1: strcat(name,"F1"); break;
  1366. case LA_KEY_F2: strcat(name,"F2"); break;
  1367. case LA_KEY_F3: strcat(name,"F3"); break;
  1368. case LA_KEY_F4: strcat(name,"F4"); break;
  1369. case LA_KEY_F5: strcat(name,"F5"); break;
  1370. case LA_KEY_F6: strcat(name,"F6"); break;
  1371. case LA_KEY_F7: strcat(name,"F7"); break;
  1372. case LA_KEY_F8: strcat(name,"F8"); break;
  1373. case LA_KEY_F9: strcat(name,"F9"); break;
  1374. case LA_KEY_F10: strcat(name,"F10"); break;
  1375. case LA_KEY_F11: strcat(name,"F11"); break;
  1376. case LA_KEY_F12: strcat(name,"F12"); break;
  1377. default:
  1378. name = name+strlen(name); _next=name;
  1379. laToUTF8(key,name,&_next); *_next=0; break;
  1380. }
  1381. }
  1382. int la_InputMappingGetKeyFromName(char* name, int* special){
  1383. if(!name ||name[0]==0){ *special=0; return 0; }
  1384. *special=0;
  1385. if(strstr(name,"Ctrl")) *special|=LA_KEY_CTRL;
  1386. if(strstr(name,"Shift")) *special|=LA_KEY_SHIFT;
  1387. if(strstr(name,"Alt")) *special|=LA_KEY_ALT;
  1388. char* p=name+strlen(name)-1;
  1389. while(*p!='+'){ p--; if(p<=name){p=name; break;} }
  1390. while(*p=='+' || *p==' '){ p++; }
  1391. if(strSame(p,"Space")) return ' ';
  1392. if(strSame(p,"Backspace")) return LA_KEY_BACKSPACE;
  1393. if(strSame(p,"Escape")) return LA_KEY_ESCAPE;
  1394. if(strSame(p,"Enter")) return LA_KEY_ENTER;
  1395. if(strSame(p,"Left")) return LA_KEY_ARRLEFT;
  1396. if(strSame(p,"Right")) return LA_KEY_ARRRIGHT;
  1397. if(strSame(p,"Up")) return LA_KEY_ARRUP;
  1398. if(strSame(p,"Down")) return LA_KEY_ARRDOWN;
  1399. if(strSame(p,"Delete")) return LA_KEY_DELETE;
  1400. if(strSame(p,"Tab")) return LA_KEY_TAB;
  1401. if(strSame(p,"Num1")) return LA_KEY_NUM1;
  1402. if(strSame(p,"Num2")) return LA_KEY_NUM2;
  1403. if(strSame(p,"Num3")) return LA_KEY_NUM3;
  1404. if(strSame(p,"Num4")) return LA_KEY_NUM4;
  1405. if(strSame(p,"Num5")) return LA_KEY_NUM5;
  1406. if(strSame(p,"Num6")) return LA_KEY_NUM6;
  1407. if(strSame(p,"Num7")) return LA_KEY_NUM7;
  1408. if(strSame(p,"Num8")) return LA_KEY_NUM8;
  1409. if(strSame(p,"Num9")) return LA_KEY_NUM9;
  1410. if(strSame(p,"Num0")) return LA_KEY_NUM0;
  1411. if(strSame(p,"NumPlus")) return LA_KEY_NUMPLUS;
  1412. if(strSame(p,"NumMinus")) return LA_KEY_NUMMINUS;
  1413. if(strSame(p,"NumMult")) return LA_KEY_NUMMULT;
  1414. if(strSame(p,"NumDivide")) return LA_KEY_NUMDIVIDE;
  1415. if(strSame(p,"NumDot")) return LA_KEY_NUMDOT;
  1416. if(strSame(p,"NumEnter")) return LA_KEY_NUMENTER;
  1417. if(strSame(p,"F1")) return LA_KEY_F1;
  1418. if(strSame(p,"F2")) return LA_KEY_F2;
  1419. if(strSame(p,"F3")) return LA_KEY_F3;
  1420. if(strSame(p,"F4")) return LA_KEY_F4;
  1421. if(strSame(p,"F5")) return LA_KEY_F5;
  1422. if(strSame(p,"F6")) return LA_KEY_F6;
  1423. if(strSame(p,"F7")) return LA_KEY_F7;
  1424. if(strSame(p,"F8")) return LA_KEY_F8;
  1425. if(strSame(p,"F9")) return LA_KEY_F9;
  1426. if(strSame(p,"F10")) return LA_KEY_F10;
  1427. if(strSame(p,"F11")) return LA_KEY_F11;
  1428. if(strSame(p,"F12")) return LA_KEY_F12;
  1429. int adv;
  1430. return laToUnicode(p,&adv);
  1431. }
  1432. laCustomSignal* laFindSignal(char* Name){
  1433. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(strSame(SSTR(cs->Name),Name)) return cs; }
  1434. return 0;
  1435. }
  1436. laCustomSignal* laFindSignalByID(int ID){
  1437. for(laCustomSignal* cs=MAIN.CustomSignals.pFirst;cs;cs=cs->Item.pNext){ if(ID==cs->Signal) return cs; }
  1438. return 0;
  1439. }
  1440. void laInputMappingUpdateSignal(laInputMappingEntry* ime){
  1441. if(ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){ char* str=SSTR(ime->Key);
  1442. if(str&&str[0]){ int adv; ime->KeyValue=la_InputMappingGetKeyFromName(str,&ime->SpecialKeyBits); }else{ ime->KeyValue=0; }
  1443. }elif(ime->DeviceType == LA_INPUT_DEVICE_JOYSTICK){ int key=0; sscanf(SSTR(ime->Key),"%d",&key); ime->KeyValue=key; }
  1444. char* signal = SSTR(ime->Signal);
  1445. laCustomSignal *cs=laFindSignal(signal); if(cs){ ime->SignalValue=cs->Signal; }else{ ime->SignalValue=0;}
  1446. }
  1447. laInputMapping* laNewInputMapping(char* Name){
  1448. laInputMapping* im=memAcquireHyper(sizeof(laInputMapping)); lstAppendItem(&MAIN.InputMapping->InputMappings,im);
  1449. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,im);
  1450. strSafeSet(&im->Name,Name);
  1451. return im;
  1452. }
  1453. laInputMappingEntry* laNewInputMappingEntry(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, char* Signal){
  1454. laInputMappingEntry* e=memAcquire(sizeof(laInputMappingEntry)); lstAppendItem(&im->Entries,e);
  1455. e->DeviceType = DeviceType; e->JoystickDevice=JoystickDevice; e->SpecialKeyBits=SpecialKeyBit;
  1456. memAssignRef(e,&e->Parent,im);
  1457. if(Signal){ strSafeSet(&e->Signal,Signal); } if(Key){ strSafeSet(&e->Key,Key); }
  1458. laInputMappingUpdateSignal(e);
  1459. e->SpecialKeyBits=SpecialKeyBit;
  1460. char buf[64],*_next=buf;
  1461. la_InputMappingGetKeyName(e->KeyValue,e->SpecialKeyBits,buf); strSafeSet(&e->Key,buf);
  1462. }
  1463. laInputMappingEntry* laNewInputMappingEntryP(laInputMapping* im, int DeviceType, int JoystickDevice, char* Key, int SpecialKeyBit, int Signal){
  1464. laCustomSignal* cs; if(!(cs=laFindSignalByID(Signal))) return 0;
  1465. laNewInputMappingEntry(im,DeviceType,JoystickDevice,Key,SpecialKeyBit,SSTR(cs->Name));
  1466. }
  1467. void laRemoveInputMappingEntry(laInputMapping* im, laInputMappingEntry* e){
  1468. memAssignRef(e,&e->Parent,0); lstRemoveItem(&im->Entries,e); strSafeDestroy(&e->Signal); strSafeDestroy(&e->Key); memFree(e);
  1469. }
  1470. void laRemoveInputMapping(laInputMapping* im){
  1471. laInputMappingEntry* e; while(e=im->Entries.pFirst){ laRemoveInputMappingEntry(im,e); }
  1472. laInputMapping* use=im->Item.pNext?im->Item.pNext:im->Item.pPrev;
  1473. memAssignRef(MAIN.InputMapping,&MAIN.InputMapping->CurrentInputMapping,use);
  1474. lstRemoveItem(&MAIN.InputMapping->InputMappings,im); strSafeDestroy(&im->Name); memFree(im);
  1475. }
  1476. laCustomSignal* laNewCustomSignal(char* Name, int Signal){
  1477. laCustomSignal* cs=memAcquire(sizeof(laCustomSignal)); lstAppendItem(&MAIN.CustomSignals,cs);
  1478. strSafeSet(&cs->Name,Name); cs->Signal = Signal;
  1479. return cs;
  1480. }
  1481. void laRemoveCustomSignal(laCustomSignal* cs){
  1482. strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
  1483. }
  1484. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
  1485. void la_SendSignalsFromEvent(laEvent* e){
  1486. laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
  1487. if(!im){return;}
  1488. for(laInputMappingEntry* ime = im->Entries.pFirst;ime;ime=ime->Item.pNext){
  1489. if(e->type==LA_KEY_DOWN && ime->DeviceType == LA_INPUT_DEVICE_KEYBOARD){
  1490. if(e->key == ime->KeyValue && e->SpecialKeyBit == ime->SpecialKeyBits){
  1491. la_SendSignalEvent(e->window->win,ime->SignalValue);
  1492. }
  1493. }
  1494. }
  1495. }
  1496. //MSG====================================================
  1497. int la_IsThisSysWindow(laWindow *wnd, SYSWINDOW hwnd){
  1498. if (wnd->win == hwnd) return 1;
  1499. else return 0;
  1500. };
  1501. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  1502. if (p->SL){ int s=p->SL<0?0:p->SL;
  1503. if (p->TX != s) laRecalcPanel(p);
  1504. p->TX = s;
  1505. }
  1506. if (p->SR){ int s=p->SR<0?0:p->SR;
  1507. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  1508. p->TW = CW - p->TX - s;
  1509. }
  1510. if (p->ST){ int s=p->ST<0?0:p->ST;
  1511. if (p->TY != s) laRecalcPanel(p);
  1512. p->TY = s;
  1513. }
  1514. if (p->SB){ int s=p->SB<0?0:p->SB;
  1515. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  1516. p->TH = CH - p->TY - s;
  1517. }
  1518. }
  1519. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  1520. laPanel *p = 0;
  1521. b->X = X;
  1522. b->Y = Y;
  1523. b->W = W;
  1524. b->H = H;
  1525. if (b->B1){
  1526. int SplitWidth;
  1527. if (b->Vertical){
  1528. SplitWidth = H * b->SplitRatio;
  1529. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  1530. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  1531. }else{
  1532. SplitWidth = W * b->SplitRatio;
  1533. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  1534. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  1535. }
  1536. }
  1537. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  1538. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  1539. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1540. }
  1541. if (p = b->CurrentPanel){
  1542. int TitleGap=b->Folded?0:LA_RH;
  1543. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  1544. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  1545. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  1546. laRecalcPanel(p);
  1547. }
  1548. }
  1549. void la_UpdateUiPlacement(laWindow *w){
  1550. laLayout *l;
  1551. laPanel *p;
  1552. int CW = w->CW;
  1553. int CH = w->CH;
  1554. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  1555. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  1556. if(w->MaximizedUi && w->MaximizedUiPanel){
  1557. laRecalcPanel(w->MaximizedUiPanel);
  1558. }elif(w->MaximizedBlock){
  1559. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1560. }else{
  1561. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  1562. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  1563. }
  1564. }
  1565. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  1566. if(p->IsMenuPanel){
  1567. p->TH=p->H=MenuHeight;
  1568. }
  1569. la_EnsurePanelSnapping(p, CW, CH);
  1570. laRecalcPanel(p);
  1571. }
  1572. }
  1573. void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
  1574. laWindow *window;
  1575. #ifdef LAGUI_ANDROID
  1576. window = MAIN.Windows.pFirst; if (!window) return;
  1577. window->X=x;window->Y=y;window->W=w;window->H=h;
  1578. window->CW=w;window->CH=h;
  1579. la_UpdateUiPlacement(window); return;
  1580. #endif
  1581. window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  1582. if (!window) return;
  1583. #ifdef _WIN32
  1584. RECT rcc; GetClientRect(window->win, &rcc);
  1585. RECT rcw; GetWindowRect(window->win, &rcw);
  1586. window->CW = rcc.right - rcc.left;
  1587. window->CH = rcc.bottom - rcc.top;
  1588. window->W = rcw.right - rcw.left;
  1589. window->H = rcw.bottom - rcw.top;
  1590. window->X = rcw.left; window->Y = rcw.top;
  1591. if (MAIN.AutoSwitchColorSpace) {
  1592. laScreen* s = laGetWindowScreen(window);
  1593. if (s) { window->OutputColorSpace = s->ColorSpace; }
  1594. }
  1595. #endif
  1596. #ifdef LA_LINUX
  1597. XWindowAttributes attr;
  1598. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  1599. window->CW = w; window->CH = h;
  1600. window->W = w; window->H = h;
  1601. window->X = x; window->Y = y;
  1602. if(MAIN.AutoSwitchColorSpace){
  1603. laScreen* s = laGetWindowScreen(window);
  1604. if(s){ window->OutputColorSpace = s->ColorSpace; }
  1605. }
  1606. #endif
  1607. la_UpdateUiPlacement(window);
  1608. }
  1609. int la_OnWindowDestroy(SYSWINDOW wnd){
  1610. laListHandle *hlst = &MAIN.Windows;
  1611. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  1612. if (!w) return 0;
  1613. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  1614. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  1615. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  1616. laShutoff(1);
  1617. return 1;
  1618. }
  1619. laListHandle h={0};laLayout*l=0;
  1620. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  1621. la_DestroyWindow(w);
  1622. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  1623. #ifdef LA_LINUX
  1624. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  1625. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
  1626. #endif
  1627. while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
  1628. }
  1629. return 0;
  1630. }
  1631. void la_MakeSpecialKeyBit(SYSWINDOW hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  1632. laListHandle *el = &wnd->EventList;
  1633. laEvent* last_e=el->pLast;
  1634. SYSWINDOW root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  1635. #ifdef LA_LINUX
  1636. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  1637. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  1638. #endif
  1639. #ifdef _WIN32
  1640. 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);
  1641. #endif
  1642. }
  1643. void laMappingRequestEval();
  1644. void la_SaveEvent(SYSWINDOW hwnd, laEvent *e, int use_last_pos){
  1645. laListHandle *wl = &MAIN.Windows;
  1646. laWindow* wnd;
  1647. #ifdef LAGUI_ANDROID
  1648. wnd = MAIN.Windows.pFirst;
  1649. #else
  1650. wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  1651. #endif
  1652. if (!wnd){ memFree(e); return; }
  1653. laListHandle *el = &wnd->EventList;
  1654. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  1655. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  1656. e->window = wnd;
  1657. e->Twist=MAIN.StylusTwist; e->HasTwist = MAIN.StylusHasTwist;
  1658. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  1659. e->Orientation=MAIN.PointerIsEraser?MAIN.EraserOrientation:MAIN.StylusOrientation;
  1660. e->Deviation=MAIN.PointerIsEraser?MAIN.EraserDeviation:MAIN.StylusDeviation;
  1661. e->IsEraser=MAIN.PointerIsEraser; e->Hover=MAIN.StylusHover;
  1662. e->GoodPressure=MAIN.IsPen;
  1663. lstAppendItem(el, (laListItem *)e);
  1664. laMappingRequestEval();
  1665. };
  1666. void la_SendKeyboardEvent(SYSWINDOW hwnd, int type, int key){
  1667. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->type = type; e->key = tolowerGuarded(key);
  1668. la_SaveEvent(hwnd, e, 1);
  1669. };
  1670. void la_SendInputEvent(SYSWINDOW hwnd, uint32_t Input){
  1671. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1672. e->type = LA_INPUT; e->Input=Input;
  1673. la_SaveEvent(hwnd, e, 1);
  1674. }
  1675. void la_SendEmptyEvent(SYSWINDOW hwnd){
  1676. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1677. e->type = LA_EMPTY;
  1678. la_SaveEvent(hwnd, e, 1);
  1679. }
  1680. void laSendOperatorTriggerEvent(){
  1681. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  1682. MAIN.ReTriggerOperators = 0;
  1683. }
  1684. int la_TranslateSpecialKey(int keysym){
  1685. #ifdef LA_LINUX
  1686. switch(keysym){
  1687. case XK_Return: return LA_KEY_ENTER;
  1688. case XK_BackSpace: return LA_KEY_BACKSPACE;
  1689. case XK_Delete: return LA_KEY_DELETE;
  1690. case XK_Escape: return LA_KEY_ESCAPE;
  1691. case XK_Tab: return LA_KEY_TAB;
  1692. case XK_Left: return LA_KEY_ARRLEFT;
  1693. case XK_Right: return LA_KEY_ARRRIGHT;
  1694. case XK_Up: return LA_KEY_ARRUP;
  1695. case XK_Down: return LA_KEY_ARRDOWN;
  1696. case XK_Control_L: return LA_KEY_CTRL;
  1697. case XK_Control_R: return LA_KEY_CTRL;
  1698. case XK_Shift_L: return LA_KEY_SHIFT;
  1699. case XK_Shift_R: return LA_KEY_SHIFT;
  1700. case XK_Alt_L: return LA_KEY_ALT;
  1701. case XK_Alt_R: return LA_KEY_ALT;
  1702. case XK_KP_1: return LA_KEY_NUM1;
  1703. case XK_KP_2: return LA_KEY_NUM2;
  1704. case XK_KP_3: return LA_KEY_NUM3;
  1705. case XK_KP_4: return LA_KEY_NUM4;
  1706. case XK_KP_5: return LA_KEY_NUM5;
  1707. case XK_KP_6: return LA_KEY_NUM6;
  1708. case XK_KP_7: return LA_KEY_NUM7;
  1709. case XK_KP_8: return LA_KEY_NUM8;
  1710. case XK_KP_9: return LA_KEY_NUM9;
  1711. case XK_KP_0: return LA_KEY_NUM0;
  1712. case XK_KP_Add: return LA_KEY_NUMPLUS;
  1713. case XK_KP_Subtract: return LA_KEY_NUMMINUS;
  1714. case XK_KP_Divide: return LA_KEY_NUMDIVIDE;
  1715. case XK_KP_Multiply: return LA_KEY_NUMMULT;
  1716. case XK_KP_Decimal: return LA_KEY_NUMDOT;
  1717. case XK_KP_Enter: return LA_KEY_NUMENTER;
  1718. default: return keysym;
  1719. }
  1720. #endif
  1721. #ifdef _WIN32
  1722. switch (keysym) {
  1723. case VK_RETURN: return LA_KEY_ENTER;
  1724. case VK_ESCAPE: return LA_KEY_ESCAPE;
  1725. case VK_TAB: return LA_KEY_TAB;
  1726. case VK_LEFT: return LA_KEY_ARRLEFT;
  1727. case VK_RIGHT: return LA_KEY_ARRRIGHT;
  1728. case VK_UP: return LA_KEY_ARRUP;
  1729. case VK_DOWN: return LA_KEY_ARRDOWN;
  1730. case VK_CONTROL: return LA_KEY_CTRL;
  1731. case VK_SHIFT: return LA_KEY_SHIFT;
  1732. case VK_MENU: return LA_KEY_ALT;
  1733. case VK_F1: return LA_KEY_F1;
  1734. case VK_F2: return LA_KEY_F2;
  1735. case VK_F3: return LA_KEY_F3;
  1736. case VK_F4: return LA_KEY_F4;
  1737. case VK_F5: return LA_KEY_F5;
  1738. case VK_F6: return LA_KEY_F6;
  1739. case VK_F7: return LA_KEY_F7;
  1740. case VK_F8: return LA_KEY_F8;
  1741. case VK_F9: return LA_KEY_F9;
  1742. case VK_F10: return LA_KEY_F10;
  1743. case VK_F11: return LA_KEY_F11;
  1744. case VK_F12: return LA_KEY_F12;
  1745. case VK_NUMPAD0: return LA_KEY_NUM0;
  1746. case VK_NUMPAD1: return LA_KEY_NUM1;
  1747. case VK_NUMPAD2: return LA_KEY_NUM2;
  1748. case VK_NUMPAD3: return LA_KEY_NUM3;
  1749. case VK_NUMPAD4: return LA_KEY_NUM4;
  1750. case VK_NUMPAD5: return LA_KEY_NUM5;
  1751. case VK_NUMPAD6: return LA_KEY_NUM6;
  1752. case VK_NUMPAD7: return LA_KEY_NUM7;
  1753. case VK_NUMPAD8: return LA_KEY_NUM8;
  1754. case VK_NUMPAD9: return LA_KEY_NUM9;
  1755. case VK_MULTIPLY: return LA_KEY_NUMMULT;
  1756. case VK_DIVIDE: return LA_KEY_NUMDIVIDE;
  1757. case VK_ADD: return LA_KEY_NUMPLUS;
  1758. case VK_SUBTRACT: return LA_KEY_NUMMINUS;
  1759. case VK_DECIMAL: return LA_KEY_NUMDOT;
  1760. case VK_OEM_1: return ';';
  1761. case VK_OEM_2: return '/';
  1762. case VK_OEM_3: return '`';
  1763. case VK_OEM_4: return '[';
  1764. case VK_OEM_5: return '\\';
  1765. case VK_OEM_6: return ']';
  1766. case VK_OEM_7: return '\'';
  1767. case VK_OEM_COMMA: return ',';
  1768. case VK_OEM_PERIOD: return '.';
  1769. case VK_OEM_PLUS: return '+';
  1770. case VK_OEM_MINUS: return '-';
  1771. default: return keysym;
  1772. }
  1773. #endif
  1774. }
  1775. void la_SendMouseEvent(SYSWINDOW hwnd, int type, int x, int y){
  1776. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  1777. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  1778. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  1779. // la_SaveEvent(hwnd, e, 0);
  1780. //}
  1781. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1782. e->type = type; e->x = x; e->y = y;
  1783. la_SaveEvent(hwnd, e, 0);
  1784. MAIN.evLastX=x; MAIN.evLastY=y;
  1785. };
  1786. void la_SendTimerEvent(SYSWINDOW hwnd, int type){
  1787. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1788. e->type = type;
  1789. la_SaveEvent(hwnd, e, 1);
  1790. };
  1791. void la_SendSignalEvent(SYSWINDOW* hwnd, int signal){
  1792. laEvent *e = memAcquireSimple(sizeof(laEvent));
  1793. e->type = LA_SIGNAL_EVENT;
  1794. e->key = signal;
  1795. la_SaveEvent(hwnd, e, 1);
  1796. };
  1797. void laRetriggerOperators(){
  1798. MAIN.ReTriggerOperators = 1;
  1799. }
  1800. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  1801. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  1802. }
  1803. void laSetCleanupCallback(laCleanupF Cleanup){
  1804. MAIN.Cleanup=Cleanup;
  1805. }
  1806. void laSetInputProcessCallback(laInputProcessF InputProcess){
  1807. MAIN.InputProcess=InputProcess;
  1808. }
  1809. //====================================================================================================
  1810. void la_DestroyTheme(laTheme* t){
  1811. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  1812. strSafeDestroy(&t->Name);
  1813. strSafeDestroy(&t->Author);
  1814. }
  1815. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  1816. laTheme *t = memAcquireHyper(sizeof(laTheme));
  1817. strSafeSet(&t->Name, Name);
  1818. strSafeSet(&t->Author, AuthorName);
  1819. lstAppendItem(&MAIN.Themes, t);
  1820. MAIN.CurrentTheme = t;
  1821. return t;
  1822. }
  1823. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  1824. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  1825. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  1826. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  1827. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  1828. strSafeSet(&bt->Name, Name);
  1829. bt->NormalY=NormalY;
  1830. bt->ActiveY=ActiveY;
  1831. bt->BorderY=BorderY;
  1832. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  1833. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  1834. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  1835. bt->BackRef = BackRef;
  1836. lstAppendItem(&t->BoxedThemes, bt);
  1837. return bt;
  1838. }
  1839. laTheme *laGetTheme(const char *ThemeName){
  1840. laTheme *t = MAIN.Themes.pFirst;
  1841. for (t; t; t = t->Item.pNext){
  1842. if (strSame(t->Name->Ptr, ThemeName)) return t;
  1843. }
  1844. return 0;
  1845. }
  1846. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  1847. laTheme *t = MAIN.Themes.pFirst;
  1848. for (t; t; t = t->Item.pNext){
  1849. laBoxedTheme *bt;
  1850. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  1851. bt = t->BoxedThemes.pFirst;
  1852. for (bt; bt; bt = bt->Item.pNext){
  1853. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  1854. }
  1855. }
  1856. return 0;
  1857. }
  1858. real* laThemeColor(laBoxedTheme* bt, int which){
  1859. switch(which){
  1860. default:
  1861. case LA_BT_NORMAL: return bt->Normal;
  1862. case LA_UI_EDITING:
  1863. case LA_BT_ACTIVE: return bt->Active;
  1864. case LA_BT_BORDER: return bt->Border;
  1865. case LA_BT_TEXT: return bt->Text; break;
  1866. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  1867. case LA_BT_DISABLED: return bt->Inactive; break;
  1868. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  1869. }
  1870. return bt->Normal;
  1871. }
  1872. real* laAccentColor(int which){
  1873. switch(which){
  1874. default:
  1875. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  1876. case LA_BT_WARNING: return MAIN.CurrentTheme->WarningColor;
  1877. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  1878. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  1879. case LA_BT_FACE:
  1880. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  1881. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  1882. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  1883. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  1884. }
  1885. return MAIN.CurrentTheme->SelectionColor;
  1886. }
  1887. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  1888. real hcy[3];
  1889. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  1890. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  1891. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  1892. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  1893. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  1894. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  1895. int *tm=&bt->LM,*tp=&bt->LP;
  1896. for(int i=0;i<4;i++){
  1897. tm[i]=(real)bt->Margins[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1898. tp[i]=(real)bt->Paddings[i]*LA_RH*MAIN.MarginSize/10+0.5;
  1899. }
  1900. }
  1901. void la_RefreshThemeColorSelf(laTheme* th){
  1902. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  1903. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha; th->WarningColor[3]=th->SelectionAlpha;
  1904. real hcy[3], usehcy[3];
  1905. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  1906. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  1907. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  1908. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  1909. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  1910. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  1911. }
  1912. void la_RefreshThemeColor(laTheme* th){
  1913. real hcy[3], usehcy[3], normalhcy[3];
  1914. tnsRGB2HCY(th->Color,hcy);
  1915. la_RefreshThemeColorSelf(th);
  1916. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  1917. la_RefreshBoxedThemeColor(bt);
  1918. (*bt->BackRef) = bt;
  1919. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  1920. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  1921. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  1922. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  1923. }
  1924. }
  1925. //I FUCKING HATE THIS STUPID FUNCTION
  1926. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  1927. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1928. laUiListDrawItem *last = uild->Items.pFirst;
  1929. int LimW=_R-_L;
  1930. int SL, SR, SU, SB;
  1931. int Target__B = Target->B;
  1932. int Target__R = Target->R;
  1933. uildi->Target = Target;
  1934. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  1935. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  1936. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  1937. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  1938. uildi->L = last ? Target->L - last->XP : Target->L;
  1939. uildi->R = last ? Target__R - last->XP : Target__R;
  1940. uildi->U = last ? Target->U - last->YP : Target->U;
  1941. uildi->B = last ? Target__B - last->YP : Target__B;
  1942. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  1943. uildi->L -= GlobalX;
  1944. uildi->R -= GlobalX;
  1945. uildi->U -= GlobalY;
  1946. uildi->B -= GlobalY;
  1947. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1948. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1949. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1950. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1951. uildi->DifX = SL - uildi->L;
  1952. uildi->DifY = SU - uildi->U;
  1953. uildi->L = SL;
  1954. uildi->R = SR+uildi->DifX;
  1955. uildi->U = SU;
  1956. uildi->B = SB;//+uildi->DifY;
  1957. if(uildi->R>_R){ uildi->R=_R; }
  1958. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  1959. //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);
  1960. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  1961. memFree(uildi);
  1962. return 0;
  1963. }
  1964. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B, uildi->R - uildi->L+1, uildi->B - uildi->U-1);
  1965. tnsOrtho(Target->L + Target->PanX + uildi->DifX-1,
  1966. Target->L + Target->PanX + uildi->DifX+1+ (uildi->R - uildi->L),
  1967. Target->U + Target->PanY + uildi->DifY+ (uildi->B - uildi->U),
  1968. Target->U + Target->PanY + uildi->DifY+1,
  1969. -100, 100);
  1970. lstPushItem(&uild->Items, uildi);
  1971. return 1;
  1972. }
  1973. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  1974. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  1975. laUiListDrawItem *last = uild->Items.pFirst;
  1976. int SL, SR, SU, SB;
  1977. if (B - U > LimH) B = U + LimH;
  1978. uildi->XP = last ? last->XP + PanX : PanX;
  1979. uildi->YP = last ? last->YP + PanY : PanY;
  1980. uildi->L = last ? L - last->XP : L;
  1981. uildi->R = last ? R - last->XP : R;
  1982. uildi->U = last ? U - last->YP : U;
  1983. uildi->B = last ? B - last->YP : B;
  1984. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  1985. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  1986. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  1987. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  1988. uildi->DifX = SL - uildi->L;
  1989. uildi->DifY = SU - uildi->U;
  1990. uildi->L = SL;
  1991. uildi->R = SR;
  1992. uildi->U = SU;
  1993. uildi->B = SB;
  1994. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  1995. tnsOrtho(L + PanX + uildi->DifX,
  1996. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  1997. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  1998. U + PanY + uildi->DifY,
  1999. -100, 100);
  2000. lstPushItem(&uild->Items, uildi);
  2001. }
  2002. void la_DoUiScissor(laUiItem* ui, int* savex, int* savey, int* savew, int* saveh,
  2003. int* savel, int* saver, int* saveu, int* saveb){
  2004. laPanel* panel=MAIN.PropMatcherContextP; int PW=panel->W, PH=panel->H;
  2005. *savex=T->vsx;*savey=T->vsy;*savew=T->vsw;*saveh=T->vsh;
  2006. *savel=T->vol;*saver=T->vor;*saveu=T->vou;*saveb=T->vob;
  2007. real p[3]={0}, tp[3]={0}; tnsMatrix44d m; tnsGetMVPMatrix(m);
  2008. real x,y,w,h;
  2009. x=TNS_MAX2(ui->L,T->vsx); y=TNS_MAX2(PH-ui->B,T->vsy);
  2010. w=TNS_MIN2(ui->R-ui->L,T->vsw); h=TNS_MIN2(ui->B-ui->U,T->vsh);
  2011. tnsViewportWithScissor(x,y,w,h); tnsOrtho(ui->L,ui->R,ui->B,ui->U,-100,100);
  2012. }
  2013. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  2014. laUiListDrawItem *uildi = uild->Items.pFirst;
  2015. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2016. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2017. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2018. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2019. Target->U + Target->PanY + uildi->DifY -1,
  2020. -100, 100);
  2021. }
  2022. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  2023. laUiListDrawItem *uildi = lstPopItem(uild);
  2024. laUiList *Target;
  2025. memFree(uildi);
  2026. uildi = uild->Items.pFirst;
  2027. if (!uildi || !uildi->Target){
  2028. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  2029. return;
  2030. }
  2031. Target = uildi->Target;
  2032. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  2033. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  2034. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  2035. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  2036. Target->U + Target->PanY + uildi->DifY -1,
  2037. -100, 100);
  2038. }
  2039. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  2040. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  2041. uildi->L = L;
  2042. uildi->R = R;
  2043. uildi->U = U;
  2044. uildi->B = B;
  2045. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  2046. tnsOrtho(L, R, B, U, -100, 100);
  2047. lstPushItem(&uild->Items, uildi);
  2048. }
  2049. void la_ClearUiListMatrix(laUiListDraw *uild){
  2050. laUiListDrawItem *uildi;
  2051. while (uildi = lstPopItem(uild)){
  2052. memFree(uildi);
  2053. }
  2054. }
  2055. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  2056. 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);
  2057. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  2058. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  2059. int la_TestUiListMinumWidth(laUiList *uil);
  2060. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  2061. if (ui){
  2062. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  2063. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  2064. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  2065. p->X = p->TX; p->Y = p->TY;
  2066. p->W = p->TW;
  2067. }
  2068. }
  2069. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  2070. int cw = MAIN.CurrentWindow->CW;
  2071. int ch = MAIN.CurrentWindow->CH;
  2072. int PH = p->TH;
  2073. laBoxedTheme*bt = *p->BT;
  2074. int uih=uil->B + bt->BM;
  2075. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  2076. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  2077. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  2078. else p->TH = PH;
  2079. p->H = p->TH;
  2080. if(p->BoundUi){
  2081. if ((p->X + p->W) > cw) p->X -= (p->X + p->W - cw);
  2082. if ((p->Y + p->H) > ch) p->Y -= (p->Y + p->H - ch);
  2083. if (p->X < 0) p->X = 0;
  2084. if (p->Y < 0) p->Y = 0;
  2085. if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
  2086. if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
  2087. }else{
  2088. if (p->Y < 0) p->Y = 0;
  2089. if ((!p->Block)&&(!p->IsMenuPanel)){
  2090. int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
  2091. if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
  2092. if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
  2093. if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
  2094. }
  2095. }
  2096. if((!p->IsMenuPanel) && (p->Mode!=LA_PANEL_FLOATING_PASSIVE)){
  2097. if(p->W<LA_RH*4) p->W=LA_RH*4;
  2098. if(p->H<LA_RH*2) p->H=LA_RH*2;
  2099. }
  2100. if (p->ST) p->TY = p->ST;
  2101. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  2102. if (p->SB) p->TH = ch - p->TY - p->SB;
  2103. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  2104. p->TX = p->X; p->TY = p->Y;
  2105. p->TW = p->W; p->TH = p->H;
  2106. }
  2107. void laPlacePanelForCreation(laPanel *p){
  2108. int cw = MAIN.CurrentWindow->CW; int ch = MAIN.CurrentWindow->CH; int PH = p->TH;
  2109. if ((!p->Block)&&(!p->IsMenuPanel)&&(!p->Parent)){
  2110. if (p->X+p->W > cw-LA_RH){ p->X = cw-LA_RH-p->W; }
  2111. if (p->Y+p->H > ch-LA_RH){ p->Y = ch-LA_RH-p->H; }
  2112. if (p->X < LA_RH){ p->X = LA_RH; } if (p->Y < LA_RH){ p->Y = LA_RH; }
  2113. p->TX=p->X; p->TY=p->Y;
  2114. }
  2115. }
  2116. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  2117. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2118. tnsViewportWithScissor(0, 0, p->W, p->H);
  2119. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  2120. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2121. }
  2122. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  2123. tnsDrawToScreen();
  2124. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  2125. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  2126. }
  2127. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  2128. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  2129. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  2130. }
  2131. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  2132. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  2133. tnsClearAll();
  2134. }
  2135. void la_PanelDrawDescendBorder(laPanel* Panel, laBoxedTheme* bt, int Width, real Alpha);
  2136. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  2137. real Color[] = {1, 1, 1, 1};
  2138. real L, W, U, H;
  2139. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2140. if(MAIN.EnableColorManagement){
  2141. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2142. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  2143. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2144. }else{
  2145. tnsUniformOutputColorSpace(T->immShader,0);
  2146. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2147. tnsUniformColorComposing(T->immShader,0,0,0);
  2148. }
  2149. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99) || p->AnimationMode==LA_PANEL_ANIMATION_FLASH)){
  2150. tnsUseNoTexture();
  2151. if (!p->IsMenuPanel){
  2152. la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  2153. }
  2154. tnsFlush();
  2155. }
  2156. if(p->ParentOperator){
  2157. tnsUseNoTexture();
  2158. tnsColor4d(LA_COLOR3(MAIN.CurrentTheme->Color),0.7*(p->AnimationMode==LA_PANEL_ANIMATION_FLASH?1.0f:p->AnimationRatio));
  2159. tnsVertex2d(0,0); tnsVertex2d(w->CW,0); tnsVertex2d(w->CW,w->CH); tnsVertex2d(0,w->CH);
  2160. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2161. }
  2162. switch (p->AnimationMode){
  2163. case 0: /* and */
  2164. case LA_PANEL_ANIMATION_FLASH:
  2165. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  2166. if(!(p->SR || p->SB || p->Parent || p->Block || p->IsMenuPanel)){
  2167. real* color=laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT); tnsColor4d(LA_COLOR3(color),color[3]*(p->ShowCorner?1:0.8));
  2168. int len=LA_RH/(p->ShowCorner?1:2); tnsUseNoTexture(); int px=p->X+p->W,py=p->Y+p->H;
  2169. tnsVertex2d(px,py); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2170. tnsPackAs(GL_TRIANGLES);
  2171. tnsColor4dv(laThemeColor(_LA_THEME_PANEL,LA_BT_NORMAL)); tnsVertex2d(px-len,py); tnsVertex2d(px,py-len);
  2172. tnsLineWidth(2); tnsPackAs(GL_LINES); tnsLineWidth(1);
  2173. }
  2174. if(p->AnimationMode==LA_PANEL_ANIMATION_FLASH){
  2175. p->AnimationRatio += MAIN.PanelAnimationSpeed * 0.1 * MAIN.LastFrameTime * 60;
  2176. if((int)(p->AnimationRatio*6)%2){
  2177. tnsUseNoTexture();
  2178. tnsColor4dv(laAccentColor(LA_BT_SELECTED));
  2179. 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);
  2180. tnsPackAs(GL_TRIANGLE_FAN); tnsFlush();
  2181. }
  2182. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2183. }
  2184. break;
  2185. case LA_PANEL_ANIMATION_DROP_DOWN:
  2186. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2187. tnsDraw2DTextureArg(
  2188. p->OffScr->pColor[0],
  2189. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  2190. Color,
  2191. 0, 0, 1 - p->AnimationRatio, 0);
  2192. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2193. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2194. break;
  2195. case LA_PANEL_ANIMATION_EXPAND:
  2196. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2197. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2198. W = tnsLinearItp(0, p->W, 0.4);
  2199. H = tnsLinearItp(0, p->H, 0.4);
  2200. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2201. tnsDraw2DTextureArg(
  2202. p->OffScr->pColor[0],
  2203. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2204. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2205. Color,
  2206. 0, 0, 0, 0);
  2207. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2208. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  2209. break;
  2210. case LA_PANEL_ANIMATION_DISSOVE:
  2211. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  2212. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  2213. W = tnsLinearItp(0, p->W, 1.4);
  2214. H = tnsLinearItp(0, p->H, 1.4);
  2215. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  2216. if (p->OffScr) tnsDraw2DTextureArg(
  2217. p->OffScr->pColor[0],
  2218. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2219. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2220. Color,
  2221. 0, 0, 0, 0);
  2222. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2223. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2224. break;
  2225. case LA_PANEL_ANIMATION_COLLAPSE:
  2226. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  2227. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  2228. W = tnsLinearItp(0, p->W, 0.4);
  2229. H = tnsLinearItp(0, p->H, 0.4);
  2230. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2231. if (p->OffScr) tnsDraw2DTextureArg(
  2232. p->OffScr->pColor[0],
  2233. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2234. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2235. Color,
  2236. 0, 0, 0, 0);
  2237. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2238. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2239. break;
  2240. case LA_PANEL_ANIMATION_MINIMIZE:
  2241. L = tnsLinearItp(0, p->X, 0.3);
  2242. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  2243. W = tnsLinearItp(0, p->W, 0.4);
  2244. H = tnsLinearItp(0, p->H, 0.4);
  2245. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  2246. tnsDraw2DTextureArg(
  2247. p->OffScr->pColor[0],
  2248. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  2249. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  2250. Color,
  2251. 0, 0, 0, 0);
  2252. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  2253. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  2254. break;
  2255. }
  2256. tnsFlush();
  2257. tnsUniformOutputColorSpace(T->immShader,0);
  2258. tnsUniformShowColorOverflowStripes(T->immShader,0);
  2259. tnsUniformColorComposing(T->immShader,0,0,0);
  2260. }
  2261. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  2262. if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
  2263. else{
  2264. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:GL_RGBA8;
  2265. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0,0);
  2266. }
  2267. tnsDrawToOffscreen(p->OffScr, 1, 0);
  2268. }
  2269. void la_PanelRefreshDetachedProp(laPanel *panel){
  2270. laProp *p;
  2271. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  2272. la_StepPropPack(&p->DetachedPP);
  2273. la_UsePropPack(&p->DetachedPP, 0);
  2274. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  2275. // laUseDataBlock(
  2276. // p->DetachedPP.LastPs->UseInstance,
  2277. // p->DetachedPP.LastPs->p,
  2278. // MAIN.PropMatcherContextP->FrameDistinguish,
  2279. // MAIN.PropMatcherContextP,
  2280. // la_PropPanelUserRemover, 0);
  2281. //}
  2282. }
  2283. }
  2284. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  2285. real* color=laThemeColor(bt,LA_BT_BORDER);
  2286. tnsColor4d(0,0,0,Alpha);
  2287. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  2288. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  2289. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  2290. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  2291. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  2292. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  2293. tnsPackAs(GL_TRIANGLE_STRIP);
  2294. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2295. tnsVertex2d(Panel->X-1, Panel->Y-1);
  2296. tnsVertex2d(Panel->X-1, Panel->Y + Panel->H+1);
  2297. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y + Panel->H+1);
  2298. tnsVertex2d(Panel->X+1 + Panel->W, Panel->Y-1);
  2299. tnsLineWidth(2.0); tnsPackAs(GL_LINE_LOOP); tnsLineWidth(1.0);
  2300. }
  2301. int la_AnimateUiListRecursive(laUiList *uil);
  2302. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  2303. int DrawState_ = 0;
  2304. laUiListDraw uild = {0};
  2305. if (p->Show){
  2306. la_SetPropMathcerContext(p);
  2307. MAIN.CurrentPanel = p;
  2308. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  2309. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  2310. //}
  2311. if (p->Refresh & LA_TAG_RECALC){
  2312. laRecalcPanelImmediate(p);
  2313. }
  2314. if (!p->MenuRefer){
  2315. if(!p->OffScr){ la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  2316. if (p->Refresh || !p->OffScr){
  2317. la_PanelDrawToOffsceen(p, &p->UI);
  2318. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2319. la_PanelBackgroundInit(p, bt);
  2320. int extrap=(p->Mode && (!p->IsMenuPanel))?p->TitleBar.B:0;
  2321. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U, p->H-bt->BM-bt->TM-extrap, p->W);
  2322. tnsFlush();
  2323. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  2324. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  2325. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  2326. DrawState_++;
  2327. }
  2328. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  2329. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  2330. if(p->UI.PanY<0){p->UI.PanY=0;}
  2331. DrawState_++;
  2332. }
  2333. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2334. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  2335. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2336. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  2337. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2338. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2339. if(p!=w->MaximizedUiPanel){
  2340. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2341. }else{
  2342. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  2343. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  2344. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  2345. tnsFlush();
  2346. }
  2347. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2348. }
  2349. }else{
  2350. if (p->Refresh || !p->OffScr){
  2351. la_PanelDrawToOffsceen(p, p->MenuRefer);
  2352. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  2353. la_PanelBackgroundInit(p, bt);
  2354. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  2355. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  2356. tnsFlush();
  2357. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  2358. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  2359. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  2360. DrawState_++;
  2361. }
  2362. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  2363. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  2364. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  2365. DrawState_++;
  2366. }
  2367. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  2368. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  2369. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  2370. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  2371. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2372. }
  2373. }
  2374. tnsDrawToScreen();
  2375. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2376. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2377. la_PanelDrawToWindow(p, w);
  2378. }elif (p->AnimationMode){
  2379. la_PanelDrawToWindow(p, w);
  2380. }
  2381. }
  2382. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  2383. if(!p->Show && p!=w->MaximizedUiPanel) return;
  2384. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  2385. laPanel *pi, *PrevPI;
  2386. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  2387. PrevPI = pi->Item.pPrev;
  2388. if (pi->AnimationMode && pi->LaterDestroy){
  2389. lstRemoveItem(&p->SubPanels, pi);
  2390. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  2391. continue;
  2392. }
  2393. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  2394. la_AttachedPanelDefDraw(w,pi,bt);
  2395. }
  2396. }
  2397. }
  2398. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  2399. real PanelSquare[] = {
  2400. b->X + 2, CH - (b->Y + 2 + LA_RH),
  2401. b->X + 2, CH - (b->Y + b->H - 4),
  2402. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  2403. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  2404. real Center[] = {
  2405. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  2406. real DraggingPlot[] = {
  2407. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2408. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2409. PanelSquare[0],
  2410. PanelSquare[1],
  2411. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2412. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2413. PanelSquare[2],
  2414. PanelSquare[3],
  2415. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2416. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2417. PanelSquare[4],
  2418. PanelSquare[5],
  2419. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2420. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2421. PanelSquare[6],
  2422. PanelSquare[7],
  2423. };
  2424. real Square[] = {
  2425. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  2426. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  2427. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  2428. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  2429. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  2430. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  2431. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  2432. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  2433. };
  2434. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  2435. LA_COLOR3(BorderColor4dV), 0,
  2436. LA_COLOR3(BorderColor4dV), 0.8,
  2437. LA_COLOR3(BorderColor4dV), 0,
  2438. LA_COLOR3(BorderColor4dV), 0.8,
  2439. LA_COLOR3(BorderColor4dV), 0,
  2440. LA_COLOR3(BorderColor4dV), 0.8,
  2441. LA_COLOR3(BorderColor4dV), 0,
  2442. };
  2443. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  2444. LA_COLOR3(FillColor4dv), 0,
  2445. LA_COLOR3(FillColor4dv), 0.8,
  2446. LA_COLOR3(FillColor4dv), 0,
  2447. LA_COLOR3(FillColor4dv), 0.8,
  2448. LA_COLOR3(FillColor4dv), 0,
  2449. LA_COLOR3(FillColor4dv), 0.8,
  2450. LA_COLOR3(FillColor4dv), 0,
  2451. };
  2452. tnsUseNoTexture();
  2453. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  2454. int Index[4];
  2455. tnsVertexArray2d(DraggingPlot, 8);
  2456. tnsColorArray4d(FillColor, 8);
  2457. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  2458. case 0:
  2459. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  2460. break;
  2461. case LA_BLOCK_DROP_LOCATION_L:
  2462. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  2463. break;
  2464. case LA_BLOCK_DROP_LOCATION_R:
  2465. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  2466. break;
  2467. case LA_BLOCK_DROP_LOCATION_U:
  2468. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  2469. break;
  2470. case LA_BLOCK_DROP_LOCATION_B:
  2471. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  2472. break;
  2473. }
  2474. //glDisable(GL_CULL_FACE);
  2475. tnsIndexArray(Index, 4);
  2476. tnsPackAs(GL_TRIANGLE_FAN);
  2477. //tnsFlush();
  2478. }
  2479. tnsVertexArray2d(DraggingPlot, 8);
  2480. tnsColorArray4d(PlotColor, 8);
  2481. tnsPackAs(GL_LINES);
  2482. tnsVertexArray2d(Square, 4);
  2483. tnsColor4dv(BorderColor4dV);
  2484. tnsPackAs(GL_LINE_LOOP);
  2485. glLineWidth(LA_SEAM_W);
  2486. tnsFlush();
  2487. glLineWidth(1);
  2488. }
  2489. void la_BlockDefDrawSelf(laBlock *b, int CH){
  2490. laBoxedTheme *bt = _LA_THEME_TAB;
  2491. laPanel *p;
  2492. real v[] = {
  2493. b->X, CH - b->Y,
  2494. b->X + LA_SEAM_W, CH - b->Y ,
  2495. b->X, CH - (b->Y + b->H),
  2496. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2497. b->X + b->W, CH - (b->Y + b->H),
  2498. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  2499. b->X + b->W, CH - b->Y,
  2500. b->X + b->W - LA_SEAM_W, CH - b->Y};
  2501. real tv[8];
  2502. real ratio = 1.0001f;
  2503. int tw = 0;
  2504. int L = LA_RH+LA_SEAM_W;
  2505. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2506. if(MAIN.EnableColorManagement){
  2507. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2508. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2509. }else{
  2510. tnsUniformOutputColorSpace(T->immShader,0);
  2511. tnsUniformColorComposing(T->immShader,0,0,0);
  2512. }
  2513. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2514. tw += p->TitleWidth + LA_SEAM_W*2;
  2515. }
  2516. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  2517. tnsUseNoTexture();
  2518. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2519. tnsVertexArray2d(v, 8);
  2520. tnsPackAs(GL_TRIANGLE_STRIP);
  2521. int TitleGap=b->Folded?0:LA_RH;
  2522. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2523. b->X + b->W, (CH - b->Y),
  2524. b->X + b->W, (CH - b->Y - TitleGap),
  2525. b->X, (CH - b->Y - TitleGap));
  2526. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  2527. tnsVertexArray2d(tv, 4);
  2528. tnsPackAs(GL_TRIANGLE_FAN);
  2529. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  2530. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  2531. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  2532. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  2533. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2534. tnsVertexArray2d(tv, 4);
  2535. tnsPackAs(GL_TRIANGLE_FAN);
  2536. if(b->Folded){
  2537. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  2538. 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);
  2539. 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);
  2540. tnsFlush(); return;
  2541. }
  2542. int LT=0,RT=0;
  2543. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2544. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  2545. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  2546. b->X + L+RT * ratio, (CH - b->Y),
  2547. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  2548. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  2549. if (p == b->CurrentPanel){
  2550. tnsUseNoTexture();
  2551. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  2552. tnsVertexArray2d(tv, 4);
  2553. tnsPackAs(GL_TRIANGLE_FAN);
  2554. 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);
  2555. }else{
  2556. 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);
  2557. }
  2558. LT =RT;
  2559. }
  2560. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  2561. tnsFlush();
  2562. tnsUniformOutputColorSpace(T->immShader,0);
  2563. tnsUniformColorComposing(T->immShader,0,0,0);
  2564. }
  2565. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  2566. laBoxedTheme *bt = _LA_THEME_PANEL;
  2567. real tv[8];
  2568. tnsUseImmShader(); tnsEnableShaderv(T->immShader);
  2569. if(MAIN.EnableColorManagement){
  2570. tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  2571. tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
  2572. }else{
  2573. tnsUniformOutputColorSpace(T->immShader,0);
  2574. tnsUniformColorComposing(T->immShader,0,0,0);
  2575. }
  2576. tnsUseNoTexture();
  2577. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  2578. b->X + b->W, (CH - b->Y),
  2579. b->X + b->W, (CH - b->Y-b->H),
  2580. b->X, (CH - b->Y-b->H));
  2581. tnsVertexArray2d(tv, 4);
  2582. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  2583. tnsPackAs(GL_TRIANGLE_FAN);
  2584. 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,
  2585. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  2586. tnsFlush();
  2587. tnsUniformOutputColorSpace(T->immShader,0);
  2588. tnsUniformColorComposing(T->immShader,0,0,0);
  2589. }
  2590. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2591. if (b->B1){
  2592. la_BlockDefDrawRecursive(w, bt, b->B1);
  2593. la_BlockDefDrawRecursive(w, bt, b->B2);
  2594. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2595. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  2596. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  2597. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2598. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2599. la_BlockDefDrawSelf(b, w->CH);
  2600. }else{
  2601. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2602. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2603. la_BlockDefDrawSelfEmpty(b, w->CH);
  2604. }
  2605. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  2606. tnsUseNoTexture();
  2607. int at; real tv[8];
  2608. if (b->Vertical){
  2609. at = b->H * b->SplitRatio + b->Y;
  2610. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  2611. b->X + b->W, (w->CH - at + LA_SEAM_W),
  2612. b->X + b->W, (w->CH - at - LA_SEAM_W),
  2613. b->X, (w->CH - at - LA_SEAM_W));
  2614. }else{
  2615. at = b->X + b->W * b->SplitRatio;
  2616. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  2617. at- LA_SEAM_W, (w->CH - b->Y),
  2618. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  2619. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  2620. }
  2621. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  2622. tnsVertexArray2d(tv, 4);
  2623. tnsPackAs(GL_TRIANGLE_FAN);
  2624. }
  2625. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  2626. tnsFlush();
  2627. }
  2628. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  2629. if (b->B1){
  2630. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  2631. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  2632. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  2633. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  2634. }
  2635. tnsFlush();
  2636. }
  2637. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  2638. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  2639. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  2640. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  2641. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  2642. if(p->OffScr){
  2643. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2644. }
  2645. }
  2646. }
  2647. void la_ClearUnusedFramebuffers(laWindow* w){
  2648. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  2649. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  2650. }
  2651. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2652. if(p->Show || p->AnimationMode) continue;
  2653. if(p->OffScr){
  2654. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  2655. }
  2656. }
  2657. }
  2658. void laDeferredDestroyPanel(laPanel* p, int immediate);
  2659. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  2660. laPanel *p, *NextP;
  2661. laLayout *l = w->CurrentLayout;
  2662. if (!w->CH || !w->CW) return;
  2663. la_ClearUnusedFramebuffers(w);
  2664. tnsDrawToScreen();
  2665. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2666. glClearColor(0.2, 0.2, 0.3, 1.0);
  2667. tnsClearAll();
  2668. tnsUseNoTexture();
  2669. if (l->Draw) l->Draw(w, l);
  2670. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  2671. glEnable(GL_BLEND);
  2672. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2673. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  2674. laUiItem* ui;
  2675. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  2676. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  2677. la_SetPropMathcerContext(p);
  2678. if(p->Refresh){
  2679. if (!p->BT) p->BT = &_LA_THEME_PANEL;
  2680. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  2681. if(MAIN.EnableColorManagement){
  2682. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  2683. tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
  2684. }else{
  2685. tnsUniformOutputColorSpace(T->immShader,0);
  2686. tnsUniformColorComposing(T->immShader,0,0,0);
  2687. }
  2688. if(p->Refresh&LA_TAG_RECALC){
  2689. laRecalcPanelImmediate(p);
  2690. }
  2691. ui->Type->Draw(ui, LA_RH); tnsFlush();
  2692. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  2693. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  2694. }
  2695. tnsDrawToScreen();
  2696. tnsResetViewMatrix();
  2697. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  2698. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  2699. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  2700. tnsFlush();
  2701. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  2702. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2703. tnsFlush();
  2704. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  2705. }
  2706. }
  2707. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  2708. la_AttachedPanelDefDraw(w,p,*p->BT);
  2709. }else{
  2710. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  2711. la_BlockDefDrawRecursive(w, bt, RootBlock);
  2712. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  2713. }
  2714. for (p = w->Panels.pLast; p; p = NextP){
  2715. NextP = p->Item.pPrev;
  2716. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  2717. if (p->AnimationMode && p->LaterDestroy){
  2718. lstRemoveItem(&w->Panels, p);
  2719. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  2720. continue;
  2721. }
  2722. la_PanelDefDraw(w, p, *p->BT);
  2723. }
  2724. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  2725. la_AttachedPanelDefDraw(w,p,*p->BT);
  2726. }
  2727. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  2728. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  2729. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  2730. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  2731. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  2732. tnsFlush();
  2733. }
  2734. for (p = w->FadingPanels.pLast; p; p = NextP){
  2735. NextP = p->Item.pPrev;
  2736. if (!p->AnimationMode){
  2737. lstRemoveItem(&w->FadingPanels, p);
  2738. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  2739. laDeferredDestroyPanel(p, 0);
  2740. }else
  2741. la_PanelDrawToWindow(p, w);
  2742. }
  2743. }
  2744. int laStartWindow(laWindow *w){
  2745. #ifdef LA_LINUX
  2746. XMapWindow(MAIN.dpy,w->win);
  2747. tnsContextMakeWindowCurrent(w);
  2748. #endif
  2749. #ifdef _WIN32
  2750. ShowWindow(w->win, SW_SHOWNORMAL);
  2751. #endif
  2752. MAIN.CurrentWindow = w;
  2753. if(!w->CurrentLayout){
  2754. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  2755. memAssignRef(w, &w->CurrentLayout, w->Layouts.pFirst);
  2756. }
  2757. laRedrawCurrentWindow();
  2758. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  2759. w->Shown = 1;
  2760. }
  2761. void la_AssignWindowPP(laWindow* w){
  2762. w->PP.EndInstance = w;
  2763. w->PP.LastPs = &w->FakePS;
  2764. w->PP.LastPs->p = _LA_PROP_WINDOW;
  2765. w->PP.LastPs->UseInstance = w;
  2766. w->PP.LastPs->Type = U'.';
  2767. }
  2768. laWindow *laDesignWindow(int X, int Y, int W, int H){
  2769. #ifdef LAGUI_ANDROID
  2770. if(MAIN.Windows.pFirst){ return MAIN.Windows.pFirst; }
  2771. #endif
  2772. laWindow *n = memAcquire(sizeof(laWindow));
  2773. strSafeSet(&n->Title, "Empty SYSWINDOW");
  2774. n->X = X; n->Y = Y; n->W = W; n->H = H;
  2775. #ifdef LAGUI_ANDROID
  2776. n->X=0; n->Y=0; n->W=MAIN.AppWidth; n->H=MAIN.AppHeight;
  2777. #endif
  2778. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  2779. lstAppendItem(&MAIN.Windows, n);
  2780. MAIN.CurrentWindow = n;
  2781. la_AssignWindowPP(n);
  2782. laui_DefaultMenuBar(n);
  2783. return n;
  2784. }
  2785. void laSetWindowCursor(int id){
  2786. MAIN.CurrentCursor = id;
  2787. #ifdef LA_LINUX
  2788. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  2789. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  2790. #endif
  2791. #ifdef _WIN32
  2792. SetCursor(la_ConvertCursorID(id));
  2793. #endif
  2794. };
  2795. void la_AssignBlockPP(laBlock* b){
  2796. b->PP.EndInstance = b;
  2797. b->PP.LastPs = &b->FakePS;
  2798. b->PP.LastPs->p = _LA_PROP_BLOCK;
  2799. b->PP.LastPs->UseInstance = b;
  2800. b->PP.LastPs->Type = U'.';
  2801. }
  2802. void laDestroyLayout(laWindow *w, laLayout* l){
  2803. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  2804. laDestroyBlocksRecursive(l->FirstBlock);
  2805. strSafeDestroy(&l->ID);
  2806. if(w->CurrentLayout==l){ memAssignRef(w, &w->CurrentLayout, l->Item.pPrev?l->Item.pPrev:l->Item.pNext); }
  2807. lstRemoveItem(&w->Layouts,l); memFree(l);
  2808. }
  2809. laLayout *laDesignLayout(laWindow *w, char *Title){
  2810. laLayout *l = memAcquire(sizeof(laLayout));
  2811. l->FirstBlock = memAcquire(sizeof(laBlock));
  2812. la_AssignBlockPP(l->FirstBlock);
  2813. lstAppendItem(&w->Layouts, l);
  2814. strSafeSet(&l->ID, Title);
  2815. memAssignRef(w, &w->CurrentLayout, l);
  2816. laRenameWindow(w, Title);
  2817. return l;
  2818. }
  2819. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  2820. 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); }
  2821. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  2822. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  2823. laNotifyUsers("la.windows.maximized_block"); }
  2824. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  2825. laNotifyUsers("la.windows.maximized_block"); }
  2826. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  2827. laRestoreCanvasUI();
  2828. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  2829. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  2830. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  2831. UiParentPanel->Show=0;
  2832. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  2833. }
  2834. void laRestoreCanvasUI(){
  2835. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2836. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  2837. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  2838. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  2839. }
  2840. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  2841. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  2842. }
  2843. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  2844. void laSplitBlockHorizon(laBlock *b, real Percentage){
  2845. laPanel *p;
  2846. b->SplitRatio = Percentage;
  2847. b->Vertical = 0;
  2848. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2849. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2850. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2851. p->Block = b->B1;
  2852. }
  2853. b->B1->Panels.pFirst = b->Panels.pFirst;
  2854. b->B1->Panels.pLast = b->Panels.pLast;
  2855. b->B1->CurrentPanel = b->CurrentPanel;
  2856. b->B1->parent = b->B2->parent=b;
  2857. b->Panels.pFirst = 0;
  2858. b->Panels.pLast = 0;
  2859. b->CurrentPanel = 0;
  2860. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2861. }
  2862. void laSplitBlockVertical(laBlock *b, real Percentage){
  2863. laPanel *p;
  2864. b->SplitRatio = Percentage;
  2865. b->Vertical = 1;
  2866. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  2867. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  2868. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2869. p->Block = b->B1;
  2870. }
  2871. b->B1->Panels.pFirst = b->Panels.pFirst;
  2872. b->B1->Panels.pLast = b->Panels.pLast;
  2873. b->B1->CurrentPanel = b->CurrentPanel;
  2874. b->B1->parent = b->B2->parent=b;
  2875. b->Panels.pFirst = 0;
  2876. b->Panels.pLast = 0;
  2877. b->CurrentPanel = 0;
  2878. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2879. }
  2880. void laCombineChildBlocks(laBlock *b){
  2881. laPanel *p; if(!b) return;
  2882. if (!b->B1->B1 && !b->B2->B1){
  2883. lstCombineLists(&b->Panels, &b->B1->Panels);
  2884. lstCombineLists(&b->Panels, &b->B2->Panels);
  2885. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  2886. p->Block = b;
  2887. }
  2888. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  2889. memFree(b->B1);
  2890. memFree(b->B2);
  2891. b->B1 = 0;
  2892. b->B2 = 0;
  2893. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2894. }elif(!b->B1->B1){
  2895. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  2896. b->Vertical = b->B2->Vertical;
  2897. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  2898. p->Block = b1;
  2899. }
  2900. lstCombineLists(&b1->Panels, &b->B1->Panels);
  2901. memFree(b->B1); memFree(b->B2);
  2902. b->B1 = b1; b->B2 = b2;
  2903. b1->parent = b; b2->parent = b;
  2904. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2905. }elif(!b->B2->B1){
  2906. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  2907. b->Vertical = b->B1->Vertical;
  2908. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  2909. p->Block = b1;
  2910. }
  2911. lstCombineLists(&b1->Panels, &b->B2->Panels);
  2912. memFree(b->B1); memFree(b->B2);
  2913. b->B1 = b1; b->B2 = b2;
  2914. b1->parent = b; b2->parent = b;
  2915. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2916. }
  2917. }
  2918. laBlock *laBlock1(laBlock *b){
  2919. return b->B1;
  2920. }
  2921. laBlock *laBlock2(laBlock *b){
  2922. return b->B2;
  2923. }
  2924. laBlock *laSwapSubBlocks(laBlock *b){
  2925. laBlock *tB;
  2926. tB = b->B2;
  2927. b->B2 = b->B1;
  2928. b->B1 = tB;
  2929. b->SplitRatio = 1 - b->SplitRatio;
  2930. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  2931. }
  2932. void laDestroyBlocksRecursive(laBlock *Root){
  2933. laPanel *p;
  2934. if (Root->B1){
  2935. laDestroyBlocksRecursive(Root->B1);
  2936. laDestroyBlocksRecursive(Root->B2);
  2937. }else{
  2938. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  2939. }
  2940. memFree(Root);
  2941. }
  2942. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  2943. if(!b->CurrentPanel ) return 0;
  2944. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  2945. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  2946. lstRemoveItem(&b->Panels, p);
  2947. if(!b->CurrentPanel && b->parent){ b=b->parent; laCombineChildBlocks(b); }
  2948. if(!p->TitleBar.UiItems.pFirst){
  2949. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  2950. }
  2951. p->Mode = LA_PANEL_FLOATING_TOP;
  2952. p->TY-=LA_RH; p->TH+=LA_RH;
  2953. p->W=p->TW=(p->PanelTemplate?p->PanelTemplate->DefaultW_RH:20)*LA_RH;
  2954. p->W=p->TH=(p->PanelTemplate?p->PanelTemplate->DefaultH_RH:20)*LA_RH;
  2955. p->Block = 0;
  2956. laEnsurePanelInBound(p,&p->UI); laPlacePanelForCreation(p);
  2957. laRecalcPanel(p);
  2958. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2959. p->BT = &_LA_THEME_FLOATING_PANEL;
  2960. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2961. laNotifyUsers("la.windows.panels");
  2962. return b->CurrentPanel;
  2963. }
  2964. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  2965. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  2966. lstRemoveItem(&from->Panels, p);
  2967. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2968. p->Mode = LA_PANEL_NORMAL;
  2969. p->Block=b;
  2970. b->CurrentPanel = p;
  2971. lstPushItem(&b->Panels, p);
  2972. laRecalcPanel(p);
  2973. p->BT = &_LA_THEME_PANEL;
  2974. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  2975. tnsFlush();
  2976. laNotifyUsers("la.windows.panels");
  2977. }
  2978. void laPopPanel(laPanel *p){
  2979. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  2980. lstRemoveItem(&p->Parent->SubPanels, p);
  2981. lstPushItem(&p->Parent->SubPanels, p);
  2982. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2983. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2984. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2985. laNotifyUsers("la.windows.panels");
  2986. }
  2987. }
  2988. void la_EnsurePanelExtras(laPanel *p){
  2989. laUiTemplate* uit=p->PanelTemplate;
  2990. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  2991. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  2992. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  2993. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  2994. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  2995. p->PropLinkFakeProp->Base.Offset = 0;
  2996. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  2997. p->PropLinkPP.EndInstance = p;
  2998. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  2999. p->PropLinkPP.LastPs->Type = U'.';
  3000. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  3001. }
  3002. laPanel* la_GivePanelNode(){
  3003. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  3004. return memAcquire(sizeof(laPanel));
  3005. }
  3006. void la_ReturnPanelNode(laPanel* p){
  3007. memset(p,0,sizeof(laPanel));
  3008. lstRemovePointer(&MAIN.DeferredRedrawList,p);
  3009. lstAppendItem(&MAIN.WastedPanels, p);
  3010. }
  3011. 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){
  3012. laPanel *p = la_GivePanelNode();
  3013. int CW = MAIN.CurrentWindow->CW;
  3014. int CH = MAIN.CurrentWindow->CH;
  3015. p->PanelTemplate = uit;
  3016. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  3017. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  3018. if (!MaxW) MaxW = 10000;
  3019. if (!MaxH) MaxH = 10000;
  3020. if (W > MaxW) W = MaxW;
  3021. if (H > MaxH) H = MaxH;
  3022. if (W < MinW) W = MinW;
  3023. if (H < MinH) H = MinH;
  3024. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  3025. p->X = p->TX = (X < 0 ? 0 : X);
  3026. p->Y = p->TY = (Y < 0 ? 0 : Y);
  3027. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  3028. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  3029. p->MaxW = MaxW; p->MaxH = MaxH;
  3030. p->MinW = MinW; p->MinH = MinH;
  3031. p->SL = SnapL; p->ST = SnapT;
  3032. p->SR = SnapR; p->SB = SnapB;
  3033. if (p->SR) p->X = CW - p->W - p->SR;
  3034. if (p->SB) p->Y = CH - p->H - p->SB;
  3035. la_EnsurePanelSnapping(p, CW, CH);
  3036. p->Show = 1;
  3037. p->PP.EndInstance = p;
  3038. p->PP.LastPs = &p->FakePS;
  3039. p->PP.LastPs->p = _LA_PROP_PANEL;
  3040. p->PP.LastPs->UseInstance = p;
  3041. p->PP.LastPs->Type = U'.';
  3042. la_EnsurePanelExtras(p);
  3043. laRecalcPanel(p);
  3044. p->FrameDistinguish = 100; //greater than 1 is ok
  3045. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  3046. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  3047. return p;
  3048. }
  3049. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  3050. if(!uit) return 0;
  3051. laPanel *p = memAcquireHyper(sizeof(laPanel));
  3052. strSafeSet(&p->Title, uit->Title->Ptr);
  3053. p->PanelTemplate = uit;
  3054. p->Show = 1;
  3055. p->PP.EndInstance = p;
  3056. p->PP.LastPs = &p->FakePS;
  3057. p->PP.LastPs->p = _LA_PROP_PANEL;
  3058. p->PP.LastPs->UseInstance = p;
  3059. p->PP.LastPs->Type = U'.';
  3060. la_EnsurePanelExtras(p);
  3061. laRecalcPanel(p);
  3062. p->FrameDistinguish = 100; //greater than 1 is ok
  3063. p->TitleWidth = tnsStringGetWidth(transLate(SSTR(p->Title)), 0, 0);
  3064. while (b->B1){ b = b->B1; } lstPushItem(&b->Panels, p);
  3065. p->Block = b; b->CurrentPanel = p;
  3066. if(uit->PropFunc){ uit->PropFunc(p); }
  3067. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  3068. laNotifyUsers("la.windows.panels");
  3069. return p;
  3070. }
  3071. laPanel *laCreatePanel(laBlock *b, char *template_id){
  3072. laUiTemplate* uit=laFindUiTemplate(template_id);
  3073. return laCreatePanelT(b, uit);
  3074. }
  3075. 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){
  3076. laUiTemplate* uit=0;
  3077. if(template_id) uit=laFindUiTemplate(template_id);
  3078. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3079. p->Mode = LA_PANEL_FLOATING_TOP;
  3080. laPlacePanelForCreation(p);
  3081. if(uit){
  3082. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  3083. }
  3084. if (w) lstPushItem(&w->Panels, p);
  3085. return p;
  3086. }
  3087. void laShowPanel(laPanel *p){
  3088. p->Show = 1; laNotifyUsers("la.windows.panels_hidden");
  3089. }
  3090. void laShowPanelWithDropDownEffect(laPanel *p){
  3091. laShowPanel(p);
  3092. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  3093. p->AnimationRatio = 0;
  3094. }
  3095. void laShowPanelWithExpandEffect(laPanel *p){
  3096. laShowPanel(p);
  3097. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  3098. p->AnimationRatio = 0;
  3099. }
  3100. void laHidePanel(laPanel *p){
  3101. if (!p->Mode) return;
  3102. p->Show = 0;
  3103. laNotifyUsers("la.windows.panels_hidden");
  3104. }
  3105. void laHidePanelWithDissoveEffect(laPanel *p){
  3106. if (!p->Mode) return;
  3107. laHidePanel(p);
  3108. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3109. p->AnimationRatio = 1;
  3110. }
  3111. void laHidePanelWithCollapseEffect(laPanel *p){
  3112. if (!p->Mode) return;
  3113. laHidePanel(p);
  3114. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  3115. p->AnimationRatio = 1;
  3116. }
  3117. void laHidePanelWithMinimizeEffect(laPanel *p){
  3118. if (!p->Mode) return;
  3119. laHidePanel(p);
  3120. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  3121. p->AnimationRatio = 1;
  3122. }
  3123. void laActivatePanel(char* TemplateID, int x, int y){
  3124. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  3125. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  3126. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  3127. laShowPanelWithExpandEffect(p); laPopPanel(p);
  3128. }
  3129. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  3130. p->UI.PanX += DeltaX;
  3131. p->UI.PanY += DeltaY;
  3132. }
  3133. int laPanUiListFree(laUiList *uil, int X, int Y){
  3134. uil->PanX+=X; uil->PanY+=Y;
  3135. }
  3136. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3137. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  3138. if(Y){X+=Y;Y=0;}
  3139. }
  3140. if (Y > 0){
  3141. if (uil->B - uil->PanY <= B) return 0;
  3142. else{
  3143. uil->PanY += Y;
  3144. if (uil->B - uil->PanY <= B){
  3145. uil->PanY = uil->B - B;
  3146. return 1;
  3147. }
  3148. }
  3149. }
  3150. if (Y < 0){
  3151. if (uil->U - uil->PanY >= U) return 0;
  3152. else{
  3153. uil->PanY += Y;
  3154. if (uil->U - uil->PanY >= U){
  3155. uil->PanY = uil->U - U;
  3156. return 1;
  3157. }
  3158. }
  3159. }
  3160. if(uil->AllowScale){
  3161. laPanUiListFree(uil, X, 0);
  3162. }else{
  3163. if (X > 0){
  3164. if (uil->R - uil->PanX <= R) return 0;
  3165. else{
  3166. uil->PanX += X;
  3167. if (uil->R - uil->PanX <= R){
  3168. uil->PanX = uil->R - R;
  3169. return 1;
  3170. }
  3171. }
  3172. }
  3173. if (X < 0){
  3174. if (uil->L - uil->PanX >= L) return 0;
  3175. else{
  3176. uil->PanX += X;
  3177. if (uil->L - uil->PanX >= L){
  3178. uil->PanX = uil->L - L;
  3179. return 1;
  3180. }
  3181. }
  3182. }
  3183. }
  3184. return 1;
  3185. }
  3186. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  3187. int ret=1;
  3188. if(!uil->AllowScale){ return 0; }
  3189. real NewScale=uil->Scale*factor;
  3190. if(NewScale<0.2){NewScale=0.2; ret=0;}
  3191. if(NewScale>5) {NewScale=5; ret=0;}
  3192. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  3193. factor=NewScale/uil->Scale;
  3194. uil->Scale=NewScale;
  3195. real mx=(L+R)/2,my=(U+B)/2;
  3196. real dx= (mx+uil->PanX)*factor;
  3197. real dy= (my+uil->PanY)*factor;
  3198. uil->PanX=dx-mx;
  3199. uil->PanY=dy-my;
  3200. MAIN.CurrentPanel->FrameDistinguish=100;
  3201. return ret;
  3202. }
  3203. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  3204. if(uil->AllowScale) return 0;
  3205. return laPanUiList(uil,X,Y,L,R,U,B);
  3206. }
  3207. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  3208. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3209. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  3210. strSafeSet(&p->Title, Title);
  3211. if (Define){
  3212. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3213. }
  3214. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3215. p->BT= &_LA_THEME_FLOATING_PANEL;
  3216. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  3217. p->BoundUi = 1;
  3218. return p;
  3219. }
  3220. 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,
  3221. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  3222. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  3223. strSafeSet(&p->Title, Title);
  3224. if (Define){
  3225. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  3226. }
  3227. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  3228. p->BT= &_LA_THEME_FLOATING_PANEL;
  3229. p->Mode = LA_PANEL_FLOATING_TOP;
  3230. p->BoundUi = 1;
  3231. return p;
  3232. }
  3233. void laDeferredDestroyPanel(laPanel *p, int immediate){
  3234. laPanel *ip;
  3235. tnsDelete2DOffscreen(p->OffScr);
  3236. p->OffScr = 0;
  3237. strSafeDestroy(&p->Title);
  3238. if (!p->AnimationMode){
  3239. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  3240. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  3241. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3242. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  3243. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  3244. }else if (p->Block){
  3245. lstRemoveItem(&p->Block->Panels, p);
  3246. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  3247. }
  3248. laNotifyUsers("la.windows.panels");
  3249. }
  3250. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  3251. //lstRemoveItem(&p->SubPanels, ip);
  3252. laDestroySinglePanel(ip, immediate);
  3253. laNotifyUsers("la.windows.panels");
  3254. }
  3255. la_ClearDetachedProp(p);
  3256. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  3257. la_ReturnPanelNode(p);
  3258. }
  3259. void laDestroySinglePanel(laPanel *p, int immediate){
  3260. la_SetPropMathcerContext(p);
  3261. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  3262. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  3263. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  3264. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  3265. }
  3266. }
  3267. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  3268. la_DestroyUiList(&p->UI, 1, 1, 0);
  3269. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  3270. //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  3271. if (p->Mode){
  3272. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  3273. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  3274. }
  3275. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  3276. if (la_UiStillInService(p)){
  3277. la_StopUiOperatorService(p);
  3278. }
  3279. if ((!p->AnimationMode) || immediate){
  3280. laDeferredDestroyPanel(p, immediate);
  3281. }else{
  3282. p->LaterDestroy = 1;
  3283. }
  3284. }
  3285. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  3286. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3287. int MinW,MinWt=0;
  3288. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  3289. int CW = MAIN.CurrentWindow->CW;
  3290. if(p->SL && p->SR){return 0;}
  3291. la_SetPropMathcerContext(p);
  3292. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3293. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  3294. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  3295. MinW = la_TestUiListMinumWidth(uil);
  3296. if (MinW<MinWt){MinW=MinWt;}
  3297. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  3298. if (MinW > 20){
  3299. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  3300. }
  3301. la_PanelValidateWidth(p,uil);
  3302. laEnsurePanelInBound(p,uil);
  3303. if(p->TW>CW){ p->TW=CW; }
  3304. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  3305. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  3306. laRedrawPanel(p);
  3307. return 1;
  3308. }
  3309. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  3310. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3311. laOperator *ai = a;
  3312. laPanel *p;
  3313. int GX, GY, GW, t = 0;
  3314. int b;
  3315. laUiDefineFunc def = ReplaceUiDefine;
  3316. int MinW;
  3317. if (!def){ def=laui_DefaultPropDetails; }
  3318. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3319. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3320. laEnclosePanelContent(p, &p->UI);
  3321. laSetOperatorLocalizer(p);
  3322. p->CloseWhenMovedOut=1;
  3323. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3324. //laShowPanelWithDropDownEffect(p);
  3325. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3326. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  3327. return p;
  3328. }
  3329. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  3330. laPanel *p;
  3331. int GX, GY, GW, t = 0;
  3332. int b;
  3333. laUiDefineFunc def = ReplaceUiDefine;
  3334. int MinW;
  3335. if (!def) return 0;
  3336. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  3337. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  3338. p->Mode = LA_PANEL_FLOATING_TOP;
  3339. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  3340. laEnclosePanelContent(p, &p->UI);
  3341. if(MAIN.CurrentWindow->Operators.pFirst){
  3342. laSetOperatorLocalizer(MAIN.PendingSplash);
  3343. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  3344. MAIN.PendingSplash=0;
  3345. }
  3346. //laShowPanelWithExpandEffect(p);
  3347. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3348. return p;
  3349. }
  3350. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  3351. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3352. laOperator *ai = a;
  3353. laPanel *p; laPropContainer* sub;
  3354. int GX, GY, GW, t = 0;
  3355. int b;
  3356. laUiDefineFunc def = ReplaceUiDefine;
  3357. int MinW;
  3358. if (!def){
  3359. if (This && This->LastPs->p){
  3360. if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  3361. elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->MenuUiDefine) def = This->LastPs->p->SubProp->MenuUiDefine;
  3362. }
  3363. if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  3364. if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  3365. }
  3366. GX = L; GY = B;
  3367. GW = (R - L) > MaxW ? MaxW : (R - L);
  3368. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  3369. laEnclosePanelContent(p, &p->UI);
  3370. laSetOperatorLocalizer(p);
  3371. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3372. laShowPanelWithDropDownEffect(p);
  3373. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  3374. if(Attachment){
  3375. p->Parent = Attachment;
  3376. lstAppendItem(&Attachment->SubPanels, p);
  3377. }
  3378. return p;
  3379. }
  3380. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  3381. laPanel *p;
  3382. int t = 0;
  3383. int b;
  3384. //laLocalToWindow(0, Attachment, &L, &t);
  3385. //laLocalToWindow(0, Attachment, &R, &U);
  3386. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  3387. laSetOperatorLocalizer(p);
  3388. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3389. laShowPanelWithDropDownEffect(p);
  3390. p->Parent = Attachment;
  3391. lstPushItem(&Attachment->SubPanels, p);
  3392. return p;
  3393. }
  3394. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  3395. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  3396. laOperator *ai = a;
  3397. laPanel *p;
  3398. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  3399. int GX, GY, GW, t = 0;
  3400. int b;
  3401. int MinW;
  3402. //laLocalToWindow(0,Attachment, &L, &t);
  3403. //laLocalToWindow(0,Attachment, &R, &B);
  3404. GX = L;
  3405. GY = B;
  3406. GW = (R - L) > MaxW ? MaxW : (R - L);
  3407. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3408. p->MenuRefer = MenuRefer;
  3409. laEnclosePanelContent(p, MenuRefer);
  3410. laSetOperatorLocalizer(p);
  3411. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3412. laShowPanelWithDropDownEffect(p);
  3413. p->Parent = Attachment;
  3414. lstPushItem(&Attachment->SubPanels, p);
  3415. return p;
  3416. }
  3417. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  3418. int L, int B, int MaxGH, int MaxW, laEvent *e){
  3419. laOperator *ai = a;
  3420. laPanel *p;
  3421. int GX, GY, GW, t = 0;
  3422. int b;
  3423. GX = L;
  3424. GY = B;
  3425. GW = MaxW;
  3426. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  3427. p->MenuRefer = &p->UI;
  3428. p->Mode = LA_PANEL_NO_PARENT_MENU;
  3429. laSetOperatorLocalizer(p);
  3430. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  3431. laShowPanelWithDropDownEffect(p);
  3432. if (Attachment){
  3433. p->Parent = Attachment;
  3434. lstPushItem(&Attachment->SubPanels, p);
  3435. }else{
  3436. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3437. }
  3438. return p;
  3439. }
  3440. 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){
  3441. laOperator *ai = For;
  3442. laPanel *p;
  3443. int b;
  3444. laUiDefineFunc def = 0;
  3445. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  3446. else def = laui_DefaultPropUiDefine;
  3447. For->PP.EndInstance = For->CustomData;
  3448. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  3449. laEnclosePanelContent(p, &p->UI);
  3450. MAIN.ToPanel = p;
  3451. laShowPanelWithExpandEffect(p);
  3452. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3453. ai->OperatorPanel = p;
  3454. p->ParentOperator = For;
  3455. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  3456. return p;
  3457. }
  3458. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3459. laPanel *p; int b; laUiList *uil; laColumn* col;
  3460. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  3461. strSafeSet(&p->Title, Title);
  3462. p->BoundUi = 1;
  3463. p->Mode = LA_PANEL_FLOATING_TOP;
  3464. p->BT = &_LA_THEME_FLOATING_PANEL;
  3465. MAIN.ToPanel = p;
  3466. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3467. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3468. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3469. laUiItem* r=laBeginRow(uil,col,0,0);
  3470. laShowSeparator(uil,col)->Expand=1;
  3471. laShowItem(uil,col,0,"LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  3472. laEndRow(uil,r);
  3473. laEnclosePanelContent(p,uil); laShowPanelWithExpandEffect(p);
  3474. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3475. laSetOperatorLocalizer(p);
  3476. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3477. return p;
  3478. }
  3479. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  3480. laPanel *p; int b; laUiList *uil; laColumn* col;
  3481. p = la_NewPanel(0, X, Y, W, 0, 1000, 0, 100, 0, 0, 0, 0, 0);
  3482. strSafeSet(&p->Title, Title);
  3483. p->BoundUi = 1;
  3484. p->Mode = LA_PANEL_FLOATING_TOP;
  3485. p->BT = &_LA_THEME_FLOATING_PANEL;
  3486. MAIN.ToPanel = p;
  3487. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  3488. uil = laPrepareUi(p); col = laFirstColumn(uil);
  3489. laShowLabel(uil, col, Message, 0, 0)->Flags|=LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP;
  3490. laUiItem* r = laBeginRow(uil,col,0,0);
  3491. laShowSeparator(uil,col)->Expand=1;
  3492. laShowItemFull(uil,col,0,"LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  3493. laEndRow(uil, r);
  3494. laEnclosePanelContent(p,uil);
  3495. laShowPanelWithExpandEffect(p);
  3496. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  3497. laSetOperatorLocalizer(p);
  3498. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  3499. return p;
  3500. }
  3501. void laOperatorModalOver(laOperator* For){
  3502. For->ModalOver = 1;
  3503. }
  3504. void laDeferredRedraw(laPanel* p){
  3505. for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
  3506. if(lip->p==p) return;
  3507. }
  3508. lstAppendPointer(&MAIN.DeferredRedrawList, p);
  3509. }
  3510. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3511. laWindow* cur=MAIN.CurrentWindow;
  3512. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  3513. MAIN.CurrentWindow=w;
  3514. la_UpdateUiPlacement(w);
  3515. }
  3516. MAIN.CurrentWindow=cur;
  3517. }
  3518. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  3519. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  3520. }
  3521. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  3522. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  3523. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  3524. void laRedrawCurrentPanel(){
  3525. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  3526. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3527. }
  3528. void laRecalcCurrentPanel(){
  3529. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  3530. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  3531. }
  3532. void laRecalcPanelImmediate(laPanel* p){
  3533. p->FrameDistinguish++;
  3534. laBoxedTheme* bt = (*p->BT);
  3535. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  3536. la_PanelRefreshDetachedProp(p);
  3537. int enclosed=0;
  3538. if(p->BoundUi || p->MenuRefer){
  3539. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  3540. else enclosed=laEnclosePanelContent(p, &p->UI);
  3541. }
  3542. if(!enclosed){
  3543. la_PanelValidateWidth(p,&p->UI);
  3544. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  3545. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  3546. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  3547. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  3548. }
  3549. laWindow* w=MAIN.CurrentWindow;
  3550. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  3551. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  3552. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  3553. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  3554. }
  3555. }
  3556. void laRecalcCurrentPanelImmediate(){
  3557. laRecalcPanelImmediate(MAIN.CurrentPanel);
  3558. }
  3559. int laNonFixedPanelExists(laPanel *p){
  3560. laPanel *ip;
  3561. if (!p) return 0;
  3562. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3563. // if (ip == p) return 1;
  3564. //}
  3565. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3566. if (ip == p) return 1;
  3567. }
  3568. return 0;
  3569. }
  3570. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  3571. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  3572. return 1;
  3573. }
  3574. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  3575. int tt=MAIN.TooltipCloseDistance;
  3576. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  3577. return 1;
  3578. }
  3579. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  3580. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  3581. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  3582. return 0;
  3583. return 1;
  3584. }
  3585. void laUnlinkSharedPanel(laPanel *p){
  3586. laWindow *w;
  3587. laPanel *ip;
  3588. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  3589. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  3590. if (ip == p){
  3591. lstRemoveItem(&w->Panels, ip);
  3592. return;
  3593. }
  3594. }
  3595. }
  3596. }
  3597. int laIsPanelCovered(laPanel *p){
  3598. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  3599. laPanel *ip;
  3600. laPanel *resp;
  3601. int in1 = 0, in2 = 0, in3 = 0;
  3602. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  3603. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  3604. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  3605. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  3606. //}
  3607. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  3608. if (ip == p){
  3609. in3 = 1;
  3610. d3 = 0;
  3611. continue;
  3612. }
  3613. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  3614. }
  3615. if (!in2 && !in3) in1 = 1;
  3616. if (in1){
  3617. if (d1 || d2 || d3) return 1;
  3618. }else{
  3619. if (in2){
  3620. if (d2 || d3) return 1;
  3621. }else if (in3)
  3622. if (d3) return 1;
  3623. }
  3624. return 0;
  3625. }
  3626. int laIsTopPanel(laPanel *p){
  3627. //if (!p->Item.pPrev) return 1;
  3628. //else {
  3629. if (!laIsPanelCovered(p)){
  3630. //laPopPanel(p);
  3631. return 1;
  3632. }
  3633. return 0;
  3634. //}
  3635. return 0;
  3636. }
  3637. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  3638. if(!p) return;
  3639. int ix = *x, iy = *y;
  3640. laListItemPointer *lip;
  3641. laOperator *ai = a;
  3642. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3643. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3644. if (a){
  3645. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3646. laUiList *uil = lip->p;
  3647. (*x) += uil->PanX;
  3648. (*y) += uil->PanY;
  3649. }
  3650. }
  3651. }
  3652. void laPanelToLocal(laOperator *a, int *x, int *y){
  3653. int ix = *x, iy = *y;
  3654. laListItemPointer *lip;
  3655. if (a){
  3656. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3657. laUiList *uil = lip->p;
  3658. (*x) += uil->PanX;
  3659. (*y) += uil->PanY;
  3660. }
  3661. }
  3662. }
  3663. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  3664. if(!p) return;
  3665. int ix = *x, iy = *y;
  3666. laListItemPointer *lip;
  3667. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3668. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3669. if (a){
  3670. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3671. laUiList *uil = lip->p;
  3672. (*x) -= uil->PanX;
  3673. (*y) -= uil->PanY;
  3674. }
  3675. }
  3676. }
  3677. void laPanelToWindow(laPanel *p, int *x, int *y){
  3678. int ix = *x, iy = *y;
  3679. laListItemPointer *lip;
  3680. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  3681. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  3682. }
  3683. void laLocalToPanel(laOperator *a, int *x, int *y){
  3684. int ix = *x, iy = *y;
  3685. laListItemPointer *lip;
  3686. if (a){
  3687. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  3688. laUiList *uil = lip->p;
  3689. (*x) -= uil->PanX;
  3690. (*y) -= uil->PanY;
  3691. }
  3692. }
  3693. }
  3694. void laSetNextMenuPos(int X, int Y, int W, int H){
  3695. MAIN.NextX = X;
  3696. MAIN.NextY = Y;
  3697. MAIN.NextW = W;
  3698. MAIN.NextH = H;
  3699. }
  3700. int laIsInBlock(laBlock *b, int X, int Y){
  3701. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  3702. return 0;
  3703. }
  3704. 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; }
  3705. 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; }
  3706. 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; }
  3707. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  3708. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  3709. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  3710. if (!b->B1 && !b->B2){
  3711. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  3712. }
  3713. }
  3714. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  3715. laPanel *p;
  3716. laBlock *sb = 0;
  3717. if (!laIsInBlock(b, X, Y)) return 0;
  3718. if (!b->B1 && !b->B2) return b;
  3719. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  3720. return laDetectBlockRecursive(b->B2, X, Y);
  3721. }
  3722. laPanel *laDetectPanel(int X, int Y){
  3723. laPanel *p; laBlock *b;
  3724. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  3725. int x = X, y = Y;
  3726. laWindowToLocal(0, p, &x, &y);
  3727. if (p->Show && laIsInPanel(p, x, y)){
  3728. return p;
  3729. }
  3730. }
  3731. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  3732. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  3733. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  3734. return 0;
  3735. }
  3736. laUiList *laPrepareUi(laPanel *p){
  3737. return &p->UI;
  3738. }
  3739. laColumn *laFirstColumn(laUiList *uil){
  3740. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  3741. else{
  3742. laColumn *c = memAcquireSimple(sizeof(laColumn));
  3743. c->SP = 1;
  3744. c->PreWidth = 1;
  3745. lstAppendItem(&uil->Columns, c);
  3746. c->Top = c;
  3747. return uil->Columns.pFirst;
  3748. }
  3749. }
  3750. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  3751. laColumn *lc, *rc;
  3752. if (c->LS || c->RS) return c;
  3753. lc = memAcquireSimple(sizeof(laColumn));
  3754. rc = memAcquireSimple(sizeof(laColumn));
  3755. c->LS = lc;
  3756. c->RS = rc;
  3757. c->LS->SP = Percent;
  3758. c->RS->SP = Percent;
  3759. c->LS->Top = c->Top;
  3760. c->RS->Top = c->Top;
  3761. if (uil){
  3762. lstAppendItem(&uil->Columns, lc);
  3763. lstAppendItem(&uil->Columns, rc);
  3764. }
  3765. if (c->LS && c->RS->MaxW == 0){
  3766. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3767. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3768. }else if (c->RS && c->LS->MaxW == 0){
  3769. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3770. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3771. }
  3772. return c;
  3773. }
  3774. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  3775. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  3776. return c->LS;
  3777. }
  3778. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  3779. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3780. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3781. return c->RS;
  3782. }
  3783. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3784. lstRemoveItem(List, c);
  3785. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3786. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3787. memFree(c);
  3788. }
  3789. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3790. laUiList *uil = TopUil;
  3791. laUiList *sub;
  3792. laUiItem *ui;
  3793. laColumn *cc, *NextCC = 0;
  3794. int Occupied = 0;
  3795. int Removed = 0;
  3796. if (!c->LS) return 0;
  3797. else{
  3798. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3799. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3800. }
  3801. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3802. if (ui->C == c->LS || ui->C == c->RS){
  3803. if (DoMerge){
  3804. ui->C = c;
  3805. Occupied = 1;
  3806. }else
  3807. return 1;
  3808. }
  3809. if (ui->Subs.pFirst){
  3810. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3811. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3812. }
  3813. }
  3814. }
  3815. if (!Removed){
  3816. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3817. if (cc == c){
  3818. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3819. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3820. c->LS = 0;
  3821. c->RS = 0;
  3822. Removed = 1;
  3823. break;
  3824. }
  3825. }
  3826. }
  3827. return Occupied;
  3828. }
  3829. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3830. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3831. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3832. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3833. ut->FakeProp->Base.Identifier = ut->Identifier;
  3834. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3835. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3836. ut->FakeProp->Base.OffsetIsPointer = 1;
  3837. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3838. return ut->ExtraProps;
  3839. }
  3840. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3841. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3842. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3843. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3844. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3845. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3846. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3847. ct->FakeProp->Base.OffsetIsPointer = 1;
  3848. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3849. return ct->ExtraProps;
  3850. }
  3851. void la_DestroyUiType(laUiType* uit){
  3852. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3853. memFree(uit);
  3854. }
  3855. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3856. laUiType *ut = memAcquire(sizeof(laUiType));
  3857. ut->Identifier = Identifer;
  3858. ut->OperatorID = UseOperator;
  3859. ut->Draw = Draw;
  3860. ut->Theme = bt;
  3861. ut->ForType = ForType;
  3862. ut->OperatorType = laGetOperatorType(UseOperator);
  3863. ut->GetHeight = GetHeight;
  3864. ut->Init = Init;
  3865. ut->Destroy = Destroy;
  3866. la_UDFAppendSharedTypePointer(Identifer, ut);
  3867. lstAppendItem(&MAIN.UiTypes, ut);
  3868. return ut;
  3869. }
  3870. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3871. laUiType *ut = MAIN.UiTypes.pFirst;
  3872. if (!P) return 0;
  3873. if (P->DefaultUiType) return P->DefaultUiType;
  3874. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3875. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3876. for (ut; ut; ut = ut->Item.pNext){
  3877. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3878. return ut;
  3879. }
  3880. }
  3881. return 0;
  3882. }
  3883. laUiType *la_GetUiButtonType(){
  3884. laUiType *ut = MAIN.UiTypes.pFirst;
  3885. for (ut; ut; ut = ut->Item.pNext){
  3886. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3887. }
  3888. return 0;
  3889. }
  3890. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3891. laCanvasTemplate *vdt;
  3892. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3893. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3894. }
  3895. return 0;
  3896. }
  3897. void la_AssignPropExtras(laUiItem* ui){
  3898. if(!ui->Type || !ui->Type->FakeProp) return;
  3899. ui->FakePs.p = ui->Type->FakeProp;
  3900. ui->FakePs.Type = U'.';
  3901. ui->FakePs.UseInstance = ui;
  3902. ui->ExtraPP.LastPs = &ui->FakePs;
  3903. }
  3904. void la_AssignCanvasPropExtras(laUiItem* ui){
  3905. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3906. laCanvasTemplate*ct=ui->CanvasTemplate;
  3907. ui->FakePs.p = ct->FakeProp;
  3908. ui->FakePs.Type = U'.';
  3909. ui->FakePs.UseInstance = ui;
  3910. ui->ExtraPP.EndInstance = ui->Extra;
  3911. ui->ExtraPP.LastPs = &ui->FakePs;
  3912. }
  3913. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3914. int result;
  3915. if (!ui) return 0;
  3916. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3917. if (Path){
  3918. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3919. if (!result){
  3920. ui->AT = laGetOperatorType(Path);
  3921. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3922. ui->Type = la_GetUiButtonType();
  3923. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3924. }else{
  3925. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3926. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3927. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3928. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3929. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3930. }
  3931. if (Base){
  3932. ui->PP.RawThis = Base;
  3933. }
  3934. }else if (Base){
  3935. ui->PP.LastPs = Base->LastPs;
  3936. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3937. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3938. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3939. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3940. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3941. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3942. }
  3943. la_AssignPropExtras(ui);
  3944. if(Widget){ ui->Flags|= Widget->Flags; }
  3945. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3946. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3947. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3948. return ui;
  3949. }
  3950. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3951. ui->Type = _LA_UI_LABEL;
  3952. ui->Template = Template;
  3953. ui->State = LA_UI_NORMAL;
  3954. strSafeSet(&ui->Display, Content);
  3955. la_AssignPropExtras(ui);
  3956. return ui;
  3957. }
  3958. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3959. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3960. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3961. ui->State = LA_UI_NORMAL;
  3962. la_AssignPropExtras(ui);
  3963. return ui;
  3964. }
  3965. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3966. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3967. transLate(Content);
  3968. la_UpdateLabelDisplay(ui, Template, Content);
  3969. ui->C = c;
  3970. if (ui->Type->Init) ui->Type->Init(ui);
  3971. ui->ExtraPP.EndInstance = ui->Extra;
  3972. lstAppendItem(&uil->UiItems, ui);
  3973. return ui;
  3974. }
  3975. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3976. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3977. la_UpdateLabelDisplay(ui, Template, Content);
  3978. ui->C = c;
  3979. if (ui->Type->Init) ui->Type->Init(ui);
  3980. ui->ExtraPP.EndInstance = ui->Extra;
  3981. lstAppendItem(&uil->UiItems, ui);
  3982. return ui;
  3983. }
  3984. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3985. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3986. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3987. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3988. ui->C = c;
  3989. if (ui->Type->Init) ui->Type->Init(ui);
  3990. ui->ExtraPP.EndInstance = ui->Extra;
  3991. lstAppendItem(&uil->UiItems, ui);
  3992. return ui;
  3993. }
  3994. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3995. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  3996. }
  3997. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3998. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  3999. }
  4000. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  4001. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4002. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  4003. ui->C = c;
  4004. ui->TemplateContext = TemplateContext;
  4005. if (ui->Type->Init) ui->Type->Init(ui);
  4006. ui->ExtraPP.EndInstance = ui->Extra;
  4007. lstAppendItem(&uil->UiItems, ui);
  4008. return ui;
  4009. }
  4010. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  4011. laUiItem *ui = memAcquire(sizeof(laUiItem));
  4012. ui->C = c; memAssignRef(ui,&ui->Extra,Image);
  4013. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  4014. ui->SymbolID=Height;
  4015. lstAppendItem(&uil->UiItems, ui);
  4016. return ui;
  4017. }
  4018. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4019. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  4020. }
  4021. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  4022. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  4023. }
  4024. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  4025. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4026. ui->Type = _LA_UI_CANVAS;
  4027. ui->State = LA_UI_NORMAL;
  4028. ui->C = c;
  4029. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  4030. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  4031. else{
  4032. 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); }
  4033. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  4034. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  4035. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  4036. }
  4037. if (ui->Type->Init) ui->Type->Init(ui);
  4038. la_AssignCanvasPropExtras(ui);
  4039. if (Height) ui->Expand=Height; else ui->Expand=6;
  4040. lstAppendItem(&uil->UiItems, ui);
  4041. return ui;
  4042. }
  4043. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  4044. laUiItem* ui=0;
  4045. #define ADD_CANVAS \
  4046. laUiItem* b=laBeginRow(uil,cr,0,0);\
  4047. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"active"));{\
  4048. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;\
  4049. }laEndCondition(uil,b3);\
  4050. laEndRow(uil,b);
  4051. if(Detached){
  4052. laColumn* cl,*cll,*clr,*cr;
  4053. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  4054. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  4055. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  4056. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  4057. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4058. ADD_CANVAS
  4059. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  4060. }laElse(uil,b2);{
  4061. laUiItem* rb=laShowItemFull(uil,clr,0,"tns.world.active_root",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  4062. ADD_CANVAS
  4063. ui=laShowCanvas(uil,c,0,"tns.world.active_root",0,Height); laDefault3DViewOverlay(ui);
  4064. }laEndCondition(uil,b2);
  4065. }else{
  4066. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  4067. }
  4068. #undef ADD_CANVAS
  4069. }
  4070. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  4071. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4072. laCanvasExtra *e;
  4073. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  4074. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  4075. ui->C = c;
  4076. if (ui->Type->Init) ui->Type->Init(ui);
  4077. ui->ExtraPP.EndInstance = ui->Extra;
  4078. lstAppendItem(&uil->UiItems, ui);
  4079. return ui;
  4080. }
  4081. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  4082. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4083. ui->Type = _LA_UI_SYMBOL;
  4084. ui->SymbolID = SymbolID;
  4085. if (Height) ui->State = Height;
  4086. ui->C = c;
  4087. if (ui->Type->Init) ui->Type->Init(ui);
  4088. ui->ExtraPP.EndInstance = ui->Extra;
  4089. lstAppendItem(&uil->UiItems, ui);
  4090. return ui;
  4091. }
  4092. laPropPack* laShowCompoundValue(laUiItem* ui, int slot, laPropPack *Base, const char *Path){
  4093. laPropPack PP={0}; int result;
  4094. if (Path){
  4095. result = la_GetPropFromPath(&PP, Base, Path, 0);
  4096. if (!result){ return 0; }
  4097. if (Base){ PP.RawThis = Base; }
  4098. }else if (Base){
  4099. PP.LastPs = Base->LastPs; PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  4100. }
  4101. laCompoundPP* CPP = memAcquire(sizeof(laCompoundPP));
  4102. CPP->Slot = slot; memcpy(&CPP->PP, &PP, sizeof(laPropPack));
  4103. lstAppendItem(&ui->CompoundPPs,CPP);
  4104. return &CPP->PP;
  4105. }
  4106. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  4107. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4108. ui->Type = &_LA_UI_ROW_BEGIN;
  4109. ui->State=Expand;
  4110. ui->Flags=Even;
  4111. ui->C = c;
  4112. if (ui->Type->Init) ui->Type->Init(ui);
  4113. ui->ExtraPP.EndInstance = ui->Extra;
  4114. lstAppendItem(&uil->UiItems, ui);
  4115. return ui;
  4116. }
  4117. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  4118. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4119. ui->Type = &_LA_UI_ROW_END;
  4120. ui->C = Begin->C;
  4121. ui->Page = (laUiList*)Begin;
  4122. if (ui->Type->Init) ui->Type->Init(ui);
  4123. ui->ExtraPP.EndInstance = ui->Extra;
  4124. lstAppendItem(&uil->UiItems, ui);
  4125. return ui;
  4126. }
  4127. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  4128. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  4129. e->Expression = Expression;
  4130. ui->Extra = e;
  4131. la_AssignPropExtras(ui);
  4132. }
  4133. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4134. laUiItem *ui = la_CreateGroupHandle(Widget);
  4135. laUiList *nuil;
  4136. ui->C = c;
  4137. lstAppendItem(&uil->UiItems, ui);
  4138. nuil = memAcquireSimple(sizeof(laUiList));
  4139. strSafeSet(&nuil->TabName, Name);
  4140. ui->Page = nuil;
  4141. lstAppendItem(&ui->Subs, nuil);
  4142. if (ui->Type->Init) ui->Type->Init(ui);
  4143. ui->ExtraPP.EndInstance = ui->Extra;
  4144. return ui;
  4145. }
  4146. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  4147. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  4148. laUiList *sub = SubUi->Page;
  4149. laColumn *s = laFirstColumn(sub);
  4150. SubUi->State = LA_UI_ACTIVE;
  4151. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  4152. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  4153. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  4154. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  4155. laShowSeparator(sub, s);
  4156. return SubUi;
  4157. }
  4158. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  4159. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  4160. laUiList *sub = SubUi->Page;
  4161. laColumn *s = laFirstColumn(sub);
  4162. SubUi->State = LA_UI_ACTIVE;
  4163. return SubUi;
  4164. }
  4165. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  4166. laEndCondition(sub, sub->UiItems.pFirst);
  4167. }
  4168. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  4169. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  4170. laUiList *nuil;
  4171. ui->C = c;
  4172. lstAppendItem(&uil->UiItems, ui);
  4173. if (ui->Type->Init) ui->Type->Init(ui);
  4174. ui->ExtraPP.EndInstance = ui->Extra;
  4175. return ui;
  4176. }
  4177. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  4178. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4179. if (!ui->Page) ui->Page = uil;
  4180. lstAppendItem(&ui->Subs, uil);
  4181. strSafeSet(&uil->TabName, Name);
  4182. laFirstColumn(uil);
  4183. //laFirstColumn(uil);
  4184. return uil;
  4185. }
  4186. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  4187. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  4188. /*if (!ui->Page) */ ui->Page = uil;
  4189. lstAppendItem(&ui->Subs, uil);
  4190. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  4191. return uil;
  4192. }
  4193. laUiConditionNode *laTrue(){
  4194. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4195. ucn->Type = LA_CONDITION_TRUE;
  4196. return ucn;
  4197. }
  4198. laUiConditionNode *laFalse(){
  4199. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4200. ucn->Type = LA_CONDITION_FALSE;
  4201. return ucn;
  4202. }
  4203. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  4204. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4205. ucn->Type = LA_CONDITION_PROP;
  4206. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  4207. strSafeSet(&ucn->String, Prop);
  4208. return ucn;
  4209. }
  4210. laUiConditionNode *laIntExpression(int Value){
  4211. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4212. ucn->Type = LA_CONDITION_INT;
  4213. ucn->IntValue = Value;
  4214. return ucn;
  4215. }
  4216. laUiConditionNode *laFloatExpression(real Value){
  4217. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4218. ucn->Type = LA_CONDITION_FLOAT;
  4219. ucn->FloatValue = Value;
  4220. return ucn;
  4221. }
  4222. laUiConditionNode *laStringExpression(char *Content){
  4223. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4224. ucn->Type = LA_CONDITION_STRING;
  4225. strSafeSet(&ucn->String, Content);
  4226. return ucn;
  4227. }
  4228. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4229. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4230. ucn->Type = LA_CONDITION_AND;
  4231. ucn->Expression1 = Expression1;
  4232. ucn->Expression2 = Expression2;
  4233. return ucn;
  4234. }
  4235. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4236. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4237. ucn->Type = LA_CONDITION_OR;
  4238. ucn->Expression1 = Expression1;
  4239. ucn->Expression2 = Expression2;
  4240. return ucn;
  4241. }
  4242. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  4243. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4244. ucn->Type = LA_CONDITION_NOT;
  4245. ucn->Expression1 = Expression1;
  4246. return ucn;
  4247. }
  4248. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4249. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4250. ucn->Type = LA_CONDITION_EQ;
  4251. ucn->Expression1 = Expression1;
  4252. ucn->Expression2 = Expression2;
  4253. return ucn;
  4254. }
  4255. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4256. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4257. ucn->Type = LA_CONDITION_GT;
  4258. ucn->Expression1 = Expression1;
  4259. ucn->Expression2 = Expression2;
  4260. return ucn;
  4261. }
  4262. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4263. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4264. ucn->Type = LA_CONDITION_LT;
  4265. ucn->Expression1 = Expression1;
  4266. ucn->Expression2 = Expression2;
  4267. return ucn;
  4268. }
  4269. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4270. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4271. ucn->Type = LA_CONDITION_GE;
  4272. ucn->Expression1 = Expression1;
  4273. ucn->Expression2 = Expression2;
  4274. return ucn;
  4275. }
  4276. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  4277. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  4278. ucn->Type = LA_CONDITION_LE;
  4279. ucn->Expression1 = Expression1;
  4280. ucn->Expression2 = Expression2;
  4281. return ucn;
  4282. }
  4283. int la_GetIntConditionValue(laUiConditionNode *Expression){
  4284. if (Expression->Type != LA_CONDITION_INT) return 0;
  4285. return Expression->IntValue;
  4286. }
  4287. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  4288. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  4289. return Expression->FloatValue;
  4290. }
  4291. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  4292. return Expression->String->Ptr;
  4293. }
  4294. 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){
  4295. switch (Mode1){
  4296. case LA_PROP_ENUM:
  4297. case LA_PROP_INT:
  4298. case LA_CONDITION_INT:
  4299. switch (Mode2){
  4300. case LA_PROP_ENUM:
  4301. case LA_PROP_INT:
  4302. case LA_CONDITION_INT:
  4303. switch (CompMode){
  4304. case LA_CONDITION_GE:
  4305. return (i1 >= i2);
  4306. case LA_CONDITION_GT:
  4307. return (i1 > i2);
  4308. case LA_CONDITION_EQ:
  4309. return (i1 == i2);
  4310. case LA_CONDITION_LT:
  4311. return (i1 < i2);
  4312. case LA_CONDITION_LE:
  4313. return (i1 <= i2);
  4314. }
  4315. case LA_PROP_FLOAT:
  4316. case LA_CONDITION_FLOAT:
  4317. switch (CompMode){
  4318. case LA_CONDITION_GE:
  4319. return ((real)i1 >= f2);
  4320. case LA_CONDITION_GT:
  4321. return ((real)i1 > f2);
  4322. case LA_CONDITION_EQ:
  4323. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  4324. case LA_CONDITION_LT:
  4325. return ((real)i1 < f2);
  4326. case LA_CONDITION_LE:
  4327. return ((real)i1 <= f2);
  4328. }
  4329. case LA_PROP_SUB:
  4330. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  4331. default:
  4332. return 0;
  4333. }
  4334. case LA_PROP_FLOAT:
  4335. case LA_CONDITION_FLOAT:
  4336. switch (Mode2){
  4337. case LA_PROP_INT:
  4338. case LA_PROP_ENUM:
  4339. case LA_CONDITION_INT:
  4340. switch (CompMode){
  4341. case LA_CONDITION_GE:
  4342. return (f1 >= (real)i2);
  4343. case LA_CONDITION_GT:
  4344. return (f1 > (real)i2);
  4345. case LA_CONDITION_EQ:
  4346. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  4347. case LA_CONDITION_LT:
  4348. return (f1 < (real)i2);
  4349. case LA_CONDITION_LE:
  4350. return (f1 <= (real)i2);
  4351. }
  4352. case LA_PROP_FLOAT:
  4353. case LA_CONDITION_FLOAT:
  4354. switch (CompMode){
  4355. case LA_CONDITION_GE:
  4356. return (f1 >= f2);
  4357. case LA_CONDITION_GT:
  4358. return (f1 > f2);
  4359. case LA_CONDITION_EQ:
  4360. return (f1 == f2);
  4361. case LA_CONDITION_LT:
  4362. return (f1 < f2);
  4363. case LA_CONDITION_LE:
  4364. return (f1 <= f2);
  4365. }
  4366. default:
  4367. return 0;
  4368. }
  4369. case LA_PROP_STRING:
  4370. case LA_CONDITION_STRING:
  4371. switch (Mode2){
  4372. case LA_PROP_STRING:
  4373. case LA_CONDITION_STRING:
  4374. return strSame(s1, s2);
  4375. default:
  4376. return 0;
  4377. }
  4378. case LA_PROP_SUB:
  4379. switch (Mode2){
  4380. case LA_PROP_SUB:
  4381. return p1 == p2;
  4382. case LA_CONDITION_INT:
  4383. case LA_PROP_INT:
  4384. case LA_PROP_ENUM:
  4385. return (int)p1 == i2;
  4386. default:
  4387. return 0;
  4388. }
  4389. default:
  4390. switch (CompMode){
  4391. case LA_CONDITION_GE:
  4392. return (i1 >= i2);
  4393. case LA_CONDITION_GT:
  4394. return (i1 > i2);
  4395. case LA_CONDITION_EQ:
  4396. return (i1 == i2);
  4397. case LA_CONDITION_LT:
  4398. return (i1 < i2);
  4399. case LA_CONDITION_LE:
  4400. return (i1 <= i2);
  4401. }
  4402. }
  4403. }
  4404. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  4405. void *Instance = 0;
  4406. int IValue1 = 0, IValue2 = 0;
  4407. real FValue1 = 0, FValue2 = 0;
  4408. void *Ptr1 = 0, *Ptr2 = 0;
  4409. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  4410. int Result1, Result2;
  4411. laEnumItem *ei; laSubProp*sp;
  4412. if (!Expression) return 0;
  4413. Str1[0] = 0;
  4414. Str2[0] = 0;
  4415. laPropIterator pi = {0};
  4416. switch (Expression->Type){
  4417. case LA_CONDITION_PROP:
  4418. if (!Expression->PP.LastPs){
  4419. (*IResult) = 0;
  4420. return 0;
  4421. }
  4422. switch (Expression->PP.LastPs->p->PropertyType){
  4423. case LA_PROP_INT:
  4424. *IResult = laGetInt(&Expression->PP);
  4425. if (*IResult) return LA_CONDITION_INT;
  4426. else return 0;
  4427. case LA_PROP_FLOAT:
  4428. *FResult = laGetFloat(&Expression->PP);
  4429. if (*FResult) return 1;
  4430. else return 0;
  4431. break;
  4432. case LA_PROP_STRING:
  4433. laGetString(&Expression->PP, _StrResult, &StrResult);
  4434. if (StrResult[0]) return 1;
  4435. else return 0;
  4436. break;
  4437. case LA_PROP_ENUM:
  4438. ei = laGetEnum(&Expression->PP);
  4439. if (!ei) return 0;
  4440. /*if(ei) */ *IResult = ei->Index;
  4441. if (*IResult) return LA_CONDITION_INT;
  4442. else return 0;
  4443. break;
  4444. case LA_PROP_SUB:
  4445. sp=Expression->PP.LastPs->p;
  4446. //if (sp->IsDetached){ *PtrResult = sp->Detached; if (sp->Detached) return 1; else return 0; }
  4447. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  4448. else Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  4449. if(!Instance){ Expression->PP.LastPs->p; if((!sp->GetActive) && (sp->Base.Offset<=0)){
  4450. Instance=laGetInstance(sp,Expression->PP.LastPs->UseInstance, &pi);
  4451. }
  4452. }
  4453. *PtrResult = Instance;
  4454. if (Instance) return 1;
  4455. break;
  4456. default:
  4457. return 0;
  4458. }
  4459. break;
  4460. case LA_CONDITION_INT:
  4461. *IResult = Expression->IntValue;
  4462. if (*IResult) return 1;
  4463. else
  4464. return 0;
  4465. case LA_CONDITION_FLOAT:
  4466. *FResult = Expression->FloatValue;
  4467. if (*FResult) return 1;
  4468. else
  4469. return 0;
  4470. case LA_CONDITION_STRING:
  4471. if (Expression->String){
  4472. strCopyFull(StrResult, Expression->String->Ptr);
  4473. return 1;
  4474. }else
  4475. return 0;
  4476. case LA_CONDITION_TRUE:
  4477. if (*IResult) *IResult = 1;
  4478. return 1;
  4479. case LA_CONDITION_FALSE:
  4480. if (*IResult) *IResult = 0;
  4481. return 0;
  4482. default:
  4483. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  4484. switch (Expression->Type){
  4485. case LA_CONDITION_AND:
  4486. if (Result1){
  4487. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4488. if (Result2) *IResult = 1;
  4489. return (Result2);
  4490. }else
  4491. return 0;
  4492. case LA_CONDITION_OR:
  4493. if (!Result1){
  4494. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4495. if (Result2) *IResult = 1;
  4496. return (Result2);
  4497. }else
  4498. return 1;
  4499. case LA_CONDITION_NOT:
  4500. return !Result1;
  4501. default:
  4502. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  4503. return la_DoCompare(Expression->Type,
  4504. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  4505. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  4506. }
  4507. break;
  4508. }
  4509. return 0;
  4510. }
  4511. int la_DoSingleExpression(laUiConditionNode *Expression){
  4512. int a;
  4513. real b;
  4514. char c[128]={0};
  4515. void *p;
  4516. if (!Expression) return 1;
  4517. c[0] = 0;
  4518. return la_DoExpression(Expression, &a, &b, c, &p);
  4519. }
  4520. void la_StepExpression(laUiConditionNode *e){
  4521. if (!e) return;
  4522. switch (e->Type){
  4523. case LA_CONDITION_AND:
  4524. case LA_CONDITION_OR:
  4525. case LA_CONDITION_GE:
  4526. case LA_CONDITION_GT:
  4527. case LA_CONDITION_EQ:
  4528. case LA_CONDITION_LT:
  4529. case LA_CONDITION_LE:
  4530. la_StepExpression(e->Expression1);
  4531. la_StepExpression(e->Expression2);
  4532. break;
  4533. case LA_CONDITION_NOT:
  4534. la_StepExpression(e->Expression1);
  4535. break;
  4536. case LA_CONDITION_PROP:
  4537. la_StepPropPack(&e->PP);
  4538. //if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){ // doesn't seem needed now with getuser
  4539. la_UsePropPack(&e->PP, 1);
  4540. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  4541. //}
  4542. break;
  4543. default:
  4544. break;
  4545. }
  4546. }
  4547. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  4548. if (!ucn) return;
  4549. la_ConditionNodeFreeRecursive(ucn->Expression1);
  4550. la_ConditionNodeFreeRecursive(ucn->Expression2);
  4551. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  4552. if (ucn->String) strSafeDestroy(&ucn->String);
  4553. if (ucn) memFree(ucn);
  4554. }
  4555. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  4556. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4557. ui->C = c;
  4558. ui->Type = &_LA_UI_CONDITION;
  4559. la_ConditionerInit(ui, Expression);
  4560. lstAppendItem(&uil->UiItems, ui);
  4561. return ui;
  4562. }
  4563. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  4564. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4565. laConditionUiExtraData *cued;
  4566. ui->Type = &_LA_UI_CONDITION_ELSE;
  4567. la_ConditionerInit(ui, 0);
  4568. cued = ui->Extra;
  4569. cued->EndUi = Beginner;
  4570. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  4571. ui->C = Beginner->C;
  4572. lstAppendItem(&uil->UiItems, ui);
  4573. return ui;
  4574. }
  4575. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  4576. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4577. laConditionUiExtraData *cued;
  4578. ui->Template = define;
  4579. ui->C = col;
  4580. ui->PP.RawThis = ExtraBase;
  4581. ui->Page = ExtraThis;
  4582. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  4583. la_ConditionerInit(ui, 0);
  4584. cued = ui->Extra;
  4585. //cued->Remove = Remove;
  4586. ui->State = LA_UI_NORMAL;
  4587. lstAppendItem(&uil->UiItems, ui);
  4588. return ui;
  4589. }
  4590. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  4591. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4592. laConditionUiExtraData *cued;
  4593. ui->Type = &_LA_UI_CONDITION_END;
  4594. la_ConditionerInit(ui, 0);
  4595. cued = ui->Extra;
  4596. cued->EndUi = Beginner;
  4597. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  4598. ui->C = Beginner->C;
  4599. lstAppendItem(&uil->UiItems, ui);
  4600. return ui;
  4601. }
  4602. laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
  4603. laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
  4604. laUiList* muil = memAcquireSimple(sizeof(laUiList));
  4605. ui->Type = _LA_UI_MENU_ROOT;
  4606. strSafeSet(&ui->Display, Title);
  4607. ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
  4608. ui->C = c;
  4609. lstAppendItem(&uil->UiItems, ui);
  4610. lstAppendItem(&ui->Subs, muil);
  4611. return muil;
  4612. }
  4613. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  4614. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  4615. ui->Type = _LA_UI_ALIGN;
  4616. ui->C = widest;
  4617. lstAppendItem(&uil->UiItems, ui);
  4618. return ui;
  4619. }
  4620. void laFixHeight(laUiList *uil, short Rows){
  4621. if (!uil) return;
  4622. uil->HeightCoeff = Rows;
  4623. }
  4624. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  4625. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  4626. if (!ExtraColumns) return;
  4627. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  4628. }
  4629. laUiTemplate *laFindUiTemplate(char *Identifier){
  4630. laUiTemplate *uit;
  4631. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4632. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4633. }
  4634. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  4635. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  4636. }
  4637. return 0;
  4638. }
  4639. void la_DestroyUiTemplate(laUiTemplate* uit){
  4640. strSafeDestroy(&uit->Identifier);
  4641. strSafeDestroy(&uit->Title);
  4642. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  4643. memFree(uit);
  4644. }
  4645. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  4646. strSafeDestroy(&uit->Identifier);
  4647. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  4648. memFree(uit);
  4649. }
  4650. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  4651. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  4652. strSafeSet(&uit->Identifier, Identifier);
  4653. strSafeSet(&uit->Title, Title);
  4654. strSafeSet(&uit->CategoryName, NewCategory);
  4655. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  4656. uit->DefaultGLFormat=DefaultGLFormat;
  4657. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  4658. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  4659. la_UDFAppendSharedTypePointer(Identifier, uit);
  4660. return uit;
  4661. }
  4662. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  4663. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  4664. strSafeSet(&t->Identifier, Identifier);
  4665. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  4666. t->Init = CustomInit; t->Destroy = CustomDestroy;
  4667. lstAppendItem(&MAIN.View2DTemplates, t);
  4668. la_UDFAppendSharedTypePointer(Identifier, t);
  4669. return t;
  4670. }
  4671. void laFinalizeUiTemplates(){
  4672. laUiTemplate *uit;
  4673. laCanvasTemplate *u2d;
  4674. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  4675. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  4676. }
  4677. }
  4678. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  4679. laPanel *p;
  4680. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  4681. if (p->PanelTemplate==uit){
  4682. return p;
  4683. }
  4684. }
  4685. return 0;
  4686. }
  4687. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  4688. laUiList *uil, *NextUil;
  4689. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  4690. NextUil = uil->Item.pNext;
  4691. lstRemoveItem(&ui->Subs, uil);
  4692. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  4693. }
  4694. la_StopUiOperatorService(ui);
  4695. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  4696. strSafeDestroy(&ui->Display);
  4697. //if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4698. // { /*la_StopUsingPropPack(&ui->PP);*/ }
  4699. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4700. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  4701. if (ui->CompoundPPs.pFirst){laCompoundPP* CPP;
  4702. while(CPP = lstPopItem(&ui->CompoundPPs)){ la_FreePropStepCache(CPP->PP.Go); memFree(CPP); }
  4703. }
  4704. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  4705. memFree(ui);
  4706. }
  4707. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  4708. laUiItem *ui, *NextUi;
  4709. laColumn *col, *NextCol;
  4710. if (!uil) return;
  4711. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  4712. NextUi = ui->Item.pNext;
  4713. if(OnlyRemoveUser && RemoveUsers){
  4714. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  4715. { /*la_StopUsingPropPack(&ui->PP);*/ }
  4716. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  4717. continue;
  4718. }
  4719. lstRemoveItem(&uil->UiItems, ui);
  4720. la_DestroyUiItem(ui, RemoveUsers);
  4721. }
  4722. if(OnlyRemoveUser){ return; }
  4723. for (col = uil->Columns.pFirst; col; col = NextCol){
  4724. NextCol = col->Item.pNext;
  4725. lstRemoveItem(&uil->Columns, col);
  4726. memFree(col);
  4727. }
  4728. strSafeDestroy(&uil->TabName);
  4729. if (!NoFree) memFree(uil);
  4730. }
  4731. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  4732. if(ui) lstRemoveItem(&ui->Subs, Tab);
  4733. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  4734. }
  4735. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  4736. laUiItem *Next = after->Item.pNext;
  4737. laUiItem *Last = uil->UiItems.pLast;
  4738. after->Item.pNext = 0;
  4739. uil->UiItems.pLast = after;
  4740. Define(uil, Base, This, ExtraColums, 0);
  4741. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  4742. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  4743. if (Next != Last) uil->UiItems.pLast = Last;
  4744. }
  4745. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  4746. // int i = 0;
  4747. // int FromW=FromR-FromL, ToW=ToR-ToL;
  4748. // if (!ui->ExtraColums) return;
  4749. // for (i; ui->ExtraColums[i]; i++) {
  4750. // laColumn* c = ui->ExtraColums[i];
  4751. // c->B = B;
  4752. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  4753. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  4754. // }
  4755. //}
  4756. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  4757. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  4758. }
  4759. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  4760. laColumn *c = ui->C;
  4761. laColumn *ic = lst->pFirst;
  4762. c->B = ui->TB + (*ui->Type->Theme)->BP;
  4763. for (ic; ic; ic = ic->Item.pNext){
  4764. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4765. ic->B = ic->B < c->B ? c->B : ic->B;
  4766. }
  4767. }
  4768. ic = ui->C;
  4769. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4770. ;
  4771. for (ic; ic; ic = ic->Item.pNext){
  4772. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4773. ic->B = ic->B < c->B ? c->B : ic->B;
  4774. }
  4775. }
  4776. }
  4777. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  4778. laColumn *c = ui->C;
  4779. laColumn *ic = lst->pFirst;
  4780. c->B = ui->TB + (*ui->Type->Theme)->TP;
  4781. for (ic; ic; ic = ic->Item.pNext){
  4782. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4783. ic->B = ic->B < c->B ? c->B : ic->B;
  4784. }
  4785. }
  4786. ic = ui->C;
  4787. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  4788. ;
  4789. for (ic; ic; ic = ic->Item.pNext){
  4790. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  4791. ic->B = ic->B < c->B ? c->B : ic->B;
  4792. }
  4793. }
  4794. }
  4795. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  4796. int rep;
  4797. int sp;
  4798. int rev;
  4799. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  4800. if (!c) return 0;
  4801. sp = (c->SP * (R - L)) + L;
  4802. rev = sp;
  4803. /*if (U)*/ c->B = U;
  4804. if (LR == 1){
  4805. c->IL = L;
  4806. c->IR = sp;
  4807. if (repos){
  4808. c->IR = repos;
  4809. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4810. c->IR = c->IL + c->MaxW*LA_RH+M;
  4811. rev = c->IR;
  4812. }
  4813. }else if (LR == 2){
  4814. c->IL = sp;
  4815. c->IR = R;
  4816. if (repos){
  4817. c->IL = repos;
  4818. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4819. c->IL = c->IR - c->MaxW*LA_RH-M;
  4820. rev = c->IL;
  4821. }
  4822. }else if (LR == 0){
  4823. c->IL = L;
  4824. c->IR = R;
  4825. }
  4826. if (c->LS && c->RS->MaxW == 0){
  4827. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4828. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4829. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4830. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4831. }else if (c->RS && c->LS->MaxW == 0){
  4832. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4833. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4834. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4835. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4836. }
  4837. return rev;
  4838. }
  4839. STRUCTURE(laRowInfo){
  4840. int MaxW;
  4841. int MinW;
  4842. int UnitMinW;
  4843. int NonExpandW;
  4844. int TotalPadding;
  4845. int Expand, Even;
  4846. int ExpandAccum;
  4847. int CountElements;
  4848. int U,MaxB,L;
  4849. laListHandle Elements;
  4850. int LastNoHeight;
  4851. };
  4852. STRUCTURE(laRowNode){
  4853. laListItem Item;
  4854. laUiItem* ui;
  4855. int GotW, LP, RP, H;
  4856. int Expand;
  4857. int UseLast;
  4858. int WaitAnimation;
  4859. };
  4860. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4861. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4862. ri->UnitMinW=LA_RH;
  4863. ri->Expand=ui->State?1:0;
  4864. ri->Even=ui->Flags?1:0;
  4865. ri->U=ui->TU; ri->L=ui->TL;
  4866. ri->MaxB=ui->TU;
  4867. }
  4868. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H, int WaitAnimation){
  4869. laRowNode* rn=CreateNew(laRowNode);
  4870. rn->LP=bt->LP;rn->RP=bt->RP;
  4871. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4872. rn->ui=ui;
  4873. rn->H=H;
  4874. rn->Expand=ui->Expand;
  4875. rn->WaitAnimation=WaitAnimation;
  4876. lstAppendItem(&ri->Elements, rn);
  4877. if(ri->LastNoHeight){ ri->LastNoHeight=0; rn->UseLast=1; return; }
  4878. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){ ri->LastNoHeight=1; };
  4879. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4880. ri->TotalPadding += (bt->LP+bt->RP);
  4881. ri->MinW+=ri->UnitMinW;
  4882. ri->NonExpandW+=rn->GotW;
  4883. ri->ExpandAccum+=ui->Expand;
  4884. ri->CountElements++;
  4885. if(ui->Expand){ri->Expand=1;}
  4886. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4887. }
  4888. int la_ShrinkableRowElements(laRowInfo* ri){
  4889. int count=0;
  4890. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4891. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4892. count++;
  4893. }
  4894. return count;
  4895. }
  4896. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4897. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end){
  4898. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4899. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4900. if(Available<0){
  4901. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4902. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4903. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4904. }else{
  4905. if(!ri->Expand && Available>0){Available=0;}
  4906. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4907. }
  4908. if(!ShareCount) return 0;
  4909. int PerNode = Available/ShareCount;
  4910. int Remaining = Available-PerNode*ShareCount;
  4911. int L = ri->L; int i=0; laRowNode* rn;
  4912. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4913. laUiItem* ui=rn->ui;
  4914. int NodeAdd, Node=rn->GotW;
  4915. if(rn->UseLast){
  4916. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4917. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4918. continue;
  4919. }
  4920. if(Available>=0){
  4921. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4922. NodeAdd+=(i<Remaining?1:0);i++;
  4923. }else{
  4924. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4925. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4926. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4927. }else{ Node=ri->UnitMinW;
  4928. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4929. }
  4930. }
  4931. ui->TL = L + rn->LP;
  4932. ui->TR = ui->TL + Node+NodeAdd;
  4933. ui->TB = ui->TU + rn->H;
  4934. L=ui->TR+rn->RP;
  4935. if (!rn->WaitAnimation){
  4936. ui->L = ui->TL; ui->R = ui->TR;
  4937. ui->U = ui->TU; ui->B = ui->TB;
  4938. }
  4939. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4940. }
  4941. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ri->U:ri->MaxB;
  4942. while(rn=lstPopItem(&ri->Elements)){ FreeMem(rn); }
  4943. memset(ri, 0, sizeof(laRowInfo));
  4944. }
  4945. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4946. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4947. int sl,sr,su,sb;
  4948. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4949. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4950. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4951. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4952. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4953. if(pc==LA_PC_SOCKET_OUT){
  4954. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4955. }else{
  4956. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4957. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4958. }
  4959. }
  4960. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4961. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4962. }
  4963. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4964. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4965. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4966. laBoxedTheme *bt;
  4967. int Lowest = 0;
  4968. int HyperValue = 0;
  4969. int WaitAnimation;
  4970. int RowMode=0; laRowInfo ri={0};
  4971. laBoxedTheme* pt=*(ParentPanel->BT);
  4972. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4973. int MaxR=0;
  4974. if(!uil->Scale){uil->Scale=1;}
  4975. uil->SaveScale=MAIN.UiScale;
  4976. MAIN.UiScale*=uil->Scale;
  4977. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4978. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4979. WaitAnimation = 0;
  4980. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4981. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4982. for (ui = uil->UiItems.pFirst; ui;){
  4983. int SubB = 0;
  4984. int H;
  4985. WaitAnimation = 0;
  4986. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4987. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4988. //if (Fast && ui->C->B > B) {
  4989. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4990. // ui = ui->Item.pNext;
  4991. // continue;
  4992. //}
  4993. if (!ui->Instructions){
  4994. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4995. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4996. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4997. laOperatorProp *ap = ui->PP.LastPs->p;
  4998. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  4999. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  5000. }
  5001. }
  5002. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  5003. la_UsePropPack(&ui->PP, 0);
  5004. if (ui->CompoundPPs.pFirst){
  5005. for(laCompoundPP* CPP=ui->CompoundPPs.pFirst;CPP;CPP=CPP->Item.pNext){
  5006. la_StepPropPack(&CPP->PP); la_UsePropPack(&CPP->PP, 0);
  5007. }
  5008. }
  5009. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5010. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  5011. // 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);
  5012. //}
  5013. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  5014. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  5015. WaitAnimation = 1;
  5016. }
  5017. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  5018. bt = (*ui->Type->Theme);
  5019. if (ui->Type == &_LA_UI_CONDITION){
  5020. laConditionUiExtraData *cued = ui->Extra;
  5021. la_StepExpression(cued->Expression);
  5022. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5023. if (!cued->IsTrue){
  5024. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5025. }else{
  5026. ui = ui->Item.pNext;
  5027. }
  5028. continue;
  5029. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5030. ui = ui->Item.pNext;
  5031. continue;
  5032. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5033. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5034. if (cued->IsTrue) ui = cued->EndUi;
  5035. else
  5036. ui = ui->Item.pNext;
  5037. continue;
  5038. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5039. laConditionUiExtraData *cued = ui->Extra;
  5040. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  5041. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  5042. if (!WaitAnimation){
  5043. ui->L = ui->TL; ui->R = ui->TR;
  5044. ui->U = ui->TU; ui->B = ui->TB;
  5045. }
  5046. if(!RowMode){
  5047. la_CalcUiItemInfluence(&uil->Columns, ui);
  5048. }else{
  5049. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5050. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5051. }
  5052. if (ui->State == LA_UI_NORMAL){
  5053. cued->IsTrue = 0;
  5054. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  5055. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  5056. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5057. }else{
  5058. cued->IsTrue = 1;
  5059. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  5060. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  5061. //}
  5062. ui = ui->Item.pNext;
  5063. }
  5064. continue;
  5065. }
  5066. if (ui->Type == _LA_UI_ALIGN){
  5067. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH/5;
  5068. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5069. if (ui->TB > Lowest) Lowest = ui->TB;
  5070. if (!WaitAnimation){
  5071. ui->L = ui->TL; ui->R = ui->TR;
  5072. ui->U = ui->TU; ui->B = ui->TB;
  5073. }
  5074. if(!RowMode){
  5075. la_CalcUiItemInfluence(&uil->Columns, ui);
  5076. }else{
  5077. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  5078. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5079. la_AddRowNode(&ri, ui, bt, H*LA_RH,WaitAnimation);
  5080. }
  5081. ui = ui->Item.pNext; continue;
  5082. }
  5083. if (ui->Type == &_LA_UI_ROW_BEGIN){
  5084. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  5085. la_InitRowNode(&ri, ui, bt);
  5086. RowMode=1; ui=ui->Item.pNext; continue;
  5087. }
  5088. if (ui->Type == &_LA_UI_ROW_END){
  5089. la_CalculateRowExpand(&ri, ui);
  5090. la_CalcUiItemInfluence(&uil->Columns, ui);
  5091. RowMode=0; ui=ui->Item.pNext; continue;
  5092. }
  5093. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  5094. int GB=0;
  5095. 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; }
  5096. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  5097. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  5098. if (H < 0){
  5099. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  5100. else{ H=LA_RH; }
  5101. }
  5102. else H *= LA_RH;
  5103. ui->TB = ui->TU;
  5104. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5105. 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
  5106. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  5107. if (ui->Type == _LA_UI_COLLECTION){
  5108. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  5109. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5110. ui->PP.EndInstance = TInstance;
  5111. laUiList *iuil = ui->Subs.pFirst;
  5112. laUiList *puil = iuil;
  5113. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  5114. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  5115. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5116. int Begin = ui->TB;
  5117. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  5118. int ElementB = ui->TU;
  5119. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  5120. int MaxB = ElementB;
  5121. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5122. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  5123. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  5124. if (!ElementLimit) RowPriority = 0;
  5125. if (!TInstance){
  5126. while (iuil){
  5127. puil = iuil->Item.pNext;
  5128. la_DestroyTabPage(ui, iuil, 0);
  5129. iuil = puil;
  5130. }
  5131. }
  5132. while (TInstance){
  5133. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  5134. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5135. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5136. ui->PP.EndInstance = TInstance; continue;
  5137. }
  5138. if(CanGetTheme){
  5139. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5140. la_SwitchThemeQuick(t, OriginalTheme);
  5141. }
  5142. if(CanGetGap){
  5143. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  5144. Gap=g*LA_RH;
  5145. }else Gap=0;
  5146. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  5147. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  5148. }else GotCategory=0;
  5149. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  5150. if (RowPriority){
  5151. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  5152. }
  5153. }
  5154. FirstIn=0;
  5155. if (ElementLimit){
  5156. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  5157. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  5158. }
  5159. while (iuil && iuil->Instance != TInstance){
  5160. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  5161. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  5162. }else{
  5163. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  5164. }
  5165. iuil = puil;
  5166. }
  5167. if(!iuil){
  5168. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  5169. }
  5170. if (!iuil){
  5171. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  5172. la_CalcUiTopInfluence(&uil->Columns, ui);
  5173. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5174. 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);
  5175. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5176. iuil = ui->Page->Item.pNext;
  5177. }else{
  5178. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  5179. 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);
  5180. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  5181. la_CalcUiItemInfluence(&uil->Columns, ui);
  5182. iuil = iuil->Item.pNext;
  5183. }
  5184. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  5185. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  5186. ui->PP.EndInstance = TInstance;
  5187. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5188. if (RowPriority){
  5189. Col += 1;
  5190. if (Col >= ElementLimit){
  5191. Col = 0;
  5192. Row += 1;
  5193. Begin = ElementB + bt->TM;
  5194. }
  5195. }elif(Spread){
  5196. EL+=Spread*LA_RH;
  5197. ER+=Spread*LA_RH;
  5198. }else{
  5199. Row += 1;
  5200. Begin = ElementB + bt->TM;
  5201. if (ElementLimit && Row >= ElementLimit){
  5202. Row = 0;
  5203. Col += 1;
  5204. Begin = ui->TU + bt->TM;
  5205. }
  5206. }
  5207. ui->TB = ElementB;
  5208. MaxB = MaxB < ElementB ? ElementB : MaxB;
  5209. }
  5210. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  5211. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  5212. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  5213. ui->TB = MaxB;
  5214. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  5215. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  5216. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  5217. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  5218. ui->TB=ui->TU+LA_RH;
  5219. }else{
  5220. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5221. ui->PP.EndInstance = TInstance;
  5222. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  5223. if(!Template) Template=laui_SubPropInfoDefault;
  5224. //ui->Template = Template;
  5225. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  5226. if (!ui->Subs.pFirst && TInstance){
  5227. la_AddInstancePage(ui, TInstance, 0);
  5228. la_CalcUiTopInfluence(&uil->Columns, ui);
  5229. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5230. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  5231. ui->TB = SubB + (NoDecal?0:bt->BM);
  5232. }else if (ui->Subs.pFirst){
  5233. if (!TInstance || TInstance != ui->Page->Instance){
  5234. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  5235. ui->Page = 0;
  5236. if (TInstance){
  5237. la_AddInstancePage(ui, TInstance, 0);
  5238. la_CalcUiTopInfluence(&uil->Columns, ui);
  5239. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  5240. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM)-EraseWidth, B, Fast, ParentPanel);
  5241. ui->TB = SubB + (NoDecal?0:bt->TM);
  5242. }else
  5243. ui->TB = ui->TU + LA_RH + bt->BM;
  5244. }else{
  5245. 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);
  5246. ui->TB = SubB + (NoDecal?0:bt->BM);
  5247. }
  5248. }
  5249. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  5250. ui->TB=ui->TU+LA_RH;
  5251. }
  5252. }
  5253. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  5254. if (!WaitAnimation){
  5255. ui->L = ui->TL;
  5256. ui->R = ui->TR;
  5257. ui->U = ui->TU;
  5258. ui->B = ui->TB;
  5259. }
  5260. }
  5261. }else{
  5262. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5263. if (ui->Type != _LA_UI_CANVAS){
  5264. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  5265. la_CalcUiTopInfluence(&uil->Columns, ui); int first_in=((ui->Flags&LA_UI_FLAGS_PREFER_BOTTOM) && ui->Page->B==0);
  5266. SubB = la_UpdateUiListRecursive(ui->Page,
  5267. 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);
  5268. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  5269. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT)+(ui->Page->HeightCoeff==-2?_PB:0) : SubB)) + (NoDecal?0:bt->BM);
  5270. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  5271. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  5272. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  5273. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  5274. }
  5275. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  5276. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  5277. if((GB && ui->TB >= GB)||first_in){ ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  5278. if(ui->Page->HeightCoeff){
  5279. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  5280. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  5281. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  5282. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  5283. }
  5284. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  5285. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  5286. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  5287. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  5288. }
  5289. }
  5290. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  5291. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  5292. }else{
  5293. laUiList *suil;
  5294. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  5295. la_CalcUiTopInfluence(&uil->Columns, ui);
  5296. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5297. 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);
  5298. }
  5299. }
  5300. ui->TB = ui->TU + H;
  5301. }
  5302. }else ui->TB = ui->TU + H;
  5303. }
  5304. if (ui->TB > Lowest && (!NoHeight)) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  5305. if(!RowMode){
  5306. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  5307. }else{
  5308. la_AddRowNode(&ri, ui, bt, H, WaitAnimation);
  5309. }
  5310. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  5311. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  5312. ui = ui->Item.pNext;
  5313. }
  5314. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  5315. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  5316. else uil->TB = Lowest;
  5317. if (!WaitAnimation){
  5318. uil->L = uil->TL;
  5319. uil->R = uil->TR;
  5320. uil->U = uil->TU;
  5321. uil->B = uil->TB;
  5322. }
  5323. MAIN.UiScale=uil->SaveScale;
  5324. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5325. return uil->TB;
  5326. }
  5327. int la_AnimateSingleUiSize(int To, int *Now){
  5328. int Delta;
  5329. if (To != *Now){
  5330. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  5331. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  5332. *Now += Delta;
  5333. return 1;
  5334. }else
  5335. return 0;
  5336. }
  5337. int la_AnimateUiListRecursive(laUiList *uil){
  5338. laUiItem *ui;
  5339. int Again = 0;
  5340. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  5341. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  5342. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  5343. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  5344. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  5345. la_AnimateSingleUiSize(ui->TR, &ui->R));
  5346. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5347. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  5348. laUiList *suil;
  5349. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  5350. Again += la_AnimateUiListRecursive(suil);
  5351. }
  5352. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  5353. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  5354. Again += la_AnimateUiListRecursive(ui->Page);
  5355. }
  5356. }
  5357. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  5358. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  5359. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  5360. la_AnimateSingleUiSize(uil->TR, &uil->R));
  5361. return Again;
  5362. }
  5363. int la_DrawUiItem(laUiItem *ui){
  5364. tnsUseNoTexture();
  5365. tnsColor4d(1, 1, 1, 1);
  5366. tnsVertex2d(ui->L, ui->U);
  5367. tnsVertex2d(ui->R, ui->U);
  5368. tnsVertex2d(ui->R, ui->B);
  5369. tnsVertex2d(ui->L, ui->B);
  5370. tnsPackAs(GL_LINE_LOOP);
  5371. }
  5372. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  5373. tnsUseNoTexture();
  5374. tnsColor4d(1, 1, 1, 1);
  5375. tnsVertex2d(ui->L - 1, ui->U - 1);
  5376. tnsVertex2d(ui->R + 1, ui->U - 1);
  5377. tnsVertex2d(ui->R + 1, ui->B + 1);
  5378. tnsVertex2d(ui->L - 1, ui->B + 1);
  5379. tnsPackAs(GL_LINE_LOOP);
  5380. }
  5381. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  5382. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  5383. return 1;
  5384. }
  5385. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  5386. laUiListDrawItem *uildi = uild->Items.pFirst;
  5387. laUiList *Target = uildi->Target;
  5388. int L, R, U, B;
  5389. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  5390. L = Target->L + Target->PanX + uildi->DifX;
  5391. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5392. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5393. U = Target->U + Target->PanY + uildi->DifY;
  5394. return la_UiInBound(ui, L, R, U, B);
  5395. }
  5396. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  5397. laUiListDrawItem *uildi = uild->Items.pFirst;
  5398. laUiList *Target = uildi->Target;
  5399. int L, R, U, B;
  5400. if (Target){
  5401. L = Target->L + Target->PanX + uildi->DifX;
  5402. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  5403. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  5404. U = Target->U + Target->PanY + uildi->DifY;
  5405. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  5406. return 1;
  5407. }else{
  5408. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  5409. return 1;
  5410. }
  5411. }
  5412. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  5413. laUiItem *ui = uil->UiItems.pFirst;
  5414. while (!strGetArgument(ui->Instructions, mark))
  5415. ui = ui->Item.pNext;
  5416. return ui;
  5417. }
  5418. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  5419. laUiList *uil;
  5420. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  5421. if (uil->Instance == Instance) return uil;
  5422. }
  5423. return uil;
  5424. }
  5425. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  5426. int mx=(L+R)/2; int my=(U+B)/2;
  5427. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  5428. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  5429. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  5430. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  5431. tnsFlush();
  5432. }
  5433. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  5434. if(!uil->ScrollerShownV) return;
  5435. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  5436. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  5437. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  5438. int U = uil->U + Offset;
  5439. int B = U + Len;
  5440. int L = UiR - RM*2 - W;
  5441. int R = L + W;
  5442. if (B > U + DisplayH) B = U + DisplayH;
  5443. if (U < uil->U) U = uil->U;
  5444. if (B <= uil->U || U >= uil->B) return;
  5445. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  5446. if (U < uil->U) U = uil->U;
  5447. tnsUseNoTexture();
  5448. laBoxedTheme* bt=_LA_THEME_PANEL;
  5449. real* color=laThemeColor(bt, LA_BT_TEXT);
  5450. tnsColor4d(LA_COLOR3(color), 0.2);
  5451. tnsVertex2d(R-RM, uil->U);
  5452. tnsVertex2d(L+RM, uil->U);
  5453. tnsVertex2d(L+RM, uil->U + DisplayH);
  5454. tnsVertex2d(R-RM, uil->U + DisplayH);
  5455. tnsPackAs(GL_TRIANGLE_FAN);
  5456. tnsColor4d(LA_COLOR3(color), 0.5);
  5457. tnsVertex2d(R-RM, uil->U);
  5458. tnsVertex2d(L+RM, uil->U);
  5459. tnsVertex2d(L+RM, uil->U + DisplayH);
  5460. tnsVertex2d(R-RM, uil->U + DisplayH);
  5461. tnsPackAs(GL_LINE_LOOP);
  5462. tnsColor4d(LA_COLOR3(color), 1);
  5463. tnsVertex2d(R, U);
  5464. tnsVertex2d(L, U);
  5465. tnsVertex2d(L, B);
  5466. tnsVertex2d(R, B);
  5467. tnsPackAs(GL_TRIANGLE_FAN);
  5468. int HU=(U+B)/2+LA_RH2;
  5469. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5470. tnsFlush();
  5471. }
  5472. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  5473. if(!uil->ScrollerShownH) return;
  5474. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  5475. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  5476. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  5477. int L = uil->L + Offset;
  5478. int R = L + Len;
  5479. int U = UiB - RM - W;
  5480. int B = U + W;
  5481. if (B > U + DisplayW) B = U + DisplayW;
  5482. if (U < uil->U) U = uil->U;
  5483. if (R <= uil->L || L >= uil->R) return;
  5484. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  5485. if (L < uil->L) L = uil->L;
  5486. tnsUseNoTexture();
  5487. laBoxedTheme* bt=_LA_THEME_PANEL;
  5488. real* color=laThemeColor(bt, LA_BT_TEXT);
  5489. tnsColor4d(LA_COLOR3(color), 0.2);
  5490. tnsVertex2d(uil->L,U+RM);
  5491. tnsVertex2d(uil->L,B-RM);
  5492. tnsVertex2d(uil->L + DisplayW,B-RM);
  5493. tnsVertex2d(uil->L + DisplayW,U+RM);
  5494. tnsPackAs(GL_TRIANGLE_FAN);
  5495. tnsColor4d(LA_COLOR3(color), 0.5);
  5496. tnsVertex2d(uil->L,U+RM);
  5497. tnsVertex2d(uil->L,B-RM);
  5498. tnsVertex2d(uil->L + DisplayW,B-RM);
  5499. tnsVertex2d(uil->L + DisplayW,U+RM);
  5500. tnsPackAs(GL_LINE_LOOP);
  5501. tnsColor4d(LA_COLOR3(color), 1);
  5502. tnsVertex2d(R, U);
  5503. tnsVertex2d(L, U);
  5504. tnsVertex2d(L, B);
  5505. tnsVertex2d(R, B);
  5506. tnsPackAs(GL_TRIANGLE_FAN);
  5507. int HU=(U+B)/2+LA_RH2;
  5508. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  5509. tnsFlush();
  5510. }
  5511. void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  5512. tnsUseNoTexture();
  5513. tnsColor4dv(color);
  5514. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  5515. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  5516. tnsPackAs(GL_TRIANGLE_FAN);
  5517. }
  5518. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  5519. laSocketRecord* sr;
  5520. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  5521. uild->WiresContainer=container;
  5522. }
  5523. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  5524. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  5525. if(lip->Target==uild->WiresContainer) break;
  5526. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  5527. }
  5528. }
  5529. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  5530. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5531. int PanX, PanY;
  5532. if(pc==LA_PC_SOCKET_OUT){
  5533. laNodeOutSocket* s=ui->PP.EndInstance;
  5534. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  5535. }else{
  5536. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  5537. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  5538. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  5539. }
  5540. }
  5541. void la_RegenerateWireColors(){
  5542. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  5543. laTheme* t=MAIN.CurrentTheme;
  5544. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  5545. real hsl[]={0.0,0.8,0.6}; hsl[1]=t->WireSaturation; hsl[2]=t->WireBrightness;
  5546. for(int i=0;i<MAIN.WireColorSlices;i++){
  5547. hsl[0]=(real)i/(real)MAIN.WireColorSlices;
  5548. tnsHSL2RGB(hsl, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  5549. }
  5550. }
  5551. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  5552. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  5553. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  5554. tnsInterpolate2dv(v1,v2,0.5,vi);
  5555. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=dist*MAIN.WireSaggyness; }
  5556. tnsVectorMinus2d(v1s,vi,v1); if(tnsLength2d(v1s)<1e-3){ v1s[0]=-1; v1s[1]=0; }else{ tnsNormalizeSelf2d(v1s); } tnsVectorMultiSelf2d(v1s,circle_r);
  5557. tnsVectorMinus2d(v2s,vi,v2); if(tnsLength2d(v2s)<1e-3){ v2s[0]=1; v2s[1]=0; }else{ tnsNormalizeSelf2d(v2s); } tnsVectorMultiSelf2d(v2s,circle_r);
  5558. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  5559. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  5560. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  5561. tnsVertex2d(v1[0],v1[1]);
  5562. for(int i=1;i<=steps;i++){
  5563. real ratio=i==steps?1.0f:step*i;
  5564. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  5565. tnsVertex2d(v1s[0],v1s[1]);
  5566. }
  5567. }
  5568. void la_DrawNodeWires(laUiListDraw* uild){
  5569. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  5570. laBoxedTheme* bt=_LA_THEME_SOCKET;
  5571. tnsUseNoTexture();
  5572. #define _RSLICES 16
  5573. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  5574. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5575. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5576. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5577. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5578. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5579. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5580. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5581. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5582. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5583. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5584. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5585. }
  5586. if(MAIN.tNodeIn->Source){
  5587. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5588. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5589. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5590. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5591. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  5592. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5593. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5594. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  5595. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  5596. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  5597. }
  5598. #undef _RSLICES
  5599. tnsFlush();
  5600. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  5601. glLineWidth(ww);
  5602. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  5603. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  5604. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  5605. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  5606. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  5607. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5608. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5609. }
  5610. if(MAIN.tNodeIn->Source){
  5611. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  5612. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  5613. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  5614. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  5615. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  5616. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  5617. }
  5618. tnsFlush();
  5619. glLineWidth(1);
  5620. la_InitSocketRecord(uild,0);
  5621. }
  5622. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  5623. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  5624. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  5625. }
  5626. 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){
  5627. laUiItem *ui;
  5628. laBoxedTheme *bt;
  5629. laUiList *sub;
  5630. laUiListDrawItem *uildi;
  5631. int Ret = 0;
  5632. if (!uil) return 0;
  5633. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  5634. ui = uil->UiItems.pFirst;
  5635. if(uil->PanY<0){uil->PanY=0;}
  5636. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  5637. uil->SaveScale=MAIN.UiScale;
  5638. MAIN.UiScale*=uil->Scale;
  5639. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5640. for (; ui;){ if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  5641. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5642. if (ui->Type == &_LA_UI_CONDITION){
  5643. laConditionUiExtraData *cued = ui->Extra;
  5644. la_StepExpression(cued->Expression);
  5645. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5646. if (!cued->IsTrue){
  5647. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5648. }else{
  5649. ui = ui->Item.pNext;
  5650. }
  5651. continue;
  5652. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5653. ui = ui->Item.pNext;
  5654. continue;
  5655. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5656. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5657. if (cued->IsTrue) ui = cued->EndUi;
  5658. else
  5659. ui = ui->Item.pNext;
  5660. continue;
  5661. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5662. laConditionUiExtraData *cued = ui->Extra;
  5663. ui->Type->Draw(ui, LA_RH);
  5664. if (ui->State == LA_UI_NORMAL){
  5665. cued->IsTrue = 0;
  5666. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5667. }else{
  5668. cued->IsTrue = 1;
  5669. ui = ui->Item.pNext;
  5670. }
  5671. continue;
  5672. }
  5673. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  5674. int NeedDraw=0;
  5675. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  5676. if(NeedDraw){
  5677. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  5678. }else{ ui->Type->Draw(ui, LA_RH); }
  5679. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  5680. tnsFlush();
  5681. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  5682. tnsResetViewMatrix();
  5683. }
  5684. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  5685. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  5686. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  5687. tnsFlush();
  5688. }
  5689. }
  5690. if(NeedDraw || RegisterNodes){
  5691. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  5692. if (ui->Type == _LA_UI_FIXED_GROUP ||
  5693. ui->Type == _LA_UI_TAB ||
  5694. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  5695. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  5696. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  5697. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5698. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  5699. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  5700. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  5701. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  5702. 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); }
  5703. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  5704. 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);
  5705. 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)); }
  5706. }elif (ui->Type == _LA_UI_COLLECTION){
  5707. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  5708. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  5709. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  5710. void* SaveInstance = ui->PP.EndInstance;
  5711. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5712. int State;
  5713. ui->PP.EndInstance = sub->Instance;
  5714. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  5715. if(NeedDraw){ int drawn=0;
  5716. if (!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && sub->Instance == Active){
  5717. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP); drawn=1;
  5718. }
  5719. if (CanGetState && !drawn){
  5720. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  5721. if(State >= 0){
  5722. la_DrawInstanceBkg(sub, laAccentColor(State),bt->LP,bt->RP);
  5723. }
  5724. }
  5725. }
  5726. if(sub->TabName && sub->TabName->Ptr){
  5727. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  5728. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  5729. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  5730. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  5731. tnsFlush();
  5732. }
  5733. if(CanGetTheme){
  5734. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  5735. la_SwitchThemeQuick(t, OriginalTheme);
  5736. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  5737. }
  5738. tnsFlush();
  5739. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  5740. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  5741. }
  5742. //ui->PP.EndInstance = Active;
  5743. ui->PP.EndInstance = SaveInstance;
  5744. }elif (ui->Type == _LA_UI_CANVAS){
  5745. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5746. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5747. tnsFlush();
  5748. 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);
  5749. }
  5750. }
  5751. }
  5752. ui = ui->Item.pNext;
  5753. }else{
  5754. ui = ui->Item.pNext;
  5755. }
  5756. }
  5757. tnsFlush();
  5758. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  5759. la_RestoreLastUiListMatrix(uild, B - U);
  5760. MAIN.UiScale=uil->SaveScale;
  5761. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  5762. return Ret;
  5763. }
  5764. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  5765. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  5766. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  5767. tnsUseNoTexture();
  5768. tnsColor4d(1, 1, 1, 1);
  5769. tnsVertex2d(L, U);
  5770. tnsVertex2d(R, U);
  5771. tnsVertex2d(R, B);
  5772. tnsVertex2d(L, B);
  5773. tnsPackAs(GL_LINE_LOOP);
  5774. tnsVertex2d(L + 3, Begin);
  5775. tnsVertex2d(R - 3, Begin);
  5776. tnsVertex2d(R - 3, End);
  5777. tnsVertex2d(L + 3, End);
  5778. tnsPackAs(GL_LINE_LOOP);
  5779. }
  5780. int laIsInUiItem(laUiItem *ui, int x, int y){
  5781. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  5782. return 1;
  5783. }
  5784. int laIsInBound(int x, int y, int l, int r, int u, int b){
  5785. if (x < l || x > r || y < u || y > b) return 0;
  5786. return 1;
  5787. }
  5788. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  5789. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  5790. laUiItem *ui, *tui;
  5791. laBoxedTheme *bt;
  5792. laUiList *sub;
  5793. int CPB = 0;
  5794. if (!uil || (LimB && y > LimB)) return 0;
  5795. x += uil->PanX;
  5796. y += uil->PanY;
  5797. for (ui = uil->UiItems.pFirst; ui;){
  5798. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5799. if (ui->Type == &_LA_UI_CONDITION){
  5800. laConditionUiExtraData *cued = ui->Extra;
  5801. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  5802. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5803. if (!cued->IsTrue){
  5804. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5805. }else{
  5806. ui = ui->Item.pNext;
  5807. }
  5808. continue;
  5809. }else if (ui->Type == &_LA_UI_CONDITION_END){
  5810. ui = ui->Item.pNext;
  5811. continue;
  5812. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5813. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5814. if (cued->IsTrue) ui = cued->EndUi;
  5815. else
  5816. ui = ui->Item.pNext;
  5817. continue;
  5818. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5819. laConditionUiExtraData *cued = ui->Extra;
  5820. if (laIsInUiItem(ui, x, y)){
  5821. lstAppendPointer(LocalBuf, uil);
  5822. return ui;
  5823. }
  5824. if (ui->State == LA_UI_NORMAL){
  5825. cued->IsTrue = 0;
  5826. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5827. }else{
  5828. cued->IsTrue = 1;
  5829. ui = ui->Item.pNext;
  5830. }
  5831. continue;
  5832. }
  5833. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5834. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5835. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5836. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5837. if(!la_DetectSplit(ui->C, x)) Add=0;
  5838. }
  5839. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5840. }
  5841. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5842. if (ui->Page->HeightCoeff) CPB = ui->B;
  5843. else CPB = ui->Page->B;
  5844. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5845. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5846. lstAppendPointer(LocalBuf, uil);
  5847. return tui;
  5848. }
  5849. }else if (laIsInUiItem(ui, x, y)){
  5850. lstAppendPointer(LocalBuf, uil);return ui;
  5851. }
  5852. }
  5853. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5854. if (laIsInUiItem(ui, x, y)){
  5855. lstAppendPointer(LocalBuf, uil);
  5856. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5857. if(Deep){
  5858. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5859. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5860. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5861. lstAppendPointer(LocalBuf, iuil);
  5862. return tui;
  5863. }
  5864. }
  5865. }
  5866. }
  5867. return ui;
  5868. }
  5869. }
  5870. if (ui->Type == _LA_UI_CANVAS){
  5871. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5872. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5873. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5874. lstAppendPointer(LocalBuf, uil);
  5875. return tui;
  5876. }
  5877. }
  5878. }
  5879. if (laIsInUiItem(ui, x, y)){
  5880. lstAppendPointer(LocalBuf, uil);
  5881. return ui;
  5882. }
  5883. }
  5884. ui = ui->Item.pNext;
  5885. }
  5886. return 0;
  5887. }
  5888. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5889. laListHandle Locals={0};
  5890. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5891. while(lstPopPointer(&Locals));
  5892. //printf("%s\n", ui?ui->Type->Identifier:"?");
  5893. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5894. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5895. if(pc==PCInOrOut) return ui;
  5896. }
  5897. return 0;
  5898. }
  5899. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5900. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5901. laUiItem *ui = uil->UiItems.pFirst;
  5902. laBoxedTheme *bt;
  5903. laUiList *tuil;
  5904. laUiList *sub;
  5905. int CPB = 0;
  5906. x += uil->PanX;
  5907. y += uil->PanY;
  5908. if (y > LimH) return uil;
  5909. if ((uil->ScrollerShownV && laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B)) ||
  5910. (uil->ScrollerShownH && laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4))){
  5911. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5912. return uil;
  5913. }
  5914. for (ui = uil->UiItems.pFirst; ui;){
  5915. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5916. if (ui->Type == &_LA_UI_CONDITION){
  5917. laConditionUiExtraData *cued = ui->Extra;
  5918. //la_StepExpression(cued->Expression);
  5919. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5920. if (!cued->IsTrue){
  5921. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5922. }else{
  5923. ui = ui->Item.pNext;
  5924. }
  5925. continue;
  5926. }
  5927. if (ui->Type == &_LA_UI_CONDITION_END){
  5928. ui = ui->Item.pNext;
  5929. continue;
  5930. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5931. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5932. if (cued->IsTrue) ui = cued->EndUi;
  5933. else
  5934. ui = ui->Item.pNext;
  5935. continue;
  5936. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5937. laConditionUiExtraData *cued = ui->Extra;
  5938. if (ui->State == LA_UI_NORMAL){
  5939. cued->IsTrue = 0;
  5940. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5941. }else{
  5942. cued->IsTrue = 1;
  5943. ui = ui->Item.pNext;
  5944. }
  5945. continue;
  5946. }
  5947. if (InToContainerUI && ui != Exception){
  5948. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5949. if (ContainerParent) (*ContainerParent) = uil;
  5950. if (ParentUi) *ParentUi = ui;
  5951. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5952. //if (y > LimH) return uil;
  5953. 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))){
  5954. return tuil;
  5955. }
  5956. }
  5957. }
  5958. }
  5959. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5960. if (ui->Page->HeightCoeff) CPB = ui->B+ui->Page->PanY;
  5961. else CPB = ui->Page->B;
  5962. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5963. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5964. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5965. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5966. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5967. if (ParentUi) *ParentUi = ui;
  5968. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB+ui->Page->PanY, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5969. }
  5970. }
  5971. ui = ui->Item.pNext;
  5972. }
  5973. return uil;
  5974. }
  5975. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5976. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5977. laUiItem *ui = uil->UiItems.pFirst;
  5978. laBoxedTheme *bt;
  5979. laUiList *tuil;
  5980. laUiList *sub;
  5981. int CPB = 0;
  5982. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5983. x += uil->PanX;
  5984. y += uil->PanY;
  5985. if (y > LimH) return uil;
  5986. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5987. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5988. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5989. return uil;
  5990. }
  5991. for (ui = uil->UiItems.pFirst; ui;){
  5992. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5993. if (ui->Type == &_LA_UI_CONDITION){
  5994. laConditionUiExtraData *cued = ui->Extra;
  5995. //la_StepExpression(cued->Expression);
  5996. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5997. if (!cued->IsTrue){
  5998. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5999. }else{
  6000. ui = ui->Item.pNext;
  6001. }
  6002. continue;
  6003. }
  6004. if (ui->Type == &_LA_UI_CONDITION_END){
  6005. ui = ui->Item.pNext;
  6006. continue;
  6007. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  6008. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  6009. if (cued->IsTrue) ui = cued->EndUi;
  6010. else
  6011. ui = ui->Item.pNext;
  6012. continue;
  6013. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  6014. laConditionUiExtraData *cued = ui->Extra;
  6015. if (ui->State == LA_UI_NORMAL){
  6016. cued->IsTrue = 0;
  6017. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  6018. }else{
  6019. cued->IsTrue = 1;
  6020. ui = ui->Item.pNext;
  6021. }
  6022. continue;
  6023. }
  6024. if (InToContainerUI && ui != Exception){
  6025. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  6026. if (ContainerParent) (*ContainerParent) = uil;
  6027. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6028. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6029. //if (y > LimH) return uil;
  6030. 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))){
  6031. return tuil;
  6032. }
  6033. }
  6034. }
  6035. }
  6036. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6037. if (ui->Page->HeightCoeff) CPB = ui->B;
  6038. else CPB = ui->Page->B;
  6039. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  6040. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6041. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  6042. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6043. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6044. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6045. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6046. }
  6047. }
  6048. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  6049. if (ui->Page->HeightCoeff) CPB = ui->B;
  6050. else
  6051. CPB = ui->Page->B;
  6052. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  6053. if (ScrollUil) *ScrollUil = ui->Page;
  6054. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6055. }
  6056. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  6057. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  6058. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  6059. }
  6060. }
  6061. ui = ui->Item.pNext;
  6062. }
  6063. return uil;
  6064. }
  6065. int la_TestUiListMinumWidth(laUiList *uil){
  6066. laUiItem *ui, *tui;
  6067. laBoxedTheme *bt;
  6068. laUiList *sub;
  6069. int CPB = 0;
  6070. int W = 0;
  6071. int tW, sW, RowMode=0, rW;
  6072. void *Restore;
  6073. for (ui = uil->UiItems.pFirst; ui;){
  6074. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  6075. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  6076. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  6077. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6078. if (W < tW) W = tW;
  6079. }elif (ui->Type == _LA_UI_COLLECTION){
  6080. Restore = ui->PP.EndInstance;
  6081. tW = 0; sW = 0;
  6082. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  6083. ui->PP.EndInstance = sub->Instance;
  6084. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  6085. if (sW > tW) tW = sW;
  6086. }
  6087. ui->PP.EndInstance = Restore;
  6088. tW = (int)((float)tW / ui->C->PreWidth + 2);
  6089. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  6090. if (W < tW) W = tW;
  6091. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  6092. RowMode=1; rW=0;
  6093. }elif (ui->Type==&_LA_UI_ROW_END){
  6094. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  6095. }elif (ui->Type->GetMinWidth){
  6096. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  6097. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  6098. }
  6099. ui = ui->Item.pNext;
  6100. }
  6101. return W;
  6102. }
  6103. void la_InitLLVM(){
  6104. //LLVMLinkInMCJIT();
  6105. //LLVMInitializeNativeTarget();
  6106. //LLVMInitializeNativeAsmPrinter();
  6107. //LLVMInitializeNativeAsmParser();
  6108. // MAIN.llvmContext = LLVMGetGlobalContext();
  6109. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  6110. }
  6111. //==================================================================================================
  6112. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  6113. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  6114. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  6115. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  6116. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  6117. memFree(kmi);
  6118. }
  6119. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  6120. laKeyMapItem *kmi;
  6121. if (!km) return 0;
  6122. kmi = memAcquire(sizeof(laKeyMapItem));
  6123. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  6124. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  6125. }else{
  6126. strSafeSet(&kmi->Operation, Operation);
  6127. }
  6128. strSafeSet(&kmi->Instructions, ExtraInstructions);
  6129. kmi->SpecialKeyBits = SpecialKeyBits;
  6130. kmi->EventType = EventType;
  6131. kmi->Key = tolowerGuarded(Key);
  6132. kmi->SelectBase = SelectBase;
  6133. lstAppendItem(&km->Items, kmi);
  6134. return kmi;
  6135. }
  6136. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  6137. laKeyMapItem *kmi; int inv=0;
  6138. char *instructions;
  6139. if(e->type==LA_MOUSEMOVE) return 0;
  6140. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6141. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6142. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6143. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6144. if (kmi->Operation)
  6145. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6146. else
  6147. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6148. inv = 1;
  6149. }
  6150. }
  6151. return inv;
  6152. }
  6153. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  6154. laKeyMapItem *kmi;
  6155. char *instructions;
  6156. int inv = 0; int lx = -1, ly = -1;
  6157. if(e->type==LA_MOUSEMOVE) return 0;
  6158. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  6159. if ((kmi->SpecialKeyBits == e->SpecialKeyBit||kmi->EventType==LA_SIGNAL_EVENT) &&
  6160. kmi->EventType == e->type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  6161. if (e->Localized){
  6162. lx = e->x;
  6163. ly = e->y;
  6164. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  6165. e->Localized = 0;
  6166. }
  6167. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  6168. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  6169. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  6170. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  6171. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  6172. }elif (kmi->Operation){
  6173. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  6174. }else{
  6175. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  6176. }
  6177. inv = 1;
  6178. if (lx >= 0){
  6179. e->x = lx;
  6180. e->y = ly;
  6181. e->Localized = 1;
  6182. }
  6183. }
  6184. }
  6185. return inv;
  6186. }
  6187. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  6188. void la_DestroyOperatorType(laOperatorType* at){
  6189. //if(at->PC) la_FreePropertyContainer(at->PC);
  6190. memFree(at);
  6191. }
  6192. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  6193. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  6194. uint32_t IconID, int ExtraMark){
  6195. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  6196. at->Identifier = ID;
  6197. at->Name = Name;
  6198. at->Description = Description;
  6199. at->Check = Check;
  6200. at->Invoke = Invoke;
  6201. at->Init = Init;
  6202. at->Exit = Exit;
  6203. at->Modal = Modal;
  6204. at->IconID = IconID;
  6205. at->ExtraMark = ExtraMark;
  6206. at->ParseArgs = la_DefaultOperatorParser;
  6207. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  6208. return at;
  6209. }
  6210. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  6211. ot->PC = memAcquire(sizeof(laPropContainer));
  6212. ot->PC->Identifier = ot->Identifier;
  6213. ot->PC->Hyper = HyperLevel;
  6214. return ot->PC;
  6215. }
  6216. laOperator *la_CreateOperator(laOperatorType *at){
  6217. laOperator *a = CreateNew(laOperator);
  6218. a->Type = at;
  6219. if (at->PC && at->PC->Props.pFirst){
  6220. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  6221. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  6222. a->PP.LastPs->p->SubProp = at->PC;
  6223. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  6224. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  6225. a->PP.LastPs->Type = U'.';
  6226. }
  6227. return a;
  6228. }
  6229. int la_OperatorTypeByID(laOperatorType *a, char *id){
  6230. return (!strcmp(a->Identifier, id));
  6231. }
  6232. laOperatorType *laGetOperatorType(const char *ID){
  6233. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6234. }
  6235. int laOperatorExistsT(laOperatorType* at){
  6236. if (!at) return 0;
  6237. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  6238. return 0;
  6239. }
  6240. int laOperatorExists(const char* ID){
  6241. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  6242. return laOperatorExistsT(at);
  6243. }
  6244. int la_OperatorExists(laOperator *ac){
  6245. if (!ac) return 0;
  6246. laOperator *a;
  6247. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  6248. return 0;
  6249. }
  6250. int la_UiOperatorExists(void *inst){
  6251. laOperator *a;
  6252. if (!inst) return 0;
  6253. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  6254. if (((laUiItem *)a->Instance) == inst){
  6255. return 1;
  6256. }
  6257. }
  6258. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6259. if (a->Instance == inst){
  6260. return 1;
  6261. }
  6262. }
  6263. return 0;
  6264. }
  6265. int la_OperatorPending(laOperator *target){
  6266. laOperator *a;
  6267. if (!target) return 0;
  6268. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  6269. if (a == target){
  6270. return 1;
  6271. }
  6272. }
  6273. return 0;
  6274. }
  6275. void laSetOperatorLocalizer(void *ToPanel){
  6276. MAIN.ToPanel = ToPanel;
  6277. }
  6278. void la_DestroyConfirmData(laConfirmData **cd);
  6279. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  6280. laOperator *ai = (*a);
  6281. laOperator *ac = ((*a)->Child);
  6282. void *Ret = 0;
  6283. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using && !ac->ModalOver){
  6284. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  6285. }
  6286. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  6287. if ((*a)->PP.LastPs){
  6288. memFree((*a)->PP.LastPs->p);
  6289. memFree((*a)->PP.LastPs);
  6290. }
  6291. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  6292. la_SetPropMathcerContext((*a)->OperatorPanel);
  6293. MAIN.CurrentPanel = (*a)->OperatorPanel;
  6294. laDestroySinglePanel((*a)->OperatorPanel,0);
  6295. }
  6296. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  6297. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  6298. lstClearPointer(&(*a)->LocalUiLists);
  6299. if (Operators){
  6300. Ret = ai->Item.pNext;
  6301. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  6302. else
  6303. lstRemoveItem(Operators, *a);
  6304. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  6305. if (ai->Child == (*a)) ai->Child = 0;
  6306. }
  6307. }
  6308. strSafeDestroy(&(*a)->RuntimeHint);
  6309. free(*a);
  6310. return Ret;
  6311. }
  6312. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  6313. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6314. if (!at) return 0;
  6315. if (!at->Check) return 1;
  6316. return (at->Check(This, Instructions));
  6317. }
  6318. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  6319. if (!at) return 0;
  6320. if (!at->Check) return 1;
  6321. return (at->Check(This, Instructions));
  6322. }
  6323. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6324. laPropPack FakePP = {0};
  6325. laPropStep FakePs = {0};
  6326. if (!at) return 0;
  6327. if (!at->Check) return 1;
  6328. FakePP.LastPs = &FakePs;
  6329. FakePP.Go = FakePP.LastPs;
  6330. FakePP.LastPs->p = This->LastPs->p;
  6331. FakePP.LastPs->UseInstance = This->EndInstance;
  6332. FakePP.EndInstance = Real_FromInstance;
  6333. FakePP.LastIndex = This->LastIndex;
  6334. return (at->Check(&FakePP, Instructions));
  6335. }
  6336. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  6337. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6338. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  6339. }
  6340. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  6341. laOperator *a, *f = From;
  6342. int rev;
  6343. if (!f && e&&e->Localized) return -1;
  6344. a = la_CreateOperator(at);
  6345. a->ToPanel = MAIN.ToPanel;
  6346. a->This = This;
  6347. a->ExtraInstructions = args;
  6348. strMakeInstructions(&a->ExtraInstructionsP, args);
  6349. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6350. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6351. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  6352. la_DestroyOperator(&a, 0, 0);
  6353. return LA_CANCELED;
  6354. }
  6355. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6356. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  6357. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6358. e->Localized = 1;
  6359. }
  6360. if (e&&e->Localized){
  6361. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  6362. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6363. e->Localized = 0;
  6364. }else{
  6365. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  6366. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6367. }
  6368. }
  6369. if (From) f->Child = a;
  6370. a->Using = 1;
  6371. if (at->Init) at->Init(a);
  6372. rev = at->Invoke(a, e);
  6373. a->Using = 0;
  6374. if (rev & LA_FINISH){
  6375. a->StopNow = 1; if(From)From->Child=0;
  6376. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6377. }
  6378. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6379. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6380. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6381. a->State = rev;
  6382. a->PP.EndInstance = a->CustomData;
  6383. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  6384. }else
  6385. la_DestroyOperator(&a, 0, 0);
  6386. return rev;
  6387. }
  6388. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  6389. laOperatorType *at; laOperator *a, *f = From;
  6390. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  6391. if (!at) return -1;
  6392. return laInvokeP(From,at,e,This,args,args2);
  6393. }
  6394. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  6395. laOperator *a, *f = From;
  6396. int rev;
  6397. laPropPack *created;
  6398. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  6399. created = memAcquireSimple(sizeof(laPropPack));
  6400. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  6401. created->Go = created->LastPs;
  6402. created->LastPs->p = OrigionalThis->LastPs->p;
  6403. created->LastPs->UseInstance = OrigionalThis->LastPs->UseInstance;
  6404. created->EndInstance = FromInstance;
  6405. created->LastIndex = OrigionalThis->LastIndex;
  6406. a = la_CreateOperator(at);
  6407. a->ToPanel = MAIN.ToPanel;
  6408. a->This = created;
  6409. a->CreatedThis = created;
  6410. a->ExtraInstructions = args;
  6411. strMakeInstructions(&a->ExtraInstructionsP, args);
  6412. strMakeInstructions(&a->ExtraInstructionsP, args2);
  6413. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  6414. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  6415. la_DestroyOperator(&a, 0, 0);
  6416. return LA_CANCELED;
  6417. }
  6418. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  6419. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  6420. if (From) f->Child = a;
  6421. a->Using = 1;
  6422. if (at->Init) at->Init(a);
  6423. rev = at->Invoke(a, e);
  6424. a->Using = 0;
  6425. if (rev & LA_FINISH){
  6426. a->StopNow = 1; if(From)From->Child=0;
  6427. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  6428. }
  6429. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  6430. if(a->ModalOver){ lstPushItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6431. else{ lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a); }
  6432. a->State = rev;
  6433. a->PP.EndInstance = a->CustomData;
  6434. }else
  6435. la_DestroyOperator(&a, 0, 0);
  6436. return rev;
  6437. }
  6438. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6439. laOperator *a, *f = From;
  6440. int rev;
  6441. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  6442. a = la_CreateOperator(at);
  6443. a->Instance = inst;
  6444. a->ToPanel = MAIN.ToPanel;
  6445. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  6446. if (From) f->Child = a;
  6447. a->Using = 1;
  6448. if (at->Init) at->Init(a);
  6449. rev = at->Invoke(a, e);
  6450. a->Using = 0;
  6451. if (rev & LA_FINISH){
  6452. a->StopNow = 1; if(From)From->Child=0;
  6453. }
  6454. if (rev & LA_BLOCK){
  6455. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  6456. a->State = rev;
  6457. }else la_DestroyOperator(&a, 0, 0);
  6458. DEB = a;
  6459. return rev;
  6460. }
  6461. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  6462. laOperatorType *at;
  6463. laOperator *a, *f = From;
  6464. if (la_UiOperatorExists(inst)) return -1;
  6465. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  6466. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  6467. }
  6468. void laRequestDelayEvent(real Seconds){
  6469. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  6470. int la_UiStillInService(void *UiInstance){
  6471. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  6472. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  6473. if (ai->Instance == UiInstance) return 1;
  6474. }
  6475. return 0;
  6476. }
  6477. void la_StopUiOperatorService(void *UiInstance){
  6478. laOperator *ai, *dai, *NextAi;
  6479. if (!MAIN.CurrentWindow) return;
  6480. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6481. NextAi = ai->Item.pNext;
  6482. if (ai->Instance == UiInstance){
  6483. if (ai->Child){
  6484. la_StopUiOperatorService(ai->Child->Instance);
  6485. ai->Child = 0;
  6486. }
  6487. laOperator *dai = ai;
  6488. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  6489. continue;
  6490. }
  6491. }
  6492. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6493. NextAi = ai->Item.pNext;
  6494. if (ai->Instance == UiInstance){
  6495. if (ai->Instance == ai->ToPanel){
  6496. //laHidePanelWithDissoveEffect(ai->ToPanel);
  6497. //ai->ToPanel->LaterDestroy = 1;
  6498. }
  6499. if (ai->Child && la_OperatorExists(ai->Child)){
  6500. la_StopUiOperatorService(ai->Child->Instance);
  6501. //ai->Child = 0;
  6502. }
  6503. if (!ai->Using){
  6504. laOperator *dai = ai;
  6505. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6506. }else
  6507. ai->StopNow = 1;
  6508. }
  6509. }
  6510. }
  6511. void la_StopAllOperators(){
  6512. laOperator *ai, *dai, *NextAi;
  6513. if (!MAIN.CurrentWindow) return;
  6514. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  6515. NextAi = ai->Item.pNext;
  6516. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  6517. continue;
  6518. }
  6519. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  6520. NextAi = ai->Item.pNext;
  6521. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  6522. laHidePanelWithDissoveEffect(ai->ToPanel);
  6523. ai->ToPanel->LaterDestroy = 1;
  6524. }
  6525. if (!ai->Using){
  6526. laOperator *dai = ai;
  6527. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  6528. }else ai->StopNow = 1;
  6529. }
  6530. }
  6531. void la_DestroyConfirmData(laConfirmData **cd){
  6532. if((!cd)||!(*cd)) return;
  6533. if ((*cd)->CustomData && (*cd)->Destroy) (*cd)->Destroy((*cd)->CustomData);
  6534. if ((*cd)->StrData) free((*cd)->StrData);
  6535. FreeMem((*cd));
  6536. (*cd) = 0;
  6537. }
  6538. void laConfirmPointer(laOperator *a, void* Data,laPropContainer* PointerType, int mode){
  6539. laOperator *ai = a; laConfirmData *cd = CreateNew(laConfirmData);
  6540. cd->PointerData = Data; cd->Mode = mode; cd->PointerType=PointerType;
  6541. ai->NextConfirmData = cd; laRetriggerOperators();
  6542. }
  6543. void laConfirmInt(laOperator *a, int Data, int mode){
  6544. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6545. cd->IData = Data; cd->Mode = mode;
  6546. ai->NextConfirmData = cd; laRetriggerOperators();
  6547. }
  6548. void laConfirmFloat(laOperator *a, real Data, int mode){
  6549. laOperator *ai = a;laConfirmData *cd = CreateNew(laConfirmData);
  6550. cd->FData = Data; cd->Mode = mode;
  6551. ai->NextConfirmData = cd; laRetriggerOperators();
  6552. }
  6553. void laConfirmString(laOperator *a, char *Str, int mode){
  6554. laOperator *ai = a;
  6555. laConfirmData *cd = CreateNew(laConfirmData);
  6556. int len = strlen(Str);
  6557. char *buf = calloc(len + 1, sizeof(char));
  6558. strcpy(buf, Str);
  6559. cd->StrData = buf;
  6560. cd->Mode = mode;
  6561. cd->Destroy = free;
  6562. ai->NextConfirmData = cd;
  6563. laRetriggerOperators();
  6564. }
  6565. int laConfirmSameDataIfAny(laOperator *a){
  6566. laOperator *ai = a;
  6567. laConfirmData *cd;
  6568. char *buf = 0;
  6569. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  6570. cd = CreateNew(laConfirmData);
  6571. if (ai->ConfirmData->StrData){
  6572. int len = strlen(ai->ConfirmData->StrData);
  6573. buf = calloc(len + 1, sizeof(char));
  6574. strcpy(buf, ai->ConfirmData->StrData);
  6575. }
  6576. //cd->CustomData = cd->CustomData;
  6577. cd->IData = ai->ConfirmData->IData;
  6578. cd->FData = ai->ConfirmData->FData;
  6579. cd->PointerData = ai->ConfirmData->PointerData;
  6580. cd->PointerType = a->ConfirmData->PointerType;
  6581. cd->StrData = buf;
  6582. cd->Mode = ai->ConfirmData->Mode;
  6583. cd->Destroy = ai->ConfirmData->Destroy;
  6584. ai->NextConfirmData = cd;
  6585. laRetriggerOperators();
  6586. return 1;
  6587. }
  6588. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  6589. laOperator *ai = a;
  6590. laConfirmData *cd = CreateNew(laConfirmData);
  6591. cd->CustomData = UserData;
  6592. cd->Mode = mode;
  6593. cd->Destroy = Destroy;
  6594. ai->NextConfirmData = cd;
  6595. laRetriggerOperators();
  6596. }
  6597. int laGetConfirmMode(laOperator *a){
  6598. return ((laOperator *)a)->ConfirmData->Mode;
  6599. }
  6600. int laGetConfirmInt(laOperator *a){
  6601. laOperator *ai = a;
  6602. int rev = ai->ConfirmData->IData;
  6603. la_DestroyConfirmData(&ai->ConfirmData);
  6604. ai->ConfirmData = 0;
  6605. return rev;
  6606. }
  6607. real laGetConfirmFloat(laOperator *a){
  6608. laOperator *ai = a;
  6609. real rev = ai->ConfirmData->FData;
  6610. la_DestroyConfirmData(&ai->ConfirmData);
  6611. ai->ConfirmData = 0;
  6612. return rev;
  6613. }
  6614. void laGetConfirmString(laOperator *a, char *buf){
  6615. laOperator *ai = a;
  6616. strcpy(buf, ai->ConfirmData->StrData);
  6617. la_DestroyConfirmData(&ai->ConfirmData);
  6618. ai->ConfirmData = 0;
  6619. }
  6620. void *laGetConfirmUserData(laOperator *a){
  6621. laOperator *ai = a;
  6622. return ai->ConfirmData->CustomData;
  6623. }
  6624. void laFinalizeOperators(){
  6625. laOperatorType *at;
  6626. laListHandle *lst;
  6627. int i;
  6628. for (i = 0; i < 256; i++){
  6629. lst = &MAIN.OperatorTypeHash.Entries[i];
  6630. for (at = lst->pFirst; at; at = at->Item.pNext){
  6631. if (at->PC && at->PC->Props.pFirst){
  6632. lstAppendItem(&MAIN.PropContainers, at->PC);
  6633. }
  6634. }
  6635. }
  6636. }
  6637. //=================
  6638. #ifdef LA_LINUX
  6639. static void la_RecordWacomMotions(XIRawEvent *event)
  6640. {
  6641. double *valuator = event->valuators.values;
  6642. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  6643. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  6644. //SYSWINDOW root_return, child_return;
  6645. //int root_x_return, root_y_return;
  6646. //int win_x_return, win_y_return;
  6647. //unsigned int mask_return;
  6648. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  6649. // &root_x_return, &root_y_return,
  6650. // &win_x_return, &win_y_return,
  6651. // &mask_return);
  6652. //
  6653. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  6654. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  6655. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  6656. real x=valuator[3],y=valuator[4];
  6657. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  6658. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  6659. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  6660. }else{ MAIN.StylusDeviation=MAIN.StylusOrientation=MAIN.EraserDeviation=MAIN.EraserOrientation=0; }
  6661. if(XIMaskIsSet(event->valuators.mask, 5)){
  6662. real angle=valuator[5]; angle=rad((900-angle)/10*2-180); if(angle<0) angle+=TNS_PI*2; MAIN.StylusTwist=angle;
  6663. if(TNS_DOUBLE_CLOSE_ENOUGH(angle,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6664. }else{ MAIN.StylusTwist=TNS_PI; MAIN.StylusHasTwist=0; }
  6665. MAIN.IsPen=1;
  6666. }
  6667. #endif
  6668. #ifdef _WIN32
  6669. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  6670. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  6671. static uint32_t ch = 0; static int lead = 0;
  6672. static wchar_t buf[10] = { 0 }; int adv;
  6673. static DWORD LastMove = 0;
  6674. char mbuf[10] = { 0 }; uint32_t uchar=0;
  6675. short wheelmark = 0;
  6676. int WheelDir = 0;
  6677. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  6678. POINTER_PEN_INFO penInfo[128]; POINTER_TOUCH_INFO touchInfo; int peninfonum = 128;
  6679. POINT point;
  6680. PACKET pkt;
  6681. static POINT ptOld, ptNew;
  6682. static UINT prsOld, prsNew, vkey;
  6683. MOUSEMOVEPOINT mmp = { 0 }; POINT pt; static POINT ptLast={0};
  6684. MOUSEMOVEPOINT mmpBuf[64];
  6685. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  6686. switch (message) {
  6687. case WM_PAINT:
  6688. //SwapBuffers(GetDC(hwnd));
  6689. break;
  6690. case WM_MOUSEMOVE:
  6691. pt.x= LOWORD(lparam); pt.y = HIWORD(lparam);
  6692. ClientToScreen(hwnd, &pt);
  6693. mmp.x = pt.x; mmp.y = pt.y;
  6694. int numPoints = GetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &mmp, mmpBuf, 64, GMMP_USE_DISPLAY_POINTS);
  6695. int i;
  6696. for(i = 0; i < numPoints; i++){
  6697. if(mmpBuf[i].time < LastMove){ break; }
  6698. if(mmpBuf[i].time == LastMove && mmpBuf[i].x==ptLast.x && mmpBuf[i].y==ptLast.y){ break; }
  6699. }
  6700. while(i){
  6701. pt.x = mmpBuf[i].x; pt.y = mmpBuf[i].y; ptLast = pt;
  6702. if (!ScreenToClient(hwnd, &pt));
  6703. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, pt.x, pt.y);
  6704. i--;
  6705. }
  6706. //la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  6707. MAIN.IsPen = 0;
  6708. LastMove = GetMessageTime();
  6709. break;
  6710. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6711. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6712. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6713. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6714. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  6715. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  6716. case WM_MOUSEWHEEL:
  6717. POINT p; p.x=LOWORD(lparam); p.y=HIWORD(lparam); ScreenToClient(hwnd,&p);
  6718. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  6719. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  6720. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, p.x, p.y);
  6721. break;
  6722. case WT_PACKET:
  6723. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  6724. if (gpWTPacket((HCTX)lparam, wparam, &pkt)) {
  6725. MAIN.StylusPressure = (real)pkt.pkNormalPressure / MAIN.WinTabMaxPenPressure;
  6726. MAIN.StylusHover = (real)pkt.pkZ / MAIN.WinTabMaxHover;
  6727. real angle = (real)pkt.pkOrientation.orAzimuth / 3600 * TNS_PI * 2 + TNS_PI / 2;
  6728. MAIN.StylusOrientation = angle; MAIN.StylusDeviation = rad((90.0f - (real)pkt.pkOrientation.orAltitude / 10.0f));
  6729. real tw = (real)pkt.pkOrientation.orTwist; tw = rad(tw / 10);
  6730. MAIN.StylusTwist = tw;
  6731. if(TNS_DOUBLE_CLOSE_ENOUGH(tw,TNS_PI)){ MAIN.StylusHasTwist=0; }else{ MAIN.StylusHasTwist=1; }
  6732. MAIN.EraserDeviation = MAIN.StylusDeviation; MAIN.EraserOrientation = MAIN.StylusOrientation;
  6733. MAIN.EraserPressure = MAIN.StylusPressure;
  6734. MAIN.IsPen = 1; MAIN.PointerIsEraser = ((pkt.pkStatus & TPS_INVERT) == TPS_INVERT);
  6735. point.x = pkt.pkX; point.y = pkt.pkY; ScreenToClient(hwnd, &point);
  6736. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6737. }
  6738. return 0; break;
  6739. case WM_SYSCOMMAND:
  6740. switch (wparam) {
  6741. case SC_MAXIMIZE:
  6742. case SC_RESTORE:
  6743. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6744. break;
  6745. case SC_KEYMENU:
  6746. return 0;
  6747. case SC_MINIMIZE:
  6748. break;
  6749. }
  6750. break;
  6751. case WM_SIZE:
  6752. if (wparam == SIZE_MINIMIZED) break;
  6753. case WM_MOVE: /* And size */
  6754. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  6755. break;
  6756. case WM_SETCURSOR:
  6757. if(MAIN.CurrentCursor) return 1;
  6758. break;
  6759. case WM_POINTERDOWN:
  6760. case WM_POINTERUP:
  6761. case WM_POINTERUPDATE:
  6762. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  6763. pointerId = GET_POINTERID_WPARAM(wparam);
  6764. pointerType = PT_POINTER;
  6765. if(!GetPointerType(pointerId, &pointerType)){
  6766. pointerType = PT_POINTER;
  6767. }
  6768. if(pointerType == PT_PEN){
  6769. if(GetPointerPenInfoHistory(pointerId, &peninfonum, penInfo)){
  6770. for (int i = peninfonum-1; i>=0; i--) {
  6771. point.x = penInfo[i].pointerInfo.ptPixelLocation.x; point.y = penInfo[i].pointerInfo.ptPixelLocation.y;
  6772. ScreenToClient(hwnd, &point);
  6773. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo[i].pressure / 1024; MAIN.PointerIsEraser = 0;
  6774. switch (penInfo[i].pointerInfo.ButtonChangeType) {
  6775. case POINTER_CHANGE_FIRSTBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, point.x, point.y); break;
  6776. case POINTER_CHANGE_FIRSTBUTTON_UP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, point.x, point.y); break;
  6777. case POINTER_CHANGE_SECONDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, point.x, point.y); break;
  6778. case POINTER_CHANGE_SECONDBUTTON_UP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, point.x, point.y); break;
  6779. case POINTER_CHANGE_THIRDBUTTON_DOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, point.x, point.y); break;
  6780. case POINTER_CHANGE_THIRDBUTTON_UP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, point.x, point.y); break;
  6781. }
  6782. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, point.x, point.y);
  6783. }
  6784. }
  6785. SkipPointerFrameMessages(pointerId);
  6786. return 0;
  6787. }
  6788. else if (pointerType == PT_TOUCH){
  6789. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  6790. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  6791. ScreenToClient(hwnd, &point);
  6792. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  6793. }
  6794. }
  6795. break;
  6796. case WM_SYSKEYDOWN:
  6797. if (lparam & 0x40000000) break;
  6798. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  6799. break;
  6800. case WM_KEYDOWN:
  6801. if (lparam & 0x40000000) break;
  6802. vkey = wparam;
  6803. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(vkey));
  6804. break;
  6805. case WM_KEYUP:
  6806. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6807. break;
  6808. case WM_SYSKEYUP:
  6809. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  6810. break;
  6811. case WM_UNICHAR:
  6812. la_SendInputEvent(hwnd, wparam);
  6813. break;
  6814. case WM_IME_CHAR:
  6815. la_SendInputEvent(hwnd, wparam);
  6816. return 0;
  6817. case WM_CHAR:
  6818. la_SendInputEvent(hwnd, wparam);
  6819. break;
  6820. case WM_SHOWWINDOW:
  6821. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  6822. break;
  6823. case WM_CLOSE:
  6824. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  6825. break;
  6826. default:
  6827. return DefWindowProc(hwnd, message, wparam, lparam);
  6828. }
  6829. return DefWindowProc(hwnd, message, wparam, lparam);
  6830. }
  6831. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  6832. return DefWindowProc(hwnd, message, wparam, lparam);
  6833. }
  6834. #endif
  6835. int la_UpdateOperatorHints(laWindow* w){
  6836. laSafeString* ss=0;
  6837. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  6838. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  6839. }
  6840. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  6841. }else{
  6842. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  6843. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  6844. }
  6845. strSafeDestroy(&ss);
  6846. }
  6847. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  6848. laOperator *a, *NextA = 0;
  6849. int Result = 0;
  6850. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  6851. la_SendSignalsFromEvent(e);
  6852. if(MAIN.InputProcess){ MAIN.CurrentInputEvent=e; MAIN.InputProcess(e); MAIN.CurrentInputEvent=0; }
  6853. a = Operators->pFirst;
  6854. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  6855. while (1){
  6856. if (!a) break;
  6857. if (a->StopNow){
  6858. NextA = a->Item.pNext;
  6859. if (a->Type->Exit) a->Type->Exit(a, Result);
  6860. ConfirmData = a->NextConfirmData;
  6861. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6862. NextConfirmData = ConfirmData;
  6863. a->ConfirmData = 0;
  6864. a->NextConfirmData = 0;
  6865. la_DestroyOperator(&a, Operators, 0);
  6866. a = NextA;
  6867. if (a){
  6868. a->ConfirmData = NextConfirmData;
  6869. }
  6870. continue;
  6871. }
  6872. a->Using = 1;
  6873. la_SetPropMathcerContext(a->ToPanel);
  6874. laSetOperatorLocalizer(a->ToPanel);
  6875. MAIN.CurrentPanel = a->ToPanel;
  6876. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6877. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6878. e->Localized = 1;
  6879. }
  6880. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6881. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6882. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6883. e->Localized = 0;
  6884. }
  6885. la_SetPropMathcerContext(0);
  6886. laSetOperatorLocalizer(0);
  6887. MAIN.CurrentPanel = 0;
  6888. a->Using = 0;
  6889. if (Result & LA_PASS_ON){
  6890. laConfirmSameDataIfAny(a);
  6891. NextA = a->Item.pNext;
  6892. }else{
  6893. NextA = 0;
  6894. if (a->NextConfirmData){
  6895. la_DestroyConfirmData(&a->NextConfirmData);
  6896. }
  6897. }
  6898. ConfirmData = a->NextConfirmData;
  6899. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6900. NextConfirmData = ConfirmData;
  6901. a->ConfirmData = 0;
  6902. a->NextConfirmData = 0;
  6903. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6904. if (a->Type->Exit) a->Type->Exit(a, Result);
  6905. la_DestroyOperator(&a, Operators, 0);
  6906. int found=0;
  6907. for(laOperator*iop=Operators->pFirst;iop;iop=iop->Item.pNext){ if(iop==NextA){found=1;} }
  6908. if(!found){ NextA=0; }
  6909. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6910. }
  6911. a = NextA;
  6912. if (a){
  6913. a->ConfirmData = NextConfirmData;
  6914. }
  6915. }
  6916. return 1;
  6917. }
  6918. int la_HandleEvents(laWindow *w){
  6919. laEvent *e, *NextE;
  6920. laOperator *a;
  6921. laThreadNotifier *tn;
  6922. MAIN.CurrentWindow=w;
  6923. //laSpinLock(&MAIN.csNotifier);
  6924. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6925. //laSpinUnlock(&MAIN.csNotifier);
  6926. laNotifyUsers(tn->Path);
  6927. FreeMem(tn);
  6928. //if (MAIN.ThreadNotifiers.pFirst)
  6929. //laSpinLock(&MAIN.csNotifier);
  6930. }
  6931. //laSpinUnlock(&MAIN.csNotifier);
  6932. while (1){
  6933. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6934. while (w->EventList.pFirst){
  6935. while (w->PendingOperators.pLast){
  6936. a = w->PendingOperators.pLast;
  6937. if (a->OperatorPanel){
  6938. laSetOperatorLocalizer(a->OperatorPanel);
  6939. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6940. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6941. }
  6942. lstRemoveItem(&w->PendingOperators, a);
  6943. lstPushItem(&w->Operators, a);
  6944. }
  6945. e = lstPopItem(&w->EventList);
  6946. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6947. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6948. memFree(e);
  6949. }
  6950. MAIN.ControllerHasNewAxis = MAIN.ControllerHasNewKey = 0;
  6951. if (!MAIN.ReTriggerOperators) break;
  6952. }
  6953. la_UpdateOperatorHints(w);
  6954. return 1;
  6955. }
  6956. int la_AllowInput(uint32_t ch){
  6957. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6958. return 0;
  6959. }
  6960. int laCopyToClipboard(unsigned char * text){
  6961. #ifdef LA_LINUX
  6962. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6963. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6964. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6965. strSafeSet(&MAIN.CopyPending, text);
  6966. #endif
  6967. }
  6968. int la_ProcessSysMessage(){
  6969. int SendDelay = 0, SendIdle = 0;
  6970. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6971. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6972. #ifdef LA_LINUX
  6973. XEvent e;
  6974. int type;
  6975. int InputCount = 0, CharCount=0;
  6976. KeySym InputKeysym = 0;
  6977. Status InputStatus = 0;
  6978. laWindow* wnd ;
  6979. while(XPending(MAIN.dpy)){
  6980. XGenericEventCookie *cookie = &e.xcookie;
  6981. XNextEvent(MAIN.dpy, &e);
  6982. if (XFilterEvent(&e, None)) continue;
  6983. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6984. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6985. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6986. XFreeEventData(MAIN.dpy, cookie); continue;
  6987. }
  6988. switch(e.type){
  6989. case ConfigureNotify:
  6990. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6991. break;
  6992. case Expose:
  6993. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6994. if(!wnd) break;
  6995. laRefreshWindow(wnd);
  6996. break;
  6997. case MotionNotify:
  6998. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6999. MAIN.IsPen=0;
  7000. break;
  7001. case ButtonPress:
  7002. type=LA_MOUSEDOWN;
  7003. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7004. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7005. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7006. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  7007. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  7008. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7009. MAIN.IsPen=0;
  7010. break;
  7011. case ButtonRelease:
  7012. type=LA_MOUSEUP;
  7013. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  7014. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  7015. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  7016. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  7017. MAIN.IsPen=0;
  7018. break;
  7019. case KeyPress:
  7020. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  7021. MAIN.InputBuf[InputCount]=0;
  7022. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  7023. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  7024. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  7025. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7026. XKeyboardState x; XGetKeyboardControl(MAIN.dpy, &x);
  7027. int numlock=0; if(x.led_mask & 2){ numlock=1; }
  7028. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7029. #ifdef DEBUG
  7030. printf("pressed KEY: %d\n", (int)InputKeysym);
  7031. #endif
  7032. if(/*numlock && */InputKeysym>=XK_KP_Space && InputKeysym<=XK_KP_9){
  7033. InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 1);
  7034. }
  7035. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  7036. }
  7037. break;
  7038. case KeyRelease:
  7039. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  7040. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  7041. }
  7042. case ClientMessage:
  7043. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  7044. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  7045. }
  7046. break;
  7047. case SelectionNotify:
  7048. if(e.xselection.selection != MAIN.bufid) continue;
  7049. if (e.xselection.property){
  7050. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  7051. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  7052. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  7053. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  7054. else if(result) {
  7055. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  7056. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  7057. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  7058. }
  7059. XFree(result);
  7060. return True;
  7061. }
  7062. case SelectionRequest:
  7063. if(!MAIN.CopyPending){ break; }
  7064. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  7065. if (e.xselectionrequest.selection != MAIN.selection) break;
  7066. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  7067. XSelectionEvent ev = {0};
  7068. int R = 0;
  7069. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  7070. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  7071. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  7072. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  7073. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  7074. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  7075. else if (ev.target == MAIN.UTF8)
  7076. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  7077. else ev.property = None;
  7078. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  7079. break;
  7080. case SelectionClear:
  7081. break;
  7082. default:
  7083. break;
  7084. }
  7085. }
  7086. #endif //linux
  7087. #ifdef _WIN32
  7088. MSG msg; int Processed = 0;
  7089. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  7090. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  7091. if (msg.wParam == VK_PROCESSKEY) {
  7092. msg.wParam = ImmGetVirtualKey(msg.hwnd);
  7093. }
  7094. TranslateMessage(&msg); DispatchMessage(&msg);
  7095. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  7096. };
  7097. if(!MAIN.Windows.pFirst){ return 0; }
  7098. #endif
  7099. #ifdef LAGUI_ANDROID
  7100. int pollResult = 0;
  7101. int pollEvents = 0;
  7102. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7103. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7104. // NOTE: Never close window, native activity is controlled by the system!
  7105. if (MAIN.app->destroyRequested != 0)
  7106. {
  7107. //CORE.Window.shouldClose = true;
  7108. //ANativeActivity_finish(MAIN.app->activity);
  7109. }
  7110. }
  7111. #endif
  7112. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7113. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  7114. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  7115. }
  7116. return 1;
  7117. };
  7118. void la_PrintOperatorStack(){
  7119. laWindow *w = MAIN.CurrentWindow;
  7120. laOperator *a;
  7121. printf("\n");
  7122. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  7123. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  7124. a->Type->Identifier, a->Instance,
  7125. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  7126. }
  7127. }
  7128. void la_DrawWindow(laWindow *w){
  7129. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  7130. MAIN.CurrentWindow = w;
  7131. la_WindowDefDraw(w, 0);
  7132. }
  7133. int laFinalize(){
  7134. if(!laValidateProperties()){ laShutoff(0); return 0; }
  7135. laUiTemplate* uit;
  7136. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  7137. return 1;
  7138. }
  7139. void la_PreFrame(){
  7140. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  7141. la_AnimationPreFrame();
  7142. if(MAIN.InitArgs.HasAudio) la_AudioPreFrame();
  7143. }
  7144. void la_PostFrame(){
  7145. laPanel* p; while(p=lstPopPointer(&MAIN.DeferredRedrawList)){ laRedrawPanel(p); }
  7146. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  7147. }
  7148. void laMainLoop(){
  7149. laWindow *w = MAIN.Windows.pFirst, *NextW;
  7150. laTimeRecorder FrameStartTime, FrameEndTime;
  7151. time_t t1, t2;
  7152. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  7153. static int a = 0;
  7154. if(!laFinalize()) return;
  7155. laSetWindowCursor(LA_ARROW);
  7156. MAIN.DelayTriggered=1;
  7157. #ifdef LAGUI_ANDROID
  7158. while(!MAIN.AppReady){ usleep(1000); }
  7159. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7160. #endif
  7161. while (1){
  7162. laRecordTime(&FrameStartTime);
  7163. la_PreFrame();
  7164. if(!la_ProcessSysMessage()){ return; }
  7165. la_UpdateControllerStatus();
  7166. if(MAIN.GraphNeedsRebuild){ MAIN.GraphNeedsRebuild = 0; }
  7167. for (w=MAIN.Windows.pFirst;w;w = NextW){
  7168. NextW = w->Item.pNext;
  7169. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  7170. }
  7171. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  7172. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7173. tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
  7174. if(MAIN.GLDebugNeedsUpdate){
  7175. la_SetCurrentGLContextDebug();
  7176. }
  7177. la_DrawWindow(w);
  7178. }
  7179. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  7180. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  7181. #ifdef LA_LINUX
  7182. #ifdef LA_USE_GLES
  7183. eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
  7184. #else
  7185. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  7186. #endif
  7187. #endif
  7188. #ifdef _WIN32
  7189. SwapBuffers(w->hdc);
  7190. #endif
  7191. #ifdef LAGUI_ANDROID
  7192. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7193. #endif
  7194. }
  7195. MAIN.GLDebugNeedsUpdate=0;
  7196. la_PostFrame();
  7197. //t2 = clock();
  7198. laRecordTime(&FrameEndTime);
  7199. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  7200. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  7201. if (Pause > 0){
  7202. int us = Pause * 1000000.0;
  7203. usleep(us);
  7204. }
  7205. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  7206. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  7207. la_AnimationPostFrame();
  7208. }
  7209. }
  7210. #ifdef LAGUI_ANDROID
  7211. int la_AndroidInitGraphics(void){
  7212. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7213. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7214. logPrintNew("Android init graphics %d x %d", MAIN.AppWidth, MAIN.AppHeight);
  7215. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7216. EGLint samples = 0;
  7217. EGLint sampleBuffer = 0;
  7218. const EGLint framebufferAttribs[] = {
  7219. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, // Type of context support
  7220. EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
  7221. EGL_GREEN_SIZE, 8, // GREEN color bit dept<android/log.h>h (alternative: 6)
  7222. EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
  7223. //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
  7224. EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
  7225. //EGL_STENCIL_SIZE, 8, // Stencil buffer size
  7226. EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
  7227. EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
  7228. EGL_NONE
  7229. };
  7230. const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
  7231. EGLint numConfigs = 0;
  7232. MAIN.egl_dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY);
  7233. if (MAIN.egl_dpy == EGL_NO_DISPLAY){ logPrint("Android no display"); return -1; }
  7234. if (eglInitialize(MAIN.egl_dpy, NULL, NULL) == EGL_FALSE){ logPrint("Android can't init display"); return -1; }
  7235. eglChooseConfig(MAIN.egl_dpy, framebufferAttribs, &MAIN.BestFBC, 1, &numConfigs);
  7236. eglBindAPI(EGL_OPENGL_API);
  7237. MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, contextAttribs);
  7238. if (MAIN.glc == EGL_NO_CONTEXT){ logPrint("Android can't create context"); return -1; }
  7239. EGLint displayFormat = 0;
  7240. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7241. ANativeWindow_setBuffersGeometry(MAIN.app->window, MAIN.AppWidth, MAIN.AppHeight, displayFormat);
  7242. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, MAIN.app->window, NULL);
  7243. // There must be at least one frame displayed before the buffers are swapped
  7244. eglSwapInterval(MAIN.egl_dpy, 1);
  7245. if (eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc) == EGL_FALSE) { logPrint("Android can't make current"); return -1; }
  7246. eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7247. MAIN.AppReady = 1;
  7248. return 0;
  7249. }
  7250. static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
  7251. switch (cmd){
  7252. case APP_CMD_START: break;
  7253. case APP_CMD_GAINED_FOCUS: MAIN.AppEnabled = 1; break;
  7254. case APP_CMD_LOST_FOCUS: MAIN.AppEnabled = 0; break;
  7255. case APP_CMD_RESUME:break;//InitPlatform();break;
  7256. case APP_CMD_INIT_WINDOW:
  7257. if (app->window != NULL){
  7258. if (MAIN.ContextRebindRequired){
  7259. // Reset screen scaling to full display size
  7260. EGLint displayFormat = 0;
  7261. eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
  7262. // Adding renderOffset here feels rather hackish, but the viewport scaling is wrong after the
  7263. // context rebinding if the screen is scaled unless offsets are added. There's probably a more
  7264. // appropriate way to fix this
  7265. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7266. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7267. ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
  7268. displayFormat);
  7269. // Recreate display surface and re-attach OpenGL context
  7270. MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
  7271. eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7272. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7273. //glClearColor(1,0.2,1,1);
  7274. //glClear(GL_COLOR_BUFFER_BIT);
  7275. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7276. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7277. MAIN.ContextRebindRequired = false;
  7278. }else{
  7279. la_AndroidInitGraphics();
  7280. }
  7281. }
  7282. break;
  7283. case APP_CMD_TERM_WINDOW:
  7284. // Detach OpenGL context and destroy discom.yiming.helloplay surface
  7285. // 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.
  7286. // NOTE 2: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
  7287. // NOTE 3: In some cases (too many context loaded), OS could unload context automatically... :(
  7288. if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
  7289. eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  7290. if (MAIN.egl_surf != EGL_NO_SURFACE) {
  7291. eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
  7292. MAIN.egl_surf = EGL_NO_SURFACE;
  7293. }
  7294. MAIN.ContextRebindRequired = true;
  7295. }
  7296. // If 'MAIN.egl_dpy' is already set to 'EGL_NO_DISPLAY'
  7297. // this means that the user has already called 'CloseWindow()'
  7298. break;
  7299. case APP_CMD_SAVE_STATE: break;
  7300. case APP_CMD_STOP: break;
  7301. case APP_CMD_DESTROY: break;
  7302. case APP_CMD_CONFIG_CHANGED:
  7303. MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
  7304. MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
  7305. la_CommandResizeWindow(0,0,0,MAIN.AppWidth,MAIN.AppHeight);
  7306. //AConfiguration_fromAssetManager(MAIN.app->config, MAIN.app->activity->assetManager);
  7307. //print_cur_config(MAIN.app);
  7308. // Check screen orientation here!
  7309. break;
  7310. default: break;
  7311. }
  7312. }
  7313. #define KEYCODE_MAP_SIZE 162
  7314. static const int KeycodeMap[KEYCODE_MAP_SIZE] = {
  7315. 0, // AKEYCODE_UNKNOWN
  7316. 0, // AKEYCODE_SOFT_LEFT
  7317. 0, // AKEYCODE_SOFT_RIGHT
  7318. 0, // AKEYCODE_HOME
  7319. 0, // AKEYCODE_BACK
  7320. 0, // AKEYCODE_CALL
  7321. 0, // AKEYCODE_ENDCALL
  7322. '0', // AKEYCODE_0
  7323. '1', // AKEYCODE_1
  7324. '2', // AKEYCODE_2
  7325. '3', // AKEYCODE_3
  7326. '4', // AKEYCODE_4
  7327. '5', // AKEYCODE_5
  7328. '6', // AKEYCODE_6
  7329. '7', // AKEYCODE_7
  7330. '8', // AKEYCODE_8
  7331. '9', // AKEYCODE_9
  7332. 0, // AKEYCODE_STAR
  7333. 0, // AKEYCODE_POUND
  7334. LA_KEY_ARRUP, // AKEYCODE_DPAD_UP
  7335. LA_KEY_ARRDOWN, // AKEYCODE_DPAD_DOWN
  7336. LA_KEY_ARRLEFT, // AKEYCODE_DPAD_LEFT
  7337. LA_KEY_ARRRIGHT, // AKEYCODE_DPAD_RIGHT
  7338. 0, // AKEYCODE_DPAD_CENTER
  7339. 0, // AKEYCODE_VOLUME_UP
  7340. 0, // AKEYCODE_VOLUME_DOWN
  7341. 0, // AKEYCODE_POWER
  7342. 0, // AKEYCODE_CAMERA
  7343. 0, // AKEYCODE_CLEAR
  7344. 'a', // AKEYCODE_A
  7345. 'b', // AKEYCODE_B
  7346. 'c', // AKEYCODE_C
  7347. 'd', // AKEYCODE_D
  7348. 'e', // AKEYCODE_E
  7349. 'f', // AKEYCODE_F
  7350. 'g', // AKEYCODE_G
  7351. 'h', // AKEYCODE_H
  7352. 'i', // AKEYCODE_I
  7353. 'j', // AKEYCODE_J
  7354. 'k', // AKEYCODE_K
  7355. 'l', // AKEYCODE_L
  7356. 'm', // AKEYCODE_M
  7357. 'n', // AKEYCODE_N
  7358. 'o', // AKEYCODE_O
  7359. 'p', // AKEYCODE_P
  7360. 'q', // AKEYCODE_Q
  7361. 'r', // AKEYCODE_R
  7362. 's', // AKEYCODE_S
  7363. 't', // AKEYCODE_T
  7364. 'u', // AKEYCODE_U
  7365. 'v', // AKEYCODE_V
  7366. 'w', // AKEYCODE_W
  7367. 'x', // AKEYCODE_X
  7368. 'y', // AKEYCODE_Y
  7369. 'z', // AKEYCODE_Z
  7370. ',', // AKEYCODE_COMMA
  7371. '.', // AKEYCODE_PERIOD
  7372. LA_KEY_ALT, // AKEYCODE_ALT_LEFT
  7373. LA_KEY_ALT, // AKEYCODE_ALT_RIGHT
  7374. LA_KEY_SHIFT, // AKEYCODE_SHIFT_LEFT
  7375. LA_KEY_SHIFT, // AKEYCODE_SHIFT_RIGHT
  7376. LA_KEY_TAB, // AKEYCODE_TAB
  7377. ' ', // AKEYCODE_SPACE
  7378. 0, // AKEYCODE_SYM
  7379. 0, // AKEYCODE_EXPLORER
  7380. 0, // AKEYCODE_ENVELOPE
  7381. LA_KEY_ENTER, // AKEYCODE_ENTER
  7382. LA_KEY_BACKSPACE, // AKEYCODE_DEL
  7383. '`', // AKEYCODE_GRAVE
  7384. '-', // AKEYCODE_MINUS
  7385. '=', // AKEYCODE_EQUALS
  7386. '(', // AKEYCODE_LEFT_BRACKET
  7387. ')', // AKEYCODE_RIGHT_BRACKET
  7388. '\\', // AKEYCODE_BACKSLASH
  7389. ';', // AKEYCODE_SEMICOLON
  7390. '\'', // AKEYCODE_APOSTROPHE
  7391. '/', // AKEYCODE_SLASH
  7392. 0, // AKEYCODE_AT
  7393. 0, // AKEYCODE_NUM
  7394. 0, // AKEYCODE_HEADSETHOOK
  7395. 0, // AKEYCODE_FOCUS
  7396. 0, // AKEYCODE_PLUS
  7397. 0, // AKEYCODE_MENU
  7398. 0, // AKEYCODE_NOTIFICATION
  7399. 0, // AKEYCODE_SEARCH
  7400. 0, // AKEYCODE_MEDIA_PLAY_PAUSE
  7401. 0, // AKEYCODE_MEDIA_STOP
  7402. 0, // AKEYCODE_MEDIA_NEXT
  7403. 0, // AKEYCODE_MEDIA_PREVIOUS
  7404. 0, // AKEYCODE_MEDIA_REWIND
  7405. 0, // AKEYCODE_MEDIA_FAST_FORWARD
  7406. 0, // AKEYCODE_MUTE
  7407. 0, // AKEYCODE_PAGE_UP
  7408. 0, // AKEYCODE_PAGE_DOWN
  7409. 0, // AKEYCODE_PICTSYMBOLS
  7410. 0, // AKEYCODE_SWITCH_CHARSET
  7411. 0, // AKEYCODE_BUTTON_A
  7412. 0, // AKEYCODE_BUTTON_B
  7413. 0, // AKEYCODE_BUTTON_C
  7414. 0, // AKEYCODE_BUTTON_X
  7415. 0, // AKEYCODE_BUTTON_Y
  7416. 0, // AKEYCODE_BUTTON_Z
  7417. 0, // AKEYCODE_BUTTON_L1
  7418. 0, // AKEYCODE_BUTTON_R1
  7419. 0, // AKEYCODE_BUTTON_L2
  7420. 0, // AKEYCODE_BUTTON_R2
  7421. 0, // AKEYCODE_BUTTON_THUMBL
  7422. 0, // AKEYCODE_BUTTON_THUMBR
  7423. 0, // AKEYCODE_BUTTON_START
  7424. 0, // AKEYCODE_BUTTON_SELECT
  7425. 0, // AKEYCODE_BUTTON_MODE
  7426. LA_KEY_ESCAPE, // AKEYCODE_ESCAPE
  7427. LA_KEY_DELETE, // AKEYCODE_FORWARD_DELL
  7428. LA_KEY_CTRL, // AKEYCODE_CTRL_LEFT
  7429. LA_KEY_CTRL, // AKEYCODE_CTRL_RIGHT
  7430. 0, // AKEYCODE_CAPS_LOCK
  7431. 0, // AKEYCODE_SCROLL_LOCK
  7432. LA_KEY_ARRLEFT, // AKEYCODE_META_LEFT
  7433. LA_KEY_ARRRIGHT, // AKEYCODE_META_RIGHT
  7434. 0, // AKEYCODE_FUNCTION
  7435. 0, // AKEYCODE_SYSRQ
  7436. 0, // AKEYCODE_BREAK
  7437. 0, // AKEYCODE_MOVE_HOME
  7438. 0, // AKEYCODE_MOVE_END
  7439. 0, // AKEYCODE_INSERT
  7440. 0, // AKEYCODE_FORWARD
  7441. 0, // AKEYCODE_MEDIA_PLAY
  7442. 0, // AKEYCODE_MEDIA_PAUSE
  7443. 0, // AKEYCODE_MEDIA_CLOSE
  7444. 0, // AKEYCODE_MEDIA_EJECT
  7445. 0, // AKEYCODE_MEDIA_RECORD
  7446. LA_KEY_F1, // AKEYCODE_F1
  7447. LA_KEY_F2, // AKEYCODE_F2
  7448. LA_KEY_F3, // AKEYCODE_F3
  7449. LA_KEY_F4, // AKEYCODE_F4
  7450. LA_KEY_F5, // AKEYCODE_F5
  7451. LA_KEY_F6, // AKEYCODE_F6
  7452. LA_KEY_F7, // AKEYCODE_F7
  7453. LA_KEY_F8, // AKEYCODE_F8
  7454. LA_KEY_F9, // AKEYCODE_F9
  7455. LA_KEY_F10, // AKEYCODE_F10
  7456. LA_KEY_F11, // AKEYCODE_F11
  7457. LA_KEY_F12, // AKEYCODE_F12
  7458. 0, // AKEYCODE_NUM_LOCK
  7459. LA_KEY_NUM0, // AKEYCODE_NUMPAD_0
  7460. LA_KEY_NUM1, // AKEYCODE_NUMPAD_1
  7461. LA_KEY_NUM2, // AKEYCODE_NUMPAD_2
  7462. LA_KEY_NUM3, // AKEYCODE_NUMPAD_3
  7463. LA_KEY_NUM4, // AKEYCODE_NUMPAD_4
  7464. LA_KEY_NUM5, // AKEYCODE_NUMPAD_5
  7465. LA_KEY_NUM6, // AKEYCODE_NUMPAD_6
  7466. LA_KEY_NUM7, // AKEYCODE_NUMPAD_7
  7467. LA_KEY_NUM8, // AKEYCODE_NUMPAD_8
  7468. LA_KEY_NUM9, // AKEYCODE_NUMPAD_9
  7469. LA_KEY_NUMDIVIDE, // AKEYCODE_NUMPAD_DIVIDE
  7470. LA_KEY_NUMMULT, // AKEYCODE_NUMPAD_MULTIPLY
  7471. LA_KEY_NUMMINUS, // AKEYCODE_NUMPAD_SUBTRACT
  7472. LA_KEY_NUMPLUS, // AKEYCODE_NUMPAD_ADD
  7473. LA_KEY_NUMDOT, // AKEYCODE_NUMPAD_DOT
  7474. 0, // AKEYCODE_NUMPAD_COMMA
  7475. LA_KEY_NUMENTER, // AKEYCODE_NUMPAD_ENTER
  7476. '=' // AKEYCODE_NUMPAD_EQUALS
  7477. };
  7478. static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *event)
  7479. {
  7480. __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
  7481. if(!MAIN.AppEnabled){return 0;}
  7482. //laRedrawAllWindows();
  7483. int type = AInputEvent_getType(event);
  7484. if(type == AINPUT_EVENT_TYPE_KEY){
  7485. int32_t keycode = AKeyEvent_getKeyCode(event);
  7486. //int32_t AKeyEvent_getMetaState(event);
  7487. int key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : 0;
  7488. if (key != 0){
  7489. // Save current key and its state
  7490. // NOTE: Android key action is 0 for down and 1 for up
  7491. if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN){
  7492. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7493. if(key!=LA_KEY_BACKSPACE)
  7494. la_SendInputEvent(0,key);
  7495. }
  7496. else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE){
  7497. la_SendKeyboardEvent(0,LA_KEY_DOWN,key);
  7498. la_SendInputEvent(0,key);
  7499. }
  7500. else la_SendKeyboardEvent(0,LA_KEY_UP,key); // Key up
  7501. }
  7502. if (keycode == AKEYCODE_POWER)
  7503. {
  7504. // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
  7505. // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
  7506. // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
  7507. // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
  7508. // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
  7509. return 0;
  7510. }
  7511. else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
  7512. {
  7513. // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
  7514. return 1;
  7515. }
  7516. else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
  7517. {
  7518. // Set default OS behaviour
  7519. return 0;
  7520. }
  7521. return 0;
  7522. }
  7523. elif(type == AINPUT_EVENT_TYPE_MOTION){
  7524. int pcount = AMotionEvent_getPointerCount(event); int x,y;
  7525. if(pcount){
  7526. real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
  7527. x=rx; y=ry;
  7528. }
  7529. int32_t action = AMotionEvent_getAction(event);
  7530. unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  7531. int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  7532. if (flags == AMOTION_EVENT_ACTION_DOWN){
  7533. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7534. la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
  7535. }
  7536. else if (flags == AMOTION_EVENT_ACTION_UP){
  7537. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7538. }
  7539. else if (flags == AMOTION_EVENT_ACTION_MOVE){
  7540. la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
  7541. }
  7542. else if (flags == AMOTION_EVENT_ACTION_CANCEL){
  7543. la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
  7544. }
  7545. }
  7546. //static float r=0;
  7547. //eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
  7548. //glViewport(0,0,MAIN.AppWidth,MAIN.AppHeight);
  7549. //glClearColor(r,0.2,1,1); r+=0.01; if(r>1){ r=0; }
  7550. //glClear(GL_COLOR_BUFFER_BIT);
  7551. //eglSwapBuffers(MAIN.egl_dpy, MAIN.egl_surf);
  7552. return 0;
  7553. }
  7554. void la_InitAssetManager(AAssetManager *manager, const char *dataPath, const char *externalDataPath){
  7555. MAIN.AssetManager = manager;
  7556. MAIN.InternalDataPath = dataPath;
  7557. MAIN.ExternalDataPath = externalDataPath;
  7558. }
  7559. static int android_read(void *cookie, char *data, int dataSize){
  7560. return AAsset_read((AAsset *)cookie, data, dataSize);
  7561. }
  7562. static int android_write(void *cookie, const char *data, int dataSize){
  7563. return 0;
  7564. }
  7565. static fpos_t android_seek(void *cookie, fpos_t offset, int whence){
  7566. return AAsset_seek((AAsset *)cookie, offset, whence);
  7567. }
  7568. static int android_close(void *cookie){
  7569. AAsset_close((AAsset *)cookie);
  7570. return 0;
  7571. }
  7572. // Replacement for fopen()
  7573. // Ref: https://developer.android.com/ndk/reference/group/asset
  7574. FILE *android_fopen(const char *fileName, const char *mode)
  7575. {
  7576. char buf[1024];
  7577. if (mode[0] == 'w')
  7578. {
  7579. // fopen() is mapped to android_fopen() that only grants read access to
  7580. // assets directory through AAssetManager but we want to also be able to
  7581. // write data when required using the standard stdio FILE access functions
  7582. // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
  7583. #undef fopen
  7584. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7585. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7586. result=fopen(buf, mode); if(result) return result;
  7587. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7588. return fopen(buf, mode);
  7589. #define fopen(name, mode) android_fopen(name, mode)
  7590. }
  7591. else
  7592. {
  7593. // NOTE: AAsset provides access to read-only asset
  7594. AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
  7595. if (asset != NULL)
  7596. {
  7597. // Get pointer to file in the assets
  7598. return funopen(asset, android_read, android_write, android_seek, android_close);
  7599. }
  7600. else
  7601. {
  7602. #undef fopen
  7603. FILE* result=fopen(fileName, mode); if(result){ return result; }
  7604. // Just do a regular open if file is not found in the assets
  7605. sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
  7606. result=fopen(buf, mode); if(result){ return result; }
  7607. sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
  7608. return fopen(buf, mode);
  7609. #define fopen(name, mode) android_fopen(name, mode)
  7610. }
  7611. }
  7612. }
  7613. void la_HideNavBar(){
  7614. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7615. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7616. (*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7617. jclass activityClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/app/NativeActivity");
  7618. jmethodID getWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,activityClass, "getWindow", "()Landroid/view/Window;");
  7619. jclass windowClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/Window");
  7620. jmethodID getDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,windowClass, "getDecorView", "()Landroid/view/View;");
  7621. jclass viewClass = (*lJNIEnv)->FindClass(lJNIEnv,"android/view/View");
  7622. jmethodID setSystemUiVisibility = (*lJNIEnv)->GetMethodID(lJNIEnv,viewClass, "setSystemUiVisibility", "(I)V");
  7623. jobject window = (*lJNIEnv)->CallObjectMethod(lJNIEnv,MAIN.app->activity->clazz, getWindow);
  7624. jobject decorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,window, getDecorView);
  7625. jfieldID flagFullscreenID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
  7626. jfieldID flagHideNavigationID = (*lJNIEnv)->GetStaticFieldID(lJNIEnv,viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
  7627. int flagFullscreen = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagFullscreenID);
  7628. int flagHideNavigation = (*lJNIEnv)->GetStaticIntField(lJNIEnv,viewClass, flagHideNavigationID);
  7629. int flag = flagFullscreen | flagHideNavigation;
  7630. (*lJNIEnv)->CallVoidMethod(lJNIEnv,decorView, setSystemUiVisibility, flag);
  7631. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7632. }
  7633. void la_InitAndroidPlatform(struct android_app *app){
  7634. MAIN.app=app;
  7635. ANativeActivity_setWindowFlags(MAIN.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
  7636. //la_HideNavBar();
  7637. MAIN.app->onAppCmd = la_AndroidCommandCallback;
  7638. MAIN.app->onInputEvent = la_AndroidInputCallback;
  7639. la_InitAssetManager(MAIN.app->activity->assetManager, MAIN.app->activity->internalDataPath, MAIN.app->activity->externalDataPath);
  7640. int pollResult = 0;
  7641. int pollEvents = 0;
  7642. while (!MAIN.AppReady){
  7643. while ((pollResult = ALooper_pollAll(MAIN.AppEnabled? 0 : -1, NULL, &pollEvents, (void**)&MAIN.event_source)) >= 0){
  7644. // Process this event
  7645. if (MAIN.event_source != NULL) MAIN.event_source->process(MAIN.app, MAIN.event_source);
  7646. // NOTE: Never close window, native activity is controlled by the system!
  7647. //if (MAIN.app->destroyRequested != 0) CORE.Window.shouldClose = true;
  7648. }
  7649. }
  7650. }
  7651. int main(int, char *[]);
  7652. void android_main(struct android_app *app){
  7653. char arg0[] = "lagui"; // NOTE: argv[] are mutable
  7654. la_InitAndroidPlatform(app);
  7655. // NOTE: Return from main is ignored
  7656. (void)main(1, (char *[]) { arg0, NULL });
  7657. // Request to end the native activity
  7658. ANativeActivity_finish(app->activity);
  7659. // Android ALooper_pollAll() variables
  7660. int pollResult = 0;
  7661. int pollEvents = 0;
  7662. // Waiting for application events before complete finishing
  7663. while (!app->destroyRequested)
  7664. {
  7665. while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&MAIN.event_source)) >= 0)
  7666. {
  7667. if ( MAIN.event_source != NULL) MAIN.event_source->process(app, MAIN.event_source);
  7668. }
  7669. }
  7670. }
  7671. void la_DisplayKeyboard(bool pShow) {
  7672. // Attaches the current thread to the JVM.
  7673. jint lResult;
  7674. jint lFlags = 0;
  7675. JavaVM* lJavaVM = MAIN.app->activity->vm;
  7676. JNIEnv* lJNIEnv = MAIN.app->activity->env;
  7677. JavaVMAttachArgs lJavaVMAttachArgs;
  7678. lJavaVMAttachArgs.version = JNI_VERSION_1_6;
  7679. lJavaVMAttachArgs.name = "NativeThread";
  7680. lJavaVMAttachArgs.group = NULL;
  7681. lResult=(*lJavaVM)->AttachCurrentThread(lJavaVM, &lJNIEnv,0);
  7682. if (lResult == JNI_ERR) {
  7683. return;
  7684. }
  7685. // Retrieves NativeActivity.
  7686. jobject lNativeActivity = MAIN.app->activity->clazz;
  7687. jclass ClassNativeActivity = (*lJNIEnv)->GetObjectClass(lJNIEnv,lNativeActivity);
  7688. logPrintNew("jvm3");
  7689. // Retrieves Context.INPUT_METHOD_SERVICE.
  7690. jclass ClassContext = (*lJNIEnv)->FindClass(lJNIEnv,"android/content/Context");
  7691. jfieldID FieldINPUT_METHOD_SERVICE =
  7692. (*lJNIEnv)->GetStaticFieldID(lJNIEnv,ClassContext,
  7693. "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
  7694. jobject INPUT_METHOD_SERVICE =
  7695. (*lJNIEnv)->GetStaticObjectField(lJNIEnv,ClassContext,
  7696. FieldINPUT_METHOD_SERVICE);
  7697. //jniCheck(INPUT_METHOD_SERVICE);
  7698. logPrintNew("jvm4");
  7699. // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
  7700. jclass ClassInputMethodManager = (*lJNIEnv)->FindClass(lJNIEnv,
  7701. "android/view/inputmethod/InputMethodManager");
  7702. jmethodID MethodGetSystemService = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7703. ClassNativeActivity, "getSystemService",
  7704. "(Ljava/lang/String;)Ljava/lang/Object;");
  7705. jobject lInputMethodManager = (*lJNIEnv)->CallObjectMethod(lJNIEnv,
  7706. lNativeActivity, MethodGetSystemService,
  7707. INPUT_METHOD_SERVICE);
  7708. // Runs getWindow().getDecorView().
  7709. jmethodID MethodGetWindow = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7710. ClassNativeActivity, "getWindow",
  7711. "()Landroid/view/Window;");
  7712. jobject lWindow = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lNativeActivity,
  7713. MethodGetWindow);
  7714. jclass ClassWindow = (*lJNIEnv)->FindClass(lJNIEnv,
  7715. "android/view/Window");
  7716. jmethodID MethodGetDecorView = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7717. ClassWindow, "getDecorView", "()Landroid/view/View;");
  7718. jobject lDecorView = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lWindow,
  7719. MethodGetDecorView);
  7720. if (pShow) {
  7721. // Runs lInputMethodManager.showSoftInput(...).
  7722. jmethodID MethodShowSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7723. ClassInputMethodManager, "showSoftInput",
  7724. "(Landroid/view/View;I)Z");
  7725. jboolean lResult = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7726. lInputMethodManager, MethodShowSoftInput,
  7727. lDecorView, lFlags);
  7728. } else {
  7729. // Runs lWindow.getViewToken()
  7730. jclass ClassView = (*lJNIEnv)->FindClass(lJNIEnv,
  7731. "android/view/View");
  7732. jmethodID MethodGetWindowToken = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7733. ClassView, "getWindowToken", "()Landroid/os/IBinder;");
  7734. jobject lBinder = (*lJNIEnv)->CallObjectMethod(lJNIEnv,lDecorView,
  7735. MethodGetWindowToken);
  7736. // lInputMethodManager.hideSoftInput(...).
  7737. jmethodID MethodHideSoftInput = (*lJNIEnv)->GetMethodID(lJNIEnv,
  7738. ClassInputMethodManager, "hideSoftInputFromWindow",
  7739. "(Landroid/os/IBinder;I)Z");
  7740. jboolean lRes = (*lJNIEnv)->CallBooleanMethod(lJNIEnv,
  7741. lInputMethodManager, MethodHideSoftInput,
  7742. lBinder, lFlags);
  7743. }
  7744. // Finished with the JVM.
  7745. (*lJavaVM)->DetachCurrentThread(lJavaVM);
  7746. }
  7747. #endif //android
  7748. #ifndef LAGUI_ANDROID
  7749. void la_DisplayKeyboard(bool pShow) {
  7750. return;
  7751. }
  7752. void la_HideNavBar(){
  7753. return;
  7754. }
  7755. #endif