babylon.gui.js 184 KB

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