babylon.gui.js 155 KB

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