babylon.gui.js 166 KB

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