]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImage.h
2002-05-30 Lars Gullik Bj�nnes <larsbj@birdstep.com>
[lyx.git] / src / graphics / GraphicsImage.h
1 // -*- C++ -*-
2 /**
3  *  \file GraphicsImage.h
4  *  Copyright 2002 the LyX Team
5  *  Read the file COPYING
6  *
7  *  \author Baruch Even <baruch.even@writeme.com>
8  *  \author Angus Leeming <a.leeming@ic.ac.uk>
9  *
10  *  An abstract base class for the images themselves.
11  *  Allows the user to retrieve the pixmap, once loaded and to issue commands
12  *  to modify it.
13  *
14  *  The signals newImage and loadableFormats are connected to the approriate
15  *  derived classes elsewhere, allowing the graphics cache to access them
16  *  without knowing anything about their instantiation.
17  *
18  *  The loading process can be asynchronous, but cropping, rotating and
19  *  scaling block execution.
20  */
21
22 #ifndef GRAPHICSIMAGE_H
23 #define GRAPHICSIMAGE_H
24
25 #include "LString.h"
26 #include "GraphicsTypes.h"
27
28 #include <boost/shared_ptr.hpp>
29
30 #include <boost/signals/signal0.hpp>
31 #include <boost/signals/signal1.hpp>
32
33 #include <X11/X.h>
34
35 #include <vector>
36 #include <utility>
37
38 #ifdef __GNUG__
39 #pragma interface
40 #endif
41
42 namespace grfx {
43
44 class GParams;
45
46 class GImage
47 {
48 public:
49         /// A list of supported formats.
50         typedef std::vector<string> FormatList;
51         /** This will be connected to a function that will return whichever
52          *  derived class we desire.
53          */
54         static boost::signal0<ImagePtr> newImage;
55
56         /// Return the list of loadable formats.
57         static boost::signal0<FormatList> loadableFormats;
58
59         ///
60         virtual ~GImage() {}
61
62         /// Create a copy
63         virtual GImage * clone() const = 0;
64
65         ///
66         virtual Pixmap getPixmap() const = 0;
67
68         /// Get the image width
69         virtual unsigned int getWidth() const = 0;
70
71         /// Get the image height
72         virtual unsigned int getHeight() const = 0;
73
74         /** At the end of the loading or modification process, return the new
75          *  image by emitting this signal */
76         typedef boost::signal1<void, bool> SignalType;
77         ///
78         typedef boost::shared_ptr<SignalType> SignalTypePtr;
79
80         /// Start loading the image file.
81         virtual void load(string const & filename, SignalTypePtr) = 0;
82
83         /** Generate the pixmap.
84          *  Uses the params to decide on color, grayscale etc.
85          *  Returns true if the pixmap is created.
86          */
87         virtual bool setPixmap(GParams const & params) = 0;
88
89         /// Clip the image using params.
90         virtual void clip(GParams const & params) = 0;
91
92         /// Rotate the image using params.
93         virtual void rotate(GParams const & params) = 0;
94
95         /// Scale the image using params.
96         virtual void scale(GParams const & params) = 0;
97
98 protected:
99         /** Uses the params to ascertain the dimensions of the scaled image.
100          *  Returned as make_pair(width, height).
101          *  If something geso wrong, returns make_pair(getWidth(), getHeight())
102          */
103         std::pair<unsigned int, unsigned int>
104         getScaledDimensions(GParams const & params) const;
105 };
106
107 } // namespace grfx
108
109 #endif // GRAPHICSIMAGE_H