diff options
Diffstat (limited to 'includes/interface')
| -rw-r--r-- | includes/interface/Button.h | 51 | ||||
| -rw-r--r-- | includes/interface/Component.h | 204 | ||||
| -rw-r--r-- | includes/interface/ControlFactory.h | 14 | ||||
| -rw-r--r-- | includes/interface/Engine.h | 64 | ||||
| -rw-r--r-- | includes/interface/Label.h | 26 | ||||
| -rw-r--r-- | includes/interface/Panel.h | 136 | ||||
| -rw-r--r-- | includes/interface/Platform.h | 108 | ||||
| -rw-r--r-- | includes/interface/Point.h | 136 | ||||
| -rw-r--r-- | includes/interface/Sandbox.h | 39 | ||||
| -rw-r--r-- | includes/interface/State.h | 77 |
10 files changed, 0 insertions, 855 deletions
diff --git a/includes/interface/Button.h b/includes/interface/Button.h deleted file mode 100644 index 9046ea1..0000000 --- a/includes/interface/Button.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Button.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef BUTTON_H_ -#define BUTTON_H_ - -#include <string> - -#include "Component.h" - -namespace ui -{ - class Button : public Component - { - public: - Button(State* parent_state, std::string buttonText); - - Button(Point position, Point size, std::string buttonText); - - Button(std::string buttonText); - virtual ~Button(); - - bool Toggleable; - - std::string ButtonText; - - 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 OnMouseEnter(int x, int y); - virtual void OnMouseLeave(int x, int y); - - virtual void Draw(const Point& screenPos); - - inline bool GetState() { return state; } - virtual void DoAction(); //action of button what ever it may be - void SetTogglable(bool isTogglable); - bool GetTogglable(); - inline bool GetToggleState(); - inline void SetToggleState(bool state); - - protected: - bool isButtonDown, state, isMouseInside, isTogglable, toggle; - }; -} -#endif /* BUTTON_H_ */ diff --git a/includes/interface/Component.h b/includes/interface/Component.h deleted file mode 100644 index 5759c08..0000000 --- a/includes/interface/Component.h +++ /dev/null @@ -1,204 +0,0 @@ -#pragma once - -#include "Point.h" -#include "State.h" -#include "Platform.h" - -namespace ui -{ - 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(State* parent_state); - Component(Point position, Point size); - Component(); - virtual ~Component(); - - void* UserData; - inline State* const GetParentState() const { return parentstate_; } - bool IsFocused() const; - - Point Position; - Point Size; - bool Locked; - bool Visible; - - /* 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); - */ - - /// - // 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); - - /// - // 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); - - /// - // 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); - - private: - State* parentstate_; - Panel* _parent; - }; -} diff --git a/includes/interface/ControlFactory.h b/includes/interface/ControlFactory.h deleted file mode 100644 index 0f8ad61..0000000 --- a/includes/interface/ControlFactory.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef CONTROLFACTORY_H -#define CONTROLFACTORY_H - -#include "Panel.h" -#include "Engine.h" - -class ControlFactory -{ -public: - static ui::Panel * MainMenu(int x, int y, int width, int height); - -}; - -#endif // CONTROLFACTORY_H diff --git a/includes/interface/Engine.h b/includes/interface/Engine.h deleted file mode 100644 index 6136fb4..0000000 --- a/includes/interface/Engine.h +++ /dev/null @@ -1,64 +0,0 @@ -#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); - 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_; } - float FpsLimit; - 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 deleted file mode 100644 index 2168956..0000000 --- a/includes/interface/Label.h +++ /dev/null @@ -1,26 +0,0 @@ -#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 deleted file mode 100644 index 7c9adab..0000000 --- a/includes/interface/Panel.h +++ /dev/null @@ -1,136 +0,0 @@ -#pragma once -#include <vector> -//#include "Platform.h" - -#include "interface/Point.h" -#include "interface/State.h" -#include "interface/Component.h" - -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; - - 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); - }; - -} diff --git a/includes/interface/Platform.h b/includes/interface/Platform.h deleted file mode 100644 index c57dca6..0000000 --- a/includes/interface/Platform.h +++ /dev/null @@ -1,108 +0,0 @@ -#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 deleted file mode 100644 index 0d0250c..0000000 --- a/includes/interface/Point.h +++ /dev/null @@ -1,136 +0,0 @@ -#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 deleted file mode 100644 index fb4a668..0000000 --- a/includes/interface/Sandbox.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Sandbox.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef SANDBOX_H_ -#define SANDBOX_H_ - -#include <queue> -#include "Point.h" -#include "Component.h" -#include "Simulation.h" -#include "Renderer.h" - -namespace ui { - -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 OnMouseMoved(int localx, int localy, int dx, int dy); - virtual void OnMouseClick(int localx, int localy, unsigned int button); - virtual void OnMouseUp(int localx, int localy, unsigned int button); - virtual void Draw(const Point& screenPos); - virtual void Tick(float delta); - virtual ~Sandbox(); -}; - -} /* namespace ui */ -#endif /* SANDBOX_H_ */ diff --git a/includes/interface/State.h b/includes/interface/State.h deleted file mode 100644 index 75e969d..0000000 --- a/includes/interface/State.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -#include <vector> - -#include "Engine.h" -#include "Component.h" -#include "Platform.h" - -namespace ui -{ - 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_; - - }; - -} |
