babylon.gui.js 182 KB

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