-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderer.cpp
More file actions
75 lines (59 loc) · 2.33 KB
/
Copy pathRenderer.cpp
File metadata and controls
75 lines (59 loc) · 2.33 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
#include <chrono>
#include <memory>
#include <random>
#include <sstream>
#include <thread>
#include "BackgroundWindowManager.h"
#include "LandscapeGenerator.h"
#include "Renderer.h"
using namespace std;
CRenderer::CRenderer()
{
}
bool CRenderer::Process(int x, int y, int width, int height)
{
auto now = chrono::system_clock::now();
if (m_lastTime + chrono::seconds(5) > now && width == m_lastWidth && height == m_lastHeight)
{
if (x != m_lastX || y != m_lastY) // Monitor needs an update but we don't need to regenerate anything
{
m_lastX = x;
m_lastY = y;
return true;
}
return false;
}
m_lastTime = now;
m_lastX = x;
m_lastY = y;
m_lastWidth = width;
m_lastHeight = height;
vector<pair<Coord<int>, Coord<int>>> coordSets = { { { 0, static_cast<int>(0.7 * height) }, { width, static_cast<int>(0.64 * height) } },
{ { 0, static_cast<int>(0.54 * height) }, { width, static_cast<int>(0.38 * height) } },
{ { 0, static_cast<int>(0.36 * height) }, { width, static_cast<int>(0.16 * height) } },
{ { static_cast<int>(0.25 * width), static_cast<int>(0) }, { width, static_cast<int>(0.4 * height) } } };
for (auto & coordSet : coordSets)
{
coordSet.first.y += (m_generator() % 200) - 100;
coordSet.second.y += (m_generator() % 200) - 100;
}
vector<Layer> layers;
layers.push_back(midpointDisplacement(coordSets[0].first, coordSets[0].second, 1.2, 540, 8));
layers.push_back(midpointDisplacement(coordSets[1].first, coordSets[1].second, 1, 259, 9));
layers.push_back(midpointDisplacement(coordSets[2].first, coordSets[2].second, 1.2, 65, 12));
layers.push_back(midpointDisplacement(coordSets[3].first, coordSets[3].second, 1.4, 43, 12));
m_landscape = drawLayers(layers, width, height, "");
return true;
}
void CRenderer::Render(HDC hDC, int x, int y, int width, int height)
{
if (hDC == nullptr || m_landscape == nullptr || width != m_lastWidth || height != m_lastHeight)
return;
HBITMAP hBitmap = CreateBitmap(width, height, 1, 32, m_landscape.get());
HDC hdcMem = CreateCompatibleDC(hDC);
HGDIOBJ oldBitmap = SelectObject(hdcMem, hBitmap);
BitBlt(hDC, x, y, width, height, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, oldBitmap);
DeleteDC(hdcMem);
DeleteObject(hBitmap);
}