babylon.gui.js 242 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471
  1. (function universalModuleDefinition(root, factory) {
  2. var amdDependencies = [];
  3. var BABYLON = root.BABYLON || this.BABYLON;
  4. if(typeof exports === 'object' && typeof module === 'object') {
  5. BABYLON = BABYLON || require("babylonjs");
  6. module.exports = factory(BABYLON);
  7. } else if(typeof define === 'function' && define.amd) {
  8. amdDependencies.push("babylonjs");
  9. define("babylonjs-gui", amdDependencies, factory);
  10. } else if(typeof exports === 'object') {
  11. BABYLON = BABYLON || require("babylonjs");
  12. exports["babylonjs-gui"] = factory(BABYLON);
  13. } else {
  14. root["BABYLON"]["GUI"] = factory(BABYLON);
  15. }
  16. })(this, function(BABYLON) {
  17. BABYLON = BABYLON || this.BABYLON;
  18. var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};
  19. var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
  20. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  21. var BABYLON;
  22. (function (BABYLON) {
  23. var GUI;
  24. (function (GUI) {
  25. var AdvancedDynamicTexture = /** @class */ (function (_super) {
  26. __extends(AdvancedDynamicTexture, _super);
  27. function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
  28. if (width === void 0) { width = 0; }
  29. if (height === void 0) { height = 0; }
  30. if (generateMipMaps === void 0) { generateMipMaps = false; }
  31. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
  32. var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, BABYLON.Engine.TEXTUREFORMAT_RGBA) || this;
  33. _this._isDirty = false;
  34. _this._rootContainer = new GUI.Container("root");
  35. _this._lastControlOver = {};
  36. _this._lastControlDown = {};
  37. _this._capturingControl = {};
  38. _this._linkedControls = new Array();
  39. _this._isFullscreen = false;
  40. _this._fullscreenViewport = new BABYLON.Viewport(0, 0, 1, 1);
  41. _this._idealWidth = 0;
  42. _this._idealHeight = 0;
  43. _this._useSmallestIdeal = false;
  44. _this._renderAtIdealSize = false;
  45. _this._blockNextFocusCheck = false;
  46. _this._renderScale = 1;
  47. scene = _this.getScene();
  48. if (!scene || !_this._texture) {
  49. return _this;
  50. }
  51. _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
  52. _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
  53. if (!_this._focusedControl) {
  54. return;
  55. }
  56. if (info.type === BABYLON.KeyboardEventTypes.KEYDOWN) {
  57. _this._focusedControl.processKeyboard(info.event);
  58. }
  59. info.skipOnPointerObservable = true;
  60. });
  61. _this._rootContainer._link(null, _this);
  62. _this.hasAlpha = true;
  63. if (!width || !height) {
  64. _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  65. _this._onResize();
  66. }
  67. _this._texture.isReady = true;
  68. return _this;
  69. }
  70. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
  71. get: function () {
  72. return this._renderScale;
  73. },
  74. set: function (value) {
  75. if (value === this._renderScale) {
  76. return;
  77. }
  78. this._renderScale = value;
  79. this._onResize();
  80. },
  81. enumerable: true,
  82. configurable: true
  83. });
  84. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  85. get: function () {
  86. return this._background;
  87. },
  88. set: function (value) {
  89. if (this._background === value) {
  90. return;
  91. }
  92. this._background = value;
  93. this.markAsDirty();
  94. },
  95. enumerable: true,
  96. configurable: true
  97. });
  98. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
  99. get: function () {
  100. return this._idealWidth;
  101. },
  102. set: function (value) {
  103. if (this._idealWidth === value) {
  104. return;
  105. }
  106. this._idealWidth = value;
  107. this.markAsDirty();
  108. this._rootContainer._markAllAsDirty();
  109. },
  110. enumerable: true,
  111. configurable: true
  112. });
  113. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
  114. get: function () {
  115. return this._idealHeight;
  116. },
  117. set: function (value) {
  118. if (this._idealHeight === value) {
  119. return;
  120. }
  121. this._idealHeight = value;
  122. this.markAsDirty();
  123. this._rootContainer._markAllAsDirty();
  124. },
  125. enumerable: true,
  126. configurable: true
  127. });
  128. Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
  129. get: function () {
  130. return this._useSmallestIdeal;
  131. },
  132. set: function (value) {
  133. if (this._useSmallestIdeal === value) {
  134. return;
  135. }
  136. this._useSmallestIdeal = value;
  137. this.markAsDirty();
  138. this._rootContainer._markAllAsDirty();
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
  144. get: function () {
  145. return this._renderAtIdealSize;
  146. },
  147. set: function (value) {
  148. if (this._renderAtIdealSize === value) {
  149. return;
  150. }
  151. this._renderAtIdealSize = value;
  152. this._onResize();
  153. },
  154. enumerable: true,
  155. configurable: true
  156. });
  157. Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
  158. get: function () {
  159. return this._layerToDispose;
  160. },
  161. enumerable: true,
  162. configurable: true
  163. });
  164. Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
  165. get: function () {
  166. return this._rootContainer;
  167. },
  168. enumerable: true,
  169. configurable: true
  170. });
  171. Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
  172. get: function () {
  173. return this._focusedControl;
  174. },
  175. set: function (control) {
  176. if (this._focusedControl == control) {
  177. return;
  178. }
  179. if (this._focusedControl) {
  180. this._focusedControl.onBlur();
  181. }
  182. if (control) {
  183. control.onFocus();
  184. }
  185. this._focusedControl = control;
  186. },
  187. enumerable: true,
  188. configurable: true
  189. });
  190. Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
  191. get: function () {
  192. if (!this.layer) {
  193. return true;
  194. }
  195. return (!this.layer.isBackground);
  196. },
  197. set: function (value) {
  198. if (!this.layer) {
  199. return;
  200. }
  201. if (this.layer.isBackground === !value) {
  202. return;
  203. }
  204. this.layer.isBackground = !value;
  205. },
  206. enumerable: true,
  207. configurable: true
  208. });
  209. AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
  210. if (!container) {
  211. container = this._rootContainer;
  212. }
  213. for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
  214. var child = _a[_i];
  215. if (child.children) {
  216. this.executeOnAllControls(func, child);
  217. continue;
  218. }
  219. func(child);
  220. }
  221. };
  222. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  223. this._isDirty = true;
  224. this.executeOnAllControls(function (control) {
  225. if (control._isFontSizeInPercentage) {
  226. control._resetFontCache();
  227. }
  228. });
  229. };
  230. AdvancedDynamicTexture.prototype.addControl = function (control) {
  231. this._rootContainer.addControl(control);
  232. return this;
  233. };
  234. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  235. this._rootContainer.removeControl(control);
  236. return this;
  237. };
  238. AdvancedDynamicTexture.prototype.dispose = function () {
  239. var scene = this.getScene();
  240. if (!scene) {
  241. return;
  242. }
  243. scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
  244. if (this._resizeObserver) {
  245. scene.getEngine().onResizeObservable.remove(this._resizeObserver);
  246. }
  247. if (this._pointerMoveObserver) {
  248. scene.onPrePointerObservable.remove(this._pointerMoveObserver);
  249. }
  250. if (this._pointerObserver) {
  251. scene.onPointerObservable.remove(this._pointerObserver);
  252. }
  253. if (this._preKeyboardObserver) {
  254. scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
  255. }
  256. if (this._canvasPointerOutObserver) {
  257. scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
  258. }
  259. if (this._layerToDispose) {
  260. this._layerToDispose.texture = null;
  261. this._layerToDispose.dispose();
  262. this._layerToDispose = null;
  263. }
  264. this._rootContainer.dispose();
  265. _super.prototype.dispose.call(this);
  266. };
  267. AdvancedDynamicTexture.prototype._onResize = function () {
  268. var scene = this.getScene();
  269. if (!scene) {
  270. return;
  271. }
  272. // Check size
  273. var engine = scene.getEngine();
  274. var textureSize = this.getSize();
  275. var renderWidth = engine.getRenderWidth() * this._renderScale;
  276. var renderHeight = engine.getRenderHeight() * this._renderScale;
  277. if (this._renderAtIdealSize) {
  278. if (this._idealWidth) {
  279. renderHeight = (renderHeight * this._idealWidth) / renderWidth;
  280. renderWidth = this._idealWidth;
  281. }
  282. else if (this._idealHeight) {
  283. renderWidth = (renderWidth * this._idealHeight) / renderHeight;
  284. renderHeight = this._idealHeight;
  285. }
  286. }
  287. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  288. this.scaleTo(renderWidth, renderHeight);
  289. this.markAsDirty();
  290. if (this._idealWidth || this._idealHeight) {
  291. this._rootContainer._markAllAsDirty();
  292. }
  293. }
  294. };
  295. AdvancedDynamicTexture.prototype._getGlobalViewport = function (scene) {
  296. var engine = scene.getEngine();
  297. return this._fullscreenViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  298. };
  299. AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
  300. var scene = this.getScene();
  301. if (!scene) {
  302. return BABYLON.Vector2.Zero();
  303. }
  304. var globalViewport = this._getGlobalViewport(scene);
  305. var projectedPosition = BABYLON.Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
  306. projectedPosition.scaleInPlace(this.renderScale);
  307. return new BABYLON.Vector2(projectedPosition.x, projectedPosition.y);
  308. };
  309. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  310. if (this._layerToDispose) {
  311. if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
  312. return;
  313. }
  314. }
  315. if (this._isFullscreen && this._linkedControls.length) {
  316. var scene = this.getScene();
  317. if (!scene) {
  318. return;
  319. }
  320. var globalViewport = this._getGlobalViewport(scene);
  321. for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
  322. var control = _a[_i];
  323. if (!control.isVisible) {
  324. continue;
  325. }
  326. var mesh = control._linkedMesh;
  327. if (!mesh || mesh.isDisposed()) {
  328. BABYLON.Tools.SetImmediate(function () {
  329. control.linkWithMesh(null);
  330. });
  331. continue;
  332. }
  333. var position = mesh.getBoundingInfo().boundingSphere.center;
  334. var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
  335. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  336. control.notRenderable = true;
  337. continue;
  338. }
  339. control.notRenderable = false;
  340. // Account for RenderScale.
  341. projectedPosition.scaleInPlace(this.renderScale);
  342. control._moveToProjectedPosition(projectedPosition);
  343. }
  344. }
  345. if (!this._isDirty && !this._rootContainer.isDirty) {
  346. return;
  347. }
  348. this._isDirty = false;
  349. this._render();
  350. this.update();
  351. };
  352. AdvancedDynamicTexture.prototype._render = function () {
  353. var textureSize = this.getSize();
  354. var renderWidth = textureSize.width;
  355. var renderHeight = textureSize.height;
  356. // Clear
  357. var context = this.getContext();
  358. context.clearRect(0, 0, renderWidth, renderHeight);
  359. if (this._background) {
  360. context.save();
  361. context.fillStyle = this._background;
  362. context.fillRect(0, 0, renderWidth, renderHeight);
  363. context.restore();
  364. }
  365. // Render
  366. context.font = "18px Arial";
  367. context.strokeStyle = "white";
  368. var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
  369. this._rootContainer._draw(measure, context);
  370. };
  371. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, pointerId, buttonIndex) {
  372. var scene = this.getScene();
  373. if (!scene) {
  374. return;
  375. }
  376. var engine = scene.getEngine();
  377. var textureSize = this.getSize();
  378. if (this._isFullscreen) {
  379. x = x * (textureSize.width / engine.getRenderWidth());
  380. y = y * (textureSize.height / engine.getRenderHeight());
  381. }
  382. if (this._capturingControl[pointerId]) {
  383. this._capturingControl[pointerId]._processObservables(type, x, y, pointerId, buttonIndex);
  384. return;
  385. }
  386. if (!this._rootContainer._processPicking(x, y, type, pointerId, buttonIndex)) {
  387. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  388. if (this._lastControlOver[pointerId]) {
  389. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  390. }
  391. delete this._lastControlOver[pointerId];
  392. }
  393. }
  394. this._manageFocus();
  395. };
  396. AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
  397. for (var pointerId in list) {
  398. if (!list.hasOwnProperty(pointerId)) {
  399. continue;
  400. }
  401. var lastControlOver = list[pointerId];
  402. if (lastControlOver === control) {
  403. delete list[pointerId];
  404. }
  405. }
  406. };
  407. AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
  408. this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
  409. this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
  410. };
  411. AdvancedDynamicTexture.prototype.attach = function () {
  412. var _this = this;
  413. var scene = this.getScene();
  414. if (!scene) {
  415. return;
  416. }
  417. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  418. if (scene.isPointerCaptured((pi.event).pointerId)) {
  419. return;
  420. }
  421. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  422. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  423. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  424. return;
  425. }
  426. if (!scene) {
  427. return;
  428. }
  429. var camera = scene.cameraToUseForPointers || scene.activeCamera;
  430. if (!camera) {
  431. return;
  432. }
  433. var engine = scene.getEngine();
  434. var viewport = camera.viewport;
  435. var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
  436. var y = (scene.pointerY / engine.getHardwareScalingLevel() - viewport.y * engine.getRenderHeight()) / viewport.height;
  437. _this._shouldBlockPointer = false;
  438. _this._doPicking(x, y, pi.type, pi.event.pointerId || 0, pi.event.button);
  439. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  440. });
  441. this._attachToOnPointerOut(scene);
  442. };
  443. AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
  444. var _this = this;
  445. if (supportPointerMove === void 0) { supportPointerMove = true; }
  446. var scene = this.getScene();
  447. if (!scene) {
  448. return;
  449. }
  450. this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
  451. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  452. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  453. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  454. return;
  455. }
  456. var pointerId = pi.event.pointerId || 0;
  457. if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
  458. var uv = pi.pickInfo.getTextureCoordinates();
  459. if (uv) {
  460. var size = _this.getSize();
  461. _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pointerId, pi.event.button);
  462. }
  463. }
  464. else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
  465. if (_this._lastControlDown[pointerId]) {
  466. _this._lastControlDown[pointerId].forcePointerUp(pointerId);
  467. }
  468. delete _this._lastControlDown[pointerId];
  469. _this.focusedControl = null;
  470. }
  471. else if (pi.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  472. if (_this._lastControlOver[pointerId]) {
  473. _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId]);
  474. }
  475. delete _this._lastControlOver[pointerId];
  476. }
  477. });
  478. mesh.enablePointerMoveEvents = supportPointerMove;
  479. this._attachToOnPointerOut(scene);
  480. };
  481. AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
  482. this.focusedControl = control;
  483. this._lastPickedControl = control;
  484. this._blockNextFocusCheck = true;
  485. };
  486. AdvancedDynamicTexture.prototype._manageFocus = function () {
  487. if (this._blockNextFocusCheck) {
  488. this._blockNextFocusCheck = false;
  489. this._lastPickedControl = this._focusedControl;
  490. return;
  491. }
  492. // Focus management
  493. if (this._focusedControl) {
  494. if (this._focusedControl !== this._lastPickedControl) {
  495. if (this._lastPickedControl.isFocusInvisible) {
  496. return;
  497. }
  498. this.focusedControl = null;
  499. }
  500. }
  501. };
  502. AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
  503. var _this = this;
  504. this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
  505. if (_this._lastControlOver[pointerEvent.pointerId]) {
  506. _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId]);
  507. }
  508. delete _this._lastControlOver[pointerEvent.pointerId];
  509. if (_this._lastControlDown[pointerEvent.pointerId]) {
  510. _this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  511. }
  512. delete _this._lastControlDown[pointerEvent.pointerId];
  513. });
  514. };
  515. // Statics
  516. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove) {
  517. if (width === void 0) { width = 1024; }
  518. if (height === void 0) { height = 1024; }
  519. if (supportPointerMove === void 0) { supportPointerMove = true; }
  520. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  521. var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  522. material.backFaceCulling = false;
  523. material.diffuseColor = BABYLON.Color3.Black();
  524. material.specularColor = BABYLON.Color3.Black();
  525. material.emissiveTexture = result;
  526. material.opacityTexture = result;
  527. mesh.material = material;
  528. result.attachToMesh(mesh, supportPointerMove);
  529. return result;
  530. };
  531. /**
  532. * FullScreenUI is created in a layer. This allows it to be treated like any other layer.
  533. * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
  534. * When the GUI is not Created as FullscreenUI it does not respect the layerMask.
  535. * layerMask is set through advancedTexture.layer.layerMask
  536. * @param name name for the Texture
  537. * @param foreground render in foreground (default is true)
  538. * @param scene scene to be rendered in
  539. * @param sampling method for scaling to fit screen
  540. * @returns AdvancedDynamicTexture
  541. */
  542. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
  543. if (foreground === void 0) { foreground = true; }
  544. if (scene === void 0) { scene = null; }
  545. if (sampling === void 0) { sampling = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
  546. var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
  547. // Display
  548. var layer = new BABYLON.Layer(name + "_layer", null, scene, !foreground);
  549. layer.texture = result;
  550. result._layerToDispose = layer;
  551. result._isFullscreen = true;
  552. // Attach
  553. result.attach();
  554. return result;
  555. };
  556. return AdvancedDynamicTexture;
  557. }(BABYLON.DynamicTexture));
  558. GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;
  559. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  560. })(BABYLON || (BABYLON = {}));
  561. //# sourceMappingURL=advancedDynamicTexture.js.map
  562. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  563. var BABYLON;
  564. (function (BABYLON) {
  565. var GUI;
  566. (function (GUI) {
  567. var Measure = /** @class */ (function () {
  568. function Measure(left, top, width, height) {
  569. this.left = left;
  570. this.top = top;
  571. this.width = width;
  572. this.height = height;
  573. }
  574. Measure.prototype.copyFrom = function (other) {
  575. this.left = other.left;
  576. this.top = other.top;
  577. this.width = other.width;
  578. this.height = other.height;
  579. };
  580. Measure.prototype.isEqualsTo = function (other) {
  581. if (this.left !== other.left) {
  582. return false;
  583. }
  584. if (this.top !== other.top) {
  585. return false;
  586. }
  587. if (this.width !== other.width) {
  588. return false;
  589. }
  590. if (this.height !== other.height) {
  591. return false;
  592. }
  593. return true;
  594. };
  595. Measure.Empty = function () {
  596. return new Measure(0, 0, 0, 0);
  597. };
  598. return Measure;
  599. }());
  600. GUI.Measure = Measure;
  601. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  602. })(BABYLON || (BABYLON = {}));
  603. //# sourceMappingURL=measure.js.map
  604. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  605. var BABYLON;
  606. (function (BABYLON) {
  607. var GUI;
  608. (function (GUI) {
  609. var Vector2WithInfo = /** @class */ (function (_super) {
  610. __extends(Vector2WithInfo, _super);
  611. function Vector2WithInfo(source, buttonIndex) {
  612. if (buttonIndex === void 0) { buttonIndex = 0; }
  613. var _this = _super.call(this, source.x, source.y) || this;
  614. _this.buttonIndex = buttonIndex;
  615. return _this;
  616. }
  617. return Vector2WithInfo;
  618. }(BABYLON.Vector2));
  619. GUI.Vector2WithInfo = Vector2WithInfo;
  620. var Matrix2D = /** @class */ (function () {
  621. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  622. this.m = new Float32Array(6);
  623. this.fromValues(m00, m01, m10, m11, m20, m21);
  624. }
  625. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  626. this.m[0] = m00;
  627. this.m[1] = m01;
  628. this.m[2] = m10;
  629. this.m[3] = m11;
  630. this.m[4] = m20;
  631. this.m[5] = m21;
  632. return this;
  633. };
  634. Matrix2D.prototype.determinant = function () {
  635. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  636. };
  637. Matrix2D.prototype.invertToRef = function (result) {
  638. var l0 = this.m[0];
  639. var l1 = this.m[1];
  640. var l2 = this.m[2];
  641. var l3 = this.m[3];
  642. var l4 = this.m[4];
  643. var l5 = this.m[5];
  644. var det = this.determinant();
  645. if (det < (BABYLON.Epsilon * BABYLON.Epsilon)) {
  646. result.m[0] = 0;
  647. result.m[1] = 0;
  648. result.m[2] = 0;
  649. result.m[3] = 0;
  650. result.m[4] = 0;
  651. result.m[5] = 0;
  652. return this;
  653. }
  654. var detDiv = 1 / det;
  655. var det4 = l2 * l5 - l3 * l4;
  656. var det5 = l1 * l4 - l0 * l5;
  657. result.m[0] = l3 * detDiv;
  658. result.m[1] = -l1 * detDiv;
  659. result.m[2] = -l2 * detDiv;
  660. result.m[3] = l0 * detDiv;
  661. result.m[4] = det4 * detDiv;
  662. result.m[5] = det5 * detDiv;
  663. return this;
  664. };
  665. Matrix2D.prototype.multiplyToRef = function (other, result) {
  666. var l0 = this.m[0];
  667. var l1 = this.m[1];
  668. var l2 = this.m[2];
  669. var l3 = this.m[3];
  670. var l4 = this.m[4];
  671. var l5 = this.m[5];
  672. var r0 = other.m[0];
  673. var r1 = other.m[1];
  674. var r2 = other.m[2];
  675. var r3 = other.m[3];
  676. var r4 = other.m[4];
  677. var r5 = other.m[5];
  678. result.m[0] = l0 * r0 + l1 * r2;
  679. result.m[1] = l0 * r1 + l1 * r3;
  680. result.m[2] = l2 * r0 + l3 * r2;
  681. result.m[3] = l2 * r1 + l3 * r3;
  682. result.m[4] = l4 * r0 + l5 * r2 + r4;
  683. result.m[5] = l4 * r1 + l5 * r3 + r5;
  684. return this;
  685. };
  686. Matrix2D.prototype.transformCoordinates = function (x, y, result) {
  687. result.x = x * this.m[0] + y * this.m[2] + this.m[4];
  688. result.y = x * this.m[1] + y * this.m[3] + this.m[5];
  689. return this;
  690. };
  691. // Statics
  692. Matrix2D.Identity = function () {
  693. return new Matrix2D(1, 0, 0, 1, 0, 0);
  694. };
  695. Matrix2D.TranslationToRef = function (x, y, result) {
  696. result.fromValues(1, 0, 0, 1, x, y);
  697. };
  698. Matrix2D.ScalingToRef = function (x, y, result) {
  699. result.fromValues(x, 0, 0, y, 0, 0);
  700. };
  701. Matrix2D.RotationToRef = function (angle, result) {
  702. var s = Math.sin(angle);
  703. var c = Math.cos(angle);
  704. result.fromValues(c, s, -s, c, 0, 0);
  705. };
  706. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  707. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  708. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  709. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  710. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  711. Matrix2D._TempPreTranslationMatrix.multiplyToRef(Matrix2D._TempScalingMatrix, Matrix2D._TempCompose0);
  712. Matrix2D._TempCompose0.multiplyToRef(Matrix2D._TempRotationMatrix, Matrix2D._TempCompose1);
  713. if (parentMatrix) {
  714. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, Matrix2D._TempCompose2);
  715. Matrix2D._TempCompose2.multiplyToRef(parentMatrix, result);
  716. }
  717. else {
  718. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, result);
  719. }
  720. };
  721. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  722. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  723. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  724. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  725. Matrix2D._TempCompose0 = Matrix2D.Identity();
  726. Matrix2D._TempCompose1 = Matrix2D.Identity();
  727. Matrix2D._TempCompose2 = Matrix2D.Identity();
  728. return Matrix2D;
  729. }());
  730. GUI.Matrix2D = Matrix2D;
  731. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  732. })(BABYLON || (BABYLON = {}));
  733. //# sourceMappingURL=math2D.js.map
  734. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  735. var BABYLON;
  736. (function (BABYLON) {
  737. var GUI;
  738. (function (GUI) {
  739. var ValueAndUnit = /** @class */ (function () {
  740. function ValueAndUnit(value, unit, negativeValueAllowed) {
  741. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PIXEL; }
  742. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  743. this.unit = unit;
  744. this.negativeValueAllowed = negativeValueAllowed;
  745. this._value = 1;
  746. this.ignoreAdaptiveScaling = false;
  747. this._value = value;
  748. }
  749. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  750. get: function () {
  751. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  752. },
  753. enumerable: true,
  754. configurable: true
  755. });
  756. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  757. get: function () {
  758. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  759. },
  760. enumerable: true,
  761. configurable: true
  762. });
  763. Object.defineProperty(ValueAndUnit.prototype, "internalValue", {
  764. get: function () {
  765. return this._value;
  766. },
  767. enumerable: true,
  768. configurable: true
  769. });
  770. ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
  771. if (this.isPixel) {
  772. return this.getValue(host);
  773. }
  774. return this.getValue(host) * refValue;
  775. };
  776. ValueAndUnit.prototype.getValue = function (host) {
  777. if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
  778. var width = 0;
  779. var height = 0;
  780. if (host.idealWidth) {
  781. width = (this._value * host.getSize().width) / host.idealWidth;
  782. }
  783. if (host.idealHeight) {
  784. height = (this._value * host.getSize().height) / host.idealHeight;
  785. }
  786. if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {
  787. return window.innerWidth < window.innerHeight ? width : height;
  788. }
  789. if (host.idealWidth) { // horizontal
  790. return width;
  791. }
  792. if (host.idealHeight) { // vertical
  793. return height;
  794. }
  795. }
  796. return this._value;
  797. };
  798. ValueAndUnit.prototype.toString = function (host) {
  799. switch (this.unit) {
  800. case ValueAndUnit.UNITMODE_PERCENTAGE:
  801. return (this.getValue(host) * 100) + "%";
  802. case ValueAndUnit.UNITMODE_PIXEL:
  803. return this.getValue(host) + "px";
  804. }
  805. return this.unit.toString();
  806. };
  807. ValueAndUnit.prototype.fromString = function (source) {
  808. var match = ValueAndUnit._Regex.exec(source.toString());
  809. if (!match || match.length === 0) {
  810. return false;
  811. }
  812. var sourceValue = parseFloat(match[1]);
  813. var sourceUnit = this.unit;
  814. if (!this.negativeValueAllowed) {
  815. if (sourceValue < 0) {
  816. sourceValue = 0;
  817. }
  818. }
  819. if (match.length === 4) {
  820. switch (match[3]) {
  821. case "px":
  822. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  823. break;
  824. case "%":
  825. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  826. sourceValue /= 100.0;
  827. break;
  828. }
  829. }
  830. if (sourceValue === this._value && sourceUnit === this.unit) {
  831. return false;
  832. }
  833. this._value = sourceValue;
  834. this.unit = sourceUnit;
  835. return true;
  836. };
  837. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  838. get: function () {
  839. return ValueAndUnit._UNITMODE_PERCENTAGE;
  840. },
  841. enumerable: true,
  842. configurable: true
  843. });
  844. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  845. get: function () {
  846. return ValueAndUnit._UNITMODE_PIXEL;
  847. },
  848. enumerable: true,
  849. configurable: true
  850. });
  851. // Static
  852. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  853. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  854. ValueAndUnit._UNITMODE_PIXEL = 1;
  855. return ValueAndUnit;
  856. }());
  857. GUI.ValueAndUnit = ValueAndUnit;
  858. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  859. })(BABYLON || (BABYLON = {}));
  860. //# sourceMappingURL=valueAndUnit.js.map
  861. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  862. var BABYLON;
  863. (function (BABYLON) {
  864. var GUI;
  865. (function (GUI) {
  866. var MultiLinePoint = /** @class */ (function () {
  867. function MultiLinePoint(multiLine) {
  868. this._multiLine = multiLine;
  869. this._x = new GUI.ValueAndUnit(0);
  870. this._y = new GUI.ValueAndUnit(0);
  871. this._point = new BABYLON.Vector2(0, 0);
  872. }
  873. Object.defineProperty(MultiLinePoint.prototype, "x", {
  874. get: function () {
  875. return this._x.toString(this._multiLine._host);
  876. },
  877. set: function (value) {
  878. if (this._x.toString(this._multiLine._host) === value) {
  879. return;
  880. }
  881. if (this._x.fromString(value)) {
  882. this._multiLine._markAsDirty();
  883. }
  884. },
  885. enumerable: true,
  886. configurable: true
  887. });
  888. Object.defineProperty(MultiLinePoint.prototype, "y", {
  889. get: function () {
  890. return this._y.toString(this._multiLine._host);
  891. },
  892. set: function (value) {
  893. if (this._y.toString(this._multiLine._host) === value) {
  894. return;
  895. }
  896. if (this._y.fromString(value)) {
  897. this._multiLine._markAsDirty();
  898. }
  899. },
  900. enumerable: true,
  901. configurable: true
  902. });
  903. Object.defineProperty(MultiLinePoint.prototype, "control", {
  904. get: function () {
  905. return this._control;
  906. },
  907. set: function (value) {
  908. if (this._control === value) {
  909. return;
  910. }
  911. if (this._control && this._controlObserver) {
  912. this._control.onDirtyObservable.remove(this._controlObserver);
  913. this._controlObserver = null;
  914. }
  915. this._control = value;
  916. if (this._control) {
  917. this._controlObserver = this._control.onDirtyObservable.add(this._multiLine.onPointUpdate);
  918. }
  919. this._multiLine._markAsDirty();
  920. },
  921. enumerable: true,
  922. configurable: true
  923. });
  924. Object.defineProperty(MultiLinePoint.prototype, "mesh", {
  925. get: function () {
  926. return this._mesh;
  927. },
  928. set: function (value) {
  929. if (this._mesh === value) {
  930. return;
  931. }
  932. if (this._mesh && this._meshObserver) {
  933. this._mesh.getScene().onAfterCameraRenderObservable.remove(this._meshObserver);
  934. }
  935. this._mesh = value;
  936. if (this._mesh) {
  937. this._meshObserver = this._mesh.getScene().onAfterCameraRenderObservable.add(this._multiLine.onPointUpdate);
  938. }
  939. this._multiLine._markAsDirty();
  940. },
  941. enumerable: true,
  942. configurable: true
  943. });
  944. MultiLinePoint.prototype.translate = function () {
  945. this._point = this._translatePoint();
  946. return this._point;
  947. };
  948. MultiLinePoint.prototype._translatePoint = function () {
  949. if (this._mesh != null) {
  950. return this._multiLine._host.getProjectedPosition(this._mesh.getBoundingInfo().boundingSphere.center, this._mesh.getWorldMatrix());
  951. }
  952. else if (this._control != null) {
  953. return new BABYLON.Vector2(this._control.centerX, this._control.centerY);
  954. }
  955. else {
  956. var host = this._multiLine._host;
  957. var xValue = this._x.getValueInPixel(host, Number(host._canvas.width));
  958. var yValue = this._y.getValueInPixel(host, Number(host._canvas.height));
  959. return new BABYLON.Vector2(xValue, yValue);
  960. }
  961. };
  962. MultiLinePoint.prototype.dispose = function () {
  963. this.control = null;
  964. this.mesh = null;
  965. };
  966. return MultiLinePoint;
  967. }());
  968. GUI.MultiLinePoint = MultiLinePoint;
  969. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  970. })(BABYLON || (BABYLON = {}));
  971. //# sourceMappingURL=multiLinePoint.js.map
  972. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  973. var BABYLON;
  974. (function (BABYLON) {
  975. var GUI;
  976. (function (GUI) {
  977. var Control = /** @class */ (function () {
  978. // Functions
  979. function Control(name) {
  980. this.name = name;
  981. this._alpha = 1;
  982. this._alphaSet = false;
  983. this._zIndex = 0;
  984. this._currentMeasure = GUI.Measure.Empty();
  985. this._fontFamily = "Arial";
  986. this._fontStyle = "";
  987. this._fontSize = new GUI.ValueAndUnit(18, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  988. this._width = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  989. this._height = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  990. this._color = "";
  991. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  992. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  993. this._isDirty = true;
  994. this._tempParentMeasure = GUI.Measure.Empty();
  995. this._cachedParentMeasure = GUI.Measure.Empty();
  996. this._paddingLeft = new GUI.ValueAndUnit(0);
  997. this._paddingRight = new GUI.ValueAndUnit(0);
  998. this._paddingTop = new GUI.ValueAndUnit(0);
  999. this._paddingBottom = new GUI.ValueAndUnit(0);
  1000. this._left = new GUI.ValueAndUnit(0);
  1001. this._top = new GUI.ValueAndUnit(0);
  1002. this._scaleX = 1.0;
  1003. this._scaleY = 1.0;
  1004. this._rotation = 0;
  1005. this._transformCenterX = 0.5;
  1006. this._transformCenterY = 0.5;
  1007. this._transformMatrix = GUI.Matrix2D.Identity();
  1008. this._invertTransformMatrix = GUI.Matrix2D.Identity();
  1009. this._transformedPosition = BABYLON.Vector2.Zero();
  1010. this._onlyMeasureMode = false;
  1011. this._isMatrixDirty = true;
  1012. this._isVisible = true;
  1013. this._fontSet = false;
  1014. this._dummyVector2 = BABYLON.Vector2.Zero();
  1015. this._downCount = 0;
  1016. this._enterCount = 0;
  1017. this._doNotRender = false;
  1018. this._downPointerIds = {};
  1019. this.isHitTestVisible = true;
  1020. this.isPointerBlocker = false;
  1021. this.isFocusInvisible = false;
  1022. this.shadowOffsetX = 0;
  1023. this.shadowOffsetY = 0;
  1024. this.shadowBlur = 0;
  1025. this.shadowColor = '#000';
  1026. this._linkOffsetX = new GUI.ValueAndUnit(0);
  1027. this._linkOffsetY = new GUI.ValueAndUnit(0);
  1028. /**
  1029. * An event triggered when the pointer move over the control.
  1030. */
  1031. this.onPointerMoveObservable = new BABYLON.Observable();
  1032. /**
  1033. * An event triggered when the pointer move out of the control.
  1034. */
  1035. this.onPointerOutObservable = new BABYLON.Observable();
  1036. /**
  1037. * An event triggered when the pointer taps the control
  1038. */
  1039. this.onPointerDownObservable = new BABYLON.Observable();
  1040. /**
  1041. * An event triggered when pointer up
  1042. */
  1043. this.onPointerUpObservable = new BABYLON.Observable();
  1044. /**
  1045. * An event triggered when a control is clicked on
  1046. */
  1047. this.onPointerClickObservable = new BABYLON.Observable();
  1048. /**
  1049. * An event triggered when pointer enters the control
  1050. */
  1051. this.onPointerEnterObservable = new BABYLON.Observable();
  1052. /**
  1053. * An event triggered when the control is marked as dirty
  1054. */
  1055. this.onDirtyObservable = new BABYLON.Observable();
  1056. /**
  1057. * An event triggered after the control is drawn
  1058. */
  1059. this.onAfterDrawObservable = new BABYLON.Observable();
  1060. }
  1061. Object.defineProperty(Control.prototype, "typeName", {
  1062. // Properties
  1063. get: function () {
  1064. return this._getTypeName();
  1065. },
  1066. enumerable: true,
  1067. configurable: true
  1068. });
  1069. Object.defineProperty(Control.prototype, "fontOffset", {
  1070. /** Gets or set information about font offsets (used to render and align text) */
  1071. get: function () {
  1072. return this._fontOffset;
  1073. },
  1074. set: function (offset) {
  1075. this._fontOffset = offset;
  1076. },
  1077. enumerable: true,
  1078. configurable: true
  1079. });
  1080. Object.defineProperty(Control.prototype, "alpha", {
  1081. get: function () {
  1082. return this._alpha;
  1083. },
  1084. set: function (value) {
  1085. if (this._alpha === value) {
  1086. return;
  1087. }
  1088. this._alphaSet = true;
  1089. this._alpha = value;
  1090. this._markAsDirty();
  1091. },
  1092. enumerable: true,
  1093. configurable: true
  1094. });
  1095. Object.defineProperty(Control.prototype, "scaleX", {
  1096. get: function () {
  1097. return this._scaleX;
  1098. },
  1099. set: function (value) {
  1100. if (this._scaleX === value) {
  1101. return;
  1102. }
  1103. this._scaleX = value;
  1104. this._markAsDirty();
  1105. this._markMatrixAsDirty();
  1106. },
  1107. enumerable: true,
  1108. configurable: true
  1109. });
  1110. Object.defineProperty(Control.prototype, "scaleY", {
  1111. get: function () {
  1112. return this._scaleY;
  1113. },
  1114. set: function (value) {
  1115. if (this._scaleY === value) {
  1116. return;
  1117. }
  1118. this._scaleY = value;
  1119. this._markAsDirty();
  1120. this._markMatrixAsDirty();
  1121. },
  1122. enumerable: true,
  1123. configurable: true
  1124. });
  1125. Object.defineProperty(Control.prototype, "rotation", {
  1126. get: function () {
  1127. return this._rotation;
  1128. },
  1129. set: function (value) {
  1130. if (this._rotation === value) {
  1131. return;
  1132. }
  1133. this._rotation = value;
  1134. this._markAsDirty();
  1135. this._markMatrixAsDirty();
  1136. },
  1137. enumerable: true,
  1138. configurable: true
  1139. });
  1140. Object.defineProperty(Control.prototype, "transformCenterY", {
  1141. get: function () {
  1142. return this._transformCenterY;
  1143. },
  1144. set: function (value) {
  1145. if (this._transformCenterY === value) {
  1146. return;
  1147. }
  1148. this._transformCenterY = value;
  1149. this._markAsDirty();
  1150. this._markMatrixAsDirty();
  1151. },
  1152. enumerable: true,
  1153. configurable: true
  1154. });
  1155. Object.defineProperty(Control.prototype, "transformCenterX", {
  1156. get: function () {
  1157. return this._transformCenterX;
  1158. },
  1159. set: function (value) {
  1160. if (this._transformCenterX === value) {
  1161. return;
  1162. }
  1163. this._transformCenterX = value;
  1164. this._markAsDirty();
  1165. this._markMatrixAsDirty();
  1166. },
  1167. enumerable: true,
  1168. configurable: true
  1169. });
  1170. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  1171. get: function () {
  1172. return this._horizontalAlignment;
  1173. },
  1174. set: function (value) {
  1175. if (this._horizontalAlignment === value) {
  1176. return;
  1177. }
  1178. this._horizontalAlignment = value;
  1179. this._markAsDirty();
  1180. },
  1181. enumerable: true,
  1182. configurable: true
  1183. });
  1184. Object.defineProperty(Control.prototype, "verticalAlignment", {
  1185. get: function () {
  1186. return this._verticalAlignment;
  1187. },
  1188. set: function (value) {
  1189. if (this._verticalAlignment === value) {
  1190. return;
  1191. }
  1192. this._verticalAlignment = value;
  1193. this._markAsDirty();
  1194. },
  1195. enumerable: true,
  1196. configurable: true
  1197. });
  1198. Object.defineProperty(Control.prototype, "width", {
  1199. get: function () {
  1200. return this._width.toString(this._host);
  1201. },
  1202. set: function (value) {
  1203. if (this._width.toString(this._host) === value) {
  1204. return;
  1205. }
  1206. if (this._width.fromString(value)) {
  1207. this._markAsDirty();
  1208. }
  1209. },
  1210. enumerable: true,
  1211. configurable: true
  1212. });
  1213. Object.defineProperty(Control.prototype, "widthInPixels", {
  1214. get: function () {
  1215. return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1216. },
  1217. enumerable: true,
  1218. configurable: true
  1219. });
  1220. Object.defineProperty(Control.prototype, "height", {
  1221. get: function () {
  1222. return this._height.toString(this._host);
  1223. },
  1224. set: function (value) {
  1225. if (this._height.toString(this._host) === value) {
  1226. return;
  1227. }
  1228. if (this._height.fromString(value)) {
  1229. this._markAsDirty();
  1230. }
  1231. },
  1232. enumerable: true,
  1233. configurable: true
  1234. });
  1235. Object.defineProperty(Control.prototype, "heightInPixels", {
  1236. get: function () {
  1237. return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1238. },
  1239. enumerable: true,
  1240. configurable: true
  1241. });
  1242. Object.defineProperty(Control.prototype, "fontFamily", {
  1243. get: function () {
  1244. return this._fontFamily;
  1245. },
  1246. set: function (value) {
  1247. if (this._fontFamily === value) {
  1248. return;
  1249. }
  1250. this._fontFamily = value;
  1251. this._fontSet = true;
  1252. },
  1253. enumerable: true,
  1254. configurable: true
  1255. });
  1256. Object.defineProperty(Control.prototype, "fontStyle", {
  1257. get: function () {
  1258. return this._fontStyle;
  1259. },
  1260. set: function (value) {
  1261. if (this._fontStyle === value) {
  1262. return;
  1263. }
  1264. this._fontStyle = value;
  1265. this._fontSet = true;
  1266. },
  1267. enumerable: true,
  1268. configurable: true
  1269. });
  1270. Object.defineProperty(Control.prototype, "_isFontSizeInPercentage", {
  1271. /** @hidden */
  1272. get: function () {
  1273. return this._fontSize.isPercentage;
  1274. },
  1275. enumerable: true,
  1276. configurable: true
  1277. });
  1278. Object.defineProperty(Control.prototype, "fontSizeInPixels", {
  1279. get: function () {
  1280. if (this._fontSize.isPixel) {
  1281. return this._fontSize.getValue(this._host);
  1282. }
  1283. return this._fontSize.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
  1284. },
  1285. enumerable: true,
  1286. configurable: true
  1287. });
  1288. Object.defineProperty(Control.prototype, "fontSize", {
  1289. get: function () {
  1290. return this._fontSize.toString(this._host);
  1291. },
  1292. set: function (value) {
  1293. if (this._fontSize.toString(this._host) === value) {
  1294. return;
  1295. }
  1296. if (this._fontSize.fromString(value)) {
  1297. this._markAsDirty();
  1298. this._fontSet = true;
  1299. }
  1300. },
  1301. enumerable: true,
  1302. configurable: true
  1303. });
  1304. Object.defineProperty(Control.prototype, "color", {
  1305. get: function () {
  1306. return this._color;
  1307. },
  1308. set: function (value) {
  1309. if (this._color === value) {
  1310. return;
  1311. }
  1312. this._color = value;
  1313. this._markAsDirty();
  1314. },
  1315. enumerable: true,
  1316. configurable: true
  1317. });
  1318. Object.defineProperty(Control.prototype, "zIndex", {
  1319. get: function () {
  1320. return this._zIndex;
  1321. },
  1322. set: function (value) {
  1323. if (this.zIndex === value) {
  1324. return;
  1325. }
  1326. this._zIndex = value;
  1327. if (this._root) {
  1328. this._root._reOrderControl(this);
  1329. }
  1330. },
  1331. enumerable: true,
  1332. configurable: true
  1333. });
  1334. Object.defineProperty(Control.prototype, "notRenderable", {
  1335. get: function () {
  1336. return this._doNotRender;
  1337. },
  1338. set: function (value) {
  1339. if (this._doNotRender === value) {
  1340. return;
  1341. }
  1342. this._doNotRender = value;
  1343. this._markAsDirty();
  1344. },
  1345. enumerable: true,
  1346. configurable: true
  1347. });
  1348. Object.defineProperty(Control.prototype, "isVisible", {
  1349. get: function () {
  1350. return this._isVisible;
  1351. },
  1352. set: function (value) {
  1353. if (this._isVisible === value) {
  1354. return;
  1355. }
  1356. this._isVisible = value;
  1357. this._markAsDirty();
  1358. },
  1359. enumerable: true,
  1360. configurable: true
  1361. });
  1362. Object.defineProperty(Control.prototype, "isDirty", {
  1363. get: function () {
  1364. return this._isDirty;
  1365. },
  1366. enumerable: true,
  1367. configurable: true
  1368. });
  1369. Object.defineProperty(Control.prototype, "paddingLeft", {
  1370. get: function () {
  1371. return this._paddingLeft.toString(this._host);
  1372. },
  1373. set: function (value) {
  1374. if (this._paddingLeft.fromString(value)) {
  1375. this._markAsDirty();
  1376. }
  1377. },
  1378. enumerable: true,
  1379. configurable: true
  1380. });
  1381. Object.defineProperty(Control.prototype, "paddingLeftInPixels", {
  1382. get: function () {
  1383. return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1384. },
  1385. enumerable: true,
  1386. configurable: true
  1387. });
  1388. Object.defineProperty(Control.prototype, "paddingRight", {
  1389. get: function () {
  1390. return this._paddingRight.toString(this._host);
  1391. },
  1392. set: function (value) {
  1393. if (this._paddingRight.fromString(value)) {
  1394. this._markAsDirty();
  1395. }
  1396. },
  1397. enumerable: true,
  1398. configurable: true
  1399. });
  1400. Object.defineProperty(Control.prototype, "paddingRightInPixels", {
  1401. get: function () {
  1402. return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1403. },
  1404. enumerable: true,
  1405. configurable: true
  1406. });
  1407. Object.defineProperty(Control.prototype, "paddingTop", {
  1408. get: function () {
  1409. return this._paddingTop.toString(this._host);
  1410. },
  1411. set: function (value) {
  1412. if (this._paddingTop.fromString(value)) {
  1413. this._markAsDirty();
  1414. }
  1415. },
  1416. enumerable: true,
  1417. configurable: true
  1418. });
  1419. Object.defineProperty(Control.prototype, "paddingTopInPixels", {
  1420. get: function () {
  1421. return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1422. },
  1423. enumerable: true,
  1424. configurable: true
  1425. });
  1426. Object.defineProperty(Control.prototype, "paddingBottom", {
  1427. get: function () {
  1428. return this._paddingBottom.toString(this._host);
  1429. },
  1430. set: function (value) {
  1431. if (this._paddingBottom.fromString(value)) {
  1432. this._markAsDirty();
  1433. }
  1434. },
  1435. enumerable: true,
  1436. configurable: true
  1437. });
  1438. Object.defineProperty(Control.prototype, "paddingBottomInPixels", {
  1439. get: function () {
  1440. return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1441. },
  1442. enumerable: true,
  1443. configurable: true
  1444. });
  1445. Object.defineProperty(Control.prototype, "left", {
  1446. get: function () {
  1447. return this._left.toString(this._host);
  1448. },
  1449. set: function (value) {
  1450. if (this._left.fromString(value)) {
  1451. this._markAsDirty();
  1452. }
  1453. },
  1454. enumerable: true,
  1455. configurable: true
  1456. });
  1457. Object.defineProperty(Control.prototype, "leftInPixels", {
  1458. get: function () {
  1459. return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1460. },
  1461. enumerable: true,
  1462. configurable: true
  1463. });
  1464. Object.defineProperty(Control.prototype, "top", {
  1465. get: function () {
  1466. return this._top.toString(this._host);
  1467. },
  1468. set: function (value) {
  1469. if (this._top.fromString(value)) {
  1470. this._markAsDirty();
  1471. }
  1472. },
  1473. enumerable: true,
  1474. configurable: true
  1475. });
  1476. Object.defineProperty(Control.prototype, "topInPixels", {
  1477. get: function () {
  1478. return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1479. },
  1480. enumerable: true,
  1481. configurable: true
  1482. });
  1483. Object.defineProperty(Control.prototype, "linkOffsetX", {
  1484. get: function () {
  1485. return this._linkOffsetX.toString(this._host);
  1486. },
  1487. set: function (value) {
  1488. if (this._linkOffsetX.fromString(value)) {
  1489. this._markAsDirty();
  1490. }
  1491. },
  1492. enumerable: true,
  1493. configurable: true
  1494. });
  1495. Object.defineProperty(Control.prototype, "linkOffsetXInPixels", {
  1496. get: function () {
  1497. return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1498. },
  1499. enumerable: true,
  1500. configurable: true
  1501. });
  1502. Object.defineProperty(Control.prototype, "linkOffsetY", {
  1503. get: function () {
  1504. return this._linkOffsetY.toString(this._host);
  1505. },
  1506. set: function (value) {
  1507. if (this._linkOffsetY.fromString(value)) {
  1508. this._markAsDirty();
  1509. }
  1510. },
  1511. enumerable: true,
  1512. configurable: true
  1513. });
  1514. Object.defineProperty(Control.prototype, "linkOffsetYInPixels", {
  1515. get: function () {
  1516. return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1517. },
  1518. enumerable: true,
  1519. configurable: true
  1520. });
  1521. Object.defineProperty(Control.prototype, "centerX", {
  1522. get: function () {
  1523. return this._currentMeasure.left + this._currentMeasure.width / 2;
  1524. },
  1525. enumerable: true,
  1526. configurable: true
  1527. });
  1528. Object.defineProperty(Control.prototype, "centerY", {
  1529. get: function () {
  1530. return this._currentMeasure.top + this._currentMeasure.height / 2;
  1531. },
  1532. enumerable: true,
  1533. configurable: true
  1534. });
  1535. Control.prototype._getTypeName = function () {
  1536. return "Control";
  1537. };
  1538. /** @hidden */
  1539. Control.prototype._resetFontCache = function () {
  1540. this._fontSet = true;
  1541. };
  1542. Control.prototype.getLocalCoordinates = function (globalCoordinates) {
  1543. var result = BABYLON.Vector2.Zero();
  1544. this.getLocalCoordinatesToRef(globalCoordinates, result);
  1545. return result;
  1546. };
  1547. Control.prototype.getLocalCoordinatesToRef = function (globalCoordinates, result) {
  1548. result.x = globalCoordinates.x - this._currentMeasure.left;
  1549. result.y = globalCoordinates.y - this._currentMeasure.top;
  1550. return this;
  1551. };
  1552. Control.prototype.getParentLocalCoordinates = function (globalCoordinates) {
  1553. var result = BABYLON.Vector2.Zero();
  1554. result.x = globalCoordinates.x - this._cachedParentMeasure.left;
  1555. result.y = globalCoordinates.y - this._cachedParentMeasure.top;
  1556. return result;
  1557. };
  1558. Control.prototype.moveToVector3 = function (position, scene) {
  1559. if (!this._host || this._root !== this._host._rootContainer) {
  1560. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  1561. return;
  1562. }
  1563. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1564. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1565. var globalViewport = this._host._getGlobalViewport(scene);
  1566. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  1567. this._moveToProjectedPosition(projectedPosition);
  1568. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  1569. this.notRenderable = true;
  1570. return;
  1571. }
  1572. this.notRenderable = false;
  1573. };
  1574. Control.prototype.linkWithMesh = function (mesh) {
  1575. if (!this._host || this._root && this._root !== this._host._rootContainer) {
  1576. if (mesh) {
  1577. BABYLON.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
  1578. }
  1579. return;
  1580. }
  1581. var index = this._host._linkedControls.indexOf(this);
  1582. if (index !== -1) {
  1583. this._linkedMesh = mesh;
  1584. if (!mesh) {
  1585. this._host._linkedControls.splice(index, 1);
  1586. }
  1587. return;
  1588. }
  1589. else if (!mesh) {
  1590. return;
  1591. }
  1592. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1593. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1594. this._linkedMesh = mesh;
  1595. this._onlyMeasureMode = true;
  1596. this._host._linkedControls.push(this);
  1597. };
  1598. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  1599. var oldLeft = this._left.getValue(this._host);
  1600. var oldTop = this._top.getValue(this._host);
  1601. var newLeft = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2);
  1602. var newTop = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2);
  1603. if (this._left.ignoreAdaptiveScaling && this._top.ignoreAdaptiveScaling) {
  1604. if (Math.abs(newLeft - oldLeft) < 0.5) {
  1605. newLeft = oldLeft;
  1606. }
  1607. if (Math.abs(newTop - oldTop) < 0.5) {
  1608. newTop = oldTop;
  1609. }
  1610. }
  1611. this.left = newLeft + "px";
  1612. this.top = newTop + "px";
  1613. this._left.ignoreAdaptiveScaling = true;
  1614. this._top.ignoreAdaptiveScaling = true;
  1615. };
  1616. Control.prototype._markMatrixAsDirty = function () {
  1617. this._isMatrixDirty = true;
  1618. this._markAsDirty();
  1619. };
  1620. Control.prototype._markAsDirty = function () {
  1621. this._isDirty = true;
  1622. if (!this._host) {
  1623. return; // Not yet connected
  1624. }
  1625. this._host.markAsDirty();
  1626. };
  1627. Control.prototype._markAllAsDirty = function () {
  1628. this._markAsDirty();
  1629. if (this._font) {
  1630. this._prepareFont();
  1631. }
  1632. };
  1633. Control.prototype._link = function (root, host) {
  1634. this._root = root;
  1635. this._host = host;
  1636. };
  1637. Control.prototype._transform = function (context) {
  1638. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  1639. return;
  1640. }
  1641. // postTranslate
  1642. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  1643. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  1644. context.translate(offsetX, offsetY);
  1645. // rotate
  1646. context.rotate(this._rotation);
  1647. // scale
  1648. context.scale(this._scaleX, this._scaleY);
  1649. // preTranslate
  1650. context.translate(-offsetX, -offsetY);
  1651. // Need to update matrices?
  1652. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  1653. this._cachedOffsetX = offsetX;
  1654. this._cachedOffsetY = offsetY;
  1655. this._isMatrixDirty = false;
  1656. GUI.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  1657. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  1658. }
  1659. };
  1660. Control.prototype._applyStates = function (context) {
  1661. if (this._fontSet) {
  1662. this._prepareFont();
  1663. this._fontSet = false;
  1664. }
  1665. if (this._font) {
  1666. context.font = this._font;
  1667. }
  1668. if (this._color) {
  1669. context.fillStyle = this._color;
  1670. }
  1671. if (this._alphaSet) {
  1672. context.globalAlpha = this._alpha;
  1673. }
  1674. };
  1675. Control.prototype._processMeasures = function (parentMeasure, context) {
  1676. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  1677. this._isDirty = false;
  1678. this._currentMeasure.copyFrom(parentMeasure);
  1679. // Let children take some pre-measurement actions
  1680. this._preMeasure(parentMeasure, context);
  1681. this._measure();
  1682. this._computeAlignment(parentMeasure, context);
  1683. // Convert to int values
  1684. this._currentMeasure.left = this._currentMeasure.left | 0;
  1685. this._currentMeasure.top = this._currentMeasure.top | 0;
  1686. this._currentMeasure.width = this._currentMeasure.width | 0;
  1687. this._currentMeasure.height = this._currentMeasure.height | 0;
  1688. // Let children add more features
  1689. this._additionalProcessing(parentMeasure, context);
  1690. this._cachedParentMeasure.copyFrom(parentMeasure);
  1691. if (this.onDirtyObservable.hasObservers()) {
  1692. this.onDirtyObservable.notifyObservers(this);
  1693. }
  1694. }
  1695. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  1696. return false;
  1697. }
  1698. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  1699. return false;
  1700. }
  1701. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  1702. return false;
  1703. }
  1704. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  1705. return false;
  1706. }
  1707. // Transform
  1708. this._transform(context);
  1709. if (this._onlyMeasureMode) {
  1710. this._onlyMeasureMode = false;
  1711. return false; // We do not want rendering for this frame as they are measure dependant information that need to be gathered
  1712. }
  1713. // Clip
  1714. this._clip(context);
  1715. context.clip();
  1716. return true;
  1717. };
  1718. Control.prototype._clip = function (context) {
  1719. context.beginPath();
  1720. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1721. var shadowOffsetX = this.shadowOffsetX;
  1722. var shadowOffsetY = this.shadowOffsetY;
  1723. var shadowBlur = this.shadowBlur;
  1724. var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
  1725. var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
  1726. var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
  1727. var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
  1728. context.rect(this._currentMeasure.left + leftShadowOffset, this._currentMeasure.top + topShadowOffset, this._currentMeasure.width + rightShadowOffset - leftShadowOffset, this._currentMeasure.height + bottomShadowOffset - topShadowOffset);
  1729. }
  1730. else {
  1731. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1732. }
  1733. };
  1734. Control.prototype._measure = function () {
  1735. // Width / Height
  1736. if (this._width.isPixel) {
  1737. this._currentMeasure.width = this._width.getValue(this._host);
  1738. }
  1739. else {
  1740. this._currentMeasure.width *= this._width.getValue(this._host);
  1741. }
  1742. if (this._height.isPixel) {
  1743. this._currentMeasure.height = this._height.getValue(this._host);
  1744. }
  1745. else {
  1746. this._currentMeasure.height *= this._height.getValue(this._host);
  1747. }
  1748. };
  1749. Control.prototype._computeAlignment = function (parentMeasure, context) {
  1750. var width = this._currentMeasure.width;
  1751. var height = this._currentMeasure.height;
  1752. var parentWidth = parentMeasure.width;
  1753. var parentHeight = parentMeasure.height;
  1754. // Left / top
  1755. var x = 0;
  1756. var y = 0;
  1757. switch (this.horizontalAlignment) {
  1758. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  1759. x = 0;
  1760. break;
  1761. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1762. x = parentWidth - width;
  1763. break;
  1764. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  1765. x = (parentWidth - width) / 2;
  1766. break;
  1767. }
  1768. switch (this.verticalAlignment) {
  1769. case Control.VERTICAL_ALIGNMENT_TOP:
  1770. y = 0;
  1771. break;
  1772. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  1773. y = parentHeight - height;
  1774. break;
  1775. case Control.VERTICAL_ALIGNMENT_CENTER:
  1776. y = (parentHeight - height) / 2;
  1777. break;
  1778. }
  1779. if (this._paddingLeft.isPixel) {
  1780. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  1781. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  1782. }
  1783. else {
  1784. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  1785. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  1786. }
  1787. if (this._paddingRight.isPixel) {
  1788. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  1789. }
  1790. else {
  1791. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  1792. }
  1793. if (this._paddingTop.isPixel) {
  1794. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  1795. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  1796. }
  1797. else {
  1798. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  1799. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  1800. }
  1801. if (this._paddingBottom.isPixel) {
  1802. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  1803. }
  1804. else {
  1805. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  1806. }
  1807. if (this._left.isPixel) {
  1808. this._currentMeasure.left += this._left.getValue(this._host);
  1809. }
  1810. else {
  1811. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  1812. }
  1813. if (this._top.isPixel) {
  1814. this._currentMeasure.top += this._top.getValue(this._host);
  1815. }
  1816. else {
  1817. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  1818. }
  1819. this._currentMeasure.left += x;
  1820. this._currentMeasure.top += y;
  1821. };
  1822. Control.prototype._preMeasure = function (parentMeasure, context) {
  1823. // Do nothing
  1824. };
  1825. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  1826. // Do nothing
  1827. };
  1828. Control.prototype._draw = function (parentMeasure, context) {
  1829. // Do nothing
  1830. };
  1831. Control.prototype.contains = function (x, y) {
  1832. // Invert transform
  1833. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  1834. x = this._transformedPosition.x;
  1835. y = this._transformedPosition.y;
  1836. // Check
  1837. if (x < this._currentMeasure.left) {
  1838. return false;
  1839. }
  1840. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  1841. return false;
  1842. }
  1843. if (y < this._currentMeasure.top) {
  1844. return false;
  1845. }
  1846. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  1847. return false;
  1848. }
  1849. if (this.isPointerBlocker) {
  1850. this._host._shouldBlockPointer = true;
  1851. }
  1852. return true;
  1853. };
  1854. Control.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  1855. if (!this.isHitTestVisible || !this.isVisible || this._doNotRender) {
  1856. return false;
  1857. }
  1858. if (!this.contains(x, y)) {
  1859. return false;
  1860. }
  1861. this._processObservables(type, x, y, pointerId, buttonIndex);
  1862. return true;
  1863. };
  1864. Control.prototype._onPointerMove = function (target, coordinates) {
  1865. var canNotify = this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  1866. if (canNotify && this.parent != null)
  1867. this.parent._onPointerMove(target, coordinates);
  1868. };
  1869. Control.prototype._onPointerEnter = function (target) {
  1870. if (this._enterCount !== 0) {
  1871. return false;
  1872. }
  1873. this._enterCount++;
  1874. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  1875. if (canNotify && this.parent != null)
  1876. this.parent._onPointerEnter(target);
  1877. return true;
  1878. };
  1879. Control.prototype._onPointerOut = function (target) {
  1880. this._enterCount = 0;
  1881. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  1882. if (canNotify && this.parent != null)
  1883. this.parent._onPointerOut(target);
  1884. };
  1885. Control.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1886. if (this._downCount !== 0) {
  1887. return false;
  1888. }
  1889. this._downCount++;
  1890. this._downPointerIds[pointerId] = true;
  1891. var canNotify = this.onPointerDownObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1892. if (canNotify && this.parent != null)
  1893. this.parent._onPointerDown(target, coordinates, pointerId, buttonIndex);
  1894. return true;
  1895. };
  1896. Control.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  1897. this._downCount = 0;
  1898. delete this._downPointerIds[pointerId];
  1899. var canNotifyClick = notifyClick;
  1900. if (notifyClick && this._enterCount > 0) {
  1901. canNotifyClick = this.onPointerClickObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1902. }
  1903. var canNotify = this.onPointerUpObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1904. if (canNotify && this.parent != null)
  1905. this.parent._onPointerUp(target, coordinates, pointerId, buttonIndex, canNotifyClick);
  1906. };
  1907. Control.prototype.forcePointerUp = function (pointerId) {
  1908. if (pointerId === void 0) { pointerId = null; }
  1909. if (pointerId !== null) {
  1910. this._onPointerUp(this, BABYLON.Vector2.Zero(), pointerId, 0, true);
  1911. }
  1912. else {
  1913. for (var key in this._downPointerIds) {
  1914. this._onPointerUp(this, BABYLON.Vector2.Zero(), +key, 0, true);
  1915. }
  1916. }
  1917. };
  1918. Control.prototype._processObservables = function (type, x, y, pointerId, buttonIndex) {
  1919. this._dummyVector2.copyFromFloats(x, y);
  1920. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  1921. this._onPointerMove(this, this._dummyVector2);
  1922. var previousControlOver = this._host._lastControlOver[pointerId];
  1923. if (previousControlOver && previousControlOver !== this) {
  1924. previousControlOver._onPointerOut(this);
  1925. }
  1926. if (previousControlOver !== this) {
  1927. this._onPointerEnter(this);
  1928. }
  1929. this._host._lastControlOver[pointerId] = this;
  1930. return true;
  1931. }
  1932. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  1933. this._onPointerDown(this, this._dummyVector2, pointerId, buttonIndex);
  1934. this._host._lastControlDown[pointerId] = this;
  1935. this._host._lastPickedControl = this;
  1936. return true;
  1937. }
  1938. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  1939. if (this._host._lastControlDown[pointerId]) {
  1940. this._host._lastControlDown[pointerId]._onPointerUp(this, this._dummyVector2, pointerId, buttonIndex, true);
  1941. }
  1942. delete this._host._lastControlDown[pointerId];
  1943. return true;
  1944. }
  1945. return false;
  1946. };
  1947. Control.prototype._prepareFont = function () {
  1948. if (!this._font && !this._fontSet) {
  1949. return;
  1950. }
  1951. this._font = this._fontStyle + " " + this.fontSizeInPixels + "px " + this._fontFamily;
  1952. this._fontOffset = Control._GetFontOffset(this._font);
  1953. };
  1954. Control.prototype.dispose = function () {
  1955. this.onDirtyObservable.clear();
  1956. this.onAfterDrawObservable.clear();
  1957. this.onPointerDownObservable.clear();
  1958. this.onPointerEnterObservable.clear();
  1959. this.onPointerMoveObservable.clear();
  1960. this.onPointerOutObservable.clear();
  1961. this.onPointerUpObservable.clear();
  1962. this.onPointerClickObservable.clear();
  1963. if (this._root) {
  1964. this._root.removeControl(this);
  1965. this._root = null;
  1966. }
  1967. var index = this._host._linkedControls.indexOf(this);
  1968. if (index > -1) {
  1969. this.linkWithMesh(null);
  1970. }
  1971. };
  1972. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  1973. get: function () {
  1974. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  1975. },
  1976. enumerable: true,
  1977. configurable: true
  1978. });
  1979. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  1980. get: function () {
  1981. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  1982. },
  1983. enumerable: true,
  1984. configurable: true
  1985. });
  1986. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  1987. get: function () {
  1988. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  1989. },
  1990. enumerable: true,
  1991. configurable: true
  1992. });
  1993. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  1994. get: function () {
  1995. return Control._VERTICAL_ALIGNMENT_TOP;
  1996. },
  1997. enumerable: true,
  1998. configurable: true
  1999. });
  2000. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  2001. get: function () {
  2002. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  2003. },
  2004. enumerable: true,
  2005. configurable: true
  2006. });
  2007. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  2008. get: function () {
  2009. return Control._VERTICAL_ALIGNMENT_CENTER;
  2010. },
  2011. enumerable: true,
  2012. configurable: true
  2013. });
  2014. Control._GetFontOffset = function (font) {
  2015. if (Control._FontHeightSizes[font]) {
  2016. return Control._FontHeightSizes[font];
  2017. }
  2018. var text = document.createElement("span");
  2019. text.innerHTML = "Hg";
  2020. text.style.font = font;
  2021. var block = document.createElement("div");
  2022. block.style.display = "inline-block";
  2023. block.style.width = "1px";
  2024. block.style.height = "0px";
  2025. block.style.verticalAlign = "bottom";
  2026. var div = document.createElement("div");
  2027. div.appendChild(text);
  2028. div.appendChild(block);
  2029. document.body.appendChild(div);
  2030. var fontAscent = 0;
  2031. var fontHeight = 0;
  2032. try {
  2033. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2034. block.style.verticalAlign = "baseline";
  2035. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2036. }
  2037. finally {
  2038. document.body.removeChild(div);
  2039. }
  2040. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  2041. Control._FontHeightSizes[font] = result;
  2042. return result;
  2043. };
  2044. ;
  2045. Control.AddHeader = function (control, text, size, options) {
  2046. var panel = new BABYLON.GUI.StackPanel("panel");
  2047. var isHorizontal = options ? options.isHorizontal : true;
  2048. var controlFirst = options ? options.controlFirst : true;
  2049. panel.isVertical = !isHorizontal;
  2050. var header = new BABYLON.GUI.TextBlock("header");
  2051. header.text = text;
  2052. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  2053. if (isHorizontal) {
  2054. header.width = size;
  2055. }
  2056. else {
  2057. header.height = size;
  2058. }
  2059. if (controlFirst) {
  2060. panel.addControl(control);
  2061. panel.addControl(header);
  2062. header.paddingLeft = "5px";
  2063. }
  2064. else {
  2065. panel.addControl(header);
  2066. panel.addControl(control);
  2067. header.paddingRight = "5px";
  2068. }
  2069. header.shadowBlur = control.shadowBlur;
  2070. header.shadowColor = control.shadowColor;
  2071. header.shadowOffsetX = control.shadowOffsetX;
  2072. header.shadowOffsetY = control.shadowOffsetY;
  2073. return panel;
  2074. };
  2075. Control.drawEllipse = function (x, y, width, height, context) {
  2076. context.translate(x, y);
  2077. context.scale(width, height);
  2078. context.beginPath();
  2079. context.arc(0, 0, 1, 0, 2 * Math.PI);
  2080. context.closePath();
  2081. context.scale(1 / width, 1 / height);
  2082. context.translate(-x, -y);
  2083. };
  2084. // Statics
  2085. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  2086. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  2087. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  2088. Control._VERTICAL_ALIGNMENT_TOP = 0;
  2089. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  2090. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  2091. Control._FontHeightSizes = {};
  2092. return Control;
  2093. }());
  2094. GUI.Control = Control;
  2095. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2096. })(BABYLON || (BABYLON = {}));
  2097. //# sourceMappingURL=control.js.map
  2098. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2099. var BABYLON;
  2100. (function (BABYLON) {
  2101. var GUI;
  2102. (function (GUI) {
  2103. var Container = /** @class */ (function (_super) {
  2104. __extends(Container, _super);
  2105. function Container(name) {
  2106. var _this = _super.call(this, name) || this;
  2107. _this.name = name;
  2108. _this._children = new Array();
  2109. _this._measureForChildren = GUI.Measure.Empty();
  2110. _this._adaptWidthToChildren = false;
  2111. _this._adaptHeightToChildren = false;
  2112. return _this;
  2113. }
  2114. Object.defineProperty(Container.prototype, "adaptHeightToChildren", {
  2115. get: function () {
  2116. return this._adaptHeightToChildren;
  2117. },
  2118. set: function (value) {
  2119. if (this._adaptHeightToChildren === value) {
  2120. return;
  2121. }
  2122. this._adaptHeightToChildren = value;
  2123. if (value) {
  2124. this.height = "100%";
  2125. }
  2126. this._markAsDirty();
  2127. },
  2128. enumerable: true,
  2129. configurable: true
  2130. });
  2131. Object.defineProperty(Container.prototype, "adaptWidthToChildren", {
  2132. get: function () {
  2133. return this._adaptWidthToChildren;
  2134. },
  2135. set: function (value) {
  2136. if (this._adaptWidthToChildren === value) {
  2137. return;
  2138. }
  2139. this._adaptWidthToChildren = value;
  2140. if (value) {
  2141. this.width = "100%";
  2142. }
  2143. this._markAsDirty();
  2144. },
  2145. enumerable: true,
  2146. configurable: true
  2147. });
  2148. Object.defineProperty(Container.prototype, "background", {
  2149. get: function () {
  2150. return this._background;
  2151. },
  2152. set: function (value) {
  2153. if (this._background === value) {
  2154. return;
  2155. }
  2156. this._background = value;
  2157. this._markAsDirty();
  2158. },
  2159. enumerable: true,
  2160. configurable: true
  2161. });
  2162. Object.defineProperty(Container.prototype, "children", {
  2163. get: function () {
  2164. return this._children;
  2165. },
  2166. enumerable: true,
  2167. configurable: true
  2168. });
  2169. Container.prototype._getTypeName = function () {
  2170. return "Container";
  2171. };
  2172. Container.prototype.getChildByName = function (name) {
  2173. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2174. var child = _a[_i];
  2175. if (child.name === name) {
  2176. return child;
  2177. }
  2178. }
  2179. return null;
  2180. };
  2181. Container.prototype.getChildByType = function (name, type) {
  2182. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2183. var child = _a[_i];
  2184. if (child.typeName === type) {
  2185. return child;
  2186. }
  2187. }
  2188. return null;
  2189. };
  2190. Container.prototype.containsControl = function (control) {
  2191. return this._children.indexOf(control) !== -1;
  2192. };
  2193. Container.prototype.addControl = function (control) {
  2194. var index = this._children.indexOf(control);
  2195. if (index !== -1) {
  2196. return this;
  2197. }
  2198. control._link(this, this._host);
  2199. control._markAllAsDirty();
  2200. this._reOrderControl(control);
  2201. this._markAsDirty();
  2202. return this;
  2203. };
  2204. Container.prototype.removeControl = function (control) {
  2205. var index = this._children.indexOf(control);
  2206. if (index !== -1) {
  2207. this._children.splice(index, 1);
  2208. control.parent = null;
  2209. }
  2210. control.linkWithMesh(null);
  2211. if (this._host) {
  2212. this._host._cleanControlAfterRemoval(control);
  2213. }
  2214. this._markAsDirty();
  2215. return this;
  2216. };
  2217. Container.prototype._reOrderControl = function (control) {
  2218. this.removeControl(control);
  2219. for (var index = 0; index < this._children.length; index++) {
  2220. if (this._children[index].zIndex > control.zIndex) {
  2221. this._children.splice(index, 0, control);
  2222. return;
  2223. }
  2224. }
  2225. this._children.push(control);
  2226. control.parent = this;
  2227. this._markAsDirty();
  2228. };
  2229. Container.prototype._markMatrixAsDirty = function () {
  2230. _super.prototype._markMatrixAsDirty.call(this);
  2231. for (var index = 0; index < this._children.length; index++) {
  2232. this._children[index]._markMatrixAsDirty();
  2233. }
  2234. };
  2235. Container.prototype._markAllAsDirty = function () {
  2236. _super.prototype._markAllAsDirty.call(this);
  2237. for (var index = 0; index < this._children.length; index++) {
  2238. this._children[index]._markAllAsDirty();
  2239. }
  2240. };
  2241. Container.prototype._localDraw = function (context) {
  2242. if (this._background) {
  2243. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2244. context.shadowColor = this.shadowColor;
  2245. context.shadowBlur = this.shadowBlur;
  2246. context.shadowOffsetX = this.shadowOffsetX;
  2247. context.shadowOffsetY = this.shadowOffsetY;
  2248. }
  2249. context.fillStyle = this._background;
  2250. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2251. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2252. context.shadowBlur = 0;
  2253. context.shadowOffsetX = 0;
  2254. context.shadowOffsetY = 0;
  2255. }
  2256. }
  2257. };
  2258. Container.prototype._link = function (root, host) {
  2259. _super.prototype._link.call(this, root, host);
  2260. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2261. var child = _a[_i];
  2262. child._link(root, host);
  2263. }
  2264. };
  2265. Container.prototype._draw = function (parentMeasure, context) {
  2266. if (!this.isVisible || this.notRenderable) {
  2267. return;
  2268. }
  2269. context.save();
  2270. this._applyStates(context);
  2271. if (this._processMeasures(parentMeasure, context)) {
  2272. this._localDraw(context);
  2273. this._clipForChildren(context);
  2274. var computedWidth = -1;
  2275. var computedHeight = -1;
  2276. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2277. var child = _a[_i];
  2278. if (child.isVisible && !child.notRenderable) {
  2279. child._tempParentMeasure.copyFrom(this._measureForChildren);
  2280. child._draw(this._measureForChildren, context);
  2281. if (child.onAfterDrawObservable.hasObservers()) {
  2282. child.onAfterDrawObservable.notifyObservers(child);
  2283. }
  2284. if (this.adaptWidthToChildren && child._width.isPixel) {
  2285. computedWidth = Math.max(computedWidth, child._currentMeasure.width);
  2286. }
  2287. if (this.adaptHeightToChildren && child._height.isPixel) {
  2288. computedHeight = Math.max(computedHeight, child._currentMeasure.height);
  2289. }
  2290. }
  2291. }
  2292. if (this.adaptWidthToChildren && computedWidth >= 0) {
  2293. this.width = computedWidth + "px";
  2294. }
  2295. if (this.adaptHeightToChildren && computedHeight >= 0) {
  2296. this.height = computedHeight + "px";
  2297. }
  2298. }
  2299. context.restore();
  2300. if (this.onAfterDrawObservable.hasObservers()) {
  2301. this.onAfterDrawObservable.notifyObservers(this);
  2302. }
  2303. };
  2304. Container.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  2305. if (!this.isVisible || this.notRenderable) {
  2306. return false;
  2307. }
  2308. if (!_super.prototype.contains.call(this, x, y)) {
  2309. return false;
  2310. }
  2311. // Checking backwards to pick closest first
  2312. for (var index = this._children.length - 1; index >= 0; index--) {
  2313. var child = this._children[index];
  2314. if (child._processPicking(x, y, type, pointerId, buttonIndex)) {
  2315. return true;
  2316. }
  2317. }
  2318. if (!this.isHitTestVisible) {
  2319. return false;
  2320. }
  2321. return this._processObservables(type, x, y, pointerId, buttonIndex);
  2322. };
  2323. Container.prototype._clipForChildren = function (context) {
  2324. // DO nothing
  2325. };
  2326. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  2327. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2328. this._measureForChildren.copyFrom(this._currentMeasure);
  2329. };
  2330. Container.prototype.dispose = function () {
  2331. _super.prototype.dispose.call(this);
  2332. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2333. var control = _a[_i];
  2334. control.dispose();
  2335. }
  2336. };
  2337. return Container;
  2338. }(GUI.Control));
  2339. GUI.Container = Container;
  2340. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2341. })(BABYLON || (BABYLON = {}));
  2342. //# sourceMappingURL=container.js.map
  2343. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2344. var BABYLON;
  2345. (function (BABYLON) {
  2346. var GUI;
  2347. (function (GUI) {
  2348. var StackPanel = /** @class */ (function (_super) {
  2349. __extends(StackPanel, _super);
  2350. function StackPanel(name) {
  2351. var _this = _super.call(this, name) || this;
  2352. _this.name = name;
  2353. _this._isVertical = true;
  2354. _this._manualWidth = false;
  2355. _this._manualHeight = false;
  2356. _this._doNotTrackManualChanges = false;
  2357. _this._tempMeasureStore = GUI.Measure.Empty();
  2358. return _this;
  2359. }
  2360. Object.defineProperty(StackPanel.prototype, "isVertical", {
  2361. get: function () {
  2362. return this._isVertical;
  2363. },
  2364. set: function (value) {
  2365. if (this._isVertical === value) {
  2366. return;
  2367. }
  2368. this._isVertical = value;
  2369. this._markAsDirty();
  2370. },
  2371. enumerable: true,
  2372. configurable: true
  2373. });
  2374. Object.defineProperty(StackPanel.prototype, "width", {
  2375. get: function () {
  2376. return this._width.toString(this._host);
  2377. },
  2378. set: function (value) {
  2379. if (!this._doNotTrackManualChanges) {
  2380. this._manualWidth = true;
  2381. }
  2382. if (this._width.toString(this._host) === value) {
  2383. return;
  2384. }
  2385. if (this._width.fromString(value)) {
  2386. this._markAsDirty();
  2387. }
  2388. },
  2389. enumerable: true,
  2390. configurable: true
  2391. });
  2392. Object.defineProperty(StackPanel.prototype, "height", {
  2393. get: function () {
  2394. return this._height.toString(this._host);
  2395. },
  2396. set: function (value) {
  2397. if (!this._doNotTrackManualChanges) {
  2398. this._manualHeight = true;
  2399. }
  2400. if (this._height.toString(this._host) === value) {
  2401. return;
  2402. }
  2403. if (this._height.fromString(value)) {
  2404. this._markAsDirty();
  2405. }
  2406. },
  2407. enumerable: true,
  2408. configurable: true
  2409. });
  2410. StackPanel.prototype._getTypeName = function () {
  2411. return "StackPanel";
  2412. };
  2413. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  2414. var stackWidth = 0;
  2415. var stackHeight = 0;
  2416. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2417. var child = _a[_i];
  2418. this._tempMeasureStore.copyFrom(child._currentMeasure);
  2419. child._currentMeasure.copyFrom(parentMeasure);
  2420. child._measure();
  2421. if (this._isVertical) {
  2422. child.top = stackHeight + "px";
  2423. if (!child._top.ignoreAdaptiveScaling) {
  2424. child._markAsDirty();
  2425. }
  2426. child._top.ignoreAdaptiveScaling = true;
  2427. stackHeight += child._currentMeasure.height;
  2428. if (child._currentMeasure.width > stackWidth) {
  2429. stackWidth = child._currentMeasure.width;
  2430. }
  2431. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2432. }
  2433. else {
  2434. child.left = stackWidth + "px";
  2435. if (!child._left.ignoreAdaptiveScaling) {
  2436. child._markAsDirty();
  2437. }
  2438. child._left.ignoreAdaptiveScaling = true;
  2439. stackWidth += child._currentMeasure.width;
  2440. if (child._currentMeasure.height > stackHeight) {
  2441. stackHeight = child._currentMeasure.height;
  2442. }
  2443. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2444. }
  2445. child._currentMeasure.copyFrom(this._tempMeasureStore);
  2446. }
  2447. this._doNotTrackManualChanges = true;
  2448. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  2449. // User can now define their own height and width for stack panel.
  2450. var panelWidthChanged = false;
  2451. var panelHeightChanged = false;
  2452. var previousHeight = this.height;
  2453. var previousWidth = this.width;
  2454. if (!this._manualHeight) {
  2455. // do not specify height if strictly defined by user
  2456. this.height = stackHeight + "px";
  2457. }
  2458. if (!this._manualWidth) {
  2459. // do not specify width if strictly defined by user
  2460. this.width = stackWidth + "px";
  2461. }
  2462. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  2463. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  2464. if (panelHeightChanged) {
  2465. this._height.ignoreAdaptiveScaling = true;
  2466. }
  2467. if (panelWidthChanged) {
  2468. this._width.ignoreAdaptiveScaling = true;
  2469. }
  2470. this._doNotTrackManualChanges = false;
  2471. if (panelWidthChanged || panelHeightChanged) {
  2472. this._markAllAsDirty();
  2473. }
  2474. _super.prototype._preMeasure.call(this, parentMeasure, context);
  2475. };
  2476. return StackPanel;
  2477. }(GUI.Container));
  2478. GUI.StackPanel = StackPanel;
  2479. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2480. })(BABYLON || (BABYLON = {}));
  2481. //# sourceMappingURL=stackPanel.js.map
  2482. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2483. var BABYLON;
  2484. (function (BABYLON) {
  2485. var GUI;
  2486. (function (GUI) {
  2487. var Rectangle = /** @class */ (function (_super) {
  2488. __extends(Rectangle, _super);
  2489. function Rectangle(name) {
  2490. var _this = _super.call(this, name) || this;
  2491. _this.name = name;
  2492. _this._thickness = 1;
  2493. _this._cornerRadius = 0;
  2494. return _this;
  2495. }
  2496. Object.defineProperty(Rectangle.prototype, "thickness", {
  2497. get: function () {
  2498. return this._thickness;
  2499. },
  2500. set: function (value) {
  2501. if (this._thickness === value) {
  2502. return;
  2503. }
  2504. this._thickness = value;
  2505. this._markAsDirty();
  2506. },
  2507. enumerable: true,
  2508. configurable: true
  2509. });
  2510. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  2511. get: function () {
  2512. return this._cornerRadius;
  2513. },
  2514. set: function (value) {
  2515. if (value < 0) {
  2516. value = 0;
  2517. }
  2518. if (this._cornerRadius === value) {
  2519. return;
  2520. }
  2521. this._cornerRadius = value;
  2522. this._markAsDirty();
  2523. },
  2524. enumerable: true,
  2525. configurable: true
  2526. });
  2527. Rectangle.prototype._getTypeName = function () {
  2528. return "Rectangle";
  2529. };
  2530. Rectangle.prototype._localDraw = function (context) {
  2531. context.save();
  2532. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2533. context.shadowColor = this.shadowColor;
  2534. context.shadowBlur = this.shadowBlur;
  2535. context.shadowOffsetX = this.shadowOffsetX;
  2536. context.shadowOffsetY = this.shadowOffsetY;
  2537. }
  2538. if (this._background) {
  2539. context.fillStyle = this._background;
  2540. if (this._cornerRadius) {
  2541. this._drawRoundedRect(context, this._thickness / 2);
  2542. context.fill();
  2543. }
  2544. else {
  2545. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2546. }
  2547. }
  2548. if (this._thickness) {
  2549. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2550. context.shadowBlur = 0;
  2551. context.shadowOffsetX = 0;
  2552. context.shadowOffsetY = 0;
  2553. }
  2554. if (this.color) {
  2555. context.strokeStyle = this.color;
  2556. }
  2557. context.lineWidth = this._thickness;
  2558. if (this._cornerRadius) {
  2559. this._drawRoundedRect(context, this._thickness / 2);
  2560. context.stroke();
  2561. }
  2562. else {
  2563. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  2564. }
  2565. }
  2566. context.restore();
  2567. };
  2568. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  2569. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2570. this._measureForChildren.width -= 2 * this._thickness;
  2571. this._measureForChildren.height -= 2 * this._thickness;
  2572. this._measureForChildren.left += this._thickness;
  2573. this._measureForChildren.top += this._thickness;
  2574. };
  2575. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  2576. if (offset === void 0) { offset = 0; }
  2577. var x = this._currentMeasure.left + offset;
  2578. var y = this._currentMeasure.top + offset;
  2579. var width = this._currentMeasure.width - offset * 2;
  2580. var height = this._currentMeasure.height - offset * 2;
  2581. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  2582. context.beginPath();
  2583. context.moveTo(x + radius, y);
  2584. context.lineTo(x + width - radius, y);
  2585. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  2586. context.lineTo(x + width, y + height - radius);
  2587. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  2588. context.lineTo(x + radius, y + height);
  2589. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  2590. context.lineTo(x, y + radius);
  2591. context.quadraticCurveTo(x, y, x + radius, y);
  2592. context.closePath();
  2593. };
  2594. Rectangle.prototype._clipForChildren = function (context) {
  2595. if (this._cornerRadius) {
  2596. this._drawRoundedRect(context, this._thickness);
  2597. context.clip();
  2598. }
  2599. };
  2600. return Rectangle;
  2601. }(GUI.Container));
  2602. GUI.Rectangle = Rectangle;
  2603. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2604. })(BABYLON || (BABYLON = {}));
  2605. //# sourceMappingURL=rectangle.js.map
  2606. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2607. var BABYLON;
  2608. (function (BABYLON) {
  2609. var GUI;
  2610. (function (GUI) {
  2611. var Ellipse = /** @class */ (function (_super) {
  2612. __extends(Ellipse, _super);
  2613. function Ellipse(name) {
  2614. var _this = _super.call(this, name) || this;
  2615. _this.name = name;
  2616. _this._thickness = 1;
  2617. return _this;
  2618. }
  2619. Object.defineProperty(Ellipse.prototype, "thickness", {
  2620. get: function () {
  2621. return this._thickness;
  2622. },
  2623. set: function (value) {
  2624. if (this._thickness === value) {
  2625. return;
  2626. }
  2627. this._thickness = value;
  2628. this._markAsDirty();
  2629. },
  2630. enumerable: true,
  2631. configurable: true
  2632. });
  2633. Ellipse.prototype._getTypeName = function () {
  2634. return "Ellipse";
  2635. };
  2636. Ellipse.prototype._localDraw = function (context) {
  2637. context.save();
  2638. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2639. context.shadowColor = this.shadowColor;
  2640. context.shadowBlur = this.shadowBlur;
  2641. context.shadowOffsetX = this.shadowOffsetX;
  2642. context.shadowOffsetY = this.shadowOffsetY;
  2643. }
  2644. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2 - this._thickness / 2, this._currentMeasure.height / 2 - this._thickness / 2, context);
  2645. if (this._background) {
  2646. context.fillStyle = this._background;
  2647. context.fill();
  2648. }
  2649. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2650. context.shadowBlur = 0;
  2651. context.shadowOffsetX = 0;
  2652. context.shadowOffsetY = 0;
  2653. }
  2654. if (this._thickness) {
  2655. if (this.color) {
  2656. context.strokeStyle = this.color;
  2657. }
  2658. context.lineWidth = this._thickness;
  2659. context.stroke();
  2660. }
  2661. context.restore();
  2662. };
  2663. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  2664. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2665. this._measureForChildren.width -= 2 * this._thickness;
  2666. this._measureForChildren.height -= 2 * this._thickness;
  2667. this._measureForChildren.left += this._thickness;
  2668. this._measureForChildren.top += this._thickness;
  2669. };
  2670. Ellipse.prototype._clipForChildren = function (context) {
  2671. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2, this._currentMeasure.height / 2, context);
  2672. context.clip();
  2673. };
  2674. return Ellipse;
  2675. }(GUI.Container));
  2676. GUI.Ellipse = Ellipse;
  2677. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2678. })(BABYLON || (BABYLON = {}));
  2679. //# sourceMappingURL=ellipse.js.map
  2680. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2681. var BABYLON;
  2682. (function (BABYLON) {
  2683. var GUI;
  2684. (function (GUI) {
  2685. var Line = /** @class */ (function (_super) {
  2686. __extends(Line, _super);
  2687. function Line(name) {
  2688. var _this = _super.call(this, name) || this;
  2689. _this.name = name;
  2690. _this._lineWidth = 1;
  2691. _this._x1 = new GUI.ValueAndUnit(0);
  2692. _this._y1 = new GUI.ValueAndUnit(0);
  2693. _this._x2 = new GUI.ValueAndUnit(0);
  2694. _this._y2 = new GUI.ValueAndUnit(0);
  2695. _this._dash = new Array();
  2696. _this.isHitTestVisible = false;
  2697. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2698. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2699. return _this;
  2700. }
  2701. Object.defineProperty(Line.prototype, "dash", {
  2702. get: function () {
  2703. return this._dash;
  2704. },
  2705. set: function (value) {
  2706. if (this._dash === value) {
  2707. return;
  2708. }
  2709. this._dash = value;
  2710. this._markAsDirty();
  2711. },
  2712. enumerable: true,
  2713. configurable: true
  2714. });
  2715. Object.defineProperty(Line.prototype, "connectedControl", {
  2716. get: function () {
  2717. return this._connectedControl;
  2718. },
  2719. set: function (value) {
  2720. var _this = this;
  2721. if (this._connectedControl === value) {
  2722. return;
  2723. }
  2724. if (this._connectedControlDirtyObserver && this._connectedControl) {
  2725. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  2726. this._connectedControlDirtyObserver = null;
  2727. }
  2728. if (value) {
  2729. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  2730. }
  2731. this._connectedControl = value;
  2732. this._markAsDirty();
  2733. },
  2734. enumerable: true,
  2735. configurable: true
  2736. });
  2737. Object.defineProperty(Line.prototype, "x1", {
  2738. get: function () {
  2739. return this._x1.toString(this._host);
  2740. },
  2741. set: function (value) {
  2742. if (this._x1.toString(this._host) === value) {
  2743. return;
  2744. }
  2745. if (this._x1.fromString(value)) {
  2746. this._markAsDirty();
  2747. }
  2748. },
  2749. enumerable: true,
  2750. configurable: true
  2751. });
  2752. Object.defineProperty(Line.prototype, "y1", {
  2753. get: function () {
  2754. return this._y1.toString(this._host);
  2755. },
  2756. set: function (value) {
  2757. if (this._y1.toString(this._host) === value) {
  2758. return;
  2759. }
  2760. if (this._y1.fromString(value)) {
  2761. this._markAsDirty();
  2762. }
  2763. },
  2764. enumerable: true,
  2765. configurable: true
  2766. });
  2767. Object.defineProperty(Line.prototype, "x2", {
  2768. get: function () {
  2769. return this._x2.toString(this._host);
  2770. },
  2771. set: function (value) {
  2772. if (this._x2.toString(this._host) === value) {
  2773. return;
  2774. }
  2775. if (this._x2.fromString(value)) {
  2776. this._markAsDirty();
  2777. }
  2778. },
  2779. enumerable: true,
  2780. configurable: true
  2781. });
  2782. Object.defineProperty(Line.prototype, "y2", {
  2783. get: function () {
  2784. return this._y2.toString(this._host);
  2785. },
  2786. set: function (value) {
  2787. if (this._y2.toString(this._host) === value) {
  2788. return;
  2789. }
  2790. if (this._y2.fromString(value)) {
  2791. this._markAsDirty();
  2792. }
  2793. },
  2794. enumerable: true,
  2795. configurable: true
  2796. });
  2797. Object.defineProperty(Line.prototype, "lineWidth", {
  2798. get: function () {
  2799. return this._lineWidth;
  2800. },
  2801. set: function (value) {
  2802. if (this._lineWidth === value) {
  2803. return;
  2804. }
  2805. this._lineWidth = value;
  2806. this._markAsDirty();
  2807. },
  2808. enumerable: true,
  2809. configurable: true
  2810. });
  2811. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  2812. set: function (value) {
  2813. return;
  2814. },
  2815. enumerable: true,
  2816. configurable: true
  2817. });
  2818. Object.defineProperty(Line.prototype, "verticalAlignment", {
  2819. set: function (value) {
  2820. return;
  2821. },
  2822. enumerable: true,
  2823. configurable: true
  2824. });
  2825. Object.defineProperty(Line.prototype, "_effectiveX2", {
  2826. get: function () {
  2827. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  2828. },
  2829. enumerable: true,
  2830. configurable: true
  2831. });
  2832. Object.defineProperty(Line.prototype, "_effectiveY2", {
  2833. get: function () {
  2834. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  2835. },
  2836. enumerable: true,
  2837. configurable: true
  2838. });
  2839. Line.prototype._getTypeName = function () {
  2840. return "Line";
  2841. };
  2842. Line.prototype._draw = function (parentMeasure, context) {
  2843. context.save();
  2844. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2845. context.shadowColor = this.shadowColor;
  2846. context.shadowBlur = this.shadowBlur;
  2847. context.shadowOffsetX = this.shadowOffsetX;
  2848. context.shadowOffsetY = this.shadowOffsetY;
  2849. }
  2850. this._applyStates(context);
  2851. if (this._processMeasures(parentMeasure, context)) {
  2852. context.strokeStyle = this.color;
  2853. context.lineWidth = this._lineWidth;
  2854. context.setLineDash(this._dash);
  2855. context.beginPath();
  2856. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  2857. context.lineTo(this._effectiveX2, this._effectiveY2);
  2858. context.stroke();
  2859. }
  2860. context.restore();
  2861. };
  2862. Line.prototype._measure = function () {
  2863. // Width / Height
  2864. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  2865. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  2866. };
  2867. Line.prototype._computeAlignment = function (parentMeasure, context) {
  2868. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  2869. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  2870. };
  2871. /**
  2872. * Move one end of the line given 3D cartesian coordinates.
  2873. * @param position Targeted world position
  2874. * @param scene Scene
  2875. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  2876. */
  2877. Line.prototype.moveToVector3 = function (position, scene, end) {
  2878. if (end === void 0) { end = false; }
  2879. if (!this._host || this._root !== this._host._rootContainer) {
  2880. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  2881. return;
  2882. }
  2883. var globalViewport = this._host._getGlobalViewport(scene);
  2884. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  2885. this._moveToProjectedPosition(projectedPosition, end);
  2886. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  2887. this.notRenderable = true;
  2888. return;
  2889. }
  2890. this.notRenderable = false;
  2891. };
  2892. /**
  2893. * Move one end of the line to a position in screen absolute space.
  2894. * @param projectedPosition Position in screen absolute space (X, Y)
  2895. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  2896. */
  2897. Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
  2898. if (end === void 0) { end = false; }
  2899. var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  2900. var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  2901. if (end) {
  2902. this.x2 = x;
  2903. this.y2 = y;
  2904. this._x2.ignoreAdaptiveScaling = true;
  2905. this._y2.ignoreAdaptiveScaling = true;
  2906. }
  2907. else {
  2908. this.x1 = x;
  2909. this.y1 = y;
  2910. this._x1.ignoreAdaptiveScaling = true;
  2911. this._y1.ignoreAdaptiveScaling = true;
  2912. }
  2913. };
  2914. return Line;
  2915. }(GUI.Control));
  2916. GUI.Line = Line;
  2917. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2918. })(BABYLON || (BABYLON = {}));
  2919. //# sourceMappingURL=line.js.map
  2920. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2921. var BABYLON;
  2922. (function (BABYLON) {
  2923. var GUI;
  2924. (function (GUI) {
  2925. var Slider = /** @class */ (function (_super) {
  2926. __extends(Slider, _super);
  2927. function Slider(name) {
  2928. var _this = _super.call(this, name) || this;
  2929. _this.name = name;
  2930. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2931. _this._minimum = 0;
  2932. _this._maximum = 100;
  2933. _this._value = 50;
  2934. _this._background = "black";
  2935. _this._borderColor = "white";
  2936. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2937. _this._isThumbCircle = false;
  2938. _this._isThumbClamped = false;
  2939. _this.onValueChangedObservable = new BABYLON.Observable();
  2940. // Events
  2941. _this._pointerIsDown = false;
  2942. _this.isPointerBlocker = true;
  2943. return _this;
  2944. }
  2945. Object.defineProperty(Slider.prototype, "borderColor", {
  2946. get: function () {
  2947. return this._borderColor;
  2948. },
  2949. set: function (value) {
  2950. if (this._borderColor === value) {
  2951. return;
  2952. }
  2953. this._borderColor = value;
  2954. this._markAsDirty();
  2955. },
  2956. enumerable: true,
  2957. configurable: true
  2958. });
  2959. Object.defineProperty(Slider.prototype, "background", {
  2960. get: function () {
  2961. return this._background;
  2962. },
  2963. set: function (value) {
  2964. if (this._background === value) {
  2965. return;
  2966. }
  2967. this._background = value;
  2968. this._markAsDirty();
  2969. },
  2970. enumerable: true,
  2971. configurable: true
  2972. });
  2973. Object.defineProperty(Slider.prototype, "barOffset", {
  2974. get: function () {
  2975. return this._barOffset.toString(this._host);
  2976. },
  2977. set: function (value) {
  2978. if (this._barOffset.toString(this._host) === value) {
  2979. return;
  2980. }
  2981. if (this._barOffset.fromString(value)) {
  2982. this._markAsDirty();
  2983. }
  2984. },
  2985. enumerable: true,
  2986. configurable: true
  2987. });
  2988. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  2989. get: function () {
  2990. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2991. },
  2992. enumerable: true,
  2993. configurable: true
  2994. });
  2995. Object.defineProperty(Slider.prototype, "thumbWidth", {
  2996. get: function () {
  2997. return this._thumbWidth.toString(this._host);
  2998. },
  2999. set: function (value) {
  3000. if (this._thumbWidth.toString(this._host) === value) {
  3001. return;
  3002. }
  3003. if (this._thumbWidth.fromString(value)) {
  3004. this._markAsDirty();
  3005. }
  3006. },
  3007. enumerable: true,
  3008. configurable: true
  3009. });
  3010. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  3011. get: function () {
  3012. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3013. },
  3014. enumerable: true,
  3015. configurable: true
  3016. });
  3017. Object.defineProperty(Slider.prototype, "minimum", {
  3018. get: function () {
  3019. return this._minimum;
  3020. },
  3021. set: function (value) {
  3022. if (this._minimum === value) {
  3023. return;
  3024. }
  3025. this._minimum = value;
  3026. this._markAsDirty();
  3027. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3028. },
  3029. enumerable: true,
  3030. configurable: true
  3031. });
  3032. Object.defineProperty(Slider.prototype, "maximum", {
  3033. get: function () {
  3034. return this._maximum;
  3035. },
  3036. set: function (value) {
  3037. if (this._maximum === value) {
  3038. return;
  3039. }
  3040. this._maximum = value;
  3041. this._markAsDirty();
  3042. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3043. },
  3044. enumerable: true,
  3045. configurable: true
  3046. });
  3047. Object.defineProperty(Slider.prototype, "value", {
  3048. get: function () {
  3049. return this._value;
  3050. },
  3051. set: function (value) {
  3052. value = Math.max(Math.min(value, this._maximum), this._minimum);
  3053. if (this._value === value) {
  3054. return;
  3055. }
  3056. this._value = value;
  3057. this._markAsDirty();
  3058. this.onValueChangedObservable.notifyObservers(this._value);
  3059. },
  3060. enumerable: true,
  3061. configurable: true
  3062. });
  3063. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  3064. get: function () {
  3065. return this._isThumbCircle;
  3066. },
  3067. set: function (value) {
  3068. if (this._isThumbCircle === value) {
  3069. return;
  3070. }
  3071. this._isThumbCircle = value;
  3072. this._markAsDirty();
  3073. },
  3074. enumerable: true,
  3075. configurable: true
  3076. });
  3077. Object.defineProperty(Slider.prototype, "isThumbClamped", {
  3078. get: function () {
  3079. return this._isThumbClamped;
  3080. },
  3081. set: function (value) {
  3082. if (this._isThumbClamped === value) {
  3083. return;
  3084. }
  3085. this._isThumbClamped = value;
  3086. this._markAsDirty();
  3087. },
  3088. enumerable: true,
  3089. configurable: true
  3090. });
  3091. Slider.prototype._getTypeName = function () {
  3092. return "Slider";
  3093. };
  3094. Slider.prototype._draw = function (parentMeasure, context) {
  3095. context.save();
  3096. this._applyStates(context);
  3097. if (this._processMeasures(parentMeasure, context)) {
  3098. // Main bar
  3099. var effectiveThumbWidth;
  3100. var effectiveBarOffset;
  3101. if (this._thumbWidth.isPixel) {
  3102. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
  3103. }
  3104. else {
  3105. effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
  3106. }
  3107. if (this._barOffset.isPixel) {
  3108. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  3109. }
  3110. else {
  3111. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  3112. }
  3113. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3114. context.shadowColor = this.shadowColor;
  3115. context.shadowBlur = this.shadowBlur;
  3116. context.shadowOffsetX = this.shadowOffsetX;
  3117. context.shadowOffsetY = this.shadowOffsetY;
  3118. }
  3119. var left = this._currentMeasure.left;
  3120. var width = this._currentMeasure.width - effectiveThumbWidth;
  3121. var thumbPosition = ((this._value - this._minimum) / (this._maximum - this._minimum)) * width;
  3122. context.fillStyle = this._background;
  3123. if (this.isThumbClamped) {
  3124. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
  3125. }
  3126. else {
  3127. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  3128. }
  3129. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3130. context.shadowBlur = 0;
  3131. context.shadowOffsetX = 0;
  3132. context.shadowOffsetY = 0;
  3133. }
  3134. context.fillStyle = this.color;
  3135. if (this.isThumbClamped) {
  3136. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3137. }
  3138. else {
  3139. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3140. }
  3141. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3142. context.shadowColor = this.shadowColor;
  3143. context.shadowBlur = this.shadowBlur;
  3144. context.shadowOffsetX = this.shadowOffsetX;
  3145. context.shadowOffsetY = this.shadowOffsetY;
  3146. }
  3147. if (this._isThumbCircle) {
  3148. context.beginPath();
  3149. context.arc(left + thumbPosition + (effectiveThumbWidth / 2), this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
  3150. context.fill();
  3151. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3152. context.shadowBlur = 0;
  3153. context.shadowOffsetX = 0;
  3154. context.shadowOffsetY = 0;
  3155. }
  3156. context.strokeStyle = this._borderColor;
  3157. context.stroke();
  3158. }
  3159. else {
  3160. context.fillRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3161. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3162. context.shadowBlur = 0;
  3163. context.shadowOffsetX = 0;
  3164. context.shadowOffsetY = 0;
  3165. }
  3166. context.strokeStyle = this._borderColor;
  3167. context.strokeRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3168. }
  3169. }
  3170. context.restore();
  3171. };
  3172. Slider.prototype._updateValueFromPointer = function (x, y) {
  3173. if (this.rotation != 0) {
  3174. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  3175. x = this._transformedPosition.x;
  3176. }
  3177. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  3178. };
  3179. Slider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3180. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3181. return false;
  3182. }
  3183. this._pointerIsDown = true;
  3184. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3185. this._host._capturingControl[pointerId] = this;
  3186. return true;
  3187. };
  3188. Slider.prototype._onPointerMove = function (target, coordinates) {
  3189. if (this._pointerIsDown) {
  3190. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3191. }
  3192. _super.prototype._onPointerMove.call(this, target, coordinates);
  3193. };
  3194. Slider.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  3195. this._pointerIsDown = false;
  3196. delete this._host._capturingControl[pointerId];
  3197. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  3198. };
  3199. return Slider;
  3200. }(GUI.Control));
  3201. GUI.Slider = Slider;
  3202. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3203. })(BABYLON || (BABYLON = {}));
  3204. //# sourceMappingURL=slider.js.map
  3205. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3206. var BABYLON;
  3207. (function (BABYLON) {
  3208. var GUI;
  3209. (function (GUI) {
  3210. var Checkbox = /** @class */ (function (_super) {
  3211. __extends(Checkbox, _super);
  3212. function Checkbox(name) {
  3213. var _this = _super.call(this, name) || this;
  3214. _this.name = name;
  3215. _this._isChecked = false;
  3216. _this._background = "black";
  3217. _this._checkSizeRatio = 0.8;
  3218. _this._thickness = 1;
  3219. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  3220. _this.isPointerBlocker = true;
  3221. return _this;
  3222. }
  3223. Object.defineProperty(Checkbox.prototype, "thickness", {
  3224. get: function () {
  3225. return this._thickness;
  3226. },
  3227. set: function (value) {
  3228. if (this._thickness === value) {
  3229. return;
  3230. }
  3231. this._thickness = value;
  3232. this._markAsDirty();
  3233. },
  3234. enumerable: true,
  3235. configurable: true
  3236. });
  3237. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  3238. get: function () {
  3239. return this._checkSizeRatio;
  3240. },
  3241. set: function (value) {
  3242. value = Math.max(Math.min(1, value), 0);
  3243. if (this._checkSizeRatio === value) {
  3244. return;
  3245. }
  3246. this._checkSizeRatio = value;
  3247. this._markAsDirty();
  3248. },
  3249. enumerable: true,
  3250. configurable: true
  3251. });
  3252. Object.defineProperty(Checkbox.prototype, "background", {
  3253. get: function () {
  3254. return this._background;
  3255. },
  3256. set: function (value) {
  3257. if (this._background === value) {
  3258. return;
  3259. }
  3260. this._background = value;
  3261. this._markAsDirty();
  3262. },
  3263. enumerable: true,
  3264. configurable: true
  3265. });
  3266. Object.defineProperty(Checkbox.prototype, "isChecked", {
  3267. get: function () {
  3268. return this._isChecked;
  3269. },
  3270. set: function (value) {
  3271. if (this._isChecked === value) {
  3272. return;
  3273. }
  3274. this._isChecked = value;
  3275. this._markAsDirty();
  3276. this.onIsCheckedChangedObservable.notifyObservers(value);
  3277. },
  3278. enumerable: true,
  3279. configurable: true
  3280. });
  3281. Checkbox.prototype._getTypeName = function () {
  3282. return "CheckBox";
  3283. };
  3284. Checkbox.prototype._draw = function (parentMeasure, context) {
  3285. context.save();
  3286. this._applyStates(context);
  3287. if (this._processMeasures(parentMeasure, context)) {
  3288. var actualWidth = this._currentMeasure.width - this._thickness;
  3289. var actualHeight = this._currentMeasure.height - this._thickness;
  3290. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3291. context.shadowColor = this.shadowColor;
  3292. context.shadowBlur = this.shadowBlur;
  3293. context.shadowOffsetX = this.shadowOffsetX;
  3294. context.shadowOffsetY = this.shadowOffsetY;
  3295. }
  3296. context.fillStyle = this._background;
  3297. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  3298. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3299. context.shadowBlur = 0;
  3300. context.shadowOffsetX = 0;
  3301. context.shadowOffsetY = 0;
  3302. }
  3303. if (this._isChecked) {
  3304. context.fillStyle = this.color;
  3305. var offsetWidth = actualWidth * this._checkSizeRatio;
  3306. var offseHeight = actualHeight * this._checkSizeRatio;
  3307. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  3308. }
  3309. context.strokeStyle = this.color;
  3310. context.lineWidth = this._thickness;
  3311. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  3312. }
  3313. context.restore();
  3314. };
  3315. // Events
  3316. Checkbox.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3317. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3318. return false;
  3319. }
  3320. this.isChecked = !this.isChecked;
  3321. return true;
  3322. };
  3323. return Checkbox;
  3324. }(GUI.Control));
  3325. GUI.Checkbox = Checkbox;
  3326. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3327. })(BABYLON || (BABYLON = {}));
  3328. //# sourceMappingURL=checkbox.js.map
  3329. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3330. var BABYLON;
  3331. (function (BABYLON) {
  3332. var GUI;
  3333. (function (GUI) {
  3334. var RadioButton = /** @class */ (function (_super) {
  3335. __extends(RadioButton, _super);
  3336. function RadioButton(name) {
  3337. var _this = _super.call(this, name) || this;
  3338. _this.name = name;
  3339. _this._isChecked = false;
  3340. _this._background = "black";
  3341. _this._checkSizeRatio = 0.8;
  3342. _this._thickness = 1;
  3343. _this.group = "";
  3344. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  3345. _this.isPointerBlocker = true;
  3346. return _this;
  3347. }
  3348. Object.defineProperty(RadioButton.prototype, "thickness", {
  3349. get: function () {
  3350. return this._thickness;
  3351. },
  3352. set: function (value) {
  3353. if (this._thickness === value) {
  3354. return;
  3355. }
  3356. this._thickness = value;
  3357. this._markAsDirty();
  3358. },
  3359. enumerable: true,
  3360. configurable: true
  3361. });
  3362. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  3363. get: function () {
  3364. return this._checkSizeRatio;
  3365. },
  3366. set: function (value) {
  3367. value = Math.max(Math.min(1, value), 0);
  3368. if (this._checkSizeRatio === value) {
  3369. return;
  3370. }
  3371. this._checkSizeRatio = value;
  3372. this._markAsDirty();
  3373. },
  3374. enumerable: true,
  3375. configurable: true
  3376. });
  3377. Object.defineProperty(RadioButton.prototype, "background", {
  3378. get: function () {
  3379. return this._background;
  3380. },
  3381. set: function (value) {
  3382. if (this._background === value) {
  3383. return;
  3384. }
  3385. this._background = value;
  3386. this._markAsDirty();
  3387. },
  3388. enumerable: true,
  3389. configurable: true
  3390. });
  3391. Object.defineProperty(RadioButton.prototype, "isChecked", {
  3392. get: function () {
  3393. return this._isChecked;
  3394. },
  3395. set: function (value) {
  3396. var _this = this;
  3397. if (this._isChecked === value) {
  3398. return;
  3399. }
  3400. this._isChecked = value;
  3401. this._markAsDirty();
  3402. this.onIsCheckedChangedObservable.notifyObservers(value);
  3403. if (this._isChecked) {
  3404. // Update all controls from same group
  3405. this._host.executeOnAllControls(function (control) {
  3406. if (control === _this) {
  3407. return;
  3408. }
  3409. if (control.group === undefined) {
  3410. return;
  3411. }
  3412. var childRadio = control;
  3413. if (childRadio.group === _this.group) {
  3414. childRadio.isChecked = false;
  3415. }
  3416. });
  3417. }
  3418. },
  3419. enumerable: true,
  3420. configurable: true
  3421. });
  3422. RadioButton.prototype._getTypeName = function () {
  3423. return "RadioButton";
  3424. };
  3425. RadioButton.prototype._draw = function (parentMeasure, context) {
  3426. context.save();
  3427. this._applyStates(context);
  3428. if (this._processMeasures(parentMeasure, context)) {
  3429. var actualWidth = this._currentMeasure.width - this._thickness;
  3430. var actualHeight = this._currentMeasure.height - this._thickness;
  3431. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3432. context.shadowColor = this.shadowColor;
  3433. context.shadowBlur = this.shadowBlur;
  3434. context.shadowOffsetX = this.shadowOffsetX;
  3435. context.shadowOffsetY = this.shadowOffsetY;
  3436. }
  3437. // Outer
  3438. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2 - this._thickness / 2, this._currentMeasure.height / 2 - this._thickness / 2, context);
  3439. context.fillStyle = this._background;
  3440. context.fill();
  3441. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3442. context.shadowBlur = 0;
  3443. context.shadowOffsetX = 0;
  3444. context.shadowOffsetY = 0;
  3445. }
  3446. context.strokeStyle = this.color;
  3447. context.lineWidth = this._thickness;
  3448. context.stroke();
  3449. // Inner
  3450. if (this._isChecked) {
  3451. context.fillStyle = this.color;
  3452. var offsetWidth = actualWidth * this._checkSizeRatio;
  3453. var offseHeight = actualHeight * this._checkSizeRatio;
  3454. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, offsetWidth / 2 - this._thickness / 2, offseHeight / 2 - this._thickness / 2, context);
  3455. context.fill();
  3456. }
  3457. }
  3458. context.restore();
  3459. };
  3460. // Events
  3461. RadioButton.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3462. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3463. return false;
  3464. }
  3465. if (!this.isChecked) {
  3466. this.isChecked = true;
  3467. }
  3468. return true;
  3469. };
  3470. return RadioButton;
  3471. }(GUI.Control));
  3472. GUI.RadioButton = RadioButton;
  3473. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3474. })(BABYLON || (BABYLON = {}));
  3475. //# sourceMappingURL=radioButton.js.map
  3476. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3477. var BABYLON;
  3478. (function (BABYLON) {
  3479. var GUI;
  3480. (function (GUI) {
  3481. var TextBlock = /** @class */ (function (_super) {
  3482. __extends(TextBlock, _super);
  3483. /**
  3484. * Creates a new TextBlock object
  3485. * @param name defines the name of the control
  3486. * @param text defines the text to display (emptry string by default)
  3487. */
  3488. function TextBlock(
  3489. /**
  3490. * Defines the name of the control
  3491. */
  3492. name, text) {
  3493. if (text === void 0) { text = ""; }
  3494. var _this = _super.call(this, name) || this;
  3495. _this.name = name;
  3496. _this._text = "";
  3497. _this._textWrapping = false;
  3498. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3499. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  3500. _this._resizeToFit = false;
  3501. _this._lineSpacing = new GUI.ValueAndUnit(0);
  3502. _this._outlineWidth = 0;
  3503. _this._outlineColor = "white";
  3504. /**
  3505. * An event triggered after the text is changed
  3506. */
  3507. _this.onTextChangedObservable = new BABYLON.Observable();
  3508. /**
  3509. * An event triggered after the text was broken up into lines
  3510. */
  3511. _this.onLinesReadyObservable = new BABYLON.Observable();
  3512. _this.text = text;
  3513. return _this;
  3514. }
  3515. Object.defineProperty(TextBlock.prototype, "lines", {
  3516. /**
  3517. * Return the line list (you may need to use the onLinesReadyObservable to make sure the list is ready)
  3518. */
  3519. get: function () {
  3520. return this._lines;
  3521. },
  3522. enumerable: true,
  3523. configurable: true
  3524. });
  3525. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  3526. /**
  3527. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  3528. */
  3529. get: function () {
  3530. return this._resizeToFit;
  3531. },
  3532. /**
  3533. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  3534. */
  3535. set: function (value) {
  3536. this._resizeToFit = value;
  3537. if (this._resizeToFit) {
  3538. this._width.ignoreAdaptiveScaling = true;
  3539. this._height.ignoreAdaptiveScaling = true;
  3540. }
  3541. },
  3542. enumerable: true,
  3543. configurable: true
  3544. });
  3545. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  3546. /**
  3547. * Gets or sets a boolean indicating if text must be wrapped
  3548. */
  3549. get: function () {
  3550. return this._textWrapping;
  3551. },
  3552. /**
  3553. * Gets or sets a boolean indicating if text must be wrapped
  3554. */
  3555. set: function (value) {
  3556. if (this._textWrapping === value) {
  3557. return;
  3558. }
  3559. this._textWrapping = value;
  3560. this._markAsDirty();
  3561. },
  3562. enumerable: true,
  3563. configurable: true
  3564. });
  3565. Object.defineProperty(TextBlock.prototype, "text", {
  3566. /**
  3567. * Gets or sets text to display
  3568. */
  3569. get: function () {
  3570. return this._text;
  3571. },
  3572. /**
  3573. * Gets or sets text to display
  3574. */
  3575. set: function (value) {
  3576. if (this._text === value) {
  3577. return;
  3578. }
  3579. this._text = value;
  3580. this._markAsDirty();
  3581. this.onTextChangedObservable.notifyObservers(this);
  3582. },
  3583. enumerable: true,
  3584. configurable: true
  3585. });
  3586. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  3587. /**
  3588. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  3589. */
  3590. get: function () {
  3591. return this._textHorizontalAlignment;
  3592. },
  3593. /**
  3594. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  3595. */
  3596. set: function (value) {
  3597. if (this._textHorizontalAlignment === value) {
  3598. return;
  3599. }
  3600. this._textHorizontalAlignment = value;
  3601. this._markAsDirty();
  3602. },
  3603. enumerable: true,
  3604. configurable: true
  3605. });
  3606. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  3607. /**
  3608. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  3609. */
  3610. get: function () {
  3611. return this._textVerticalAlignment;
  3612. },
  3613. /**
  3614. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  3615. */
  3616. set: function (value) {
  3617. if (this._textVerticalAlignment === value) {
  3618. return;
  3619. }
  3620. this._textVerticalAlignment = value;
  3621. this._markAsDirty();
  3622. },
  3623. enumerable: true,
  3624. configurable: true
  3625. });
  3626. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  3627. /**
  3628. * Gets or sets line spacing value
  3629. */
  3630. get: function () {
  3631. return this._lineSpacing.toString(this._host);
  3632. },
  3633. /**
  3634. * Gets or sets line spacing value
  3635. */
  3636. set: function (value) {
  3637. if (this._lineSpacing.fromString(value)) {
  3638. this._markAsDirty();
  3639. }
  3640. },
  3641. enumerable: true,
  3642. configurable: true
  3643. });
  3644. Object.defineProperty(TextBlock.prototype, "outlineWidth", {
  3645. /**
  3646. * Gets or sets outlineWidth of the text to display
  3647. */
  3648. get: function () {
  3649. return this._outlineWidth;
  3650. },
  3651. /**
  3652. * Gets or sets outlineWidth of the text to display
  3653. */
  3654. set: function (value) {
  3655. if (this._outlineWidth === value) {
  3656. return;
  3657. }
  3658. this._outlineWidth = value;
  3659. this._markAsDirty();
  3660. },
  3661. enumerable: true,
  3662. configurable: true
  3663. });
  3664. Object.defineProperty(TextBlock.prototype, "outlineColor", {
  3665. /**
  3666. * Gets or sets outlineColor of the text to display
  3667. */
  3668. get: function () {
  3669. return this._outlineColor;
  3670. },
  3671. /**
  3672. * Gets or sets outlineColor of the text to display
  3673. */
  3674. set: function (value) {
  3675. if (this._outlineColor === value) {
  3676. return;
  3677. }
  3678. this._outlineColor = value;
  3679. this._markAsDirty();
  3680. },
  3681. enumerable: true,
  3682. configurable: true
  3683. });
  3684. TextBlock.prototype._getTypeName = function () {
  3685. return "TextBlock";
  3686. };
  3687. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  3688. var width = this._currentMeasure.width;
  3689. var x = 0;
  3690. switch (this._textHorizontalAlignment) {
  3691. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  3692. x = 0;
  3693. break;
  3694. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  3695. x = width - textWidth;
  3696. break;
  3697. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  3698. x = (width - textWidth) / 2;
  3699. break;
  3700. }
  3701. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3702. context.shadowColor = this.shadowColor;
  3703. context.shadowBlur = this.shadowBlur;
  3704. context.shadowOffsetX = this.shadowOffsetX;
  3705. context.shadowOffsetY = this.shadowOffsetY;
  3706. }
  3707. if (this.outlineWidth) {
  3708. context.strokeText(text, this._currentMeasure.left + x, y);
  3709. }
  3710. context.fillText(text, this._currentMeasure.left + x, y);
  3711. };
  3712. /** @hidden */
  3713. TextBlock.prototype._draw = function (parentMeasure, context) {
  3714. context.save();
  3715. this._applyStates(context);
  3716. if (this._processMeasures(parentMeasure, context)) {
  3717. // Render lines
  3718. this._renderLines(context);
  3719. }
  3720. context.restore();
  3721. };
  3722. TextBlock.prototype._applyStates = function (context) {
  3723. _super.prototype._applyStates.call(this, context);
  3724. if (this.outlineWidth) {
  3725. context.lineWidth = this.outlineWidth;
  3726. context.strokeStyle = this.outlineColor;
  3727. }
  3728. };
  3729. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  3730. this._lines = [];
  3731. var _lines = this.text.split("\n");
  3732. if (this._textWrapping && !this._resizeToFit) {
  3733. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  3734. var _line = _lines_1[_i];
  3735. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  3736. }
  3737. }
  3738. else {
  3739. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  3740. var _line = _lines_2[_a];
  3741. this._lines.push(this._parseLine(_line, context));
  3742. }
  3743. }
  3744. this.onLinesReadyObservable.notifyObservers(this);
  3745. };
  3746. TextBlock.prototype._parseLine = function (line, context) {
  3747. if (line === void 0) { line = ''; }
  3748. return { text: line, width: context.measureText(line).width };
  3749. };
  3750. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  3751. if (line === void 0) { line = ''; }
  3752. var words = line.split(' ');
  3753. var width = this._currentMeasure.width;
  3754. var lineWidth = 0;
  3755. for (var n = 0; n < words.length; n++) {
  3756. var testLine = n > 0 ? line + " " + words[n] : words[0];
  3757. var metrics = context.measureText(testLine);
  3758. var testWidth = metrics.width;
  3759. if (testWidth > width && n > 0) {
  3760. this._lines.push({ text: line, width: lineWidth });
  3761. line = words[n];
  3762. lineWidth = context.measureText(line).width;
  3763. }
  3764. else {
  3765. lineWidth = testWidth;
  3766. line = testLine;
  3767. }
  3768. }
  3769. return { text: line, width: lineWidth };
  3770. };
  3771. TextBlock.prototype._renderLines = function (context) {
  3772. var height = this._currentMeasure.height;
  3773. if (!this._fontOffset) {
  3774. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  3775. }
  3776. var rootY = 0;
  3777. switch (this._textVerticalAlignment) {
  3778. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  3779. rootY = this._fontOffset.ascent;
  3780. break;
  3781. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  3782. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  3783. break;
  3784. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  3785. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  3786. break;
  3787. }
  3788. rootY += this._currentMeasure.top;
  3789. var maxLineWidth = 0;
  3790. for (var i = 0; i < this._lines.length; i++) {
  3791. var line = this._lines[i];
  3792. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  3793. if (this._lineSpacing.isPixel) {
  3794. rootY += this._lineSpacing.getValue(this._host);
  3795. }
  3796. else {
  3797. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  3798. }
  3799. }
  3800. this._drawText(line.text, line.width, rootY, context);
  3801. rootY += this._fontOffset.height;
  3802. if (line.width > maxLineWidth)
  3803. maxLineWidth = line.width;
  3804. }
  3805. if (this._resizeToFit) {
  3806. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  3807. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  3808. }
  3809. };
  3810. TextBlock.prototype.dispose = function () {
  3811. _super.prototype.dispose.call(this);
  3812. this.onTextChangedObservable.clear();
  3813. };
  3814. return TextBlock;
  3815. }(GUI.Control));
  3816. GUI.TextBlock = TextBlock;
  3817. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3818. })(BABYLON || (BABYLON = {}));
  3819. //# sourceMappingURL=textBlock.js.map
  3820. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3821. var DOMImage = Image;
  3822. var BABYLON;
  3823. (function (BABYLON) {
  3824. var GUI;
  3825. (function (GUI) {
  3826. var Image = /** @class */ (function (_super) {
  3827. __extends(Image, _super);
  3828. function Image(name, url) {
  3829. if (url === void 0) { url = null; }
  3830. var _this = _super.call(this, name) || this;
  3831. _this.name = name;
  3832. _this._loaded = false;
  3833. _this._stretch = Image.STRETCH_FILL;
  3834. _this._autoScale = false;
  3835. _this._sourceLeft = 0;
  3836. _this._sourceTop = 0;
  3837. _this._sourceWidth = 0;
  3838. _this._sourceHeight = 0;
  3839. _this._cellWidth = 0;
  3840. _this._cellHeight = 0;
  3841. _this._cellId = -1;
  3842. _this.source = url;
  3843. return _this;
  3844. }
  3845. Object.defineProperty(Image.prototype, "sourceLeft", {
  3846. get: function () {
  3847. return this._sourceLeft;
  3848. },
  3849. set: function (value) {
  3850. if (this._sourceLeft === value) {
  3851. return;
  3852. }
  3853. this._sourceLeft = value;
  3854. this._markAsDirty();
  3855. },
  3856. enumerable: true,
  3857. configurable: true
  3858. });
  3859. Object.defineProperty(Image.prototype, "sourceTop", {
  3860. get: function () {
  3861. return this._sourceTop;
  3862. },
  3863. set: function (value) {
  3864. if (this._sourceTop === value) {
  3865. return;
  3866. }
  3867. this._sourceTop = value;
  3868. this._markAsDirty();
  3869. },
  3870. enumerable: true,
  3871. configurable: true
  3872. });
  3873. Object.defineProperty(Image.prototype, "sourceWidth", {
  3874. get: function () {
  3875. return this._sourceWidth;
  3876. },
  3877. set: function (value) {
  3878. if (this._sourceWidth === value) {
  3879. return;
  3880. }
  3881. this._sourceWidth = value;
  3882. this._markAsDirty();
  3883. },
  3884. enumerable: true,
  3885. configurable: true
  3886. });
  3887. Object.defineProperty(Image.prototype, "sourceHeight", {
  3888. get: function () {
  3889. return this._sourceHeight;
  3890. },
  3891. set: function (value) {
  3892. if (this._sourceHeight === value) {
  3893. return;
  3894. }
  3895. this._sourceHeight = value;
  3896. this._markAsDirty();
  3897. },
  3898. enumerable: true,
  3899. configurable: true
  3900. });
  3901. Object.defineProperty(Image.prototype, "autoScale", {
  3902. get: function () {
  3903. return this._autoScale;
  3904. },
  3905. set: function (value) {
  3906. if (this._autoScale === value) {
  3907. return;
  3908. }
  3909. this._autoScale = value;
  3910. if (value && this._loaded) {
  3911. this.synchronizeSizeWithContent();
  3912. }
  3913. },
  3914. enumerable: true,
  3915. configurable: true
  3916. });
  3917. Object.defineProperty(Image.prototype, "stretch", {
  3918. get: function () {
  3919. return this._stretch;
  3920. },
  3921. set: function (value) {
  3922. if (this._stretch === value) {
  3923. return;
  3924. }
  3925. this._stretch = value;
  3926. this._markAsDirty();
  3927. },
  3928. enumerable: true,
  3929. configurable: true
  3930. });
  3931. Object.defineProperty(Image.prototype, "domImage", {
  3932. get: function () {
  3933. return this._domImage;
  3934. },
  3935. set: function (value) {
  3936. var _this = this;
  3937. this._domImage = value;
  3938. this._loaded = false;
  3939. if (this._domImage.width) {
  3940. this._onImageLoaded();
  3941. }
  3942. else {
  3943. this._domImage.onload = function () {
  3944. _this._onImageLoaded();
  3945. };
  3946. }
  3947. },
  3948. enumerable: true,
  3949. configurable: true
  3950. });
  3951. Image.prototype._onImageLoaded = function () {
  3952. this._imageWidth = this._domImage.width;
  3953. this._imageHeight = this._domImage.height;
  3954. this._loaded = true;
  3955. if (this._autoScale) {
  3956. this.synchronizeSizeWithContent();
  3957. }
  3958. this._markAsDirty();
  3959. };
  3960. Object.defineProperty(Image.prototype, "source", {
  3961. set: function (value) {
  3962. var _this = this;
  3963. if (this._source === value) {
  3964. return;
  3965. }
  3966. this._loaded = false;
  3967. this._source = value;
  3968. this._domImage = new DOMImage();
  3969. this._domImage.onload = function () {
  3970. _this._onImageLoaded();
  3971. };
  3972. if (value) {
  3973. BABYLON.Tools.SetCorsBehavior(value, this._domImage);
  3974. this._domImage.src = value;
  3975. }
  3976. },
  3977. enumerable: true,
  3978. configurable: true
  3979. });
  3980. Object.defineProperty(Image.prototype, "cellWidth", {
  3981. get: function () {
  3982. return this._cellWidth;
  3983. },
  3984. set: function (value) {
  3985. if (this._cellWidth === value) {
  3986. return;
  3987. }
  3988. this._cellWidth = value;
  3989. this._markAsDirty();
  3990. },
  3991. enumerable: true,
  3992. configurable: true
  3993. });
  3994. Object.defineProperty(Image.prototype, "cellHeight", {
  3995. get: function () {
  3996. return this._cellHeight;
  3997. },
  3998. set: function (value) {
  3999. if (this._cellHeight === value) {
  4000. return;
  4001. }
  4002. this._cellHeight = value;
  4003. this._markAsDirty();
  4004. },
  4005. enumerable: true,
  4006. configurable: true
  4007. });
  4008. Object.defineProperty(Image.prototype, "cellId", {
  4009. get: function () {
  4010. return this._cellId;
  4011. },
  4012. set: function (value) {
  4013. if (this._cellId === value) {
  4014. return;
  4015. }
  4016. this._cellId = value;
  4017. this._markAsDirty();
  4018. },
  4019. enumerable: true,
  4020. configurable: true
  4021. });
  4022. Image.prototype._getTypeName = function () {
  4023. return "Image";
  4024. };
  4025. Image.prototype.synchronizeSizeWithContent = function () {
  4026. if (!this._loaded) {
  4027. return;
  4028. }
  4029. this.width = this._domImage.width + "px";
  4030. this.height = this._domImage.height + "px";
  4031. };
  4032. Image.prototype._draw = function (parentMeasure, context) {
  4033. context.save();
  4034. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4035. context.shadowColor = this.shadowColor;
  4036. context.shadowBlur = this.shadowBlur;
  4037. context.shadowOffsetX = this.shadowOffsetX;
  4038. context.shadowOffsetY = this.shadowOffsetY;
  4039. }
  4040. var x, y, width, height;
  4041. if (this.cellId == -1) {
  4042. x = this._sourceLeft;
  4043. y = this._sourceTop;
  4044. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  4045. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  4046. }
  4047. else {
  4048. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  4049. var column = (this.cellId / rowCount) >> 0;
  4050. var row = this.cellId % rowCount;
  4051. x = this.cellWidth * row;
  4052. y = this.cellHeight * column;
  4053. width = this.cellWidth;
  4054. height = this.cellHeight;
  4055. }
  4056. this._applyStates(context);
  4057. if (this._processMeasures(parentMeasure, context)) {
  4058. if (this._loaded) {
  4059. switch (this._stretch) {
  4060. case Image.STRETCH_NONE:
  4061. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4062. break;
  4063. case Image.STRETCH_FILL:
  4064. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4065. break;
  4066. case Image.STRETCH_UNIFORM:
  4067. var hRatio = this._currentMeasure.width / width;
  4068. var vRatio = this._currentMeasure.height / height;
  4069. var ratio = Math.min(hRatio, vRatio);
  4070. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  4071. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  4072. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  4073. break;
  4074. case Image.STRETCH_EXTEND:
  4075. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4076. if (this._autoScale) {
  4077. this.synchronizeSizeWithContent();
  4078. }
  4079. if (this._root && this._root.parent) { // Will update root size if root is not the top root
  4080. this._root.width = this.width;
  4081. this._root.height = this.height;
  4082. }
  4083. break;
  4084. }
  4085. }
  4086. }
  4087. context.restore();
  4088. };
  4089. Object.defineProperty(Image, "STRETCH_NONE", {
  4090. get: function () {
  4091. return Image._STRETCH_NONE;
  4092. },
  4093. enumerable: true,
  4094. configurable: true
  4095. });
  4096. Object.defineProperty(Image, "STRETCH_FILL", {
  4097. get: function () {
  4098. return Image._STRETCH_FILL;
  4099. },
  4100. enumerable: true,
  4101. configurable: true
  4102. });
  4103. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  4104. get: function () {
  4105. return Image._STRETCH_UNIFORM;
  4106. },
  4107. enumerable: true,
  4108. configurable: true
  4109. });
  4110. Object.defineProperty(Image, "STRETCH_EXTEND", {
  4111. get: function () {
  4112. return Image._STRETCH_EXTEND;
  4113. },
  4114. enumerable: true,
  4115. configurable: true
  4116. });
  4117. // Static
  4118. Image._STRETCH_NONE = 0;
  4119. Image._STRETCH_FILL = 1;
  4120. Image._STRETCH_UNIFORM = 2;
  4121. Image._STRETCH_EXTEND = 3;
  4122. return Image;
  4123. }(GUI.Control));
  4124. GUI.Image = Image;
  4125. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4126. })(BABYLON || (BABYLON = {}));
  4127. //# sourceMappingURL=image.js.map
  4128. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4129. var BABYLON;
  4130. (function (BABYLON) {
  4131. var GUI;
  4132. (function (GUI) {
  4133. var Button = /** @class */ (function (_super) {
  4134. __extends(Button, _super);
  4135. function Button(name) {
  4136. var _this = _super.call(this, name) || this;
  4137. _this.name = name;
  4138. _this.thickness = 1;
  4139. _this.isPointerBlocker = true;
  4140. _this.pointerEnterAnimation = function () {
  4141. _this.alpha -= 0.1;
  4142. };
  4143. _this.pointerOutAnimation = function () {
  4144. _this.alpha += 0.1;
  4145. };
  4146. _this.pointerDownAnimation = function () {
  4147. _this.scaleX -= 0.05;
  4148. _this.scaleY -= 0.05;
  4149. };
  4150. _this.pointerUpAnimation = function () {
  4151. _this.scaleX += 0.05;
  4152. _this.scaleY += 0.05;
  4153. };
  4154. return _this;
  4155. }
  4156. Button.prototype._getTypeName = function () {
  4157. return "Button";
  4158. };
  4159. // While being a container, the button behaves like a control.
  4160. Button.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  4161. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  4162. return false;
  4163. }
  4164. if (!_super.prototype.contains.call(this, x, y)) {
  4165. return false;
  4166. }
  4167. this._processObservables(type, x, y, pointerId, buttonIndex);
  4168. return true;
  4169. };
  4170. Button.prototype._onPointerEnter = function (target) {
  4171. if (!_super.prototype._onPointerEnter.call(this, target)) {
  4172. return false;
  4173. }
  4174. if (this.pointerEnterAnimation) {
  4175. this.pointerEnterAnimation();
  4176. }
  4177. return true;
  4178. };
  4179. Button.prototype._onPointerOut = function (target) {
  4180. if (this.pointerOutAnimation) {
  4181. this.pointerOutAnimation();
  4182. }
  4183. _super.prototype._onPointerOut.call(this, target);
  4184. };
  4185. Button.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4186. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4187. return false;
  4188. }
  4189. if (this.pointerDownAnimation) {
  4190. this.pointerDownAnimation();
  4191. }
  4192. return true;
  4193. };
  4194. Button.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  4195. if (this.pointerUpAnimation) {
  4196. this.pointerUpAnimation();
  4197. }
  4198. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  4199. };
  4200. // Statics
  4201. Button.CreateImageButton = function (name, text, imageUrl) {
  4202. var result = new Button(name);
  4203. // Adding text
  4204. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4205. textBlock.textWrapping = true;
  4206. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4207. textBlock.paddingLeft = "20%";
  4208. result.addControl(textBlock);
  4209. // Adding image
  4210. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4211. iconImage.width = "20%";
  4212. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  4213. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  4214. result.addControl(iconImage);
  4215. return result;
  4216. };
  4217. Button.CreateImageOnlyButton = function (name, imageUrl) {
  4218. var result = new Button(name);
  4219. // Adding image
  4220. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4221. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  4222. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  4223. result.addControl(iconImage);
  4224. return result;
  4225. };
  4226. Button.CreateSimpleButton = function (name, text) {
  4227. var result = new Button(name);
  4228. // Adding text
  4229. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4230. textBlock.textWrapping = true;
  4231. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4232. result.addControl(textBlock);
  4233. return result;
  4234. };
  4235. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  4236. var result = new Button(name);
  4237. // Adding image
  4238. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4239. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  4240. result.addControl(iconImage);
  4241. // Adding text
  4242. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4243. textBlock.textWrapping = true;
  4244. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4245. result.addControl(textBlock);
  4246. return result;
  4247. };
  4248. return Button;
  4249. }(GUI.Rectangle));
  4250. GUI.Button = Button;
  4251. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4252. })(BABYLON || (BABYLON = {}));
  4253. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4254. var BABYLON;
  4255. (function (BABYLON) {
  4256. var GUI;
  4257. (function (GUI) {
  4258. var ColorPicker = /** @class */ (function (_super) {
  4259. __extends(ColorPicker, _super);
  4260. function ColorPicker(name) {
  4261. var _this = _super.call(this, name) || this;
  4262. _this.name = name;
  4263. _this._value = BABYLON.Color3.Red();
  4264. _this._tmpColor = new BABYLON.Color3();
  4265. _this._pointerStartedOnSquare = false;
  4266. _this._pointerStartedOnWheel = false;
  4267. _this._squareLeft = 0;
  4268. _this._squareTop = 0;
  4269. _this._squareSize = 0;
  4270. _this._h = 360;
  4271. _this._s = 1;
  4272. _this._v = 1;
  4273. _this.onValueChangedObservable = new BABYLON.Observable();
  4274. // Events
  4275. _this._pointerIsDown = false;
  4276. _this.value = new BABYLON.Color3(.88, .1, .1);
  4277. _this.size = "200px";
  4278. _this.isPointerBlocker = true;
  4279. return _this;
  4280. }
  4281. Object.defineProperty(ColorPicker.prototype, "value", {
  4282. get: function () {
  4283. return this._value;
  4284. },
  4285. set: function (value) {
  4286. if (this._value.equals(value)) {
  4287. return;
  4288. }
  4289. this._value.copyFrom(value);
  4290. this._RGBtoHSV(this._value, this._tmpColor);
  4291. this._h = this._tmpColor.r;
  4292. this._s = Math.max(this._tmpColor.g, 0.00001);
  4293. this._v = Math.max(this._tmpColor.b, 0.00001);
  4294. this._markAsDirty();
  4295. this.onValueChangedObservable.notifyObservers(this._value);
  4296. },
  4297. enumerable: true,
  4298. configurable: true
  4299. });
  4300. Object.defineProperty(ColorPicker.prototype, "width", {
  4301. set: function (value) {
  4302. if (this._width.toString(this._host) === value) {
  4303. return;
  4304. }
  4305. if (this._width.fromString(value)) {
  4306. this._height.fromString(value);
  4307. this._markAsDirty();
  4308. }
  4309. },
  4310. enumerable: true,
  4311. configurable: true
  4312. });
  4313. Object.defineProperty(ColorPicker.prototype, "height", {
  4314. set: function (value) {
  4315. if (this._height.toString(this._host) === value) {
  4316. return;
  4317. }
  4318. if (this._height.fromString(value)) {
  4319. this._width.fromString(value);
  4320. this._markAsDirty();
  4321. }
  4322. },
  4323. enumerable: true,
  4324. configurable: true
  4325. });
  4326. Object.defineProperty(ColorPicker.prototype, "size", {
  4327. get: function () {
  4328. return this.width;
  4329. },
  4330. set: function (value) {
  4331. this.width = value;
  4332. },
  4333. enumerable: true,
  4334. configurable: true
  4335. });
  4336. ColorPicker.prototype._getTypeName = function () {
  4337. return "ColorPicker";
  4338. };
  4339. ColorPicker.prototype._updateSquareProps = function () {
  4340. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4341. var wheelThickness = radius * .2;
  4342. var innerDiameter = (radius - wheelThickness) * 2;
  4343. var squareSize = innerDiameter / (Math.sqrt(2));
  4344. var offset = radius - squareSize * .5;
  4345. this._squareLeft = this._currentMeasure.left + offset;
  4346. this._squareTop = this._currentMeasure.top + offset;
  4347. this._squareSize = squareSize;
  4348. };
  4349. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  4350. var lgh = context.createLinearGradient(left, top, width + left, top);
  4351. lgh.addColorStop(0, '#fff');
  4352. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  4353. context.fillStyle = lgh;
  4354. context.fillRect(left, top, width, height);
  4355. var lgv = context.createLinearGradient(left, top, left, height + top);
  4356. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  4357. lgv.addColorStop(1, '#000');
  4358. context.fillStyle = lgv;
  4359. context.fillRect(left, top, width, height);
  4360. };
  4361. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  4362. context.beginPath();
  4363. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  4364. context.lineWidth = 3;
  4365. context.strokeStyle = '#333333';
  4366. context.stroke();
  4367. context.beginPath();
  4368. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  4369. context.lineWidth = 3;
  4370. context.strokeStyle = '#ffffff';
  4371. context.stroke();
  4372. };
  4373. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  4374. var canvas = document.createElement("canvas");
  4375. canvas.width = radius * 2;
  4376. canvas.height = radius * 2;
  4377. var context = canvas.getContext("2d");
  4378. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  4379. var data = image.data;
  4380. var color = this._tmpColor;
  4381. var maxDistSq = radius * radius;
  4382. var innerRadius = radius - thickness;
  4383. var minDistSq = innerRadius * innerRadius;
  4384. for (var x = -radius; x < radius; x++) {
  4385. for (var y = -radius; y < radius; y++) {
  4386. var distSq = x * x + y * y;
  4387. if (distSq > maxDistSq || distSq < minDistSq) {
  4388. continue;
  4389. }
  4390. var dist = Math.sqrt(distSq);
  4391. var ang = Math.atan2(y, x);
  4392. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  4393. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  4394. data[index] = color.r * 255;
  4395. data[index + 1] = color.g * 255;
  4396. data[index + 2] = color.b * 255;
  4397. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  4398. //apply less alpha to bigger color pickers
  4399. var alphaAmount = .2;
  4400. var maxAlpha = .2;
  4401. var minAlpha = .04;
  4402. var lowerRadius = 50;
  4403. var upperRadius = 150;
  4404. if (radius < lowerRadius) {
  4405. alphaAmount = maxAlpha;
  4406. }
  4407. else if (radius > upperRadius) {
  4408. alphaAmount = minAlpha;
  4409. }
  4410. else {
  4411. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  4412. }
  4413. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  4414. if (alphaRatio < alphaAmount) {
  4415. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  4416. }
  4417. else if (alphaRatio > 1 - alphaAmount) {
  4418. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  4419. }
  4420. else {
  4421. data[index + 3] = 255;
  4422. }
  4423. }
  4424. }
  4425. context.putImageData(image, 0, 0);
  4426. return canvas;
  4427. };
  4428. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  4429. var r = color.r;
  4430. var g = color.g;
  4431. var b = color.b;
  4432. var max = Math.max(r, g, b);
  4433. var min = Math.min(r, g, b);
  4434. var h = 0;
  4435. var s = 0;
  4436. var v = max;
  4437. var dm = max - min;
  4438. if (max !== 0) {
  4439. s = dm / max;
  4440. }
  4441. if (max != min) {
  4442. if (max == r) {
  4443. h = (g - b) / dm;
  4444. if (g < b) {
  4445. h += 6;
  4446. }
  4447. }
  4448. else if (max == g) {
  4449. h = (b - r) / dm + 2;
  4450. }
  4451. else if (max == b) {
  4452. h = (r - g) / dm + 4;
  4453. }
  4454. h *= 60;
  4455. }
  4456. result.r = h;
  4457. result.g = s;
  4458. result.b = v;
  4459. };
  4460. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  4461. var chroma = value * saturation;
  4462. var h = hue / 60;
  4463. var x = chroma * (1 - Math.abs((h % 2) - 1));
  4464. var r = 0;
  4465. var g = 0;
  4466. var b = 0;
  4467. if (h >= 0 && h <= 1) {
  4468. r = chroma;
  4469. g = x;
  4470. }
  4471. else if (h >= 1 && h <= 2) {
  4472. r = x;
  4473. g = chroma;
  4474. }
  4475. else if (h >= 2 && h <= 3) {
  4476. g = chroma;
  4477. b = x;
  4478. }
  4479. else if (h >= 3 && h <= 4) {
  4480. g = x;
  4481. b = chroma;
  4482. }
  4483. else if (h >= 4 && h <= 5) {
  4484. r = x;
  4485. b = chroma;
  4486. }
  4487. else if (h >= 5 && h <= 6) {
  4488. r = chroma;
  4489. b = x;
  4490. }
  4491. var m = value - chroma;
  4492. result.set((r + m), (g + m), (b + m));
  4493. };
  4494. ColorPicker.prototype._draw = function (parentMeasure, context) {
  4495. context.save();
  4496. this._applyStates(context);
  4497. if (this._processMeasures(parentMeasure, context)) {
  4498. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4499. var wheelThickness = radius * .2;
  4500. var left = this._currentMeasure.left;
  4501. var top = this._currentMeasure.top;
  4502. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  4503. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  4504. }
  4505. this._updateSquareProps();
  4506. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4507. context.shadowColor = this.shadowColor;
  4508. context.shadowBlur = this.shadowBlur;
  4509. context.shadowOffsetX = this.shadowOffsetX;
  4510. context.shadowOffsetY = this.shadowOffsetY;
  4511. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  4512. }
  4513. context.drawImage(this._colorWheelCanvas, left, top);
  4514. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4515. context.shadowBlur = 0;
  4516. context.shadowOffsetX = 0;
  4517. context.shadowOffsetY = 0;
  4518. }
  4519. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  4520. var cx = this._squareLeft + this._squareSize * this._s;
  4521. var cy = this._squareTop + this._squareSize * (1 - this._v);
  4522. this._drawCircle(cx, cy, radius * .04, context);
  4523. var dist = radius - wheelThickness * .5;
  4524. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  4525. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  4526. this._drawCircle(cx, cy, wheelThickness * .35, context);
  4527. }
  4528. context.restore();
  4529. };
  4530. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  4531. if (this._pointerStartedOnWheel) {
  4532. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4533. var centerX = radius + this._currentMeasure.left;
  4534. var centerY = radius + this._currentMeasure.top;
  4535. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  4536. }
  4537. else if (this._pointerStartedOnSquare) {
  4538. this._updateSquareProps();
  4539. this._s = (x - this._squareLeft) / this._squareSize;
  4540. this._v = 1 - (y - this._squareTop) / this._squareSize;
  4541. this._s = Math.min(this._s, 1);
  4542. this._s = Math.max(this._s, 0.00001);
  4543. this._v = Math.min(this._v, 1);
  4544. this._v = Math.max(this._v, 0.00001);
  4545. }
  4546. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  4547. this.value = this._tmpColor;
  4548. };
  4549. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  4550. this._updateSquareProps();
  4551. var left = this._squareLeft;
  4552. var top = this._squareTop;
  4553. var size = this._squareSize;
  4554. if (coordinates.x >= left && coordinates.x <= left + size &&
  4555. coordinates.y >= top && coordinates.y <= top + size) {
  4556. return true;
  4557. }
  4558. return false;
  4559. };
  4560. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  4561. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4562. var centerX = radius + this._currentMeasure.left;
  4563. var centerY = radius + this._currentMeasure.top;
  4564. var wheelThickness = radius * .2;
  4565. var innerRadius = radius - wheelThickness;
  4566. var radiusSq = radius * radius;
  4567. var innerRadiusSq = innerRadius * innerRadius;
  4568. var dx = coordinates.x - centerX;
  4569. var dy = coordinates.y - centerY;
  4570. var distSq = dx * dx + dy * dy;
  4571. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  4572. return true;
  4573. }
  4574. return false;
  4575. };
  4576. ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4577. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4578. return false;
  4579. }
  4580. this._pointerIsDown = true;
  4581. this._pointerStartedOnSquare = false;
  4582. this._pointerStartedOnWheel = false;
  4583. if (this._isPointOnSquare(coordinates)) {
  4584. this._pointerStartedOnSquare = true;
  4585. }
  4586. else if (this._isPointOnWheel(coordinates)) {
  4587. this._pointerStartedOnWheel = true;
  4588. }
  4589. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4590. this._host._capturingControl[pointerId] = this;
  4591. return true;
  4592. };
  4593. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  4594. if (this._pointerIsDown) {
  4595. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4596. }
  4597. _super.prototype._onPointerMove.call(this, target, coordinates);
  4598. };
  4599. ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  4600. this._pointerIsDown = false;
  4601. delete this._host._capturingControl[pointerId];
  4602. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  4603. };
  4604. return ColorPicker;
  4605. }(GUI.Control));
  4606. GUI.ColorPicker = ColorPicker;
  4607. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4608. })(BABYLON || (BABYLON = {}));
  4609. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4610. var BABYLON;
  4611. (function (BABYLON) {
  4612. var GUI;
  4613. (function (GUI) {
  4614. var InputText = /** @class */ (function (_super) {
  4615. __extends(InputText, _super);
  4616. function InputText(name, text) {
  4617. if (text === void 0) { text = ""; }
  4618. var _this = _super.call(this, name) || this;
  4619. _this.name = name;
  4620. _this._text = "";
  4621. _this._placeholderText = "";
  4622. _this._background = "#222222";
  4623. _this._focusedBackground = "#000000";
  4624. _this._placeholderColor = "gray";
  4625. _this._thickness = 1;
  4626. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  4627. _this._autoStretchWidth = true;
  4628. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  4629. _this._isFocused = false;
  4630. _this._blinkIsEven = false;
  4631. _this._cursorOffset = 0;
  4632. _this.promptMessage = "Please enter text:";
  4633. _this.onTextChangedObservable = new BABYLON.Observable();
  4634. _this.onFocusObservable = new BABYLON.Observable();
  4635. _this.onBlurObservable = new BABYLON.Observable();
  4636. _this.text = text;
  4637. return _this;
  4638. }
  4639. Object.defineProperty(InputText.prototype, "maxWidth", {
  4640. get: function () {
  4641. return this._maxWidth.toString(this._host);
  4642. },
  4643. set: function (value) {
  4644. if (this._maxWidth.toString(this._host) === value) {
  4645. return;
  4646. }
  4647. if (this._maxWidth.fromString(value)) {
  4648. this._markAsDirty();
  4649. }
  4650. },
  4651. enumerable: true,
  4652. configurable: true
  4653. });
  4654. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  4655. get: function () {
  4656. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4657. },
  4658. enumerable: true,
  4659. configurable: true
  4660. });
  4661. Object.defineProperty(InputText.prototype, "margin", {
  4662. get: function () {
  4663. return this._margin.toString(this._host);
  4664. },
  4665. set: function (value) {
  4666. if (this._margin.toString(this._host) === value) {
  4667. return;
  4668. }
  4669. if (this._margin.fromString(value)) {
  4670. this._markAsDirty();
  4671. }
  4672. },
  4673. enumerable: true,
  4674. configurable: true
  4675. });
  4676. Object.defineProperty(InputText.prototype, "marginInPixels", {
  4677. get: function () {
  4678. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4679. },
  4680. enumerable: true,
  4681. configurable: true
  4682. });
  4683. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  4684. get: function () {
  4685. return this._autoStretchWidth;
  4686. },
  4687. set: function (value) {
  4688. if (this._autoStretchWidth === value) {
  4689. return;
  4690. }
  4691. this._autoStretchWidth = value;
  4692. this._markAsDirty();
  4693. },
  4694. enumerable: true,
  4695. configurable: true
  4696. });
  4697. Object.defineProperty(InputText.prototype, "thickness", {
  4698. get: function () {
  4699. return this._thickness;
  4700. },
  4701. set: function (value) {
  4702. if (this._thickness === value) {
  4703. return;
  4704. }
  4705. this._thickness = value;
  4706. this._markAsDirty();
  4707. },
  4708. enumerable: true,
  4709. configurable: true
  4710. });
  4711. Object.defineProperty(InputText.prototype, "focusedBackground", {
  4712. get: function () {
  4713. return this._focusedBackground;
  4714. },
  4715. set: function (value) {
  4716. if (this._focusedBackground === value) {
  4717. return;
  4718. }
  4719. this._focusedBackground = value;
  4720. this._markAsDirty();
  4721. },
  4722. enumerable: true,
  4723. configurable: true
  4724. });
  4725. Object.defineProperty(InputText.prototype, "background", {
  4726. get: function () {
  4727. return this._background;
  4728. },
  4729. set: function (value) {
  4730. if (this._background === value) {
  4731. return;
  4732. }
  4733. this._background = value;
  4734. this._markAsDirty();
  4735. },
  4736. enumerable: true,
  4737. configurable: true
  4738. });
  4739. Object.defineProperty(InputText.prototype, "placeholderColor", {
  4740. get: function () {
  4741. return this._placeholderColor;
  4742. },
  4743. set: function (value) {
  4744. if (this._placeholderColor === value) {
  4745. return;
  4746. }
  4747. this._placeholderColor = value;
  4748. this._markAsDirty();
  4749. },
  4750. enumerable: true,
  4751. configurable: true
  4752. });
  4753. Object.defineProperty(InputText.prototype, "placeholderText", {
  4754. get: function () {
  4755. return this._placeholderText;
  4756. },
  4757. set: function (value) {
  4758. if (this._placeholderText === value) {
  4759. return;
  4760. }
  4761. this._placeholderText = value;
  4762. this._markAsDirty();
  4763. },
  4764. enumerable: true,
  4765. configurable: true
  4766. });
  4767. Object.defineProperty(InputText.prototype, "text", {
  4768. get: function () {
  4769. return this._text;
  4770. },
  4771. set: function (value) {
  4772. if (this._text === value) {
  4773. return;
  4774. }
  4775. this._text = value;
  4776. this._markAsDirty();
  4777. this.onTextChangedObservable.notifyObservers(this);
  4778. },
  4779. enumerable: true,
  4780. configurable: true
  4781. });
  4782. Object.defineProperty(InputText.prototype, "width", {
  4783. get: function () {
  4784. return this._width.toString(this._host);
  4785. },
  4786. set: function (value) {
  4787. if (this._width.toString(this._host) === value) {
  4788. return;
  4789. }
  4790. if (this._width.fromString(value)) {
  4791. this._markAsDirty();
  4792. }
  4793. this.autoStretchWidth = false;
  4794. },
  4795. enumerable: true,
  4796. configurable: true
  4797. });
  4798. InputText.prototype.onBlur = function () {
  4799. this._isFocused = false;
  4800. this._scrollLeft = null;
  4801. this._cursorOffset = 0;
  4802. clearTimeout(this._blinkTimeout);
  4803. this._markAsDirty();
  4804. this.onBlurObservable.notifyObservers(this);
  4805. };
  4806. InputText.prototype.onFocus = function () {
  4807. this._scrollLeft = null;
  4808. this._isFocused = true;
  4809. this._blinkIsEven = false;
  4810. this._cursorOffset = 0;
  4811. this._markAsDirty();
  4812. this.onFocusObservable.notifyObservers(this);
  4813. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  4814. var value = prompt(this.promptMessage);
  4815. if (value !== null) {
  4816. this.text = value;
  4817. }
  4818. this._host.focusedControl = null;
  4819. return;
  4820. }
  4821. };
  4822. InputText.prototype._getTypeName = function () {
  4823. return "InputText";
  4824. };
  4825. InputText.prototype.processKey = function (keyCode, key) {
  4826. // Specific cases
  4827. switch (keyCode) {
  4828. case 32: //SPACE
  4829. key = " "; //ie11 key for space is "Spacebar"
  4830. break;
  4831. case 8: // BACKSPACE
  4832. if (this._text && this._text.length > 0) {
  4833. if (this._cursorOffset === 0) {
  4834. this.text = this._text.substr(0, this._text.length - 1);
  4835. }
  4836. else {
  4837. var deletePosition = this._text.length - this._cursorOffset;
  4838. if (deletePosition > 0) {
  4839. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  4840. }
  4841. }
  4842. }
  4843. return;
  4844. case 46: // DELETE
  4845. if (this._text && this._text.length > 0) {
  4846. var deletePosition = this._text.length - this._cursorOffset;
  4847. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  4848. this._cursorOffset--;
  4849. }
  4850. return;
  4851. case 13: // RETURN
  4852. this._host.focusedControl = null;
  4853. return;
  4854. case 35: // END
  4855. this._cursorOffset = 0;
  4856. this._blinkIsEven = false;
  4857. this._markAsDirty();
  4858. return;
  4859. case 36: // HOME
  4860. this._cursorOffset = this._text.length;
  4861. this._blinkIsEven = false;
  4862. this._markAsDirty();
  4863. return;
  4864. case 37: // LEFT
  4865. this._cursorOffset++;
  4866. if (this._cursorOffset > this._text.length) {
  4867. this._cursorOffset = this._text.length;
  4868. }
  4869. this._blinkIsEven = false;
  4870. this._markAsDirty();
  4871. return;
  4872. case 39: // RIGHT
  4873. this._cursorOffset--;
  4874. if (this._cursorOffset < 0) {
  4875. this._cursorOffset = 0;
  4876. }
  4877. this._blinkIsEven = false;
  4878. this._markAsDirty();
  4879. return;
  4880. }
  4881. // Printable characters
  4882. if ((keyCode === -1) || // Direct access
  4883. (keyCode === 32) || // Space
  4884. (keyCode > 47 && keyCode < 58) || // Numbers
  4885. (keyCode > 64 && keyCode < 91) || // Letters
  4886. (keyCode > 185 && keyCode < 193) || // Special characters
  4887. (keyCode > 218 && keyCode < 223) || // Special characters
  4888. (keyCode > 95 && keyCode < 112)) { // Numpad
  4889. if (this._cursorOffset === 0) {
  4890. this.text += key;
  4891. }
  4892. else {
  4893. var insertPosition = this._text.length - this._cursorOffset;
  4894. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  4895. }
  4896. }
  4897. };
  4898. InputText.prototype.processKeyboard = function (evt) {
  4899. this.processKey(evt.keyCode, evt.key);
  4900. };
  4901. InputText.prototype._draw = function (parentMeasure, context) {
  4902. var _this = this;
  4903. context.save();
  4904. this._applyStates(context);
  4905. if (this._processMeasures(parentMeasure, context)) {
  4906. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4907. context.shadowColor = this.shadowColor;
  4908. context.shadowBlur = this.shadowBlur;
  4909. context.shadowOffsetX = this.shadowOffsetX;
  4910. context.shadowOffsetY = this.shadowOffsetY;
  4911. }
  4912. // Background
  4913. if (this._isFocused) {
  4914. if (this._focusedBackground) {
  4915. context.fillStyle = this._focusedBackground;
  4916. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4917. }
  4918. }
  4919. else if (this._background) {
  4920. context.fillStyle = this._background;
  4921. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4922. }
  4923. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4924. context.shadowBlur = 0;
  4925. context.shadowOffsetX = 0;
  4926. context.shadowOffsetY = 0;
  4927. }
  4928. if (!this._fontOffset) {
  4929. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  4930. }
  4931. // Text
  4932. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  4933. if (this.color) {
  4934. context.fillStyle = this.color;
  4935. }
  4936. var text = this._text;
  4937. if (!this._isFocused && !this._text && this._placeholderText) {
  4938. text = this._placeholderText;
  4939. if (this._placeholderColor) {
  4940. context.fillStyle = this._placeholderColor;
  4941. }
  4942. }
  4943. this._textWidth = context.measureText(text).width;
  4944. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  4945. if (this._autoStretchWidth) {
  4946. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  4947. }
  4948. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  4949. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  4950. context.save();
  4951. context.beginPath();
  4952. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  4953. context.clip();
  4954. if (this._isFocused && this._textWidth > availableWidth) {
  4955. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  4956. if (!this._scrollLeft) {
  4957. this._scrollLeft = textLeft;
  4958. }
  4959. }
  4960. else {
  4961. this._scrollLeft = clipTextLeft;
  4962. }
  4963. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  4964. // Cursor
  4965. if (this._isFocused) {
  4966. // Need to move cursor
  4967. if (this._clickedCoordinate) {
  4968. var rightPosition = this._scrollLeft + this._textWidth;
  4969. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  4970. var currentSize = 0;
  4971. this._cursorOffset = 0;
  4972. var previousDist = 0;
  4973. do {
  4974. if (this._cursorOffset) {
  4975. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  4976. }
  4977. this._cursorOffset++;
  4978. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  4979. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  4980. // Find closest move
  4981. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  4982. this._cursorOffset--;
  4983. }
  4984. this._blinkIsEven = false;
  4985. this._clickedCoordinate = null;
  4986. }
  4987. // Render cursor
  4988. if (!this._blinkIsEven) {
  4989. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  4990. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  4991. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  4992. if (cursorLeft < clipTextLeft) {
  4993. this._scrollLeft += (clipTextLeft - cursorLeft);
  4994. cursorLeft = clipTextLeft;
  4995. this._markAsDirty();
  4996. }
  4997. else if (cursorLeft > clipTextLeft + availableWidth) {
  4998. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  4999. cursorLeft = clipTextLeft + availableWidth;
  5000. this._markAsDirty();
  5001. }
  5002. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  5003. }
  5004. clearTimeout(this._blinkTimeout);
  5005. this._blinkTimeout = setTimeout(function () {
  5006. _this._blinkIsEven = !_this._blinkIsEven;
  5007. _this._markAsDirty();
  5008. }, 500);
  5009. }
  5010. context.restore();
  5011. // Border
  5012. if (this._thickness) {
  5013. if (this.color) {
  5014. context.strokeStyle = this.color;
  5015. }
  5016. context.lineWidth = this._thickness;
  5017. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  5018. }
  5019. }
  5020. context.restore();
  5021. };
  5022. InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5023. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5024. return false;
  5025. }
  5026. this._clickedCoordinate = coordinates.x;
  5027. if (this._host.focusedControl === this) {
  5028. // Move cursor
  5029. clearTimeout(this._blinkTimeout);
  5030. this._markAsDirty();
  5031. return true;
  5032. }
  5033. this._host.focusedControl = this;
  5034. return true;
  5035. };
  5036. InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5037. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5038. };
  5039. InputText.prototype.dispose = function () {
  5040. _super.prototype.dispose.call(this);
  5041. this.onBlurObservable.clear();
  5042. this.onFocusObservable.clear();
  5043. this.onTextChangedObservable.clear();
  5044. };
  5045. return InputText;
  5046. }(GUI.Control));
  5047. GUI.InputText = InputText;
  5048. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5049. })(BABYLON || (BABYLON = {}));
  5050. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  5051. var BABYLON;
  5052. (function (BABYLON) {
  5053. var GUI;
  5054. (function (GUI) {
  5055. var KeyPropertySet = /** @class */ (function () {
  5056. function KeyPropertySet() {
  5057. }
  5058. return KeyPropertySet;
  5059. }());
  5060. GUI.KeyPropertySet = KeyPropertySet;
  5061. var VirtualKeyboard = /** @class */ (function (_super) {
  5062. __extends(VirtualKeyboard, _super);
  5063. function VirtualKeyboard() {
  5064. var _this = _super !== null && _super.apply(this, arguments) || this;
  5065. _this.onKeyPressObservable = new BABYLON.Observable();
  5066. _this.defaultButtonWidth = "40px";
  5067. _this.defaultButtonHeight = "40px";
  5068. _this.defaultButtonPaddingLeft = "2px";
  5069. _this.defaultButtonPaddingRight = "2px";
  5070. _this.defaultButtonPaddingTop = "2px";
  5071. _this.defaultButtonPaddingBottom = "2px";
  5072. _this.defaultButtonColor = "#DDD";
  5073. _this.defaultButtonBackground = "#070707";
  5074. _this.shiftButtonColor = "#7799FF";
  5075. _this.selectedShiftThickness = 1;
  5076. _this.shiftState = 0;
  5077. return _this;
  5078. }
  5079. VirtualKeyboard.prototype._getTypeName = function () {
  5080. return "VirtualKeyboard";
  5081. };
  5082. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  5083. var _this = this;
  5084. var button = GUI.Button.CreateSimpleButton(key, key);
  5085. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  5086. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  5087. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  5088. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  5089. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  5090. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  5091. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  5092. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  5093. button.thickness = 0;
  5094. button.isFocusInvisible = true;
  5095. button.shadowColor = this.shadowColor;
  5096. button.shadowBlur = this.shadowBlur;
  5097. button.shadowOffsetX = this.shadowOffsetX;
  5098. button.shadowOffsetY = this.shadowOffsetY;
  5099. button.onPointerUpObservable.add(function () {
  5100. _this.onKeyPressObservable.notifyObservers(key);
  5101. });
  5102. return button;
  5103. };
  5104. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  5105. var panel = new GUI.StackPanel();
  5106. panel.isVertical = false;
  5107. panel.isFocusInvisible = true;
  5108. for (var i = 0; i < keys.length; i++) {
  5109. var properties = null;
  5110. if (propertySets && propertySets.length === keys.length) {
  5111. properties = propertySets[i];
  5112. }
  5113. panel.addControl(this._createKey(keys[i], properties));
  5114. }
  5115. this.addControl(panel);
  5116. };
  5117. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  5118. if (!this.children) {
  5119. return;
  5120. }
  5121. for (var i = 0; i < this.children.length; i++) {
  5122. var row = this.children[i];
  5123. if (!row || !row.children) {
  5124. continue;
  5125. }
  5126. var rowContainer = row;
  5127. for (var j = 0; j < rowContainer.children.length; j++) {
  5128. var button = rowContainer.children[j];
  5129. if (!button || !button.children[0]) {
  5130. continue;
  5131. }
  5132. var button_tblock = button.children[0];
  5133. if (button_tblock.text === "\u21E7") {
  5134. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  5135. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  5136. }
  5137. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  5138. }
  5139. }
  5140. };
  5141. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  5142. get: function () {
  5143. return this._connectedInputText;
  5144. },
  5145. enumerable: true,
  5146. configurable: true
  5147. });
  5148. VirtualKeyboard.prototype.connect = function (input) {
  5149. var _this = this;
  5150. this.isVisible = false;
  5151. this._connectedInputText = input;
  5152. // Events hooking
  5153. this._onFocusObserver = input.onFocusObservable.add(function () {
  5154. _this.isVisible = true;
  5155. });
  5156. this._onBlurObserver = input.onBlurObservable.add(function () {
  5157. _this.isVisible = false;
  5158. });
  5159. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  5160. if (!_this._connectedInputText) {
  5161. return;
  5162. }
  5163. switch (key) {
  5164. case "\u21E7":
  5165. _this.shiftState++;
  5166. if (_this.shiftState > 2) {
  5167. _this.shiftState = 0;
  5168. }
  5169. _this.applyShiftState(_this.shiftState);
  5170. return;
  5171. case "\u2190":
  5172. _this._connectedInputText.processKey(8);
  5173. return;
  5174. case "\u21B5":
  5175. _this._connectedInputText.processKey(13);
  5176. return;
  5177. }
  5178. _this._connectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  5179. if (_this.shiftState === 1) {
  5180. _this.shiftState = 0;
  5181. _this.applyShiftState(_this.shiftState);
  5182. }
  5183. });
  5184. };
  5185. VirtualKeyboard.prototype.disconnect = function () {
  5186. if (!this._connectedInputText) {
  5187. return;
  5188. }
  5189. this._connectedInputText.onFocusObservable.remove(this._onFocusObserver);
  5190. this._connectedInputText.onBlurObservable.remove(this._onBlurObserver);
  5191. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  5192. this._connectedInputText = null;
  5193. };
  5194. // Statics
  5195. VirtualKeyboard.CreateDefaultLayout = function () {
  5196. var returnValue = new VirtualKeyboard();
  5197. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  5198. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  5199. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  5200. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  5201. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  5202. return returnValue;
  5203. };
  5204. return VirtualKeyboard;
  5205. }(GUI.StackPanel));
  5206. GUI.VirtualKeyboard = VirtualKeyboard;
  5207. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5208. })(BABYLON || (BABYLON = {}));
  5209. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  5210. var BABYLON;
  5211. (function (BABYLON) {
  5212. var GUI;
  5213. (function (GUI) {
  5214. var MultiLine = /** @class */ (function (_super) {
  5215. __extends(MultiLine, _super);
  5216. function MultiLine(name) {
  5217. var _this = _super.call(this, name) || this;
  5218. _this.name = name;
  5219. _this._lineWidth = 1;
  5220. _this.onPointUpdate = function () {
  5221. _this._markAsDirty();
  5222. };
  5223. _this.isHitTestVisible = false;
  5224. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5225. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  5226. _this._dash = [];
  5227. _this._points = [];
  5228. return _this;
  5229. }
  5230. Object.defineProperty(MultiLine.prototype, "dash", {
  5231. get: function () {
  5232. return this._dash;
  5233. },
  5234. set: function (value) {
  5235. if (this._dash === value) {
  5236. return;
  5237. }
  5238. this._dash = value;
  5239. this._markAsDirty();
  5240. },
  5241. enumerable: true,
  5242. configurable: true
  5243. });
  5244. MultiLine.prototype.getAt = function (index) {
  5245. if (!this._points[index]) {
  5246. this._points[index] = new GUI.MultiLinePoint(this);
  5247. }
  5248. return this._points[index];
  5249. };
  5250. MultiLine.prototype.add = function () {
  5251. var _this = this;
  5252. var items = [];
  5253. for (var _i = 0; _i < arguments.length; _i++) {
  5254. items[_i] = arguments[_i];
  5255. }
  5256. return items.map(function (item) { return _this.push(item); });
  5257. };
  5258. MultiLine.prototype.push = function (item) {
  5259. var point = this.getAt(this._points.length);
  5260. if (item == null)
  5261. return point;
  5262. if (item instanceof BABYLON.AbstractMesh) {
  5263. point.mesh = item;
  5264. }
  5265. else if (item instanceof GUI.Control) {
  5266. point.control = item;
  5267. }
  5268. else if (item.x != null && item.y != null) {
  5269. point.x = item.x;
  5270. point.y = item.y;
  5271. }
  5272. return point;
  5273. };
  5274. MultiLine.prototype.remove = function (value) {
  5275. var index;
  5276. if (value instanceof GUI.MultiLinePoint) {
  5277. index = this._points.indexOf(value);
  5278. if (index === -1) {
  5279. return;
  5280. }
  5281. }
  5282. else {
  5283. index = value;
  5284. }
  5285. var point = this._points[index];
  5286. if (!point) {
  5287. return;
  5288. }
  5289. point.dispose();
  5290. this._points.splice(index, 1);
  5291. };
  5292. Object.defineProperty(MultiLine.prototype, "lineWidth", {
  5293. get: function () {
  5294. return this._lineWidth;
  5295. },
  5296. set: function (value) {
  5297. if (this._lineWidth === value) {
  5298. return;
  5299. }
  5300. this._lineWidth = value;
  5301. this._markAsDirty();
  5302. },
  5303. enumerable: true,
  5304. configurable: true
  5305. });
  5306. Object.defineProperty(MultiLine.prototype, "horizontalAlignment", {
  5307. set: function (value) {
  5308. return;
  5309. },
  5310. enumerable: true,
  5311. configurable: true
  5312. });
  5313. Object.defineProperty(MultiLine.prototype, "verticalAlignment", {
  5314. set: function (value) {
  5315. return;
  5316. },
  5317. enumerable: true,
  5318. configurable: true
  5319. });
  5320. MultiLine.prototype._getTypeName = function () {
  5321. return "MultiLine";
  5322. };
  5323. MultiLine.prototype._draw = function (parentMeasure, context) {
  5324. context.save();
  5325. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5326. context.shadowColor = this.shadowColor;
  5327. context.shadowBlur = this.shadowBlur;
  5328. context.shadowOffsetX = this.shadowOffsetX;
  5329. context.shadowOffsetY = this.shadowOffsetY;
  5330. }
  5331. this._applyStates(context);
  5332. if (this._processMeasures(parentMeasure, context)) {
  5333. context.strokeStyle = this.color;
  5334. context.lineWidth = this._lineWidth;
  5335. context.setLineDash(this._dash);
  5336. context.beginPath();
  5337. var first = true; //first index is not necessarily 0
  5338. this._points.forEach(function (point) {
  5339. if (!point) {
  5340. return;
  5341. }
  5342. if (first) {
  5343. context.moveTo(point._point.x, point._point.y);
  5344. first = false;
  5345. }
  5346. else {
  5347. context.lineTo(point._point.x, point._point.y);
  5348. }
  5349. });
  5350. context.stroke();
  5351. }
  5352. context.restore();
  5353. };
  5354. MultiLine.prototype._additionalProcessing = function (parentMeasure, context) {
  5355. var _this = this;
  5356. this._minX = null;
  5357. this._minY = null;
  5358. this._maxX = null;
  5359. this._maxY = null;
  5360. this._points.forEach(function (point, index) {
  5361. if (!point) {
  5362. return;
  5363. }
  5364. point.translate();
  5365. if (_this._minX == null || point._point.x < _this._minX)
  5366. _this._minX = point._point.x;
  5367. if (_this._minY == null || point._point.y < _this._minY)
  5368. _this._minY = point._point.y;
  5369. if (_this._maxX == null || point._point.x > _this._maxX)
  5370. _this._maxX = point._point.x;
  5371. if (_this._maxY == null || point._point.y > _this._maxY)
  5372. _this._maxY = point._point.y;
  5373. });
  5374. if (this._minX == null)
  5375. this._minX = 0;
  5376. if (this._minY == null)
  5377. this._minY = 0;
  5378. if (this._maxX == null)
  5379. this._maxX = 0;
  5380. if (this._maxY == null)
  5381. this._maxY = 0;
  5382. };
  5383. MultiLine.prototype._measure = function () {
  5384. if (this._minX == null || this._maxX == null || this._minY == null || this._maxY == null) {
  5385. return;
  5386. }
  5387. this._currentMeasure.width = Math.abs(this._maxX - this._minX) + this._lineWidth;
  5388. this._currentMeasure.height = Math.abs(this._maxY - this._minY) + this._lineWidth;
  5389. };
  5390. MultiLine.prototype._computeAlignment = function (parentMeasure, context) {
  5391. if (this._minX == null || this._minY == null) {
  5392. return;
  5393. }
  5394. this._currentMeasure.left = this._minX - this._lineWidth / 2;
  5395. this._currentMeasure.top = this._minY - this._lineWidth / 2;
  5396. };
  5397. MultiLine.prototype.dispose = function () {
  5398. while (this._points.length > 0) {
  5399. this.remove(this._points.length - 1);
  5400. }
  5401. _super.prototype.dispose.call(this);
  5402. };
  5403. return MultiLine;
  5404. }(GUI.Control));
  5405. GUI.MultiLine = MultiLine;
  5406. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5407. })(BABYLON || (BABYLON = {}));
  5408. return BABYLON.GUI;
  5409. });