pragma once everywhere

This commit is contained in:
Kolyah35 2026-03-28 00:00:19 +03:00
parent a45c01d013
commit 7d3257669a
575 changed files with 37222 additions and 38345 deletions

View file

@ -1,80 +1,78 @@
#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__*/
#pragma once
//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;
};
}

View file

@ -1,55 +1,53 @@
#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__*/
#pragma once
#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;
};

View file

@ -1,34 +1,32 @@
#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 void keyPressed(Minecraft* minecraft, int key) {}
virtual void charPressed(Minecraft* minecraft, char key) {}
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__*/
#pragma once
#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 void keyPressed(Minecraft* minecraft, int key) {}
virtual void charPressed(Minecraft* minecraft, char key) {}
virtual bool pointInside(int x, int y);
void setVisible(bool visible);
bool active;
bool visible;
int x;
int y;
int width;
int height;
};

View file

@ -1,28 +1,26 @@
#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 );
virtual void keyPressed(Minecraft* minecraft, int key);
virtual void charPressed(Minecraft* minecraft, char key);
protected:
std::vector<GuiElement*> children;
};
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__*/
#pragma once
#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 );
virtual void keyPressed(Minecraft* minecraft, int key);
virtual void charPressed(Minecraft* minecraft, char key);
protected:
std::vector<GuiElement*> children;
};

View file

@ -1,97 +1,95 @@
#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(OptionId optId);
void toggle(Options* options);
void updateImage(Options* options);
static const int ButtonId = 9999999;
protected:
bool isSecondImage(bool hovered) { return _secondImage; }
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
private:
OptionId m_optId;
bool _secondImage;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__*/
#pragma once
#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(OptionId optId);
void toggle(Options* options);
void updateImage(Options* options);
static const int ButtonId = 9999999;
protected:
bool isSecondImage(bool hovered) { return _secondImage; }
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
private:
OptionId m_optId;
bool _secondImage;
};

View file

@ -1,62 +1,60 @@
#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__*/
#pragma once
#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;
};
}

View file

@ -1,95 +1,93 @@
#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__*/
#pragma once
#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;
};

View file

@ -1,21 +1,19 @@
#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__*/
#pragma once
#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;
};

View file

@ -1,78 +1,76 @@
#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__*/
#pragma once
#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;
};

View file

@ -1,32 +1,30 @@
#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 "ScrollingPane.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);
OptionsGroup& addOptionItem(OptionId optId, Minecraft* minecraft);
protected:
void createToggle(OptionId optId, Minecraft* minecraft);
void createProgressSlider(OptionId optId, Minecraft* minecraft);
void createStepSlider(OptionId optId, Minecraft* minecraft);
void createTextbox(OptionId optId, Minecraft* minecraft);
void createKey(OptionId optId, Minecraft* minecraft);
std::string label;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__*/
#pragma once
//package net.minecraft.client.gui;
#include <string>
#include "GuiElementContainer.h"
#include "ScrollingPane.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);
OptionsGroup& addOptionItem(OptionId optId, Minecraft* minecraft);
protected:
void createToggle(OptionId optId, Minecraft* minecraft);
void createProgressSlider(OptionId optId, Minecraft* minecraft);
void createStepSlider(OptionId optId, Minecraft* minecraft);
void createTextbox(OptionId optId, Minecraft* minecraft);
void createKey(OptionId optId, Minecraft* minecraft);
std::string label;
};

View file

@ -1,27 +1,25 @@
#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(OptionId optionId, std::string label, GuiElement* element);
virtual void render(Minecraft* minecraft, int xm, int ym);
void setupPositions();
private:
OptionId m_optionId;
std::string m_label;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__*/
#pragma once
#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(OptionId optionId, std::string label, GuiElement* element);
virtual void render(Minecraft* minecraft, int xm, int ym);
void setupPositions();
private:
OptionId m_optionId;
std::string m_label;
};

View file

@ -1,82 +1,80 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
#include "../GuiComponent.h"
class MinecraftClient;
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(MinecraftClient& 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:
MinecraftClient& 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__*/
#pragma once
#include "../GuiComponent.h"
class MinecraftClient;
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(MinecraftClient& 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:
MinecraftClient& 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;
};

View file

@ -1,94 +1,92 @@
#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__*/
#pragma once
#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;
};

View file

@ -1,69 +1,67 @@
#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__*/
#pragma once
#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;
};

View file

@ -1,203 +1,201 @@
#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);
// scroll the content by the given amount (dx horizontal, dy vertical)
// positive values move content downward/rightward
void scrollBy(float dx, float dy);
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__*/
#pragma once
#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);
// scroll the content by the given amount (dx horizontal, dy vertical)
// positive values move content downward/rightward
void scrollBy(float dx, float dy);
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;
};

View file

@ -1,48 +1,46 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__
#include "GuiElement.h"
#include "../../../client/Options.h"
#include <client/Option.h>
class Slider : public GuiElement {
typedef GuiElement super;
public:
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);
protected:
Slider(OptionId optId);
OptionId m_optId;
bool m_mouseDownOnElement;
float m_percentage;
int m_numSteps;
};
class SliderFloat : public Slider {
public:
SliderFloat(Minecraft* minecraft, OptionId option);
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
OptionFloat* m_option;
};
class SliderInt : public Slider {
public:
SliderInt(Minecraft* minecraft, OptionId option);
virtual void render( Minecraft* minecraft, int xm, int ym ) override;
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
OptionInt* m_option;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__*/
#pragma once
#include "GuiElement.h"
#include "../../../client/Options.h"
#include <client/Option.h>
class Slider : public GuiElement {
typedef GuiElement super;
public:
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);
protected:
Slider(OptionId optId);
OptionId m_optId;
bool m_mouseDownOnElement;
float m_percentage;
int m_numSteps;
};
class SliderFloat : public Slider {
public:
SliderFloat(Minecraft* minecraft, OptionId option);
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
OptionFloat* m_option;
};
class SliderInt : public Slider {
public:
SliderInt(Minecraft* minecraft, OptionId option);
virtual void render( Minecraft* minecraft, int xm, int ym ) override;
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
OptionInt* m_option;
};

View file

@ -1,44 +1,42 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__
//package net.minecraft.client.gui;
#include <string>
#include "GuiElement.h"
#include "../../Options.h"
#include "../../../platform/input/Mouse.h"
#include "../../../platform/input/Keyboard.h"
class Font;
class Minecraft;
class TextBox: public GuiElement
{
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 mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum);
virtual void setFocus(Minecraft* minecraft);
virtual bool loseFocus(Minecraft* minecraft);
virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void keyPressed(Minecraft* minecraft, int key);
virtual void charPressed(Minecraft* minecraft, char c);
virtual void tick(Minecraft* minecraft);
public:
std::string hint;
std::string text;
int id;
int blinkTicks;
bool focused;
bool blink;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__*/
#pragma once
//package net.minecraft.client.gui;
#include <string>
#include "GuiElement.h"
#include "../../Options.h"
#include "../../../platform/input/Mouse.h"
#include "../../../platform/input/Keyboard.h"
class Font;
class Minecraft;
class TextBox: public GuiElement
{
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 mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum);
virtual void setFocus(Minecraft* minecraft);
virtual bool loseFocus(Minecraft* minecraft);
virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void keyPressed(Minecraft* minecraft, int key);
virtual void charPressed(Minecraft* minecraft, char c);
virtual void tick(Minecraft* minecraft);
public:
std::string hint;
std::string text;
int id;
int blinkTicks;
bool focused;
bool blink;
};