babylon.gui.js 186 KB

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