Debian Codegraph @

Tests/BlitterTest/main.cpp

raw
1 #include <ClanLib/application.h>
2 #include <ClanLib/core.h>
3 #include <ClanLib/display.h>
4 #include <ClanLib/dx7.h>
5
6 /////////////////////////////////////////////////////////////////////////////
7 // Application class
8
9 class Application : public CL_ClanApplication
10 {
11 public:
12 int main(int argc, char** argv);
13
14 void blitter_test(CL_DisplayWindow &window);
15 void on_input_down(const CL_InputEvent &key);
16
17 bool quit;
18 } app;
19
20 /////////////////////////////////////////////////////////////////////////////
21 // Application main entry point:
22
23 int Application::main(int argc, char** argv)
24 {
25 CL_ConsoleWindow debug_console("Debug console");
26 debug_console.redirect_stdio();
27 try
28 {
29 CL_SetupCore::init();
30 CL_SetupDisplay::init();
31 CL_SetupDX7::init();
32
33 CL_DisplayWindow window("ClanLib clanDisplay 2.0 test program", 800, 600);
34
35 CL_Slot slot_input_down = CL_Keyboard::sig_key_down().connect(
36 this, &Application::on_input_down);
37
38 quit = false;
39
40 blitter_test(window);
41
42 CL_SetupDX7::deinit();
43 CL_SetupDisplay::deinit();
44 CL_SetupCore::deinit();
45 }
46 catch (CL_Error error)
47 {
48 std::cout << "Uncaught error: " << error.message.c_str() << std::endl;
49 debug_console.wait_for_key();
50 }
51
52 return 0;
53 }
54
55 void Application::on_input_down(const CL_InputEvent &key)
56 {
57 std::cout << "Key down: " << key.device.get_key_name(key.id).c_str() << " (" << key.id << ")" << std::endl;
58 if (key.id == CL_KEY_ESCAPE) quit = true;
59 }
60
61 void Application::blitter_test(CL_DisplayWindow &window)
62 {
63 static int col = 0;
64 static int col_delta = 1;
65
66 std::list<CL_Surface> images;
67 std::list<std::string> text;
68
69 images.push_back(CL_Surface(new CL_PCXProvider("images/test8.pcx"), true)); text.push_back("test8.pcx");
70 images.push_back(CL_Surface(new CL_PNGProvider("images/test8.png"), true)); text.push_back("test8.png");
71 images.push_back(CL_Surface(new CL_TargaProvider("images/test8.tga"), true)); text.push_back("test8.tga");
72 images.push_back(CL_Surface(new CL_PNGProvider("images/test8_alpha.png"), true)); text.push_back("test8_alpha.png");
73 images.push_back(CL_Surface(new CL_TargaProvider("images/test16.tga"), true)); text.push_back("test16.tga");
74 images.push_back(CL_Surface(new CL_JPEGProvider("images/test24.jpg"), true)); text.push_back("test24.jpg");
75 images.push_back(CL_Surface(new CL_PCXProvider("images/test24.pcx"), true)); text.push_back("test24.pcx");
76 images.push_back(CL_Surface(new CL_PNGProvider("images/test24.png"), true)); text.push_back("test24.png");
77 images.push_back(CL_Surface(new CL_TargaProvider("images/test24.tga"), true)); text.push_back("images/test24.tga");
78 images.push_back(CL_Surface(new CL_PNGProvider("images/test32.png"), true)); text.push_back("images/test32.png");
79 images.push_back(CL_Surface(new CL_TargaProvider("images/test32.tga"), true)); text.push_back("images/test32.tga");
80 images.push_back(CL_Surface(new CL_PNGProvider("images/test32_alpha.png"), true)); text.push_back("images/test32_alpha.png");
81 images.push_back(CL_Surface(new CL_TargaProvider("images/test32_alpha.tga"), true)); text.push_back("images/test32_alpha.tga");
82
83 CL_GraphicContext *gc = window.get_gc();
84
85 CL_Font sysfont("Comic Sans MS", 15);
86 sysfont.set_alignment(origin_center);
87
88 while (!quit)
89 {
90 // Clear screen
91 CL_Display::clear(CL_Color(col, col, 0));
92
93 // Fade background between black and white
94 col += col_delta;
95 if(col > 255 || col < 0)
96 {
97 col_delta = -col_delta;
98 col += col_delta;
99 }
100
101 gc->draw_line(200, 0, 200, 600, CL_Color(100,100,100));
102 gc->draw_line(600, 0, 600, 600, CL_Color(100,100,100));
103
104 gc->draw_line(0, 150, 800, 150, CL_Color(100,100,100));
105 gc->draw_line(0, 450, 800, 450, CL_Color(100,100,100));
106
107 gc->draw_line(400, 0, 400, 600, CL_Color(255,255,255));
108 gc->draw_line(0, 300, 800, 300, CL_Color(255,255,255));
109
110 int x = 0;
111 int y = 0;
112 std::list<CL_Surface>::iterator i1;
113 std::list<std::string>::iterator i2;
114 for(i1 = images.begin(), i2 = text.begin(); i1 != images.end(); ++i1, ++i2)
115 {
116 (*i1).set_scale(0.37f, 0.37f);
117 (*i1).draw(x + 5, y + 5);
118 sysfont.draw(x + 100, y + 140, (*i2));
119
120 x += 200;
121 if(x == 800)
122 {
123 x = 0;
124 y += 150;
125 }
126
127 break; // only draw first image for now (needed for dx7 testing)
128 }
129
130 window.flip();
131 CL_System::keep_alive(10);
132 }
133
134 quit = false;
135 }