babylon.gui.js 221 KB

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