babylon.gui.js 185 KB

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