babylon.gui.js 163 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794
  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._tempMeasureStore = GUI.Measure.Empty();
  1749. return _this;
  1750. }
  1751. Object.defineProperty(StackPanel.prototype, "isVertical", {
  1752. get: function () {
  1753. return this._isVertical;
  1754. },
  1755. set: function (value) {
  1756. if (this._isVertical === value) {
  1757. return;
  1758. }
  1759. this._isVertical = value;
  1760. this._markAsDirty();
  1761. },
  1762. enumerable: true,
  1763. configurable: true
  1764. });
  1765. StackPanel.prototype._getTypeName = function () {
  1766. return "StackPanel";
  1767. };
  1768. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  1769. var stack = 0;
  1770. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1771. var child = _a[_i];
  1772. this._tempMeasureStore.copyFrom(child._currentMeasure);
  1773. child._currentMeasure.copyFrom(parentMeasure);
  1774. child._measure();
  1775. if (this._isVertical) {
  1776. child.top = stack + "px";
  1777. if (!child._top.ignoreAdaptiveScaling) {
  1778. child._markAsDirty();
  1779. }
  1780. child._top.ignoreAdaptiveScaling = true;
  1781. stack += child._currentMeasure.height;
  1782. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1783. }
  1784. else {
  1785. child.left = stack + "px";
  1786. if (!child._left.ignoreAdaptiveScaling) {
  1787. child._markAsDirty();
  1788. }
  1789. child._left.ignoreAdaptiveScaling = true;
  1790. stack += child._currentMeasure.width;
  1791. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1792. }
  1793. child._currentMeasure.copyFrom(this._tempMeasureStore);
  1794. }
  1795. var panelChanged = false;
  1796. if (this._isVertical) {
  1797. var previousHeight = this.height;
  1798. this.height = stack + "px";
  1799. panelChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  1800. this._height.ignoreAdaptiveScaling = true;
  1801. }
  1802. else {
  1803. var previousWidth = this.width;
  1804. this.width = stack + "px";
  1805. panelChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  1806. this._width.ignoreAdaptiveScaling = true;
  1807. }
  1808. if (panelChanged) {
  1809. this._markAllAsDirty();
  1810. }
  1811. _super.prototype._preMeasure.call(this, parentMeasure, context);
  1812. };
  1813. return StackPanel;
  1814. }(GUI.Container));
  1815. GUI.StackPanel = StackPanel;
  1816. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1817. })(BABYLON || (BABYLON = {}));
  1818. //# sourceMappingURL=stackPanel.js.map
  1819. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1820. var __extends = (this && this.__extends) || (function () {
  1821. var extendStatics = Object.setPrototypeOf ||
  1822. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1823. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1824. return function (d, b) {
  1825. extendStatics(d, b);
  1826. function __() { this.constructor = d; }
  1827. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1828. };
  1829. })();
  1830. var BABYLON;
  1831. (function (BABYLON) {
  1832. var GUI;
  1833. (function (GUI) {
  1834. var Rectangle = (function (_super) {
  1835. __extends(Rectangle, _super);
  1836. function Rectangle(name) {
  1837. var _this = _super.call(this, name) || this;
  1838. _this.name = name;
  1839. _this._thickness = 1;
  1840. _this._cornerRadius = 0;
  1841. return _this;
  1842. }
  1843. Object.defineProperty(Rectangle.prototype, "thickness", {
  1844. get: function () {
  1845. return this._thickness;
  1846. },
  1847. set: function (value) {
  1848. if (this._thickness === value) {
  1849. return;
  1850. }
  1851. this._thickness = value;
  1852. this._markAsDirty();
  1853. },
  1854. enumerable: true,
  1855. configurable: true
  1856. });
  1857. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  1858. get: function () {
  1859. return this._cornerRadius;
  1860. },
  1861. set: function (value) {
  1862. if (value < 0) {
  1863. value = 0;
  1864. }
  1865. if (this._cornerRadius === value) {
  1866. return;
  1867. }
  1868. this._cornerRadius = value;
  1869. this._markAsDirty();
  1870. },
  1871. enumerable: true,
  1872. configurable: true
  1873. });
  1874. Rectangle.prototype._getTypeName = function () {
  1875. return "Rectangle";
  1876. };
  1877. Rectangle.prototype._localDraw = function (context) {
  1878. context.save();
  1879. if (this._background) {
  1880. context.fillStyle = this._background;
  1881. if (this._cornerRadius) {
  1882. this._drawRoundedRect(context, this._thickness / 2);
  1883. context.fill();
  1884. }
  1885. else {
  1886. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1887. }
  1888. }
  1889. if (this._thickness) {
  1890. if (this.color) {
  1891. context.strokeStyle = this.color;
  1892. }
  1893. context.lineWidth = this._thickness;
  1894. if (this._cornerRadius) {
  1895. this._drawRoundedRect(context, this._thickness / 2);
  1896. context.stroke();
  1897. }
  1898. else {
  1899. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  1900. }
  1901. }
  1902. context.restore();
  1903. };
  1904. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  1905. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1906. this._measureForChildren.width -= 2 * this._thickness;
  1907. this._measureForChildren.height -= 2 * this._thickness;
  1908. this._measureForChildren.left += this._thickness;
  1909. this._measureForChildren.top += this._thickness;
  1910. };
  1911. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  1912. if (offset === void 0) { offset = 0; }
  1913. var x = this._currentMeasure.left + offset;
  1914. var y = this._currentMeasure.top + offset;
  1915. var width = this._currentMeasure.width - offset * 2;
  1916. var height = this._currentMeasure.height - offset * 2;
  1917. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  1918. context.beginPath();
  1919. context.moveTo(x + radius, y);
  1920. context.lineTo(x + width - radius, y);
  1921. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  1922. context.lineTo(x + width, y + height - radius);
  1923. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  1924. context.lineTo(x + radius, y + height);
  1925. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  1926. context.lineTo(x, y + radius);
  1927. context.quadraticCurveTo(x, y, x + radius, y);
  1928. context.closePath();
  1929. };
  1930. Rectangle.prototype._clipForChildren = function (context) {
  1931. if (this._cornerRadius) {
  1932. this._drawRoundedRect(context, this._thickness);
  1933. context.clip();
  1934. }
  1935. };
  1936. return Rectangle;
  1937. }(GUI.Container));
  1938. GUI.Rectangle = Rectangle;
  1939. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1940. })(BABYLON || (BABYLON = {}));
  1941. //# sourceMappingURL=rectangle.js.map
  1942. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1943. var __extends = (this && this.__extends) || (function () {
  1944. var extendStatics = Object.setPrototypeOf ||
  1945. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1946. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1947. return function (d, b) {
  1948. extendStatics(d, b);
  1949. function __() { this.constructor = d; }
  1950. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1951. };
  1952. })();
  1953. var BABYLON;
  1954. (function (BABYLON) {
  1955. var GUI;
  1956. (function (GUI) {
  1957. var Ellipse = (function (_super) {
  1958. __extends(Ellipse, _super);
  1959. function Ellipse(name) {
  1960. var _this = _super.call(this, name) || this;
  1961. _this.name = name;
  1962. _this._thickness = 1;
  1963. return _this;
  1964. }
  1965. Object.defineProperty(Ellipse.prototype, "thickness", {
  1966. get: function () {
  1967. return this._thickness;
  1968. },
  1969. set: function (value) {
  1970. if (this._thickness === value) {
  1971. return;
  1972. }
  1973. this._thickness = value;
  1974. this._markAsDirty();
  1975. },
  1976. enumerable: true,
  1977. configurable: true
  1978. });
  1979. Ellipse.prototype._getTypeName = function () {
  1980. return "Ellipse";
  1981. };
  1982. Ellipse.prototype._localDraw = function (context) {
  1983. context.save();
  1984. 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);
  1985. if (this._background) {
  1986. context.fillStyle = this._background;
  1987. context.fill();
  1988. }
  1989. if (this._thickness) {
  1990. if (this.color) {
  1991. context.strokeStyle = this.color;
  1992. }
  1993. context.lineWidth = this._thickness;
  1994. context.stroke();
  1995. }
  1996. context.restore();
  1997. };
  1998. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  1999. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2000. this._measureForChildren.width -= 2 * this._thickness;
  2001. this._measureForChildren.height -= 2 * this._thickness;
  2002. this._measureForChildren.left += this._thickness;
  2003. this._measureForChildren.top += this._thickness;
  2004. };
  2005. Ellipse.prototype._clipForChildren = function (context) {
  2006. 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);
  2007. context.clip();
  2008. };
  2009. return Ellipse;
  2010. }(GUI.Container));
  2011. GUI.Ellipse = Ellipse;
  2012. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2013. })(BABYLON || (BABYLON = {}));
  2014. //# sourceMappingURL=ellipse.js.map
  2015. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2016. var __extends = (this && this.__extends) || (function () {
  2017. var extendStatics = Object.setPrototypeOf ||
  2018. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2019. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2020. return function (d, b) {
  2021. extendStatics(d, b);
  2022. function __() { this.constructor = d; }
  2023. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2024. };
  2025. })();
  2026. var DOMImage = Image;
  2027. var BABYLON;
  2028. (function (BABYLON) {
  2029. var GUI;
  2030. (function (GUI) {
  2031. var Line = (function (_super) {
  2032. __extends(Line, _super);
  2033. function Line(name) {
  2034. var _this = _super.call(this, name) || this;
  2035. _this.name = name;
  2036. _this._lineWidth = 1;
  2037. _this._x1 = new GUI.ValueAndUnit(0);
  2038. _this._y1 = new GUI.ValueAndUnit(0);
  2039. _this._x2 = new GUI.ValueAndUnit(0);
  2040. _this._y2 = new GUI.ValueAndUnit(0);
  2041. _this._dash = new Array();
  2042. _this.isHitTestVisible = false;
  2043. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2044. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2045. return _this;
  2046. }
  2047. Object.defineProperty(Line.prototype, "dash", {
  2048. get: function () {
  2049. return this._dash;
  2050. },
  2051. set: function (value) {
  2052. if (this._dash === value) {
  2053. return;
  2054. }
  2055. this._dash = value;
  2056. this._markAsDirty();
  2057. },
  2058. enumerable: true,
  2059. configurable: true
  2060. });
  2061. Object.defineProperty(Line.prototype, "connectedControl", {
  2062. get: function () {
  2063. return this._connectedControl;
  2064. },
  2065. set: function (value) {
  2066. var _this = this;
  2067. if (this._connectedControl === value) {
  2068. return;
  2069. }
  2070. if (this._connectedControlDirtyObserver && this._connectedControl) {
  2071. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  2072. this._connectedControlDirtyObserver = null;
  2073. }
  2074. if (value) {
  2075. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  2076. }
  2077. this._connectedControl = value;
  2078. this._markAsDirty();
  2079. },
  2080. enumerable: true,
  2081. configurable: true
  2082. });
  2083. Object.defineProperty(Line.prototype, "x1", {
  2084. get: function () {
  2085. return this._x1.toString(this._host);
  2086. },
  2087. set: function (value) {
  2088. if (this._x1.toString(this._host) === value) {
  2089. return;
  2090. }
  2091. if (this._x1.fromString(value)) {
  2092. this._markAsDirty();
  2093. }
  2094. },
  2095. enumerable: true,
  2096. configurable: true
  2097. });
  2098. Object.defineProperty(Line.prototype, "y1", {
  2099. get: function () {
  2100. return this._y1.toString(this._host);
  2101. },
  2102. set: function (value) {
  2103. if (this._y1.toString(this._host) === value) {
  2104. return;
  2105. }
  2106. if (this._y1.fromString(value)) {
  2107. this._markAsDirty();
  2108. }
  2109. },
  2110. enumerable: true,
  2111. configurable: true
  2112. });
  2113. Object.defineProperty(Line.prototype, "x2", {
  2114. get: function () {
  2115. return this._x2.toString(this._host);
  2116. },
  2117. set: function (value) {
  2118. if (this._x2.toString(this._host) === value) {
  2119. return;
  2120. }
  2121. if (this._x2.fromString(value)) {
  2122. this._markAsDirty();
  2123. }
  2124. },
  2125. enumerable: true,
  2126. configurable: true
  2127. });
  2128. Object.defineProperty(Line.prototype, "y2", {
  2129. get: function () {
  2130. return this._y2.toString(this._host);
  2131. },
  2132. set: function (value) {
  2133. if (this._y2.toString(this._host) === value) {
  2134. return;
  2135. }
  2136. if (this._y2.fromString(value)) {
  2137. this._markAsDirty();
  2138. }
  2139. },
  2140. enumerable: true,
  2141. configurable: true
  2142. });
  2143. Object.defineProperty(Line.prototype, "lineWidth", {
  2144. get: function () {
  2145. return this._lineWidth;
  2146. },
  2147. set: function (value) {
  2148. if (this._lineWidth === value) {
  2149. return;
  2150. }
  2151. this._lineWidth = value;
  2152. this._markAsDirty();
  2153. },
  2154. enumerable: true,
  2155. configurable: true
  2156. });
  2157. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  2158. set: function (value) {
  2159. return;
  2160. },
  2161. enumerable: true,
  2162. configurable: true
  2163. });
  2164. Object.defineProperty(Line.prototype, "verticalAlignment", {
  2165. set: function (value) {
  2166. return;
  2167. },
  2168. enumerable: true,
  2169. configurable: true
  2170. });
  2171. Object.defineProperty(Line.prototype, "_effectiveX2", {
  2172. get: function () {
  2173. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  2174. },
  2175. enumerable: true,
  2176. configurable: true
  2177. });
  2178. Object.defineProperty(Line.prototype, "_effectiveY2", {
  2179. get: function () {
  2180. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  2181. },
  2182. enumerable: true,
  2183. configurable: true
  2184. });
  2185. Line.prototype._getTypeName = function () {
  2186. return "Line";
  2187. };
  2188. Line.prototype._draw = function (parentMeasure, context) {
  2189. context.save();
  2190. this._applyStates(context);
  2191. if (this._processMeasures(parentMeasure, context)) {
  2192. context.strokeStyle = this.color;
  2193. context.lineWidth = this._lineWidth;
  2194. context.setLineDash(this._dash);
  2195. context.beginPath();
  2196. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  2197. context.lineTo(this._effectiveX2, this._effectiveY2);
  2198. context.stroke();
  2199. }
  2200. context.restore();
  2201. };
  2202. Line.prototype._measure = function () {
  2203. // Width / Height
  2204. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  2205. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  2206. };
  2207. Line.prototype._computeAlignment = function (parentMeasure, context) {
  2208. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  2209. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  2210. };
  2211. Line.prototype._moveToProjectedPosition = function (projectedPosition) {
  2212. this.x1 = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  2213. this.y1 = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  2214. this._x1.ignoreAdaptiveScaling = true;
  2215. this._y1.ignoreAdaptiveScaling = true;
  2216. };
  2217. return Line;
  2218. }(GUI.Control));
  2219. GUI.Line = Line;
  2220. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2221. })(BABYLON || (BABYLON = {}));
  2222. //# sourceMappingURL=line.js.map
  2223. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2224. var __extends = (this && this.__extends) || (function () {
  2225. var extendStatics = Object.setPrototypeOf ||
  2226. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2227. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2228. return function (d, b) {
  2229. extendStatics(d, b);
  2230. function __() { this.constructor = d; }
  2231. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2232. };
  2233. })();
  2234. var DOMImage = Image;
  2235. var BABYLON;
  2236. (function (BABYLON) {
  2237. var GUI;
  2238. (function (GUI) {
  2239. var Slider = (function (_super) {
  2240. __extends(Slider, _super);
  2241. function Slider(name) {
  2242. var _this = _super.call(this, name) || this;
  2243. _this.name = name;
  2244. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2245. _this._minimum = 0;
  2246. _this._maximum = 100;
  2247. _this._value = 50;
  2248. _this._background = "black";
  2249. _this._borderColor = "white";
  2250. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2251. _this.onValueChangedObservable = new BABYLON.Observable();
  2252. // Events
  2253. _this._pointerIsDown = false;
  2254. _this.isPointerBlocker = true;
  2255. return _this;
  2256. }
  2257. Object.defineProperty(Slider.prototype, "borderColor", {
  2258. get: function () {
  2259. return this._borderColor;
  2260. },
  2261. set: function (value) {
  2262. if (this._borderColor === value) {
  2263. return;
  2264. }
  2265. this._borderColor = value;
  2266. this._markAsDirty();
  2267. },
  2268. enumerable: true,
  2269. configurable: true
  2270. });
  2271. Object.defineProperty(Slider.prototype, "background", {
  2272. get: function () {
  2273. return this._background;
  2274. },
  2275. set: function (value) {
  2276. if (this._background === value) {
  2277. return;
  2278. }
  2279. this._background = value;
  2280. this._markAsDirty();
  2281. },
  2282. enumerable: true,
  2283. configurable: true
  2284. });
  2285. Object.defineProperty(Slider.prototype, "barOffset", {
  2286. get: function () {
  2287. return this._barOffset.toString(this._host);
  2288. },
  2289. set: function (value) {
  2290. if (this._barOffset.toString(this._host) === value) {
  2291. return;
  2292. }
  2293. if (this._barOffset.fromString(value)) {
  2294. this._markAsDirty();
  2295. }
  2296. },
  2297. enumerable: true,
  2298. configurable: true
  2299. });
  2300. Object.defineProperty(Slider.prototype, "thumbWidth", {
  2301. get: function () {
  2302. return this._thumbWidth.toString(this._host);
  2303. },
  2304. set: function (value) {
  2305. if (this._thumbWidth.toString(this._host) === value) {
  2306. return;
  2307. }
  2308. if (this._thumbWidth.fromString(value)) {
  2309. this._markAsDirty();
  2310. }
  2311. },
  2312. enumerable: true,
  2313. configurable: true
  2314. });
  2315. Object.defineProperty(Slider.prototype, "minimum", {
  2316. get: function () {
  2317. return this._minimum;
  2318. },
  2319. set: function (value) {
  2320. if (this._minimum === value) {
  2321. return;
  2322. }
  2323. this._minimum = value;
  2324. this._markAsDirty();
  2325. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2326. },
  2327. enumerable: true,
  2328. configurable: true
  2329. });
  2330. Object.defineProperty(Slider.prototype, "maximum", {
  2331. get: function () {
  2332. return this._maximum;
  2333. },
  2334. set: function (value) {
  2335. if (this._maximum === value) {
  2336. return;
  2337. }
  2338. this._maximum = value;
  2339. this._markAsDirty();
  2340. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2341. },
  2342. enumerable: true,
  2343. configurable: true
  2344. });
  2345. Object.defineProperty(Slider.prototype, "value", {
  2346. get: function () {
  2347. return this._value;
  2348. },
  2349. set: function (value) {
  2350. value = Math.max(Math.min(value, this._maximum), this._minimum);
  2351. if (this._value === value) {
  2352. return;
  2353. }
  2354. this._value = value;
  2355. this._markAsDirty();
  2356. this.onValueChangedObservable.notifyObservers(this._value);
  2357. },
  2358. enumerable: true,
  2359. configurable: true
  2360. });
  2361. Slider.prototype._getTypeName = function () {
  2362. return "Slider";
  2363. };
  2364. Slider.prototype._draw = function (parentMeasure, context) {
  2365. context.save();
  2366. this._applyStates(context);
  2367. if (this._processMeasures(parentMeasure, context)) {
  2368. // Main bar
  2369. var effectiveThumbWidth;
  2370. var effectiveBarOffset;
  2371. if (this._thumbWidth.isPixel) {
  2372. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.height);
  2373. }
  2374. else {
  2375. effectiveThumbWidth = this._currentMeasure.height * this._thumbWidth.getValue(this._host);
  2376. }
  2377. if (this._barOffset.isPixel) {
  2378. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  2379. }
  2380. else {
  2381. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  2382. }
  2383. var left = this._currentMeasure.left + effectiveThumbWidth / 2;
  2384. var width = this._currentMeasure.width - effectiveThumbWidth;
  2385. var thumbPosition = (this._value - this._minimum) / (this._maximum - this._minimum) * width;
  2386. // Bar
  2387. context.fillStyle = this._background;
  2388. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  2389. context.fillStyle = this.color;
  2390. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  2391. // Thumb
  2392. context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2393. context.strokeStyle = this._borderColor;
  2394. context.strokeRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2395. }
  2396. context.restore();
  2397. };
  2398. Slider.prototype._updateValueFromPointer = function (x) {
  2399. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  2400. };
  2401. Slider.prototype._onPointerDown = function (coordinates) {
  2402. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  2403. return false;
  2404. }
  2405. this._pointerIsDown = true;
  2406. this._updateValueFromPointer(coordinates.x);
  2407. this._host._capturingControl = this;
  2408. return true;
  2409. };
  2410. Slider.prototype._onPointerMove = function (coordinates) {
  2411. if (this._pointerIsDown) {
  2412. this._updateValueFromPointer(coordinates.x);
  2413. }
  2414. };
  2415. Slider.prototype._onPointerUp = function (coordinates) {
  2416. this._pointerIsDown = false;
  2417. this._host._capturingControl = null;
  2418. _super.prototype._onPointerUp.call(this, coordinates);
  2419. };
  2420. return Slider;
  2421. }(GUI.Control));
  2422. GUI.Slider = Slider;
  2423. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2424. })(BABYLON || (BABYLON = {}));
  2425. //# sourceMappingURL=slider.js.map
  2426. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2427. var __extends = (this && this.__extends) || (function () {
  2428. var extendStatics = Object.setPrototypeOf ||
  2429. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2430. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2431. return function (d, b) {
  2432. extendStatics(d, b);
  2433. function __() { this.constructor = d; }
  2434. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2435. };
  2436. })();
  2437. var DOMImage = Image;
  2438. var BABYLON;
  2439. (function (BABYLON) {
  2440. var GUI;
  2441. (function (GUI) {
  2442. var Checkbox = (function (_super) {
  2443. __extends(Checkbox, _super);
  2444. function Checkbox(name) {
  2445. var _this = _super.call(this, name) || this;
  2446. _this.name = name;
  2447. _this._isChecked = false;
  2448. _this._background = "black";
  2449. _this._checkSizeRatio = 0.8;
  2450. _this._thickness = 1;
  2451. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2452. _this.isPointerBlocker = true;
  2453. return _this;
  2454. }
  2455. Object.defineProperty(Checkbox.prototype, "thickness", {
  2456. get: function () {
  2457. return this._thickness;
  2458. },
  2459. set: function (value) {
  2460. if (this._thickness === value) {
  2461. return;
  2462. }
  2463. this._thickness = value;
  2464. this._markAsDirty();
  2465. },
  2466. enumerable: true,
  2467. configurable: true
  2468. });
  2469. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  2470. get: function () {
  2471. return this._checkSizeRatio;
  2472. },
  2473. set: function (value) {
  2474. value = Math.max(Math.min(1, value), 0);
  2475. if (this._checkSizeRatio === value) {
  2476. return;
  2477. }
  2478. this._checkSizeRatio = value;
  2479. this._markAsDirty();
  2480. },
  2481. enumerable: true,
  2482. configurable: true
  2483. });
  2484. Object.defineProperty(Checkbox.prototype, "background", {
  2485. get: function () {
  2486. return this._background;
  2487. },
  2488. set: function (value) {
  2489. if (this._background === value) {
  2490. return;
  2491. }
  2492. this._background = value;
  2493. this._markAsDirty();
  2494. },
  2495. enumerable: true,
  2496. configurable: true
  2497. });
  2498. Object.defineProperty(Checkbox.prototype, "isChecked", {
  2499. get: function () {
  2500. return this._isChecked;
  2501. },
  2502. set: function (value) {
  2503. if (this._isChecked === value) {
  2504. return;
  2505. }
  2506. this._isChecked = value;
  2507. this._markAsDirty();
  2508. this.onIsCheckedChangedObservable.notifyObservers(value);
  2509. },
  2510. enumerable: true,
  2511. configurable: true
  2512. });
  2513. Checkbox.prototype._getTypeName = function () {
  2514. return "CheckBox";
  2515. };
  2516. Checkbox.prototype._draw = function (parentMeasure, context) {
  2517. context.save();
  2518. this._applyStates(context);
  2519. if (this._processMeasures(parentMeasure, context)) {
  2520. var actualWidth = this._currentMeasure.width - this._thickness;
  2521. var actualHeight = this._currentMeasure.height - this._thickness;
  2522. context.fillStyle = this._background;
  2523. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2524. if (this._isChecked) {
  2525. context.fillStyle = this.color;
  2526. var offsetWidth = actualWidth * this._checkSizeRatio;
  2527. var offseHeight = actualHeight * this._checkSizeRatio;
  2528. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  2529. }
  2530. context.strokeStyle = this.color;
  2531. context.lineWidth = this._thickness;
  2532. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2533. }
  2534. context.restore();
  2535. };
  2536. // Events
  2537. Checkbox.prototype._onPointerDown = function (coordinates) {
  2538. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  2539. return false;
  2540. }
  2541. this.isChecked = !this.isChecked;
  2542. return true;
  2543. };
  2544. return Checkbox;
  2545. }(GUI.Control));
  2546. GUI.Checkbox = Checkbox;
  2547. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2548. })(BABYLON || (BABYLON = {}));
  2549. //# sourceMappingURL=checkBox.js.map
  2550. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2551. var __extends = (this && this.__extends) || (function () {
  2552. var extendStatics = Object.setPrototypeOf ||
  2553. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2554. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2555. return function (d, b) {
  2556. extendStatics(d, b);
  2557. function __() { this.constructor = d; }
  2558. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2559. };
  2560. })();
  2561. var DOMImage = Image;
  2562. var BABYLON;
  2563. (function (BABYLON) {
  2564. var GUI;
  2565. (function (GUI) {
  2566. var RadioButton = (function (_super) {
  2567. __extends(RadioButton, _super);
  2568. function RadioButton(name) {
  2569. var _this = _super.call(this, name) || this;
  2570. _this.name = name;
  2571. _this._isChecked = false;
  2572. _this._background = "black";
  2573. _this._checkSizeRatio = 0.8;
  2574. _this._thickness = 1;
  2575. _this.group = "";
  2576. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2577. _this.isPointerBlocker = true;
  2578. return _this;
  2579. }
  2580. Object.defineProperty(RadioButton.prototype, "thickness", {
  2581. get: function () {
  2582. return this._thickness;
  2583. },
  2584. set: function (value) {
  2585. if (this._thickness === value) {
  2586. return;
  2587. }
  2588. this._thickness = value;
  2589. this._markAsDirty();
  2590. },
  2591. enumerable: true,
  2592. configurable: true
  2593. });
  2594. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  2595. get: function () {
  2596. return this._checkSizeRatio;
  2597. },
  2598. set: function (value) {
  2599. value = Math.max(Math.min(1, value), 0);
  2600. if (this._checkSizeRatio === value) {
  2601. return;
  2602. }
  2603. this._checkSizeRatio = value;
  2604. this._markAsDirty();
  2605. },
  2606. enumerable: true,
  2607. configurable: true
  2608. });
  2609. Object.defineProperty(RadioButton.prototype, "background", {
  2610. get: function () {
  2611. return this._background;
  2612. },
  2613. set: function (value) {
  2614. if (this._background === value) {
  2615. return;
  2616. }
  2617. this._background = value;
  2618. this._markAsDirty();
  2619. },
  2620. enumerable: true,
  2621. configurable: true
  2622. });
  2623. Object.defineProperty(RadioButton.prototype, "isChecked", {
  2624. get: function () {
  2625. return this._isChecked;
  2626. },
  2627. set: function (value) {
  2628. var _this = this;
  2629. if (this._isChecked === value) {
  2630. return;
  2631. }
  2632. this._isChecked = value;
  2633. this._markAsDirty();
  2634. this.onIsCheckedChangedObservable.notifyObservers(value);
  2635. if (this._isChecked) {
  2636. // Update all controls from same group
  2637. this._host.executeOnAllControls(function (control) {
  2638. if (control === _this) {
  2639. return;
  2640. }
  2641. if (control.group === undefined) {
  2642. return;
  2643. }
  2644. var childRadio = control;
  2645. if (childRadio.group === _this.group) {
  2646. childRadio.isChecked = false;
  2647. }
  2648. });
  2649. }
  2650. },
  2651. enumerable: true,
  2652. configurable: true
  2653. });
  2654. RadioButton.prototype._getTypeName = function () {
  2655. return "RadioButton";
  2656. };
  2657. RadioButton.prototype._draw = function (parentMeasure, context) {
  2658. context.save();
  2659. this._applyStates(context);
  2660. if (this._processMeasures(parentMeasure, context)) {
  2661. var actualWidth = this._currentMeasure.width - this._thickness;
  2662. var actualHeight = this._currentMeasure.height - this._thickness;
  2663. // Outer
  2664. 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);
  2665. context.fillStyle = this._background;
  2666. context.fill();
  2667. context.strokeStyle = this.color;
  2668. context.lineWidth = this._thickness;
  2669. context.stroke();
  2670. // Inner
  2671. if (this._isChecked) {
  2672. context.fillStyle = this.color;
  2673. var offsetWidth = actualWidth * this._checkSizeRatio;
  2674. var offseHeight = actualHeight * this._checkSizeRatio;
  2675. 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);
  2676. context.fill();
  2677. }
  2678. }
  2679. context.restore();
  2680. };
  2681. // Events
  2682. RadioButton.prototype._onPointerDown = function (coordinates) {
  2683. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  2684. return false;
  2685. }
  2686. this.isChecked = !this.isChecked;
  2687. return true;
  2688. };
  2689. return RadioButton;
  2690. }(GUI.Control));
  2691. GUI.RadioButton = RadioButton;
  2692. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2693. })(BABYLON || (BABYLON = {}));
  2694. //# sourceMappingURL=radioButton.js.map
  2695. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2696. var __extends = (this && this.__extends) || (function () {
  2697. var extendStatics = Object.setPrototypeOf ||
  2698. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2699. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2700. return function (d, b) {
  2701. extendStatics(d, b);
  2702. function __() { this.constructor = d; }
  2703. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2704. };
  2705. })();
  2706. var BABYLON;
  2707. (function (BABYLON) {
  2708. var GUI;
  2709. (function (GUI) {
  2710. var TextBlock = (function (_super) {
  2711. __extends(TextBlock, _super);
  2712. function TextBlock(name, text) {
  2713. if (text === void 0) { text = ""; }
  2714. var _this = _super.call(this, name) || this;
  2715. _this.name = name;
  2716. _this._text = "";
  2717. _this._textWrapping = false;
  2718. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  2719. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  2720. _this.text = text;
  2721. return _this;
  2722. }
  2723. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  2724. get: function () {
  2725. return this._textWrapping;
  2726. },
  2727. set: function (value) {
  2728. if (this._textWrapping === value) {
  2729. return;
  2730. }
  2731. this._textWrapping = value;
  2732. this._markAsDirty();
  2733. },
  2734. enumerable: true,
  2735. configurable: true
  2736. });
  2737. Object.defineProperty(TextBlock.prototype, "text", {
  2738. get: function () {
  2739. return this._text;
  2740. },
  2741. set: function (value) {
  2742. if (this._text === value) {
  2743. return;
  2744. }
  2745. this._text = value;
  2746. this._markAsDirty();
  2747. },
  2748. enumerable: true,
  2749. configurable: true
  2750. });
  2751. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  2752. get: function () {
  2753. return this._textHorizontalAlignment;
  2754. },
  2755. set: function (value) {
  2756. if (this._textHorizontalAlignment === value) {
  2757. return;
  2758. }
  2759. this._textHorizontalAlignment = value;
  2760. this._markAsDirty();
  2761. },
  2762. enumerable: true,
  2763. configurable: true
  2764. });
  2765. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  2766. get: function () {
  2767. return this._textVerticalAlignment;
  2768. },
  2769. set: function (value) {
  2770. if (this._textVerticalAlignment === value) {
  2771. return;
  2772. }
  2773. this._textVerticalAlignment = value;
  2774. this._markAsDirty();
  2775. },
  2776. enumerable: true,
  2777. configurable: true
  2778. });
  2779. TextBlock.prototype._getTypeName = function () {
  2780. return "TextBlock";
  2781. };
  2782. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  2783. var width = this._currentMeasure.width;
  2784. var x = 0;
  2785. switch (this._textHorizontalAlignment) {
  2786. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  2787. x = 0;
  2788. break;
  2789. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  2790. x = width - textWidth;
  2791. break;
  2792. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  2793. x = (width - textWidth) / 2;
  2794. break;
  2795. }
  2796. context.fillText(text, this._currentMeasure.left + x, y);
  2797. };
  2798. TextBlock.prototype._draw = function (parentMeasure, context) {
  2799. context.save();
  2800. this._applyStates(context);
  2801. if (this._processMeasures(parentMeasure, context)) {
  2802. // Render lines
  2803. this._renderLines(context);
  2804. }
  2805. context.restore();
  2806. };
  2807. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  2808. this._lines = [];
  2809. var _lines = this.text.split("\n");
  2810. if (this._textWrapping) {
  2811. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  2812. var _line = _lines_1[_i];
  2813. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  2814. }
  2815. }
  2816. else {
  2817. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  2818. var _line = _lines_2[_a];
  2819. this._lines.push(this._parseLine(_line, context));
  2820. }
  2821. }
  2822. };
  2823. TextBlock.prototype._parseLine = function (line, context) {
  2824. if (line === void 0) { line = ''; }
  2825. return { text: line, width: context.measureText(line).width };
  2826. };
  2827. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  2828. if (line === void 0) { line = ''; }
  2829. var words = line.split(' ');
  2830. var width = this._currentMeasure.width;
  2831. var lineWidth = 0;
  2832. for (var n = 0; n < words.length; n++) {
  2833. var testLine = n > 0 ? line + " " + words[n] : words[0];
  2834. var metrics = context.measureText(testLine);
  2835. var testWidth = metrics.width;
  2836. if (testWidth > width && n > 0) {
  2837. this._lines.push({ text: line, width: lineWidth });
  2838. line = words[n];
  2839. lineWidth = context.measureText(line).width;
  2840. }
  2841. else {
  2842. lineWidth = testWidth;
  2843. line = testLine;
  2844. }
  2845. }
  2846. return { text: line, width: lineWidth };
  2847. };
  2848. TextBlock.prototype._renderLines = function (context) {
  2849. var width = this._currentMeasure.width;
  2850. var height = this._currentMeasure.height;
  2851. if (!this._fontOffset) {
  2852. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  2853. }
  2854. var rootY = 0;
  2855. switch (this._textVerticalAlignment) {
  2856. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  2857. rootY = this._fontOffset.ascent;
  2858. break;
  2859. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  2860. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  2861. break;
  2862. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  2863. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  2864. break;
  2865. }
  2866. rootY += this._currentMeasure.top;
  2867. for (var _i = 0, _a = this._lines; _i < _a.length; _i++) {
  2868. var line = _a[_i];
  2869. this._drawText(line.text, line.width, rootY, context);
  2870. rootY += this._fontOffset.height;
  2871. }
  2872. };
  2873. return TextBlock;
  2874. }(GUI.Control));
  2875. GUI.TextBlock = TextBlock;
  2876. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2877. })(BABYLON || (BABYLON = {}));
  2878. //# sourceMappingURL=textBlock.js.map
  2879. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2880. var __extends = (this && this.__extends) || (function () {
  2881. var extendStatics = Object.setPrototypeOf ||
  2882. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2883. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2884. return function (d, b) {
  2885. extendStatics(d, b);
  2886. function __() { this.constructor = d; }
  2887. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2888. };
  2889. })();
  2890. var DOMImage = Image;
  2891. var BABYLON;
  2892. (function (BABYLON) {
  2893. var GUI;
  2894. (function (GUI) {
  2895. var Image = (function (_super) {
  2896. __extends(Image, _super);
  2897. function Image(name, url) {
  2898. var _this = _super.call(this, name) || this;
  2899. _this.name = name;
  2900. _this._loaded = false;
  2901. _this._stretch = Image.STRETCH_FILL;
  2902. _this._autoScale = false;
  2903. _this._sourceLeft = 0;
  2904. _this._sourceTop = 0;
  2905. _this._sourceWidth = 0;
  2906. _this._sourceHeight = 0;
  2907. _this.source = url;
  2908. return _this;
  2909. }
  2910. Object.defineProperty(Image.prototype, "sourceLeft", {
  2911. get: function () {
  2912. return this._sourceLeft;
  2913. },
  2914. set: function (value) {
  2915. if (this._sourceLeft === value) {
  2916. return;
  2917. }
  2918. this._sourceLeft = value;
  2919. this._markAsDirty();
  2920. },
  2921. enumerable: true,
  2922. configurable: true
  2923. });
  2924. Object.defineProperty(Image.prototype, "sourceTop", {
  2925. get: function () {
  2926. return this._sourceTop;
  2927. },
  2928. set: function (value) {
  2929. if (this._sourceTop === value) {
  2930. return;
  2931. }
  2932. this._sourceTop = value;
  2933. this._markAsDirty();
  2934. },
  2935. enumerable: true,
  2936. configurable: true
  2937. });
  2938. Object.defineProperty(Image.prototype, "sourceWidth", {
  2939. get: function () {
  2940. return this._sourceWidth;
  2941. },
  2942. set: function (value) {
  2943. if (this._sourceWidth === value) {
  2944. return;
  2945. }
  2946. this._sourceWidth = value;
  2947. this._markAsDirty();
  2948. },
  2949. enumerable: true,
  2950. configurable: true
  2951. });
  2952. Object.defineProperty(Image.prototype, "sourceHeight", {
  2953. get: function () {
  2954. return this._sourceHeight;
  2955. },
  2956. set: function (value) {
  2957. if (this._sourceHeight === value) {
  2958. return;
  2959. }
  2960. this._sourceHeight = value;
  2961. this._markAsDirty();
  2962. },
  2963. enumerable: true,
  2964. configurable: true
  2965. });
  2966. Object.defineProperty(Image.prototype, "autoScale", {
  2967. get: function () {
  2968. return this._autoScale;
  2969. },
  2970. set: function (value) {
  2971. if (this._autoScale === value) {
  2972. return;
  2973. }
  2974. this._autoScale = value;
  2975. if (value && this._loaded) {
  2976. this.synchronizeSizeWithContent();
  2977. }
  2978. },
  2979. enumerable: true,
  2980. configurable: true
  2981. });
  2982. Object.defineProperty(Image.prototype, "stretch", {
  2983. get: function () {
  2984. return this._stretch;
  2985. },
  2986. set: function (value) {
  2987. if (this._stretch === value) {
  2988. return;
  2989. }
  2990. this._stretch = value;
  2991. this._markAsDirty();
  2992. },
  2993. enumerable: true,
  2994. configurable: true
  2995. });
  2996. Object.defineProperty(Image.prototype, "domImage", {
  2997. get: function () {
  2998. return this._domImage;
  2999. },
  3000. set: function (value) {
  3001. var _this = this;
  3002. this._domImage = value;
  3003. this._loaded = false;
  3004. if (this._domImage.width) {
  3005. this._onImageLoaded();
  3006. }
  3007. else {
  3008. this._domImage.onload = function () {
  3009. _this._onImageLoaded();
  3010. };
  3011. }
  3012. },
  3013. enumerable: true,
  3014. configurable: true
  3015. });
  3016. Image.prototype._onImageLoaded = function () {
  3017. this._imageWidth = this._domImage.width;
  3018. this._imageHeight = this._domImage.height;
  3019. this._loaded = true;
  3020. if (this._autoScale) {
  3021. this.synchronizeSizeWithContent();
  3022. }
  3023. this._markAsDirty();
  3024. };
  3025. Object.defineProperty(Image.prototype, "source", {
  3026. set: function (value) {
  3027. var _this = this;
  3028. if (this._source === value) {
  3029. return;
  3030. }
  3031. this._loaded = false;
  3032. this._source = value;
  3033. this._domImage = new DOMImage();
  3034. this._domImage.onload = function () {
  3035. _this._onImageLoaded();
  3036. };
  3037. this._domImage.crossOrigin = "anonymous";
  3038. this._domImage.src = value;
  3039. },
  3040. enumerable: true,
  3041. configurable: true
  3042. });
  3043. Image.prototype._getTypeName = function () {
  3044. return "Image";
  3045. };
  3046. Image.prototype.synchronizeSizeWithContent = function () {
  3047. if (!this._loaded) {
  3048. return;
  3049. }
  3050. this.width = this._domImage.width + "px";
  3051. this.height = this._domImage.height + "px";
  3052. };
  3053. Image.prototype._draw = function (parentMeasure, context) {
  3054. context.save();
  3055. var x = this._sourceLeft;
  3056. var y = this._sourceTop;
  3057. var width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  3058. var height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  3059. this._applyStates(context);
  3060. if (this._processMeasures(parentMeasure, context)) {
  3061. if (this._loaded) {
  3062. switch (this._stretch) {
  3063. case Image.STRETCH_NONE:
  3064. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3065. break;
  3066. case Image.STRETCH_FILL:
  3067. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3068. break;
  3069. case Image.STRETCH_UNIFORM:
  3070. var hRatio = this._currentMeasure.width / width;
  3071. var vRatio = this._currentMeasure.height / height;
  3072. var ratio = Math.min(hRatio, vRatio);
  3073. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  3074. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  3075. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  3076. break;
  3077. case Image.STRETCH_EXTEND:
  3078. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3079. if (this._autoScale) {
  3080. this.synchronizeSizeWithContent();
  3081. }
  3082. this._root.width = this.width;
  3083. this._root.height = this.height;
  3084. break;
  3085. }
  3086. }
  3087. }
  3088. context.restore();
  3089. };
  3090. Object.defineProperty(Image, "STRETCH_NONE", {
  3091. get: function () {
  3092. return Image._STRETCH_NONE;
  3093. },
  3094. enumerable: true,
  3095. configurable: true
  3096. });
  3097. Object.defineProperty(Image, "STRETCH_FILL", {
  3098. get: function () {
  3099. return Image._STRETCH_FILL;
  3100. },
  3101. enumerable: true,
  3102. configurable: true
  3103. });
  3104. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  3105. get: function () {
  3106. return Image._STRETCH_UNIFORM;
  3107. },
  3108. enumerable: true,
  3109. configurable: true
  3110. });
  3111. Object.defineProperty(Image, "STRETCH_EXTEND", {
  3112. get: function () {
  3113. return Image._STRETCH_EXTEND;
  3114. },
  3115. enumerable: true,
  3116. configurable: true
  3117. });
  3118. return Image;
  3119. }(GUI.Control));
  3120. // Static
  3121. Image._STRETCH_NONE = 0;
  3122. Image._STRETCH_FILL = 1;
  3123. Image._STRETCH_UNIFORM = 2;
  3124. Image._STRETCH_EXTEND = 3;
  3125. GUI.Image = Image;
  3126. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3127. })(BABYLON || (BABYLON = {}));
  3128. //# sourceMappingURL=image.js.map
  3129. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3130. var __extends = (this && this.__extends) || (function () {
  3131. var extendStatics = Object.setPrototypeOf ||
  3132. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3133. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3134. return function (d, b) {
  3135. extendStatics(d, b);
  3136. function __() { this.constructor = d; }
  3137. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3138. };
  3139. })();
  3140. var BABYLON;
  3141. (function (BABYLON) {
  3142. var GUI;
  3143. (function (GUI) {
  3144. var Button = (function (_super) {
  3145. __extends(Button, _super);
  3146. function Button(name) {
  3147. var _this = _super.call(this, name) || this;
  3148. _this.name = name;
  3149. _this.thickness = 1;
  3150. _this.isPointerBlocker = true;
  3151. _this.pointerEnterAnimation = function () {
  3152. _this.alpha -= 0.1;
  3153. };
  3154. _this.pointerOutAnimation = function () {
  3155. _this.alpha += 0.1;
  3156. };
  3157. _this.pointerDownAnimation = function () {
  3158. _this.scaleX -= 0.05;
  3159. _this.scaleY -= 0.05;
  3160. };
  3161. _this.pointerUpAnimation = function () {
  3162. _this.scaleX += 0.05;
  3163. _this.scaleY += 0.05;
  3164. };
  3165. return _this;
  3166. }
  3167. Button.prototype._getTypeName = function () {
  3168. return "Button";
  3169. };
  3170. // While being a container, the button behaves like a control.
  3171. Button.prototype._processPicking = function (x, y, type) {
  3172. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  3173. return false;
  3174. }
  3175. if (!_super.prototype.contains.call(this, x, y)) {
  3176. return false;
  3177. }
  3178. this._processObservables(type, x, y);
  3179. return true;
  3180. };
  3181. Button.prototype._onPointerEnter = function () {
  3182. if (!_super.prototype._onPointerEnter.call(this)) {
  3183. return false;
  3184. }
  3185. if (this.pointerEnterAnimation) {
  3186. this.pointerEnterAnimation();
  3187. }
  3188. return true;
  3189. };
  3190. Button.prototype._onPointerOut = function () {
  3191. if (this.pointerOutAnimation) {
  3192. this.pointerOutAnimation();
  3193. }
  3194. _super.prototype._onPointerOut.call(this);
  3195. };
  3196. Button.prototype._onPointerDown = function (coordinates) {
  3197. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  3198. return false;
  3199. }
  3200. if (this.pointerDownAnimation) {
  3201. this.pointerDownAnimation();
  3202. }
  3203. return true;
  3204. };
  3205. Button.prototype._onPointerUp = function (coordinates) {
  3206. if (this.pointerUpAnimation) {
  3207. this.pointerUpAnimation();
  3208. }
  3209. _super.prototype._onPointerUp.call(this, coordinates);
  3210. };
  3211. // Statics
  3212. Button.CreateImageButton = function (name, text, imageUrl) {
  3213. var result = new Button(name);
  3214. // Adding text
  3215. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3216. textBlock.textWrapping = true;
  3217. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3218. textBlock.paddingLeft = "20%";
  3219. result.addControl(textBlock);
  3220. // Adding image
  3221. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3222. iconImage.width = "20%";
  3223. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  3224. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3225. result.addControl(iconImage);
  3226. return result;
  3227. };
  3228. Button.CreateImageOnlyButton = function (name, imageUrl) {
  3229. var result = new Button(name);
  3230. // Adding image
  3231. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3232. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  3233. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3234. result.addControl(iconImage);
  3235. return result;
  3236. };
  3237. Button.CreateSimpleButton = function (name, text) {
  3238. var result = new Button(name);
  3239. // Adding text
  3240. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3241. textBlock.textWrapping = true;
  3242. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3243. result.addControl(textBlock);
  3244. return result;
  3245. };
  3246. return Button;
  3247. }(GUI.Rectangle));
  3248. GUI.Button = Button;
  3249. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3250. })(BABYLON || (BABYLON = {}));
  3251. //# sourceMappingURL=button.js.map
  3252. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3253. var __extends = (this && this.__extends) || (function () {
  3254. var extendStatics = Object.setPrototypeOf ||
  3255. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3256. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3257. return function (d, b) {
  3258. extendStatics(d, b);
  3259. function __() { this.constructor = d; }
  3260. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3261. };
  3262. })();
  3263. var DOMImage = Image;
  3264. var BABYLON;
  3265. (function (BABYLON) {
  3266. var GUI;
  3267. (function (GUI) {
  3268. var ColorPicker = (function (_super) {
  3269. __extends(ColorPicker, _super);
  3270. function ColorPicker(name) {
  3271. var _this = _super.call(this, name) || this;
  3272. _this.name = name;
  3273. _this._value = BABYLON.Color3.Red();
  3274. _this._tmpColor = new BABYLON.Color3();
  3275. _this._pointerStartedOnSquare = false;
  3276. _this._pointerStartedOnWheel = false;
  3277. _this._squareLeft = 0;
  3278. _this._squareTop = 0;
  3279. _this._squareSize = 0;
  3280. _this._h = 360;
  3281. _this._s = 1;
  3282. _this._v = 1;
  3283. _this.onValueChangedObservable = new BABYLON.Observable();
  3284. // Events
  3285. _this._pointerIsDown = false;
  3286. _this.value = new BABYLON.Color3(.88, .1, .1);
  3287. _this.size = "200px";
  3288. _this.isPointerBlocker = true;
  3289. return _this;
  3290. }
  3291. Object.defineProperty(ColorPicker.prototype, "value", {
  3292. get: function () {
  3293. return this._value;
  3294. },
  3295. set: function (value) {
  3296. if (this._value.equals(value)) {
  3297. return;
  3298. }
  3299. this._value.copyFrom(value);
  3300. this._RGBtoHSV(this._value, this._tmpColor);
  3301. this._h = this._tmpColor.r;
  3302. this._s = Math.max(this._tmpColor.g, 0.00001);
  3303. this._v = Math.max(this._tmpColor.b, 0.00001);
  3304. this._markAsDirty();
  3305. this.onValueChangedObservable.notifyObservers(this._value);
  3306. },
  3307. enumerable: true,
  3308. configurable: true
  3309. });
  3310. Object.defineProperty(ColorPicker.prototype, "width", {
  3311. set: function (value) {
  3312. if (this._width.toString(this._host) === value) {
  3313. return;
  3314. }
  3315. if (this._width.fromString(value)) {
  3316. this._height.fromString(value);
  3317. this._markAsDirty();
  3318. }
  3319. },
  3320. enumerable: true,
  3321. configurable: true
  3322. });
  3323. Object.defineProperty(ColorPicker.prototype, "height", {
  3324. set: function (value) {
  3325. if (this._height.toString(this._host) === value) {
  3326. return;
  3327. }
  3328. if (this._height.fromString(value)) {
  3329. this._width.fromString(value);
  3330. this._markAsDirty();
  3331. }
  3332. },
  3333. enumerable: true,
  3334. configurable: true
  3335. });
  3336. Object.defineProperty(ColorPicker.prototype, "size", {
  3337. get: function () {
  3338. return this.width;
  3339. },
  3340. set: function (value) {
  3341. this.width = value;
  3342. },
  3343. enumerable: true,
  3344. configurable: true
  3345. });
  3346. ColorPicker.prototype._getTypeName = function () {
  3347. return "ColorPicker";
  3348. };
  3349. ColorPicker.prototype._updateSquareProps = function () {
  3350. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3351. var wheelThickness = radius * .2;
  3352. var innerDiameter = (radius - wheelThickness) * 2;
  3353. var squareSize = innerDiameter / (Math.sqrt(2));
  3354. var offset = radius - squareSize * .5;
  3355. this._squareLeft = this._currentMeasure.left + offset;
  3356. this._squareTop = this._currentMeasure.top + offset;
  3357. this._squareSize = squareSize;
  3358. };
  3359. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  3360. var lgh = context.createLinearGradient(left, top, width + left, top);
  3361. lgh.addColorStop(0, '#fff');
  3362. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  3363. context.fillStyle = lgh;
  3364. context.fillRect(left, top, width, height);
  3365. var lgv = context.createLinearGradient(left, top, left, height + top);
  3366. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  3367. lgv.addColorStop(1, '#000');
  3368. context.fillStyle = lgv;
  3369. context.fillRect(left, top, width, height);
  3370. };
  3371. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  3372. context.beginPath();
  3373. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  3374. context.lineWidth = 3;
  3375. context.strokeStyle = '#333333';
  3376. context.stroke();
  3377. context.beginPath();
  3378. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  3379. context.lineWidth = 3;
  3380. context.strokeStyle = '#ffffff';
  3381. context.stroke();
  3382. };
  3383. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  3384. var canvas = document.createElement("canvas");
  3385. canvas.width = radius * 2;
  3386. canvas.height = radius * 2;
  3387. var context = canvas.getContext("2d");
  3388. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  3389. var data = image.data;
  3390. var color = this._tmpColor;
  3391. var maxDistSq = radius * radius;
  3392. var innerRadius = radius - thickness;
  3393. var minDistSq = innerRadius * innerRadius;
  3394. for (var x = -radius; x < radius; x++) {
  3395. for (var y = -radius; y < radius; y++) {
  3396. var distSq = x * x + y * y;
  3397. if (distSq > maxDistSq || distSq < minDistSq) {
  3398. continue;
  3399. }
  3400. var dist = Math.sqrt(distSq);
  3401. var ang = Math.atan2(y, x);
  3402. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  3403. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  3404. data[index] = color.r * 255;
  3405. data[index + 1] = color.g * 255;
  3406. data[index + 2] = color.b * 255;
  3407. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3408. //apply less alpha to bigger color pickers
  3409. var alphaAmount = .2;
  3410. var maxAlpha = .2;
  3411. var minAlpha = .04;
  3412. var lowerRadius = 50;
  3413. var upperRadius = 150;
  3414. if (radius < lowerRadius) {
  3415. alphaAmount = maxAlpha;
  3416. }
  3417. else if (radius > upperRadius) {
  3418. alphaAmount = minAlpha;
  3419. }
  3420. else {
  3421. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  3422. }
  3423. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3424. if (alphaRatio < alphaAmount) {
  3425. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  3426. }
  3427. else if (alphaRatio > 1 - alphaAmount) {
  3428. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  3429. }
  3430. else {
  3431. data[index + 3] = 255;
  3432. }
  3433. }
  3434. }
  3435. context.putImageData(image, 0, 0);
  3436. return canvas;
  3437. };
  3438. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  3439. var r = color.r;
  3440. var g = color.g;
  3441. var b = color.b;
  3442. var max = Math.max(r, g, b);
  3443. var min = Math.min(r, g, b);
  3444. var h = 0;
  3445. var s = 0;
  3446. var v = max;
  3447. var dm = max - min;
  3448. if (max !== 0) {
  3449. s = dm / max;
  3450. }
  3451. if (max != min) {
  3452. if (max == r) {
  3453. h = (g - b) / dm;
  3454. if (g < b) {
  3455. h += 6;
  3456. }
  3457. }
  3458. else if (max == g) {
  3459. h = (b - r) / dm + 2;
  3460. }
  3461. else if (max == b) {
  3462. h = (r - g) / dm + 4;
  3463. }
  3464. h *= 60;
  3465. }
  3466. result.r = h;
  3467. result.g = s;
  3468. result.b = v;
  3469. };
  3470. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  3471. var chroma = value * saturation;
  3472. var h = hue / 60;
  3473. var x = chroma * (1 - Math.abs((h % 2) - 1));
  3474. var r = 0;
  3475. var g = 0;
  3476. var b = 0;
  3477. if (h >= 0 && h <= 1) {
  3478. r = chroma;
  3479. g = x;
  3480. }
  3481. else if (h >= 1 && h <= 2) {
  3482. r = x;
  3483. g = chroma;
  3484. }
  3485. else if (h >= 2 && h <= 3) {
  3486. g = chroma;
  3487. b = x;
  3488. }
  3489. else if (h >= 3 && h <= 4) {
  3490. g = x;
  3491. b = chroma;
  3492. }
  3493. else if (h >= 4 && h <= 5) {
  3494. r = x;
  3495. b = chroma;
  3496. }
  3497. else if (h >= 5 && h <= 6) {
  3498. r = chroma;
  3499. b = x;
  3500. }
  3501. var m = value - chroma;
  3502. result.set((r + m), (g + m), (b + m));
  3503. };
  3504. ColorPicker.prototype._draw = function (parentMeasure, context) {
  3505. context.save();
  3506. this._applyStates(context);
  3507. if (this._processMeasures(parentMeasure, context)) {
  3508. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3509. var wheelThickness = radius * .2;
  3510. var left = this._currentMeasure.left;
  3511. var top = this._currentMeasure.top;
  3512. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  3513. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  3514. }
  3515. context.drawImage(this._colorWheelCanvas, left, top);
  3516. this._updateSquareProps();
  3517. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  3518. var cx = this._squareLeft + this._squareSize * this._s;
  3519. var cy = this._squareTop + this._squareSize * (1 - this._v);
  3520. this._drawCircle(cx, cy, radius * .04, context);
  3521. var dist = radius - wheelThickness * .5;
  3522. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  3523. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  3524. this._drawCircle(cx, cy, wheelThickness * .35, context);
  3525. }
  3526. context.restore();
  3527. };
  3528. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  3529. if (this._pointerStartedOnWheel) {
  3530. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3531. var centerX = radius + this._currentMeasure.left;
  3532. var centerY = radius + this._currentMeasure.top;
  3533. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  3534. }
  3535. else if (this._pointerStartedOnSquare) {
  3536. this._updateSquareProps();
  3537. this._s = (x - this._squareLeft) / this._squareSize;
  3538. this._v = 1 - (y - this._squareTop) / this._squareSize;
  3539. this._s = Math.min(this._s, 1);
  3540. this._s = Math.max(this._s, 0.00001);
  3541. this._v = Math.min(this._v, 1);
  3542. this._v = Math.max(this._v, 0.00001);
  3543. }
  3544. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  3545. this.value = this._tmpColor;
  3546. };
  3547. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  3548. this._updateSquareProps();
  3549. var left = this._squareLeft;
  3550. var top = this._squareTop;
  3551. var size = this._squareSize;
  3552. if (coordinates.x >= left && coordinates.x <= left + size &&
  3553. coordinates.y >= top && coordinates.y <= top + size) {
  3554. return true;
  3555. }
  3556. return false;
  3557. };
  3558. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  3559. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3560. var centerX = radius + this._currentMeasure.left;
  3561. var centerY = radius + this._currentMeasure.top;
  3562. var wheelThickness = radius * .2;
  3563. var innerRadius = radius - wheelThickness;
  3564. var radiusSq = radius * radius;
  3565. var innerRadiusSq = innerRadius * innerRadius;
  3566. var dx = coordinates.x - centerX;
  3567. var dy = coordinates.y - centerY;
  3568. var distSq = dx * dx + dy * dy;
  3569. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  3570. return true;
  3571. }
  3572. return false;
  3573. };
  3574. ColorPicker.prototype._onPointerDown = function (coordinates) {
  3575. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  3576. return false;
  3577. }
  3578. this._pointerIsDown = true;
  3579. this._pointerStartedOnSquare = false;
  3580. this._pointerStartedOnWheel = false;
  3581. if (this._isPointOnSquare(coordinates)) {
  3582. this._pointerStartedOnSquare = true;
  3583. }
  3584. else if (this._isPointOnWheel(coordinates)) {
  3585. this._pointerStartedOnWheel = true;
  3586. }
  3587. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3588. this._host._capturingControl = this;
  3589. return true;
  3590. };
  3591. ColorPicker.prototype._onPointerMove = function (coordinates) {
  3592. if (this._pointerIsDown) {
  3593. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3594. }
  3595. _super.prototype._onPointerMove.call(this, coordinates);
  3596. };
  3597. ColorPicker.prototype._onPointerUp = function (coordinates) {
  3598. this._pointerIsDown = false;
  3599. this._host._capturingControl = null;
  3600. _super.prototype._onPointerUp.call(this, coordinates);
  3601. };
  3602. return ColorPicker;
  3603. }(GUI.Control));
  3604. GUI.ColorPicker = ColorPicker;
  3605. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3606. })(BABYLON || (BABYLON = {}));
  3607. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3608. var __extends = (this && this.__extends) || (function () {
  3609. var extendStatics = Object.setPrototypeOf ||
  3610. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3611. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3612. return function (d, b) {
  3613. extendStatics(d, b);
  3614. function __() { this.constructor = d; }
  3615. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3616. };
  3617. })();
  3618. var BABYLON;
  3619. (function (BABYLON) {
  3620. var GUI;
  3621. (function (GUI) {
  3622. var InputText = (function (_super) {
  3623. __extends(InputText, _super);
  3624. function InputText(name, text) {
  3625. if (text === void 0) { text = ""; }
  3626. var _this = _super.call(this, name) || this;
  3627. _this.name = name;
  3628. _this._text = "";
  3629. _this._background = "black";
  3630. _this._thickness = 1;
  3631. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  3632. _this._autoStretchWidth = true;
  3633. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  3634. _this.text = text;
  3635. return _this;
  3636. }
  3637. Object.defineProperty(InputText.prototype, "maxWidth", {
  3638. get: function () {
  3639. return this._maxWidth.toString(this._host);
  3640. },
  3641. set: function (value) {
  3642. if (this._maxWidth.toString(this._host) === value) {
  3643. return;
  3644. }
  3645. if (this._maxWidth.fromString(value)) {
  3646. this._markAsDirty();
  3647. }
  3648. },
  3649. enumerable: true,
  3650. configurable: true
  3651. });
  3652. Object.defineProperty(InputText.prototype, "margin", {
  3653. get: function () {
  3654. return this._margin.toString(this._host);
  3655. },
  3656. set: function (value) {
  3657. if (this._margin.toString(this._host) === value) {
  3658. return;
  3659. }
  3660. if (this._margin.fromString(value)) {
  3661. this._markAsDirty();
  3662. }
  3663. },
  3664. enumerable: true,
  3665. configurable: true
  3666. });
  3667. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  3668. get: function () {
  3669. return this._autoStretchWidth;
  3670. },
  3671. set: function (value) {
  3672. if (this._autoStretchWidth === value) {
  3673. return;
  3674. }
  3675. this._autoStretchWidth = value;
  3676. this._markAsDirty();
  3677. },
  3678. enumerable: true,
  3679. configurable: true
  3680. });
  3681. Object.defineProperty(InputText.prototype, "thickness", {
  3682. get: function () {
  3683. return this._thickness;
  3684. },
  3685. set: function (value) {
  3686. if (this._thickness === value) {
  3687. return;
  3688. }
  3689. this._thickness = value;
  3690. this._markAsDirty();
  3691. },
  3692. enumerable: true,
  3693. configurable: true
  3694. });
  3695. Object.defineProperty(InputText.prototype, "background", {
  3696. get: function () {
  3697. return this._background;
  3698. },
  3699. set: function (value) {
  3700. if (this._background === value) {
  3701. return;
  3702. }
  3703. this._background = value;
  3704. this._markAsDirty();
  3705. },
  3706. enumerable: true,
  3707. configurable: true
  3708. });
  3709. Object.defineProperty(InputText.prototype, "text", {
  3710. get: function () {
  3711. return this._text;
  3712. },
  3713. set: function (value) {
  3714. if (this._text === value) {
  3715. return;
  3716. }
  3717. this._text = value;
  3718. this._markAsDirty();
  3719. },
  3720. enumerable: true,
  3721. configurable: true
  3722. });
  3723. InputText.prototype._getTypeName = function () {
  3724. return "InputText";
  3725. };
  3726. InputText.prototype._draw = function (parentMeasure, context) {
  3727. context.save();
  3728. this._applyStates(context);
  3729. if (this._processMeasures(parentMeasure, context)) {
  3730. // Background
  3731. if (this._background) {
  3732. context.fillStyle = this._background;
  3733. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3734. }
  3735. // Text
  3736. if (this._text) {
  3737. if (this.color) {
  3738. context.fillStyle = this.color;
  3739. }
  3740. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  3741. context.fillText(this._text, this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width), this._currentMeasure.top + rootY);
  3742. if (this._autoStretchWidth) {
  3743. 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";
  3744. }
  3745. }
  3746. // Border
  3747. if (this._thickness) {
  3748. if (this.color) {
  3749. context.strokeStyle = this.color;
  3750. }
  3751. context.lineWidth = this._thickness;
  3752. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  3753. }
  3754. }
  3755. context.restore();
  3756. };
  3757. return InputText;
  3758. }(GUI.Control));
  3759. GUI.InputText = InputText;
  3760. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3761. })(BABYLON || (BABYLON = {}));