<commit_before>package net.mcft.copy.backpacks.client.gui;

import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.GlStateManager.DestFactor;
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public abstract class GuiElementBase {
	
	public static final String ELLIPSIS    = "...";
	public static final int ELLIPSIS_WIDTH = getStringWidth(ELLIPSIS);
	public static final int LINE_HEIGHT    = getFontRenderer().FONT_HEIGHT;
	
	public static final int COLOR_CONTROL           = 0xFFE0E0E0;
	public static final int COLOR_CONTROL_HIGHLIGHT = 0xFFFFFFA0;
	public static final int COLOR_CONTROL_DISABLED  = 0xFFA0A0A0;
	
	
	private GuiContext _context;
	private GuiContainer _parent;
	
	private boolean _visible = true, _enabled = true;

	private int _width, _height;
	
	private Alignment _horizontalAlign = new Alignment.Min(0);
	private Alignment _verticalAlign = new Alignment.Min(0);
	
	private List<String> _tooltip = null;
	private Supplier<List<String>> _tooltipFunc = null;
	private int _tooltipDelay = TooltipDelay.NORMAL;
	
	private int _dragStartX, _dragStartY;
	private int _dragPrevX, _dragPrevY;
	
	
	void setContext(GuiContext value) { _context = value; }
	void setParent(GuiContainer value) { _parent = value; }
	
	public final GuiContext getContext() { return _context; }
	public final GuiContainer getParent() { return _parent; }
	
	public boolean isVisible() { return _visible; }
	public void setVisible(boolean value) { _visible = value; }
	
	public boolean isEnabled() { return _enabled &&
		((getParent() != null) ? getParent().isEnabled() : true); }
	public void setEnabled(boolean value) { _enabled = value; }
	
	// Size related
	
	public int getSize(Direction direction)
		{ return (direction == Direction.HORIZONTAL) ? _width : _height; }
	public final int getWidth() { return getSize(Direction.HORIZONTAL); }
	public final int getHeight() { return getSize(Direction.VERTICAL); }
	
	public void setSize(Direction direction, int value) {
		if (value == getSize(direction)) return;
		if (direction == Direction.HORIZONTAL) _width = value;
		else _height = value;
		onSizeChanged(direction);
		if (_parent != null) _parent.onChildSizeChanged(this, direction);
	}
	public final void setWidth(int value) { setSize(Direction.HORIZONTAL, value); }
	public final void setHeight(int value) { setSize(Direction.VERTICAL, value); }
	public final void setSize(int width, int height) { setWidth(width); setHeight(height); }
	
	// Alignment related
	
	public Alignment getAlign(Direction direction)
		{ return (direction == Direction.HORIZONTAL) ? _horizontalAlign : _verticalAlign; }
	public final Alignment getHorizontalAlign() { return getAlign(Direction.HORIZONTAL); }
	public final Alignment getVerticalAlign() { return getAlign(Direction.VERTICAL); }
	
	public void setAlign(Direction direction, Alignment value) {
		if (value == null) throw new NullPointerException("Argument must be non-null");
		if (direction == Direction.HORIZONTAL) _horizontalAlign = value;
		else _verticalAlign = value;
		if (_parent != null) _parent.onChildAlignChanged(this, direction);
	}
	public final void setAlignHorizontal(Alignment value) { setAlign(Direction.HORIZONTAL, value); }
	public final void setAlignVertical(Alignment value) { setAlign(Direction.VERTICAL, value); }
	public final void setAlign(Alignment horizontal, Alignment vertical)
		{ setAlignHorizontal(horizontal); setAlignVertical(vertical); }
	
	// Useful alignment shortcuts
	
	public final void setPosition(int left, int top)
		{ setAlign(new Alignment.Min(left), new Alignment.Min(top)); }
	
	public final void setLeft(int value) { setAlignHorizontal(new Alignment.Min(value)); }
	public final void setRight(int value) { setAlignHorizontal(new Alignment.Max(value)); }
	public final void setTop(int value) { setAlignVertical(new Alignment.Min(value)); }
	public final void setBottom(int value) { setAlignVertical(new Alignment.Max(value)); }
	
	public final void setLeftRight(int value) { setLeftRight(value, value); }
	public final void setLeftRight(int left, int right)
		{ setAlignHorizontal(new Alignment.Both(left, right)); }
	public final void setTopBottom(int value) { setTopBottom(value, value); }
	public final void setTopBottom(int top, int bottom)
		{ setAlignVertical(new Alignment.Both(top, bottom)); }
	
	public final void setCenteredHorizontal() { setAlignHorizontal(new Alignment.Center()); }
	public final void setCenteredHorizontal(int width) { setCenteredHorizontal(); setWidth(width); }
	public final void setCenteredVertical() { setAlignVertical(new Alignment.Center()); }
	public final void setCenteredVertical(int height) { setCenteredVertical(); setHeight(height); }
	
	public final void setFillHorizontal() { setLeftRight(0); }
	public final void setFillVertical() { setTopBottom(0); }
	public final void setFill() { setFillHorizontal(); setFillVertical(); }
	
	// Tooltips
	
	public boolean hasTooltip() { return !getTooltip().isEmpty(); }
	
	public List<String> getTooltip() {
		List<String> tooltip = (_tooltipFunc != null) ? _tooltipFunc.get() : _tooltip;
		if (tooltip == null) tooltip = Collections.emptyList();
		return tooltip;
	}
	public int getTooltipDelay() { return _tooltipDelay; }
	
	public void setTooltip(List<String> value)
		{ setTooltip(TooltipDelay.NORMAL, value); }
	public void setTooltip(int delay, List<String> value)
		{ _tooltip = value; _tooltipDelay = delay; }
	public void setTooltip(Supplier<List<String>> value)
		{ setTooltip(TooltipDelay.NORMAL, value); }
	public void setTooltip(int delay, Supplier<List<String>> value)
		{ _tooltipFunc = value; _tooltipDelay = delay; }
	
	public static final class TooltipDelay {
		public static final int SHORT = 200;
		public static final int NORMAL = 400;
		public static final int LONG = 800;
		private TooltipDelay() {  }
	}
	
	// Element focus
	
	/** Returns if this element can be focused. */
	public boolean canFocus() { return false; }
	/** Returns if this element is currently focused. */
	public boolean isFocused() { return (getContext().getFocused() == this); }
	
	/** Makes this element the currently focused element. */
	public void setFocused() { setFocused(true); }
	/** Sets whether this element is the currently focused element. */
	public void setFocused(boolean value) {
		if (value && !canFocus())
			throw new UnsupportedOperationException("This element can't be focused");
		if (!isVisible()) return;
		getContext().setFocused(value ? this : null);
	}
	
	// Press / drag related
	
	/** Returns if this element can be pressed. */
	public boolean canPress() { return (canDrag() || canFocus()); }
	/** Returns if this element is currently being pressed down. */
	public boolean isPressed() { return (getContext().getPressed() == this); }
	/** Called when this element is pressed with the left mouse button.
	 *  Mouse position is relative to the element's position. */
	public void onPressed(int mouseX, int mouseY) {  }
	
	/** Returns if this element can be dragged. */
	public boolean canDrag() { return false; }
	/** Returns if this element is currently being dragged. */<commit_msg>Fix crash when removing element from container<commit_after>package net.mcft.copy.backpacks.client.gui;

import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.GlStateManager.DestFactor;
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public abstract class GuiElementBase {
	
	public static final String ELLIPSIS    = "...";
	public static final int ELLIPSIS_WIDTH = getStringWidth(ELLIPSIS);
	public static final int LINE_HEIGHT    = getFontRenderer().FONT_HEIGHT;
	
	public static final int COLOR_CONTROL           = 0xFFE0E0E0;
	public static final int COLOR_CONTROL_HIGHLIGHT = 0xFFFFFFA0;
	public static final int COLOR_CONTROL_DISABLED  = 0xFFA0A0A0;
	
	
	private GuiContext _context;
	private GuiContainer _parent;
	
	private boolean _visible = true, _enabled = true;

	private int _width, _height;
	
	private Alignment _horizontalAlign = new Alignment.Min(0);
	private Alignment _verticalAlign = new Alignment.Min(0);
	
	private List<String> _tooltip = null;
	private Supplier<List<String>> _tooltipFunc = null;
	private int _tooltipDelay = TooltipDelay.NORMAL;
	
	private int _dragStartX, _dragStartY;
	private int _dragPrevX, _dragPrevY;
	
	
	void setContext(GuiContext value) { _context = value; }
	void setParent(GuiContainer value) { _parent = value; }
	
	public final GuiContext getContext() { return _context; }
	public final GuiContainer getParent() { return _parent; }
	
	public boolean isVisible() { return _visible; }
	public void setVisible(boolean value) { _visible = value; }
	
	public boolean isEnabled() { return _enabled &&
		((getParent() != null) ? getParent().isEnabled() : true); }
	public void setEnabled(boolean value) { _enabled = value; }
	
	// Size related
	
	public int getSize(Direction direction)
		{ return (direction == Direction.HORIZONTAL) ? _width : _height; }
	public final int getWidth() { return getSize(Direction.HORIZONTAL); }
	public final int getHeight() { return getSize(Direction.VERTICAL); }
	
	public void setSize(Direction direction, int value) {
		if (value == getSize(direction)) return;
		if (direction == Direction.HORIZONTAL) _width = value;
		else _height = value;
		onSizeChanged(direction);
		if (_parent != null) _parent.onChildSizeChanged(this, direction);
	}
	public final void setWidth(int value) { setSize(Direction.HORIZONTAL, value); }
	public final void setHeight(int value) { setSize(Direction.VERTICAL, value); }
	public final void setSize(int width, int height) { setWidth(width); setHeight(height); }
	
	// Alignment related
	
	public Alignment getAlign(Direction direction)
		{ return (direction == Direction.HORIZONTAL) ? _horizontalAlign : _verticalAlign; }
	public final Alignment getHorizontalAlign() { return getAlign(Direction.HORIZONTAL); }
	public final Alignment getVerticalAlign() { return getAlign(Direction.VERTICAL); }
	
	public void setAlign(Direction direction, Alignment value) {
		if (value == null) throw new NullPointerException("Argument must be non-null");
		if (direction == Direction.HORIZONTAL) _horizontalAlign = value;
		else _verticalAlign = value;
		if (_parent != null) _parent.onChildAlignChanged(this, direction);
	}
	public final void setAlignHorizontal(Alignment value) { setAlign(Direction.HORIZONTAL, value); }
	public final void setAlignVertical(Alignment value) { setAlign(Direction.VERTICAL, value); }
	public final void setAlign(Alignment horizontal, Alignment vertical)
		{ setAlignHorizontal(horizontal); setAlignVertical(vertical); }
	
	// Useful alignment shortcuts
	
	public final void setPosition(int left, int top)
		{ setAlign(new Alignment.Min(left), new Alignment.Min(top)); }
	
	public final void setLeft(int value) { setAlignHorizontal(new Alignment.Min(value)); }
	public final void setRight(int value) { setAlignHorizontal(new Alignment.Max(value)); }
	public final void setTop(int value) { setAlignVertical(new Alignment.Min(value)); }
	public final void setBottom(int value) { setAlignVertical(new Alignment.Max(value)); }
	
	public final void setLeftRight(int value) { setLeftRight(value, value); }
	public final void setLeftRight(int left, int right)
		{ setAlignHorizontal(new Alignment.Both(left, right)); }
	public final void setTopBottom(int value) { setTopBottom(value, value); }
	public final void setTopBottom(int top, int bottom)
		{ setAlignVertical(new Alignment.Both(top, bottom)); }
	
	public final void setCenteredHorizontal() { setAlignHorizontal(new Alignment.Center()); }
	public final void setCenteredHorizontal(int width) { setCenteredHorizontal(); setWidth(width); }
	public final void setCenteredVertical() { setAlignVertical(new Alignment.Center()); }
	public final void setCenteredVertical(int height) { setCenteredVertical(); setHeight(height); }
	
	public final void setFillHorizontal() { setLeftRight(0); }
	public final void setFillVertical() { setTopBottom(0); }
	public final void setFill() { setFillHorizontal(); setFillVertical(); }
	
	// Tooltips
	
	public boolean hasTooltip() { return !getTooltip().isEmpty(); }
	
	public List<String> getTooltip() {
		List<String> tooltip = (_tooltipFunc != null) ? _tooltipFunc.get() : _tooltip;
		if (tooltip == null) tooltip = Collections.emptyList();
		return tooltip;
	}
	public int getTooltipDelay() { return _tooltipDelay; }
	
	public void setTooltip(List<String> value)
		{ setTooltip(TooltipDelay.NORMAL, value); }
	public void setTooltip(int delay, List<String> value)
		{ _tooltip = value; _tooltipDelay = delay; }
	public void setTooltip(Supplier<List<String>> value)
		{ setTooltip(TooltipDelay.NORMAL, value); }
	public void setTooltip(int delay, Supplier<List<String>> value)
		{ _tooltipFunc = value; _tooltipDelay = delay; }
	
	public static final class TooltipDelay {
		public static final int SHORT = 200;
		public static final int NORMAL = 400;
		public static final int LONG = 800;
		private TooltipDelay() {  }
	}
	
	// Element focus
	
	/** Returns if this element can be focused. */
	public boolean canFocus() { return false; }
	/** Returns if this element is currently focused. */
	public boolean isFocused() { return (getContext().getFocused() == this); }
	
	/** Makes this element the currently focused element. */
	public void setFocused() { setFocused(true); }
	/** Sets whether this element is the currently focused element. */
	public void setFocused(boolean value) {
		if (value && !canFocus())
			throw new UnsupportedOperationException("This element can't be focused");
		if (!isVisible()) return;
		getContext().setFocused(value ? this : null);
	}
	
	// Press / drag related
	
	/** Returns if this element can be pressed. */
	public boolean canPress() { return (canDrag() || canFocus()); }
	/** Returns if this element is currently being pressed down. */
	public boolean isPressed() { return (getContext() != null) && (getContext().getPressed() == this); }
	/** Called when this element is pressed with the left mouse button.
	 *  Mouse position is relative to the element's position. */
	public void onPressed(int mouseX, int mouseY) {  }
	
	/** Returns if this element can be dragged. */
	public boolean canDrag() { return false; }
	/** Returns if this element is currently being dragged. */
{'fraction_non_alphanumeric': 0.10593900481540931, 'fraction_numerical': 0.0032102728731942215, 'mean_word_length': 5.163830629204591, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '5832444', 'n_tokens_mistral': 4682, 'n_tokens_neox': 4502, 'n_words': 1326}