babylon.gui.js 149 KB

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