package ru.dbotthepony.mc.otm.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

import static ru.dbotthepony.mc.otm.client.render.RenderHelperKt.popScissorRect;
import static ru.dbotthepony.mc.otm.client.render.RenderHelperKt.pushScissorRect;

// because scissor stack fucking sucks.
// mostly because it is not a stack at all.
@Mixin(GuiGraphics.class)
public abstract class GuiGraphicsMixin {
	@Overwrite
	public void enableScissor(int x0, int y0, int x1, int y1) {
		double scale = Minecraft.getInstance().getWindow().getGuiScale();
		pushScissorRect((int) (scale * x0), (int) (scale * y0), (int) (scale * (x1 - x0)), (int) (scale * (y1 - y0)));
	}

	@Overwrite
	public void disableScissor() {
		popScissorRect();
	}
}
