103 m_img_nx = m_rDC.GetWidth ();
104 m_img_ny = m_rDC.GetHeight(); m_img_nPixels = m_img_nx * m_img_ny;
106 if( m_img_nx < 1 || m_img_ny < 1 )
114 if( m_rWorld.Get_XRange() == 0. || m_rWorld.Get_YRange() == 0. )
116 m_rWorld.Inflate(m_rWorld.Get_XRange() ? 0. : 1., m_rWorld.Get_YRange() ? 0. : 1.,
false);
120 double dxdyDC = (double)m_img_nx / (
double)m_img_ny;
121 double dxdyWorld = m_rWorld.Get_XRange() / m_rWorld.Get_YRange();
123 if( dxdyDC > dxdyWorld )
125 m_rWorld.Inflate(0.5 * (m_rWorld.Get_YRange() * dxdyDC - m_rWorld.Get_XRange()), 0.,
false);
127 else if( dxdyDC < dxdyWorld )
129 m_rWorld.Inflate(0., 0.5 * (m_rWorld.Get_XRange() / dxdyDC - m_rWorld.Get_YRange()),
false);
132 m_World2DC = m_img_nx / m_rWorld.Get_XRange();
133 m_DC2World = m_rWorld.Get_XRange() / m_img_nx;
136 m_bmp.Create(m_img_nx, m_img_ny);
137 m_dc.SelectObject(m_bmp);
138 m_dc.SetBackground(wxBrush(Background < 0 ? *wxWHITE : wxColour(
SG_GET_R(Background),
SG_GET_G(Background),
SG_GET_B(Background))));
141 if( (m_img_alpha = bAlpha ? (BYTE *)m_Alpha.Create(
sizeof(BYTE), m_img_nPixels) : NULL) != NULL )
143 memset(m_img_alpha, 0, m_img_nPixels);
152 m_img.Destroy(); m_img_rgb = NULL; m_img_alpha = NULL; m_img_nx = 0; m_img_nPixels = 0;
167 return(
SG_Get_Color(m_dc.GetBackground().GetColour()) );
173 wxBitmap Bitmap;
Get_Bitmap(Bitmap);
return( Bitmap );
187 Bitmap = wxBitmap(Image);
194 m_dc.SelectObject(wxNullBitmap);
198 m_dc.SelectObject(m_bmp);
212 m_dc.SelectObject(wxNullBitmap);
214 Image = m_bmp.ConvertToImage();
218 if( Image.HasAlpha() ==
false )
223 #pragma omp parallel for
224 for(
int y=0; y<m_img_ny; y++)
226 for(
int x=0, i=y*m_img_nx; x<m_img_nx; x++, i++)
228 Image.SetAlpha(x, y, m_img_alpha[i]);
233 m_dc.SelectObject(m_bmp);
248 #pragma omp parallel for
249 for(
int y=0; y<Map.
Get_NY(); y++)
253 BYTE rgb[4] = { Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy), Image.GetAlpha(x, yy) };
273 m_bmp_layer.Create(m_img_nx, m_img_ny);
274 m_dc .SelectObject(m_bmp_layer);
275 m_dc .SetBackground (*wxWHITE_BRUSH);
278 m_bmp_alpha.Create(m_img_nx, m_img_ny);
279 m_dc_alpha .SelectObject(m_bmp_alpha);
280 m_dc_alpha .SetBrush (*wxWHITE_BRUSH);
281 m_dc_alpha .SetPen (*wxWHITE_PEN);
282 m_dc_alpha .SetTextForeground(*wxWHITE);
283 m_dc_alpha .SetBackground (*wxBLACK_BRUSH);
292 m_dc.SelectObject(m_bmp); m_dc_alpha.SelectObject(wxNullBitmap);
296 wxImage img_layer = m_bmp_layer.ConvertToImage(); BYTE *rgb = img_layer.GetData();
297 wxImage img_alpha = m_bmp_alpha.ConvertToImage(); BYTE *alpha = img_alpha.GetData();
299 #pragma omp parallel for
300 for(
int i=0; i<m_img_nPixels; i++)
304 _Draw_Image_Pixel(i, *((
int *)(rgb + i * 3)));
350 for(
int iPart=0, jPoint=0; iPart<pPolygon->
Get_Part_Count(); iPart++)
354 for(
int iPoint=0; iPoint<pPolygon->
Get_Point_Count(iPart); iPoint++, jPoint++)
376 if( m_DC2World <= 0. || m_img_nx < 1 || m_img_ny < 1 )
381 m_Opacity = Transparency < 0. ? 1. : Transparency > 1. ? 0. : 1. - Transparency;
396 wxMemoryDC copy_dc; wxBitmap copy_bmp(m_img_nx, m_img_ny);
398 copy_dc.SelectObject(copy_bmp);
399 copy_dc.Blit(0, 0, m_img_nx, m_img_ny, &m_dc, 0, 0);
400 copy_dc.SelectObject(wxNullBitmap);
402 if( copy_bmp.IsOk() )
404 m_img = copy_bmp.ConvertToImage();
408 m_img_rgb = m_img.GetData();
422 m_dc.DrawBitmap(wxBitmap(m_img), 0, 0,
true);
424 m_img.Destroy(); m_img_rgb = NULL;
435 if( x1 > x2 ) {
double x = x1; x1 = x2; x2 = x; }
436 if( y1 > y2 ) {
double y = y1; y1 = y2; y2 = y; }
438 if( y1 < 0 ) { y1 = 0; }
439 if( y2 > m_img_ny ) { y2 = m_img_ny; }
441 if( x1 < 0 ) { x1 = 0; }
442 if( x2 > m_img_nx ) { x2 = m_img_nx; }
445 for(
int y=y1; y<y2; y++)
447 for(
int x=x1, i=y*m_img_nx+x1; x<x2; x++, i++)
449 _Draw_Image_Pixel(i, Color);
464 Font.SetPointSize((
int)(m_Scale * Font.GetPointSize()));
475 if( m_dc_alpha.IsOk() )
477 m_dc_alpha.SetFont(Font);
486 if( m_dc_alpha.IsOk() )
488 wxPen _Pen(Pen); _Pen.SetColour(*wxWHITE);
490 m_dc_alpha.SetPen(_Pen);
497 m_dc.SetBrush(Brush);
499 if( m_dc_alpha.IsOk() )
501 wxBrush _Brush(Brush); _Brush.SetColour(*wxWHITE);
503 m_dc_alpha.SetBrush(_Brush);
515 m_dc.DrawPoint(x, y);
517 if( m_dc_alpha.IsOk() )
519 m_dc_alpha.DrawPoint(x, y);
526 m_dc.DrawLine(x1, y1, x2, y2);
528 if( m_dc_alpha.IsOk() )
530 m_dc_alpha.DrawLine(x1, y1, x2, y2);
537 m_dc.DrawRectangle(x, y, width, height);
539 if( m_dc_alpha.IsOk() )
541 m_dc_alpha.DrawRectangle(x, y, width, height);
547 m_dc.DrawRectangle(r);
549 if( m_dc_alpha.IsOk() )
551 m_dc_alpha.DrawRectangle(r);
558 m_dc.DrawCircle(x, y, radius);
560 if( m_dc_alpha.IsOk() )
562 m_dc_alpha.DrawCircle(x, y, radius);
569 m_dc.DrawArc(xStart, yStart, xEnd, yEnd, xc, yc);
571 if( m_dc_alpha.IsOk() )
573 m_dc_alpha.DrawArc(xStart, yStart, xEnd, yEnd, xc, yc);
580 m_dc.DrawPolygon(n, points, xoffset, yoffset, fill_style);
582 if( m_dc_alpha.IsOk() )
584 m_dc_alpha.DrawPolygon(n, points, xoffset, yoffset, fill_style);
591 m_dc.DrawPolyPolygon(n, count, points, xoffset, yoffset, fill_style);
593 if( m_dc_alpha.IsOk() )
595 m_dc_alpha.DrawPolyPolygon(n, count, points, xoffset, yoffset, fill_style);
602 m_dc.DrawBitmap(bitmap, x, y, useAlpha);
604 if( m_dc_alpha.IsOk() )
606 m_dc_alpha.DrawBitmap(bitmap, x, y, useAlpha);
620 if( m_dc_alpha.IsOk() )
631 if( m_dc_alpha.IsOk() )
638void CSG_Map_DC::DrawText(
int Align,
int x,
int y,
const wxString &Text,
int Effect, wxColour Effect_Color,
int Effect_Size)
640 SG_DC_Draw_Text(m_dc, Align, x, y, Text, Effect, Effect_Color, Effect_Size);
642 if( m_dc_alpha.IsOk() )
644 SG_DC_Draw_Text(m_dc_alpha, Align, x, y, Text, Effect, Effect_Color, Effect_Size);
649void CSG_Map_DC::DrawText(
int Align,
int x,
int y,
double Angle,
const wxString &Text,
int Effect, wxColour Effect_Color,
int Effect_Size)
651 SG_DC_Draw_Text(m_dc, Align, x, y, Angle, Text, Effect, Effect_Color, Effect_Size);
653 if( m_dc_alpha.IsOk() )
655 SG_DC_Draw_Text(m_dc_alpha, Align, x, y, Angle, Text, Effect, Effect_Color, Effect_Size);
virtual void Set_Value(sLong i, BYTE Value, bool bScaled=true)
bool Create(const CSG_Grid &Grid)
bool Get_Image(wxImage &Image)
void SetBrush(const wxBrush &Brush)
void DrawPoint(int x, int y)
bool Draw_Layer_Begin(void)
bool Draw_Image_Begin(double Transparency, Mode Mode=Mode::Transparent)
void SetPen(const wxPen &Pen)
void DrawPolygon(int n, const wxPoint points[], int xoffset=0, int yoffset=0, wxPolygonFillMode fill_style=wxODDEVEN_RULE)
virtual ~CSG_Map_DC(void)
void DrawArc(int xStart, int yStart, int xEnd, int yEnd, int xc, int yc)
double yWorld2DC(double y, bool bRound=true)
void DrawCircle(int x, int y, int radius)
const CSG_Rect & rWorld(void) const
double xWorld2DC(double x, bool bRound=true)
void DrawBitmap(const wxBitmap &bitmap, int x, int y, bool useAlpha=false)
bool Create(const CSG_Rect &rWorld, const CSG_Rect_Int &rDC, double Scale=1., int Background=-1, bool bAlpha=false)
bool Draw_Layer_End(double Transparency=0.)
void DrawLine(int x1, int y1, int x2, int y2)
const wxRect & rDC(void) const
void Draw_Image_Pixels(int x1, int y1, int x2, int y2, int Color)
wxBitmap Get_Bitmap(void)
const double & Scale(void) const
void Draw_Polygon(CSG_Shape_Polygon *pPolygon)
bool Draw_Image_End(void)
int Get_Background(void) const
void SetFont(const wxFont &Font)
void DrawPolyPolygon(int n, const int count[], const wxPoint points[], int xoffset=0, int yoffset=0, wxPolygonFillMode fill_style=wxODDEVEN_RULE)
void DrawText(int Align, int x, int y, const wxString &Text)
void Set_Font(wxFont &Font)
void DrawRectangle(int x1, int y1, int width, int height)
double Get_YRange(void) const
double Get_YCenter(void) const
double Get_XRange(void) const
double Get_XCenter(void) const
virtual TSG_Point Get_Point(int iPoint=0) const
virtual int Get_Part_Count(void) const
virtual int Get_Point_Count(void) const
virtual const CSG_Rect & Get_Extent(void)
void SG_DC_Draw_Text(wxDC &dc, int Align, int x, int y, const wxString &Text)
int SG_Get_Color(const wxColour &Color)