forked from mirrors/kolyah35-minecraft-pe-0.6.1
.h -> .hpp everything
This commit is contained in:
parent
7d3257669a
commit
7418263193
845 changed files with 53732 additions and 53754 deletions
|
|
@ -1,219 +1,219 @@
|
|||
#include "Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
Button::Button(int id, const std::string& msg)
|
||||
: GuiElement(true, true, 0, 0, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Button::render( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
if (!visible) return;
|
||||
|
||||
/*
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(hovered || selected);
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
*/
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
renderFace(minecraft, xm , ym);
|
||||
}
|
||||
|
||||
void Button::released( int mx, int my ) {
|
||||
_currentlyDown = false;
|
||||
}
|
||||
|
||||
bool Button::clicked( Minecraft* minecraft, int mx, int my )
|
||||
{
|
||||
return active && mx >= x && my >= y && mx < x + width && my < y + height;
|
||||
}
|
||||
|
||||
void Button::setPressed() {
|
||||
_currentlyDown = true;
|
||||
}
|
||||
|
||||
int Button::getYImage( bool hovered )
|
||||
{
|
||||
int res = 1;
|
||||
if (!active) res = 0;
|
||||
else if (hovered) res = 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
void Button::renderFace(Minecraft* mc, int xm, int ym) {
|
||||
Font* font = mc->font;
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered(mc, xm, ym) || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Button::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(selected || hovered(minecraft, xm, ym));;
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
blit(x + width / 2, y, 200 - width / 2, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
}
|
||||
|
||||
bool Button::hovered(Minecraft* minecraft, int xm , int ym) {
|
||||
return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym);
|
||||
}
|
||||
|
||||
bool Button::isInside( int xm, int ym ) {
|
||||
return xm >= x && ym >= y && xm < x + width && ym < y + height;
|
||||
}
|
||||
|
||||
//
|
||||
// BlankButton
|
||||
//
|
||||
BlankButton::BlankButton(int id)
|
||||
: super(id, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
BlankButton::BlankButton(int id, int x, int y, int w, int h)
|
||||
: super(id, x, y, w, h, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
//
|
||||
// The Touch-interface button
|
||||
//
|
||||
namespace Touch {
|
||||
|
||||
TButton::TButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg)
|
||||
{
|
||||
}
|
||||
|
||||
void TButton::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
// bool hovered = active && (_currentlyDown && isInside(xm, ym));
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
if (active)
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
else
|
||||
glColor4f2(0.5f, 0.5f, 0.5f, 1);
|
||||
|
||||
blit(x, y, hovered?66:0, 0, width, height, 66, 26);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Header spacing in Touchscreen mode
|
||||
//
|
||||
THeader::THeader(int id, const std::string& msg)
|
||||
: super(id, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
void THeader::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Font* font = minecraft->font;
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
int xx = x + width/2;
|
||||
if (xText != -99999)
|
||||
xx = xText;
|
||||
drawCenteredString(font, msg, xx, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
|
||||
void THeader::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
// Left cap
|
||||
blit(x, y, 150, 26, 2, height-1, 2, 25);
|
||||
// Middle
|
||||
blit(x+2, y, 153, 26, width-3, height-1, 8, 25);
|
||||
// Right cap
|
||||
blit(x+width-2, y, 162, 26, 2, height-1, 2, 25);
|
||||
// Shadow
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
blit(x, y+height-1, 153, 52, width, 3, 8, 3);
|
||||
}
|
||||
|
||||
};
|
||||
#include "Button.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
Button::Button(int id, const std::string& msg)
|
||||
: GuiElement(true, true, 0, 0, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Button::render( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
if (!visible) return;
|
||||
|
||||
/*
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(hovered || selected);
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
*/
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
renderFace(minecraft, xm , ym);
|
||||
}
|
||||
|
||||
void Button::released( int mx, int my ) {
|
||||
_currentlyDown = false;
|
||||
}
|
||||
|
||||
bool Button::clicked( Minecraft* minecraft, int mx, int my )
|
||||
{
|
||||
return active && mx >= x && my >= y && mx < x + width && my < y + height;
|
||||
}
|
||||
|
||||
void Button::setPressed() {
|
||||
_currentlyDown = true;
|
||||
}
|
||||
|
||||
int Button::getYImage( bool hovered )
|
||||
{
|
||||
int res = 1;
|
||||
if (!active) res = 0;
|
||||
else if (hovered) res = 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
void Button::renderFace(Minecraft* mc, int xm, int ym) {
|
||||
Font* font = mc->font;
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered(mc, xm, ym) || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Button::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(selected || hovered(minecraft, xm, ym));;
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
blit(x + width / 2, y, 200 - width / 2, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
}
|
||||
|
||||
bool Button::hovered(Minecraft* minecraft, int xm , int ym) {
|
||||
return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym);
|
||||
}
|
||||
|
||||
bool Button::isInside( int xm, int ym ) {
|
||||
return xm >= x && ym >= y && xm < x + width && ym < y + height;
|
||||
}
|
||||
|
||||
//
|
||||
// BlankButton
|
||||
//
|
||||
BlankButton::BlankButton(int id)
|
||||
: super(id, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
BlankButton::BlankButton(int id, int x, int y, int w, int h)
|
||||
: super(id, x, y, w, h, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
//
|
||||
// The Touch-interface button
|
||||
//
|
||||
namespace Touch {
|
||||
|
||||
TButton::TButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg)
|
||||
{
|
||||
}
|
||||
|
||||
void TButton::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
// bool hovered = active && (_currentlyDown && isInside(xm, ym));
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
if (active)
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
else
|
||||
glColor4f2(0.5f, 0.5f, 0.5f, 1);
|
||||
|
||||
blit(x, y, hovered?66:0, 0, width, height, 66, 26);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Header spacing in Touchscreen mode
|
||||
//
|
||||
THeader::THeader(int id, const std::string& msg)
|
||||
: super(id, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
void THeader::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Font* font = minecraft->font;
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
int xx = x + width/2;
|
||||
if (xText != -99999)
|
||||
xx = xText;
|
||||
drawCenteredString(font, msg, xx, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
|
||||
void THeader::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
// Left cap
|
||||
blit(x, y, 150, 26, 2, height-1, 2, 25);
|
||||
// Middle
|
||||
blit(x+2, y, 153, 26, width-3, height-1, 8, 25);
|
||||
// Right cap
|
||||
blit(x+width-2, y, 162, 26, 2, height-1, 2, 25);
|
||||
// Shadow
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
blit(x, y+height-1, 153, 52, width, 3, 8, 3);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElement.h"
|
||||
#include "../../Options.h"
|
||||
#include "GuiElement.hpp"
|
||||
#include "client/Options.hpp"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
|
|
@ -1 +1 @@
|
|||
#include "GuiElement.h"
|
||||
#include "GuiElement.hpp"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "Button.h"
|
||||
#include "Button.hpp"
|
||||
|
||||
class GButton: public Button {
|
||||
typedef Button super;
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
#include "GuiElement.h"
|
||||
|
||||
GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: active(active),
|
||||
visible(visible),
|
||||
x(x),
|
||||
y(y),
|
||||
width(width),
|
||||
height(height) {
|
||||
|
||||
}
|
||||
|
||||
bool GuiElement::pointInside( int x, int y ) {
|
||||
if(x >= this->x && x < this->x + this->width) {
|
||||
if(y >= this->y && y < this->y + this->height) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#include "GuiElement.hpp"
|
||||
|
||||
GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: active(active),
|
||||
visible(visible),
|
||||
x(x),
|
||||
y(y),
|
||||
width(width),
|
||||
height(height) {
|
||||
|
||||
}
|
||||
|
||||
bool GuiElement::pointInside( int x, int y ) {
|
||||
if(x >= this->x && x < this->x + this->width) {
|
||||
if(y >= this->y && y < this->y + this->height) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
|
||||
class Tesselator;
|
||||
class Minecraft;
|
||||
|
|
@ -1,66 +1,66 @@
|
|||
#include "GuiElementContainer.h"
|
||||
#include <algorithm>
|
||||
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: GuiElement(active, visible, x, y, width, height) {
|
||||
|
||||
}
|
||||
|
||||
GuiElementContainer::~GuiElementContainer() {
|
||||
while(!children.empty()) {
|
||||
GuiElement* element = children.back();
|
||||
children.pop_back();
|
||||
delete element;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->render(minecraft, xm, ym);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::setupPositions() {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->setupPositions();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::addChild( GuiElement* element ) {
|
||||
children.push_back(element);
|
||||
}
|
||||
|
||||
void GuiElementContainer::removeChild( GuiElement* element ) {
|
||||
std::vector<GuiElement*>::iterator it = std::find(children.begin(), children.end(), element);
|
||||
if(it != children.end())
|
||||
children.erase(it);
|
||||
}
|
||||
|
||||
void GuiElementContainer::tick( Minecraft* minecraft ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->tick(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseClicked(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseReleased(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->keyPressed(minecraft, key);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::charPressed(Minecraft* minecraft, char key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->charPressed(minecraft, key);
|
||||
}
|
||||
#include "GuiElementContainer.hpp"
|
||||
#include <algorithm>
|
||||
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: GuiElement(active, visible, x, y, width, height) {
|
||||
|
||||
}
|
||||
|
||||
GuiElementContainer::~GuiElementContainer() {
|
||||
while(!children.empty()) {
|
||||
GuiElement* element = children.back();
|
||||
children.pop_back();
|
||||
delete element;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->render(minecraft, xm, ym);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::setupPositions() {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->setupPositions();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::addChild( GuiElement* element ) {
|
||||
children.push_back(element);
|
||||
}
|
||||
|
||||
void GuiElementContainer::removeChild( GuiElement* element ) {
|
||||
std::vector<GuiElement*>::iterator it = std::find(children.begin(), children.end(), element);
|
||||
if(it != children.end())
|
||||
children.erase(it);
|
||||
}
|
||||
|
||||
void GuiElementContainer::tick( Minecraft* minecraft ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->tick(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseClicked(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseReleased(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->keyPressed(minecraft, key);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::charPressed(Minecraft* minecraft, char key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->charPressed(minecraft, key);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "GuiElement.h"
|
||||
#include "GuiElement.hpp"
|
||||
#include <vector>
|
||||
class Tesselator;
|
||||
class Minecraft;
|
||||
|
|
@ -1,135 +1,135 @@
|
|||
#include "ImageButton.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../platform/log.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include <client/Option.h>
|
||||
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg, const ImageDef& imagedef)
|
||||
: super(id, msg),
|
||||
_imageDef(imagedef)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void ImageButton::setupDefault() {
|
||||
width = 48;
|
||||
height = 48;
|
||||
scaleWhenPressed = true;
|
||||
}
|
||||
|
||||
void ImageButton::setImageDef(const ImageDef& imageDef, bool setButtonSize) {
|
||||
_imageDef = imageDef;
|
||||
if (setButtonSize) {
|
||||
width = (int)_imageDef.width;
|
||||
height = (int)_imageDef.height;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
bool IsSecondImage = isSecondImage(hovered);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
if (scaleWhenPressed && hovered) {
|
||||
hx *= 0.95f;
|
||||
hy *= 0.95f;
|
||||
}
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(IsSecondImage?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(IsSecondImage?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 17/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// A toggleable Button
|
||||
//
|
||||
OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {}
|
||||
|
||||
void OptionButton::toggle(Options* options) {
|
||||
options->toggle(m_optId);
|
||||
|
||||
// Update graphics here
|
||||
updateImage(options);
|
||||
}
|
||||
|
||||
void OptionButton::updateImage(Options* options) {
|
||||
_secondImage = options->getBooleanValue(m_optId);
|
||||
}
|
||||
|
||||
void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if(clicked(minecraft, x, y)) {
|
||||
toggle(&minecraft->options);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "ImageButton.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "platform/log.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include <client/Option.hpp>
|
||||
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg, const ImageDef& imagedef)
|
||||
: super(id, msg),
|
||||
_imageDef(imagedef)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void ImageButton::setupDefault() {
|
||||
width = 48;
|
||||
height = 48;
|
||||
scaleWhenPressed = true;
|
||||
}
|
||||
|
||||
void ImageButton::setImageDef(const ImageDef& imageDef, bool setButtonSize) {
|
||||
_imageDef = imageDef;
|
||||
if (setButtonSize) {
|
||||
width = (int)_imageDef.width;
|
||||
height = (int)_imageDef.height;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
bool IsSecondImage = isSecondImage(hovered);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
if (scaleWhenPressed && hovered) {
|
||||
hx *= 0.95f;
|
||||
hy *= 0.95f;
|
||||
}
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(IsSecondImage?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(IsSecondImage?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 17/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// A toggleable Button
|
||||
//
|
||||
OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {}
|
||||
|
||||
void OptionButton::toggle(Options* options) {
|
||||
options->toggle(m_optId);
|
||||
|
||||
// Update graphics here
|
||||
updateImage(options);
|
||||
}
|
||||
|
||||
void OptionButton::updateImage(Options* options) {
|
||||
_secondImage = options->getBooleanValue(m_optId);
|
||||
}
|
||||
|
||||
void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if(clicked(minecraft, x, y)) {
|
||||
toggle(&minecraft->options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Button.h"
|
||||
#include "Button.hpp"
|
||||
|
||||
typedef struct IntRectangle {
|
||||
IntRectangle()
|
||||
|
|
@ -1,206 +1,206 @@
|
|||
#include "InventoryPane.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../../world/entity/player/Inventory.h"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
InventoryPane::InventoryPane( IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize)
|
||||
: screen(screen),
|
||||
mc(mc),
|
||||
paneWidth(paneWidth),
|
||||
rect(rect),
|
||||
super(
|
||||
SF_LockX|/*SF_Scissor|*/SF_ShowScrollbar|SF_NoHoldSelect,
|
||||
rect, // Pane rect
|
||||
IntRectangle(0, 0, itemSize, itemSize), // Item rect
|
||||
0, numItems, Gui::GuiScale),
|
||||
BorderPixels(itemBorderSize),
|
||||
lastItemIndex(-1),
|
||||
lastItemTicks(-1),
|
||||
fillMarginX(2),
|
||||
fillMarginY(4),
|
||||
markerType(1),
|
||||
markerIndex(-1),
|
||||
markerShare(0),
|
||||
renderDecorations(true)
|
||||
{
|
||||
_clickArea = new RectangleArea(0, 0, 0, 0);
|
||||
area._x0 = rect.x - clickMarginH;
|
||||
area._x1 = rect.x + rect.w + clickMarginH;
|
||||
area._y0 -= By;
|
||||
area._y1 += By;
|
||||
|
||||
/*
|
||||
const int left = bbox.x + (bbox.w - paneWidth) / 2;
|
||||
bg.x = left;
|
||||
bg.w = left + paneWidth; // @note: read as x1, not width
|
||||
bg.y = bbox.y - fillMarginY;
|
||||
bg.h = bbox.y + bbox.h + fillMarginY; // @note: read as y1, not width
|
||||
*/
|
||||
}
|
||||
|
||||
InventoryPane::~InventoryPane() {
|
||||
delete _clickArea;
|
||||
}
|
||||
|
||||
void InventoryPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bg.x, bg.y, bg.w, bg.h, 0xff333333);
|
||||
fill((float)(bbox.x-fillMarginX-1), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX+1), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
//fill(0.0f, (float)(bbox.y-fillMarginY), 400.0f, (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);//(float)(bbox.x-fillMarginX), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
std::vector<const ItemInstance*> inventoryItems = screen->getItems(this);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = mc->height - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
t.colorABGR(0xffffffff);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
blit(item.xf, item.yf, 200, 46, (float)itemBbox.w, (float)itemBbox.h, 16, 16);
|
||||
}
|
||||
mc->textures->loadAndBindTexture("gui/gui.png");
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
GridItem* marked = NULL;
|
||||
float mxx, myy;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
int j = item.id;
|
||||
const ItemInstance* citem = inventoryItems[j];
|
||||
if (!citem) continue;
|
||||
|
||||
bool allowed = true;
|
||||
|
||||
t.enableColor();
|
||||
//#ifdef DEMO_MODE //@huge @attn
|
||||
if (!screen->isAllowed(j)) { allowed = false; t.color( 64, 64, 64); }
|
||||
else
|
||||
//#endif
|
||||
if (lastItemTicks > 0 && lastItemIndex == j) {
|
||||
int gv = 255 - lastItemTicks * 15;
|
||||
t.color(gv, gv, gv, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
} else {
|
||||
t.color(255, 255, 255, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
}
|
||||
t.noColor();
|
||||
float xx = Gui::floorAlignToScreenPixel(item.xf + BorderPixels + 4);
|
||||
float yy = Gui::floorAlignToScreenPixel(item.yf + BorderPixels + 4);
|
||||
ItemRenderer::renderGuiItem(NULL, mc->textures, citem, xx, yy, 16, 16, false);
|
||||
|
||||
if (j == markerIndex && markerShare >= 0)
|
||||
marked = &item, mxx = xx, myy = yy;
|
||||
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
if (marked) {
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
const float yy0 = myy - 5.0f;
|
||||
const float yy1 = yy0 + 2;
|
||||
fill(mxx, yy0, mxx + 16.0f, yy1, 0xff606060);
|
||||
fill(mxx, yy0, mxx + markerShare * 16.0f, yy1, markerType==1?0xff00ff00:0xff476543);
|
||||
glEnable2(GL_BLEND);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
if (!mc->isCreativeMode()) {
|
||||
const float ikText = Gui::InvGuiScale + Gui::InvGuiScale;
|
||||
const float kText = 0.5f * Gui::GuiScale;
|
||||
t.beginOverride();
|
||||
t.scale2d(ikText, ikText);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem) continue;
|
||||
|
||||
char buf[64] = {0};
|
||||
/*int c = */ Gui::itemCountItoa(buf, citem->count);
|
||||
|
||||
float tx = Gui::floorAlignToScreenPixel(kText * (item.xf + BorderPixels + 3));
|
||||
float ty = Gui::floorAlignToScreenPixel(kText * (item.yf + BorderPixels + 3));
|
||||
mc->gui.renderSlotText(citem, tx, ty, true, true);
|
||||
}
|
||||
t.resetScale();
|
||||
glEnable2(GL_BLEND);
|
||||
t.endOverrideAndDraw();
|
||||
}
|
||||
|
||||
if (renderDecorations) {
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem || citem->isNull()) continue;
|
||||
|
||||
if (citem->isDamaged()) {
|
||||
ItemRenderer::renderGuiItemDecorations(citem, item.xf + 8, item.yf + 12);
|
||||
}
|
||||
}
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.endOverrideAndDraw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
//fillGradient(bbox.x - 1, bbox.y, bbox.x + bbox.w + 1, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
//fillGradient(bbox.x - 1, bbox.y + bbox.h - 20, bbox.x + bbox.w + 1, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y, bg.w + fillMarginX, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y + bbox.h - 20, bg.w + fillMarginX, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool InventoryPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
//screen->onItemSelected(gridId);
|
||||
if (screen->isAllowed(gridId))
|
||||
if (screen->addItem(this, gridId)) {
|
||||
lastItemIndex = gridId;
|
||||
lastItemTicks = 7;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void InventoryPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
const int color = ((int)(255.0f * sb.alpha) << 24) | 0xaaaaaa;
|
||||
const float xx = (float)(bbox.x + bbox.w);
|
||||
fill(xx - sb.w, sb.y, xx, sb.y + sb.h, color);
|
||||
}
|
||||
|
||||
void InventoryPane::tick()
|
||||
{
|
||||
--lastItemTicks;
|
||||
super::tick();
|
||||
}
|
||||
|
||||
void InventoryPane::setRenderDecorations( bool value ) {
|
||||
renderDecorations = value;
|
||||
}
|
||||
|
||||
}
|
||||
#include "InventoryPane.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "world/entity/player/Inventory.hpp"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
InventoryPane::InventoryPane( IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize)
|
||||
: screen(screen),
|
||||
mc(mc),
|
||||
paneWidth(paneWidth),
|
||||
rect(rect),
|
||||
super(
|
||||
SF_LockX|/*SF_Scissor|*/SF_ShowScrollbar|SF_NoHoldSelect,
|
||||
rect, // Pane rect
|
||||
IntRectangle(0, 0, itemSize, itemSize), // Item rect
|
||||
0, numItems, Gui::GuiScale),
|
||||
BorderPixels(itemBorderSize),
|
||||
lastItemIndex(-1),
|
||||
lastItemTicks(-1),
|
||||
fillMarginX(2),
|
||||
fillMarginY(4),
|
||||
markerType(1),
|
||||
markerIndex(-1),
|
||||
markerShare(0),
|
||||
renderDecorations(true)
|
||||
{
|
||||
_clickArea = new RectangleArea(0, 0, 0, 0);
|
||||
area._x0 = rect.x - clickMarginH;
|
||||
area._x1 = rect.x + rect.w + clickMarginH;
|
||||
area._y0 -= By;
|
||||
area._y1 += By;
|
||||
|
||||
/*
|
||||
const int left = bbox.x + (bbox.w - paneWidth) / 2;
|
||||
bg.x = left;
|
||||
bg.w = left + paneWidth; // @note: read as x1, not width
|
||||
bg.y = bbox.y - fillMarginY;
|
||||
bg.h = bbox.y + bbox.h + fillMarginY; // @note: read as y1, not width
|
||||
*/
|
||||
}
|
||||
|
||||
InventoryPane::~InventoryPane() {
|
||||
delete _clickArea;
|
||||
}
|
||||
|
||||
void InventoryPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bg.x, bg.y, bg.w, bg.h, 0xff333333);
|
||||
fill((float)(bbox.x-fillMarginX-1), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX+1), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
//fill(0.0f, (float)(bbox.y-fillMarginY), 400.0f, (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);//(float)(bbox.x-fillMarginX), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
std::vector<const ItemInstance*> inventoryItems = screen->getItems(this);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = mc->height - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
t.colorABGR(0xffffffff);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
blit(item.xf, item.yf, 200, 46, (float)itemBbox.w, (float)itemBbox.h, 16, 16);
|
||||
}
|
||||
mc->textures->loadAndBindTexture("gui/gui.png");
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
GridItem* marked = NULL;
|
||||
float mxx, myy;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
int j = item.id;
|
||||
const ItemInstance* citem = inventoryItems[j];
|
||||
if (!citem) continue;
|
||||
|
||||
bool allowed = true;
|
||||
|
||||
t.enableColor();
|
||||
//#ifdef DEMO_MODE //@huge @attn
|
||||
if (!screen->isAllowed(j)) { allowed = false; t.color( 64, 64, 64); }
|
||||
else
|
||||
//#endif
|
||||
if (lastItemTicks > 0 && lastItemIndex == j) {
|
||||
int gv = 255 - lastItemTicks * 15;
|
||||
t.color(gv, gv, gv, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
} else {
|
||||
t.color(255, 255, 255, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
}
|
||||
t.noColor();
|
||||
float xx = Gui::floorAlignToScreenPixel(item.xf + BorderPixels + 4);
|
||||
float yy = Gui::floorAlignToScreenPixel(item.yf + BorderPixels + 4);
|
||||
ItemRenderer::renderGuiItem(NULL, mc->textures, citem, xx, yy, 16, 16, false);
|
||||
|
||||
if (j == markerIndex && markerShare >= 0)
|
||||
marked = &item, mxx = xx, myy = yy;
|
||||
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
if (marked) {
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
const float yy0 = myy - 5.0f;
|
||||
const float yy1 = yy0 + 2;
|
||||
fill(mxx, yy0, mxx + 16.0f, yy1, 0xff606060);
|
||||
fill(mxx, yy0, mxx + markerShare * 16.0f, yy1, markerType==1?0xff00ff00:0xff476543);
|
||||
glEnable2(GL_BLEND);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
if (!mc->isCreativeMode()) {
|
||||
const float ikText = Gui::InvGuiScale + Gui::InvGuiScale;
|
||||
const float kText = 0.5f * Gui::GuiScale;
|
||||
t.beginOverride();
|
||||
t.scale2d(ikText, ikText);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem) continue;
|
||||
|
||||
char buf[64] = {0};
|
||||
/*int c = */ Gui::itemCountItoa(buf, citem->count);
|
||||
|
||||
float tx = Gui::floorAlignToScreenPixel(kText * (item.xf + BorderPixels + 3));
|
||||
float ty = Gui::floorAlignToScreenPixel(kText * (item.yf + BorderPixels + 3));
|
||||
mc->gui.renderSlotText(citem, tx, ty, true, true);
|
||||
}
|
||||
t.resetScale();
|
||||
glEnable2(GL_BLEND);
|
||||
t.endOverrideAndDraw();
|
||||
}
|
||||
|
||||
if (renderDecorations) {
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem || citem->isNull()) continue;
|
||||
|
||||
if (citem->isDamaged()) {
|
||||
ItemRenderer::renderGuiItemDecorations(citem, item.xf + 8, item.yf + 12);
|
||||
}
|
||||
}
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.endOverrideAndDraw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
//fillGradient(bbox.x - 1, bbox.y, bbox.x + bbox.w + 1, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
//fillGradient(bbox.x - 1, bbox.y + bbox.h - 20, bbox.x + bbox.w + 1, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y, bg.w + fillMarginX, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y + bbox.h - 20, bg.w + fillMarginX, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool InventoryPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
//screen->onItemSelected(gridId);
|
||||
if (screen->isAllowed(gridId))
|
||||
if (screen->addItem(this, gridId)) {
|
||||
lastItemIndex = gridId;
|
||||
lastItemTicks = 7;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void InventoryPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
const int color = ((int)(255.0f * sb.alpha) << 24) | 0xaaaaaa;
|
||||
const float xx = (float)(bbox.x + bbox.w);
|
||||
fill(xx - sb.w, sb.y, xx, sb.y + sb.h, color);
|
||||
}
|
||||
|
||||
void InventoryPane::tick()
|
||||
{
|
||||
--lastItemTicks;
|
||||
super::tick();
|
||||
}
|
||||
|
||||
void InventoryPane::setRenderDecorations( bool value ) {
|
||||
renderDecorations = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "ScrollingPane.h"
|
||||
#include "ImageButton.h"
|
||||
#include "ScrollingPane.hpp"
|
||||
#include "ImageButton.hpp"
|
||||
|
||||
class Minecraft;
|
||||
class ItemInstance;
|
||||
|
|
@ -1,148 +1,148 @@
|
|||
#include "ItemPane.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "NinePatch.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
ItemPane::ItemPane( IItemPaneCallback* screen,
|
||||
Textures* textures,
|
||||
const IntRectangle& rect,
|
||||
int numItems,
|
||||
int guiHeight,
|
||||
int physicalScreenHeight,
|
||||
bool isVertical /*= true*/)
|
||||
: super(
|
||||
(isVertical?SF_LockX:SF_LockY)/*|SF_Scissor*/|SF_ShowScrollbar,
|
||||
rect, // Pane rect
|
||||
isVertical?IntRectangle(0, 0, rect.w, 22) // Item rect if vertical
|
||||
:IntRectangle(0, 0, 32, rect.h), // Item rect if horizontal
|
||||
isVertical?1:numItems, numItems, Gui::GuiScale),
|
||||
screen(screen),
|
||||
textures(textures),
|
||||
physicalScreenHeight(physicalScreenHeight),
|
||||
guiSlotItem(NULL),
|
||||
guiSlotItemSelected(NULL),
|
||||
isVertical(isVertical)
|
||||
{
|
||||
// Expand the area to make it easier to scroll
|
||||
area._x0 -= 4;
|
||||
area._x1 += 4;
|
||||
area._y0 = 0;
|
||||
area._y1 = (float)guiHeight;
|
||||
|
||||
// GUI
|
||||
NinePatchFactory builder(textures, "gui/spritesheet.png");
|
||||
guiSlotItem = builder.createSymmetrical(IntRectangle(20, 32, 8, 8), 2, 2);
|
||||
guiSlotItemSelected = builder.createSymmetrical(IntRectangle(28, 32, 8, 8), 2, 2);
|
||||
guiSlotItem->setSize((float)rect.w + 4, 22);
|
||||
guiSlotItemSelected->setSize((float)rect.w + 4, 22);
|
||||
}
|
||||
|
||||
ItemPane::~ItemPane() {
|
||||
delete guiSlotItem;
|
||||
delete guiSlotItemSelected;
|
||||
}
|
||||
|
||||
void ItemPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0xff666666);
|
||||
const std::vector<CItem*>& cat = screen->getItems(this);
|
||||
if (cat.empty()) return;
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = physicalScreenHeight - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
(item.selected? guiSlotItemSelected : guiSlotItem)->draw(t, Gui::floorAlignToScreenPixel(item.xf-1), Gui::floorAlignToScreenPixel(item.yf));
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
ItemRenderer::renderGuiItem(NULL, textures, &citem->item,
|
||||
Gui::floorAlignToScreenPixel(item.xf + itemBbox.w - 16),
|
||||
Gui::floorAlignToScreenPixel(2 + item.yf), 16, 16, false);
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
char buf[64] = {0};
|
||||
int c = Gui::itemCountItoa(buf, citem->inventoryCount);
|
||||
|
||||
float xf = item.xf - 1;
|
||||
if (citem->canCraft()) {
|
||||
f->drawShadow(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbActive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->drawShadow(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbActive);
|
||||
t.resetScale();
|
||||
} else {
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 3),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 7), rgbInactiveShadow);
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbInactive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->draw(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbInactive);
|
||||
t.resetScale();
|
||||
}
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
//fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, 20, 0x00000000, 0x80ff0000)
|
||||
if (isVertical) {
|
||||
fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + 28, 0xbb000000, 0x00000000);
|
||||
fillGradient(bbox.x, bbox.y + bbox.h - 28, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
} else {
|
||||
fillHorizontalGradient(bbox.x, bbox.y, bbox.x + 28, bbox.y + bbox.h, 0xbb000000, 0x00000000);
|
||||
fillHorizontalGradient(bbox.x + bbox.w - 28, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
}
|
||||
|
||||
//LOGI("scroll: %f - %f, %f :: %f, %f\n", hScroll.alpha, hScroll.x, hScroll.y, hScroll.w, hScroll.h);
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool ItemPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
if (selected)
|
||||
screen->onItemSelected(this, gridId);
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
void ItemPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
int color = ((int)(255.0f * sb.alpha) << 24) | 0xffffff;
|
||||
fill(2 + sb.x, sb.y, 2 + sb.x + sb.w, sb.y + sb.h, color);
|
||||
}
|
||||
#include "ItemPane.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "NinePatch.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
ItemPane::ItemPane( IItemPaneCallback* screen,
|
||||
Textures* textures,
|
||||
const IntRectangle& rect,
|
||||
int numItems,
|
||||
int guiHeight,
|
||||
int physicalScreenHeight,
|
||||
bool isVertical /*= true*/)
|
||||
: super(
|
||||
(isVertical?SF_LockX:SF_LockY)/*|SF_Scissor*/|SF_ShowScrollbar,
|
||||
rect, // Pane rect
|
||||
isVertical?IntRectangle(0, 0, rect.w, 22) // Item rect if vertical
|
||||
:IntRectangle(0, 0, 32, rect.h), // Item rect if horizontal
|
||||
isVertical?1:numItems, numItems, Gui::GuiScale),
|
||||
screen(screen),
|
||||
textures(textures),
|
||||
physicalScreenHeight(physicalScreenHeight),
|
||||
guiSlotItem(NULL),
|
||||
guiSlotItemSelected(NULL),
|
||||
isVertical(isVertical)
|
||||
{
|
||||
// Expand the area to make it easier to scroll
|
||||
area._x0 -= 4;
|
||||
area._x1 += 4;
|
||||
area._y0 = 0;
|
||||
area._y1 = (float)guiHeight;
|
||||
|
||||
// GUI
|
||||
NinePatchFactory builder(textures, "gui/spritesheet.png");
|
||||
guiSlotItem = builder.createSymmetrical(IntRectangle(20, 32, 8, 8), 2, 2);
|
||||
guiSlotItemSelected = builder.createSymmetrical(IntRectangle(28, 32, 8, 8), 2, 2);
|
||||
guiSlotItem->setSize((float)rect.w + 4, 22);
|
||||
guiSlotItemSelected->setSize((float)rect.w + 4, 22);
|
||||
}
|
||||
|
||||
ItemPane::~ItemPane() {
|
||||
delete guiSlotItem;
|
||||
delete guiSlotItemSelected;
|
||||
}
|
||||
|
||||
void ItemPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0xff666666);
|
||||
const std::vector<CItem*>& cat = screen->getItems(this);
|
||||
if (cat.empty()) return;
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = physicalScreenHeight - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
(item.selected? guiSlotItemSelected : guiSlotItem)->draw(t, Gui::floorAlignToScreenPixel(item.xf-1), Gui::floorAlignToScreenPixel(item.yf));
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
ItemRenderer::renderGuiItem(NULL, textures, &citem->item,
|
||||
Gui::floorAlignToScreenPixel(item.xf + itemBbox.w - 16),
|
||||
Gui::floorAlignToScreenPixel(2 + item.yf), 16, 16, false);
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
char buf[64] = {0};
|
||||
int c = Gui::itemCountItoa(buf, citem->inventoryCount);
|
||||
|
||||
float xf = item.xf - 1;
|
||||
if (citem->canCraft()) {
|
||||
f->drawShadow(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbActive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->drawShadow(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbActive);
|
||||
t.resetScale();
|
||||
} else {
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 3),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 7), rgbInactiveShadow);
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbInactive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->draw(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbInactive);
|
||||
t.resetScale();
|
||||
}
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
//fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, 20, 0x00000000, 0x80ff0000)
|
||||
if (isVertical) {
|
||||
fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + 28, 0xbb000000, 0x00000000);
|
||||
fillGradient(bbox.x, bbox.y + bbox.h - 28, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
} else {
|
||||
fillHorizontalGradient(bbox.x, bbox.y, bbox.x + 28, bbox.y + bbox.h, 0xbb000000, 0x00000000);
|
||||
fillHorizontalGradient(bbox.x + bbox.w - 28, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
}
|
||||
|
||||
//LOGI("scroll: %f - %f, %f :: %f, %f\n", hScroll.alpha, hScroll.x, hScroll.y, hScroll.w, hScroll.h);
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool ItemPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
if (selected)
|
||||
screen->onItemSelected(this, gridId);
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
void ItemPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
int color = ((int)(255.0f * sb.alpha) << 24) | 0xffffff;
|
||||
fill(2 + sb.x, sb.y, 2 + sb.x + sb.w, sb.y + sb.h, color);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ScrollingPane.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "ScrollingPane.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
|
||||
class Font;
|
||||
class Textures;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include "KeyOption.h"
|
||||
#include <client/Minecraft.h>
|
||||
#include "KeyOption.hpp"
|
||||
#include <client/Minecraft.hpp>
|
||||
|
||||
KeyOption::KeyOption(Minecraft* minecraft, OptionId optId)
|
||||
: Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include "Button.h"
|
||||
#include <client/Options.h>
|
||||
#include "Button.hpp"
|
||||
#include <client/Options.hpp>
|
||||
|
||||
class KeyOption : public Touch::TButton {
|
||||
public:
|
||||
|
|
@ -1,104 +1,104 @@
|
|||
#include "LargeImageButton.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../../platform/log.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg, ImageDef& imagedef)
|
||||
: super(id, msg)
|
||||
{
|
||||
_imageDef = imagedef;
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void LargeImageButton::setupDefault() {
|
||||
_buttonScale = 1;
|
||||
width = 72;
|
||||
height = 72;
|
||||
}
|
||||
|
||||
void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
|
||||
if (hovered)
|
||||
_buttonScale = Mth::Max(0.95f, _buttonScale-0.025f);
|
||||
else
|
||||
_buttonScale = Mth::Min(1.00f, _buttonScale+0.025f);
|
||||
|
||||
hx *= _buttonScale;
|
||||
hy *= _buttonScale;
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(hovered?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(hovered?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "LargeImageButton.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "platform/log.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg, ImageDef& imagedef)
|
||||
: super(id, msg)
|
||||
{
|
||||
_imageDef = imagedef;
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void LargeImageButton::setupDefault() {
|
||||
_buttonScale = 1;
|
||||
width = 72;
|
||||
height = 72;
|
||||
}
|
||||
|
||||
void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
|
||||
if (hovered)
|
||||
_buttonScale = Mth::Max(0.95f, _buttonScale-0.025f);
|
||||
else
|
||||
_buttonScale = Mth::Min(1.00f, _buttonScale+0.025f);
|
||||
|
||||
hx *= _buttonScale;
|
||||
hy *= _buttonScale;
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(hovered?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(hovered?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "ImageButton.h"
|
||||
#include "ImageButton.hpp"
|
||||
|
||||
class LargeImageButton: public ImageButton
|
||||
{
|
||||
|
|
@ -1,141 +1,141 @@
|
|||
#include "NinePatch.h"
|
||||
|
||||
NinePatchDescription::NinePatchDescription( float x, float y, float x1, float x2, float x3, float y1, float y2, float y3, float w, float e, float n, float s ) : u0(x), u1(x + x1), u2(x + x2), u3(x + x3),
|
||||
v0(y), v1(y + y1), v2(y + y2), v3(y + y3),
|
||||
w(w), e(e), n(n), s(s),
|
||||
imgW(-1),
|
||||
imgH(-1) {
|
||||
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImage( const TextureData& d ) {
|
||||
return transformUVForImageSize(d.w, d.h);
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImageSize( int w, int h ) {
|
||||
if (imgW < 0)
|
||||
imgW = imgH = 1;
|
||||
|
||||
const float us = (float) imgW / w; // @todo: prepare for normal blit? (e.g. mult by 256)
|
||||
const float vs = (float) imgH / h;
|
||||
u0 *= us; u1 *= us; u2 *= us; u3 *= us;
|
||||
v0 *= vs; v1 *= vs; v2 *= vs; v3 *= vs;
|
||||
|
||||
imgW = w;
|
||||
imgH = h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NinePatchDescription NinePatchDescription::createSymmetrical( int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt ) {
|
||||
NinePatchDescription patch((float)src.x, (float)src.y,// width and height of src
|
||||
(float)xCutAt, (float)(src.w-xCutAt), (float)src.w, // u tex coordinates
|
||||
(float)yCutAt, (float)(src.h-yCutAt), (float)src.h, // v tex coordinates
|
||||
(float)xCutAt, (float)xCutAt, (float)yCutAt, (float)yCutAt); // border width and heights
|
||||
if (texWidth > 0) patch.transformUVForImageSize(texWidth, texHeight);
|
||||
return patch;
|
||||
}
|
||||
|
||||
NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w, float h)
|
||||
: desc(desc),
|
||||
imageName(imageName),
|
||||
textures(textures),
|
||||
w(-1), h(-1),
|
||||
excluded(0)
|
||||
{
|
||||
setSize(w, h);
|
||||
}
|
||||
|
||||
void NinePatchLayer::setSize( float w, float h ) {
|
||||
if (w == this->w && h == this->h)
|
||||
return;
|
||||
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
buildQuad(i);
|
||||
}
|
||||
|
||||
void NinePatchLayer::draw( Tesselator& t, float x, float y ) {
|
||||
textures->loadAndBindTexture(imageName);
|
||||
t.begin();
|
||||
t.addOffset(x, y, 0);
|
||||
for (int i = 0, b = 1; i < 9; ++i, b += b)
|
||||
if ((b & excluded) == 0)
|
||||
d(t, quads[i]);
|
||||
t.addOffset(-x, -y, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::exclude( int excludeId ) {
|
||||
return setExcluded(excluded | (1 << excludeId));
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::setExcluded( int exludeBits ) {
|
||||
excluded = exludeBits;
|
||||
return this;
|
||||
}
|
||||
|
||||
void NinePatchLayer::buildQuad( int qid ) {
|
||||
//@attn; fix
|
||||
CachedQuad& q = quads[qid];
|
||||
const int yid = qid / 3;
|
||||
const int xid = qid - 3 * yid;
|
||||
q.u0 = (&desc.u0)[xid];
|
||||
q.u1 = (&desc.u0)[xid + 1];
|
||||
q.v0 = (&desc.v0)[yid];
|
||||
q.v1 = (&desc.v0)[yid + 1];
|
||||
q.z = 0;
|
||||
getPatchInfo(xid, yid, q.x0, q.x1, q.y0, q.y1);
|
||||
/* q.x0 = w * (q.u0 - desc.u0);
|
||||
q.y0 = h * (q.v0 - desc.v0);
|
||||
q.x1 = w * (q.u1 - desc.u0);
|
||||
q.y1 = h * (q.v1 - desc.v0);
|
||||
*/
|
||||
}
|
||||
|
||||
void NinePatchLayer::getPatchInfo( int xc, int yc, float& x0, float& x1, float& y0, float& y1 ) {
|
||||
if (xc == 0) { x0 = 0; x1 = desc.w; }
|
||||
else if (xc == 1) { x0 = desc.w; x1 = w - desc.e; }
|
||||
else if (xc == 2) { x0 = w-desc.e; x1 = w; }
|
||||
if (yc == 0) { y0 = 0; y1 = desc.n; }
|
||||
else if (yc == 1) { y0 = desc.n; y1 = h - desc.s; }
|
||||
else if (yc == 2) { y0 = h-desc.s; y1 = h; }
|
||||
}
|
||||
|
||||
void NinePatchLayer::d( Tesselator& t, const CachedQuad& q ) {
|
||||
/*
|
||||
t.vertexUV(x , y + h, blitOffset, (float)(sx ), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y + h, blitOffset, (float)(sx + sw), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y , blitOffset, (float)(sx + sw), (float)(sy ));
|
||||
t.vertexUV(x , y , blitOffset, (float)(sx ), (float)(sy ));
|
||||
*/
|
||||
|
||||
t.vertexUV(q.x0, q.y1, q.z, q.u0, q.v1);
|
||||
t.vertexUV(q.x1, q.y1, q.z, q.u1, q.v1);
|
||||
t.vertexUV(q.x1, q.y0, q.z, q.u1, q.v0);
|
||||
t.vertexUV(q.x0, q.y0, q.z, q.u0, q.v0);
|
||||
}
|
||||
|
||||
NinePatchFactory::NinePatchFactory( Textures* textures, const std::string& imageName ) : textures(textures),
|
||||
imageName(imageName),
|
||||
width(1),
|
||||
height(1) {
|
||||
TextureId id = textures->loadTexture(imageName);
|
||||
if (id != Textures::InvalidId) {
|
||||
const TextureData* data = textures->getTemporaryTextureData(id);
|
||||
if (data) { // This should never be false
|
||||
width = data->w;
|
||||
height = data->h;
|
||||
}
|
||||
} else {
|
||||
LOGE("Error @ NinePatchFactory::ctor - Couldn't find texture: %s\n", imageName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchFactory::createSymmetrical( const IntRectangle& src, int xCutAt, int yCutAt, float w /*= 32.0f*/, float h /*= 32.0f*/ ) {
|
||||
return new NinePatchLayer(
|
||||
NinePatchDescription::createSymmetrical(width, height, src, xCutAt, yCutAt),
|
||||
imageName, textures, w, h);
|
||||
}
|
||||
#include "NinePatch.hpp"
|
||||
|
||||
NinePatchDescription::NinePatchDescription( float x, float y, float x1, float x2, float x3, float y1, float y2, float y3, float w, float e, float n, float s ) : u0(x), u1(x + x1), u2(x + x2), u3(x + x3),
|
||||
v0(y), v1(y + y1), v2(y + y2), v3(y + y3),
|
||||
w(w), e(e), n(n), s(s),
|
||||
imgW(-1),
|
||||
imgH(-1) {
|
||||
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImage( const TextureData& d ) {
|
||||
return transformUVForImageSize(d.w, d.h);
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImageSize( int w, int h ) {
|
||||
if (imgW < 0)
|
||||
imgW = imgH = 1;
|
||||
|
||||
const float us = (float) imgW / w; // @todo: prepare for normal blit? (e.g. mult by 256)
|
||||
const float vs = (float) imgH / h;
|
||||
u0 *= us; u1 *= us; u2 *= us; u3 *= us;
|
||||
v0 *= vs; v1 *= vs; v2 *= vs; v3 *= vs;
|
||||
|
||||
imgW = w;
|
||||
imgH = h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NinePatchDescription NinePatchDescription::createSymmetrical( int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt ) {
|
||||
NinePatchDescription patch((float)src.x, (float)src.y,// width and height of src
|
||||
(float)xCutAt, (float)(src.w-xCutAt), (float)src.w, // u tex coordinates
|
||||
(float)yCutAt, (float)(src.h-yCutAt), (float)src.h, // v tex coordinates
|
||||
(float)xCutAt, (float)xCutAt, (float)yCutAt, (float)yCutAt); // border width and heights
|
||||
if (texWidth > 0) patch.transformUVForImageSize(texWidth, texHeight);
|
||||
return patch;
|
||||
}
|
||||
|
||||
NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w, float h)
|
||||
: desc(desc),
|
||||
imageName(imageName),
|
||||
textures(textures),
|
||||
w(-1), h(-1),
|
||||
excluded(0)
|
||||
{
|
||||
setSize(w, h);
|
||||
}
|
||||
|
||||
void NinePatchLayer::setSize( float w, float h ) {
|
||||
if (w == this->w && h == this->h)
|
||||
return;
|
||||
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
buildQuad(i);
|
||||
}
|
||||
|
||||
void NinePatchLayer::draw( Tesselator& t, float x, float y ) {
|
||||
textures->loadAndBindTexture(imageName);
|
||||
t.begin();
|
||||
t.addOffset(x, y, 0);
|
||||
for (int i = 0, b = 1; i < 9; ++i, b += b)
|
||||
if ((b & excluded) == 0)
|
||||
d(t, quads[i]);
|
||||
t.addOffset(-x, -y, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::exclude( int excludeId ) {
|
||||
return setExcluded(excluded | (1 << excludeId));
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::setExcluded( int exludeBits ) {
|
||||
excluded = exludeBits;
|
||||
return this;
|
||||
}
|
||||
|
||||
void NinePatchLayer::buildQuad( int qid ) {
|
||||
//@attn; fix
|
||||
CachedQuad& q = quads[qid];
|
||||
const int yid = qid / 3;
|
||||
const int xid = qid - 3 * yid;
|
||||
q.u0 = (&desc.u0)[xid];
|
||||
q.u1 = (&desc.u0)[xid + 1];
|
||||
q.v0 = (&desc.v0)[yid];
|
||||
q.v1 = (&desc.v0)[yid + 1];
|
||||
q.z = 0;
|
||||
getPatchInfo(xid, yid, q.x0, q.x1, q.y0, q.y1);
|
||||
/* q.x0 = w * (q.u0 - desc.u0);
|
||||
q.y0 = h * (q.v0 - desc.v0);
|
||||
q.x1 = w * (q.u1 - desc.u0);
|
||||
q.y1 = h * (q.v1 - desc.v0);
|
||||
*/
|
||||
}
|
||||
|
||||
void NinePatchLayer::getPatchInfo( int xc, int yc, float& x0, float& x1, float& y0, float& y1 ) {
|
||||
if (xc == 0) { x0 = 0; x1 = desc.w; }
|
||||
else if (xc == 1) { x0 = desc.w; x1 = w - desc.e; }
|
||||
else if (xc == 2) { x0 = w-desc.e; x1 = w; }
|
||||
if (yc == 0) { y0 = 0; y1 = desc.n; }
|
||||
else if (yc == 1) { y0 = desc.n; y1 = h - desc.s; }
|
||||
else if (yc == 2) { y0 = h-desc.s; y1 = h; }
|
||||
}
|
||||
|
||||
void NinePatchLayer::d( Tesselator& t, const CachedQuad& q ) {
|
||||
/*
|
||||
t.vertexUV(x , y + h, blitOffset, (float)(sx ), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y + h, blitOffset, (float)(sx + sw), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y , blitOffset, (float)(sx + sw), (float)(sy ));
|
||||
t.vertexUV(x , y , blitOffset, (float)(sx ), (float)(sy ));
|
||||
*/
|
||||
|
||||
t.vertexUV(q.x0, q.y1, q.z, q.u0, q.v1);
|
||||
t.vertexUV(q.x1, q.y1, q.z, q.u1, q.v1);
|
||||
t.vertexUV(q.x1, q.y0, q.z, q.u1, q.v0);
|
||||
t.vertexUV(q.x0, q.y0, q.z, q.u0, q.v0);
|
||||
}
|
||||
|
||||
NinePatchFactory::NinePatchFactory( Textures* textures, const std::string& imageName ) : textures(textures),
|
||||
imageName(imageName),
|
||||
width(1),
|
||||
height(1) {
|
||||
TextureId id = textures->loadTexture(imageName);
|
||||
if (id != Textures::InvalidId) {
|
||||
const TextureData* data = textures->getTemporaryTextureData(id);
|
||||
if (data) { // This should never be false
|
||||
width = data->w;
|
||||
height = data->h;
|
||||
}
|
||||
} else {
|
||||
LOGE("Error @ NinePatchFactory::ctor - Couldn't find texture: %s\n", imageName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchFactory::createSymmetrical( const IntRectangle& src, int xCutAt, int yCutAt, float w /*= 32.0f*/, float h /*= 32.0f*/ ) {
|
||||
return new NinePatchLayer(
|
||||
NinePatchDescription::createSymmetrical(width, height, src, xCutAt, yCutAt),
|
||||
imageName, textures, w, h);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "ImageButton.h"
|
||||
#include "../../renderer/TextureData.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "ImageButton.hpp"
|
||||
#include "client/renderer/TextureData.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
|
||||
class Tesselator;
|
||||
|
||||
|
|
@ -1,115 +1,115 @@
|
|||
#include "OptionsGroup.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "ImageButton.h"
|
||||
#include "OptionsItem.h"
|
||||
#include "Slider.h"
|
||||
#include "../../../locale/I18n.h"
|
||||
#include "TextOption.h"
|
||||
#include "KeyOption.h"
|
||||
|
||||
OptionsGroup::OptionsGroup( std::string labelID ) {
|
||||
label = I18n::get(labelID);
|
||||
}
|
||||
|
||||
void OptionsGroup::setupPositions() {
|
||||
// First we write the header and then we add the items
|
||||
int curY = y + 18;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->width = width - 5;
|
||||
|
||||
(*it)->y = curY;
|
||||
(*it)->x = x + 10;
|
||||
(*it)->setupPositions();
|
||||
curY += (*it)->height + 3;
|
||||
}
|
||||
height = curY;
|
||||
}
|
||||
|
||||
void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
float padX = 10.0f;
|
||||
float padY = 5.0f;
|
||||
|
||||
minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false);
|
||||
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) {
|
||||
auto option = minecraft->options.getOpt(optId);
|
||||
|
||||
if (option == nullptr) return *this;
|
||||
|
||||
// TODO: do a options key class to check it faster via dynamic_cast
|
||||
if (option->getStringId().find("options.key") != std::string::npos) createKey(optId, minecraft);
|
||||
else if (dynamic_cast<OptionBool*>(option)) createToggle(optId, minecraft);
|
||||
else if (dynamic_cast<OptionFloat*>(option)) createProgressSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionInt*>(option)) createStepSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionString*>(option)) createTextbox(optId, minecraft);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// TODO: wrap this copypaste shit into templates
|
||||
|
||||
void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) {
|
||||
ImageDef def;
|
||||
|
||||
def.setSrc(IntRectangle(160, 206, 39, 20));
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 39 * 0.7f;
|
||||
def.height = 20 * 0.7f;
|
||||
|
||||
OptionButton* element = new OptionButton(optId);
|
||||
element->setImageDef(def, true);
|
||||
element->updateImage(&minecraft->options);
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderFloat(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderInt(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) {
|
||||
TextBox* element = new TextOption(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) {
|
||||
KeyOption* element = new KeyOption(minecraft, optId);
|
||||
element->width = 50;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
#include "OptionsGroup.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "ImageButton.hpp"
|
||||
#include "OptionsItem.hpp"
|
||||
#include "Slider.hpp"
|
||||
#include "locale/I18n.hpp"
|
||||
#include "TextOption.hpp"
|
||||
#include "KeyOption.hpp"
|
||||
|
||||
OptionsGroup::OptionsGroup( std::string labelID ) {
|
||||
label = I18n::get(labelID);
|
||||
}
|
||||
|
||||
void OptionsGroup::setupPositions() {
|
||||
// First we write the header and then we add the items
|
||||
int curY = y + 18;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->width = width - 5;
|
||||
|
||||
(*it)->y = curY;
|
||||
(*it)->x = x + 10;
|
||||
(*it)->setupPositions();
|
||||
curY += (*it)->height + 3;
|
||||
}
|
||||
height = curY;
|
||||
}
|
||||
|
||||
void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
float padX = 10.0f;
|
||||
float padY = 5.0f;
|
||||
|
||||
minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false);
|
||||
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) {
|
||||
auto option = minecraft->options.getOpt(optId);
|
||||
|
||||
if (option == nullptr) return *this;
|
||||
|
||||
// TODO: do a options key class to check it faster via dynamic_cast
|
||||
if (option->getStringId().find("options.key") != std::string::npos) createKey(optId, minecraft);
|
||||
else if (dynamic_cast<OptionBool*>(option)) createToggle(optId, minecraft);
|
||||
else if (dynamic_cast<OptionFloat*>(option)) createProgressSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionInt*>(option)) createStepSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionString*>(option)) createTextbox(optId, minecraft);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// TODO: wrap this copypaste shit into templates
|
||||
|
||||
void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) {
|
||||
ImageDef def;
|
||||
|
||||
def.setSrc(IntRectangle(160, 206, 39, 20));
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 39 * 0.7f;
|
||||
def.height = 20 * 0.7f;
|
||||
|
||||
OptionButton* element = new OptionButton(optId);
|
||||
element->setImageDef(def, true);
|
||||
element->updateImage(&minecraft->options);
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderFloat(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderInt(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) {
|
||||
TextBox* element = new TextOption(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) {
|
||||
KeyOption* element = new KeyOption(minecraft, optId);
|
||||
element->width = 50;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElementContainer.h"
|
||||
#include "ScrollingPane.h"
|
||||
#include "../../Options.h"
|
||||
#include "GuiElementContainer.hpp"
|
||||
#include "ScrollingPane.hpp"
|
||||
#include "client/Options.hpp"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
|
|
@ -1,42 +1,42 @@
|
|||
#include "OptionsItem.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../locale/I18n.h"
|
||||
#include "../../../util/Mth.h"
|
||||
OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element )
|
||||
: GuiElementContainer(false, true, 0, 0, 24, 12),
|
||||
m_optionId(optionId),
|
||||
m_label(label) {
|
||||
addChild(element);
|
||||
}
|
||||
|
||||
void OptionsItem::setupPositions() {
|
||||
int currentHeight = 0;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->x = x + width - (*it)->width - 15;
|
||||
(*it)->y = y + currentHeight;
|
||||
currentHeight += (*it)->height;
|
||||
}
|
||||
height = currentHeight;
|
||||
}
|
||||
|
||||
void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int yOffset = (height - 8) / 2;
|
||||
std::string text = m_label;
|
||||
if (m_optionId == OPTIONS_GUI_SCALE) {
|
||||
int value = minecraft->options.getIntValue(OPTIONS_GUI_SCALE);
|
||||
std::string scaleText;
|
||||
switch (value) {
|
||||
case 0: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
case 1: scaleText = I18n::get("options.guiScale.small"); break;
|
||||
case 2: scaleText = I18n::get("options.guiScale.medium"); break;
|
||||
case 3: scaleText = I18n::get("options.guiScale.large"); break;
|
||||
case 4: scaleText = I18n::get("options.guiScale.larger"); break;
|
||||
case 5: scaleText = I18n::get("options.guiScale.largest"); break;
|
||||
default: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
}
|
||||
text += ": " + scaleText;
|
||||
}
|
||||
|
||||
minecraft->font->draw(text, (float)x, (float)y + yOffset, 0x909090, false);
|
||||
super::render(minecraft, xm, ym);
|
||||
#include "OptionsItem.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "locale/I18n.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element )
|
||||
: GuiElementContainer(false, true, 0, 0, 24, 12),
|
||||
m_optionId(optionId),
|
||||
m_label(label) {
|
||||
addChild(element);
|
||||
}
|
||||
|
||||
void OptionsItem::setupPositions() {
|
||||
int currentHeight = 0;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->x = x + width - (*it)->width - 15;
|
||||
(*it)->y = y + currentHeight;
|
||||
currentHeight += (*it)->height;
|
||||
}
|
||||
height = currentHeight;
|
||||
}
|
||||
|
||||
void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int yOffset = (height - 8) / 2;
|
||||
std::string text = m_label;
|
||||
if (m_optionId == OPTIONS_GUI_SCALE) {
|
||||
int value = minecraft->options.getIntValue(OPTIONS_GUI_SCALE);
|
||||
std::string scaleText;
|
||||
switch (value) {
|
||||
case 0: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
case 1: scaleText = I18n::get("options.guiScale.small"); break;
|
||||
case 2: scaleText = I18n::get("options.guiScale.medium"); break;
|
||||
case 3: scaleText = I18n::get("options.guiScale.large"); break;
|
||||
case 4: scaleText = I18n::get("options.guiScale.larger"); break;
|
||||
case 5: scaleText = I18n::get("options.guiScale.largest"); break;
|
||||
default: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
}
|
||||
text += ": " + scaleText;
|
||||
}
|
||||
|
||||
minecraft->font->draw(text, (float)x, (float)y + yOffset, 0x909090, false);
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "GuiElementContainer.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../../client/Options.h"
|
||||
#include "GuiElementContainer.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "client/Options.hpp"
|
||||
class Font;
|
||||
class Textures;
|
||||
class NinePatchLayer;
|
||||
|
|
@ -1,299 +1,299 @@
|
|||
#include "RolledSelectionListH.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../platform/input/Multitouch.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "MinecraftClient.h"
|
||||
|
||||
|
||||
RolledSelectionListH::RolledSelectionListH( MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
|
||||
: minecraft(minecraft),
|
||||
width(width),
|
||||
height(height),
|
||||
x0((float)x0),
|
||||
x1((float)x1),
|
||||
y0((float)y0),
|
||||
y1((float)y1),
|
||||
itemWidth(itemWidth),
|
||||
selectionX(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerWidth(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
xDrag(0.0f),
|
||||
xo(0.0f),
|
||||
xoo(0.0f),
|
||||
xInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastxoo(0),
|
||||
_xinertia(0)
|
||||
{
|
||||
xo = xoo = (float)(itemWidth-width) * 0.5f;
|
||||
_lastxoo = xoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerWidth = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemWidth + headerWidth;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(x - x0 - headerWidth + (int) xo - 4);
|
||||
int isInsideY = y >= y0 && y <= y1;
|
||||
return isInsideY? getItemAtXPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtXPositionRaw(int x) {
|
||||
int slot = x / itemWidth;
|
||||
bool isInsideX = slot >= 0 && x >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListH::capXPosition()
|
||||
{
|
||||
const float MinX = (float)(itemWidth-width)/2;
|
||||
const float MaxX = MinX + (getNumberOfItems()-1) * itemWidth;
|
||||
if (xo < MinX) { xo = MinX; xInertia = 0; return true; }
|
||||
if (xo > MaxX) { xo = MaxX; xInertia = 0; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::tick() {
|
||||
|
||||
//if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_xinertia = _lastxoo - xoo;
|
||||
}
|
||||
_lastxoo = xoo;
|
||||
xoo = xo - xInertia;
|
||||
}
|
||||
|
||||
float RolledSelectionListH::getPos(float alpha) {
|
||||
return xoo - xInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = getItemAtPosition(xm, height/2);
|
||||
//float localX = (float)(xm*Gui::InvGuiScale - x0 - xo + lastSelection * itemWidth + headerWidth);
|
||||
selectStart(lastSelection, 0, 0);//localX, ym-y0);
|
||||
selectionX = xm;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
xo -= (xm - xDrag);
|
||||
xoo = xo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
//const int* ids;
|
||||
//LOGI("mtouch: %d\n", Multitouch::getActivePointerIds(&ids));
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
xInertia = _xinertia < 0? Mth::Max(-20.0f, _xinertia) : Mth::Min(20.0f, _xinertia);
|
||||
}
|
||||
//LOGI("Inertia: %f. Time: %d, delta-x: %d, (xm, sel: %d, %d)\n", xInertia, getTimeMs() - lastSelectionTime, std::abs(selectionX - xm), xm, selectionX);
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(xInertia) <= 2.0001f) {
|
||||
xInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(xInertia) <= 10 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
int slot = getItemAtPosition(xm, height/2);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (slot >= 0 && slot == lastSelection && std::abs(selectionX - xm) < 10)
|
||||
selectItem(slot, false);
|
||||
else
|
||||
selectCancel();
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
xo = getPos(a);
|
||||
}
|
||||
xDrag = (float)xm;
|
||||
|
||||
capXPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
//LOGI("x: %f\n", xo);
|
||||
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, (x0 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by1, 0, (x1 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by0, 0, (x1 + (int) xo) / s, by0 / s);
|
||||
t.vertexUV(x0, by0, 0, (x0 + (int) xo) / s, by0 / s);
|
||||
t.draw();
|
||||
|
||||
const int HalfHeight = 48;
|
||||
|
||||
if (getNumberOfItems() == 0) xo = 0;
|
||||
|
||||
int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
int rowBaseX = (int)(x0 /*+ 4*/ - (int) xo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowBaseX, rowY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float x = (float)(rowBaseX + (i) * itemWidth + headerWidth);
|
||||
float h = (float)itemWidth;
|
||||
|
||||
if (x > x1 || (x + h) < x0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float y0 = height / 2.0f - HalfHeight - 4; //@kindle-res:+2
|
||||
float y1 = height / 2.0f + HalfHeight - 4; //@kindle-res:-6
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
int ew = 0;
|
||||
int color = 0x808080;
|
||||
if (_componentSelected) {
|
||||
ew = 0;
|
||||
color = 0x7F89BF;
|
||||
}
|
||||
t.begin();
|
||||
t.color(color);
|
||||
t.vertex(x - 1 - ew, y0 - ew, 0);
|
||||
t.vertex(x - 1 - ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y0 - ew, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertex(x, y0 + 1, 0);
|
||||
t.vertex(x, y1 - 1, 0);
|
||||
t.vertex(x + h, y1 - 1, 0);
|
||||
t.vertex(x + h, y0 + 1, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, (int)x, rowY, (int)h, t);
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::touched()
|
||||
{
|
||||
}
|
||||
#include "RolledSelectionListH.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "platform/input/Multitouch.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "MinecraftClient.hpp"
|
||||
|
||||
|
||||
RolledSelectionListH::RolledSelectionListH( MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
|
||||
: minecraft(minecraft),
|
||||
width(width),
|
||||
height(height),
|
||||
x0((float)x0),
|
||||
x1((float)x1),
|
||||
y0((float)y0),
|
||||
y1((float)y1),
|
||||
itemWidth(itemWidth),
|
||||
selectionX(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerWidth(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
xDrag(0.0f),
|
||||
xo(0.0f),
|
||||
xoo(0.0f),
|
||||
xInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastxoo(0),
|
||||
_xinertia(0)
|
||||
{
|
||||
xo = xoo = (float)(itemWidth-width) * 0.5f;
|
||||
_lastxoo = xoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerWidth = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemWidth + headerWidth;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(x - x0 - headerWidth + (int) xo - 4);
|
||||
int isInsideY = y >= y0 && y <= y1;
|
||||
return isInsideY? getItemAtXPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtXPositionRaw(int x) {
|
||||
int slot = x / itemWidth;
|
||||
bool isInsideX = slot >= 0 && x >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListH::capXPosition()
|
||||
{
|
||||
const float MinX = (float)(itemWidth-width)/2;
|
||||
const float MaxX = MinX + (getNumberOfItems()-1) * itemWidth;
|
||||
if (xo < MinX) { xo = MinX; xInertia = 0; return true; }
|
||||
if (xo > MaxX) { xo = MaxX; xInertia = 0; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::tick() {
|
||||
|
||||
//if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_xinertia = _lastxoo - xoo;
|
||||
}
|
||||
_lastxoo = xoo;
|
||||
xoo = xo - xInertia;
|
||||
}
|
||||
|
||||
float RolledSelectionListH::getPos(float alpha) {
|
||||
return xoo - xInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = getItemAtPosition(xm, height/2);
|
||||
//float localX = (float)(xm*Gui::InvGuiScale - x0 - xo + lastSelection * itemWidth + headerWidth);
|
||||
selectStart(lastSelection, 0, 0);//localX, ym-y0);
|
||||
selectionX = xm;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
xo -= (xm - xDrag);
|
||||
xoo = xo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
//const int* ids;
|
||||
//LOGI("mtouch: %d\n", Multitouch::getActivePointerIds(&ids));
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
xInertia = _xinertia < 0? Mth::Max(-20.0f, _xinertia) : Mth::Min(20.0f, _xinertia);
|
||||
}
|
||||
//LOGI("Inertia: %f. Time: %d, delta-x: %d, (xm, sel: %d, %d)\n", xInertia, getTimeMs() - lastSelectionTime, std::abs(selectionX - xm), xm, selectionX);
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(xInertia) <= 2.0001f) {
|
||||
xInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(xInertia) <= 10 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
int slot = getItemAtPosition(xm, height/2);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (slot >= 0 && slot == lastSelection && std::abs(selectionX - xm) < 10)
|
||||
selectItem(slot, false);
|
||||
else
|
||||
selectCancel();
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
xo = getPos(a);
|
||||
}
|
||||
xDrag = (float)xm;
|
||||
|
||||
capXPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
//LOGI("x: %f\n", xo);
|
||||
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, (x0 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by1, 0, (x1 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by0, 0, (x1 + (int) xo) / s, by0 / s);
|
||||
t.vertexUV(x0, by0, 0, (x0 + (int) xo) / s, by0 / s);
|
||||
t.draw();
|
||||
|
||||
const int HalfHeight = 48;
|
||||
|
||||
if (getNumberOfItems() == 0) xo = 0;
|
||||
|
||||
int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
int rowBaseX = (int)(x0 /*+ 4*/ - (int) xo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowBaseX, rowY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float x = (float)(rowBaseX + (i) * itemWidth + headerWidth);
|
||||
float h = (float)itemWidth;
|
||||
|
||||
if (x > x1 || (x + h) < x0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float y0 = height / 2.0f - HalfHeight - 4; //@kindle-res:+2
|
||||
float y1 = height / 2.0f + HalfHeight - 4; //@kindle-res:-6
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
int ew = 0;
|
||||
int color = 0x808080;
|
||||
if (_componentSelected) {
|
||||
ew = 0;
|
||||
color = 0x7F89BF;
|
||||
}
|
||||
t.begin();
|
||||
t.color(color);
|
||||
t.vertex(x - 1 - ew, y0 - ew, 0);
|
||||
t.vertex(x - 1 - ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y0 - ew, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertex(x, y0 + 1, 0);
|
||||
t.vertex(x, y1 - 1, 0);
|
||||
t.vertex(x + h, y1 - 1, 0);
|
||||
t.vertex(x + h, y0 + 1, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, (int)x, rowY, (int)h, t);
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::touched()
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
class MinecraftClient;
|
||||
class Tesselator;
|
||||
|
||||
|
|
@ -1,352 +1,352 @@
|
|||
#include "RolledSelectionListV.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
|
||||
RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ )
|
||||
: minecraft(minecraft_),
|
||||
width(width_),
|
||||
height(height_),
|
||||
x0((float)x0_),
|
||||
x1((float)x1_),
|
||||
y0((float)y0_),
|
||||
y1((float)y1_),
|
||||
itemHeight(itemHeight_),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yoo(0.0f),
|
||||
yInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderDirtBackground(true),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastyoo(0),
|
||||
_yinertia(0),
|
||||
_stickPixels(0),
|
||||
_lastxm(0),
|
||||
_lastym(0)
|
||||
{
|
||||
yo = yoo = 0;//(float)(-itemHeight) * 0.5f;
|
||||
_lastyoo = yoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int isInsideX = x >= x0 && x <= x1;
|
||||
return isInsideX? getItemAtYPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtYPositionRaw(int y) {
|
||||
int slot = y / itemHeight;
|
||||
bool isInsideX = slot >= 0 && y >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListV::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
return false;
|
||||
/*
|
||||
const float MinY = -itemHeight/2;//(float)(itemHeight-height)/2;
|
||||
const float MaxY = MinY + (getNumberOfItems()-1) * itemHeight;
|
||||
if (yo < MinY) { yo = MinY; yInertia = 0; return true; }
|
||||
if (yo > MaxY) { yo = MaxY; yInertia = 0; return true; }
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
void RolledSelectionListV::tick() {
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_yinertia = _lastyoo - yoo;
|
||||
}
|
||||
_lastyoo = yoo;
|
||||
|
||||
//yInertia = Mth::absDecrease(yInertia, 1.0f, 0);
|
||||
|
||||
yoo = yo - yInertia;
|
||||
|
||||
//LOGI("tick: %f, %f, %f\n", yo, yInertia, _yinertia);
|
||||
}
|
||||
|
||||
float RolledSelectionListV::getPos(float alpha) {
|
||||
return yoo - yInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::render( int xm, int ym, float a )
|
||||
{
|
||||
_lastxm = xm;
|
||||
_lastym = ym;
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = convertSelection( getItemAtPosition(width/2, ym), xm, ym );
|
||||
selectStart(lastSelection);
|
||||
//LOGI("Sel : %d\n", lastSelection);
|
||||
selectionY = ym;
|
||||
_stickPixels = 10;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
float delta = (ym - yDrag);
|
||||
float absDelta = Mth::abs(delta);
|
||||
if (absDelta > _stickPixels) {
|
||||
_stickPixels = 0;
|
||||
delta -= delta>0? _stickPixels : -_stickPixels;
|
||||
} else {
|
||||
delta = 0;
|
||||
_stickPixels -= absDelta;
|
||||
}
|
||||
yo -= delta;
|
||||
yoo = yo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
yInertia = _yinertia < 0? Mth::Max(-10.0f, _yinertia) : Mth::Min(10.0f, _yinertia);
|
||||
}
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(yInertia) <= 2.0001f) {
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(yInertia) <= 10 /*&& getTimeMs() - lastSelectionTime < 300 */)
|
||||
{
|
||||
//float clickSlotPos = (ym - x0 - headerHeight + (int) yo - 4);
|
||||
int slot = convertSelection( getItemAtPosition(width/2, ym), xm, ym);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (xm >= x0 && xm <= x1 && slot >= 0 && slot == lastSelection && std::abs(selectionY - ym) < 10)
|
||||
selectItem(slot, false);
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo = getPos(a);
|
||||
}
|
||||
yDrag = (float)ym;
|
||||
|
||||
evaluate(xm, ym);
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (_renderDirtBackground)
|
||||
renderDirtBackground();
|
||||
|
||||
if (getNumberOfItems() == 0) yo = 0;
|
||||
|
||||
//int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
if (doRenderHeader) {
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
onPreRender();
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
//float y0 = height / 2.0f - HalfHeight - 4;
|
||||
//float y1 = height / 2.0f + HalfHeight - 4;
|
||||
//glColor4f2(1, 1, 1, 1);
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//int ew = 0;
|
||||
//int color = 0x808080;
|
||||
//if (_componentSelected) {
|
||||
// ew = 0;
|
||||
// color = 0x7F89BF;
|
||||
//}
|
||||
//t.begin();
|
||||
//t.color(color);
|
||||
//t.vertex(x - 2 - ew, y0 - ew, 0);
|
||||
//t.vertex(x - 2 - ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y0 - ew, 0);
|
||||
|
||||
//t.color(0x000000);
|
||||
//t.vertex(x - 1, y0 + 1, 0);
|
||||
//t.vertex(x - 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y0 + 1, 0);
|
||||
|
||||
//t.draw();
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
}
|
||||
onPostRender();
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
renderForeground();
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
//glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::touched()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::evaluate(int xm, int ym)
|
||||
{
|
||||
if (std::abs(selectionY - ym) >= 10) {
|
||||
lastSelection = -1;
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPreRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPostRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderDirtBackground()
|
||||
{
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
const float uvy = (float)((int) yo);
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, x0 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by1, 0, x1 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by0, 0, x1 / s, (by0+uvy) / s);
|
||||
t.vertexUV(x0, by0, 0, x0 / s, (by0+uvy) / s);
|
||||
t.draw();
|
||||
//LOGI("%f, %f - %f, %f\n", x0, by0, x1, by1);
|
||||
}
|
||||
#include "RolledSelectionListV.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
|
||||
RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ )
|
||||
: minecraft(minecraft_),
|
||||
width(width_),
|
||||
height(height_),
|
||||
x0((float)x0_),
|
||||
x1((float)x1_),
|
||||
y0((float)y0_),
|
||||
y1((float)y1_),
|
||||
itemHeight(itemHeight_),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yoo(0.0f),
|
||||
yInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderDirtBackground(true),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastyoo(0),
|
||||
_yinertia(0),
|
||||
_stickPixels(0),
|
||||
_lastxm(0),
|
||||
_lastym(0)
|
||||
{
|
||||
yo = yoo = 0;//(float)(-itemHeight) * 0.5f;
|
||||
_lastyoo = yoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int isInsideX = x >= x0 && x <= x1;
|
||||
return isInsideX? getItemAtYPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtYPositionRaw(int y) {
|
||||
int slot = y / itemHeight;
|
||||
bool isInsideX = slot >= 0 && y >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListV::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
return false;
|
||||
/*
|
||||
const float MinY = -itemHeight/2;//(float)(itemHeight-height)/2;
|
||||
const float MaxY = MinY + (getNumberOfItems()-1) * itemHeight;
|
||||
if (yo < MinY) { yo = MinY; yInertia = 0; return true; }
|
||||
if (yo > MaxY) { yo = MaxY; yInertia = 0; return true; }
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
void RolledSelectionListV::tick() {
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_yinertia = _lastyoo - yoo;
|
||||
}
|
||||
_lastyoo = yoo;
|
||||
|
||||
//yInertia = Mth::absDecrease(yInertia, 1.0f, 0);
|
||||
|
||||
yoo = yo - yInertia;
|
||||
|
||||
//LOGI("tick: %f, %f, %f\n", yo, yInertia, _yinertia);
|
||||
}
|
||||
|
||||
float RolledSelectionListV::getPos(float alpha) {
|
||||
return yoo - yInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::render( int xm, int ym, float a )
|
||||
{
|
||||
_lastxm = xm;
|
||||
_lastym = ym;
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = convertSelection( getItemAtPosition(width/2, ym), xm, ym );
|
||||
selectStart(lastSelection);
|
||||
//LOGI("Sel : %d\n", lastSelection);
|
||||
selectionY = ym;
|
||||
_stickPixels = 10;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
float delta = (ym - yDrag);
|
||||
float absDelta = Mth::abs(delta);
|
||||
if (absDelta > _stickPixels) {
|
||||
_stickPixels = 0;
|
||||
delta -= delta>0? _stickPixels : -_stickPixels;
|
||||
} else {
|
||||
delta = 0;
|
||||
_stickPixels -= absDelta;
|
||||
}
|
||||
yo -= delta;
|
||||
yoo = yo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
yInertia = _yinertia < 0? Mth::Max(-10.0f, _yinertia) : Mth::Min(10.0f, _yinertia);
|
||||
}
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(yInertia) <= 2.0001f) {
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(yInertia) <= 10 /*&& getTimeMs() - lastSelectionTime < 300 */)
|
||||
{
|
||||
//float clickSlotPos = (ym - x0 - headerHeight + (int) yo - 4);
|
||||
int slot = convertSelection( getItemAtPosition(width/2, ym), xm, ym);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (xm >= x0 && xm <= x1 && slot >= 0 && slot == lastSelection && std::abs(selectionY - ym) < 10)
|
||||
selectItem(slot, false);
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo = getPos(a);
|
||||
}
|
||||
yDrag = (float)ym;
|
||||
|
||||
evaluate(xm, ym);
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (_renderDirtBackground)
|
||||
renderDirtBackground();
|
||||
|
||||
if (getNumberOfItems() == 0) yo = 0;
|
||||
|
||||
//int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
if (doRenderHeader) {
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
onPreRender();
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
//float y0 = height / 2.0f - HalfHeight - 4;
|
||||
//float y1 = height / 2.0f + HalfHeight - 4;
|
||||
//glColor4f2(1, 1, 1, 1);
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//int ew = 0;
|
||||
//int color = 0x808080;
|
||||
//if (_componentSelected) {
|
||||
// ew = 0;
|
||||
// color = 0x7F89BF;
|
||||
//}
|
||||
//t.begin();
|
||||
//t.color(color);
|
||||
//t.vertex(x - 2 - ew, y0 - ew, 0);
|
||||
//t.vertex(x - 2 - ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y0 - ew, 0);
|
||||
|
||||
//t.color(0x000000);
|
||||
//t.vertex(x - 1, y0 + 1, 0);
|
||||
//t.vertex(x - 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y0 + 1, 0);
|
||||
|
||||
//t.draw();
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
}
|
||||
onPostRender();
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
renderForeground();
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
//glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::touched()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::evaluate(int xm, int ym)
|
||||
{
|
||||
if (std::abs(selectionY - ym) >= 10) {
|
||||
lastSelection = -1;
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPreRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPostRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderDirtBackground()
|
||||
{
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
const float uvy = (float)((int) yo);
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, x0 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by1, 0, x1 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by0, 0, x1 / s, (by0+uvy) / s);
|
||||
t.vertexUV(x0, by0, 0, x0 / s, (by0+uvy) / s);
|
||||
t.draw();
|
||||
//LOGI("%f, %f - %f, %f\n", x0, by0, x1, by1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
class Minecraft;
|
||||
class Tesselator;
|
||||
|
||||
|
|
@ -1,296 +1,296 @@
|
|||
#include "ScrolledSelectionList.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
static int Abs(int d) {
|
||||
return d >= 0? d : -d;
|
||||
}
|
||||
|
||||
ScrolledSelectionList::ScrolledSelectionList( Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight )
|
||||
: minecraft(_minecraft),
|
||||
width(_width),
|
||||
height(_height),
|
||||
y0((float)_y0),
|
||||
y1((float)_y1),
|
||||
itemHeight(_itemHeight),
|
||||
x0(0.0f),
|
||||
x1((float)_width),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yInertia(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int x0 = width / 2 - (92 + 16 + 2);
|
||||
int x1 = width / 2 + (92 + 16 + 2);
|
||||
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = clickSlotPos / itemHeight;
|
||||
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems()) {
|
||||
return slot;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float xx0 = width / 2.0f + 124;
|
||||
//float xx1 = xx0 + 6;
|
||||
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1 && ym != ignoreY) {
|
||||
if (dragState == NO_DRAG) {
|
||||
dragState = DRAG_SKIP;
|
||||
}
|
||||
else if (dragState >= 0)
|
||||
{
|
||||
if (dragState == DRAG_SKIP)
|
||||
{
|
||||
lastSelectionTime = getTimeMs();
|
||||
selectionY = ym;
|
||||
}
|
||||
else if (dragState == DRAG_NORMAL)
|
||||
{
|
||||
yo -= (ym - yDrag);
|
||||
yInertia += (float)(ym - yDrag);
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
ignoreY = -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (dragState != NO_DRAG)
|
||||
{
|
||||
//LOGI("UP ym: %d\n", ym);
|
||||
}
|
||||
//ignoreY = ym;
|
||||
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (dragState >= 0 && std::abs(yInertia) < 2)
|
||||
{
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (dragState >= 0 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
float clickSlotPos = (ym - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = (int)clickSlotPos / itemHeight;
|
||||
|
||||
if (slot >= 0 && Abs(selectionY - ym) < itemHeight)
|
||||
{
|
||||
bool doubleClick = false;
|
||||
selectItem(slot, doubleClick);
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo -= yInertia;
|
||||
}
|
||||
yInertia = yInertia * .75f;
|
||||
yDrag = (float)ym;
|
||||
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
renderDirtBackground();
|
||||
|
||||
int rowX = (int)(width / 2 - 92 - 16);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float x0 = width / 2.0f - (92 + 16 + 2);
|
||||
float x1 = width / 2.0f + (92 + 16 + 2);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.begin();
|
||||
t.color(0x808080);
|
||||
t.vertexUV(x0, y + h + 2, 0, 0, 1);
|
||||
t.vertexUV(x1, y + h + 2, 0, 1, 1);
|
||||
t.vertexUV(x1, y - 2, 0, 1, 0);
|
||||
t.vertexUV(x0, y - 2, 0, 0, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertexUV(x0 + 1, y + h + 1, 0, 0, 1);
|
||||
t.vertexUV(x1 - 1, y + h + 1, 0, 1, 1);
|
||||
t.vertexUV(x1 - 1, y - 1, 0, 1, 0);
|
||||
t.vertexUV(x0 + 1, y - 1, 0, 0, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
int d = 4;
|
||||
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x0, y0 + d, 0, 0, 1);
|
||||
t.vertexUV(x1, y0 + d, 0, 1, 1);
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x1, y0, 0, 1, 0);
|
||||
t.vertexUV(x0, y0, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x0, y1, 0, 0, 1);
|
||||
t.vertexUV(x1, y1, 0, 1, 1);
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x1, y1 - d, 0, 1, 0);
|
||||
t.vertexUV(x0, y1 - d, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
// {
|
||||
// float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
// if (max > 0) {
|
||||
// float barHeight = (y1 - y0) * (y1 - y0) / (getMaxPosition());
|
||||
// if (barHeight < 32) barHeight = 32;
|
||||
// if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8);
|
||||
//
|
||||
// float yp = (int) yo * (y1 - y0 - barHeight) / max + y0;
|
||||
// if (yp < y0) yp = y0;
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x000000, 255);
|
||||
// t.vertexUV(xx0, y1, 0.0f, 0.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y1, 0.0f, 1.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y0, 0.0f, 1.0f, 0.0f);
|
||||
// t.vertexUV(xx0, y0, 0.0f, 0.0f, 0.0f);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x808080, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight, 0, 0, 1);
|
||||
// t.vertexUV(xx1, yp + barHeight, 0, 1, 1);
|
||||
// t.vertexUV(xx1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0xc0c0c0, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight - 1, 0, 0, 1);
|
||||
// t.vertexUV(xx1 - 1, yp + barHeight - 1, 0, 1, 1);
|
||||
// t.vertexUV(xx1 - 1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
// }
|
||||
// }
|
||||
|
||||
renderDecorations(xm, ym);
|
||||
|
||||
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderDirtBackground()
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, y1, 0, x0 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y1, 0, x1 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y0, 0, x1 / s, (y0 + (int) yo) / s);
|
||||
t.vertexUV(x0, y0, 0, x0 / s, (y0 + (int) yo) / s);
|
||||
t.draw();
|
||||
}
|
||||
#include "ScrolledSelectionList.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
static int Abs(int d) {
|
||||
return d >= 0? d : -d;
|
||||
}
|
||||
|
||||
ScrolledSelectionList::ScrolledSelectionList( Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight )
|
||||
: minecraft(_minecraft),
|
||||
width(_width),
|
||||
height(_height),
|
||||
y0((float)_y0),
|
||||
y1((float)_y1),
|
||||
itemHeight(_itemHeight),
|
||||
x0(0.0f),
|
||||
x1((float)_width),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yInertia(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int x0 = width / 2 - (92 + 16 + 2);
|
||||
int x1 = width / 2 + (92 + 16 + 2);
|
||||
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = clickSlotPos / itemHeight;
|
||||
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems()) {
|
||||
return slot;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float xx0 = width / 2.0f + 124;
|
||||
//float xx1 = xx0 + 6;
|
||||
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1 && ym != ignoreY) {
|
||||
if (dragState == NO_DRAG) {
|
||||
dragState = DRAG_SKIP;
|
||||
}
|
||||
else if (dragState >= 0)
|
||||
{
|
||||
if (dragState == DRAG_SKIP)
|
||||
{
|
||||
lastSelectionTime = getTimeMs();
|
||||
selectionY = ym;
|
||||
}
|
||||
else if (dragState == DRAG_NORMAL)
|
||||
{
|
||||
yo -= (ym - yDrag);
|
||||
yInertia += (float)(ym - yDrag);
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
ignoreY = -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (dragState != NO_DRAG)
|
||||
{
|
||||
//LOGI("UP ym: %d\n", ym);
|
||||
}
|
||||
//ignoreY = ym;
|
||||
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (dragState >= 0 && std::abs(yInertia) < 2)
|
||||
{
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (dragState >= 0 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
float clickSlotPos = (ym - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = (int)clickSlotPos / itemHeight;
|
||||
|
||||
if (slot >= 0 && Abs(selectionY - ym) < itemHeight)
|
||||
{
|
||||
bool doubleClick = false;
|
||||
selectItem(slot, doubleClick);
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo -= yInertia;
|
||||
}
|
||||
yInertia = yInertia * .75f;
|
||||
yDrag = (float)ym;
|
||||
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
renderDirtBackground();
|
||||
|
||||
int rowX = (int)(width / 2 - 92 - 16);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float x0 = width / 2.0f - (92 + 16 + 2);
|
||||
float x1 = width / 2.0f + (92 + 16 + 2);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.begin();
|
||||
t.color(0x808080);
|
||||
t.vertexUV(x0, y + h + 2, 0, 0, 1);
|
||||
t.vertexUV(x1, y + h + 2, 0, 1, 1);
|
||||
t.vertexUV(x1, y - 2, 0, 1, 0);
|
||||
t.vertexUV(x0, y - 2, 0, 0, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertexUV(x0 + 1, y + h + 1, 0, 0, 1);
|
||||
t.vertexUV(x1 - 1, y + h + 1, 0, 1, 1);
|
||||
t.vertexUV(x1 - 1, y - 1, 0, 1, 0);
|
||||
t.vertexUV(x0 + 1, y - 1, 0, 0, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
int d = 4;
|
||||
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x0, y0 + d, 0, 0, 1);
|
||||
t.vertexUV(x1, y0 + d, 0, 1, 1);
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x1, y0, 0, 1, 0);
|
||||
t.vertexUV(x0, y0, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x0, y1, 0, 0, 1);
|
||||
t.vertexUV(x1, y1, 0, 1, 1);
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x1, y1 - d, 0, 1, 0);
|
||||
t.vertexUV(x0, y1 - d, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
// {
|
||||
// float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
// if (max > 0) {
|
||||
// float barHeight = (y1 - y0) * (y1 - y0) / (getMaxPosition());
|
||||
// if (barHeight < 32) barHeight = 32;
|
||||
// if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8);
|
||||
//
|
||||
// float yp = (int) yo * (y1 - y0 - barHeight) / max + y0;
|
||||
// if (yp < y0) yp = y0;
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x000000, 255);
|
||||
// t.vertexUV(xx0, y1, 0.0f, 0.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y1, 0.0f, 1.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y0, 0.0f, 1.0f, 0.0f);
|
||||
// t.vertexUV(xx0, y0, 0.0f, 0.0f, 0.0f);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x808080, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight, 0, 0, 1);
|
||||
// t.vertexUV(xx1, yp + barHeight, 0, 1, 1);
|
||||
// t.vertexUV(xx1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0xc0c0c0, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight - 1, 0, 0, 1);
|
||||
// t.vertexUV(xx1 - 1, yp + barHeight - 1, 0, 1, 1);
|
||||
// t.vertexUV(xx1 - 1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
// }
|
||||
// }
|
||||
|
||||
renderDecorations(xm, ym);
|
||||
|
||||
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderDirtBackground()
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, y1, 0, x0 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y1, 0, x1 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y0, 0, x1 / s, (y0 + (int) yo) / s);
|
||||
t.vertexUV(x0, y0, 0, x0 / s, (y0 + (int) yo) / s);
|
||||
t.draw();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
class Minecraft;
|
||||
class Tesselator;
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "ImageButton.h"
|
||||
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../../../world/phys/Vec3.h"
|
||||
#include "../../Timer.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
#include "ImageButton.hpp"
|
||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
||||
#include "world/phys/Vec3.hpp"
|
||||
#include "client/Timer.hpp"
|
||||
|
||||
enum ScrollingPaneFlags {
|
||||
SF_LockX = 1 << 0,
|
||||
|
|
@ -1,94 +1,94 @@
|
|||
#include "Slider.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../Screen.h"
|
||||
#include "../../../locale/I18n.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {}
|
||||
|
||||
void Slider::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int xSliderStart = x + 5;
|
||||
int xSliderEnd = x + width - 5;
|
||||
int ySliderStart = y + 6;
|
||||
int ySliderEnd = y + 9;
|
||||
int handleSizeX = 9;
|
||||
int handleSizeY = 15;
|
||||
int barWidth = xSliderEnd - xSliderStart;
|
||||
//fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff);
|
||||
fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060);
|
||||
|
||||
if (m_numSteps > 2) {
|
||||
int stepDistance = barWidth / (m_numSteps-1);
|
||||
for(int a = 0; a < m_numSteps; ++a) {
|
||||
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
|
||||
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
|
||||
}
|
||||
}
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
blit(xSliderStart + (int)(m_percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY);
|
||||
}
|
||||
|
||||
void Slider::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(pointInside(x, y)) {
|
||||
m_mouseDownOnElement = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
m_mouseDownOnElement = false;
|
||||
}
|
||||
|
||||
void Slider::tick(Minecraft* minecraft) {
|
||||
if(minecraft->screen != NULL) {
|
||||
int xm = Mouse::getX();
|
||||
int ym = Mouse::getY();
|
||||
|
||||
minecraft->screen->toGUICoordinate(xm, ym);
|
||||
|
||||
if(m_mouseDownOnElement) {
|
||||
m_percentage = float(xm - x) / float(width);
|
||||
m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionFloat*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_percentage = Mth::clamp((m_option->get() - m_option->getMin()) / (m_option->getMax() - m_option->getMin()), 0.f, 1.f);
|
||||
}
|
||||
|
||||
SliderInt::SliderInt(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionInt*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_numSteps = m_option->getMax() - m_option->getMin() + 1;
|
||||
m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1);
|
||||
}
|
||||
|
||||
void SliderInt::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Slider::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
int curStep = int(m_percentage * (m_numSteps-1) + 0.5f);
|
||||
curStep = Mth::clamp(curStep + m_option->getMin(), m_option->getMin(), m_option->getMax());
|
||||
m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1);
|
||||
|
||||
minecraft->options.set(m_optId, curStep);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin());
|
||||
}
|
||||
#include "Slider.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "locale/I18n.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {}
|
||||
|
||||
void Slider::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int xSliderStart = x + 5;
|
||||
int xSliderEnd = x + width - 5;
|
||||
int ySliderStart = y + 6;
|
||||
int ySliderEnd = y + 9;
|
||||
int handleSizeX = 9;
|
||||
int handleSizeY = 15;
|
||||
int barWidth = xSliderEnd - xSliderStart;
|
||||
//fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff);
|
||||
fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060);
|
||||
|
||||
if (m_numSteps > 2) {
|
||||
int stepDistance = barWidth / (m_numSteps-1);
|
||||
for(int a = 0; a < m_numSteps; ++a) {
|
||||
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
|
||||
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
|
||||
}
|
||||
}
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
blit(xSliderStart + (int)(m_percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY);
|
||||
}
|
||||
|
||||
void Slider::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(pointInside(x, y)) {
|
||||
m_mouseDownOnElement = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
m_mouseDownOnElement = false;
|
||||
}
|
||||
|
||||
void Slider::tick(Minecraft* minecraft) {
|
||||
if(minecraft->screen != NULL) {
|
||||
int xm = Mouse::getX();
|
||||
int ym = Mouse::getY();
|
||||
|
||||
minecraft->screen->toGUICoordinate(xm, ym);
|
||||
|
||||
if(m_mouseDownOnElement) {
|
||||
m_percentage = float(xm - x) / float(width);
|
||||
m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionFloat*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_percentage = Mth::clamp((m_option->get() - m_option->getMin()) / (m_option->getMax() - m_option->getMin()), 0.f, 1.f);
|
||||
}
|
||||
|
||||
SliderInt::SliderInt(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionInt*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_numSteps = m_option->getMax() - m_option->getMin() + 1;
|
||||
m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1);
|
||||
}
|
||||
|
||||
void SliderInt::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Slider::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
int curStep = int(m_percentage * (m_numSteps-1) + 0.5f);
|
||||
curStep = Mth::clamp(curStep + m_option->getMin(), m_option->getMin(), m_option->getMax());
|
||||
m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1);
|
||||
|
||||
minecraft->options.set(m_optId, curStep);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "GuiElement.h"
|
||||
#include "../../../client/Options.h"
|
||||
#include <client/Option.h>
|
||||
#include "GuiElement.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include <client/Option.hpp>
|
||||
|
||||
class Slider : public GuiElement {
|
||||
typedef GuiElement super;
|
||||
|
|
@ -1,102 +1,102 @@
|
|||
#include "TextBox.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
// delegate constructors
|
||||
TextBox::TextBox(int id, const std::string& msg)
|
||||
: TextBox(id, 0, 0, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, const std::string& msg)
|
||||
: TextBox(id, x, y, 24, Font::DefaultLineHeight + 4, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg)
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id), hint(msg), focused(false), blink(false), blinkTicks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TextBox::setFocus(Minecraft* minecraft) {
|
||||
if (!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
blinkTicks = 0;
|
||||
blink = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextBox::loseFocus(Minecraft* minecraft) {
|
||||
if (focused) {
|
||||
minecraft->platform()->hideKeyboard();
|
||||
focused = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if (pointInside(x, y)) {
|
||||
setFocus(minecraft);
|
||||
} else {
|
||||
loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::charPressed(Minecraft* minecraft, char c) {
|
||||
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
|
||||
text.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::keyPressed(Minecraft* minecraft, int key) {
|
||||
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
|
||||
text.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::tick(Minecraft* minecraft) {
|
||||
blinkTicks++;
|
||||
if (blinkTicks >= 5) {
|
||||
blink = !blink;
|
||||
blinkTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::render(Minecraft* minecraft, int xm, int ym) {
|
||||
// textbox like in beta 1.7.3
|
||||
// change appearance when focused so the user can tell it's active
|
||||
// active background darker gray with a subtle border
|
||||
uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0;
|
||||
uint32_t borderColor = focused ? 0xff000000 : 0xff000000;
|
||||
fill(x, y, x + width, y + height, bgColor);
|
||||
fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
glScissor(
|
||||
Gui::GuiScale * (x + 2),
|
||||
minecraft->height - Gui::GuiScale * (y + height - 2),
|
||||
Gui::GuiScale * (width - 2),
|
||||
Gui::GuiScale * (height - 2)
|
||||
);
|
||||
|
||||
int _y = y + (height - Font::DefaultLineHeight) / 2;
|
||||
|
||||
if (text.empty() && !focused) {
|
||||
drawString(minecraft->font, hint, x + 2, _y, 0xff5e5e5e);
|
||||
}
|
||||
|
||||
if (focused && blink) text.push_back('_');
|
||||
|
||||
drawString(minecraft->font, text, x + 2, _y, 0xffffffff);
|
||||
|
||||
if (focused && blink) text.pop_back();
|
||||
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
}
|
||||
#include "TextBox.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
|
||||
// delegate constructors
|
||||
TextBox::TextBox(int id, const std::string& msg)
|
||||
: TextBox(id, 0, 0, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, const std::string& msg)
|
||||
: TextBox(id, x, y, 24, Font::DefaultLineHeight + 4, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg)
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id), hint(msg), focused(false), blink(false), blinkTicks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TextBox::setFocus(Minecraft* minecraft) {
|
||||
if (!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
blinkTicks = 0;
|
||||
blink = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextBox::loseFocus(Minecraft* minecraft) {
|
||||
if (focused) {
|
||||
minecraft->platform()->hideKeyboard();
|
||||
focused = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if (pointInside(x, y)) {
|
||||
setFocus(minecraft);
|
||||
} else {
|
||||
loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::charPressed(Minecraft* minecraft, char c) {
|
||||
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
|
||||
text.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::keyPressed(Minecraft* minecraft, int key) {
|
||||
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
|
||||
text.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::tick(Minecraft* minecraft) {
|
||||
blinkTicks++;
|
||||
if (blinkTicks >= 5) {
|
||||
blink = !blink;
|
||||
blinkTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::render(Minecraft* minecraft, int xm, int ym) {
|
||||
// textbox like in beta 1.7.3
|
||||
// change appearance when focused so the user can tell it's active
|
||||
// active background darker gray with a subtle border
|
||||
uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0;
|
||||
uint32_t borderColor = focused ? 0xff000000 : 0xff000000;
|
||||
fill(x, y, x + width, y + height, bgColor);
|
||||
fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
glScissor(
|
||||
Gui::GuiScale * (x + 2),
|
||||
minecraft->height - Gui::GuiScale * (y + height - 2),
|
||||
Gui::GuiScale * (width - 2),
|
||||
Gui::GuiScale * (height - 2)
|
||||
);
|
||||
|
||||
int _y = y + (height - Font::DefaultLineHeight) / 2;
|
||||
|
||||
if (text.empty() && !focused) {
|
||||
drawString(minecraft->font, hint, x + 2, _y, 0xff5e5e5e);
|
||||
}
|
||||
|
||||
if (focused && blink) text.push_back('_');
|
||||
|
||||
drawString(minecraft->font, text, x + 2, _y, 0xffffffff);
|
||||
|
||||
if (focused && blink) text.pop_back();
|
||||
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElement.h"
|
||||
#include "../../Options.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "GuiElement.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include "TextOption.h"
|
||||
#include <client/Minecraft.h>
|
||||
#include "TextOption.hpp"
|
||||
#include <client/Minecraft.hpp>
|
||||
|
||||
TextOption::TextOption(Minecraft* minecraft, OptionId optId)
|
||||
: TextBox((int)optId, minecraft->options.getOpt(optId)->getStringId())
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include "TextBox.h"
|
||||
#include <client/Options.h>
|
||||
#include "TextBox.hpp"
|
||||
#include <client/Options.hpp>
|
||||
|
||||
class TextOption : public TextBox {
|
||||
public:
|
||||
Loading…
Add table
Add a link
Reference in a new issue