CS-Coursework/public/pages/test/components/user.js

85 lines
2.1 KiB
JavaScript

/**
* @file This file provides a UserShower class, representing a visual element for editing the length of a test.
* @author Arlo Filley
*/
/**
* Represents a visual element for editing the length of a test.
* @class
*/
class UserShower {
/**
* Creates an instance of UserShower.
* @constructor
* @param {number} x - The x-coordinate of the UserShower.
* @param {number} y - The y-coordinate of the UserShower.
* @param {number} height - The height of the UserShower.
* @param {number} width - The width of the UserShower.
*/
constructor(x, y, height, width) {
/**
* Represents the button associated with the UserShower.
* @type {Button}
*/
this.button = new Button(x, y, height, width, "");
/**
* The x-coordinate of the UserShower.
* @type {number}
*/
this.x = x;
/**
* The y-coordinate of the UserShower.
* @type {number}
*/
this.y = y;
/**
* The height of the UserShower.
* @type {number}
*/
this.height = height;
/**
* The width of the UserShower.
* @type {number}
*/
this.width = width;
/**
* The horizontal center of the UserShower.
* @type {number}
*/
this.hCenter = this.x + this.height / 2;
/**
* The vertical center of the UserShower.
* @type {number}
*/
this.vCenter = this.y + this.width / 2;
}
/**
* Draws the UserShower and its associated button.
*/
draw() {
textAlign(CENTER, CENTER);
// Draw the button
this.button.draw();
// Set image mode to center
imageMode(CENTER);
// Check button state and display appropriate icon
if (this.button.isPressed()) {
screenManager.setScreen(new AccountScreen());
} else if (this.button.isHovered()) {
image(accountIconBlack, this.hCenter, this.vCenter);
} else {
image(accountIconWhite, this.hCenter, this.vCenter);
}
}
}