babylon.gui.js 227 KB

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