| 1 |
#include "glyphbuffertest.h" |
| 2 |
|
| 3 |
#include <string> |
| 4 |
#include <iostream> |
| 5 |
#include <cmath> |
| 6 |
|
| 7 |
using namespace std; |
| 8 |
|
| 9 |
int GlyphBufferTestApp::main(int argc, char** argv) |
| 10 |
{ |
| 11 |
try |
| 12 |
{ |
| 13 |
CL_SetupCore::init(); |
| 14 |
CL_SetupDisplay::init(); |
| 15 |
CL_SetupGL::init(); |
| 16 |
|
| 17 |
CL_ResourceManager resources("data.scr", false); |
| 18 |
CL_DisplayWindow window("ClanLib Glyph Buffer Test", 640, 480); |
| 19 |
CL_Font font("Font", &resources); |
| 20 |
|
| 21 |
CL_Rect drect(55, 10, 505, 450); |
| 22 |
|
| 23 |
unsigned int start_time = CL_System::get_time(); |
| 24 |
|
| 25 |
//Character indexes: 8 10 22 30 42 48 |
| 26 |
string message = "Color : R G B\nScale : 0.5 1.0 1.5\nAngle : 15 30 45\n"; |
| 27 |
message += "Hit escape to exit. WASD to rotate/scale. Space to reset. "; |
| 28 |
message += "This text should be centered in the blue rectangle. The red rectangle is the unrotated, unscaled bounding rect. "; |
| 29 |
message += "Here is the greatest joke in the world: One day, a pirate walked into a bar. "; |
| 30 |
message += "The pirate had a steering wheel strapped to his crotch. The barman asked, \"Why "; |
| 31 |
message += "do you have a steering wheel strapped to your crotch?\". The pirate responded, "; |
| 32 |
message += "\"Arrrr! It's drivin' me nuts!\""; |
| 33 |
|
| 34 |
CL_GlyphBuffer gb; |
| 35 |
gb.set_alignment(origin_center); |
| 36 |
font.set_alignment(origin_center); |
| 37 |
font.draw_to_gb(message, gb, drect.get_size()); |
| 38 |
|
| 39 |
//Assign the effects (note that spaces, newlines, and other characters for which glyphs do not exist, don't go into the glyph buffer) |
| 40 |
map<int, CL_Color>& c = gb.get_color_effects(); |
| 41 |
c[8] = CL_Color::red; |
| 42 |
c[10] = CL_Color::blue; |
| 43 |
c[12] = CL_Color::green; |
| 44 |
|
| 45 |
map<int, float>& sx = gb.get_scale_x_effects(); |
| 46 |
map<int, float>& sy = gb.get_scale_y_effects(); |
| 47 |
sx[22] = sx[23] = sx[24] = sy[22] = sy[23] = sy[24] = 0.5; |
| 48 |
sx[30] = sx[31] = sx[32] = sy[30] = sy[31] = sy[32] = 1.5; |
| 49 |
|
| 50 |
map<int, float>& a = gb.get_angle_effects(); |
| 51 |
a[42] = a[43] = 15; |
| 52 |
a[45] = a[46] = 30; |
| 53 |
a[48] = a[49] = 45; |
| 54 |
|
| 55 |
int elapsed_time = CL_System::get_time() - start_time; |
| 56 |
cout << "Time elapsed filling GlyphBuffer is " << elapsed_time << " milliseconds.\n"; |
| 57 |
cout << "Glyph Buffer glyphs size is " << gb.get_glyphs().size() << "\n"; |
| 58 |
|
| 59 |
while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
| 60 |
{ |
| 61 |
CL_Display::clear(CL_Color::white); |
| 62 |
|
| 63 |
CL_Display::draw_rect(drect, CL_Color::blue); |
| 64 |
CL_Display::draw_rect(gb.bounding_rect(drect), CL_Color::red); |
| 65 |
gb.draw(drect); |
| 66 |
|
| 67 |
if (CL_Keyboard::get_keycode(CL_KEY_A)) |
| 68 |
gb.rotate(-1); |
| 69 |
|
| 70 |
if (CL_Keyboard::get_keycode(CL_KEY_D)) |
| 71 |
gb.rotate(1); |
| 72 |
|
| 73 |
if (CL_Keyboard::get_keycode(CL_KEY_W)) |
| 74 |
{ |
| 75 |
float scale_x, scale_y; |
| 76 |
gb.get_scale(scale_x, scale_y); |
| 77 |
gb.set_scale(scale_x + 0.01, scale_y + 0.01); |
| 78 |
} |
| 79 |
|
| 80 |
if (CL_Keyboard::get_keycode(CL_KEY_S)) |
| 81 |
{ |
| 82 |
float scale_x, scale_y; |
| 83 |
gb.get_scale(scale_x, scale_y); |
| 84 |
gb.set_scale(scale_x - 0.01, scale_y - 0.01); |
| 85 |
} |
| 86 |
|
| 87 |
if (CL_Keyboard::get_keycode(CL_KEY_SPACE)) |
| 88 |
{ |
| 89 |
gb.set_angle(0); |
| 90 |
gb.set_scale(1.0, 1.0); |
| 91 |
} |
| 92 |
|
| 93 |
CL_Display::flip(); |
| 94 |
CL_System::keep_alive(15); |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
CL_SetupGL::deinit(); |
| 99 |
CL_SetupDisplay::deinit(); |
| 100 |
CL_SetupCore::deinit(); |
| 101 |
} |
| 102 |
catch (CL_Error err) |
| 103 |
{ |
| 104 |
cout << "Fatal error: " << err.message << endl; |
| 105 |
abort(); |
| 106 |
} |
| 107 |
|
| 108 |
return 0; |
| 109 |
} |