-
Notifications
You must be signed in to change notification settings - Fork 9
/
ExampleMultiDisplay.cpp
99 lines (81 loc) · 2.03 KB
/
ExampleMultiDisplay.cpp
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
// Multiple Displays Example.
// Demonstrates how to open and update multiple displays.
// Part of the PixelToaster Framebuffer Library - http://www.pixeltoaster.com
#include "PixelToaster.h"
#include <stdio.h>
#ifdef PIXELTOASTER_NO_STL
# include <vector>
using std::vector;
#endif
using namespace PixelToaster;
class MultiDisplayListener : public Listener
{
void onOpen(DisplayInterface& display) override
{
printf("open: %s\n", display.title());
}
bool onClose(DisplayInterface& display) override
{
printf("close: %s\n", display.title());
return true;
}
void onMouseMove(DisplayInterface& display, Mouse mouse) override
{
printf("%s: mouse move (%f,%f)\n",
display.title(),
mouse.x,
mouse.y);
}
};
MultiDisplayListener listener;
int main()
{
const int width = 320;
const int height = 240;
Display a, b, c;
a.listener(&listener);
b.listener(&listener);
c.listener(&listener);
a.open("Display A", width, height);
b.open("Display B", width, height);
c.open("Display C", width, height);
vector<Pixel> pixels(width * height);
while (a.open() || b.open() || c.open())
{
unsigned int index = 0;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
pixels[index].r = 0.1f + (x + y) * 0.0015f;
pixels[index].g = 0.5f + (x + y) * 0.001f;
pixels[index].b = 0.7f + (x + y) * 0.0005f;
++index;
}
}
if (a.open())
{
#ifdef PIXELTOASTER_NO_STL
a.update(pixels.data());
#else
a.update(pixels);
#endif
}
if (b.open())
{
#ifdef PIXELTOASTER_NO_STL
b.update(pixels.data());
#else
b.update(pixels);
#endif
}
if (c.open())
{
#ifdef PIXELTOASTER_NO_STL
c.update(pixels.data());
#else
c.update(pixels);
#endif
}
}
}