the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Button.h"
3#include "Textures.h"
4
5Button::Button(int id, int x, int y, const wstring& msg)
6{
7 init(id, x, y, 200, 20, msg);
8}
9
10Button::Button(int id, int x, int y, int w, int h, const wstring& msg)
11{
12 init(id, x, y, w, h, msg);
13}
14
15// 4J - added
16void Button::init(int id, int x, int y, int w, int h, const wstring& msg)
17{
18 active = true;
19 visible = true;
20
21 // this bit of code from original ctor
22 this->id = id;
23 this->x = x;
24 this->y = y;
25 this->w = w;
26 this->h = h;
27 this->msg = msg;
28}
29
30int Button::getYImage(bool hovered)
31{
32 int res = 1;
33 if (!active) res = 0;
34 else if (hovered) res = 2;
35 return res;
36}
37
38void Button::render(Minecraft *minecraft, int xm, int ym)
39{
40 if (!visible) return;
41
42 Font *font = minecraft->font;
43
44 glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(TN_GUI_GUI)); // 4J was L"/gui/gui.png"
45 glColor4f(1, 1, 1, 1);
46
47
48 bool hovered = xm >= x && ym >= y && xm < x + w && ym < y + h;
49 int yImage = getYImage(hovered);
50
51 blit(x, y, 0, 46 + yImage * 20, w / 2, h);
52 blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h);
53
54 renderBg(minecraft, xm, ym);
55
56 if (!active)
57 {
58 drawCenteredString(font, msg, x + w / 2, y + (h - 8) / 2, 0xffa0a0a0);
59 }
60 else
61 {
62 if (hovered)
63 {
64 drawCenteredString(font, msg, x + w / 2, y + (h - 8) / 2, 0xffffa0);
65 }
66 else
67 {
68 drawCenteredString(font, msg, x + w / 2, y + (h - 8) / 2, 0xe0e0e0);
69 }
70 }
71
72}
73
74void Button::renderBg(Minecraft *minecraft, int xm, int ym)
75{
76}
77
78void Button::released(int mx, int my)
79{
80}
81
82bool Button::clicked(Minecraft *minecraft, int mx, int my)
83{
84 return active && mx >= x && my >= y && mx < x + w && my < y + h;
85}