babylon.gui.js 227 KB

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