*/}}

la_kernel.c 242 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629
  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. #include "la_5.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <math.h>
  22. #include <time.h>
  23. #include <sys/time.h>
  24. #include <X11/Xlib.h>
  25. #include <X11/Xutil.h>
  26. #include <X11/Xos.h>
  27. #include <X11/keysymdef.h>
  28. #include <X11/XKBlib.h>
  29. #include <X11/extensions/XInput2.h>
  30. #include <X11/extensions/Xfixes.h>
  31. #include <X11/Xcursor/Xcursor.h>
  32. #include <X11/cursorfont.h>
  33. #include <GL/glx.h>
  34. //#include <GL/glext.h>
  35. //#include <GL/glu.h>
  36. LA MAIN;
  37. extern tnsMain *T;
  38. int deb = 0;
  39. laOperator *DEB;
  40. laColumn *DEBUG_C;
  41. #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
  42. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
  43. typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
  44. typedef void (*glXSwapIntervalEXTProc)(Display *dpy, GLXDrawable drawable, int interval);
  45. glXCreateContextAttribsARBProc glXCreateContextAttribsF;
  46. glXSwapIntervalEXTProc glXSwapIntervalEXTF;
  47. static void la_PrintWacomValuators(Display *display, XIAnyClassInfo **classes, int num_classes){
  48. int i;
  49. for (i = 0; i < num_classes; i++) {
  50. if (classes[i]->type == XIValuatorClass) {
  51. XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
  52. logPrint(" Valuator %d: '%s'\n", v->number, (v->label) ? XGetAtomName(display, v->label) : "No label");
  53. logPrint(" Range: %f - %f\n", v->min, v->max);
  54. logPrint(" Resolution: %d units/m\n", v->resolution);
  55. logPrint(" Mode: %s\n", v->mode == XIModeAbsolute ? "absolute": "relative");
  56. if (v->mode == XIModeAbsolute) logPrint(" Current value: %f\n", v->value);
  57. }
  58. }
  59. }
  60. static void la_RegisterWacomEventMasks(Display *display, int deviceid, real* max_pressure) {
  61. XIDeviceInfo *info, *dev;
  62. int i, ndevices;
  63. dev = XIQueryDevice(display, deviceid, &ndevices);
  64. XIEventMask *mask=memAcquireSimple(sizeof(XIEventMask));
  65. mask->deviceid = deviceid;
  66. mask->mask_len = XIMaskLen(XI_RawMotion);
  67. mask->mask=memAcquireSimple(mask->mask_len);
  68. memset(mask->mask, 0, mask->mask_len);
  69. XISetMask(mask->mask, XI_RawMotion);
  70. XISelectEvents(display, DefaultRootWindow(display), mask, 1);
  71. int FoundMax=0;
  72. for (i = 0; i < dev->num_classes; i++) {
  73. if (dev->classes[i]->type == XIValuatorClass) {
  74. XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i];
  75. if(v->number==2){ *max_pressure=v->max; FoundMax=1; break; }
  76. }
  77. }
  78. if(!FoundMax){*max_pressure=65535;}
  79. logPrint(" Device Name: '%s' (%d)\n", dev->name, dev->deviceid);
  80. //la_PrintWacomValuators(display, dev->classes, dev->num_classes);
  81. XIFreeDeviceInfo(dev);
  82. }
  83. void la_ScanWacomDevices(Display *display, int deviceid){
  84. XIDeviceInfo *info, *dev;
  85. int ndevices;
  86. int i; char * word;
  87. int _event, _error;
  88. if (!XQueryExtension(MAIN.dpy, "XInputExtension", &MAIN.xi_opcode, &_event, &_error)) {
  89. logPrint("X Input extension not available, wacom pressure events are not available.\n"); return;
  90. }
  91. info = XIQueryDevice(display, deviceid, &ndevices);
  92. for(i = 0; i < ndevices; i++) {
  93. dev = &info[i];
  94. int is_ipts=0; if(strstr(dev->name, "ipts")){ is_ipts=1; }
  95. word = strtok (dev->name," ");
  96. while (1) {
  97. word = strtok (NULL, " "); if (!word) break;
  98. if (strcmp("stylus", word) == 0) MAIN.WacomDeviceStylus = dev->deviceid; // wacom
  99. elif (strcmp("eraser", word) == 0) MAIN.WacomDeviceEraser = dev->deviceid; // wacom
  100. elif (is_ipts && strcmp("Pen", word) == 0) MAIN.WacomDeviceStylus = dev->deviceid; // surface ipts
  101. elif (is_ipts && strcmp("Eraser", word) == 0) MAIN.WacomDeviceEraser = dev->deviceid; // surface ipts
  102. }
  103. }
  104. if(MAIN.WacomDeviceStylus || MAIN.WacomDeviceEraser){
  105. logPrintNew("Found wacom devices:\n");
  106. if(MAIN.WacomDeviceStylus) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceStylus,&MAIN.StylusMaxPressure);
  107. if(MAIN.WacomDeviceEraser) la_RegisterWacomEventMasks(display, MAIN.WacomDeviceEraser,&MAIN.EraserMaxPressure);
  108. }else{
  109. logPrintNew("No wacom pen device connected.\n");
  110. }
  111. XIFreeDeviceInfo(info);
  112. }
  113. void laHideCursor(){
  114. if(!MAIN.CurrentWindow) return; XFixesHideCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  115. }
  116. void laShowCursor(){
  117. if(!MAIN.CurrentWindow) return; XFixesShowCursor(MAIN.dpy, MAIN.CurrentWindow->win);
  118. }
  119. void la_XErrorHandler(Display *display, XErrorEvent *event){
  120. char buf[512];
  121. XGetErrorText(display, event->error_code, buf, sizeof(buf));
  122. printf("X Error:\n%s\n",buf);
  123. }
  124. Window la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc){
  125. XSetWindowAttributes swa;
  126. XWindowAttributes wa;
  127. swa.event_mask =
  128. KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
  129. ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|ExposureMask|PointerMotionMask;
  130. swa.colormap = MAIN.cmap;
  131. Window root = DefaultRootWindow(MAIN.dpy);
  132. Window win = XCreateWindow(MAIN.dpy, root, x,y, w, h, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  133. XSetWMProtocols(MAIN.dpy , win, &MAIN.MsgDelWindow, 1);
  134. if(x>0||y>0){
  135. XSizeHints my_hints = {0};
  136. my_hints.flags = PPosition;
  137. my_hints.x = x; my_hints.y = y;
  138. XSetNormalHints(MAIN.dpy, win, &my_hints);
  139. }
  140. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 4, GLX_CONTEXT_MINOR_VERSION_ARB, 6, 0};
  141. if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
  142. printf("\n\tcannot create gl context\n\n"); exit(0);
  143. }
  144. XStoreName(MAIN.dpy, win, title);
  145. //XMapWindow(MAIN.dpy, win);
  146. glXMakeCurrent(MAIN.dpy, win, MAIN.glc);
  147. int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
  148. MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
  149. MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
  150. XSetICFocus(MAIN.ic);
  151. XClassHint ch; ch.res_name = "LAGUI_WINDOW"; ch.res_class = "LAGUI_WINDOW";
  152. XSetClassHint(MAIN.dpy, win, &ch);
  153. #define _NET_WM_STATE_ADD 1
  154. if(w<0&&h<0){
  155. XEvent xev;
  156. Atom wm_state = XInternAtom(MAIN.dpy, "_NET_WM_STATE", False);
  157. Atom max_horz = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  158. Atom max_vert = XInternAtom(MAIN.dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  159. memset(&xev, 0, sizeof(xev));
  160. xev.type = ClientMessage;
  161. xev.xclient.window = win;
  162. xev.xclient.message_type = wm_state;
  163. xev.xclient.format = 32;
  164. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  165. xev.xclient.data.l[1] = max_horz;
  166. xev.xclient.data.l[2] = max_vert;
  167. XSendEvent(MAIN.dpy, DefaultRootWindow(MAIN.dpy), False, SubstructureNotifyMask, &xev);
  168. }
  169. return win;
  170. };
  171. int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
  172. GLXContext glc;
  173. Window hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
  174. window->win = hwnd;
  175. //if (!hwnd)
  176. //{
  177. // MessageBox(0, "Error Creating Window!", "Error", 0);
  178. // return 0;
  179. //};
  180. //ImmAssociateContext(hwnd,0);
  181. //la_SetupGLEnviornment(window, hwnd);
  182. //GetClientRect(window->win, &rc);
  183. //window->CW = rc.right - rc.left;
  184. //window->CH = rc.bottom - rc.top;
  185. XWindowAttributes attr;
  186. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  187. window->CW =attr.width;
  188. window->CH = attr.height;
  189. window->glc = glc;
  190. return 1;
  191. };
  192. void la_DestroySystemWindowX11(laWindow* w){
  193. glXMakeCurrent(MAIN.dpy, None, NULL);
  194. glXDestroyContext(MAIN.dpy, w->glc);
  195. XDestroyWindow(MAIN.dpy, w->win);
  196. };
  197. int la_DestroySystemWindow(laWindow* wnd){
  198. la_DestroySystemWindowX11(wnd);
  199. }
  200. void la_DestroyWindow(laWindow *wnd){
  201. laLayout *l; laPanel *p;
  202. if (!wnd) return;
  203. la_StopAllOperators();
  204. strSafeDestroy(&wnd->Title);
  205. while (p = lstPopItem(&wnd->Panels)){ laDestroySinglePanel(p,1); }
  206. while (l = lstPopItem(&wnd->Layouts)){
  207. laDestroyBlocksRecursive(l->FirstBlock);
  208. strSafeDestroy(&l->ID);
  209. memFree(l);
  210. }
  211. la_DestroySystemWindow(wnd);
  212. lstRemoveItem(&MAIN.Windows, wnd);
  213. memFree(wnd);
  214. MAIN.CurrentWindow=MAIN.Windows.pFirst;
  215. }
  216. void laRenameWindow(laWindow* wnd, char* name){
  217. if(!wnd) return;
  218. strSafeSet(&wnd->Title, name);
  219. if(!wnd->win) return;
  220. XStoreName(MAIN.dpy, wnd->win, name);
  221. }
  222. const char* la_ConvertCursorID(int id){
  223. switch (id) {
  224. case LA_ARROW: return "arrow";
  225. case LA_CROSS: return "cross";
  226. case LA_LEFT_AND_RIGHT: return "sb_h_double_arrow";
  227. case LA_UP_AND_DOWN: return "sb_v_double_arrow";
  228. case LA_MOVE: return "diamond_cross";
  229. case LA_HAND: return "hand1";
  230. case LA_CORNER: return "bottom_right_corner";
  231. }
  232. return "arrow";
  233. }
  234. void la_MakePanelTitleBar(laPanel *p, laUiDefineFunc ReplaceDefine);
  235. void la_InitThreadEnviornment(){
  236. //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
  237. }
  238. laLogEntry* logEnsure(int Create){
  239. if(!MAIN.Logs.pFirst || Create){
  240. laLogEntry* le=memAcquireSimple(sizeof(laLogEntry));
  241. lstAppendItem(&MAIN.Logs, le);
  242. }
  243. return MAIN.Logs.pLast;
  244. }
  245. void logPrintTV(int Continued, char* format, va_list v){
  246. if(!format || !format[0]) return;
  247. laLogEntry* le=logEnsure(Continued);
  248. strSafePrintV(&le->Content, format, v);
  249. laNotifyUsers("la.logs");
  250. }
  251. void logPrintT(int Continued, char* format, ...){
  252. if(!format || !format[0]) return;
  253. laLogEntry* le=logEnsure(Continued);
  254. va_list aptr; va_start(aptr, format);
  255. strSafePrint(&le->Content, format, aptr);
  256. va_end(aptr);
  257. laNotifyUsers("la.logs");
  258. }
  259. void logPrint(char* format, ...){
  260. va_list aptr; va_start(aptr, format);
  261. logPrintTV(0, format, aptr);
  262. va_end(aptr);
  263. }
  264. void logPrintNew(char* format, ...){
  265. logEnsure(1);
  266. va_list aptr; va_start(aptr, format);
  267. logPrintTV(0, format, aptr);
  268. va_end(aptr);
  269. }
  270. void logClear(){
  271. laLogEntry*l;
  272. while(l=lstPopItem(&MAIN.Logs)){ strSafeDestroy(&l->Content); memFree(l); }
  273. }
  274. #define PROGRESSW (LA_RH*15)
  275. void laShowProgress(real p1, real p2){
  276. laBoxedTheme *bt = _LA_THEME_TAB; real* fg=laThemeColor(bt,LA_BT_TEXT); real* bg=laThemeColor(bt,LA_BT_NORMAL);
  277. if(!MAIN.Progress.Called){
  278. laRecordTime(&MAIN.Progress.TimeCalled); MAIN.Progress.Called=1;
  279. }else{
  280. laTimeRecorder tm; laRecordTime(&tm);
  281. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled); if(t<0.1) return;
  282. memcpy(&MAIN.Progress.TimeCalled,&tm,sizeof(laTimeRecorder));
  283. if(!MAIN.Progress.Shown){
  284. int w=XDisplayWidth(MAIN.dpy, 0),h=XDisplayHeight(MAIN.dpy, 0); int ww=PROGRESSW+LA_RH*2;
  285. XMoveResizeWindow(MAIN.dpy,MAIN.Progress.w,w/2-ww/2,h/2-LA_RH*2/2,ww,LA_RH*2);
  286. long a=LA_COLOR3_TO_HEX(bg);
  287. XSetForeground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(fg));
  288. XSetBackground(MAIN.dpy,MAIN.Progress.gc,LA_COLOR3_TO_HEX(bg));
  289. XSetWindowBackground(MAIN.dpy,MAIN.Progress.w,LA_COLOR3_TO_HEX(bg));
  290. if(MAIN.CurrentWindow) XSetTransientForHint(MAIN.dpy,MAIN.Progress.w,MAIN.CurrentWindow->win);
  291. XMapWindow(MAIN.dpy,MAIN.Progress.w);
  292. MAIN.Progress.Shown=1;
  293. }
  294. }
  295. XClearWindow(MAIN.dpy,MAIN.Progress.w);
  296. if(p1>=0) MAIN.Progress.p1=p1; if(p2>=0) MAIN.Progress.p2=p2;
  297. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,0,PROGRESSW*MAIN.Progress.p1,LA_RH);
  298. XFillRectangle(MAIN.dpy,MAIN.Progress.w,MAIN.Progress.gc,LA_RH*2,LA_RH,PROGRESSW*MAIN.Progress.p2,LA_RH);
  299. tnsDrawLCD7_ProgressX11(LA_RH*1.5,0,MAIN.Progress.p1);
  300. tnsDrawLCD7_ProgressX11(LA_RH*1.5,LA_RH,MAIN.Progress.p2);
  301. XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  302. }
  303. void laHideProgress(){
  304. if(!MAIN.Progress.Shown){
  305. MAIN.Progress.Called=0; return;
  306. }
  307. laTimeRecorder tm; laRecordTime(&tm);
  308. real t=laTimeElapsedSecondsf(&tm,&MAIN.Progress.TimeCalled);
  309. if(t<0.2){ usleep((TNS_MIN2(0.2-t,0.2))*1000000); }
  310. XUnmapWindow(MAIN.dpy,MAIN.Progress.w); XSync(MAIN.dpy, 1); XFlush(MAIN.dpy);
  311. MAIN.Progress.Called = MAIN.Progress.Shown = 0;
  312. }
  313. //=======================
  314. void la_InitProgressWindow(){
  315. 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));
  316. if(!MAIN.Progress.w) return;
  317. Atom window_type = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE", False); long value = XInternAtom(MAIN.dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
  318. XChangeProperty(MAIN.dpy, MAIN.Progress.w, window_type,XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );
  319. MAIN.Progress.gc=XCreateGC(MAIN.dpy,MAIN.Progress.w,0,&MAIN.Progress.gc_values);
  320. if(MAIN.Progress.gc<0) return;
  321. XSetFillStyle(MAIN.dpy, MAIN.Progress.gc, FillSolid);
  322. XSetLineAttributes(MAIN.dpy, MAIN.Progress.gc, 2, LineSolid, CapButt, JoinBevel);
  323. XSync(MAIN.dpy,0);
  324. }
  325. void laSetFontFolderPath(char* absolute){
  326. strcpy(MAIN.SysFontDir,absolute); int len=strlen(MAIN.SysFontDir);
  327. if(MAIN.SysFontDir[len-1]!='/'){ MAIN.SysFontDir[len]='/'; MAIN.SysFontDir[len+1]=0; }
  328. }
  329. int laGetReady(){
  330. Window root, win;
  331. GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
  332. XSetWindowAttributes swa={0};
  333. XWindowAttributes wa={0};
  334. XEvent xev;
  335. logPrintNew("Initializing LaGUI...\n");
  336. setlocale(LC_CTYPE, "zh_CN.utf8");
  337. XSetLocaleModifiers("");
  338. XSetErrorHandler(la_XErrorHandler);
  339. int i;
  340. if ((MAIN.dpy = XOpenDisplay(NULL)) == NULL){
  341. printf("\n\tcannot connect to x server\n\n");
  342. exit(0);
  343. }
  344. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  345. static int visual_attribs[] =
  346. {
  347. GLX_X_RENDERABLE , True,
  348. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  349. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  350. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  351. GLX_RED_SIZE , 8,
  352. GLX_GREEN_SIZE , 8,
  353. GLX_BLUE_SIZE , 8,
  354. GLX_ALPHA_SIZE , 8,
  355. GLX_DEPTH_SIZE , 24,
  356. //GLX_STENCIL_SIZE , 8,
  357. GLX_DOUBLEBUFFER , True,
  358. GLX_SAMPLE_BUFFERS , 1,
  359. GLX_SAMPLES , 4,
  360. None
  361. };
  362. int fbcount = -1;
  363. GLXFBConfig* fbconfig = glXChooseFBConfig(MAIN.dpy, DefaultScreen(MAIN.dpy), visual_attribs, &fbcount );
  364. logPrint("glXChooseFBConfig matched %d\n",fbcount);
  365. if (!fbcount){ printf("\n\tno matching visual\n\n"); exit(0); }
  366. MAIN.BestFBC = fbconfig[0];
  367. int sample_buf,samples;
  368. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLE_BUFFERS, &sample_buf);
  369. glXGetFBConfigAttrib(MAIN.dpy, MAIN.BestFBC, GLX_SAMPLES, &samples);
  370. logPrint(" Chosen framebuffer with: %s %d samples\n",sample_buf?"Multisample":"-",samples);
  371. MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
  372. free(fbconfig);
  373. root = DefaultRootWindow(MAIN.dpy);
  374. if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
  375. printf("\n\tcannot create colormap\n\n"); exit(0);
  376. }
  377. swa.colormap = MAIN.cmap;
  378. root = DefaultRootWindow(MAIN.dpy);
  379. win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
  380. int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 4, GLX_CONTEXT_MINOR_VERSION_ARB, 6, 0};
  381. glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  382. if ((MAIN.glc = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, NULL, GL_TRUE, attribs)) == NULL){
  383. printf("\n\tcannot create gl context\n\n"); exit(0);
  384. }
  385. glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
  386. glXMakeCurrent(MAIN.dpy, win, MAIN.glc);
  387. int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
  388. logPrint(" OpenGL Version: %d.%d\n",major,minor);
  389. logPrint(" OpenGL Renderer: %s\n",glGetString(GL_RENDERER));
  390. int err=0;
  391. if((err=glewInit())!=GLEW_OK){
  392. printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
  393. };
  394. MAIN.MsgDelWindow = XInternAtom(MAIN.dpy, "WM_DELETE_WINDOW", 0);
  395. MAIN.bufid = XInternAtom(MAIN.dpy, "CLIPBOARD", False),
  396. MAIN.fmtid = XInternAtom(MAIN.dpy, "UTF8_STRING", False),
  397. MAIN.propid = XInternAtom(MAIN.dpy, "XSEL_DATA", False),
  398. MAIN.incrid = XInternAtom(MAIN.dpy, "INCR", False);
  399. MAIN.targets_atom = XInternAtom(MAIN.dpy, "TARGETS",0);
  400. MAIN.text_atom = XInternAtom(MAIN.dpy, "TEXT", 0);
  401. MAIN.UTF8 = XInternAtom(MAIN.dpy, "UTF8_STRING", 1);
  402. MAIN.selection = XInternAtom(MAIN.dpy, "CLIPBOARD", 0);
  403. if(MAIN.UTF8 == None) MAIN.UTF8 = XA_STRING;
  404. MAIN.wmstate=XInternAtom(MAIN.dpy,"_NET_WM_STATE",1);
  405. MAIN.wmfullscr=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  406. MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
  407. la_GetWorkingDirectoryInternal();
  408. MAIN.SavePreferenceOnExit=1;
  409. MAIN.FontSize = 0.6;
  410. MAIN.UiRowHeight = MAIN.ScaledUiRowHeight =24;
  411. MAIN.UiScale=1;
  412. MAIN.MarginSize = 1;
  413. MAIN.ColorPickerGamma=1.5;
  414. tnsInitRenderKernel(64);
  415. tnsInitBuiltinShaders();
  416. tnsSetuptnsFontManager();
  417. #define LOAD_FONT(font)\
  418. if(!tnsLoadSystemFont(MAIN.SysFontDir, font)) printf("Can't load font \"" font "\"\n");
  419. LOAD_FONT("NotoSansCJK-Regular.ttc");
  420. LOAD_FONT("NotoEmoji-Regular.ttf");
  421. LOAD_FONT("NotoSansSymbols-Regular.ttf");
  422. LOAD_FONT("NotoSansSymbols2-Regular.ttf");
  423. //LOAD_FONT("NotoMusic-Regular.ttf");
  424. //LOAD_FONT("NotoSansEgyptianHieroglyphs-Regular.ttf);
  425. if(!tnsLoadSystemFontMono(MAIN.SysFontDir, "NotoSansMono-Regular.ttf")) printf("Can't load font \"NotoSansMono-Regular.ttf\"\n");;
  426. arrEnsureLength(&MAIN.InputBuf,0,&MAIN.InputBufMax,sizeof(char));
  427. arrEnsureLength(&MAIN.InputBufU,0,&MAIN.InputBufUMax,sizeof(uint32_t));
  428. arrEnsureLength(&MAIN.NodeTypes,0,&MAIN.NodeTypeMax,sizeof(laBaseNode*));
  429. MAIN.InputMapping=memAcquire(sizeof(laRackPageCollection));
  430. MAIN.Drivers=memAcquire(sizeof(laRackPageCollection));
  431. //interactions:
  432. MAIN.TopFramerate = 60;
  433. MAIN.ValuatorThreshold = 8;
  434. MAIN.ScrollingSpeed = 3;
  435. MAIN.AnimationSpeed = 0.4;
  436. MAIN.PanelAnimationSpeed = 0.4;
  437. MAIN.ZoomSpeed2D = 0.01;
  438. MAIN.IdleTime = 0.75;
  439. MAIN.TooltipCloseDistance = 30;
  440. //display:
  441. MAIN.FloatingAlpha = 0.7;
  442. MAIN.SolidShadowLength = 20;
  443. MAIN.WireColorSlices = 16;
  444. MAIN.WireThickness = 5;
  445. MAIN.WireSaggyness = 5;
  446. //timeline:
  447. MAIN.Animation.FrameBegin = 1;
  448. MAIN.Animation.FrameEnd = 250;
  449. MAIN.Animation.Frame = 1;
  450. MAIN.Animation.FrameRate = 25;
  451. MAIN.Animation.FrameStep = 1;
  452. laAddResourceFolder(".");
  453. laAddResourceFolder("/home/yiming/Documents/sync/Projects/2022/nul5/build");
  454. laSetMenuBarTemplates(laui_DefaultMenuButtons, laui_DefaultMenuExtras, "🧩LaGUI 2022");
  455. laAddExtraExtension(LA_FILETYPE_UDF,"udf",0);
  456. la_InitProgressWindow();
  457. la_MakeTranslations();
  458. //tns_RegisterResourcesForSoftwareRender();
  459. la_RegisterGeneralProps();
  460. la_RegisterBuiltinTemplates();
  461. la_RegisterMainThemes();
  462. la_RegisterMainOperators();
  463. la_RegisterMainUiTypes();
  464. la_RegisterModellingOperators();
  465. la_RegisterInternalProps();
  466. la_RegisterWindowKeys();
  467. laFinalizeUiTemplates();
  468. laFinalizeOperators();
  469. la_InitControllers();
  470. la_RegisterControllerProps();
  471. la_RegisterInputMapperOperators();
  472. tns_RegisterNodes();
  473. la_InitThreadEnviornment();
  474. laSetRootInstance(&MAIN);
  475. if(!MAIN.DBInstMemLeft){ hsh65536Init(&MAIN.DBInstMemLeft); }
  476. laPushDifferences(0, 0);
  477. la_MakeDummyManagedUDF();
  478. la_RegenerateWireColors();
  479. logPrint("Initialization Completed\n");
  480. MAIN.InitDone=1;
  481. }
  482. void laShutoff(){
  483. if(MAIN.SavePreferenceOnExit){ laSaveUserPreferences(); }
  484. transDumpMissMatchRecord("TranslationDump.txt");
  485. if(MAIN.Cleanup) MAIN.Cleanup();
  486. strSafeDestroy(&MAIN.WorkingDirectory);
  487. strSafeDestroy(&MAIN.example_string);
  488. la_NoLongerRecordUndo(); //XXX: it's not reliable yet, we need to only remove steps that are consistent with current data structure
  489. // (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. )
  490. laWindow* wi; while(wi=lstPopItem(&MAIN.Windows)){ la_DestroyWindow(wi); }
  491. laUiTemplate* uit; while(uit=lstPopItem(&MAIN.PanelTemplates)){ la_DestroyUiTemplate(uit); }
  492. laCanvasTemplate* u2t; while(u2t=lstPopItem(&MAIN.View2DTemplates)){ la_DestroyCanvasTemplate(u2t); }
  493. laUiType* uit1; while(uit1=lstPopItem(&MAIN.UiTypes)){ la_DestroyUiType(uit1); }
  494. laOperatorType* at; for(int i=0;i<256;i++){ while(at=lstPopItem(&MAIN.OperatorTypeHash.Entries[i])) la_DestroyOperatorType(at); }
  495. laSharedTypeItem* sti; while(sti=lstPopItem(&MAIN.SharedTypePointerSync)){ memFree(sti); }
  496. laKeyMapItem* kmi; while(kmi=lstPopItem(&MAIN.KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  497. laTheme* t; while(t=lstPopItem(&MAIN.Themes)){ la_DestroyTheme(t); }
  498. arrFree(&MAIN.InputBuf,&MAIN.InputBufNext);
  499. arrFree(&MAIN.InputBufU,&MAIN.InputBufUNext);
  500. strSafeDestroy(&MAIN.CopyPending);
  501. la_ClearUDFRegistryAndFolders();
  502. laClearManagedUDF();
  503. laClearSaveProp();
  504. logClear();
  505. tnsQuit();
  506. laPropContainer* pc; while(pc=lstPopItem(&MAIN.PropContainers)){ la_FreePropertyContainer(pc); }
  507. //laPanel* p; while(p=lstPopItem(&MAIN.WastedPanels)){ memFree(p); }
  508. strSafeDump();
  509. hshFree(&MAIN.DBInstMemLeft);
  510. memNoLonger();
  511. glXDestroyContext(MAIN.dpy,MAIN.glc);
  512. }
  513. void laSaveUserPreferences(){
  514. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  515. laUDF* udf=laPrepareUDF(path);
  516. laWriteProp(udf,"la.windows");
  517. laWriteProp(udf,"la.user_preferences");
  518. for(laListItemPointer* lip=MAIN.ExtraPreferencePaths.pFirst;lip;lip=lip->pNext){
  519. laWriteProp(udf,lip->p);
  520. }
  521. laPackUDF(udf,0,0);
  522. }
  523. void laEnsureUserPreferences(){
  524. char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
  525. laUDFRegistry* r=laFindUDFRegistry(path);
  526. if(!r){ laSaveUserPreferences(); return; }
  527. laUDF* udf=laOpenUDF(r->Path->Ptr,1,0,0); if(!udf){ logPrint("Can't read preferences. Using default settings."); return; }
  528. laClearUDFRegistries(); while(MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(MAIN.ResourceFolders.pFirst); }
  529. laExtractUDF(udf,0,LA_UDF_MODE_OVERWRITE,0);
  530. laCloseUDF(udf);
  531. }
  532. void laAddExtraExtension(int FileType, ...){
  533. va_list list; va_start(list,FileType);
  534. char* ext;
  535. while(ext=va_arg(list,char*)){ if(!ext) break;
  536. laExtensionType* et=memAcquireSimple(sizeof(laExtensionType));
  537. et->FileType=FileType; et->Extension=ext;
  538. lstAppendItem(&MAIN.ExtraExtensions, et);
  539. }
  540. va_end(list);
  541. }
  542. void laAddExtraPreferencePath(const char* path){
  543. if(!path) return;
  544. lstAppendPointer(&MAIN.ExtraPreferencePaths, path);
  545. }
  546. void laAddExtraPreferencePage(const char* name, laUiDefineFunc Func){
  547. if(!name || !Func) return;
  548. laExtraPreferencePage*epp=memAcquireSimple(sizeof(laExtraPreferencePage));
  549. epp->Name=name; epp->Func=Func; lstAppendItem(&MAIN.ExtraPreferencePages,epp);
  550. }
  551. void laSetMenuBarTemplates(laUiDefineFunc MenuButtons, laUiDefineFunc MenuExtras, const char* ProgramName){
  552. MAIN.MenuButtons=MenuButtons; MAIN.MenuExtras=MenuExtras; MAIN.MenuProgramName=ProgramName;
  553. }
  554. void laSetAboutTemplates(laUiDefineFunc AboutContent, laUiDefineFunc AboutVersion, laUiDefineFunc AboutAuthor){
  555. MAIN.AboutAuthor=AboutAuthor; MAIN.AboutVersion=AboutVersion; MAIN.AboutContent=AboutContent;
  556. }
  557. void laSetPreferenceTemplates(laUiDefineFunc PreferencePageDisplay, laUiDefineFunc PreferencePageInput, laUiDefineFunc PreferencePageResource, laUiDefineFunc PreferencePageTheme){
  558. MAIN.PreferencePageDisplay=PreferencePageDisplay; MAIN.PreferencePageInput=PreferencePageInput;
  559. MAIN.PreferencePageResource=PreferencePageResource; MAIN.PreferencePageTheme=PreferencePageTheme;
  560. }
  561. //MSG====================================================
  562. int la_IsThisSysWindow(laWindow *wnd, Window hwnd){
  563. if (wnd->win == hwnd) return 1;
  564. else return 0;
  565. };
  566. void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
  567. if (p->SL){ int s=p->SL<0?0:p->SL;
  568. if (p->TX != s) laRecalcPanel(p);
  569. p->TX = s;
  570. }
  571. if (p->SR){ int s=p->SR<0?0:p->SR;
  572. if (p->TW != CW - p->TX - s) laRecalcPanel(p);
  573. p->TW = CW - p->TX - s;
  574. }
  575. if (p->ST){ int s=p->ST<0?0:p->ST;
  576. if (p->TY != s) laRecalcPanel(p);
  577. p->TY = s;
  578. }
  579. if (p->SB){ int s=p->SB<0?0:p->SB;
  580. if (p->TH != CH - p->TY - s) laRecalcPanel(p);
  581. p->TH = CH - p->TY - s;
  582. }
  583. }
  584. void la_RecalcBlockRecursive(laBlock *b, int X, int Y, int W, int H){
  585. laPanel *p = 0;
  586. b->X = X;
  587. b->Y = Y;
  588. b->W = W;
  589. b->H = H;
  590. if (b->B1){
  591. int SplitWidth;
  592. if (b->Vertical){
  593. SplitWidth = H * b->SplitRatio;
  594. la_RecalcBlockRecursive(b->B1, X, Y, W, SplitWidth);
  595. la_RecalcBlockRecursive(b->B2, X, Y + SplitWidth, W, H - SplitWidth);
  596. }else{
  597. SplitWidth = W * b->SplitRatio;
  598. la_RecalcBlockRecursive(b->B1, X, Y, SplitWidth, H);
  599. la_RecalcBlockRecursive(b->B2, X + SplitWidth, Y, W - SplitWidth, H);
  600. }
  601. }
  602. //if (!b->CurrentPanel)b->CurrentPanel = b->Panels.pFirst;
  603. for(p=b->Panels.pFirst;p;p=p->Item.pNext){
  604. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  605. }
  606. if (p = b->CurrentPanel){
  607. int TitleGap=b->Folded?0:LA_RH;
  608. p->X = X + LA_SEAM_W; p->Y = Y + LA_SEAM_W + TitleGap;
  609. p->TX = X + LA_SEAM_W; p->TY = Y + LA_SEAM_W + TitleGap;
  610. p->TW = W - LA_SEAM_W*2; p->TH = H - LA_SEAM_W*2 - TitleGap;
  611. laRecalcPanel(p);
  612. }
  613. }
  614. void la_UpdateUiPlacement(laWindow *w){
  615. laLayout *l;
  616. laPanel *p;
  617. int CW = w->CW;
  618. int CH = w->CH;
  619. laBoxedTheme* bt = _LA_THEME_FLOATING_PANEL;
  620. int MenuHeight=(bt->TM+bt->BM)*2+LA_RH;
  621. if(w->MaximizedUi && w->MaximizedUiPanel){
  622. laRecalcPanel(w->MaximizedUiPanel);
  623. }elif(w->MaximizedBlock){
  624. la_RecalcBlockRecursive(w->MaximizedBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  625. }else{
  626. for (l = w->Layouts.pFirst; l; l = l->Item.pNext){
  627. la_RecalcBlockRecursive(l->FirstBlock, -LA_SEAM_W, MenuHeight, CW+LA_SEAM_W*2, CH-MenuHeight+LA_SEAM_W);
  628. }
  629. }
  630. for (p = w->Panels.pFirst; p; p = p->Item.pNext){
  631. if(p->IsMenuPanel){
  632. p->TH=p->H=MenuHeight;
  633. }
  634. la_EnsurePanelSnapping(p, CW, CH);
  635. laRecalcPanel(p);
  636. }
  637. }
  638. void la_CommandResizeWindow(Window hwnd, int x, int y, int w, int h){
  639. laWindow *window = lstFindItem(hwnd, la_IsThisSysWindow, &MAIN.Windows);
  640. if (!window) return;
  641. XWindowAttributes attr;
  642. XGetWindowAttributes(MAIN.dpy, window->win, &attr);
  643. window->CW = w; window->CH = h;
  644. window->W = w; window->H = h;
  645. window->X = x; window->Y = y;
  646. la_UpdateUiPlacement(window);
  647. }
  648. int la_OnWindowDestroy(Window wnd){
  649. laListHandle *hlst = &MAIN.Windows;
  650. laWindow *w = lstFindItem(wnd, la_IsThisSysWindow, hlst);
  651. if (!w) return 0;
  652. if (MAIN.Windows.pFirst==MAIN.Windows.pLast){
  653. int empty=0; int mod=laRegisterModifications(1,1,&empty,0);
  654. if(mod || empty){ laInvoke(0, "LA_managed_save", 0,0,"on_exit=true;",0); return 0; }
  655. laShutoff();
  656. return 1;
  657. }
  658. laListHandle h={0};laLayout*l=0;
  659. while(l=lstPopItem(&w->Layouts)){ lstAppendItem(&h, l); }
  660. la_DestroyWindow(w);
  661. int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  662. if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
  663. else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done=1; while(l=lstPopItem(&h)){ lstAppendItem(&w->Layouts, l); } }
  664. }
  665. return 0;
  666. }
  667. void la_MakeSpecialKeyBit(Window hwnd,laWindow*wnd,laEvent *e,int use_last_pos){
  668. laListHandle *el = &wnd->EventList;
  669. laEvent* last_e=el->pLast;
  670. Window root_ret, win_ret; int rrx=0,rry=0,rx=e->x,ry=e->y,rmask=0;
  671. XQueryPointer(MAIN.dpy, wnd->win, &root_ret,&win_ret,&rrx,&rry,&rx,&ry,&rmask);
  672. e->SpecialKeyBit = ((rmask&ShiftMask)?LA_KEY_SHIFT:0)|((rmask&ControlMask)?LA_KEY_CTRL:0)|((rmask&Mod1Mask)?LA_KEY_ALT:0);
  673. }
  674. void la_SaveEvent(Window hwnd, laEvent *e, int use_last_pos){
  675. laListHandle *wl = &MAIN.Windows;
  676. laWindow* wnd = lstFindItem(hwnd, la_IsThisSysWindow, wl);
  677. if (!wnd){ memFree(e); return; }
  678. laListHandle *el = &wnd->EventList;
  679. la_MakeSpecialKeyBit(hwnd,wnd,e,use_last_pos);
  680. if(use_last_pos){ e->x=MAIN.evLastX; e->y=MAIN.evLastY; }
  681. e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
  682. e->AngleX=rad(MAIN.PointerIsEraser?MAIN.EraserAngleX:MAIN.StylusAngleX);
  683. e->AngleY=rad(MAIN.PointerIsEraser?MAIN.EraserAngleY:MAIN.StylusAngleY);
  684. e->IsEraser=MAIN.PointerIsEraser;
  685. lstAppendItem(el, (laListItem *)e);
  686. laMappingRequestEval();
  687. };
  688. void la_SendKeyboardEvent(Window hwnd, int type, int key){
  689. laEvent *e = memAcquireSimple(sizeof(laEvent)); e->Type = type; e->key = key;
  690. la_SaveEvent(hwnd, e, 1);
  691. };
  692. void la_SendInputEvent(Window hwnd, uint32_t Input){
  693. laEvent *e = memAcquireSimple(sizeof(laEvent));
  694. e->Type = LA_INPUT; e->Input=Input;
  695. la_SaveEvent(hwnd, e, 1);
  696. }
  697. void la_SendEmptyEvent(Window hwnd){
  698. laEvent *e = memAcquireSimple(sizeof(laEvent));
  699. e->Type = LA_EMPTY;
  700. la_SaveEvent(hwnd, e, 1);
  701. }
  702. void laSendOperatorTriggerEvent(){
  703. if (MAIN.ReTriggerOperators) la_SendEmptyEvent(MAIN.CurrentWindow->win);
  704. MAIN.ReTriggerOperators = 0;
  705. }
  706. int la_TranslateSpecialKey(int keysym){
  707. switch(keysym){
  708. case XK_Return: return LA_KEY_ENTER;
  709. case XK_BackSpace: return LA_KEY_BACKSPACE;
  710. case XK_Delete: return LA_KEY_DELETE;
  711. case XK_Escape: return LA_KEY_ESCAPE;
  712. case XK_Tab: return LA_KEY_TAB;
  713. case XK_Left: return LA_KEY_ARRLEFT;
  714. case XK_Right: return LA_KEY_ARRRIGHT;
  715. case XK_Up: return LA_KEY_ARRUP;
  716. case XK_Down: return LA_KEY_ARRDOWN;
  717. case XK_Control_L: return LA_KEY_CTRL;
  718. case XK_Control_R: return LA_KEY_CTRL;
  719. case XK_Shift_L: return LA_KEY_SHIFT;
  720. case XK_Shift_R: return LA_KEY_SHIFT;
  721. case XK_Alt_L: return LA_KEY_ALT;
  722. case XK_Alt_R: return LA_KEY_ALT;
  723. default: return keysym;
  724. }
  725. }
  726. void la_SendMouseEvent(Window hwnd, int type, int x, int y){
  727. //if((type&LA_STATE_DOWN)&&(x!=MAIN.evLastX || y!=MAIN.evLastY)){
  728. // laEvent *e = memAcquireSimple(sizeof(laEvent));
  729. // e->Type = LA_MOUSEMOVE; e->x = x; e->y = y;
  730. // la_SaveEvent(hwnd, e, 0);
  731. //}
  732. laEvent *e = memAcquireSimple(sizeof(laEvent));
  733. e->Type = type; e->x = x; e->y = y;
  734. la_SaveEvent(hwnd, e, 0);
  735. MAIN.evLastX=x; MAIN.evLastY=y;
  736. };
  737. void la_SendTimerEvent(Window hwnd, int type){
  738. laEvent *e = memAcquireSimple(sizeof(laEvent));
  739. e->Type = type;
  740. la_SaveEvent(hwnd, e, 1);
  741. };
  742. void laRetriggerOperators(){
  743. MAIN.ReTriggerOperators = 1;
  744. }
  745. void laSetFrameCallbacks(laPreFrameF PreFrame, laPreDrawF PreDraw, laPostFrameF PostFrame){
  746. MAIN.PreFrame=PreFrame; MAIN.PreDraw=PreDraw; MAIN.PostFrame=PostFrame;
  747. }
  748. void laSetCleanupCallback(laCleanupF Cleanup){
  749. MAIN.Cleanup=Cleanup;
  750. }
  751. //====================================================================================================
  752. void la_DestroyTheme(laTheme* t){
  753. laBoxedTheme*bt; while(bt=lstPopItem(&t->BoxedThemes)){ strSafeDestroy(&bt->Name); *bt->BackRef=0; memFree(bt); }
  754. strSafeDestroy(&t->Name);
  755. strSafeDestroy(&t->Author);
  756. }
  757. laTheme *laDesignTheme(const char *Name, const char *AuthorName){
  758. laTheme *t = memAcquireHyper(sizeof(laTheme));
  759. strSafeSet(&t->Name, Name);
  760. strSafeSet(&t->Author, AuthorName);
  761. lstAppendItem(&MAIN.Themes, t);
  762. MAIN.CurrentTheme = t;
  763. return t;
  764. }
  765. laBoxedTheme *laDesignBoxedTheme(laTheme *t, const char *Name, laBoxedTheme** BackRef,
  766. real NormalY,real ActiveY,real BorderY,real TextY,real TextActiveY, real Alpha,
  767. real LeftMargin, real RightMargin, real TopMargin, real BottomMargin,
  768. real LeftPadding, real RightPadding, real TopPadding, real BottomPadding){
  769. laBoxedTheme *bt = memAcquire(sizeof(laBoxedTheme));
  770. strSafeSet(&bt->Name, Name);
  771. bt->NormalY=NormalY;
  772. bt->ActiveY=ActiveY;
  773. bt->BorderY=BorderY;
  774. bt->TextY=TextY; bt->TextActiveY=TextActiveY; bt->Alpha = Alpha;
  775. bt->Margins[0] = LeftMargin; bt->Margins[1] = RightMargin; bt->Margins[2] = TopMargin; bt->Margins[3] = BottomMargin;
  776. bt->Paddings[0] = LeftPadding; bt->Paddings[1] = RightPadding; bt->Paddings[2] = TopPadding; bt->Paddings[3] = BottomPadding;
  777. bt->BackRef = BackRef;
  778. lstAppendItem(&t->BoxedThemes, bt);
  779. return bt;
  780. }
  781. laTheme *laGetTheme(const char *ThemeName){
  782. laTheme *t = MAIN.Themes.pFirst;
  783. for (t; t; t = t->Item.pNext){
  784. if (strSame(t->Name->Ptr, ThemeName)) return t;
  785. }
  786. return 0;
  787. }
  788. laBoxedTheme *laGetBoxedTheme(const char *ThemeName, const char *BoxName){
  789. laTheme *t = MAIN.Themes.pFirst;
  790. for (t; t; t = t->Item.pNext){
  791. laBoxedTheme *bt;
  792. if (!strSame(t->Name->Ptr, ThemeName)) continue;
  793. bt = t->BoxedThemes.pFirst;
  794. for (bt; bt; bt = bt->Item.pNext){
  795. if (strSame(bt->Name->Ptr, BoxName)) return bt;
  796. }
  797. }
  798. return 0;
  799. }
  800. real* laThemeColor(laBoxedTheme* bt, int which){
  801. switch(which){
  802. default:
  803. case LA_BT_NORMAL: return bt->Normal;
  804. case LA_UI_EDITING:
  805. case LA_BT_ACTIVE: return bt->Active;
  806. case LA_BT_BORDER: return bt->Border;
  807. case LA_BT_TEXT: return bt->Text; break;
  808. case LA_BT_TEXT_ACTIVE: return bt->TextActive; break;
  809. case LA_BT_DISABLED: return bt->Inactive; break;
  810. case LA_BT_DISABLED|LA_BT_TEXT: return bt->TextInactive; break;
  811. }
  812. return bt->Normal;
  813. }
  814. real* laAccentColor(int which){
  815. switch(which){
  816. default:
  817. case LA_BT_NORMAL: case LA_UI_EDITING: case LA_BT_ACTIVE: return MAIN.CurrentTheme->SelectionColor;
  818. case LA_BT_BORDER: case LA_BT_TEXT: case LA_BT_TEXT_ACTIVE: return MAIN.CurrentTheme->CursorColor;
  819. case LA_BT_VERTEX: return MAIN.CurrentTheme->VertexColor;
  820. case LA_BT_FACE:
  821. case LA_BT_EDGE: return MAIN.CurrentTheme->EdgeColor;
  822. case LA_BT_SVERTEX: return MAIN.CurrentTheme->SVertexColor;
  823. case LA_BT_SEDGE: return MAIN.CurrentTheme->SEdgeColor;
  824. case LA_BT_SFACE: return MAIN.CurrentTheme->SFaceColor;
  825. }
  826. return MAIN.CurrentTheme->SelectionColor;
  827. }
  828. void la_RefreshBoxedThemeColor(laBoxedTheme* bt){
  829. real hcy[3];
  830. tnsRGB2HCY(MAIN.CurrentTheme->Color,hcy);
  831. hcy[2]=bt->NormalY; tnsHCY2RGB(hcy, bt->Normal); bt->Normal[3]=bt->Alpha;
  832. hcy[2]=bt->ActiveY; tnsHCY2RGB(hcy, bt->Active); bt->Active[3]=bt->Alpha;
  833. hcy[2]=bt->BorderY; tnsHCY2RGB(hcy, bt->Border); bt->Border[3]=1;
  834. hcy[2]=bt->TextY; tnsHCY2RGB(hcy, bt->Text); bt->Text[3]=1;
  835. hcy[2]=bt->TextActiveY; tnsHCY2RGB(hcy, bt->TextActive); bt->TextActive[3]=1;
  836. int *tm=&bt->LM,*tp=&bt->LP;
  837. for(int i=0;i<4;i++){
  838. tm[i]=bt->Margins[i]*LA_RH*MAIN.MarginSize;
  839. tp[i]=bt->Paddings[i]*LA_RH*MAIN.MarginSize;
  840. }
  841. }
  842. void la_RefreshThemeColorSelf(laTheme* th){
  843. tnsVectorCopy3d(th->AccentColor, th->CursorColor); th->CursorColor[3]=th->CursorAlpha;
  844. tnsVectorCopy3d(th->AccentColor, th->SelectionColor);th->SelectionColor[3]=th->SelectionAlpha;
  845. real hcy[3], usehcy[3];
  846. tnsRGB2HCY(th->Color,hcy); tnsVectorCopy3d(hcy,usehcy);
  847. usehcy[2]=th->VertexBrightness; tnsHCY2RGB(usehcy, th->VertexColor); th->VertexColor[3]=th->VertexTransparency;
  848. usehcy[2]=th->EdgeBrightness; tnsHCY2RGB(usehcy, th->EdgeColor); th->EdgeColor[3]=th->EdgeTransparency;
  849. tnsVectorCopy3d(th->AccentColor, th->SVertexColor); th->SVertexColor[3]=th->SelectedVertexTransparency;
  850. tnsVectorCopy3d(th->AccentColor, th->SEdgeColor); th->SEdgeColor[3]=th->SelectedEdgeTransparency;
  851. tnsVectorCopy3d(th->AccentColor, th->SFaceColor); th->SFaceColor[3]=th->SelectedFaceTransparency;
  852. }
  853. void la_RefreshThemeColor(laTheme* th){
  854. real hcy[3], usehcy[3], normalhcy[3];
  855. tnsRGB2HCY(th->Color,hcy);
  856. la_RefreshThemeColorSelf(th);
  857. for(laBoxedTheme* bt = th->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){
  858. la_RefreshBoxedThemeColor(bt);
  859. (*bt->BackRef) = bt;
  860. tnsRGB2HCY(bt->Text, usehcy); usehcy[1]*=th->InactiveSaturation;
  861. tnsHCY2RGB(usehcy, bt->TextInactive); bt->TextInactive[3]=th->InactiveMix;
  862. tnsRGB2HCY(bt->Normal, normalhcy); normalhcy[1]*=th->InactiveSaturation;
  863. tnsHCY2RGB(normalhcy, bt->Inactive); bt->Inactive[3]=bt->Alpha*th->InactiveMix;
  864. }
  865. }
  866. //I FUCKING HATE THIS STUPID FUNCTION
  867. int la_SetUpUiListMatrix(laUiListDraw *uild, laUiList *Target, int _L, int _R, int LimH, int PanelH, int GlobalX, int GlobalY){
  868. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  869. laUiListDrawItem *last = uild->Items.pFirst;
  870. int LimW=_R-_L;
  871. int SL, SR, SU, SB;
  872. int Target__B = Target->B;
  873. int Target__R = Target->R;
  874. uildi->Target = Target;
  875. //if (Target__B - Target->U > LimH) Target__B = Target->U + LimH;
  876. if (Target__R - Target->L > LimW) Target__R = Target->L + LimW;
  877. uildi->XP = last ? last->XP + Target->PanX : Target->PanX;
  878. uildi->YP = last ? last->YP + Target->PanY : Target->PanY;
  879. uildi->L = last ? Target->L - last->XP : Target->L;
  880. uildi->R = last ? Target__R - last->XP : Target__R;
  881. uildi->U = last ? Target->U - last->YP : Target->U;
  882. uildi->B = last ? Target__B - last->YP : Target__B;
  883. if (uildi->B - uildi->U > LimH) uildi->B = Target->U + LimH;
  884. uildi->L -= GlobalX;
  885. uildi->R -= GlobalX;
  886. uildi->U -= GlobalY;
  887. uildi->B -= GlobalY;
  888. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  889. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  890. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  891. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  892. uildi->DifX = SL - uildi->L;
  893. uildi->DifY = SU - uildi->U;
  894. uildi->L = SL;
  895. uildi->R = SR+uildi->DifX;
  896. uildi->U = SU;
  897. uildi->B = SB;//+uildi->DifY;
  898. if(uildi->R>_R){ uildi->R=_R; }
  899. if(uildi->B-SU>LimH){ uildi->B=SU+LimH; }
  900. //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);
  901. if(uildi->R - uildi->L<=0 || uildi->B - uildi->U<=0){
  902. memFree(uildi);
  903. return 0;
  904. }
  905. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  906. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  907. Target->L + Target->PanX + uildi->DifX +1+ (uildi->R - uildi->L),
  908. Target->U + Target->PanY + uildi->DifY +1+ (uildi->B - uildi->U),
  909. Target->U + Target->PanY + uildi->DifY -1,
  910. -100, 100);
  911. lstPushItem(&uild->Items, uildi);
  912. return 1;
  913. }
  914. void la_SetUpUiListMatrixInLine(laUiListDraw *uild, int L, int R, int U, int B, int PanX, int PanY, int LimH, int PanelH){
  915. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  916. laUiListDrawItem *last = uild->Items.pFirst;
  917. int SL, SR, SU, SB;
  918. if (B - U > LimH) B = U + LimH;
  919. uildi->XP = last ? last->XP + PanX : PanX;
  920. uildi->YP = last ? last->YP + PanY : PanY;
  921. uildi->L = last ? L - last->XP : L;
  922. uildi->R = last ? R - last->XP : R;
  923. uildi->U = last ? U - last->YP : U;
  924. uildi->B = last ? B - last->YP : B;
  925. SL = last ? (uildi->L < last->L ? last->L : uildi->L) : uildi->L;
  926. SR = last ? (uildi->R > last->R ? last->R : uildi->R) : uildi->R;
  927. SU = last ? (uildi->U < last->U ? last->U : uildi->U) : uildi->U;
  928. SB = last ? (uildi->B > last->B ? last->B : uildi->B) : uildi->B;
  929. uildi->DifX = SL - uildi->L;
  930. uildi->DifY = SU - uildi->U;
  931. uildi->L = SL;
  932. uildi->R = SR;
  933. uildi->U = SU;
  934. uildi->B = SB;
  935. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  936. tnsOrtho(L + PanX + uildi->DifX,
  937. L + PanX + uildi->DifX + (uildi->R - uildi->L),
  938. U + PanY + uildi->DifY + (uildi->B - uildi->U),
  939. U + PanY + uildi->DifY,
  940. -100, 100);
  941. lstPushItem(&uild->Items, uildi);
  942. }
  943. void la_RebuildCurrentUiListMatrix(laUiListDraw *uild, laUiList *Target, int LimH, int PanelH){
  944. laUiListDrawItem *uildi = uild->Items.pFirst;
  945. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  946. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  947. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  948. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  949. Target->U + Target->PanY + uildi->DifY -1,
  950. -100, 100);
  951. }
  952. void la_RestoreLastUiListMatrix(laUiListDraw *uild, int PanelH){
  953. laUiListDrawItem *uildi = lstPopItem(uild);
  954. laUiList *Target;
  955. memFree(uildi);
  956. uildi = uild->Items.pFirst;
  957. if (!uildi || !uildi->Target){
  958. if (uild->Items.pFirst) la_RestoreLastUiListMatrix(uild, PanelH);
  959. return;
  960. }
  961. Target = uildi->Target;
  962. tnsViewportWithScissor(uildi->L-1, PanelH - uildi->B-1, uildi->R - uildi->L+2, uildi->B - uildi->U+2);
  963. tnsOrtho(Target->L + Target->PanX + uildi->DifX -1,
  964. Target->L + Target->PanX + uildi->DifX +1 + (uildi->R - uildi->L),
  965. Target->U + Target->PanY + uildi->DifY +1 + (uildi->B - uildi->U),
  966. Target->U + Target->PanY + uildi->DifY -1,
  967. -100, 100);
  968. }
  969. void la_SetupUiListLimitMatrix(laUiListDraw *uild, int L, int R, int U, int B, int PanelH){
  970. laUiListDrawItem *uildi = memAcquireSimple(sizeof(laUiListDrawItem));
  971. uildi->L = L;
  972. uildi->R = R;
  973. uildi->U = U;
  974. uildi->B = B;
  975. tnsViewportWithScissor(uildi->L, PanelH - uildi->B, uildi->R - uildi->L, uildi->B - uildi->U);
  976. tnsOrtho(L, R, B, U, -100, 100);
  977. lstPushItem(&uild->Items, uildi);
  978. }
  979. void la_ClearUiListMatrix(laUiListDraw *uild){
  980. laUiListDrawItem *uildi;
  981. while (uildi = lstPopItem(uild)){
  982. memFree(uildi);
  983. }
  984. }
  985. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel);
  986. 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);
  987. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser);
  988. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR);
  989. int la_TestUiListMinumWidth(laUiList *uil);
  990. void la_PanelValidateWidth(laPanel *p, laUiList *ui){
  991. if (ui){
  992. if (p->MaxW && p->TW > p->MaxW) p->TW = p->MaxW;
  993. if (p->MinW && p->TW < p->MinW) p->TW = p->MinW;
  994. la_EnsurePanelSnapping(p, MAIN.CurrentWindow->CW, MAIN.CurrentWindow->CH);
  995. p->X = p->TX; p->Y = p->TY;
  996. p->W = p->TW;
  997. }
  998. }
  999. void laEnsurePanelInBound(laPanel *p, laUiList *uil){
  1000. int cw = MAIN.CurrentWindow->CW;
  1001. int ch = MAIN.CurrentWindow->CH;
  1002. int PH = p->TH;
  1003. laBoxedTheme*bt = *p->BT;
  1004. int uih=uil->B + bt->TM+bt->BM;
  1005. if (p->BoundUi && !(p->SB||p->ST)) PH = TNS_MAX2(uih, p->MinH);
  1006. if (p->MaxH && PH > p->MaxH) p->TH = p->MaxH;
  1007. else if (p->MinH && PH < p->MinH) p->TH = p->MinH;
  1008. else p->TH = PH;
  1009. p->H = p->TH;
  1010. if ((p->X + p->W) > cw){
  1011. p->X -= (p->X + p->W - cw);
  1012. }
  1013. if ((p->Y + p->H) > ch){
  1014. p->Y -= (p->Y + p->H - ch);
  1015. }
  1016. if (p->X < 0) p->X = 0;
  1017. if (p->Y < 0) p->Y = 0;
  1018. if ((p->X + p->W) > cw){
  1019. p->W -= (p->X + p->W - cw);
  1020. }
  1021. if ((p->Y + p->H) > ch){
  1022. p->H -= (p->Y + p->H - ch);
  1023. }
  1024. if (p->ST) p->TY = p->ST;
  1025. if (p->SB && p->TH != ch - p->TY - p->SB) laRecalcPanel(p);
  1026. if (p->SB) p->TH = ch - p->TY - p->SB;
  1027. if(p->CloseWhenMovedOut==2){ p->X=(cw-p->W)/2; p->Y=(ch-p->H)/2; }
  1028. p->TX = p->X; p->TY = p->Y;
  1029. p->TW = p->W; p->TH = p->H;
  1030. if (p->OffScr &&
  1031. (p->W != p->OffScr->pColor[0]->Width ||
  1032. p->H != p->OffScr->pColor[0]->Height)){
  1033. tnsConfigureOffscreen(p->OffScr, p->W,p->H);
  1034. }
  1035. }
  1036. void la_SetPanelMatrix(laPanel *p, laBoxedTheme *bt){
  1037. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1038. tnsViewportWithScissor(0, 0, p->W, p->H);
  1039. //tnsMatrixMode(TNS_PROJECTION_MATRIX);
  1040. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1041. }
  1042. void la_SetPanelMatrixDrawWindow(laPanel *p, laBoxedTheme *bt){
  1043. tnsDrawToScreen();
  1044. tnsViewportWithScissor(p->X, MAIN.CurrentWindow->CH - p->H - p->Y, p->W, p->H);
  1045. tnsOrtho(0, p->W, p->H, 0, -100, 100);
  1046. }
  1047. void la_SetPanelMatrixLRTB(int PW, int PH, int LPadding, int RPadding, int TPadding, int BPadding, int XOffset, int YOffset){
  1048. tnsViewportWithScissor(LPadding, BPadding, PW - LPadding - RPadding, PH - TPadding - BPadding);
  1049. tnsOrtho(XOffset, XOffset + PW - LPadding - RPadding, YOffset + PH - BPadding, YOffset + TPadding, -100, 100);
  1050. }
  1051. void la_PanelBackgroundInit(laPanel *p, laBoxedTheme *bt){
  1052. glClearColor(LA_COLOR4(laThemeColor(bt,LA_BT_NORMAL)));
  1053. tnsClearAll();
  1054. }
  1055. void la_PanelDrawToWindow(laPanel *p, laWindow *w){
  1056. real Color[] = {1, 1, 1, 1};
  1057. real L, W, U, H;
  1058. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  1059. tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
  1060. switch (p->AnimationMode){
  1061. case 0:
  1062. tnsDraw2DTextureDirectly(p->OffScr->pColor[0], p->X, p->Y, p->W, p->H);
  1063. if(p->ShowCorner && ((!p->SR) && (!p->SB))){ tnsDrawStringAuto("◢",laThemeColor(_LA_THEME_PANEL,LA_BT_TEXT),p->X+p->W-LA_RH,p->X+p->W,p->Y+p->H-LA_RH,0); }
  1064. //if(p->Mode==LA_PANEL_FLOATING_TOP)
  1065. // tnsDrawStringAuto("◿",laThemeColor(*p->BT,LA_BT_BORDER),p->X+p->W-LA_RH, p->X+p->W, p->H+p->Y-LA_RH, LA_TEXT_ALIGN_CENTER);
  1066. break;
  1067. case LA_PANEL_ANIMATION_DROP_DOWN:
  1068. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1069. tnsDraw2DTextureArg(
  1070. p->OffScr->pColor[0],
  1071. p->X, p->Y, p->W, p->H * p->AnimationRatio,
  1072. Color,
  1073. 0, 0, 1 - p->AnimationRatio, 0);
  1074. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1075. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  1076. break;
  1077. case LA_PANEL_ANIMATION_EXPAND:
  1078. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1079. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1080. W = tnsLinearItp(0, p->W, 0.4);
  1081. H = tnsLinearItp(0, p->H, 0.4);
  1082. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1083. tnsDraw2DTextureArg(
  1084. p->OffScr->pColor[0],
  1085. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1086. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1087. Color,
  1088. 0, 0, 0, 0);
  1089. p->AnimationRatio += (1 - p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1090. if (p->AnimationRatio > 0.99) p->AnimationMode = 0; laRefreshWindow();
  1091. break;
  1092. case LA_PANEL_ANIMATION_DISSOVE:
  1093. L = tnsLinearItp(p->X, p->X + p->W, -0.2);
  1094. U = tnsLinearItp(p->Y, p->Y + p->H, -0.2);
  1095. W = tnsLinearItp(0, p->W, 1.4);
  1096. H = tnsLinearItp(0, p->H, 1.4);
  1097. tnsVectorMultiSelf4d(Color, (p->AnimationRatio));
  1098. if (p->OffScr) tnsDraw2DTextureArg(
  1099. p->OffScr->pColor[0],
  1100. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1101. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1102. Color,
  1103. 0, 0, 0, 0);
  1104. p->AnimationRatio -= (p->AnimationRatio) * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1105. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1106. break;
  1107. case LA_PANEL_ANIMATION_COLLAPSE:
  1108. L = tnsLinearItp(p->X, p->X + p->W, 0.3);
  1109. U = tnsLinearItp(p->Y, p->Y + p->H, 0.3);
  1110. W = tnsLinearItp(0, p->W, 0.4);
  1111. H = tnsLinearItp(0, p->H, 0.4);
  1112. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1113. if (p->OffScr) tnsDraw2DTextureArg(
  1114. p->OffScr->pColor[0],
  1115. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1116. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1117. Color,
  1118. 0, 0, 0, 0);
  1119. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1120. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1121. break;
  1122. case LA_PANEL_ANIMATION_MINIMIZE:
  1123. L = tnsLinearItp(0, p->X, 0.3);
  1124. U = tnsLinearItp(w->H, p->Y + p->H, 0.3);
  1125. W = tnsLinearItp(0, p->W, 0.4);
  1126. H = tnsLinearItp(0, p->H, 0.4);
  1127. tnsVectorMultiSelf4d(Color, p->AnimationRatio);
  1128. tnsDraw2DTextureArg(
  1129. p->OffScr->pColor[0],
  1130. tnsLinearItp(L, p->X, p->AnimationRatio), tnsLinearItp(U, p->Y, p->AnimationRatio),
  1131. tnsLinearItp(W, p->W, p->AnimationRatio), tnsLinearItp(H, p->H, p->AnimationRatio),
  1132. Color,
  1133. 0, 0, 0, 0);
  1134. p->AnimationRatio -= p->AnimationRatio * MAIN.PanelAnimationSpeed * MAIN.LastFrameTime * 60;
  1135. if (p->AnimationRatio < 0.01) p->AnimationMode = 0; laRefreshWindow();
  1136. break;
  1137. }
  1138. tnsFlush();
  1139. tnsUniformOutputColorSpace(T->immShader,0);
  1140. tnsUniformShowColorOverflowStripes(T->immShader,0);
  1141. }
  1142. void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
  1143. laEnsurePanelInBound(p,p->MenuRefer?p->MenuRefer:&p->UI);
  1144. if (!p->OffScr){
  1145. int GLFormat=(p->PanelTemplate&&p->PanelTemplate->DefaultGLFormat)?p->PanelTemplate->DefaultGLFormat:GL_RGBA8;
  1146. p->OffScr = tnsCreate2DOffscreen(GLFormat, p->W, p->H, MAIN.PanelMultisample, 0);
  1147. }
  1148. tnsDrawToOffscreen(p->OffScr, 1, 0);
  1149. }
  1150. void la_PanelRefreshDetachedProp(laPanel *panel){
  1151. laProp *p;
  1152. for (p = panel->PropLinkContainer->Props.pFirst; p; p = p->Item.pNext){
  1153. la_StepPropPack(&p->DetachedPP);
  1154. la_UsePropPack(&p->DetachedPP, 0);
  1155. //if (p->DetachedPP.LastPs && p->DetachedPP.LastPs->p->Container ? p->DetachedPP.LastPs->p->Container->Hyper : 0){
  1156. // laUseDataBlock(
  1157. // p->DetachedPP.LastPs->UseInstance,
  1158. // p->DetachedPP.LastPs->p,
  1159. // MAIN.PropMatcherContextP->FrameDistinguish,
  1160. // MAIN.PropMatcherContextP,
  1161. // la_PropPanelUserRemover, 0);
  1162. //}
  1163. }
  1164. }
  1165. void la_PanelDrawDescendBorder(laPanel *Panel, laBoxedTheme *bt, int Width, real Alpha){
  1166. real* color=laThemeColor(bt,LA_BT_BORDER);
  1167. tnsColor4d(0,0,0,Alpha);
  1168. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H);
  1169. tnsVertex2d(Panel->X + Width, Panel->Y + Panel->H + Width);
  1170. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  1171. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Panel->H + Width);
  1172. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Width);
  1173. tnsVertex2d(Panel->X + Panel->W + Width, Panel->Y + Width);
  1174. tnsPackAs(GL_TRIANGLE_STRIP);
  1175. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1176. tnsVertex2d(Panel->X, Panel->Y);
  1177. tnsVertex2d(Panel->X, Panel->Y + Panel->H);
  1178. tnsVertex2d(Panel->X + Panel->W, Panel->Y + Panel->H);
  1179. tnsVertex2d(Panel->X + Panel->W, Panel->Y);
  1180. tnsPackAs(GL_LINE_LOOP);
  1181. }
  1182. int la_AnimateUiListRecursive(laUiList *uil);
  1183. void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
  1184. int DrawState_ = 0;
  1185. laUiListDraw uild = {0};
  1186. if (p->Show){
  1187. la_SetPropMathcerContext(p);
  1188. MAIN.CurrentPanel = p;
  1189. //if(p->Refresh&(LA_TAG_REDRAW|LA_TAG_RECALC)){
  1190. // printf("Draw %0xld (%s)\n", p, p->Title?p->Title->Ptr:0);
  1191. //}
  1192. if (p->Refresh & LA_TAG_RECALC){
  1193. laRecalcPanelImmediate(p);
  1194. }
  1195. if (!p->MenuRefer){
  1196. if(!p->OffScr){la_PanelDrawToOffsceen(p,&p->UI); p->Refresh|=LA_TAG_REDRAW; laRefreshWindow(); }
  1197. if (p->Refresh || !p->OffScr){
  1198. la_PanelDrawToOffsceen(p, &p->UI);
  1199. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  1200. la_PanelBackgroundInit(p, bt);
  1201. la_DrawUiListScrollerV(&p->UI, p->UI.PanY, p->UI.B-p->UI.U-bt->TM-bt->BM, p->H-p->TitleBar.B-bt->TM-bt->BM*2, p->W);
  1202. tnsFlush();
  1203. if(((p->UI.B>p->H) && (!p->UI.ScrollerShownV))||
  1204. ((p->UI.B<=p->H) && p->UI.ScrollerShownV)){
  1205. p->UI.ScrollerShownV=!p->UI.ScrollerShownV;
  1206. DrawState_++;
  1207. }
  1208. if(p->UI.PanY && p->UI.B-p->UI.PanY<p->H-bt->BM ){
  1209. p->UI.PanY = (p->UI.B-p->H/*-bt->BM-bt->TM*/-p->TitleBar.B);
  1210. if(p->UI.PanY<0){p->UI.PanY=0;}
  1211. DrawState_++;
  1212. }
  1213. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  1214. if (!la_AnimateUiListRecursive(&p->TitleBar)) p->Refresh = 0;
  1215. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  1216. if (!la_AnimateUiListRecursive(&p->UI)){ p->Refresh = p->Refresh; if(p->Refresh){ laRefreshWindow(); } }
  1217. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  1218. DrawState_ += la_DrawUiListRecursive(&uild, &p->TitleBar, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1219. if(p!=w->MaximizedUiPanel){
  1220. DrawState_ += la_DrawUiListRecursive(&uild, &p->UI, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1221. }else{
  1222. tnsViewportWithScissor(0,0,p->W,p->H); tnsOrtho(0,p->W,p->H,0,-100,100);
  1223. tnsDrawStringAutoM("Canvas is maximized",0,laThemeColor(bt,LA_BT_TEXT),
  1224. bt->LM,p->W-bt->RM,(p->H - p->TitleBar.B)/2+LA_RH2,LA_TEXT_ALIGN_CENTER|LA_TEXT_LINE_WRAP);
  1225. tnsFlush();
  1226. }
  1227. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  1228. }
  1229. }else{
  1230. if (p->Refresh || !p->OffScr){
  1231. la_PanelDrawToOffsceen(p, p->MenuRefer);
  1232. la_SetupUiListLimitMatrix(&uild, 0, p->W, 0, p->H, p->H);
  1233. la_PanelBackgroundInit(p, bt);
  1234. la_DrawUiListScrollerV(p->MenuRefer, p->MenuRefer->PanY,
  1235. p->MenuRefer->B-p->MenuRefer->U-bt->TM-bt->BM, p->H-bt->TM-bt->BM*2, p->W);
  1236. tnsFlush();
  1237. if(((p->MenuRefer->TB>p->H-bt->BP) && (!p->MenuRefer->ScrollerShownV))||
  1238. ((p->MenuRefer->TB<=p->H-bt->BP) && p->MenuRefer->ScrollerShownV)){
  1239. p->MenuRefer->ScrollerShownV=!p->MenuRefer->ScrollerShownV;
  1240. DrawState_++;
  1241. }
  1242. if(p->UI.PanY && p->MenuRefer->B-p->MenuRefer->PanY<p->H-bt->BM){
  1243. p->MenuRefer->PanY = (p->MenuRefer->B-p->H-bt->BM);
  1244. if(p->MenuRefer->PanY<0){p->MenuRefer->PanY=0;}
  1245. DrawState_++;
  1246. }
  1247. if(p->Refresh&LA_TAG_RECALC_SCROLLER) DrawState_++;
  1248. if (!la_AnimateUiListRecursive(p->MenuRefer)) p->Refresh = 0;
  1249. else { p->Refresh = LA_TAG_ANIMATION; laRefreshWindow(); }
  1250. DrawState_ += la_DrawUiListRecursive(&uild, p->MenuRefer, 0, p->W, 0, p->H, 10000, -1, 0, 0, 0);
  1251. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  1252. }
  1253. }
  1254. tnsDrawToScreen();
  1255. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1256. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  1257. if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99))){
  1258. tnsUseNoTexture();
  1259. if (!p->IsMenuPanel){
  1260. la_PanelDrawDescendBorder(p, bt, MAIN.SolidShadowLength, MAIN.FloatingAlpha);
  1261. }
  1262. tnsFlush();
  1263. }
  1264. la_PanelDrawToWindow(p, w);
  1265. }elif (p->AnimationMode){
  1266. la_PanelDrawToWindow(p, w);
  1267. }
  1268. }
  1269. void la_AttachedPanelDefDraw(laWindow* w, laPanel* p, laBoxedTheme* bt){
  1270. if(!p->Show && p!=w->MaximizedUiPanel) return;
  1271. if (p->SubPanels.pLast && (p->LaterDestroy ? !p->AnimationMode : 1)){
  1272. laPanel *pi, *PrevPI;
  1273. for (pi = p->SubPanels.pLast; pi; pi = PrevPI){
  1274. PrevPI = pi->Item.pPrev;
  1275. if (pi->AnimationMode && pi->LaterDestroy){
  1276. lstRemoveItem(&p->SubPanels, pi);
  1277. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, pi);
  1278. continue;
  1279. }
  1280. la_PanelDefDraw(w, pi, _LA_THEME_FLOATING_PANEL);
  1281. la_AttachedPanelDefDraw(w,pi,bt);
  1282. }
  1283. }
  1284. }
  1285. void la_BlockDrawDropLocations(laBlock *b, int CH, real *BorderColor4dV, real *FillColor4dv){
  1286. real PanelSquare[] = {
  1287. b->X + 2, CH - (b->Y + 2 + LA_RH),
  1288. b->X + 2, CH - (b->Y + b->H - 4),
  1289. b->X + b->W - 4, CH - (b->Y + b->H - 4),
  1290. b->X + b->W - 4, CH - (b->Y + 2 + LA_RH)};
  1291. real Center[] = {
  1292. tnsLinearItp(PanelSquare[0], PanelSquare[4], 0.5), tnsLinearItp(PanelSquare[1], PanelSquare[5], 0.5)};
  1293. real DraggingPlot[] = {
  1294. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  1295. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  1296. PanelSquare[0],
  1297. PanelSquare[1],
  1298. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  1299. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  1300. PanelSquare[2],
  1301. PanelSquare[3],
  1302. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  1303. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  1304. PanelSquare[4],
  1305. PanelSquare[5],
  1306. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  1307. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  1308. PanelSquare[6],
  1309. PanelSquare[7],
  1310. };
  1311. real Square[] = {
  1312. tnsLinearItp(PanelSquare[0], Center[0], 0.5),
  1313. tnsLinearItp(PanelSquare[1], Center[1], 0.5),
  1314. tnsLinearItp(PanelSquare[2], Center[0], 0.5),
  1315. tnsLinearItp(PanelSquare[3], Center[1], 0.5),
  1316. tnsLinearItp(PanelSquare[4], Center[0], 0.5),
  1317. tnsLinearItp(PanelSquare[5], Center[1], 0.5),
  1318. tnsLinearItp(PanelSquare[6], Center[0], 0.5),
  1319. tnsLinearItp(PanelSquare[7], Center[1], 0.5),
  1320. };
  1321. real PlotColor[] = {LA_COLOR3(BorderColor4dV), 0.8,
  1322. LA_COLOR3(BorderColor4dV), 0,
  1323. LA_COLOR3(BorderColor4dV), 0.8,
  1324. LA_COLOR3(BorderColor4dV), 0,
  1325. LA_COLOR3(BorderColor4dV), 0.8,
  1326. LA_COLOR3(BorderColor4dV), 0,
  1327. LA_COLOR3(BorderColor4dV), 0.8,
  1328. LA_COLOR3(BorderColor4dV), 0,
  1329. };
  1330. real FillColor[] = {LA_COLOR3(FillColor4dv), 0.8,
  1331. LA_COLOR3(FillColor4dv), 0,
  1332. LA_COLOR3(FillColor4dv), 0.8,
  1333. LA_COLOR3(FillColor4dv), 0,
  1334. LA_COLOR3(FillColor4dv), 0.8,
  1335. LA_COLOR3(FillColor4dv), 0,
  1336. LA_COLOR3(FillColor4dv), 0.8,
  1337. LA_COLOR3(FillColor4dv), 0,
  1338. };
  1339. tnsUseNoTexture();
  1340. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock == b){
  1341. int Index[4];
  1342. tnsVertexArray2d(DraggingPlot, 8);
  1343. tnsColorArray4d(FillColor, 8);
  1344. switch (MAIN.CurrentWindow->CurrentLayout->DropLocation){
  1345. case 0:
  1346. Index[0] = 0; Index[1] = 2; Index[2] = 4; Index[3] = 6;
  1347. break;
  1348. case LA_BLOCK_DROP_LOCATION_L:
  1349. Index[0] = 0; Index[1] = 1; Index[2] = 3; Index[3] = 2;
  1350. break;
  1351. case LA_BLOCK_DROP_LOCATION_R:
  1352. Index[0] = 4; Index[1] = 5; Index[2] = 7; Index[3] = 6;
  1353. break;
  1354. case LA_BLOCK_DROP_LOCATION_U:
  1355. Index[0] = 0; Index[1] = 1; Index[2] = 7; Index[3] = 6;
  1356. break;
  1357. case LA_BLOCK_DROP_LOCATION_B:
  1358. Index[0] = 4; Index[1] = 5; Index[2] = 3; Index[3] = 2;
  1359. break;
  1360. }
  1361. //glDisable(GL_CULL_FACE);
  1362. tnsIndexArray(Index, 4);
  1363. tnsPackAs(GL_TRIANGLE_FAN);
  1364. //tnsFlush();
  1365. }
  1366. tnsVertexArray2d(DraggingPlot, 8);
  1367. tnsColorArray4d(PlotColor, 8);
  1368. tnsPackAs(GL_LINES);
  1369. tnsVertexArray2d(Square, 4);
  1370. tnsColor4dv(BorderColor4dV);
  1371. tnsPackAs(GL_LINE_LOOP);
  1372. glLineWidth(LA_SEAM_W);
  1373. tnsFlush();
  1374. glLineWidth(1);
  1375. }
  1376. void la_BlockDefDrawSelf(laBlock *b, int CH){
  1377. laBoxedTheme *bt = _LA_THEME_TAB;
  1378. laPanel *p;
  1379. real v[] = {
  1380. b->X, CH - b->Y,
  1381. b->X + LA_SEAM_W, CH - b->Y ,
  1382. b->X, CH - (b->Y + b->H),
  1383. b->X + LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  1384. b->X + b->W, CH - (b->Y + b->H),
  1385. b->X + b->W - LA_SEAM_W, CH - (b->Y + b->H - LA_SEAM_W),
  1386. b->X + b->W, CH - b->Y,
  1387. b->X + b->W - LA_SEAM_W, CH - b->Y};
  1388. real tv[8];
  1389. real ratio = 1.0001f;
  1390. int tw = 0;
  1391. int L = LA_RH+LA_SEAM_W;
  1392. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  1393. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1394. tw += p->TitleWidth + LA_SEAM_W*2;
  1395. }
  1396. if (tw > b->W - LA_SEAM_W*2 - LA_RH) ratio = (real)(b->W - LA_SEAM_W*2 - LA_RH) / (real)tw;
  1397. tnsUseNoTexture();
  1398. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  1399. tnsVertexArray2d(v, 8);
  1400. tnsPackAs(GL_TRIANGLE_STRIP);
  1401. int TitleGap=b->Folded?0:LA_RH;
  1402. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  1403. b->X + b->W, (CH - b->Y),
  1404. b->X + b->W, (CH - b->Y - TitleGap),
  1405. b->X, (CH - b->Y - TitleGap));
  1406. tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  1407. tnsVertexArray2d(tv, 4);
  1408. tnsPackAs(GL_TRIANGLE_FAN);
  1409. tnsMakeQuad2d(tv,b->X + LA_SEAM_W, (CH - b->Y - TitleGap),
  1410. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap),
  1411. b->X + b->W - LA_SEAM_W, (CH - b->Y - TitleGap - LA_SEAM_W),
  1412. b->X + LA_SEAM_W, (CH - b->Y - TitleGap- LA_SEAM_W));
  1413. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1414. tnsVertexArray2d(tv, 4);
  1415. tnsPackAs(GL_TRIANGLE_FAN);
  1416. if(b->Folded){
  1417. real Color[4]; tnsVectorCopy4d(laThemeColor(bt,LA_BT_BORDER), Color); Color[3]*=b->OnButton==2?1:(b->OnButton==1?0.3:0);
  1418. 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);
  1419. 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);
  1420. tnsFlush(); return;
  1421. }
  1422. int LT=0,RT=0;
  1423. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1424. RT = LT + p->TitleWidth + LA_SEAM_W*2;
  1425. tnsMakeQuad2d(tv,b->X + L+LT * ratio, (CH - b->Y),
  1426. b->X + L+RT * ratio, (CH - b->Y),
  1427. b->X + L+RT * ratio, (CH - b->Y - LA_RH),
  1428. b->X + L+LT * ratio, (CH - b->Y - LA_RH));
  1429. if (p == b->CurrentPanel){
  1430. tnsUseNoTexture();
  1431. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  1432. tnsVertexArray2d(tv, 4);
  1433. tnsPackAs(GL_TRIANGLE_FAN);
  1434. 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);
  1435. }else{
  1436. 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);
  1437. }
  1438. LT =RT;
  1439. }
  1440. tnsDrawStringAuto("🔻",laThemeColor(bt,LA_BT_BORDER), b->X+LA_SEAM_W,b->X+b->W, CH-b->Y, LA_TEXT_REVERT_Y);
  1441. tnsFlush();
  1442. tnsUniformOutputColorSpace(T->immShader,0);
  1443. }
  1444. void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
  1445. laBoxedTheme *bt = _LA_THEME_PANEL;
  1446. real tv[8];
  1447. tnsUseImmShader(); tnsEnableShaderv(T->immShader); tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
  1448. tnsUseNoTexture();
  1449. tnsMakeQuad2d(tv, b->X, (CH - b->Y),
  1450. b->X + b->W, (CH - b->Y),
  1451. b->X + b->W, (CH - b->Y-b->H),
  1452. b->X, (CH - b->Y-b->H));
  1453. tnsVertexArray2d(tv, 4);
  1454. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  1455. tnsPackAs(GL_TRIANGLE_FAN);
  1456. 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,
  1457. LA_TEXT_ALIGN_CENTER|LA_TEXT_REVERT_Y|LA_TEXT_USE_NEWLINE|LA_TEXT_LINE_WRAP);
  1458. tnsFlush();
  1459. tnsUniformOutputColorSpace(T->immShader,0);
  1460. }
  1461. void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  1462. if (b->B1){
  1463. la_BlockDefDrawRecursive(w, bt, b->B1);
  1464. la_BlockDefDrawRecursive(w, bt, b->B2);
  1465. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  1466. if (!b->CurrentPanel->BT) b->CurrentPanel->BT = &_LA_THEME_PANEL;
  1467. la_PanelDefDraw(w, b->CurrentPanel, *b->CurrentPanel->BT);
  1468. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1469. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1470. la_BlockDefDrawSelf(b, w->CH);
  1471. }else{
  1472. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1473. tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1474. la_BlockDefDrawSelfEmpty(b, w->CH);
  1475. }
  1476. if(b==MAIN.CurrentWindow->CurrentLayout->MovingBlock){
  1477. tnsUseNoTexture();
  1478. int at; real tv[8];
  1479. if (b->Vertical){
  1480. at = b->H * b->SplitRatio + b->Y;
  1481. tnsMakeQuad2d(tv,b->X, (w->CH - at + LA_SEAM_W),
  1482. b->X + b->W, (w->CH - at + LA_SEAM_W),
  1483. b->X + b->W, (w->CH - at - LA_SEAM_W),
  1484. b->X, (w->CH - at - LA_SEAM_W));
  1485. }else{
  1486. at = b->X + b->W * b->SplitRatio;
  1487. tnsMakeQuad2d(tv,at+ LA_SEAM_W, (w->CH - b->Y),
  1488. at- LA_SEAM_W, (w->CH - b->Y),
  1489. at- LA_SEAM_W, (w->CH - b->Y - b->H),
  1490. at+ LA_SEAM_W, (w->CH - b->Y - b->H));
  1491. }
  1492. tnsColor4dv(laThemeColor(_LA_THEME_TAB,LA_BT_BORDER));
  1493. tnsVertexArray2d(tv, 4);
  1494. tnsPackAs(GL_TRIANGLE_FAN);
  1495. }
  1496. //la_SetPanelMatrixDrawWindow(b->CurrentPanel, *b->CurrentPanel->BT);
  1497. tnsFlush();
  1498. }
  1499. void la_BlockDefDrawAttachedRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
  1500. if (b->B1){
  1501. la_BlockDefDrawAttachedRecursive(w, bt, b->B1);
  1502. la_BlockDefDrawAttachedRecursive(w, bt, b->B2);
  1503. }elif (b->CurrentPanel /*&& b->CurrentPanel->Refresh*/){
  1504. la_AttachedPanelDefDraw(w,b->CurrentPanel,*b->CurrentPanel->BT);
  1505. }
  1506. tnsFlush();
  1507. }
  1508. void la_ClearBlockFramebuffersRecursive(laBlock* b, int AlsoClearCurrent){
  1509. if(b->B1)la_ClearBlockFramebuffersRecursive(b->B1,AlsoClearCurrent);
  1510. if(b->B2)la_ClearBlockFramebuffersRecursive(b->B2,AlsoClearCurrent);
  1511. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  1512. if(!AlsoClearCurrent && p==b->CurrentPanel) continue;
  1513. if(p->OffScr){
  1514. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  1515. }
  1516. }
  1517. }
  1518. void la_ClearUnusedFramebuffers(laWindow* w){
  1519. for(laLayout* l = w->Layouts.pFirst;l;l=l->Item.pNext){
  1520. la_ClearBlockFramebuffersRecursive(l->FirstBlock, l!=w->CurrentLayout);
  1521. }
  1522. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  1523. if(p->Show || p->AnimationMode) continue;
  1524. if(p->OffScr){
  1525. tnsDelete2DOffscreen(p->OffScr); p->OffScr=0;
  1526. }
  1527. }
  1528. }
  1529. void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
  1530. laPanel *p, *NextP;
  1531. laLayout *l = w->CurrentLayout;
  1532. la_ClearUnusedFramebuffers(w);
  1533. tnsDrawToScreen();
  1534. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1535. glClearColor(0.2, 0.2, 0.3, 1.0);
  1536. tnsClearAll();
  1537. tnsUseNoTexture();
  1538. if (l->Draw) l->Draw(w, l);
  1539. tnsResetModelMatrix();tnsResetProjectionMatrix();tnsResetViewMatrix();
  1540. //tnsShadeMode(GL_SMOOTH);
  1541. glEnable(GL_BLEND);
  1542. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1543. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  1544. laUiItem* ui;
  1545. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  1546. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  1547. if(p->Refresh){
  1548. if(p->Refresh&LA_TAG_RECALC){
  1549. la_SetPropMathcerContext(p);
  1550. laRecalcPanelImmediate(p);
  1551. }
  1552. ui->Type->Draw(ui, LA_RH); tnsFlush();
  1553. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  1554. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  1555. }
  1556. tnsDrawToScreen();
  1557. tnsResetViewMatrix();
  1558. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1559. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  1560. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  1561. tnsFlush();
  1562. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  1563. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  1564. tnsFlush();
  1565. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  1566. }
  1567. }
  1568. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  1569. }else{
  1570. laBlock* RootBlock= w->MaximizedBlock?w->MaximizedBlock:l->FirstBlock;
  1571. la_BlockDefDrawRecursive(w, bt, RootBlock);
  1572. la_BlockDefDrawAttachedRecursive(w,bt, RootBlock);
  1573. }
  1574. for (p = w->Panels.pLast; p; p = NextP){
  1575. NextP = p->Item.pPrev;
  1576. if (!p->BT) p->BT = &_LA_THEME_FLOATING_PANEL;
  1577. if (p->AnimationMode && p->LaterDestroy){
  1578. lstRemoveItem(&w->Panels, p);
  1579. lstAppendItem(&MAIN.CurrentWindow->FadingPanels, p);
  1580. continue;
  1581. }
  1582. la_PanelDefDraw(w, p, *p->BT);
  1583. }
  1584. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  1585. la_AttachedPanelDefDraw(w,p,*p->BT);
  1586. }
  1587. if (MAIN.CurrentWindow->CurrentLayout->DropToBlock){
  1588. laBoxedTheme* ubt=_LA_THEME_TAB;tnsUseNoTexture();
  1589. tnsViewportWithScissor(0, 0, w->CW, w->CH); tnsOrtho(0, w->CW, 0, w->CH, -100, 100);
  1590. la_BlockDrawDropLocations(MAIN.CurrentWindow->CurrentLayout->DropToBlock,
  1591. MAIN.CurrentWindow->CH, laThemeColor(ubt,LA_BT_ACTIVE), laThemeColor(ubt,LA_BT_BORDER));
  1592. tnsFlush();
  1593. }
  1594. for (p = w->FadingPanels.pLast; p; p = NextP){
  1595. NextP = p->Item.pPrev;
  1596. if (!p->AnimationMode){
  1597. lstRemoveItem(&w->FadingPanels, p);
  1598. p->AnimationMode = LA_PANEL_ANIMATION_DESTROY; laRefreshWindow();
  1599. laDeferredDestroyPanel(p, 0);
  1600. }else
  1601. la_PanelDrawToWindow(p, w);
  1602. }
  1603. }
  1604. int laStartWindow(laWindow *w){
  1605. //ShowWindow(w->win, SW_SHOWNORMAL);
  1606. XMapWindow(MAIN.dpy,w->win);
  1607. glXMakeContextCurrent(MAIN.dpy, w->win,w->win, w->glc);
  1608. MAIN.CurrentWindow = w;
  1609. if(!w->CurrentLayout){
  1610. if(!w->Layouts.pFirst){laDesignLayout(w, "Empty Layout");}
  1611. w->CurrentLayout=w->Layouts.pFirst;
  1612. }
  1613. laRedrawCurrentWindow();
  1614. laInvokeUi(0, "LA_window_operator", 0, w, 0, 0);
  1615. w->Shown = 1;
  1616. }
  1617. void la_AssignWindowPP(laWindow* w){
  1618. w->PP.EndInstance = w;
  1619. w->PP.LastPs = &w->FakePS;
  1620. w->PP.LastPs->p = _LA_PROP_WINDOW;
  1621. w->PP.LastPs->UseInstance = w;
  1622. w->PP.LastPs->Type = L'.';
  1623. }
  1624. laWindow *laDesignWindow(int X, int Y, int W, int H){
  1625. laWindow *n = memAcquire(sizeof(laWindow));
  1626. strSafeSet(&n->Title, "Empty Window");
  1627. n->X = X; n->Y = Y; n->W = W; n->H = H;
  1628. n->OutputShowStripes=1;
  1629. n->Redraw=1;
  1630. la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
  1631. lstAppendItem(&MAIN.Windows, n);
  1632. MAIN.CurrentWindow = n;
  1633. la_AssignWindowPP(n);
  1634. laui_DefaultMenuBar(n);
  1635. return n;
  1636. }
  1637. void laSetWindowCursor(int id){
  1638. Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
  1639. XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
  1640. };
  1641. void la_AssignBlockPP(laBlock* b){
  1642. b->PP.EndInstance = b;
  1643. b->PP.LastPs = &b->FakePS;
  1644. b->PP.LastPs->p = _LA_PROP_BLOCK;
  1645. b->PP.LastPs->UseInstance = b;
  1646. b->PP.LastPs->Type = L'.';
  1647. }
  1648. void laDestroyLayout(laWindow *w, laLayout* l){
  1649. if((!l->Item.pPrev) && (!l->Item.pNext)) return;
  1650. laDestroyBlocksRecursive(l->FirstBlock);
  1651. strSafeDestroy(&l->ID);
  1652. if(w->CurrentLayout==l){ w->CurrentLayout=l->Item.pPrev?l->Item.pPrev:l->Item.pNext; }
  1653. lstRemoveItem(&w->Layouts,l); memFree(l);
  1654. }
  1655. laLayout *laDesignLayout(laWindow *w, char *Title){
  1656. laLayout *l = memAcquireHyper(sizeof(laLayout));
  1657. l->FirstBlock = memAcquire(sizeof(laBlock));
  1658. la_AssignBlockPP(l->FirstBlock);
  1659. lstAppendItem(&w->Layouts, l);
  1660. strSafeSet(&l->ID, Title);
  1661. w->CurrentLayout = l;
  1662. laRenameWindow(w, Title);
  1663. return l;
  1664. }
  1665. void laFoldBlockTitle(laBlock* b){ if(b->B1) return; b->Folded=1; la_RecalcBlockRecursive(b,b->X,b->Y,b->W,b->H); }
  1666. 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); }
  1667. void laMaximizeBlock(laBlock* b){ if(b->B1) return; laWindow* w=MAIN.CurrentWindow;
  1668. if(w->MaximizedBlock==b){laRestoreToLayout(); return;} w->MaximizedBlock=b; la_UpdateUiPlacement(w);
  1669. laNotifyUsers("la.windows.maximized_block"); }
  1670. void laRestoreToLayout(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedBlock) return; w->MaximizedBlock=0; la_UpdateUiPlacement(w);
  1671. laNotifyUsers("la.windows.maximized_block"); }
  1672. void laMaximizeCanvasUI(laUiItem* ui, laPanel* UiParentPanel){
  1673. laRestoreCanvasUI();
  1674. if(!ui->Type||(!(ui->Type->Tag&LA_UI_TAG_IS_OFFSCREEN))||!UiParentPanel) return;
  1675. la_StopUiOperatorService(UiParentPanel); la_StopUiOperatorService(ui); laRetriggerOperators();
  1676. laWindow* w=MAIN.CurrentWindow; w->MaximizedUi=ui; w->MaximizedUiPanel=UiParentPanel; laRecalcPanel(UiParentPanel);
  1677. UiParentPanel->Show=0;
  1678. laNotifyUsers("la.windows.maximized_ui"); laHideMenuBar();
  1679. }
  1680. void laRestoreCanvasUI(){
  1681. laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  1682. la_StopUiOperatorService(w->MaximizedUi); laRetriggerOperators(); w->MaximizedUiPanel->Show=1;
  1683. laRecalcPanel(w->MaximizedUiPanel); w->MaximizedUi=0; w->MaximizedUiPanel=0; la_UpdateUiPlacement(w);
  1684. laNotifyUsers("la.windows.maximized_ui"); laShowMenuBar();
  1685. }
  1686. void laHideMenuBar(){ laWindow* w=MAIN.CurrentWindow; if(!w->MaximizedUi || !w->MaximizedUiPanel) return;
  1687. for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=0; laRefreshWindow(); break; } }
  1688. }
  1689. void laShowMenuBar(){ for(laPanel* p=MAIN.CurrentWindow->Panels.pFirst;p;p=p->Item.pNext){ if(p->IsMenuPanel){ p->Show=1; laRefreshWindow(); break; } } }
  1690. void laSplitBlockHorizon(laBlock *b, real Percentage){
  1691. laPanel *p;
  1692. b->SplitRatio = Percentage;
  1693. b->Vertical = 0;
  1694. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  1695. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  1696. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1697. p->Block = b->B1;
  1698. }
  1699. b->B1->Panels.pFirst = b->Panels.pFirst;
  1700. b->B1->Panels.pLast = b->Panels.pLast;
  1701. b->B1->CurrentPanel = b->CurrentPanel;
  1702. b->B1->parent = b->B2->parent=b;
  1703. b->Panels.pFirst = 0;
  1704. b->Panels.pLast = 0;
  1705. b->CurrentPanel = 0;
  1706. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1707. }
  1708. void laSplitBlockVertical(laBlock *b, real Percentage){
  1709. laPanel *p;
  1710. b->SplitRatio = Percentage;
  1711. b->Vertical = 1;
  1712. b->B1 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B1); b->B1->Folded=b->Folded;
  1713. b->B2 = memAcquire(sizeof(laBlock)); la_AssignBlockPP(b->B2);
  1714. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1715. p->Block = b->B1;
  1716. }
  1717. b->B1->Panels.pFirst = b->Panels.pFirst;
  1718. b->B1->Panels.pLast = b->Panels.pLast;
  1719. b->B1->CurrentPanel = b->CurrentPanel;
  1720. b->B1->parent = b->B2->parent=b;
  1721. b->Panels.pFirst = 0;
  1722. b->Panels.pLast = 0;
  1723. b->CurrentPanel = 0;
  1724. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1725. }
  1726. void laCombineChildBlocks(laBlock *b){
  1727. laPanel *p; if(!b) return;
  1728. if (!b->B1->B1 && !b->B2->B1){
  1729. lstCombineLists(&b->Panels, &b->B1->Panels);
  1730. lstCombineLists(&b->Panels, &b->B2->Panels);
  1731. for (p = b->Panels.pFirst; p; p = p->Item.pNext){
  1732. p->Block = b;
  1733. }
  1734. b->CurrentPanel = b->B1->CurrentPanel?b->B1->CurrentPanel:b->B2->CurrentPanel;
  1735. memFree(b->B1);
  1736. memFree(b->B2);
  1737. b->B1 = 0;
  1738. b->B2 = 0;
  1739. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1740. }elif(!b->B1->B1){
  1741. laBlock* b1 = b->B2->B1; laBlock* b2 = b->B2->B2;
  1742. b->Vertical = b->B2->Vertical;
  1743. for (p = b->B1->Panels.pFirst; p; p = p->Item.pNext){
  1744. p->Block = b1;
  1745. }
  1746. lstCombineLists(&b1->Panels, &b->B1->Panels);
  1747. memFree(b->B1); memFree(b->B2);
  1748. b->B1 = b1; b->B2 = b2;
  1749. b1->parent = b; b2->parent = b;
  1750. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1751. }elif(!b->B2->B1){
  1752. laBlock* b1 = b->B1->B1;laBlock* b2 = b->B1->B2;
  1753. b->Vertical = b->B1->Vertical;
  1754. for (p = b->B2->Panels.pFirst; p; p = p->Item.pNext){
  1755. p->Block = b1;
  1756. }
  1757. lstCombineLists(&b1->Panels, &b->B2->Panels);
  1758. memFree(b->B1); memFree(b->B2);
  1759. b->B1 = b1; b->B2 = b2;
  1760. b1->parent = b; b2->parent = b;
  1761. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1762. }
  1763. }
  1764. laBlock *laBlock1(laBlock *b){
  1765. return b->B1;
  1766. }
  1767. laBlock *laBlock2(laBlock *b){
  1768. return b->B2;
  1769. }
  1770. laBlock *laSwapSubBlocks(laBlock *b){
  1771. laBlock *tB;
  1772. tB = b->B2;
  1773. b->B2 = b->B1;
  1774. b->B1 = tB;
  1775. b->SplitRatio = 1 - b->SplitRatio;
  1776. la_RecalcBlockRecursive(b, b->X, b->Y, b->W, b->H);
  1777. }
  1778. void laDestroyBlocksRecursive(laBlock *Root){
  1779. laPanel *p;
  1780. if (Root->B1){
  1781. laDestroyBlocksRecursive(Root->B1);
  1782. laDestroyBlocksRecursive(Root->B2);
  1783. }else{
  1784. while (p = lstPopItem(&Root->Panels)){ laDestroySinglePanel(p, 1); }
  1785. }
  1786. memFree(Root);
  1787. }
  1788. laPanel* laTearOffPanel(laBlock* b, laPanel* p_if_set){
  1789. if(!b->CurrentPanel ) return 0;
  1790. laPanel* p = p_if_set?p_if_set:b->CurrentPanel;
  1791. b->CurrentPanel = p->Item.pNext?p->Item.pNext:p->Item.pPrev;
  1792. lstRemoveItem(&b->Panels, p);
  1793. if(!b->CurrentPanel && b->parent){
  1794. b=b->parent;
  1795. laCombineChildBlocks(b);
  1796. }
  1797. if(!p->TitleBar.UiItems.pFirst){
  1798. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate?p->PanelTemplate->Header:0);
  1799. }
  1800. p->Mode = LA_PANEL_FLOATING_TOP;
  1801. p->TY-=LA_RH;
  1802. p->TH+=LA_RH;
  1803. laRecalcPanel(p);
  1804. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  1805. p->BT = &_LA_THEME_FLOATING_PANEL;
  1806. p->Block = 0;
  1807. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  1808. laNotifyUsers("la.windows.panels");
  1809. return b->CurrentPanel;
  1810. }
  1811. void laDockPanel(laWindow* from, laBlock* b, laPanel* p){
  1812. if(!b||!p||p->Mode!=LA_PANEL_FLOATING_TOP||b->B1||b->B2) return;
  1813. lstRemoveItem(&from->Panels, p);
  1814. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  1815. p->Mode = LA_PANEL_NORMAL;
  1816. p->Block=b;
  1817. b->CurrentPanel = p;
  1818. lstPushItem(&b->Panels, p);
  1819. laRecalcPanel(p);
  1820. p->BT = &_LA_THEME_PANEL;
  1821. la_RecalcBlockRecursive(b, b->X,b->Y,b->W,b->H);
  1822. tnsFlush();
  1823. laNotifyUsers("la.windows.panels");
  1824. }
  1825. void laPopPanel(laPanel *p){
  1826. if (p->Mode == LA_PANEL_FLOATING_PASSIVE){
  1827. lstRemoveItem(&p->Parent->SubPanels, p);
  1828. lstPushItem(&p->Parent->SubPanels, p);
  1829. }else if (p->Mode == LA_PANEL_FLOATING_TOP){
  1830. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  1831. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  1832. laNotifyUsers("la.windows.panels");
  1833. }
  1834. }
  1835. void la_EnsurePanelExtras(laPanel *p){
  1836. laUiTemplate* uit=p->PanelTemplate;
  1837. p->PropLinkContainer = memAcquire(sizeof(laPropContainer));
  1838. p->PropLinkFakeProp = memAcquire(sizeof(laSubProp));
  1839. p->PropLinkFakeProp->Base.Identifier = "LA_UI_FAKE_PROP_PLACEHOLDER";
  1840. p->PropLinkFakeProp->Base.PropertyType = LA_PROP_SUB;
  1841. p->PropLinkFakeProp->Base.SubProp = p->PropLinkContainer;
  1842. p->PropLinkFakeProp->Base.Offset = 0;
  1843. p->PropLinkFakeProp->Base.OffsetIsPointer = 1;
  1844. p->PropLinkPP.EndInstance = p;
  1845. p->PropLinkPP.LastPs = &p->PropLinkFakePS;
  1846. p->PropLinkPP.LastPs->Type = L'.';
  1847. p->PropLinkFakePS.p = p->PropLinkFakeProp;
  1848. }
  1849. laPanel* la_GivePanelNode(){
  1850. laPanel* p; if(p=lstPopItem(&MAIN.WastedPanels)) return p;
  1851. return memAcquire(sizeof(laPanel));
  1852. }
  1853. void la_ReturnPanelNode(laPanel* p){
  1854. memset(p,0,sizeof(laPanel));
  1855. lstAppendItem(&MAIN.WastedPanels, p);
  1856. }
  1857. 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){
  1858. laPanel *p = la_GivePanelNode();
  1859. int CW = MAIN.CurrentWindow->CW;
  1860. int CH = MAIN.CurrentWindow->CH;
  1861. p->PanelTemplate = uit;
  1862. if((!W) && uit)W=uit->DefaultW_RH*LA_RH;
  1863. if((!H) && uit)H=uit->DefaultH_RH*LA_RH;
  1864. if (!MaxW) MaxW = 10000;
  1865. if (!MaxH) MaxH = 10000;
  1866. if (W > MaxW) W = MaxW;
  1867. if (H > MaxH) H = MaxH;
  1868. if (W < MinW) W = MinW;
  1869. if (H < MinH) H = MinH;
  1870. if(uit) { strSafeSet(&p->Title, uit->Title->Ptr); }
  1871. p->X = p->TX = (X < 0 ? 0 : X);
  1872. p->Y = p->TY = (Y < 0 ? 0 : Y);
  1873. p->W = p->TW = (W < 0 ? CW + W - p->X : W);
  1874. p->H = p->TH = (H < 0 ? CH + H - p->Y : H);
  1875. p->MaxW = MaxW;
  1876. p->MaxH = MaxH;
  1877. p->MinW = MinW;
  1878. p->MinH = MinH;
  1879. p->SL = SnapL;
  1880. p->ST = SnapT;
  1881. p->SR = SnapR;
  1882. p->SB = SnapB;
  1883. if (p->SR) p->X = CW - p->W - p->SR;
  1884. if (p->SB) p->Y = CH - p->H - p->SB;
  1885. la_EnsurePanelSnapping(p, CW, CH);
  1886. p->Show = 1;
  1887. p->PP.EndInstance = p;
  1888. p->PP.LastPs = &p->FakePS;
  1889. p->PP.LastPs->p = _LA_PROP_PANEL;
  1890. p->PP.LastPs->UseInstance = p;
  1891. p->PP.LastPs->Type = L'.';
  1892. la_EnsurePanelExtras(p);
  1893. laRecalcPanel(p);
  1894. p->FrameDistinguish = 100; //greater than 1 is ok
  1895. if(uit&&uit->PropFunc){ uit->PropFunc(p); }
  1896. if(uit){uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);}
  1897. return p;
  1898. }
  1899. laPanel *laCreatePanelT(laBlock *b, laUiTemplate* uit){
  1900. if(!uit) return 0;
  1901. laPanel *p = memAcquireHyper(sizeof(laPanel));
  1902. strSafeSet(&p->Title, uit->Title->Ptr);
  1903. p->PanelTemplate = uit;
  1904. p->Show = 1;
  1905. p->PP.EndInstance = p;
  1906. p->PP.LastPs = &p->FakePS;
  1907. p->PP.LastPs->p = _LA_PROP_PANEL;
  1908. p->PP.LastPs->UseInstance = p;
  1909. p->PP.LastPs->Type = L'.';
  1910. la_EnsurePanelExtras(p);
  1911. laRecalcPanel(p);
  1912. p->FrameDistinguish = 100; //greater than 1 is ok
  1913. p->TitleWidth = tnsStringGetWidth(transLate(p->Title->Ptr), 0, 0);
  1914. while (b->B1){
  1915. b = b->B1;
  1916. }
  1917. lstPushItem(&b->Panels, p);
  1918. p->Block = b;
  1919. b->CurrentPanel = p;
  1920. if(uit->PropFunc){ uit->PropFunc(p); }
  1921. uit->Define(&p->UI, &p->PP, &p->PropLinkPP, 0, 0);
  1922. laNotifyUsers("la.windows.panels");
  1923. return p;
  1924. }
  1925. laPanel *laCreatePanel(laBlock *b, char *template_id){
  1926. laUiTemplate* uit=laFindUiTemplate(template_id);
  1927. return laCreatePanelT(b, uit);
  1928. }
  1929. 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){
  1930. laUiTemplate* uit=0;
  1931. if(template_id) uit=laFindUiTemplate(template_id);
  1932. laPanel *p = la_NewPanel(uit, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  1933. p->Mode = LA_PANEL_FLOATING_TOP;
  1934. if(uit){
  1935. laui_DefaultPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, p->PanelTemplate->Header);
  1936. }
  1937. if (w) lstPushItem(&w->Panels, p);
  1938. return p;
  1939. }
  1940. void laShowPanel(laPanel *p){
  1941. p->Show = 1;
  1942. laNotifyUsers("la.windows.panels_hidden");
  1943. }
  1944. void laShowPanelWithDropDownEffect(laPanel *p){
  1945. laShowPanel(p);
  1946. p->AnimationMode = LA_PANEL_ANIMATION_DROP_DOWN; laRefreshWindow();
  1947. p->AnimationRatio = 0;
  1948. }
  1949. void laShowPanelWithExpandEffect(laPanel *p){
  1950. laShowPanel(p);
  1951. p->AnimationMode = LA_PANEL_ANIMATION_EXPAND; laRefreshWindow();
  1952. p->AnimationRatio = 0;
  1953. }
  1954. void laHidePanel(laPanel *p){
  1955. if (!p->Mode) return;
  1956. p->Show = 0;
  1957. laNotifyUsers("la.windows.panels_hidden");
  1958. }
  1959. void laHidePanelWithDissoveEffect(laPanel *p){
  1960. if (!p->Mode) return;
  1961. laHidePanel(p);
  1962. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  1963. p->AnimationRatio = 1;
  1964. }
  1965. void laHidePanelWithCollapseEffect(laPanel *p){
  1966. if (!p->Mode) return;
  1967. laHidePanel(p);
  1968. p->AnimationMode = LA_PANEL_ANIMATION_COLLAPSE; laRefreshWindow();
  1969. p->AnimationRatio = 1;
  1970. }
  1971. void laHidePanelWithMinimizeEffect(laPanel *p){
  1972. if (!p->Mode) return;
  1973. laHidePanel(p);
  1974. p->AnimationMode = LA_PANEL_ANIMATION_MINIMIZE; laRefreshWindow();
  1975. p->AnimationRatio = 1;
  1976. }
  1977. void laActivatePanel(char* TemplateID, int x, int y){
  1978. laUiTemplate* uit = laFindUiTemplate(TemplateID);
  1979. laPanel *p = la_FindFreePanelByTemplate(MAIN.CurrentWindow, uit);
  1980. if (!p){ p=laCreateTopPanel(MAIN.CurrentWindow, TemplateID, x, y, 0,0, 0, 0, 0, 0, 0, 0, 0, 0); }
  1981. laShowPanelWithExpandEffect(p); laPopPanel(p);
  1982. }
  1983. void laPanPanel(laPanel *p, int DeltaX, int DeltaY){
  1984. p->UI.PanX += DeltaX;
  1985. p->UI.PanY += DeltaY;
  1986. }
  1987. int laPanUiListFree(laUiList *uil, int X, int Y){
  1988. uil->PanX+=X; uil->PanY+=Y;
  1989. }
  1990. int laPanUiList(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  1991. if(uil->ScrollerShownH && !uil->ScrollerShownV){
  1992. if(Y){X+=Y;Y=0;}
  1993. }
  1994. if (Y > 0){
  1995. if (uil->B - uil->PanY <= B) return 0;
  1996. else{
  1997. uil->PanY += Y;
  1998. if (uil->B - uil->PanY <= B){
  1999. uil->PanY = uil->B - B;
  2000. return 1;
  2001. }
  2002. }
  2003. }
  2004. if (Y < 0){
  2005. if (uil->U - uil->PanY >= U) return 0;
  2006. else{
  2007. uil->PanY += Y;
  2008. if (uil->U - uil->PanY >= U){
  2009. uil->PanY = uil->U - U;
  2010. return 1;
  2011. }
  2012. }
  2013. }
  2014. if(uil->AllowScale){
  2015. laPanUiListFree(uil, X, 0);
  2016. }else{
  2017. if (X > 0){
  2018. if (uil->R - uil->PanX <= R) return 0;
  2019. else{
  2020. uil->PanX += X;
  2021. if (uil->R - uil->PanX <= R){
  2022. uil->PanX = uil->R - R;
  2023. return 1;
  2024. }
  2025. }
  2026. }
  2027. if (X < 0){
  2028. if (uil->L - uil->PanX >= L) return 0;
  2029. else{
  2030. uil->PanX += X;
  2031. if (uil->L - uil->PanX >= L){
  2032. uil->PanX = uil->L - L;
  2033. return 1;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. return 1;
  2039. }
  2040. int laScaleUiList(laUiList *uil, real factor, int L, int R, int U, int B){
  2041. int ret=1;
  2042. if(!uil->AllowScale){ return 0; }
  2043. real NewScale=uil->Scale*factor;
  2044. if(NewScale<0.2){NewScale=0.2; ret=0;}
  2045. if(NewScale>5) {NewScale=5; ret=0;}
  2046. if(NewScale>1-1e-4 && NewScale<1+1e-4){NewScale=1;}
  2047. factor=NewScale/uil->Scale;
  2048. uil->Scale=NewScale;
  2049. real mx=(L+R)/2,my=(U+B)/2;
  2050. real dx= (mx+uil->PanX)*factor;
  2051. real dy= (my+uil->PanY)*factor;
  2052. uil->PanX=dx-mx;
  2053. uil->PanY=dy-my;
  2054. MAIN.CurrentPanel->FrameDistinguish=100;
  2055. return ret;
  2056. }
  2057. int laPanUiListAuto(laUiList *uil, int X, int Y, int L, int R, int U, int B){
  2058. if(uil->AllowScale) return 0;
  2059. return laPanUiList(uil,X,Y,L,R,U,B);
  2060. }
  2061. laPanel *laDesignPropPanel(char *Title, int X, int Y, int W, int H,
  2062. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2063. laPanel *p = la_NewPanel(0, X, Y, W, H, 0, H, 0, 0, 0, 0, 0, 0);
  2064. strSafeSet(&p->Title, Title);
  2065. if (Define){
  2066. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2067. }
  2068. //laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2069. p->BT= &_LA_THEME_FLOATING_PANEL;
  2070. p->Mode = LA_PANEL_FLOATING_PASSIVE;
  2071. p->BoundUi = 1;
  2072. return p;
  2073. }
  2074. 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,
  2075. laUiDefineFunc Define, laPropPack *This, laPropPack *OperatorProps){
  2076. laPanel *p = la_NewPanel(0, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB);
  2077. strSafeSet(&p->Title, Title);
  2078. if (Define){
  2079. Define(laPrepareUi(p), This, OperatorProps, NULL, 0);
  2080. }
  2081. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, OperatorProps, 0, 0);
  2082. p->BT= &_LA_THEME_FLOATING_PANEL;
  2083. p->Mode = LA_PANEL_FLOATING_TOP;
  2084. p->BoundUi = 1;
  2085. return p;
  2086. }
  2087. void laDeferredDestroyPanel(laPanel *p, int immediate){
  2088. laPanel *ip;
  2089. tnsDelete2DOffscreen(p->OffScr);
  2090. p->OffScr = 0;
  2091. strSafeDestroy(&p->Title);
  2092. if (!p->AnimationMode){
  2093. if (p->Parent) lstRemoveItem(&p->Parent->SubPanels, p);
  2094. else if (p->Mode == LA_PANEL_FLOATING_TOP){
  2095. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2096. }else if (p->Mode == LA_PANEL_NO_PARENT_MENU){
  2097. lstRemoveItem(&MAIN.CurrentWindow->Panels, p);
  2098. }else if (p->Block){
  2099. lstRemoveItem(&p->Block->Panels, p);
  2100. if (p->Block->CurrentPanel == p) p->Block->CurrentPanel = p->Block->Panels.pFirst;
  2101. }
  2102. laNotifyUsers("la.windows.panels");
  2103. }
  2104. for (ip = p->SubPanels.pFirst; ip; ip = ip->Item.pNext){
  2105. //lstRemoveItem(&p->SubPanels, ip);
  2106. laDestroySinglePanel(ip, immediate);
  2107. laNotifyUsers("la.windows.panels");
  2108. }
  2109. la_ClearDetachedProp(p);
  2110. memFree(p->PropLinkContainer); memFree(p->PropLinkFakeProp);
  2111. la_ReturnPanelNode(p);
  2112. }
  2113. void laDestroySinglePanel(laPanel *p, int immediate){
  2114. la_SetPropMathcerContext(p);
  2115. if (p->PropLinkPP.LastPs&&p->PropLinkPP.LastPs->p->SubProp->Props.pFirst){
  2116. for(laProp* prop=p->PropLinkPP.LastPs->p->SubProp->Props.pFirst;prop;prop=prop->Item.pNext){
  2117. { /* la_StopUsingPropPack(&prop->DetachedPP); */ }
  2118. //laStopUsingDataBlock(prop->DetachedPP.LastPs->UseInstance, prop->DetachedPP.LastPs->p,MAIN.PropMatcherContextP);
  2119. }
  2120. }
  2121. if(MAIN.CurrentWindow&&p==MAIN.CurrentWindow->MaximizedUiPanel){ laRestoreCanvasUI(); }
  2122. la_DestroyUiList(&p->UI, 1, 1, 0);
  2123. la_DestroyUiList(&p->TitleBar, 1, 1, 0);
  2124. la_DestroyUiList(p->MenuRefer, 0, 1, 1);
  2125. if (p->Mode){
  2126. p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
  2127. p->AnimationRatio = p->CloseWhenMovedOut?0.0:1.0;
  2128. }
  2129. if (p->ParentOperator && la_UiOperatorExists(p)) ((laOperator *)p->ParentOperator)->OperatorPanel = 0;
  2130. if (la_UiStillInService(p)){
  2131. la_StopUiOperatorService(p);
  2132. }
  2133. if ((!p->AnimationMode) || immediate){
  2134. laDeferredDestroyPanel(p, immediate);
  2135. }else{
  2136. p->LaterDestroy = 1;
  2137. }
  2138. }
  2139. int laEnclosePanelContent(laPanel *p, laUiList *uil){
  2140. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2141. int MinW,MinWt=0;
  2142. int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
  2143. int CW = MAIN.CurrentWindow->CW;
  2144. if(p->SL && p->SR){return 0;}
  2145. la_SetPropMathcerContext(p);
  2146. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  2147. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, 0, 1000, 0, 0, p);
  2148. MinWt = la_TestUiListMinumWidth(&p->TitleBar);
  2149. MinW = la_TestUiListMinumWidth(uil);
  2150. if (MinW<MinWt){MinW=MinWt;}
  2151. int ScrollerW=(uil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0);
  2152. if (MinW > 20){
  2153. p->TW = MinW + bt->LM + bt->RM+ScrollerW;
  2154. }
  2155. la_PanelValidateWidth(p,uil);
  2156. laEnsurePanelInBound(p,uil);
  2157. if(p->TW>CW){ p->TW=CW; }
  2158. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW - bt->LM-bt->RM, p->TH, 0, p);
  2159. la_UpdateUiListRecursive(uil, bt->TM+p->TitleBar.B, bt->LM, p->TW - bt->RM - ScrollerW, 0, 0, p);
  2160. laRedrawPanel(p);
  2161. return 1;
  2162. }
  2163. laPanel *laEnableIdlePanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laPropPack *This,
  2164. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2165. laOperator *ai = a;
  2166. laPanel *p;
  2167. int GX, GY, GW, t = 0;
  2168. int b;
  2169. laUiDefineFunc def = ReplaceUiDefine;
  2170. int MinW;
  2171. if (!def){ def=laui_DefaultPropDetails; }
  2172. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  2173. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  2174. laEnclosePanelContent(p, &p->UI);
  2175. laSetOperatorLocalizer(p);
  2176. p->CloseWhenMovedOut=1;
  2177. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2178. //laShowPanelWithDropDownEffect(p);
  2179. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  2180. if(Attachment){ p->Parent = Attachment; lstAppendItem(&Attachment->SubPanels, p); }
  2181. return p;
  2182. }
  2183. laPanel *laEnableSplashPanel(laUiDefineFunc ReplaceUiDefine, int L, int R, int B, int MaxGH, int MaxW, laEvent* e){
  2184. laPanel *p;
  2185. int GX, GY, GW, t = 0;
  2186. int b;
  2187. laUiDefineFunc def = ReplaceUiDefine;
  2188. int MinW;
  2189. if (!def) return 0;
  2190. GX = L; GY = B; GW = (R - L) > MaxW ? MaxW : (R - L);
  2191. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, 0, 0);
  2192. p->Mode = LA_PANEL_FLOATING_TOP;
  2193. p->CloseWhenMovedOut=2; MAIN.PendingSplash=p;
  2194. laEnclosePanelContent(p, &p->UI);
  2195. if(MAIN.CurrentWindow->Operators.pFirst){
  2196. laSetOperatorLocalizer(MAIN.PendingSplash);
  2197. laInvokeUi(0, "LA_panel_operator", e, MAIN.PendingSplash, 0, 1);
  2198. MAIN.PendingSplash=0;
  2199. }
  2200. //laShowPanelWithExpandEffect(p);
  2201. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2202. return p;
  2203. }
  2204. laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *OperatorProps, laUiDefineFunc ReplaceUiDefine, laUiDefineFunc FallBackUiDefine, laPropPack *This,
  2205. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2206. laOperator *ai = a;
  2207. laPanel *p; laPropContainer* sub;
  2208. int GX, GY, GW, t = 0;
  2209. int b;
  2210. laUiDefineFunc def = ReplaceUiDefine;
  2211. int MinW;
  2212. if (!def){
  2213. if (This && This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
  2214. if ((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
  2215. else def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
  2216. }
  2217. GX = L; GY = B;
  2218. GW = (R - L) > MaxW ? MaxW : (R - L);
  2219. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, def, This, OperatorProps);
  2220. laEnclosePanelContent(p, &p->UI);
  2221. laSetOperatorLocalizer(p);
  2222. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2223. laShowPanelWithDropDownEffect(p);
  2224. if(!Attachment){ Attachment=MAIN.CurrentWindow->MaximizedUiPanel; }
  2225. if(Attachment){
  2226. p->Parent = Attachment;
  2227. lstAppendItem(&Attachment->SubPanels, p);
  2228. }
  2229. return p;
  2230. }
  2231. laPanel *laEnableEmptyPropertyPanel(laPanel *Attachment, laOperator *a, int L, int R, int U, int MaxGH, laEvent *e){
  2232. laPanel *p;
  2233. int t = 0;
  2234. int b;
  2235. //laLocalToWindow(0, Attachment, &L, &t);
  2236. //laLocalToWindow(0, Attachment, &R, &U);
  2237. p = laDesignPropPanel("TMP", L, U, R - L, MaxGH, 0, 0, 0);
  2238. laSetOperatorLocalizer(p);
  2239. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2240. laShowPanelWithDropDownEffect(p);
  2241. p->Parent = Attachment;
  2242. lstPushItem(&Attachment->SubPanels, p);
  2243. return p;
  2244. }
  2245. laPanel *laEnableMenuPanel(laPanel *Attachment, laOperator *a, laUiList *MenuRefer, laPropPack *This,
  2246. int L, int R, int B, int MaxGH, int MaxW, laEvent *e){
  2247. laOperator *ai = a;
  2248. laPanel *p;
  2249. laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
  2250. int GX, GY, GW, t = 0;
  2251. int b;
  2252. int MinW;
  2253. //laLocalToWindow(0,Attachment, &L, &t);
  2254. //laLocalToWindow(0,Attachment, &R, &B);
  2255. GX = L;
  2256. GY = B;
  2257. GW = (R - L) > MaxW ? MaxW : (R - L);
  2258. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2259. p->MenuRefer = MenuRefer;
  2260. laEnclosePanelContent(p, MenuRefer);
  2261. laSetOperatorLocalizer(p);
  2262. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2263. laShowPanelWithDropDownEffect(p);
  2264. p->Parent = Attachment;
  2265. lstPushItem(&Attachment->SubPanels, p);
  2266. return p;
  2267. }
  2268. laPanel *laDefineAndEnableMenuPanel(laPanel *Attachment, laOperator *a, laPropPack *This,
  2269. int L, int B, int MaxGH, int MaxW, laEvent *e){
  2270. laOperator *ai = a;
  2271. laPanel *p;
  2272. int GX, GY, GW, t = 0;
  2273. int b;
  2274. GX = L;
  2275. GY = B;
  2276. GW = MaxW;
  2277. p = laDesignPropPanel("TMP", GX, GY, GW, MaxGH, 0, 0, 0);
  2278. p->MenuRefer = &p->UI;
  2279. p->Mode = LA_PANEL_NO_PARENT_MENU;
  2280. laSetOperatorLocalizer(p);
  2281. laInvokeUi(a, "LA_menu_panel_operator", e, p, 0, 1);
  2282. laShowPanelWithDropDownEffect(p);
  2283. if (Attachment){
  2284. p->Parent = Attachment;
  2285. lstPushItem(&Attachment->SubPanels, p);
  2286. }else{
  2287. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2288. }
  2289. return p;
  2290. }
  2291. 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){
  2292. laOperator *ai = For;
  2293. laPanel *p;
  2294. int b;
  2295. laUiDefineFunc def = 0;
  2296. if (ai->Type->UiDefine) def = ai->Type->UiDefine;
  2297. else def = laui_DefaultPropUiDefine;
  2298. For->PP.EndInstance = For->CustomData;
  2299. p = laDesignOperatorPanel(ai->Type->Name, X, Y, W, H, MaxW, MaxH, MinW, MinH, SnapL, SnapR, SnapT, SnapB, def, This, &For->PP);
  2300. laEnclosePanelContent(p, &p->UI);
  2301. MAIN.ToPanel = p;
  2302. laShowPanelWithExpandEffect(p);
  2303. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2304. ai->OperatorPanel = p;
  2305. p->ParentOperator = For;
  2306. laInvokeUi(For, "LA_modal_panel_operator", 0, p, 0, 1);
  2307. return p;
  2308. }
  2309. laPanel *laEnableYesNoPanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2310. laPanel *p;
  2311. int b;
  2312. laUiList *uil;
  2313. laColumn *col, *cor, *corl, *corr;
  2314. p = la_NewPanel(0, X, Y, W, 0, 1000, 500, 50, 0, 0, 0, 0, 0);
  2315. strSafeSet(&p->Title, Title);
  2316. p->BoundUi = 1;
  2317. p->Mode = LA_PANEL_FLOATING_TOP;
  2318. p->BT = &_LA_THEME_FLOATING_PANEL;
  2319. MAIN.ToPanel = p;
  2320. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2321. uil = laPrepareUi(p);
  2322. col = laFirstColumn(uil);
  2323. laSplitColumn(uil, col, 0.5);
  2324. cor = laRightColumn(col, 600);
  2325. laShowLabel(uil, col, Message, 0, 0);
  2326. laShowItem(uil, cor, 0, "LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_TEXT_ALIGN_CENTER;
  2327. laEnclosePanelContent(p,uil);
  2328. laShowPanelWithExpandEffect(p);
  2329. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2330. laSetOperatorLocalizer(p);
  2331. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2332. return p;
  2333. }
  2334. laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, char *Message, int X, int Y, int W, laEvent *e){
  2335. laPanel *p;
  2336. int b;
  2337. laUiList *uil;
  2338. laColumn *col, *cor, *corl, *corr;
  2339. p = la_NewPanel(0, X, Y, W, 0, 1000, 90, 100, 0, 0, 0, 0, 0);
  2340. strSafeSet(&p->Title, Title);
  2341. p->BoundUi = 1;
  2342. p->Mode = LA_PANEL_FLOATING_TOP;
  2343. p->BT = &_LA_THEME_FLOATING_PANEL;
  2344. MAIN.ToPanel = p;
  2345. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2346. uil = laPrepareUi(p);
  2347. col = laFirstColumn(uil);
  2348. laSplitColumn(uil, col, 0.35);
  2349. cor = laRightColumn(col, 200);
  2350. laShowLabel(uil, col, Message, 0, 0);
  2351. laShowItemFull(uil, cor, 0, "LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  2352. laEnclosePanelContent(p,uil);
  2353. laShowPanelWithExpandEffect(p);
  2354. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2355. laSetOperatorLocalizer(p);
  2356. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2357. return p;
  2358. }
  2359. laPanel *laEnableMultiMessagePanel(laOperator *a, laPanel *Attachment, char *Title, laPanelMessageList *pml, int X, int Y, int W, laEvent *e){
  2360. laPanel *p;
  2361. int b;
  2362. laUiList *uil;
  2363. laColumn *col, *cor, *corl, *corr;
  2364. laPanelMessage *pm;
  2365. p = la_NewPanel(0, X, Y, W, 0, 1000, 1000, 100, 0, 0, 0, 0, 0);
  2366. strSafeSet(&p->Title, Title);
  2367. p->BoundUi = 1;
  2368. p->Mode = LA_PANEL_FLOATING_TOP;
  2369. p->BT = &_LA_THEME_FLOATING_PANEL;
  2370. MAIN.ToPanel = p;
  2371. laui_DefaultOperatorPanelTitleBar(&p->TitleBar, &p->PP, &p->PropLinkPP, 0, 0);
  2372. uil = laPrepareUi(p);
  2373. col = laFirstColumn(uil);
  2374. laSplitColumn(uil, col, 0.35);
  2375. cor = laRightColumn(col, 200);
  2376. while (pm = lstPopItem(pml)){
  2377. laShowLabel(uil, col, pm->Message->Ptr, 0, 0);
  2378. strSafeDestroy(&pm->Message);
  2379. FreeMem(pm);
  2380. }
  2381. laShowItemFull(uil, cor, 0, "LA_confirm",0,"text=Okay;",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
  2382. laShowPanelWithExpandEffect(p);
  2383. lstPushItem(&MAIN.CurrentWindow->Panels, p);
  2384. laSetOperatorLocalizer(p);
  2385. laInvokeUi(a, "LA_modal_panel_operator", e, p, 0, 1);
  2386. return p;
  2387. }
  2388. void laAddPanelMessage(laPanelMessageList *pml, char *Message){
  2389. if (!Message || !Message[0]) return;
  2390. laPanelMessage *pm = CreateNew(laPanelMessage);
  2391. strSafeSet(&pm->Message, Message);
  2392. lstAppendItem(&pml->Msg, pm);
  2393. }
  2394. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2395. laWindow* cur=MAIN.CurrentWindow;
  2396. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  2397. MAIN.CurrentWindow=w;
  2398. la_UpdateUiPlacement(w);
  2399. }
  2400. MAIN.CurrentWindow=cur;
  2401. }
  2402. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2403. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  2404. }
  2405. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  2406. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  2407. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  2408. void laRedrawCurrentPanel(){
  2409. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  2410. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2411. }
  2412. void laRecalcCurrentPanel(){
  2413. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  2414. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2415. }
  2416. void laRecalcPanelImmediate(laPanel* p){
  2417. p->FrameDistinguish++;
  2418. laBoxedTheme* bt = (*p->BT);
  2419. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  2420. la_PanelRefreshDetachedProp(p);
  2421. int enclosed=0;
  2422. if(p->BoundUi || p->MenuRefer){
  2423. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  2424. else enclosed=laEnclosePanelContent(p, &p->UI);
  2425. }
  2426. if(!enclosed){
  2427. la_PanelValidateWidth(p,&p->UI);
  2428. //laEnsurePanelInBound(p,&p->UI);
  2429. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->TM-bt->BM, 0, p);
  2430. la_UpdateUiListRecursive(&p->UI, bt->TM+p->TitleBar.TB, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->TM-bt->BM, 0, p);
  2431. }
  2432. laWindow* w=MAIN.CurrentWindow;
  2433. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  2434. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  2435. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  2436. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  2437. }
  2438. }
  2439. void laRecalcCurrentPanelImmediate(){
  2440. laRecalcPanelImmediate(MAIN.CurrentPanel);
  2441. }
  2442. int laNonFixedPanelExists(laPanel *p){
  2443. laPanel *ip;
  2444. if (!p) return 0;
  2445. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2446. // if (ip == p) return 1;
  2447. //}
  2448. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2449. if (ip == p) return 1;
  2450. }
  2451. return 0;
  2452. }
  2453. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  2454. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  2455. return 1;
  2456. }
  2457. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  2458. int tt=MAIN.TooltipCloseDistance;
  2459. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  2460. return 1;
  2461. }
  2462. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  2463. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  2464. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  2465. return 0;
  2466. return 1;
  2467. }
  2468. void laUnlinkSharedPanel(laPanel *p){
  2469. laWindow *w;
  2470. laPanel *ip;
  2471. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  2472. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  2473. if (ip == p){
  2474. lstRemoveItem(&w->Panels, ip);
  2475. return;
  2476. }
  2477. }
  2478. }
  2479. }
  2480. int laIsPanelCovered(laPanel *p){
  2481. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  2482. laPanel *ip;
  2483. laPanel *resp;
  2484. int in1 = 0, in2 = 0, in3 = 0;
  2485. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  2486. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2487. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  2488. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  2489. //}
  2490. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2491. if (ip == p){
  2492. in3 = 1;
  2493. d3 = 0;
  2494. continue;
  2495. }
  2496. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  2497. }
  2498. if (!in2 && !in3) in1 = 1;
  2499. if (in1){
  2500. if (d1 || d2 || d3) return 1;
  2501. }else{
  2502. if (in2){
  2503. if (d2 || d3) return 1;
  2504. }else if (in3)
  2505. if (d3) return 1;
  2506. }
  2507. return 0;
  2508. }
  2509. int laIsTopPanel(laPanel *p){
  2510. //if (!p->Item.pPrev) return 1;
  2511. //else {
  2512. if (!laIsPanelCovered(p)){
  2513. //laPopPanel(p);
  2514. return 1;
  2515. }
  2516. return 0;
  2517. //}
  2518. return 0;
  2519. }
  2520. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  2521. if(!p) return;
  2522. int ix = *x, iy = *y;
  2523. laListItemPointer *lip;
  2524. laOperator *ai = a;
  2525. (*x) = ix - p->X;
  2526. (*y) = iy - p->Y;
  2527. if (a){
  2528. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2529. laUiList *uil = lip->p;
  2530. (*x) += uil->PanX;
  2531. (*y) += uil->PanY;
  2532. }
  2533. }
  2534. }
  2535. void laPanelToLocal(laOperator *a, int *x, int *y){
  2536. int ix = *x, iy = *y;
  2537. laListItemPointer *lip;
  2538. if (a){
  2539. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2540. laUiList *uil = lip->p;
  2541. (*x) += uil->PanX;
  2542. (*y) += uil->PanY;
  2543. }
  2544. }
  2545. }
  2546. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  2547. if(!p) return;
  2548. int ix = *x, iy = *y;
  2549. laListItemPointer *lip;
  2550. (*x) = ix + p->X;
  2551. (*y) = iy + p->Y;
  2552. if (a){
  2553. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2554. laUiList *uil = lip->p;
  2555. (*x) -= uil->PanX;
  2556. (*y) -= uil->PanY;
  2557. }
  2558. }
  2559. }
  2560. void laPanelToWindow(laPanel *p, int *x, int *y){
  2561. int ix = *x, iy = *y;
  2562. laListItemPointer *lip;
  2563. (*x) = ix + p->X;
  2564. (*y) = iy + p->Y;
  2565. }
  2566. void laLocalToPanel(laOperator *a, int *x, int *y){
  2567. int ix = *x, iy = *y;
  2568. laListItemPointer *lip;
  2569. if (a){
  2570. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2571. laUiList *uil = lip->p;
  2572. (*x) -= uil->PanX;
  2573. (*y) -= uil->PanY;
  2574. }
  2575. }
  2576. }
  2577. void laSetNextMenuPos(int X, int Y, int W, int H){
  2578. MAIN.NextX = X;
  2579. MAIN.NextY = Y;
  2580. MAIN.NextW = W;
  2581. MAIN.NextH = H;
  2582. }
  2583. int laIsInBlock(laBlock *b, int X, int Y){
  2584. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  2585. return 0;
  2586. }
  2587. 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; }
  2588. 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; }
  2589. 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; }
  2590. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  2591. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  2592. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  2593. if (!b->B1 && !b->B2){
  2594. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  2595. }
  2596. }
  2597. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  2598. laPanel *p;
  2599. laBlock *sb = 0;
  2600. if (!laIsInBlock(b, X, Y)) return 0;
  2601. if (!b->B1 && !b->B2) return b;
  2602. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  2603. return laDetectBlockRecursive(b->B2, X, Y);
  2604. }
  2605. laPanel *laDetectPanel(int X, int Y){
  2606. laPanel *p; laBlock *b;
  2607. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  2608. int x = X, y = Y;
  2609. laWindowToLocal(0, p, &x, &y);
  2610. if (p->Show && laIsInPanel(p, x, y)){
  2611. return p;
  2612. }
  2613. }
  2614. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  2615. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  2616. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  2617. return 0;
  2618. }
  2619. laUiList *laPrepareUi(laPanel *p){
  2620. return &p->UI;
  2621. }
  2622. laColumn *laFirstColumn(laUiList *uil){
  2623. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  2624. else{
  2625. laColumn *c = memAcquireSimple(sizeof(laColumn));
  2626. c->SP = 1;
  2627. c->PreWidth = 1;
  2628. lstAppendItem(&uil->Columns, c);
  2629. c->Top = c;
  2630. return uil->Columns.pFirst;
  2631. }
  2632. }
  2633. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  2634. laColumn *lc, *rc;
  2635. if (c->LS || c->RS) return c;
  2636. lc = memAcquireSimple(sizeof(laColumn));
  2637. rc = memAcquireSimple(sizeof(laColumn));
  2638. c->LS = lc;
  2639. c->RS = rc;
  2640. c->LS->SP = Percent;
  2641. c->RS->SP = Percent;
  2642. c->LS->Top = c->Top;
  2643. c->RS->Top = c->Top;
  2644. if (uil){
  2645. lstAppendItem(&uil->Columns, lc);
  2646. lstAppendItem(&uil->Columns, rc);
  2647. }
  2648. if (c->LS && c->RS->MaxW == 0){
  2649. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  2650. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  2651. }else if (c->RS && c->LS->MaxW == 0){
  2652. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  2653. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  2654. }
  2655. return c;
  2656. }
  2657. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  2658. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  2659. return c->LS;
  2660. }
  2661. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  2662. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  2663. if (MaxWidth) c->RS->MaxW = MaxWidth;
  2664. return c->RS;
  2665. }
  2666. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  2667. lstRemoveItem(List, c);
  2668. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  2669. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  2670. memFree(c);
  2671. }
  2672. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  2673. laUiList *uil = TopUil;
  2674. laUiList *sub;
  2675. laUiItem *ui;
  2676. laColumn *cc, *NextCC = 0;
  2677. int Occupied = 0;
  2678. int Removed = 0;
  2679. if (!c->LS) return 0;
  2680. else{
  2681. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  2682. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  2683. }
  2684. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  2685. if (ui->C == c->LS || ui->C == c->RS){
  2686. if (DoMerge){
  2687. ui->C = c;
  2688. Occupied = 1;
  2689. }else
  2690. return 1;
  2691. }
  2692. if (ui->Subs.pFirst){
  2693. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  2694. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  2695. }
  2696. }
  2697. }
  2698. if (!Removed){
  2699. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  2700. if (cc == c){
  2701. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  2702. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  2703. c->LS = 0;
  2704. c->RS = 0;
  2705. Removed = 1;
  2706. break;
  2707. }
  2708. }
  2709. }
  2710. return Occupied;
  2711. }
  2712. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int hyper){
  2713. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,L'◳',0,size,0,0,hyper);
  2714. ut->FakeProp = memAcquire(sizeof(laSubProp));
  2715. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  2716. ut->FakeProp->Base.Identifier = ut->Identifier;
  2717. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  2718. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  2719. ut->FakeProp->Base.OffsetIsPointer = 1;
  2720. //ut->FakeProp->Base.Container = ut->ExtraProps;
  2721. return ut->ExtraProps;
  2722. }
  2723. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int hyper){
  2724. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,L'◳',0,size,0,0,hyper);
  2725. ct->FakeProp = memAcquire(sizeof(laSubProp));
  2726. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  2727. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  2728. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  2729. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  2730. ct->FakeProp->Base.OffsetIsPointer = 1;
  2731. //ut->FakeProp->Base.Container = ut->ExtraProps;
  2732. return ct->ExtraProps;
  2733. }
  2734. void la_DestroyUiType(laUiType* uit){
  2735. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  2736. memFree(uit);
  2737. }
  2738. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  2739. laUiType *ut = memAcquire(sizeof(laUiType));
  2740. ut->Identifier = Identifer;
  2741. ut->OperatorID = UseOperator;
  2742. ut->Draw = Draw;
  2743. ut->Theme = bt;
  2744. ut->ForType = ForType;
  2745. ut->OperatorType = laGetOperatorType(UseOperator);
  2746. ut->GetHeight = GetHeight;
  2747. ut->Init = Init;
  2748. ut->Destroy = Destroy;
  2749. la_UDFAppendSharedTypePointer(Identifer, ut);
  2750. lstAppendItem(&MAIN.UiTypes, ut);
  2751. return ut;
  2752. }
  2753. laUiType *la_GetUiTypeFromProperty(laProp *P){
  2754. laUiType *ut = MAIN.UiTypes.pFirst;
  2755. if (!P) return 0;
  2756. if (P->DefaultUiType) return P->DefaultUiType;
  2757. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  2758. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  2759. for (ut; ut; ut = ut->Item.pNext){
  2760. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  2761. return ut;
  2762. }
  2763. }
  2764. return 0;
  2765. }
  2766. laUiType *la_GetUiButtonType(){
  2767. laUiType *ut = MAIN.UiTypes.pFirst;
  2768. for (ut; ut; ut = ut->Item.pNext){
  2769. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  2770. }
  2771. return 0;
  2772. }
  2773. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  2774. laCanvasTemplate *vdt;
  2775. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  2776. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  2777. }
  2778. return 0;
  2779. }
  2780. void la_AssignPropExtras(laUiItem* ui){
  2781. if(!ui->Type || !ui->Type->FakeProp) return;
  2782. ui->FakePs.p = ui->Type->FakeProp;
  2783. ui->FakePs.Type = L'.';
  2784. ui->FakePs.UseInstance = ui;
  2785. ui->ExtraPP.LastPs = &ui->FakePs;
  2786. }
  2787. void la_AssignCanvasPropExtras(laUiItem* ui){
  2788. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  2789. laCanvasTemplate*ct=ui->CanvasTemplate;
  2790. ui->FakePs.p = ct->FakeProp;
  2791. ui->FakePs.Type = L'.';
  2792. ui->FakePs.UseInstance = ui;
  2793. ui->ExtraPP.EndInstance = ui->Extra;
  2794. ui->ExtraPP.LastPs = &ui->FakePs;
  2795. }
  2796. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  2797. int result;
  2798. if (!ui) return 0;
  2799. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  2800. if (Path){
  2801. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  2802. if (!result){
  2803. ui->AT = laGetOperatorType(Path);
  2804. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  2805. ui->Type = la_GetUiButtonType();
  2806. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  2807. }else{
  2808. ui->Type = (OverrideType && ((OverrideType->ForType == ui->PP.LastPs->p->PropertyType) || (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ? OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  2809. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  2810. }
  2811. if (Base){
  2812. ui->PP.RawThis = Base;
  2813. }
  2814. }else if (Base){
  2815. ui->PP.LastPs = Base->LastPs;
  2816. ui->Type = (OverrideType && ((OverrideType->ForType == ui->PP.LastPs->p->PropertyType) || (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ? OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  2817. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  2818. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  2819. }
  2820. la_AssignPropExtras(ui);
  2821. if(Widget){ ui->Flags|= Widget->Flags; }
  2822. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  2823. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  2824. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  2825. return ui;
  2826. }
  2827. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  2828. ui->Type = _LA_UI_LABEL;
  2829. ui->Template = Template;
  2830. ui->State = LA_UI_NORMAL;
  2831. strSafeSet(&ui->Display, Content);
  2832. la_AssignPropExtras(ui);
  2833. return ui;
  2834. }
  2835. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  2836. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2837. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  2838. ui->State = LA_UI_NORMAL;
  2839. la_AssignPropExtras(ui);
  2840. return ui;
  2841. }
  2842. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  2843. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2844. transLate(Content);
  2845. la_UpdateLabelDisplay(ui, Template, Content);
  2846. ui->C = c;
  2847. if (ui->Type->Init) ui->Type->Init(ui);
  2848. ui->ExtraPP.EndInstance = ui->Extra;
  2849. lstAppendItem(&uil->UiItems, ui);
  2850. return ui;
  2851. }
  2852. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  2853. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2854. la_UpdateLabelDisplay(ui, Template, Content);
  2855. ui->C = c;
  2856. if (ui->Type->Init) ui->Type->Init(ui);
  2857. ui->ExtraPP.EndInstance = ui->Extra;
  2858. lstAppendItem(&uil->UiItems, ui);
  2859. return ui;
  2860. }
  2861. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  2862. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2863. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  2864. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  2865. ui->C = c;
  2866. if (ui->Type->Init) ui->Type->Init(ui);
  2867. ui->ExtraPP.EndInstance = ui->Extra;
  2868. lstAppendItem(&uil->UiItems, ui);
  2869. return ui;
  2870. }
  2871. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  2872. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  2873. }
  2874. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  2875. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2876. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  2877. ui->C = c;
  2878. ui->TemplateContext = TemplateContext;
  2879. if (ui->Type->Init) ui->Type->Init(ui);
  2880. ui->ExtraPP.EndInstance = ui->Extra;
  2881. lstAppendItem(&uil->UiItems, ui);
  2882. return ui;
  2883. }
  2884. laUiItem *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  2885. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2886. ui->C = c; ui->Extra=Image;
  2887. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  2888. ui->SymbolID=Height;
  2889. lstAppendItem(&uil->UiItems, ui);
  2890. return ui;
  2891. }
  2892. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  2893. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  2894. }
  2895. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  2896. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  2897. }
  2898. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  2899. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2900. ui->Type = _LA_UI_CANVAS;
  2901. ui->State = LA_UI_NORMAL;
  2902. ui->C = c;
  2903. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  2904. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  2905. else{
  2906. 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); }
  2907. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  2908. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  2909. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  2910. }
  2911. if (ui->Type->Init) ui->Type->Init(ui);
  2912. la_AssignCanvasPropExtras(ui);
  2913. if (Height) ui->Expand=Height; else ui->Expand=6;
  2914. lstAppendItem(&uil->UiItems, ui);
  2915. return ui;
  2916. }
  2917. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  2918. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2919. laCanvasExtra *e;
  2920. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  2921. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  2922. ui->C = c;
  2923. if (ui->Type->Init) ui->Type->Init(ui);
  2924. ui->ExtraPP.EndInstance = ui->Extra;
  2925. lstAppendItem(&uil->UiItems, ui);
  2926. return ui;
  2927. }
  2928. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  2929. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2930. ui->Type = _LA_UI_SYMBOL;
  2931. ui->SymbolID = SymbolID;
  2932. if (Height) ui->State = Height;
  2933. ui->C = c;
  2934. if (ui->Type->Init) ui->Type->Init(ui);
  2935. ui->ExtraPP.EndInstance = ui->Extra;
  2936. lstAppendItem(&uil->UiItems, ui);
  2937. return ui;
  2938. }
  2939. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  2940. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2941. ui->Type = &_LA_UI_ROW_BEGIN;
  2942. ui->State=Expand;
  2943. ui->Flags=Even;
  2944. ui->C = c;
  2945. if (ui->Type->Init) ui->Type->Init(ui);
  2946. ui->ExtraPP.EndInstance = ui->Extra;
  2947. lstAppendItem(&uil->UiItems, ui);
  2948. return ui;
  2949. }
  2950. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  2951. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  2952. ui->Type = &_LA_UI_ROW_END;
  2953. ui->C = Begin->C;
  2954. ui->Page = (laUiList*)Begin;
  2955. if (ui->Type->Init) ui->Type->Init(ui);
  2956. ui->ExtraPP.EndInstance = ui->Extra;
  2957. lstAppendItem(&uil->UiItems, ui);
  2958. return ui;
  2959. }
  2960. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  2961. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  2962. e->Expression = Expression;
  2963. ui->Extra = e;
  2964. la_AssignPropExtras(ui);
  2965. }
  2966. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  2967. laUiItem *ui = la_CreateGroupHandle(Widget);
  2968. laUiList *nuil;
  2969. ui->C = c;
  2970. lstAppendItem(&uil->UiItems, ui);
  2971. nuil = memAcquireSimple(sizeof(laUiList));
  2972. strSafeSet(&nuil->TabName, Name);
  2973. ui->Page = nuil;
  2974. lstAppendItem(&ui->Subs, nuil);
  2975. if (ui->Type->Init) ui->Type->Init(ui);
  2976. ui->ExtraPP.EndInstance = ui->Extra;
  2977. return ui;
  2978. }
  2979. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  2980. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  2981. laUiList *sub = SubUi->Page;
  2982. laColumn *s = laFirstColumn(sub);
  2983. SubUi->State = LA_UI_ACTIVE;
  2984. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  2985. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  2986. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  2987. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  2988. laShowSeparator(sub, s);
  2989. return SubUi;
  2990. }
  2991. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  2992. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  2993. laUiList *sub = SubUi->Page;
  2994. laColumn *s = laFirstColumn(sub);
  2995. SubUi->State = LA_UI_ACTIVE;
  2996. return SubUi;
  2997. }
  2998. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  2999. laEndCondition(sub, sub->UiItems.pFirst);
  3000. }
  3001. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  3002. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  3003. laUiList *nuil;
  3004. ui->C = c;
  3005. lstAppendItem(&uil->UiItems, ui);
  3006. if (ui->Type->Init) ui->Type->Init(ui);
  3007. ui->ExtraPP.EndInstance = ui->Extra;
  3008. return ui;
  3009. }
  3010. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  3011. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3012. if (!ui->Page) ui->Page = uil;
  3013. lstAppendItem(&ui->Subs, uil);
  3014. strSafeSet(&uil->TabName, Name);
  3015. laFirstColumn(uil);
  3016. //laFirstColumn(uil);
  3017. return uil;
  3018. }
  3019. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  3020. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3021. /*if (!ui->Page) */ ui->Page = uil;
  3022. lstAppendItem(&ui->Subs, uil);
  3023. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  3024. return uil;
  3025. }
  3026. laUiConditionNode *laTrue(){
  3027. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3028. ucn->Type = LA_CONDITION_TRUE;
  3029. return ucn;
  3030. }
  3031. laUiConditionNode *laFalse(){
  3032. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3033. ucn->Type = LA_CONDITION_FALSE;
  3034. return ucn;
  3035. }
  3036. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  3037. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3038. ucn->Type = LA_CONDITION_PROP;
  3039. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  3040. strSafeSet(&ucn->String, Prop);
  3041. return ucn;
  3042. }
  3043. laUiConditionNode *laIntExpression(int Value){
  3044. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3045. ucn->Type = LA_CONDITION_INT;
  3046. ucn->IntValue = Value;
  3047. return ucn;
  3048. }
  3049. laUiConditionNode *laFloatExpression(real Value){
  3050. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3051. ucn->Type = LA_CONDITION_FLOAT;
  3052. ucn->FloatValue = Value;
  3053. return ucn;
  3054. }
  3055. laUiConditionNode *laStringExpression(char *Content){
  3056. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3057. ucn->Type = LA_CONDITION_STRING;
  3058. strSafeSet(&ucn->String, Content);
  3059. return ucn;
  3060. }
  3061. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3062. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3063. ucn->Type = LA_CONDITION_AND;
  3064. ucn->Expression1 = Expression1;
  3065. ucn->Expression2 = Expression2;
  3066. return ucn;
  3067. }
  3068. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3069. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3070. ucn->Type = LA_CONDITION_OR;
  3071. ucn->Expression1 = Expression1;
  3072. ucn->Expression2 = Expression2;
  3073. return ucn;
  3074. }
  3075. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  3076. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3077. ucn->Type = LA_CONDITION_NOT;
  3078. ucn->Expression1 = Expression1;
  3079. return ucn;
  3080. }
  3081. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3082. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3083. ucn->Type = LA_CONDITION_EQ;
  3084. ucn->Expression1 = Expression1;
  3085. ucn->Expression2 = Expression2;
  3086. return ucn;
  3087. }
  3088. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3089. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3090. ucn->Type = LA_CONDITION_GT;
  3091. ucn->Expression1 = Expression1;
  3092. ucn->Expression2 = Expression2;
  3093. return ucn;
  3094. }
  3095. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3096. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3097. ucn->Type = LA_CONDITION_LT;
  3098. ucn->Expression1 = Expression1;
  3099. ucn->Expression2 = Expression2;
  3100. return ucn;
  3101. }
  3102. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3103. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3104. ucn->Type = LA_CONDITION_GE;
  3105. ucn->Expression1 = Expression1;
  3106. ucn->Expression2 = Expression2;
  3107. return ucn;
  3108. }
  3109. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3110. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3111. ucn->Type = LA_CONDITION_LE;
  3112. ucn->Expression1 = Expression1;
  3113. ucn->Expression2 = Expression2;
  3114. return ucn;
  3115. }
  3116. int la_GetIntConditionValue(laUiConditionNode *Expression){
  3117. if (Expression->Type != LA_CONDITION_INT) return 0;
  3118. return Expression->IntValue;
  3119. }
  3120. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  3121. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  3122. return Expression->FloatValue;
  3123. }
  3124. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  3125. return Expression->String->Ptr;
  3126. }
  3127. 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){
  3128. switch (Mode1){
  3129. case LA_PROP_ENUM:
  3130. case LA_PROP_INT:
  3131. case LA_CONDITION_INT:
  3132. switch (Mode2){
  3133. case LA_PROP_ENUM:
  3134. case LA_PROP_INT:
  3135. case LA_CONDITION_INT:
  3136. switch (CompMode){
  3137. case LA_CONDITION_GE:
  3138. return (i1 >= i2);
  3139. case LA_CONDITION_GT:
  3140. return (i1 > i2);
  3141. case LA_CONDITION_EQ:
  3142. return (i1 == i2);
  3143. case LA_CONDITION_LT:
  3144. return (i1 < i2);
  3145. case LA_CONDITION_LE:
  3146. return (i1 <= i2);
  3147. }
  3148. case LA_PROP_FLOAT:
  3149. case LA_CONDITION_FLOAT:
  3150. switch (CompMode){
  3151. case LA_CONDITION_GE:
  3152. return ((real)i1 >= f2);
  3153. case LA_CONDITION_GT:
  3154. return ((real)i1 > f2);
  3155. case LA_CONDITION_EQ:
  3156. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  3157. case LA_CONDITION_LT:
  3158. return ((real)i1 < f2);
  3159. case LA_CONDITION_LE:
  3160. return ((real)i1 <= f2);
  3161. }
  3162. case LA_PROP_SUB:
  3163. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  3164. default:
  3165. return 0;
  3166. }
  3167. case LA_PROP_FLOAT:
  3168. case LA_CONDITION_FLOAT:
  3169. switch (Mode2){
  3170. case LA_PROP_INT:
  3171. case LA_PROP_ENUM:
  3172. case LA_CONDITION_INT:
  3173. switch (CompMode){
  3174. case LA_CONDITION_GE:
  3175. return (f1 >= (real)i2);
  3176. case LA_CONDITION_GT:
  3177. return (f1 > (real)i2);
  3178. case LA_CONDITION_EQ:
  3179. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  3180. case LA_CONDITION_LT:
  3181. return (f1 < (real)i2);
  3182. case LA_CONDITION_LE:
  3183. return (f1 <= (real)i2);
  3184. }
  3185. case LA_PROP_FLOAT:
  3186. case LA_CONDITION_FLOAT:
  3187. switch (CompMode){
  3188. case LA_CONDITION_GE:
  3189. return (f1 >= f2);
  3190. case LA_CONDITION_GT:
  3191. return (f1 > f2);
  3192. case LA_CONDITION_EQ:
  3193. return (f1 == f2);
  3194. case LA_CONDITION_LT:
  3195. return (f1 < f2);
  3196. case LA_CONDITION_LE:
  3197. return (f1 <= f2);
  3198. }
  3199. default:
  3200. return 0;
  3201. }
  3202. case LA_PROP_STRING:
  3203. case LA_CONDITION_STRING:
  3204. switch (Mode2){
  3205. case LA_PROP_STRING:
  3206. case LA_CONDITION_STRING:
  3207. return strSame(s1, s2);
  3208. default:
  3209. return 0;
  3210. }
  3211. case LA_PROP_SUB:
  3212. switch (Mode2){
  3213. case LA_PROP_SUB:
  3214. return p1 == p2;
  3215. case LA_CONDITION_INT:
  3216. case LA_PROP_INT:
  3217. case LA_PROP_ENUM:
  3218. return (int)p1 == i2;
  3219. default:
  3220. return 0;
  3221. }
  3222. default:
  3223. switch (CompMode){
  3224. case LA_CONDITION_GE:
  3225. return (i1 >= i2);
  3226. case LA_CONDITION_GT:
  3227. return (i1 > i2);
  3228. case LA_CONDITION_EQ:
  3229. return (i1 == i2);
  3230. case LA_CONDITION_LT:
  3231. return (i1 < i2);
  3232. case LA_CONDITION_LE:
  3233. return (i1 <= i2);
  3234. }
  3235. }
  3236. }
  3237. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  3238. void *Instance = 0;
  3239. int IValue1 = 0, IValue2 = 0;
  3240. real FValue1 = 0, FValue2 = 0;
  3241. void *Ptr1 = 0, *Ptr2 = 0;
  3242. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  3243. int Result1, Result2;
  3244. laEnumItem *ei;
  3245. if (!Expression) return 0;
  3246. Str1[0] = 0;
  3247. Str2[0] = 0;
  3248. laPropIterator pi = {0};
  3249. switch (Expression->Type){
  3250. case LA_CONDITION_PROP:
  3251. if (!Expression->PP.LastPs){
  3252. (*IResult) = 0;
  3253. return 0;
  3254. }
  3255. switch (Expression->PP.LastPs->p->PropertyType){
  3256. case LA_PROP_INT:
  3257. *IResult = laGetInt(&Expression->PP);
  3258. if (*IResult) return LA_CONDITION_INT;
  3259. else
  3260. return 0;
  3261. case LA_PROP_FLOAT:
  3262. *FResult = laGetFloat(&Expression->PP);
  3263. if (*FResult) return 1;
  3264. else
  3265. return 0;
  3266. break;
  3267. case LA_PROP_STRING:
  3268. laGetString(&Expression->PP, _StrResult, &StrResult);
  3269. if (StrResult[0]) return 1;
  3270. else
  3271. return 0;
  3272. break;
  3273. case LA_PROP_ENUM:
  3274. ei = laGetEnum(&Expression->PP);
  3275. if (!ei) return 0;
  3276. /*if(ei) */ *IResult = ei->Index;
  3277. if (*IResult) return LA_CONDITION_INT;
  3278. break;
  3279. case LA_PROP_SUB:
  3280. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  3281. else
  3282. Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  3283. *PtrResult = Instance;
  3284. if (Instance) return 1;
  3285. break;
  3286. default:
  3287. return 0;
  3288. }
  3289. case LA_CONDITION_INT:
  3290. *IResult = Expression->IntValue;
  3291. if (*IResult) return 1;
  3292. else
  3293. return 0;
  3294. case LA_CONDITION_FLOAT:
  3295. *FResult = Expression->FloatValue;
  3296. if (*FResult) return 1;
  3297. else
  3298. return 0;
  3299. case LA_CONDITION_STRING:
  3300. if (Expression->String){
  3301. strCopyFull(StrResult, Expression->String->Ptr);
  3302. return 1;
  3303. }else
  3304. return 0;
  3305. case LA_CONDITION_TRUE:
  3306. if (*IResult) *IResult = 1;
  3307. return 1;
  3308. case LA_CONDITION_FALSE:
  3309. if (*IResult) *IResult = 0;
  3310. return 0;
  3311. default:
  3312. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  3313. switch (Expression->Type){
  3314. case LA_CONDITION_AND:
  3315. if (Result1){
  3316. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3317. if (Result2) *IResult = 1;
  3318. return (Result2);
  3319. }else
  3320. return 0;
  3321. case LA_CONDITION_OR:
  3322. if (!Result1){
  3323. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3324. if (Result2) *IResult = 1;
  3325. return (Result2);
  3326. }else
  3327. return 1;
  3328. case LA_CONDITION_NOT:
  3329. return !Result1;
  3330. default:
  3331. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3332. return la_DoCompare(Expression->Type,
  3333. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  3334. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  3335. }
  3336. break;
  3337. }
  3338. return 0;
  3339. }
  3340. int la_DoSingleExpression(laUiConditionNode *Expression){
  3341. int a;
  3342. real b;
  3343. char c[128]={0};
  3344. void *p;
  3345. if (!Expression) return 1;
  3346. c[0] = 0;
  3347. return la_DoExpression(Expression, &a, &b, c, &p);
  3348. }
  3349. void la_StepExpression(laUiConditionNode *e){
  3350. if (!e) return;
  3351. switch (e->Type){
  3352. case LA_CONDITION_AND:
  3353. case LA_CONDITION_OR:
  3354. case LA_CONDITION_GE:
  3355. case LA_CONDITION_GT:
  3356. case LA_CONDITION_EQ:
  3357. case LA_CONDITION_LT:
  3358. case LA_CONDITION_LE:
  3359. la_StepExpression(e->Expression1);
  3360. la_StepExpression(e->Expression2);
  3361. break;
  3362. case LA_CONDITION_NOT:
  3363. la_StepExpression(e->Expression1);
  3364. break;
  3365. case LA_CONDITION_PROP:
  3366. la_StepPropPack(&e->PP);
  3367. if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){
  3368. la_UsePropPack(&e->PP, 1);
  3369. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  3370. }
  3371. break;
  3372. default:
  3373. break;
  3374. }
  3375. }
  3376. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  3377. if (!ucn) return;
  3378. la_ConditionNodeFreeRecursive(ucn->Expression1);
  3379. la_ConditionNodeFreeRecursive(ucn->Expression2);
  3380. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  3381. if (ucn->String) strSafeDestroy(&ucn->String);
  3382. if (ucn) memFree(ucn);
  3383. }
  3384. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  3385. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3386. ui->C = c;
  3387. ui->Type = &_LA_UI_CONDITION;
  3388. la_ConditionerInit(ui, Expression);
  3389. lstAppendItem(&uil->UiItems, ui);
  3390. return ui;
  3391. }
  3392. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  3393. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3394. laConditionUiExtraData *cued;
  3395. ui->Type = &_LA_UI_CONDITION_ELSE;
  3396. la_ConditionerInit(ui, 0);
  3397. cued = ui->Extra;
  3398. cued->EndUi = Beginner;
  3399. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  3400. ui->C = Beginner->C;
  3401. lstAppendItem(&uil->UiItems, ui);
  3402. return ui;
  3403. }
  3404. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  3405. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3406. laConditionUiExtraData *cued;
  3407. ui->Template = define;
  3408. ui->C = col;
  3409. ui->PP.RawThis = ExtraBase;
  3410. ui->Page = ExtraThis;
  3411. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  3412. la_ConditionerInit(ui, 0);
  3413. cued = ui->Extra;
  3414. //cued->Remove = Remove;
  3415. ui->State = LA_UI_NORMAL;
  3416. lstAppendItem(&uil->UiItems, ui);
  3417. return ui;
  3418. }
  3419. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  3420. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3421. laConditionUiExtraData *cued;
  3422. ui->Type = &_LA_UI_CONDITION_END;
  3423. la_ConditionerInit(ui, 0);
  3424. cued = ui->Extra;
  3425. cued->EndUi = Beginner;
  3426. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  3427. ui->C = Beginner->C;
  3428. lstAppendItem(&uil->UiItems, ui);
  3429. return ui;
  3430. }
  3431. laUiList *laMakeMenuPage(laUiList *uil, laColumn *c, const char *Title){
  3432. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3433. laUiList *muil = memAcquireSimple(sizeof(laUiList));
  3434. ui->Type = _LA_UI_MENU_ROOT;
  3435. strSafeSet(&ui->Display, Title);
  3436. ui->State = LA_UI_NORMAL;
  3437. ui->C = c;
  3438. lstAppendItem(&uil->UiItems, ui);
  3439. lstAppendItem(&ui->Subs, muil);
  3440. return muil;
  3441. }
  3442. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  3443. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3444. ui->Type = _LA_UI_ALIGN;
  3445. ui->C = widest;
  3446. lstAppendItem(&uil->UiItems, ui);
  3447. return ui;
  3448. }
  3449. void laFixHeight(laUiList *uil, short Rows){
  3450. if (!uil) return;
  3451. uil->HeightCoeff = Rows;
  3452. }
  3453. int la_GetUiType(laUiItem* ui) {
  3454. if (ui->AT) return LA_UI_INTERNAL_BUTTON;
  3455. if (ui->PP.LastPs) {
  3456. if (ui->Type == _LA_UI_CANVAS) return LA_UI_INTERNAL_2D_VIEW;
  3457. return LA_UI_INTERNAL_WATCHER;
  3458. }
  3459. if (ui->Display) {
  3460. if (ui->Type == _LA_UI_MENU_ROOT) return LA_UI_INTERNAL_MENU;
  3461. return LA_UI_INTERNAL_LABEL;
  3462. }
  3463. if (ui->Subs.pFirst) {
  3464. if (ui->Type == _LA_UI_FIXED_GROUP)return LA_UI_INTERNAL_GROUP;
  3465. if (ui->Type == _LA_UI_TAB)return LA_UI_INTERNAL_TAB;
  3466. return LA_UI_INTERNAL_GROUP;
  3467. }
  3468. if (ui->Type == _LA_UI_BUTTON) return LA_UI_INTERNAL_BUTTON;
  3469. if (ui->Type == &_LA_UI_CONDITION) return LA_UI_INTERNAL_BRACKET_BEGIN;
  3470. if (ui->Type == &_LA_UI_CONDITION_ELSE) return LA_UI_INTERNAL_BRACKET_ELSE;
  3471. if (ui->Type == &_LA_UI_CONDITION_END) return LA_UI_INTERNAL_BRACKET_END;
  3472. if (ui->Type == _LA_UI_CONDITION_TOGGLE) return LA_UI_INTERNAL_FOLDER_BEGIN;
  3473. if (ui->Type == _LA_UI_ALIGN) return LA_UI_INTERNAL_ALIGNER;
  3474. if (ui->Type == _LA_UI_COLUMN_ADJUSTER) return LA_UI_INTERNAL_ADJUSTER;
  3475. if (ui->Type == _LA_UI_SYMBOL) return LA_UI_INTERNAL_SYMBOL;
  3476. return LA_UI_INTERNAL_WATCHER;
  3477. }
  3478. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  3479. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  3480. if (!ExtraColumns) return;
  3481. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  3482. }
  3483. laUiTemplate *laFindUiTemplate(char *Identifier){
  3484. laUiTemplate *uit;
  3485. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3486. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3487. }
  3488. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3489. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3490. }
  3491. return 0;
  3492. }
  3493. void la_DestroyUiTemplate(laUiTemplate* uit){
  3494. strSafeDestroy(&uit->Identifier);
  3495. strSafeDestroy(&uit->Title);
  3496. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  3497. memFree(uit);
  3498. }
  3499. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  3500. strSafeDestroy(&uit->Identifier);
  3501. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3502. memFree(uit);
  3503. }
  3504. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  3505. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  3506. strSafeSet(&uit->Identifier, Identifier);
  3507. strSafeSet(&uit->Title, Title);
  3508. strSafeSet(&uit->CategoryName, NewCategory);
  3509. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  3510. uit->DefaultGLFormat=DefaultGLFormat;
  3511. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  3512. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  3513. la_UDFAppendSharedTypePointer(Identifier, uit);
  3514. return uit;
  3515. }
  3516. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  3517. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  3518. strSafeSet(&t->Identifier, Identifier);
  3519. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  3520. t->Init = CustomInit; t->Destroy = CustomDestroy;
  3521. lstAppendItem(&MAIN.View2DTemplates, t);
  3522. la_UDFAppendSharedTypePointer(Identifier, t);
  3523. return t;
  3524. }
  3525. void laFinalizeUiTemplates(){
  3526. laUiTemplate *uit;
  3527. laCanvasTemplate *u2d;
  3528. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  3529. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  3530. }
  3531. }
  3532. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  3533. laPanel *p;
  3534. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  3535. if (p->PanelTemplate==uit){
  3536. return p;
  3537. }
  3538. }
  3539. return 0;
  3540. }
  3541. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  3542. laUiList *uil, *NextUil;
  3543. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  3544. NextUil = uil->Item.pNext;
  3545. lstRemoveItem(&ui->Subs, uil);
  3546. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  3547. }
  3548. la_StopUiOperatorService(ui);
  3549. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  3550. strSafeDestroy(&ui->Display);
  3551. if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3552. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3553. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3554. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  3555. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  3556. memFree(ui);
  3557. }
  3558. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  3559. laUiItem *ui, *NextUi;
  3560. laColumn *col, *NextCol;
  3561. if (!uil) return;
  3562. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  3563. NextUi = ui->Item.pNext;
  3564. if(OnlyRemoveUser && RemoveUsers){
  3565. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3566. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3567. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3568. continue;
  3569. }
  3570. lstRemoveItem(&uil->UiItems, ui);
  3571. la_DestroyUiItem(ui, RemoveUsers);
  3572. }
  3573. if(OnlyRemoveUser){ return; }
  3574. for (col = uil->Columns.pFirst; col; col = NextCol){
  3575. NextCol = col->Item.pNext;
  3576. lstRemoveItem(&uil->Columns, col);
  3577. memFree(col);
  3578. }
  3579. strSafeDestroy(&uil->TabName);
  3580. if (!NoFree) memFree(uil);
  3581. }
  3582. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  3583. if(ui) lstRemoveItem(&ui->Subs, Tab);
  3584. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  3585. }
  3586. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  3587. laUiItem *Next = after->Item.pNext;
  3588. laUiItem *Last = uil->UiItems.pLast;
  3589. after->Item.pNext = 0;
  3590. uil->UiItems.pLast = after;
  3591. Define(uil, Base, This, ExtraColums, 0);
  3592. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  3593. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  3594. if (Next != Last) uil->UiItems.pLast = Last;
  3595. }
  3596. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  3597. // int i = 0;
  3598. // int FromW=FromR-FromL, ToW=ToR-ToL;
  3599. // if (!ui->ExtraColums) return;
  3600. // for (i; ui->ExtraColums[i]; i++) {
  3601. // laColumn* c = ui->ExtraColums[i];
  3602. // c->B = B;
  3603. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  3604. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  3605. // }
  3606. //}
  3607. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  3608. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  3609. }
  3610. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  3611. laColumn *c = ui->C;
  3612. laColumn *ic = lst->pFirst;
  3613. c->B = ui->TB + (*ui->Type->Theme)->BP;
  3614. for (ic; ic; ic = ic->Item.pNext){
  3615. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3616. ic->B = ic->B < c->B ? c->B : ic->B;
  3617. }
  3618. }
  3619. ic = ui->C;
  3620. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  3621. ;
  3622. for (ic; ic; ic = ic->Item.pNext){
  3623. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3624. ic->B = ic->B < c->B ? c->B : ic->B;
  3625. }
  3626. }
  3627. }
  3628. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  3629. laColumn *c = ui->C;
  3630. laColumn *ic = lst->pFirst;
  3631. c->B = ui->TB + (*ui->Type->Theme)->TP;
  3632. for (ic; ic; ic = ic->Item.pNext){
  3633. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3634. ic->B = ic->B < c->B ? c->B : ic->B;
  3635. }
  3636. }
  3637. ic = ui->C;
  3638. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  3639. ;
  3640. for (ic; ic; ic = ic->Item.pNext){
  3641. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3642. ic->B = ic->B < c->B ? c->B : ic->B;
  3643. }
  3644. }
  3645. }
  3646. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  3647. int rep;
  3648. int sp;
  3649. int rev;
  3650. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  3651. if (!c) return 0;
  3652. sp = (c->SP * (R - L)) + L;
  3653. rev = sp;
  3654. /*if (U)*/ c->B = U;
  3655. if (LR == 1){
  3656. c->IL = L;
  3657. c->IR = sp;
  3658. if (repos){
  3659. c->IR = repos;
  3660. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  3661. c->IR = c->IL + c->MaxW*LA_RH+M;
  3662. rev = c->IR;
  3663. }
  3664. }else if (LR == 2){
  3665. c->IL = sp;
  3666. c->IR = R;
  3667. if (repos){
  3668. c->IL = repos;
  3669. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  3670. c->IL = c->IR - c->MaxW*LA_RH-M;
  3671. rev = c->IL;
  3672. }
  3673. }else if (LR == 0){
  3674. c->IL = L;
  3675. c->IR = R;
  3676. }
  3677. if (c->LS && c->RS->MaxW == 0){
  3678. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  3679. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  3680. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3681. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3682. }else if (c->RS && c->LS->MaxW == 0){
  3683. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  3684. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  3685. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  3686. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  3687. }
  3688. return rev;
  3689. }
  3690. STRUCTURE(laRowInfo){
  3691. int MaxW;
  3692. int MinW;
  3693. int UnitMinW;
  3694. int NonExpandW;
  3695. int TotalPadding;
  3696. int Expand, Even;
  3697. int ExpandAccum;
  3698. int CountElements;
  3699. int U,MaxB,L;
  3700. laListHandle Elements;
  3701. };
  3702. STRUCTURE(laRowNode){
  3703. laListItem Item;
  3704. laUiItem* ui;
  3705. int GotW, LP, RP, H;
  3706. int Expand;
  3707. };
  3708. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  3709. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  3710. ri->UnitMinW=LA_RH+bt->LM+bt->RM;
  3711. ri->Expand=ui->State?1:0;
  3712. ri->Even=ui->Flags?1:0;
  3713. ri->U=ui->TU; ri->L=ui->TL;
  3714. ri->MaxB=ui->TU;
  3715. }
  3716. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H){
  3717. laRowNode* rn=CreateNew(laRowNode);
  3718. rn->LP=bt->LP;rn->RP=bt->RP;
  3719. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH)) +bt->LM+bt->RM;
  3720. rn->ui=ui;
  3721. rn->H=H;
  3722. rn->Expand=ui->Expand;
  3723. lstAppendItem(&ri->Elements, rn);
  3724. if(!ri->UnitMinW){ri->UnitMinW=LA_RH+bt->LM+bt->RM;}
  3725. ri->TotalPadding += bt->LP+bt->RP;
  3726. ri->MinW+=ri->UnitMinW;
  3727. ri->NonExpandW+=rn->GotW;
  3728. ri->ExpandAccum+=ui->Expand;
  3729. ri->CountElements++;
  3730. if(ui->Expand){ri->Expand=1;}
  3731. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  3732. }
  3733. int la_ShrinkableRowElements(laRowInfo* ri){
  3734. int count=0;
  3735. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  3736. if(rn->GotW<=ri->UnitMinW) continue;
  3737. count++;
  3738. }
  3739. return count;
  3740. }
  3741. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end, int WaitAnimation){
  3742. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  3743. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  3744. if(Available<0){
  3745. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  3746. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  3747. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  3748. }else{
  3749. if(!ri->Expand && Available>0){Available=0;}
  3750. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  3751. }
  3752. if(!ShareCount) return 0;
  3753. int PerNode = Available/ShareCount;
  3754. int Remaining = Available-PerNode*ShareCount;
  3755. int L = ri->L; int i=0; laRowNode* rn;
  3756. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  3757. laUiItem* ui=rn->ui;
  3758. int NodeAdd, Node=rn->GotW;
  3759. if(Available>=0){
  3760. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  3761. NodeAdd+=(i<Remaining?1:0);i++;
  3762. }else{
  3763. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  3764. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  3765. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  3766. }else{ Node=ri->UnitMinW;
  3767. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  3768. }
  3769. }
  3770. ui->TL = L + rn->LP;
  3771. ui->TR = ui->TL + Node+NodeAdd;
  3772. ui->TB = ui->TU + rn->H;
  3773. L=ui->TR+rn->RP;
  3774. if (!WaitAnimation){
  3775. ui->L = ui->TL; ui->R = ui->TR;
  3776. ui->U = ui->TU; ui->B = ui->TB;
  3777. }
  3778. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  3779. }
  3780. ui_end->TB = ri->MaxB;
  3781. while(rn=lstPopItem(&ri->Elements)){
  3782. FreeMem(rn);
  3783. }
  3784. memset(ri, 0, sizeof(laRowInfo));
  3785. }
  3786. void la_RecordSocketRuntimePosition(laUiItem* ui){
  3787. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  3788. int sl,sr,su,sb;
  3789. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  3790. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  3791. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  3792. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  3793. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  3794. if(pc==LA_PC_SOCKET_OUT){
  3795. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  3796. }else{
  3797. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  3798. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  3799. }
  3800. }
  3801. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  3802. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  3803. }
  3804. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  3805. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  3806. laBoxedTheme *bt;
  3807. int Lowest = 0;
  3808. int HyperValue = 0;
  3809. int WaitAnimation;
  3810. int RowMode=0; laRowInfo ri={0};
  3811. laBoxedTheme* pt=*(ParentPanel->BT);
  3812. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  3813. int MaxR=0;
  3814. if(!uil->Scale){uil->Scale=1;}
  3815. uil->SaveScale=MAIN.UiScale;
  3816. MAIN.UiScale*=uil->Scale;
  3817. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  3818. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  3819. WaitAnimation = 0;
  3820. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  3821. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  3822. for (ui = uil->UiItems.pFirst; ui;){
  3823. int SubB = 0;
  3824. int H;
  3825. WaitAnimation = 0;
  3826. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  3827. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  3828. //if (Fast && ui->C->B > B) {
  3829. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  3830. // ui = ui->Item.pNext;
  3831. // continue;
  3832. //}
  3833. if (!ui->Instructions){
  3834. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  3835. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  3836. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  3837. laOperatorProp *ap = ui->PP.LastPs->p;
  3838. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  3839. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  3840. }
  3841. }
  3842. if (/*!ui->NoRefresh && */ ui->PP.LastPs){
  3843. la_StepPropPack(&ui->PP);
  3844. }
  3845. la_UsePropPack(&ui->PP, 0);
  3846. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  3847. // 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);
  3848. //}
  3849. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  3850. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  3851. WaitAnimation = 1;
  3852. }
  3853. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  3854. bt = (*ui->Type->Theme);
  3855. if (ui->Type == &_LA_UI_CONDITION){
  3856. laConditionUiExtraData *cued = ui->Extra;
  3857. la_StepExpression(cued->Expression);
  3858. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  3859. if (!cued->IsTrue){
  3860. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  3861. }else{
  3862. ui = ui->Item.pNext;
  3863. }
  3864. continue;
  3865. }else if (ui->Type == &_LA_UI_CONDITION_END){
  3866. ui = ui->Item.pNext;
  3867. continue;
  3868. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  3869. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  3870. if (cued->IsTrue) ui = cued->EndUi;
  3871. else
  3872. ui = ui->Item.pNext;
  3873. continue;
  3874. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  3875. laConditionUiExtraData *cued = ui->Extra;
  3876. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  3877. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  3878. if (!WaitAnimation){
  3879. ui->L = ui->TL; ui->R = ui->TR;
  3880. ui->U = ui->TU; ui->B = ui->TB;
  3881. }
  3882. if(!RowMode){
  3883. la_CalcUiItemInfluence(&uil->Columns, ui);
  3884. }else{
  3885. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  3886. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  3887. }
  3888. if (ui->State == LA_UI_NORMAL){
  3889. cued->IsTrue = 0;
  3890. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  3891. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  3892. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  3893. }else{
  3894. cued->IsTrue = 1;
  3895. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  3896. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  3897. //}
  3898. ui = ui->Item.pNext;
  3899. }
  3900. continue;
  3901. }
  3902. if (ui->Type == _LA_UI_ALIGN){
  3903. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU;
  3904. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  3905. if (ui->TB > Lowest) Lowest = ui->TB;
  3906. if (!WaitAnimation){
  3907. ui->L = ui->TL; ui->R = ui->TR;
  3908. ui->U = ui->TU; ui->B = ui->TB;
  3909. }
  3910. if(!RowMode){
  3911. la_CalcUiItemInfluence(&uil->Columns, ui);
  3912. }else{
  3913. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  3914. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  3915. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  3916. }
  3917. ui = ui->Item.pNext; continue;
  3918. }
  3919. if (ui->Type == &_LA_UI_ROW_BEGIN){
  3920. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  3921. la_InitRowNode(&ri, ui, bt);
  3922. RowMode=1; ui=ui->Item.pNext; continue;
  3923. }
  3924. if (ui->Type == &_LA_UI_ROW_END){
  3925. la_CalculateRowExpand(&ri, ui, WaitAnimation);
  3926. la_CalcUiItemInfluence(&uil->Columns, ui);
  3927. RowMode=0; ui=ui->Item.pNext; continue;
  3928. }
  3929. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  3930. int GB=0;
  3931. 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; }
  3932. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  3933. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  3934. if (H < 0){
  3935. if(B){ H = B + (H+1) * LA_RH - ui->TU; }
  3936. else{ H=LA_RH; }
  3937. }
  3938. else H *= LA_RH;
  3939. ui->TB = ui->TU;
  3940. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  3941. 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
  3942. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  3943. if (ui->Type == _LA_UI_COLLECTION){
  3944. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  3945. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  3946. ui->PP.EndInstance = TInstance;
  3947. laUiList *iuil = ui->Subs.pFirst;
  3948. laUiList *puil = iuil;
  3949. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  3950. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  3951. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  3952. int Begin = ui->TB;
  3953. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  3954. int ElementB = ui->TU;
  3955. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  3956. int MaxB = ElementB;
  3957. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  3958. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  3959. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  3960. if (!ElementLimit) RowPriority = 0;
  3961. if (!TInstance){
  3962. while (iuil){
  3963. puil = iuil->Item.pNext;
  3964. la_DestroyTabPage(ui, iuil, 0);
  3965. iuil = puil;
  3966. }
  3967. }
  3968. while (TInstance){
  3969. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  3970. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  3971. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  3972. ui->PP.EndInstance = TInstance; continue;
  3973. }
  3974. if(CanGetTheme){
  3975. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  3976. la_SwitchThemeQuick(t, OriginalTheme);
  3977. }
  3978. if(CanGetGap){
  3979. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  3980. Gap=g*LA_RH;
  3981. }else Gap=0;
  3982. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  3983. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  3984. }else GotCategory=0;
  3985. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  3986. if (RowPriority){
  3987. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  3988. }
  3989. }
  3990. FirstIn=0;
  3991. if (ElementLimit){
  3992. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  3993. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  3994. }
  3995. while (iuil && iuil->Instance != TInstance){
  3996. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  3997. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  3998. }else{
  3999. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  4000. }
  4001. iuil = puil;
  4002. }
  4003. if(!iuil){
  4004. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  4005. }
  4006. if (!iuil){
  4007. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  4008. la_CalcUiTopInfluence(&uil->Columns, ui);
  4009. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4010. 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);
  4011. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4012. iuil = ui->Page->Item.pNext;
  4013. }else{
  4014. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  4015. 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);
  4016. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4017. la_CalcUiItemInfluence(&uil->Columns, ui);
  4018. iuil = iuil->Item.pNext;
  4019. }
  4020. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4021. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4022. ui->PP.EndInstance = TInstance;
  4023. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4024. if (RowPriority){
  4025. Col += 1;
  4026. if (Col >= ElementLimit){
  4027. Col = 0;
  4028. Row += 1;
  4029. Begin = ElementB + bt->TM;
  4030. }
  4031. }elif(Spread){
  4032. EL+=Spread*LA_RH;
  4033. ER+=Spread*LA_RH;
  4034. }else{
  4035. Row += 1;
  4036. Begin = ElementB + bt->TM;
  4037. if (ElementLimit && Row >= ElementLimit){
  4038. Row = 0;
  4039. Col += 1;
  4040. Begin = ui->TU + bt->TM;
  4041. }
  4042. }
  4043. ui->TB = ElementB;
  4044. MaxB = MaxB < ElementB ? ElementB : MaxB;
  4045. }
  4046. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  4047. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  4048. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4049. ui->TB = MaxB;
  4050. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  4051. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  4052. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  4053. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4054. ui->PP.EndInstance = TInstance;
  4055. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4056. if(!Template) Template=laui_SubPropInfoDefault;
  4057. //ui->Template = Template;
  4058. if (!ui->Subs.pFirst && TInstance){
  4059. la_AddInstancePage(ui, TInstance, 0);
  4060. la_CalcUiTopInfluence(&uil->Columns, ui);
  4061. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4062. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4063. ui->TB = SubB + (NoDecal?0:bt->TM);
  4064. }else if (ui->Subs.pFirst){
  4065. if (!TInstance || TInstance != ui->Page->Instance){
  4066. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  4067. ui->Page = 0;
  4068. if (TInstance){
  4069. la_AddInstancePage(ui, TInstance, 0);
  4070. la_CalcUiTopInfluence(&uil->Columns, ui);
  4071. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4072. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4073. ui->TB = SubB + (NoDecal?0:bt->TM);
  4074. }else
  4075. ui->TB = ui->TU + LA_RH + bt->BM;
  4076. }else{
  4077. SubB = la_UpdateUiListRecursive(ui->Page, ui->TB+(NoDecal?0:bt->TM), ui->TL+(NoDecal?0:bt->LM), ui->TR-(NoDecal?0:bt->RM), B, Fast, ParentPanel);
  4078. ui->TB = SubB + (NoDecal?0:bt->TM);
  4079. }
  4080. }
  4081. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  4082. if (!WaitAnimation){
  4083. ui->L = ui->TL;
  4084. ui->R = ui->TR;
  4085. ui->U = ui->TU;
  4086. ui->B = ui->TB;
  4087. }
  4088. }
  4089. }else{
  4090. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4091. if (ui->Type != _LA_UI_CANVAS){
  4092. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  4093. la_CalcUiTopInfluence(&uil->Columns, ui);
  4094. SubB = la_UpdateUiListRecursive(ui->Page,
  4095. 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);
  4096. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  4097. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH : SubB)) + (NoDecal?0:bt->TM);
  4098. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  4099. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  4100. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  4101. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  4102. }
  4103. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  4104. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  4105. if(GB && ui->TB >= GB){
  4106. ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  4107. if(ui->Page->HeightCoeff){
  4108. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  4109. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  4110. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  4111. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  4112. }
  4113. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  4114. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  4115. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  4116. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  4117. }
  4118. }
  4119. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  4120. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  4121. }else{
  4122. laUiList *suil;
  4123. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  4124. la_CalcUiTopInfluence(&uil->Columns, ui);
  4125. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4126. 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);
  4127. }
  4128. }
  4129. ui->TB = ui->TU + H;
  4130. }
  4131. }else ui->TB = ui->TU + H;
  4132. }
  4133. if (ui->TB > Lowest) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  4134. if(!RowMode){
  4135. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  4136. }else{
  4137. la_AddRowNode(&ri, ui, bt, H);
  4138. }
  4139. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  4140. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4141. ui = ui->Item.pNext;
  4142. }
  4143. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  4144. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  4145. else uil->TB = Lowest;
  4146. if (!WaitAnimation){
  4147. uil->L = uil->TL;
  4148. uil->R = uil->TR;
  4149. uil->U = uil->TU;
  4150. uil->B = uil->TB;
  4151. }
  4152. MAIN.UiScale=uil->SaveScale;
  4153. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4154. return uil->TB;
  4155. }
  4156. int la_AnimateSingleUiSize(int To, int *Now){
  4157. int Delta;
  4158. if (To != *Now){
  4159. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  4160. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  4161. *Now += Delta;
  4162. return 1;
  4163. }else
  4164. return 0;
  4165. }
  4166. int la_AnimateUiListRecursive(laUiList *uil){
  4167. laUiItem *ui;
  4168. int Again = 0;
  4169. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  4170. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  4171. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  4172. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  4173. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  4174. la_AnimateSingleUiSize(ui->TR, &ui->R));
  4175. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4176. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  4177. laUiList *suil;
  4178. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4179. Again += la_AnimateUiListRecursive(suil);
  4180. }
  4181. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  4182. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4183. Again += la_AnimateUiListRecursive(ui->Page);
  4184. }
  4185. }
  4186. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  4187. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  4188. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  4189. la_AnimateSingleUiSize(uil->TR, &uil->R));
  4190. return Again;
  4191. }
  4192. int la_DrawUiItem(laUiItem *ui){
  4193. tnsUseNoTexture();
  4194. tnsColor4d(1, 1, 1, 1);
  4195. tnsVertex2d(ui->L, ui->U);
  4196. tnsVertex2d(ui->R, ui->U);
  4197. tnsVertex2d(ui->R, ui->B);
  4198. tnsVertex2d(ui->L, ui->B);
  4199. tnsPackAs(GL_LINE_LOOP);
  4200. }
  4201. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  4202. tnsUseNoTexture();
  4203. tnsColor4d(1, 1, 1, 1);
  4204. tnsVertex2d(ui->L - 1, ui->U - 1);
  4205. tnsVertex2d(ui->R + 1, ui->U - 1);
  4206. tnsVertex2d(ui->R + 1, ui->B + 1);
  4207. tnsVertex2d(ui->L - 1, ui->B + 1);
  4208. tnsPackAs(GL_LINE_LOOP);
  4209. }
  4210. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  4211. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  4212. return 1;
  4213. }
  4214. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  4215. laUiListDrawItem *uildi = uild->Items.pFirst;
  4216. laUiList *Target = uildi->Target;
  4217. int L, R, U, B;
  4218. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  4219. L = Target->L + Target->PanX + uildi->DifX;
  4220. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4221. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4222. U = Target->U + Target->PanY + uildi->DifY;
  4223. return la_UiInBound(ui, L, R, U, B);
  4224. }
  4225. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  4226. laUiListDrawItem *uildi = uild->Items.pFirst;
  4227. laUiList *Target = uildi->Target;
  4228. int L, R, U, B;
  4229. if (Target){
  4230. L = Target->L + Target->PanX + uildi->DifX;
  4231. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4232. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4233. U = Target->U + Target->PanY + uildi->DifY;
  4234. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  4235. return 1;
  4236. }else{
  4237. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  4238. return 1;
  4239. }
  4240. }
  4241. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  4242. laUiItem *ui = uil->UiItems.pFirst;
  4243. while (!strGetArgument(ui->Instructions, mark))
  4244. ui = ui->Item.pNext;
  4245. return ui;
  4246. }
  4247. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  4248. laUiList *uil;
  4249. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  4250. if (uil->Instance == Instance) return uil;
  4251. }
  4252. return uil;
  4253. }
  4254. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  4255. int mx=(L+R)/2; int my=(U+B)/2;
  4256. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  4257. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  4258. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  4259. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  4260. tnsFlush();
  4261. }
  4262. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  4263. if(!uil->ScrollerShownV) return;
  4264. int W = LA_SCROLL_W;
  4265. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  4266. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  4267. int U = uil->U + Offset;
  4268. int B = U + Len;
  4269. int L = UiR - _LA_THEME_PANEL->RM - W;
  4270. int R = L + W;
  4271. if (B > U + DisplayH) B = U + DisplayH;
  4272. if (U < uil->U) U = uil->U;
  4273. if (B <= uil->U || U >= uil->B) return;
  4274. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  4275. if (U < uil->U) U = uil->U;
  4276. tnsUseNoTexture();
  4277. laBoxedTheme* bt=_LA_THEME_PANEL;
  4278. real* color=laThemeColor(bt, LA_BT_TEXT);
  4279. tnsColor4d(LA_COLOR3(color), 0.8);
  4280. tnsVertex2d(R, U);
  4281. tnsVertex2d(L, U);
  4282. tnsVertex2d(L, B);
  4283. tnsVertex2d(R, B);
  4284. tnsPackAs(GL_TRIANGLE_FAN);
  4285. tnsColor4d(LA_COLOR3(color), 0.8);
  4286. tnsVertex2d(R, uil->U);
  4287. tnsVertex2d(L, uil->U);
  4288. tnsVertex2d(L, uil->U + DisplayH);
  4289. tnsVertex2d(R, uil->U + DisplayH);
  4290. tnsPackAs(GL_LINE_LOOP);
  4291. int HU=(U+B)/2+LA_RH2;
  4292. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4293. }
  4294. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  4295. if(!uil->ScrollerShownH) return;
  4296. int W = LA_SCROLL_W;
  4297. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  4298. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  4299. int L = uil->L + Offset;
  4300. int R = L + Len;
  4301. int U = UiB - _LA_THEME_PANEL->RM - W;
  4302. int B = U + W;
  4303. if (B > U + DisplayW) B = U + DisplayW;
  4304. if (U < uil->U) U = uil->U;
  4305. if (R <= uil->L || L >= uil->R) return;
  4306. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  4307. if (L < uil->L) L = uil->L;
  4308. tnsUseNoTexture();
  4309. laBoxedTheme* bt=_LA_THEME_PANEL;
  4310. real* color=laThemeColor(bt, LA_BT_TEXT);
  4311. tnsColor4d(LA_COLOR3(color), 0.8);
  4312. tnsVertex2d(R, U);
  4313. tnsVertex2d(L, U);
  4314. tnsVertex2d(L, B);
  4315. tnsVertex2d(R, B);
  4316. tnsPackAs(GL_TRIANGLE_FAN);
  4317. tnsColor4d(LA_COLOR3(color), 0.8);
  4318. tnsVertex2d(uil->L,U);
  4319. tnsVertex2d(uil->L,B);
  4320. tnsVertex2d(uil->L + DisplayW,B);
  4321. tnsVertex2d(uil->L + DisplayW,U);
  4322. tnsPackAs(GL_LINE_LOOP);
  4323. int HU=(U+B)/2+LA_RH2;
  4324. tnsDrawStringAuto("↔",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4325. }
  4326. void la_DrawInstanceBkg(laUiList *uil, real* color){
  4327. tnsUseNoTexture();
  4328. tnsColor4dv(color);
  4329. tnsVertex2d(uil->L, uil->U); tnsVertex2d(uil->R, uil->U);
  4330. tnsVertex2d(uil->R, uil->B); tnsVertex2d(uil->L, uil->B);
  4331. tnsPackAs(GL_TRIANGLE_FAN);
  4332. }
  4333. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  4334. laSocketRecord* sr;
  4335. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  4336. uild->WiresContainer=container;
  4337. }
  4338. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  4339. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  4340. if(lip->Target==uild->WiresContainer) break;
  4341. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  4342. }
  4343. }
  4344. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  4345. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4346. int PanX, PanY;
  4347. if(pc==LA_PC_SOCKET_OUT){
  4348. laNodeOutSocket* s=ui->PP.EndInstance;
  4349. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  4350. }else{
  4351. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  4352. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  4353. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  4354. }
  4355. }
  4356. void la_RegenerateWireColors(){
  4357. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  4358. laTheme* t=MAIN.CurrentTheme;
  4359. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  4360. real hcy[]={0.0,0.8,0.6}; hcy[1]=t->WireSaturation; hcy[2]=t->WireBrightness;
  4361. for(int i=0;i<MAIN.WireColorSlices;i++){
  4362. hcy[0]=(real)i/(real)MAIN.WireColorSlices;
  4363. tnsHCY2RGB(hcy, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  4364. }
  4365. }
  4366. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  4367. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  4368. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  4369. tnsInterpolate2dv(v1,v2,0.5,vi);
  4370. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=log(dist+1)*MAIN.WireSaggyness; }
  4371. tnsVectorMinus2d(v1s,vi,v1); tnsNormalizeSelf2d(v1s); tnsVectorMultiSelf2d(v1s,circle_r);
  4372. tnsVectorMinus2d(v2s,vi,v2); tnsNormalizeSelf2d(v2s); tnsVectorMultiSelf2d(v2s,circle_r);
  4373. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  4374. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  4375. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  4376. tnsVertex2d(v1[0],v1[1]);
  4377. for(int i=1;i<=steps;i++){
  4378. real ratio=i==steps?1.0f:step*i;
  4379. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  4380. tnsVertex2d(v1s[0],v1s[1]);
  4381. }
  4382. }
  4383. void la_DrawNodeWires(laUiListDraw* uild){
  4384. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  4385. laBoxedTheme* bt=_LA_THEME_SOCKET;
  4386. tnsUseNoTexture();
  4387. #define _RSLICES 16
  4388. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  4389. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4390. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4391. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4392. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4393. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4394. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4395. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4396. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4397. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4398. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4399. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4400. }
  4401. if(MAIN.tNodeIn->Source){
  4402. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4403. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4404. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4405. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4406. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4407. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4408. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4409. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4410. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4411. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4412. }
  4413. #undef _RSLICES
  4414. tnsFlush();
  4415. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  4416. glLineWidth(ww);
  4417. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4418. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4419. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4420. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4421. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4422. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4423. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4424. }
  4425. if(MAIN.tNodeIn->Source){
  4426. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4427. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4428. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4429. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4430. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4431. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4432. }
  4433. tnsFlush();
  4434. glLineWidth(1);
  4435. la_InitSocketRecord(uild,0);
  4436. }
  4437. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  4438. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  4439. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  4440. }
  4441. 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){
  4442. laUiItem *ui;
  4443. laBoxedTheme *bt;
  4444. laUiList *sub;
  4445. laUiListDrawItem *uildi;
  4446. int Ret = 0;
  4447. if (!uil) return 0;
  4448. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  4449. ui = uil->UiItems.pFirst;
  4450. if(uil->PanY<0){uil->PanY=0;}
  4451. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  4452. uil->SaveScale=MAIN.UiScale;
  4453. MAIN.UiScale*=uil->Scale;
  4454. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4455. for (; ui;){
  4456. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4457. if (ui->Type == &_LA_UI_CONDITION){
  4458. laConditionUiExtraData *cued = ui->Extra;
  4459. la_StepExpression(cued->Expression);
  4460. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4461. if (!cued->IsTrue){
  4462. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4463. }else{
  4464. ui = ui->Item.pNext;
  4465. }
  4466. continue;
  4467. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4468. ui = ui->Item.pNext;
  4469. continue;
  4470. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4471. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4472. if (cued->IsTrue) ui = cued->EndUi;
  4473. else
  4474. ui = ui->Item.pNext;
  4475. continue;
  4476. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4477. laConditionUiExtraData *cued = ui->Extra;
  4478. ui->Type->Draw(ui, LA_RH);
  4479. if (ui->State == LA_UI_NORMAL){
  4480. cued->IsTrue = 0;
  4481. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4482. }else{
  4483. cued->IsTrue = 1;
  4484. ui = ui->Item.pNext;
  4485. }
  4486. continue;
  4487. }
  4488. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  4489. int NeedDraw=0;
  4490. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  4491. if(NeedDraw){
  4492. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  4493. }else{ ui->Type->Draw(ui, LA_RH); }
  4494. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  4495. tnsFlush();
  4496. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  4497. tnsResetViewMatrix();
  4498. }
  4499. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  4500. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  4501. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  4502. tnsFlush();
  4503. }
  4504. }
  4505. if(NeedDraw || RegisterNodes){
  4506. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  4507. if (ui->Type == _LA_UI_FIXED_GROUP ||
  4508. ui->Type == _LA_UI_TAB ||
  4509. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4510. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  4511. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  4512. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4513. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  4514. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  4515. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  4516. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  4517. 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); }
  4518. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  4519. 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);
  4520. 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)); }
  4521. }elif (ui->Type == _LA_UI_COLLECTION){
  4522. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  4523. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4524. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4525. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4526. int State;
  4527. ui->PP.EndInstance = sub->Instance;
  4528. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  4529. if(!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && NeedDraw){
  4530. if (CanGetState){
  4531. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  4532. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL));
  4533. }elif (sub->Instance == Active){
  4534. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL));
  4535. }
  4536. }
  4537. if(sub->TabName && sub->TabName->Ptr){
  4538. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4539. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4540. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  4541. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  4542. tnsFlush();
  4543. }
  4544. if(CanGetTheme){
  4545. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4546. la_SwitchThemeQuick(t, OriginalTheme);
  4547. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL));
  4548. }
  4549. tnsFlush();
  4550. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  4551. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4552. }
  4553. ui->PP.EndInstance = Active;
  4554. }elif (ui->Type == _LA_UI_CANVAS){
  4555. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4556. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4557. tnsFlush();
  4558. Ret += la_DrawUiListRecursive(uild, sub, L-1, R+1, U-1, B+1, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  4559. }
  4560. }
  4561. }
  4562. ui = ui->Item.pNext;
  4563. }else{
  4564. ui = ui->Item.pNext;
  4565. }
  4566. }
  4567. tnsFlush();
  4568. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  4569. la_RestoreLastUiListMatrix(uild, B - U);
  4570. MAIN.UiScale=uil->SaveScale;
  4571. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4572. return Ret;
  4573. }
  4574. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  4575. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  4576. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  4577. tnsUseNoTexture();
  4578. tnsColor4d(1, 1, 1, 1);
  4579. tnsVertex2d(L, U);
  4580. tnsVertex2d(R, U);
  4581. tnsVertex2d(R, B);
  4582. tnsVertex2d(L, B);
  4583. tnsPackAs(GL_LINE_LOOP);
  4584. tnsVertex2d(L + 3, Begin);
  4585. tnsVertex2d(R - 3, Begin);
  4586. tnsVertex2d(R - 3, End);
  4587. tnsVertex2d(L + 3, End);
  4588. tnsPackAs(GL_LINE_LOOP);
  4589. }
  4590. int laIsInUiItem(laUiItem *ui, int x, int y){
  4591. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  4592. return 1;
  4593. }
  4594. int laIsInBound(int x, int y, int l, int r, int u, int b){
  4595. if (x < l || x > r || y < u || y > b) return 0;
  4596. return 1;
  4597. }
  4598. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  4599. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  4600. laUiItem *ui, *tui;
  4601. laBoxedTheme *bt;
  4602. laUiList *sub;
  4603. int CPB = 0;
  4604. if (!uil || (LimB && y > LimB)) return 0;
  4605. x += uil->PanX;
  4606. y += uil->PanY;
  4607. for (ui = uil->UiItems.pFirst; ui;){
  4608. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4609. if (ui->Type == &_LA_UI_CONDITION){
  4610. laConditionUiExtraData *cued = ui->Extra;
  4611. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  4612. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4613. if (!cued->IsTrue){
  4614. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4615. }else{
  4616. ui = ui->Item.pNext;
  4617. }
  4618. continue;
  4619. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4620. ui = ui->Item.pNext;
  4621. continue;
  4622. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4623. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4624. if (cued->IsTrue) ui = cued->EndUi;
  4625. else
  4626. ui = ui->Item.pNext;
  4627. continue;
  4628. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4629. laConditionUiExtraData *cued = ui->Extra;
  4630. if (laIsInUiItem(ui, x, y)){
  4631. lstAppendPointer(LocalBuf, uil);
  4632. return ui;
  4633. }
  4634. if (ui->State == LA_UI_NORMAL){
  4635. cued->IsTrue = 0;
  4636. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4637. }else{
  4638. cued->IsTrue = 1;
  4639. ui = ui->Item.pNext;
  4640. }
  4641. continue;
  4642. }
  4643. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  4644. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  4645. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  4646. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  4647. if(!la_DetectSplit(ui->C, x)) Add=0;
  4648. }
  4649. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  4650. }
  4651. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4652. if (ui->Page->HeightCoeff) CPB = ui->B;
  4653. else CPB = ui->Page->B;
  4654. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4655. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  4656. lstAppendPointer(LocalBuf, uil);
  4657. return tui;
  4658. }
  4659. }else if (laIsInUiItem(ui, x, y)){
  4660. lstAppendPointer(LocalBuf, uil);return ui;
  4661. }
  4662. }
  4663. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  4664. if (laIsInUiItem(ui, x, y)){
  4665. lstAppendPointer(LocalBuf, uil);
  4666. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  4667. if(Deep){
  4668. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  4669. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  4670. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  4671. lstAppendPointer(LocalBuf, iuil);
  4672. return tui;
  4673. }
  4674. }
  4675. }
  4676. }
  4677. return ui;
  4678. }
  4679. }
  4680. if (ui->Type == _LA_UI_CANVAS){
  4681. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4682. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4683. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  4684. lstAppendPointer(LocalBuf, uil);
  4685. return tui;
  4686. }
  4687. }
  4688. }
  4689. if (laIsInUiItem(ui, x, y)){
  4690. lstAppendPointer(LocalBuf, uil);
  4691. return ui;
  4692. }
  4693. }
  4694. ui = ui->Item.pNext;
  4695. }
  4696. return 0;
  4697. }
  4698. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  4699. laListHandle Locals={0};
  4700. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  4701. while(lstPopPointer(&Locals));
  4702. printf("%s\n", ui?ui->Type->Identifier:"?");
  4703. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  4704. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4705. if(pc==PCInOrOut) return ui;
  4706. }
  4707. return 0;
  4708. }
  4709. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  4710. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  4711. laUiItem *ui = uil->UiItems.pFirst;
  4712. laBoxedTheme *bt;
  4713. laUiList *tuil;
  4714. laUiList *sub;
  4715. int CPB = 0;
  4716. x += uil->PanX;
  4717. y += uil->PanY;
  4718. if (y > LimH) return uil;
  4719. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  4720. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  4721. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  4722. return uil;
  4723. }
  4724. for (ui = uil->UiItems.pFirst; ui;){
  4725. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4726. if (ui->Type == &_LA_UI_CONDITION){
  4727. laConditionUiExtraData *cued = ui->Extra;
  4728. //la_StepExpression(cued->Expression);
  4729. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4730. if (!cued->IsTrue){
  4731. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4732. }else{
  4733. ui = ui->Item.pNext;
  4734. }
  4735. continue;
  4736. }
  4737. if (ui->Type == &_LA_UI_CONDITION_END){
  4738. ui = ui->Item.pNext;
  4739. continue;
  4740. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4741. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4742. if (cued->IsTrue) ui = cued->EndUi;
  4743. else
  4744. ui = ui->Item.pNext;
  4745. continue;
  4746. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4747. laConditionUiExtraData *cued = ui->Extra;
  4748. if (ui->State == LA_UI_NORMAL){
  4749. cued->IsTrue = 0;
  4750. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4751. }else{
  4752. cued->IsTrue = 1;
  4753. ui = ui->Item.pNext;
  4754. }
  4755. continue;
  4756. }
  4757. if (InToContainerUI && ui != Exception){
  4758. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4759. if (ContainerParent) (*ContainerParent) = uil;
  4760. if (ParentUi) *ParentUi = ui;
  4761. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4762. //if (y > LimH) return uil;
  4763. 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))){
  4764. return tuil;
  4765. }
  4766. }
  4767. }
  4768. }
  4769. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4770. if (ui->Page->HeightCoeff) CPB = ui->B;
  4771. else CPB = ui->Page->B;
  4772. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  4773. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  4774. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  4775. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  4776. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4777. if (ParentUi) *ParentUi = ui;
  4778. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  4779. }
  4780. }
  4781. ui = ui->Item.pNext;
  4782. }
  4783. return uil;
  4784. }
  4785. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  4786. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  4787. laUiItem *ui = uil->UiItems.pFirst;
  4788. laBoxedTheme *bt;
  4789. laUiList *tuil;
  4790. laUiList *sub;
  4791. int CPB = 0;
  4792. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  4793. x += uil->PanX;
  4794. y += uil->PanY;
  4795. if (y > LimH) return uil;
  4796. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  4797. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  4798. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  4799. return uil;
  4800. }
  4801. for (ui = uil->UiItems.pFirst; ui;){
  4802. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4803. if (ui->Type == &_LA_UI_CONDITION){
  4804. laConditionUiExtraData *cued = ui->Extra;
  4805. //la_StepExpression(cued->Expression);
  4806. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4807. if (!cued->IsTrue){
  4808. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4809. }else{
  4810. ui = ui->Item.pNext;
  4811. }
  4812. continue;
  4813. }
  4814. if (ui->Type == &_LA_UI_CONDITION_END){
  4815. ui = ui->Item.pNext;
  4816. continue;
  4817. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4818. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4819. if (cued->IsTrue) ui = cued->EndUi;
  4820. else
  4821. ui = ui->Item.pNext;
  4822. continue;
  4823. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4824. laConditionUiExtraData *cued = ui->Extra;
  4825. if (ui->State == LA_UI_NORMAL){
  4826. cued->IsTrue = 0;
  4827. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4828. }else{
  4829. cued->IsTrue = 1;
  4830. ui = ui->Item.pNext;
  4831. }
  4832. continue;
  4833. }
  4834. if (InToContainerUI && ui != Exception){
  4835. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4836. if (ContainerParent) (*ContainerParent) = uil;
  4837. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4838. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4839. //if (y > LimH) return uil;
  4840. 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))){
  4841. return tuil;
  4842. }
  4843. }
  4844. }
  4845. }
  4846. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4847. if (ui->Page->HeightCoeff) CPB = ui->B;
  4848. else CPB = ui->Page->B;
  4849. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  4850. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4851. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  4852. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4853. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4854. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4855. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  4856. }
  4857. }
  4858. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  4859. if (ui->Page->HeightCoeff) CPB = ui->B;
  4860. else
  4861. CPB = ui->Page->B;
  4862. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  4863. if (ScrollUil) *ScrollUil = ui->Page;
  4864. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4865. }
  4866. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  4867. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  4868. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  4869. }
  4870. }
  4871. ui = ui->Item.pNext;
  4872. }
  4873. return uil;
  4874. }
  4875. int la_TestUiListMinumWidth(laUiList *uil){
  4876. laUiItem *ui, *tui;
  4877. laBoxedTheme *bt;
  4878. laUiList *sub;
  4879. int CPB = 0;
  4880. int W = 0;
  4881. int tW, sW, RowMode=0, rW;
  4882. void *Restore;
  4883. for (ui = uil->UiItems.pFirst; ui;){
  4884. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4885. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  4886. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  4887. tW = (int)((float)tW / ui->C->PreWidth + 2);
  4888. if (W < tW) W = tW;
  4889. }elif (ui->Type == _LA_UI_COLLECTION){
  4890. Restore = ui->PP.EndInstance;
  4891. tW = 0; sW = 0;
  4892. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4893. ui->PP.EndInstance = sub->Instance;
  4894. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  4895. if (sW > tW) tW = sW;
  4896. }
  4897. ui->PP.EndInstance = Restore;
  4898. tW = (int)((float)tW / ui->C->PreWidth + 2);
  4899. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  4900. if (W < tW) W = tW;
  4901. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  4902. RowMode=1; rW=0;
  4903. }elif (ui->Type==&_LA_UI_ROW_END){
  4904. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  4905. }elif (ui->Type->GetMinWidth){
  4906. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  4907. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  4908. }
  4909. ui = ui->Item.pNext;
  4910. }
  4911. return W;
  4912. }
  4913. void la_InitLLVM(){
  4914. //LLVMLinkInMCJIT();
  4915. //LLVMInitializeNativeTarget();
  4916. //LLVMInitializeNativeAsmPrinter();
  4917. //LLVMInitializeNativeAsmParser();
  4918. // MAIN.llvmContext = LLVMGetGlobalContext();
  4919. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  4920. }
  4921. //==================================================================================================
  4922. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  4923. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  4924. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  4925. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  4926. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  4927. memFree(kmi);
  4928. }
  4929. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  4930. laKeyMapItem *kmi;
  4931. if (!km) return 0;
  4932. kmi = memAcquire(sizeof(laKeyMapItem));
  4933. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  4934. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  4935. }else{
  4936. strSafeSet(&kmi->Operation, Operation);
  4937. }
  4938. strSafeSet(&kmi->Instructions, ExtraInstructions);
  4939. kmi->SpecialKeyBits = SpecialKeyBits;
  4940. kmi->EventType = EventType;
  4941. kmi->Key = Key;
  4942. kmi->SelectBase = SelectBase;
  4943. lstAppendItem(&km->Items, kmi);
  4944. return kmi;
  4945. }
  4946. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  4947. laKeyMapItem *kmi; int inv=0;
  4948. char *instructions;
  4949. if(e->Type==LA_MOUSEMOVE) return 0;
  4950. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  4951. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  4952. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  4953. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  4954. if (kmi->Operation)
  4955. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  4956. else
  4957. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  4958. inv = 1;
  4959. }
  4960. }
  4961. return inv;
  4962. }
  4963. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  4964. laKeyMapItem *kmi;
  4965. char *instructions;
  4966. int inv = 0; int lx = -1, ly = -1;
  4967. if(e->Type==LA_MOUSEMOVE) return 0;
  4968. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  4969. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  4970. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  4971. if (e->Localized){
  4972. lx = e->x;
  4973. ly = e->y;
  4974. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  4975. e->Localized = 0;
  4976. }
  4977. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  4978. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  4979. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  4980. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  4981. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  4982. }elif (kmi->Operation){
  4983. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  4984. }else{
  4985. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  4986. }
  4987. inv = 1;
  4988. if (lx >= 0){
  4989. e->x = lx;
  4990. e->y = ly;
  4991. e->Localized = 1;
  4992. }
  4993. }
  4994. }
  4995. return inv;
  4996. }
  4997. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  4998. void la_DestroyOperatorType(laOperatorType* at){
  4999. //if(at->PC) la_FreePropertyContainer(at->PC);
  5000. memFree(at);
  5001. }
  5002. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  5003. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  5004. uint32_t IconID, int ExtraMark){
  5005. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  5006. at->Identifier = ID;
  5007. at->Name = Name;
  5008. at->Description = Description;
  5009. at->Check = Check;
  5010. at->Invoke = Invoke;
  5011. at->Init = Init;
  5012. at->Exit = Exit;
  5013. at->Modal = Modal;
  5014. at->IconID = IconID;
  5015. at->ExtraMark = ExtraMark;
  5016. at->ParseArgs = la_DefaultOperatorParser;
  5017. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  5018. return at;
  5019. }
  5020. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  5021. ot->PC = memAcquire(sizeof(laPropContainer));
  5022. ot->PC->Identifier = ot->Identifier;
  5023. ot->PC->Hyper = HyperLevel;
  5024. return ot->PC;
  5025. }
  5026. laOperator *la_CreateOperator(laOperatorType *at){
  5027. laOperator *a = CreateNew(laOperator);
  5028. a->Type = at;
  5029. if (at->PC && at->PC->Props.pFirst){
  5030. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  5031. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  5032. a->PP.LastPs->p->SubProp = at->PC;
  5033. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  5034. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  5035. a->PP.LastPs->Type = L'.';
  5036. }
  5037. return a;
  5038. }
  5039. int la_OperatorTypeByID(laOperatorType *a, char *id){
  5040. return (!strcmp(a->Identifier, id));
  5041. }
  5042. laOperatorType *laGetOperatorType(const char *ID){
  5043. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5044. }
  5045. int laOperatorExistsT(laOperatorType* at){
  5046. if (!at) return 0;
  5047. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  5048. return 0;
  5049. }
  5050. int laOperatorExists(const char* ID){
  5051. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  5052. return laOperatorExistsT(at);
  5053. }
  5054. int la_OperatorExists(laOperator *ac){
  5055. if (!ac) return 0;
  5056. laOperator *a;
  5057. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  5058. return 0;
  5059. }
  5060. int la_UiOperatorExists(void *inst){
  5061. laOperator *a;
  5062. if (!inst) return 0;
  5063. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  5064. if (((laUiItem *)a->Instance) == inst){
  5065. return 1;
  5066. }
  5067. }
  5068. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5069. if (a->Instance == inst){
  5070. return 1;
  5071. }
  5072. }
  5073. return 0;
  5074. }
  5075. int la_OperatorPending(laOperator *target){
  5076. laOperator *a;
  5077. if (!target) return 0;
  5078. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5079. if (a == target){
  5080. return 1;
  5081. }
  5082. }
  5083. return 0;
  5084. }
  5085. void laSetOperatorLocalizer(void *ToPanel){
  5086. MAIN.ToPanel = ToPanel;
  5087. }
  5088. void la_DestroyConfirmData(laConfirmData **cd);
  5089. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  5090. laOperator *ai = (*a);
  5091. laOperator *ac = ((*a)->Child);
  5092. void *Ret = 0;
  5093. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using){
  5094. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  5095. }
  5096. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  5097. if ((*a)->PP.LastPs){
  5098. memFree((*a)->PP.LastPs->p);
  5099. memFree((*a)->PP.LastPs);
  5100. }
  5101. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  5102. la_SetPropMathcerContext((*a)->OperatorPanel);
  5103. MAIN.CurrentPanel = (*a)->OperatorPanel;
  5104. laDestroySinglePanel((*a)->OperatorPanel,0);
  5105. }
  5106. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  5107. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  5108. lstClearPointer(&(*a)->LocalUiLists);
  5109. if (Operators){
  5110. Ret = ai->Item.pNext;
  5111. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  5112. else
  5113. lstRemoveItem(Operators, *a);
  5114. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  5115. if (ai->Child == (*a)) ai->Child = 0;
  5116. }
  5117. }
  5118. strSafeDestroy(&(*a)->RuntimeHint);
  5119. free(*a);
  5120. return Ret;
  5121. }
  5122. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  5123. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5124. if (!at) return 0;
  5125. if (!at->Check) return 1;
  5126. return (at->Check(This, Instructions));
  5127. }
  5128. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  5129. if (!at) return 0;
  5130. if (!at->Check) return 1;
  5131. return (at->Check(This, Instructions));
  5132. }
  5133. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5134. laPropPack FakePP = {0};
  5135. laPropStep FakePs = {0};
  5136. if (!at) return 0;
  5137. if (!at->Check) return 1;
  5138. FakePP.LastPs = &FakePs;
  5139. FakePP.Go = FakePP.LastPs;
  5140. FakePP.LastPs->p = This->LastPs->p;
  5141. FakePP.LastPs->UseInstance = This->EndInstance;
  5142. FakePP.EndInstance = Real_FromInstance;
  5143. FakePP.LastIndex = This->LastIndex;
  5144. return (at->Check(&FakePP, Instructions));
  5145. }
  5146. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5147. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5148. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  5149. }
  5150. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  5151. laOperator *a, *f = From;
  5152. int rev;
  5153. if (!f && e&&e->Localized) return -1;
  5154. a = la_CreateOperator(at);
  5155. a->ToPanel = MAIN.ToPanel;
  5156. a->This = This;
  5157. a->ExtraInstructions = args;
  5158. strMakeInstructions(&a->ExtraInstructionsP, args);
  5159. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5160. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5161. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  5162. la_DestroyOperator(&a, 0, 0);
  5163. return LA_CANCELED;
  5164. }
  5165. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5166. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  5167. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5168. e->Localized = 1;
  5169. }
  5170. if (e&&e->Localized){
  5171. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  5172. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5173. e->Localized = 0;
  5174. }else{
  5175. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5176. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5177. }
  5178. }
  5179. if (From) f->Child = a;
  5180. a->Using = 1;
  5181. if (at->Init) at->Init(a);
  5182. rev = at->Invoke(a, e);
  5183. a->Using = 0;
  5184. if (rev & LA_FINISH){
  5185. a->StopNow = 1; if(From)From->Child=0;
  5186. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5187. }
  5188. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5189. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5190. a->State = rev;
  5191. a->PP.EndInstance = a->CustomData;
  5192. if (a->PP.LastPs) a->PP.LastPs->Type = L'.';
  5193. }else
  5194. la_DestroyOperator(&a, 0, 0);
  5195. return rev;
  5196. }
  5197. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  5198. laOperatorType *at; laOperator *a, *f = From;
  5199. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5200. if (!at) return -1;
  5201. return laInvokeP(From,at,e,This,args,args2);
  5202. }
  5203. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  5204. laOperator *a, *f = From;
  5205. int rev;
  5206. laPropPack *created;
  5207. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  5208. created = memAcquireSimple(sizeof(laPropPack));
  5209. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  5210. created->Go = created->LastPs;
  5211. created->LastPs->p = OrigionalThis->LastPs->p;
  5212. created->LastPs->UseInstance = FromInstance;
  5213. created->EndInstance = FromInstance;
  5214. created->LastIndex = OrigionalThis->LastIndex;
  5215. a = la_CreateOperator(at);
  5216. a->ToPanel = MAIN.ToPanel;
  5217. a->This = created;
  5218. a->CreatedThis = created;
  5219. a->ExtraInstructions = args;
  5220. strMakeInstructions(&a->ExtraInstructionsP, args);
  5221. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5222. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5223. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  5224. la_DestroyOperator(&a, 0, 0);
  5225. return LA_CANCELED;
  5226. }
  5227. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5228. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5229. if (From) f->Child = a;
  5230. a->Using = 1;
  5231. if (at->Init) at->Init(a);
  5232. rev = at->Invoke(a, e);
  5233. a->Using = 0;
  5234. if (rev & LA_FINISH){
  5235. a->StopNow = 1; if(From)From->Child=0;
  5236. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5237. }
  5238. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5239. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5240. a->State = rev;
  5241. a->PP.EndInstance = a->CustomData;
  5242. }else
  5243. la_DestroyOperator(&a, 0, 0);
  5244. return rev;
  5245. }
  5246. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5247. laOperator *a, *f = From;
  5248. int rev;
  5249. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  5250. a = la_CreateOperator(at);
  5251. a->Instance = inst;
  5252. a->ToPanel = MAIN.ToPanel;
  5253. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  5254. if (From) f->Child = a;
  5255. a->Using = 1;
  5256. if (at->Init) at->Init(a);
  5257. rev = at->Invoke(a, e);
  5258. a->Using = 0;
  5259. if (rev & LA_FINISH){
  5260. a->StopNow = 1; if(From)From->Child=0;
  5261. }
  5262. if (rev & LA_BLOCK){
  5263. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5264. a->State = rev;
  5265. }else la_DestroyOperator(&a, 0, 0);
  5266. DEB = a;
  5267. return rev;
  5268. }
  5269. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5270. laOperatorType *at;
  5271. laOperator *a, *f = From;
  5272. if (la_UiOperatorExists(inst)) return -1;
  5273. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  5274. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  5275. }
  5276. void laRequestDelayEvent(real Seconds){
  5277. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  5278. int la_UiStillInService(void *UiInstance){
  5279. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  5280. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  5281. if (ai->Instance == UiInstance) return 1;
  5282. }
  5283. return 0;
  5284. }
  5285. void la_StopUiOperatorService(void *UiInstance){
  5286. laOperator *ai, *dai, *NextAi;
  5287. if (!MAIN.CurrentWindow) return;
  5288. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5289. NextAi = ai->Item.pNext;
  5290. if (ai->Instance == UiInstance){
  5291. if (ai->Child){
  5292. la_StopUiOperatorService(ai->Child->Instance);
  5293. ai->Child = 0;
  5294. }
  5295. laOperator *dai = ai;
  5296. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  5297. continue;
  5298. }
  5299. }
  5300. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5301. NextAi = ai->Item.pNext;
  5302. if (ai->Instance == UiInstance){
  5303. if (ai->Instance == ai->ToPanel){
  5304. //laHidePanelWithDissoveEffect(ai->ToPanel);
  5305. //ai->ToPanel->LaterDestroy = 1;
  5306. }
  5307. if (ai->Child && la_OperatorExists(ai->Child)){
  5308. la_StopUiOperatorService(ai->Child->Instance);
  5309. //ai->Child = 0;
  5310. }
  5311. if (!ai->Using){
  5312. laOperator *dai = ai;
  5313. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5314. }else
  5315. ai->StopNow = 1;
  5316. }
  5317. }
  5318. }
  5319. void la_StopAllOperators(){
  5320. laOperator *ai, *dai, *NextAi;
  5321. if (!MAIN.CurrentWindow) return;
  5322. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5323. NextAi = ai->Item.pNext;
  5324. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  5325. continue;
  5326. }
  5327. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5328. NextAi = ai->Item.pNext;
  5329. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  5330. laHidePanelWithDissoveEffect(ai->ToPanel);
  5331. ai->ToPanel->LaterDestroy = 1;
  5332. }
  5333. if (!ai->Using){
  5334. laOperator *dai = ai;
  5335. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5336. }else ai->StopNow = 1;
  5337. }
  5338. }
  5339. void la_DestroyConfirmData(laConfirmData **cd){
  5340. if((!cd)||!(*cd)) return;
  5341. if ((*cd)->CustomData) (*cd)->Destroy((*cd)->CustomData);
  5342. if ((*cd)->StrData) free((*cd)->StrData);
  5343. FreeMem((*cd));
  5344. (*cd) = 0;
  5345. }
  5346. void laConfirmInt(laOperator *a, int Data, int mode){
  5347. laOperator *ai = a;
  5348. laConfirmData *cd = CreateNew(laConfirmData);
  5349. cd->IData = Data;
  5350. cd->Mode = mode;
  5351. ai->NextConfirmData = cd;
  5352. laRetriggerOperators();
  5353. }
  5354. void laConfirmFloat(laOperator *a, real Data, int mode){
  5355. laOperator *ai = a;
  5356. laConfirmData *cd = CreateNew(laConfirmData);
  5357. cd->FData = Data;
  5358. cd->Mode = mode;
  5359. ai->NextConfirmData = cd;
  5360. laRetriggerOperators();
  5361. }
  5362. void laConfirmString(laOperator *a, char *Str, int mode){
  5363. laOperator *ai = a;
  5364. laConfirmData *cd = CreateNew(laConfirmData);
  5365. int len = strlen(Str);
  5366. char *buf = calloc(len + 1, sizeof(char));
  5367. strcpy(buf, Str);
  5368. cd->StrData = buf;
  5369. cd->Mode = mode;
  5370. cd->Destroy = free;
  5371. ai->NextConfirmData = cd;
  5372. laRetriggerOperators();
  5373. }
  5374. int laConfirmSameDataIfAny(laOperator *a){
  5375. laOperator *ai = a;
  5376. laConfirmData *cd;
  5377. char *buf = 0;
  5378. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  5379. cd = CreateNew(laConfirmData);
  5380. if (ai->ConfirmData->StrData){
  5381. int len = strlen(ai->ConfirmData->StrData);
  5382. buf = calloc(len + 1, sizeof(char));
  5383. strcpy(buf, ai->ConfirmData->StrData);
  5384. }
  5385. //cd->CustomData = cd->CustomData;
  5386. cd->IData = ai->ConfirmData->IData;
  5387. cd->FData = ai->ConfirmData->FData;
  5388. cd->StrData = buf;
  5389. cd->Mode = ai->ConfirmData->Mode;
  5390. cd->Destroy = ai->ConfirmData->Destroy;
  5391. ai->NextConfirmData = cd;
  5392. laRetriggerOperators();
  5393. return 1;
  5394. }
  5395. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  5396. laOperator *ai = a;
  5397. laConfirmData *cd = CreateNew(laConfirmData);
  5398. cd->CustomData = UserData;
  5399. cd->Mode = mode;
  5400. cd->Destroy = Destroy;
  5401. ai->NextConfirmData = cd;
  5402. laRetriggerOperators();
  5403. }
  5404. int laGetConfirmMode(laOperator *a){
  5405. return ((laOperator *)a)->ConfirmData->Mode;
  5406. }
  5407. int laGetConfirmInt(laOperator *a){
  5408. laOperator *ai = a;
  5409. int rev = ai->ConfirmData->IData;
  5410. la_DestroyConfirmData(&ai->ConfirmData);
  5411. ai->ConfirmData = 0;
  5412. return rev;
  5413. }
  5414. real laGetConfirmFloat(laOperator *a){
  5415. laOperator *ai = a;
  5416. real rev = ai->ConfirmData->FData;
  5417. la_DestroyConfirmData(&ai->ConfirmData);
  5418. ai->ConfirmData = 0;
  5419. return rev;
  5420. }
  5421. void laGetConfirmString(laOperator *a, char *buf){
  5422. laOperator *ai = a;
  5423. strcpy(buf, ai->ConfirmData->StrData);
  5424. la_DestroyConfirmData(&ai->ConfirmData);
  5425. ai->ConfirmData = 0;
  5426. }
  5427. void *laGetConfirmUserData(laOperator *a){
  5428. laOperator *ai = a;
  5429. return ai->ConfirmData->CustomData;
  5430. }
  5431. void laFinalizeOperators(){
  5432. laOperatorType *at;
  5433. laListHandle *lst;
  5434. int i;
  5435. for (i = 0; i < 256; i++){
  5436. lst = &MAIN.OperatorTypeHash.Entries[i];
  5437. for (at = lst->pFirst; at; at = at->Item.pNext){
  5438. if (at->PC && at->PC->Props.pFirst){
  5439. lstAppendItem(&MAIN.PropContainers, at->PC);
  5440. }
  5441. }
  5442. }
  5443. }
  5444. //=================
  5445. static void la_RecordWacomMotions(XIRawEvent *event)
  5446. {
  5447. double *valuator = event->valuators.values;
  5448. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  5449. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  5450. //Window root_return, child_return;
  5451. //int root_x_return, root_y_return;
  5452. //int win_x_return, win_y_return;
  5453. //unsigned int mask_return;
  5454. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  5455. // &root_x_return, &root_y_return,
  5456. // &win_x_return, &win_y_return,
  5457. // &mask_return);
  5458. //
  5459. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  5460. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  5461. if(XIMaskIsSet(event->valuators.mask, 3)){ if(IsStylus) MAIN.StylusAngleX=valuator[3]; else MAIN.EraserAngleX=valuator[3]; }
  5462. if(XIMaskIsSet(event->valuators.mask, 4)){ if(IsStylus) MAIN.StylusAngleY=valuator[4]; else MAIN.EraserAngleY=valuator[4]; }
  5463. MAIN.IsPen=1;
  5464. }
  5465. int la_UpdateOperatorHints(laWindow* w){
  5466. laSafeString* ss=0;
  5467. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  5468. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  5469. }
  5470. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  5471. }else{
  5472. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  5473. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  5474. }
  5475. strSafeDestroy(&ss);
  5476. }
  5477. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  5478. laOperator *a, *NextA = 0;
  5479. int Result = 0;
  5480. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  5481. a = Operators->pFirst;
  5482. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  5483. while (1){
  5484. if (!a) break;
  5485. if (a->StopNow){
  5486. NextA = a->Item.pNext;
  5487. if (a->Type->Exit) a->Type->Exit(a, Result);
  5488. ConfirmData = a->NextConfirmData;
  5489. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  5490. NextConfirmData = ConfirmData;
  5491. a->ConfirmData = 0;
  5492. a->NextConfirmData = 0;
  5493. la_DestroyOperator(&a, Operators, 0);
  5494. a = NextA;
  5495. if (a){
  5496. a->ConfirmData = NextConfirmData;
  5497. }
  5498. continue;
  5499. }
  5500. a->Using = 1;
  5501. la_SetPropMathcerContext(a->ToPanel);
  5502. laSetOperatorLocalizer(a->ToPanel);
  5503. MAIN.CurrentPanel = a->ToPanel;
  5504. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  5505. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5506. e->Localized = 1;
  5507. }
  5508. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  5509. //la_PrintOperatorStack();
  5510. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  5511. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  5512. e->Localized = 0;
  5513. }
  5514. la_SetPropMathcerContext(0);
  5515. laSetOperatorLocalizer(0);
  5516. MAIN.CurrentPanel = 0;
  5517. a->Using = 0;
  5518. if (Result & LA_PASS_ON){
  5519. laConfirmSameDataIfAny(a);
  5520. NextA = a->Item.pNext;
  5521. }else{
  5522. NextA = 0;
  5523. if (a->NextConfirmData){
  5524. la_DestroyConfirmData(&a->NextConfirmData);
  5525. }
  5526. }
  5527. ConfirmData = a->NextConfirmData;
  5528. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  5529. NextConfirmData = ConfirmData;
  5530. a->ConfirmData = 0;
  5531. a->NextConfirmData = 0;
  5532. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  5533. if (a->Type->Exit) a->Type->Exit(a, Result);
  5534. la_DestroyOperator(&a, Operators, 0);
  5535. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  5536. }
  5537. a = NextA;
  5538. if (a){
  5539. a->ConfirmData = NextConfirmData;
  5540. }
  5541. }
  5542. return 1;
  5543. }
  5544. int la_HandleEvents(laWindow *w){
  5545. laEvent *e, *NextE;
  5546. laOperator *a;
  5547. laThreadNotifier *tn;
  5548. MAIN.CurrentWindow=w;
  5549. //pthread_spin_lock(&MAIN.csNotifier);
  5550. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  5551. //pthread_spin_unlock(&MAIN.csNotifier);
  5552. laNotifyUsers(tn->Path);
  5553. FreeMem(tn);
  5554. //if (MAIN.ThreadNotifiers.pFirst)
  5555. //pthread_spin_lock(&MAIN.csNotifier);
  5556. }
  5557. //pthread_spin_unlock(&MAIN.csNotifier);
  5558. while (1){
  5559. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  5560. while (w->EventList.pFirst){
  5561. while (w->PendingOperators.pLast){
  5562. a = w->PendingOperators.pLast;
  5563. if (a->OperatorPanel){
  5564. laSetOperatorLocalizer(a->OperatorPanel);
  5565. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  5566. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  5567. }
  5568. lstRemoveItem(&w->PendingOperators, a);
  5569. lstPushItem(&w->Operators, a);
  5570. }
  5571. e = lstPopItem(&w->EventList);
  5572. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  5573. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  5574. memFree(e);
  5575. }
  5576. if (!MAIN.ReTriggerOperators) break;
  5577. }
  5578. la_UpdateOperatorHints(w);
  5579. return 1;
  5580. }
  5581. int la_AllowInput(uint32_t ch){
  5582. if(ch>=32 || ch==L'\n' || ch==L'\t' || ch==L'\b') return 1;
  5583. return 0;
  5584. }
  5585. int laCopyToClipboard(unsigned char * text){
  5586. XEvent event; Window owner, window=MAIN.CurrentWindow->win;
  5587. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  5588. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  5589. strSafeSet(&MAIN.CopyPending, text);
  5590. }
  5591. int la_ProcessSysMessage(){
  5592. XEvent e;
  5593. int type;
  5594. int InputCount = 0, CharCount=0;
  5595. KeySym InputKeysym = 0;
  5596. Status InputStatus = 0;
  5597. laWindow* wnd ;
  5598. int SendDelay=0,SendIdle=0;
  5599. if(!MAIN.DelayTriggered && MAIN.TimeAccum-MAIN.DelayStart>MAIN.DelayTime) SendDelay=1;
  5600. if(!MAIN.IdleTriggered && MAIN.TimeAccum-MAIN.IdleStart>MAIN.IdleTime) SendIdle=1;
  5601. while(XPending(MAIN.dpy)){
  5602. XGenericEventCookie *cookie = &e.xcookie;
  5603. XNextEvent(MAIN.dpy, &e);
  5604. if (XFilterEvent(&e, None)) continue;
  5605. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  5606. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  5607. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  5608. XFreeEventData(MAIN.dpy, cookie); continue;
  5609. }
  5610. switch(e.type){
  5611. case ConfigureNotify:
  5612. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  5613. break;
  5614. case Expose:
  5615. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  5616. if(!wnd) break;
  5617. laRefreshWindow(wnd);
  5618. break;
  5619. case MotionNotify:
  5620. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  5621. MAIN.IsPen=0;
  5622. break;
  5623. case ButtonPress:
  5624. type=LA_MOUSEDOWN;
  5625. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  5626. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  5627. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  5628. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  5629. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  5630. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  5631. MAIN.IsPen=0;
  5632. break;
  5633. case ButtonRelease:
  5634. type=LA_MOUSEUP;
  5635. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  5636. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  5637. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  5638. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  5639. MAIN.IsPen=0;
  5640. break;
  5641. case KeyPress:
  5642. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  5643. MAIN.InputBuf[InputCount]=0;
  5644. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  5645. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  5646. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  5647. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  5648. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  5649. #ifdef DEBUG
  5650. printf("pressed KEY: %d\n", (int)InputKeysym);
  5651. #endif
  5652. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  5653. }
  5654. break;
  5655. case KeyRelease:
  5656. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  5657. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  5658. }
  5659. case ClientMessage:
  5660. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  5661. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  5662. }
  5663. break;
  5664. case SelectionNotify:
  5665. if(e.xselection.selection != MAIN.bufid) continue;
  5666. if (e.xselection.property){
  5667. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  5668. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  5669. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  5670. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  5671. else if(result) {
  5672. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  5673. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  5674. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  5675. }
  5676. XFree(result);
  5677. return True;
  5678. }
  5679. case SelectionRequest:
  5680. if(!MAIN.CopyPending){ break; }
  5681. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  5682. if (e.xselectionrequest.selection != MAIN.selection) break;
  5683. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  5684. XSelectionEvent ev = {0};
  5685. int R = 0;
  5686. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  5687. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  5688. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  5689. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  5690. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  5691. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  5692. else if (ev.target == MAIN.UTF8)
  5693. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  5694. else ev.property = None;
  5695. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  5696. break;
  5697. case SelectionClear:
  5698. break;
  5699. default:
  5700. break;
  5701. }
  5702. }
  5703. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  5704. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  5705. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  5706. }
  5707. return 1;
  5708. };
  5709. void la_PrintOperatorStack(){
  5710. laWindow *w = MAIN.CurrentWindow;
  5711. laOperator *a;
  5712. printf("\n");
  5713. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  5714. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  5715. a->Type->Identifier, a->Instance,
  5716. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  5717. }
  5718. }
  5719. void la_DrawWindow(laWindow *w){
  5720. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  5721. MAIN.CurrentWindow = w;
  5722. la_WindowDefDraw(w, 0);
  5723. }
  5724. int laFinalize(){
  5725. if(!laValidateProperties()){ laShutoff(); return 0; }
  5726. laUiTemplate* uit;
  5727. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  5728. return 1;
  5729. }
  5730. void laMainLoop(){
  5731. laWindow *w = MAIN.Windows.pFirst, *NextW;
  5732. laTimeRecorder FrameStartTime, FrameEndTime;
  5733. time_t t1, t2;
  5734. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  5735. static int a = 0;
  5736. if(!laFinalize()) return;
  5737. MAIN.DelayTriggered=1;
  5738. while (1){
  5739. laRecordTime(&FrameStartTime);
  5740. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  5741. if(!la_ProcessSysMessage()){ return; }
  5742. la_UpdateControllerStatus();
  5743. if(MAIN.InputMapping->NeedRebuild){ la_RebuildInputMapping(); }
  5744. if(MAIN.InputMapping->NeedEval){ la_RunInputMapping(); }
  5745. if(MAIN.Drivers->NeedRebuild){ la_RebuildDriverEval(); }
  5746. if(MAIN.Drivers->NeedEval){ la_RunDrivers(); }
  5747. for (w=MAIN.Windows.pFirst;w;w = NextW){
  5748. NextW = w->Item.pNext;
  5749. if(!la_HandleEvents(w)){ laShutoff(); return; }
  5750. }
  5751. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  5752. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  5753. tnsSwitchToCurrentWindowContext(w);
  5754. la_DrawWindow(w);
  5755. }
  5756. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  5757. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  5758. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  5759. }
  5760. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  5761. //t2 = clock();
  5762. laRecordTime(&FrameEndTime);
  5763. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  5764. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  5765. if (Pause > 0){
  5766. int ms = Pause * 1000000.0;
  5767. usleep(ms);
  5768. }
  5769. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  5770. FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  5771. }
  5772. }