<commit_before>package mnm.mods.tabbychat.gui;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.Map;
import java.util.Set;

import mnm.mods.tabbychat.ChatChannel;
import mnm.mods.tabbychat.TabbyChat;
import mnm.mods.tabbychat.api.Channel;
import mnm.mods.tabbychat.api.Chat;
import mnm.mods.tabbychat.core.GuiNewChatTC;
import mnm.mods.tabbychat.settings.AdvancedSettings;
import mnm.mods.tabbychat.settings.ColorSettings;
import mnm.mods.util.gui.BorderLayout;
import mnm.mods.util.gui.GuiPanel;
import mnm.mods.util.gui.events.GuiMouseAdapter;
import mnm.mods.util.gui.events.GuiMouseEvent;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.MathHelper;

import org.lwjgl.input.Mouse;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

public class ChatBox extends GuiPanel implements Chat, GuiMouseAdapter {

    private static ColorSettings colors = TabbyChat.getInstance().colorSettings;

    private ChatArea chatArea;
    private ChatTray pnlTray;
    private TextBox txtChatInput;

    private Map<String, Channel> allChannels = Maps.newHashMap();
    private Set<Channel> channels = Sets.newHashSet(ChatChannel.DEFAULT_CHANNEL);
    private Channel active = ChatChannel.DEFAULT_CHANNEL;

    private Point drag;
    private Rectangle tempbox;

    public ChatBox(Rectangle rect) {
        super();
        this.setLayout(new BorderLayout());
        this.addComponent(pnlTray = new ChatTray(), BorderLayout.Position.NORTH);
        this.addComponent(chatArea = new ChatArea(), BorderLayout.Position.CENTER);
        this.addComponent(txtChatInput = new TextBox(), BorderLayout.Position.SOUTH);
        this.addComponent(new Scrollbar(chatArea), BorderLayout.Position.EAST);
        this.setBounds(rect);
    }

    @Override
    public void accept(GuiMouseEvent event) {
        Rectangle bounds = getBounds();
        float scale = getActualScale();

        // divide by scale because smaller scales make the point movement larger
        int x = (int) (event.position.x / scale);
        int y = (int) (event.position.y / scale);

        if (event.event == GuiMouseEvent.PRESSED) {
            if (Mouse.isButtonDown(0) && (pnlTray.isHovered() || (GuiScreen.isAltKeyDown() && isHovered()))) {
                drag = new Point(x, y);
                tempbox = new Rectangle(bounds);
            }
        }

        if (drag != null) {
            if (event.event == GuiMouseEvent.RELEASED) {
                // save bounds
                AdvancedSettings sett = TabbyChat.getInstance().advancedSettings;
                sett.chatX.setValue(bounds.x);
                sett.chatY.setValue(bounds.y);

                sett.saveSettingsFile();
                drag = null;
                tempbox = null;
            } else if (event.event == GuiMouseEvent.DRAGGED) {
                bounds.setLocation(tempbox.x + x - drag.x, tempbox.y + y - drag.y);
            }
        }
    }

    @Override
    public void drawComponent(int mouseX, int mouseY) {

        this.setForeColor(colors.chatTextColor.getValue().getColor());
        this.setBackColor(colors.chatBoxColor.getValue().getColor());
        setScale(GuiNewChatTC.getInstance().getChatScale());
        float scale = getScale();

        GlStateManager.pushMatrix();
        // Reset the matrix so we can have a clean slate
        GlStateManager.loadIdentity();
        // Translate it so everything's drawn correctly
        GlStateManager.translate(0f, 0f, -2000f);
        // Scale it accordingly
        GlStateManager.scale(scale, scale, 1.0F);

        // Make the upper left corner of the panel (0,0).
        GlStateManager.translate(this.getBounds().x, this.getBounds().y, 0.0F);
        super.drawComponent(mouseX, mouseY);

        GlStateManager.popMatrix();

    }

    @Override
    public void updateComponent() {
        Rectangle bounds = getBounds();
        Point point = getActualPosition();
        float scale = getActualScale();
        ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
<commit_msg>Don't constantly set the colors and scale. Translate to above the hotbar items.<commit_after>package mnm.mods.tabbychat.gui;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.Map;
import java.util.Set;

import mnm.mods.tabbychat.ChatChannel;
import mnm.mods.tabbychat.TabbyChat;
import mnm.mods.tabbychat.api.Channel;
import mnm.mods.tabbychat.api.Chat;
import mnm.mods.tabbychat.core.GuiNewChatTC;
import mnm.mods.tabbychat.settings.AdvancedSettings;
import mnm.mods.tabbychat.settings.ColorSettings;
import mnm.mods.util.gui.BorderLayout;
import mnm.mods.util.gui.GuiPanel;
import mnm.mods.util.gui.events.GuiMouseAdapter;
import mnm.mods.util.gui.events.GuiMouseEvent;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.MathHelper;

import org.lwjgl.input.Mouse;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

public class ChatBox extends GuiPanel implements Chat, GuiMouseAdapter {

    private static ColorSettings colors = TabbyChat.getInstance().colorSettings;

    private ChatArea chatArea;
    private ChatTray pnlTray;
    private TextBox txtChatInput;

    private Map<String, Channel> allChannels = Maps.newHashMap();
    private Set<Channel> channels = Sets.newHashSet(ChatChannel.DEFAULT_CHANNEL);
    private Channel active = ChatChannel.DEFAULT_CHANNEL;

    private Point drag;
    private Rectangle tempbox;

    public ChatBox(Rectangle rect) {
        super();
        this.setLayout(new BorderLayout());
        this.addComponent(pnlTray = new ChatTray(), BorderLayout.Position.NORTH);
        this.addComponent(chatArea = new ChatArea(), BorderLayout.Position.CENTER);
        this.addComponent(txtChatInput = new TextBox(), BorderLayout.Position.SOUTH);
        this.addComponent(new Scrollbar(chatArea), BorderLayout.Position.EAST);
        this.setBounds(rect);
    }

    @Override
    public void accept(GuiMouseEvent event) {
        Rectangle bounds = getBounds();
        float scale = getActualScale();

        // divide by scale because smaller scales make the point movement larger
        int x = (int) (event.position.x / scale);
        int y = (int) (event.position.y / scale);

        if (event.event == GuiMouseEvent.PRESSED) {
            if (Mouse.isButtonDown(0) && (pnlTray.isHovered() || (GuiScreen.isAltKeyDown() && isHovered()))) {
                drag = new Point(x, y);
                tempbox = new Rectangle(bounds);
            }
        }

        if (drag != null) {
            if (event.event == GuiMouseEvent.RELEASED) {
                // save bounds
                AdvancedSettings sett = TabbyChat.getInstance().advancedSettings;
                sett.chatX.setValue(bounds.x);
                sett.chatY.setValue(bounds.y);

                sett.saveSettingsFile();
                drag = null;
                tempbox = null;
            } else if (event.event == GuiMouseEvent.DRAGGED) {
                bounds.setLocation(tempbox.x + x - drag.x, tempbox.y + y - drag.y);
            }
        }
    }

    @Override
    public int getForeColor() {
        return colors.chatTextColor.getValue().getColor();
    }

    @Override
    public int getBackColor() {
        return colors.chatBoxColor.getValue().getColor();
    }

    @Override
    public float getScale() {
        return GuiNewChatTC.getInstance().getChatScale();
    }

    @Override
    public void drawComponent(int mouseX, int mouseY) {

        float scale = getScale();

        GlStateManager.pushMatrix();
        // Reset the matrix so it can have a clean slate
        GlStateManager.loadIdentity();
        // Translate it so everything's drawn correctly
        GlStateManager.translate(0f, 0f, -2000f);
        // Go up some more so it's in front of the hotbar.
        GlStateManager.translate(0, 0, 0x97);
        // Scale it accordingly
        GlStateManager.scale(scale, scale, 1.0F);

        // Make the upper left corner of the panel (0,0).
        GlStateManager.translate(this.getBounds().x, this.getBounds().y, 0.0F);
        super.drawComponent(mouseX, mouseY);

        GlStateManager.popMatrix();

    }

    @Override
    public void updateComponent() {
        Rectangle bounds = getBounds();
        Point point = getActualPosition();
        float scale = getActualScale();
        ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);

{'fraction_non_alphanumeric': 0.10744277004486369, 'fraction_numerical': 0.003566087656735304, 'mean_word_length': 2.816505706760316, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4885804', 'n_tokens_mistral': 2626, 'n_tokens_neox': 2535, 'n_words': 557}