|
2 | 2 |
|
3 | 3 | import dev.deftu.omnicore.api.client.image.OmniImage; |
4 | 4 | import dev.deftu.omnicore.api.client.image.OmniImages; |
| 5 | +import dev.deftu.omnicore.api.client.render.DefaultVertexFormats; |
| 6 | +import dev.deftu.omnicore.api.client.render.DrawMode; |
5 | 7 | import dev.deftu.omnicore.api.client.render.OmniRenderingContext; |
6 | 8 | import dev.deftu.omnicore.api.client.render.OmniTextRenderer; |
| 9 | +import dev.deftu.omnicore.api.client.render.pipeline.OmniRenderPipeline; |
7 | 10 | import dev.deftu.omnicore.api.client.render.pipeline.OmniRenderPipelines; |
| 11 | +import dev.deftu.omnicore.api.client.render.state.OmniBlendState; |
8 | 12 | import dev.deftu.omnicore.api.client.render.stack.OmniPoseStack; |
| 13 | +import dev.deftu.omnicore.api.client.render.vertex.OmniBufferBuilder; |
| 14 | +import dev.deftu.omnicore.api.client.render.vertex.OmniBufferBuilders; |
9 | 15 | import dev.deftu.omnicore.api.client.textures.OmniTextureHandle; |
10 | 16 | import dev.deftu.omnicore.api.client.textures.OmniTextures; |
11 | 17 | import dev.deftu.omnicore.api.color.OmniColor; |
|
26 | 32 |
|
27 | 33 | public class MinecraftDrawContextAdapter implements IDrawContext { |
28 | 34 | private static final Map<BufferedImage, OmniTextureHandle> TEXTURE_CACHE = Collections.synchronizedMap(new WeakHashMap<>()); |
| 35 | + |
| 36 | + private static final OmniRenderPipeline INVERTED_PIPELINE = OmniRenderPipelines |
| 37 | + .builderWithDefaultShader(ResourceLocation.fromNamespaceAndPath("rescreen", "inverted_rect"), |
| 38 | + DefaultVertexFormats.POSITION_COLOR, DrawMode.QUADS).setColorLogic(OmniRenderPipeline.ColorLogic.OR_REVERSE) |
| 39 | + .setBlendState(OmniBlendState.DISABLED).build(); |
| 40 | + |
| 41 | + private static final OmniColor SELECTION_COLOR = new OmniColor(0.0f, 0.0f, 1.0f, 1.0f); |
| 42 | + |
29 | 43 | private final OmniRenderingContext ctx; |
30 | 44 | private final OmniPoseStack matrices; |
31 | 45 | private final float renderScale; |
@@ -189,5 +203,16 @@ public void drawPixelArt(Identifier identifier, float x, float y, float width, f |
189 | 203 | drawBufferedImage(identifier, x, y, width, height); |
190 | 204 | } |
191 | 205 |
|
192 | | - @Override public void drawInvertedRect(float v, float v1, float v2, float v3) {} |
| 206 | + @Override |
| 207 | + public void drawInvertedRect(float x1, float y1, float x2, float y2) { |
| 208 | + if (x1 == x2 || y1 == y2) return; |
| 209 | + float minX = Math.min(x1, x2); |
| 210 | + float minY = Math.min(y1, y2); |
| 211 | + float w = Math.max(x1, x2) - minX; |
| 212 | + float h = Math.max(y1, y2) - minY; |
| 213 | + |
| 214 | + OmniBufferBuilder builder = OmniBufferBuilders.create(INVERTED_PIPELINE); |
| 215 | + builder.quad(ctx.pose(), minX, minY, w, h, SELECTION_COLOR); |
| 216 | + builder.buildOrThrow().drawAndClose(INVERTED_PIPELINE); |
| 217 | + } |
193 | 218 | } |
0 commit comments