Norbert's Game Engine v200
Loading...
Searching...
No Matches
eWindow Class Reference

#include <Window.hpp>

Inheritance diagram for eWindow:
eBase

Public Member Functions

bool Initialize ()
 
void Unload ()
 
void SetSize (vec2i size)
 
vec2i GetSize ()
 
void SetTitle (eString title)
 
eString GetTitle ()
 
int ShowMessageBox (eString title, eString content, bool okaycancel)
 
HWND GetWnd ()
 
bool WindowCloseRequested ()
 
void SetWindowCloseRequest (bool vl)
 
void FocusWindow ()
 
bool IsWindowFocused ()
 
bool IsWindowVisible ()
 
void SetWindowVisibility (bool vl)
 
void IconifyWindow ()
 
bool IsWindowIconified ()
 
void SetWindowResizable (bool vl)
 
void SetWindowDecorated (bool vl)
 
bool IsWindowMaximized ()
 
void RestoreWindow ()
 
void MaximizeWindow ()
 
void SetWindowAspectRatio (vec2i aspect)
 
void SetWindowSizeLimits (vec2i min, vec2i max)
 
void SetWindowIcon (eString filePath, real3 sx, real3 sy, int desiredChannels)
 
void CenterWindow ()
 
vec2i GetWindowSize ()
 
void SetWindowPosition (vec2i pos)
 
vec2i GetWindowPosition ()
 
void SetWindowSize (vec2i size)
 
void SwitchFullscreen ()
 
void AutoSize ()
 
vec2i GetMonitorSize ()
 
void SetUserPointer (void *ptr)
 
void * GetUserPointer ()
 
void SwitchFullscreenEx ()
 
GLFWwindow * GetGLFWwindow ()
 
eMouse * GetMouse ()
 
eKeyboard * GetKeyboard ()
 
bool SizeChanged ()
 
- Public Member Functions inherited from eBase
template<typename T >
T * Cast (eBase *obj)
 Cast class to base.
 

Static Public Member Functions

static bool INIT ()
 
static void UPDATE ()
 
static void RELEASE ()
 

Detailed Description

Window class

Definition at line 22 of file Window.hpp.

Constructor & Destructor Documentation

◆ eWindow()

eWindow::eWindow ( )

Definition at line 35 of file Window.cpp.

36{
37 mWnd = nullptr;
38}

◆ ~eWindow()

eWindow::~eWindow ( )

Definition at line 40 of file Window.cpp.

41{
42 Unload();
43 mSize = vec2i(0);
44 mTitle.Clear();
45}
void Clear()
Clear text.
Definition String.cpp:58

Member Function Documentation

◆ AutoSize()

void eWindow::AutoSize ( )

Definition at line 249 of file Window.cpp.

250{
251 const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
252 int w = (uint)vidmode->width;
253 int h = (uint)vidmode->height;
254 glfwSetWindowSize(mWnd, w, h);
255}

◆ CenterWindow()

void eWindow::CenterWindow ( )

Definition at line 207 of file Window.cpp.

208{
209 int w, h;
210 glfwGetWindowSize(mWnd, &w, &h);
211
212 const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
213 glfwSetWindowPos(mWnd, (vidmode->width / 2) - (w / 2), (vidmode->height / 2) - (h / 2));
214}

◆ FocusWindow()

void eWindow::FocusWindow ( )

Definition at line 117 of file Window.cpp.

118{
119 glfwFocusWindow(mWnd);
120}

◆ GetGLFWwindow()

GLFWwindow * eWindow::GetGLFWwindow ( )

Definition at line 275 of file Window.cpp.

276{
277 return mWnd;
278}

◆ GetKeyboard()

eKeyboard * eWindow::GetKeyboard ( )

Definition at line 285 of file Window.cpp.

286{
287 return mKeyboard;
288}

◆ GetMonitorSize()

vec2i eWindow::GetMonitorSize ( )

Definition at line 257 of file Window.cpp.

258{
259 const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
260 int w = (uint)vidmode->width;
261 int h = (uint)vidmode->height;
262 return vec2i(w, h);
263}

◆ GetMouse()

eMouse * eWindow::GetMouse ( )

Definition at line 280 of file Window.cpp.

281{
282 return mMouse;
283}

◆ GetSize()

vec2i eWindow::GetSize ( )

Definition at line 78 of file Window.cpp.

79{
80 return mSize;
81}

◆ GetTitle()

eString eWindow::GetTitle ( )

Definition at line 90 of file Window.cpp.

91{
92 return mTitle;
93}

◆ GetUserPointer()

void * eWindow::GetUserPointer ( )

Definition at line 270 of file Window.cpp.

271{
272 return glfwGetWindowUserPointer(mWnd);
273}

◆ GetWindowPosition()

vec2i eWindow::GetWindowPosition ( )

Definition at line 228 of file Window.cpp.

229{
230 int x, y;
231 glfwGetWindowPos(mWnd, &x, &y);
232 return vec2i(x, y);
233}

◆ GetWindowSize()

vec2i eWindow::GetWindowSize ( )

Definition at line 216 of file Window.cpp.

217{
218 int w, h;
219 glfwGetWindowSize(mWnd, &w, &h);
220 return vec2i(w, h);
221}

◆ GetWnd()

HWND eWindow::GetWnd ( )

Definition at line 102 of file Window.cpp.

103{
104 return glfwGetWin32Window(mWnd);
105}

◆ IconifyWindow()

void eWindow::IconifyWindow ( )

Definition at line 132 of file Window.cpp.

133{
134 glfwIconifyWindow(mWnd);
135}

◆ INIT()

bool eWindow::INIT ( )
static

Definition at line 14 of file Window.cpp.

15{
16 if (!glfwInit())
17 {
18 eConsole::PrintLog("GLFW ERROR", "glfwInit() returned false!");
20 return false;
21 }
22 return true;
23}
static void WriteToDisk()
Write the console text to a crash file called 'CRASH.log'.
Definition Console.cpp:40
static void PrintLog(eString head, eString msg)
Print a log.
Definition Console.cpp:22

◆ Initialize()

bool eWindow::Initialize ( )

Definition at line 47 of file Window.cpp.

48{
49 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
50 mWnd = glfwCreateWindow(mSize.x, mSize.y, mTitle.Get(), nullptr, nullptr);
51
52 glfwShowWindow(mWnd);
53
54 mMouse = new eMouse();
55 mMouse->SetWindow(this);
56
57 mKeyboard = new eKeyboard();
58 mKeyboard->SetWindow(this);
59 return true;
60}
const char * Get()
Return text as c-string.
Definition String.cpp:64

◆ IsWindowFocused()

bool eWindow::IsWindowFocused ( )

Definition at line 142 of file Window.cpp.

143{
144 return static_cast<bool>(glfwGetWindowAttrib(mWnd, GLFW_FOCUSED));
145}

◆ IsWindowIconified()

bool eWindow::IsWindowIconified ( )

Definition at line 137 of file Window.cpp.

138{
139 return static_cast<bool>(glfwGetWindowAttrib(mWnd, GLFW_ICONIFIED));
140}

◆ IsWindowMaximized()

bool eWindow::IsWindowMaximized ( )

Definition at line 157 of file Window.cpp.

158{
159 return static_cast<bool>(glfwGetWindowAttrib(mWnd, GLFW_MAXIMIZED));
160}

◆ IsWindowVisible()

bool eWindow::IsWindowVisible ( )

Definition at line 122 of file Window.cpp.

123{
124 return static_cast<bool>(glfwGetWindowAttrib(mWnd, GLFW_VISIBLE));
125}

◆ MaximizeWindow()

void eWindow::MaximizeWindow ( )

Definition at line 167 of file Window.cpp.

168{
169 glfwMaximizeWindow(mWnd);
170}

◆ RELEASE()

void eWindow::RELEASE ( )
static

Definition at line 30 of file Window.cpp.

31{
32 glfwTerminate();
33}

◆ RestoreWindow()

void eWindow::RestoreWindow ( )

Definition at line 162 of file Window.cpp.

163{
164 glfwRestoreWindow(mWnd);
165}

◆ SetSize()

void eWindow::SetSize ( vec2i size)

Definition at line 73 of file Window.cpp.

74{
75 mSize = size;
76}

◆ SetTitle()

void eWindow::SetTitle ( eString title)

Definition at line 83 of file Window.cpp.

84{
85 mTitle = title;
86 if (mWnd != nullptr)
87 glfwSetWindowTitle(mWnd, mTitle.Get());
88}

◆ SetUserPointer()

void eWindow::SetUserPointer ( void * ptr)

Definition at line 265 of file Window.cpp.

266{
267 glfwSetWindowUserPointer(mWnd, ptr);
268}

◆ SetWindowAspectRatio()

void eWindow::SetWindowAspectRatio ( vec2i aspect)

Definition at line 172 of file Window.cpp.

173{
174 glfwSetWindowAspectRatio(mWnd, aspect.x, aspect.y);
175}

◆ SetWindowCloseRequest()

void eWindow::SetWindowCloseRequest ( bool vl)

Definition at line 112 of file Window.cpp.

113{
114 glfwSetWindowShouldClose(mWnd, vl);
115}

◆ SetWindowDecorated()

void eWindow::SetWindowDecorated ( bool vl)

Definition at line 152 of file Window.cpp.

153{
154 glfwSetWindowAttrib(mWnd, GLFW_DECORATED, vl);
155}

◆ SetWindowIcon()

void eWindow::SetWindowIcon ( eString filePath,
real3 sx,
real3 sy,
int desiredChannels )

Definition at line 190 of file Window.cpp.

191{
192 const char* fp = filePath.Get();
193 if (EDR::FileExists(fp))
194 {
195 GLFWimage* iconImg = new GLFWimage();
196 iconImg->width = sx;
197 iconImg->height = sy;
198 iconImg->pixels = stbi_load(fp, &iconImg->width, &iconImg->height, NULL, desiredChannels);
199 glfwSetWindowIcon(mWnd, 1, iconImg);
200 stbi_image_free(iconImg->pixels);
201 delete iconImg;
202 }
203 else
204 eConsole::PrintLog("WARNING::eWindow::SetWindowIcon", "Icon file '" + filePath.GetStrg() + "' could not be found!");
205}
const strg & GetStrg() const
Return text as std::string.
Definition String.cpp:70

◆ SetWindowPosition()

void eWindow::SetWindowPosition ( vec2i pos)

Definition at line 223 of file Window.cpp.

224{
225 glfwSetWindowPos(mWnd, pos.x, pos.y);
226}

◆ SetWindowResizable()

void eWindow::SetWindowResizable ( bool vl)

Definition at line 147 of file Window.cpp.

148{
149 glfwSetWindowAttrib(mWnd, GLFW_RESIZABLE, vl);
150}

◆ SetWindowSize()

void eWindow::SetWindowSize ( vec2i size)

Definition at line 235 of file Window.cpp.

236{
237 glfwSetWindowSize(mWnd, size.x, size.y);
238}

◆ SetWindowSizeLimits()

void eWindow::SetWindowSizeLimits ( vec2i min,
vec2i max )

Definition at line 177 of file Window.cpp.

178{
179 int minX = min.x;
180 int minY = min.y;
181 int maxX = max.x;
182 int maxY = max.y;
183 if (min.x == 0 && min.y == 0)
184 minX = minY = GLFW_DONT_CARE;
185 if (max.x == 0 && max.y == 0)
186 maxX = maxY = GLFW_DONT_CARE;
187 glfwSetWindowSizeLimits(mWnd, minX, minY, maxX, maxY);
188}

◆ SetWindowVisibility()

void eWindow::SetWindowVisibility ( bool vl)

Definition at line 127 of file Window.cpp.

128{
129 vl ? glfwShowWindow(mWnd) : glfwHideWindow(mWnd);
130}

◆ ShowMessageBox()

int eWindow::ShowMessageBox ( eString title,
eString content,
bool okaycancel )

Definition at line 95 of file Window.cpp.

96{
97 strg _content = content.GetStrg();
98 strg _title = title.GetStrg();
99 return MessageBox(NULL, std::wstring(_content.begin(), _content.end()).c_str(), std::wstring(_title.begin(), _title.end()).c_str(), okaycancel ? MB_OKCANCEL | MB_SYSTEMMODAL : NULL);
100}

◆ SizeChanged()

bool eWindow::SizeChanged ( )

Definition at line 332 of file Window.cpp.

333{
334 const vec2i asize = GetWindowSize();
335 if (asize != mSize)
336 {
337 eLayer::mRefreshSize = true;
338 mSize = asize;
339 return true;
340 }
341 return false;
342}

◆ SwitchFullscreen()

void eWindow::SwitchFullscreen ( )

Definition at line 240 of file Window.cpp.

241{
242 int w, h;
243 glfwGetWindowSize(mWnd, &w, &h);
244
245 GLFWmonitor* currentMonitor = get_current_monitor(mWnd);
246 glfwSetWindowMonitor(mWnd, currentMonitor, 0, 0, w, h, GLFW_DONT_CARE);
247}

◆ SwitchFullscreenEx()

void eWindow::SwitchFullscreenEx ( )

Definition at line 325 of file Window.cpp.

326{
327 SetWindowDecorated(false);
328 SetWindowPosition(vec2i(0));
329 AutoSize();
330}

◆ Unload()

void eWindow::Unload ( )

Definition at line 62 of file Window.cpp.

63{
64 if (mMouse)
65 delete mMouse;
66
67 if (mKeyboard)
68 delete mKeyboard;
69
70 glfwDestroyWindow(mWnd);
71}

◆ UPDATE()

void eWindow::UPDATE ( )
static

Definition at line 25 of file Window.cpp.

26{
27 glfwPollEvents();
28}

◆ WindowCloseRequested()

bool eWindow::WindowCloseRequested ( )

Definition at line 107 of file Window.cpp.

108{
109 return glfwWindowShouldClose(mWnd);
110}

The documentation for this class was generated from the following files: