diff --git a/packages/webamp-modern-2/src/skin/Button.ts b/packages/webamp-modern-2/src/skin/Button.ts index 024a5f6a..be38a82d 100644 --- a/packages/webamp-modern-2/src/skin/Button.ts +++ b/packages/webamp-modern-2/src/skin/Button.ts @@ -27,6 +27,30 @@ export default class Button extends GuiObj { return true; } + // This shadows `getheight()` on GuiObj + getheight(): number { + if (this._height) { + return this._height; + } + if (this._image != null) { + const bitmap = UI_ROOT.getBitmap(this._image); + return bitmap.getHeight(); + } + return super.getheight(); + } + + // This shadows `getwidth()` on GuiObj + getwidth(): number { + if (this._width) { + return this._width; + } + if (this._image != null) { + const bitmap = UI_ROOT.getBitmap(this._image); + return bitmap.getWidth(); + } + return super.getwidth(); + } + getactivated(): boolean { return this._active; } diff --git a/packages/webamp-modern-2/src/skin/Group.ts b/packages/webamp-modern-2/src/skin/Group.ts index acb27579..9cb111c5 100644 --- a/packages/webamp-modern-2/src/skin/Group.ts +++ b/packages/webamp-modern-2/src/skin/Group.ts @@ -87,6 +87,30 @@ export default class Group extends GuiObj { ); } + // This shadows `getheight()` on GuiObj + getheight(): number { + if (this._height) { + return this._height; + } + if (this._background != null) { + const bitmap = UI_ROOT.getBitmap(this._background); + return bitmap.getHeight(); + } + return super.getheight(); + } + + // This shadows `getwidth()` on GuiObj + getwidth(): number { + if (this._width) { + return this._width; + } + if (this._background != null) { + const bitmap = UI_ROOT.getBitmap(this._background); + return bitmap.getWidth(); + } + return super.getwidth(); + } + draw() { super.draw(); this._div.setAttribute("data-obj-name", "Group"); diff --git a/packages/webamp-modern-2/src/skin/GuiObj.ts b/packages/webamp-modern-2/src/skin/GuiObj.ts index 9963ca44..dd05948d 100644 --- a/packages/webamp-modern-2/src/skin/GuiObj.ts +++ b/packages/webamp-modern-2/src/skin/GuiObj.ts @@ -109,8 +109,11 @@ export default class GuiObj extends XmlObj { * * @ret The height of the object. */ - getheight() { - assert(this._height != null, "Expected GUIObj to have a height."); + getheight(): number { + assert( + this._height != null, + `Expected GUIObj to have a height in ${this.getId()}.` + ); // FIXME return this._height; } @@ -120,9 +123,12 @@ export default class GuiObj extends XmlObj { * * @ret The width of the object. */ - getwidth() { - // FIXME - return this._width || 100; + getwidth(): number { + assert( + this._width != null, + `Expected GUIObj to have a width in ${this.getId()}.` + ); + return this._width; } /** @@ -222,12 +228,8 @@ export default class GuiObj extends XmlObj { if (this._y) { this._div.style.top = px(this._y); } - if (this._width) { - this._div.style.width = px(this._width); - } - if (this._height) { - this._div.style.height = px(this.getheight()); - } + this._div.style.width = px(this.getwidth()); + this._div.style.height = px(this.getheight()); } draw() { diff --git a/packages/webamp-modern-2/src/skin/Layer.ts b/packages/webamp-modern-2/src/skin/Layer.ts index cdc7c4e8..e7701cc7 100644 --- a/packages/webamp-modern-2/src/skin/Layer.ts +++ b/packages/webamp-modern-2/src/skin/Layer.ts @@ -1,6 +1,7 @@ import GuiObj from "./GuiObj"; import UI_ROOT from "../UIRoot"; import { px } from "../utils"; +import Bitmap from "./Bitmap"; // http://wiki.winamp.com/wiki/XML_GUI_Objects#.3Clayer.2F.3E export default class Layer extends GuiObj { @@ -20,6 +21,30 @@ export default class Layer extends GuiObj { return true; } + // This shadows `getheight()` on GuiObj + getheight(): number { + if (this._height) { + return this._height; + } + if (this._image != null) { + const bitmap = UI_ROOT.getBitmap(this._image); + return bitmap.getHeight(); + } + return super.getheight(); + } + + // This shadows `getwidth()` on GuiObj + getwidth(): number { + if (this._width) { + return this._width; + } + if (this._image != null) { + const bitmap = UI_ROOT.getBitmap(this._image); + return bitmap.getWidth(); + } + return super.getwidth(); + } + draw() { super.draw(); this._div.setAttribute("data-obj-name", "Layer"); @@ -27,12 +52,6 @@ export default class Layer extends GuiObj { const bitmap = UI_ROOT.getBitmap(this._image); this._div.style.backgroundImage = bitmap.getBackgrondImageCSSAttribute(); this._div.style.backgroundPosition = bitmap.getBackgrondPositionCSSAttribute(); - if (!this._div.style.width && bitmap.getWidth()) { - this._div.style.width = px(bitmap.getWidth()); - } - if (!this._div.style.height && bitmap.getHeight()) { - this._div.style.height = px(bitmap.getHeight()); - } } } }