babylon.gui.js 225 KB

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