babylon.gui.js 228 KB

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