babylon.gui.js 224 KB

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