*/}}

la_kernel.c 226 KB

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