]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/render_area_2d.hxx
Merge branch 'jmt/gps'
[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 - david.luff@nottingham.ac.uk
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 draw(osg::State& state);
64         
65         void SetPixelColor(const float* rgba);
66         void SetBackgroundColor(const float* rgba);
67         void SetPosition(int posx, int posy);
68         void SetLogicalSize(int logx, int logy);
69         void SetActualSize(int sizex, int sizey);
70         
71         // Set clipping region in logical units
72         void SetClipRegion(int x1, int y1, int x2, int y2);
73         // Set clip region to be the same as the rendered area (default)
74         void ResetClipRegion();
75         
76         // Drawing specified in logical units
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         // Draw a pixel specified by *logical* position
81         void DrawPixel(int x, int y, bool invert = false);
82         
83         // The old drawing functions have been renamed in order to buffer the drawing for FG
84         //
85         // Drawing specified in logical units
86         void oldDrawLine(int x1, int y1, int x2, int y2);
87         void oldDrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
88         void oldDrawBackground();
89         // Draw a pixel specified by *logical* position
90         void oldDrawPixel(int x, int y, bool invert = false);
91         
92         // Flush the buffer pipeline
93         void Flush();
94         
95         // Turn debugging on or off.
96         inline void SetDebugging(bool b) { _ra2d_debug = b; }
97
98 private:
99         int _logx, _logy;       // logical size of rendered area
100         int _sizex, _sizey;             // Actual size of rendered area
101         int _posx, _posy;       // Position of rendered area
102         int _clipx1, _clipx2, _clipy1, _clipy2; // Current clipping region in *logical* units
103         
104         float _backgroundColor[4];
105         float _pixelColor[4];
106         
107         // Actual drawing routines copied from Atlas
108         void doSetColor( const float *rgb );
109         void doDrawQuad( const SGVec2f *p);
110         void doDrawQuad( const SGVec2f *p, const SGVec4f *color );
111         
112         vector<RA2DPrimitive> drawing_list;
113         
114         // Control whether to output debugging output
115         bool _ra2d_debug;
116 };
117
118 #endif