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

85 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2023-10-17 15:15:41 +01:00
/**
* @file This file provides a UserShower class, representing a visual element for editing the length of a test.
2023-10-17 15:15:41 +01:00
* @author Arlo Filley
*/
/**
* Represents a visual element for editing the length of a test.
* @class
2023-10-17 15:15:41 +01:00
*/
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.
*/
2023-10-17 15:15:41 +01:00
constructor(x, y, height, width) {
/**
* Represents the button associated with the UserShower.
* @type {Button}
*/
2023-10-17 15:15:41 +01:00
this.button = new Button(x, y, height, width, "");
/**
* The x-coordinate of the UserShower.
* @type {number}
*/
2023-10-17 15:15:41 +01:00
this.x = x;
/**
* The y-coordinate of the UserShower.
* @type {number}
*/
2023-10-17 15:15:41 +01:00
this.y = y;
/**
* The height of the UserShower.
* @type {number}
*/
2023-10-17 15:15:41 +01:00
this.height = height;
/**
* The width of the UserShower.
* @type {number}
*/
2023-10-17 15:15:41 +01:00
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;
2023-10-17 15:15:41 +01:00
}
/**
* Draws the UserShower and its associated button.
*/
2023-10-17 15:15:41 +01:00
draw() {
textAlign(CENTER, CENTER);
// Draw the button
2023-10-17 15:15:41 +01:00
this.button.draw();
// Set image mode to center
2023-10-17 15:15:41 +01:00
imageMode(CENTER);
// Check button state and display appropriate icon
2023-10-17 15:15:41 +01:00
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);
2023-10-17 15:15:41 +01:00
}
}
}