Files
mcpe/source/client/gui/components/Button.cpp
Brent a0f71c7b27 C++03 Support & Partial Xbox 360 Support (#37)
* WIP C++03 + Xbox 360 Support

* math.h & _USE_MATH_DEFINES on Level.hpp
Updated Xenon vcxproj file for new file structure.

* * Fix bad GUI scale setup.

* * Gui: Use ratios instead of hardcoded sub-1 floating point values, to make the mechanism more clear.

* Add Direct Connect Button and Screen (#30)

* Add Direct Connect Button and Screen

* Remove accidental extra build directories for wasm

* Add DirectConnectScreen.cpp to the CMake

* Use Hungarian coding style notation

* * Fix errors caused by #30

* * Improve the Chat Screen

* * Improve the DirectConnectScreen, among other things.

* * Update the game title once again.

* * Add build-wasm.bat.

* * Add info about compiling for wasm

* * Fix send to specific GUID actually broadcasting to everyone

* * Add command manager.

* * Add writeable configuration.

* * Allow dynamic screen size change on windows

* * Allow the same thing on the emscripten version.

* WIP C++03 + Xbox 360 Support

* Fixed a possible merging issue that broke RakNet?

* Additional Xbox 360 compatability fixes

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
Co-authored-by: iProgramInCpp <iprogramincpp@gmail.com>
Co-authored-by: ts <124226059+uniformization@users.noreply.github.com>
2023-08-07 15:48:52 +03:00

121 lines
2.4 KiB
C++

/********************************************************************
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"
void Button::_init()
{
m_width = 0;
m_height = 0;
m_xPos = 0;
m_yPos = 0;
m_text = "";
m_bEnabled = true;
m_bVisible = true;
field_36 = false;
#ifndef ORIGINAL_CODE
m_lastX = 0;
m_lastY = 0;
#endif
}
Button::Button(int buttonId, int xPos, int yPos, int btnWidth, int btnHeight, const std::string& text)
{
_init();
m_buttonId = buttonId;
m_xPos = xPos;
m_yPos = yPos;
m_text = text;
m_width = btnWidth;
m_height = btnHeight;
}
Button::Button(int buttonId, int xPos, int yPos, const std::string& text)
{
_init();
m_buttonId = buttonId;
m_xPos = xPos;
m_yPos = yPos;
m_text = text;
m_width = 200;
m_height = 24;
}
Button::Button(int buttonId, const std::string& text)
{
_init();
m_buttonId = buttonId;
m_text = text;
m_width = 200;
m_height = 24;
}
bool Button::clicked(Minecraft* pMinecraft, 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;
}
int Button::getYImage(bool bHovered)
{
if (!m_bEnabled) return 0;
if (bHovered) return 2;
return 1;
}
void Button::released(int xPos, int yPos)
{
}
void Button::renderBg(Minecraft*, int, int)
{
}
void Button::render(Minecraft* pMinecraft, int xPos, int yPos)
{
if (!m_bVisible) return;
#ifdef ENH_HIGHLIGHT_BY_HOVER
field_36 = clicked(pMinecraft, xPos, yPos);
#endif
Font* pFont = pMinecraft->m_pFont;
Textures* pTexs = pMinecraft->m_pTextures;
pTexs->loadAndBindTexture("gui/gui.png");
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
int iYPos = 20 * getYImage(field_36) + 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);
renderBg(pMinecraft, xPos, yPos);
int textColor;
if (!m_bEnabled)
textColor = int(0xFFA0A0A0U);
else if (field_36)
textColor = int(0xFFFFA0U);
else
textColor = int(0xE0E0E0U);
drawCenteredString(pFont, m_text, m_xPos + m_width / 2, m_yPos + (m_height - 8) / 2, textColor);
}