fltk::SharedImage Class Reference

#include <SharedImage.h>

Inherits fltk::Image.

Inherited by fltk::bmpImage, fltk::gifImage, fltk::jpegImage, fltk::pngImage, fltk::pnmImage, and fltk::xpmFileImage.

List of all members.

Public Types

typedef SharedImage *(* Handler )(const char *filename, uchar *header, int headerlen)

Public Member Functions

void _draw (const Rectangle &) const
void clear_cache ()
void reload (const uchar *datas=0)
int remove ()

Static Public Member Functions

static void add_handler (Handler f)
static SharedImageget (const char *n)
static SharedImageget (SharedImage *(*create)(), const char *name, const uchar *datas=0)
static const char * get_filename (const char *)
static void remove_handler (Handler f)
static void set_cache_size (unsigned l)
static void set_root_directory (const char *d)

Protected Member Functions

virtual bool fetch ()=0
const char * get_filename () const

Detailed Description

Subclass of Image that can read a file or block of compressed data. This provides several useful functions: Images are identified by filename. The static get() function will return an existing instance if it was called before with the same filename. The release() function will decrement the reference count and delete the image if nobody wants it any more. An inline block of data may be provided that is the contents of the file, so the file does not have to exist and you can link the image directly into your program. You may set a memory usage limit. If Image::mem_used() goes above this limit, it will call destroy() on least-recently-used images until it goes below this limit. The get() function can determine the type of the file or block of data and create the correct subclass.

Member Typedef Documentation

typedef SharedImage*(* fltk::SharedImage::Handler)(const char *filename, uchar *header, int headerlen)

a SharedImageHandler accepts handling a filename by analizing its extension and/or eventually its header, if it handles it it returns a non null pointer on the loaded concrete image fetch to the data/pixels unified buffer the image, return true if success. this method() does NOT draw the image, it only prepares a generic buffer and its info, this method should be used by all non-progresive-reading read() methods so that we avoid redondant code

Member Function Documentation

void SharedImage::_draw ( const Rectangle r) const [virtual]

Resizes the image to fit in the rectangle. This is the virtual method from the Symbol base class, so this is what is called if the image is used as a label or box type.

If the destination rectangle is not the same size, inset() is used to figure out the edge thicknesses. The image is then diced into 9 rectangles in a 3x3 grid by the insets, and each piece is scaled individually. This is very useful for scaling paintings of buttons. Note that if the insets are zero (the default) then the whole image is scaled as one piece. If you want, inset() can return different thicknesses depending on the size, producing very interesting scaling.

It is possible this will use drawflags(INACTIVE) to gray out the image in a system-specific way. NYI.

Reimplemented from fltk::Image.

void SharedImage::add_handler ( SharedImage::Handler  f) [static]

adds a new handler for hanling a concrete type of image, typically one handler per image type should be registered

void SharedImage::clear_cache ( )

Clear the cache for this image and all of its children in the binary tree

Calls destroy() on this and every less-recently-used SharedImage?.

virtual bool fltk::SharedImage::fetch ( ) [protected, pure virtual]

This is called by the draw() functions once after the Image is created or after refetch() has been called. This allows subclasses to defer reading files and calling setpixels() calls until the first draw() or measure(). This should return true if successful, false on any error (though fltk does not do anything useful with errors).

The base class does nothing and returns true, thus leaving the image unchanged.

Sample implementation:

  bool MyImage::fetch() {
    setsize(get_width(file), get_height(file));
    for (int y=0; y<height(); y++) {
      uchar* buffer = linebuffer(y);
      get_line_of_pixels(file, buffer, y);
      setpixels(buffer, y);
    return true;

Reimplemented from fltk::Image.

Implemented in fltk::gifImage, and fltk::xpmFileImage.

SharedImage * SharedImage::get ( const char *  n) [static]

get an image of this name and dimensions , can be already loaded or not

SharedImage * SharedImage::get ( SharedImage *(*)()  create,
const char *  name,
const uchar *  datas = 0 
) [static]

Return an SharedImage, using the create function if an image with the given name doesn't already exist. Use datas, or read from the file with filename name if datas==0.

const char * SharedImage::get_filename ( const char *  name) [static]

Expand a name relative to root to see what file it will read

Prepends the shared_image_root to the name. This is what get_filename() would return for a SharedImage with this name.

const char * SharedImage::get_filename ( ) const [protected]

Return the filename obtained from the concatenation of the image root directory and this image name WARNING : the returned pointer will be available only until next call to get_filename

void SharedImage::reload ( const uchar *  datas = 0)

Reload the image, useful if it has changed on disk, or if the datas / in memory have changed (you can also give a new pointer on datas)

int SharedImage::remove ( )

Remove an image from the database and delete it if its refcount has fallen to zero Each remove() decrements the refcount, each get() increments it Return 1 if it has been really deleted.

void SharedImage::remove_handler ( SharedImage::Handler  f) [static]

removes a concrete handler

void SharedImage::set_cache_size ( unsigned  l) [static]

Set the size of the cache (0 = unlimited is the default)

void SharedImage::set_root_directory ( const char *  d) [static]

Set the position where images are looked for on disk

The documentation for this class was generated from the following files: