File: GuiElement.h

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (105 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download | duplicates (4)
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
105
/* 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>

namespace agui
{

class GuiElement
{
public:
	GuiElement(GuiElement* parent = NULL);
	virtual ~GuiElement();
	
	void Draw();
	bool HandleEvent(const SDL_Event& ev);
	bool MouseOver(int x, int y) const;
	bool MouseOver(float x, float y) const;
	
	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);
	bool SizeFixed() const
	{
		return fixedSize;
	};
	float* GetSize()
	{
		return size;
	};
	float* GetPos()
	{
		return pos;
	};
	void SetWeight(unsigned newWeight)
	{
		weight = newWeight;
	};
	unsigned Weight() const
	{
		return weight;
	};
	
	void GeometryChange();

	float GetMidY() const
	{
		return pos[1] + (size[1] / 2.0f);
	};

	float DefaultOpacity() const;
	virtual float Opacity() const
	{
		if (parent)
			return parent->Opacity();
		else
			return DefaultOpacity();
	};

	void Move(float x, float y);
	GuiElement* GetRoot()
	{
		if (parent)
			return parent->GetRoot();
		else
			return this;
	};

	void DrawBox(int how);

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() {};
	
	static int screensize[2];
	static int screenoffset[2];
	
	bool fixedSize;
	float pos[2];
	float size[2];
	unsigned weight;
};

}

#endif