Skip to content

Commit c501c67

Browse files
committed
make more draw methods use new methods
1 parent 2f2ee0a commit c501c67

File tree

3 files changed

+32
-45
lines changed

3 files changed

+32
-45
lines changed

src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,20 @@ public static void drawEllipse(float x0, float y0, float w, float h, int color,
7373
public static void drawEllipse(float x0, float y0, float w, float h, int centerColor, int outerColor, int segments) {
7474
Platform.setupDrawColor();
7575
Platform.setupDrawGradient();
76-
Tessellator tessellator = Tessellator.getInstance();
77-
BufferBuilder bufferbuilder = tessellator.getBuffer();
7876
float x_2 = x0 + w / 2f, y_2 = y0 + h / 2f;
7977
Platform.startDrawing(Platform.DrawMode.TRIANGLE_FAN, Platform.VertexFormat.POS_COLOR, bufferBuilder -> {
8078
// start at center
81-
bufferbuilder.pos(x_2, y_2, 0.0f).color(Color.getRed(centerColor), Color.getGreen(centerColor), Color.getBlue(centerColor), Color.getAlpha(centerColor)).endVertex();
79+
bufferBuilder.pos(x_2, y_2, 0.0f).color(Color.getRed(centerColor), Color.getGreen(centerColor), Color.getBlue(centerColor), Color.getAlpha(centerColor)).endVertex();
8280
int a = Color.getAlpha(outerColor), r = Color.getRed(outerColor), g = Color.getGreen(outerColor), b = Color.getBlue(outerColor);
8381
float incr = (float) (PI2 / segments);
8482
for (int i = 0; i <= segments; i++) {
8583
float angle = incr * i;
8684
float x = (float) (Math.sin(angle) * (w / 2) + x_2);
8785
float y = (float) (Math.cos(angle) * (h / 2) + y_2);
88-
bufferbuilder.pos(x, y, 0.0f).color(r, g, b, a).endVertex();
86+
bufferBuilder.pos(x, y, 0.0f).color(r, g, b, a).endVertex();
8987
}
9088
});
9189
Platform.endDrawGradient();
92-
//Platform.setupDrawTex();
9390
}
9491

9592
public static void drawRoundedRect(float x0, float y0, float w, float h, int color, int cornerRadius, int segments) {

src/main/java/com/cleanroommc/modularui/utils/fakeworld/SchemaRenderer.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
import com.cleanroommc.modularui.screen.viewport.GuiContext;
55
import com.cleanroommc.modularui.theme.WidgetTheme;
66
import com.cleanroommc.modularui.utils.Color;
7+
import com.cleanroommc.modularui.utils.Platform;
78
import com.cleanroommc.modularui.widget.sizer.Area;
89

910
import net.minecraft.block.state.IBlockState;
1011
import net.minecraft.client.Minecraft;
11-
import net.minecraft.client.renderer.*;
12+
import net.minecraft.client.renderer.BlockRendererDispatcher;
13+
import net.minecraft.client.renderer.BufferBuilder;
14+
import net.minecraft.client.renderer.GlStateManager;
15+
import net.minecraft.client.renderer.OpenGlHelper;
16+
import net.minecraft.client.renderer.RenderHelper;
17+
import net.minecraft.client.renderer.Tessellator;
1218
import net.minecraft.client.renderer.texture.TextureMap;
1319
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
1420
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
@@ -142,16 +148,12 @@ public RayTraceResult rayTraceMousePos() {
142148
GlStateManager.color(1, 1, 1, 1);
143149

144150
// render rect with FBO texture
145-
Tessellator tessellator = Tessellator.getInstance();
146-
BufferBuilder bufferbuilder = tessellator.getBuffer();
147-
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
148-
149-
bufferbuilder.pos(x + width, y + height, 0).tex(1, 0).endVertex();
150-
bufferbuilder.pos(x + width, y, 0).tex(1, 1).endVertex();
151-
bufferbuilder.pos(x, y, 0).tex(0, 1).endVertex();
152-
bufferbuilder.pos(x, y + height, 0).tex(0, 0).endVertex();
153-
tessellator.draw();
154-
151+
Platform.startDrawing(Platform.DrawMode.QUADS, Platform.VertexFormat.POS_TEX, bufferBuilder -> {
152+
bufferBuilder.pos(x + width, y + height, 0).tex(1, 0).endVertex();
153+
bufferBuilder.pos(x + width, y, 0).tex(1, 1).endVertex();
154+
bufferBuilder.pos(x, y, 0).tex(0, 1).endVertex();
155+
bufferBuilder.pos(x, y + height, 0).tex(0, 0).endVertex();
156+
});
155157
GlStateManager.bindTexture(lastFbo);
156158
}
157159

src/main/java/com/cleanroommc/modularui/widgets/textfield/TextFieldRenderer.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import com.cleanroommc.modularui.drawable.text.TextRenderer;
44
import com.cleanroommc.modularui.utils.Color;
5+
import com.cleanroommc.modularui.utils.Platform;
56

6-
import net.minecraft.client.renderer.BufferBuilder;
77
import net.minecraft.client.renderer.GlStateManager;
8-
import net.minecraft.client.renderer.Tessellator;
9-
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
108
import net.minecraftforge.fml.relauncher.Side;
119
import net.minecraftforge.fml.relauncher.SideOnly;
1210

@@ -139,19 +137,10 @@ public void drawMarked(float y0, float x0, float x1) {
139137
float alpha = Color.getAlphaF(this.markedColor);
140138
if (alpha == 0)
141139
alpha = 1f;
142-
Tessellator tessellator = Tessellator.getInstance();
143-
BufferBuilder bufferbuilder = tessellator.getBuffer();
144-
GlStateManager.color(red, green, blue, alpha);
145-
GlStateManager.disableTexture2D();
146-
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
147-
bufferbuilder.pos(x0, y1, 0.0D).endVertex();
148-
bufferbuilder.pos(x1, y1, 0.0D).endVertex();
149-
bufferbuilder.pos(x1, y0, 0.0D).endVertex();
150-
bufferbuilder.pos(x0, y0, 0.0D).endVertex();
151-
tessellator.draw();
152-
GlStateManager.disableColorLogic();
153-
GlStateManager.enableTexture2D();
154-
GlStateManager.color(1, 1, 1, 1);
140+
GlStateManager.pushMatrix();
141+
GlStateManager.scale(this.scale, this.scale, 0);
142+
drawRect(x0, y0, x1, y1, red, green, blue, alpha);
143+
GlStateManager.popMatrix();
155144
}
156145

157146
@SideOnly(Side.CLIENT)
@@ -166,22 +155,21 @@ private void drawCursor(float x0, float y0) {
166155
float alpha = Color.getAlphaF(this.cursorColor);
167156
if (alpha == 0)
168157
alpha = 1f;
169-
Tessellator tessellator = Tessellator.getInstance();
170-
BufferBuilder bufferbuilder = tessellator.getBuffer();
171-
GlStateManager.disableBlend();
172158
GlStateManager.pushMatrix();
173159
GlStateManager.scale(this.scale, this.scale, 0);
160+
drawRect(x0, y0, x1, y1, red, green, blue, alpha);
161+
GlStateManager.popMatrix();
162+
}
163+
164+
private static void drawRect(float x0, float y0, float x1, float y1, float red, float green, float blue, float alpha) {
165+
Platform.setupDrawColor();
174166
GlStateManager.color(red, green, blue, alpha);
175-
GlStateManager.disableTexture2D();
176-
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
177-
bufferbuilder.pos(x0, y1, 0.0D).endVertex();
178-
bufferbuilder.pos(x1, y1, 0.0D).endVertex();
179-
bufferbuilder.pos(x1, y0, 0.0D).endVertex();
180-
bufferbuilder.pos(x0, y0, 0.0D).endVertex();
181-
tessellator.draw();
167+
Platform.startDrawing(Platform.DrawMode.QUADS, Platform.VertexFormat.POS, bufferBuilder -> {
168+
bufferBuilder.pos(x0, y1, 0.0D).endVertex();
169+
bufferBuilder.pos(x1, y1, 0.0D).endVertex();
170+
bufferBuilder.pos(x1, y0, 0.0D).endVertex();
171+
bufferBuilder.pos(x0, y0, 0.0D).endVertex();
172+
});
182173
GlStateManager.color(1, 1, 1, 1);
183-
GlStateManager.enableTexture2D();
184-
GlStateManager.popMatrix();
185-
GlStateManager.enableBlend();
186174
}
187175
}

0 commit comments

Comments
 (0)