babylon.gui.js 228 KB

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