And then Microsoft happened...

This commit is contained in:
2014-05-15 21:44:33 +02:00
parent 6684aa06b7
commit 9723d80742
4 changed files with 179 additions and 183 deletions
+75 -75
View File
@@ -1,75 +1,75 @@
//#ifndef GUI_Frame_h__
//#define GUI_Frame_h__
//
//#include <memory>
//
//#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<Frame> parent)
// : Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
// { SetParent(parent); Initialize(); }
//
// virtual void Initialize() { }
// std::shared_ptr<Frame> Parent() const { return m_Parent; }
// void SetParent(std::shared_ptr<Frame> parent)
// {
// parent->AddChild(std::shared_ptr<Frame>(this));
// m_Parent = parent;
// EventBroker = parent->EventBroker;
// }
//
// void AddChild(std::shared_ptr<Frame> child)
// {
// m_Children.push_back(child);
// if (m_Parent != nullptr)
// {
// m_Parent->AddChild(child);
// }
// }
//
// typedef std::list<std::shared_ptr<Frame>>::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<Frame> m_Parent;
// std::list<std::shared_ptr<Frame>> m_Children;
//};
//
//}
//
//#endif // GUI_Frame_h__
#ifndef GUI_Frame_h__
#define GUI_Frame_h__
#include <memory>
#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<Frame> parent)
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
{ SetParent(parent); Initialize(); }
virtual void Initialize() { }
std::shared_ptr<Frame> Parent() const { return m_Parent; }
void SetParent(std::shared_ptr<Frame> parent)
{
parent->AddChild(std::shared_ptr<Frame>(this));
m_Parent = parent;
EventBroker = parent->EventBroker;
}
void AddChild(std::shared_ptr<Frame> child)
{
m_Children.push_back(child);
if (m_Parent != nullptr)
{
m_Parent->AddChild(child);
}
}
typedef std::list<std::shared_ptr<Frame>>::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<Frame> m_Parent;
std::list<std::shared_ptr<Frame>> m_Children;
};
}
#endif // GUI_Frame_h__
+3 -2
View File
@@ -1,5 +1,6 @@
#include "PrecompiledHeader.h"
#include "InputManager.h"
#include <XInput.h>
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.
+6 -11
View File
@@ -3,13 +3,6 @@
#include <array>
namespace Windows
{
#include <Xinput.h>
#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<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState;
typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState;
std::array<GamepadAxisState, XUSER_MAX_COUNT> m_CurrentGamepadAxisState;
std::array<GamepadAxisState, XUSER_MAX_COUNT> m_LastGamepadAxisState;
std::array<GamepadAxisState, MAX_GAMEPADS> m_CurrentGamepadAxisState;
std::array<GamepadAxisState, MAX_GAMEPADS> m_LastGamepadAxisState;
typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState;
std::array<GamepadButtonState, XUSER_MAX_COUNT> m_CurrentGamepadButtonState;
std::array<GamepadButtonState, XUSER_MAX_COUNT> m_LastGamepadButtonState;
std::array<GamepadButtonState, MAX_GAMEPADS> m_CurrentGamepadButtonState;
std::array<GamepadButtonState, MAX_GAMEPADS> m_LastGamepadButtonState;
double m_CurrentMouseX, m_CurrentMouseY;
double m_LastMouseX, m_LastMouseY;
+95 -95
View File
@@ -1,95 +1,95 @@
//#ifndef Util_Rectangle_h__
//#define Util_Rectangle_h__
//
//#include <algorithm>
//
//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 <algorithm>
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__