From: <laz...@us...> - 2002-09-16 12:01:29
|
Update of /cvsroot/ede/efltk/test In directory usw-pr-cvs1:/tmp/cvs-serv5077/test Modified Files: Makefile editor.cpp Added Files: alphablend.cpp image_manip.cpp listview.cpp Log Message: - Fixed Fl_Text_Editor ATTR_UNDERLINE draw - Added 3 more tests - fixed Fl_ListView keyboard events, when none of items are selected. --- NEW FILE: alphablend.cpp --- #include <stdlib.h> #include <stdio.h> #include <efltk/Fl.h> #include <efltk/Fl_Double_Window.h> #include <efltk/Fl_Window.h> #include <efltk/Fl_Button.h> #include <efltk/fl_draw.h> #include <efltk/x.h> #include <efltk/Fl_Color.h> #include <efltk/Fl_Image.h> #include <efltk/Fl_Images.h> #include <config.h> static int X = 10, Y=100, TY=-20; //Bouncing Ball class BBWin : public Fl_Double_Window { public: BBWin(Fl_Image *back, Fl_Image *ball) : Fl_Double_Window(200, 200, "Bouncing Ball") { bg = back; b = ball; scale_bg=0; alpha_b=0; } void draw() { if(scale_bg) { if(scale_bg->width() != w() || scale_bg->height() != h()) { delete scale_bg; scale_bg = 0; } } if(!scale_bg) { scale_bg = bg->scale(w(),h()); } if(scale_bg) scale_bg->draw(0, 0, w(), h()); else bg->draw(0, 0, bg->width(), bg->height()); if(alpha_b) { delete alpha_b; alpha_b = 0; } if(!alpha_b && scale_bg) { alpha_b = b->blend(scale_bg, X,Y, b->width(), b->height()); } if(alpha_b) alpha_b->draw(X, Y, b->width(), b->height()); fl_font(FL_HELVETICA, 12); fl_draw("Alpha Blending with\neFLTK, nice...", 10, TY, w()-20, 20, FL_ALIGN_CENTER); } Fl_Image *b, *bg, *scale_bg, *alpha_b; }; void bb_timeout(void *data) { static int xdir = 1, ydir = 1; if(X > ((BBWin *)data)->width()-((BBWin *)data)->b->width()+1) xdir = -2; else if(X < 1) xdir = 2; X += xdir; if(Y > ((BBWin *)data)->height()-((BBWin *)data)->b->height()+1) ydir = -3; else if(Y < 1) ydir = 1; Y += ydir; TY++; if(TY-20>((BBWin *)data)->h()) TY=-20; ((BBWin *)data)->redraw(); Fl::repeat_timeout(0.01, bb_timeout, data); } #define WIDTH 200 #define HEIGHT 200 uchar* make_image() { // pitch = WORD alignment bits per line int pitch=Fl_Renderer::calc_pitch(3, WIDTH); int skip = pitch - WIDTH * 3; uchar *image = new uchar[HEIGHT*pitch]; uchar *p = image; for (int y = 0; y < HEIGHT; y++) { double Y = double(y)/(HEIGHT-1); for (int x = 0; x < WIDTH; x++) { double X = double(x)/(WIDTH-1); *p++ = uchar(255*((1-X)*(1-Y))); // red in upper-left *p++ = uchar(255*((1-X)*Y)); // green in lower-left *p++ = uchar(255*(X*Y)); // blue in lower-right } p+=skip; } return image; } int main(int argc, char *argv[]) { #ifdef HAVE_PNG // Initialize extension for PNG fl_init_images_lib(); Fl::args(argc, argv); ////////////////////////////// // Bouncing ball... Fl_Image *bb_bg, *bb; bb_bg = new Fl_Image(WIDTH, HEIGHT, 24, make_image(), 0x0000FF, 0x00FF00, 0xFF0000, 0 ,0); bb = Fl_Image::read("bb.png"); if(bb_bg && bb) { // Speed up things bb_bg->system_convert(); BBWin bwin(bb_bg, bb); bwin.resizable(bwin); Fl::add_timeout(0.1, bb_timeout, (void *)&bwin); ////////////////////////////// bwin.show(); while(bwin.visible()) { Fl::wait(); } delete bb_bg; delete bb; } #else Fl::warning("This test works only with PNG lib support"); #endif return 0; } --- NEW FILE: image_manip.cpp --- #include <efltk/Fl.h> #include <efltk/Fl_Window.h> #include <efltk/Fl_Box.h> #include <efltk/Fl_Value_Slider.h> #include <efltk/Fl_Radio_Button.h> #include <efltk/Fl_Check_Button.h> #include <efltk/Fl_Image.h> #include <efltk/Fl_Image_Filter.h> Fl_Value_Slider *slider[3]; Fl_Image *image, *show_image=0; Fl_Image_Filter *current=0; Fl_Check_Button *lock; Fl_Box *image_box; void slider_cb(Fl_Widget *w, void *d) { if(lock->value()) { Fl_Slider *s = (Fl_Slider*)w; double val = s->value(); slider[0]->value(val); slider[1]->value(val); slider[2]->value(val); } if(show_image) delete show_image; show_image = Fl_Image_Filter::apply_to_new(image, 0, current, slider[0]->value(), slider[1]->value(), slider[2]->value()); image_box->image(show_image); image_box->redraw(); } void button_cb(Fl_Widget *w, void *d) { int b = (int)d; switch(b) { case 1: slider[0]->activate(); slider[1]->deactivate(); slider[2]->deactivate(); slider[0]->range(-1, 1); slider[0]->value(0); slider[1]->value(0); slider[2]->value(0); current = FILTER_BRIGHTNESS; break; case 2: slider[0]->activate(); slider[1]->activate(); slider[2]->activate(); slider[0]->range(-3, 3); slider[0]->value(1); slider[1]->value(1); slider[2]->value(1); current = FILTER_CONTRAST; break; case 3: slider[0]->activate(); slider[1]->activate(); slider[2]->activate(); slider[0]->range(-3, 3); slider[0]->value(1); slider[1]->value(1); slider[2]->value(1); current = FILTER_GAMMA; break; case 4: slider[0]->deactivate(); slider[1]->deactivate(); slider[2]->deactivate(); slider[0]->range(-3, 3); slider[0]->value(1); slider[1]->value(1); slider[2]->value(1); current = FILTER_DESATURATE; break; }; slider_cb(slider[0], 0); } #define WIDTH 200 #define HEIGHT 200 uchar* make_image() { // pitch = WORD alignment bits per line int pitch=Fl_Renderer::calc_pitch(3, WIDTH); int skip = pitch - WIDTH * 3; uchar *image = new uchar[HEIGHT*pitch]; uchar *p = image; for (int y = 0; y < HEIGHT; y++) { double Y = double(y)/(HEIGHT-1); for (int x = 0; x < WIDTH; x++) { double X = double(x)/(WIDTH-1); *p++ = uchar(255*((1-X)*(1-Y))); // red in upper-left *p++ = uchar(255*((1-X)*Y)); // green in lower-left *p++ = uchar(255*(X*Y)); // blue in lower-right } p+=skip; } return image; } // Make RGB image Fl_Image rgb_image(WIDTH, HEIGHT, 24, make_image(), 0x0000FF, 0x00FF00, 0xFF0000, 0 ,0); int main(int argc, char *argv[]) { Fl::args(argc, argv); image = &rgb_image; Fl_Window w(500,270,"Image filter test"); Fl_Box b(10,10,250,250); b.box(FL_DOWN_BOX); b.image(image); image_box = &b; Fl_Value_Slider s1(280, 20, 30, 240, "R"); s1.when(FL_WHEN_RELEASE); s1.callback(slider_cb, (void*)1); s1.deactivate(); s1.range(-3, 3); s1.value(1); s1.align(FL_ALIGN_TOP); s1.type(Fl_Value_Slider::VERTICAL); slider[0] = &s1; Fl_Value_Slider s2(320, 20, 30, 240, "G"); s2.when(FL_WHEN_RELEASE); s2.callback(slider_cb, (void*)2); s2.deactivate(); s2.range(-3, 3); s2.value(1); s2.align(FL_ALIGN_TOP); s2.type(Fl_Value_Slider::VERTICAL); slider[1] = &s2; Fl_Value_Slider s3(360, 20, 30, 240, "B"); s3.when(FL_WHEN_RELEASE); s3.callback(slider_cb, (void*)3); s3.deactivate(); s3.range(-3, 3); s3.value(1); s3.align(FL_ALIGN_TOP); s3.type(Fl_Value_Slider::VERTICAL); slider[2] = &s3; Fl_Group g(400, 20, 90, 100, "Filter:"); g.box(FL_ENGRAVED_BOX); Fl_Radio_Button b1(2,10,88,20,"Brightness"); b1.callback(button_cb, (void*)1); Fl_Radio_Button b2(2,30,88,20,"Contrast"); b2.callback(button_cb, (void*)2); Fl_Radio_Button b3(2,50,88,20,"Gamma"); b3.callback(button_cb, (void*)3); Fl_Radio_Button b4(2,70,88,20,"Desaturate"); b4.callback(button_cb, (void*)4); g.end(); Fl_Check_Button l(400, 140, 90, 20, "Lock sliders"); lock = &l; w.show(); return Fl::run(); } --- NEW FILE: listview.cpp --- #include <efltk/Fl.h> #include <efltk/Fl_Double_Window.h> #include <efltk/Fl_Window.h> #include <efltk/Fl_Button.h> #include <efltk/Fl_ListView.h> #include <efltk/Fl_ListView_Item.h> #include <efltk/Fl_Image.h> static Fl_Image *im, *bg; Fl_Button *moveb, *multib, *imb, *stripeb; void callback(Fl_ListView *l, void *) { Fl_ListView_Item *i = (Fl_ListView_Item *)l->item(); if(i) { if(Fl::event_clicks()) printf("Double "); printf("Clicked '"); for(int a=0; a<l->columns(); a++) printf("%s ", i->label(a)); printf("'\n"); } } void cb_multi(Fl_Widget *w, void *d) { Fl_ListView *l = (Fl_ListView *)d; if(w->value()) l->type(l->type() | Fl_ListView::MULTI_SELECTION); else l->type(l->type() &~ Fl_ListView::MULTI_SELECTION); } void cb_move(Fl_Widget *w, void *d) { Fl_ListView *l = (Fl_ListView *)d; if(w->value()) l->type(l->type() | Fl_ListView::MOVE_SELECTION); else l->type(l->type() &~ Fl_ListView::MOVE_SELECTION); } void cb_single(Fl_Widget *w, void *d) { Fl_ListView *l = (Fl_ListView *)d; l->type( l->type() &~ (Fl_ListView::MULTI_SELECTION|Fl_ListView::MOVE_SELECTION) ); l->draw_stripes(false); l->bg_image(0); multib->value(0); moveb->value(0); imb->value(0); stripeb->value(0); l->redraw(); } void cb_image(Fl_Widget *w, void *d) { Fl_ListView *l = (Fl_ListView *)d; if(w->value()) l->bg_image(bg); else l->bg_image(0); l->redraw(); l->relayout(); } void cb_stripes(Fl_Widget *w, void *d) { Fl_ListView *l = (Fl_ListView *)d; if(w->value()) l->draw_stripes(true); else l->draw_stripes(false); l->redraw(); } static char * ball_xpm[] = { "16 16 13 1", " c None", ". c #FFECEC", "+ c #FFC1C1", "@ c #FF9A9A", "# c #FF8585", "$ c #FFD9D9", "% c #FF8686", "& c #FF4141", "* c #FF1A1A", "= c #FF0505", "- c #FF7373", "; c #FF1919", "> c #FF0000", " ", " .+@##@+. ", " $%&*==*&%$ ", " $-;>>>>>>;-$ ", " .%;>>>>>>>>;%. ", " +&>>>>>>>>>>&+ ", " @*>>>>>>>>>>*@ ", " #=>>>>>>>>>>=# ", " #=>>>>>>>>>>=# ", " @*>>>>>>>>>>*@ ", " +&>>>>>>>>>>&+ ", " .%;>>>>>>>>;%. ", " $-;>>>>>>;-$ ", " $%&*==*&%$ ", " .+@##@+. ", " "}; #define WIDTH 200 #define HEIGHT 200 uchar* make_image() { // pitch = WORD alignment bits per line int pitch=Fl_Renderer::calc_pitch(3, WIDTH); int skip = pitch - WIDTH * 3; uchar *image = new uchar[HEIGHT*pitch]; uchar *p = image; for (int y = 0; y < HEIGHT; y++) { double Y = double(y)/(HEIGHT-1); for (int x = 0; x < WIDTH; x++) { double X = double(x)/(WIDTH-1); *p++ = uchar(255*((1-X)*(1-Y))); // red in upper-left *p++ = uchar(255*((1-X)*Y)); // green in lower-left *p++ = uchar(255*(X*Y)); // blue in lower-right } p+=skip; } return image; } int main() { Fl::init(); im = Fl_Image::read_xpm(0, ball_xpm); bg = new Fl_Image(WIDTH, HEIGHT, 24, make_image(), 0x0000FF, 0x00FF00, 0xFF0000, 0 ,0); //Fl_Double_Window w(300,300,"ListView Test"); Fl_Window w(300, 300, "ListView Test"); w.begin(); Fl_ListView l(10,10,280,250); //l.header()->hide(); l.callback((Fl_Callback*)callback); // Set some look for header l.header()->box(FL_VERT_SHADE_UP_BOX); l.header()->label_color(FL_WHITE); l.header()->label_font(FL_HELVETICA_BOLD); // Add 4 cols l.add_column("First"); l.add_column("Second"); l.add_column("Third"); l.add_column("Fourth"); // Add images for cols l.column_image(0, im); l.column_image(1, im); l.column_image(2, im); l.column_image(3, im); // Set alignment flags l.column_flags(0, FL_ALIGN_LEFT); l.column_flags(1, FL_ALIGN_CENTER); l.column_flags(2, FL_ALIGN_CENTER); l.column_flags(3, FL_ALIGN_RIGHT); // Set type for multi and move selection support //l.type(l.type()|Fl_ListView::MULTI_SELECTION|Fl_ListView::MOVE_SELECTION); // Add 100 items for(int a=0; a<100; a++) { Fl_ListView_Item *i = new Fl_ListView_Item(0, "Some Text", "COL 3", "-----------Long column-----------"); char tmp[32]; sprintf(tmp, "COL1: %d", a); // Copy tmp to column one, ListView will deallocate it. i->copy_label(0, tmp); // Set some alignment flags i->column_flags(0, FL_ALIGN_LEFT); i->column_flags(1, FL_ALIGN_CENTER); i->column_flags(2, FL_ALIGN_CENTER); i->column_flags(3, FL_ALIGN_RIGHT); // Set color for column 2 i->color(1, FL_RED); // Set font for column 3 i->font(2, FL_HELVETICA_BOLD, 14); // Images for cols 1,2,3 i->image(0, im); i->image(1, im); i->image(2, im); } l.relayout(); l.end(); Fl_Button but(10, 265, 50, 20, "Move"); but.type(Fl_Button::TOGGLE); but.callback(cb_move, &l); Fl_Button but2(70, 265, 50, 20, "Multi"); but2.type(Fl_Button::TOGGLE); but2.callback(cb_multi, &l); Fl_Button but4(130, 265, 50, 20, "Image"); but4.type(Fl_Button::TOGGLE); but4.callback(cb_image, &l); Fl_Button but5(190, 265, 50, 20, "Stripes"); but5.type(Fl_Button::TOGGLE); but5.callback(cb_stripes, &l); Fl_Button but3(250, 265, 40, 20, "Clear"); but3.callback(cb_single, &l); moveb = &but; multib = &but2; imb = &but4; stripeb = &but5; w.resizable(&l); w.end(); w.show(); // Speed up things littlebit Fl::check(); // Get FLTK display info bg->system_convert(); // Convert to system format, no conversion during scaling... Fl::run(); delete im; delete bg; return 0; } Index: Makefile =================================================================== RCS file: /cvsroot/ede/efltk/test/Makefile,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile 7 Sep 2002 23:10:27 -0000 1.3 +++ Makefile 16 Sep 2002 12:01:21 -0000 1.4 @@ -31,14 +31,15 @@ clock.cpp color_chooser.cpp cube.cpp cursor.cpp curve.cpp fast_slow.cpp \ fonts.cpp fullscreen.cpp gl_overlay.cpp iconize.cpp input.cpp navigation.cpp \ output.cpp overlay.cpp pack.cpp radio.cpp shape.cpp tile.cpp CubeMain.cpp CubeView.cpp \ - preferences.cpp + preferences.cpp image_manip.cpp listview.cpp alphablend.cpp ALL = demo hello resizable scroll image file_chooser menubar browser \ threads progress editor inactive checkers valuators glpuzzle boxtype \ multi_image help mdi_test resize tabs line_style doublebuffer subwindow \ keyboard label layout arc ask button buttons clock color_chooser cube \ cursor curve fast_slow fonts fullscreen gl_overlay iconize input navigation \ - output overlay pack radio shape tile CubeView preferences + output overlay pack radio shape tile CubeView preferences image_manip \ + listview alphablend all: demos @@ -79,6 +80,9 @@ image_file: image_file.cpp $(FLIMAGESLIB) $(FLLIB) $(CXX) -I.. $(CXXFLAGS) $< $(IMAGELIBS) $(PNGLIBS) $(JPEGLIBS) $(LDLIBS) -o $@ + +alphablend: alphablend.cpp $(FLCORELIB) $(FLUILIB) + $(CXX) -I.. $(CXXFLAGS) $< $(LDLIBS) $(FLIMAGESLIB) $(PNGLIBS) $(JPEGLIBS) -o $@ file_chooser: file_chooser.cpp $(FLCORELIB) $(FLUILIB) $(CXX) -I.. $(CXXFLAGS) $< $(LDLIBS) $(FLIMAGESLIB) $(PNGLIBS) $(JPEGLIBS) -o $@ Index: editor.cpp =================================================================== RCS file: /cvsroot/ede/efltk/test/editor.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- editor.cpp 15 Sep 2002 21:30:38 -0000 1.3 +++ editor.cpp 16 Sep 2002 12:01:21 -0000 1.4 @@ -68,8 +68,8 @@ { FL_DARK3, FL_COURIER_ITALIC, 12 }, // C - Block comments { FL_BLUE, FL_COURIER, 12 }, // D - Strings { fl_color_average(FL_RED, FL_BLACK, 0.5), FL_COURIER, 12 }, // E - Directives - { FL_RED, FL_COURIER_BOLD, 12 }, // F - Types - { FL_BLUE, FL_COURIER_BOLD, 12 } // G - Keywords + { FL_RED, FL_COURIER_BOLD, 12 , Fl_Text_Display::ATTR_UNDERLINE}, // F - Types + { FL_BLUE, FL_COURIER_BOLD, 12 , Fl_Text_Display::ATTR_UNDERLINE} // G - Keywords }; const char *code_keywords[] = { // List of known C/C++ keywords... "and", |