*/}}

la_kernel.c 243 KB

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