Skip to content

Commit

Permalink
Properly position and clip the scrolling panel.
Browse files Browse the repository at this point in the history
Fixes #104
  • Loading branch information
mattmess1221 committed Jun 15, 2019
1 parent 875cc66 commit b3037a5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public GuiComponent() {
* @param mouseY The mouse y
* @param parTicks
*/
public void render(int mouseX, int mouseY, float parTicks) {
@Override
public void renderButton(int mouseX, int mouseY, float parTicks) {
}

public void renderCaption(int x, int y) {
Expand Down Expand Up @@ -139,6 +140,16 @@ public void onClosed() {

}

@Override
protected boolean clicked(double x, double y) {
return isMouseOver(x, y);
}

@Override
public boolean isMouseOver(double x, double y) {
return this.isEnabled() && this.isVisible() && getLocation().contains(x, y);
}

/**
* Gets the current location of this component.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package mnm.mods.tabbychat.client.gui.component;

import static org.lwjgl.opengl.GL11.*;

import mnm.mods.tabbychat.client.gui.component.layout.BorderLayout;
import mnm.mods.tabbychat.util.Dim;
import mnm.mods.tabbychat.util.ILocation;
import mnm.mods.tabbychat.util.Location;
import mnm.mods.tabbychat.client.gui.component.layout.BorderLayout.Position;
import org.lwjgl.opengl.GL11;

import javax.annotation.Nonnull;

Expand All @@ -31,20 +30,26 @@ public GuiScrollingPanel() {

@Override
public void render(int mouseX, int mouseY, float parTicks) {

ILocation rect = getLocation();
this.panel.setLocation(this.panel.getLocation().copy().setXPos(rect.getXPos()));

double height = mc.mainWindow.getHeight();
double scale = mc.mainWindow.getGuiScaleFactor();

glEnable(GL_SCISSOR_TEST);
glScissor(rect.getXPos(), mc.mainWindow.getHeight() - rect.getYPos(), rect.getWidth(), rect.getHeight());
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL11.glScissor((int) ((rect.getXPos()) * scale), (int) (height - rect.getYHeight() * scale),
(int) (rect.getWidth() * scale + 1), (int) (rect.getHeight() * scale + 1));

super.render(mouseX, mouseY, parTicks);

glDisable(GL_SCISSOR_TEST);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
}

@Override
public boolean mouseScrolled(double x, double y, double scroll) {
Location rect = panel.getLocation().copy();
int scr = (int) (rect.getYPos() + scroll / 12);
int scr = (int) (rect.getYPos() + scroll * 8);
rect.setYPos(scr);

panel.getParent().map(GuiComponent::getLocation).ifPresent(prect -> {
Expand Down Expand Up @@ -91,7 +96,7 @@ public void render(int mouseX, int mouseY, float parTicks) {
float perc = ((float) scroll / (float) total) * ((float) size / (float) max);
int pos = (int) (-perc * max);

fill(loc.getXPos()-1, loc.getYPos() + pos, loc.getXPos(), loc.getYPos() + pos + size - 1, -1);
fill(loc.getXPos() - 1, loc.getYPos() + pos, loc.getXPos(), loc.getYPos() + pos + size - 1, -1);
super.render(mouseX, mouseY, parTicks);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public GuiSettingsChannel(AbstractChannel channel) {
this.setLayout(new BorderLayout());
this.setDisplayString(I18n.format(CHANNEL_TITLE));
this.setSecondaryColor(Color.of(0, 15, 100, 65));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import mnm.mods.tabbychat.TCMarkers;
import mnm.mods.tabbychat.client.AbstractChannel;
import mnm.mods.tabbychat.client.ChatManager;
import mnm.mods.tabbychat.client.DefaultChannel;
import mnm.mods.tabbychat.TabbyChat;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class GuiSettingsScreen extends ComponentScreen {
public GuiSettingsScreen(@Nullable Channel channel) {
super(new StringTextComponent("Settings"));
if (channel != DefaultChannel.INSTANCE) {
selectedSetting = new GuiSettingsChannel();
selectedSetting = new GuiSettingsChannel((AbstractChannel) channel);
}

for (Map.Entry<Class<? extends SettingPanel<?>>, Supplier<? extends SettingPanel<?>>> sett : settings.entrySet()) {
Expand All @@ -65,7 +66,6 @@ public GuiSettingsScreen(@Nullable Channel channel) {
@Override
public void init() {


getPanel().add(panel = new GuiPanel(new BorderLayout()));

int x = this.width / 2 - 300 / 2;
Expand Down

0 comments on commit b3037a5

Please sign in to comment.