]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/render_area_2d.hxx
new FSF address
[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 <simgear/compiler.h>
32
33 #include <plib/ssg.h>
34 #include <vector>
35
36 SG_USING_STD(vector);
37
38 enum RA2DDrawingType {
39         RA2D_LINE,
40         RA2D_QUAD,
41         RA2D_PIXEL
42 };
43
44 struct RA2DPrimitive {
45         RA2DPrimitive();
46
47         RA2DDrawingType type;
48         int x1, y1, x2, y2;
49         bool invert;
50         bool debug;
51 };
52
53 class RenderArea2D {
54         
55 public:
56         RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy);
57         ~RenderArea2D();
58         
59         void draw();
60         
61         void SetPixelColor(const float* rgba);
62         void SetBackgroundColor(const float* rgba);
63         void SetPosition(int posx, int posy);
64         void SetLogicalSize(int logx, int logy);
65         void SetActualSize(int sizex, int sizey);
66         
67         // Set clipping region in logical units
68         void SetClipRegion(int x1, int y1, int x2, int y2);
69         // Set clip region to be the same as the rendered area (default)
70         void ResetClipRegion();
71         
72         // Drawing specified in logical units
73         void DrawLine(int x1, int y1, int x2, int y2);
74         void DrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
75         void DrawBackground();
76         // Draw a pixel specified by *logical* position
77         void DrawPixel(int x, int y, bool invert = false);
78         
79         // The old drawing functions have been renamed in order to buffer the drawing for FG
80         //
81         // Drawing specified in logical units
82         void oldDrawLine(int x1, int y1, int x2, int y2);
83         void oldDrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
84         void oldDrawBackground();
85         // Draw a pixel specified by *logical* position
86         void oldDrawPixel(int x, int y, bool invert = false);
87         
88         // Flush the buffer pipeline
89         void Flush();
90         
91         // Turn debugging on or off.
92         inline void SetDebugging(bool b) { _ra2d_debug = b; }
93
94 private:
95         int _logx, _logy;       // logical size of rendered area
96         int _sizex, _sizey;             // Actual size of rendered area
97         int _posx, _posy;       // Position of rendered area
98         int _clipx1, _clipx2, _clipy1, _clipy2; // Current clipping region in *logical* units
99         
100         float _backgroundColor[4];
101         float _pixelColor[4];
102         
103         // Actual drawing routines copied from Atlas
104         void doSetColor( const float *rgb );
105         void doDrawQuad( const sgVec2 *p, const sgVec3 *normals );
106         void doDrawQuad( const sgVec2 *p, const sgVec3 *normals, const sgVec4 *color );
107         
108         vector<RA2DPrimitive> drawing_list;
109         
110         // Control whether to output debugging output
111         bool _ra2d_debug;
112 };
113
114 #endif