SAGA API Version 9.14
Loading...
Searching...
No Matches
map_dc.h
Go to the documentation of this file.
1
3// //
4// SAGA //
5// //
6// System for Automated Geoscientific Analyses //
7// //
8// Application Programming Interface //
9// //
10// Library: SAGA_API //
11// //
12//-------------------------------------------------------//
13// //
14// map_dc.h //
15// //
16// Copyright (C) 2024 by //
17// Olaf Conrad //
18// //
19//-------------------------------------------------------//
20// //
21// This file is part of 'SAGA - System for Automated //
22// Geoscientific Analyses'. SAGA is free software; you //
23// can redistribute it and/or modify it under the terms //
24// of the GNU General Public License as published by the //
25// Free Software Foundation, either version 2 of the //
26// License, or (at your option) any later version. //
27// //
28// SAGA is distributed in the hope that it will be //
29// useful, but WITHOUT ANY WARRANTY; without even the //
30// implied warranty of MERCHANTABILITY or FITNESS FOR A //
31// PARTICULAR PURPOSE. See the GNU General Public //
32// License for more details. //
33// //
34// You should have received a copy of the GNU General //
35// Public License along with this program; if not, see //
36// <http://www.gnu.org/licenses/>. //
37// //
38//-------------------------------------------------------//
39// //
40// contact: Olaf Conrad //
41// Institute of Geography //
42// University of Hamburg //
43// Germany //
44// //
45// e-mail: oconrad@saga-gis.org //
46// //
48
49//---------------------------------------------------------
50#ifndef _HEADER_INCLUDED__SAGA_API__map_dc_H
51#define _HEADER_INCLUDED__SAGA_API__map_dc_H
52
53
55// //
56// //
57// //
59
60//---------------------------------------------------------
61#include "../shapes.h"
62
63#include <wx/dcmemory.h>
64#include <wx/image.h>
65
66
68// //
69// //
70// //
72
73//---------------------------------------------------------
75{
76public:
77
78 CSG_Map_DC(void);
79 virtual ~CSG_Map_DC(void);
80
81 bool Destroy (void);
82
83 CSG_Map_DC (const CSG_Rect &rWorld, const CSG_Rect_Int &rDC, double Scale = 1., int Background = -1, bool bAlpha = false);
84 bool Create (const CSG_Rect &rWorld, const CSG_Rect_Int &rDC, double Scale = 1., int Background = -1, bool bAlpha = false);
85
86 CSG_Map_DC (const CSG_Rect &rWorld, const wxRect &rDC, double Scale = 1., int Background = -1, bool bAlpha = false);
87 bool Create (const CSG_Rect &rWorld, const wxRect &rDC, double Scale = 1., int Background = -1, bool bAlpha = false);
88
89 //-----------------------------------------------------
90 enum class Mode
91 {
93 };
94
95 //-----------------------------------------------------
96 wxMemoryDC & Get_DC (void) { return( m_dc ); }
97
98 int Get_Background (void) const;
99
100 bool has_Alpha (void) const { return( m_img_alpha != NULL ); }
101
102 void SetFont (const wxFont &Font );
103 void SetPen (const wxPen &Pen );
104 void SetBrush (const wxBrush &Brush);
105
106 void DrawPoint (int x, int y);
107 void DrawLine (int x1, int y1, int x2, int y2);
108 void DrawRectangle (int x1, int y1, int width, int height);
109 void DrawRectangle (const wxRect &r);
110 void DrawCircle (int x, int y, int radius);
111 void DrawArc (int xStart, int yStart, int xEnd, int yEnd, int xc, int yc);
112 void DrawPolygon (int n, const wxPoint points[], int xoffset = 0, int yoffset = 0, wxPolygonFillMode fill_style = wxODDEVEN_RULE);
113 void DrawPolyPolygon (int n, const int count[], const wxPoint points[], int xoffset = 0, int yoffset = 0, wxPolygonFillMode fill_style = wxODDEVEN_RULE);
114 void DrawBitmap (const wxBitmap &bitmap, int x, int y, bool useAlpha = false);
115
116 void DrawText (int Align, int x, int y , const wxString &Text);
117 void DrawText (int Align, int x, int y, double Angle, const wxString &Text);
118 void DrawText (int Align, int x, int y , const wxString &Text, int Effect, wxColour Effect_Color, int Effect_Size = 1);
119 void DrawText (int Align, int x, int y, double Angle, const wxString &Text, int Effect, wxColour Effect_Color, int Effect_Size = 1);
120
121 //-----------------------------------------------------
122 const double & Scale (void) const { return( m_Scale ); }
123
124 const CSG_Rect & rWorld (void) const { return( m_rWorld ); }
125
126 const int & DC_Width (void) const { return( m_rDC.width ); }
127 const int & DC_Height (void) const { return( m_rDC.height ); }
128
129 const wxRect & rDC (void) const { return( m_rDC ); }
130
131 const double & World2DC (void) const { return( m_World2DC ); }
132
134 {
135 TSG_Point_Int _p; _p.x = (int)xWorld2DC(p.x), _p.y = (int)yWorld2DC(p.y);
136
137 return( _p );
138 }
139
140 double xWorld2DC (double x, bool bRound = true)
141 {
142 x = (x - m_rWorld.Get_XMin()) * m_World2DC;
143
144 return( bRound ? (int)(x < 0. ? x - 0.5 : x + 0.5) : x );
145 }
146
147 double yWorld2DC (double y, bool bRound = true)
148 {
149 y = (m_rWorld.Get_YMax() - y) * m_World2DC - 1;
150
151 return( bRound ? (int)(y < 0. ? y - 0.5 : y + 0.5) : y );
152 }
153
154 const double & DC2World (void) const { return( m_DC2World ); }
155
156 double xDC2World (double x)
157 {
158 return( m_rWorld.Get_XMin() + m_DC2World * x );
159 }
160
161 double yDC2World (double y)
162 {
163 return( m_rWorld.Get_YMax() - m_DC2World * (y + 1) );
164 }
165
166 //-----------------------------------------------------
167 void Set_Font (wxFont &Font);
168
169 wxBitmap Get_Bitmap (void);
170 bool Get_Bitmap (wxBitmap &Bitmap);
171 bool Get_Image (wxImage &Image );
172
173 bool Get_Image (CSG_Grid &Image );
174
175 //-----------------------------------------------------
176 bool Draw_Layer_Begin (void);
177 bool Draw_Layer_End (double Transparency = 0.);
178
179 void Draw_Polygon (CSG_Shape_Polygon *pPolygon);
180
181 //-----------------------------------------------------
182 bool Draw_Image_Begin (double Transparency, Mode Mode = Mode::Transparent);
183 bool Draw_Image_End (void);
184
185 void Draw_Image_Pixels (int x1, int y1, int x2, int y2, int Color);
186 void Draw_Image_Pixel (int x, int y , int Color)
187 {
188 if( x >= 0 && x < m_img_nx )
189 {
190 _Draw_Image_Pixel(y * m_img_nx + x, Color);
191 }
192 }
193
194
195private:
196
197 BYTE *m_img_rgb { NULL }, *m_img_alpha { NULL };
198
199 int m_img_nx { 0 }, m_img_ny { 0 }, m_img_nPixels { 0 };
200
201 Mode m_img_mode { Mode::Opaque };
202
203 double m_World2DC { 1. }, m_DC2World { 1. }, m_Opacity { 1. }, m_Scale { 1. };
204
205 CSG_Array m_Alpha;
206
207 CSG_Rect m_rWorld;
208
209 wxRect m_rDC;
210
211 wxImage m_img;
212
213 wxBitmap m_bmp, m_bmp_alpha, m_bmp_layer;
214
215 wxMemoryDC m_dc, m_dc_alpha;
216
217
218 //-----------------------------------------------------
219 void _Draw_Image_Pixel (int i, int Color)
220 {
221 if( i >= 0 && i < m_img_nPixels )
222 {
223 BYTE r = SG_GET_R(Color), g = SG_GET_G(Color), b = SG_GET_B(Color), *rgb = m_img_rgb + 3 * i;
224
225 switch( m_img_mode )
226 {
227 case Mode::Opaque: default: {
228 if( m_img_alpha ) { m_img_alpha[i] = 0xFF; }
229 break; }
230
231 case Mode::Shade: {
232 r = (BYTE)(r * rgb[0] / 255.);
233 g = (BYTE)(g * rgb[1] / 255.);
234 b = (BYTE)(b * rgb[2] / 255.);
235
236 if( m_img_alpha ) { m_img_alpha[i] = 0xFF; }
237 break; }
238
239 case Mode::Transparent: {
240 if( m_Opacity <= 0. ) { return; }
241 if( m_Opacity < 1. )
242 {
243 r = (BYTE)(r * m_Opacity + (1. - m_Opacity) * rgb[0]);
244 g = (BYTE)(g * m_Opacity + (1. - m_Opacity) * rgb[1]);
245 b = (BYTE)(b * m_Opacity + (1. - m_Opacity) * rgb[2]);
246 }
247
248 if( m_img_alpha ) { m_img_alpha[i] = 0xFF; }
249 break; }
250
251 case Mode::Alpha: {
252 double Opacity = m_Opacity * SG_GET_A(Color) / 255.;
253
254 if( Opacity <= 0. ) { return; }
255 if( Opacity < 1. )
256 {
257 r = (BYTE)(r * Opacity + (1. - Opacity) * rgb[0]);
258 g = (BYTE)(g * Opacity + (1. - Opacity) * rgb[1]);
259 b = (BYTE)(b * Opacity + (1. - Opacity) * rgb[2]);
260 }
261
262 if( m_img_alpha && m_img_alpha[i] < 255 )
263 {
264 if( Opacity >= 1. )
265 {
266 m_img_alpha[i] = 255;
267 }
268 else if( m_img_alpha[i] == 0 )
269 {
270 m_img_alpha[i] = (BYTE)(Opacity * 255.);
271 }
272 else
273 {
274 m_img_alpha[i] = m_img_alpha[i] + (BYTE)(255 * (1. - m_img_alpha[i] / 255.) * Opacity);
275 }
276 }
277 break; }
278 }
279
280 rgb[0] = r;
281 rgb[1] = g;
282 rgb[2] = b;
283 }
284 }
285
286};
287
288
290// //
291// //
292// //
294
295//---------------------------------------------------------
296#endif // #ifndef _HEADER_INCLUDED__SAGA_API__map_dc_H
#define SG_GET_B(rgb)
Definition api_core.h:1350
#define SG_GET_G(rgb)
Definition api_core.h:1349
#define SG_GET_R(rgb)
Definition api_core.h:1348
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
#define SG_GET_A(rgb)
Definition api_core.h:1351
bool Destroy(void)
Definition map_dc.cpp:150
double yDC2World(double y)
Definition map_dc.h:161
CSG_Map_DC(void)
Definition map_dc.cpp:62
double yWorld2DC(double y, bool bRound=true)
Definition map_dc.h:147
double xDC2World(double x)
Definition map_dc.h:156
const CSG_Rect & rWorld(void) const
Definition map_dc.h:124
double xWorld2DC(double x, bool bRound=true)
Definition map_dc.h:140
const int & DC_Width(void) const
Definition map_dc.h:126
bool Create(const CSG_Rect &rWorld, const CSG_Rect_Int &rDC, double Scale=1., int Background=-1, bool bAlpha=false)
Definition map_dc.cpp:91
wxMemoryDC & Get_DC(void)
Definition map_dc.h:96
const wxRect & rDC(void) const
Definition map_dc.h:129
bool has_Alpha(void) const
Definition map_dc.h:100
void Draw_Image_Pixel(int x, int y, int Color)
Definition map_dc.h:186
TSG_Point_Int World2DC(const CSG_Point &p)
Definition map_dc.h:133
const double & Scale(void) const
Definition map_dc.h:122
const double & DC2World(void) const
Definition map_dc.h:154
const int & DC_Height(void) const
Definition map_dc.h:127
const double & World2DC(void) const
Definition map_dc.h:131
struct SSG_Point_Int TSG_Point_Int
double x
Definition geo_tools.h:129
double y
Definition geo_tools.h:129