27 #include "wx/canvas/canimage.h"
51 m_OpacityFactor = 255;
53 m_image = wxImage( 10, 10 );
55 m_filename = wxT(
"" );
57 m_type = wxBITMAP_TYPE_PNG;
59 m_drawPatternOnTop =
false;
71 h = image.GetHeight();
75 m_OpacityFactor = 255;
79 m_filename = wxT(
"" );
81 m_type = wxBITMAP_TYPE_PNG;
83 m_drawPatternOnTop =
false;
86 a2dImage::a2dImage(
const wxString& imagefile, wxBitmapType type,
double xc,
double yc,
double w,
double h )
92 if ( !wxFileExists( imagefile ) )
95 m_image = wxImage( 100, 100 );
99 bitmap.LoadFile( imagefile, type );
100 m_image = bitmap.ConvertToImage();
104 w = m_image.GetWidth();
107 h = m_image.GetHeight();
109 m_filename = imagefile;
115 m_OpacityFactor = 255;
117 m_drawPatternOnTop =
false;
127 m_OpacityFactor = 255;
131 m_filename = wxT(
"" );
133 m_type = wxBITMAP_TYPE_PNG;
135 m_drawPatternOnTop =
false;
141 m_width = other.m_width;
142 m_height = other.m_height;
143 m_OpacityFactor = other.m_OpacityFactor;
144 m_image = other.m_image;
145 m_filename = other.m_filename;
146 m_type = other.m_type;
147 m_drawPatternOnTop = other.m_drawPatternOnTop;
150 a2dImage::~a2dImage()
162 unsigned char* source_data = m_image.GetData();
163 long w = m_image.GetWidth();
164 long h = m_image.GetHeight();
166 double rectw = m_width / m_image.GetWidth();
167 double recth = m_height / m_image.GetHeight();
169 for (
long y = 0; y < h; y++ )
173 for (
long x = 0; x < w; x++ )
175 unsigned char* pixel = source_data + ( y * w ) * 3 + x * 3;
176 unsigned char red = pixel[0] ;
177 unsigned char green = pixel[1] ;
178 unsigned char blue = pixel[2] ;
179 unsigned char alpha = 255 ;
181 if ( red >= col1.Red() && red <= col2.Red() &&
182 green >= col1.Green() && green <= col2.Green() &&
183 blue >= col1.Blue() && blue <= col2.Blue()
190 else if ( rowlenght )
192 a2dRect* pixRect =
new a2dRect( -m_width / 2.0 + startrow * rectw, m_height / 2.0 - y * recth, rectw * rowlenght, -recth );
197 canpathlist->push_back( pixRect );
204 a2dRect* pixRect =
new a2dRect( -m_width / 2.0 + startrow * rectw, m_height / 2.0 - y * recth, rectw * rowlenght, -recth );
209 canpathlist->push_back( pixRect );
251 m_filename = filename;
258 if ( !wxFileExists( m_filename ) )
260 wxCHECK_RET( m_image.LoadFile( m_filename, type ), wxT(
"invalid image file" ) );
269 if ( m_drawPatternOnTop != drawPatternOnTop )
271 m_drawPatternOnTop = drawPatternOnTop;
293 return new a2dImage( *
this, options, refs );
300 bbox.
Expand( -m_width / 2, -m_height / 2 );
301 bbox.
Expand( m_width / 2, m_height / 2 );
308 if ( !m_drawPatternOnTop )
326 if ( m_drawPatternOnTop )
347 #if wxART2D_USE_CVGIO
351 if ( xmlparts == a2dXmlSer_attrib )
360 if ( !m_filename.IsEmpty() )
362 wxString fullfilepath = parser.GetFileName().GetPathWithSep() + m_filename;
363 if ( !::wxFileExists( fullfilepath ) )
366 if ( !::wxFileExists( fullfilepath ) )
372 m_image.LoadFile( fullfilepath, m_type );
376 m_image = wxImage( (
int ) m_width, (
int ) m_height );
387 if ( xmlparts == a2dXmlSer_attrib )
389 if ( m_filename.IsEmpty() )
391 m_image.SaveFile(
GetName(), m_type );
392 out.WriteAttribute( wxT(
"filename" ),
GetName() );
397 if ( filename.IsEmpty() )
399 wxString fullfilepath = out.GetFileName().GetPathWithSep() + m_filename;
400 m_image.SaveFile( fullfilepath, m_type );
403 out.WriteAttribute( wxT(
"filename" ), m_filename );
405 out.WriteAttribute( wxT(
"width" ), m_width );
406 out.WriteAttribute( wxT(
"height" ), m_height );
407 out.WriteAttribute( wxT(
"type" ), ( wxInt32 ) m_type );
408 out.WriteAttribute( wxT(
"patternontop" ), m_drawPatternOnTop );
409 out.WriteAttribute( wxT(
"opacityfactor" ), ( wxUint8 ) m_OpacityFactor );
415 #endif //wxART2D_USE_CVGIO
429 a2dRgbaImage::a2dRgbaImage(
double x,
double y, wxImage& image, wxUint8 OpacityFactor )
430 :
a2dRectMM( x, y, image.GetWidth(), image.GetHeight() )
433 m_OpacityFactor = OpacityFactor;
434 m_drawPatternOnTop =
false;
437 a2dRgbaImage::~a2dRgbaImage()
444 m_glimage = other.m_glimage;
445 m_OpacityFactor = other.m_OpacityFactor;
446 m_flip = other.m_flip;
447 m_drawPatternOnTop = other.m_drawPatternOnTop;
458 if ( !m_drawPatternOnTop )
475 if ( m_drawPatternOnTop )
490 #if wxART2D_USE_CVGIO
495 if ( xmlparts == a2dXmlSer_attrib )
506 if ( xmlparts == a2dXmlSer_attrib )
513 #endif //wxART2D_USE_CVGIO
525 m_image = wxImage( 10, 10 );
527 m_filename = wxT(
"" );
529 m_type = wxBITMAP_TYPE_PNG;
531 m_drawPatternOnTop =
false;
535 :
a2dRectMM( x, y, image.GetWidth(), image.GetHeight() )
539 m_filename = wxT(
"" );
541 m_type = wxBITMAP_TYPE_PNG;
543 m_drawPatternOnTop =
false;
551 m_filename = wxT(
"" );
553 m_type = wxBITMAP_TYPE_PNG;
555 m_drawPatternOnTop =
false;
564 if ( !wxFileExists( imagefile ) )
567 m_image = wxImage( 100, 100 );
571 bitmap.LoadFile( imagefile, type );
572 m_image = bitmap.ConvertToImage();
575 m_filename = imagefile;
577 m_drawPatternOnTop =
false;
585 m_filename = wxT(
"" );
587 m_type = wxBITMAP_TYPE_PNG;
589 m_drawPatternOnTop =
false;
595 m_image = other.m_image;
596 m_filename = other.m_filename;
597 m_type = other.m_type;
598 m_drawPatternOnTop = other.m_drawPatternOnTop;
601 a2dImageMM::~a2dImageMM()
613 unsigned char* source_data = m_image.GetData();
614 long w = m_image.GetWidth();
615 long h = m_image.GetHeight();
617 double rectw =
GetWidth() / m_image.GetWidth();
618 double recth =
GetHeight() / m_image.GetHeight();
620 for (
long y = 0; y < h; y++ )
624 for (
long x = 0; x < w; x++ )
626 unsigned char* pixel = source_data + ( y * w ) * 3 + x * 3;
627 unsigned char red = pixel[0] ;
628 unsigned char green = pixel[1] ;
629 unsigned char blue = pixel[2] ;
630 unsigned char alpha = 255 ;
632 if ( red >= col1.Red() && red <= col2.Red() &&
633 green >= col1.Green() && green <= col2.Green() &&
634 blue >= col1.Blue() && blue <= col2.Blue()
641 else if ( rowlenght )
648 canpathlist->push_back( pixRect );
660 canpathlist->push_back( pixRect );
702 m_filename = filename;
709 if ( !wxFileExists( m_filename ) )
711 wxCHECK_RET( m_image.LoadFile( m_filename, type ), wxT(
"invalid image file" ) );
720 if ( m_drawPatternOnTop != drawPatternOnTop )
722 m_drawPatternOnTop = drawPatternOnTop;
744 return new a2dImageMM( *
this, options, refs );
751 if ( !m_drawPatternOnTop )
772 if ( m_drawPatternOnTop )
793 #if wxART2D_USE_CVGIO
797 if ( xmlparts == a2dXmlSer_attrib )
803 if ( !m_filename.IsEmpty() )
806 if ( !::wxFileExists( fname ) )
811 m_image.LoadFile( fname, m_type );
826 if ( xmlparts == a2dXmlSer_attrib )
828 if ( m_filename.IsEmpty() )
830 m_image.SaveFile(
GetName(), m_type );
831 out.WriteAttribute( wxT(
"filename" ),
GetName() );
835 out.WriteAttribute( wxT(
"filename" ), m_filename );
837 out.WriteAttribute( wxT(
"type" ), ( wxInt32 ) m_type );
838 out.WriteAttribute( wxT(
"patternontop" ), m_drawPatternOnTop );
844 #endif //wxART2D_USE_CVGIO
a2dHit m_how
return in which way the object was hit (stroke, fill, ...)
bool GetAttributeValueBool(const wxString &attrib, bool defaultv=false)
Returns the boolean value of an attribute.
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
void RenderObject(a2dCanvasObject *torender, int imagew=100, int imageh=100)
render the given object into the image of this object
void SetRoot(a2dDrawing *root, bool recurse=true)
Sets this object to a a2dCanvasDocument.
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
virtual wxString GetName() const
Returns the name of this object, if no name is given the internal id will be returned.
wxString FindValidPath(const wxString &filename, bool reportError=true)
Find the first full path for which the file exists.
class to map references to objects stored in XML, in order to make the connection later on...
a2dDrawing * m_root
root group for rendering and accessing the canvas's also contains layer settings
a2dCanvasOFlags m_flags
holds flags for objects
double m_maxx
maximum x of rectangle
const a2dError a2dError_FileCouldNotOpen
Input and output handler for the XmlSer format.
virtual void SetPending(bool pending)
set this object pending for update
OVERLAP
Result of a a2dBoundingBox intersection or hittest.
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
a2dGlobal * a2dGlobals
global a2dCanvasGlobal to have easy access to global settings
bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
The base class for all drawable objects in a a2dCanvasDocument.
void SetFilename(const wxString filename, wxBitmapType type, bool doread=true)
set filename and type of image for saving.
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
wxUint16 m_layer
layer of object, default wxLAYER_DEFAULT
virtual void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
virtual bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only disables skew and rotation editing
a2dCanvasObject is the base class for Canvas Objects.
virtual bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only used for editable objects and under control of a editing tool.
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
a2dCanvas uses a2dCanvasView for displaying a view on a a2dCanvasDocument.
virtual void DrawCenterRoundedRectangle(double xc, double yc, double width, double height, double radius, bool pixelsize=false)
Draw CenterRoundedRectangle in world coordinates.
void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
double m_minx
minimum x of rectangle
bool m_selected
object is selected
a2dDrawStyle GetDrawStyle() const
get drawstyle used for drawing.
vector path a2dVectorPath derived from a2dCanvasObject
a2dAffineMatrix m_lworld
used for positioning the object (x,y,ang,scale etc.)
a2dImageMM (will scale/rotate image when needed)
long GetAttributeValueLong(const wxString &attrib, long defaultv=0)
Returns the long value of an attribute.
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
void Expand(const a2dPoint2D &, const a2dPoint2D &)
expand boundingbox width two points
void SetFilename(const wxString filename, wxBitmapType type, bool doread=true)
set filename and type of image for saving.
double GetHeight() const
return height
virtual void DrawRoundedRectangle(double x, double y, double width, double height, double radius, bool pixelsize=false)
Draw RoundedRectangle in world coordinates.
void Transform(const a2dAffineMatrix &tworld)
transform the object using the given matrix
void SetPropertyToObject(a2dObject *obj, const basetype &value, SetFlags setflags=set_none) const
Set the property in obj to value.
void SetDrawPatternOnTop(bool drawPatternOnTop)
Sets if the pattern (a rectangle) will be drawn on top of this image.
bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
rectangular shapes derived from a2dCanvasObject
a2dDrawer2D * GetDrawer2D() const
get current a2dDrawer2D
bool m_editable
object can be edited
a2dImage (will scale/rotate image when needed)
a2dCanvasObjectList * GetAsRectangles(const wxColour &col1, const wxColour &col2, bool transform)
return a list of a2dRect, for each pixel which has a colour in the box formed by col1 and col2 ...
virtual void DrawImage(const wxImage &image, double x, double y, double width, double height, wxUint8 Opacity=255)=0
Draw wxImage in world coordinates.
A2DGENERALDLLEXP a2dSmrtPtr< a2dGeneralGlobal > a2dGeneralGlobals
a global pointer to get to global instance of important classes.
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Input and output handler for the XmlSer format.
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
a2dPathList & GetImagePathList()
Path for Images.
void RenderObject(a2dCanvasObject *torender, int imagew=100, int imageh=100)
render the given object into the image of this object
virtual bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only used for editable objects and under control of a editing tool.
A 2x3 affine matrix class for 2D transformations.
double GetAttributeValueDouble(const wxString &attrib, double defaultv=0)
Returns the double value of an attribute.
double m_maxy
maximum y of rectangle
virtual double GetContourWidth() const
get the Contour width of the shape
while iterating a a2dCanvasDocument, this holds the context.
void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
void SetDrawPatternOnTop(bool drawPatternOnTop)
Sets if the pattern (a rectangle) will be drawn on top of this image.
wxString GetAttributeValue(const wxString &attrib, const wxString &defaultv=wxT(""))
Returns the value of an attribute.
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
a2dCanvasObjectList * GetAsRectangles(const wxColour &col1, const wxColour &col2, bool transform)
return a list of a2dRect, for each pixel which has a colour in the box formed by col1 and col2 ...
bool Translate(double x, double y)
Translate by dx, dy:
const a2dStroke * a2dTRANSPARENT_STROKE
global a2dStroke stock object for TRANSPARENT stroking
double m_miny
minimum of rectangle
virtual bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only disables skew and rotation editing
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
double GetWidth() const
return width
static a2dHit stock_fill
Stock object for a fill hit.
the a2dDrawingPart is a a2dView specially designed for displaying parts of a a2dDrawing. It uses a a2dDrawer2D to actually redraw things from the document, by giving that a2dDrawer2D as drawing context to the document, and telling the document to redraw a certain rectangular area. At that last is what this class is for. It optimizes the areas to be redrawn after object in the document were changed. To do that it combines redraw areas to a minimal set of redrawing areas. All the administration for this and the way things will be redrawn is from this view.
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
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...
This template class is for property ids with a known data type.
virtual void SetLayer(wxUint16 layer)
set layer index where this object is drawn upon.
void SetContourWidth(double width)
set the Contour width of the shape
double GetContourWidth() const
get the Contour width of the shape
CloneOptions
options for cloning
structure to give as parameter to member functions of a2dCanvasObject
#define A2D_PROPID_GSI(type, classname, propname, defaultval)
to define a get set property more easily
const a2dFill * a2dTRANSPARENT_FILL
global a2dFill stock object for TRANSPARENT filling
general canvas module declarations and classes