SAGA API Version 9.14
Loading...
Searching...
No Matches
dc_helper.cpp
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// dc_helper.cpp //
15// //
16// Copyright (C) 2008 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// e-mail: oconrad@saga-gis.org //
41// //
42// contact: Olaf Conrad //
43// Institute of Geography //
44// University of Hamburg //
45// Germany //
46// //
48
49//---------------------------------------------------------
50#include <wx/wxprec.h>
51#include <wx/dc.h>
52
53//---------------------------------------------------------
54#include "dc_helper.h"
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
64int SG_Get_Color (const wxColour &Color)
65{
66 return( SG_GET_RGB(Color.Red(), Color.Green(), Color.Blue()) );
67}
68
69//---------------------------------------------------------
70wxColour SG_Get_wxColor (int Color)
71{
72 return( wxColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color)) );
73}
74
75
77// //
79
80//---------------------------------------------------------
81wxColour SG_System_Get_Color(wxSystemColour index)
82{
83 #ifdef _SAGA_LINUX
84 if( SG_UI_Get_Window_Main() == NULL )
85 {
86 switch( index )
87 {
88 case wxSYS_COLOUR_WINDOW : return( *wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE ) );
89 case wxSYS_COLOUR_WINDOWTEXT : return( *wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK ) );
90 case wxSYS_COLOUR_BTNHIGHLIGHT: return( *wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY ) );
91 case wxSYS_COLOUR_BTNSHADOW : return( *wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK ) );
92
93 default : return( *wxBLACK );
94 }
95 }
96 #endif
97
98 return( wxSystemSettings::GetColour(index) );
99}
100
101//---------------------------------------------------------
103{
104 switch( Mode )
105 {
106 default: return( SG_System_Get_Color(wxSYS_COLOUR_WINDOW) );
107 case 1: return( *wxWHITE ); // bright
108 case 2: return( *wxBLACK ); // dark
109 }
110}
111
112//---------------------------------------------------------
114{
115 switch( Mode )
116 {
117 default: return( SG_System_Get_Color(wxSYS_COLOUR_WINDOWTEXT) );
118 case 1: return( *wxBLACK ); // bright
119 case 2: return( *wxWHITE ); // dark
120 }
121}
122
123
125// //
127
128//---------------------------------------------------------
129bool SG_Set_Font(CSG_Parameter *pFont, wxFont &Font, wxColour &Colour)
130{
131 if( !pFont || pFont->Get_Type() != PARAMETER_TYPE_Font )
132 {
133 return( false );
134 }
135
136 long c = pFont->asColor(); Colour.Set(SG_GET_R(c), SG_GET_G(c), SG_GET_B(c));
137
138 #ifdef __WXMAC__
139 if( !Font.SetNativeFontInfoUserDesc(pFont->asFont()) )
140 #else
141 if( !Font.SetNativeFontInfo(pFont->asFont()) )
142 #endif
143 {
144 Font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
145 }
146
147 return( true );
148}
149
150//---------------------------------------------------------
151bool SG_Set_Font(const wxFont &Font, wxColour Colour, CSG_Parameter *pFont)
152{
153 if( !pFont || pFont->Get_Type() != PARAMETER_TYPE_Font )
154 {
155 return( false );
156 }
157
158 pFont->Set_Value((int)SG_GET_RGB(Colour.Red(), Colour.Green(), Colour.Blue()));
159 #ifdef __WXMAC__
160 pFont->Set_Value(Font.GetNativeFontInfoUserDesc().wc_str());
161 #else
162 pFont->Set_Value(Font.GetNativeFontInfoDesc().wc_str());
163 #endif
164
165 return( true );
166}
167
168//---------------------------------------------------------
170{
171 wxFont Font; wxColour Colour;
172
173 SG_Set_Font(pFont, Font, Colour);
174
175 return( Font );
176}
177
178
180// //
181// //
182// //
184
185//---------------------------------------------------------
186void SG_DC_Draw_Edge(wxDC &dc, int Edge_Style, int ax, int ay, int bx, int by)
187{
188 switch( Edge_Style )
189 {
190 //-----------------------------------------------------
192 {
193 if( dc.GetPen().IsOk() == false ) { dc.SetPen(*wxBLACK); }
194
195 dc.DrawLine(bx, ay, bx, by);
196 dc.DrawLine(bx, by, ax, by);
197 dc.DrawLine(ax, ay, bx, ay);
198 dc.DrawLine(ax, by, ax, ay);
199 }
200 break;
201
202 //-----------------------------------------------------
204 {
205 SG_DC_Draw_Edge(dc, SG_DC_EDGE_STYLE_SUNKEN, ax + 0, ay + 0, bx - 0, by - 0);
206 SG_DC_Draw_Edge(dc, SG_DC_EDGE_STYLE_RAISED, ax + 1, ay + 1, bx - 1, by - 1);
207 }
208 break;
209
210 //-----------------------------------------------------
212 {
213 wxPen oldPen(dc.GetPen());
214
215 dc.SetPen(wxPen(SG_System_Get_Color(wxSYS_COLOUR_BTNHIGHLIGHT), 0, wxPENSTYLE_SOLID));
216 dc.DrawLine(bx, ay, bx, by);
217 dc.DrawLine(bx, by, ax, by);
218
219 dc.SetPen(wxPen(SG_System_Get_Color(wxSYS_COLOUR_BTNSHADOW ), 0, wxPENSTYLE_SOLID));
220 dc.DrawLine(ax, by, ax, ay);
221 dc.DrawLine(ax, ay, bx, ay);
222
223 dc.SetPen(oldPen);
224 }
225 break;
226
227 //-----------------------------------------------------
229 {
230 wxPen oldPen(dc.GetPen());
231
232 dc.SetPen(wxPen(SG_System_Get_Color(wxSYS_COLOUR_BTNSHADOW ), 0, wxPENSTYLE_SOLID));
233 dc.DrawLine(bx, ay, bx, by);
234 dc.DrawLine(bx, by, ax, by);
235
236 dc.SetPen(wxPen(SG_System_Get_Color(wxSYS_COLOUR_BTNHIGHLIGHT), 0, wxPENSTYLE_SOLID));
237 dc.DrawLine(ax, by, ax, ay);
238 dc.DrawLine(ax, ay, bx, ay);
239
240 dc.SetPen(oldPen);
241 }
242 break;
243 }
244}
245
246//---------------------------------------------------------
247void SG_DC_Draw_Edge(wxDC &dc, int Edge_Style, wxRect r)
248{
249 SG_DC_Draw_Edge(dc, Edge_Style, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
250}
251
252
254// //
255// //
256// //
258
259//---------------------------------------------------------
260void SG_DC_Draw_Rect(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by)
261{
262 SG_DC_Draw_FillRect(dc, Color, ax, ay, bx, by);
263
264 SG_DC_Draw_Edge(dc, SG_DC_EDGE_STYLE_SIMPLE, ax, ay, bx, by);
265}
266
267//---------------------------------------------------------
268void SG_DC_Draw_Rect(wxDC &dc, wxColour Color, wxRect r)
269{
270 SG_DC_Draw_Rect(dc, Color, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
271}
272
273
275// //
276// //
277// //
279
280//---------------------------------------------------------
281void SG_DC_Draw_FillRect(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by)
282{
283 if( ax > bx )
284 {
285 int i = ax; ax = bx; bx = i;
286 }
287
288 if( ay > by )
289 {
290 int i = ay; ay = by; by = i;
291 }
292
293 //-----------------------------------------------------
294 wxPen oldPen(dc.GetPen()); dc.SetPen(wxPen(Color));
295
296 if( bx - ax < by - ay )
297 {
298 for(int i=ax; i<bx; i++)
299 {
300 dc.DrawLine(i, ay, i, by);
301 }
302 }
303 else
304 {
305 for(int i=ay; i<by; i++)
306 {
307 dc.DrawLine(ax, i, bx, i);
308 }
309 }
310
311 //-----------------------------------------------------
312 dc.SetPen(oldPen);
313}
314
315//---------------------------------------------------------
316void SG_DC_Draw_FillRect(wxDC &dc, wxColour Color, wxRect r)
317{
318 SG_DC_Draw_FillRect(dc, Color, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
319}
320
321
323// //
324// //
325// //
327
328//---------------------------------------------------------
329void SG_DC_Draw_Text(wxDC &dc, int Align, int x, int y, const wxString &Text)
330{
331 if( Align != SG_DC_TEXTALIGN_TOPLEFT )
332 {
333 wxCoord xSize, ySize;
334
335 dc.GetTextExtent(Text, &xSize, &ySize);
336
337 //-------------------------------------------------
338 if ( Align & SG_DC_TEXTALIGN_XCENTER )
339 {
340 x -= xSize / 2;
341 }
342 else if ( Align & SG_DC_TEXTALIGN_RIGHT )
343 {
344 x -= xSize;
345 }
346
347 //-------------------------------------------------
348 if ( Align & SG_DC_TEXTALIGN_YCENTER )
349 {
350 y -= ySize / 2;
351 }
352 else if ( Align & SG_DC_TEXTALIGN_BOTTOM )
353 {
354 y -= ySize;
355 }
356 }
357
358 dc.DrawText(Text, x, y);
359}
360
361//---------------------------------------------------------
362void SG_DC_Draw_Text(wxDC &dc, int Align, int x, int y, double Angle, const wxString &Text)
363{
364 if( Angle == 0. )
365 {
366 SG_DC_Draw_Text(dc, Align, x, y, Text);
367
368 return;
369 }
370
371 if( Align != SG_DC_TEXTALIGN_TOPLEFT )
372 {
373 wxCoord xSize, ySize; double d;
374
375 dc.GetTextExtent(Text, &xSize, &ySize);
376
377 //-------------------------------------------------
378 d = M_DEG_TO_RAD * Angle;
379
380 if ( Align & SG_DC_TEXTALIGN_XCENTER )
381 {
382 x -= (int)(xSize * cos(d) / 2.);
383 y += (int)(xSize * sin(d) / 2.);
384 }
385 else if ( Align & SG_DC_TEXTALIGN_RIGHT )
386 {
387 x -= (int)(xSize * cos(d));
388 y += (int)(xSize * sin(d));
389 }
390
391 //-------------------------------------------------
392 d = M_DEG_TO_RAD * (Angle - 90.);
393
394 if ( Align & SG_DC_TEXTALIGN_YCENTER )
395 {
396 x -= (int)(ySize * cos(d) / 2.);
397 y += (int)(ySize * sin(d) / 2.);
398 }
399 else if ( Align & SG_DC_TEXTALIGN_BOTTOM )
400 {
401 x -= (int)(ySize * cos(d));
402 y += (int)(ySize * sin(d));
403 }
404 }
405
406 dc.DrawRotatedText(Text, x, y, Angle);
407}
408
409//---------------------------------------------------------
410void SG_DC_Draw_Text (wxDC &dc, int Align, int x, int y, const wxString &Text, int Effect, wxColour Effect_Color, int Effect_Size)
411{
412 SG_DC_Draw_Text(dc, Align, x, y, 0., Text, Effect, Effect_Color);
413}
414
415void SG_DC_Draw_Text (wxDC &dc, int Align, int x, int y, double Angle, const wxString &Text, int Effect, wxColour Effect_Color, int Effect_Size)
416{
417 if( Effect != SG_DC_TEXTEFFECT_NONE )
418 {
419 wxColour oldColor = dc.GetTextForeground(); dc.SetTextForeground(Effect_Color);
420
421 if( Effect_Size <= 1 )
422 {
423 int d = 1;
424
425 if( Effect & SG_DC_TEXTEFFECT_TOP ) SG_DC_Draw_Text(dc, Align, x , y - d, Angle, Text);
426 if( Effect & SG_DC_TEXTEFFECT_TOPLEFT ) SG_DC_Draw_Text(dc, Align, x - d, y - d, Angle, Text);
427 if( Effect & SG_DC_TEXTEFFECT_LEFT ) SG_DC_Draw_Text(dc, Align, x - d, y , Angle, Text);
428 if( Effect & SG_DC_TEXTEFFECT_BOTTOMLEFT ) SG_DC_Draw_Text(dc, Align, x - d, y + d, Angle, Text);
429 if( Effect & SG_DC_TEXTEFFECT_BOTTOM ) SG_DC_Draw_Text(dc, Align, x , y + d, Angle, Text);
430 if( Effect & SG_DC_TEXTEFFECT_BOTTOMRIGHT ) SG_DC_Draw_Text(dc, Align, x + d, y + d, Angle, Text);
431 if( Effect & SG_DC_TEXTEFFECT_RIGHT ) SG_DC_Draw_Text(dc, Align, x + d, y , Angle, Text);
432 if( Effect & SG_DC_TEXTEFFECT_TOPRIGHT ) SG_DC_Draw_Text(dc, Align, x + d, y - d, Angle, Text);
433 }
434 else if( Effect != SG_DC_TEXTEFFECT_FRAME )
435 {
436 for(int d=1; d<=Effect_Size; d++)
437 {
438 if( Effect & SG_DC_TEXTEFFECT_TOP ) SG_DC_Draw_Text(dc, Align, x , y - d, Angle, Text);
439 if( Effect & SG_DC_TEXTEFFECT_TOPLEFT ) SG_DC_Draw_Text(dc, Align, x - d, y - d, Angle, Text);
440 if( Effect & SG_DC_TEXTEFFECT_LEFT ) SG_DC_Draw_Text(dc, Align, x - d, y , Angle, Text);
441 if( Effect & SG_DC_TEXTEFFECT_BOTTOMLEFT ) SG_DC_Draw_Text(dc, Align, x - d, y + d, Angle, Text);
442 if( Effect & SG_DC_TEXTEFFECT_BOTTOM ) SG_DC_Draw_Text(dc, Align, x , y + d, Angle, Text);
443 if( Effect & SG_DC_TEXTEFFECT_BOTTOMRIGHT ) SG_DC_Draw_Text(dc, Align, x + d, y + d, Angle, Text);
444 if( Effect & SG_DC_TEXTEFFECT_RIGHT ) SG_DC_Draw_Text(dc, Align, x + d, y , Angle, Text);
445 if( Effect & SG_DC_TEXTEFFECT_TOPRIGHT ) SG_DC_Draw_Text(dc, Align, x + d, y - d, Angle, Text);
446 }
447 }
448 else
449 {
450 for(int dy=y-Effect_Size; dy<=y+Effect_Size; dy++)
451 {
452 for(int dx=x-Effect_Size; dx<=x+Effect_Size; dx++)
453 {
454 SG_DC_Draw_Text(dc, Align, dx, dy, Angle, Text);
455 }
456 }
457 }
458
459 dc.SetTextForeground(oldColor);
460 }
461
462 SG_DC_Draw_Text(dc, Align, x, y, Angle, Text);
463}
464
465
467// //
468// //
469// //
471
472//---------------------------------------------------------
473#define TEXTSPACE 6
474
475//---------------------------------------------------------
476void SG_DC_Draw_Scale(wxDC &dc, const wxRect &r, double zMin, double zMax, int Orientation, int Tick, int Style, const wxString &Unit, bool bUseDCFont)
477{
478 int Width = Orientation != SG_DC_SCALE_VERTICAL ? r.GetWidth() : r.GetHeight();
479 int Height = Orientation != SG_DC_SCALE_VERTICAL ? r.GetHeight() : r.GetWidth();
480
481 if( zMin >= zMax || Width < 5 || Height < 5 )
482 {
483 return;
484 }
485
486 //-----------------------------------------------------
487 wxPen oldPen (dc.GetPen ());
488 wxBrush oldBrush(dc.GetBrush());
489 wxFont oldFont (dc.GetFont ());
490
491 //-----------------------------------------------------
492 if( Style & SG_DC_SCALE_STYLE_GLOOMING )
493 {
495
496 wxRect rTmp; wxColour oldColour(dc.GetTextForeground());
497
498 dc.SetPen(wxPen(*wxWHITE)); dc.SetTextForeground(*wxWHITE);
499
500 rTmp = r; rTmp.Offset( 0, 1); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
501 rTmp = r; rTmp.Offset( 1, 1); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
502 rTmp = r; rTmp.Offset( 1, 0); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
503 rTmp = r; rTmp.Offset( 1, -1); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
504 rTmp = r; rTmp.Offset( 0, -1); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
505 rTmp = r; rTmp.Offset(-1, -1); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
506 rTmp = r; rTmp.Offset(-1, 0); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
507 rTmp = r; rTmp.Offset(-1, 1); SG_DC_Draw_Scale(dc, rTmp, zMin, zMax, Orientation, Tick, Style, Unit, bUseDCFont);
508
509 dc.SetPen(oldPen); dc.SetTextForeground(oldColour);
510 }
511
512 //-----------------------------------------------------
513 if( bUseDCFont )
514 {
515 wxFont Font(dc.GetFont());
516 Font.SetPointSize((int)((Tick == SG_DC_SCALE_TICK_NONE ? 0.60 : 0.45) * (double)Height));
517 dc.SetFont(Font);
518 }
519 else
520 {
521 dc.SetFont(wxFont((int)((Tick == SG_DC_SCALE_TICK_NONE ? 0.60 : 0.45) * (double)Height),
522 wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL
523 ));
524 }
525
526 //-----------------------------------------------------
527 double zToDC = (double)Width / (zMax - zMin);
528 double dz = pow(10., floor(log10(zMax - zMin)) - 1.);
529 int Decimals = dz >= 1. ? 0 : (int)floor(-log10(dz));
530
531 int h = dc.GetTextExtent(wxString::Format("%.*f", Decimals, zMax)).GetWidth();
532
533 while( zToDC * dz < h + TEXTSPACE ) { dz *= 2; }
534
535 //-----------------------------------------------------
536 int Align, x[2], y[2]; h = 0;
537
538 switch( Tick )
539 {
540 default : Align = SG_DC_TEXTALIGN_TOPLEFT ; break;
541 case SG_DC_SCALE_TICK_TOP : Align = SG_DC_TEXTALIGN_TOPCENTER ; break;
543 }
544
545 if( Orientation != SG_DC_SCALE_VERTICAL )
546 {
547 x[0] = -1; x[1] = (int)((Tick == SG_DC_SCALE_TICK_NONE ? 1.00 : 0.30) * (double)Height);
548 y[0] = r.GetTop () + (Tick != SG_DC_SCALE_TICK_BOTTOM ? 0 : Height);
549 y[1] = r.GetTop () + (Tick != SG_DC_SCALE_TICK_BOTTOM ? x[1] : Height - x[1]);
550 }
551 else // if( Orientation == SG_DC_SCALE_VERTICAL )
552 {
553 y[0] = -1; y[1] = (int)((Tick == SG_DC_SCALE_TICK_NONE ? 1.00 : 0.30) * (double)Height);
554 x[0] = r.GetLeft() + (Tick != SG_DC_SCALE_TICK_BOTTOM ? 0 : Height);
555 x[1] = r.GetLeft() + (Tick != SG_DC_SCALE_TICK_BOTTOM ? y[1] : Height - y[1]);
556 }
557
558 //-----------------------------------------------------
559 for(double z=dz*floor(zMin/dz); !std::isinf(z) && z<=zMax; z+=dz)
560 {
561 if( Tick == SG_DC_SCALE_TICK_NONE || z >= zMin )
562 {
563 int zDC = Style & SG_DC_SCALE_STYLE_DESCENDENT
564 ? Width - 1 - (int)(zToDC * (z - zMin))
565 : (int)(zToDC * (z - zMin));
566
567 if( Orientation != SG_DC_SCALE_VERTICAL )
568 {
569 int xLast = x[0]; x[0] = x[1] = r.GetLeft() + zDC;
570
571 if( Style & SG_DC_SCALE_STYLE_BLACKWHITE && xLast >= 0 )
572 {
573 dc.SetBrush(h++ % 2 ? *wxWHITE : *wxBLACK);
574
575 dc.DrawRectangle(xLast, y[0], x[1] - xLast, y[1] - y[0]);
576 }
577 }
578 else // if( Orientation == SG_DC_SCALE_VERTICAL )
579 {
580 int yLast = y[0]; y[0] = y[1] = r.GetTop () + zDC;
581
582 if( Style & SG_DC_SCALE_STYLE_BLACKWHITE && yLast >= 0 )
583 {
584 dc.SetBrush(h++ % 2 ? *wxWHITE : *wxBLACK);
585
586 dc.DrawRectangle(x[0], yLast, x[1] - x[0], y[1] - yLast);
587 }
588 }
589
590 if( !(Style & SG_DC_SCALE_STYLE_BLACKWHITE) )
591 {
592 dc.DrawLine(x[0], y[0], x[1], y[1]);
593 }
594
595 SG_DC_Draw_Text(dc, Align, x[1], y[1], Orientation != SG_DC_SCALE_VERTICAL ? 0 : 90,
596 wxString::Format("%.*f", Decimals, z)
597 );
598 }
599 }
600
601 //-----------------------------------------------------
602 if( Orientation != SG_DC_SCALE_VERTICAL )
603 {
604 if( Style & SG_DC_SCALE_STYLE_LINECONN )
605 {
606 dc.DrawLine(r.GetLeft(), y[0], x[1], y[0]);
607 }
608
609 if( !Unit.IsEmpty() )
610 {
611 if( Style & SG_DC_SCALE_STYLE_UNIT_BELOW )
612 {
613 SG_DC_Draw_Text(dc, SG_DC_TEXTALIGN_TOPCENTER , r.GetLeft() + r.GetWidth() / 2, r.GetBottom(), Unit);
614 }
615 else // if( Style & SG_DC_SCALE_STYLE_UNIT_ABOVE )
616 {
617 SG_DC_Draw_Text(dc, SG_DC_TEXTALIGN_BOTTOMCENTER, r.GetLeft() + r.GetWidth() / 2, r.GetTop (), Unit);
618 }
619 }
620 }
621 else
622 {
623 if( Style & SG_DC_SCALE_STYLE_LINECONN )
624 {
625 dc.DrawLine(x[0], r.GetTop(), x[0], y[1]);
626 }
627
628 if( !Unit.IsEmpty() )
629 {
630 if( Style & SG_DC_SCALE_STYLE_UNIT_BELOW )
631 {
632 SG_DC_Draw_Text(dc, SG_DC_TEXTALIGN_TOPCENTER , r.GetRight(), r.GetTop() + r.GetHeight() / 2, 90., Unit);
633 }
634 else // if( Style & SG_DC_SCALE_STYLE_UNIT_ABOVE )
635 {
636 SG_DC_Draw_Text(dc, SG_DC_TEXTALIGN_BOTTOMCENTER, r.GetLeft (), r.GetTop() + r.GetHeight() / 2, 90., Unit);
637 }
638 }
639 }
640
641 //-----------------------------------------------------
642 dc.SetPen (oldPen );
643 dc.SetBrush(oldBrush);
644 dc.SetFont (oldFont );
645}
646
647//---------------------------------------------------------
648void SG_DC_Draw_Scale(wxDC &dc, const wxRect &r, double zMin, double zMax, bool bHorizontal, bool bAscendent, bool bTickAtTop, const wxString &Unit, bool bUseDCFont)
649{
651}
652
653
655// //
656// //
657// //
659
660//---------------------------------------------------------
661#define RULER_TEXT_SPACE 4
662
663//---------------------------------------------------------
664bool SG_DC_Draw_Ruler(wxDC &dc, const wxRect &r, bool bHorizontal, double zMin, double zMax, bool bAscendent, int FontSize, const wxColour &Colour)
665{
666 if( zMin < zMax && r.GetWidth() > 0 && r.GetHeight() > 0 )
667 {
668 dc.SetPen(Colour);
669 dc.SetFont(wxFont(FontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
670 dc.SetTextForeground(Colour);
671
672 double Width = bHorizontal ? r.GetWidth() : r.GetHeight();
673
674 int xMin = r.GetX();
675 int xMax = r.GetX() + r.GetWidth();
676 int yMin = r.GetY() + r.GetHeight();
677 int yMax = r.GetY();
678
679 //-------------------------------------------------
680 double zToDC = (double)Width / (zMax - zMin);
681
682 double dz = pow(10., floor(log10(zMax - zMin)) - 1.);
683 int Decimals = dz >= 1. ? 0 : (int)fabs(log10(dz));
684
685 wxSize Extent = dc.GetTextExtent(wxString::Format("%.*f", Decimals, zMax));
686 int dyFont = RULER_TEXT_SPACE + Extent.y;
687 int dxFont = RULER_TEXT_SPACE;
688
689 double zDC = 2 * Extent.x;
690 while( zToDC * dz < zDC + RULER_TEXT_SPACE )
691 {
692 dz *= 2;
693 }
694
695 //-------------------------------------------------
696 double z = dz * floor(zMin / dz); if( z < zMin ) z += dz;
697
698 for(; z<=zMax; z+=dz)
699 {
700 zDC = bAscendent ? zToDC * (z - zMin) : Width - zToDC * (z - zMin);
701
702 if( bHorizontal )
703 {
704 int zPos = (int)(xMin + zDC);
705 dc.DrawLine(zPos, yMin, zPos, yMax);
706 dc.DrawText(wxString::Format("%.*f", Decimals, z), zPos + dxFont, yMin - dyFont);
707 }
708 else
709 {
710 int zPos = (int)(yMin - zDC);
711 dc.DrawLine(xMin, zPos, xMax, zPos);
712 dc.DrawText(wxString::Format("%.*f", Decimals, z), xMin + dxFont, zPos - dyFont);
713 }
714 }
715
716 return( true );
717 }
718
719 return( false );
720}
721
722
724// //
725// //
726// //
728
729//---------------------------------------------------------
void * SG_UI_Get_Window_Main(void)
#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 SG_GET_RGB(r, g, b)
Definition api_core.h:1345
const SG_Char * asFont(void) const
virtual TSG_Parameter_Type Get_Type(void) const =0
virtual bool Set_Value(int Value)
long asColor(void) const
Definition parameters.h:288
bool SG_DC_Draw_Ruler(wxDC &dc, const wxRect &r, bool bHorizontal, double zMin, double zMax, bool bAscendent, int FontSize, const wxColour &Colour)
#define TEXTSPACE
wxColour SG_System_Get_Color_Foreground(int Mode)
wxColour SG_System_Get_Color_Background(int Mode)
void SG_DC_Draw_Scale(wxDC &dc, const wxRect &r, double zMin, double zMax, int Orientation, int Tick, int Style, const wxString &Unit, bool bUseDCFont)
wxColour SG_Get_wxColor(int Color)
Definition dc_helper.cpp:70
bool SG_Set_Font(CSG_Parameter *pFont, wxFont &Font, wxColour &Colour)
wxColour SG_System_Get_Color(wxSystemColour index)
Definition dc_helper.cpp:81
void SG_DC_Draw_Rect(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by)
void SG_DC_Draw_Text(wxDC &dc, int Align, int x, int y, const wxString &Text)
int SG_Get_Color(const wxColour &Color)
Definition dc_helper.cpp:64
#define RULER_TEXT_SPACE
wxFont SG_Get_wxFont(CSG_Parameter *pFont)
void SG_DC_Draw_FillRect(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by)
void SG_DC_Draw_Edge(wxDC &dc, int Edge_Style, int ax, int ay, int bx, int by)
#define SG_DC_SCALE_STYLE_DEFAULT
Definition dc_helper.h:176
#define SG_DC_TEXTALIGN_YCENTER
Definition dc_helper.h:128
#define SG_DC_SCALE_STYLE_GLOOMING
Definition dc_helper.h:180
#define SG_DC_TEXTALIGN_TOPCENTER
Definition dc_helper.h:132
#define SG_DC_SCALE_HORIZONTAL
Definition dc_helper.h:167
#define SG_DC_TEXTALIGN_BOTTOM
Definition dc_helper.h:129
#define SG_DC_SCALE_TICK_NONE
Definition dc_helper.h:171
#define SG_DC_TEXTEFFECT_TOPRIGHT
Definition dc_helper.h:149
#define SG_DC_TEXTEFFECT_LEFT
Definition dc_helper.h:144
#define SG_DC_TEXTALIGN_BOTTOMCENTER
Definition dc_helper.h:138
#define SG_DC_SCALE_STYLE_BLACKWHITE
Definition dc_helper.h:179
#define SG_DC_SCALE_STYLE_LINECONN
Definition dc_helper.h:178
#define SG_DC_SCALE_VERTICAL
Definition dc_helper.h:168
#define SG_DC_TEXTEFFECT_BOTTOM
Definition dc_helper.h:146
#define SG_DC_SCALE_TICK_TOP
Definition dc_helper.h:172
#define SG_DC_SCALE_STYLE_UNIT_BELOW
Definition dc_helper.h:182
@ SG_DC_EDGE_STYLE_SIMPLE
Definition dc_helper.h:98
@ SG_DC_EDGE_STYLE_SUNKEN
Definition dc_helper.h:100
@ SG_DC_EDGE_STYLE_RAISED
Definition dc_helper.h:101
@ SG_DC_EDGE_STYLE_STATIC
Definition dc_helper.h:99
#define SG_DC_TEXTALIGN_XCENTER
Definition dc_helper.h:125
#define SG_DC_TEXTEFFECT_NONE
Definition dc_helper.h:141
#define SG_DC_TEXTEFFECT_BOTTOMRIGHT
Definition dc_helper.h:147
#define SG_DC_SCALE_TICK_BOTTOM
Definition dc_helper.h:173
#define SG_DC_TEXTEFFECT_TOPLEFT
Definition dc_helper.h:143
#define SG_DC_SCALE_STYLE_DESCENDENT
Definition dc_helper.h:177
#define SG_DC_TEXTEFFECT_BOTTOMLEFT
Definition dc_helper.h:145
#define SG_DC_TEXTALIGN_TOPLEFT
Definition dc_helper.h:131
#define SG_DC_TEXTEFFECT_RIGHT
Definition dc_helper.h:148
#define SG_DC_TEXTEFFECT_TOP
Definition dc_helper.h:142
#define SG_DC_TEXTEFFECT_FRAME
Definition dc_helper.h:150
#define SG_DC_TEXTALIGN_RIGHT
Definition dc_helper.h:126
#define M_DEG_TO_RAD
Definition mat_tools.h:109
@ PARAMETER_TYPE_Font
Definition parameters.h:139