babylon.gui.js 197 KB

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