*/}}

la_kernel.c 255 KB

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