mikymod 12 лет назад
Родитель
Сommit
271d60a97d

+ 0 - 260
src/os/win/WGLRenderWindow.cpp

@@ -1,260 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "WGLRenderWindow.h"
-#include "Types.h"
-#include "Log.h"
-#include "resources.h"
-
-namespace crown
-{
-
-char WGLRenderWindow::mWindowClassName[20] = "";
-
-WGLRenderWindow::WGLRenderWindow() :
-	mWindowHandle(0),
-	mRC(0),
-	mDC(0),
-	mCreated(false)
-{
-}
-
-WGLRenderWindow::~WGLRenderWindow()
-{
-	if (mRC)
-	{
-		wglMakeCurrent(NULL, NULL);
-		wglDeleteContext(mRC);
-	}
-
-	if (mWindowHandle)
-	{
-		::DestroyWindow(mWindowHandle);
-	}
-}
-
-bool WGLRenderWindow::Create(uint32_t x, uint32_t y, uint32_t width, uint32_t height,
-							 uint32_t depth, bool fullscreen)
-{
-	if (!width || !height)
-	{
-		Log::E("Width and height must differ from 0.");
-		return false;
-	}
-
-	if (fullscreen)
-	{
-		DEVMODE dmScreenSettings; // Device Mode
-		memset(&dmScreenSettings, 0, sizeof (dmScreenSettings)); // Makes Sure Memory's Cleared
-		dmScreenSettings.dmSize = sizeof (dmScreenSettings); // Size Of The Devmode Structure
-		dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
-		dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
-		dmScreenSettings.dmBitsPerPel = 32; // Selected Bits Per Pixel
-		dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
-
-		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
-		if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
-		{
-			fullscreen = false;
-			Log::I("Fullscreen resolution not supported, switching to windowed mode.");
-		}
-	}
-
-	strcpy(mWindowClassName, "CrownWindowClass");
-	WNDCLASSEX wcex;
-	wcex.cbSize = sizeof (WNDCLASSEX);
-	wcex.style = CS_OWNDC;
-	wcex.lpfnWndProc = (WNDPROC) DefWindowProc;
-	wcex.cbClsExtra = 0;
-	wcex.cbWndExtra = 0;
-	wcex.hInstance = GetModuleHandle(NULL);
-	wcex.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
-	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
-	wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
-	wcex.lpszMenuName = NULL;
-	wcex.lpszClassName = mWindowClassName;
-	wcex.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
-
-	if (!RegisterClassEx(&wcex))
-	{
-		Log::E("Unable to register a Window Class.");
-		return false;
-	}
-
-	if (fullscreen)
-	{
-		mWindowHandle = CreateWindowEx(0, mWindowClassName, "", WS_POPUP, 0, 0, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
-	}
-	else
-	{
-		mWindowHandle = CreateWindowEx(0, mWindowClassName, "", WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX, x, y, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
-	}
-
-	if (mWindowHandle == NULL)
-	{
-		Log::E("Unable to create a Window.");
-		return false;
-	}
-
-	//Save the WGLRenderWindow point32_ter to the window's user data
-	SetWindowLong(mWindowHandle, GWL_USERDATA, (LONG) this);
-	RECT rc;
-	rc.left = rc.top = 0;
-	rc.right = width;
-	rc.bottom = height;
-	int32_t style, styleEx;
-	style = GetWindowLong(mWindowHandle, GWL_STYLE);
-	styleEx = GetWindowLong(mWindowHandle, GWL_EXSTYLE);
-	AdjustWindowRectEx(&rc, style, false, styleEx);
-	SetWindowPos(mWindowHandle, 0, 0, 0, rc.right-rc.left, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
-	PIXELFORMATDESCRIPTOR pfd;
-	int32_t iFormat;
-	/* get the device context (DC) */
-	mDC = GetDC(mWindowHandle);
-	/* set the pixel format for the DC */
-	ZeroMemory(&pfd, sizeof (pfd));
-	pfd.nSize = sizeof (pfd);
-	pfd.nVersion = 1;
-	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
-	pfd.iPixelType = PFD_TYPE_RGBA;
-	pfd.cColorBits = 24;
-	pfd.cDepthBits = depth;
-	pfd.iLayerType = PFD_MAIN_PLANE;
-	iFormat = ChoosePixelFormat(mDC, &pfd);
-
-	if (iFormat == 0)
-	{
-		Log::E("Pixel format not supported.");
-		return false;
-	}
-
-	if (!SetPixelFormat(mDC, iFormat, &pfd))
-	{
-		Log::E("Unable to set the pixel format, altough it seems to be supported.");
-		return false;
-	}
-
-	mRC = wglCreateContext(mDC);
-
-
-	if (mRC == NULL)
-	{
-		Log::E("Unable to create a rendering context.");
-		return false;
-	}
-
-	wglMakeCurrent(mDC, mRC);
-
-	mFull = fullscreen;
-	mX = x;
-	mY = y;
-	mWidth = width;
-	mHeight = height;
-	mCreated = true;
-	SetVisible(true);
-	//GetDevice()->GetRenderer()->ResizeRenderTarget(width, height);
-	return true;
-}
-
-void WGLRenderWindow::Destroy()
-{
-	if (!mCreated)
-	{
-		return;
-	}
-
-	mCreated = false;
-}
-
-void WGLRenderWindow::SetVisible(bool visible)
-{
-	if (visible)
-	{
-		ShowWindow(mWindowHandle, SW_SHOW);
-	}
-	else
-	{
-		ShowWindow(mWindowHandle, SW_HIDE);
-	}
-}
-
-void WGLRenderWindow::Move(uint32_t x, uint32_t y)
-{
-	SetWindowPos(mWindowHandle, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
-}
-
-void WGLRenderWindow::Resize(uint32_t width, uint32_t height)
-{
-	SetWindowPos(mWindowHandle, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
-}
-
-void WGLRenderWindow::SetFullscreen(bool full)
-{
-}
-
-void WGLRenderWindow::_SetTitleAndAdditionalTextToWindow()
-{
-	SetWindowText(mWindowHandle, GetDisplayedTitle().c_str());
-}
-
-void WGLRenderWindow::EventLoop()
-{
-	//The ultimate lamer trick: do the event loop filtering out the mouse and keyboard events by doing sequential calls with int32_tervals
-	EventLoopDo(0, 0);
-	//EventLoopDo(1, WM_KEYFIRST-1);
-	//EventLoopDo(WM_KEYFIRST, WM_KEYLAST);
-	//EventLoopDo(WM_KEYLAST+1, WM_MOUSEFIRST-1);
-	//EventLoopDo(WM_MOUSEFIRST, WM_MOUSELAST);
-	//EventLoopDo(WM_MOUSELAST+1, WM_USER);
-}
-
-void WGLRenderWindow::EventLoopDo(unsigned int32_t minMsg, unsigned int32_t maxMsg)
-{
-	MSG msg;
-	while (PeekMessage(&msg, mWindowHandle, minMsg, maxMsg, PM_REMOVE))
-	{
-		TranslateMessage(&msg);
-		DispatchMessage(&msg);
-	}
-}
-
-void WGLRenderWindow::Bind()
-{
-	wglMakeCurrent(mDC, mRC);
-}
-
-void WGLRenderWindow::Unbind()
-{
-	wglMakeCurrent(NULL, NULL);
-}
-
-void WGLRenderWindow::Update()
-{
-	SwapBuffers(mDC);
-}
-
-} // namespace crown
-

+ 0 - 104
src/os/win/WGLRenderWindow.h

@@ -1,104 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <windows.h>
-#include "RenderWindow.h"
-#include "Types.h"
-
-namespace crown
-{
-
-class WGLRenderWindow : public RenderWindow
-{
-
-public:
-
-	//! Constructor
-	WGLRenderWindow();
-
-	//! Destructor
-	~WGLRenderWindow();
-
-	//! Creates the window
-	virtual bool Create(uint32_t x, uint32_t y, uint32_t width, uint32_t height,
-						uint32_t depth, bool fullscreen);
-
-	//! Destroys the window
-	virtual void Destroy();
-
-	//! Sets whether the window is visible
-	virtual void SetVisible(bool visible);
-
-	//! Sets the window's position
-	virtual void Move(uint32_t x, uint32_t y);
-
-	//! Sets the window's width and height
-	virtual void Resize(uint32_t width, uint32_t height);
-
-	//! Sets whether the window is in fullscreen mode
-	virtual void SetFullscreen(bool full);
-
-	virtual void Bind();
-
-	virtual void Unbind();
-
-	//! Updates the window's content
-	virtual void Update();
-
-	//! Manages basic window's events
-	virtual void EventLoop();
-
-	//! Returns the associated X Window
-	HWND GetWindowHandle() const
-	{
-		return mWindowHandle;
-	}
-
-	HDC GetDrawingContext() const
-	{
-		return mDC;
-	}
-
-private:
-
-	HWND mWindowHandle;
-	HGLRC mRC;
-	HDC mDC;
-
-	bool mCreated;
-
-	//! Sets the window's title plus the additional title text in the window
-	virtual void _SetTitleAndAdditionalTextToWindow();
-
-	static char mWindowClassName[20];
-
-	void EventLoopDo(unsigned int32_t minMsg, unsigned int32_t maxMsg);
-};
-
-} // namespace crown
-

+ 0 - 203
src/os/win/WinKeyboard.cpp

@@ -1,203 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "WinKeyboard.h"
-#include "Exceptions.h"
-#include "WinInputManager.h"
-
-// Undef functions to avoid conflicts
-#undef MK_SHIFT
-#undef MK_ALT
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-WinKeyboard::WinKeyboard(InputManager* creator) :
-	Keyboard(creator),
-	mModifierMask(0),
-	mWindowHandle(0)
-{
-	for (int32_t i = 0; i < MAX_KEYCODES; i++)
-	{
-		mKeyState[i] = false;
-	}
-
-	if (mCreator)
-	{
-		mWindowHandle = (HWND)(static_cast<WinInputManager*>(mCreator)->GetWindowHandle());
-	}
-
-	static_cast<WinInputManager*>(mCreator)->SetKeyboardAvailable(true);
-}
-
-//-----------------------------------------------------------------------------
-WinKeyboard::~WinKeyboard()
-{
-	if (mCreator)
-	{
-		static_cast<WinInputManager*>(mCreator)->SetKeyboardAvailable(false);
-	}
-}
-
-//-----------------------------------------------------------------------------
-bool WinKeyboard::IsModifierPressed(ModifierKey modifier) const
-{
-	return (mModifierMask & modifier) == modifier;
-}
-
-//-----------------------------------------------------------------------------
-bool WinKeyboard::IsKeyPressed(KeyCode key) const
-{
-	return mKeyState[key] == true;
-}
-
-//-----------------------------------------------------------------------------
-bool WinKeyboard::IsKeyReleased(KeyCode key) const
-{
-	return mKeyState[key] == false;
-}
-
-//-----------------------------------------------------------------------------
-void WinKeyboard::EventLoop()
-{
-	MSG msg;
-	while (PeekMessage(&msg, mWindowHandle, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
-	{
-		TranslateMessage(&msg);
-		DispatchMessage(&msg);
-
-		switch (msg.message)
-		{
-			case WM_KEYDOWN:
-			case WM_KEYUP:
-			{
-				KeyboardEvent keyboardEvent;
-				Key kc = TranslateKey(msg.wParam);
-
-				// Check if any modifier key is pressed or released
-				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
-				{
-					(msg.message == WM_KEYDOWN) ? mModifierMask |= MK_SHIFT : mModifierMask &= ~MK_SHIFT;
-				}
-				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
-				{
-					(msg.message == WM_KEYDOWN) ? mModifierMask |= MK_CTRL : mModifierMask &= ~MK_CTRL;
-				}
-				else if (kc == KC_LALT || kc == KC_RALT)
-				{
-					(msg.message == WM_KEYDOWN) ? mModifierMask |= MK_ALT : mModifierMask &= ~MK_ALT;
-				}
-
-				mKeyState[kc] = (msg.message == WM_KEYDOWN) ? true : false;
-				keyboardEvent.key = kc;
-
-				if (mListener)
-				{
-					if (msg.message == WM_KEYDOWN)
-					{
-						mListener->KeyPressed(keyboardEvent);
-					}
-					else if (msg.message == WM_KEYUP)
-					{
-						mListener->KeyReleased(keyboardEvent);
-					}
-				}
-			}break;
-			case WM_CHAR:
-			{
-				KeyboardEvent keyboardEvent;
-				keyboardEvent.text[0] = msg.wParam;
-				keyboardEvent.text[1] = '\0';
-
-				if (mListener)
-				{
-					mListener->TextInput(keyboardEvent);
-				}
-			}break;
-		}
-	}
-}
-
-//-----------------------------------------------------------------------------
-Key WinKeyboard::TranslateKey(int32_t winKey)
-{
-	if ((winKey > 0x40 && winKey < 0x5B) || (winKey > 0x60 && winKey < 0x7B) || (winKey > 0x2F && winKey < 0x3A))
-	{
-		return (Key)winKey;
-	}
-
-	switch (winKey)
-	{
-		case VK_BACK:		return KC_BACKSPACE;
-		case VK_TAB:		return KC_TAB;
-		case VK_SPACE:		return KC_SPACE;
-		case VK_ESCAPE:		return KC_ESCAPE;
-		case VK_RETURN:		return KC_ENTER;
-		case VK_F1:			return KC_F1;
-		case VK_F2:			return KC_F2;
-		case VK_F3:			return KC_F3;
-		case VK_F4:			return KC_F4;
-		case VK_F5:			return KC_F5;
-		case VK_F6:			return KC_F6;
-		case VK_F7:			return KC_F7;
-		case VK_F8:			return KC_F8;
-		case VK_F9:			return KC_F9;
-		case VK_F10:		return KC_F10;
-		case VK_F11:		return KC_F11;
-		case VK_F12:		return KC_F12;
-		case VK_HOME:		return KC_HOME;
-		case VK_LEFT:		return KC_LEFT;
-		case VK_UP:			return KC_UP;
-		case VK_RIGHT:		return KC_RIGHT;
-		case VK_DOWN:		return KC_DOWN;
-		case VK_PRIOR:		return KC_PAGE_UP;
-		case VK_NEXT:		return KC_PAGE_DOWN;
-		case VK_LSHIFT:		return KC_LSHIFT;
-		case VK_RSHIFT:		return KC_RSHIFT;
-		case VK_LCONTROL:	return KC_LCONTROL;
-		case VK_RCONTROL:	return KC_RCONTROL;
-		case VK_CAPITAL:	return KC_CAPS_LOCK;
-		case VK_LMENU:		return KC_LALT;
-		case VK_@noteNU:		return KC_RALT;
-		case VK_LWIN:		return KC_LSUPER;
-		case VK_RWIN:		return KC_RSUPER;
-		case VK_NUMPAD0:	return KC_KP_0;
-		case VK_NUMPAD1:	return KC_KP_1;
-		case VK_NUMPAD2:	return KC_KP_2;
-		case VK_NUMPAD3:	return KC_KP_3;
-		case VK_NUMPAD4:	return KC_KP_4;
-		case VK_NUMPAD5:	return KC_KP_5;
-		case VK_NUMPAD6:	return KC_KP_6;
-		case VK_NUMPAD7:	return KC_KP_7;
-		case VK_NUMPAD8:	return KC_KP_8;
-		case VK_NUMPAD9:	return KC_KP_9;
-		default:			return KC_NOKEY;
-	}
-}
-
-} // namespace crown
-

+ 0 - 81
src/os/win/WinKeyboard.h

@@ -1,81 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Keyboard.h"
-#include <windows.h>
-
-namespace crown
-{
-
-/**
-	Implementation of Keyboard int32_terface for Windows.
-*/
-class WinKeyboard : public Keyboard
-{
-
-public:
-
-	/** @a copydoc Keyboard::Keyboard() */
-	WinKeyboard(InputManager* creator);
-
-	/** @a copydoc Keyboard::~Keyboard() */
-	~WinKeyboard();
-
-	/** @a copydoc Keyboard::IsModifierPressed() */
-	virtual bool IsModifierPressed(ModifierKey modifier) const;
-
-	/** @a copydoc Keyboard::IsKeyPressed() */
-	virtual bool IsKeyPressed(KeyCode key) const;
-
-	/** @a copydoc Keyboard::IsKeyReleased() */
-	virtual bool IsKeyReleased(KeyCode key) const;
-
-	/** @a copydoc Keyboard::EventLoop() */
-	virtual void EventLoop();
-
-	/**
-		Returns whether DetectableAutoRepeat is set.
-	@a return
-		True if set, false otherwise
-	*/
-	inline bool HasDetectableAutoRepeat() { return mDetectableAutoRepeat; }
-
-private:
-
-	Key TranslateKey(int32_t winKey);
-
-	uint32_t mModifierMask;
-	bool mKeyState[MAX_KEYCODES];
-	bool mDetectableAutoRepeat;
-
-	// Win related
-	HWND mWindowHandle;
-};
-
-} // namespace crown
-

+ 0 - 220
src/os/win/WinMouse.cpp

@@ -1,220 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "WinMouse.h"
-#include "Exceptions.h"
-#include "WinInputManager.h"
-
-// Undef functions to avoid conflicts
-#undef MB_RIGHT
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-WinMouse::WinMouse(InputManager* creator) :
-	Mouse(creator),
-	mIsCursorVisible(true),
-	mWindowHandle(0)
-{
-	if (mCreator)
-	{
-		mWindowHandle = (HWND)(static_cast<WinInputManager*>(mCreator)->GetWindowHandle());
-	}
-
-	static_cast<WinInputManager*>(mCreator)->SetMouseAvailable(true);
-}
-
-//-----------------------------------------------------------------------------
-WinMouse::~WinMouse()
-{
-	if (mCreator)
-	{
-		static_cast<WinInputManager*>(mCreator)->SetMouseAvailable(false);
-	}
-
-	if (!IsCursorVisible())
-	{
-		SetCursorVisible(true);
-	}
-}
-
-//-----------------------------------------------------------------------------
-bool WinMouse::IsCursorVisible() const
-{
-	return mIsCursorVisible;
-}
-
-//-----------------------------------------------------------------------------
-void WinMouse::SetCursorVisible(bool visible)
-{
-	mIsCursorVisible = visible;
-	ShowCursor(visible);
-}
-
-//-----------------------------------------------------------------------------
-Point32_t2 WinMouse::GetCursorXY() const
-{
-	Point32_t2 tmp;
-	POINT p;
-	GetCursorPos(&p);
-	ScreenToClient(mWindowHandle, &p);
-	tmp.x = p.x;
-	tmp.y = p.y;
-	return tmp;
-}
-
-//-----------------------------------------------------------------------------
-void WinMouse::SetCursorXY(const Point32_t2& position)
-{
-	uint32_t width, height;
-	RECT windowRect;
-	GetWindowRect(mWindowHandle, &windowRect);
-
-	width = windowRect.right - windowRect.left;
-	height = windowRect.bottom - windowRect.top;
-
-	POINT p = {(LONG)position.x, (LONG)position.y};
-
-	if (p.x > (int32_t)width)
-	{
-		p.x = width;
-	}
-	else
-	{
-		p.x = (LONG)position.x;
-	}
-
-	if (p.y > (int32_t)height)
-	{
-		p.y = height;
-	}
-	else
-	{
-		p.y = (LONG)position.y;
-	}
-
-	ClientToScreen(mWindowHandle, &p);
-	SetCursorPos(p.x, p.y);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 WinMouse::GetCursorRelativeXY() const
-{
-	uint32_t width, height;
-	RECT windowRect;
-	GetWindowRect(mWindowHandle, &windowRect);
-
-	width = windowRect.right - windowRect.left;
-	height = windowRect.bottom - windowRect.top;
-
-	Vec2 pos;
-	pos = GetCursorXY().ToVec2();
-	pos.x = 1.0f / (float)width * pos.x;
-	pos.y = 1.0f / (float)height * pos.y;
-
-	return pos;
-}
-
-//-----------------------------------------------------------------------------
-void WinMouse::SetCursorRelativeXY(const Vec2& position)
-{
-	uint32_t width, height;
-	RECT windowRect;
-	GetWindowRect(mWindowHandle, &windowRect);
-
-	width = windowRect.right - windowRect.left;
-	height = windowRect.bottom - windowRect.top;
-
-	SetCursorXY(Point32_t2((int32_t)(position.x * width), (int32_t)(position.y * height)));
-}
-
-//-----------------------------------------------------------------------------
-void WinMouse::EventLoop()
-{
-	MSG msg;
-	while (PeekMessage(&msg, mWindowHandle, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
-	{
-		TranslateMessage(&msg);
-		DispatchMessage(&msg);
-
-		switch (msg.message)
-		{
-			case WM_LBUTTONDOWN:
-			case WM_LBUTTONUP:
-			case WM_RBUTTONDOWN:
-			case WM_RBUTTONUP:
-			case WM_MBUTTONDOWN:
-			case WM_MBUTTONUP:
-			{
-				MouseEvent mouseEvent;
-
-				if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONUP)
-				{
-					mouseEvent.button = MB_LEFT;
-				}
-				else if (msg.message == WM_RBUTTONDOWN || msg.message == WM_RBUTTONUP)
-				{
-					mouseEvent.button = MB_RIGHT;
-				}
-				else if (msg.message == WM_MBUTTONDOWN || msg.message == WM_MBUTTONUP)
-				{
-					mouseEvent.button = MB_MIDDLE;
-				}
-
-				mouseEvent.x = LOWORD(msg.lParam);
-				mouseEvent.y = HIWORD(msg.lParam);
-
-				if (mListener)
-				{
-					if (msg.message == WM_LBUTTONDOWN || msg.message == WM_RBUTTONDOWN || msg.message == WM_MBUTTONDOWN)
-					{
-						mListener->ButtonPressed(mouseEvent);
-					}
-					else if (msg.message == WM_LBUTTONUP || msg.message == WM_RBUTTONUP || msg.message == WM_MBUTTONUP)
-					{
-						mListener->ButtonReleased(mouseEvent);
-					}
-				}
-			}break;
-			case WM_MOUSEMOVE:
-			{
-				MouseEvent mouseEvent;
-
-				mouseEvent.x = LOWORD(msg.lParam);
-				mouseEvent.y = HIWORD(msg.lParam);
-
-				if (mListener)
-				{
-					mListener->CursorMoved(mouseEvent);
-				}
-			}break;
-		}
-	}
-}
-
-} // namespace crown
-

+ 0 - 79
src/os/win/WinMouse.h

@@ -1,79 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Mouse.h"
-#include <windows.h>
-
-namespace crown
-{
-
-/**
-	Implementation of Mouse int32_terface for Windows.
-*/
-class WinMouse : public Mouse
-{
-
-public:
-
-	/** @a copydoc Mouse::Mouse() */
-	WinMouse(InputManager* creator);
-
-	/** @a copydoc Mouse::~Mouse() */
-	~WinMouse();
-
-	/** @a copydoc Mouse::IsVisible() */
-	virtual bool IsCursorVisible() const;
-
-	/** @a copydoc Mouse::SetVisible() */
-	virtual void SetCursorVisible(bool visible);
-
-	/** @a copydoc Mouse::GetCursorXY() */
-	virtual Point32_t2 GetCursorXY() const;
-
-	/** @a copydoc Mouse::SetCursorXY() */
-	virtual void SetCursorXY(const Point32_t2& position);
-
-	/** @a copydoc Mouse::GetCursorRelativeXY() */
-	virtual Vec2 GetCursorRelativeXY() const;
-
-	/** @a copydoc Mouse::SetCursorRelativeXY() */
-	virtual void SetCursorRelativeXY(const Vec2& position);
-
-	/** @a copydoc Mouse::EventLoop() */
-	virtual void EventLoop();
-
-private:
-
-	bool mIsCursorVisible;
-
-	// Win related
-	HWND mWindowHandle;
-};
-
-} // namespace crown
-

+ 0 - 160
src/os/win/WinTimer.cpp

@@ -1,160 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <windows.h>
-#include "Timer.h"
-
-namespace crown
-{
-
-Timer::Timer()
-{
-	mPreciseTimer = (QueryPerformanceFrequency((LARGE_INTEGER*) &mFrequency) == TRUE);
-
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &mCreationTime);
-	}
-	else
-	{
-		mFrequency = 1000;
-		mCreationTime = timeGetTime();
-	}
-
-	Reset();
-}
-
-Timer::~Timer()
-{
-}
-
-void Timer::Reset()
-{
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &mCreationTime);
-	}
-	else
-	{
-		mCreationTime = timeGetTime();
-	}
-}
-
-uint64_t Timer::GetMilliseconds() const
-{
-	uint64_t currentTime;
-
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &currentTime);
-	}
-	else
-	{
-		currentTime = timeGetTime();
-	}
-
-	return (uint64_t) ((currentTime - mCreationTime) / (mFrequency / 1000));
-}
-
-uint64_t Timer::GetMicroseconds() const
-{
-	uint64_t currentTime;
-
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &currentTime);
-	}
-	else
-	{
-		currentTime = timeGetTime();
-	}
-
-	//I'm using doubles here because if the timer isn't precise, it's always going to say
-	//0us because of the int32_teger calculus.
-	return (uint64_t)((currentTime - mCreationTime) / (mFrequency/1000000.0));
-}
-
-
-void Timer::StartMilliseconds()
-{
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &mStartTime);
-	}
-	else
-	{
-		mStartTime = timeGetTime();
-	}
-}
-
-uint64_t Timer::StopMilliseconds() const
-{
-	uint64_t currentTime;
-
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &currentTime);
-	}
-	else
-	{
-		currentTime = timeGetTime();
-	}
-
-	return (uint64_t) ((currentTime - mStartTime) / (mFrequency / 1000));
-}
-
-void Timer::StartMicroseconds()
-{
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &mStartTime);
-	}
-	else
-	{
-		mStartTime = timeGetTime();
-	}
-}
-
-uint64_t Timer::StopMicroseconds() const
-{
-	uint64_t currentTime;
-
-	if (mPreciseTimer)
-	{
-		QueryPerformanceCounter((LARGE_INTEGER*) &currentTime);
-	}
-	else
-	{
-		currentTime = timeGetTime();
-	}
-
-	//I'm using doubles here because if the timer isn't precise, it's always going to say
-	//0us because of the int32_teger calculus.
-	return (uint64_t)((currentTime - mStartTime) / (mFrequency/1000000.0));
-}
-
-} // namespace crown
-

+ 0 - 77
src/os/win/WinTimer.h

@@ -1,77 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-
-namespace crown
-{
-
-class Timer
-{
-
-public:
-
-	//! Constructor
-	Timer();
-
-	//! Destructor
-	~Timer();
-
-	//! Returns the time (in milliseconds) elapsed since the instantiation of this class
-	uint64_t GetMilliseconds() const;
-
-	//! Returns the time (in microseconds) elapsed since the instantiation of this class
-	uint64_t GetMicroseconds() const;
-
-	//! Records the current time
-	void StartMilliseconds();
-
-	//! Returns the time (in milliseconds) elapsed since the last call to StartMilliseconds()
-	uint64_t StopMilliseconds() const;
-
-	//! Records the current time
-	void StartMicroseconds();
-
-	//! Returns the time (in microseconds) elapsed since the last call to StartMicroseconds()
-	uint64_t StopMicroseconds() const;
-
-private:
-
-	// Records the initial reference time
-	void Reset();
-
-	// Time at instantiation
-	uint64_t mCreationTime;
-	// Time at Start* call
-	uint64_t mStartTime;
-	uint64_t mFrequency;
-	bool mPreciseTimer;
-};
-
-} // namespace crown
-