diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2009-04-12 13:48:03 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2009-04-12 13:48:03 +0000 |
| commit | afe1b90dd012216b007112dc5c92f22a1f034bd7 (patch) | |
| tree | 4901f175dfc467c1fad640657e9f0db4f823c8d4 | |
| parent | fcfe41ee0566038fcc6c690569b4d04469f43b06 (diff) | |
Reorganized Unittest / fixed and improved OS X keybord support and alternative input methods / fixed OS X utf8 DnD
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6755 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | CHANGES | 6 | ||||
| -rw-r--r-- | src/Fl_get_key_mac.cxx | 4 | ||||
| -rw-r--r-- | src/Fl_mac.cxx | 97 | ||||
| -rw-r--r-- | src/fl_dnd_mac.cxx | 2 | ||||
| -rw-r--r-- | src/fl_rect.cxx | 4 | ||||
| -rw-r--r-- | src/fl_shortcut.cxx | 42 | ||||
| -rw-r--r-- | test/Makefile | 3 | ||||
| -rw-r--r-- | test/unittest_about.cxx | 66 | ||||
| -rw-r--r-- | test/unittest_circles.cxx | 99 | ||||
| -rw-r--r-- | test/unittest_images.cxx | 99 | ||||
| -rw-r--r-- | test/unittest_lines.cxx | 75 | ||||
| -rw-r--r-- | test/unittest_points.cxx | 69 | ||||
| -rw-r--r-- | test/unittest_rects.cxx | 66 | ||||
| -rw-r--r-- | test/unittest_text.cxx | 97 | ||||
| -rw-r--r-- | test/unittest_viewport.cxx | 64 | ||||
| -rw-r--r-- | test/unittests.cxx | 531 | ||||
| -rw-r--r-- | test/utf8.cxx | 39 |
17 files changed, 927 insertions, 436 deletions
@@ -1,5 +1,11 @@ CHANGES IN FLTK 1.3.0 + - Added alternative text input awareness on OS X + - Fixed 'del' keycode on OS X (must be verified for all keyboards) + - Fixed OS X support for sending and receiving dnd data as utf8 + - Added drop box to utf8 test that will show the utf8 encoding + for the first dropped character + - Restructured the unittest application - Updated the bundled libpng to v1.2.35 (released 18 Feb. 2009) - Fl_Preferences.H now doesn't include windows.h any more (Windows only, STR #2173). diff --git a/src/Fl_get_key_mac.cxx b/src/Fl_get_key_mac.cxx index 63d660251..afdeddb7b 100644 --- a/src/Fl_get_key_mac.cxx +++ b/src/Fl_get_key_mac.cxx @@ -54,7 +54,7 @@ static const struct {unsigned short vk, fltk;} vktab[] = { { 107, FL_Scroll_Lock }, { 53, FL_Escape }, { 0x73, FL_Home }, { 123, FL_Left }, { 126, FL_Up }, { 124, FL_Right }, { 125, FL_Down }, { 0x74, FL_Page_Up }, { 0x79, FL_Page_Down }, { 119, FL_End }, { 0x71, FL_Print }, { 127, FL_Insert }, - { 0x6e, FL_Menu }, { 114, FL_Help }, { 0x47, FL_Num_Lock }, + { 0x6e, FL_Menu }, { 114, FL_Help }, /*{ 0x47, FL_Num_Lock },*/ { 76, FL_KP_Enter }, { 67, FL_KP+'*' }, { 69, FL_KP+'+'}, { 78, FL_KP+'-' }, { 65, FL_KP+'.' }, { 75, FL_KP+'/' }, { 82, FL_KP+'0' }, { 83, FL_KP+'1' }, { 84, FL_KP+'2' }, { 85, FL_KP+'3' }, { 86, FL_KP+'4' }, { 87, FL_KP+'5' }, { 88, FL_KP+'6' }, { 89, FL_KP+'7' }, @@ -64,7 +64,7 @@ static const struct {unsigned short vk, fltk;} vktab[] = { { 0x65, FL_F+9 }, { 0x6D, FL_F+10 }, { 0x67, FL_F+11 }, { 0x6f, FL_F+12 }, { 56, FL_Shift_L }, { 56, FL_Shift_R }, { 59, FL_Control_L }, { 59, FL_Control_R }, { 57, FL_Caps_Lock }, { 55, FL_Meta_L }, { 55, FL_Meta_R }, - { 58, FL_Alt_L }, { 58, FL_Alt_R }, { 0x75, FL_Delete }, + { 58, FL_Alt_L }, { 58, FL_Alt_R }, /*{ 0x75, FL_Delete },*/ { 0x47, FL_Delete }, }; static int fltk2mac(int fltk) { diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx index f17e79cb7..a7835881a 100644 --- a/src/Fl_mac.cxx +++ b/src/Fl_mac.cxx @@ -156,7 +156,7 @@ static unsigned short macKeyLookUp[128] = 0/*FL_Shift_L*/, 0/*FL_Caps_Lock*/, 0/*FL_Alt_L*/, 0/*FL_Control_L*/, 0/*FL_Shift_R*/, 0/*FL_Alt_R*/, 0/*FL_Control_R*/, 0, - 0, FL_KP+'.', FL_Right, FL_KP+'*', 0, FL_KP+'+', FL_Left, FL_Num_Lock, + 0, FL_KP+'.', FL_Right, FL_KP+'*', 0, FL_KP+'+', FL_Left, FL_Delete, FL_Down, 0, 0, FL_KP+'/', FL_KP_Enter, FL_Up, FL_KP+'-', 0, 0, FL_KP+'=', FL_KP+'0', FL_KP+'1', FL_KP+'2', FL_KP+'3', FL_KP+'4', FL_KP+'5', @@ -1234,6 +1234,34 @@ static int keycode_wrap_old( static int (*keycode_function)(char*, int, EventKind, UInt32, UInt32, UInt32*, unsigned char, unsigned short) = keycode_wrap_old; +// EXPERIMENTAL! +pascal OSStatus carbonTextHandler( + EventHandlerCallRef nextHandler, EventRef event, void *userData ) +{ + Fl_Window *window = (Fl_Window*)userData; + Fl::first_window(window); + fl_lock_function(); + int kind = GetEventKind(event); + unsigned short buf[200]; + ByteCount size; + GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, + NULL, 100, &size, &buf ); +// printf("TextEvent: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]); + // FIXME: oversimplified! + unsigned ucs = buf[0]; + char utf8buf[20]; + int len = fl_utf8encode(ucs, utf8buf); + Fl::e_length = len; + Fl::e_text = utf8buf; + while (window->parent()) window = window->window(); + Fl::handle(FL_KEYBOARD, window); + fl_unlock_function(); + fl_lock_function(); + Fl::handle(FL_KEYUP, window); + fl_unlock_function(); + return noErr; +} + /** * handle carbon keyboard events */ @@ -1256,7 +1284,7 @@ pascal OSStatus carbonKeyboardHandler( NULL, sizeof(UInt32), NULL, &mods ); // get the key code only for key events - UInt32 keyCode = 0; + UInt32 keyCode = 0, maskedKeyCode = 0; unsigned char key = 0; unsigned short sym = 0; if (kind!=kEventRawKeyModifiersChanged) { @@ -1265,7 +1293,12 @@ pascal OSStatus carbonKeyboardHandler( GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key ); } - /* output a human readable event identifier for debugging + // extended keyboards can also send sequences on key-up to generate Kanji etc. codes. + // Some observed prefixes are 0x81 to 0x83, followed by an 8 bit keycode. + // In this mode, there seem to be no key-down codes +// printf("%08x %08x %08x\n", keyCode, mods, key); + maskedKeyCode = keyCode & 0x7f; + /* output a human readable event identifier for debugging */ const char *ev = ""; switch (kind) { case kEventRawKeyDown: ev = "kEventRawKeyDown"; break; @@ -1274,8 +1307,8 @@ pascal OSStatus carbonKeyboardHandler( case kEventRawKeyModifiersChanged: ev = "kEventRawKeyModifiersChanged"; break; default: ev = "unknown"; } - printf("%08x %08x %08x '%c' %s \n", mods, keyCode, key, key, ev); - */ +// printf("%08x %08x %08x '%c' %s \n", mods, keyCode, key, key, ev); +// */ switch (kind) { case kEventRawKeyDown: @@ -1311,12 +1344,13 @@ pascal OSStatus carbonKeyboardHandler( else if ( Fl::e_state&FL_CTRL && key<32 ) sym = key+96; else if ( Fl::e_state&FL_ALT ) // find the keycap of this key - sym = keycode_to_sym( keyCode & 0x7f, 0, macKeyLookUp[ keyCode & 0x7f ] ); + sym = keycode_to_sym( maskedKeyCode, 0, macKeyLookUp[ maskedKeyCode ] ); else - sym = macKeyLookUp[ keyCode & 0x7f ]; + sym = macKeyLookUp[ maskedKeyCode ]; Fl::e_keysym = Fl::e_original_keysym = sym; // Handle FL_KP_Enter on regular keyboards and on Powerbooks - if ( keyCode==0x4c || keyCode==0x34) key=0x0d; + if ( maskedKeyCode==0x4c || maskedKeyCode==0x34) key=0x0d; + // Handle the Delete key on the keypad // Matt: the Mac has no concept of a NumLock key, or at least not visible // Matt: to Carbon. The kEventKeyModifierNumLockMask is only set when // Matt: a numeric keypad key is pressed and does not correspond with @@ -1850,19 +1884,36 @@ static OSErr fillCurrentDragData(DragReference dragRef) FlavorFlags flags; Size itemSize, size = 0; CountDragItems( dragRef, &nItem ); + for ( i = 1; i <= nItem; i++ ) { GetDragItemReferenceNumber( dragRef, i, &itemRef ); + ret = GetFlavorFlags( dragRef, itemRef, 'utf8', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utf8', &itemSize ); + size += itemSize; + continue; + } + ret = GetFlavorFlags( dragRef, itemRef, 'utxt', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utxt', &itemSize ); + size += itemSize; + continue; + } ret = GetFlavorFlags( dragRef, itemRef, 'TEXT', &flags ); if ( ret == noErr ) { GetFlavorDataSize( dragRef, itemRef, 'TEXT', &itemSize ); size += itemSize; + continue; } ret = GetFlavorFlags( dragRef, itemRef, 'hfs ', &flags ); if ( ret == noErr ) { size += 1024; //++ ouch! We should create the full pathname and figure out its length + continue; } } @@ -1878,6 +1929,25 @@ static OSErr fillCurrentDragData(DragReference dragRef) for ( i = 1; i <= nItem; i++ ) { GetDragItemReferenceNumber( dragRef, i, &itemRef ); + ret = GetFlavorFlags( dragRef, itemRef, 'utf8', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utf8', &itemSize ); + GetFlavorData( dragRef, itemRef, 'utf8', dst, &itemSize, 0L ); + dst += itemSize; + *dst++ = '\n'; // add our element separator + continue; + } + GetDragItemReferenceNumber( dragRef, i, &itemRef ); + ret = GetFlavorFlags( dragRef, itemRef, 'utxt', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utxt', &itemSize ); + GetFlavorData( dragRef, itemRef, 'utxt', dst, &itemSize, 0L ); + dst += itemSize; + *dst++ = '\n'; // add our element separator + continue; + } ret = GetFlavorFlags( dragRef, itemRef, 'TEXT', &flags ); if ( ret == noErr ) { @@ -1885,17 +1955,19 @@ static OSErr fillCurrentDragData(DragReference dragRef) GetFlavorData( dragRef, itemRef, 'TEXT', dst, &itemSize, 0L ); dst += itemSize; *dst++ = '\n'; // add our element separator + continue; } ret = GetFlavorFlags( dragRef, itemRef, 'hfs ', &flags ); if ( ret == noErr ) { HFSFlavor hfs; itemSize = sizeof( hfs ); GetFlavorData( dragRef, itemRef, 'hfs ', &hfs, &itemSize, 0L ); - itemSize = FSSpec2UnixPath( &hfs.fileSpec, dst ); + itemSize = FSSpec2UnixPath( &hfs.fileSpec, dst ); // return the path name in UTF8 dst += itemSize; if ( itemSize>1 && ( hfs.fileType=='fold' || hfs.fileType=='disk' ) ) *dst++ = '/'; *dst++ = '\n'; // add our element separator + continue; } } @@ -2185,6 +2257,7 @@ void Fl_X::make(Fl_Window* w) { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDragged } }; ret = InstallWindowEventHandler( x->xid, mouseHandler, 4, mouseEvents, w, 0L ); + EventHandlerUPP keyboardHandler = NewEventHandlerUPP( carbonKeyboardHandler ); // will not be disposed by Carbon... static EventTypeSpec keyboardEvents[] = { { kEventClassKeyboard, kEventRawKeyDown }, @@ -2192,6 +2265,12 @@ void Fl_X::make(Fl_Window* w) { kEventClassKeyboard, kEventRawKeyUp }, { kEventClassKeyboard, kEventRawKeyModifiersChanged } }; ret = InstallWindowEventHandler( x->xid, keyboardHandler, 4, keyboardEvents, w, 0L ); + + EventHandlerUPP textHandler = NewEventHandlerUPP( carbonTextHandler ); // will not be disposed by Carbon... + static EventTypeSpec textEvents[] = { + { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } }; + ret = InstallWindowEventHandler( x->xid, textHandler, 1, textEvents, w, 0L ); + EventHandlerUPP windowHandler = NewEventHandlerUPP( carbonWindowHandler ); // will not be disposed by Carbon... static EventTypeSpec windowEvents[] = { { kEventClassWindow, kEventWindowDrawContent }, diff --git a/src/fl_dnd_mac.cxx b/src/fl_dnd_mac.cxx index eaae1d149..af8cf1c58 100644 --- a/src/fl_dnd_mac.cxx +++ b/src/fl_dnd_mac.cxx @@ -51,7 +51,7 @@ int Fl::dnd() result = NewDrag( &dragRef ); if ( result != noErr ) return false; - result = AddDragItemFlavor( dragRef, 1, 'TEXT', fl_selection_buffer, fl_selection_length, 0 ); + result = AddDragItemFlavor( dragRef, 1, 'utf8', fl_selection_buffer, fl_selection_length, 0 ); if ( result != noErr ) { DisposeDrag( dragRef ); return false; } Point mp; diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx index ec0ed5832..fb7fe0f05 100644 --- a/src/fl_rect.cxx +++ b/src/fl_rect.cxx @@ -419,8 +419,8 @@ void fl_point(int x, int y) { SetPixel(fl_gc, x, y, fl_RGB()); #elif defined(__APPLE_QUARTZ__) if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); - CGContextMoveToPoint(fl_gc, x, y); - CGContextAddLineToPoint(fl_gc, x, y); + CGContextMoveToPoint(fl_gc, x-.5, y); // Quartz needs a line that is one pixel long, or it will not draw anything + CGContextAddLineToPoint(fl_gc, x+.5, y); CGContextStrokePath(fl_gc); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); #else diff --git a/src/fl_shortcut.cxx b/src/fl_shortcut.cxx index b0519d14f..050d454b2 100644 --- a/src/fl_shortcut.cxx +++ b/src/fl_shortcut.cxx @@ -95,9 +95,9 @@ int Fl::test_shortcut(int shortcut) { return 0; } -#if defined(WIN32) || defined(__APPLE__) // if not X // This table must be in numeric order by fltk (X) keysym number: struct Keyname {int key; const char* name;}; +#if defined(WIN32) static Keyname table[] = { {' ', "Space"}, {FL_BackSpace, "Backspace"}, @@ -131,6 +131,40 @@ static Keyname table[] = { {FL_Alt_R, "Alt_R"}, {FL_Delete, "Delete"} }; +#elif defined(__APPLE__) +static Keyname table[] = { + {' ', "Space"}, + {FL_BackSpace,"\xe2\x8c\xab"}, + {FL_Tab, "\xe2\x87\xa5"}, + {0xff0b/*XK_Clear*/, "Clear"}, + {FL_Enter, "\xe2\x86\xa9"}, + {FL_Pause, "Pause"}, + {FL_Scroll_Lock, "Scroll_Lock"}, + {FL_Escape, "\xe2\x90\x9b"}, + {FL_Home, "\xe2\x86\x96"}, + {FL_Left, "\xe2\x86\x90"}, + {FL_Up, "\xe2\x86\x91"}, + {FL_Right, "\xe2\x86\x92"}, + {FL_Down, "\xe2\x86\x93"}, + {FL_Page_Up, "\xe2\x87\x9e"}, // utf8 arrow up with two strokes + {FL_Page_Down,"\xe2\x87\x9f"}, // utf8 arrow down with two strokes + {FL_End, "\xe2\x86\x98"}, + {FL_Print, "Print"}, + {FL_Insert, "Insert"}, + {FL_Menu, "Menu"}, + {FL_Num_Lock, "Num_Lock"}, + {FL_KP_Enter, "\xe2\x86\xb5"}, + {FL_Shift_L, "Shift_L"}, + {FL_Shift_R, "Shift_R"}, + {FL_Control_L,"Control_L"}, + {FL_Control_R,"Control_R"}, + {FL_Caps_Lock,"\xe2\x87\xaa"}, // utf8 Caps Lock symbol + {FL_Meta_L, "Meta_L"}, + {FL_Meta_R, "Meta_R"}, + {FL_Alt_L, "Alt_L"}, + {FL_Alt_R, "Alt_R"}, + {FL_Delete, "\xe2\x8c\xa7"} +}; #endif /** @@ -158,9 +192,9 @@ const char* fl_shortcut_label(int shortcut) { } #ifdef __APPLE__ // \todo Mac : we might want to change the symbols for Mac users - consider drawing Apple Symbols... . - if (shortcut & FL_SHIFT) {strcpy(p,"\xe2\x87\xa7"); p += 3;} //: Mac hollow up arrow - if (shortcut & FL_CTRL) {strcpy(p,"^"); p += 1;} //: Mac ctrl key - if (shortcut & FL_ALT) {strcpy(p,"\xe2\x8e\x87"); p += 3;} //: Mac 'Alt/Option' or fancy switch symbol + if (shortcut & FL_SHIFT) {strcpy(p,"\xe2\x87\xa7"); p += 3;} //: Mac hollow up arrow + if (shortcut & FL_CTRL) {strcpy(p,"\xe2\x8c\x83"); p += 3;} //: Mac ctrl key + if (shortcut & FL_ALT) {strcpy(p,"\xe2\x8e\x87"); p += 3;} //: Mac 'Alt/Option' or fancy switch symbol if (shortcut & FL_META) {strcpy(p,"\xe2\x8c\x98"); p += 3;} //: Mac 'Apple' key #else if (shortcut & FL_META) {strcpy(p,"Meta+"); p += 5;} diff --git a/test/Makefile b/test/Makefile index e7d293c5f..79f731f93 100644 --- a/test/Makefile +++ b/test/Makefile @@ -264,6 +264,9 @@ $(ALL): $(LIBNAME) # General demos... unittests$(EXEEXT): unittests.o +unittests.cxx: unittest_about.cxx unittest_points.cxx unittest_lines.cxx unittest_circles.cxx \ + unittest_rects.cxx unittest_text.cxx unittest_viewport.cxx unittest_images.cxx + adjuster$(EXEEXT): adjuster.o arc$(EXEEXT): arc.o diff --git a/test/unittest_about.cxx b/test/unittest_about.cxx new file mode 100644 index 000000000..798d3872b --- /dev/null +++ b/test/unittest_about.cxx @@ -0,0 +1,66 @@ +// +// "$Id: $" +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Help_View.H> + +// +//------- Introduction to FLTK drawing test ------- +// +class About : public Fl_Help_View { +public: + static Fl_Widget *create() { + return new About(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + About(int x, int y, int w, int h) : Fl_Help_View(x, y, w, h) { + value( +"<htmL><body><h2>About Unit Testing...</h2>\n" +"<h3>the UI Designer</h3>\n" +"<p>Designing a good user interface is an art. Widgets must be selected and carefully positioned " +"to create a consistent look and feel for the user. Text must fit into given boxes and graphic " +"elements must be correctly aligned. A good UI library will give consisten results on any " +"supported platform and render all graphics in the way the UI designer intended.</p>\n" +"<p>FLTK supports a large collection of platforms and graphics drivers. This unit testing " +"application contains modules which will test rendering and alignment for most " +"FLTK core graphics functions.</p>\n" +"<h3>the Developer</h3>\n" +"<p>Unittest is also a great help when implementing new graphics drivers. The tests are sorted " +"in the same order in which a new graphics driver could be implemented. Most tests rely " +"on the previous test to function correctly, so sticking to the given order is a good idea.</p>\n" +"<h3>Conventions</h3>\n" +"<p>In most tests, two layers of graphics are drawn for most test. The lower layer contains " +"red and green pixels. The upper layer contains black pixels. The test is rendered correctly " +"if all red pixels are covered, but none of the green pixels. The top graphics layer can be " +"switched on and off.</p>" +"</body></html>"); + } +}; + +UnitTest about("About...", About::create); + +// +// End of "$Id: $". +// diff --git a/test/unittest_circles.cxx b/test/unittest_circles.cxx new file mode 100644 index 000000000..d8d3fb4fb --- /dev/null +++ b/test/unittest_circles.cxx @@ -0,0 +1,99 @@ +// +// "$Id: $" +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Box.H> +#include <FL/fl_draw.H> + +// +//------- test the circle drawing capabilities of this implementation ---------- +// +class CircleTest : public Fl_Box { +public: + static Fl_Widget *create() { + return new CircleTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + CircleTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { + label("testing int drawing of circles and ovals (fl_arc, fl_pie)\n" + "No red lines should be visible. " + "If you see bright red pixels, the circle drawing alignment is off. " + "If you see dark red pixels, your system supports anti-aliasing " + "which should be of no concern. " + "The green rectangles should not be overwritten by circle drawings."); + align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); + box(FL_BORDER_BOX); + } + void draw() { + Fl_Box::draw(); + int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); + // test fl_arc for full circles + fl_color(FL_GREEN); fl_rect(a+ 9, b+ 9, 33, 33); + fl_color(FL_RED); fl_xyline(a+24, b+10, a+27); fl_xyline(a+24, b+40, a+27); + fl_yxline(a+10, b+24, b+27); fl_yxline(a+40, b+24, b+27); + fl_color(FL_BLACK); fl_arc(a+10, b+10, 31, 31, 0.0, 360.0); + // test fl_arc segmet 1 + fl_color(FL_GREEN); fl_rect(a+54, b+ 4, 43, 43); + fl_rect(a+54, b+4, 18, 18); fl_rect(a+79, b+29, 18, 18); + fl_color(FL_RED); fl_point(a+55, b+30); fl_point(a+70, b+45); + fl_point(a+80, b+5); fl_point(a+95, b+20); + fl_color(FL_BLACK); fl_arc(a+65, b+ 5, 31, 31, -35.0, 125.0); + // test fl_arc segmet 2 + fl_color(FL_BLACK); fl_arc(a+55, b+15, 31, 31, 145.0, 305.0); + // test fl_pie for full circles + fl_color(FL_RED); fl_xyline(a+24, b+60, a+27); fl_xyline(a+24, b+90, a+27); + fl_yxline(a+10, b+74, b+77); fl_yxline(a+40, b+74, b+77); + fl_color(FL_GREEN); fl_rect(a+ 9, b+59, 33, 33); + fl_color(FL_BLACK); fl_pie(a+10, b+60, 31, 31, 0.0, 360.0); + // test fl_pie segmet 1 + fl_color(FL_GREEN); fl_rect(a+54, b+54, 43, 43); + fl_rect(a+54, b+54, 18, 18); fl_rect(a+79, b+79, 18, 18); + fl_point(a+79, b+71); fl_point(a+71, b+79); + fl_color(FL_RED); fl_point(a+55, b+80); fl_point(a+70, b+95); + fl_point(a+80, b+55); fl_point(a+95, b+70); + fl_point(a+81, b+69); fl_point(a+69, b+81); + fl_color(FL_BLACK); fl_pie(a+65, b+55, 31, 31, -30.0, 120.0); + // test fl_pie segmet 2 + fl_color(FL_BLACK); fl_pie(a+55, b+65, 31, 31, 150.0, 300.0); + //---- oval testing (horizontal squish) + a +=120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); + fl_color(FL_GREEN); + fl_rect(a+19, b+9, 63, 33); fl_rect(a+19, b+59, 63, 33); + fl_color(FL_BLACK); + fl_arc(a+20, b+10, 61, 31, 0, 360); fl_pie(a+20, b+60, 61, 31, 0, 360); + //---- oval testing (horizontal squish) + a += 120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); + fl_color(FL_GREEN); + fl_rect(a+9, b+19, 33, 63); fl_rect(a+59, b+19, 33, 63); + fl_color(FL_BLACK); + fl_arc(a+10, b+20, 31, 61, 0, 360); fl_pie(a+60, b+20, 31, 61, 0, 360); + } +}; + +UnitTest circle("circles and arcs", CircleTest::create); + +// +// End of "$Id: $" +// diff --git a/test/unittest_images.cxx b/test/unittest_images.cxx new file mode 100644 index 000000000..161854af6 --- /dev/null +++ b/test/unittest_images.cxx @@ -0,0 +1,99 @@ +// +// "$Id: $" +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Box.H> +#include <FL/fl_draw.H> + +// +//------- test the line drawing capabilities of this implementation ---------- +// +class ImageTest : public Fl_Box { +public: + static Fl_Widget *create() { + int x, y; + uchar *dg, *dga, *drgb, *drgba; + dg = img_gray = (uchar*)malloc(128*128*1); + dga = img_gray_a = (uchar*)malloc(128*128*2); + drgb = img_rgb = (uchar*)malloc(128*128*3); + drgba = img_rgba = (uchar*)malloc(128*128*4); + for (y=0; y<128; y++) { + for (x=0; x<128; x++) { + *drgb++ = *drgba = *dg++ = *dga++ = y<<1; + *drgb++ = *drgba = x<<1; + *drgb++ = *drgba = (127-x)<<1; + *dga++ = *drgba = x+y; + } + } + return new ImageTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + static uchar *img_gray; + static uchar *img_gray_a; + static uchar *img_rgb; + static uchar *img_rgba; + ImageTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { + label("Testing Image Drawing\n\n" + "This test renders four images, two of them with a checker board\n" + "visible through the graphics. Color and gray gradients should be\n" + "visible. This does not test any image formats such as JPEG."); + align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); + box(FL_BORDER_BOX); + } + void draw() { + Fl_Box::draw(); + int xx = x()+10, yy = y()+10; + fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); + fl_draw_image(img_rgb, xx+1, yy+1, 128, 128, 3); + fl_draw("RGB", xx+134, yy+64); + xx = x()+10; yy = y()+10+134; + fl_color(FL_BLACK); fl_rectf(xx, yy, 130, 130); + fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 64, 64); + fl_color(FL_WHITE); fl_rectf(xx+65, yy+65, 64, 64); + fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4); + fl_color(FL_BLACK); fl_draw("RGBA", xx+134, yy+64); + xx = x()+10+200; yy = y()+10; + fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); + fl_draw_image(img_gray, xx+1, yy+1, 128, 128, 1); + fl_draw("Gray", xx+134, yy+64); + xx = x()+10+200; yy = y()+10+134; + fl_color(FL_BLACK); fl_rectf(xx, yy, 130, 130); + fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 64, 64); + fl_color(FL_WHITE); fl_rectf(xx+65, yy+65, 64, 64); + fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128, 2); + fl_color(FL_BLACK); fl_draw("Gray+Alpha", xx+134, yy+64); + } +}; + +uchar *ImageTest::img_gray = 0; +uchar *ImageTest::img_gray_a = 0; +uchar *ImageTest::img_rgb = 0; +uchar *ImageTest::img_rgba = 0; + +UnitTest images("drawing images", ImageTest::create); + +// +// End of "$Id: $" +// diff --git a/test/unittest_lines.cxx b/test/unittest_lines.cxx new file mode 100644 index 000000000..8658a9713 --- /dev/null +++ b/test/unittest_lines.cxx @@ -0,0 +1,75 @@ +// +// "$Id: $" +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Box.H> +#include <FL/fl_draw.H> + +// +//------- test the line drawing capabilities of this implementation ---------- +// +class LineTest : public Fl_Box { +public: + static Fl_Widget *create() { + return new LineTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + LineTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { + label("testing the integer based fl_line calls\n" + "No red pixels should be visible.\n" + "If you see bright red pixels, the line drawing alignment is off,\n" + "or the last pixel in a line does not get drawn.\n" + "If you see dark red pixels, anti-aliasing must be switched off."); + align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); + box(FL_BORDER_BOX); + } + void draw() { + Fl_Box::draw(); + int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); + // testing fl_xyline(x, y, x1) + fl_color(FL_RED); fl_point(a+10, b+10); fl_point(a+20, b+10); + fl_color(FL_BLACK); fl_xyline(a+10, b+10, a+20); + // testing fl_xyline(x, y, x1, y2); + fl_color(FL_RED); fl_point(a+10, b+20); fl_point(a+20, b+20); + fl_point(a+20, b+30); + fl_color(FL_BLACK); fl_xyline(a+10, b+20, a+20, b+30); + // testing fl_xyline(x, y, x1, y2, x3); + fl_color(FL_RED); fl_point(a+10, b+40); fl_point(a+20, b+40); + fl_point(a+20, b+50); fl_point(a+30, b+50); + fl_color(FL_BLACK); fl_xyline(a+10, b+40, a+20, b+50, a+30); + //+++ add testing for the fl_yxline commands! + // testing fl_loop(x,y, x,y, x,y, x, y) + fl_color(FL_RED); fl_point(a+60, b+60); fl_point(a+90, b+60); + fl_point(a+60, b+90); fl_point(a+90, b+90); + fl_color(FL_BLACK); + fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90); + } +}; + +UnitTest lines("drawing lines", LineTest::create); + +// +// End of "$Id: $" +// diff --git a/test/unittest_points.cxx b/test/unittest_points.cxx new file mode 100644 index 000000000..5d84a868a --- /dev/null +++ b/test/unittest_points.cxx @@ -0,0 +1,69 @@ +// +// "$Id: $: +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Box.H> +#include <FL/fl_draw.H> + +// +//------- test the point drawing capabilities of this implementation ---------- +// +class PointTest : public Fl_Box { +public: + static Fl_Widget *create() { + return new PointTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + PointTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { + label("testing the fl_point call\n" + "You should see four pixels each in black, red, green and blue. " + "Make sure that pixels are not anti-aliased (blurred across multiple pixels)!"); + align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); + box(FL_BORDER_BOX); + } + void draw() { + Fl_Box::draw(); + int a = x()+10, b = y()+10; + fl_color(FL_WHITE); fl_rectf(a, b, 90, 90); + fl_color(FL_BLACK); fl_rect(a, b, 90, 90); + fl_point(a+10, b+10); fl_point(a+20, b+20); + fl_point(a+10, b+20); fl_point(a+20, b+10); + fl_color(FL_RED); a = x()+70; + fl_point(a+10, b+10); fl_point(a+20, b+20); + fl_point(a+10, b+20); fl_point(a+20, b+10); + fl_color(FL_GREEN); a = x()+10; b = y()+70; + fl_point(a+10, b+10); fl_point(a+20, b+20); + fl_point(a+10, b+20); fl_point(a+20, b+10); + fl_color(FL_BLUE); a = x()+70; + fl_point(a+10, b+10); fl_point(a+20, b+20); + fl_point(a+10, b+20); fl_point(a+20, b+10); + } +}; + +UnitTest points("drawing points", PointTest::create); + +// +// End of "$Id: $" +// diff --git a/test/unittest_rects.cxx b/test/unittest_rects.cxx new file mode 100644 index 000000000..0a7e06d5b --- /dev/null +++ b/test/unittest_rects.cxx @@ -0,0 +1,66 @@ +// +// "$Id: $" +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Box.H> +#include <FL/fl_draw.H> // fl_text_extents() + +// +//------- test the rectangle drawing capabilities of this implementation ---------- +// +class RectTest : public Fl_Box { +public: + static Fl_Widget *create() { + return new RectTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + RectTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { + label("testing the fl_rect call\n" + "No red pixels should be visible. " + "If you see bright red lines, or if parts of the green frames are hidden, " + "the rect drawing alignment is off."); + align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); + box(FL_BORDER_BOX); + } + void draw() { + Fl_Box::draw(); + int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); + // testing fl_rect() with positive size + fl_color(FL_RED); fl_loop(a+10, b+10, a+40, b+10, a+40, b+40, a+10, b+40); + fl_color(FL_GREEN); fl_loop(a+ 9, b+ 9, a+41, b+ 9, a+41, b+41, a+ 9, b+41); + fl_color(FL_GREEN); fl_loop(a+11, b+11, a+39, b+11, a+39, b+39, a+11, b+39); + fl_color(FL_BLACK); fl_rect(a+10, b+10, 31, 31); + // testing fl_rect() with positive size + fl_color(FL_RED); fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90); + fl_color(FL_GREEN); fl_loop(a+59, b+59, a+91, b+59, a+91, b+91, a+59, b+91); + fl_color(FL_BLACK); fl_rectf(a+60, b+60, 31, 31); + } +}; + +UnitTest rects("rectangles", RectTest::create); + +// +// End of "$Id: $" +// diff --git a/test/unittest_text.cxx b/test/unittest_text.cxx new file mode 100644 index 000000000..231e22dbe --- /dev/null +++ b/test/unittest_text.cxx @@ -0,0 +1,97 @@ +// +// "$Id: $" +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Box.H> +#include <FL/fl_draw.H> + +// +// --- fl_text_extents() tests ----------------------------------------------- +// +class TextExtentsTest : public Fl_Widget +{ + void DrawTextAndBoxes(const char *txt, int X, int Y) { + int wo = 0, ho = 0; + int dx, dy; + // First, we draw the bounding boxes (fl_measure and fl_text_extents) + // draw fl_measure() typographical bounding box + fl_measure(txt, wo, ho, 0); + int desc = fl_descent(); + fl_color(FL_RED); + fl_rect(X, Y-ho+desc, wo, ho); + // draw fl_text_extents() glyph bounding box + fl_text_extents(txt, dx, dy, wo, ho); + fl_color(FL_GREEN); + fl_rect(X+dx, Y+dy, wo, ho); + // Then we draw the text to show how it fits insode each of the two boxes + fl_color(FL_BLACK); + fl_draw(txt, X, Y); + } +public: + static Fl_Widget *create() { + return new TextExtentsTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + TextExtentsTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {} + void draw(void) { + int x0 = x(); // origin is current window position for Fl_Box + int y0 = y(); + int w0 = w(); + int h0 = h(); + fl_push_clip(x0, y0, w0, h0); // reset local clipping + { + // set the background colour - slightly off-white to enhance the green bounding box + fl_color(fl_gray_ramp(FL_NUM_GRAY - 3)); + fl_rectf(x0, y0, w0, h0); + + fl_font(FL_HELVETICA, 30); + int xx = x0+55; + int yy = y0+40; + DrawTextAndBoxes("!abcdeABCDE\"#A", xx, yy); yy += 50; // mixed string + DrawTextAndBoxes("oacs", xx, yy); xx += 100; // small glyphs + DrawTextAndBoxes("qjgIPT", xx, yy); yy += 50; xx -= 100; // glyphs with descenders + DrawTextAndBoxes("````````", xx, yy); yy += 50; // high small glyphs + DrawTextAndBoxes("--------", xx, yy); yy += 50; // mid small glyphs + DrawTextAndBoxes("________", xx, yy); yy += 50; // low small glyphs + + fl_font(FL_HELVETICA, 14); + fl_color(FL_RED); fl_draw("fl_measure bounding box in RED", xx, yy); yy += 20; + fl_color(FL_GREEN); fl_draw("fl_text_extents bounding box in GREEN", xx, yy); + fl_color(FL_BLACK); + xx = x0 + 10; yy += 30; + fl_draw("NOTE: On systems with text anti-aliasing (e.g. OSX Quartz)", xx, yy); + w0 = h0 = 0; fl_measure("NOTE: ", w0, h0, 0); + xx += w0; yy += h0; + fl_draw("text may leak slightly outside the fl_text_extents()", xx, yy); + } + fl_pop_clip(); // remove the local clip + } +}; + +UnitTest textExtents("rendering text", TextExtentsTest::create); + +// +// End of "$Id: $" +// diff --git a/test/unittest_viewport.cxx b/test/unittest_viewport.cxx new file mode 100644 index 000000000..5c10ad7a3 --- /dev/null +++ b/test/unittest_viewport.cxx @@ -0,0 +1,64 @@ +// +// "$Id: $" +// +// Unit tests for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2009 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/Fl_Box.H> +#include <FL/fl_draw.H> + +// +//------- test viewport clipping ---------- +// +class ViewportTest : public Fl_Box { +public: + static Fl_Widget *create() { + return new ViewportTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); + } + ViewportTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { + label("Testing Viewport Alignment\n\n" + "Only green lines should be visible.\n" + "If red lines are visible in the corners of this window,\n" + "your viewport alignment and clipping is off.\n" + "If there is a space between the green lines and the window border,\n" + "the viewport is off, but some clipping may be working.\n" + "Also, your window size may be off to begin with."); + align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER|FL_ALIGN_WRAP); + box(FL_BORDER_BOX); + } + void show() { + Fl_Box::show(); + mainwin->testAlignment(1); + } + void hide() { + Fl_Box::hide(); + mainwin->testAlignment(0); + } +}; + +UnitTest viewport("viewport test", ViewportTest::create); + +// +// End of "$Id: +// diff --git a/test/unittests.cxx b/test/unittests.cxx index 47fda8445..d2c72dd9d 100644 --- a/test/unittests.cxx +++ b/test/unittests.cxx @@ -29,10 +29,12 @@ // v0.2 - Ian's 02/12/09 fixes applied // v0.3 - Fixes to circle desc, augmented extent tests, fixed indents, added show(argc,argv) // v1.0 - Submit for svn +// v1.1 - Matthias seperated all tests into multiple source files for hopefully easier handling #include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Hold_Browser.H> +#include <FL/Fl_Help_View.H> #include <FL/Fl_Group.H> #include <FL/Fl_Box.H> #include <FL/fl_draw.H> // fl_text_extents() @@ -51,453 +53,146 @@ typedef void (*UnitTestCallback)(const char*,Fl_Group*); -Fl_Window *mainwin = 0; +class MainWindow *mainwin = 0; Fl_Hold_Browser *browser = 0; -////////////////////////////// -// UNIT TEST CODE STARTS HERE -////////////////////////////// - -// -//------- test the circle drawing capabilities of this implementation ---------- -// -class CircleTest : public Fl_Box { -public: CircleTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { - label("testing int drawing of circles and ovals (fl_arc, fl_pie)\n" - "No red lines should be visible. " - "If you see bright red pixels, the circle drawing alignment is off. " - "If you see dark red pixels, your system supports anti-aliasing " - "which should be of no concern. " - "The green rectangles should not be overwritten by circle drawings."); - align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); - box(FL_BORDER_BOX); - } - void draw() { - Fl_Box::draw(); - int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); - // test fl_arc for full circles - fl_color(FL_GREEN); fl_rect(a+ 9, b+ 9, 33, 33); - fl_color(FL_RED); fl_xyline(a+24, b+10, a+27); fl_xyline(a+24, b+40, a+27); - fl_yxline(a+10, b+24, b+27); fl_yxline(a+40, b+24, b+27); - fl_color(FL_BLACK); fl_arc(a+10, b+10, 31, 31, 0.0, 360.0); - // test fl_arc segmet 1 - fl_color(FL_GREEN); fl_rect(a+54, b+ 4, 43, 43); - fl_rect(a+54, b+4, 18, 18); fl_rect(a+79, b+29, 18, 18); - fl_color(FL_RED); fl_point(a+55, b+30); fl_point(a+70, b+45); - fl_point(a+80, b+5); fl_point(a+95, b+20); - fl_color(FL_BLACK); fl_arc(a+65, b+ 5, 31, 31, -35.0, 125.0); - // test fl_arc segmet 2 - fl_color(FL_BLACK); fl_arc(a+55, b+15, 31, 31, 145.0, 305.0); - // test fl_pie for full circles - fl_color(FL_RED); fl_xyline(a+24, b+60, a+27); fl_xyline(a+24, b+90, a+27); - fl_yxline(a+10, b+74, b+77); fl_yxline(a+40, b+74, b+77); - fl_color(FL_GREEN); fl_rect(a+ 9, b+59, 33, 33); - fl_color(FL_BLACK); fl_pie(a+10, b+60, 31, 31, 0.0, 360.0); - // test fl_pie segmet 1 - fl_color(FL_GREEN); fl_rect(a+54, b+54, 43, 43); - fl_rect(a+54, b+54, 18, 18); fl_rect(a+79, b+79, 18, 18); - fl_point(a+79, b+71); fl_point(a+71, b+79); - fl_color(FL_RED); fl_point(a+55, b+80); fl_point(a+70, b+95); - fl_point(a+80, b+55); fl_point(a+95, b+70); - fl_point(a+81, b+69); fl_point(a+69, b+81); - fl_color(FL_BLACK); fl_pie(a+65, b+55, 31, 31, -30.0, 120.0); - // test fl_pie segmet 2 - fl_color(FL_BLACK); fl_pie(a+55, b+65, 31, 31, 150.0, 300.0); - //---- oval testing (horizontal squish) - a +=120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); - fl_color(FL_GREEN); - fl_rect(a+19, b+9, 63, 33); fl_rect(a+19, b+59, 63, 33); - fl_color(FL_BLACK); - fl_arc(a+20, b+10, 61, 31, 0, 360); fl_pie(a+20, b+60, 61, 31, 0, 360); - //---- oval testing (horizontal squish) - a += 120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); - fl_color(FL_GREEN); - fl_rect(a+9, b+19, 33, 63); fl_rect(a+59, b+19, 33, 63); - fl_color(FL_BLACK); - fl_arc(a+10, b+20, 31, 61, 0, 360); fl_pie(a+60, b+20, 31, 61, 0, 360); - } -}; - -void unittest_fl_circle_test_cb(const char *action, Fl_Group *grp) { - if ( grp == 0 ) { - abort(); - } else if ( strcmp(action, "create") == 0 ) { - grp->begin(); { - // Create this unit test's widgets - new CircleTest(grp->x(), grp->y(), grp->w(), grp->h()); - } - grp->end(); - } else if ( strcmp(action, "show") == 0 ) { - } else if ( strcmp(action, "hide") == 0 ) { - } - return; -} - -// -//------- test the point drawing capabilities of this implementation ---------- -// -class PointTest : public Fl_Box { -public: PointTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { - label("testing the fl_point call\n" - "You should see four pixels each in black, red, green and blue. " - "Make sure that pixels are not anti-aliased (blurred across multiple pixels)!"); - align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); - box(FL_BORDER_BOX); - } - void draw() { - Fl_Box::draw(); - int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 90, 90); - fl_point(a+10, b+10); fl_point(a+20, b+20); - fl_point(a+10, b+20); fl_point(a+20, b+10); - fl_color(FL_RED); a = x()+70; - fl_point(a+10, b+10); fl_point(a+20, b+20); - fl_point(a+10, b+20); fl_point(a+20, b+10); - fl_color(FL_GREEN); a = x()+10; b = y()+70; - fl_point(a+10, b+10); fl_point(a+20, b+20); - fl_point(a+10, b+20); fl_point(a+20, b+10); - fl_color(FL_BLUE); a = x()+70; - fl_point(a+10, b+10); fl_point(a+20, b+20); - fl_point(a+10, b+20); fl_point(a+20, b+10); - } -}; - -void unittest_fl_point_test_cb(const char *action, Fl_Group *grp) { - if ( grp == 0 ) { - abort(); - } else if ( strcmp(action, "create") == 0 ) { - grp->begin(); { - // Create this unit test's widgets - new PointTest(grp->x(), grp->y(), grp->w(), grp->h()); - } - grp->end(); - } else if ( strcmp(action, "show") == 0 ) { - } else if ( strcmp(action, "hide") == 0 ) { - } - return; -} - -// -//------- test the line drawing capabilities of this implementation ---------- -// -class LineTest : public Fl_Box { -public: LineTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { - label("testing the integer based fl_line calls\n" - "No red pixels should be visible.\n" - "If you see bright red pixels, the line drawing alignment is off,\n" - "or the last pixel in a line does not get drawn.\n" - "If you see dark red pixels, anti-aliasing must be switched off."); - align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); - box(FL_BORDER_BOX); - } - void draw() { - Fl_Box::draw(); - int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); - // testing fl_xyline(x, y, x1) - fl_color(FL_RED); fl_point(a+10, b+10); fl_point(a+20, b+10); - fl_color(FL_BLACK); fl_xyline(a+10, b+10, a+20); - // testing fl_xyline(x, y, x1, y2); - fl_color(FL_RED); fl_point(a+10, b+20); fl_point(a+20, b+20); - fl_point(a+20, b+30); - fl_color(FL_BLACK); fl_xyline(a+10, b+20, a+20, b+30); - // testing fl_xyline(x, y, x1, y2, x3); - fl_color(FL_RED); fl_point(a+10, b+40); fl_point(a+20, b+40); - fl_point(a+20, b+50); fl_point(a+30, b+50); - fl_color(FL_BLACK); fl_xyline(a+10, b+40, a+20, b+50, a+30); - //+++ add testing for the fl_yxline commands! - // testing fl_loop(x,y, x,y, x,y, x, y) - fl_color(FL_RED); fl_point(a+60, b+60); fl_point(a+90, b+60); - fl_point(a+60, b+90); fl_point(a+90, b+90); - fl_color(FL_BLACK); - fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90); - } +// This class helps to automagically register a new test with the unittest app. +// Please see the examples on how this is used. +class UnitTest { +public: + UnitTest(const char *label, Fl_Widget* (*create)()) : + fWidget(0L) + { + fLabel = strdup(label); + fCreate = create; + add(this); + } + ~UnitTest() { + delete fWidget; + free(fLabel); + } + const char *label() { + return fLabel; + } + void create() { + fWidget = fCreate(); + if (fWidget) fWidget->hide(); + } + void show() { + if (fWidget) fWidget->show(); + } + void hide() { + if (fWidget) fWidget->hide(); + } + static int numTest() { return nTest; } + static UnitTest *test(int i) { return fTest[i]; } +private: + char *fLabel; + Fl_Widget *(*fCreate)(); + Fl_Widget *fWidget; + + static void add(UnitTest *t) { + fTest[nTest] = t; + nTest++; + } + static int nTest; + static UnitTest *fTest[200]; }; -void unittest_fl_line_test_cb(const char *action, Fl_Group *grp) { - if ( grp == 0 ) { - abort(); - } else if ( strcmp(action, "create") == 0 ) { - grp->begin(); { - // Create this unit test's widgets - new LineTest(grp->x(), grp->y(), grp->w(), grp->h()); - } - grp->end(); - } else if ( strcmp(action, "show") == 0 ) { - } else if ( strcmp(action, "hide") == 0 ) { - } - return; -} +int UnitTest::nTest = 0; +UnitTest *UnitTest::fTest[]; -// -//------- test the rectangle drawing capabilities of this implementation ---------- -// -class RectTest : public Fl_Box { -public: RectTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { - label("testing the fl_rect call\n" - "No red pixels should be visible. " - "If you see bright red lines, or if parts of the green frames are hidden, " - "the rect drawing alignment is off."); - align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); - box(FL_BORDER_BOX); - } - void draw() { - Fl_Box::draw(); - int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100); - // testing fl_rect() with positive size - fl_color(FL_RED); fl_loop(a+10, b+10, a+40, b+10, a+40, b+40, a+10, b+40); - fl_color(FL_GREEN); fl_loop(a+ 9, b+ 9, a+41, b+ 9, a+41, b+41, a+ 9, b+41); - fl_color(FL_GREEN); fl_loop(a+11, b+11, a+39, b+11, a+39, b+39, a+11, b+39); - fl_color(FL_BLACK); fl_rect(a+10, b+10, 31, 31); - // testing fl_rect() with positive size - fl_color(FL_RED); fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90); - fl_color(FL_GREEN); fl_loop(a+59, b+59, a+91, b+59, a+91, b+91, a+59, b+91); - fl_color(FL_BLACK); fl_rectf(a+60, b+60, 31, 31); - } -}; -void unittest_fl_rect_test_cb(const char *action, Fl_Group *grp) { - if ( grp == 0 ) { - abort(); - } else if ( strcmp(action, "create") == 0 ) { - grp->begin(); { - // Create this unit test's widgets - new RectTest(grp->x(), grp->y(), grp->w(), grp->h()); - } - grp->end(); - } else if ( strcmp(action, "show") == 0 ) { - } else if ( strcmp(action, "hide") == 0 ) { +// The main window needs an additional drawing feature in order to support +// the viewport alignment test. +class MainWindow : public Fl_Window { +public: + MainWindow(int w, int h, const char *l=0L) : + Fl_Window(w, h, l), + fTestAlignment(0) + { } + // this code is used by the viewport alignment test + void drawAlignmentIndicators() { + const int sze = 16; + // top left corner + fl_color(FL_GREEN); fl_yxline(0, sze, 0, sze); + fl_color(FL_RED); fl_yxline(-1, sze, -1, sze); + fl_color(FL_WHITE); fl_rectf(3, 3, sze-2, sze-2); + fl_color(FL_BLACK); fl_rect(3, 3, sze-2, sze-2); + // bottom left corner + fl_color(FL_GREEN); fl_yxline(0, h()-sze-1, h()-1, sze); + fl_color(FL_RED); fl_yxline(-1, h()-sze-1, h(), sze); + fl_color(FL_WHITE); fl_rectf(3, h()-sze-1, sze-2, sze-2); + fl_color(FL_BLACK); fl_rect(3, h()-sze-1, sze-2, sze-2); + // bottom right corner + fl_color(FL_GREEN); fl_yxline(w()-1, h()-sze-1, h()-1, w()-sze-1); + fl_color(FL_RED); fl_yxline(w(), h()-sze-1, h(), w()-sze-1); + fl_color(FL_WHITE); fl_rectf(w()-sze-1, h()-sze-1, sze-2, sze-2); + fl_color(FL_BLACK); fl_rect(w()-sze-1, h()-sze-1, sze-2, sze-2); + // top right corner + fl_color(FL_GREEN); fl_yxline(w()-1, sze, 0, w()-sze-1); + fl_color(FL_RED); fl_yxline(w(), sze, -1, w()-sze-1); + fl_color(FL_WHITE); fl_rectf(w()-sze-1, 3, sze-2, sze-2); + fl_color(FL_BLACK); fl_rect(w()-sze-1, 3, sze-2, sze-2); } - return; -} - -// -//------- test viewport clipping ---------- -// -class ViewportTest : public Fl_Widget { - int pos; -public: ViewportTest(int x, int y, int w, int h, int p) : Fl_Widget(x, y, w, h), pos(p) { } void draw() { - if (pos&1) { - fl_color(FL_RED); fl_yxline(x()+w(), y(), y()+h()); - fl_color(FL_GREEN); fl_yxline(x()+w()-1, y(), y()+h()); - } else { - fl_color(FL_RED); fl_yxline(x()-1, y(), y()+h()); - fl_color(FL_GREEN); fl_yxline(x(), y(), y()+h()); - } - if (pos&2) { - fl_color(FL_RED); fl_xyline(x(), y()+h(), x()+w()); - fl_color(FL_GREEN); fl_xyline(x(), y()+h()-1, x()+w()); - } else { - fl_color(FL_RED); fl_xyline(x(), y()-1, x()+w()); - fl_color(FL_GREEN); fl_xyline(x(), y(), x()+w()); + Fl_Window::draw(); + if (fTestAlignment) { + drawAlignmentIndicators(); } - fl_color(FL_BLACK); - fl_loop(x()+3, y()+3, x()+w()-4, y()+3, x()+w()-4, y()+h()-4, x()+3, y()+h()-4); } -}; - -void unittest_viewport_test_cb(const char *action, Fl_Group *grp) { - static Fl_Window *win = 0; - if ( grp == 0 ) { - abort(); - } else if ( strcmp(action, "create") == 0 ) { - // Create this unit test's widgets - grp->begin(); - grp->label("See separate window for this test"); - grp->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER); - grp->end(); - // MAKE ENTIRELY SEPARATE WINDOW - win = new Fl_Window(grp->w(), grp->h(), "Viewport Test"); { - Fl_Box *msg = new Fl_Box(0,0,win->w(),win->h()); - msg->box(FL_NO_BOX); - msg->label("testing viewport alignment\n" - "Only green lines should be visible.\n" - "If red lines are visible in the corners of this window,\n" - "your viewport alignment and clipping is off.\n" - "If there is a space between the green lines and the window border,\n" - "the viewport is off, but some clipping may be working.\n" - "Also, your window size may be off to begin with."); - msg->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER|FL_ALIGN_WRAP); - new ViewportTest(0, 0, 20, 20, 0); - new ViewportTest(win->w()-20, 0, 20, 20, 1); - new ViewportTest(0, win->h()-20, 20, 20, 2); - new ViewportTest(win->w()-20, win->h()-20, 20, 20, 3); - win->resizable(win); - win->end(); - } - grp->end(); - } else if ( strcmp(action, "show") == 0 ) { - if ( win ) win->show(); - } else if ( strcmp(action, "hide") == 0 ) { - if ( win ) win->hide(); - } - return; -} - -// -// --- fl_text_extents() tests ----------------------------------------------- -// -class TextExtentsTest : public Fl_Widget -{ - void DrawTextAndBoxes(const char *txt, int X, int Y) { - int wo = 0, ho = 0; - int dx, dy; - // First, we draw the bounding boxes (fl_measure and fl_text_extents) - // draw fl_measure() typographical bounding box - fl_measure(txt, wo, ho, 0); - int desc = fl_descent(); - fl_color(FL_RED); - fl_rect(X, Y-ho+desc, wo, ho); - // draw fl_text_extents() glyph bounding box - fl_text_extents(txt, dx, dy, wo, ho); - fl_color(FL_GREEN); - fl_rect(X+dx, Y+dy, wo, ho); - // Then we draw the text to show how it fits insode each of the two boxes - fl_color(FL_BLACK); - fl_draw(txt, X, Y); - } -public: TextExtentsTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {} - void draw(void) { - int x0 = x(); // origin is current window position for Fl_Box - int y0 = y(); - int w0 = w(); - int h0 = h(); - fl_push_clip(x0, y0, w0, h0); // reset local clipping - { - // set the background colour - slightly off-white to enhance the green bounding box - fl_color(fl_gray_ramp(FL_NUM_GRAY - 3)); - fl_rectf(x0, y0, w0, h0); - - fl_font(FL_HELVETICA, 30); - int xx = x0+55; - int yy = y0+40; - DrawTextAndBoxes("!abcdeABCDE\"#A", xx, yy); yy += 50; // mixed string - DrawTextAndBoxes("oacs", xx, yy); xx += 100; // small glyphs - DrawTextAndBoxes("qjgIPT", xx, yy); yy += 50; xx -= 100; // glyphs with descenders - DrawTextAndBoxes("````````", xx, yy); yy += 50; // high small glyphs - DrawTextAndBoxes("--------", xx, yy); yy += 50; // mid small glyphs - DrawTextAndBoxes("________", xx, yy); yy += 50; // low small glyphs - - fl_font(FL_HELVETICA, 14); - fl_color(FL_RED); fl_draw("fl_measure bounding box in RED", xx, yy); yy += 20; - fl_color(FL_GREEN); fl_draw("fl_text_extents bounding box in GREEN", xx, yy); - fl_color(FL_BLACK); - xx = x0 + 10; yy += 30; - fl_draw("NOTE: On systems with text anti-aliasing (e.g. OSX Quartz)", xx, yy); - w0 = h0 = 0; fl_measure("NOTE: ", w0, h0, 0); - xx += w0; yy += h0; - fl_draw("text may leach slightly outside the fl_text_extents()", xx, yy); - } - fl_pop_clip(); // remove the local clip + void testAlignment(int v) { + fTestAlignment = v; + redraw(); } + int fTestAlignment; }; -void unittest_fl_text_extents_test_cb(const char *action, Fl_Group *grp) { - if ( grp == 0 ) { - abort(); - } else if ( strcmp(action, "create") == 0 ) { - grp->begin(); { - // Create this unit test's widgets - new TextExtentsTest(grp->x(), grp->y(), grp->w(), grp->h()); - } - grp->end(); - } else if ( strcmp(action, "show") == 0 ) { - } else if ( strcmp(action, "hide") == 0 ) { - } - return; -} +//------- include the various unit tests as inline code ------- -////////////////////////////////////////////////////////////////////////// -// UNIT TEST CODE *ENDS* HERE -////////////////////////////////////////////////////////////////////////// +#include "unittest_about.cxx" +#include "unittest_points.cxx" +#include "unittest_lines.cxx" +#include "unittest_rects.cxx" +#include "unittest_circles.cxx" +#include "unittest_text.cxx" +#include "unittest_images.cxx" +#include "unittest_viewport.cxx" -// -// --- SAMPLE UNIT TEST TEMPLATE --------------------------------------------- -// -void unittest_sample_test_cb(const char *action, Fl_Group *grp) { - if ( grp == 0 ) { - abort(); - } else if ( strcmp(action, "create") == 0 ) { - // CREATE YOUR UNIT TEST'S WIDGETS - // This is where you create your widgets for the test. - // The Fl_Group 'grp' has been created for you. - // - grp->begin(); { - // EXAMPLE: Create a green box. - Fl_Box *box = new Fl_Box(grp->x(), grp->y(), grp->w(), grp->h(), "Sample Unit Test"); - box->align(FL_ALIGN_CENTER); - box->box(FL_BORDER_BOX); - box->color(0x50805000); // green - } - grp->end(); - } else if ( strcmp(action, "show") == 0 ) { - // YOUR UNIT TEST HAS JUST BEEN SELECTED TO BE SHOWN - } else if ( strcmp(action, "hide") == 0 ) { - // YOUR UNIT TEST HAS JUST BEEN HIDDEN - } - return; -} -// UNIT TEST MANAGEMENT -class TestInfo { -public: - const char *name; - Fl_Group *grp; - UnitTestCallback cb; - // CTOR - TestInfo(const char *name, Fl_Group *grp, UnitTestCallback cb) { - this->name = name; - this->grp = grp; - this->cb = cb; - } - void DoCallback(const char *action) { - if ( ! cb ) return; - (cb)(action, grp); - } -}; -// START TEST THE USER CLICKED ON +// callback whenever the browser value changes void Browser_CB(Fl_Widget*, void*) { for ( int t=1; t<=browser->size(); t++ ) { - TestInfo *ti = (TestInfo*)browser->data(t); + UnitTest *ti = (UnitTest*)browser->data(t); if ( browser->selected(t) ) { - ti->grp->show(); - ti->DoCallback("show"); // show the selected test + ti->show(); } else { - ti->grp->hide(); - ti->DoCallback("hide"); // hide the deselected test(s) + ti->hide(); } } } -// ADD A UNIT TEST TO THE BROWSER -void AddTest(const char *testname, UnitTestCallback unit_cb) { - // Create new group for the test area - mainwin->begin(); - Fl_Group *grp = new Fl_Group(TESTAREA_X,TESTAREA_Y,TESTAREA_W,TESTAREA_H,testname); - grp->end(); - grp->hide(); - // New test info instance for this test - TestInfo *ti = new TestInfo(testname, grp, unit_cb); - // Add new browser item - browser->add(testname, (void*)ti); - // Tell test to create widgets - ti->DoCallback("create"); -} + + +// this is the main call. It creates the window and adds all previously +// registered tests to the browser widget. int main(int argc, char **argv) { Fl::args(argc,argv); - mainwin = new Fl_Window(MAINWIN_W, MAINWIN_H, "Fltk Unit Tests"); + Fl::visual(FL_RGB); + mainwin = new MainWindow(MAINWIN_W, MAINWIN_H, "Fltk Unit Tests"); browser = new Fl_Hold_Browser(BROWSER_X, BROWSER_Y, BROWSER_W, BROWSER_H, "Unit Tests"); browser->align(FL_ALIGN_TOP|FL_ALIGN_LEFT); browser->when(FL_WHEN_CHANGED); browser->callback(Browser_CB); - //// START: ADD CALLS TO UNIT TESTS HERE - //// List in alphabetical order please.. - //// - AddTest("fl_circle()", &unittest_fl_circle_test_cb); - AddTest("fl_line()", &unittest_fl_line_test_cb); - AddTest("fl_point()", &unittest_fl_point_test_cb); - AddTest("fl_rect()", &unittest_fl_rect_test_cb); - AddTest("fl_text_extents()", &unittest_fl_text_extents_test_cb); - AddTest("Viewport test", &unittest_viewport_test_cb); - AddTest("Sample test", &unittest_sample_test_cb); + + int i, n = UnitTest::numTest(); + for (i=0; i<n; i++) { + UnitTest *t = UnitTest::test(i); + mainwin->begin(); + t->create(); + mainwin->end(); + browser->add(t->label(), (void*)t); + } + ///// mainwin->resizable(mainwin); mainwin->show(argc,argv); diff --git a/test/utf8.cxx b/test/utf8.cxx index 1b9647191..86b006f3f 100644 --- a/test/utf8.cxx +++ b/test/utf8.cxx @@ -480,6 +480,41 @@ void i7_cb(Fl_Widget *w, void *d) i8->value(buf); } +class UCharDropBox : public Fl_Output { +public: + UCharDropBox(int x, int y, int w, int h, const char *label=0) : + Fl_Output(x, y, w, h, label) { } + int handle(int event) { + switch (event) { + case FL_DND_ENTER: return 1; + case FL_DND_DRAG: return 1; + case FL_DND_RELEASE: return 1; + case FL_PASTE: + { + const char *t = Fl::event_text(); + int i, n; + fl_utf8decode(t, t+Fl::event_length(), &n); + if (n==0) { + value(""); + return 1; + } + char buffer[200], *d = buffer; + for (i=0; i<n; i++) *d++ = t[i]; + *d++ = ' '; + for (i=0; i<n; i++) { + const char lut[] = "0123456789abcdef"; + *d++ = '\\'; *d++ = 'x'; + *d++ = lut[(t[i]>>4)&0x0f]; *d++ = lut[t[i]&0x0f]; + } + *d++ = 0; + value(buffer); + } + return 1; + } + return Fl_Output::handle(event); + } +}; + /********************************************************************************************/ int main(int argc, char** argv) { @@ -597,6 +632,10 @@ int main(int argc, char** argv) // SOME JAPANESE UTF8 TEXT const char *utfstr = "\xe4\xbd\x95\xe3\x82\x82\xe8\xa1" "\x8c\xe3\x82\x8b\xe3\x80\x82"; // 何も行る。 + + UCharDropBox db(5, 300, 190, 30); + db.textsize(16); + db.value("unichar drop box"); Fl_Output o9(5, 330, 190, 45); o9.textfont(extra_font); |
