babylon.gui.js 192 KB

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