OpenCPN Partial API docs
ocpndc.h
1 /******************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: Layer to use wxDC or opengl
5  * Author: Sean D'Epagnier
6  *
7  ***************************************************************************
8  * Copyright (C) 2011 by Sean D'Epagnier *
9  * sean at depagnier dot com *
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License *
22  * along with this program; if not, write to the *
23  * Free Software Foundation, Inc., *
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25  ***************************************************************************
26  *
27  *f
28  */
29 
30 #ifndef __OCPNDC_H__
31 #define __OCPNDC_H__
32 
33 #include <vector>
34 
35 #include "dychart.h"
36 
37 #include "linmath.h"
38 
39 #include "TexFont.h"
40 #include "viewport.h"
41 #ifdef ocpnUSE_GL
42  #include "shaders.h"
43 #endif
44 
45 class ViewPort;
46 class GLUtesselator;
47 
48 void DrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
49  bool b_hiqual);
50 
51 //----------------------------------------------------------------------------
52 // ocpnDC
53 //----------------------------------------------------------------------------
54 
55 class wxGLCanvas;
56 class glChartCanvas;
57 
58 class ocpnDC {
59 public:
60  ocpnDC(glChartCanvas &canvas);
61  ocpnDC(wxGLCanvas &canvas);
62  ocpnDC(wxDC &pdc);
63  ocpnDC();
64 
65  ~ocpnDC();
66 
67  void Init();
68 
69  void SetGLCanvas(glChartCanvas *canvas);
70  void SetBackground(const wxBrush &brush);
71  void SetPen(const wxPen &pen);
72  void SetBrush(const wxBrush &brush);
73  void SetTextForeground(const wxColour &colour);
74  void SetFont(const wxFont &font);
75  static void SetGLAttrs(bool highQuality);
76  void SetGLStipple() const;
77 
78  const wxPen &GetPen() const;
79  const wxBrush &GetBrush() const;
80  const wxFont &GetFont() const;
81 
82  void GetSize(wxCoord *width, wxCoord *height) const;
83 
84  void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
85  bool b_hiqual = true);
86  void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0,
87  wxCoord yoffset = 0, bool b_hiqual = true);
88  void DrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
89  bool b_hiqual);
90  void DrawGLThickLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,
91  wxPen pen, bool b_hiqual);
92 
93  void StrokeLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
94  void StrokeLine(wxPoint a, wxPoint b) { StrokeLine(a.x, a.y, b.x, b.y); }
95  void StrokeLines(int n, wxPoint *points);
96 
97  void Clear();
98  void DrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
99  void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
100  wxCoord rr);
101  void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
102  void DrawCircle(const wxPoint &pt, wxCoord radius) {
103  DrawCircle(pt.x, pt.y, radius);
104  }
105  void StrokeCircle(wxCoord x, wxCoord y, wxCoord radius);
106 
107  void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
108  void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0,
109  wxCoord yoffset = 0, float scale = 1.0, float angle = 0.0);
110  void DrawPolygonTessellated(int n, wxPoint points[], wxCoord xoffset = 0,
111  wxCoord yoffset = 0);
112  void StrokePolygon(int n, wxPoint points[], wxCoord xoffset = 0,
113  wxCoord yoffset = 0, float scale = 1.0);
114 
115  void DrawBitmap(const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask);
116 
117  void DrawText(const wxString &text, wxCoord x, wxCoord y, float angle = 0.0);
118  void GetTextExtent(const wxString &string, wxCoord *w, wxCoord *h,
119  wxCoord *descent = NULL, wxCoord *externalLeading = NULL,
120  wxFont *font = NULL);
121 
122  void ResetBoundingBox();
123  void CalcBoundingBox(wxCoord x, wxCoord y);
124 
125  void DestroyClippingRegion() {}
126 
127  wxDC *GetDC() const { return dc; }
128  void SetDPIFactor(double factor){ m_dpi_factor = factor; }
129  void SetVP(ViewPort vp);
130 
131 #ifdef ocpnUSE_GL
132  GLfloat *s_odc_tess_work_buf;
133 #endif
134 
135 #if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
136  int s_odc_tess_vertex_idx;
137  int s_odc_tess_vertex_idx_this;
138  int s_odc_tess_buf_len;
139  GLenum s_odc_tess_mode;
140  int s_odc_nvertex;
141  vec4 s_odc_tess_color;
142  ViewPort *s_odc_tessVP;
143  GLUtesselator *m_tobj;
144 
145 #endif
146  int m_canvasIndex;
147 #ifdef ocpnUSE_GL
148  TexFont m_texfont;
149 #endif
150 
151 protected:
152  bool ConfigurePen();
153  bool ConfigureBrush();
154 
155  void GLDrawBlendData(wxCoord x, wxCoord y, wxCoord w, wxCoord h, int format,
156  const unsigned char *data);
157 
158  void drawrrhelperGLES2(wxCoord x0, wxCoord y0, wxCoord r, int quadrant,
159  int steps);
160 
161  void BuildShaders();
162 
163  glChartCanvas *m_glchartCanvas;
164  wxGLCanvas *m_glcanvas;
165 
166  wxDC *dc;
167  wxPen m_pen;
168  wxBrush m_brush;
169  wxColour m_textforegroundcolour;
170  wxFont m_font;
171 
172  bool m_buseTex;
173 
174 #if wxUSE_GRAPHICS_CONTEXT
175  wxGraphicsContext *pgc;
176 #endif
177 
178  float *workBuf;
179  size_t workBufSize;
180  unsigned int workBufIndex;
181  double m_dpi_factor;
182  ViewPort m_vp;
183 #ifdef ocpnUSE_GL
184  GLShaderProgram *m_pcolor_tri_shader_program;
185  GLShaderProgram *m_pAALine_shader_program;
186  GLShaderProgram *m_pcircle_filled_shader_program;
187  GLShaderProgram *m_ptexture_2D_shader_program;
188 #endif
189 };
190 
191 #endif
Definition: ocpndc.h:58
Definition: Quilt.cpp:867