babylon.gui.js 216 KB

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