1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef GUIELEMENT_H
#define GUIELEMENT_H
#include <list>
#include <SDL_events.h>
#include "Rendering/GL/VertexArrayTypes.h"
struct VAO;
class VBO;
namespace agui
{
class GuiElement
{
public:
GuiElement(GuiElement* parent = nullptr);
virtual ~GuiElement();
void Draw();
void DrawBox(unsigned int idx = 0);
void DrawOutline();
bool HandleEvent(const SDL_Event& ev);
bool MouseOver(int x, int y) const;
bool MouseOver(float x, float y) const;
#if 0
VAO* GetVAO(unsigned int k);
VBO* GetVBO(unsigned int k);
#endif
static void UpdateDisplayGeo(int x, int y, int offsetX, int offsetY);
static float PixelToGlX(int x);
static float PixelToGlY(int y);
static float GlToPixelX(float x);
static float GlToPixelY(float y);
virtual void AddChild(GuiElement* elem);
void SetPos(float x, float y);
void SetSize(float x, float y, bool fixed = false);
void SetDepth(float z) { depth = z; }
virtual bool HasTexCoors() const { return false; }
bool SizeFixed() const { return fixedSize; }
const float* GetSize() const { return size; }
const float* GetPos() const { return pos; }
float GetDepth() const { return depth; }
void SetWeight(unsigned newWeight) { weight = newWeight; }
unsigned Weight() const { return weight; }
void GeometryChange();
float GetMidY() const { return (pos[1] + (size[1] * 0.5f)); }
float DefaultOpacity() const { return 0.8f; }
virtual float Opacity() const {
if (parent != nullptr)
return parent->Opacity();
return DefaultOpacity();
};
void Move(float x, float y);
GuiElement* GetRoot() {
if (parent != nullptr)
return parent->GetRoot();
return this;
};
protected:
GuiElement* parent;
typedef std::list<GuiElement*> ChildList;
ChildList children;
virtual void DrawSelf() {}
virtual bool HandleEventSelf(const SDL_Event& ev) { return false; }
virtual void GeometryChangeSelf();
void GeometryChangeSelfRaw(unsigned int bufIndx, unsigned int numBytes, const VA_TYPE_T* elemsPtr) const;
static int screensize[2];
static int screenoffset[2];
bool fixedSize;
float pos[2]; // top-left x,y coor
float size[2]; // x,y dimensions
float depth = 0.0f;
unsigned weight;
unsigned elIndex;
};
}
#endif
|