*/}}

la_kernel.c 230 KB

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