*/}}

la_kernel.c 265 KB

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