-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.cpccScreenSaverAbstract.h
171 lines (136 loc) · 5.67 KB
/
app.cpccScreenSaverAbstract.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* *****************************************
* File: app.cpccScreenSaverAbstract.h
* Purpose: Portable (cross-platform), light-weight, library
* screensaver interface with windows and OSX
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2014 StarMessage software.
* License: Free for opensource projects.
* Commercial license exists for closed source projects.
* Web: http://www.StarMessageSoftware.com/cpcclibrary
* Download: https://github.com/starmessage/cpcc
* email: sales -at- starmessage.info
* *****************************************
*/
#pragma once
#include <string>
#include <vector>
#include "app.cpccScreenSaverInterface.h"
#include "gui.cpccWindow.h"
#include "core.cpccHardware.h"
class cpccScreenSaverAbstract: public cpccScreenSaverInterface
{
private:
logObjectLife objLog;
cpcc_string m_containerFolder;
protected: // data
cpccWindowBase* DesktopWindowPtr;
std::vector<cpccRecti> m_drawRegions;
protected: // constructor/destructor
cpccScreenSaverAbstract():
DesktopWindowPtr(NULL),
// m_PreserveDeskopContents(false), // opaque by default
objLog((cpcc_char *) _T("cpccScreenSaverAbstract"))
{
// infoLog().addf(_T("Program: %s %s"), cpccAppInfo::ProgramName, cpccAppInfo::Version);
}
virtual ~cpccScreenSaverAbstract()
{
if (DesktopWindowPtr)
{
delete(DesktopWindowPtr);
DesktopWindowPtr=NULL;
}
}
private: // functions
// bit blit from buffer to screen
virtual void flushOneFrame(void) override
{ // appLog.addInfof("cpccScreenSaverAbstract.flushOneFrame() #%i", mFramesElapsed);
if (DesktopWindowPtr)
DesktopWindowPtr->flush();
// appLog.addInfof("cpccScreenSaverAbstract.flushOneFrame() #%i exiting", mFramesElapsed);
}
protected: // screensaver standard functions
virtual void setContainerFolder(const cpcc_char *aFolder) override
{
if (!aFolder)
{
m_containerFolder = _T("");
errorLog().add("screensaver's container folder:NULL");
return;
}
m_containerFolder = aFolder;
infoLog().addf("screensaver's container folder:%s", aFolder);
}
const cpcc_char* getContainerFolder(void) const
{
return m_containerFolder.c_str();
}
void calcDrawRegionsAndOffset(const int monitorID, const int aDpiScaleFactor)
{
#ifdef _WIN32
if (monitorID == -1)
{
// DesktopWindowPtr->setOffset(-DesktopWindowPtr->getLeft(), -DesktopWindowPtr->getTop());
cpccRecti rect = DesktopWindowPtr->getBounds();
rect.left = 0;
rect.top = 0;
m_drawRegions.push_back(rect);
return;
}
if (monitorID != -1)
{
cpccMonitorList list;
cpccHardware::getListOfMonitors(list);
if (list.size() > 0)
{
// report on monitors found
infoLog().addf(_T("Number of monitors for the drawRegions:%i"), list.size());
int min_left = 0, min_top = 0, i = 0;
for (const auto& monitor : list)
{
cpccRecti rect(monitor.left, monitor.top, monitor.right, monitor.bottom);
infoLog().addf(_T("Monitor rect:%s"), rect.asString().c_str());
m_drawRegions.push_back(rect);
if (i == 0) // first iteration
{ // put initial values
min_left = monitor.left;
min_top = monitor.top;
}
else
{
if (min_left > monitor.left)
min_left = monitor.left;
if (min_top > monitor.top)
min_top = monitor.top;
}
++i;
}
// remove the minimum
if (min_left != 0)
for (auto& r : m_drawRegions)
r.left -= min_left;
if (min_top != 0)
for (auto& r : m_drawRegions)
r.top -= min_top;
// infoLog().addf(_T("setOffset x=%i, y=%i"), -min_left, -min_top);
// DesktopWindowPtr->setOffset(-min_left, -min_top);
return;
}
}
#endif
m_drawRegions.push_back(DesktopWindowPtr->getBounds());
//debugLog().addf(_T("calcDrawRegionsAndOffset %s"), DesktopWindowPtr->getBounds().asString().c_str());
}
// todo: rename: initWithWindowHandleAndRect
virtual void initWithWindowHandle( cpccNativeWindowHandle wHandle, const int monitorId, const int dpiScaleFactor) override
{
infoLog().addf( _T("cpccScreenSaverAbstract.initWithWindowHandle(%X)"), (cpccNativeWindowHandle) wHandle);
if (!DesktopWindowPtr)
DesktopWindowPtr = new cpccWindow(wHandle);
// infoLog().addf( _T("TopLeft:%i,%i screen width:%i, height:%i"), DesktopWindowPtr->getTop(), DesktopWindowPtr->getLeft(), DesktopWindowPtr->getWidth(), DesktopWindowPtr->getHeight());
infoLog().addf(_T("Screensaver container folder:%s"), getContainerFolder());
calcDrawRegionsAndOffset(monitorId, dpiScaleFactor);
}
virtual void shutDown(void) override { }
};