DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2449
Version: 1.3-current





Link: http://www.fltk.org/str.php?L2449
Version: 1.3-current
// A trival example illustration how to load an image
//
// Step 1. Compile using: flt-config --use-images --compile pngtest.cxx
//
// Step 2. Run: pngtest
//         The program opens tux.png (in the CWD).
//

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Value_Output.H>
#include <FL/Fl_Shared_Image.H> // Image I/O
#include <FL/fl_ask.H>                  // fl_alert, fl_choice
#include <FL/filename.H>                // fl_filename_name
#include <string.h>                             // strncmp, strlen, etc.
#include <stdio.h>                              // snprintf

// Widget group that displays the image. Fl_Group holds
// the Fl_Box and the Fl_DND_Box. This way Fl_DND_Box
// will resize according to Fl_Box
Fl_Box *box = (Fl_Box*)0;
Fl_Value_Output *width = (Fl_Value_Output*)0;
Fl_Value_Output *height = (Fl_Value_Output*)0;
Fl_Value_Output *depth = (Fl_Value_Output*)0;

void file_close()
{
        Fl_Shared_Image *img = (Fl_Shared_Image*)box->image();

        if(!img)
                return; // no image displayed

        box->image(0);
        
        // The image is shared, release until no more references
        while(img->refcount())
                img->release();
}

void file_open(const char *fpath)
{
        file_close();

        Fl_Shared_Image *img = Fl_Shared_Image::get(fpath);
        
        if(!img)
        {
                fl_alert("Failed to load image: %s", fpath);
                return;
        }

        box->size(img->w(), img->h());
        box->image(img);

        width->value(img->w());
        height->value(img->h());
        depth->value(img->d());

        Fl::redraw();
}

int main(int argc, char *argv[])
{
        Fl::visual(FL_DOUBLE | FL_INDEX);
        Fl::get_system_colors();
        fl_register_images();
        Fl::scheme("gtk+");

        Fl_Double_Window *wnd = new Fl_Double_Window(10, 10, 500, 445, "Open 
tux.png");
        {
                { 
                        Fl_Scroll *o = new Fl_Scroll(15, 15, 470, 315, 0);
                        o->box(FL_ENGRAVED_BOX);
                        {
                                box = new Fl_Box(17, 17, 468, 313, 0);
                                box->box(FL_FLAT_BOX);
                                box->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER);
                        }
                        o->end();
                        Fl_Group::current()->resizable(o);
                }

                width = new Fl_Value_Output(45, 340, 100, 30, "Width:");
                width->align(FL_ALIGN_LEFT);
                height = new Fl_Value_Output(200, 340, 100, 30, "Height:");
                height->align(FL_ALIGN_LEFT);
                depth = new Fl_Value_Output(350, 340, 100, 30, "Depth:");
                depth->align(FL_ALIGN_LEFT);
        }
        wnd->end();
        wnd->show(argc, argv);

        file_open("tux.png");

        return Fl::run();
}

_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to