mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-20 06:53:30 +00:00
the whole game
This commit is contained in:
218
src/client/gui/components/Button.cpp
Executable file
218
src/client/gui/components/Button.cpp
Executable file
@@ -0,0 +1,218 @@
|
||||
#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)) : false;
|
||||
}
|
||||
|
||||
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) : false);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
80
src/client/gui/components/Button.h
Executable file
80
src/client/gui/components/Button.h
Executable file
@@ -0,0 +1,80 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElement.h"
|
||||
#include "../../Options.h"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
|
||||
class Button: public GuiElement
|
||||
{
|
||||
public:
|
||||
Button(int id, const std::string& msg);
|
||||
Button(int id, int x, int y, const std::string& msg);
|
||||
Button(int id, int x, int y, int w, int h, const std::string& msg);
|
||||
virtual ~Button() {}
|
||||
virtual void render(Minecraft* minecraft, int xm, int ym);
|
||||
|
||||
virtual bool clicked(Minecraft* minecraft, int mx, int my);
|
||||
virtual void released(int mx, int my);
|
||||
virtual void setPressed();
|
||||
|
||||
bool isInside(int xm, int ym);
|
||||
protected:
|
||||
virtual int getYImage(bool hovered);
|
||||
virtual void renderBg(Minecraft* minecraft, int xm, int ym);
|
||||
|
||||
virtual void renderFace(Minecraft* minecraft, int xm, int ym);
|
||||
bool hovered(Minecraft* minecraft, int xm, int ym);
|
||||
public:
|
||||
std::string msg;
|
||||
int id;
|
||||
|
||||
bool selected;
|
||||
protected:
|
||||
bool _currentlyDown;
|
||||
};
|
||||
|
||||
// @note: A bit backwards, but this is a button that
|
||||
// only reacts to clicks, but isn't rendered.
|
||||
class BlankButton: public Button
|
||||
{
|
||||
typedef Button super;
|
||||
public:
|
||||
BlankButton(int id);
|
||||
BlankButton(int id, int x, int y, int w, int h);
|
||||
};
|
||||
|
||||
|
||||
namespace Touch {
|
||||
class TButton: public Button
|
||||
{
|
||||
typedef Button super;
|
||||
public:
|
||||
TButton(int id, const std::string& msg);
|
||||
TButton(int id, int x, int y, const std::string& msg);
|
||||
TButton(int id, int x, int y, int w, int h, const std::string& msg);
|
||||
protected:
|
||||
virtual void renderBg(Minecraft* minecraft, int xm, int ym);
|
||||
};
|
||||
|
||||
// "Header" in Touchscreen mode
|
||||
class THeader: public Button {
|
||||
typedef Button super;
|
||||
public:
|
||||
THeader(int id, const std::string& msg);
|
||||
THeader(int id, int x, int y, const std::string& msg);
|
||||
THeader(int id, int x, int y, int w, int h, const std::string& msg);
|
||||
protected:
|
||||
virtual void renderBg(Minecraft* minecraft, int xm, int ym);
|
||||
void render( Minecraft* minecraft, int xm, int ym );
|
||||
public:
|
||||
int xText;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__*/
|
||||
1
src/client/gui/components/GButton.cpp
Executable file
1
src/client/gui/components/GButton.cpp
Executable file
@@ -0,0 +1 @@
|
||||
#include "GuiElement.h"
|
||||
55
src/client/gui/components/GButton.h
Executable file
55
src/client/gui/components/GButton.h
Executable file
@@ -0,0 +1,55 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI__GButton_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI__GButton_H__
|
||||
#include "Button.h"
|
||||
|
||||
class GButton: public Button {
|
||||
typedef Button super;
|
||||
public:
|
||||
static const int LayerDefault = 1;
|
||||
static const int LayerSelected = 2;
|
||||
static const int LayerMax = 4;
|
||||
|
||||
GButton(int id)
|
||||
: super(id, "")
|
||||
{}
|
||||
~GButton() {
|
||||
for (unsigned int i = 0; i < layers.size(); ++i) {
|
||||
delete layers[i].first;
|
||||
}
|
||||
}
|
||||
|
||||
void addElement(int layerId, GuiElement* e) {
|
||||
if (!e || layerId < 0 || layerId >= LayerMax) {
|
||||
LOGE("Error @ GButton::element : Trying to add element %p at layer: %d\n", e, layerId);
|
||||
return;
|
||||
}
|
||||
layers.push_back(std::make_pair(e, layerId));
|
||||
}
|
||||
|
||||
void render( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
if (!visible) return;
|
||||
|
||||
bool isHovered = minecraft->isTouchscreen()?
|
||||
(_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height): false;
|
||||
|
||||
int layer = isHovered? LayerSelected : LayerDefault;
|
||||
if (layer < 0) return;
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.addOffset((float)x, (float)y, 0);
|
||||
|
||||
for (unsigned int i = 0; i < layers.size(); ++i) {
|
||||
if ((layers[i].second & layer) != 0)
|
||||
layers[i].first->render(minecraft, 0, 0);
|
||||
}
|
||||
|
||||
t.addOffset((float)-x, (float)-y, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::pair<GuiElement*, int> > layers;
|
||||
};
|
||||
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI__GButton_H__*/
|
||||
20
src/client/gui/components/GuiElement.cpp
Executable file
20
src/client/gui/components/GuiElement.cpp
Executable file
@@ -0,0 +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;
|
||||
}
|
||||
27
src/client/gui/components/GuiElement.h
Executable file
27
src/client/gui/components/GuiElement.h
Executable file
@@ -0,0 +1,27 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiElement_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI__GuiElement_H__
|
||||
#include "../GuiComponent.h"
|
||||
|
||||
class Tesselator;
|
||||
class Minecraft;
|
||||
|
||||
class GuiElement : public GuiComponent {
|
||||
public:
|
||||
GuiElement(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24);
|
||||
virtual ~GuiElement() {}
|
||||
virtual void tick(Minecraft* minecraft) {}
|
||||
virtual void render(Minecraft* minecraft, int xm, int ym) { }
|
||||
virtual void setupPositions() {}
|
||||
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {}
|
||||
virtual void mouseReleased(Minecraft* minecraft, int x, int y, int buttonNum) {}
|
||||
virtual bool pointInside(int x, int y);
|
||||
void setVisible(bool visible);
|
||||
bool active;
|
||||
bool visible;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiElement_H__*/
|
||||
54
src/client/gui/components/GuiElementContainer.cpp
Executable file
54
src/client/gui/components/GuiElementContainer.cpp
Executable file
@@ -0,0 +1,54 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
27
src/client/gui/components/GuiElementContainer.h
Executable file
27
src/client/gui/components/GuiElementContainer.h
Executable file
@@ -0,0 +1,27 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__
|
||||
#include "GuiElement.h"
|
||||
#include <vector>
|
||||
class Tesselator;
|
||||
class Minecraft;
|
||||
|
||||
class GuiElementContainer : public GuiElement {
|
||||
public:
|
||||
GuiElementContainer(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24);
|
||||
virtual ~GuiElementContainer();
|
||||
virtual void render(Minecraft* minecraft, int xm, int ym);
|
||||
virtual void setupPositions();
|
||||
virtual void addChild(GuiElement* element);
|
||||
virtual void removeChild(GuiElement* element);
|
||||
|
||||
virtual void tick( Minecraft* minecraft );
|
||||
|
||||
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
|
||||
|
||||
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum );
|
||||
|
||||
protected:
|
||||
std::vector<GuiElement*> children;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__*/
|
||||
160
src/client/gui/components/ImageButton.cpp
Executable file
160
src/client/gui/components/ImageButton.cpp
Executable file
@@ -0,0 +1,160 @@
|
||||
#include "ImageButton.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../platform/log.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.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) : false);
|
||||
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(const Options::Option* option)
|
||||
: _option(option),
|
||||
_isFloat(false),
|
||||
super(ButtonId, "")
|
||||
{
|
||||
}
|
||||
|
||||
OptionButton::OptionButton(const Options::Option* option, float onValue, float offValue)
|
||||
: _option(option),
|
||||
_isFloat(true),
|
||||
_onValue(onValue),
|
||||
_offValue(offValue),
|
||||
super(ButtonId, "")
|
||||
{
|
||||
}
|
||||
|
||||
bool OptionButton::isSecondImage(bool hovered) {
|
||||
return _secondImage;
|
||||
}
|
||||
|
||||
void OptionButton::toggle(Options* options) {
|
||||
if (_isFloat) {
|
||||
options->set(_option, (Mth::abs(_current - _onValue) < 0.01f) ? _offValue : _onValue);
|
||||
} else {
|
||||
options->toggle(_option, 1);
|
||||
}
|
||||
// Update graphics here
|
||||
updateImage(options);
|
||||
}
|
||||
|
||||
void OptionButton::updateImage(Options* options) {
|
||||
if (_isFloat) {
|
||||
_current = options->getProgressValue(_option);
|
||||
_secondImage = Mth::abs(_current - _onValue) < 0.01f;
|
||||
} else {
|
||||
_secondImage = options->getBooleanValue(_option);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if(clicked(minecraft, x, y)) {
|
||||
toggle(&minecraft->options);
|
||||
}
|
||||
}
|
||||
}
|
||||
105
src/client/gui/components/ImageButton.h
Executable file
105
src/client/gui/components/ImageButton.h
Executable file
@@ -0,0 +1,105 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__
|
||||
|
||||
#include "Button.h"
|
||||
|
||||
typedef struct IntRectangle {
|
||||
IntRectangle()
|
||||
: x(0),
|
||||
y(0),
|
||||
w(1),
|
||||
h(1)
|
||||
{}
|
||||
IntRectangle(int x, int y, int w, int h)
|
||||
: x(x),
|
||||
y(y),
|
||||
w(w),
|
||||
h(h)
|
||||
{}
|
||||
|
||||
int x, y;
|
||||
int w, h;
|
||||
} IntRectangle;
|
||||
|
||||
typedef struct ImageDef {
|
||||
ImageDef()
|
||||
: hasSrc(false),
|
||||
x(0),
|
||||
y(0),
|
||||
width(16),
|
||||
height(16)
|
||||
{}
|
||||
|
||||
std::string name;
|
||||
int x;
|
||||
int y;
|
||||
float width;
|
||||
float height;
|
||||
|
||||
ImageDef& setSrc(const IntRectangle& srcRect) {
|
||||
hasSrc = true;
|
||||
src = srcRect;
|
||||
return *this;
|
||||
}
|
||||
IntRectangle* getSrc() {
|
||||
return hasSrc? &src : NULL;
|
||||
}
|
||||
protected:
|
||||
IntRectangle src;
|
||||
bool hasSrc;
|
||||
} ImageDef;
|
||||
|
||||
|
||||
class ImageButton: public Button
|
||||
{
|
||||
typedef Button super;
|
||||
public:
|
||||
ImageButton(int id, const std::string& msg);
|
||||
ImageButton(int id, const std::string& msg, const ImageDef& imageDef);
|
||||
void setImageDef(const ImageDef& imageDef, bool setButtonSize);
|
||||
|
||||
void render(Minecraft* minecraft, int xm, int ym);
|
||||
void renderBg(Minecraft* minecraft, int xm, int ym) {}
|
||||
|
||||
protected:
|
||||
virtual void setupDefault();
|
||||
virtual bool isSecondImage(bool hovered) { return hovered; }
|
||||
|
||||
ImageDef _imageDef;
|
||||
public:
|
||||
bool scaleWhenPressed;
|
||||
};
|
||||
|
||||
//
|
||||
// A toggleable Button
|
||||
//
|
||||
class OptionButton: public ImageButton
|
||||
{
|
||||
typedef ImageButton super;
|
||||
public:
|
||||
OptionButton(const Options::Option* option);
|
||||
OptionButton(const Options::Option* option, float onValue, float offValue);
|
||||
|
||||
void toggle(Options* options);
|
||||
void updateImage(Options* options);
|
||||
|
||||
static const int ButtonId = 9999999;
|
||||
protected:
|
||||
bool isSecondImage(bool hovered);
|
||||
|
||||
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
|
||||
|
||||
private:
|
||||
|
||||
const Options::Option* _option;
|
||||
bool _secondImage;
|
||||
|
||||
// If not float, it's considered to be a boolean value
|
||||
bool _isFloat;
|
||||
float _onValue;
|
||||
float _offValue;
|
||||
float _current;
|
||||
};
|
||||
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__*/
|
||||
206
src/client/gui/components/InventoryPane.cpp
Executable file
206
src/client/gui/components/InventoryPane.cpp
Executable file
@@ -0,0 +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;
|
||||
}
|
||||
|
||||
}
|
||||
62
src/client/gui/components/InventoryPane.h
Executable file
62
src/client/gui/components/InventoryPane.h
Executable file
@@ -0,0 +1,62 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__
|
||||
|
||||
#include "ScrollingPane.h"
|
||||
#include "ImageButton.h"
|
||||
|
||||
class Minecraft;
|
||||
class ItemInstance;
|
||||
class Font;
|
||||
class IArea;
|
||||
|
||||
namespace Touch {
|
||||
|
||||
class IInventoryPaneCallback;
|
||||
|
||||
class InventoryPane: public ScrollingPane
|
||||
{
|
||||
typedef ScrollingPane super;
|
||||
public:
|
||||
InventoryPane(IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize);
|
||||
~InventoryPane();
|
||||
|
||||
void tick();
|
||||
void renderBatch( std::vector<GridItem>& item, float alpha );
|
||||
bool onSelect( int gridId, bool selected );
|
||||
void drawScrollBar( ScrollBar& hScroll );
|
||||
|
||||
void setRenderDecorations(bool value);
|
||||
|
||||
IntRectangle rect;
|
||||
int paneWidth;
|
||||
IArea* _clickArea;
|
||||
IInventoryPaneCallback* screen;
|
||||
Minecraft* mc;
|
||||
|
||||
int fillMarginX;
|
||||
int fillMarginY;
|
||||
|
||||
int markerType;
|
||||
int markerIndex;
|
||||
float markerShare;
|
||||
private:
|
||||
int lastItemIndex;
|
||||
int lastItemTicks;
|
||||
int BorderPixels;
|
||||
bool renderDecorations;
|
||||
|
||||
IntRectangle bg;
|
||||
};
|
||||
|
||||
class IInventoryPaneCallback
|
||||
{
|
||||
public:
|
||||
virtual ~IInventoryPaneCallback() {}
|
||||
virtual bool addItem(const InventoryPane* forPane, int index) = 0;
|
||||
virtual bool isAllowed( int slot ) = 0;
|
||||
virtual std::vector<const ItemInstance*> getItems(const InventoryPane* forPane) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__*/
|
||||
148
src/client/gui/components/ItemPane.cpp
Executable file
148
src/client/gui/components/ItemPane.cpp
Executable file
@@ -0,0 +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);
|
||||
}
|
||||
95
src/client/gui/components/ItemPane.h
Executable file
95
src/client/gui/components/ItemPane.h
Executable file
@@ -0,0 +1,95 @@
|
||||
#ifndef ITEMPANE_H__
|
||||
#define ITEMPANE_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ScrollingPane.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
|
||||
class Font;
|
||||
class Textures;
|
||||
class NinePatchLayer;
|
||||
class Recipe;
|
||||
class ItemPane;
|
||||
|
||||
class CItem
|
||||
{
|
||||
public:
|
||||
CItem(const ItemInstance& ins, Recipe* recipe, const std::string& text)
|
||||
: item(ins),
|
||||
recipe(recipe),
|
||||
text(text),
|
||||
sortText(text),
|
||||
//maxBuildCount(0),
|
||||
numBuilt(0),
|
||||
inventoryCount(0),
|
||||
_canCraft(false)
|
||||
{
|
||||
}
|
||||
|
||||
typedef struct ReqItem {
|
||||
ReqItem() {}
|
||||
ReqItem(const ItemInstance& needItem, int has)
|
||||
: item(needItem), has(has) {}
|
||||
ItemInstance item;
|
||||
int has;
|
||||
bool enough() { return has >= item.count; }
|
||||
} ReqItem;
|
||||
|
||||
bool canCraft() {
|
||||
return _canCraft;// || maxBuildCount > 0;
|
||||
}
|
||||
void setCanCraft(bool status) {
|
||||
_canCraft = status;
|
||||
}
|
||||
|
||||
ItemInstance item;
|
||||
Recipe* recipe;
|
||||
std::string text;
|
||||
std::string sortText;
|
||||
//int maxBuildCount;
|
||||
int numBuilt;
|
||||
int inventoryCount;
|
||||
std::vector<ReqItem> neededItems;
|
||||
private:
|
||||
bool _canCraft;
|
||||
};
|
||||
|
||||
class IItemPaneCallback
|
||||
{
|
||||
public:
|
||||
virtual ~IItemPaneCallback() {}
|
||||
virtual void onItemSelected(const ItemPane* forPane, int index) = 0;
|
||||
virtual const std::vector<CItem*>& getItems(const ItemPane* forPane) = 0;
|
||||
};
|
||||
|
||||
class ItemPane: public ScrollingPane
|
||||
{
|
||||
typedef ScrollingPane super;
|
||||
public:
|
||||
ItemPane( IItemPaneCallback* screen,
|
||||
Textures* textures,
|
||||
const IntRectangle& rect,
|
||||
int numItems,
|
||||
int guiHeight,
|
||||
int physicalScreenHeight,
|
||||
bool isVertical = true);
|
||||
~ItemPane();
|
||||
|
||||
void renderBatch( std::vector<GridItem>& item, float alpha );
|
||||
bool onSelect( int gridId, bool selected );
|
||||
void drawScrollBar( ScrollBar& hScroll );
|
||||
//void setSize()
|
||||
|
||||
Font* f;
|
||||
Textures* textures;
|
||||
IItemPaneCallback* screen;
|
||||
|
||||
int physicalScreenHeight; // Needed for glScissor
|
||||
bool isVertical;
|
||||
|
||||
NinePatchLayer* guiSlotItem;
|
||||
NinePatchLayer* guiSlotItemSelected;
|
||||
};
|
||||
|
||||
#endif /*ITEMPANE_H__*/
|
||||
104
src/client/gui/components/LargeImageButton.cpp
Executable file
104
src/client/gui/components/LargeImageButton.cpp
Executable file
@@ -0,0 +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) : false);
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/client/gui/components/LargeImageButton.h
Executable file
21
src/client/gui/components/LargeImageButton.h
Executable file
@@ -0,0 +1,21 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__
|
||||
|
||||
#include "ImageButton.h"
|
||||
|
||||
class LargeImageButton: public ImageButton
|
||||
{
|
||||
typedef ImageButton super;
|
||||
public:
|
||||
LargeImageButton(int id, const std::string& msg);
|
||||
LargeImageButton(int id, const std::string& msg, ImageDef& imageDef);
|
||||
|
||||
void render(Minecraft* minecraft, int xm, int ym);
|
||||
|
||||
private:
|
||||
void setupDefault();
|
||||
|
||||
float _buttonScale;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__*/
|
||||
141
src/client/gui/components/NinePatch.cpp
Executable file
141
src/client/gui/components/NinePatch.cpp
Executable file
@@ -0,0 +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);
|
||||
}
|
||||
78
src/client/gui/components/NinePatch.h
Executable file
78
src/client/gui/components/NinePatch.h
Executable file
@@ -0,0 +1,78 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI__NinePatch_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI__NinePatch_H__
|
||||
|
||||
#include "ImageButton.h"
|
||||
#include "../../renderer/TextureData.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
|
||||
class Tesselator;
|
||||
|
||||
class NinePatchDescription {
|
||||
public:
|
||||
NinePatchDescription& transformUVForImage(const TextureData& d);
|
||||
NinePatchDescription& transformUVForImageSize(int w, int h);
|
||||
|
||||
float u0, u1, u2, u3;
|
||||
float v0, v1, v2, v3;
|
||||
float w, e, n, s;
|
||||
|
||||
static NinePatchDescription createSymmetrical(int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt);
|
||||
private:
|
||||
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);
|
||||
|
||||
int imgW;
|
||||
int imgH;
|
||||
};
|
||||
|
||||
class NinePatchLayer: public GuiElement
|
||||
{
|
||||
struct CachedQuad;
|
||||
public:
|
||||
NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w = 32, float h = 32);
|
||||
virtual ~NinePatchLayer() {};
|
||||
void setSize(float w, float h);
|
||||
|
||||
void draw(Tesselator& t, float x, float y);
|
||||
|
||||
NinePatchLayer* exclude(int excludeId);
|
||||
NinePatchLayer* setExcluded(int exludeBits);
|
||||
|
||||
float getWidth() { return w; }
|
||||
float getHeight() { return h; }
|
||||
|
||||
private:
|
||||
void buildQuad(int qid);
|
||||
void getPatchInfo(int xc, int yc, float& x0, float& x1, float& y0, float& y1);
|
||||
|
||||
void d(Tesselator& t, const CachedQuad& q);
|
||||
|
||||
float w, h;
|
||||
NinePatchDescription desc;
|
||||
std::string imageName;
|
||||
Textures* textures;
|
||||
int excluded;
|
||||
|
||||
typedef struct CachedQuad {
|
||||
float x0, x1, y0, y1, z;
|
||||
float u0, u1, v0, v1;
|
||||
} CachedQuad;
|
||||
CachedQuad quads[9];
|
||||
};
|
||||
|
||||
class NinePatchFactory {
|
||||
public:
|
||||
NinePatchFactory(Textures* textures, const std::string& imageName );
|
||||
|
||||
NinePatchLayer* createSymmetrical(const IntRectangle& src, int xCutAt, int yCutAt, float w = 32.0f, float h = 32.0f);
|
||||
|
||||
private:
|
||||
Textures* textures;
|
||||
std::string imageName;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI__NinePatch_H__*/
|
||||
68
src/client/gui/components/OptionsGroup.cpp
Executable file
68
src/client/gui/components/OptionsGroup.cpp
Executable file
@@ -0,0 +1,68 @@
|
||||
#include "OptionsGroup.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "ImageButton.h"
|
||||
#include "OptionsItem.h"
|
||||
#include "Slider.h"
|
||||
#include "../../../locale/I18n.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 + 10;
|
||||
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 ) {
|
||||
minecraft->font->draw(label, (float)x + 2, (float)y, 0xffffffff, false);
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
OptionsGroup& OptionsGroup::addOptionItem( const Options::Option* option, Minecraft* minecraft ) {
|
||||
if(option->isBoolean())
|
||||
createToggle(option, minecraft);
|
||||
else if(option->isProgress())
|
||||
createProgressSlider(option, minecraft);
|
||||
else if(option->isInt())
|
||||
createStepSlider(option, minecraft);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void OptionsGroup::createToggle( const Options::Option* option, 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(option);
|
||||
element->setImageDef(def, true);
|
||||
std::string itemLabel = I18n::get(option->getCaptionId());
|
||||
OptionsItem* item = new OptionsItem(itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createProgressSlider( const Options::Option* option, Minecraft* minecraft ) {
|
||||
Slider* element = new Slider(minecraft,
|
||||
option,
|
||||
minecraft->options.getProgrssMin(option),
|
||||
minecraft->options.getProgrssMax(option));
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
OptionsItem* item = new OptionsItem(label, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createStepSlider( const Options::Option* option, Minecraft* minecraft ) {
|
||||
|
||||
}
|
||||
27
src/client/gui/components/OptionsGroup.h
Executable file
27
src/client/gui/components/OptionsGroup.h
Executable file
@@ -0,0 +1,27 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElementContainer.h"
|
||||
#include "../../Options.h"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
|
||||
class OptionsGroup: public GuiElementContainer {
|
||||
typedef GuiElementContainer super;
|
||||
public:
|
||||
OptionsGroup(std::string labelID);
|
||||
virtual void setupPositions();
|
||||
virtual void render(Minecraft* minecraft, int xm, int ym);
|
||||
virtual OptionsGroup& addOptionItem(const Options::Option* option, Minecraft* minecraft);
|
||||
protected:
|
||||
virtual void createToggle(const Options::Option* option, Minecraft* minecraft);
|
||||
virtual void createProgressSlider(const Options::Option* option, Minecraft* minecraft);
|
||||
virtual void createStepSlider(const Options::Option* option, Minecraft* minecraft);
|
||||
std::string label;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__*/
|
||||
24
src/client/gui/components/OptionsItem.cpp
Executable file
24
src/client/gui/components/OptionsItem.cpp
Executable file
@@ -0,0 +1,24 @@
|
||||
#include "OptionsItem.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../util/Mth.h"
|
||||
OptionsItem::OptionsItem( std::string label, GuiElement* element )
|
||||
: GuiElementContainer(false, true, 0, 0, 24, 12),
|
||||
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;
|
||||
minecraft->font->draw(label, (float)x, (float)y + yOffset, 0x909090, false);
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
26
src/client/gui/components/OptionsItem.h
Executable file
26
src/client/gui/components/OptionsItem.h
Executable file
@@ -0,0 +1,26 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "GuiElementContainer.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../../client/Options.h"
|
||||
class Font;
|
||||
class Textures;
|
||||
class NinePatchLayer;
|
||||
class ItemPane;
|
||||
|
||||
class OptionsItem: public GuiElementContainer
|
||||
{
|
||||
typedef GuiElementContainer super;
|
||||
public:
|
||||
OptionsItem(std::string label, GuiElement* element);
|
||||
virtual void render(Minecraft* minecraft, int xm, int ym);
|
||||
void setupPositions();
|
||||
|
||||
private:
|
||||
std::string label;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__*/
|
||||
64
src/client/gui/components/OptionsPane.cpp
Executable file
64
src/client/gui/components/OptionsPane.cpp
Executable file
@@ -0,0 +1,64 @@
|
||||
#include "OptionsPane.h"
|
||||
#include "OptionsGroup.h"
|
||||
#include "OptionsItem.h"
|
||||
#include "ImageButton.h"
|
||||
#include "Slider.h"
|
||||
#include "../../Minecraft.h"
|
||||
|
||||
OptionsPane::OptionsPane() {
|
||||
|
||||
}
|
||||
|
||||
void OptionsPane::setupPositions() {
|
||||
int currentHeight = y + 1;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it ) {
|
||||
(*it)->width = width;
|
||||
(*it)->y = currentHeight;
|
||||
(*it)->x = x;
|
||||
currentHeight += (*it)->height + 1;
|
||||
}
|
||||
height = currentHeight;
|
||||
super::setupPositions();
|
||||
}
|
||||
|
||||
OptionsGroup& OptionsPane::createOptionsGroup( std::string label ) {
|
||||
OptionsGroup* newGroup = new OptionsGroup(label);
|
||||
children.push_back(newGroup);
|
||||
// create and return a new group index
|
||||
return *newGroup;
|
||||
}
|
||||
|
||||
void OptionsPane::createToggle( unsigned int group, std::string label, const Options::Option* option ) {
|
||||
// if(group > children.size()) return;
|
||||
// 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(option);
|
||||
// element->setImageDef(def, true);
|
||||
// OptionsItem* item = new OptionsItem(label, element);
|
||||
// ((OptionsGroup*)children[group])->addChild(item);
|
||||
// setupPositions();
|
||||
}
|
||||
|
||||
void OptionsPane::createProgressSlider( Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, float progressMin/*=1.0f*/, float progressMax/*=1.0f */ ) {
|
||||
// if(group > children.size()) return;
|
||||
// Slider* element = new Slider(minecraft, option, progressMin, progressMax);
|
||||
// element->width = 100;
|
||||
// element->height = 20;
|
||||
// OptionsItem* item = new OptionsItem(label, element);
|
||||
// ((OptionsGroup*)children[group])->addChild(item);
|
||||
// setupPositions();
|
||||
}
|
||||
|
||||
void OptionsPane::createStepSlider( Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, const std::vector<int>& stepVec ) {
|
||||
// if(group > children.size()) return;
|
||||
// Slider* element = new Slider(minecraft, option, stepVec);
|
||||
// element->width = 100;
|
||||
// element->height = 20;
|
||||
// sliders.push_back(element);
|
||||
// OptionsItem* item = new OptionsItem(label, element);
|
||||
// ((OptionsGroup*)children[group])->addChild(item);
|
||||
// setupPositions();
|
||||
}
|
||||
30
src/client/gui/components/OptionsPane.h
Executable file
30
src/client/gui/components/OptionsPane.h
Executable file
@@ -0,0 +1,30 @@
|
||||
#ifndef ITEMPANE_H__
|
||||
#define ITEMPANE_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "GuiElementContainer.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../../client/Options.h"
|
||||
class Font;
|
||||
class Textures;
|
||||
class NinePatchLayer;
|
||||
class ItemPane;
|
||||
class OptionButton;
|
||||
class Button;
|
||||
class OptionsGroup;
|
||||
class Slider;
|
||||
class Minecraft;
|
||||
class OptionsPane: public GuiElementContainer
|
||||
{
|
||||
typedef GuiElementContainer super;
|
||||
public:
|
||||
OptionsPane();
|
||||
OptionsGroup& createOptionsGroup( std::string label );
|
||||
void createToggle( unsigned int group, std::string label, const Options::Option* option );
|
||||
void createProgressSlider(Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, float progressMin=1.0f, float progressMax=1.0f );
|
||||
void createStepSlider(Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, const std::vector<int>& stepVec );
|
||||
void setupPositions();
|
||||
};
|
||||
|
||||
#endif /*ITEMPANE_H__*/
|
||||
299
src/client/gui/components/RolledSelectionListH.cpp
Executable file
299
src/client/gui/components/RolledSelectionListH.cpp
Executable file
@@ -0,0 +1,299 @@
|
||||
#include "RolledSelectionListH.h"
|
||||
#include "../../Minecraft.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"
|
||||
|
||||
|
||||
RolledSelectionListH::RolledSelectionListH( Minecraft* 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()
|
||||
{
|
||||
}
|
||||
82
src/client/gui/components/RolledSelectionListH.h
Executable file
82
src/client/gui/components/RolledSelectionListH.h
Executable file
@@ -0,0 +1,82 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
class Minecraft;
|
||||
class Tesselator;
|
||||
|
||||
|
||||
class RolledSelectionListH : public GuiComponent
|
||||
{
|
||||
static const int NO_DRAG = -1;
|
||||
static const int DRAG_OUTSIDE = -2;
|
||||
static const int DRAG_NORMAL = 0;
|
||||
public:
|
||||
RolledSelectionListH(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth);
|
||||
|
||||
virtual int getItemAtPosition(int x, int y);
|
||||
|
||||
virtual bool capXPosition();
|
||||
|
||||
virtual void tick();
|
||||
virtual void render(int xm, int ym, float a);
|
||||
virtual void renderHoleBackground(/*float x0, float x1,*/ float y0, float y1, int a0, int a1);
|
||||
virtual void setRenderSelection(bool _renderSelection);
|
||||
virtual void setComponentSelected(bool selected);
|
||||
protected:
|
||||
void setRenderHeader(bool _renderHeader, int _headerHeight);
|
||||
|
||||
virtual int getNumberOfItems() = 0;
|
||||
|
||||
virtual void selectStart(int item, int localX, int localY) {}
|
||||
virtual void selectCancel() {}
|
||||
virtual void selectItem(int item, bool doubleClick) = 0;
|
||||
virtual bool isSelectedItem(int item) = 0;
|
||||
|
||||
virtual int getMaxPosition();
|
||||
virtual float getPos(float alpha);
|
||||
virtual void touched();
|
||||
|
||||
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0;
|
||||
virtual void renderHeader(int x, int y, Tesselator& t) {}
|
||||
virtual void renderBackground() = 0;
|
||||
virtual void renderDecorations(int mouseX, int mouseY) {}
|
||||
|
||||
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
|
||||
int getItemAtXPositionRaw(int x);
|
||||
protected:
|
||||
Minecraft* minecraft;
|
||||
|
||||
float x0;
|
||||
float x1;
|
||||
int itemWidth;
|
||||
int width;
|
||||
int height;
|
||||
//private:
|
||||
float y0;
|
||||
float y1;
|
||||
|
||||
int dragState;
|
||||
float xDrag;
|
||||
float xo;
|
||||
float xoo;
|
||||
float xInertia;
|
||||
float _xinertia;
|
||||
|
||||
int selectionX;
|
||||
bool renderSelection;
|
||||
bool _componentSelected;
|
||||
|
||||
bool _renderTopBorder;
|
||||
bool _renderBottomBorder;
|
||||
|
||||
private:
|
||||
int headerWidth;
|
||||
bool doRenderHeader;
|
||||
long lastSelectionTime;
|
||||
int lastSelection;
|
||||
|
||||
float _lastxoo;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__*/
|
||||
352
src/client/gui/components/RolledSelectionListV.cpp
Executable file
352
src/client/gui/components/RolledSelectionListV.cpp
Executable file
@@ -0,0 +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);
|
||||
}
|
||||
94
src/client/gui/components/RolledSelectionListV.h
Executable file
94
src/client/gui/components/RolledSelectionListV.h
Executable file
@@ -0,0 +1,94 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
class Minecraft;
|
||||
class Tesselator;
|
||||
|
||||
|
||||
class RolledSelectionListV : public GuiComponent
|
||||
{
|
||||
static const int NO_DRAG = -1;
|
||||
static const int DRAG_OUTSIDE = -2;
|
||||
static const int DRAG_NORMAL = 0;
|
||||
public:
|
||||
RolledSelectionListV(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemHeight);
|
||||
|
||||
virtual int getItemAtPosition(int x, int y);
|
||||
|
||||
virtual bool capYPosition();
|
||||
|
||||
virtual void tick();
|
||||
virtual void render(int xm, int ym, float a);
|
||||
virtual void renderHoleBackground(/*float x0, float x1,*/ float y0, float y1, int a0, int a1);
|
||||
virtual void setRenderSelection(bool _renderSelection);
|
||||
virtual void setComponentSelected(bool selected);
|
||||
protected:
|
||||
void setRenderHeader(bool _renderHeader, int _headerHeight);
|
||||
|
||||
virtual int getNumberOfItems() = 0;
|
||||
|
||||
virtual void selectStart(int item) {}
|
||||
virtual void selectCancel() {}
|
||||
virtual void selectItem(int item, bool doubleClick) = 0;
|
||||
virtual bool isSelectedItem(int item) = 0;
|
||||
|
||||
virtual int getMaxPosition();
|
||||
virtual float getPos(float alpha);
|
||||
virtual void touched();
|
||||
|
||||
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0;
|
||||
virtual void renderHeader(int x, int y, Tesselator& t) {}
|
||||
virtual void renderBackground() = 0;
|
||||
virtual void renderForeground() {}
|
||||
virtual void renderDecorations(int mouseX, int mouseY) {}
|
||||
|
||||
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
|
||||
virtual int convertSelection(int item, int xm, int ym) { return item; }
|
||||
|
||||
int getItemAtYPositionRaw(int y);
|
||||
void evaluate(int xm, int ym);
|
||||
virtual void onPreRender();
|
||||
virtual void onPostRender();
|
||||
void renderDirtBackground();
|
||||
protected:
|
||||
Minecraft* minecraft;
|
||||
|
||||
float x0;
|
||||
float x1;
|
||||
int itemHeight;
|
||||
int width;
|
||||
int height;
|
||||
//private:
|
||||
float y0;
|
||||
float y1;
|
||||
|
||||
int dragState;
|
||||
float yDrag;
|
||||
float yo;
|
||||
float yoo;
|
||||
float yInertia;
|
||||
float _yinertia;
|
||||
|
||||
int selectionY;
|
||||
bool renderSelection;
|
||||
bool _componentSelected;
|
||||
|
||||
bool _renderDirtBackground;
|
||||
bool _renderTopBorder;
|
||||
bool _renderBottomBorder;
|
||||
|
||||
int _lastxm;
|
||||
int _lastym;
|
||||
private:
|
||||
int headerHeight;
|
||||
bool doRenderHeader;
|
||||
long lastSelectionTime;
|
||||
int lastSelection;
|
||||
|
||||
float _lastyoo;
|
||||
|
||||
float _stickPixels;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__*/
|
||||
296
src/client/gui/components/ScrolledSelectionList.cpp
Executable file
296
src/client/gui/components/ScrolledSelectionList.cpp
Executable file
@@ -0,0 +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();
|
||||
}
|
||||
69
src/client/gui/components/ScrolledSelectionList.h
Executable file
69
src/client/gui/components/ScrolledSelectionList.h
Executable file
@@ -0,0 +1,69 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
class Minecraft;
|
||||
class Tesselator;
|
||||
|
||||
|
||||
class ScrolledSelectionList : public GuiComponent
|
||||
{
|
||||
static const int NO_DRAG = -1;
|
||||
static const int DRAG_OUTSIDE = -2;
|
||||
static const int DRAG_NORMAL = 0;
|
||||
static const int DRAG_SKIP = 1; // special case to fix android jump bug
|
||||
public:
|
||||
ScrolledSelectionList(Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight);
|
||||
|
||||
virtual void setRenderSelection(bool _renderSelection);
|
||||
protected:
|
||||
void setRenderHeader(bool _renderHeader, int _headerHeight);
|
||||
|
||||
virtual int getNumberOfItems() = 0;
|
||||
|
||||
virtual void selectItem(int item, bool doubleClick) = 0;
|
||||
virtual bool isSelectedItem(int item) = 0;
|
||||
|
||||
virtual int getMaxPosition();
|
||||
|
||||
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0;
|
||||
virtual void renderHeader(int x, int y, Tesselator& t) {}
|
||||
virtual void renderBackground() = 0;
|
||||
virtual void renderDecorations(int mouseX, int mouseY) {}
|
||||
|
||||
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
|
||||
public:
|
||||
virtual int getItemAtPosition(int x, int y);
|
||||
|
||||
virtual void capYPosition();
|
||||
|
||||
virtual void render(int xm, int ym, float a);
|
||||
virtual void renderHoleBackground(float y0, float y1, int a0, int a1);
|
||||
void renderDirtBackground();
|
||||
protected:
|
||||
Minecraft* minecraft;
|
||||
|
||||
float y0;
|
||||
float y1;
|
||||
int itemHeight;
|
||||
private:
|
||||
int width;
|
||||
int height;
|
||||
float x1;
|
||||
float x0;
|
||||
|
||||
int ignoreY; // new attempt to fix android jump bug
|
||||
int dragState;
|
||||
float yDrag;
|
||||
float yo;
|
||||
float yInertia;
|
||||
|
||||
int selectionY;
|
||||
long lastSelectionTime;
|
||||
|
||||
bool renderSelection;
|
||||
bool doRenderHeader;
|
||||
int headerHeight;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__*/
|
||||
732
src/client/gui/components/ScrollingPane.cpp
Executable file
732
src/client/gui/components/ScrollingPane.cpp
Executable file
@@ -0,0 +1,732 @@
|
||||
#include "ScrollingPane.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../../SharedConstants.h"
|
||||
|
||||
#define STR(x) (x.toString().c_str())
|
||||
|
||||
static const float kPenetrationDeceleration = 0.03f;
|
||||
static const float kPenetrationAcceleration = 0.08f;
|
||||
static const float kMaxTrackingTime = 100.0f;
|
||||
static const float kAcceleration = 15;
|
||||
static const float kMinVelocityForDecelerationWithPaging = 4 / 3.0f;
|
||||
static const float kMinVelocityForDeceleration = 1 / 3.0f;
|
||||
static const float kDesiredAnimationFrameRate = 1000.0f / 60;
|
||||
static const float kDecelerationFrictionFactor = 0.95f;
|
||||
static const float kMinimumVelocityToHideScrollIndicators = 0.05f;
|
||||
static const float kMinimumVelocity = 0.01f;
|
||||
static const float kMinimumTrackingForDrag = 5;
|
||||
static const float kMinIndicatorLength = 34.0f / 3;
|
||||
static const float PKScrollIndicatorEndSize = 3;
|
||||
static const float PKScrollIndicatorThickness = 7.0f /3;
|
||||
|
||||
ScrollingPane::ScrollingPane(
|
||||
int optionFlags,
|
||||
const IntRectangle& boundingBox,
|
||||
const IntRectangle& itemRect,
|
||||
int columns,
|
||||
int numItems,
|
||||
float screenScale /* = 1.0f */,
|
||||
const IntRectangle& itemBoundingRect /*= IntRectangle(0,0,0,0)*/ )
|
||||
: flags(optionFlags),
|
||||
bbox(boundingBox),
|
||||
size(boundingBox),
|
||||
area((float)bbox.x, (float)bbox.y, (float)(bbox.x + bbox.w), (float)(bbox.y + bbox.h)),
|
||||
bboxArea(area),
|
||||
itemRect(itemRect),
|
||||
numItems(numItems),
|
||||
screenScale(screenScale),
|
||||
invScreenScale(1.0f / screenScale),
|
||||
//hasItemBounding(),
|
||||
px(0), py(0), fpx(0), fpy(0),
|
||||
dx(0), dy(0),
|
||||
dragState(-1),
|
||||
dragLastDeltaTimeStamp(-1.0f),
|
||||
friction(0.95f),
|
||||
highlightTimer(-1),
|
||||
highlightStarted(-1),
|
||||
selectedId(-1),
|
||||
decelerating(false),
|
||||
tracking(false),
|
||||
dragging(false),
|
||||
pagingEnabled(false),
|
||||
_scrollEnabled(true),
|
||||
_timer(60),
|
||||
_doStepTimer(false),
|
||||
_wasDown(false),//Mouse::isButtonDown(MouseAction::ACTION_LEFT)),
|
||||
_lx(-9999), _ly(-9999)
|
||||
{
|
||||
if (itemBoundingRect.w > 0)
|
||||
itemBbox = itemBoundingRect;
|
||||
else
|
||||
itemBbox = itemRect;
|
||||
|
||||
this->columns = (columns>0)? columns : bbox.w / itemBbox.w;
|
||||
|
||||
if (this->columns <= 0) {
|
||||
LOGW("Columns are 0! Area width is smaller than item width. Setting columns to 1.\n");
|
||||
this->columns = 1;
|
||||
}
|
||||
//LOGI("%d, %d :: %d\n", bbox.w, itemBbox.w, this->columns);
|
||||
|
||||
rows = 1 + (numItems-1) / this->columns,
|
||||
|
||||
/*
|
||||
if (columns * itemBbox.w <= bbox.w) flags |= SF_LockX;
|
||||
if (rows * itemBbox.h <= bbox.h) flags |= SF_LockY;
|
||||
*/
|
||||
|
||||
dragDeltas.reserve(128);
|
||||
|
||||
te_moved = 0;
|
||||
te_ended = 1;
|
||||
|
||||
selected = new bool[numItems];
|
||||
for (int i = 0; i < numItems; ++i)
|
||||
selected[i] = false;
|
||||
|
||||
// Setup the scroll bars
|
||||
vScroll.w = vScroll.h = PKScrollIndicatorThickness;
|
||||
hScroll.w = hScroll.h = PKScrollIndicatorThickness;
|
||||
vScroll.x = bbox.x + bbox.w - vScroll.w;
|
||||
vScroll.y = 0;
|
||||
hScroll.x = 0;
|
||||
hScroll.y = bbox.y + bbox.h - hScroll.h;
|
||||
|
||||
// vScroll.alpha
|
||||
// vScroll.fading = hScroll.fading = -1;
|
||||
}
|
||||
|
||||
ScrollingPane::~ScrollingPane() {
|
||||
delete[] selected;
|
||||
}
|
||||
|
||||
//void ScrollingPane::init(Minecraft* mc, int width, int height) {
|
||||
// this->mc = mc;
|
||||
// this->width = width;
|
||||
// this->height = height;
|
||||
//}
|
||||
|
||||
void ScrollingPane::tick() {
|
||||
|
||||
if (isSet(SF_ShowScrollbar)) {
|
||||
updateScrollFade(vScroll);
|
||||
updateScrollFade(hScroll);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScrollingPane::getGridItemFor_slow(int itemIndex, GridItem& out) {
|
||||
GridItem nw = getItemForPos(0, 0, false);
|
||||
GridItem se = getItemForPos((float)bbox.w - 1, (float)bbox.h - 1, false);
|
||||
const float bxx = bbox.x - (fpx /*+ dx*alpha*/) + (nw.xf - nw.x);
|
||||
const float byy = bbox.y - (fpy /*+ dy*alpha*/) + (nw.yf - nw.y);
|
||||
|
||||
int y = itemIndex / columns;
|
||||
int x = itemIndex - (y * columns);
|
||||
|
||||
out.id = itemIndex;
|
||||
out.xf = bxx + x * itemBbox.w;
|
||||
out.yf = byy + y * itemBbox.h;
|
||||
out.x = x;
|
||||
out.y = y;
|
||||
|
||||
return x >= nw.x && x <= se.x
|
||||
&& y >= nw.y && y <= se.y;
|
||||
}
|
||||
|
||||
|
||||
void ScrollingPane::render( int xm, int ym, float alpha ) {
|
||||
// Handle user interaction first
|
||||
handleUserInput();
|
||||
|
||||
_timer.advanceTime();
|
||||
|
||||
if (_doStepTimer && !te_moved) {
|
||||
for (int i = 0; i < _timer.ticks; ++i)
|
||||
stepThroughDecelerationAnimation(false);
|
||||
this->lastFrame = getTimeMs();
|
||||
}
|
||||
|
||||
// Render
|
||||
//if (isSet(SF_Scissor)) {
|
||||
// glEnable2(GL_SCISSOR_TEST);
|
||||
// GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
// GLuint y = 480 - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
// GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
// GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
// glScissor(x, y, w, h);
|
||||
// LOGI("x, y, w, h: %d, %d, %d, %d\n", x, y, w, h);
|
||||
//}
|
||||
|
||||
std::vector<GridItem> itemsToRender;
|
||||
GridItem nw = getItemForPos(0, 0, false);
|
||||
GridItem se = getItemForPos((float)bbox.w - 1, (float)bbox.h - 1, false);
|
||||
|
||||
//LOGI("getItem: %d, %d - %d, %d\n", nw.x, nw.y, se.x, se.y);
|
||||
|
||||
const float bxx = bbox.x - (fpx /*+ dx*alpha*/) + (nw.xf - nw.x);
|
||||
const float byy = bbox.y - (fpy /*+ dy*alpha*/) + (nw.yf - nw.y);
|
||||
for (int y = nw.y; y <= se.y; ++y)
|
||||
for (int x = nw.x; x <= se.x; ++x) {
|
||||
int id = y * columns + x;
|
||||
if (y <0 || id < 0 || id >= numItems) continue; // @todo: break rather
|
||||
if (isNotSet(SF_WrapX) && (x < 0 || x >= columns)) continue; // @todo: break rather
|
||||
GridItem item; //@todo: v- Does not support SF_Wrapping
|
||||
item.id = id;
|
||||
item.xf = bxx + x * itemBbox.w;
|
||||
item.yf = byy + y * itemBbox.h;
|
||||
item.x = (int)item.xf;
|
||||
item.y = (int)item.yf;
|
||||
//LOGI("i: %d (%.1f, %.1f)\t", id, item.xf, item.yf);
|
||||
if (isSet(SF_MultiSelect)) item.selected = selected[id];
|
||||
else item.selected = (id == selectedId);
|
||||
|
||||
itemsToRender.push_back(item);
|
||||
}
|
||||
renderBatch(itemsToRender, alpha);
|
||||
|
||||
//if (isSet(SF_Scissor))
|
||||
// glDisable2(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
void ScrollingPane::renderBatch(std::vector<GridItem>& items, float alpha) {
|
||||
for (unsigned int i = 0; i < items.size(); ++i)
|
||||
renderItem(items[i], alpha);
|
||||
}
|
||||
|
||||
void ScrollingPane::renderItem(GridItem& item, float alpha) {
|
||||
}
|
||||
|
||||
ScrollingPane::GridItem ScrollingPane::getItemForPos( float x, float y, bool isScreenPos ) {
|
||||
// Screen relative pos (rather than ScrollingPane relative pos)
|
||||
if (isScreenPos) {
|
||||
x -= bbox.x;
|
||||
y -= bbox.y;
|
||||
}
|
||||
|
||||
// Add the scrolled offset
|
||||
x += fpx;
|
||||
y += fpy;
|
||||
|
||||
// Does the grid SF_Wrap around?
|
||||
if (isSet(SF_WrapX)) x = fmod(x, (float)(itemBbox.w * columns));
|
||||
if (isSet(SF_WrapY)) y = fmod(y, (float)(itemBbox.h * rows));
|
||||
|
||||
GridItem out;
|
||||
out.xf = x / itemBbox.w;
|
||||
out.yf = y / itemBbox.h;
|
||||
out.x = (int) out.xf;
|
||||
out.y = (int) out.yf;
|
||||
out.id = out.y * columns + out.x;
|
||||
return out;
|
||||
}
|
||||
|
||||
void ScrollingPane::addDeltaPos(float x, float y, float dt, int a) {
|
||||
if (dt <= 0)
|
||||
return;
|
||||
|
||||
Vec3 delta = (dragLastPos - Vec3(x, y, 0)) * (1.0f / dt);
|
||||
dragDeltas.push_back(delta.x);
|
||||
dragDeltas.push_back(delta.y);
|
||||
dragLastPos.set(x, y, 0);
|
||||
dragLastDeltaTimeStamp += dt; // @attn @fix: This relies on user to be correct
|
||||
//LOGI(">> delta %d: %s\n", a, STR(delta));
|
||||
}
|
||||
|
||||
static const int PKTableViewMinTouchDurationForCellSelection = 150;
|
||||
|
||||
void ScrollingPane::handleUserInput() {
|
||||
|
||||
bool isDown = Mouse::isButtonDown(MouseAction::ACTION_LEFT);
|
||||
float x = Mouse::getX() * invScreenScale;
|
||||
float y = Mouse::getY() * invScreenScale;
|
||||
int t = getTimeMs();
|
||||
bool isInside = area.isInside(x, y);
|
||||
//LOGI("inside? %d\n", isInside);
|
||||
|
||||
bool moved = (x != _lx || y != _ly);
|
||||
|
||||
_lx = x;
|
||||
_ly = y;
|
||||
|
||||
if (te_ended > 0 && _wasDown && !isDown)
|
||||
touchesEnded(x, y, t);
|
||||
else if (isDown && !_wasDown && isInside)
|
||||
touchesBegan(x, y, t);
|
||||
else if (te_moved > 0 && moved && isDown)
|
||||
touchesMoved(x, y, t);
|
||||
|
||||
if (highlightTimer >= 0 && isNotSet(SF_NoHoldSelect)) {
|
||||
if (getTimeMs() - highlightTimer >= PKTableViewMinTouchDurationForCellSelection)
|
||||
onHoldItem();
|
||||
}
|
||||
|
||||
_wasDown = isDown;
|
||||
}
|
||||
|
||||
Vec3& ScrollingPane::contentOffset() {
|
||||
return _contentOffset;
|
||||
}
|
||||
|
||||
void ScrollingPane::beginTracking(float x, float y, int t) { //@param 1: MouseEvent a
|
||||
if (this->tracking) {
|
||||
return;
|
||||
}
|
||||
//a.preventDefault();
|
||||
this->stopDecelerationAnimation();
|
||||
//this->hostingLayer.style.webkitTransitionDuration = 0;
|
||||
this->adjustContentSize(); //@todo @?
|
||||
this->minPoint.set((float)(this->size.w - this->adjustedContentSize.w), (float)(this->size.h - this->adjustedContentSize.h), 0); //@todo
|
||||
this->snapContentOffsetToBounds(false);
|
||||
this->startPosition = this->_contentOffset;
|
||||
this->startTouchPosition.set(x, y, 0);
|
||||
this->startTime = (float)t;
|
||||
this->startTimePosition = this->contentOffset();
|
||||
this->tracking = true;
|
||||
this->dragging = false;
|
||||
this->touchesHaveMoved = false;
|
||||
//window.addEventListener(PKMoveEvent, this, true); //@todo
|
||||
//window.addEventListener(PKEndEvent, this, true);
|
||||
//window.addEventListener("touchcancel", this, true);
|
||||
//window.addEventListener(PKEndEvent, this, false)
|
||||
};
|
||||
|
||||
void ScrollingPane::touchesBegan(float x, float y, int t) { //@param 1: MouseEvent a
|
||||
if (!this->_scrollEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
te_ended = 1;
|
||||
//if (a.eventPhase == Event.CAPTURING_PHASE) {
|
||||
// if (a._manufactured) {
|
||||
// return
|
||||
// }
|
||||
//this->highlightItem = getItemForPos(x, y, true);
|
||||
// if (this.delaysContentTouches) {
|
||||
// a.stopPropagation();
|
||||
// this.callMethodNameAfterDelay("beginTouchesInContent", kContentTouchesDelay, a);
|
||||
this->beginTracking(x, y, t);
|
||||
// }
|
||||
//} else {
|
||||
// this.beginTracking(a)
|
||||
//}
|
||||
te_moved = 2;
|
||||
|
||||
GridItem gi = getItemForPos(x, y, true);
|
||||
if (gi.id >= 0 && gi.id < numItems) {
|
||||
//LOGI("Pressed down at %d (%d, %d)\n", gi.id, gi.x, gi.y);
|
||||
highlightItem.id = bboxArea.isInside(x, y)? gi.id : -1;
|
||||
highlightStarted = highlightTimer = bboxArea.isInside(x, y)? getTimeMs() : -1;
|
||||
} else {
|
||||
highlightItem.id = -1;
|
||||
highlightStarted = highlightTimer = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::touchesMoved(float x, float y, int t)
|
||||
{
|
||||
this->touchesHaveMoved = true;
|
||||
//this->callSuper(d);
|
||||
Vec3 e(x, y, 0);
|
||||
float b = e.x - this->startTouchPosition.x;
|
||||
float c = e.y - this->startTouchPosition.y;
|
||||
if (!this->dragging) {
|
||||
if ((Mth::abs(b) >= kMinimumTrackingForDrag && isNotSet(SF_LockX)) || (Mth::abs(c) >= kMinimumTrackingForDrag && isNotSet(SF_LockY))) {
|
||||
willBeginDragging();
|
||||
this->dragging = true;
|
||||
this->firstDrag = true;
|
||||
|
||||
if (isSet(SF_ShowScrollbar)) {
|
||||
if (isNotSet(SF_LockX) && (this->adjustedContentSize.w > this->size.w))
|
||||
//this->hScroll.visible = true;
|
||||
this->hScroll.fading = 1;
|
||||
if (isNotSet(SF_LockY) && (this->adjustedContentSize.h > this->size.h))
|
||||
//this->vScroll.visible = true;
|
||||
this->vScroll.fading = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this->dragging) {
|
||||
//d.stopPropagation();
|
||||
float f = isNotSet(SF_LockX) ? (this->startPosition.x + b) : this->_contentOffset.x;
|
||||
float a = isNotSet(SF_LockY) ? (this->startPosition.y + c) : this->_contentOffset.y;
|
||||
if (isNotSet(SF_HardLimits)) {
|
||||
f -= ((f < this->minPoint.x) ? (f - this->minPoint.x) : ((f > 0) ? f : 0)) / 2;
|
||||
a -= ((a < this->minPoint.y) ? (a - this->minPoint.y) : ((a > 0) ? a : 0)) / 2;
|
||||
} else {
|
||||
f = Mth::Min(Mth::Max(this->minPoint.x, f), 0.0f);
|
||||
a = Mth::Min(Mth::Max(this->minPoint.y, a), 0.0f);
|
||||
}
|
||||
if (this->firstDrag) {
|
||||
this->firstDrag = false;
|
||||
this->startTouchPosition = e;
|
||||
return;
|
||||
}
|
||||
this->setContentOffset(f, a);
|
||||
this->lastEventTime = t;//d.timeStamp;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::touchesEnded(float x, float y, int t) {
|
||||
te_ended = 0;
|
||||
highlightStarted = -1;
|
||||
//te_moved = 0;
|
||||
|
||||
//this.callSuper(a);
|
||||
this->tracking = false;
|
||||
if (this->dragging) {
|
||||
this->dragging = false;
|
||||
//a.stopPropagation();
|
||||
if (t - this->lastEventTime <= kMaxTrackingTime) {
|
||||
this->_contentOffsetBeforeDeceleration = this->_contentOffset;
|
||||
this->startDecelerationAnimation(false);
|
||||
}
|
||||
if (!this->decelerating) {}
|
||||
//window.removeEventListener(PKEndEvent, this, false);
|
||||
didEndDragging();
|
||||
}
|
||||
if (!this->decelerating) {
|
||||
if (fpy < 0 || fpy > bbox.h) { //@todo: for x as well (or rather, x^y)
|
||||
this->_contentOffsetBeforeDeceleration = this->_contentOffset;
|
||||
this->startDecelerationAnimation(true);
|
||||
} else {
|
||||
this->snapContentOffsetToBounds(true); //@fix
|
||||
this->hideScrollIndicators();
|
||||
}
|
||||
}
|
||||
//if (a.eventPhase == Event.BUBBLING_PHASE) { //@? @todo
|
||||
// window.removeEventListener(PKEndEvent, this, false);
|
||||
|
||||
//// old and shaky, doesn't work good with Xperia Play (and presumably lots of others)
|
||||
//if (!this->touchesHaveMoved && this->highlightItem.id >= 0) {
|
||||
// _onSelect(this->highlightItem.id);
|
||||
//}
|
||||
if (Vec3(x, y, 0).distanceToSqr(startTouchPosition) <= 6.0f * 6.0f && this->highlightItem.id >= 0) {
|
||||
_onSelect(this->highlightItem.id);
|
||||
}
|
||||
//}
|
||||
te_moved = 0;
|
||||
};
|
||||
|
||||
|
||||
void ScrollingPane::touchesCancelled(float x, float y, int a) {
|
||||
touchesEnded(x, y, a);
|
||||
}
|
||||
|
||||
void ScrollingPane::startDecelerationAnimation( bool force )
|
||||
{
|
||||
Vec3 a(this->_contentOffset.x - this->startTimePosition.x, this->_contentOffset.y - this->startTimePosition.y, 0);
|
||||
float b = (getTimeMs()/*event.timeStamp*/ - this->startTime) / kAcceleration;
|
||||
//LOGI("starting deceleration! %s, %f\n", STR(a), b);
|
||||
|
||||
this->decelerationVelocity = Vec3(a.x / b, a.y / b, 0);
|
||||
this->minDecelerationPoint = this->minPoint;
|
||||
this->maxDecelerationPoint = Vec3(0, 0, 0);
|
||||
if (this->pagingEnabled) {
|
||||
this->minDecelerationPoint.x = Mth::Max(this->minPoint.x, std::floor(this->_contentOffsetBeforeDeceleration.x / this->size.w) * this->size.w);
|
||||
this->minDecelerationPoint.y = Mth::Max(this->minPoint.y, std::floor(this->_contentOffsetBeforeDeceleration.y / this->size.h) * this->size.h);
|
||||
this->maxDecelerationPoint.x = Mth::Min(0.0f, std::ceil(this->_contentOffsetBeforeDeceleration.x / this->size.w) * this->size.w);
|
||||
this->maxDecelerationPoint.y = Mth::Min(0.0f, std::ceil(this->_contentOffsetBeforeDeceleration.y / this->size.h) * this->size.h);
|
||||
}
|
||||
this->penetrationDeceleration = kPenetrationDeceleration;
|
||||
this->penetrationAcceleration = kPenetrationAcceleration;
|
||||
if (this->pagingEnabled) {
|
||||
this->penetrationDeceleration *= 5;
|
||||
}
|
||||
float c = this->pagingEnabled ? kMinVelocityForDecelerationWithPaging : kMinVelocityForDeceleration;
|
||||
if (force || (Mth::abs(this->decelerationVelocity.x) > c || Mth::abs(this->decelerationVelocity.y) > c)) {
|
||||
this->decelerating = true;
|
||||
//LOGI("accelerating True - A\n");
|
||||
_doStepTimer = true;
|
||||
//this->decelerationTimer = this->callMethodNameAfterDelay("stepThroughDecelerationAnimation", kDesiredAnimationFrameRate); //@?
|
||||
this->lastFrame = getTimeMs();
|
||||
willBeginDecelerating();
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::hideScrollIndicators() {
|
||||
//hScroll.visible = vScroll.visible = false;
|
||||
hScroll.fading = vScroll.fading = 0;
|
||||
}
|
||||
|
||||
|
||||
void ScrollingPane::stopDecelerationAnimation()
|
||||
{
|
||||
//LOGI("decelerating False - A\n");
|
||||
this->decelerating = false;
|
||||
_doStepTimer = false;
|
||||
//clearTimeout(this.decelerationTimer) //@?
|
||||
}
|
||||
|
||||
void ScrollingPane::stepThroughDecelerationAnimation(bool noAnimation) {
|
||||
if (!this->decelerating) {
|
||||
return;
|
||||
}
|
||||
int d = getTimeMs();
|
||||
int k = d - this->lastFrame;
|
||||
|
||||
int l = noAnimation ? 0 : (int)(std::floor(0.5f + ((float)k / kDesiredAnimationFrameRate) - 1));
|
||||
//LOGI("k: %d, %d %d : %d\n", d, this->lastFrame, k, l);
|
||||
for (int j = 0; j < l; j++)
|
||||
this->stepThroughDecelerationAnimation(true);
|
||||
|
||||
float g = this->contentOffset().x + this->decelerationVelocity.x;
|
||||
float h = this->contentOffset().y + this->decelerationVelocity.y;
|
||||
if (isSet(SF_HardLimits)) {
|
||||
float a = Mth::Min(Mth::Max(this->minPoint.x, g), 0.0f);
|
||||
if (a != g) {
|
||||
g = a;
|
||||
this->decelerationVelocity.x = 0;
|
||||
}
|
||||
float c = Mth::Min(Mth::Max(this->minPoint.y, h), 0.0f);
|
||||
if (c != h) {
|
||||
h = c;
|
||||
this->decelerationVelocity.y = 0;
|
||||
}
|
||||
}
|
||||
if (noAnimation) {
|
||||
this->contentOffset().x = g;
|
||||
this->contentOffset().y = h;
|
||||
} else {
|
||||
this->setContentOffset(g, h);
|
||||
}
|
||||
if (!this->pagingEnabled) {
|
||||
this->decelerationVelocity.x *= kDecelerationFrictionFactor;
|
||||
this->decelerationVelocity.y *= kDecelerationFrictionFactor;
|
||||
}
|
||||
float b = Mth::abs(this->decelerationVelocity.x);
|
||||
float i = Mth::abs(this->decelerationVelocity.y);
|
||||
if (!noAnimation && b <= kMinimumVelocityToHideScrollIndicators && i <= kMinimumVelocityToHideScrollIndicators) {
|
||||
this->hideScrollIndicators();
|
||||
if (b <= kMinimumVelocity && i <= kMinimumVelocity) {
|
||||
//LOGI("decelerating False - B\n");
|
||||
this->decelerating = false;
|
||||
didEndDecelerating();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!noAnimation) {
|
||||
//this->decelerationTimer = this->callMethodNameAfterDelay("stepThroughDecelerationAnimation", kDesiredAnimationFrameRate)
|
||||
}
|
||||
//if (noAnimation) doStepTimer = false;
|
||||
|
||||
|
||||
if (isNotSet(SF_HardLimits)) {
|
||||
Vec3 e;
|
||||
if (g < this->minDecelerationPoint.x) {
|
||||
e.x = this->minDecelerationPoint.x - g;
|
||||
} else {
|
||||
if (g > this->maxDecelerationPoint.x) {
|
||||
e.x = this->maxDecelerationPoint.x - g;
|
||||
}
|
||||
}
|
||||
if (h < this->minDecelerationPoint.y) {
|
||||
e.y = this->minDecelerationPoint.y - h;
|
||||
} else {
|
||||
if (h > this->maxDecelerationPoint.y) {
|
||||
e.y = this->maxDecelerationPoint.y - h;
|
||||
}
|
||||
}
|
||||
if (e.x != 0) {
|
||||
if (e.x * this->decelerationVelocity.x <= 0) {
|
||||
this->decelerationVelocity.x += e.x * this->penetrationDeceleration;
|
||||
} else {
|
||||
this->decelerationVelocity.x = e.x * this->penetrationAcceleration;
|
||||
}
|
||||
}
|
||||
if (e.y != 0) {
|
||||
if (e.y * this->decelerationVelocity.y <= 0) {
|
||||
this->decelerationVelocity.y += e.y * this->penetrationDeceleration;
|
||||
} else {
|
||||
this->decelerationVelocity.y = e.y * this->penetrationAcceleration;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!noAnimation) {
|
||||
this->lastFrame = d;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::setContentOffset(float x, float y) {
|
||||
this->setContentOffsetWithAnimation(Vec3(x, y, 0), false);
|
||||
}
|
||||
void ScrollingPane::setContentOffset(Vec3 a) {
|
||||
this->setContentOffsetWithAnimation(a, false);
|
||||
};
|
||||
|
||||
void ScrollingPane::setContentOffsetWithAnimation(Vec3 b, bool doScroll) {
|
||||
this->_contentOffset = b;
|
||||
fpx = -this->_contentOffset.x;
|
||||
fpy = -this->_contentOffset.y;
|
||||
/* //@todo //@?
|
||||
this->hostingLayer.style.webkitTransform = PKUtils.t(this->_contentOffset.x, this->_contentOffset.y);
|
||||
if (a) {
|
||||
this->scrollTransitionsNeedRemoval = true;
|
||||
this->hostingLayer.style.webkitTransitionDuration = kPagingTransitionDuration
|
||||
} else {
|
||||
this->didScroll(false)
|
||||
}
|
||||
*/
|
||||
if (!doScroll) {
|
||||
// @todo: for scroll indicator //@?
|
||||
if (isSet(SF_ShowScrollbar)) {
|
||||
if (isNotSet(SF_LockX)) this->updateHorizontalScrollIndicator();
|
||||
if (isNotSet(SF_LockY)) this->updateVerticalScrollIndicator();
|
||||
}
|
||||
}
|
||||
//this->notifyPropertyChange("contentOffset")
|
||||
}
|
||||
|
||||
void ScrollingPane::snapContentOffsetToBounds(bool a) {
|
||||
bool b = false;
|
||||
Vec3 c;
|
||||
if (this->pagingEnabled) {
|
||||
c.x = std::floor(0.5f + this->_contentOffset.x / this->size.w) * this->size.w;
|
||||
c.y = std::floor(0.5f + this->_contentOffset.y / this->size.h) * this->size.h;
|
||||
b = true;
|
||||
} else {
|
||||
if (isNotSet(SF_HardLimits)) {
|
||||
c.x = Mth::Min(Mth::Max(this->minPoint.x, this->_contentOffset.x), 0.0f);
|
||||
c.y = Mth::Min(Mth::Max(this->minPoint.y, this->_contentOffset.y), 0.0f);
|
||||
b = (c.x != this->_contentOffset.x || c.y != this->_contentOffset.y);
|
||||
}
|
||||
}
|
||||
if (b) {
|
||||
this->setContentOffsetWithAnimation(c, a);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::adjustContentSize()
|
||||
{
|
||||
this->adjustedContentSize.w = Mth::Max(itemBbox.w * columns, bbox.w);
|
||||
this->adjustedContentSize.h = Mth::Max(itemBbox.h * rows, bbox.h);
|
||||
}
|
||||
|
||||
void ScrollingPane::onHoldItem() {
|
||||
//LOGI("dragging, tracking %d, %d\n", !this->dragging, this->tracking);
|
||||
int id = highlightItem.id;
|
||||
if (id != -1 && !this->dragging && this->tracking)
|
||||
_onSelect(id);
|
||||
highlightTimer = -1;
|
||||
//highlightItem.id = -1;
|
||||
}
|
||||
|
||||
bool ScrollingPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
void ScrollingPane::updateHorizontalScrollIndicator()
|
||||
{
|
||||
float c = (isNotSet(SF_LockX) && isSet(SF_ShowScrollbar)) ? PKScrollIndicatorEndSize * 2 : 1;
|
||||
float d = Mth::Max(kMinIndicatorLength, std::floor(0.5f + (this->size.w / this->adjustedContentSize.w) * (this->size.w - c)));
|
||||
float a = (-this->_contentOffset.x / (this->adjustedContentSize.w - this->size.w)) * (this->size.w - c - d);
|
||||
//float b = this->size.h - PKScrollIndicatorThickness - 1;
|
||||
if (this->_contentOffset.x > 0) {
|
||||
d = std::floor(0.5f + Mth::Max(d - this->_contentOffset.x, PKScrollIndicatorThickness));
|
||||
a = 1;
|
||||
} else {
|
||||
if (this->_contentOffset.x < -(this->adjustedContentSize.w - this->size.w)) {
|
||||
d = std::floor(0.5f + Mth::Max(d + this->adjustedContentSize.w - this->size.w + this->contentOffset().x, PKScrollIndicatorThickness));
|
||||
a = this->size.w - d - c;
|
||||
}
|
||||
}
|
||||
this->hScroll.x = a + bbox.x;
|
||||
//this->hScroll.y = b;
|
||||
this->hScroll.w = d; //@property
|
||||
};
|
||||
|
||||
|
||||
void ScrollingPane::updateVerticalScrollIndicator()
|
||||
{
|
||||
float c = (isNotSet(SF_LockY) && isSet(SF_ShowScrollbar)) ? PKScrollIndicatorEndSize * 2 : 1;
|
||||
float d = Mth::Max(kMinIndicatorLength, std::floor(0.5f + (this->size.h / this->adjustedContentSize.h) * (this->size.h - c)));
|
||||
//float a = this->size.w - PKScrollIndicatorThickness - 1;
|
||||
float b = (-this->_contentOffset.y / (this->adjustedContentSize.h - this->size.h)) * (this->size.h - c - d);
|
||||
if (this->_contentOffset.y > 0) {
|
||||
d = std::floor(0.5f + Mth::Max(d - this->_contentOffset.y, PKScrollIndicatorThickness));
|
||||
b = 1;
|
||||
} else {
|
||||
if (this->_contentOffset.y < -(this->adjustedContentSize.h - this->size.h)) {
|
||||
d = std::floor(0.5f + Mth::Max(d + this->adjustedContentSize.h - this->size.h + this->contentOffset().y, PKScrollIndicatorThickness));
|
||||
b = this->size.h - d - c;
|
||||
}
|
||||
}
|
||||
//this->vScroll.x = a;
|
||||
this->vScroll.y = b + bbox.y;
|
||||
this->vScroll.h = d; //@property
|
||||
};
|
||||
|
||||
void ScrollingPane::_onSelect( int id )
|
||||
{
|
||||
if (isSet(SF_MultiSelect)) {
|
||||
selected[id] = onSelect(id, !selected[id]);
|
||||
} else {
|
||||
// Change the selection, if the user wants it
|
||||
// @note: There's currently no way to clear a selection
|
||||
bool doSelect = onSelect(id, true);
|
||||
if (id != selectedId && doSelect) {
|
||||
onSelect(selectedId, false);
|
||||
selectedId = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::updateScrollFade( ScrollBar& sb ) {
|
||||
if (sb.fading == 1 && ((sb.alpha += 0.33f) >= 1)) {
|
||||
sb.alpha = 1;
|
||||
sb.fading = -1;
|
||||
}
|
||||
if (sb.fading == 0 && ((sb.alpha -= 0.10f) <= 0)) {
|
||||
sb.alpha = 0;
|
||||
sb.fading = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::setSelected( int id, bool selected )
|
||||
{
|
||||
if (isSet(SF_MultiSelect))
|
||||
this->selected[id] = selected;
|
||||
else {
|
||||
if (selected) selectedId = selected? id : -1;
|
||||
else if (id == selectedId)
|
||||
selectedId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollingPane::translate( float xo, float yo )
|
||||
{
|
||||
bbox.x += (int)xo;
|
||||
bbox.y += (int)yo;
|
||||
area._x0 += xo;
|
||||
area._x1 += xo;
|
||||
area._y0 += yo;
|
||||
area._y1 += yo;
|
||||
bboxArea._x0 += xo;
|
||||
bboxArea._x1 += xo;
|
||||
bboxArea._y0 += yo;
|
||||
bboxArea._y1 += yo;
|
||||
hScroll.x += xo;
|
||||
hScroll.y += yo;
|
||||
vScroll.x += xo;
|
||||
vScroll.y += yo;
|
||||
}
|
||||
|
||||
bool ScrollingPane::queryHoldTime(int* gridItem, int* heldMs) {
|
||||
*gridItem = -1;
|
||||
*heldMs = -1;
|
||||
|
||||
if (!dragging && highlightStarted >= 0) {
|
||||
GridItem item = getItemForPos(_lx, _ly, true);
|
||||
if (item.id == highlightItem.id) {
|
||||
*gridItem = highlightItem.id;
|
||||
*heldMs = getTimeMs() - highlightStarted;
|
||||
return true;
|
||||
} else {
|
||||
highlightStarted = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
199
src/client/gui/components/ScrollingPane.h
Executable file
199
src/client/gui/components/ScrollingPane.h
Executable file
@@ -0,0 +1,199 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "ImageButton.h"
|
||||
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../../../world/phys/Vec3.h"
|
||||
#include "../../Timer.h"
|
||||
|
||||
enum ScrollingPaneFlags {
|
||||
SF_LockX = 1 << 0,
|
||||
SF_LockY = 1 << 1,
|
||||
SF_WrapX = 1 << 2,
|
||||
SF_WrapY = 1 << 3,
|
||||
SF_HardLimits = 1 << 4,
|
||||
SF_MultiSelect = 1 << 5,
|
||||
//SF_Snap = 1 << 6,
|
||||
//SF_CustomSnap = 1 << 7,
|
||||
//SF_Scissor = 1 << 8,
|
||||
SF_ShowScrollbar= 1 << 9,
|
||||
SF_NoHoldSelect = 1 << 10
|
||||
};
|
||||
|
||||
typedef struct ScrollBar {
|
||||
ScrollBar()
|
||||
: alpha(0),
|
||||
fading(-1)
|
||||
{}
|
||||
float x;
|
||||
float y;
|
||||
float w;
|
||||
float h;
|
||||
//bool visible;
|
||||
float alpha;
|
||||
int fading;
|
||||
} ScrollBar;
|
||||
|
||||
class ScrollingPane: public GuiComponent {
|
||||
public:
|
||||
typedef struct GridItem {
|
||||
int id;
|
||||
int x, y;
|
||||
// The GUI coordinates comes in (xf, yf)
|
||||
float xf, yf;
|
||||
bool selected;
|
||||
} GridItem;
|
||||
|
||||
ScrollingPane(int flags, const IntRectangle& boundingBox, const IntRectangle& itemRect, int columns, int numItems, float screenScale = 1.0f, const IntRectangle& itemBoundingRect = IntRectangle(0,0,0,0));
|
||||
~ScrollingPane();
|
||||
//void init(Minecraft*, int width, int height);
|
||||
void tick();
|
||||
void render(int xm, int ym, float alpha);
|
||||
|
||||
bool getGridItemFor_slow(int itemIndex, GridItem& out);
|
||||
|
||||
void setSelected(int id, bool selected);
|
||||
|
||||
// This function is called with all visible GridItems. The base
|
||||
// implementation just dispatches each item to renderItem in y,x order
|
||||
virtual void renderBatch(std::vector<GridItem>& items, float alpha);
|
||||
virtual void renderItem(GridItem& item, float alpha);
|
||||
|
||||
//void render(int xx, int yy);
|
||||
bool queryHoldTime(int* gridId, int* heldMs);
|
||||
|
||||
protected:
|
||||
GridItem getItemForPos(float x, float y, bool isScreenPos);
|
||||
void handleUserInput();
|
||||
void addDeltaPos(float x, float y, float dt, int z);
|
||||
|
||||
void translate(float xo, float yo);
|
||||
|
||||
int flags;
|
||||
|
||||
int columns;
|
||||
int rows;
|
||||
int numItems;
|
||||
|
||||
int px, py;
|
||||
float fpx, fpy;
|
||||
|
||||
float screenScale;
|
||||
float invScreenScale;
|
||||
//bool hasItemBounding;
|
||||
|
||||
IntRectangle bbox;
|
||||
IntRectangle itemRect;
|
||||
IntRectangle itemBbox;
|
||||
RectangleArea area;
|
||||
RectangleArea bboxArea;
|
||||
|
||||
// Dragging info
|
||||
std::vector<float> dragDeltas;
|
||||
int dragState;
|
||||
Vec3 dragBeginPos;
|
||||
Vec3 dragBeginScreenPos;
|
||||
int dragTicks;
|
||||
float dragLastDeltaTimeStamp;
|
||||
Vec3 dragLastPos;
|
||||
|
||||
float dx, dy;
|
||||
float friction;
|
||||
|
||||
float dstx, dsty;
|
||||
|
||||
// Rewrite
|
||||
bool dragging; //!
|
||||
bool decelerating;
|
||||
bool tracking; //!
|
||||
|
||||
bool pagingEnabled; //!
|
||||
|
||||
Vec3 _contentOffset; //!
|
||||
Vec3 _contentOffsetBeforeDeceleration; //*
|
||||
|
||||
int lastEventTime; //<
|
||||
|
||||
Vec3 decelerationVelocity; //*
|
||||
Vec3 minDecelerationPoint; //*
|
||||
Vec3 maxDecelerationPoint; //*
|
||||
|
||||
float penetrationDeceleration; //<
|
||||
float penetrationAcceleration; //<
|
||||
|
||||
Vec3 minPoint; //*
|
||||
Vec3 startPosition; //*
|
||||
Vec3 startTouchPosition; //*
|
||||
Vec3 startTimePosition; //*
|
||||
|
||||
bool wasDeceleratingWhenTouchesBegan; //*
|
||||
bool firstDrag; //<
|
||||
|
||||
float startTime; //<
|
||||
//float startTime
|
||||
|
||||
IntRectangle size;
|
||||
int lastFrame;
|
||||
|
||||
bool _scrollEnabled; //!
|
||||
bool touchesHaveMoved; //*
|
||||
|
||||
virtual void didEndDragging() {}
|
||||
virtual void didEndDecelerating() {}
|
||||
virtual void willBeginDecelerating() {}
|
||||
virtual void willBeginDragging() {}
|
||||
|
||||
int te_moved,
|
||||
te_ended,
|
||||
te_highlight;
|
||||
int highlightTimer;
|
||||
int highlightStarted;
|
||||
GridItem highlightItem;
|
||||
|
||||
bool* selected;
|
||||
int selectedId;
|
||||
|
||||
ScrollBar vScroll, hScroll;
|
||||
|
||||
IntRectangle adjustedContentSize;
|
||||
void touchesBegan(float x, float y, int t);
|
||||
void touchesMoved(float x, float y, int t);
|
||||
void touchesEnded(float x, float y, int t);
|
||||
void touchesCancelled(float x, float y, int t);
|
||||
void beginTracking(float x, float y, int t);
|
||||
void onHoldItem();
|
||||
|
||||
void _onSelect( int id );
|
||||
virtual bool onSelect(int gridId, bool selected);
|
||||
|
||||
Vec3& contentOffset();
|
||||
|
||||
void startDecelerationAnimation(bool force);
|
||||
void stopDecelerationAnimation();
|
||||
void stepThroughDecelerationAnimation(bool f);
|
||||
|
||||
void setContentOffset(float x, float y);
|
||||
void setContentOffset(Vec3 a);
|
||||
void setContentOffsetWithAnimation(Vec3 b, bool doScroll);
|
||||
void snapContentOffsetToBounds(bool snap); //*
|
||||
void adjustContentSize();
|
||||
//TouchAreaModel _areaModel;
|
||||
|
||||
bool isAllSet(int flag) { return (flags & flag) == flag; }
|
||||
bool isSet(int flag) { return (flags & flag) != 0; }
|
||||
bool isNotSet(int flag) { return !isSet(flag); }
|
||||
|
||||
void updateHorizontalScrollIndicator();
|
||||
void updateVerticalScrollIndicator();
|
||||
void hideScrollIndicators(); //*
|
||||
void updateScrollFade( ScrollBar& vScroll );
|
||||
private:
|
||||
Timer _timer;
|
||||
bool _doStepTimer;
|
||||
bool _wasDown;
|
||||
float _lx;
|
||||
float _ly;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__*/
|
||||
100
src/client/gui/components/Slider.cpp
Executable file
100
src/client/gui/components/Slider.cpp
Executable file
@@ -0,0 +1,100 @@
|
||||
#include "Slider.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../Screen.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
Slider::Slider(Minecraft* minecraft, const Options::Option* option, float progressMin, float progressMax)
|
||||
: sliderType(SliderProgress), mouseDownOnElement(false), option(option), numSteps(0), progressMin(progressMin), progressMax(progressMax) {
|
||||
if(option != NULL) {
|
||||
percentage = (minecraft->options.getProgressValue(option) - progressMin) / (progressMax - progressMin);
|
||||
}
|
||||
}
|
||||
|
||||
Slider::Slider(Minecraft* minecraft, const Options::Option* option, const std::vector<int>& stepVec )
|
||||
: sliderType(SliderStep),
|
||||
curStepValue(0),
|
||||
curStep(0),
|
||||
sliderSteps(stepVec),
|
||||
mouseDownOnElement(false),
|
||||
option(option),
|
||||
percentage(0),
|
||||
progressMin(0.0f),
|
||||
progressMax(1.0) {
|
||||
assert(stepVec.size() > 1);
|
||||
numSteps = sliderSteps.size();
|
||||
if(option != NULL) {
|
||||
curStepValue;
|
||||
int curStep;
|
||||
curStepValue = minecraft->options.getIntValue(option);
|
||||
std::vector<int>::iterator currentItem = std::find(sliderSteps.begin(), sliderSteps.end(), curStepValue);
|
||||
if(currentItem != sliderSteps.end()) {
|
||||
curStep = currentItem - sliderSteps.begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(sliderType == SliderStep) {
|
||||
int stepDistance = barWidth / (numSteps -1);
|
||||
for(int a = 0; a <= numSteps - 1; ++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)(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)) {
|
||||
mouseDownOnElement = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
mouseDownOnElement = false;
|
||||
if(sliderType == SliderStep) {
|
||||
curStep = Mth::floor((percentage * (numSteps-1) + 0.5f));
|
||||
curStepValue = sliderSteps[Mth::Min(curStep, numSteps-1)];
|
||||
percentage = float(curStep) / (numSteps - 1);
|
||||
setOption(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::tick(Minecraft* minecraft) {
|
||||
if(minecraft->screen != NULL) {
|
||||
int xm = Mouse::getX();
|
||||
int ym = Mouse::getY();
|
||||
minecraft->screen->toGUICoordinate(xm, ym);
|
||||
if(mouseDownOnElement) {
|
||||
percentage = float(xm - x) / float(width);
|
||||
percentage = Mth::clamp(percentage, 0.0f, 1.0f);
|
||||
setOption(minecraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::setOption( Minecraft* minecraft ) {
|
||||
if(option != NULL) {
|
||||
if(sliderType == SliderStep) {
|
||||
if(minecraft->options.getIntValue(option) != curStepValue) {
|
||||
minecraft->options.set(option, curStepValue);
|
||||
}
|
||||
} else {
|
||||
if(minecraft->options.getProgressValue(option) != percentage * (progressMax - progressMin) + progressMin) {
|
||||
minecraft->options.set(option, percentage * (progressMax - progressMin) + progressMin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/client/gui/components/Slider.h
Executable file
40
src/client/gui/components/Slider.h
Executable file
@@ -0,0 +1,40 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__
|
||||
|
||||
#include "GuiElement.h"
|
||||
#include "../../../client/Options.h"
|
||||
enum SliderType {
|
||||
SliderProgress, // Sets slider between {0..1}
|
||||
SliderStep // Uses the closest step
|
||||
};
|
||||
class Slider : public GuiElement {
|
||||
typedef GuiElement super;
|
||||
public:
|
||||
// Creates a progress slider with no steps
|
||||
Slider(Minecraft* minecraft, const Options::Option* option, float progressMin, float progressMax);
|
||||
Slider(Minecraft* minecraft, const Options::Option* option, const std::vector<int>& stepVec);
|
||||
virtual void render( Minecraft* minecraft, int xm, int ym );
|
||||
|
||||
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
|
||||
|
||||
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum );
|
||||
|
||||
virtual void tick(Minecraft* minecraft);
|
||||
|
||||
private:
|
||||
virtual void setOption(Minecraft* minecraft);
|
||||
|
||||
private:
|
||||
SliderType sliderType;
|
||||
std::vector<int> sliderSteps;
|
||||
bool mouseDownOnElement;
|
||||
float percentage;
|
||||
int curStepValue;
|
||||
int curStep;
|
||||
int numSteps;
|
||||
float progressMin;
|
||||
float progressMax;
|
||||
const Options::Option* option;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__*/
|
||||
24
src/client/gui/components/SmallButton.cpp
Executable file
24
src/client/gui/components/SmallButton.cpp
Executable file
@@ -0,0 +1,24 @@
|
||||
#include "SmallButton.h"
|
||||
|
||||
SmallButton::SmallButton( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, 150, 20, msg),
|
||||
option(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
SmallButton::SmallButton( int id, int x, int y, int width, int height, const std::string& msg )
|
||||
: super(id, x, y, width, height, msg),
|
||||
option(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
SmallButton::SmallButton( int id, int x, int y, Options::Option* item, const std::string& msg )
|
||||
: super(id, x, y, 150, 20, msg),
|
||||
option(item)
|
||||
{
|
||||
}
|
||||
|
||||
Options::Option* SmallButton::getOption()
|
||||
{
|
||||
return option;
|
||||
}
|
||||
23
src/client/gui/components/SmallButton.h
Executable file
23
src/client/gui/components/SmallButton.h
Executable file
@@ -0,0 +1,23 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "Button.h"
|
||||
#include "../../Options.h"
|
||||
|
||||
class SmallButton: public Button
|
||||
{
|
||||
typedef Button super;
|
||||
public:
|
||||
SmallButton(int id, int x, int y, const std::string& msg);
|
||||
SmallButton(int id, int x, int y, int width, int height, const std::string& msg);
|
||||
SmallButton(int id, int x, int y, Options::Option* item, const std::string& msg);
|
||||
|
||||
Options::Option* getOption();
|
||||
private:
|
||||
Options::Option* option;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__*/
|
||||
37
src/client/gui/components/TextBox.cpp
Executable file
37
src/client/gui/components/TextBox.cpp
Executable file
@@ -0,0 +1,37 @@
|
||||
#include "TextBox.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
TextBox::TextBox( int id, const std::string& msg )
|
||||
: id(0), w(0), h(0), x(0), y(0), text(msg), focused(false) {
|
||||
|
||||
}
|
||||
|
||||
TextBox::TextBox( int id, int x, int y, const std::string& msg )
|
||||
: id(id), w(0), h(0), x(x), y(y), text(msg), focused(false) {
|
||||
|
||||
}
|
||||
|
||||
TextBox::TextBox( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: id(id), w(w), h(h), x(x), y(y), text(msg) {
|
||||
|
||||
}
|
||||
|
||||
void TextBox::setFocus(Minecraft* minecraft) {
|
||||
if(!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextBox::loseFocus(Minecraft* minecraft) {
|
||||
if(focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextBox::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
|
||||
}
|
||||
34
src/client/gui/components/TextBox.h
Executable file
34
src/client/gui/components/TextBox.h
Executable file
@@ -0,0 +1,34 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "../GuiComponent.h"
|
||||
#include "../../Options.h"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
|
||||
class TextBox: public GuiComponent
|
||||
{
|
||||
public:
|
||||
TextBox(int id, const std::string& msg);
|
||||
TextBox(int id, int x, int y, const std::string& msg);
|
||||
TextBox(int id, int x, int y, int w, int h, const std::string& msg);
|
||||
|
||||
virtual void setFocus(Minecraft* minecraft);
|
||||
virtual bool loseFocus(Minecraft* minecraft);
|
||||
|
||||
virtual void render(Minecraft* minecraft, int xm, int ym);
|
||||
|
||||
public:
|
||||
int w, h;
|
||||
int x, y;
|
||||
|
||||
std::string text;
|
||||
int id;
|
||||
bool focused;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__*/
|
||||
Reference in New Issue
Block a user