| 1 |
/* |
| 2 |
TextStyler Example |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <ClanLib/core.h> |
| 6 |
#include <ClanLib/application.h> |
| 7 |
#include <ClanLib/display.h> |
| 8 |
#include <ClanLib/gl.h> |
| 9 |
|
| 10 |
#include <iostream> |
| 11 |
#include <string> |
| 12 |
#include <vector> |
| 13 |
|
| 14 |
using namespace std; |
| 15 |
|
| 16 |
class TextStylerApp : public CL_ClanApplication |
| 17 |
{ |
| 18 |
public: |
| 19 |
int main(int, char **) |
| 20 |
{ |
| 21 |
try |
| 22 |
{ |
| 23 |
CL_SetupCore::init(); |
| 24 |
CL_SetupDisplay::init(); |
| 25 |
CL_SetupGL::init(); |
| 26 |
|
| 27 |
CL_ResourceManager resources("ts.xml", false); |
| 28 |
|
| 29 |
CL_DisplayWindow window("ClanLib TextStyler Example", 640, 480); |
| 30 |
CL_TextStyler ts("ts", &resources); |
| 31 |
|
| 32 |
string str; |
| 33 |
str += "The rain in Spain} falls mainly on the plains. Also, all your base are belong to us! Who set up us the bomb? "; |
| 34 |
str += "{{{red}}Foo Bar Narf Bork and many other pastries.{/red} And also, {{narf! "; |
| 35 |
str += "[s 2.0]This text should be doublesize.[s 2.0]This text quadsize.[/s][/s]This text normal. "; |
| 36 |
str += "[s 1.0 2.0]This text doubletall.[/s][s 2.0 1.0]This text doublewide.[/s]This text normal.\n\n"; |
| 37 |
str += "Left aligned.\n"; |
| 38 |
str += "[j right]Right aligned.\n"; |
| 39 |
str += "Still right aligned.\n"; |
| 40 |
str += "Center aligne[j center]d.\n"; |
| 41 |
str += "[/j]Right aligned.\n"; |
| 42 |
str += "[/j]Left aligned.\n"; |
| 43 |
|
| 44 |
CL_Rect drect(25, 25, 600, 440); |
| 45 |
CL_GlyphBuffer gb; |
| 46 |
ts.draw_to_gb(str, gb, drect.get_size()); |
| 47 |
|
| 48 |
unsigned int start_time = CL_System::get_time(); |
| 49 |
int fcount = 0; |
| 50 |
while(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
| 51 |
{ |
| 52 |
++fcount; |
| 53 |
|
| 54 |
CL_Display::clear(CL_Color::white); |
| 55 |
float sx, sy; |
| 56 |
ts.get_scale(sx, sy); |
| 57 |
|
| 58 |
if (CL_Keyboard::get_keycode(CL_KEY_W)) |
| 59 |
{ |
| 60 |
gb.clear(); |
| 61 |
ts.set_scale(sx + 0.01, sy + 0.01); |
| 62 |
ts.draw_to_gb(str, gb, drect.get_size()); |
| 63 |
} |
| 64 |
|
| 65 |
if (CL_Keyboard::get_keycode(CL_KEY_S)) |
| 66 |
{ |
| 67 |
gb.clear(); |
| 68 |
ts.set_scale(sx - 0.01, sy - 0.01); |
| 69 |
ts.draw_to_gb(str, gb, drect.get_size()); |
| 70 |
} |
| 71 |
|
| 72 |
CL_Display::draw_rect(drect, CL_Color::blue); |
| 73 |
CL_Display::draw_rect(gb.bounding_rect(drect), CL_Color::red); |
| 74 |
gb.draw(drect); |
| 75 |
|
| 76 |
unsigned int elapsed_time = CL_System::get_time() - start_time; |
| 77 |
if (elapsed_time >= 1000) |
| 78 |
{ |
| 79 |
cerr << "FPS: " << fcount << "\n"; |
| 80 |
fcount = 0; |
| 81 |
start_time = CL_System::get_time(); |
| 82 |
} |
| 83 |
|
| 84 |
CL_Display::flip(); |
| 85 |
CL_System::keep_alive(); |
| 86 |
} |
| 87 |
|
| 88 |
CL_SetupGL::deinit(); |
| 89 |
CL_SetupDisplay::deinit(); |
| 90 |
CL_SetupCore::deinit(); |
| 91 |
} |
| 92 |
catch (CL_Error err) |
| 93 |
{ |
| 94 |
std::cout << "Exception caught: " << err.message.c_str() << std::endl; |
| 95 |
return -1; |
| 96 |
} |
| 97 |
|
| 98 |
return 0; |
| 99 |
} |
| 100 |
} app; |