*/}}

la_kernel.c 226 KB

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