wxArt2D
canimage.h
1 /*! \file wx/canvas/rectangle.h
2  \brief rectangular shapes derived from a2dCanvasObject
3 
4  rectangle shapes
5 
6  \author Klaas Holwerda
7 
8  Copyright: 2000-2004 (c) Klaas Holwerda
9 
10  Licence: wxWidgets Licence
11 
12  RCS-ID: $Id: canimage.h,v 1.3 2009/07/17 16:03:34 titato Exp $
13 */
14 
15 #ifndef __WXIMAGEPRIM_H__
16 #define __WXIMAGEPRIM_H__
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 #include "wx/image.h"
23 #include "wx/canvas/candefs.h"
24 #include "wx/canvas/canobj.h"
25 #include "wx/canvas/rectangle.h"
26 
27 //! a2dImage (will scale/rotate image when needed)
28 /*!
29  Holds a wxImage.
30 
31  \ingroup canvasobject
32 */
33 class A2DCANVASDLLEXP a2dImage: public a2dCanvasObject
34 {
35 public:
36 
37  //!constructor
38  a2dImage();
39 
40  //!Image position is middle point of image
41  /*!
42  \param image: reference to image
43  \param xc: x center
44  \param yc: y center
45  \param w: Width of object.
46  \param h: Heigth of object.
47  */
48  a2dImage( const wxImage& image, double xc, double yc, double w, double h );
49 
50  //!Image position is middle point of image
51  /*!
52  \param imagefile filename of image
53  \param type type of file
54  \param xc x center
55  \param yc y center
56  \param w Width of object.
57  \param h Heigth of object.
58  */
59  a2dImage( const wxString& imagefile, wxBitmapType type, double xc, double yc, double w, double h );
60 
61  //! construct the object by rendering the given object into the image of this object
62  /*!
63  \param torender object to render into image
64  \param xc: x center
65  \param yc: y center
66  \param w: Width of this object.
67  \param h: Heigth of this object.
68  \param imagew: Width in pixels to initiate image.
69  \param imageh: Heigth in pixels to initiate image.
70 
71  \remark the (imagew, imageh) is used by the rendering engine and defines the resolution
72 
73  \remark for the layers in the object the a2dCanvasDocument of torender is used,
74  if not set, a temporary document is created, using the default layer set.
75  */
76  a2dImage( a2dCanvasObject* torender, double xc, double yc, double w, double h, int imagew = 100, int imageh = 100 );
77 
78  a2dImage( const a2dImage& ori, CloneOptions options, a2dRefMap* refs );
79 
80  ~a2dImage();
81 
82  //! How transparent is this image
83  /*!
84  \param OpacityFactor opacity is set 0 total transparent 255 non transparent
85  */
86  void SetOpacityFactor( wxUint8 OpacityFactor );
87 
88  //! see SetOpacityFactor()
89  wxUint8 GetOpacityFactor() { return m_OpacityFactor; }
90 
91  //! return a list of a2dRect, for each pixel which has a colour in the box formed by col1 and col2
92  /*!
93  Can be used to vectorize an image.
94  */
95  a2dCanvasObjectList* GetAsRectangles( const wxColour& col1, const wxColour& col2, bool transform );
96 
97  //! render the given object into the image of this object
98  /*!
99  \param torender object to render into image
100  \param imagew: Width in pixels to initiate image.
101  \param imageh: Heigth in pixels to initiate image.
102 
103  \remark the (imagew, imageh) is used by the rendering engine and defines the resolution
104 
105  \remark for the layers in the object the a2dCanvasDocument of torender is used,
106  if not set, a temporary document is created, using the default layer set.
107  */
108  void RenderObject( a2dCanvasObject* torender, int imagew = 100 , int imageh = 100 );
109 
110  //!get width of image
111  double GetWidth() const { return m_width; }
112 
113  //!get height of image
114  double GetHeight() const { return m_height; }
115 
116  //!set width
117  /*! \param width width of image */
118  void SetWidth( double width ) { m_width = width; SetPending( true ); }
119 
120  //!set height
121  /*!! \param height height of image */
122  void SetHeight( double height ) { m_height = height; SetPending( true ); }
123 
124  //! get internal wxImage object
125  wxImage& GetImage() { return m_image; }
126 
127  //! set image
128  void SetImage( const wxImage& image ) { m_image = image; SetPending( true ); }
129 
130  //! get filename
131  wxString& GetFilename() { return m_filename; }
132 
133  //! set filename and type of image for saving.
134  /*!
135  \param filename filename of image
136  \param type the type of the image
137  \param doread when true the image is now read from the file.
138  */
139  void SetFilename( const wxString filename, wxBitmapType type, bool doread = true );
140 
141  //! set type of image for saving
142  void SetImageType( wxBitmapType type ) { m_type = type; }
143 
144  //! return type of image as was read from the file, or just set.
145  wxBitmapType GetImageType() { return m_type; }
146 
147  //! Sets if the pattern (a rectangle) will be drawn on top of this image
148  /*!
149  If set to <code>true</code> the pattern (a rect) will be drawn on top
150  of the image, else the pattern will be drawn behind the image.
151 
152  \remark By default the rectangle / pattern will be drawn behind the image
153 
154  \param drawPatternOnTop Set <code>true</code> to draw on top of the image, else <code>false</code>
155  */
156  void SetDrawPatternOnTop( bool drawPatternOnTop );
157 
158  //! Returns if the pattern will be drawn on top of the image
159  /*!
160  \see SetDrawPatternOnTop
161 
162  \return <code>true</code> if pattern will be drawn on top of this image, else <code>false</code> (default)
163  */
164  bool GetDrawPatternOnTop() { return m_drawPatternOnTop; }
165 
166  DECLARE_DYNAMIC_CLASS( a2dImage )
167 
168 protected:
169 
170  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
171 
172  //! only disables skew and rotation editing
173  virtual bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
174 
175 #if wxART2D_USE_CVGIO
176  virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
177 
178  void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
179 #endif //wxART2D_USE_CVGIO
180 
181  void DoRender( a2dIterC& ic, OVERLAP clipparent );
182  bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
183  a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
184 
185  double m_width;
186  double m_height;
187 
188  wxImage m_image;
189 
190  wxString m_filename;
191 
192  wxBitmapType m_type;
193 
194  bool m_drawPatternOnTop;
195 
196  wxUint8 m_OpacityFactor;
197 
198 public:
199  static a2dPropertyIdDouble* PROPID_Width;
200  static a2dPropertyIdDouble* PROPID_Height;
201 
203 
204 private:
205  //!this is a not implemented copy constructor that avoids automatic creation of one
206  a2dImage( const a2dImage& other );
207 };
208 
209 //! a2dRgbaImage
210 /*!
211  Rectangle with radius and Min and Max coordinates.
212  This rectangle has extra information such that its origin is not always the position of the matrix.
213  It can be placed relative to its matrix in any way.
214  The need for this type of rectangle, becomes clear when one needs to resize a rectangular shape around
215  its children objects.
216 
217 
218  \ingroup canvasobject
219 */
220 class A2DCANVASDLLEXP a2dRgbaImage: public a2dRectMM
221 {
222 
223  DECLARE_EVENT_TABLE()
224 
225 public:
226 
227  a2dRgbaImage();
228 
229  //!constructor
230  /*!
231  \param x: x minimum
232  \param y: y minimum
233  \param image width and hight taken from here
234  \param alpha alhpa of image set to this
235  */
236  a2dRgbaImage( double x, double y, wxImage& image, wxUint8 OpacityFactor );
237 
238  a2dRgbaImage( const a2dRgbaImage& image, CloneOptions options, a2dRefMap* refs );
239 
240  ~a2dRgbaImage();
241 
242  //! How transparent is this image
243  /*!
244  \param OpacityFactor opacity is set 0 total transparent 255 non transparent
245  */
246  void SetOpacityFactor( wxUint8 OpacityFactor );
247 
248  //! see SetOpacityFactor()
249  wxUint8 GetOpacityFactor() { return m_OpacityFactor; }
250 
251  //!set width of rectangle
252  /*!
253  \param w width of rectangle
254  */
255  void SetWidth( double w ) { m_maxx = m_minx + w; SetPending( true ); }
256 
257  //!set height of rectangle
258  /*!
259  \param h height of rectangle
260  */
261  void SetHeight( double h ) { m_maxy = m_miny + h; SetPending( true ); }
262 
263  a2dImageRGBA& GetImage() { return m_glimage; }
264 
265 #if wxART2D_USE_CVGIO
266  virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
267 
268  void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
269 #endif //wxART2D_USE_CVGIO
270 
271  DECLARE_DYNAMIC_CLASS( a2dRgbaImage )
272 
273 protected:
274 
275  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
276  void DoRender( a2dIterC& ic, OVERLAP clipparent );
277 
278  a2dImageRGBA m_glimage;
279 
280  bool m_flip;
281 
282  bool m_drawPatternOnTop;
283 
284  wxUint8 m_OpacityFactor;
285 
286 private:
287  //!this is a not implemented copy constructor that avoids automatic creation of one
288  a2dRgbaImage( const a2dRgbaImage& other );
289 };
290 
291 //! a2dImageMM (will scale/rotate image when needed)
292 /*!
293  Holds a wxImage.
294 
295  \ingroup canvasobject
296 */
297 class A2DCANVASDLLEXP a2dImageMM: public a2dRectMM
298 {
299 public:
300 
301  //!constructor
302  a2dImageMM();
303 
304  //!Image position is middle point of image
305  /*!
306  \param image: reference to image
307  \param xc: x center
308  \param yc: y center
309  \param w: Width of object.
310  \param h: Heigth of object.
311  */
312  a2dImageMM( const wxImage& image, double xc, double yc, double w, double h );
313 
314  //!Image position is middle point of image
315  /*!
316  \param imagefile filename of image
317  \param type type of file
318  \param xc x center
319  \param yc y center
320  \param w Width of object.
321  \param h Heigth of object.
322  */
323  a2dImageMM( const wxString& imagefile, wxBitmapType type, double xc, double yc, double w, double h );
324 
325  //!constructor
326  /*!
327  \param x: x minimum
328  \param y: y minimum
329  \param image width and hight taken from here
330  \param alpha alhpa of image set to this
331  */
332  a2dImageMM( double x, double y, wxImage& image, unsigned char alpha );
333 
334  //! construct the object by rendering the given object into the image of this object
335  /*!
336  \param torender object to render into image
337  \param xc: x center
338  \param yc: y center
339  \param w: Width of this object.
340  \param h: Heigth of this object.
341  \param imagew: Width in pixels to initiate image.
342  \param imageh: Heigth in pixels to initiate image.
343 
344  \remark the (imagew, imageh) is used by the rendering engine and defines the resolution
345 
346  \remark for the layers in the object the a2dCanvasDocument of torender is used,
347  if not set, a temporary document is created, using the default layer set.
348  */
349  a2dImageMM( a2dCanvasObject* torender, double xc, double yc, double w, double h, int imagew = 100, int imageh = 100 );
350 
351  a2dImageMM( const a2dImageMM& ori, CloneOptions options, a2dRefMap* refs );
352 
353  ~a2dImageMM();
354 
355  //! return a list of a2dRect, for each pixel which has a colour in the box formed by col1 and col2
356  /*!
357  Can be used to vectorize an image.
358  */
359  a2dCanvasObjectList* GetAsRectangles( const wxColour& col1, const wxColour& col2, bool transform );
360 
361  //! render the given object into the image of this object
362  /*!
363  \param torender object to render into image
364  \param imagew: Width in pixels to initiate image.
365  \param imageh: Heigth in pixels to initiate image.
366 
367  \remark the (imagew, imageh) is used by the rendering engine and defines the resolution
368 
369  \remark for the layers in the object the a2dCanvasDocument of torender is used,
370  if not set, a temporary document is created, using the default layer set.
371  */
372  void RenderObject( a2dCanvasObject* torender, int imagew = 100 , int imageh = 100 );
373 
374  //! get internal wxImage object
375  wxImage& GetImage() { return m_image; }
376 
377  //! set image
378  void SetImage( const wxImage& image ) { m_image = image; SetPending( true ); }
379 
380  //! get filename
381  wxString& GetFilename() { return m_filename; }
382 
383  //! set filename and type of image for saving.
384  /*!
385  \param filename filename of image
386  \param type the type of the image
387  \param doread when true the image is now read from the file.
388  */
389  void SetFilename( const wxString filename, wxBitmapType type, bool doread = true );
390 
391  //! set type of image for saving
392  void SetImageType( wxBitmapType type ) { m_type = type; }
393 
394  //! return type of image as was read from the file, or just set.
395  wxBitmapType GetImageType() { return m_type; }
396 
397  //! Sets if the pattern (a rectangle) will be drawn on top of this image
398  /*!
399  If set to <code>true</code> the pattern (a rect) will be drawn on top
400  of the image, else the pattern will be drawn behind the image.
401 
402  \remark By default the rectangle / pattern will be drawn behind the image
403 
404  \param drawPatternOnTop Set <code>true</code> to draw on top of the image, else <code>false</code>
405  */
406  void SetDrawPatternOnTop( bool drawPatternOnTop );
407 
408  //! Returns if the pattern will be drawn on top of the image
409  /*!
410  \see SetDrawPatternOnTop
411 
412  \return <code>true</code> if pattern will be drawn on top of this image, else <code>false</code> (default)
413  */
414  bool GetDrawPatternOnTop() { return m_drawPatternOnTop; }
415 
416  DECLARE_DYNAMIC_CLASS( a2dImageMM )
417 
418 protected:
419 
420  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
421  //! only disables skew and rotation editing
422  virtual bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
423 
424 #if wxART2D_USE_CVGIO
425  virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
426 
427  void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
428 #endif //wxART2D_USE_CVGIO
429 
430  void DoRender( a2dIterC& ic, OVERLAP clipparent );
431  bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
432 
433  wxImage m_image;
434 
435  wxString m_filename;
436 
437  wxBitmapType m_type;
438 
439  bool m_drawPatternOnTop;
440 
441 private:
442  //!this is a not implemented copy constructor that avoids automatic creation of one
443  a2dImageMM( const a2dImageMM& other );
444 };
445 
446 #endif /* __WXIMAGEPRIM_H__ */
double GetWidth() const
get width of image
Definition: canimage.h:111
virtual bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: canobj.cpp:3713
wxImage & GetImage()
get internal wxImage object
Definition: canimage.h:375
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
wxUint8 GetOpacityFactor()
see SetOpacityFactor()
Definition: canimage.h:89
Ref Counted base object.
Definition: gen.h:1045
void SetImage(const wxImage &image)
set image
Definition: canimage.h:128
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
virtual void SetPending(bool pending)
set this object pending for update
Definition: canobj.cpp:2585
OVERLAP
Result of a a2dBoundingBox intersection or hittest.
Definition: bbox.h:24
The base class for all drawable objects in a a2dCanvasDocument.
#define DECLARE_PROPERTIES()
check if class has the given id as a valid id for this object
Definition: gen.h:835
virtual void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
Definition: canobj.cpp:5728
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
wxImage & GetImage()
get internal wxImage object
Definition: canimage.h:125
defenitions an no more
virtual void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
Definition: canobj.cpp:4695
void SetImageType(wxBitmapType type)
set type of image for saving
Definition: canimage.h:392
bool GetDrawPatternOnTop()
Returns if the pattern will be drawn on top of the image.
Definition: canimage.h:164
a2dImageMM (will scale/rotate image when needed)
Definition: canimage.h:297
wxBitmapType GetImageType()
return type of image as was read from the file, or just set.
Definition: canimage.h:145
rectangular shapes derived from a2dCanvasObject
a2dRgbaImage
Definition: canimage.h:220
a2dImage (will scale/rotate image when needed)
Definition: canimage.h:33
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Definition: canobj.cpp:5569
void SetWidth(double w)
set width of rectangle
Definition: canimage.h:255
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
wxBitmapType GetImageType()
return type of image as was read from the file, or just set.
Definition: canimage.h:395
void SetWidth(double width)
set width
Definition: canimage.h:118
wxString & GetFilename()
get filename
Definition: canimage.h:131
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
void SetImage(const wxImage &image)
set image
Definition: canimage.h:378
double GetHeight() const
get height of image
Definition: canimage.h:114
void SetHeight(double height)
set height
Definition: canimage.h:122
a2dRectMM
Definition: rectangle.h:39
wxUint8 GetOpacityFactor()
see SetOpacityFactor()
Definition: canimage.h:249
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
void SetHeight(double h)
set height of rectangle
Definition: canimage.h:261
virtual a2dBoundingBox DoGetUnTransformedBbox(a2dBboxFlags flags=a2dCANOBJ_BBOX_NON) const
In derived object this should be overriden to calculate the boundingbox of the object without its chi...
Definition: canobj.cpp:5031
This template class is for property ids with a known data type.
Definition: id.h:477
bool GetDrawPatternOnTop()
Returns if the pattern will be drawn on top of the image.
Definition: canimage.h:414
wxString & GetFilename()
get filename
Definition: canimage.h:381
list of a2dObject&#39;s
Definition: gen.h:3157
void SetImageType(wxBitmapType type)
set type of image for saving
Definition: canimage.h:142
CloneOptions
options for cloning
Definition: gen.h:1200
structure to give as parameter to member functions of a2dCanvasObject
Definition: canobj.h:252
wxEditStyle
Definition: canobj.h:109
canimage.h Source File -- Sun Oct 12 2014 17:04:13 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation