]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
Added wxTolBar::etMargins
[wxWidgets.git] / include / wx / image.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: image.h
3 // Purpose: wxImage class
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_IMAGE_H_
11 #define _WX_IMAGE_H_
12
13 #ifdef __GNUG__
14 #pragma interface "image.h"
15 #endif
16
17 #include "wx/setup.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/gdicmn.h"
21
22 //-----------------------------------------------------------------------------
23 // classes
24 //-----------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxImageHandler;
27 class WXDLLEXPORT wxPNGHandler;
28 class WXDLLEXPORT wxBMPHandler;
29 class WXDLLEXPORT wxImage;
30
31 class WXDLLEXPORT wxBitmap;
32
33 //-----------------------------------------------------------------------------
34 // wxImageHandler
35 //-----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxImageHandler: public wxObject
38 {
39 DECLARE_DYNAMIC_CLASS(wxImageHandler)
40
41 public:
42 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
43
44 virtual bool LoadFile( wxImage *image, const wxString& name );
45 virtual bool SaveFile( wxImage *image, const wxString& name );
46
47 inline void SetName(const wxString& name) { m_name = name; }
48 inline void SetExtension(const wxString& ext) { m_extension = ext; }
49 inline void SetType(long type) { m_type = type; }
50 inline wxString GetName() const { return m_name; }
51 inline wxString GetExtension() const { return m_extension; }
52 inline long GetType() const { return m_type; }
53
54 protected:
55 wxString m_name;
56 wxString m_extension;
57 long m_type;
58
59 };
60
61 //-----------------------------------------------------------------------------
62 // wxPNGHandler
63 //-----------------------------------------------------------------------------
64
65 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
66 {
67 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
68
69 public:
70
71 inline wxPNGHandler()
72 {
73 m_name = "PNG file";
74 m_extension = "png";
75 m_type = wxBITMAP_TYPE_PNG;
76 };
77
78 virtual bool LoadFile( wxImage *image, const wxString& name );
79 virtual bool SaveFile( wxImage *image, const wxString& name );
80 };
81
82 //-----------------------------------------------------------------------------
83 // wxBMPHandler
84 //-----------------------------------------------------------------------------
85
86 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
87 {
88 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
89
90 public:
91
92 inline wxBMPHandler()
93 {
94 m_name = "BMP file";
95 m_extension = "bmp";
96 m_type = wxBITMAP_TYPE_BMP;
97 };
98
99 virtual bool LoadFile( wxImage *image, const wxString& name );
100 };
101
102 //-----------------------------------------------------------------------------
103 // wxImage
104 //-----------------------------------------------------------------------------
105
106 class WXDLLEXPORT wxImage: public wxObject
107 {
108 DECLARE_DYNAMIC_CLASS(wxImage)
109
110 friend class WXDLLEXPORT wxImageHandler;
111
112 public:
113
114 wxImage();
115 wxImage( int width, int height );
116 wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
117
118 wxImage( const wxImage& image );
119 wxImage( const wxImage* image );
120
121 // these functions get implemented in /src/(platform)/bitmap.cpp
122 wxImage( const wxBitmap &bitmap );
123 wxBitmap ConvertToBitmap() const;
124
125 void Create( int width, int height );
126 void Destroy();
127
128 wxImage Scale( int width, int height );
129
130 // these routines are slow but safe
131 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
132 unsigned char GetRed( int x, int y );
133 unsigned char GetGreen( int x, int y );
134 unsigned char GetBlue( int x, int y );
135
136 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
137 virtual bool SaveFile( const wxString& name, int type );
138
139 bool Ok() const;
140 int GetWidth() const;
141 int GetHeight() const;
142
143 char unsigned *GetData() const;
144 void SetData( char unsigned *data );
145
146 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
147 unsigned char GetMaskRed() const;
148 unsigned char GetMaskGreen() const;
149 unsigned char GetMaskBlue() const;
150 void SetMask( bool mask = TRUE );
151 bool HasMask() const;
152
153 inline wxImage& operator = (const wxImage& image)
154 { if (*this == image) return (*this); Ref(image); return *this; }
155 inline bool operator == (const wxImage& image)
156 { return m_refData == image.m_refData; }
157 inline bool operator != (const wxImage& image)
158 { return m_refData != image.m_refData; }
159
160 static inline wxList& GetHandlers() { return sm_handlers; }
161 static void AddHandler( wxImageHandler *handler );
162 static void InsertHandler( wxImageHandler *handler );
163 static bool RemoveHandler( const wxString& name );
164 static wxImageHandler *FindHandler( const wxString& name );
165 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
166 static wxImageHandler *FindHandler( long imageType );
167
168 static void CleanUpHandlers();
169 static void InitStandardHandlers();
170
171 protected:
172
173 static wxList sm_handlers;
174
175 };
176
177 #endif
178 // _WX_IMAGE_H_