-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenManager.cpp
More file actions
99 lines (78 loc) · 2.13 KB
/
ScreenManager.cpp
File metadata and controls
99 lines (78 loc) · 2.13 KB
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
94
95
96
97
98
99
///////////////////////////////////////////////////////////
// Manages screens
///////////////////////////////////////////////////////////
#pragma once
#include "Utils.h"
#include "ScreenManager.h"
CScreenManager::CScreenManager()
{
m_bInit = false;
m_bIsLowRes = false;
// Normally the user fly his drone outside, this means, on a laptop (one screen)
int index=0;
DISPLAY_DEVICE Device;
Device.cb = sizeof(DISPLAY_DEVICE);
while (EnumDisplayDevices(NULL, index++, &Device, 0))
{
if (Device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
{
m_MainDevice = Device;
m_bInit = true;
break;
}
}
}
CScreenManager::~CScreenManager()
{
}
bool CScreenManager::SetLowResolution()
{
if(!m_bInit)
{
return false;
}
DEVMODE DevMod;
DevMod.dmSize = sizeof(DEVMODE);
if (!EnumDisplaySettings(m_MainDevice.DeviceName, ENUM_CURRENT_SETTINGS, &DevMod))
{
DoLog("Failed to enum display settings, low resolution canceled", MSG_ERROR);
return false;
}
if( (DevMod.dmPelsWidth <= 1366) || (DevMod.dmPelsWidth <= 768) )
{
DoLog("Screen has already a low res, ignore resolution change", MSG_WARNING);
return true;
}
// Flag for what we want to set
DevMod.dmFields = (DM_PELSWIDTH | DM_PELSHEIGHT);
// Try a 19/9 low res
DevMod.dmPelsWidth = 1366;
DevMod.dmPelsHeight = 768;
if (ChangeDisplaySettings(&DevMod, CDS_TEST) != DISP_CHANGE_SUCCESSFUL)
{
// Try a 4/3 low res
DevMod.dmPelsWidth = 1024;
DevMod.dmPelsHeight = 768;
if (ChangeDisplaySettings(&DevMod, CDS_TEST) != DISP_CHANGE_SUCCESSFUL)
{
DoLog("Low resolution display settings not supported, canceled", MSG_ERROR);
return false;
}
}
if(ChangeDisplaySettings(&DevMod, 0) != DISP_CHANGE_SUCCESSFUL)
{
DoLog("Failed to apply low resolution display settings", MSG_ERROR);
return false;
}
m_bIsLowRes = true;
return true;
}
void CScreenManager::ResetResolution()
{
if(m_bIsLowRes)
{
// Takes the registry settings
ChangeDisplaySettings(NULL, 0);
m_bIsLowRes = false;
}
}