*/}}

la_kernel.c 264 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190
  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. glEnable(GL_BLEND);
  1901. //lBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1902. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
  1903. laUiItem* ui;
  1904. if((ui=w->MaximizedUi) && w->MaximizedUiPanel && ui->Type->Draw && ui->CanvasTemplate->SecondDraw){
  1905. MAIN.CurrentPanel=w->MaximizedUiPanel; laPanel* p=w->MaximizedUiPanel; int DrawState_=0;
  1906. la_SetPropMathcerContext(p);
  1907. if(p->Refresh){
  1908. tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
  1909. tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
  1910. if(p->Refresh&LA_TAG_RECALC){
  1911. laRecalcPanelImmediate(p);
  1912. }
  1913. ui->Type->Draw(ui, LA_RH); tnsFlush();
  1914. if (!la_AnimateUiListRecursive(&p->UI)) p->Refresh = 0;
  1915. else { p->Refresh|=LA_TAG_ANIMATION; laRefreshWindow(); }
  1916. }
  1917. tnsDrawToScreen();
  1918. tnsResetViewMatrix();
  1919. tnsViewportWithScissor(0, 0, w->CW, w->CH);
  1920. tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
  1921. ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  1922. tnsFlush();
  1923. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  1924. laUiListDraw uild = {0}; for (laUiList* sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  1925. tnsFlush();
  1926. DrawState_+=la_DrawUiListRecursive(&uild, sub, ui->L, ui->R, ui->U, ui->B, 10000, 0, 0, 0, 0);
  1927. }
  1928. }
  1929. if (DrawState_){ p->Refresh = LA_TAG_RECALC; laRefreshWindow(); }
  1930. la_AttachedPanelDefDraw(w,p,*p->BT);
  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. void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2731. laWindow* cur=MAIN.CurrentWindow;
  2732. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  2733. MAIN.CurrentWindow=w;
  2734. la_UpdateUiPlacement(w);
  2735. }
  2736. MAIN.CurrentWindow=cur;
  2737. }
  2738. void laRedrawCurrentWindow(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
  2739. if (MAIN.CurrentWindow) la_UpdateUiPlacement(MAIN.CurrentWindow);
  2740. }
  2741. void laRefreshWindow(){ MAIN.CurrentWindow->Redraw=1; }
  2742. void laRedrawPanel(laPanel* p){ p->Refresh |= LA_TAG_REDRAW; MAIN.CurrentWindow->Redraw=1; }
  2743. void laRecalcPanel(laPanel* p){ p->Refresh |= LA_TAG_RECALC; MAIN.CurrentWindow->Redraw=1; }
  2744. void laRedrawCurrentPanel(){
  2745. if (MAIN.CurrentPanel) laRedrawPanel(MAIN.CurrentPanel);
  2746. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRedrawPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2747. }
  2748. void laRecalcCurrentPanel(){
  2749. if (MAIN.CurrentPanel) laRecalcPanel(MAIN.CurrentPanel);
  2750. elif (MAIN.CurrentWindow->MaximizedUiPanel) laRecalcPanel(MAIN.CurrentWindow->MaximizedUiPanel);
  2751. }
  2752. void laRecalcPanelImmediate(laPanel* p){
  2753. p->FrameDistinguish++;
  2754. laBoxedTheme* bt = (*p->BT);
  2755. int scrollw=p->UI.ScrollerShownV?bt->RM*2+LA_SCROLL_W:0;
  2756. la_PanelRefreshDetachedProp(p);
  2757. int enclosed=0;
  2758. if(p->BoundUi || p->MenuRefer){
  2759. if(p->MenuRefer) enclosed=laEnclosePanelContent(p, p->MenuRefer);
  2760. else enclosed=laEnclosePanelContent(p, &p->UI);
  2761. }
  2762. if(!enclosed){
  2763. la_PanelValidateWidth(p,&p->UI);
  2764. //laEnsurePanelInBound(p,&p->UI);
  2765. la_UpdateUiListRecursive(&p->TitleBar, bt->TM, bt->LM, p->TW-bt->RM, p->TH-bt->BM, 0, p);
  2766. int UseB=p->TitleBar.TB; if((!p->Mode)||(p->Mode==LA_PANEL_FLOATING_PASSIVE)){ UseB=0; }
  2767. la_UpdateUiListRecursive(&p->UI, UseB+bt->TM, bt->LM, p->TW-bt->RM-scrollw, p->TH-bt->BM, 0, p);
  2768. }
  2769. laWindow* w=MAIN.CurrentWindow;
  2770. if(w->MaximizedUiPanel==p&&w->MaximizedUi){ int CW = w->CW; int CH = w->CH;
  2771. laUiItem* ui=w->MaximizedUi; ui->TU=ui->U=0; ui->TB=ui->B=CH; ui->TL=ui->L=0; ui->TR=ui->R=CW;
  2772. if(!ui->Page) return; laBoxedTheme* bt=(*ui->Type->Theme);
  2773. la_UpdateUiListRecursive(ui->Page, ui->TU+bt->TM, ui->TL+bt->LM, ui->TR-bt->RM, ui->TB, 0, w->MaximizedUiPanel);
  2774. }
  2775. }
  2776. void laRecalcCurrentPanelImmediate(){
  2777. laRecalcPanelImmediate(MAIN.CurrentPanel);
  2778. }
  2779. int laNonFixedPanelExists(laPanel *p){
  2780. laPanel *ip;
  2781. if (!p) return 0;
  2782. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2783. // if (ip == p) return 1;
  2784. //}
  2785. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2786. if (ip == p) return 1;
  2787. }
  2788. return 0;
  2789. }
  2790. int laIsInPanel(laPanel *p, int PanelX, int PanelY){
  2791. if (PanelX < 0 || PanelY < 0 || PanelY > p->H || PanelX > p->W) return 0;
  2792. return 1;
  2793. }
  2794. int laIsCloseToPanel(laPanel *p, int PanelX, int PanelY){
  2795. int tt=MAIN.TooltipCloseDistance;
  2796. if (PanelX < -tt || PanelY < -tt || PanelY > p->H+tt || PanelX > p->W+tt) return 0;
  2797. return 1;
  2798. }
  2799. int laPanelOverlappingEachOther(laPanel *p1, laPanel *p2){
  2800. if (p1->X > p2->X + p2->W || p1->X + p1->W < p2->X ||
  2801. p1->Y > p2->Y + p2->H || p1->Y + p1->H < p2->Y)
  2802. return 0;
  2803. return 1;
  2804. }
  2805. void laUnlinkSharedPanel(laPanel *p){
  2806. laWindow *w;
  2807. laPanel *ip;
  2808. for (w = MAIN.Windows.pFirst; w; w = w->Item.pNext){
  2809. for (ip = w->Panels.pFirst; ip; ip = ip->Item.pNext){
  2810. if (ip == p){
  2811. lstRemoveItem(&w->Panels, ip);
  2812. return;
  2813. }
  2814. }
  2815. }
  2816. }
  2817. int laIsPanelCovered(laPanel *p){
  2818. //laLayout* l = MAIN.CurrentWindow->CurrentLayout;
  2819. laPanel *ip;
  2820. laPanel *resp;
  2821. int in1 = 0, in2 = 0, in3 = 0;
  2822. laPanel *d1 = 0, *d2 = 0, *d3 = 0;
  2823. //for (ip = MAIN.CurrentWindow->CurrentLayout->Panels.pLast; ip; ip = ip->Item.pPrev) {
  2824. // if (ip == p) { in1 = 1; d1 = 0; continue; }
  2825. // if (ip->Show && laPanelOverlappingEachOther(ip, p)) d1 = ip;
  2826. //}
  2827. for (ip = MAIN.CurrentWindow->Panels.pLast; ip; ip = ip->Item.pPrev){
  2828. if (ip == p){
  2829. in3 = 1;
  2830. d3 = 0;
  2831. continue;
  2832. }
  2833. if (ip->Show && laPanelOverlappingEachOther(ip, p)) d3 = ip;
  2834. }
  2835. if (!in2 && !in3) in1 = 1;
  2836. if (in1){
  2837. if (d1 || d2 || d3) return 1;
  2838. }else{
  2839. if (in2){
  2840. if (d2 || d3) return 1;
  2841. }else if (in3)
  2842. if (d3) return 1;
  2843. }
  2844. return 0;
  2845. }
  2846. int laIsTopPanel(laPanel *p){
  2847. //if (!p->Item.pPrev) return 1;
  2848. //else {
  2849. if (!laIsPanelCovered(p)){
  2850. //laPopPanel(p);
  2851. return 1;
  2852. }
  2853. return 0;
  2854. //}
  2855. return 0;
  2856. }
  2857. void laWindowToLocal(laOperator *a, laPanel *p, int *x, int *y){
  2858. if(!p) return;
  2859. int ix = *x, iy = *y;
  2860. laListItemPointer *lip;
  2861. laOperator *ai = a;
  2862. (*x) = ix - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  2863. (*y) = iy - ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  2864. if (a){
  2865. for (lip = ai->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2866. laUiList *uil = lip->p;
  2867. (*x) += uil->PanX;
  2868. (*y) += uil->PanY;
  2869. }
  2870. }
  2871. }
  2872. void laPanelToLocal(laOperator *a, int *x, int *y){
  2873. int ix = *x, iy = *y;
  2874. laListItemPointer *lip;
  2875. if (a){
  2876. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2877. laUiList *uil = lip->p;
  2878. (*x) += uil->PanX;
  2879. (*y) += uil->PanY;
  2880. }
  2881. }
  2882. }
  2883. void laLocalToWindow(laOperator *a, laPanel *p, int *x, int *y){
  2884. if(!p) return;
  2885. int ix = *x, iy = *y;
  2886. laListItemPointer *lip;
  2887. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  2888. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  2889. if (a){
  2890. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2891. laUiList *uil = lip->p;
  2892. (*x) -= uil->PanX;
  2893. (*y) -= uil->PanY;
  2894. }
  2895. }
  2896. }
  2897. void laPanelToWindow(laPanel *p, int *x, int *y){
  2898. int ix = *x, iy = *y;
  2899. laListItemPointer *lip;
  2900. (*x) = ix + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->X);
  2901. (*y) = iy + ((MAIN.CurrentWindow->MaximizedUiPanel==p)?0: p->Y);
  2902. }
  2903. void laLocalToPanel(laOperator *a, int *x, int *y){
  2904. int ix = *x, iy = *y;
  2905. laListItemPointer *lip;
  2906. if (a){
  2907. for (lip = a->LocalUiLists.pFirst; lip; lip = lip->pNext){
  2908. laUiList *uil = lip->p;
  2909. (*x) -= uil->PanX;
  2910. (*y) -= uil->PanY;
  2911. }
  2912. }
  2913. }
  2914. void laSetNextMenuPos(int X, int Y, int W, int H){
  2915. MAIN.NextX = X;
  2916. MAIN.NextY = Y;
  2917. MAIN.NextW = W;
  2918. MAIN.NextH = H;
  2919. }
  2920. int laIsInBlock(laBlock *b, int X, int Y){
  2921. if (X >= b->X && X <= b->X + b->W && Y >= b->Y && Y <= b->Y + b->H) return 1;
  2922. return 0;
  2923. }
  2924. 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; }
  2925. 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; }
  2926. 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; }
  2927. laBlock *laClearBlockButtonRecursive(laBlock *b, laBlock *except){
  2928. if(b->B1){laClearBlockButtonRecursive(b->B1,except);}
  2929. if(b->B2){laClearBlockButtonRecursive(b->B2,except);}
  2930. if (!b->B1 && !b->B2){
  2931. if(b!=except && b->OnButton){ b->OnButton=0; laRefreshWindow(); }
  2932. }
  2933. }
  2934. laBlock *laDetectBlockRecursive(laBlock *b, int X, int Y){
  2935. laPanel *p;
  2936. laBlock *sb = 0;
  2937. if (!laIsInBlock(b, X, Y)) return 0;
  2938. if (!b->B1 && !b->B2) return b;
  2939. if (sb = laDetectBlockRecursive(b->B1, X, Y)) return sb;
  2940. return laDetectBlockRecursive(b->B2, X, Y);
  2941. }
  2942. laPanel *laDetectPanel(int X, int Y){
  2943. laPanel *p; laBlock *b;
  2944. for (p = MAIN.CurrentWindow->Panels.pFirst; p; p = p->Item.pNext){
  2945. int x = X, y = Y;
  2946. laWindowToLocal(0, p, &x, &y);
  2947. if (p->Show && laIsInPanel(p, x, y)){
  2948. return p;
  2949. }
  2950. }
  2951. if(MAIN.CurrentWindow->MaximizedUiPanel){return 0;}
  2952. laBlock* RootBlock=MAIN.CurrentWindow->MaximizedBlock?MAIN.CurrentWindow->MaximizedBlock:MAIN.CurrentWindow->CurrentLayout->FirstBlock;
  2953. if (b = laDetectBlockRecursive(RootBlock, X, Y)) return b->CurrentPanel;
  2954. return 0;
  2955. }
  2956. laUiList *laPrepareUi(laPanel *p){
  2957. return &p->UI;
  2958. }
  2959. laColumn *laFirstColumn(laUiList *uil){
  2960. if (uil->Columns.pFirst) return uil->Columns.pFirst;
  2961. else{
  2962. laColumn *c = memAcquireSimple(sizeof(laColumn));
  2963. c->SP = 1;
  2964. c->PreWidth = 1;
  2965. lstAppendItem(&uil->Columns, c);
  2966. c->Top = c;
  2967. return uil->Columns.pFirst;
  2968. }
  2969. }
  2970. laColumn *laSplitColumn(laUiList *uil, laColumn *c, real Percent){
  2971. laColumn *lc, *rc;
  2972. if (c->LS || c->RS) return c;
  2973. lc = memAcquireSimple(sizeof(laColumn));
  2974. rc = memAcquireSimple(sizeof(laColumn));
  2975. c->LS = lc;
  2976. c->RS = rc;
  2977. c->LS->SP = Percent;
  2978. c->RS->SP = Percent;
  2979. c->LS->Top = c->Top;
  2980. c->RS->Top = c->Top;
  2981. if (uil){
  2982. lstAppendItem(&uil->Columns, lc);
  2983. lstAppendItem(&uil->Columns, rc);
  2984. }
  2985. if (c->LS && c->RS->MaxW == 0){
  2986. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  2987. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  2988. }else if (c->RS && c->LS->MaxW == 0){
  2989. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  2990. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  2991. }
  2992. return c;
  2993. }
  2994. laColumn *laLeftColumn(laColumn *c, int MaxWidth){
  2995. if (c->LS && MaxWidth) c->LS->MaxW = MaxWidth;
  2996. return c->LS;
  2997. }
  2998. laColumn *laRightColumn(laColumn *c, int MaxWidth){
  2999. if (c->LS && c->LS->MaxW && MaxWidth) return c->RS;
  3000. if (MaxWidth) c->RS->MaxW = MaxWidth;
  3001. return c->RS;
  3002. }
  3003. void la_DestroyColumnRecursive(laListHandle *List, laColumn *c){
  3004. lstRemoveItem(List, c);
  3005. if (c->LS) la_DestroyColumnRecursive(List, c->LS);
  3006. if (c->RS) la_DestroyColumnRecursive(List, c->RS);
  3007. memFree(c);
  3008. }
  3009. int laCheckAndMergeSubColumnsUiList(laUiList *TopUil, laColumn *c, int DoMerge){
  3010. laUiList *uil = TopUil;
  3011. laUiList *sub;
  3012. laUiItem *ui;
  3013. laColumn *cc, *NextCC = 0;
  3014. int Occupied = 0;
  3015. int Removed = 0;
  3016. if (!c->LS) return 0;
  3017. else{
  3018. laCheckAndMergeSubColumnsUiList(TopUil, c->LS, DoMerge);
  3019. laCheckAndMergeSubColumnsUiList(TopUil, c->RS, DoMerge);
  3020. }
  3021. for (ui = TopUil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  3022. if (ui->C == c->LS || ui->C == c->RS){
  3023. if (DoMerge){
  3024. ui->C = c;
  3025. Occupied = 1;
  3026. }else
  3027. return 1;
  3028. }
  3029. if (ui->Subs.pFirst){
  3030. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  3031. laCheckAndMergeSubColumnsUiList(sub, c, DoMerge);
  3032. }
  3033. }
  3034. }
  3035. if (!Removed){
  3036. for (cc = uil->Columns.pFirst; cc; cc = cc->Item.pNext){
  3037. if (cc == c){
  3038. if (c->LS) la_DestroyColumnRecursive(&uil->Columns, c->LS);
  3039. if (c->RS) la_DestroyColumnRecursive(&uil->Columns, c->RS);
  3040. c->LS = 0;
  3041. c->RS = 0;
  3042. Removed = 1;
  3043. break;
  3044. }
  3045. }
  3046. }
  3047. return Occupied;
  3048. }
  3049. laPropContainer* laUiHasExtraProps(laUiType *ut, int size, int Hyper){
  3050. ut->ExtraProps = laAddPropertyContainer(ut->Identifier, 0,0,U'◳',0,size,0,0,Hyper);
  3051. ut->FakeProp = memAcquire(sizeof(laSubProp));
  3052. ut->FakeProp->Base.SubProp = ut->ExtraProps;
  3053. ut->FakeProp->Base.Identifier = ut->Identifier;
  3054. ut->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3055. ut->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3056. ut->FakeProp->Base.OffsetIsPointer = 1;
  3057. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3058. return ut->ExtraProps;
  3059. }
  3060. laPropContainer* laCanvasHasExtraProps(laCanvasTemplate *ct, int size, int Hyper){
  3061. ct->ExtraProps = laAddPropertyContainer(ct->Identifier->Ptr, 0,0,U'◳',0,size,0,0,Hyper);
  3062. ct->FakeProp = memAcquire(sizeof(laSubProp));
  3063. ct->FakeProp->Base.SubProp = ct->ExtraProps;
  3064. ct->FakeProp->Base.Identifier = ct->Identifier->Ptr;
  3065. ct->FakeProp->Base.PropertyType = LA_PROP_SUB;
  3066. ct->FakeProp->Base.Offset = offsetof(laUiItem, Extra);
  3067. ct->FakeProp->Base.OffsetIsPointer = 1;
  3068. //ut->FakeProp->Base.Container = ut->ExtraProps;
  3069. return ct->ExtraProps;
  3070. }
  3071. void la_DestroyUiType(laUiType* uit){
  3072. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3073. memFree(uit);
  3074. }
  3075. laUiType *la_RegisterUiType(const char *Identifer, int ForType, const char *UseOperator, laBoxedTheme **bt, laUiDrawFunc *Draw, laUiGetHeightFunc GetHeight, laUiInitFunc Init, laUiDestroyFunc Destroy){
  3076. laUiType *ut = memAcquire(sizeof(laUiType));
  3077. ut->Identifier = Identifer;
  3078. ut->OperatorID = UseOperator;
  3079. ut->Draw = Draw;
  3080. ut->Theme = bt;
  3081. ut->ForType = ForType;
  3082. ut->OperatorType = laGetOperatorType(UseOperator);
  3083. ut->GetHeight = GetHeight;
  3084. ut->Init = Init;
  3085. ut->Destroy = Destroy;
  3086. la_UDFAppendSharedTypePointer(Identifer, ut);
  3087. lstAppendItem(&MAIN.UiTypes, ut);
  3088. return ut;
  3089. }
  3090. laUiType *la_GetUiTypeFromProperty(laProp *P){
  3091. laUiType *ut = MAIN.UiTypes.pFirst;
  3092. if (!P) return 0;
  3093. if (P->DefaultUiType) return P->DefaultUiType;
  3094. if (P->SubProp == LA_PC_SOCKET_IN || P->SubProp == LA_PC_SOCKET_OUT) return _LA_UI_NODE_SOCKET;
  3095. if (P->PropertyType == LA_PROP_SUB) return _LA_UI_COLLECTION;
  3096. for (ut; ut; ut = ut->Item.pNext){
  3097. if ((ut->ForType&LA_PROP_GENERIC_BITS) == (P->PropertyType&LA_PROP_GENERIC_BITS)){
  3098. return ut;
  3099. }
  3100. }
  3101. return 0;
  3102. }
  3103. laUiType *la_GetUiButtonType(){
  3104. laUiType *ut = MAIN.UiTypes.pFirst;
  3105. for (ut; ut; ut = ut->Item.pNext){
  3106. if (ut->ForType == LA_PROP_OPERATOR) return ut;
  3107. }
  3108. return 0;
  3109. }
  3110. laCanvasTemplate *la_GetCanvasTemplate(char* TargetContainerID, char* TemplateID){
  3111. laCanvasTemplate *vdt;
  3112. for (vdt = MAIN.View2DTemplates.pFirst; vdt; vdt = vdt->Item.pNext){
  3113. if (strSame(TemplateID, vdt->Identifier->Ptr) || strSame(TargetContainerID, vdt->TargetContainerID)) return vdt;
  3114. }
  3115. return 0;
  3116. }
  3117. void la_AssignPropExtras(laUiItem* ui){
  3118. if(!ui->Type || !ui->Type->FakeProp) return;
  3119. ui->FakePs.p = ui->Type->FakeProp;
  3120. ui->FakePs.Type = U'.';
  3121. ui->FakePs.UseInstance = ui;
  3122. ui->ExtraPP.LastPs = &ui->FakePs;
  3123. }
  3124. void la_AssignCanvasPropExtras(laUiItem* ui){
  3125. if(!ui->CanvasTemplate || !ui->CanvasTemplate->FakeProp) return;
  3126. laCanvasTemplate*ct=ui->CanvasTemplate;
  3127. ui->FakePs.p = ct->FakeProp;
  3128. ui->FakePs.Type = U'.';
  3129. ui->FakePs.UseInstance = ui;
  3130. ui->ExtraPP.EndInstance = ui->Extra;
  3131. ui->ExtraPP.LastPs = &ui->FakePs;
  3132. }
  3133. laUiItem *la_UpdatePropDisplay(laUiItem *ui, laPropPack *Base, const char *Path, laUiDefineFunc Template, laWidget* Widget, char* instructions){
  3134. int result;
  3135. if (!ui) return 0;
  3136. laUiType* OverrideType=Widget&&Widget->Type?Widget->Type:0;
  3137. if (Path){
  3138. result = la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3139. if (!result){
  3140. ui->AT = laGetOperatorType(Path);
  3141. if (!ui->AT /* && !OverrideType*/) return la_UpdatePropDisplay(ui, 0, "la.unknown_prop", 0, 0, instructions);
  3142. ui->Type = la_GetUiButtonType();
  3143. if (OverrideType && (OverrideType->ForType == LA_PROP_OPERATOR)) ui->Type = OverrideType;
  3144. }else{
  3145. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3146. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3147. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->Identifier)))) ?
  3148. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3149. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3150. }
  3151. if (Base){
  3152. ui->PP.RawThis = Base;
  3153. }
  3154. }else if (Base){
  3155. ui->PP.LastPs = Base->LastPs;
  3156. ui->Type = (OverrideType && ((!OverrideType->ForType)||
  3157. (OverrideType->ForType&&OverrideType->ForType == ui->PP.LastPs->p->PropertyType)||
  3158. (OverrideType->TargetSub && !strcmp(OverrideType->TargetSub, ui->PP.LastPs->p->SubProp->Identifier)))) ?
  3159. OverrideType : la_GetUiTypeFromProperty(ui->PP.LastPs->p);
  3160. ui->PP.RawThis = Base; //HACK! Not Unified For Prop Access!!!<<<----------??????????
  3161. ui->Flags|=ui->PP.LastPs->p->DefaultFlags;
  3162. }
  3163. la_AssignPropExtras(ui);
  3164. if(Widget){ ui->Flags|= Widget->Flags; }
  3165. if(Template) ui->Template = Template; ui->State = LA_UI_NORMAL;
  3166. if(!ui->Type) ui->Type = Widget?Widget->Type:0;
  3167. if(instructions) strSafeSet(&ui->ExtraInstructions, instructions);
  3168. return ui;
  3169. }
  3170. laUiItem *la_UpdateLabelDisplay(laUiItem *ui, laUiDefineFunc Template, char *Content){
  3171. ui->Type = _LA_UI_LABEL;
  3172. ui->Template = Template;
  3173. ui->State = LA_UI_NORMAL;
  3174. strSafeSet(&ui->Display, Content);
  3175. la_AssignPropExtras(ui);
  3176. return ui;
  3177. }
  3178. laUiItem *la_CreateGroupHandle(laWidget* Widget){
  3179. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3180. ui->Type = (Widget&&Widget->Type)?Widget->Type : _LA_UI_FIXED_GROUP;
  3181. ui->State = LA_UI_NORMAL;
  3182. la_AssignPropExtras(ui);
  3183. return ui;
  3184. }
  3185. laUiItem *laShowLabel(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3186. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3187. transLate(Content);
  3188. la_UpdateLabelDisplay(ui, Template, Content);
  3189. ui->C = c;
  3190. if (ui->Type->Init) ui->Type->Init(ui);
  3191. ui->ExtraPP.EndInstance = ui->Extra;
  3192. lstAppendItem(&uil->UiItems, ui);
  3193. return ui;
  3194. }
  3195. laUiItem *laShowLabelDynamic(laUiList *uil, laColumn *c, const char *Content, laUiDefineFunc Template, laWidget* Widget){
  3196. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3197. la_UpdateLabelDisplay(ui, Template, Content);
  3198. ui->C = c;
  3199. if (ui->Type->Init) ui->Type->Init(ui);
  3200. ui->ExtraPP.EndInstance = ui->Extra;
  3201. lstAppendItem(&uil->UiItems, ui);
  3202. return ui;
  3203. }
  3204. laUiItem *laShowIcon(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget){
  3205. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3206. la_UpdatePropDisplay(ui, Base, Path, 0, Widget, 0);
  3207. ui->Flags |= LA_UI_FLAGS_INT_ICON;
  3208. ui->C = c;
  3209. if (ui->Type->Init) ui->Type->Init(ui);
  3210. ui->ExtraPP.EndInstance = ui->Extra;
  3211. lstAppendItem(&uil->UiItems, ui);
  3212. return ui;
  3213. }
  3214. laUiItem *laShowInvisibleItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3215. laWidget wg={&_LA_UI_INVISIBLE, 0}; return laShowItemFull(uil,c,Base,Path,&wg,0,0,0);
  3216. }
  3217. laUiItem *laShowItem(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path){
  3218. return laShowItemFull(uil,c,Base,Path,0,0,0,0);
  3219. }
  3220. laUiItem *laShowItemFull(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, laWidget* Widget, char* instructions, laUiDefineFunc Template, int TemplateContext){
  3221. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3222. la_UpdatePropDisplay(ui, Base, Path, Template, Widget, instructions);
  3223. ui->C = c;
  3224. ui->TemplateContext = TemplateContext;
  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 *laShowImage(laUiList *uil, laColumn *c, tnsImage* Image, int Height){
  3231. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3232. ui->C = c; ui->Extra=Image;
  3233. ui->Type=_LA_UI_IMAGE; ui->Type->Init(ui);
  3234. ui->SymbolID=Height;
  3235. lstAppendItem(&uil->UiItems, ui);
  3236. return ui;
  3237. }
  3238. laUiItem *laShowNodeSocket(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3239. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_NODE_SOCKET,instructions,0,0);
  3240. }
  3241. laUiItem *laShowHeightAdjuster(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, char* instructions){
  3242. return laShowItemFull(uil,c,Base,Path,LA_WIDGET_HEIGHT_ADJUSTER,instructions,0,0);
  3243. }
  3244. laUiItem *laShowCanvas(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, const char *id2DTemplate, int Height){
  3245. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3246. ui->Type = _LA_UI_CANVAS;
  3247. ui->State = LA_UI_NORMAL;
  3248. ui->C = c;
  3249. la_GetPropFromPath(&ui->PP, Base, Path, 0);
  3250. if (id2DTemplate) ui->CanvasTemplate = la_GetCanvasTemplate(0, id2DTemplate);
  3251. else{
  3252. 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); }
  3253. laSubProp* sp=ui->PP.LastPs->p; ui->PP.LastPs->p->SubProp=la_EnsureSubTarget(sp,0);
  3254. ui->CanvasTemplate = la_GetCanvasTemplate(sp->TargetID, 0);
  3255. if(!ui->CanvasTemplate){ la_FreePropStepCache(ui->PP.Go); memFree(ui); return laShowItem(uil,c,Base,Path); }
  3256. }
  3257. if (ui->Type->Init) ui->Type->Init(ui);
  3258. la_AssignCanvasPropExtras(ui);
  3259. if (Height) ui->Expand=Height; else ui->Expand=6;
  3260. lstAppendItem(&uil->UiItems, ui);
  3261. return ui;
  3262. }
  3263. laUiItem *laShow3DCanvasCombo(laUiList *uil, laColumn *c, laPropPack *Base, const char *Path, int Height, laPropPack* Detached){
  3264. laUiItem* ui=0;
  3265. if(Detached){
  3266. laColumn* cl,*cll,*clr,*cr;
  3267. laSplitColumn(uil,c,0.35); cl=laLeftColumn(c,7); cr=laRightColumn(c,0);
  3268. laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,1); clr=laRightColumn(cl,0);
  3269. laShowItemFull(uil,cll,Detached,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  3270. laUiItem* rb=laShowItemFull(uil,clr,Detached,"root_object",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  3271. laUiItem* b2=laOnConditionThat(uil,c,laPropExpression(&rb->PP,"active"));{
  3272. laUiItem* b=laBeginRow(uil,cr,0,0);
  3273. laShowLabel(uil,cr,"⯈",0,0); laShowItem(uil,cr,&rb->PP,"active.name")->Flags|=LA_UI_FLAGS_NO_DECAL;
  3274. laEndRow(uil,b);
  3275. }laEndCondition(uil,b2);
  3276. b2=laOnConditionThat(uil,c,laPropExpression(Detached,"detached"));{
  3277. ui=laShowCanvas(uil,c,Detached,"root_object",0,Height); laDefault3DViewOverlay(ui);
  3278. }laElse(uil,b2);{
  3279. ui=laShowCanvas(uil,c,0,"tns.world.root_objects",0,Height); laDefault3DViewOverlay(ui);
  3280. }laEndCondition(uil,b2);
  3281. }else{
  3282. ui=laShowCanvas(uil,c,Base,Path,0,Height); laDefault3DViewOverlay(ui);
  3283. }
  3284. }
  3285. laUiItem *laShowColumnAdjuster(laUiList *uil, laColumn *c){
  3286. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3287. laCanvasExtra *e;
  3288. ui->Type = _LA_UI_COLUMN_ADJUSTER;
  3289. ui->Flags |= LA_WIDGET_COLUMN_ADJUSTER->Flags;
  3290. ui->C = c;
  3291. if (ui->Type->Init) ui->Type->Init(ui);
  3292. ui->ExtraPP.EndInstance = ui->Extra;
  3293. lstAppendItem(&uil->UiItems, ui);
  3294. return ui;
  3295. }
  3296. laUiItem *laShowSymbol(laUiList *uil, laColumn *c, int SymbolID, int Height){
  3297. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3298. ui->Type = _LA_UI_SYMBOL;
  3299. ui->SymbolID = SymbolID;
  3300. if (Height) ui->State = Height;
  3301. ui->C = c;
  3302. if (ui->Type->Init) ui->Type->Init(ui);
  3303. ui->ExtraPP.EndInstance = ui->Extra;
  3304. lstAppendItem(&uil->UiItems, ui);
  3305. return ui;
  3306. }
  3307. laUiItem *laBeginRow(laUiList *uil, laColumn *c, int Expand, int Even){
  3308. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3309. ui->Type = &_LA_UI_ROW_BEGIN;
  3310. ui->State=Expand;
  3311. ui->Flags=Even;
  3312. ui->C = c;
  3313. if (ui->Type->Init) ui->Type->Init(ui);
  3314. ui->ExtraPP.EndInstance = ui->Extra;
  3315. lstAppendItem(&uil->UiItems, ui);
  3316. return ui;
  3317. }
  3318. laUiItem *laEndRow(laUiList *uil, laUiItem* Begin){
  3319. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3320. ui->Type = &_LA_UI_ROW_END;
  3321. ui->C = Begin->C;
  3322. ui->Page = (laUiList*)Begin;
  3323. if (ui->Type->Init) ui->Type->Init(ui);
  3324. ui->ExtraPP.EndInstance = ui->Extra;
  3325. lstAppendItem(&uil->UiItems, ui);
  3326. return ui;
  3327. }
  3328. void la_ConditionerInit(laUiItem *ui, laUiConditionNode *Expression){
  3329. laConditionUiExtraData *e = CreateNew(laConditionUiExtraData);
  3330. e->Expression = Expression;
  3331. ui->Extra = e;
  3332. la_AssignPropExtras(ui);
  3333. }
  3334. laUiItem *laMakeGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3335. laUiItem *ui = la_CreateGroupHandle(Widget);
  3336. laUiList *nuil;
  3337. ui->C = c;
  3338. lstAppendItem(&uil->UiItems, ui);
  3339. nuil = memAcquireSimple(sizeof(laUiList));
  3340. strSafeSet(&nuil->TabName, Name);
  3341. ui->Page = nuil;
  3342. lstAppendItem(&ui->Subs, nuil);
  3343. if (ui->Type->Init) ui->Type->Init(ui);
  3344. ui->ExtraPP.EndInstance = ui->Extra;
  3345. return ui;
  3346. }
  3347. laUiItem *laMakeFoldableGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget, int DefaultFolded, int ButtonFlags){
  3348. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget:0);
  3349. laUiList *sub = SubUi->Page;
  3350. laColumn *s = laFirstColumn(sub);
  3351. SubUi->State = LA_UI_ACTIVE;
  3352. laUiItem *b1 = laOnConditionToggle(sub, s, 0, 0, 0, 0, 0);
  3353. strSafePrint(&b1->ExtraInstructions, "text=… %s", Name);
  3354. if(!DefaultFolded) b1->State=LA_UI_ACTIVE;
  3355. if(ButtonFlags)b1->Flags|=ButtonFlags; else b1->Flags|=LA_UI_FLAGS_NO_DECAL;
  3356. laShowSeparator(sub, s);
  3357. return SubUi;
  3358. }
  3359. laUiItem *laMakeEmptyGroup(laUiList *uil, laColumn *c, const char *Name, laWidget* Widget){
  3360. laUiItem *SubUi = laMakeGroup(uil, c, Name, Widget?Widget->Type:0);
  3361. laUiList *sub = SubUi->Page;
  3362. laColumn *s = laFirstColumn(sub);
  3363. SubUi->State = LA_UI_ACTIVE;
  3364. return SubUi;
  3365. }
  3366. void laEndFoldableGroup(laUiList *sub, laUiItem *group){
  3367. laEndCondition(sub, sub->UiItems.pFirst);
  3368. }
  3369. laUiItem *laMakeTab(laUiList *uil, laColumn *c, laWidget* Widget){
  3370. laUiItem *ui = la_CreateGroupHandle(Widget?Widget:LA_WIDGET_TAB);
  3371. laUiList *nuil;
  3372. ui->C = c;
  3373. lstAppendItem(&uil->UiItems, ui);
  3374. if (ui->Type->Init) ui->Type->Init(ui);
  3375. ui->ExtraPP.EndInstance = ui->Extra;
  3376. return ui;
  3377. }
  3378. laUiList *laAddTabPage(laUiItem *ui, const char *Name){
  3379. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3380. if (!ui->Page) ui->Page = uil;
  3381. lstAppendItem(&ui->Subs, uil);
  3382. strSafeSet(&uil->TabName, Name);
  3383. laFirstColumn(uil);
  3384. //laFirstColumn(uil);
  3385. return uil;
  3386. }
  3387. laUiList *la_AddInstancePage(laUiItem *ui, void *Instance, laWidget* Widget){
  3388. laUiList *uil = memAcquireSimple(sizeof(laUiList));
  3389. /*if (!ui->Page) */ ui->Page = uil;
  3390. lstAppendItem(&ui->Subs, uil);
  3391. uil->Instance = Instance; ui->PP.EndInstance=Instance;
  3392. return uil;
  3393. }
  3394. laUiConditionNode *laTrue(){
  3395. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3396. ucn->Type = LA_CONDITION_TRUE;
  3397. return ucn;
  3398. }
  3399. laUiConditionNode *laFalse(){
  3400. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3401. ucn->Type = LA_CONDITION_FALSE;
  3402. return ucn;
  3403. }
  3404. laUiConditionNode *laPropExpression(laPropPack *Base, char *Prop){
  3405. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3406. ucn->Type = LA_CONDITION_PROP;
  3407. la_GetPropFromPath(&ucn->PP, Base, Prop, 0);
  3408. strSafeSet(&ucn->String, Prop);
  3409. return ucn;
  3410. }
  3411. laUiConditionNode *laIntExpression(int Value){
  3412. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3413. ucn->Type = LA_CONDITION_INT;
  3414. ucn->IntValue = Value;
  3415. return ucn;
  3416. }
  3417. laUiConditionNode *laFloatExpression(real Value){
  3418. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3419. ucn->Type = LA_CONDITION_FLOAT;
  3420. ucn->FloatValue = Value;
  3421. return ucn;
  3422. }
  3423. laUiConditionNode *laStringExpression(char *Content){
  3424. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3425. ucn->Type = LA_CONDITION_STRING;
  3426. strSafeSet(&ucn->String, Content);
  3427. return ucn;
  3428. }
  3429. laUiConditionNode *laAnd(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3430. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3431. ucn->Type = LA_CONDITION_AND;
  3432. ucn->Expression1 = Expression1;
  3433. ucn->Expression2 = Expression2;
  3434. return ucn;
  3435. }
  3436. laUiConditionNode *laOr(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3437. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3438. ucn->Type = LA_CONDITION_OR;
  3439. ucn->Expression1 = Expression1;
  3440. ucn->Expression2 = Expression2;
  3441. return ucn;
  3442. }
  3443. laUiConditionNode *laNot(laUiConditionNode *Expression1){
  3444. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3445. ucn->Type = LA_CONDITION_NOT;
  3446. ucn->Expression1 = Expression1;
  3447. return ucn;
  3448. }
  3449. laUiConditionNode *laEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3450. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3451. ucn->Type = LA_CONDITION_EQ;
  3452. ucn->Expression1 = Expression1;
  3453. ucn->Expression2 = Expression2;
  3454. return ucn;
  3455. }
  3456. laUiConditionNode *laGreaterThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3457. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3458. ucn->Type = LA_CONDITION_GT;
  3459. ucn->Expression1 = Expression1;
  3460. ucn->Expression2 = Expression2;
  3461. return ucn;
  3462. }
  3463. laUiConditionNode *laLessThan(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3464. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3465. ucn->Type = LA_CONDITION_LT;
  3466. ucn->Expression1 = Expression1;
  3467. ucn->Expression2 = Expression2;
  3468. return ucn;
  3469. }
  3470. laUiConditionNode *laGreaterEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3471. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3472. ucn->Type = LA_CONDITION_GE;
  3473. ucn->Expression1 = Expression1;
  3474. ucn->Expression2 = Expression2;
  3475. return ucn;
  3476. }
  3477. laUiConditionNode *laLessEqual(laUiConditionNode *Expression1, laUiConditionNode *Expression2){
  3478. laUiConditionNode *ucn = memAcquireSimple(sizeof(laUiConditionNode));
  3479. ucn->Type = LA_CONDITION_LE;
  3480. ucn->Expression1 = Expression1;
  3481. ucn->Expression2 = Expression2;
  3482. return ucn;
  3483. }
  3484. int la_GetIntConditionValue(laUiConditionNode *Expression){
  3485. if (Expression->Type != LA_CONDITION_INT) return 0;
  3486. return Expression->IntValue;
  3487. }
  3488. real la_GetFloatConditionValue(laUiConditionNode *Expression){
  3489. if (Expression->Type != LA_CONDITION_FLOAT) return 0;
  3490. return Expression->FloatValue;
  3491. }
  3492. char *la_GetStringConditionValue(laUiConditionNode *Expression){
  3493. return Expression->String->Ptr;
  3494. }
  3495. 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){
  3496. switch (Mode1){
  3497. case LA_PROP_ENUM:
  3498. case LA_PROP_INT:
  3499. case LA_CONDITION_INT:
  3500. switch (Mode2){
  3501. case LA_PROP_ENUM:
  3502. case LA_PROP_INT:
  3503. case LA_CONDITION_INT:
  3504. switch (CompMode){
  3505. case LA_CONDITION_GE:
  3506. return (i1 >= i2);
  3507. case LA_CONDITION_GT:
  3508. return (i1 > i2);
  3509. case LA_CONDITION_EQ:
  3510. return (i1 == i2);
  3511. case LA_CONDITION_LT:
  3512. return (i1 < i2);
  3513. case LA_CONDITION_LE:
  3514. return (i1 <= i2);
  3515. }
  3516. case LA_PROP_FLOAT:
  3517. case LA_CONDITION_FLOAT:
  3518. switch (CompMode){
  3519. case LA_CONDITION_GE:
  3520. return ((real)i1 >= f2);
  3521. case LA_CONDITION_GT:
  3522. return ((real)i1 > f2);
  3523. case LA_CONDITION_EQ:
  3524. return ((real)i1 >= f2 - 0.0001 && (real)i1 <= f2 + 0.0001);
  3525. case LA_CONDITION_LT:
  3526. return ((real)i1 < f2);
  3527. case LA_CONDITION_LE:
  3528. return ((real)i1 <= f2);
  3529. }
  3530. case LA_PROP_SUB:
  3531. if (CompMode == LA_CONDITION_EQ) return i1 == (int)p2;
  3532. default:
  3533. return 0;
  3534. }
  3535. case LA_PROP_FLOAT:
  3536. case LA_CONDITION_FLOAT:
  3537. switch (Mode2){
  3538. case LA_PROP_INT:
  3539. case LA_PROP_ENUM:
  3540. case LA_CONDITION_INT:
  3541. switch (CompMode){
  3542. case LA_CONDITION_GE:
  3543. return (f1 >= (real)i2);
  3544. case LA_CONDITION_GT:
  3545. return (f1 > (real)i2);
  3546. case LA_CONDITION_EQ:
  3547. return (f1 + 0.0001 >= (real)i2 && f1 - 0.0001 <= (real)i2);
  3548. case LA_CONDITION_LT:
  3549. return (f1 < (real)i2);
  3550. case LA_CONDITION_LE:
  3551. return (f1 <= (real)i2);
  3552. }
  3553. case LA_PROP_FLOAT:
  3554. case LA_CONDITION_FLOAT:
  3555. switch (CompMode){
  3556. case LA_CONDITION_GE:
  3557. return (f1 >= f2);
  3558. case LA_CONDITION_GT:
  3559. return (f1 > f2);
  3560. case LA_CONDITION_EQ:
  3561. return (f1 == f2);
  3562. case LA_CONDITION_LT:
  3563. return (f1 < f2);
  3564. case LA_CONDITION_LE:
  3565. return (f1 <= f2);
  3566. }
  3567. default:
  3568. return 0;
  3569. }
  3570. case LA_PROP_STRING:
  3571. case LA_CONDITION_STRING:
  3572. switch (Mode2){
  3573. case LA_PROP_STRING:
  3574. case LA_CONDITION_STRING:
  3575. return strSame(s1, s2);
  3576. default:
  3577. return 0;
  3578. }
  3579. case LA_PROP_SUB:
  3580. switch (Mode2){
  3581. case LA_PROP_SUB:
  3582. return p1 == p2;
  3583. case LA_CONDITION_INT:
  3584. case LA_PROP_INT:
  3585. case LA_PROP_ENUM:
  3586. return (int)p1 == i2;
  3587. default:
  3588. return 0;
  3589. }
  3590. default:
  3591. switch (CompMode){
  3592. case LA_CONDITION_GE:
  3593. return (i1 >= i2);
  3594. case LA_CONDITION_GT:
  3595. return (i1 > i2);
  3596. case LA_CONDITION_EQ:
  3597. return (i1 == i2);
  3598. case LA_CONDITION_LT:
  3599. return (i1 < i2);
  3600. case LA_CONDITION_LE:
  3601. return (i1 <= i2);
  3602. }
  3603. }
  3604. }
  3605. int la_DoExpression(laUiConditionNode *Expression, int *IResult, real *FResult, char *_StrResult, void **PtrResult){
  3606. void *Instance = 0;
  3607. int IValue1 = 0, IValue2 = 0;
  3608. real FValue1 = 0, FValue2 = 0;
  3609. void *Ptr1 = 0, *Ptr2 = 0;
  3610. char Str1[128], Str2[128]={0}; char* StrResult=_StrResult;
  3611. int Result1, Result2;
  3612. laEnumItem *ei;
  3613. if (!Expression) return 0;
  3614. Str1[0] = 0;
  3615. Str2[0] = 0;
  3616. laPropIterator pi = {0};
  3617. switch (Expression->Type){
  3618. case LA_CONDITION_PROP:
  3619. if (!Expression->PP.LastPs){
  3620. (*IResult) = 0;
  3621. return 0;
  3622. }
  3623. switch (Expression->PP.LastPs->p->PropertyType){
  3624. case LA_PROP_INT:
  3625. *IResult = laGetInt(&Expression->PP);
  3626. if (*IResult) return LA_CONDITION_INT;
  3627. else
  3628. return 0;
  3629. case LA_PROP_FLOAT:
  3630. *FResult = laGetFloat(&Expression->PP);
  3631. if (*FResult) return 1;
  3632. else
  3633. return 0;
  3634. break;
  3635. case LA_PROP_STRING:
  3636. laGetString(&Expression->PP, _StrResult, &StrResult);
  3637. if (StrResult[0]) return 1;
  3638. else
  3639. return 0;
  3640. break;
  3641. case LA_PROP_ENUM:
  3642. ei = laGetEnum(&Expression->PP);
  3643. if (!ei) return 0;
  3644. /*if(ei) */ *IResult = ei->Index;
  3645. if (*IResult) return LA_CONDITION_INT;
  3646. break;
  3647. case LA_PROP_SUB:
  3648. if (!Expression->PP.Go) Instance = Expression->PP.EndInstance;
  3649. else
  3650. Instance = laGetActiveInstance(Expression->PP.LastPs->p, Expression->PP.LastPs->UseInstance, &pi);
  3651. *PtrResult = Instance;
  3652. if (Instance) return 1;
  3653. break;
  3654. default:
  3655. return 0;
  3656. }
  3657. case LA_CONDITION_INT:
  3658. *IResult = Expression->IntValue;
  3659. if (*IResult) return 1;
  3660. else
  3661. return 0;
  3662. case LA_CONDITION_FLOAT:
  3663. *FResult = Expression->FloatValue;
  3664. if (*FResult) return 1;
  3665. else
  3666. return 0;
  3667. case LA_CONDITION_STRING:
  3668. if (Expression->String){
  3669. strCopyFull(StrResult, Expression->String->Ptr);
  3670. return 1;
  3671. }else
  3672. return 0;
  3673. case LA_CONDITION_TRUE:
  3674. if (*IResult) *IResult = 1;
  3675. return 1;
  3676. case LA_CONDITION_FALSE:
  3677. if (*IResult) *IResult = 0;
  3678. return 0;
  3679. default:
  3680. Result1 = la_DoExpression(Expression->Expression1, &IValue1, &FValue1, &Str1, &Ptr1);
  3681. switch (Expression->Type){
  3682. case LA_CONDITION_AND:
  3683. if (Result1){
  3684. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3685. if (Result2) *IResult = 1;
  3686. return (Result2);
  3687. }else
  3688. return 0;
  3689. case LA_CONDITION_OR:
  3690. if (!Result1){
  3691. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3692. if (Result2) *IResult = 1;
  3693. return (Result2);
  3694. }else
  3695. return 1;
  3696. case LA_CONDITION_NOT:
  3697. return !Result1;
  3698. default:
  3699. Result2 = la_DoExpression(Expression->Expression2, &IValue2, &FValue2, &Str2, &Ptr2);
  3700. return la_DoCompare(Expression->Type,
  3701. (Expression->Expression1->Type == LA_CONDITION_PROP && Expression->Expression1->PP.LastPs) ? Expression->Expression1->PP.LastPs->p->PropertyType : Expression->Expression1->Type, IValue1, FValue1, Str1, Ptr1,
  3702. (Expression->Expression2->Type == LA_CONDITION_PROP && Expression->Expression2->PP.LastPs) ? Expression->Expression2->PP.LastPs->p->PropertyType : Expression->Expression2->Type, IValue2, FValue2, Str2, Ptr2);
  3703. }
  3704. break;
  3705. }
  3706. return 0;
  3707. }
  3708. int la_DoSingleExpression(laUiConditionNode *Expression){
  3709. int a;
  3710. real b;
  3711. char c[128]={0};
  3712. void *p;
  3713. if (!Expression) return 1;
  3714. c[0] = 0;
  3715. return la_DoExpression(Expression, &a, &b, c, &p);
  3716. }
  3717. void la_StepExpression(laUiConditionNode *e){
  3718. if (!e) return;
  3719. switch (e->Type){
  3720. case LA_CONDITION_AND:
  3721. case LA_CONDITION_OR:
  3722. case LA_CONDITION_GE:
  3723. case LA_CONDITION_GT:
  3724. case LA_CONDITION_EQ:
  3725. case LA_CONDITION_LT:
  3726. case LA_CONDITION_LE:
  3727. la_StepExpression(e->Expression1);
  3728. la_StepExpression(e->Expression2);
  3729. break;
  3730. case LA_CONDITION_NOT:
  3731. la_StepExpression(e->Expression1);
  3732. break;
  3733. case LA_CONDITION_PROP:
  3734. la_StepPropPack(&e->PP);
  3735. if (e->PP.LastPs && e->PP.LastPs->p->Container && e->PP.LastPs->p->Container->Hyper){
  3736. la_UsePropPack(&e->PP, 1);
  3737. //laUseDataBlock(e->PP.Go ? e->PP.LastPs->UseInstance : e->PP.EndInstance, e->PP.LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover,1);
  3738. }
  3739. break;
  3740. default:
  3741. break;
  3742. }
  3743. }
  3744. void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn){
  3745. if (!ucn) return;
  3746. la_ConditionNodeFreeRecursive(ucn->Expression1);
  3747. la_ConditionNodeFreeRecursive(ucn->Expression2);
  3748. if (ucn->PP.LastPs) la_FreePropStepCache(ucn->PP.Go);
  3749. if (ucn->String) strSafeDestroy(&ucn->String);
  3750. if (ucn) memFree(ucn);
  3751. }
  3752. laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expression){
  3753. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3754. ui->C = c;
  3755. ui->Type = &_LA_UI_CONDITION;
  3756. la_ConditionerInit(ui, Expression);
  3757. lstAppendItem(&uil->UiItems, ui);
  3758. return ui;
  3759. }
  3760. laUiItem *laElse(laUiList *uil, laUiItem *Beginner){
  3761. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3762. laConditionUiExtraData *cued;
  3763. ui->Type = &_LA_UI_CONDITION_ELSE;
  3764. la_ConditionerInit(ui, 0);
  3765. cued = ui->Extra;
  3766. cued->EndUi = Beginner;
  3767. ((laConditionUiExtraData *)Beginner->Extra)->ElseUi = ui;
  3768. ui->C = Beginner->C;
  3769. lstAppendItem(&uil->UiItems, ui);
  3770. return ui;
  3771. }
  3772. laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget){
  3773. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3774. laConditionUiExtraData *cued;
  3775. ui->Template = define;
  3776. ui->C = col;
  3777. ui->PP.RawThis = ExtraBase;
  3778. ui->Page = ExtraThis;
  3779. ui->Type = Widget? Widget->Type : _LA_UI_CONDITION_TOGGLE;
  3780. la_ConditionerInit(ui, 0);
  3781. cued = ui->Extra;
  3782. //cued->Remove = Remove;
  3783. ui->State = LA_UI_NORMAL;
  3784. lstAppendItem(&uil->UiItems, ui);
  3785. return ui;
  3786. }
  3787. laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
  3788. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3789. laConditionUiExtraData *cued;
  3790. ui->Type = &_LA_UI_CONDITION_END;
  3791. la_ConditionerInit(ui, 0);
  3792. cued = ui->Extra;
  3793. cued->EndUi = Beginner;
  3794. ((laConditionUiExtraData *)Beginner->Extra)->EndUi = ui;
  3795. ui->C = Beginner->C;
  3796. lstAppendItem(&uil->UiItems, ui);
  3797. return ui;
  3798. }
  3799. laUiList *laMakeMenuPage(laUiList *uil, laColumn *c, const char *Title){
  3800. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3801. laUiList *muil = memAcquireSimple(sizeof(laUiList));
  3802. ui->Type = _LA_UI_MENU_ROOT;
  3803. strSafeSet(&ui->Display, Title);
  3804. ui->State = LA_UI_NORMAL;
  3805. ui->C = c;
  3806. lstAppendItem(&uil->UiItems, ui);
  3807. lstAppendItem(&ui->Subs, muil);
  3808. return muil;
  3809. }
  3810. laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
  3811. laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
  3812. ui->Type = _LA_UI_ALIGN;
  3813. ui->C = widest;
  3814. lstAppendItem(&uil->UiItems, ui);
  3815. return ui;
  3816. }
  3817. void laFixHeight(laUiList *uil, short Rows){
  3818. if (!uil) return;
  3819. uil->HeightCoeff = Rows;
  3820. }
  3821. void laMakeUiListFromTemplate(laUiList *Into, laUiDefineFunc Template,
  3822. laPropPack *PanelPP, laPropPack *PanelExtraPP, laPropPack *Base, laPropPack *Operator, laListHandle *ExtraColumns, int Context){
  3823. if (!ExtraColumns) return;
  3824. Template(Into, Base, Operator, ExtraColumns->pFirst, Context);
  3825. }
  3826. laUiTemplate *laFindUiTemplate(char *Identifier){
  3827. laUiTemplate *uit;
  3828. for (uit = MAIN.PanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3829. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3830. }
  3831. for (uit = MAIN.InitPanelTemplates.pFirst; uit; uit = uit->Item.pNext){
  3832. if (!strcmp(uit->Identifier->Ptr, Identifier)) return uit;
  3833. }
  3834. return 0;
  3835. }
  3836. void la_DestroyUiTemplate(laUiTemplate* uit){
  3837. strSafeDestroy(&uit->Identifier);
  3838. strSafeDestroy(&uit->Title);
  3839. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMap.Items)){ la_FreeKeyMapItem(kmi); }
  3840. memFree(uit);
  3841. }
  3842. void la_DestroyCanvasTemplate(laCanvasTemplate* uit){
  3843. strSafeDestroy(&uit->Identifier);
  3844. laKeyMapItem* kmi; while(kmi=lstPopItem(&uit->KeyMapper.Items)){ la_FreeKeyMapItem(kmi); }
  3845. memFree(uit);
  3846. }
  3847. laUiTemplate *laRegisterUiTemplate(char *Identifier, char* Title, laUiDefineFunc func,laPanelDetachedPropFunc PropFunc, laUiDefineFunc header, char* NewCategory, int DefaultGLFormat, int DefaultW_RH, int DefaultH_RH){
  3848. laUiTemplate *uit = memAcquire(sizeof(laUiTemplate));
  3849. strSafeSet(&uit->Identifier, Identifier);
  3850. strSafeSet(&uit->Title, Title);
  3851. strSafeSet(&uit->CategoryName, NewCategory);
  3852. uit->Define = func; uit->Header = header; uit->PropFunc = PropFunc;
  3853. uit->DefaultGLFormat=DefaultGLFormat;
  3854. uit->DefaultH_RH=DefaultH_RH?abs(DefaultH_RH):15; uit->DefaultW_RH=DefaultW_RH?abs(DefaultW_RH):15;
  3855. if(MAIN.InitDone) lstAppendItem(&MAIN.PanelTemplates, uit); else lstAppendItem(&MAIN.InitPanelTemplates, uit);
  3856. la_UDFAppendSharedTypePointer(Identifier, uit);
  3857. return uit;
  3858. }
  3859. laCanvasTemplate *laRegisterCanvasTemplate(char *Identifier, char *ForContainer, laModalFunc ExtraModal, laCanvasDrawFunc Func, laUiDrawFunc SecondDraw, laUiInitFunc CustomInit, laUiDestroyFunc CustomDestroy){
  3860. laCanvasTemplate *t = memAcquire(sizeof(laCanvasTemplate));
  3861. strSafeSet(&t->Identifier, Identifier);
  3862. t->Draw = Func; t->SecondDraw = SecondDraw; t->TargetContainerID = ForContainer; t->ExtraModal=ExtraModal;
  3863. t->Init = CustomInit; t->Destroy = CustomDestroy;
  3864. lstAppendItem(&MAIN.View2DTemplates, t);
  3865. la_UDFAppendSharedTypePointer(Identifier, t);
  3866. return t;
  3867. }
  3868. void laFinalizeUiTemplates(){
  3869. laUiTemplate *uit;
  3870. laCanvasTemplate *u2d;
  3871. for (u2d = MAIN.View2DTemplates.pFirst; u2d; u2d = u2d->Item.pNext){
  3872. if (u2d->TargetContainerID) u2d->TargetContainer = la_ContainerLookup(u2d->TargetContainerID);
  3873. }
  3874. }
  3875. laPanel *la_FindFreePanelByTemplate(laWindow *w, const laUiTemplate *uit){
  3876. laPanel *p;
  3877. for (p=w->Panels.pFirst; p; p = p->Item.pNext){
  3878. if (p->PanelTemplate==uit){
  3879. return p;
  3880. }
  3881. }
  3882. return 0;
  3883. }
  3884. void la_DestroyUiItem(laUiItem *ui, int RemoveUsers){
  3885. laUiList *uil, *NextUil;
  3886. for (uil = ui->Subs.pFirst; uil; uil = NextUil){
  3887. NextUil = uil->Item.pNext;
  3888. lstRemoveItem(&ui->Subs, uil);
  3889. la_DestroyUiList(uil, 0, RemoveUsers, 0);
  3890. }
  3891. la_StopUiOperatorService(ui);
  3892. strSafeDestroy(&ui->ExtraInstructions);strDestroyStringSplitor(&ui->Instructions);
  3893. strSafeDestroy(&ui->Display);
  3894. if (RemoveUsers && ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3895. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3896. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3897. la_FreePropStepCache(ui->PP.Go); //-------[Up Here], instance already been freed.XXXXXXXXXXXX!!!!!!!!!!1
  3898. if (ui->Type->Destroy) ui->Type->Destroy(ui);
  3899. memFree(ui);
  3900. }
  3901. void la_DestroyUiList(laUiList *uil, int NoFree, int RemoveUsers, int OnlyRemoveUser){
  3902. laUiItem *ui, *NextUi;
  3903. laColumn *col, *NextCol;
  3904. if (!uil) return;
  3905. for (ui = uil->UiItems.pFirst; ui; ui = NextUi){
  3906. NextUi = ui->Item.pNext;
  3907. if(OnlyRemoveUser && RemoveUsers){
  3908. if (ui->PP.LastPs && ui->PP.LastPs->p->Container->Hyper)
  3909. { /*la_StopUsingPropPack(&ui->PP);*/ }
  3910. //laStopUsingDataBlock(ui->PP.LastPs->UseInstance,ui->PP.LastPs->p,MAIN.PropMatcherContextP);
  3911. continue;
  3912. }
  3913. lstRemoveItem(&uil->UiItems, ui);
  3914. la_DestroyUiItem(ui, RemoveUsers);
  3915. }
  3916. if(OnlyRemoveUser){ return; }
  3917. for (col = uil->Columns.pFirst; col; col = NextCol){
  3918. NextCol = col->Item.pNext;
  3919. lstRemoveItem(&uil->Columns, col);
  3920. memFree(col);
  3921. }
  3922. strSafeDestroy(&uil->TabName);
  3923. if (!NoFree) memFree(uil);
  3924. }
  3925. void la_DestroyTabPage(laUiItem *ui, laUiList *Tab, int RemoveUsers){
  3926. if(ui) lstRemoveItem(&ui->Subs, Tab);
  3927. la_DestroyUiList(Tab, 1, RemoveUsers, 0);
  3928. }
  3929. void la_CreateUiAfter(laUiList *uil, laUiItem *after, laUiDefineFunc Define, laPropPack *Base, laPropPack *This, laColumn **ExtraColums){
  3930. laUiItem *Next = after->Item.pNext;
  3931. laUiItem *Last = uil->UiItems.pLast;
  3932. after->Item.pNext = 0;
  3933. uil->UiItems.pLast = after;
  3934. Define(uil, Base, This, ExtraColums, 0);
  3935. if (Next) Next->Item.pPrev = uil->UiItems.pLast;
  3936. ((laUiItem *)uil->UiItems.pLast)->Item.pNext = Next;
  3937. if (Next != Last) uil->UiItems.pLast = Last;
  3938. }
  3939. //void la_RefreshExtraColumns(laUiItem* ui, int B,int FromL,int ToL,int FromR,int ToR){
  3940. // int i = 0;
  3941. // int FromW=FromR-FromL, ToW=ToR-ToL;
  3942. // if (!ui->ExtraColums) return;
  3943. // for (i; ui->ExtraColums[i]; i++) {
  3944. // laColumn* c = ui->ExtraColums[i];
  3945. // c->B = B;
  3946. // c->IL = (c->IL - FromL) / FromW*ToW + ToL;
  3947. // c->IR = (c->IR - FromL) / FromW*ToW + ToL;
  3948. // }
  3949. //}
  3950. void la_PropPanelUserRemover(void* this_UNUSED, laItemUserLinker* iul){
  3951. laPanel* p = iul->Pointer.p; if(p->FrameDistinguish == iul->FrameDistinguish){ laRecalcPanel(p); }
  3952. }
  3953. void la_CalcUiItemInfluence(laListHandle *lst, laUiItem *ui){
  3954. laColumn *c = ui->C;
  3955. laColumn *ic = lst->pFirst;
  3956. c->B = ui->TB + (*ui->Type->Theme)->BP;
  3957. for (ic; ic; ic = ic->Item.pNext){
  3958. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3959. ic->B = ic->B < c->B ? c->B : ic->B;
  3960. }
  3961. }
  3962. ic = ui->C;
  3963. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  3964. ;
  3965. for (ic; ic; ic = ic->Item.pNext){
  3966. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3967. ic->B = ic->B < c->B ? c->B : ic->B;
  3968. }
  3969. }
  3970. }
  3971. void la_CalcUiTopInfluence(laListHandle *lst, laUiItem *ui){
  3972. laColumn *c = ui->C;
  3973. laColumn *ic = lst->pFirst;
  3974. c->B = ui->TB + (*ui->Type->Theme)->TP;
  3975. for (ic; ic; ic = ic->Item.pNext){
  3976. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3977. ic->B = ic->B < c->B ? c->B : ic->B;
  3978. }
  3979. }
  3980. ic = ui->C;
  3981. while (ic->Item.pPrev && (ic = ic->Item.pPrev))
  3982. ;
  3983. for (ic; ic; ic = ic->Item.pNext){
  3984. if (((ic->IR > c->IL) && (ic->IL < c->IR)) || ((ic->IL < c->IR) && (ic->IR > c->IL))){
  3985. ic->B = ic->B < c->B ? c->B : ic->B;
  3986. }
  3987. }
  3988. }
  3989. int la_ResetUiColum(laColumn *c, laColumn *Top, int U, int L, int R, int LR, int repos){ //1=L,2=R
  3990. int rep;
  3991. int sp;
  3992. int rev;
  3993. int M=_LA_THEME_PANEL->LM+_LA_THEME_PANEL->RM;
  3994. if (!c) return 0;
  3995. sp = (c->SP * (R - L)) + L;
  3996. rev = sp;
  3997. /*if (U)*/ c->B = U;
  3998. if (LR == 1){
  3999. c->IL = L;
  4000. c->IR = sp;
  4001. if (repos){
  4002. c->IR = repos;
  4003. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4004. c->IR = c->IL + c->MaxW*LA_RH+M;
  4005. rev = c->IR;
  4006. }
  4007. }else if (LR == 2){
  4008. c->IL = sp;
  4009. c->IR = R;
  4010. if (repos){
  4011. c->IL = repos;
  4012. }else if (c->MaxW*LA_RH && c->IR - c->IL > c->MaxW*LA_RH+M){
  4013. c->IL = c->IR - c->MaxW*LA_RH-M;
  4014. rev = c->IL;
  4015. }
  4016. }else if (LR == 0){
  4017. c->IL = L;
  4018. c->IR = R;
  4019. }
  4020. if (c->LS && c->RS->MaxW == 0){
  4021. rep = la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, 0);
  4022. la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, rep);
  4023. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4024. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4025. }else if (c->RS && c->LS->MaxW == 0){
  4026. rep = la_ResetUiColum(c->RS, Top, U, c->IL, c->IR, 2, 0);
  4027. la_ResetUiColum(c->LS, Top, U, c->IL, c->IR, 1, rep);
  4028. c->LS->PreWidth = c->PreWidth * c->LS->SP;
  4029. c->RS->PreWidth = c->PreWidth * (1 - c->RS->SP);
  4030. }
  4031. return rev;
  4032. }
  4033. STRUCTURE(laRowInfo){
  4034. int MaxW;
  4035. int MinW;
  4036. int UnitMinW;
  4037. int NonExpandW;
  4038. int TotalPadding;
  4039. int Expand, Even;
  4040. int ExpandAccum;
  4041. int CountElements;
  4042. int U,MaxB,L;
  4043. laListHandle Elements;
  4044. int LastNoHeight;
  4045. };
  4046. STRUCTURE(laRowNode){
  4047. laListItem Item;
  4048. laUiItem* ui;
  4049. int GotW, LP, RP, H;
  4050. int Expand;
  4051. int UseLast;
  4052. };
  4053. int la_InitRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt){
  4054. ri->MaxW = ui->TR-ui->TL;//row node does not use margin
  4055. ri->UnitMinW=LA_RH;
  4056. ri->Expand=ui->State?1:0;
  4057. ri->Even=ui->Flags?1:0;
  4058. ri->U=ui->TU; ri->L=ui->TL;
  4059. ri->MaxB=ui->TU;
  4060. }
  4061. void la_AddRowNode(laRowInfo* ri, laUiItem* ui, laBoxedTheme* bt, int H){
  4062. laRowNode* rn=CreateNew(laRowNode);
  4063. rn->LP=bt->LP;rn->RP=bt->RP;
  4064. rn->GotW = (ui->Type->GetMinWidth?ui->Type->GetMinWidth(ui):(LA_RH));
  4065. rn->ui=ui;
  4066. rn->H=H;
  4067. rn->Expand=ui->Expand;
  4068. lstAppendItem(&ri->Elements, rn);
  4069. if(ri->LastNoHeight){
  4070. ri->LastNoHeight=0; rn->UseLast=1; return; }
  4071. if(ui->Flags&LA_UI_FLAGS_UNDERNEATH){
  4072. ri->LastNoHeight=1; };
  4073. if(!ri->UnitMinW){ri->UnitMinW=LA_RH;}
  4074. ri->TotalPadding += (bt->LP+bt->RP);
  4075. ri->MinW+=ri->UnitMinW;
  4076. ri->NonExpandW+=rn->GotW;
  4077. ri->ExpandAccum+=ui->Expand;
  4078. ri->CountElements++;
  4079. if(ui->Expand){ri->Expand=1;}
  4080. if(ri->U+H+bt->BP>ri->MaxB){ri->MaxB=ri->U+H+bt->BP;}
  4081. }
  4082. int la_ShrinkableRowElements(laRowInfo* ri){
  4083. int count=0;
  4084. for(laRowNode* rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4085. if(rn->GotW<=ri->UnitMinW || rn->UseLast) continue;
  4086. count++;
  4087. }
  4088. return count;
  4089. }
  4090. void la_RecordSocketRuntimePosition(laUiItem* ui);
  4091. int la_CalculateRowExpand(laRowInfo* ri, laUiItem* ui_end, int WaitAnimation){
  4092. int Available=ri->MaxW-ri->NonExpandW-ri->TotalPadding;
  4093. int ShareCount=0, Additional=0, AdditionalRemaining=0, Shrinkable=0; real NodeAddFraction=0;
  4094. if(Available<0){
  4095. ShareCount=1;// Shrinkable=la_ShrinkableRowElements(ri);
  4096. Additional=(ri->MaxW-ri->MinW-ri->TotalPadding)/ri->CountElements;
  4097. AdditionalRemaining = (ri->MaxW-ri->MinW-ri->TotalPadding)-Additional*ri->CountElements;
  4098. }else{
  4099. if(!ri->Expand && Available>0){Available=0;}
  4100. ShareCount=ri->ExpandAccum?ri->ExpandAccum:ri->CountElements;
  4101. }
  4102. if(!ShareCount) return 0;
  4103. int PerNode = Available/ShareCount;
  4104. int Remaining = Available-PerNode*ShareCount;
  4105. int L = ri->L; int i=0; laRowNode* rn;
  4106. for(rn=ri->Elements.pFirst;rn;rn=rn->Item.pNext){
  4107. laUiItem* ui=rn->ui;
  4108. int NodeAdd, Node=rn->GotW;
  4109. if(rn->UseLast){
  4110. laRowNode* prevrn=rn->Item.pPrev; laUiItem* prevui=prevrn->ui;
  4111. rn->ui->TL=prevui->TL;rn->ui->TR=prevui->TR;rn->ui->TU=prevui->TU;rn->ui->TB=prevui->TB;
  4112. continue;
  4113. }
  4114. if(Available>=0){
  4115. NodeAdd=ri->ExpandAccum?(PerNode*rn->Expand):PerNode;
  4116. NodeAdd+=(i<Remaining?1:0);i++;
  4117. }else{
  4118. if(ri->MaxW>=ri->MinW+ri->TotalPadding) {
  4119. NodeAddFraction+=((rn->GotW>ri->UnitMinW)?(real)Available*(real)(rn->GotW-ri->UnitMinW)/(real)(ri->NonExpandW-ri->MinW):0);
  4120. NodeAdd=(int)NodeAddFraction; NodeAddFraction-=NodeAdd;
  4121. }else{ Node=ri->UnitMinW;
  4122. NodeAdd=Additional+(i<-AdditionalRemaining?-1:0);i++;
  4123. }
  4124. }
  4125. ui->TL = L + rn->LP;
  4126. ui->TR = ui->TL + Node+NodeAdd;
  4127. ui->TB = ui->TU + rn->H;
  4128. L=ui->TR+rn->RP;
  4129. if (!WaitAnimation){
  4130. ui->L = ui->TL; ui->R = ui->TR;
  4131. ui->U = ui->TU; ui->B = ui->TB;
  4132. }
  4133. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4134. }
  4135. ui_end->TB = ui_end->Flags&LA_UI_FLAGS_UNDERNEATH?ui_end->TU:ri->MaxB;
  4136. while(rn=lstPopItem(&ri->Elements)){
  4137. FreeMem(rn);
  4138. }
  4139. memset(ri, 0, sizeof(laRowInfo));
  4140. }
  4141. void la_RecordSocketRuntimePosition(laUiItem* ui){
  4142. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4143. int sl,sr,su,sb;
  4144. if(ui->Flags&LA_UI_SOCKET_LABEL_N){ sl=ui->TL; sr=ui->TR; su=ui->TU+LA_RH; }
  4145. elif(ui->Flags&LA_UI_SOCKET_LABEL_S){ sl=ui->TL; sr=ui->TR; su=ui->TU; }
  4146. elif(ui->Flags&LA_UI_SOCKET_LABEL_W){ sl=ui->TL+LA_2RH; sr=ui->TR; su=ui->TU; }
  4147. elif(ui->Flags&LA_UI_SOCKET_LABEL_E){ sl=ui->TL; sr=ui->TR-LA_2RH; su=ui->TU; }
  4148. else{ sl=ui->TL; su=ui->TU; sr=ui->TR; } sb=su+LA_RH;
  4149. if(pc==LA_PC_SOCKET_OUT){
  4150. laNodeOutSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4151. }else{
  4152. laNodeInSocket* s=ui->PP.EndInstance; s->RuntimeX=(sl+sr)/2; s->RuntimeY=(su+sb)/2;
  4153. laUseDataBlock(s, LA_PROP_SOCKET_SOURCE, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, 0);
  4154. }
  4155. }
  4156. laUiList* la_GiveExistingPage(laListHandle* from, void* instance){
  4157. for(laUiList* uil=from->pFirst;uil;uil=uil->Item.pNext){ if(uil->Instance == instance){ lstRemoveItem(from,uil); return uil; } } return 0;
  4158. }
  4159. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme);
  4160. int la_UpdateUiListRecursive(laUiList *uil, int U, int L, int R, int B, int Fast, laPanel *ParentPanel){
  4161. laUiItem *ui; laListHandle TempPages={0}; laUiList* FoundUil;
  4162. laBoxedTheme *bt;
  4163. int Lowest = 0;
  4164. int HyperValue = 0;
  4165. int WaitAnimation;
  4166. int RowMode=0; laRowInfo ri={0};
  4167. laBoxedTheme* pt=*(ParentPanel->BT);
  4168. int _PL=-pt->LM,_PR=-pt->RM,_PT=-pt->TM,_PB=-pt->BM;
  4169. int MaxR=0;
  4170. if(!uil->Scale){uil->Scale=1;}
  4171. uil->SaveScale=MAIN.UiScale;
  4172. MAIN.UiScale*=uil->Scale;
  4173. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4174. uil->TU = U;uil->TL = L;uil->TR = R;uil->TB = uil->TU;
  4175. WaitAnimation = 0;
  4176. if (!uil->Columns.pFirst && !uil->UiItems.pFirst) return U;
  4177. la_ResetUiColum(uil->Columns.pFirst, uil->Columns.pFirst, U, L, R, 0, 0);
  4178. for (ui = uil->UiItems.pFirst; ui;){
  4179. int SubB = 0;
  4180. int H;
  4181. WaitAnimation = 0;
  4182. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4183. int NoHeight=ui->Flags&LA_UI_FLAGS_UNDERNEATH;
  4184. //if (Fast && ui->C->B > B) {
  4185. // //la_CalcUiItemInfluence(&uil->Colums, ui);
  4186. // ui = ui->Item.pNext;
  4187. // continue;
  4188. //}
  4189. if (!ui->Instructions){
  4190. if (ui->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->ExtraInstructions->Ptr);
  4191. if (ui->AT && ui->AT->ExtraInstructions) strMakeInstructions(&ui->Instructions, ui->AT->ExtraInstructions);
  4192. if (ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_OPERATOR){
  4193. laOperatorProp *ap = ui->PP.LastPs->p;
  4194. if (!ap->OperatorType) ap->OperatorType = laGetOperatorType(ap->OperatorID);
  4195. if (ap->OperatorType&&ap->OperatorType->ExtraInstructions) strMakeInstructions(&ui->Instructions, ap->OperatorType->ExtraInstructions);
  4196. }
  4197. }
  4198. if (ui->PP.LastPs){ la_StepPropPack(&ui->PP); }
  4199. la_UsePropPack(&ui->PP, 0);
  4200. if(ui->Type==&_LA_UI_INVISIBLE){ ui=ui->Item.pNext; continue; }
  4201. //if (ui->PP.LastPs && (HyperValue = ui->PP.LastPs->p->Container ? ui->PP.LastPs->p->Container->Hyper : 0)){
  4202. // 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);
  4203. //}
  4204. if ((ui->AnimationDistinguish + 1) == ParentPanel->FrameDistinguish){
  4205. ParentPanel->Refresh |= LA_TAG_ANIMATION; laRefreshWindow();
  4206. WaitAnimation = 1;
  4207. }
  4208. ui->AnimationDistinguish = ParentPanel->FrameDistinguish;
  4209. bt = (*ui->Type->Theme);
  4210. if (ui->Type == &_LA_UI_CONDITION){
  4211. laConditionUiExtraData *cued = ui->Extra;
  4212. la_StepExpression(cued->Expression);
  4213. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4214. if (!cued->IsTrue){
  4215. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4216. }else{
  4217. ui = ui->Item.pNext;
  4218. }
  4219. continue;
  4220. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4221. ui = ui->Item.pNext;
  4222. continue;
  4223. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4224. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4225. if (cued->IsTrue) ui = cued->EndUi;
  4226. else
  4227. ui = ui->Item.pNext;
  4228. continue;
  4229. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4230. laConditionUiExtraData *cued = ui->Extra;
  4231. ui->TL = ui->C->IL + bt->LP; ui->TR = ui->C->IR - bt->RP;
  4232. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU+LA_RH;
  4233. if (!WaitAnimation){
  4234. ui->L = ui->TL; ui->R = ui->TR;
  4235. ui->U = ui->TU; ui->B = ui->TB;
  4236. }
  4237. if(!RowMode){
  4238. la_CalcUiItemInfluence(&uil->Columns, ui);
  4239. }else{
  4240. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4241. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4242. }
  4243. if (ui->State == LA_UI_NORMAL){
  4244. cued->IsTrue = 0;
  4245. //if(cued->Remove && (ui->Item.pNext != cued->EndUi))
  4246. // la_DestroyUiRange(uil, ui->Item.pNext, cued->ElseUi?cued->ElseUi->Item.pPrev:cued->EndUi->Item.pPrev);
  4247. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4248. }else{
  4249. cued->IsTrue = 1;
  4250. //if (cued->Remove && (ui->Item.pNext == cued->EndUi || ui->Item.pNext==cued->ElseUi)) {
  4251. // la_CreateUiAfter(uil, ui, ui->Template, ui->PP.RawThis, ui->Page, uil->Columns.pFirst);
  4252. //}
  4253. ui = ui->Item.pNext;
  4254. }
  4255. continue;
  4256. }
  4257. if (ui->Type == _LA_UI_ALIGN){
  4258. ui->TU = ui->C->B + bt->TP; ui->TB = ui->TU;
  4259. ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4260. if (ui->TB > Lowest) Lowest = ui->TB;
  4261. if (!WaitAnimation){
  4262. ui->L = ui->TL; ui->R = ui->TR;
  4263. ui->U = ui->TU; ui->B = ui->TB;
  4264. }
  4265. if(!RowMode){
  4266. la_CalcUiItemInfluence(&uil->Columns, ui);
  4267. }else{
  4268. ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  4269. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4270. la_AddRowNode(&ri, ui, bt, H*LA_RH);
  4271. }
  4272. ui = ui->Item.pNext; continue;
  4273. }
  4274. if (ui->Type == &_LA_UI_ROW_BEGIN){
  4275. ui->TU = ui->C->B; ui->TL = ui->C->IL; ui->TR = ui->C->IR;
  4276. la_InitRowNode(&ri, ui, bt);
  4277. RowMode=1; ui=ui->Item.pNext; continue;
  4278. }
  4279. if (ui->Type == &_LA_UI_ROW_END){
  4280. la_CalculateRowExpand(&ri, ui, WaitAnimation);
  4281. la_CalcUiItemInfluence(&uil->Columns, ui);
  4282. RowMode=0; ui=ui->Item.pNext; continue;
  4283. }
  4284. if(!RowMode){ ui->TL = ui->C->IL + (NoGap?_PL:bt->LP); ui->TR = ui->C->IR - (NoGap?_PR:bt->RP); }
  4285. int GB=0;
  4286. 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; }
  4287. H = ui->Type->GetHeight ? ui->Type->GetHeight(ui) : 1;
  4288. ui->TU = ui->C->B + (NoGap?_PT:bt->TP);
  4289. if (H < 0){
  4290. if(B){ H = B + (H+1) * LA_RH - ui->TU+_PB+((H<-1)?_PT:0); }
  4291. else{ H=LA_RH; }
  4292. }
  4293. else H *= LA_RH;
  4294. ui->TB = ui->TU;
  4295. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4296. 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
  4297. laPropIterator pi = {0}; laSubProp* uisp=ui->PP.LastPs->p;
  4298. if (ui->Type == _LA_UI_COLLECTION){
  4299. //void* TInstance = ui->PP.Go?laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi):ui->PP.EndInstance;
  4300. void *TInstance = laGetInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4301. ui->PP.EndInstance = TInstance;
  4302. laUiList *iuil = ui->Subs.pFirst;
  4303. laUiList *puil = iuil;
  4304. int Row = 0, Col = 0, RowPriority = ui->SymbolID > 0 ? 1 : 0, ElementLimit = ui->SymbolID ? abs(ui->SymbolID) : 0;
  4305. int Spread=ui->Expand>2?ui->Expand:0; if(Spread){ RowPriority=0; ElementLimit=0; }
  4306. laUiDefineFunc Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4307. int Begin = ui->TB;
  4308. int EL = ui->TL, ER = Spread?(Spread*LA_RH+ui->TL):ui->TR;
  4309. int ElementB = ui->TU;
  4310. real ElementWidth = ElementLimit ? 1.0f / ElementLimit : 1.0;
  4311. int MaxB = ElementB;
  4312. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4313. int CanGetGap= laCanGetGap(ui->PP.LastPs->p); int Gap=0;
  4314. int CanGetCategory= laCanGetCategory(ui->PP.LastPs->p); char _cat[256]; char* cat=_cat; int GotCategory=0,FirstIn=1;
  4315. if (!ElementLimit) RowPriority = 0;
  4316. if (!TInstance){
  4317. while (iuil){
  4318. puil = iuil->Item.pNext;
  4319. la_DestroyTabPage(ui, iuil, 0);
  4320. iuil = puil;
  4321. }
  4322. }
  4323. while (TInstance){
  4324. if(uisp->UiFilter && (!uisp->UiFilter(ui->PP.LastPs->UseInstance, TInstance))){
  4325. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4326. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4327. ui->PP.EndInstance = TInstance; continue;
  4328. }
  4329. if(CanGetTheme){
  4330. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4331. la_SwitchThemeQuick(t, OriginalTheme);
  4332. }
  4333. if(CanGetGap){
  4334. int g=laGetUiGap(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance); g=g<0?0:g;
  4335. Gap=g*LA_RH;
  4336. }else Gap=0;
  4337. if(CanGetCategory){ _cat[0]=0; cat=_cat; GotCategory=0;
  4338. laGetCategory(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance, _cat, &cat); if(cat[0]) GotCategory=1;
  4339. }else GotCategory=0;
  4340. if(GotCategory){ Begin+=LA_RH*(FirstIn?1:1.5)+bt->TM;
  4341. if (RowPriority){
  4342. Row += 1; Col=0; Begin = ElementB+bt->TM+LA_RH*(FirstIn?1:1.5)+bt->TM;
  4343. }
  4344. }
  4345. FirstIn=0;
  4346. if (ElementLimit){
  4347. EL = tnsInterpolate(ui->TL, ui->TR, (Col)*ElementWidth);
  4348. ER = tnsInterpolate(ui->TL, ui->TR, (Col + 1) * ElementWidth);
  4349. }
  4350. while (iuil && iuil->Instance != TInstance){
  4351. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){
  4352. lstInsertItemBefore(&ui->Subs, FoundUil, iuil); puil = FoundUil;
  4353. }else{
  4354. puil = iuil->Item.pNext; lstRemoveItem(&ui->Subs, iuil); lstAppendItem(&TempPages, iuil);
  4355. }
  4356. iuil = puil;
  4357. }
  4358. if(!iuil){
  4359. if(FoundUil=la_GiveExistingPage(&TempPages, TInstance)){ lstAppendItem(&ui->Subs, FoundUil); iuil = FoundUil; }
  4360. }
  4361. if (!iuil){
  4362. la_AddInstancePage(ui, TInstance, 0); if(GotCategory){ strSafeSet(&ui->Page->TabName,cat); }
  4363. la_CalcUiTopInfluence(&uil->Columns, ui);
  4364. if (Template) laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4365. 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);
  4366. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4367. iuil = ui->Page->Item.pNext;
  4368. }else{
  4369. la_CalcUiTopInfluence(&uil->Columns, ui); if(GotCategory){ strSafeSet(&iuil->TabName,cat); }
  4370. 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);
  4371. ElementB = RowPriority ? (SubB > ElementB ? SubB : ElementB) : SubB;
  4372. la_CalcUiItemInfluence(&uil->Columns, ui);
  4373. iuil = iuil->Item.pNext;
  4374. }
  4375. TInstance = laGetNextInstance(ui->PP.LastPs->p, TInstance, &pi);
  4376. Template = ui->Template?ui->Template:laGetPropertyUiDefine(&ui->PP, TInstance);
  4377. ui->PP.EndInstance = TInstance;
  4378. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4379. if (RowPriority){
  4380. Col += 1;
  4381. if (Col >= ElementLimit){
  4382. Col = 0;
  4383. Row += 1;
  4384. Begin = ElementB + bt->TM;
  4385. }
  4386. }elif(Spread){
  4387. EL+=Spread*LA_RH;
  4388. ER+=Spread*LA_RH;
  4389. }else{
  4390. Row += 1;
  4391. Begin = ElementB + bt->TM;
  4392. if (ElementLimit && Row >= ElementLimit){
  4393. Row = 0;
  4394. Col += 1;
  4395. Begin = ui->TU + bt->TM;
  4396. }
  4397. }
  4398. ui->TB = ElementB;
  4399. MaxB = MaxB < ElementB ? ElementB : MaxB;
  4400. }
  4401. while (iuil){ puil = iuil->Item.pNext; la_DestroyTabPage(ui, iuil, 0); iuil = puil; }
  4402. while (iuil=lstPopItem(&TempPages)){ la_DestroyTabPage(0, iuil, 0); }
  4403. ui->PP.EndInstance = laGetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, &pi);
  4404. ui->TB = MaxB;
  4405. if(Spread){ ui->TR=ER-Spread*LA_RH; if(ui->TR>MaxR) MaxR=ui->TR; }
  4406. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB = MaxB; }
  4407. }else if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE){
  4408. if(ui->Flags&LA_UI_COLLECTION_SIMPLE_SELECTOR){
  4409. ui->TB=ui->TU+LA_RH;
  4410. }else{
  4411. void *TInstance = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4412. ui->PP.EndInstance = TInstance;
  4413. laUiTemplate *Template = ui->Template ? ui->Template : laGetPropertyUiDefine(&ui->PP, TInstance);
  4414. if(!Template) Template=laui_SubPropInfoDefault;
  4415. //ui->Template = Template;
  4416. int EraseWidth=(ui->Type == _LA_UI_COLLECTION_SELECTOR)?LA_RH:0;
  4417. if (!ui->Subs.pFirst && TInstance){
  4418. la_AddInstancePage(ui, TInstance, 0);
  4419. la_CalcUiTopInfluence(&uil->Columns, ui);
  4420. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4421. 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);
  4422. ui->TB = SubB + (NoDecal?0:bt->BM);
  4423. }else if (ui->Subs.pFirst){
  4424. if (!TInstance || TInstance != ui->Page->Instance){
  4425. la_DestroyTabPage(ui, ui->Subs.pFirst, 0);
  4426. ui->Page = 0;
  4427. if (TInstance){
  4428. la_AddInstancePage(ui, TInstance, 0);
  4429. la_CalcUiTopInfluence(&uil->Columns, ui);
  4430. laMakeUiListFromTemplate(ui->Page, Template, &ParentPanel->PP, &ParentPanel->PropLinkPP, &ui->PP, 0, &uil->Columns, ui->TemplateContext);
  4431. 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);
  4432. ui->TB = SubB + (NoDecal?0:bt->TM);
  4433. }else
  4434. ui->TB = ui->TU + LA_RH + bt->BM;
  4435. }else{
  4436. 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);
  4437. ui->TB = SubB + (NoDecal?0:bt->BM);
  4438. }
  4439. }
  4440. if(ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->TB>(ui->TU+LA_RH*0.9))&&(ui->TB<ui->TU+(LA_RH*1.1))){
  4441. ui->TB=ui->TU+LA_RH;
  4442. }
  4443. }
  4444. if (ui->TB-ui->TU<LA_RH) ui->TB = ui->TU + LA_RH;
  4445. if (!WaitAnimation){
  4446. ui->L = ui->TL;
  4447. ui->R = ui->TR;
  4448. ui->U = ui->TU;
  4449. ui->B = ui->TB;
  4450. }
  4451. }
  4452. }else{
  4453. if (ui->Type != _LA_UI_COLLECTION && (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4454. if (ui->Type != _LA_UI_CANVAS){
  4455. int scrollw=ui->Page->ScrollerShownV?bt->RP*2+LA_SCROLL_W:0;
  4456. la_CalcUiTopInfluence(&uil->Columns, ui);
  4457. SubB = la_UpdateUiListRecursive(ui->Page,
  4458. 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);
  4459. ui->TB = (ui->Page->HeightCoeff > 0 ? ui->TU + ui->Page->HeightCoeff * LA_RH :
  4460. (ui->Page->HeightCoeff < 0 ? B + (ui->Page->HeightCoeff+1) * LA_RH + (_PB+_PT) : SubB)) + (NoDecal?0:bt->BM);
  4461. int subh = ui->TB-ui->TU-LA_RH-bt->TM-bt->BM;
  4462. if((ui->Page->TR>ui->TR-(NoDecal?0:bt->RM) && (!ui->Page->ScrollerShownH)) ||
  4463. (ui->Page->TR<=ui->TR-(NoDecal?0:bt->RM) && ui->Page->ScrollerShownH)){
  4464. ui->Page->ScrollerShownH=!ui->Page->ScrollerShownH;
  4465. }
  4466. if(ui->Page->AllowScale){ui->Page->ScrollerShownH=1;}
  4467. if(ui->Page->ScrollerShownH){subh-=LA_SCROLL_W-bt->BM;}
  4468. if(GB && ui->TB >= GB){
  4469. ui->Page->PanY=(SubB-ui->TB-bt->BM); if(ui->Page->PanY<0)ui->Page->PanY=0; }
  4470. if(ui->Page->HeightCoeff){
  4471. if((subh<ui->Page->TB-ui->Page->TU && (!ui->Page->ScrollerShownV)) ||
  4472. (subh>=ui->Page->TB-ui->Page->TU && ui->Page->ScrollerShownV)){
  4473. ui->Page->ScrollerShownV=!ui->Page->ScrollerShownV;
  4474. ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER; laRefreshWindow();
  4475. }
  4476. if(SubB-ui->Page->PanY<ui->TB-bt->BM-(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0)){
  4477. ui->Page->PanY = (SubB-ui->TB-bt->BM+(ui->Page->ScrollerShownH?LA_SCROLL_W+bt->BM:0));
  4478. if(ui->Page->PanY<0){ui->Page->PanY=0;}
  4479. //ParentPanel->Refresh|=LA_TAG_RECALC_SCROLLER;
  4480. }
  4481. }
  4482. if(ui->Page->ScrollerShownH && !ui->Page->HeightCoeff){
  4483. ui->TB+=(bt->BP*2+LA_SCROLL_W); }
  4484. }else{
  4485. laUiList *suil;
  4486. if(!MAIN.CurrentWindow->MaximizedUi || ui!=MAIN.CurrentWindow->MaximizedUi){
  4487. la_CalcUiTopInfluence(&uil->Columns, ui);
  4488. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4489. 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);
  4490. }
  4491. }
  4492. ui->TB = ui->TU + H;
  4493. }
  4494. }else ui->TB = ui->TU + H;
  4495. }
  4496. if (ui->TB > Lowest) Lowest = ui->TB + (bt ? (NoGap?_PB:bt->BP) : 0);
  4497. if(!RowMode){
  4498. if(!NoHeight) la_CalcUiItemInfluence(&uil->Columns, ui);
  4499. }else{
  4500. la_AddRowNode(&ri, ui, bt, H);
  4501. }
  4502. if (!WaitAnimation){ ui->L = ui->TL; ui->R = ui->TR; ui->U = ui->TU; ui->B = ui->TB; }
  4503. if(ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocketRuntimePosition(ui); }
  4504. ui = ui->Item.pNext;
  4505. }
  4506. uil->TR=MaxR>uil->TR?MaxR:uil->TR;
  4507. if (uil->Columns.pFirst) uil->TB = ((laColumn *)uil->Columns.pFirst)->B;
  4508. else uil->TB = Lowest;
  4509. if (!WaitAnimation){
  4510. uil->L = uil->TL;
  4511. uil->R = uil->TR;
  4512. uil->U = uil->TU;
  4513. uil->B = uil->TB;
  4514. }
  4515. MAIN.UiScale=uil->SaveScale;
  4516. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4517. return uil->TB;
  4518. }
  4519. int la_AnimateSingleUiSize(int To, int *Now){
  4520. int Delta;
  4521. if (To != *Now){
  4522. Delta = (To - (*Now)) * (MAIN.AnimationSpeed) * MAIN.LastFrameTime * 60;
  4523. if (!Delta) Delta = To > (*Now) ? 1 : -1;
  4524. *Now += Delta;
  4525. return 1;
  4526. }else
  4527. return 0;
  4528. }
  4529. int la_AnimateUiListRecursive(laUiList *uil){
  4530. laUiItem *ui;
  4531. int Again = 0;
  4532. for (ui = uil->UiItems.pFirst; ui; ui = ui->Item.pNext){
  4533. int TB = ui->B, TU = ui->U, TL = ui->L, TR = ui->R, SB, SU, SL, SR;
  4534. Again += (la_AnimateSingleUiSize(ui->TB, &ui->B) +
  4535. la_AnimateSingleUiSize(ui->TU, &ui->U) +
  4536. la_AnimateSingleUiSize(ui->TL, &ui->L) +
  4537. la_AnimateSingleUiSize(ui->TR, &ui->R));
  4538. if (ui->Type == _LA_UI_COLLECTION_SELECTOR || ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4539. (ui->PP.LastPs && ui->PP.LastPs->p && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB && ui->Type != _LA_UI_CANVAS)){
  4540. laUiList *suil;
  4541. for (suil = ui->Subs.pFirst; suil; suil = suil->Item.pNext){
  4542. Again += la_AnimateUiListRecursive(suil);
  4543. }
  4544. }else if (ui->Type != _LA_UI_COLLECTION && ui->Type != &_LA_UI_ROW_END &&
  4545. (ui->Subs.pFirst || ui->Page) && ui->Type != _LA_UI_MENU_ROOT){
  4546. Again += la_AnimateUiListRecursive(ui->Page);
  4547. }
  4548. }
  4549. Again += (la_AnimateSingleUiSize(uil->TB, &uil->B) +
  4550. la_AnimateSingleUiSize(uil->TU, &uil->U) +
  4551. la_AnimateSingleUiSize(uil->TL, &uil->L) +
  4552. la_AnimateSingleUiSize(uil->TR, &uil->R));
  4553. return Again;
  4554. }
  4555. int la_DrawUiItem(laUiItem *ui){
  4556. tnsUseNoTexture();
  4557. tnsColor4d(1, 1, 1, 1);
  4558. tnsVertex2d(ui->L, ui->U);
  4559. tnsVertex2d(ui->R, ui->U);
  4560. tnsVertex2d(ui->R, ui->B);
  4561. tnsVertex2d(ui->L, ui->B);
  4562. tnsPackAs(GL_LINE_LOOP);
  4563. }
  4564. int la_DrawActiveUiItemOverlay(laUiItem *ui){
  4565. tnsUseNoTexture();
  4566. tnsColor4d(1, 1, 1, 1);
  4567. tnsVertex2d(ui->L - 1, ui->U - 1);
  4568. tnsVertex2d(ui->R + 1, ui->U - 1);
  4569. tnsVertex2d(ui->R + 1, ui->B + 1);
  4570. tnsVertex2d(ui->L - 1, ui->B + 1);
  4571. tnsPackAs(GL_LINE_LOOP);
  4572. }
  4573. int la_UiInBound(laUiItem *ui, int L, int R, int U, int B){
  4574. if (ui->R <= L || ui->L >= R || ui->U >= B || ui->B <= U) return 0;
  4575. return 1;
  4576. }
  4577. int la_UiInBoundEx(laUiItem *ui, laUiListDraw *uild){
  4578. laUiListDrawItem *uildi = uild->Items.pFirst;
  4579. laUiList *Target = uildi->Target;
  4580. int L, R, U, B;
  4581. if (!Target) return la_UiInBound(ui, uildi->L, uildi->R, uildi->U, uildi->B);
  4582. L = Target->L + Target->PanX + uildi->DifX;
  4583. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4584. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4585. U = Target->U + Target->PanY + uildi->DifY;
  4586. return la_UiInBound(ui, L, R, U, B);
  4587. }
  4588. int la_UiListInBoundEx(laUiList *uil, laUiListDraw *uild){
  4589. laUiListDrawItem *uildi = uild->Items.pFirst;
  4590. laUiList *Target = uildi->Target;
  4591. int L, R, U, B;
  4592. if (Target){
  4593. L = Target->L + Target->PanX + uildi->DifX;
  4594. R = Target->L + Target->PanX + uildi->DifX + (uildi->R - uildi->L);
  4595. B = Target->U + Target->PanY + uildi->DifY + (uildi->B - uildi->U);
  4596. U = Target->U + Target->PanY + uildi->DifY;
  4597. if (uil->R <= L || uil->L >= R || uil->U >= B || uil->B <= U) return 0;
  4598. return 1;
  4599. }else{
  4600. if (uil->R <= uildi->L || uil->L >= uildi->R || uil->U >= uildi->B || uil->B <= uildi->U) return 0;
  4601. return 1;
  4602. }
  4603. }
  4604. laUiItem *la_FindUiWithMark(laUiList *uil, char *mark){
  4605. laUiItem *ui = uil->UiItems.pFirst;
  4606. while (!strGetArgument(ui->Instructions, mark))
  4607. ui = ui->Item.pNext;
  4608. return ui;
  4609. }
  4610. laUiList *la_FindSubListWithInstance(laUiItem *ui, void *Instance){
  4611. laUiList *uil;
  4612. for (uil = ui->Subs.pFirst; uil; uil = uil->Item.pNext){
  4613. if (uil->Instance == Instance) return uil;
  4614. }
  4615. return uil;
  4616. }
  4617. void la_DrawUiListArrows(laUiList *uil, int L, int R, int U, int B, real* color){
  4618. int mx=(L+R)/2; int my=(U+B)/2;
  4619. if(uil->R-uil->PanX>R){ tnsDrawStringAuto("▷", color, R-LA_RH, R, my-LA_RH2, LA_TEXT_ALIGN_RIGHT); }
  4620. if(uil->L-uil->PanX<L){ tnsDrawStringAuto("◁", color, L, L+LA_RH, my-LA_RH2, LA_TEXT_ALIGN_LEFT); }
  4621. if(uil->U-uil->PanY<U){ tnsDrawStringAuto("△", color, mx-LA_RH2, mx+LA_RH2, U, LA_TEXT_ALIGN_CENTER); }
  4622. if(uil->B-uil->PanY>B){ tnsDrawStringAuto("▽", color, mx-LA_RH2, mx+LA_RH2, B-LA_RH, LA_TEXT_ALIGN_CENTER); }
  4623. tnsFlush();
  4624. }
  4625. void la_DrawUiListScrollerV(laUiList *uil, int DisplayOffset, int TotalH, int DisplayH, int UiR){
  4626. if(!uil->ScrollerShownV) return;
  4627. int W = LA_SCROLL_W, RM=_LA_THEME_PANEL->RM;
  4628. int Len = (int)((real)DisplayH / (real)TotalH * (real)DisplayH);
  4629. int Offset = (int)((real)DisplayOffset / (real)TotalH * (real)DisplayH);
  4630. int U = uil->U + Offset;
  4631. int B = U + Len;
  4632. int L = UiR - RM*2 - W;
  4633. int R = L + W;
  4634. if (B > U + DisplayH) B = U + DisplayH;
  4635. if (U < uil->U) U = uil->U;
  4636. if (B <= uil->U || U >= uil->B) return;
  4637. if (B > uil->U + DisplayH) B = uil->U + DisplayH;
  4638. if (U < uil->U) U = uil->U;
  4639. tnsUseNoTexture();
  4640. laBoxedTheme* bt=_LA_THEME_PANEL;
  4641. real* color=laThemeColor(bt, LA_BT_TEXT);
  4642. tnsColor4d(LA_COLOR3(color), 0.2);
  4643. tnsVertex2d(R-RM, uil->U);
  4644. tnsVertex2d(L+RM, uil->U);
  4645. tnsVertex2d(L+RM, uil->U + DisplayH);
  4646. tnsVertex2d(R-RM, uil->U + DisplayH);
  4647. tnsPackAs(GL_TRIANGLE_FAN);
  4648. tnsColor4d(LA_COLOR3(color), 0.5);
  4649. tnsVertex2d(R-RM, uil->U);
  4650. tnsVertex2d(L+RM, uil->U);
  4651. tnsVertex2d(L+RM, uil->U + DisplayH);
  4652. tnsVertex2d(R-RM, uil->U + DisplayH);
  4653. tnsPackAs(GL_LINE_LOOP);
  4654. tnsColor4d(LA_COLOR3(color), 1);
  4655. tnsVertex2d(R, U);
  4656. tnsVertex2d(L, U);
  4657. tnsVertex2d(L, B);
  4658. tnsVertex2d(R, B);
  4659. tnsPackAs(GL_TRIANGLE_FAN);
  4660. int HU=(U+B)/2+LA_RH2;
  4661. tnsDrawStringAuto("☰",laThemeColor(bt, LA_BT_BORDER),L-100,R+100,HU,LA_TEXT_REVERT_Y|LA_TEXT_ALIGN_CENTER);
  4662. tnsFlush();
  4663. }
  4664. void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int DisplayW, int UiB){
  4665. if(!uil->ScrollerShownH) return;
  4666. int W = LA_SCROLL_W,RM=_LA_THEME_PANEL->RM;
  4667. int Len = (int)((real)DisplayW / (real)TotalW * (real)DisplayW);
  4668. int Offset = (int)((real)DisplayOffset / (real)TotalW * (real)DisplayW);
  4669. int L = uil->L + Offset;
  4670. int R = L + Len;
  4671. int U = UiB - RM - W;
  4672. int B = U + W;
  4673. if (B > U + DisplayW) B = U + DisplayW;
  4674. if (U < uil->U) U = uil->U;
  4675. if (R <= uil->L || L >= uil->R) return;
  4676. if (R > uil->L + DisplayW) R = uil->L + DisplayW;
  4677. if (L < uil->L) L = uil->L;
  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(uil->L,U+RM);
  4683. tnsVertex2d(uil->L,B-RM);
  4684. tnsVertex2d(uil->L + DisplayW,B-RM);
  4685. tnsVertex2d(uil->L + DisplayW,U+RM);
  4686. tnsPackAs(GL_TRIANGLE_FAN);
  4687. tnsColor4d(LA_COLOR3(color), 0.5);
  4688. tnsVertex2d(uil->L,U+RM);
  4689. tnsVertex2d(uil->L,B-RM);
  4690. tnsVertex2d(uil->L + DisplayW,B-RM);
  4691. tnsVertex2d(uil->L + DisplayW,U+RM);
  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_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
  4704. tnsUseNoTexture();
  4705. tnsColor4dv(color);
  4706. tnsVertex2d(uil->L-LP, uil->U); tnsVertex2d(uil->R+RP, uil->U);
  4707. tnsVertex2d(uil->R+RP, uil->B); tnsVertex2d(uil->L-LP, uil->B);
  4708. tnsPackAs(GL_TRIANGLE_FAN);
  4709. }
  4710. void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
  4711. laSocketRecord* sr;
  4712. while(sr=lstPopItem(&uild->SocketRecord)){ memFree(sr); }
  4713. uild->WiresContainer=container;
  4714. }
  4715. void la_GetUiListOffsetUntil(laUiListDraw* uild, int* X, int* Y){
  4716. *X=*Y=0; for(laUiListDrawItem* lip=uild->Items.pLast;lip&&lip->Target;lip=lip->Item.pPrev){
  4717. if(lip->Target==uild->WiresContainer) break;
  4718. laUiList* uil=lip->Target; *X+=uil->PanX; *Y+=uil->PanY;
  4719. }
  4720. }
  4721. void la_RecordSocket(laUiListDraw* uild, laUiList* uil, laUiItem* ui){
  4722. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  4723. int PanX, PanY;
  4724. if(pc==LA_PC_SOCKET_OUT){
  4725. laNodeOutSocket* s=ui->PP.EndInstance;
  4726. la_GetUiListOffsetUntil(uild, &s->RuntimePX, &s->RuntimePY);
  4727. }else{
  4728. laNodeInSocket* s=ui->PP.EndInstance; if(!s->Source) return;
  4729. laSocketRecord* sr=memAcquireSimple(sizeof(laSocketRecord));
  4730. sr->In=s; sr->Out=s->Source; lstAppendItem(&uild->SocketRecord, sr);
  4731. }
  4732. }
  4733. void la_RegenerateWireColors(){
  4734. if(MAIN.WireColorCache) free(MAIN.WireColorCache);
  4735. laTheme* t=MAIN.CurrentTheme;
  4736. MAIN.WireColorCache = calloc(1, sizeof(real)*4*MAIN.WireColorSlices);
  4737. real hcy[]={0.0,0.8,0.6}; hcy[1]=t->WireSaturation; hcy[2]=t->WireBrightness;
  4738. for(int i=0;i<MAIN.WireColorSlices;i++){
  4739. hcy[0]=(real)i/(real)MAIN.WireColorSlices;
  4740. tnsHCY2RGB(hcy, &MAIN.WireColorCache[i*4]); MAIN.WireColorCache[i*4+3]=t->WireTransparency;
  4741. }
  4742. }
  4743. void la_SendWireVerts(real x1, real y1, real x2, real y2, real circle_r){
  4744. tnsVector2d v1,vi,v2,v1s,v2s; real dist=0;
  4745. v1[0]=x1; v1[1]=y1; v2[0]=x2; v2[1]=y2;
  4746. tnsInterpolate2dv(v1,v2,0.5,vi);
  4747. if(MAIN.WireSaggyness>0.01){ dist=tnsDist2dv(v1,v2); vi[1]+=log(dist+1)*MAIN.WireSaggyness; }
  4748. tnsVectorMinus2d(v1s,vi,v1); tnsNormalizeSelf2d(v1s); tnsVectorMultiSelf2d(v1s,circle_r);
  4749. tnsVectorMinus2d(v2s,vi,v2); tnsNormalizeSelf2d(v2s); tnsVectorMultiSelf2d(v2s,circle_r);
  4750. tnsVectorAccum2d(v1, v1s); tnsVectorAccum2d(v2, v2s);
  4751. if(MAIN.WireSaggyness<0.01){ tnsVertex2d(v1[0],v1[1]); tnsVertex2d(v2[0],v2[1]); return; }
  4752. int seglen=3, steps=dist/seglen+1; real step=1.0f/steps;
  4753. tnsVertex2d(v1[0],v1[1]);
  4754. for(int i=1;i<=steps;i++){
  4755. real ratio=i==steps?1.0f:step*i;
  4756. tnsInterpolateTripple2d(v1,vi,v2,ratio, v1s);
  4757. tnsVertex2d(v1s[0],v1s[1]);
  4758. }
  4759. }
  4760. void la_DrawNodeWires(laUiListDraw* uild){
  4761. if(!uild->SocketRecord.pFirst && !MAIN.tNodeIn->Source){ return; }
  4762. laBoxedTheme* bt=_LA_THEME_SOCKET;
  4763. tnsUseNoTexture();
  4764. #define _RSLICES 16
  4765. real v[_RSLICES*4]; int idx[_RSLICES*2+2]; real r=LA_RH2/TNS_MAX2(uild->WiresContainer->Scale,1);
  4766. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4767. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4768. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4769. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4770. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4771. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4772. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4773. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4774. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4775. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4776. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4777. }
  4778. if(MAIN.tNodeIn->Source){
  4779. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4780. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4781. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4782. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4783. tnsMakeRing2d(v,idx,_RSLICES, inx, iny, r, r*0.6);
  4784. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4785. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4786. tnsMakeRing2d(v,idx,_RSLICES, outx, outy, r, r*0.6);
  4787. tnsVertexArray2d(v,_RSLICES*2); tnsIndexArray(idx, _RSLICES*2+2);
  4788. tnsColor4d(LA_COLOR3(&MAIN.WireColorCache[cid]),1); tnsPackAs(GL_TRIANGLE_STRIP);
  4789. }
  4790. #undef _RSLICES
  4791. tnsFlush();
  4792. int ww=MAIN.WireThickness*TNS_MIN2(uild->WiresContainer->Scale,1);
  4793. glLineWidth(ww);
  4794. for(laSocketRecord*sr=uild->SocketRecord.pFirst;sr;sr=sr->Item.pNext){
  4795. int cid=sr->In->ColorId%MAIN.WireColorSlices*4;
  4796. int inx=sr->In->RuntimeX+sr->In->RuntimePX, iny=sr->In->RuntimeY+sr->In->RuntimePY;
  4797. int outx=sr->Out->RuntimeX+sr->Out->RuntimePX, outy=sr->Out->RuntimeY+sr->Out->RuntimePY;
  4798. if(sr->Out==MAIN.tNodeOut){ outx=inx+MAIN.tNodeOut->RuntimeX+MAIN.tNodeOut->RuntimePX; outy=iny+MAIN.tNodeOut->RuntimeY+MAIN.tNodeOut->RuntimePY; }
  4799. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4800. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4801. }
  4802. if(MAIN.tNodeIn->Source){
  4803. laNodeInSocket* ins=MAIN.tNodeIn; laNodeOutSocket* outs=ins->Source;
  4804. int cid=ins->ColorId%MAIN.WireColorSlices*4;
  4805. int outx=outs->RuntimeX+outs->RuntimePX, outy=outs->RuntimeY+outs->RuntimePY;
  4806. int inx=ins->RuntimeX+ins->RuntimePX+outx, iny=ins->RuntimeY+ins->RuntimePY+outy;
  4807. la_SendWireVerts(inx, iny, outx, outy, r*0.9);
  4808. tnsColor4dv(&MAIN.WireColorCache[cid]); tnsPackAs(GL_LINE_STRIP);
  4809. }
  4810. tnsFlush();
  4811. glLineWidth(1);
  4812. la_InitSocketRecord(uild,0);
  4813. }
  4814. void la_SwitchThemeQuick(laTheme* t, laTheme* DefaultTheme){
  4815. if(!DefaultTheme){return;} MAIN.CurrentTheme = t?t:DefaultTheme; t=MAIN.CurrentTheme;
  4816. for(laBoxedTheme* bt = t->BoxedThemes.pFirst;bt;bt=bt->Item.pNext){ (*bt->BackRef) = bt; }
  4817. }
  4818. 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){
  4819. laUiItem *ui;
  4820. laBoxedTheme *bt;
  4821. laUiList *sub;
  4822. laUiListDrawItem *uildi;
  4823. int Ret = 0;
  4824. if (!uil) return 0;
  4825. //printf("d %d\n",MAIN.CurrentPanel->FrameDistinguish);
  4826. ui = uil->UiItems.pFirst;
  4827. if(uil->PanY<0){uil->PanY=0;}
  4828. if (!la_SetUpUiListMatrix(uild, uil, L, R, LimH, B - U, GlobalX, GlobalY)) return 0;
  4829. uil->SaveScale=MAIN.UiScale;
  4830. MAIN.UiScale*=uil->Scale;
  4831. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4832. for (; ui;){
  4833. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4834. if (ui->Type == &_LA_UI_CONDITION){
  4835. laConditionUiExtraData *cued = ui->Extra;
  4836. la_StepExpression(cued->Expression);
  4837. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4838. if (!cued->IsTrue){
  4839. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4840. }else{
  4841. ui = ui->Item.pNext;
  4842. }
  4843. continue;
  4844. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4845. ui = ui->Item.pNext;
  4846. continue;
  4847. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  4848. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  4849. if (cued->IsTrue) ui = cued->EndUi;
  4850. else
  4851. ui = ui->Item.pNext;
  4852. continue;
  4853. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  4854. laConditionUiExtraData *cued = ui->Extra;
  4855. ui->Type->Draw(ui, LA_RH);
  4856. if (ui->State == LA_UI_NORMAL){
  4857. cued->IsTrue = 0;
  4858. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4859. }else{
  4860. cued->IsTrue = 1;
  4861. ui = ui->Item.pNext;
  4862. }
  4863. continue;
  4864. }
  4865. if (ui->AnimationDistinguish != MAIN.CurrentPanel->FrameDistinguish) Ret = 1;
  4866. int NeedDraw=0;
  4867. if (la_UiInBoundEx(ui, uild)){ NeedDraw=1; }
  4868. if(NeedDraw){
  4869. if (!ui->Type->Draw){ la_DrawUiItem(ui); tnsFlush();
  4870. }else{ ui->Type->Draw(ui, LA_RH); }
  4871. if (ui->Type->Tag & LA_UI_TAG_IS_OFFSCREEN){
  4872. tnsFlush();
  4873. tnsDrawToOffscreen(MAIN.CurrentPanel->OffScr, 1, 0);
  4874. tnsResetViewMatrix();
  4875. }
  4876. if (ui->Type->Tag & (LA_UI_TAG_NEED_REBUILD)){
  4877. la_RebuildCurrentUiListMatrix(uild, uil, LimH, B - U);
  4878. if (ui->CanvasTemplate->SecondDraw) ui->CanvasTemplate->SecondDraw(ui, LA_RH);
  4879. tnsFlush();
  4880. }
  4881. }
  4882. if(NeedDraw || RegisterNodes){
  4883. if (RegisterNodes && ui->Type==_LA_UI_NODE_SOCKET){ la_RecordSocket(uild,uil,ui); }
  4884. if (ui->Type == _LA_UI_FIXED_GROUP ||
  4885. ui->Type == _LA_UI_TAB ||
  4886. ui->Type == _LA_UI_COLLECTION_SINGLE ||
  4887. ui->Type == _LA_UI_COLLECTION_SELECTOR && (ui->Subs.pFirst || ui->Page)){
  4888. if (!ui->Page){ ui = ui->Item.pNext; continue; }
  4889. tnsFlush(); int DoNodes=RegisterNodes; int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4890. if(ui->Flags&LA_UI_FLAGS_NODE_CONTAINER){ la_InitSocketRecord(uild, ui->Page); DoNodes=1; }
  4891. Ret += la_DrawUiListRecursive(uild, ui->Page, ui->L+(NoDecal?0:bt->LM), ui->R-(NoDecal?0:bt->RM), U, B,
  4892. (ui->Page->HeightCoeff ? ui->B - ui->Page->U : 10000) -(NoDecal?0:bt->LM), ConditionStackLevel, GlobalX, GlobalY, DoNodes);
  4893. if (ui->Page->ScrollerShownH){ la_DrawUiListScrollerH(ui->Page, ui->Page->PanX,
  4894. 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); }
  4895. if (ui->Page->HeightCoeff) la_DrawUiListScrollerV(ui->Page, ui->Page->PanY,
  4896. 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);
  4897. 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)); }
  4898. }elif (ui->Type == _LA_UI_COLLECTION){
  4899. int CanGetState = laCanGetState(ui->PP.LastPs->p);
  4900. int CanGetTheme = laCanGetTheme(ui->PP.LastPs->p);laTheme* OriginalTheme=MAIN.CurrentTheme;
  4901. void *Active = laGetActiveInstanceStrict(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance);
  4902. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4903. int State;
  4904. ui->PP.EndInstance = sub->Instance;
  4905. if ((!la_UiListInBoundEx(sub, uild)) && (!RegisterNodes)) continue;
  4906. if(!(ui->Flags&LA_UI_COLLECTION_NO_HIGHLIGHT) && NeedDraw){
  4907. if (CanGetState){
  4908. State = laGetUiState(ui->PP.LastPs->p, sub->Instance);
  4909. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP);
  4910. }elif (sub->Instance == Active){
  4911. la_DrawInstanceBkg(sub, laAccentColor(LA_BT_NORMAL),bt->LP,bt->RP);
  4912. }
  4913. }
  4914. if(sub->TabName && sub->TabName->Ptr){
  4915. int NoDecal=ui->Flags&LA_UI_FLAGS_NO_DECAL;
  4916. int NoGap=ui->Flags&LA_UI_FLAGS_NO_GAP;
  4917. tnsDrawStringAuto(transLate(sub->TabName->Ptr),laThemeColor(bt,LA_BT_DISABLED|LA_BT_TEXT),
  4918. ui->L+(NoDecal?0:bt->LM)+(NoGap?0:bt->LP),ui->R,sub->U-LA_RH,LA_TEXT_MONO);
  4919. tnsFlush();
  4920. }
  4921. if(CanGetTheme){
  4922. laTheme* t=laGetUiTheme(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, ui->PP.EndInstance);
  4923. la_SwitchThemeQuick(t, OriginalTheme);
  4924. if(t) la_DrawInstanceBkg(sub, laThemeColor(_LA_THEME_FLOATING_PANEL ,LA_BT_NORMAL),bt->LP,bt->RP);
  4925. }
  4926. tnsFlush();
  4927. Ret += la_DrawUiListRecursive(uild, sub, L, R, U, B, 10000, ConditionStackLevel, GlobalX, GlobalY, RegisterNodes);
  4928. if(CanGetTheme){ la_SwitchThemeQuick(0, OriginalTheme); }
  4929. }
  4930. ui->PP.EndInstance = Active;
  4931. }elif (ui->Type == _LA_UI_CANVAS){
  4932. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  4933. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  4934. tnsFlush();
  4935. 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);
  4936. }
  4937. }
  4938. }
  4939. ui = ui->Item.pNext;
  4940. }else{
  4941. ui = ui->Item.pNext;
  4942. }
  4943. }
  4944. tnsFlush();
  4945. if(uild->WiresContainer == uil){ la_DrawNodeWires(uild); }
  4946. la_RestoreLastUiListMatrix(uild, B - U);
  4947. MAIN.UiScale=uil->SaveScale;
  4948. MAIN.ScaledUiRowHeight=MAIN.UiRowHeight*MAIN.UiScale;
  4949. return Ret;
  4950. }
  4951. int la_DrawPanelScrollBarV(int L, int R, int U, int B, real Total, real Range, real Offset){
  4952. int Begin = U + (int)(Offset / Total * (real)(B - U)) + 3;
  4953. int End = Begin + (int)(Range / Total * (real)(B - U)) - 3;
  4954. tnsUseNoTexture();
  4955. tnsColor4d(1, 1, 1, 1);
  4956. tnsVertex2d(L, U);
  4957. tnsVertex2d(R, U);
  4958. tnsVertex2d(R, B);
  4959. tnsVertex2d(L, B);
  4960. tnsPackAs(GL_LINE_LOOP);
  4961. tnsVertex2d(L + 3, Begin);
  4962. tnsVertex2d(R - 3, Begin);
  4963. tnsVertex2d(R - 3, End);
  4964. tnsVertex2d(L + 3, End);
  4965. tnsPackAs(GL_LINE_LOOP);
  4966. }
  4967. int laIsInUiItem(laUiItem *ui, int x, int y){
  4968. if (x < ui->L || x > ui->R || y < ui->U || y > ui->B) return 0;
  4969. return 1;
  4970. }
  4971. int laIsInBound(int x, int y, int l, int r, int u, int b){
  4972. if (x < l || x > r || y < u || y > b) return 0;
  4973. return 1;
  4974. }
  4975. laColumn *la_DetectSplit(laColumn *Root, int LocalX);
  4976. laUiItem *la_DetectUiItemRecursive(laUiList *uil, int x, int y, int LimB, laListHandle *LocalBuf, int Deep){
  4977. laUiItem *ui, *tui;
  4978. laBoxedTheme *bt;
  4979. laUiList *sub;
  4980. int CPB = 0;
  4981. if (!uil || (LimB && y > LimB)) return 0;
  4982. x += uil->PanX;
  4983. y += uil->PanY;
  4984. for (ui = uil->UiItems.pFirst; ui;){
  4985. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  4986. if (ui->Type == &_LA_UI_CONDITION){
  4987. laConditionUiExtraData *cued = ui->Extra;
  4988. //la_StepExpression(cued->Expression); for some reason we can't step here, only step in update :thinking:
  4989. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  4990. if (!cued->IsTrue){
  4991. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  4992. }else{
  4993. ui = ui->Item.pNext;
  4994. }
  4995. continue;
  4996. }else if (ui->Type == &_LA_UI_CONDITION_END){
  4997. ui = ui->Item.pNext;
  4998. continue;
  4999. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5000. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5001. if (cued->IsTrue) ui = cued->EndUi;
  5002. else
  5003. ui = ui->Item.pNext;
  5004. continue;
  5005. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5006. laConditionUiExtraData *cued = ui->Extra;
  5007. if (laIsInUiItem(ui, x, y)){
  5008. lstAppendPointer(LocalBuf, uil);
  5009. return ui;
  5010. }
  5011. if (ui->State == LA_UI_NORMAL){
  5012. cued->IsTrue = 0;
  5013. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5014. }else{
  5015. cued->IsTrue = 1;
  5016. ui = ui->Item.pNext;
  5017. }
  5018. continue;
  5019. }
  5020. //printf("%s > ",ui->Type->Identifier?ui->Type->Identifier:"-");
  5021. if (ui->Type != _LA_UI_COLLECTION && ui->Type != _LA_UI_COLLECTION_SINGLE &&
  5022. ui->Type != _LA_UI_FIXED_GROUP && ui->Type != _LA_UI_TAB && ui->Type != _LA_UI_CANVAS && laIsInUiItem(ui, x, y)){
  5023. int Add=1; if(ui->Type==_LA_UI_COLUMN_ADJUSTER){
  5024. if(!la_DetectSplit(ui->C, x)) Add=0;
  5025. }
  5026. if(Add){ lstAppendPointer(LocalBuf, uil); return ui; }
  5027. }
  5028. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5029. if (ui->Page->HeightCoeff) CPB = ui->B;
  5030. else CPB = ui->Page->B;
  5031. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5032. if (tui = la_DetectUiItemRecursive(ui->Page, x /* + ui->Page->PanX*/, y /*+ ui->Page->PanY*/, CPB, LocalBuf, Deep)){
  5033. lstAppendPointer(LocalBuf, uil);
  5034. return tui;
  5035. }
  5036. }else if (laIsInUiItem(ui, x, y)){
  5037. lstAppendPointer(LocalBuf, uil);return ui;
  5038. }
  5039. }
  5040. if (ui->Type == _LA_UI_COLLECTION || ui->Type==_LA_UI_COLLECTION_SINGLE){
  5041. if (laIsInUiItem(ui, x, y)){
  5042. lstAppendPointer(LocalBuf, uil);
  5043. if (ui->Subs.pFirst) ((laUiList *)ui->Subs.pFirst)->HeightCoeff = LimB;
  5044. if(Deep){
  5045. for(laUiList* iuil=ui->Subs.pFirst;iuil;iuil=iuil->Item.pNext){
  5046. if (laIsInBound(x, y, iuil->L, iuil->R, iuil->U, iuil->B)){
  5047. if (tui = la_DetectUiItemRecursive(iuil, x , y , iuil->B, LocalBuf, Deep)){
  5048. lstAppendPointer(LocalBuf, iuil);
  5049. return tui;
  5050. }
  5051. }
  5052. }
  5053. }
  5054. return ui;
  5055. }
  5056. }
  5057. if (ui->Type == _LA_UI_CANVAS){
  5058. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5059. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5060. if (tui = la_DetectUiItemRecursive(sub, x, y, ui->B, LocalBuf, Deep)){
  5061. lstAppendPointer(LocalBuf, uil);
  5062. return tui;
  5063. }
  5064. }
  5065. }
  5066. if (laIsInUiItem(ui, x, y)){
  5067. lstAppendPointer(LocalBuf, uil);
  5068. return ui;
  5069. }
  5070. }
  5071. ui = ui->Item.pNext;
  5072. }
  5073. return 0;
  5074. }
  5075. laUiItem *la_DetectSocketRecursive(laUiList* uil, int x, int y, int LimB, laPropContainer* PCInOrOut){
  5076. laListHandle Locals={0};
  5077. laUiItem* ui=la_DetectUiItemRecursive(uil, x,y,LimB,&Locals, 1);
  5078. while(lstPopPointer(&Locals));
  5079. printf("%s\n", ui?ui->Type->Identifier:"?");
  5080. if(ui && ui->Type==_LA_UI_NODE_SOCKET){
  5081. laProp* p=ui->PP.LastPs->p; laPropContainer* pc=la_EnsureSubTarget(p,0);
  5082. if(pc==PCInOrOut) return ui;
  5083. }
  5084. return 0;
  5085. }
  5086. laUiList *la_DetectUiListRecursive(laUiList *uil, int x, int y, int LimH,
  5087. laUiItem **ParentUi, laUiList **ScrollUil, laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception){
  5088. laUiItem *ui = uil->UiItems.pFirst;
  5089. laBoxedTheme *bt;
  5090. laUiList *tuil;
  5091. laUiList *sub;
  5092. int CPB = 0;
  5093. x += uil->PanX;
  5094. y += uil->PanY;
  5095. if (y > LimH) return uil;
  5096. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5097. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5098. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5099. return uil;
  5100. }
  5101. for (ui = uil->UiItems.pFirst; ui;){
  5102. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5103. if (ui->Type == &_LA_UI_CONDITION){
  5104. laConditionUiExtraData *cued = ui->Extra;
  5105. //la_StepExpression(cued->Expression);
  5106. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5107. if (!cued->IsTrue){
  5108. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5109. }else{
  5110. ui = ui->Item.pNext;
  5111. }
  5112. continue;
  5113. }
  5114. if (ui->Type == &_LA_UI_CONDITION_END){
  5115. ui = ui->Item.pNext;
  5116. continue;
  5117. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5118. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5119. if (cued->IsTrue) ui = cued->EndUi;
  5120. else
  5121. ui = ui->Item.pNext;
  5122. continue;
  5123. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5124. laConditionUiExtraData *cued = ui->Extra;
  5125. if (ui->State == LA_UI_NORMAL){
  5126. cued->IsTrue = 0;
  5127. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5128. }else{
  5129. cued->IsTrue = 1;
  5130. ui = ui->Item.pNext;
  5131. }
  5132. continue;
  5133. }
  5134. if (InToContainerUI && ui != Exception){
  5135. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5136. if (ContainerParent) (*ContainerParent) = uil;
  5137. if (ParentUi) *ParentUi = ui;
  5138. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5139. //if (y > LimH) return uil;
  5140. 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))){
  5141. return tuil;
  5142. }
  5143. }
  5144. }
  5145. }
  5146. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5147. if (ui->Page->HeightCoeff) CPB = ui->B;
  5148. else CPB = ui->Page->B;
  5149. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5150. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5151. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5152. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui;
  5153. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5154. if (ParentUi) *ParentUi = ui;
  5155. if (tuil = la_DetectUiListRecursive(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception)) return tuil;
  5156. }
  5157. }
  5158. ui = ui->Item.pNext;
  5159. }
  5160. return uil;
  5161. }
  5162. laUiList *la_DetectUiListRecursiveDeep(laUiList *uil, int x, int y, int LimH, laUiItem **ParentUi, laUiList **ScrollUil,
  5163. laUiList **ContainerParent, int InToContainerUI, laUiItem *Exception, laListHandle* levels){
  5164. laUiItem *ui = uil->UiItems.pFirst;
  5165. laBoxedTheme *bt;
  5166. laUiList *tuil;
  5167. laUiList *sub;
  5168. int CPB = 0;
  5169. laUiListRecord* uilr=lstAppendPointerSized(levels, uil, sizeof(laUiListRecord));
  5170. x += uil->PanX;
  5171. y += uil->PanY;
  5172. if (y > LimH) return uil;
  5173. if (/*uil->ScrollerShownV && */ laIsInBound(x, y, uil->R, uil->R+LA_SCROLL_W+4, uil->U, uil->B) ||
  5174. /*uil->ScrollerShownH && */ laIsInBound(x, y, uil->L, uil->R, uil->B, uil->B+LA_SCROLL_W+4)){
  5175. if (ScrollUil) *ScrollUil = uil; /* if (ParentUi)*ParentUi = uil;*/
  5176. return uil;
  5177. }
  5178. for (ui = uil->UiItems.pFirst; ui;){
  5179. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5180. if (ui->Type == &_LA_UI_CONDITION){
  5181. laConditionUiExtraData *cued = ui->Extra;
  5182. //la_StepExpression(cued->Expression);
  5183. cued->IsTrue = la_DoSingleExpression(cued->Expression);
  5184. if (!cued->IsTrue){
  5185. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5186. }else{
  5187. ui = ui->Item.pNext;
  5188. }
  5189. continue;
  5190. }
  5191. if (ui->Type == &_LA_UI_CONDITION_END){
  5192. ui = ui->Item.pNext;
  5193. continue;
  5194. }else if (ui->Type == &_LA_UI_CONDITION_ELSE){
  5195. laConditionUiExtraData *cued = ((laConditionUiExtraData *)ui->Extra)->EndUi->Extra;
  5196. if (cued->IsTrue) ui = cued->EndUi;
  5197. else
  5198. ui = ui->Item.pNext;
  5199. continue;
  5200. }else if (ui->Type == _LA_UI_CONDITION_TOGGLE){
  5201. laConditionUiExtraData *cued = ui->Extra;
  5202. if (ui->State == LA_UI_NORMAL){
  5203. cued->IsTrue = 0;
  5204. ui = cued->ElseUi ? cued->ElseUi : cued->EndUi;
  5205. }else{
  5206. cued->IsTrue = 1;
  5207. ui = ui->Item.pNext;
  5208. }
  5209. continue;
  5210. }
  5211. if (InToContainerUI && ui != Exception){
  5212. if (ui->Type == _LA_UI_CANVAS && !(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  5213. if (ContainerParent) (*ContainerParent) = uil;
  5214. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5215. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5216. //if (y > LimH) return uil;
  5217. 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))){
  5218. return tuil;
  5219. }
  5220. }
  5221. }
  5222. }
  5223. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5224. if (ui->Page->HeightCoeff) CPB = ui->B;
  5225. else CPB = ui->Page->B;
  5226. if (ui->Page->ScrollerShownV && laIsInBound(x, y, ui->R - LA_SCROLL_W - bt->RP*2, ui->R, ui->Page->U, CPB)){
  5227. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5228. }elif (ui->Page->ScrollerShownH && laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->B - LA_SCROLL_W - bt->BP*2, ui->B)){
  5229. if (ScrollUil) *ScrollUil = ui->Page; if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5230. }elif (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5231. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5232. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5233. }
  5234. }
  5235. if ((ui->PP.LastPs && ui->PP.LastPs->p->PropertyType == LA_PROP_SUB) && (ui->Subs.pFirst || ui->Page)){
  5236. if (ui->Page->HeightCoeff) CPB = ui->B;
  5237. else
  5238. CPB = ui->Page->B;
  5239. if (laIsInBound(x, y, ui->Page->R, ui->Page->R + LA_SCROLL_W + bt->RM, ui->Page->U, CPB)){
  5240. if (ScrollUil) *ScrollUil = ui->Page;
  5241. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5242. }
  5243. if (laIsInBound(x, y, ui->Page->L, ui->Page->R, ui->Page->U, CPB)){
  5244. if (ParentUi) *ParentUi = ui; uilr->pui=ui;
  5245. if (tuil = la_DetectUiListRecursiveDeep(ui->Page, x, y, CPB, ParentUi, ScrollUil, ContainerParent, InToContainerUI, Exception, levels)) return tuil;
  5246. }
  5247. }
  5248. ui = ui->Item.pNext;
  5249. }
  5250. return uil;
  5251. }
  5252. int la_TestUiListMinumWidth(laUiList *uil){
  5253. laUiItem *ui, *tui;
  5254. laBoxedTheme *bt;
  5255. laUiList *sub;
  5256. int CPB = 0;
  5257. int W = 0;
  5258. int tW, sW, RowMode=0, rW;
  5259. void *Restore;
  5260. for (ui = uil->UiItems.pFirst; ui;){
  5261. bt = ui->Type->Theme ? (*ui->Type->Theme) : 0;
  5262. if ((ui->Type == _LA_UI_FIXED_GROUP || ui->Type == _LA_UI_TAB) && (ui->Subs.pFirst || ui->Page)){
  5263. tW = la_TestUiListMinumWidth(ui->Page) + bt->LP + bt->RP;
  5264. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5265. if (W < tW) W = tW;
  5266. }elif (ui->Type == _LA_UI_COLLECTION){
  5267. Restore = ui->PP.EndInstance;
  5268. tW = 0; sW = 0;
  5269. for (sub = ui->Subs.pFirst; sub; sub = sub->Item.pNext){
  5270. ui->PP.EndInstance = sub->Instance;
  5271. sW = la_TestUiListMinumWidth(sub) + bt->LP + bt->RP;
  5272. if (sW > tW) tW = sW;
  5273. }
  5274. ui->PP.EndInstance = Restore;
  5275. tW = (int)((float)tW / ui->C->PreWidth + 2);
  5276. tW *= (ui->SymbolID > 0 ? ui->SymbolID : 1);
  5277. if (W < tW) W = tW;
  5278. }elif (ui->Type==&_LA_UI_ROW_BEGIN){
  5279. RowMode=1; rW=0;
  5280. }elif (ui->Type==&_LA_UI_ROW_END){
  5281. RowMode=0; rW=(int)((float)rW / ui->C->PreWidth + 2); if (W < rW) W = rW;
  5282. }elif (ui->Type->GetMinWidth){
  5283. tW = ui->Type->GetMinWidth(ui) + bt->LP + bt->RP;
  5284. if(RowMode){ rW+=tW; }else{ tW = (int)((float)tW / ui->C->PreWidth + 2); if (W < tW) W = tW; }
  5285. }
  5286. ui = ui->Item.pNext;
  5287. }
  5288. return W;
  5289. }
  5290. void la_InitLLVM(){
  5291. //LLVMLinkInMCJIT();
  5292. //LLVMInitializeNativeTarget();
  5293. //LLVMInitializeNativeAsmPrinter();
  5294. //LLVMInitializeNativeAsmParser();
  5295. // MAIN.llvmContext = LLVMGetGlobalContext();
  5296. //MAIN.llvmModule = LLVMModuleCreateWithNameInContext(LA_NODE_MAIN_MODULE_NAME, MAIN.llvmContext);
  5297. }
  5298. //==================================================================================================
  5299. void la_FreeKeyMapItem(laKeyMapItem* kmi){
  5300. if(kmi->Instructions) strSafeDestroy(&kmi->Instructions);
  5301. if(kmi->Operation) strSafeDestroy(&kmi->Operation);
  5302. if(kmi->Action.Go) la_FreePropStepCache(kmi->Action.Go);
  5303. if(kmi->Base.Go) la_FreePropStepCache(kmi->Action.Go);
  5304. memFree(kmi);
  5305. }
  5306. laKeyMapItem *laAssignNewKey(laKeyMapper *km, char *Path, char *Operation, char SelectBase, int SpecialKeyBits, int EventType, int Key, char *ExtraInstructions){
  5307. laKeyMapItem *kmi;
  5308. if (!km) return 0;
  5309. kmi = memAcquire(sizeof(laKeyMapItem));
  5310. if (la_GetPropFromPath(&kmi->Base, 0, Path, 0)){
  5311. la_GetPropFromPath(&kmi->Action, &kmi->Base, Operation, 0);
  5312. }else{
  5313. strSafeSet(&kmi->Operation, Operation);
  5314. }
  5315. strSafeSet(&kmi->Instructions, ExtraInstructions);
  5316. kmi->SpecialKeyBits = SpecialKeyBits;
  5317. kmi->EventType = EventType;
  5318. kmi->Key = Key;
  5319. kmi->SelectBase = SelectBase;
  5320. lstAppendItem(&km->Items, kmi);
  5321. return kmi;
  5322. }
  5323. int laKeyMapExecuteEvent(laOperator *from, laKeyMapper *km, laEvent *e){
  5324. laKeyMapItem *kmi; int inv=0;
  5325. char *instructions;
  5326. if(e->Type==LA_MOUSEMOVE) return 0;
  5327. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5328. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5329. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5330. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5331. if (kmi->Operation)
  5332. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5333. else
  5334. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5335. inv = 1;
  5336. }
  5337. }
  5338. return inv;
  5339. }
  5340. int laKeyMapExecuteEventEx(laOperator *from, laPropPack *UiExtra, laKeyMapper *km, laEvent *e){
  5341. laKeyMapItem *kmi;
  5342. char *instructions;
  5343. int inv = 0; int lx = -1, ly = -1;
  5344. if(e->Type==LA_MOUSEMOVE) return 0;
  5345. for (kmi = km->Items.pFirst; kmi; kmi = kmi->Item.pNext){
  5346. if (kmi->SpecialKeyBits == e->SpecialKeyBit &&
  5347. kmi->EventType == e->Type && ((kmi->Key == e->Input) || (kmi->Key == e->key))){
  5348. if (e->Localized){
  5349. lx = e->x;
  5350. ly = e->y;
  5351. laLocalToWindow(from, MAIN.ToPanel, &e->x, &e->y);
  5352. e->Localized = 0;
  5353. }
  5354. instructions = kmi->Instructions ? kmi->Instructions->Ptr : 0;
  5355. if (kmi->SelectBase == LA_KM_SEL_UI_EXTRA){
  5356. laInvoke(from, kmi->Operation->Ptr, e, UiExtra, instructions, 0);
  5357. }elif (kmi->SelectBase == LA_KM_SEL_PANEL){
  5358. laInvoke(from, kmi->Operation->Ptr, e, &((laPanel *)MAIN.ToPanel)->PP, instructions, 0);
  5359. }elif (kmi->Operation){
  5360. laInvoke(from, kmi->Operation->Ptr, e, 0, instructions, 0);
  5361. }else{
  5362. laInvoke(from, ((laOperatorProp *)&kmi->Action.LastPs)->OperatorID, e, &kmi->Base, instructions, 0);
  5363. }
  5364. inv = 1;
  5365. if (lx >= 0){
  5366. e->x = lx;
  5367. e->y = ly;
  5368. e->Localized = 1;
  5369. }
  5370. }
  5371. }
  5372. return inv;
  5373. }
  5374. void la_DefaultOperatorParser(laStringSplitor *ss, char *IconID, char *DisplayString);
  5375. void la_DestroyOperatorType(laOperatorType* at){
  5376. //if(at->PC) la_FreePropertyContainer(at->PC);
  5377. memFree(at);
  5378. }
  5379. laOperatorType *laCreateOperatorType(const char *ID, const char *Name, const char *Description,
  5380. laCheckFunc Check, laInitFunc Init, laExitFunc Exit, laInvokeFunc Invoke, laModalFunc Modal,
  5381. uint32_t IconID, int ExtraMark){
  5382. laOperatorType *at = memAcquire(sizeof(laOperatorType));
  5383. at->Identifier = ID;
  5384. at->Name = Name;
  5385. at->Description = Description;
  5386. at->Check = Check;
  5387. at->Invoke = Invoke;
  5388. at->Init = Init;
  5389. at->Exit = Exit;
  5390. at->Modal = Modal;
  5391. at->IconID = IconID;
  5392. at->ExtraMark = ExtraMark;
  5393. at->ParseArgs = la_DefaultOperatorParser;
  5394. hsh256InsertItemCSTR(&MAIN.OperatorTypeHash, at, at->Identifier);
  5395. return at;
  5396. }
  5397. laPropContainer* laDefineOperatorProps(laOperatorType* ot, int HyperLevel){
  5398. ot->PC = memAcquire(sizeof(laPropContainer));
  5399. ot->PC->Identifier = ot->Identifier;
  5400. ot->PC->Hyper = HyperLevel;
  5401. return ot->PC;
  5402. }
  5403. laOperator *la_CreateOperator(laOperatorType *at){
  5404. laOperator *a = CreateNew(laOperator);
  5405. a->Type = at;
  5406. if (at->PC && at->PC->Props.pFirst){
  5407. a->PP.LastPs = memAcquireSimple(sizeof(laPropStep));
  5408. a->PP.LastPs->p = memAcquire(sizeof(laSubProp));
  5409. a->PP.LastPs->p->SubProp = at->PC;
  5410. a->PP.LastPs->p->PropertyType = LA_PROP_SUB;
  5411. a->PP.LastPs->p->Identifier = at->PC->Identifier;
  5412. a->PP.LastPs->Type = U'.';
  5413. }
  5414. return a;
  5415. }
  5416. int la_OperatorTypeByID(laOperatorType *a, char *id){
  5417. return (!strcmp(a->Identifier, id));
  5418. }
  5419. laOperatorType *laGetOperatorType(const char *ID){
  5420. return hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5421. }
  5422. int laOperatorExistsT(laOperatorType* at){
  5423. if (!at) return 0;
  5424. for (laOperator *a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (at == a->Type){ return 1; } }
  5425. return 0;
  5426. }
  5427. int laOperatorExists(const char* ID){
  5428. laOperatorType* at=laGetOperatorType(ID); if (!at) return 0;
  5429. return laOperatorExistsT(at);
  5430. }
  5431. int la_OperatorExists(laOperator *ac){
  5432. if (!ac) return 0;
  5433. laOperator *a;
  5434. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){ if (ac == a){return 1;}}
  5435. return 0;
  5436. }
  5437. int la_UiOperatorExists(void *inst){
  5438. laOperator *a;
  5439. if (!inst) return 0;
  5440. for (a = MAIN.CurrentWindow->Operators.pFirst; a; a = a->Item.pNext){
  5441. if (((laUiItem *)a->Instance) == inst){
  5442. return 1;
  5443. }
  5444. }
  5445. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5446. if (a->Instance == inst){
  5447. return 1;
  5448. }
  5449. }
  5450. return 0;
  5451. }
  5452. int la_OperatorPending(laOperator *target){
  5453. laOperator *a;
  5454. if (!target) return 0;
  5455. for (a = MAIN.CurrentWindow->PendingOperators.pFirst; a; a = a->Item.pNext){
  5456. if (a == target){
  5457. return 1;
  5458. }
  5459. }
  5460. return 0;
  5461. }
  5462. void laSetOperatorLocalizer(void *ToPanel){
  5463. MAIN.ToPanel = ToPanel;
  5464. }
  5465. void la_DestroyConfirmData(laConfirmData **cd);
  5466. void *la_DestroyOperator(laOperator **a, laListHandle *Operators, int OnlyThisOne){
  5467. laOperator *ai = (*a);
  5468. laOperator *ac = ((*a)->Child);
  5469. void *Ret = 0;
  5470. if (!OnlyThisOne && ac && la_OperatorExists(ac) && !ac->Using){
  5471. la_DestroyOperator(&ac, Operators, OnlyThisOne);
  5472. }
  5473. if ((*a)->ConfirmData) la_DestroyConfirmData(&((*a)->ConfirmData));
  5474. if ((*a)->PP.LastPs){
  5475. memFree((*a)->PP.LastPs->p);
  5476. memFree((*a)->PP.LastPs);
  5477. }
  5478. if (laNonFixedPanelExists((*a)->OperatorPanel)){
  5479. la_SetPropMathcerContext((*a)->OperatorPanel);
  5480. MAIN.CurrentPanel = (*a)->OperatorPanel;
  5481. laDestroySinglePanel((*a)->OperatorPanel,0);
  5482. }
  5483. if ((*a)->CreatedThis) memFree((*a)->CreatedThis);
  5484. if ((*a)->ExtraInstructionsP) strDestroyStringSplitor(&(*a)->ExtraInstructionsP);
  5485. lstClearPointer(&(*a)->LocalUiLists);
  5486. if (Operators){
  5487. Ret = ai->Item.pNext;
  5488. if (la_OperatorPending((*a) /*->Instance*/)) lstRemoveItem(&MAIN.CurrentWindow->PendingOperators, *a);
  5489. else
  5490. lstRemoveItem(Operators, *a);
  5491. for (ai = Operators->pFirst; ai; ai = ai->Item.pNext){
  5492. if (ai->Child == (*a)) ai->Child = 0;
  5493. }
  5494. }
  5495. strSafeDestroy(&(*a)->RuntimeHint);
  5496. free(*a);
  5497. return Ret;
  5498. }
  5499. int laOperatorAvailable(char *ID, laPropPack *This, laStringSplitor *Instructions){
  5500. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5501. if (!at) return 0;
  5502. if (!at->Check) return 1;
  5503. return (at->Check(This, Instructions));
  5504. }
  5505. int laOperatorAvailableP(laOperatorType *at, laPropPack *This, laStringSplitor *Instructions){
  5506. if (!at) return 0;
  5507. if (!at->Check) return 1;
  5508. return (at->Check(This, Instructions));
  5509. }
  5510. int laOperatorAvailablePSafe(laOperatorType *at, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5511. laPropPack FakePP = {0};
  5512. laPropStep FakePs = {0};
  5513. if (!at) return 0;
  5514. if (!at->Check) return 1;
  5515. FakePP.LastPs = &FakePs;
  5516. FakePP.Go = FakePP.LastPs;
  5517. FakePP.LastPs->p = This->LastPs->p;
  5518. FakePP.LastPs->UseInstance = This->EndInstance;
  5519. FakePP.EndInstance = Real_FromInstance;
  5520. FakePP.LastIndex = This->LastIndex;
  5521. return (at->Check(&FakePP, Instructions));
  5522. }
  5523. int laOperatorAvailableSafe(char *ID, laPropPack *This, void *Real_FromInstance, laStringSplitor *Instructions){
  5524. laOperatorType *at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5525. return laOperatorAvailablePSafe(at, This, Real_FromInstance, Instructions);
  5526. }
  5527. int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This, char *args, char *args2){
  5528. laOperator *a, *f = From;
  5529. int rev;
  5530. if (!f && e&&e->Localized) return -1;
  5531. a = la_CreateOperator(at);
  5532. a->ToPanel = MAIN.ToPanel;
  5533. a->This = This;
  5534. a->ExtraInstructions = args;
  5535. strMakeInstructions(&a->ExtraInstructionsP, args);
  5536. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5537. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5538. if (!laOperatorAvailableP(at, This, a->ExtraInstructionsP)){
  5539. la_DestroyOperator(&a, 0, 0);
  5540. return LA_CANCELED;
  5541. }
  5542. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5543. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL){
  5544. laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5545. e->Localized = 1;
  5546. }
  5547. if (e&&e->Localized){
  5548. if (!at->ExtraMark & LA_EXTRA_TO_PANEL){
  5549. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5550. e->Localized = 0;
  5551. }else{
  5552. laLocalToWindow(f, f->ToPanel, &e->x, &e->y);
  5553. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  5554. }
  5555. }
  5556. if (From) f->Child = a;
  5557. a->Using = 1;
  5558. if (at->Init) at->Init(a);
  5559. rev = at->Invoke(a, e);
  5560. a->Using = 0;
  5561. if (rev & LA_FINISH){
  5562. a->StopNow = 1; if(From)From->Child=0;
  5563. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5564. }
  5565. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5566. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5567. a->State = rev;
  5568. a->PP.EndInstance = a->CustomData;
  5569. if (a->PP.LastPs) a->PP.LastPs->Type = U'.';
  5570. }else
  5571. la_DestroyOperator(&a, 0, 0);
  5572. return rev;
  5573. }
  5574. int laInvoke(laOperator *From, char *ID, laEvent *e, laPropPack *This, char *args, char *args2){
  5575. laOperatorType *at; laOperator *a, *f = From;
  5576. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID);
  5577. if (!at) return -1;
  5578. return laInvokeP(From,at,e,This,args,args2);
  5579. }
  5580. int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *OrigionalThis, void *FromInstance, char *args, char *args2){
  5581. laOperator *a, *f = From;
  5582. int rev;
  5583. laPropPack *created;
  5584. if (!f && e&&e->Localized || !OrigionalThis || !OrigionalThis->LastPs) return -1;
  5585. created = memAcquireSimple(sizeof(laPropPack));
  5586. created->LastPs = memAcquireSimple(sizeof(laPropStep));
  5587. created->Go = created->LastPs;
  5588. created->LastPs->p = OrigionalThis->LastPs->p;
  5589. created->LastPs->UseInstance = FromInstance;
  5590. created->EndInstance = FromInstance;
  5591. created->LastIndex = OrigionalThis->LastIndex;
  5592. a = la_CreateOperator(at);
  5593. a->ToPanel = MAIN.ToPanel;
  5594. a->This = created;
  5595. a->CreatedThis = created;
  5596. a->ExtraInstructions = args;
  5597. strMakeInstructions(&a->ExtraInstructionsP, args);
  5598. strMakeInstructions(&a->ExtraInstructionsP, args2);
  5599. strMakeInstructions(&a->ExtraInstructionsP, at->ExtraInstructions);
  5600. if (!laOperatorAvailableP(at, created, a->ExtraInstructionsP)){
  5601. la_DestroyOperator(&a, 0, 0);
  5602. return LA_CANCELED;
  5603. }
  5604. lstGeneratePointerList(f ? &f->LocalUiLists : 0, 0, &a->LocalUiLists);
  5605. if (e&&!e->Localized && at->ExtraMark & LA_EXTRA_TO_PANEL) laWindowToLocal(0, a->ToPanel, &e->x, &e->y);
  5606. if (From) f->Child = a;
  5607. a->Using = 1;
  5608. if (at->Init) at->Init(a);
  5609. rev = at->Invoke(a, e);
  5610. a->Using = 0;
  5611. if (rev & LA_FINISH){
  5612. a->StopNow = 1; if(From)From->Child=0;
  5613. laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
  5614. }
  5615. if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
  5616. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5617. a->State = rev;
  5618. a->PP.EndInstance = a->CustomData;
  5619. }else
  5620. la_DestroyOperator(&a, 0, 0);
  5621. return rev;
  5622. }
  5623. int laInvokeUiP(laOperator *From, laOperatorType *at, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5624. laOperator *a, *f = From;
  5625. int rev;
  5626. if (!at || (la_UiOperatorExists(inst))){ return -1; }
  5627. a = la_CreateOperator(at);
  5628. a->Instance = inst;
  5629. a->ToPanel = MAIN.ToPanel;
  5630. if (!IgnoreLocals) lstGeneratePointerList(f ? &f->LocalUiLists : 0, Locals, &a->LocalUiLists);
  5631. if (From) f->Child = a;
  5632. a->Using = 1;
  5633. if (at->Init) at->Init(a);
  5634. rev = at->Invoke(a, e);
  5635. a->Using = 0;
  5636. if (rev & LA_FINISH){
  5637. a->StopNow = 1; if(From)From->Child=0;
  5638. }
  5639. if (rev & LA_BLOCK){
  5640. lstAppendItem(&MAIN.CurrentWindow->PendingOperators, a);
  5641. a->State = rev;
  5642. }else la_DestroyOperator(&a, 0, 0);
  5643. DEB = a;
  5644. return rev;
  5645. }
  5646. int laInvokeUi(laOperator *From, char *ID, laEvent *e, void *inst, laListHandle *Locals, int IgnoreLocals){
  5647. laOperatorType *at;
  5648. laOperator *a, *f = From;
  5649. if (la_UiOperatorExists(inst)) return -1;
  5650. at = hsh256FindItemSTR(&MAIN.OperatorTypeHash, la_OperatorTypeByID, ID); if (!at) return -1;
  5651. return laInvokeUiP(From,at,e,inst,Locals,IgnoreLocals);
  5652. }
  5653. void laRequestDelayEvent(real Seconds){
  5654. MAIN.DelayTriggered=0; MAIN.DelayStart=MAIN.TimeAccum; MAIN.DelayTime = Seconds; }
  5655. int la_UiStillInService(void *UiInstance){
  5656. laOperator *ai, *dai; if(!MAIN.CurrentWindow) return 0;
  5657. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = ai->Item.pNext){
  5658. if (ai->Instance == UiInstance) return 1;
  5659. }
  5660. return 0;
  5661. }
  5662. void la_StopUiOperatorService(void *UiInstance){
  5663. laOperator *ai, *dai, *NextAi;
  5664. if (!MAIN.CurrentWindow) return;
  5665. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5666. NextAi = ai->Item.pNext;
  5667. if (ai->Instance == UiInstance){
  5668. if (ai->Child){
  5669. la_StopUiOperatorService(ai->Child->Instance);
  5670. ai->Child = 0;
  5671. }
  5672. laOperator *dai = ai;
  5673. la_DestroyOperator(&dai, &MAIN.CurrentWindow->PendingOperators, 1);
  5674. continue;
  5675. }
  5676. }
  5677. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5678. NextAi = ai->Item.pNext;
  5679. if (ai->Instance == UiInstance){
  5680. if (ai->Instance == ai->ToPanel){
  5681. //laHidePanelWithDissoveEffect(ai->ToPanel);
  5682. //ai->ToPanel->LaterDestroy = 1;
  5683. }
  5684. if (ai->Child && la_OperatorExists(ai->Child)){
  5685. la_StopUiOperatorService(ai->Child->Instance);
  5686. //ai->Child = 0;
  5687. }
  5688. if (!ai->Using){
  5689. laOperator *dai = ai;
  5690. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5691. }else
  5692. ai->StopNow = 1;
  5693. }
  5694. }
  5695. }
  5696. void la_StopAllOperators(){
  5697. laOperator *ai, *dai, *NextAi;
  5698. if (!MAIN.CurrentWindow) return;
  5699. for (ai = MAIN.CurrentWindow->PendingOperators.pFirst; ai; ai = NextAi){
  5700. NextAi = ai->Item.pNext;
  5701. NextAi = la_DestroyOperator(&ai, &MAIN.CurrentWindow->PendingOperators, 1);
  5702. continue;
  5703. }
  5704. for (ai = MAIN.CurrentWindow->Operators.pFirst; ai; ai = NextAi){
  5705. NextAi = ai->Item.pNext;
  5706. if (ai->ToPanel && ai->Instance == ai->ToPanel && !ai->ToPanel->IsMenuPanel){
  5707. laHidePanelWithDissoveEffect(ai->ToPanel);
  5708. ai->ToPanel->LaterDestroy = 1;
  5709. }
  5710. if (!ai->Using){
  5711. laOperator *dai = ai;
  5712. la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
  5713. }else ai->StopNow = 1;
  5714. }
  5715. }
  5716. void la_DestroyConfirmData(laConfirmData **cd){
  5717. if((!cd)||!(*cd)) return;
  5718. if ((*cd)->CustomData) (*cd)->Destroy((*cd)->CustomData);
  5719. if ((*cd)->StrData) free((*cd)->StrData);
  5720. FreeMem((*cd));
  5721. (*cd) = 0;
  5722. }
  5723. void laConfirmInt(laOperator *a, int Data, int mode){
  5724. laOperator *ai = a;
  5725. laConfirmData *cd = CreateNew(laConfirmData);
  5726. cd->IData = Data;
  5727. cd->Mode = mode;
  5728. ai->NextConfirmData = cd;
  5729. laRetriggerOperators();
  5730. }
  5731. void laConfirmFloat(laOperator *a, real Data, int mode){
  5732. laOperator *ai = a;
  5733. laConfirmData *cd = CreateNew(laConfirmData);
  5734. cd->FData = Data;
  5735. cd->Mode = mode;
  5736. ai->NextConfirmData = cd;
  5737. laRetriggerOperators();
  5738. }
  5739. void laConfirmString(laOperator *a, char *Str, int mode){
  5740. laOperator *ai = a;
  5741. laConfirmData *cd = CreateNew(laConfirmData);
  5742. int len = strlen(Str);
  5743. char *buf = calloc(len + 1, sizeof(char));
  5744. strcpy(buf, Str);
  5745. cd->StrData = buf;
  5746. cd->Mode = mode;
  5747. cd->Destroy = free;
  5748. ai->NextConfirmData = cd;
  5749. laRetriggerOperators();
  5750. }
  5751. int laConfirmSameDataIfAny(laOperator *a){
  5752. laOperator *ai = a;
  5753. laConfirmData *cd;
  5754. char *buf = 0;
  5755. if (!ai->ConfirmData || ai->NextConfirmData) return 0;
  5756. cd = CreateNew(laConfirmData);
  5757. if (ai->ConfirmData->StrData){
  5758. int len = strlen(ai->ConfirmData->StrData);
  5759. buf = calloc(len + 1, sizeof(char));
  5760. strcpy(buf, ai->ConfirmData->StrData);
  5761. }
  5762. //cd->CustomData = cd->CustomData;
  5763. cd->IData = ai->ConfirmData->IData;
  5764. cd->FData = ai->ConfirmData->FData;
  5765. cd->StrData = buf;
  5766. cd->Mode = ai->ConfirmData->Mode;
  5767. cd->Destroy = ai->ConfirmData->Destroy;
  5768. ai->NextConfirmData = cd;
  5769. laRetriggerOperators();
  5770. return 1;
  5771. }
  5772. void laConfirmUserData(laOperator *a, void *UserData, laConfirmDataDestroyFunc Destroy, int mode){
  5773. laOperator *ai = a;
  5774. laConfirmData *cd = CreateNew(laConfirmData);
  5775. cd->CustomData = UserData;
  5776. cd->Mode = mode;
  5777. cd->Destroy = Destroy;
  5778. ai->NextConfirmData = cd;
  5779. laRetriggerOperators();
  5780. }
  5781. int laGetConfirmMode(laOperator *a){
  5782. return ((laOperator *)a)->ConfirmData->Mode;
  5783. }
  5784. int laGetConfirmInt(laOperator *a){
  5785. laOperator *ai = a;
  5786. int rev = ai->ConfirmData->IData;
  5787. la_DestroyConfirmData(&ai->ConfirmData);
  5788. ai->ConfirmData = 0;
  5789. return rev;
  5790. }
  5791. real laGetConfirmFloat(laOperator *a){
  5792. laOperator *ai = a;
  5793. real rev = ai->ConfirmData->FData;
  5794. la_DestroyConfirmData(&ai->ConfirmData);
  5795. ai->ConfirmData = 0;
  5796. return rev;
  5797. }
  5798. void laGetConfirmString(laOperator *a, char *buf){
  5799. laOperator *ai = a;
  5800. strcpy(buf, ai->ConfirmData->StrData);
  5801. la_DestroyConfirmData(&ai->ConfirmData);
  5802. ai->ConfirmData = 0;
  5803. }
  5804. void *laGetConfirmUserData(laOperator *a){
  5805. laOperator *ai = a;
  5806. return ai->ConfirmData->CustomData;
  5807. }
  5808. void laFinalizeOperators(){
  5809. laOperatorType *at;
  5810. laListHandle *lst;
  5811. int i;
  5812. for (i = 0; i < 256; i++){
  5813. lst = &MAIN.OperatorTypeHash.Entries[i];
  5814. for (at = lst->pFirst; at; at = at->Item.pNext){
  5815. if (at->PC && at->PC->Props.pFirst){
  5816. lstAppendItem(&MAIN.PropContainers, at->PC);
  5817. }
  5818. }
  5819. }
  5820. }
  5821. //=================
  5822. #ifdef __linux__
  5823. static void la_RecordWacomMotions(XIRawEvent *event)
  5824. {
  5825. double *valuator = event->valuators.values;
  5826. int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
  5827. if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
  5828. //SYSWINDOW root_return, child_return;
  5829. //int root_x_return, root_y_return;
  5830. //int win_x_return, win_y_return;
  5831. //unsigned int mask_return;
  5832. //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
  5833. // &root_x_return, &root_y_return,
  5834. // &win_x_return, &win_y_return,
  5835. // &mask_return);
  5836. //
  5837. //printf("root: x %d y %d\n", win_x_return, win_y_return);
  5838. if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/MAIN.StylusMaxPressure; else MAIN.EraserPressure=valuator[2]/MAIN.EraserMaxPressure; }
  5839. if(XIMaskIsSet(event->valuators.mask, 3) && XIMaskIsSet(event->valuators.mask, 4)){
  5840. real x=valuator[3],y=valuator[4];
  5841. real orientation=atan2(y,x); real deviation=sqrt(x*x+y*y); deviation=rad(deviation);
  5842. //printf("%f %f\n",orientation,deviation);
  5843. if(IsStylus){ MAIN.StylusOrientation=orientation;MAIN.StylusDeviation=deviation; }
  5844. else { MAIN.EraserOrientation=orientation;MAIN.EraserDeviation=deviation; }
  5845. }
  5846. MAIN.IsPen=1;
  5847. }
  5848. #endif
  5849. #ifdef _WIN32
  5850. #define PARAM_2_FROM(p) LOWORD(p),HIWORD(p)
  5851. LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  5852. static uint32_t ch = 0; static int lead = 0;
  5853. static wchar_t buf[10] = { 0 }; int adv;
  5854. char mbuf[10] = { 0 }; uint32_t uchar=0;
  5855. short wheelmark = 0;
  5856. int WheelDir = 0;
  5857. UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
  5858. POINTER_PEN_INFO penInfo; POINTER_TOUCH_INFO touchInfo;
  5859. POINT point;
  5860. PACKET pkt;
  5861. static POINT ptOld, ptNew;
  5862. static UINT prsOld, prsNew;
  5863. if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
  5864. switch (message) {
  5865. case WM_PAINT:
  5866. //SwapBuffers(GetDC(hwnd));
  5867. break;
  5868. case WM_MOUSEMOVE:
  5869. la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
  5870. MAIN.IsPen = 0;
  5871. break;
  5872. case WM_LBUTTONDOWN: la_SendMouseEvent(hwnd, LA_L_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  5873. case WM_LBUTTONUP: la_SendMouseEvent(hwnd, LA_L_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  5874. case WM_RBUTTONDOWN: la_SendMouseEvent(hwnd, LA_R_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  5875. case WM_RBUTTONUP: la_SendMouseEvent(hwnd, LA_R_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  5876. case WM_MBUTTONDOWN: la_SendMouseEvent(hwnd, LA_M_MOUSE_DOWN, PARAM_2_FROM(lparam)); break;
  5877. case WM_MBUTTONUP: la_SendMouseEvent(hwnd, LA_M_MOUSE_UP, PARAM_2_FROM(lparam)); break;
  5878. case WM_MOUSEWHEEL:
  5879. if ((wheelmark = HIWORD(wparam)) > 0) WheelDir = LA_MOUSEUP;
  5880. else if ((wheelmark = HIWORD(wparam)) < 0) WheelDir = LA_MOUSEDOWN;
  5881. la_SendMouseEvent(hwnd, WheelDir|LA_KEY_MOUSE_SCROLL, PARAM_2_FROM(lparam));
  5882. break;
  5883. case WT_PACKET:
  5884. if (!MAIN.InkOrWinTab) { break; /* Use Windows Ink. */ }
  5885. if (gpWTPacket((HCTX)lparam, wparam, &pkt)){
  5886. MAIN.StylusPressure = (real)pkt.pkNormalPressure/MAIN.WinTabMaxPenPressure;
  5887. real angle = (real)pkt.pkOrientation.orAzimuth / 3600*TNS_PI*2+TNS_PI/2;
  5888. MAIN.StylusOrientation = angle; MAIN.StylusDeviation=rad((90.0f-(real)pkt.pkOrientation.orAltitude/10.0f));
  5889. //printf("%f %f\n",angle,MAIN.StylusDeviation);
  5890. MAIN.IsPen = 1; MAIN.PointerIsEraser=((pkt.pkStatus & TPS_INVERT)==TPS_INVERT);
  5891. }
  5892. break;
  5893. case WM_SYSCOMMAND:
  5894. switch (wparam) {
  5895. case SC_MAXIMIZE:
  5896. case SC_RESTORE:
  5897. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  5898. break;
  5899. case SC_KEYMENU:
  5900. return 0;
  5901. }
  5902. break;
  5903. case WM_SIZE:
  5904. if (wparam == SIZE_MINIMIZED) break;
  5905. la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
  5906. break;
  5907. case WM_POINTERUPDATE:
  5908. if (MAIN.InkOrWinTab) { break;/* Use WinTab. */ }
  5909. pointerId = GET_POINTERID_WPARAM(wparam);
  5910. pointerType = PT_POINTER;
  5911. if(!GetPointerType(pointerId, &pointerType)){
  5912. pointerType = PT_POINTER;
  5913. printf("is pointer\n");
  5914. }
  5915. if(pointerType == PT_PEN){
  5916. if(GetPointerPenInfo(pointerId, &penInfo)){
  5917. point.x = penInfo.pointerInfo.ptPixelLocation.x; point.y = penInfo.pointerInfo.ptPixelLocation.y;
  5918. ScreenToClient(hwnd, &point);
  5919. MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo.pressure / 1024; MAIN.PointerIsEraser = 0;
  5920. }
  5921. }
  5922. else if (pointerType == PT_TOUCH){
  5923. if (GetPointerTouchInfo(pointerId, &touchInfo)) {
  5924. point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
  5925. ScreenToClient(hwnd, &point);
  5926. MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
  5927. }
  5928. }
  5929. break;
  5930. //case WM_SYSKEYDOWN:
  5931. // if (lparam & 0x40000000) break;
  5932. // if (la_SendSpecialKey(hwnd, LA_STATE_DOWN, wparam))
  5933. // break;
  5934. case WM_KEYDOWN:
  5935. if (lparam & 0x40000000) break;
  5936. la_SendKeyboardEvent(hwnd, LA_KEY_DOWN, la_TranslateSpecialKey(wparam));
  5937. break;
  5938. case WM_KEYUP:
  5939. la_SendKeyboardEvent(hwnd, LA_KEY_UP, la_TranslateSpecialKey(wparam));
  5940. break;
  5941. //case WM_SYSKEYUP:
  5942. // if (la_SendSpecialKey(hwnd, LA_STATE_UP, wparam));
  5943. // break;
  5944. case WM_UNICHAR:
  5945. la_SendInputEvent(hwnd, wparam);
  5946. break;
  5947. case WM_IME_CHAR:
  5948. la_SendInputEvent(hwnd, wparam);
  5949. return 0;
  5950. case WM_CHAR:
  5951. la_SendInputEvent(hwnd, wparam);
  5952. break;
  5953. case WM_SHOWWINDOW:
  5954. //SendCommandEvent(hwnd, EVT_WND_SIZE_FINISH);
  5955. break;
  5956. case WM_CLOSE:
  5957. if (!la_OnWindowDestroy(hwnd)) return 0; return 1;
  5958. break;
  5959. default:
  5960. return DefWindowProc(hwnd, message, wparam, lparam);
  5961. }
  5962. return DefWindowProc(hwnd, message, wparam, lparam);
  5963. }
  5964. LRESULT CALLBACK LA_ProgressWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
  5965. return DefWindowProc(hwnd, message, wparam, lparam);
  5966. }
  5967. #endif
  5968. int la_UpdateOperatorHints(laWindow* w){
  5969. laSafeString* ss=0;
  5970. for(laOperator* o=w->Operators.pFirst;o;o=o->Item.pNext){
  5971. if(o->RuntimeHint&&o->RuntimeHint->Ptr){ strSafePrint(&ss, "%s | %s ", o->Type->Name, o->RuntimeHint->Ptr);}
  5972. }
  5973. if((w->OperatorHints&&ss&&strSame(ss->Ptr,w->OperatorHints->Ptr))||(!w->OperatorHints&&!ss)){ //pass
  5974. }else{
  5975. if(ss){ strSafeSet(&w->OperatorHints,ss->Ptr); } else { strSafeDestroy(&w->OperatorHints); }
  5976. laNotifyUsers("la.windows.operator_hints");//printf("op hint\n");
  5977. }
  5978. strSafeDestroy(&ss);
  5979. }
  5980. int la_HandleSingleEvent(laEvent *e, laListHandle *Operators){
  5981. laOperator *a, *NextA = 0;
  5982. int Result = 0;
  5983. laConfirmData *ConfirmData = 0, *NextConfirmData = 0;
  5984. a = Operators->pFirst;
  5985. la_DestroyConfirmData(&MAIN.InvokeConfirmData);
  5986. while (1){
  5987. if (!a) break;
  5988. if (a->StopNow){
  5989. NextA = a->Item.pNext;
  5990. if (a->Type->Exit) a->Type->Exit(a, Result);
  5991. ConfirmData = a->NextConfirmData;
  5992. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  5993. NextConfirmData = ConfirmData;
  5994. a->ConfirmData = 0;
  5995. a->NextConfirmData = 0;
  5996. la_DestroyOperator(&a, Operators, 0);
  5997. a = NextA;
  5998. if (a){
  5999. a->ConfirmData = NextConfirmData;
  6000. }
  6001. continue;
  6002. }
  6003. a->Using = 1;
  6004. la_SetPropMathcerContext(a->ToPanel);
  6005. laSetOperatorLocalizer(a->ToPanel);
  6006. MAIN.CurrentPanel = a->ToPanel;
  6007. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6008. laWindowToLocal(a, a->ToPanel, &e->x, &e->y);
  6009. e->Localized = 1;
  6010. }
  6011. if (a->State & LA_BLOCK){ Result = a->Type->Modal(a, e); }
  6012. //la_PrintOperatorStack();
  6013. if (a->Type->ExtraMark & LA_EXTRA_TO_PANEL){
  6014. laLocalToWindow(a, a->ToPanel, &e->x, &e->y);
  6015. e->Localized = 0;
  6016. }
  6017. la_SetPropMathcerContext(0);
  6018. laSetOperatorLocalizer(0);
  6019. MAIN.CurrentPanel = 0;
  6020. a->Using = 0;
  6021. if (Result & LA_PASS_ON){
  6022. laConfirmSameDataIfAny(a);
  6023. NextA = a->Item.pNext;
  6024. }else{
  6025. NextA = 0;
  6026. if (a->NextConfirmData){
  6027. la_DestroyConfirmData(&a->NextConfirmData);
  6028. }
  6029. }
  6030. ConfirmData = a->NextConfirmData;
  6031. if (a->ConfirmData) la_DestroyConfirmData(&a->ConfirmData);
  6032. NextConfirmData = ConfirmData;
  6033. a->ConfirmData = 0;
  6034. a->NextConfirmData = 0;
  6035. if (Result & LA_FINISH || Result == LA_CANCEL || (a->StopNow && a->Using == 0)){
  6036. if (a->Type->Exit) a->Type->Exit(a, Result);
  6037. la_DestroyOperator(&a, Operators, 0);
  6038. if(Result == LA_OPERATOR_CALLS_SHUTOFF){ return 0; }
  6039. }
  6040. a = NextA;
  6041. if (a){
  6042. a->ConfirmData = NextConfirmData;
  6043. }
  6044. }
  6045. return 1;
  6046. }
  6047. int la_HandleEvents(laWindow *w){
  6048. laEvent *e, *NextE;
  6049. laOperator *a;
  6050. laThreadNotifier *tn;
  6051. MAIN.CurrentWindow=w;
  6052. //pthread_spin_lock(&MAIN.csNotifier);
  6053. while (tn = lstPopItem(&MAIN.ThreadNotifiers)){
  6054. //pthread_spin_unlock(&MAIN.csNotifier);
  6055. laNotifyUsers(tn->Path);
  6056. FreeMem(tn);
  6057. //if (MAIN.ThreadNotifiers.pFirst)
  6058. //pthread_spin_lock(&MAIN.csNotifier);
  6059. }
  6060. //pthread_spin_unlock(&MAIN.csNotifier);
  6061. while (1){
  6062. if (MAIN.ReTriggerOperators) laSendOperatorTriggerEvent();
  6063. while (w->EventList.pFirst){
  6064. while (w->PendingOperators.pLast){
  6065. a = w->PendingOperators.pLast;
  6066. if (a->OperatorPanel){
  6067. laSetOperatorLocalizer(a->OperatorPanel);
  6068. if (a->OperatorPanel->Mode == LA_PANEL_FLOATING_TOP)
  6069. laInvokeUi(a, "LA_modal_panel_operator", 0, a->OperatorPanel, 0, 1);
  6070. }
  6071. lstRemoveItem(&w->PendingOperators, a);
  6072. lstPushItem(&w->Operators, a);
  6073. }
  6074. e = lstPopItem(&w->EventList);
  6075. if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
  6076. if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); memFree(e); return 0; } //EXIT
  6077. memFree(e);
  6078. }
  6079. if (!MAIN.ReTriggerOperators) break;
  6080. }
  6081. la_UpdateOperatorHints(w);
  6082. return 1;
  6083. }
  6084. int la_AllowInput(uint32_t ch){
  6085. if(ch>=32 || ch==U'\n' || ch==U'\t' || ch==U'\b') return 1;
  6086. return 0;
  6087. }
  6088. int laCopyToClipboard(unsigned char * text){
  6089. #ifdef __linux__
  6090. XEvent event; SYSWINDOW owner, window=MAIN.CurrentWindow->win;
  6091. XSetSelectionOwner(MAIN.dpy, MAIN.selection, window, 0);
  6092. if (XGetSelectionOwner (MAIN.dpy, MAIN.selection) != window) return 0;
  6093. strSafeSet(&MAIN.CopyPending, text);
  6094. #endif
  6095. }
  6096. int la_ProcessSysMessage(){
  6097. int SendDelay = 0, SendIdle = 0;
  6098. if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
  6099. if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
  6100. #ifdef __linux__
  6101. XEvent e;
  6102. int type;
  6103. int InputCount = 0, CharCount=0;
  6104. KeySym InputKeysym = 0;
  6105. Status InputStatus = 0;
  6106. laWindow* wnd ;
  6107. while(XPending(MAIN.dpy)){
  6108. XGenericEventCookie *cookie = &e.xcookie;
  6109. XNextEvent(MAIN.dpy, &e);
  6110. if (XFilterEvent(&e, None)) continue;
  6111. SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
  6112. if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
  6113. if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
  6114. XFreeEventData(MAIN.dpy, cookie); continue;
  6115. }
  6116. switch(e.type){
  6117. case ConfigureNotify:
  6118. la_CommandResizeWindow(e.xconfigure.window, e.xconfigure.x, e.xconfigure.y, e.xconfigure.width, e.xconfigure.height);
  6119. break;
  6120. case Expose:
  6121. wnd = lstFindItem(e.xexpose.window, la_IsThisSysWindow, &MAIN.Windows);
  6122. if(!wnd) break;
  6123. laRefreshWindow(wnd);
  6124. break;
  6125. case MotionNotify:
  6126. la_SendMouseEvent(e.xmotion.window, LA_MOUSEMOVE, e.xmotion.x,e.xmotion.y);
  6127. MAIN.IsPen=0;
  6128. break;
  6129. case ButtonPress:
  6130. type=LA_MOUSEDOWN;
  6131. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6132. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6133. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6134. elif(e.xbutton.button==4){type=LA_MOUSEUP|LA_KEY_MOUSE_SCROLL;}
  6135. elif(e.xbutton.button==5){type=LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL;}
  6136. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6137. MAIN.IsPen=0;
  6138. break;
  6139. case ButtonRelease:
  6140. type=LA_MOUSEUP;
  6141. if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
  6142. elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
  6143. elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
  6144. la_SendMouseEvent(e.xbutton.window, type, e.xbutton.x,e.xbutton.y);
  6145. MAIN.IsPen=0;
  6146. break;
  6147. case KeyPress:
  6148. InputCount=Xutf8LookupString(MAIN.ic, (XKeyPressedEvent*)&e, MAIN.InputBuf, MAIN.InputBufMax, &InputKeysym, &InputStatus);
  6149. MAIN.InputBuf[InputCount]=0;
  6150. if (InputStatus==XBufferOverflow) printf("XInputBufferOverflow\n");
  6151. if (InputStatus == XLookupKeySym || InputStatus == XLookupBoth) { /*printf("status: %d\n", InputStatus);*/ }
  6152. if (InputCount){ MAIN.InputBuf[InputCount]=0; } strToUnicode(MAIN.InputBufU,MAIN.InputBuf); int UCount=strlenU(MAIN.InputBufU);
  6153. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6154. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6155. #ifdef DEBUG
  6156. printf("pressed KEY: %d\n", (int)InputKeysym);
  6157. #endif
  6158. la_SendKeyboardEvent(e.xkey.window, LA_KEY_DOWN, la_TranslateSpecialKey(InputKeysym));
  6159. }
  6160. break;
  6161. case KeyRelease:
  6162. if(InputKeysym=XkbKeycodeToKeysym(e.xkey.display, e.xkey.keycode, 0, 0)){
  6163. la_SendKeyboardEvent(e.xkey.window, LA_KEY_UP, la_TranslateSpecialKey(InputKeysym));
  6164. }
  6165. case ClientMessage:
  6166. if(e.xclient.data.l[0]==MAIN.MsgDelWindow){
  6167. if(la_OnWindowDestroy(e.xclient.window)){ return 0; }
  6168. }
  6169. break;
  6170. case SelectionNotify:
  6171. if(e.xselection.selection != MAIN.bufid) continue;
  6172. if (e.xselection.property){
  6173. char *result; unsigned long ressize, restail; int resbits; Atom fmtid;
  6174. XGetWindowProperty(MAIN.dpy, MAIN.CurrentWindow->win, MAIN.propid, 0, LONG_MAX/4, False, AnyPropertyType,
  6175. &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
  6176. if (fmtid == MAIN.incrid) logPrintNew("Pasted buffer is too large and INCR reading is not implemented yet.\n");
  6177. else if(result) {
  6178. arrEnsureLength(&MAIN.InputBufU, strlen(result), &MAIN.InputBufUMax, sizeof(uint32_t));
  6179. strToUnicode(MAIN.InputBufU,result); int UCount=strlenU(MAIN.InputBufU);
  6180. for(int i=0;i<UCount;i++){ if(la_AllowInput(MAIN.InputBufU[i])) la_SendInputEvent(e.xkey.window, MAIN.InputBufU[i]); }
  6181. }
  6182. XFree(result);
  6183. return True;
  6184. }
  6185. case SelectionRequest:
  6186. if(!MAIN.CopyPending){ break; }
  6187. char* text=MAIN.CopyPending->Ptr; int size=strlen(text);
  6188. if (e.xselectionrequest.selection != MAIN.selection) break;
  6189. XSelectionRequestEvent * xsr = &e.xselectionrequest;
  6190. XSelectionEvent ev = {0};
  6191. int R = 0;
  6192. ev.type = SelectionNotify, ev.display = xsr->display, ev.requestor = xsr->requestor,
  6193. ev.selection = xsr->selection, ev.time = xsr->time, ev.target = xsr->target, ev.property = xsr->property;
  6194. if (ev.target == MAIN.targets_atom) R = XChangeProperty (ev.display, ev.requestor, ev.property, XA_ATOM, 32,
  6195. PropModeReplace, (unsigned char*)&MAIN.UTF8, 1);
  6196. else if (ev.target == XA_STRING || ev.target == MAIN.text_atom)
  6197. R = XChangeProperty(ev.display, ev.requestor, ev.property, XA_STRING, 8, PropModeReplace, text, size);
  6198. else if (ev.target == MAIN.UTF8)
  6199. R = XChangeProperty(ev.display, ev.requestor, ev.property, MAIN.UTF8, 8, PropModeReplace, text, size);
  6200. else ev.property = None;
  6201. if ((R & 2) == 0) XSendEvent (MAIN.dpy, ev.requestor, 0, 0, (XEvent *)&ev);
  6202. break;
  6203. case SelectionClear:
  6204. break;
  6205. default:
  6206. break;
  6207. }
  6208. }
  6209. #endif //linux
  6210. #ifdef _WIN32
  6211. MSG msg; int Processed = 0;
  6212. if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0) Processed = 1;
  6213. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  6214. TranslateMessage(&msg); DispatchMessage(&msg);
  6215. SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
  6216. };
  6217. #endif
  6218. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6219. if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
  6220. if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE); MAIN.IdleTriggered=1; }
  6221. }
  6222. return 1;
  6223. };
  6224. void la_PrintOperatorStack(){
  6225. laWindow *w = MAIN.CurrentWindow;
  6226. laOperator *a;
  6227. printf("\n");
  6228. for (a = w->Operators.pFirst; a; a = a->Item.pNext){
  6229. printf("OP [%-25s] For [0x%08x] Child[%-25s][0x%08x]\n",
  6230. a->Type->Identifier, a->Instance,
  6231. (a->Child ? a->Child->Type->Identifier : ""), a->Child);
  6232. }
  6233. }
  6234. void la_DrawWindow(laWindow *w){
  6235. if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
  6236. MAIN.CurrentWindow = w;
  6237. la_WindowDefDraw(w, 0);
  6238. }
  6239. int laFinalize(){
  6240. if(!laValidateProperties()){ laShutoff(0); return 0; }
  6241. laUiTemplate* uit;
  6242. while(uit=lstPopItem(&MAIN.InitPanelTemplates)) lstAppendItem(&MAIN.PanelTemplates,uit);
  6243. return 1;
  6244. }
  6245. void laMainLoop(){
  6246. laWindow *w = MAIN.Windows.pFirst, *NextW;
  6247. laTimeRecorder FrameStartTime, FrameEndTime;
  6248. time_t t1, t2;
  6249. real TimeInterval, Pause, TimeAccum = 0, FrameInterval;
  6250. static int a = 0;
  6251. if(!laFinalize()) return;
  6252. MAIN.DelayTriggered=1;
  6253. while (1){
  6254. laRecordTime(&FrameStartTime);
  6255. if(MAIN.PreFrame){ MAIN.PreFrame(); }
  6256. la_AnimationPreFrame();
  6257. if(!la_ProcessSysMessage()){ return; }
  6258. la_UpdateControllerStatus();
  6259. if(MAIN.GraphNeedsRebuild){ la_RebuildInputMapping(); MAIN.InputNeedsEval = 0; }
  6260. if(MAIN.InputNeedsEval){ la_RunInputMapping(); }
  6261. for (w=MAIN.Windows.pFirst;w;w = NextW){
  6262. NextW = w->Item.pNext;
  6263. if(!la_HandleEvents(w)){ laShutoff(1); return; }
  6264. }
  6265. if(MAIN.PreDraw){ MAIN.PreDraw(); }
  6266. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6267. tnsSwitchToCurrentWindowContext(w);
  6268. la_DrawWindow(w);
  6269. }
  6270. for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  6271. if(!w->RedrawTouched) continue; w->RedrawTouched=0;
  6272. #ifdef __linux__
  6273. glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
  6274. #endif
  6275. #ifdef _WIN32
  6276. SwapBuffers(w->hdc);
  6277. #endif
  6278. }
  6279. if(MAIN.PostFrame){ MAIN.PostFrame(); }
  6280. //t2 = clock();
  6281. laRecordTime(&FrameEndTime);
  6282. TimeInterval = laTimeElapsedSecondsf(&FrameEndTime, &FrameStartTime);
  6283. Pause = (1.0 / MAIN.TopFramerate - TimeInterval);
  6284. if (Pause > 0){
  6285. int us = Pause * 1000000.0;
  6286. usleep(us);
  6287. }
  6288. MAIN.TimeAccum += (MAIN.LastFrameTime = Pause+TimeInterval);
  6289. //FrameInterval = 1.0 / MAIN.Animation.FrameRate;
  6290. la_AnimationPostFrame();
  6291. }
  6292. }