Skip to content

Commit 6e23a68

Browse files
IconButton now can be scaled to whatever size given. Solves issue #3.
1 parent f0f8d66 commit 6e23a68

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

src/main/java/com/codingpupper3033/codebtekml/gui/buttons/IconButton.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
*/
1414
public class IconButton extends GuiButton {
1515
private static final ResourceLocation buttonTextureLocation = new ResourceLocation(CodeBTEKMLMod.MODID,"textures/gui/connect_screen.png");
16-
private ICON type;
16+
private final ICON type;
1717

1818
/// Types of icons able to be on the button
1919
public enum ICON {
2020
FILE(0,0,16,16),
2121
HELP(16,0,16,16);
2222

2323
private final int x;
24-
private int y;
25-
private int w;
26-
private int h;
24+
private final int y;
25+
private final int w;
26+
private final int h;
2727

2828

2929
ICON(int x, int y, int w, int h) {
@@ -34,6 +34,21 @@ public enum ICON {
3434
}
3535
}
3636

37+
/**
38+
* Instantiates a new Icon button.
39+
*
40+
* @param type icon on the button
41+
* @param buttonId the button id
42+
* @param x the x Position
43+
* @param y the y Position
44+
* @param widthIn the width of the button
45+
* @param heightIn the height of the button
46+
*/
47+
public IconButton(ICON type, int buttonId, int x, int y, int widthIn, int heightIn) {
48+
super(buttonId, x, y, widthIn, heightIn, "");
49+
this.type = type;
50+
}
51+
3752
/**
3853
* New IconButton
3954
* @param type icon on the button
@@ -42,20 +57,31 @@ public enum ICON {
4257
* @param y y position
4358
*/
4459
public IconButton(ICON type, int buttonId, int x, int y) {
45-
super(buttonId, x, y, 20, 20, "");
46-
this.type = type;
60+
this(type, buttonId, x, y, 20, 20);
4761
}
48-
4962
@Override
5063
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
5164
super.drawButton(mc, mouseX, mouseY, partialTicks);
5265

5366
if (visible) {
5467
GlStateManager.pushMatrix();
5568
{
69+
//Scale
70+
int scale = Math.min(width/type.w, height/type.h);
71+
int iconWidth = type.w*scale;
72+
int iconHeight = type.h*scale;
73+
74+
// Icon position
75+
int iconRelativeX = (width-iconWidth)/2;
76+
int iconRelativeY = (height-iconHeight)/2;
77+
78+
// Go to Icon Position
79+
GlStateManager.translate(x+iconRelativeX, y+iconRelativeY, 0);
80+
5681
mc.renderEngine.bindTexture(buttonTextureLocation);
5782
GlStateManager.color(1,1,1,1);
58-
drawTexturedModalRect(x+2, y+2,type.x,type.y, type.w, type.h);
83+
GlStateManager.scale(scale,scale,1);
84+
drawTexturedModalRect(0, 0,type.x,type.y, type.w, type.h);
5985
}
6086
GlStateManager.popMatrix();
6187
}

src/main/java/com/codingpupper3033/codebtekml/gui/screens/GuiDrawKML.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public class GuiDrawKML extends GuiScreen {
3131
// Parent
32-
private GuiScreen parentScreen;
32+
private final GuiScreen parentScreen;
3333

3434
// File Name Text Box
3535
public static final int FILE_NAME_TEXT_BOX_ID = 1;

src/main/java/com/codingpupper3033/codebtekml/helpers/kmlfile/KMLParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class KMLParser {
4040
public static final String LINESTRING_NODE_NAME = "LineString";
4141
public static final String POINT_NODE_NAME = "Point";
4242

43-
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
43+
private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
4444

4545

4646
/**

src/main/java/com/codingpupper3033/codebtekml/helpers/map/altitude/OpenElevationGoundLevelProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public double[] getGroundLevels(Coordinate[] coordinates) throws IOException {
9090

9191
/**
9292
* Processes the ground level for all Coordinates in the queue
93-
* @return
93+
* @return whether it was able to process the queue
9494
*/
9595
@Override
9696
public boolean processCoordinateGroundLevelQueue() {

0 commit comments

Comments
 (0)