Standardize widht/height from images

This commit is contained in:
Jordan Eldredge 2021-06-26 21:54:27 -07:00
parent 4a79701587
commit 032e212fbe
4 changed files with 86 additions and 17 deletions

View file

@ -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;
}

View file

@ -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");

View file

@ -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() {

View file

@ -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());
}
}
}
}