*/}}

la_kernel.c 235 KB

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