OpenCPN Partial API docs
Loading...
Searching...
No Matches
pi_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 __PIOCPNDC_H__
31#define __PIOCPNDC_H__
32
33#include <vector>
34#include "linmath.h"
35
36#include "pi_TexFont.h"
37#include "ocpn_plugin.h"
38
39#ifdef ocpnUSE_GL
40#include <wx/glcanvas.h>
41#endif
42
43// class ViewPort;
44class GLUtesselator;
45
46void piDrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
47 bool b_hiqual);
48
49//----------------------------------------------------------------------------
50// pi_ocpnDC
51//----------------------------------------------------------------------------
52
53class wxGLCanvas;
54
55class pi_ocpnDC {
56public:
57 pi_ocpnDC(wxGLCanvas &canvas);
58 pi_ocpnDC(wxDC &pdc);
59 pi_ocpnDC();
60
61 ~pi_ocpnDC();
62
63 void SetBackground(const wxBrush &brush);
64 void SetPen(const wxPen &pen);
65 void SetBrush(const wxBrush &brush);
66 void SetTextForeground(const wxColour &colour);
67 void SetFont(const wxFont &font);
68 static void SetGLAttrs(bool highQuality);
69 void SetGLStipple() const;
70 void SetVP(PlugIn_ViewPort *vp);
71 void SetDC(wxDC *dc_in) { dc = dc_in; }
72
73 const wxPen &GetPen() const;
74 const wxBrush &GetBrush() const;
75 const wxFont &GetFont() const;
76
77 void GetSize(wxCoord *width, wxCoord *height) const;
78
79 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
80 bool b_hiqual = true);
81 void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0,
82 wxCoord yoffset = 0, bool b_hiqual = true);
83
84 void StrokeLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
85 void StrokeLine(wxPoint a, wxPoint b) { StrokeLine(a.x, a.y, b.x, b.y); }
86 void StrokeLines(int n, wxPoint *points);
87
88 void Clear();
89 void DrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
90 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
91 wxCoord rr);
92 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
93 void DrawCircle(const wxPoint &pt, wxCoord radius) {
94 DrawCircle(pt.x, pt.y, radius);
95 }
96 void StrokeCircle(wxCoord x, wxCoord y, wxCoord radius);
97
98 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
99 void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0,
100 wxCoord yoffset = 0, float scale = 1.0, float angle = 0.0);
101 void DrawPolygonTessellated(int n, wxPoint points[], wxCoord xoffset = 0,
102 wxCoord yoffset = 0);
103 void StrokePolygon(int n, wxPoint points[], wxCoord xoffset = 0,
104 wxCoord yoffset = 0, float scale = 1.0);
105
106 void DrawBitmap(const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask);
107
108 void DrawText(const wxString &text, wxCoord x, wxCoord y);
109 void GetTextExtent(const wxString &string, wxCoord *w, wxCoord *h,
110 wxCoord *descent = NULL, wxCoord *externalLeading = NULL,
111 wxFont *font = NULL);
112
113 void ResetBoundingBox();
114 void CalcBoundingBox(wxCoord x, wxCoord y);
115
116 void DestroyClippingRegion() {}
117
118 wxDC *GetDC() const { return dc; }
119
120 void DrawGLLineArray(int n, float *vertex_array, unsigned char *color_array,
121 bool b_hiqual);
122 void DrawGLLineArray(int n, float *vertex_array, float *color_array,
123 bool b_hiqual);
124
125#ifdef ocpnUSE_GL
126 GLfloat *s_odc_tess_work_buf;
127#endif
128
129#ifdef USE_ANDROID_GLES2
130 int s_odc_tess_vertex_idx;
131 int s_odc_tess_vertex_idx_this;
132 int s_odc_tess_buf_len;
133 GLenum s_odc_tess_mode;
134 int s_odc_nvertex;
135 vec4 s_odc_tess_color;
136 // ViewPort *s_odc_tessVP;
137 GLUtesselator *m_tobj;
138
139#endif
140
141protected:
142 bool ConfigurePen();
143 bool ConfigureBrush();
144
145 void GLDrawBlendData(wxCoord x, wxCoord y, wxCoord w, wxCoord h, int format,
146 const unsigned char *data);
147
148 void drawrrhelperGLES2(wxCoord x0, wxCoord y0, wxCoord r, int quadrant,
149 int steps);
150
151 wxGLCanvas *glcanvas;
152 wxDC *dc;
153 wxPen m_pen;
154 wxBrush m_brush;
155 wxColour m_textforegroundcolour;
156 wxFont m_font;
157
158#ifdef ocpnUSE_GL
159 TexFont m_texfont;
160#endif
161 bool m_buseTex;
162
163#if wxUSE_GRAPHICS_CONTEXT
164 wxGraphicsContext *pgc;
165#endif
166
167 float *workBuf;
168 size_t workBufSize;
169 unsigned int workBufIndex;
170
171 wxSize m_vpSize;
172};
173
174#endif
PlugIn Object Definition/API.