babylon.gui.js 208 KB

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