forked from xCollateral/VulkanMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuiElement.java
More file actions
130 lines (106 loc) · 3.35 KB
/
GuiElement.java
File metadata and controls
130 lines (106 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package net.vulkanmod.config.gui;
import net.minecraft.Util;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class GuiElement implements GuiEventListener, NarratableEntry {
protected int width;
protected int height;
public int x;
public int y;
protected boolean hovered;
protected long hoverStartTime;
protected int hoverTime;
protected long hoverStopTime;
@SuppressWarnings("unused") // this will surely be used some day
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
}
public void setPosition(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
@SuppressWarnings("unused") // this will surely be used someday
public void resize(int width, int height) {
this.width = width;
this.height = height;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void updateState(double mX, double mY) {
// Update hover
if (isMouseOver(mX, mY)) {
if (!this.hovered) {
this.hoverStartTime = Util.getMillis();
}
this.hovered = true;
this.hoverTime = (int) (Util.getMillis() - this.hoverStartTime);
} else {
if (this.hovered) {
this.hoverStopTime = Util.getMillis();
}
this.hovered = false;
this.hoverTime = 0;
}
}
public float getHoverMultiplier(float time) {
if (this.hovered) {
return Math.min(((this.hoverTime) / time), 1.0f);
}
else {
int delta = (int) (Util.getMillis() - this.hoverStopTime);
return Math.max(1.0f - (delta / time), 0.0f);
}
}
@Nullable
@Override
public ComponentPath nextFocusPath(FocusNavigationEvent focusNavigationEvent) {
return GuiEventListener.super.nextFocusPath(focusNavigationEvent);
}
@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return mouseX >= this.x && mouseY >= this.y
&& mouseX <= (this.x + this.width) && mouseY <= (this.y + this.height);
}
@Nullable
@Override
public ComponentPath getCurrentFocusPath() {
return GuiEventListener.super.getCurrentFocusPath();
}
@Override
public @NotNull ScreenRectangle getRectangle() {
return GuiEventListener.super.getRectangle();
}
@Override
public void setFocused(boolean bl) {
}
@Override
public boolean isFocused() {
return false;
}
@Override
public @NotNull NarrationPriority narrationPriority() {
return NarrationPriority.NONE;
}
@Override
public void updateNarration(NarrationElementOutput narrationElementOutput) {
}
}