diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index d587bbe..628a650 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -1,75 +1,75 @@ -//#ifndef GUI_Frame_h__ -//#define GUI_Frame_h__ -// -//#include -// -//#include "Util/Rectangle.h" -//#include "EventBroker.h" -// -//// HACK: Decouple renderer plz -//#include "Renderer.h" -// -//namespace GUI -//{ -// -//class Frame : public Rectangle -//{ -//public: -// enum class Anchor -// { -// Left, -// Right, -// Top, -// Bottom -// }; -// -// // Set up a base frame with an event broker -// Frame(std::shared_ptr<::EventBroker> eventBroker) -// : EventBroker(eventBroker) -// , Rectangle() -// { Initialize(); } -// // Create a frame as a child -// Frame(std::shared_ptr parent) -// : Rectangle(static_cast(*parent)) // Clone parent rectangle using copy constructor -// { SetParent(parent); Initialize(); } -// -// virtual void Initialize() { } -// std::shared_ptr Parent() const { return m_Parent; } -// void SetParent(std::shared_ptr parent) -// { -// parent->AddChild(std::shared_ptr(this)); -// m_Parent = parent; -// EventBroker = parent->EventBroker; -// } -// -// void AddChild(std::shared_ptr child) -// { -// m_Children.push_back(child); -// if (m_Parent != nullptr) -// { -// m_Parent->AddChild(child); -// } -// } -// -// typedef std::list>::const_iterator FrameChildrenIterator; -// FrameChildrenIterator begin() -// { -// return m_Children.begin(); -// } -// FrameChildrenIterator end() -// { -// return m_Children.end(); -// } -// -// virtual void Update(double dt) { } -// virtual void Draw(Renderer* renderer) { } -// -//protected: -// std::shared_ptr<::EventBroker> EventBroker; -// std::shared_ptr m_Parent; -// std::list> m_Children; -//}; -// -//} -// -//#endif // GUI_Frame_h__ +#ifndef GUI_Frame_h__ +#define GUI_Frame_h__ + +#include + +#include "Util/Rectangle.h" +#include "EventBroker.h" + +// HACK: Decouple renderer plz +#include "Renderer.h" + +namespace GUI +{ + +class Frame : public Rectangle +{ +public: + enum class Anchor + { + Left, + Right, + Top, + Bottom + }; + + // Set up a base frame with an event broker + Frame(std::shared_ptr<::EventBroker> eventBroker) + : EventBroker(eventBroker) + , Rectangle() + { Initialize(); } + // Create a frame as a child + Frame(std::shared_ptr parent) + : Rectangle(static_cast(*parent)) // Clone parent rectangle using copy constructor + { SetParent(parent); Initialize(); } + + virtual void Initialize() { } + std::shared_ptr Parent() const { return m_Parent; } + void SetParent(std::shared_ptr parent) + { + parent->AddChild(std::shared_ptr(this)); + m_Parent = parent; + EventBroker = parent->EventBroker; + } + + void AddChild(std::shared_ptr child) + { + m_Children.push_back(child); + if (m_Parent != nullptr) + { + m_Parent->AddChild(child); + } + } + + typedef std::list>::const_iterator FrameChildrenIterator; + FrameChildrenIterator begin() + { + return m_Children.begin(); + } + FrameChildrenIterator end() + { + return m_Children.end(); + } + + virtual void Update(double dt) { } + virtual void Draw(Renderer* renderer) { } + +protected: + std::shared_ptr<::EventBroker> EventBroker; + std::shared_ptr m_Parent; + std::list> m_Children; +}; + +} + +#endif // GUI_Frame_h__ diff --git a/src/InputManager.cpp b/src/InputManager.cpp index ea22d96..00ae7be 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -1,5 +1,6 @@ #include "PrecompiledHeader.h" #include "InputManager.h" +#include void InputManager::Initialize() { @@ -97,9 +98,9 @@ void InputManager::Update(double dt) // } // Xbox360 controller - using namespace Windows; + //using namespace ; DWORD dwResult; - for (int i = 0; i < XUSER_MAX_COUNT; i++) + for (int i = 0; i < MAX_GAMEPADS; i++) { XINPUT_STATE state = { 0 }; // Simply get the state of the controller from XInput. diff --git a/src/InputManager.h b/src/InputManager.h index 189430f..104d2b4 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -3,13 +3,6 @@ #include -namespace Windows -{ -#include -#undef min -#undef max -} - #include "EventBroker.h" #include "Events/KeyDown.h" #include "Events/KeyUp.h" @@ -36,6 +29,8 @@ public: void Initialize(); + static const short MAX_GAMEPADS = 4; + void Update(double dt); private: @@ -47,11 +42,11 @@ private: std::array m_CurrentMouseState; std::array m_LastMouseState; typedef std::array(Gamepad::Axis::LAST) + 1> GamepadAxisState; - std::array m_CurrentGamepadAxisState; - std::array m_LastGamepadAxisState; + std::array m_CurrentGamepadAxisState; + std::array m_LastGamepadAxisState; typedef std::array(Gamepad::Button::LAST) + 1> GamepadButtonState; - std::array m_CurrentGamepadButtonState; - std::array m_LastGamepadButtonState; + std::array m_CurrentGamepadButtonState; + std::array m_LastGamepadButtonState; double m_CurrentMouseX, m_CurrentMouseY; double m_LastMouseX, m_LastMouseY; diff --git a/src/Util/Rectangle.h b/src/Util/Rectangle.h index e55e268..0d0db32 100644 --- a/src/Util/Rectangle.h +++ b/src/Util/Rectangle.h @@ -1,95 +1,95 @@ -//#ifndef Util_Rectangle_h__ -//#define Util_Rectangle_h__ -// -//#include -// -//struct Rectangle -//{ -// Rectangle() -// : X(0), Y(0), Width(0), Height(0) { } -// -// Rectangle(int x, int y, int width = 0, int height = 0) -// : X(x), Y(y), Width(width), Height(height) { } -// -// /*Rectangle(const Rectangle &rect) -// : X(rect.X), Y(rect.Y), Width(rect.Width), Height(rect.Height) { }*/ -// -// int X; -// int Y; -// int Width; -// int Height; -// -// const int& GetLeft() const { return X; } -// void SetLeft(int left) -// { -// Width += X - left; -// X = left; -// } -// int GetRight() const { return X + Width; } -// void SetRight(int right) -// { -// Width = right - X; -// } -// const int& GetTop() const { return Y; } -// void SetTop(int top) -// { -// Height += Y - top; -// Y = top; -// } -// int GetBottom() const { return Y + Height; } -// int SetBottom(int bottom) -// { -// Height = bottom - Y; -// } -// -// Rectangle& operator+=(const Rectangle &rhs) -// { -// SetLeft(std::min(GetLeft(), rhs.GetLeft())); -// SetRight(std::max(GetRight(), rhs.GetRight())); -// SetTop(std::min(GetTop(), rhs.GetTop())); -// SetBottom(std::max(GetBottom(), rhs.GetBottom())); -// } -// -// static bool Intersects(const Rectangle &r1, const Rectangle &r2) -// { -// return !(r2.GetLeft() > r1.GetRight() || r2.GetRight() < r1.GetLeft() || r2.GetTop() > r1.GetBottom() || r2.GetBottom() < r1.GetTop()); -// } -//}; -// -//inline bool operator==(const Rectangle &r1, const Rectangle &r2) -//{ -// return (r1.X == r2.X) && (r1.Y == r2.Y) && (r1.Width == r2.Width) && (r1.Height == r2.Height); -//} -// -//inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs) -//{ -// return !(lhs == rhs); -//} -// -//inline bool operator<(const Rectangle &lhs, const Rectangle &rhs) -//{ -// return (lhs.Width < rhs.Width) && (lhs.Height < rhs.Height); -//} -// -//inline bool operator>(const Rectangle &lhs, const Rectangle &rhs) -//{ -// return rhs < lhs; -//} -// -//inline bool operator<=(const Rectangle &lhs, const Rectangle &rhs) -//{ -// return !(lhs > rhs); -//} -// -//inline bool operator>=(const Rectangle &lhs, const Rectangle &rhs) -//{ -// return !(lhs < rhs); -//} -// -//inline Rectangle operator+(Rectangle lhs, const Rectangle &rhs) -//{ -// lhs += rhs; -// return lhs; -//} -// -//#endif // Util_Rectangle_h__ +#ifndef Util_Rectangle_h__ +#define Util_Rectangle_h__ + +#include + +struct Rectangle +{ + Rectangle() + : X(0), Y(0), Width(0), Height(0) { } + + Rectangle(int x, int y, int width = 0, int height = 0) + : X(x), Y(y), Width(width), Height(height) { } + + /*Rectangle(const Rectangle &rect) + : X(rect.X), Y(rect.Y), Width(rect.Width), Height(rect.Height) { }*/ + + int X; + int Y; + int Width; + int Height; + + const int& GetLeft() const { return X; } + void SetLeft(int left) + { + Width += X - left; + X = left; + } + int GetRight() const { return X + Width; } + void SetRight(int right) + { + Width = right - X; + } + const int& GetTop() const { return Y; } + void SetTop(int top) + { + Height += Y - top; + Y = top; + } + int GetBottom() const { return Y + Height; } + int SetBottom(int bottom) + { + Height = bottom - Y; + } + + Rectangle& operator+=(const Rectangle &rhs) + { + SetLeft(std::min(GetLeft(), rhs.GetLeft())); + SetRight(std::max(GetRight(), rhs.GetRight())); + SetTop(std::min(GetTop(), rhs.GetTop())); + SetBottom(std::max(GetBottom(), rhs.GetBottom())); + } + + static bool Intersects(const Rectangle &r1, const Rectangle &r2) + { + return !(r2.GetLeft() > r1.GetRight() || r2.GetRight() < r1.GetLeft() || r2.GetTop() > r1.GetBottom() || r2.GetBottom() < r1.GetTop()); + } +}; + +inline bool operator==(const Rectangle &r1, const Rectangle &r2) +{ + return (r1.X == r2.X) && (r1.Y == r2.Y) && (r1.Width == r2.Width) && (r1.Height == r2.Height); +} + +inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs) +{ + return !(lhs == rhs); +} + +inline bool operator<(const Rectangle &lhs, const Rectangle &rhs) +{ + return (lhs.Width < rhs.Width) && (lhs.Height < rhs.Height); +} + +inline bool operator>(const Rectangle &lhs, const Rectangle &rhs) +{ + return rhs < lhs; +} + +inline bool operator<=(const Rectangle &lhs, const Rectangle &rhs) +{ + return !(lhs > rhs); +} + +inline bool operator>=(const Rectangle &lhs, const Rectangle &rhs) +{ + return !(lhs < rhs); +} + +inline Rectangle operator+(Rectangle lhs, const Rectangle &rhs) +{ + lhs += rhs; + return lhs; +} + +#endif // Util_Rectangle_h__