babylon.gui.js 154 KB

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