diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-08 17:39:03 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-08 17:39:03 (GMT) |
| commit | b0ea52690ba56a0d0602ad8674b7e5ab2ba3e778 (patch) | |
| tree | 7d72e0509f4d2643d3be837a337d088ca5949c73 /includes/interface | |
| download | powder-b0ea52690ba56a0d0602ad8674b7e5ab2ba3e778.zip powder-b0ea52690ba56a0d0602ad8674b7e5ab2ba3e778.tar.gz | |
Initial
Diffstat (limited to 'includes/interface')
| -rw-r--r-- | includes/interface/Button.h | 42 | ||||
| -rw-r--r-- | includes/interface/Component.h | 53 | ||||
| -rw-r--r-- | includes/interface/Panel.h | 22 | ||||
| -rw-r--r-- | includes/interface/Sandbox.h | 33 | ||||
| -rw-r--r-- | includes/interface/State.h | 61 | ||||
| -rw-r--r-- | includes/interface/Window.h | 22 |
6 files changed, 233 insertions, 0 deletions
diff --git a/includes/interface/Button.h b/includes/interface/Button.h new file mode 100644 index 0000000..1b2900e --- /dev/null +++ b/includes/interface/Button.h @@ -0,0 +1,42 @@ +/* + * 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(int x, int y, int width, int height, const std::string& buttonText); + + 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, int dx, int dy); + virtual void OnMouseLeave(int x, int y, int dx, int dy); + + virtual void Draw(void* userdata); + + inline bool GetState() { return state; } + virtual void DoAction(); //action of button what ever it may be + + protected: + bool isButtonDown, state, isMouseInside; + }; +} +#endif /* BUTTON_H_ */ diff --git a/includes/interface/Component.h b/includes/interface/Component.h new file mode 100644 index 0000000..a4d02db --- /dev/null +++ b/includes/interface/Component.h @@ -0,0 +1,53 @@ +/* + * Component.h + * + * Created on: Jan 8, 2012 + * Author: Simon + */ + +#ifndef COMPONENT_H_ +#define COMPONENT_H_ + +namespace ui +{ + class State; + + class Component + { + public: + Component(int x, int y, int width, int height); + virtual ~Component(); + + 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; + bool Visible; + bool Enabled; + int Width; + int Height; + int X; + int Y; + + virtual void Tick(float dt); + virtual void Draw(void* userdata); + + virtual void OnMouseEnter(int localx, int localy, int dx, int dy); + virtual void OnMouseLeave(int localx, int localy, int dx, int dy); + virtual void OnMouseMoved(int localx, int localy, int dx, int dy); + 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); + virtual void OnMouseWheel(int localx, int localy, int d); + virtual void OnMouseWheelInside(int localx, int localy, int d); + virtual void OnMouseWheelFocused(int localx, int localy, int d); + virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); + + State* Parent; + }; +} +#endif /* COMPONENT_H_ */ diff --git a/includes/interface/Panel.h b/includes/interface/Panel.h new file mode 100644 index 0000000..9549ff4 --- /dev/null +++ b/includes/interface/Panel.h @@ -0,0 +1,22 @@ +/* + * Panel.h + * + * Created on: Jan 8, 2012 + * Author: Simon + */ + +#ifndef PANEL_H_ +#define PANEL_H_ + +#include "interface/Component.h" + +namespace ui { + +class Panel: public ui::Component { +public: + Panel(int x, int y, int width, int height); + virtual ~Panel(); +}; + +} /* namespace ui */ +#endif /* PANEL_H_ */ diff --git a/includes/interface/Sandbox.h b/includes/interface/Sandbox.h new file mode 100644 index 0000000..10d588f --- /dev/null +++ b/includes/interface/Sandbox.h @@ -0,0 +1,33 @@ +/* + * Sandbox.h + * + * Created on: Jan 8, 2012 + * Author: Simon + */ + +#ifndef SANDBOX_H_ +#define SANDBOX_H_ + +#include "Component.h" +#include "Simulation.h" +#include "Renderer.h" + +namespace ui { + +class Sandbox: public ui::Component { +private: + bool isMouseDown; + Renderer * ren; + Simulation * sim; +public: + Sandbox(); + 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 Tick(float delta); + virtual ~Sandbox(); +}; + +} /* namespace ui */ +#endif /* SANDBOX_H_ */ diff --git a/includes/interface/State.h b/includes/interface/State.h new file mode 100644 index 0000000..00df199 --- /dev/null +++ b/includes/interface/State.h @@ -0,0 +1,61 @@ +/* + * State.h + * + * Created on: Jan 8, 2012 + * Author: Simon + */ + +#ifndef STATE_H_ +#define STATE_H_ + +#include <vector> + +#include "interface/Component.h" + +namespace ui { + +class State +{ +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_ */ diff --git a/includes/interface/Window.h b/includes/interface/Window.h new file mode 100644 index 0000000..86a4bcd --- /dev/null +++ b/includes/interface/Window.h @@ -0,0 +1,22 @@ +/* + * 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_ */ |
