diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-14 18:51:24 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-14 18:51:24 (GMT) |
| commit | 2c9295007a287dc01ff63fcf7b3da141f7474e37 (patch) | |
| tree | e8065e920ca45686a40e41fd46513e13d46f47b0 /includes/interface | |
| parent | fc2f52099c0bbb2412046252bf7b5e4113bbe8e4 (diff) | |
| download | powder-2c9295007a287dc01ff63fcf7b3da141f7474e37.zip powder-2c9295007a287dc01ff63fcf7b3da141f7474e37.tar.gz | |
Various things, also IEF UI
Diffstat (limited to 'includes/interface')
| -rw-r--r-- | includes/interface/Button.h | 15 | ||||
| -rw-r--r-- | includes/interface/Component.h | 217 | ||||
| -rw-r--r-- | includes/interface/ControlFactory.h | 2 | ||||
| -rw-r--r-- | includes/interface/Engine.h | 64 | ||||
| -rw-r--r-- | includes/interface/Label.h | 26 | ||||
| -rw-r--r-- | includes/interface/Panel.h | 148 | ||||
| -rw-r--r-- | includes/interface/Platform.h | 108 | ||||
| -rw-r--r-- | includes/interface/Point.h | 136 | ||||
| -rw-r--r-- | includes/interface/Sandbox.h | 11 | ||||
| -rw-r--r-- | includes/interface/State.h | 128 | ||||
| -rw-r--r-- | includes/interface/Window.h | 22 |
11 files changed, 739 insertions, 138 deletions
diff --git a/includes/interface/Button.h b/includes/interface/Button.h index 1b2900e..86688cf 100644 --- a/includes/interface/Button.h +++ b/includes/interface/Button.h @@ -17,7 +17,12 @@ namespace ui class Button : public Component { public: - Button(int x, int y, int width, int height, const std::string& buttonText); + Button(State* parent_state, std::string buttonText); + + Button(Point position, Point size, std::string buttonText); + + Button(std::string buttonText); + virtual ~Button(); bool Toggleable; @@ -25,12 +30,12 @@ namespace ui virtual void OnMouseClick(int x, int y, unsigned int button); virtual void OnMouseUnclick(int x, int y, unsigned int button); - virtual void OnMouseUp(int x, int y, unsigned int button); + //virtual void OnMouseUp(int x, int y, unsigned int button); - virtual void OnMouseEnter(int x, int y, int dx, int dy); - virtual void OnMouseLeave(int x, int y, int dx, int dy); + virtual void OnMouseEnter(int x, int y); + virtual void OnMouseLeave(int x, int y); - virtual void Draw(void* userdata); + virtual void Draw(const Point& screenPos); inline bool GetState() { return state; } virtual void DoAction(); //action of button what ever it may be diff --git a/includes/interface/Component.h b/includes/interface/Component.h index a4d02db..5759c08 100644 --- a/includes/interface/Component.h +++ b/includes/interface/Component.h @@ -1,53 +1,204 @@ -/* - * Component.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ +#pragma once -#ifndef COMPONENT_H_ -#define COMPONENT_H_ +#include "Point.h" +#include "State.h" +#include "Platform.h" namespace ui { - class State; - - class Component + class State; + class Panel; + + /* class Component + * + * An interactive UI component that can be added to a state or an XComponent*. + * *See sys::XComponent + */ + class Component { public: - Component(int x, int y, int width, int height); + Component(State* parent_state); + Component(Point position, Point size); + Component(); virtual ~Component(); + + void* UserData; + inline State* const GetParentState() const { return parentstate_; } + bool IsFocused() const; - inline void LocalizePoint(int& x, int& y) { x -= X; y -= Y; } //convert a global point (point on the state) to a point based on component's position - inline void GlobalizePoint(int& x, int& y) { x += X; y += Y; } //convert a local point based on component's position to a global point on the state - - bool Focused; + Point Position; + Point Size; + bool Locked; bool Visible; - bool Enabled; - int Width; - int Height; - int X; - int Y; - virtual void Tick(float dt); - virtual void Draw(void* userdata); + /* See the parent of this component. + * If new_parent is NULL, this component will have no parent. (THIS DOES NOT delete THE COMPONENT. See XComponent::RemoveChild) + */ + void SetParentState(State* state); + void SetParent(Panel* new_parent); + + //Get the parent component. + inline Panel* const GetParent() const { return _parent; } + + //UI functions: + /* + void Tick(float dt); + void Draw(const Point& screenPos); + + void OnMouseHover(int localx, int localy); + void OnMouseMoved(int localx, int localy, int dx, int dy); + void OnMouseMovedInside(int localx, int localy, int dx, int dy); + void OnMouseEnter(int localx, int localy); + void OnMouseLeave(int localx, int localy); + void OnMouseDown(int x, int y, unsigned int button); + void OnMouseUp(int x, int y, unsigned int button); + void OnMouseClick(int localx, int localy, unsigned int button); + void OnMouseUnclick(int localx, int localy, unsigned int button); + void OnMouseWheel(int localx, int localy, int d); + void OnMouseWheelInside(int localx, int localy, int d); + void OnKeyPress(int key, bool shift, bool ctrl, bool alt); + void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); + */ - virtual void OnMouseEnter(int localx, int localy, int dx, int dy); - virtual void OnMouseLeave(int localx, int localy, int dx, int dy); + /// + // Called: Every tick. + // Params: + // dt: The change in time. + /// + virtual void Tick(float dt); + + /// + // Called: When ready to draw. + // Params: + // None + /// + virtual void Draw(const Point& screenPos); + + + + + /// + // Called: When the mouse is currently hovering over the item. (Called every tick) + // Params: + // localx: Local mouse X position. + // localy: Local mouse Y position. + /// + virtual void OnMouseHover(int localx, int localy); + + /// + // Called: When the mouse moves. + // Params: + // localx: Local mouse X position. + // localy: Local mouse Y position. + // dx: Mouse X delta. + // dy: Mouse Y delta. + /// virtual void OnMouseMoved(int localx, int localy, int dx, int dy); + + /// + // Called: When the mouse moves. + // Params: + // localx: Local mouse X position. + // localy: Local mouse Y position. + // dx: Mouse X delta. + // dy: Mouse Y delta. + /// virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy); - virtual void OnMouseHover(int localx, int localy); - virtual void OnMouseDown(int localx, int localy, unsigned int button); - virtual void OnMouseUp(int localx, int localy, unsigned int button); - virtual void OnMouseClick(int localx, int localy, unsigned int button); - virtual void OnMouseUnclick(int localx, int localy, unsigned int button); + + /// + // Called: When the mouse moves on top of the item. + // Params: + // localx: Local mouse X position. + // localy: Local mouse Y position. + // dx: Mouse X delta. + // dy: Mouse Y delta. + /// + virtual void OnMouseEnter(int localx, int localy); + + /// + // Called: When the mouse leaves the item. + // Params: + // localx: Local mouse X position. + // localy: Local mouse Y position. + /// + virtual void OnMouseLeave(int localx, int localy); + + /// + // Called: When a mouse button is pressed. + // Params: + // x: X position of the mouse. + // y: Y position of the mouse. + // button: The button that is being held down. + /// + virtual void OnMouseDown(int x, int y, unsigned button); + + /// + // Called: When a mouse button is released. + // Params: + // x: X position of the mouse. + // y: Y position of the mouse. + // button: The button that is being released. + /// + virtual void OnMouseUp(int x, int y, unsigned button); + + /// + // Called: When a mouse button is pressed on top of the item. + // Params: + // x: X position of the mouse. + // y: Y position of the mouse. + // button: The button that is being held down. + /// + virtual void OnMouseClick(int localx, int localy, unsigned button); + + /// + // Called: When a mouse button is released on top of the item. + // Params: + // x: X position of the mouse. + // y: Y position of the mouse. + // button: The button that is being released. + /// + virtual void OnMouseUnclick(int localx, int localy, unsigned button); + + /// + // Called: When the mouse wheel moves/changes. + // Params: + // localx: Local mouse X position. + // localy: Local mouse Y position. + // d: The mouse wheel movement value. + /// virtual void OnMouseWheel(int localx, int localy, int d); + + /// + // Called: When the mouse wheel moves/changes on top of the item. + // Params: + // localx: Local mouse X position. + // localy: Local mouse Y position. + // d: The mouse wheel movement value. + /// virtual void OnMouseWheelInside(int localx, int localy, int d); - virtual void OnMouseWheelFocused(int localx, int localy, int d); + + /// + // Called: When a key is pressed. + // Params: + // key: The value of the key that is being pressed. + // shift: Shift key is down. + // ctrl: Control key is down. + // alt: Alternate key is down. + /// virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt); + + /// + // Called: When a key is released. + // Params: + // key: The value of the key that is being released. + // shift: Shift key is released. + // ctrl: Control key is released. + // alt: Alternate key is released. + /// virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); - State* Parent; + private: + State* parentstate_; + Panel* _parent; }; } -#endif /* COMPONENT_H_ */ diff --git a/includes/interface/ControlFactory.h b/includes/interface/ControlFactory.h index 8bfd780..ba5f43b 100644 --- a/includes/interface/ControlFactory.h +++ b/includes/interface/ControlFactory.h @@ -2,7 +2,7 @@ #define CONTROLFACTORY_H #include "Panel.h" -#include "Window.h" +#include "Engine.h" #include "GameSession.h" class ControlFactory diff --git a/includes/interface/Engine.h b/includes/interface/Engine.h new file mode 100644 index 0000000..682a09d --- /dev/null +++ b/includes/interface/Engine.h @@ -0,0 +1,64 @@ +#pragma once + +#include <SDL/SDL.h> +#include "Singleton.h" +#include "Platform.h" +#include "State.h" +#include "Graphics.h" + +namespace ui +{ + class State; + + /* class Engine + * + * Controls the User Interface. + * Send user inputs to the Engine and the appropriate controls and components will interact. + */ + class Engine: public Singleton<Engine> + { + public: + Engine(); + ~Engine(); + + void onMouseMove(int x, int y); + void onMouseClick(int x, int y, unsigned button); + void onMouseUnclick(int x, int y, unsigned button); + void onMouseWheel(int x, int y, int delta); + void onKeyPress(int key, bool shift, bool ctrl, bool alt); + void onKeyRelease(int key, bool shift, bool ctrl, bool alt); + void onResize(int newWidth, int newHeight); + void onClose(); + + void Begin(int width, int height, SDL_Surface * surface); + inline bool Running() { return running_; } + void Exit(); + + void Tick(float dt); + void Draw(); + + inline int GetMouseX() { return mousex_; } + inline int GetMouseY() { return mousey_; } + inline int GetWidth() { return width_; } + inline int GetHeight() { return height_; } + + inline void SetSize(int width, int height); + + void SetState(State* state); + inline State* GetState() { return state_; } + Graphics * g; + private: + State* statequeued_; + State* state_; + + bool running_; + + int mousex_; + int mousey_; + int mousexp_; + int mouseyp_; + int width_; + int height_; + }; + +} diff --git a/includes/interface/Label.h b/includes/interface/Label.h new file mode 100644 index 0000000..2168956 --- /dev/null +++ b/includes/interface/Label.h @@ -0,0 +1,26 @@ +#ifndef LABEL_H +#define LABEL_H + +#include <string> + +#include "Component.h" + +namespace ui +{ + class Label : public Component + { + public: + Label(State* parent_state, std::string labelText); + + Label(Point position, Point size, std::string labelText); + + Label(std::string labelText); + virtual ~Label(); + + std::string LabelText; + + virtual void Draw(const Point& screenPos); + }; +} + +#endif // LABEL_H diff --git a/includes/interface/Panel.h b/includes/interface/Panel.h index 9549ff4..7c9adab 100644 --- a/includes/interface/Panel.h +++ b/includes/interface/Panel.h @@ -1,22 +1,136 @@ -/* - * Panel.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef PANEL_H_ -#define PANEL_H_ +#pragma once +#include <vector> +//#include "Platform.h" +#include "interface/Point.h" +#include "interface/State.h" #include "interface/Component.h" -namespace ui { +namespace ui +{ + /* class XComponent + * + * An eXtension of the Component class. + * Adds the ability to have child components. + * + * See sys::Component + */ +class Component; + class Panel : public Component + { + public: + friend class Component; -class Panel: public ui::Component { -public: - Panel(int x, int y, int width, int height); - virtual ~Panel(); -}; + Panel(State* parent_state); + Panel(Point position, Point size); + Panel(); + virtual ~Panel(); + + /* Add a child component. + * Similar to XComponent::SetParent + * + * If the component is already parented, then this will become the new parent. + */ + void AddChild(Component* c); + + // Remove child from component. This DOES NOT free the component from memory. + void RemoveChild(Component* c); + + // Remove child from component. This WILL free the component from memory unless told otherwise. + void RemoveChild(unsigned idx, bool freeMem = true); + + //Grab the number of children this component owns. + int GetChildCount(); + + //Get child of this component by index. + Component* GetChild(unsigned idx); + + void Tick(float dt); + void Draw(const Point& screenPos); + + void OnMouseHover(int localx, int localy); + void OnMouseMoved(int localx, int localy, int dx, int dy); + void OnMouseMovedInside(int localx, int localy, int dx, int dy); + void OnMouseEnter(int localx, int localy); + void OnMouseLeave(int localx, int localy); + void OnMouseDown(int x, int y, unsigned button); + void OnMouseUp(int x, int y, unsigned button); + void OnMouseClick(int localx, int localy, unsigned button); + void OnMouseUnclick(int localx, int localy, unsigned button); + void OnMouseWheel(int localx, int localy, int d); + void OnMouseWheelInside(int localx, int localy, int d); + void OnKeyPress(int key, bool shift, bool ctrl, bool alt); + void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); + + protected: + // child components + std::vector<ui::Component*> children; + + //UI functions: + /* + void XTick(float dt); + void XDraw(const Point& screenPos); + + void XOnMouseHover(int localx, int localy); + void XOnMouseMoved(int localx, int localy, int dx, int dy); + void XOnMouseMovedInside(int localx, int localy, int dx, int dy); + void XOnMouseEnter(int localx, int localy); + void XOnMouseLeave(int localx, int localy); + void XOnMouseDown(int x, int y, unsigned int button); + void XOnMouseUp(int x, int y, unsigned int button); + void XOnMouseClick(int localx, int localy, unsigned int button); + void XOnMouseUnclick(int localx, int localy, unsigned int button); + void XOnMouseWheel(int localx, int localy, int d); + void XOnMouseWheelInside(int localx, int localy, int d); + void XOnKeyPress(int key, bool shift, bool ctrl, bool alt); + void XOnKeyRelease(int key, bool shift, bool ctrl, bool alt); + */ + + // Overridable. Called by XComponent::Tick() + virtual void XTick(float dt); + + // Overridable. Called by XComponent::Draw() + virtual void XDraw(const Point& screenPos); + + + // Overridable. Called by XComponent::XOnMouseHover() + virtual void XOnMouseHover(int localx, int localy); + + // Overridable. Called by XComponent::OnMouseMoved() + virtual void XOnMouseMoved(int localx, int localy, int dx, int dy); + + // Overridable. Called by XComponent::OnMouseMovedInside() + virtual void XOnMouseMovedInside(int localx, int localy, int dx, int dy); + + // Overridable. Called by XComponent::OnMouseEnter() + virtual void XOnMouseEnter(int localx, int localy); + + // Overridable. Called by XComponent::OnMouseLeave() + virtual void XOnMouseLeave(int localx, int localy); + + // Overridable. Called by XComponent::OnMouseDown() + virtual void XOnMouseDown(int x, int y, unsigned button); + + // Overridable. Called by XComponent::OnMouseUp() + virtual void XOnMouseUp(int x, int y, unsigned button); + + // Overridable. Called by XComponent::OnMouseClick() + virtual void XOnMouseClick(int localx, int localy, unsigned button); + + // Overridable. Called by XComponent::OnMouseUnclick() + virtual void XOnMouseUnclick(int localx, int localy, unsigned button); + + // Overridable. Called by XComponent::OnMouseWheel() + virtual void XOnMouseWheel(int localx, int localy, int d); + + // Overridable. Called by XComponent::OnMouseWheelInside() + virtual void XOnMouseWheelInside(int localx, int localy, int d); + + // Overridable. Called by XComponent::OnKeyPress() + virtual void XOnKeyPress(int key, bool shift, bool ctrl, bool alt); + + // Overridable. Called by XComponent::OnKeyRelease() + virtual void XOnKeyRelease(int key, bool shift, bool ctrl, bool alt); + }; -} /* namespace ui */ -#endif /* PANEL_H_ */ +} diff --git a/includes/interface/Platform.h b/includes/interface/Platform.h new file mode 100644 index 0000000..c57dca6 --- /dev/null +++ b/includes/interface/Platform.h @@ -0,0 +1,108 @@ +#pragma once + + +/* ***** Platform-ness ***** */ + +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32_LEAN_AND_MEAN) +# define IEF_PLATFORM_WIN32 +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +#elif defined(linux) || defined(_linux) || defined(__linux) +# define IEF_PLATFORM_LINUX + +#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh) +# define IEF_PLATFORM_MACOSX + +//#elif defined(__FreeBSD__) || define(__FreeBSD_kernel__) +//# define IEF_PLATFORM_FREEBSD + +#else +# error Operating System not supported. +#endif + + +/* ***** Endian-ness ***** */ + +#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__) +# define IEF_ENDIAN_BIG + +#else +# define IEF_ENDIAN_LITTLE +#endif + + +/* ***** Debug-ness ***** */ + +#if !defined(NDEBUG) || defined(_DEBUG) +# define IEF_DEBUG +#endif + + +/* ***** Primitive Types ***** */ + +#ifndef NULL +# define NULL 0 +#endif + +#include <climits> +namespace sys +{ + +#if UCHAR_MAX == 0xFF //char + typedef signed char s8; + typedef unsigned char u8; +#else +# error No 8-Bit Integer supported. +#endif +#if USHRT_MAX == 0xFFFF //short + typedef signed short s16; + typedef unsigned short u16; +#elif UINT_MAX == 0xFFFF + typedef signed int s16; + typedef unsigned int u16; +#elif ULONG_MAX == 0xFFFF + typedef signed long s16; + typedef unsigned long u16; + #else + # error No 16-Bit Integer supported. + #endif + #if USHRT_MAX == 0xFFFFFFFF //int + typedef signed short s32; + typedef unsigned short u32; +#elif UINT_MAX == 0xFFFFFFFF + typedef signed int s32; + typedef unsigned int u32; +#elif ULONG_MAX == 0xFFFFFFFF + typedef signed long s32; + typedef unsigned long u32; + #else + # error No 32-Bit Integer supported. + #endif +#if UINT_MAX == 0xFFFFFFFFFFFFFFFF //long + typedef signed int s64; + typedef unsigned int u64; +#elif ULONG_MAX == 0xFFFFFFFFFFFFFFFF + typedef signed long s64; + typedef unsigned long u64; +#elif ULLONG_MAX == 0xFFFFFFFFFFFFFFFF + typedef signed long long s64; + typedef unsigned long long u64; +#else +# pragma message("Warning: 64-bit not supported. s64 and u64 defined as 32-bit.") + typedef s32 s64; + typedef u32 u64; +#endif +//floating +typedef float f32; +typedef double f64; +//misc +typedef u8 byte; +typedef u8 ubyte; +typedef s8 sbyte; +typedef s64 llong; +typedef s64 sllong; +typedef u64 ullong; +typedef char* cstring; + +} //namespace sys diff --git a/includes/interface/Point.h b/includes/interface/Point.h new file mode 100644 index 0000000..0d0250c --- /dev/null +++ b/includes/interface/Point.h @@ -0,0 +1,136 @@ +#pragma once +#include "Platform.h" + +namespace ui +{ + +//Lightweight 2D Int32/Float32 Point struct for UI +struct Point +{ +#if ENABLE_FLOAT_UI +# define POINT_T float +#else +# define POINT_T int +#endif + + POINT_T X; + POINT_T Y; + + Point(POINT_T x, POINT_T y) + : X(x) + , Y(y) + { + } + + inline Point operator - () const + { + return Point(-X, -Y); + } + + inline Point operator + (const Point& v) const + { + return Point(X + v.X, Y + v.Y); + } + + inline Point operator - (const Point& v) const + { + return Point(X - v.X, Y - v.Y); + } + + inline Point operator * (const Point& v) const + { + return Point(X * v.X, Y * v.Y); + } + + inline Point operator * (int v) const + { + return Point(X * static_cast<POINT_T>(v), Y * static_cast<POINT_T>(v)); + } + + inline Point operator * (float v) const + { + return Point(X * static_cast<POINT_T>(v), Y * static_cast<POINT_T>(v)); + } + + inline Point operator / (const Point& v) const + { + return Point(X / v.X, Y / v.Y); + } + + inline Point operator / (int v) const + { + return Point(X / static_cast<POINT_T>(v), Y / static_cast<POINT_T>(v)); + } + + inline Point operator / (float v) const + { + return Point(X / static_cast<POINT_T>(v), Y / static_cast<POINT_T>(v)); + } + + inline void operator += (const Point& v) + { + X += v.X; + Y += v.Y; + } + + inline void operator -= (const Point& v) + { + X -= v.X; + Y -= v.Y; + } + + inline void operator *= (const Point& v) + { + X *= v.X; + Y *= v.Y; + } + + inline void operator *= (int v) + { + X *= static_cast<POINT_T>(v); + Y *= static_cast<POINT_T>(v); + } + + inline void operator *= (float v) + { + X *= static_cast<POINT_T>(v); + Y *= static_cast<POINT_T>(v); + } + + inline void operator /= (const Point& v) + { + X /= v.X; + Y /= v.Y; + } + + inline void operator /= (int v) + { + X /= static_cast<POINT_T>(v); + Y /= static_cast<POINT_T>(v); + } + + inline void operator /= (float v) + { + X /= static_cast<POINT_T>(v); + Y /= static_cast<POINT_T>(v); + } + + inline bool operator == (const Point& v) const + { + return (X == v.X && Y == v.Y); + } + + inline bool operator != (const Point& v) const + { + return (X != v.X || Y != v.Y); + } + + inline void operator = (const Point& v) + { + X = v.X; + Y = v.Y; + } + +}; + +} diff --git a/includes/interface/Sandbox.h b/includes/interface/Sandbox.h index 32a0471..f4daa87 100644 --- a/includes/interface/Sandbox.h +++ b/includes/interface/Sandbox.h @@ -8,6 +8,8 @@ #ifndef SANDBOX_H_ #define SANDBOX_H_ +#include <queue> +#include "Point.h" #include "Component.h" #include "Simulation.h" #include "Renderer.h" @@ -18,16 +20,17 @@ class Sandbox: public ui::Component { private: int lastCoordX, lastCoordY; int activeElement; + std::queue<Point*> pointQueue; bool isMouseDown; Renderer * ren; Simulation * sim; public: Sandbox(); virtual Simulation * GetSimulation(); - virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy); - virtual void OnMouseDown(int localx, int localy, unsigned int button); - virtual void OnMouseUp(int localx, int localy, unsigned int button); - virtual void Draw(void* userdata); + virtual void OnMouseMoved(int localx, int localy, int dx, int dy); + virtual void OnMouseClick(int localx, int localy, unsigned int button); + virtual void OnMouseUnclick(int localx, int localy, unsigned int button); + virtual void Draw(const Point& screenPos); virtual void Tick(float delta); virtual ~Sandbox(); }; diff --git a/includes/interface/State.h b/includes/interface/State.h index 00df199..75e969d 100644 --- a/includes/interface/State.h +++ b/includes/interface/State.h @@ -1,61 +1,77 @@ -/* - * State.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef STATE_H_ -#define STATE_H_ +#pragma once #include <vector> -#include "interface/Component.h" - -namespace ui { +#include "Engine.h" +#include "Component.h" +#include "Platform.h" -class State +namespace ui { -public: - State(int w, int h); - virtual ~State(); - - bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds - - virtual void Tick(float dt); - virtual void Draw(void* userdata); - - virtual void OnMouseMove(int x, int y); - virtual void OnMouseDown(int x, int y, unsigned int button); - virtual void OnMouseUp(int x, int y, unsigned int button); - virtual void OnMouseWheel(int x, int y, int d); - virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); - - virtual void Add(Component *child); - virtual void Remove(Component *child); - - inline bool IsFocused(Component* c) { return (c == focusedComponent_); } - inline int GetMouseX() { return mouseX; } - inline int GetMouseY() { return mouseY; } - inline int GetWidth() { return width; } - inline int GetHeight() { return height; } - -protected: - std::vector<Component*> Components; - - int width; - int height; - - int mouseX; - int mouseY; - int mouseXP; - int mouseYP; - -private: - Component* focusedComponent_; - -}; - -} /* namespace ui */ -#endif /* STATE_H_ */ + class Engine; + class Component; + + /* class State + * + * A UI state. Contains all components. + */ + class State + { + public: + State(); + virtual ~State(); + + bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds + + // Add Component to state + void AddComponent(Component* c); + + // Get the number of components this state has. + unsigned GetComponentCount(); + + // Get component by index. (See GetComponentCount()) + Component* GetComponent(unsigned idx); + + // Remove a component from state. NOTE: This DOES NOT free component from memory. + void RemoveComponent(Component* c); + + // Remove a component from state. NOTE: This WILL free component from memory. + void RemoveComponent(unsigned idx); + + void DoInitialized(); + void DoExit(); + void DoTick(float dt); + void DoDraw(); + + void DoMouseMove(int x, int y, int dx, int dy); + void DoMouseDown(int x, int y, unsigned button); + void DoMouseUp(int x, int y, unsigned button); + void DoMouseWheel(int x, int y, int d); + void DoKeyPress(int key, bool shift, bool ctrl, bool alt); + void DoKeyRelease(int key, bool shift, bool ctrl, bool alt); + + bool IsFocused(const Component* c) const; + void FocusComponent(Component* c); + + void* UserData; + + protected: + virtual void OnInitialized() {} + virtual void OnExit() {} + virtual void OnTick(float dt) {} + virtual void OnDraw() {} + + virtual void OnMouseMove(int x, int y, int dx, int dy) {} + virtual void OnMouseDown(int x, int y, unsigned button) {} + virtual void OnMouseUp(int x, int y, unsigned button) {} + virtual void OnMouseWheel(int x, int y, int d) {} + virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {} + virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {} + + private: + std::vector<Component*> Components; + Component* focusedComponent_; + + }; + +} diff --git a/includes/interface/Window.h b/includes/interface/Window.h deleted file mode 100644 index 86a4bcd..0000000 --- a/includes/interface/Window.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Window.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef WINDOW_H_ -#define WINDOW_H_ - -#include "interface/State.h" - -namespace ui { - -class Window: public ui::State { -public: - Window(); - virtual ~Window(); -}; - -} /* namespace ui */ -#endif /* WINDOW_H_ */ |
