Skip to content

Commit da4dd4e

Browse files
committed
App - Implement WindowGeometry Model
1 parent 44dc7ac commit da4dd4e

File tree

4 files changed

+205
-4
lines changed

4 files changed

+205
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ add_library (${PROJECT_NAME}
3535
"src/app/aura.cpp"
3636
"src/app/configurationbase.cpp"
3737
"src/app/interprocesscommunicator.cpp"
38+
"src/app/windowgeometry.cpp"
3839
"src/database/sqlcontext.cpp"
3940
"src/database/sqldatabase.cpp"
4041
"src/database/sqlite3.c"

docs/app.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ This module contains types and functions for creating Nickvision applications.
77
- [Aura](#aura)
88
- [ConfigurationBase](#configurationbase)
99
- [InterProcessCommunicator](#interprocesscommunicator)
10+
- [WindowGeometry](#windowgeometry)
1011

1112
## AppInfo
1213
Description: A model for the information about an application.
1314

14-
Interface: [appinfo.h](/include/aura/appinfo.h)
15+
Interface: [appinfo.h](/include/app/appinfo.h)
1516

1617
Type: `class`
1718

@@ -127,7 +128,7 @@ Path: `Nickvision::App::AppInfo`
127128
## Aura
128129
Description: An application base.
129130
130-
Interface: [aura.h](/include/aura/aura.h)
131+
Interface: [aura.h](/include/app/aura.h)
131132
132133
Type: `class`
133134
@@ -233,7 +234,7 @@ Path: `Nickvision::App::Aura`
233234
## ConfigurationBase
234235
Description: A base class for configuration files.
235236

236-
Interface: [configurationbase.h](/include/aura/configurationbase.h)
237+
Interface: [configurationbase.h](/include/app/configurationbase.h)
237238

238239
Type: `class`
239240

@@ -337,7 +338,7 @@ Type: `file`
337338
## InterProcessCommunicator
338339
Description: An inter process communicator (server/client).
339340

340-
Interface: [interprocesscommunicator.h](/include/aura/interprocesscommunicator.h)
341+
Interface: [interprocesscommunicator.h](/include/app/interprocesscommunicator.h)
341342

342343
Type: `class`
343344

@@ -414,3 +415,49 @@ If this program is ran for the first time, ipc will be the server instance. `han
414415

415416
If this program is ran not for the first time, its arguments will be sent to the first instance and this instance itself will close. The first instance's `handleArguments` function will be called as a result of `CommandReceived` being invoked by the ipc server receiving the command.
416417

418+
## WindowGeometry
419+
Description: A model of a window's geometry.
420+
421+
Interface: [windowgeometry.h](/include/app/windowgeometry.h)
422+
423+
Type: `class`
424+
425+
Path: `Nickvision::App::WindowGeometry`
426+
427+
### Member Variables
428+
- ```
429+
long Width: get, set
430+
```
431+
- The window's width.
432+
- ```
433+
long Height: get, set
434+
```
435+
- The window's height.
436+
- ```
437+
bool IsMaximized: get, set
438+
```
439+
- Whether or not the window is maximized.
440+
441+
### Methods
442+
- ```cpp
443+
WindowGeometry()
444+
```
445+
- Constructs a WindowGeometry.
446+
- Note: Uses default values: 800 width, 600 height, not maximized.
447+
- ```cpp
448+
WindowGeometry(long width, long height, bool isMaximized)
449+
```
450+
- Constructs a WindowGeometry.
451+
- Accepts: The window's width, width, the window's height, height, and whether or not the window is maximized, isMaximized.
452+
- ```cpp
453+
WindowGeometry(HWND hwnd)
454+
```
455+
- Constructs a WindowGeometry.
456+
- Accepts: The window handle to get the geometry from, hwnd.
457+
- Note: This function is only available on Windows.
458+
- ```cpp
459+
bool apply(HWND hwnd)
460+
```
461+
- Accepts: The window handle to apply the geometry to, hwnd.
462+
- Returns: True if successful.
463+
- Returns: False if unsuccessful.

include/app/windowgeometry.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#ifndef WINDOWGEOMETRY_H
2+
#define WINDOWGEOMETRY_H
3+
4+
#ifdef _WIN32
5+
#include <windows.h>
6+
#endif
7+
8+
namespace Nickvision::App
9+
{
10+
/**
11+
* @brief A model of a window's geometry.
12+
*/
13+
class WindowGeometry
14+
{
15+
public:
16+
/**
17+
* @brief Construct a WindowGeometry.
18+
*/
19+
WindowGeometry();
20+
/**
21+
* @brief Construct a WindowGeometry.
22+
* @param width The width of the window
23+
* @param height The height of the window
24+
* @param isMaximized Whether or not the window is maximized
25+
*/
26+
WindowGeometry(long width, long height, bool isMaximized);
27+
#ifdef _WIN32
28+
/**
29+
* @brief Construct a WindowGeometry.
30+
* @param hwnd The window handle to get the geometry from
31+
*/
32+
WindowGeometry(HWND hwnd);
33+
#endif
34+
/**
35+
* @brief Gets the width of the window.
36+
* @return The width of the window
37+
*/
38+
long getWidth();
39+
/**
40+
* @brief Sets the width of the window.
41+
* @param width The new width of the window
42+
*/
43+
void setWidth(long width);
44+
/**
45+
* @brief Gets the height of the window.
46+
* @return The height of the window
47+
*/
48+
long getHeight();
49+
/**
50+
* @brief Sets the height of the window.
51+
* @param height The new height of the window
52+
*/
53+
void setHeight(long height);
54+
/**
55+
* @brief Gets whether or not the window is maximized.
56+
* @return True if maximized, else false
57+
*/
58+
bool isMaximized();
59+
/**
60+
* @brief Sets whether or not the window is maximized.
61+
* @param isMaximized True if maximized, else false
62+
*/
63+
void setIsMaximized(bool isMaximized);
64+
#ifdef _WIN32
65+
/**
66+
* @brief Applies the geometry to a window.
67+
* @param hwnd The window handle to apply the geometry to
68+
* @return True if successful, else false
69+
*/
70+
bool apply(HWND hwnd);
71+
#endif
72+
73+
private:
74+
long m_width;
75+
long m_height;
76+
bool m_isMaximized;
77+
};
78+
}
79+
80+
#endif //WINDOWGEOMETRY_H

src/app/windowgeometry.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "app/windowgeometry.h"
2+
3+
namespace Nickvision::App
4+
{
5+
WindowGeometry::WindowGeometry()
6+
: m_width{ 800 },
7+
m_height{ 600 },
8+
m_isMaximized{ false }
9+
{
10+
11+
}
12+
13+
WindowGeometry::WindowGeometry(long width, long height, bool isMaximized)
14+
: m_width{ width },
15+
m_height{ height },
16+
m_isMaximized{ isMaximized }
17+
{
18+
19+
}
20+
21+
#ifdef _WIN32
22+
WindowGeometry::WindowGeometry(HWND hwnd)
23+
{
24+
WINDOWPLACEMENT placement;
25+
GetWindowPlacement(hwnd, &placement);
26+
m_width = placement.rcNormalPosition.right - placement.rcNormalPosition.left;
27+
m_height = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top;
28+
m_isMaximized = placement.showCmd == SW_SHOWMAXIMIZED;
29+
}
30+
#endif
31+
32+
long WindowGeometry::getWidth()
33+
{
34+
return m_width;
35+
}
36+
37+
void WindowGeometry::setWidth(long width)
38+
{
39+
m_width = width;
40+
}
41+
42+
long WindowGeometry::getHeight()
43+
{
44+
return m_height;
45+
}
46+
47+
void WindowGeometry::setHeight(long height)
48+
{
49+
m_height = height;
50+
}
51+
52+
bool WindowGeometry::isMaximized()
53+
{
54+
return m_isMaximized;
55+
}
56+
57+
void WindowGeometry::setIsMaximized(bool isMaximized)
58+
{
59+
m_isMaximized = isMaximized;
60+
}
61+
62+
#ifdef _WIN32
63+
bool WindowGeometry::apply(HWND hwnd)
64+
{
65+
WINDOWPLACEMENT placement;
66+
GetWindowPlacement(hwnd, &placement);
67+
placement.rcNormalPosition.right = placement.rcNormalPosition.left + m_width;
68+
placement.rcNormalPosition.bottom = placement.rcNormalPosition.top + m_height;
69+
placement.showCmd = m_isMaximized ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
70+
return SetWindowPlacement(hwnd, &placement);
71+
}
72+
#endif
73+
}

0 commit comments

Comments
 (0)