3 * \file GraphicsImage.h
4 * Read the file COPYING
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
11 * An abstract base class for the images themselves.
12 * Allows the user to retrieve the pixmap, once loaded and to issue commands
15 * The boost::functions newImage and loadableFormats are connected to the
16 * appropriate derived classes elsewhere, allowing the graphics cache to
17 * access them without knowing anything about their instantiation.
19 * The loading process can be asynchronous, but cropping, rotating and
20 * scaling block execution.
23 #ifndef GRAPHICSIMAGE_H
24 #define GRAPHICSIMAGE_H
28 #include <boost/shared_ptr.hpp>
29 #include <boost/function/function0.hpp>
30 #include <boost/signals/signal1.hpp>
45 /** This is to be connected to a function that will return a new
46 * instance of a viable derived class.
48 typedef boost::shared_ptr<Image> ImagePtr;
50 static boost::function0<ImagePtr> newImage;
52 /// Return the list of loadable formats.
53 typedef std::vector<string> FormatList;
55 static boost::function0<FormatList> loadableFormats;
57 /// Must define default c-tor explicitly as we define a copy c-tor.
59 /// Don't copy the signal finishedLoading
60 Image(Image const &) {}
65 virtual Image * clone() const = 0;
67 /// Get the image width
68 virtual unsigned int getWidth() const = 0;
70 /// Get the image height
71 virtual unsigned int getHeight() const = 0;
73 /// is the image drawable ?
74 virtual bool isDrawable() const = 0;
76 /** At the end of the loading process inform the outside world
77 * by emitting a signal.
79 typedef boost::signal1<void, bool> SignalType;
81 SignalType finishedLoading;
83 /** Start loading the image file.
84 * The caller should expect this process to be asynchronous and
85 * so should connect to the "finished" signal above.
87 virtual void load(string const & filename) = 0;
89 /** Generate the pixmap.
90 * Uses the params to decide on color, grayscale etc.
91 * Returns true if the pixmap is created.
93 virtual bool setPixmap(Params const & params) = 0;
95 /// Clip the image using params.
96 virtual void clip(Params const & params) = 0;
98 /// Rotate the image using params.
99 virtual void rotate(Params const & params) = 0;
101 /// Scale the image using params.
102 virtual void scale(Params const & params) = 0;
105 /** Uses the params to ascertain the dimensions of the scaled image.
106 * Returned as make_pair(width, height).
107 * If something goes wrong, returns make_pair(getWidth(), getHeight())
109 std::pair<unsigned int, unsigned int>
110 getScaledDimensions(Params const & params) const;
115 #endif // GRAPHICSIMAGE_H