babylon.gui.js 206 KB

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