mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-23 20:09:46 +03:00
GUI: Rename some methods, start to implement new one
This commit is contained in:
78
source/client/newui/controls/Button.cpp
Normal file
78
source/client/newui/controls/Button.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
The following code is licensed under the BSD 1 clause license.
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
|
||||
#include "Button.hpp"
|
||||
|
||||
bool Button::onClick(Minecraft* pMinecraft, int x, int y)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Button::onUnpress(Minecraft* pMinecraft, int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
int Button::getYImage(bool bHovered)
|
||||
{
|
||||
if (!m_bEnabled) return 0;
|
||||
if (bHovered) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Button::isHovered(int xPos, int yPos)
|
||||
{
|
||||
if (!m_bEnabled) return false;
|
||||
if (xPos < m_xPos) return false;
|
||||
if (yPos < m_yPos) return false;
|
||||
if (xPos >= m_xPos + m_width) return false;
|
||||
if (yPos >= m_yPos + m_height) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//#define NEWGUI
|
||||
void Button::onDraw(Minecraft* pMinecraft, int x, int y)
|
||||
{
|
||||
#ifdef ENH_HIGHLIGHT_BY_HOVER
|
||||
m_bHovered = isHovered(x, y);
|
||||
#endif
|
||||
|
||||
Font* pFont = pMinecraft->m_pFont;
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
#ifdef NEWGUI
|
||||
// FIXME
|
||||
pMinecraft->m_pTextures->loadAndBindTexture("gui/newgui/buttonNew.png");
|
||||
//pMinecraft->m_pTextures->loadAndBindTexture("gui/newgui/play_screen/HoverButtonThinNewBevel.png");
|
||||
|
||||
blit(m_xPos, m_yPos, 0, 0, 2, 2, 2, 2);
|
||||
blit(m_xPos + m_width - 2, m_yPos, 2, 0, 2, 2, 2, 2);
|
||||
blit(m_xPos, m_yPos + m_height - 2, 0, 2, 2, 2, 2, 2);
|
||||
blit(m_xPos + m_width - 2, m_yPos + m_height - 2, 2, 2, 2, 2, 2, 2);
|
||||
blit(m_xPos + 2, m_yPos, 2, 2, m_width - 4, m_height, 1, 4);
|
||||
#else
|
||||
pMinecraft->m_pTextures->loadAndBindTexture("gui/gui.png");
|
||||
|
||||
int iYPos = 20 * getYImage(m_bHovered) + 46;
|
||||
|
||||
blit(m_xPos, m_yPos, 0, iYPos, m_width / 2, m_height, 0, 20);
|
||||
blit(m_xPos + m_width / 2, m_yPos, 200 - m_width / 2, iYPos, m_width / 2, m_height, 0, 20);
|
||||
#endif
|
||||
|
||||
//renderBg(pMinecraft, x, y);
|
||||
|
||||
int textColor;
|
||||
if (!m_bEnabled)
|
||||
textColor = int(0xFFA0A0A0U);
|
||||
else if (m_bHovered)
|
||||
textColor = int(0xFFFFA0U);
|
||||
else
|
||||
textColor = int(0xE0E0E0U);
|
||||
|
||||
drawCenteredText(pFont, m_text, m_xPos + m_width / 2, m_yPos + (m_height - 8) / 2, textColor);
|
||||
}
|
||||
41
source/client/newui/controls/Button.hpp
Normal file
41
source/client/newui/controls/Button.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
The following code is licensed under the BSD 1 clause license.
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "IControl.hpp"
|
||||
|
||||
class Button : public IControl
|
||||
{
|
||||
public:
|
||||
Button(int x, int y, int width = 200, int height = 24, const std::string text = "", bool enabled = true) :
|
||||
m_xPos(x),
|
||||
m_yPos(y),
|
||||
m_width(width),
|
||||
m_height(height),
|
||||
m_text(text),
|
||||
m_bEnabled(enabled)
|
||||
{
|
||||
}
|
||||
|
||||
bool onClick(Minecraft* pMinecraft, int x, int y) override;
|
||||
void onUnpress(Minecraft* pMinecraft, int x, int y) override;
|
||||
void onDraw(Minecraft* pMinecraft, int x, int y) override;
|
||||
|
||||
private:
|
||||
int getYImage(bool bHovered);
|
||||
bool isHovered(int xPos, int yPos);
|
||||
|
||||
public:
|
||||
bool m_bEnabled;
|
||||
bool m_bHovered;
|
||||
int m_xPos;
|
||||
int m_yPos;
|
||||
int m_width;
|
||||
int m_height;
|
||||
std::string m_text;
|
||||
};
|
||||
29
source/client/newui/controls/IControl.hpp
Normal file
29
source/client/newui/controls/IControl.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
The following code is licensed under the BSD 1 clause license.
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "client/app/Minecraft.hpp"
|
||||
#include "../Drawer.hpp"
|
||||
|
||||
class IControl : public Drawer
|
||||
{
|
||||
public:
|
||||
IControl() : Drawer(),
|
||||
m_bVisible(true)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void onTick() {}
|
||||
virtual bool onClick(Minecraft* pMinecraft, int x, int y) { return false; }
|
||||
virtual void onUnpress(Minecraft* pMinecraft, int x, int y) {}
|
||||
virtual void onDraw(Minecraft* pMinecraft, int x, int y) {}
|
||||
virtual void onKeyPressed(Minecraft* pMinecraft, int key) {}
|
||||
virtual void onCharPressed(Minecraft* pMinecraft, int chr) {}
|
||||
|
||||
bool m_bVisible;
|
||||
};
|
||||
Reference in New Issue
Block a user