Basic window functions.
This commit is contained in:
@ -130,12 +130,16 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Window.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\deps\glfw\glfw.vcxproj">
|
||||
<Project>{c40453a2-a653-46a2-9ad7-f174540ef26c}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Window.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -18,5 +18,13 @@
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Window.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Window.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
66
2dGameProject/Window.cpp
Normal file
66
2dGameProject/Window.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include "Window.h"
|
||||
|
||||
Window::Window(int width, int height, const char* title) {
|
||||
glfw_window = glfwCreateWindow(width, height, title, NULL, NULL);
|
||||
if (!glfw_window)
|
||||
throw ("Failed to create GLFW Window!");
|
||||
setWidth(width);
|
||||
setHeight(height);
|
||||
setTitle(title);
|
||||
|
||||
}
|
||||
|
||||
Window::~Window() {
|
||||
glfwDestroyWindow(glfw_window);
|
||||
}
|
||||
|
||||
void Window::setWidth(int width) {
|
||||
this->width = width;
|
||||
glfwSetWindowSize(glfw_window, width, height);
|
||||
}
|
||||
|
||||
int Window::getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
void Window::setHeight(int height) {
|
||||
this->height = height;
|
||||
glfwSetWindowSize(glfw_window, width, height);
|
||||
}
|
||||
|
||||
int Window::getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
void Window::setTitle(const char* title) {
|
||||
this->title = title;
|
||||
glfwSetWindowTitle(glfw_window, title);
|
||||
}
|
||||
|
||||
const char* Window::getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void Window::setFullscreen(bool fullscreen) {
|
||||
is_fullscreen = fullscreen;
|
||||
if (fullscreen)
|
||||
glfwSetWindowMonitor(glfw_window, glfwGetPrimaryMonitor(), 0, 0, width, height, GLFW_DONT_CARE);
|
||||
else
|
||||
glfwSetWindowMonitor(glfw_window, NULL);
|
||||
}
|
||||
|
||||
bool Window::isFullscreen() {
|
||||
return is_fullscreen;
|
||||
}
|
||||
|
||||
void Window::setResizable(bool resizable) {
|
||||
is_resizable = resizable;
|
||||
if (resizable)
|
||||
glfwSetWindowAttrib(glfw_window, GLFW_RESIZABLE, GLFW_TRUE);
|
||||
else
|
||||
glfwSetWindowAttrib(glfw_window, GLFW_RESIZABLE, GLFW_FALSE);
|
||||
}
|
||||
|
||||
bool Window::isResizable() {
|
||||
return is_resizable;
|
||||
}
|
26
2dGameProject/Window.h
Normal file
26
2dGameProject/Window.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
class Window {
|
||||
private:
|
||||
GLFWwindow* glfw_window;
|
||||
int width, height;
|
||||
const char* title;
|
||||
bool is_fullscreen;
|
||||
bool is_resizable;
|
||||
|
||||
public:
|
||||
Window(int width, int height, const char* title);
|
||||
~Window();
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
void setWidth(int width);
|
||||
void setHeight(int height);
|
||||
const char* getTitle();
|
||||
void setTitle(const char* title);
|
||||
bool isFullscreen();
|
||||
bool isResizable();
|
||||
void setFullscreen(bool fullscreen);
|
||||
void setResizable(bool resizable);
|
||||
};
|
||||
|
Reference in New Issue
Block a user