<commit_before>package com.creativemd.creativecore.gui.container;

import java.util.ArrayList;
import java.util.List;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;

import com.creativemd.creativecore.gui.CoreControl;
import com.creativemd.creativecore.gui.GuiControl;
import com.creativemd.creativecore.gui.GuiRenderHelper;
import com.creativemd.creativecore.gui.Rect;
import com.creativemd.creativecore.gui.client.style.Style;
import com.creativemd.creativecore.gui.event.gui.GuiControlClickEvent;
import com.creativemd.creativecore.gui.event.gui.GuiToolTipEvent;

import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.Vec3d;

public abstract class GuiParent extends GuiControl implements IControlParent {
	
	public ArrayList<GuiControl> controls = new ArrayList<>();
	
	public GuiParent(String name, int x, int y, int width, int height) {
		super(name, x, y, width, height);
	}
	
	@Override
	public List getControls() {
		return controls;
	}
	
	@Override
	public void refreshControls() {
		for (int i = 0; i < controls.size(); i++) {
			updateControl(controls.get(i), i);
		}
	}
	
	public void updateControl(GuiControl control, int id) {
		control.parent = this;
		control.setID(id);
	}
	
	public void addControl(GuiControl control) {
		updateControl(control, controls.size());
		controls.add(control);
	}
	
	// ================Rendering================
	
	protected int lastRenderedHeight = 0;
	
	public float getScaleFactor() {
		return 1F;
	}
	
	protected double getOffsetY() {
		return 0;
	}
	
	protected double getOffsetX() {
		return 0;
	}
	
	@Override
	protected void renderContent(GuiRenderHelper helper, Style style, int width, int height) {
	}
	
	@Override
	protected void renderContent(GuiRenderHelper helper, Style style, int width, int height, Rect relativeMaximumRect) {
		GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
		
		float scale = getScaleFactor();
		double xOffset = getOffsetX();
		double yOffset = getOffsetY();
		
		Rect newRect = relativeMaximumRect.mergeRects(getRect());
		
		lastRenderedHeight = 0;
		
		for (int i = controls.size() - 1; i >= 0; i--) {
			GuiControl control = controls.get(i);
			
			if (control.visible && control.isVisibleInsideRect((int) -xOffset, (int) -yOffset, width, height, scale)) {
				if (control.canOverlap())
					GL11.glDisable(GL11.GL_STENCIL_TEST);
				else {
					GL11.glEnable(GL11.GL_STENCIL_TEST);
					prepareContentStencil(helper, relativeMaximumRect);
					
					GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
					GL11.glStencilFunc(GL11.GL_EQUAL, 0x1, 0x1);
				}
				
				GlStateManager.pushMatrix();
				GlStateManager.translate(xOffset, yOffset, 0);
				control.renderControl(helper, scale, newRect.getOffsetRect((int) xOffset, (int) yOffset));
				GlStateManager.popMatrix();
				
				if (!control.canOverlap())
					GL11.glDisable(GL11.GL_STENCIL_TEST);
			}
			
			lastRenderedHeight = (int) Math.max(lastRenderedHeight, (control.posY + control.height) * scale);
			
		}
		
		GL11.glEnable(GL11.GL_STENCIL_TEST);
		
		prepareContentStencil(helper, relativeMaximumRect);
		
		GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
		GL11.glStencilFunc(GL11.GL_EQUAL, 0x1, 0x1);
		
		renderContent(helper, style, width, height);
		
		GL11.glDisable(GL11.GL_STENCIL_TEST);
	}
	
	// ================Helper================
	
	@Override
	public CoreControl get(String name) {
		for (int i = 0; i < controls.size(); i++) {
			GuiControl control = controls.get(i);
			if (control.is(name))
				return control;
			if (control instanceof IControlParent) {
				CoreControl tempcontrol = ((IControlParent) control).get(name);
				if (tempcontrol != null)
					return tempcontrol;
			}
		}
		return null;
	}
	
	@Override
	public boolean has(String name) {
		for (int i = 0; i < controls.size(); i++) {
			GuiControl control = controls.get(i);
			if (control.name.equalsIgnoreCase(name))
				return true;
		}
		return false;
	}
	
	// ================Interaction================
	
	public boolean isMouseOver() {
		if (parent != null)
			return super.isMouseOver();
		return true;
	}
	
	@Override
	public Vec3d getMousePos() {
		if (parent != null)
			return getParent().getMousePos().addVector(-getOffsetX() - this.posX, -getOffsetY() - this.posY, 0);
		ScaledResolution scaledresolution = new ScaledResolution(mc);<commit_msg>Fixed child mouse position offset<commit_after>package com.creativemd.creativecore.gui.container;

import java.util.ArrayList;
import java.util.List;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;

import com.creativemd.creativecore.gui.CoreControl;
import com.creativemd.creativecore.gui.GuiControl;
import com.creativemd.creativecore.gui.GuiRenderHelper;
import com.creativemd.creativecore.gui.Rect;
import com.creativemd.creativecore.gui.client.style.Style;
import com.creativemd.creativecore.gui.event.gui.GuiControlClickEvent;
import com.creativemd.creativecore.gui.event.gui.GuiToolTipEvent;

import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.Vec3d;

public abstract class GuiParent extends GuiControl implements IControlParent {
	
	public ArrayList<GuiControl> controls = new ArrayList<>();
	
	public GuiParent(String name, int x, int y, int width, int height) {
		super(name, x, y, width, height);
	}
	
	@Override
	public List getControls() {
		return controls;
	}
	
	@Override
	public void refreshControls() {
		for (int i = 0; i < controls.size(); i++) {
			updateControl(controls.get(i), i);
		}
	}
	
	public void updateControl(GuiControl control, int id) {
		control.parent = this;
		control.setID(id);
	}
	
	public void addControl(GuiControl control) {
		updateControl(control, controls.size());
		controls.add(control);
	}
	
	// ================Rendering================
	
	protected int lastRenderedHeight = 0;
	
	public float getScaleFactor() {
		return 1F;
	}
	
	protected double getOffsetY() {
		return 0;
	}
	
	protected double getOffsetX() {
		return 0;
	}
	
	@Override
	protected void renderContent(GuiRenderHelper helper, Style style, int width, int height) {
	}
	
	@Override
	protected void renderContent(GuiRenderHelper helper, Style style, int width, int height, Rect relativeMaximumRect) {
		GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
		
		float scale = getScaleFactor();
		double xOffset = getOffsetX();
		double yOffset = getOffsetY();
		
		Rect newRect = relativeMaximumRect.mergeRects(getRect());
		
		lastRenderedHeight = 0;
		
		for (int i = controls.size() - 1; i >= 0; i--) {
			GuiControl control = controls.get(i);
			
			if (control.visible && control.isVisibleInsideRect((int) -xOffset, (int) -yOffset, width, height, scale)) {
				if (control.canOverlap())
					GL11.glDisable(GL11.GL_STENCIL_TEST);
				else {
					GL11.glEnable(GL11.GL_STENCIL_TEST);
					prepareContentStencil(helper, relativeMaximumRect);
					
					GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
					GL11.glStencilFunc(GL11.GL_EQUAL, 0x1, 0x1);
				}
				
				GlStateManager.pushMatrix();
				GlStateManager.translate(xOffset, yOffset, 0);
				control.renderControl(helper, scale, newRect.getOffsetRect((int) xOffset, (int) yOffset));
				GlStateManager.popMatrix();
				
				if (!control.canOverlap())
					GL11.glDisable(GL11.GL_STENCIL_TEST);
			}
			
			lastRenderedHeight = (int) Math.max(lastRenderedHeight, (control.posY + control.height) * scale);
			
		}
		
		GL11.glEnable(GL11.GL_STENCIL_TEST);
		
		prepareContentStencil(helper, relativeMaximumRect);
		
		GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
		GL11.glStencilFunc(GL11.GL_EQUAL, 0x1, 0x1);
		
		renderContent(helper, style, width, height);
		
		GL11.glDisable(GL11.GL_STENCIL_TEST);
	}
	
	// ================Helper================
	
	@Override
	public CoreControl get(String name) {
		for (int i = 0; i < controls.size(); i++) {
			GuiControl control = controls.get(i);
			if (control.is(name))
				return control;
			if (control instanceof IControlParent) {
				CoreControl tempcontrol = ((IControlParent) control).get(name);
				if (tempcontrol != null)
					return tempcontrol;
			}
		}
		return null;
	}
	
	@Override
	public boolean has(String name) {
		for (int i = 0; i < controls.size(); i++) {
			GuiControl control = controls.get(i);
			if (control.name.equalsIgnoreCase(name))
				return true;
		}
		return false;
	}
	
	// ================Interaction================
	
	public boolean isMouseOver() {
		if (parent != null)
			return super.isMouseOver();
		return true;
	}
	
	@Override
	public Vec3d getMousePos() {
		if (parent != null)
			return getParent().getMousePos().addVector(-getContentOffset() - getOffsetX() - this.posX, -getContentOffset() - getOffsetY() - this.posY, 0);
		ScaledResolution scaledresolution = new ScaledResolution(mc);
{'fraction_non_alphanumeric': 0.138801261829653, 'fraction_numerical': 0.015772870662460567, 'mean_word_length': 4.243354991139988, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3141631', 'n_tokens_mistral': 3413, 'n_tokens_neox': 2898, 'n_words': 613}