Debian Codegraph @

Tests/FontTest/fonttest.cpp

raw
1 #include "fonttest.h"
2
3 #include <string>
4 #include <iostream>
5 #include <cmath>
6
7 using namespace std;
8
9
10 void do_test(
11 const CL_Rect &rect,
12 CL_Origin origin,
13 const string &descrip,
14 CL_Font font,
15 bool print_time)
16 {
17 string message = descrip + " Hit escape to exit. ";
18 message += "Here is the greatest joke in the world: One day, a pirate walked into a bar. ";
19 message += "The pirate had a steering wheel strapped to his crotch. The barman asked, \"Why ";
20 message += "do you have a steering wheel strapped to your crotch?\". The pirate responded, ";
21 message += "\"Arrrr! It's drivin' me nuts!\"";
22
23 font.set_alignment(origin);
24 font.set_color(CL_Color::red);
25
26 unsigned int start_time = CL_System::get_time();
27 font.draw(rect, message);
28 int elapsed_time = CL_System::get_time() - start_time;
29
30 CL_Display::draw_rect(rect, CL_Color::blue);
31
32 if (print_time)
33 cout << descrip << ": " << elapsed_time << " milliseconds.\n";
34 }
35
36 int FontTestApp::main(int argc, char** argv)
37 {
38 try
39 {
40 CL_SetupCore::init();
41 CL_SetupDisplay::init();
42 CL_SetupGL::init();
43
44 CL_ResourceManager resources("data.scr", false);
45 CL_DisplayWindow window("ClanLib Font Test", 640, 480);
46 CL_Font font("Font", &resources);
47
48 int framec = 0;
49 bool show_times = false;
50
51 while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
52 {
53 CL_Display::clear(CL_Color::white);
54
55 do_test(CL_Rect(20, 20, 206, 153), origin_top_left, "Top left alignment", font, show_times);
56 do_test(CL_Rect(226, 20, 412, 153), origin_top_center, "Top center alignment", font, show_times);
57 do_test(CL_Rect(432, 20, 618, 153), origin_top_right, "Top right alignment", font, show_times);
58 do_test(CL_Rect(20, 173, 206, 306), origin_center_left, "Center left alignment", font, show_times);
59 do_test(CL_Rect(226, 173, 412, 306), origin_center, "Center alignment", font, show_times);
60 do_test(CL_Rect(432, 173, 618, 306), origin_center_right, "Center right alignment", font, show_times);
61 do_test(CL_Rect(20, 326, 206, 459), origin_bottom_left, "Bottom left alignment", font, show_times);
62 do_test(CL_Rect(226, 326, 412, 459), origin_bottom_center, "Bottom center alignment", font, show_times);
63 do_test(CL_Rect(432, 326, 618, 459), origin_bottom_right, "Bottom right alignment", font, show_times);
64
65 CL_Display::flip();
66 CL_System::keep_alive(10);
67
68 ++framec;
69
70 if (framec % 200 == 0)
71 show_times = true;
72 else
73 show_times = false;
74 }
75
76 CL_SetupGL::deinit();
77 CL_SetupDisplay::deinit();
78 CL_SetupCore::deinit();
79 }
80 catch (CL_Error err)
81 {
82 cout << "Fatal error: " << err.message << endl;
83 abort();
84 }
85
86 return 0;
87 }