Skip to content

Commit 8032022

Browse files
committed
multiple default colors & apply stencil to plot
1 parent f9305bf commit 8032022

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

src/main/java/com/cleanroommc/modularui/drawable/graph/GraphDrawable.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.cleanroommc.modularui.api.GuiAxis;
44
import com.cleanroommc.modularui.api.drawable.IDrawable;
55
import com.cleanroommc.modularui.drawable.GuiDraw;
6+
import com.cleanroommc.modularui.drawable.Stencil;
67
import com.cleanroommc.modularui.screen.viewport.GuiContext;
78
import com.cleanroommc.modularui.theme.WidgetTheme;
89
import com.cleanroommc.modularui.utils.Color;
@@ -46,13 +47,15 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
4647
this.view.postResize();
4748
}
4849
if (this.backgroundColor != 0) {
49-
GuiDraw.drawRect(this.view.sx0, this.view.sy0, this.view.sx1 - this.view.sx0, this.view.sy1 - this.view.sy0, this.backgroundColor);
50+
GuiDraw.drawRect(this.view.sx0, this.view.sy0, this.view.getScreenWidth(), this.view.getScreenHeight(), this.backgroundColor);
5051
}
5152
Platform.setupDrawColor();
5253
drawGrid(context);
54+
Stencil.applyTransformed((int) this.view.sx0, (int) this.view.sy0, (int) (this.view.getScreenWidth() + 1), (int) (this.view.getScreenHeight() + 1));
5355
for (Plot plot : this.plots) {
5456
plot.draw(this.view);
5557
}
58+
Stencil.remove();
5659
drawTicks(context);
5760
GuiDraw.drawBorderOutsideLTRB(this.view.sx0, this.view.sy0, this.view.sx1, this.view.sy1, 0.5f, Color.BLACK.main);
5861
this.x.drawLabels(this.view, this.y);
@@ -95,6 +98,15 @@ private boolean compute() {
9598
this.dirty = false;
9699
this.x.compute(this.plots);
97100
this.y.compute(this.plots);
101+
int colorIndex = 0;
102+
for (Plot plot : this.plots) {
103+
if (plot.defaultColor) {
104+
plot.color = Plot.DEFAULT_PLOT_COLORS[colorIndex];
105+
if (++colorIndex == Plot.DEFAULT_PLOT_COLORS.length) {
106+
colorIndex = 0;
107+
}
108+
}
109+
}
98110
return true;
99111
}
100112

src/main/java/com/cleanroommc/modularui/drawable/graph/GraphView.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,52 @@ public void setAspectRatio(float aspectRatio) {
106106
public float getAspectRatio() {
107107
return aspectRatio;
108108
}
109+
110+
public float getGraphX0() {
111+
return gx0;
112+
}
113+
114+
public float getGraphX1() {
115+
return gx1;
116+
}
117+
118+
public float getGraphY0() {
119+
return gy0;
120+
}
121+
122+
public float getGraphY1() {
123+
return gy1;
124+
}
125+
126+
public float getScreenX0() {
127+
return sx0;
128+
}
129+
130+
public float getScreenX1() {
131+
return sx1;
132+
}
133+
134+
public float getScreenY0() {
135+
return sy0;
136+
}
137+
138+
public float getScreenY1() {
139+
return sy1;
140+
}
141+
142+
public float getScreenWidth() {
143+
return sx1 - sx0;
144+
}
145+
146+
public float getScreenHeight() {
147+
return sy1 - sy0;
148+
}
149+
150+
public float getGraphWidth() {
151+
return gx1 - gx0;
152+
}
153+
154+
public float getGraphHeight() {
155+
return gy1 - gy0;
156+
}
109157
}

src/main/java/com/cleanroommc/modularui/drawable/graph/Plot.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@
1010

1111
public class Plot {
1212

13+
public static final int[] DEFAULT_PLOT_COLORS = {
14+
Color.BLUE_ACCENT.main,
15+
Color.ORANGE_ACCENT.darker(0),
16+
Color.GREEN.main,
17+
Color.RED.main,
18+
Color.DEEP_PURPLE_ACCENT.main,
19+
Color.BROWN.main,
20+
Color.TEAL.main,
21+
Color.LIME.main
22+
};
23+
1324
float[] xs = FloatArrayMath.EMPTY;
1425
float[] ys = FloatArrayMath.EMPTY;
1526
float thickness = 1f;
16-
int color = Color.BLUE_ACCENT.main;
27+
boolean defaultColor = true;
28+
int color;
1729

1830
private float[] vertexBuffer;
1931
private boolean dirty = true;
@@ -192,6 +204,7 @@ public Plot thickness(float thickness) {
192204

193205
public Plot color(int color) {
194206
this.color = color;
207+
this.defaultColor = color == 0;
195208
return this;
196209
}
197210
}

0 commit comments

Comments
 (0)