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/State.h | |
| parent | fc2f52099c0bbb2412046252bf7b5e4113bbe8e4 (diff) | |
| download | powder-2c9295007a287dc01ff63fcf7b3da141f7474e37.zip powder-2c9295007a287dc01ff63fcf7b3da141f7474e37.tar.gz | |
Various things, also IEF UI
Diffstat (limited to 'includes/interface/State.h')
| -rw-r--r-- | includes/interface/State.h | 128 |
1 files changed, 72 insertions, 56 deletions
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_; + + }; + +} |
