babylon.gui.js 223 KB

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