-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpixie.cpp
94 lines (77 loc) · 2.11 KB
/
pixie.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <string.h>
#include <ctype.h>
#include "pixie.h"
#include <assert.h>
using namespace Pixie;
Window::Window()
{
m_keyCallback = NULL;
m_delta = 0.0f;
m_pixels = 0;
m_scale = 1;
assert(sizeof(m_mouseButtonDown) == sizeof(m_lastMouseButtonDown));
memset(m_mouseButtonDown, 0, sizeof(m_mouseButtonDown));
memset(m_lastMouseButtonDown, 0, sizeof(m_lastMouseButtonDown));
memset(m_inputCharacters, 0, sizeof(m_inputCharacters));
assert(sizeof(m_keyDown) == sizeof(m_lastKeyDown));
memset(m_lastKeyDown, 0, sizeof(m_lastKeyDown));
memset(m_keyDown, 0, sizeof(m_keyDown));
// Initialise ASCII entries in keymap.
for (int i = 0; i < Key_Num; i++)
m_keyMap[i] = i >= Key_ASCII_Start && i <= Key_ASCII_End ? i : Key_Num;
PlatformInit();
}
Window::~Window()
{
delete[] m_pixels;
}
bool Window::Open(const TCHAR* title, int width, int height, bool fullscreen, bool maintainAspectRatio /*= false*/, int scale /*= 1*/)
{
// Create the buffer first because on OSX we need it to exist when initialising.
m_pixels = new uint32_t[width * height];
m_width = width;
m_height = height;
m_scale = scale;
m_time = 0.0f;
m_fullscreen = fullscreen;
m_maintainAspectRatio = maintainAspectRatio;
if (!PlatformOpen(title, width, height))
{
delete[] m_pixels;
m_pixels = 0;
return false;
}
return true;
}
bool Window::Update()
{
UpdateMouse();
UpdateKeyboard();
bool result = PlatformUpdate();
m_time += m_delta;
return result;
}
void Window::Close()
{
PlatformClose();
}
void Window::UpdateMouse()
{
memcpy(m_lastMouseButtonDown, m_mouseButtonDown, sizeof(m_mouseButtonDown));
}
void Window::UpdateKeyboard()
{
memset(m_inputCharacters, 0, sizeof(m_inputCharacters));
memcpy(m_lastKeyDown, m_keyDown, sizeof(m_keyDown));
}
void Window::AddInputCharacter(char c)
{
if (!isprint(c))
return;
size_t length = strlen(m_inputCharacters);
if (length + 1 < sizeof(m_inputCharacters))
{
m_inputCharacters[length] = c;
m_inputCharacters[length + 1] = 0;
}
}