| 1 | // |
| 2 | // "$Id$" |
| 3 | // |
| 4 | // Unit tests for the Fast Light Tool Kit (FLTK). |
| 5 | // |
| 6 | // Copyright 1998-2010 by Bill Spitzak and others. |
| 7 | // |
| 8 | // This library is free software. Distribution and use rights are outlined in |
| 9 | // the file "COPYING" which should have been included with this file. If this |
| 10 | // file is missing or damaged, see the license at: |
| 11 | // |
| 12 | // http://www.fltk.org/COPYING.php |
| 13 | // |
| 14 | // Please report all bugs and problems on the following page: |
| 15 | // |
| 16 | // http://www.fltk.org/str.php |
| 17 | // |
| 18 | |
| 19 | #include <FL/Fl_Box.H> |
| 20 | #include <FL/fl_draw.H> |
| 21 | |
| 22 | // |
| 23 | // Test symbol rendering |
| 24 | // |
| 25 | class SymbolTest : public Fl_Widget |
| 26 | { |
| 27 | void DrawTextAndBoxes(const char *txt, int X, int Y) { |
| 28 | int wo = 0, ho = 0; |
| 29 | fl_measure(txt, wo, ho, 1); |
| 30 | // Draw fl_measure() rect |
| 31 | fl_color(FL_RED); |
| 32 | fl_rect(X, Y, wo, ho); |
| 33 | // ////////////////////////////////////////////////////////////////////// |
| 34 | // NOTE: fl_text_extents() currently does not support multiline strings.. |
| 35 | // until it does, let's leave this out, as we do multiline tests.. |
| 36 | // ////////////////////////////////////////////////////////////////////// |
| 37 | // // draw fl_text_extents() glyph bounding box |
| 38 | // int dx,dy; |
| 39 | // fl_text_extents(txt, dx, dy, wo, ho); |
| 40 | // fl_color(FL_GREEN); |
| 41 | // fl_rect(X+dx, Y+dy, wo, ho); |
| 42 | // |
| 43 | // Draw text with symbols enabled |
| 44 | fl_color(FL_BLACK); |
| 45 | fl_draw(txt, X, Y, 10, 10, FL_ALIGN_INSIDE|FL_ALIGN_TOP|FL_ALIGN_LEFT, 0, 1); |
| 46 | } |
| 47 | public: |
| 48 | static Fl_Widget *create() { |
| 49 | return new SymbolTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); |
| 50 | } |
| 51 | SymbolTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {} |
| 52 | void draw(void) { |
| 53 | int x0 = x(); // origin is current window position for Fl_Box |
| 54 | int y0 = y(); |
| 55 | int w0 = w(); |
| 56 | int h0 = h(); |
| 57 | fl_push_clip(x0, y0, w0, h0); // reset local clipping |
| 58 | { |
| 59 | // set the background colour - slightly off-white to enhance the green bounding box |
| 60 | fl_color(fl_gray_ramp(FL_NUM_GRAY - 3)); |
| 61 | fl_rectf(x0, y0, w0, h0); |
| 62 | int fsize = 25; |
| 63 | fl_font(FL_HELVETICA, fsize); |
| 64 | int xx = x0+10; |
| 65 | int yy = y0+10; |
| 66 | DrawTextAndBoxes("Text" ,xx,yy); yy += fsize+10; // check no symbols |
| 67 | DrawTextAndBoxes("@->" ,xx,yy); yy += fsize+10; // check symbol alone |
| 68 | DrawTextAndBoxes("@-> " ,xx,yy); yy += fsize+10; // check symbol with trailing space |
| 69 | DrawTextAndBoxes("@-> Rt Arrow" ,xx,yy); yy += fsize+10; // check symbol at left edge |
| 70 | DrawTextAndBoxes("Lt Arrow @<-" ,xx,yy); yy += fsize+10; // check symbol at right edge |
| 71 | DrawTextAndBoxes("@-> Rt/Lt @<-" ,xx,yy); yy += fsize+10; // check symbol at lt+rt edges |
| 72 | DrawTextAndBoxes("@@ At/Lt @<-" ,xx,yy); yy += fsize+10; // check @@ at left, symbol at right |
| 73 | DrawTextAndBoxes("@-> Lt/At @@" ,xx,yy); yy += fsize+10; // check symbol at left, @@ at right |
| 74 | DrawTextAndBoxes("@@ At/At @@" ,xx,yy); yy += fsize+10; // check @@ at left+right |
| 75 | xx = x0+200; |
| 76 | yy = y0+10; |
| 77 | DrawTextAndBoxes("Line1\nLine2" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, no symbol |
| 78 | DrawTextAndBoxes("@-> Line1\nLine2 @<-" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, lt+rt symbols |
| 79 | DrawTextAndBoxes("@-> Line1\nLine2\nLine3 @<-",xx,yy); yy += (fsize+10)*3; // check 3 lines, lt+rt symbols |
| 80 | DrawTextAndBoxes("@@@@" ,xx,yy); yy += (fsize+10); // check abutting @@'s |
| 81 | DrawTextAndBoxes("@@ @@" ,xx,yy); yy += (fsize+10); // check @@'s with space sep |
| 82 | |
| 83 | fl_font(FL_HELVETICA, 14); |
| 84 | fl_color(FL_RED); |
| 85 | fl_draw("fl_measure bounding box in RED", x0+10,y0+h0-20); |
| 86 | } |
| 87 | fl_pop_clip(); // remove the local clip |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | UnitTest symbolExtents("symbol text", SymbolTest::create); |
| 92 | |
| 93 | // |
| 94 | // End of "$Id$" |
| 95 | // |