]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/render_area_2d.hxx
Fix a dumb bug in NavDisplay text-enable.
[flightgear.git] / src / Instrumentation / render_area_2d.hxx
1 // RenderArea2D.hxx - a class to manage 2D polygon-based drawing
2 //                    for a complex instrument (eg. GPS).
3 //
4 // Written by David Luff, started 2005.
5 //
6 // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23
24 #ifndef _RENDER_AREA_2D
25 #define _RENDER_AREA_2D
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include <osg/ref_ptr>
32 #include <osg/State>
33 #include <osg/StateSet>
34
35 #include <simgear/compiler.h>
36 #include <simgear/math/SGMath.hxx>
37
38 #include <vector>
39
40 using std::vector;
41
42 enum RA2DDrawingType {
43         RA2D_LINE,
44         RA2D_QUAD,
45         RA2D_PIXEL
46 };
47
48 struct RA2DPrimitive {
49         RA2DPrimitive();
50
51         RA2DDrawingType type;
52         int x1, y1, x2, y2;
53         bool invert;
54         bool debug;
55 };
56
57 class RenderArea2D {
58         
59 public:
60         RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy);
61         ~RenderArea2D();
62         
63         void SetPixelColor(const float* rgba);
64         void SetBackgroundColor(const float* rgba);
65         void SetPosition(int posx, int posy);
66         void SetLogicalSize(int logx, int logy);
67         void SetActualSize(int sizex, int sizey);
68         
69         // Set clipping region in logical units
70         void SetClipRegion(int x1, int y1, int x2, int y2);
71         // Set clip region to be the same as the rendered area (default)
72         void ResetClipRegion();
73         
74         // The DrawXXX functions place the shapes in the buffer, specified 
75         // in logical units, and clipped to the current clip region.
76         void DrawPixel(int x, int y, bool invert = false);
77         void DrawLine(int x1, int y1, int x2, int y2);
78         void DrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
79         void DrawBackground();
80         
81         // Call Draw to have the buffer contents drawn and then cleared.
82         void Draw(osg::State& state);
83         
84         // Clear the buffer contents
85         void Flush();
86         
87         // Turn debugging on or off.
88         inline void SetDebugging(bool b) { _ra2d_debug = b; }
89
90 private:
91         int _logx, _logy;       // logical size of rendered area
92         int _sizex, _sizey;             // Actual size of rendered area
93         int _posx, _posy;       // Position of rendered area
94         int _clipx1, _clipx2, _clipy1, _clipy2; // Current clipping region in *logical* units
95         
96         float _backgroundColor[4];
97         float _pixelColor[4];
98         
99         // Drawing specified in logical units
100         void DoDrawPixel(int x, int y, bool invert = false);
101         void DoDrawLine(int x1, int y1, int x2, int y2);
102         void DoDrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
103         void DoDrawBackground();
104         
105         // Actual rendering routines copied from Atlas
106         void SetRenderColor( const float *rgb );
107         void RenderQuad( const SGVec2f *p);
108         void RenderQuad( const SGVec2f *p, const SGVec4f *color );
109         
110         vector<RA2DPrimitive> drawing_list;
111         
112         // Control whether to output debugging output
113         bool _ra2d_debug;
114 };
115
116 #endif