Skip to content

Commit

Permalink
[#17] : Added feature to confine cursor to window
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Jun 25, 2020
1 parent be2da1f commit ff5e33a
Show file tree
Hide file tree
Showing 46 changed files with 506 additions and 413 deletions.
12 changes: 11 additions & 1 deletion engines/basic/include/delta_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@ namespace dbasic {
bool IsKeyDown(ysKeyboard::KEY_CODE key);
bool ProcessKeyDown(ysKeyboard::KEY_CODE key);

bool IsMouseKeyDown(ysMouse::BUTTON_CODE key);
bool IsMouseKeyDown(ysMouse::Button key);
int GetMouseWheel();
void GetMousePos(int *x, int *y);

void SetCursorPositionLock(bool lock) { m_cursorPositionLocked = lock; }
bool GetCursorPositionLock() { return m_cursorPositionLocked; }

void SetCursorHidden(bool hidden) { m_cursorHidden = hidden; }
bool GetCursorHidden() const { return m_cursorHidden; }

float GetFrameLength();
float GetAverageFramerate();

Expand Down Expand Up @@ -221,6 +227,10 @@ namespace dbasic {
// Settings
float m_clearColor[4];

// Cursor
bool m_cursorPositionLocked;
bool m_cursorHidden;

protected:
// Initialization Routines
ysError InitializeGeometry();
Expand Down
18 changes: 15 additions & 3 deletions engines/basic/src/delta_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ ysError dbasic::DeltaEngine::CreateGameWindow(const char *title, void *instance,
YDS_ERROR_DECLARE("CreateGameWindow");

// Create the window system
YDS_NESTED_ERROR_CALL(ysWindowSystem::CreateWindowSystem(&m_windowSystem, ysWindowSystemObject::Platform::WINDOWS));
YDS_NESTED_ERROR_CALL(ysWindowSystem::CreateWindowSystem(&m_windowSystem, ysWindowSystemObject::Platform::Windows));
m_windowSystem->ConnectInstance(instance);

// Find the monitor setup
m_windowSystem->SurveyMonitors();
ysMonitor *mainMonitor = m_windowSystem->GetMonitor(0);

YDS_NESTED_ERROR_CALL(ysInputSystem::CreateInputSystem(&m_inputSystem, ysWindowSystemObject::Platform::WINDOWS));
YDS_NESTED_ERROR_CALL(ysInputSystem::CreateInputSystem(&m_inputSystem, ysWindowSystemObject::Platform::Windows));
m_windowSystem->AssignInputSystem(m_inputSystem);
m_inputSystem->CreateDevices(false);

Expand Down Expand Up @@ -168,6 +168,18 @@ ysError dbasic::DeltaEngine::StartFrame() {
if (IsKeyDown(ysKeyboard::KEY_B)) m_device->SetDebugFlag(0, true);
else m_device->SetDebugFlag(0, false);

if (m_gameWindow->IsActive()) {
m_windowSystem->SetCursorVisible(!m_cursorHidden);
if (m_cursorPositionLocked) {
m_windowSystem->ReleaseCursor();
m_windowSystem->ConfineCursor(m_gameWindow);
}
}
else {
m_windowSystem->SetCursorVisible(true);
m_windowSystem->ReleaseCursor();
}

if (IsOpen()) {
m_device->SetRenderTarget(m_mainRenderTarget);
m_device->ClearBuffers(m_clearColor);
Expand Down Expand Up @@ -515,7 +527,7 @@ bool dbasic::DeltaEngine::ProcessKeyDown(ysKeyboard::KEY_CODE key) {
return false;
}

bool dbasic::DeltaEngine::IsMouseKeyDown(ysMouse::BUTTON_CODE key) {
bool dbasic::DeltaEngine::IsMouseKeyDown(ysMouse::Button key) {
if (m_mainMouse != nullptr) {
ysMouse *mouse = m_mainMouse->GetAsMouse();
return mouse->GetButton(key)->IsDown();
Expand Down
11 changes: 3 additions & 8 deletions include/yds_d3d10_shader_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
#include "yds_shader_program.h"

class ysD3D10Shader;
class ysD3D10ShaderProgram : public ysShaderProgram
{

class ysD3D10ShaderProgram : public ysShaderProgram {
friend class ysD3D10Device;

public:

ysD3D10ShaderProgram();
virtual ~ysD3D10ShaderProgram();

protected:

ysD3D10Shader *GetShader(ysShader::SHADER_TYPE type);

ysD3D10Shader *GetShader(ysShader::ShaderType type);
};

#endif
#endif /* YDS_D3D10_SHADER_PROGRAM_H */
11 changes: 3 additions & 8 deletions include/yds_d3d11_shader_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
#include "yds_shader_program.h"

class ysD3D11Shader;
class ysD3D11ShaderProgram : public ysShaderProgram
{

class ysD3D11ShaderProgram : public ysShaderProgram {
friend class ysD3D11Device;

public:

ysD3D11ShaderProgram();
~ysD3D11ShaderProgram();

protected:

ysD3D11Shader *GetShader(ysShader::SHADER_TYPE type);

ysD3D11Shader *GetShader(ysShader::ShaderType type);
};

#endif
#endif /* YDS_D3D11_SHADER_PROGRAM_H */
32 changes: 16 additions & 16 deletions include/yds_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

class ysMouse {
public:
enum BUTTON_CODE {
BUTTON_LEFT,
BUTTON_RIGHT,
BUTTON_MIDDLE,

BUTTON_1,
BUTTON_2,
BUTTON_3,
BUTTON_4,
BUTTON_5,

BUTTON_COUNT
enum class Button {
Left,
Right,
Middle,

Aux_1,
Aux_2,
Aux_3,
Aux_4,
Aux_5,

Count
};

public:
Expand All @@ -26,22 +26,22 @@ class ysMouse {
void Reset();
void UpdatePosition(int x, int y, bool delta = true);
void UpdateWheel(int dwheel);
void UpdateButton(BUTTON_CODE button, ysKey::KEY_STATE state);
void UpdateButton(Button button, ysKey::KEY_STATE state);

int GetX() const { return m_x; }
int GetY() const { return m_y; }
int GetWheel() const { return m_wheel; }
const ysKey *GetButton(BUTTON_CODE button) const { return &m_buttons[button]; }
const ysKey *GetButton(Button button) const { return &m_buttons[(int)button]; }

bool ProcessMouseButton(BUTTON_CODE button, ysKey::KEY_STATE state);
bool ProcessMouseButton(Button button, ysKey::KEY_STATE state);

protected:
int m_x;
int m_y;
int m_wheel;

protected:
ysKey m_buttons[BUTTON_COUNT];
ysKey m_buttons[(int)Button::Count];
};

#endif /* YDS_MOUSE_H */
148 changes: 74 additions & 74 deletions include/yds_opengl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,90 +38,90 @@ class ysOpenGLVirtualContext : public ysRenderingContext {
}

// OpenGL Extensions
PFNGLGENBUFFERSPROC glGenBuffers;
PFNGLDELETEBUFFERSPROC glDeleteBuffers;
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
PFNGLBINDBUFFERPROC glBindBuffer;
PFNGLBINDBUFFERRANGEPROC glBindBufferRange;
PFNGLBUFFERDATAPROC glBufferData;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer;

PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f;
PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f;

PFNGLDELETEPROGRAMPROC glDeleteProgram;
PFNGLDELETESHADERPROC glDeleteShader;

PFNGLCREATESHADERPROC glCreateShader;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLDETACHSHADERPROC glDetachShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation;
PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation;
PFNGLGETFRAGDATALOCATIONPROC glGetFragDataLocation;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLDRAWBUFFERSPROC glDrawBuffers;

PFNGLUNIFORM4FPROC glUniform4f;
PFNGLUNIFORM4FVPROC glUniform4fv;
PFNGLUNIFORM3FVPROC glUniform3fv;
PFNGLUNIFORM2FVPROC glUniform2fv;
PFNGLUNIFORM3FPROC glUniform3f;
PFNGLUNIFORM2FPROC glUniform2f;
PFNGLUNIFORM1FPROC glUniform1f;
PFNGLUNIFORM1IPROC glUniform1i;

PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv;

PFNGLMAPBUFFERPROC glMapBuffer;
PFNGLMAPBUFFERRANGEPROC glMapBufferRange;
PFNGLUNMAPBUFFERPROC glUnmapBuffer;

PFNGLGETPROGRAMIVPROC glGetProgramiv;
PFNGLGETACTIVEUNIFORMNAMEPROC glGetActiveUniformName;
PFNGLGETACTIVEUNIFORMSIVPROC glGetActiveUniformsiv;
PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform;

PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;
PFNGLGENBUFFERSPROC glGenBuffers = nullptr;
PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr;
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr;
PFNGLBINDBUFFERPROC glBindBuffer = nullptr;
PFNGLBINDBUFFERRANGEPROC glBindBufferRange = nullptr;
PFNGLBUFFERDATAPROC glBufferData = nullptr;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr;
PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr;
PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer = nullptr;

PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f = nullptr;
PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr;

PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr;
PFNGLDELETESHADERPROC glDeleteShader = nullptr;

PFNGLCREATESHADERPROC glCreateShader = nullptr;
PFNGLSHADERSOURCEPROC glShaderSource = nullptr;
PFNGLCOMPILESHADERPROC glCompileShader = nullptr;
PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr;
PFNGLATTACHSHADERPROC glAttachShader = nullptr;
PFNGLDETACHSHADERPROC glDetachShader = nullptr;
PFNGLLINKPROGRAMPROC glLinkProgram = nullptr;
PFNGLUSEPROGRAMPROC glUseProgram = nullptr;
PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr;
PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation = nullptr;
PFNGLGETFRAGDATALOCATIONPROC glGetFragDataLocation = nullptr;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr;
PFNGLGETSHADERIVPROC glGetShaderiv = nullptr;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr;
PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr;

PFNGLUNIFORM4FPROC glUniform4f = nullptr;
PFNGLUNIFORM4FVPROC glUniform4fv = nullptr;
PFNGLUNIFORM3FVPROC glUniform3fv = nullptr;
PFNGLUNIFORM2FVPROC glUniform2fv = nullptr;
PFNGLUNIFORM3FPROC glUniform3f = nullptr;
PFNGLUNIFORM2FPROC glUniform2f = nullptr;
PFNGLUNIFORM1FPROC glUniform1f = nullptr;
PFNGLUNIFORM1IPROC glUniform1i = nullptr;

PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr;
PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv = nullptr;

PFNGLMAPBUFFERPROC glMapBuffer = nullptr;
PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr;
PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr;

PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr;
PFNGLGETACTIVEUNIFORMNAMEPROC glGetActiveUniformName = nullptr;
PFNGLGETACTIVEUNIFORMSIVPROC glGetActiveUniformsiv = nullptr;
PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform = nullptr;

PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex = nullptr;

// Textures

PFNGLACTIVETEXTUREPROC glActiveTexture;
PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr;
PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr;

// Buffers

PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr;
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr;
PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr;

PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData;
PFNGLBUFFERSUBDATAPROC glBufferSubData;
PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData = nullptr;
PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr;

PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr;
PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr;
PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr;
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr;

PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
PFNGLBLENDEQUATIONPROC glBlendEquation;
PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer = nullptr;
PFNGLBLENDEQUATIONPROC glBlendEquation = nullptr;

PFNWGLMAKECONTEXTCURRENTARBPROC wglMakeContextCurrent;
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
PFNWGLMAKECONTEXTCURRENTARBPROC wglMakeContextCurrent = nullptr;
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = nullptr;
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = nullptr;

bool IsRealContext() { return m_isRealContext; }

Expand Down
11 changes: 3 additions & 8 deletions include/yds_opengl_shader_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
#include "yds_shader_program.h"

class ysOpenGLShader;
class ysOpenGLShaderProgram : public ysShaderProgram
{

class ysOpenGLShaderProgram : public ysShaderProgram {
friend class ysOpenGLDevice;

public:

ysOpenGLShaderProgram();
~ysOpenGLShaderProgram();

protected:

ysOpenGLShader *GetShader(ysShader::SHADER_TYPE type);
ysOpenGLShader *GetShader(ysShader::ShaderType type);

unsigned int m_handle;

};

#endif
#endif /* YDS_OPENGL_SHADER_PROGRAM_H */
8 changes: 4 additions & 4 deletions include/yds_rendering_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class ysRenderingContext : public ysContextObject {
friend ysDevice;

public:
enum ContextMode {
WINDOWED,
FULLSCREEN,
UNDEFINED
enum class ContextMode {
Windowed,
Fullscreen,
Undefined
};

public:
Expand Down
Loading

0 comments on commit ff5e33a

Please sign in to comment.