babylon.gui.js 214 KB

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