babylon.gui.js 222 KB

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