babylon.gui.js 194 KB

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