Skip to content

Commit 30c1b12

Browse files
committed
Modernize code a bit.
1 parent 9365b4b commit 30c1b12

14 files changed

+305
-231
lines changed

ExampleFloatingPoint.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
#include "PixelToaster.h"
66

7+
#ifdef PIXELTOASTER_NO_STL
8+
# include <vector>
9+
using std::vector;
10+
#endif
11+
712
using namespace PixelToaster;
813

914
int main()
@@ -31,6 +36,10 @@ int main()
3136
}
3237
}
3338

39+
#ifdef PIXELTOASTER_NO_STL
40+
display.update(pixels.data());
41+
#else
3442
display.update(pixels);
43+
#endif
3544
}
3645
}

ExampleFullscreen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
#include "PixelToaster.h"
66

7+
#ifdef PIXELTOASTER_NO_STL
8+
# include <vector>
9+
using std::vector;
10+
#endif
11+
712
using namespace PixelToaster;
813

914
int main()
@@ -31,6 +36,10 @@ int main()
3136
}
3237
}
3338

39+
#ifdef PIXELTOASTER_NO_STL
40+
display.update(pixels.data());
41+
#else
3442
display.update(pixels);
43+
#endif
3544
}
3645
}

ExampleImage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
#include <cstdio>
66
#include "PixelToaster.h"
77

8+
#ifdef PIXELTOASTER_NO_STL
9+
# include <vector>
10+
using std::vector;
11+
#endif
12+
813
using namespace PixelToaster;
914

1015
bool load(const char filename[], int& width, int& height, vector<Pixel>& pixels);
@@ -28,7 +33,13 @@ int main()
2833
Display display("Image Example", width, height);
2934

3035
while (display.open())
36+
{
37+
#ifdef PIXELTOASTER_NO_STL
38+
display.update(pixels.data());
39+
#else
3140
display.update(pixels);
41+
#endif
42+
}
3243

3344
return 0;
3445
}

ExampleKeyboardAndMouse.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
#include <cstdio>
66
#include "PixelToaster.h"
77

8+
#ifdef PIXELTOASTER_NO_STL
9+
# include <vector>
10+
using std::vector;
11+
#endif
12+
813
using namespace PixelToaster;
914

1015
class Application : public Listener
@@ -38,29 +43,33 @@ class Application : public Listener
3843
}
3944
}
4045

46+
#ifdef PIXELTOASTER_NO_STL
47+
display.update(pixels.data());
48+
#else
4149
display.update(pixels);
50+
#endif
4251
}
4352

4453
return 0;
4554
}
4655

4756
protected:
48-
void onKeyDown(DisplayInterface& display, Key key)
57+
virtual void onKeyDown(DisplayInterface& display, Key key) override
4958
{
5059
printf("onKeyDown: key=%s\n", getKeyString(key));
5160
}
5261

53-
void onKeyPressed(DisplayInterface& display, Key key)
62+
virtual void onKeyPressed(DisplayInterface& display, Key key) override
5463
{
5564
printf("onKeyPressed: key=%s\n", getKeyString(key));
5665
}
5766

58-
void onKeyUp(DisplayInterface& display, Key key)
67+
virtual void onKeyUp(DisplayInterface& display, Key key) override
5968
{
6069
printf("onKeyUp: key=%s\n", getKeyString(key));
6170
}
6271

63-
void onMouseButtonDown(DisplayInterface& display, Mouse mouse)
72+
virtual void onMouseButtonDown(DisplayInterface& display, Mouse mouse) override
6473
{
6574
printf("onMouseButtonDown: buttons=%d,%d,%d x=%f, y=%f\n",
6675
mouse.buttons.left,
@@ -70,7 +79,7 @@ class Application : public Listener
7079
mouse.y);
7180
}
7281

73-
void onMouseButtonUp(DisplayInterface& display, Mouse mouse)
82+
virtual void onMouseButtonUp(DisplayInterface& display, Mouse mouse) override
7483
{
7584
printf("onMouseButtonUp: buttons=%d,%d,%d x=%f, y=%f\n",
7685
mouse.buttons.left,
@@ -80,7 +89,7 @@ class Application : public Listener
8089
mouse.y);
8190
}
8291

83-
void onMouseMove(DisplayInterface& display, Mouse mouse)
92+
virtual void onMouseMove(DisplayInterface& display, Mouse mouse) override
8493
{
8594
printf("onMouseMove: buttons=%d,%d,%d x=%f, y=%f\n",
8695
mouse.buttons.left,
@@ -90,12 +99,12 @@ class Application : public Listener
9099
mouse.y);
91100
}
92101

93-
void onActivate(DisplayInterface& display, bool active)
102+
virtual void onActivate(DisplayInterface& display, bool active) override
94103
{
95104
printf("onActivate: active=%d\n", active);
96105
}
97106

98-
void onOpen(DisplayInterface& display)
107+
virtual void onOpen(DisplayInterface& display) override
99108
{
100109
printf("onOpen: \"%s\", %d x %d ", display.title(), display.width(), display.height());
101110
switch (display.mode())
@@ -111,7 +120,7 @@ class Application : public Listener
111120
}
112121
}
113122

114-
bool onClose(DisplayInterface& display)
123+
virtual bool onClose(DisplayInterface& display) override
115124
{
116125
printf("onClose");
117126
return true;

ExampleMultiDisplay.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55
#include "PixelToaster.h"
66
#include <stdio.h>
77

8+
#ifdef PIXELTOASTER_NO_STL
9+
# include <vector>
10+
using std::vector;
11+
#endif
12+
813
using namespace PixelToaster;
914

1015
class MultiDisplayListener : public Listener
1116
{
12-
void onOpen(DisplayInterface& display)
17+
void onOpen(DisplayInterface& display) override
1318
{
1419
printf("open: %s\n", display.title());
1520
}
1621

17-
bool onClose(DisplayInterface& display)
22+
bool onClose(DisplayInterface& display) override
1823
{
1924
printf("close: %s\n", display.title());
2025
return true;
2126
}
2227

23-
void onMouseMove(DisplayInterface& display, Mouse mouse)
28+
void onMouseMove(DisplayInterface& display, Mouse mouse) override
2429
{
2530
printf("%s: mouse move (%f,%f)\n",
2631
display.title(),
@@ -65,12 +70,30 @@ int main()
6570
}
6671

6772
if (a.open())
73+
{
74+
#ifdef PIXELTOASTER_NO_STL
75+
a.update(pixels.data());
76+
#else
6877
a.update(pixels);
78+
#endif
79+
}
6980

7081
if (b.open())
82+
{
83+
#ifdef PIXELTOASTER_NO_STL
84+
b.update(pixels.data());
85+
#else
7186
b.update(pixels);
87+
#endif
88+
}
7289

7390
if (c.open())
91+
{
92+
#ifdef PIXELTOASTER_NO_STL
93+
c.update(pixels.data());
94+
#else
7495
c.update(pixels);
96+
#endif
97+
}
7598
}
7699
}

ExampleTrueColor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
#include "PixelToaster.h"
66

7+
#ifdef PIXELTOASTER_NO_STL
8+
# include <vector>
9+
using std::vector;
10+
#endif
11+
712
using namespace PixelToaster;
813

914
int main()
@@ -31,6 +36,10 @@ int main()
3136
}
3237
}
3338

39+
#ifdef PIXELTOASTER_NO_STL
40+
display.update(pixels.data());
41+
#else
3442
display.update(pixels);
43+
#endif
3544
}
3645
}

PixelToaster.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@
3939
# error unknown pixeltoaster platform!
4040
#endif
4141

42-
PixelToaster::DisplayInterface* PixelToaster::createDisplay()
42+
PIXELTOASTER_API PixelToaster::DisplayInterface* PixelToaster::createDisplay()
4343
{
4444
#ifdef DisplayClass
4545
return new DisplayClass();
4646
#else
47-
return NULL;
47+
return nullptr;
4848
#endif
4949
}
5050

51-
PixelToaster::TimerInterface* PixelToaster::createTimer()
51+
PIXELTOASTER_API PixelToaster::TimerInterface* PixelToaster::createTimer()
5252
{
5353
#ifdef TimerClass
5454
return new TimerClass();
5555
#else
56-
return NULL;
56+
return nullptr;
5757
#endif
5858
}
5959

@@ -77,7 +77,7 @@ PixelToaster::Converter_XRGB8888_to_BGR565 converter_XRGB8888_to_BGR565;
7777
PixelToaster::Converter_XRGB8888_to_XRGB1555 converter_XRGB8888_to_XRGB1555;
7878
PixelToaster::Converter_XRGB8888_to_XBGR1555 converter_XRGB8888_to_XBGR1555;
7979

80-
PixelToaster::Converter* PixelToaster::requestConverter(PixelToaster::Format source, PixelToaster::Format destination)
80+
PIXELTOASTER_API PixelToaster::Converter* PixelToaster::requestConverter(PixelToaster::Format source, PixelToaster::Format destination)
8181
{
8282
if (source == Format::XBGRFFFF)
8383
{
@@ -94,7 +94,7 @@ PixelToaster::Converter* PixelToaster::requestConverter(PixelToaster::Format sou
9494
case Format::XBGR1555: return &converter_XBGRFFFF_to_XBGR1555;
9595

9696
default:
97-
return NULL;
97+
return nullptr;
9898
}
9999
}
100100
else if (source == Format::XRGB8888)
@@ -112,9 +112,9 @@ PixelToaster::Converter* PixelToaster::requestConverter(PixelToaster::Format sou
112112
case Format::XBGR1555: return &converter_XRGB8888_to_XBGR1555;
113113

114114
default:
115-
return NULL;
115+
return nullptr;
116116
}
117117
}
118118

119-
return NULL;
119+
return nullptr;
120120
}

0 commit comments

Comments
 (0)