*/}}

la_kernel.c 243 KB

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