1 // RenderArea2D.hxx - a class to manage 2D polygon-based drawing
2 // for a complex instrument (eg. GPS).
4 // Written by David Luff, started 2005.
6 // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
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.
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.
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.
24 #ifndef _RENDER_AREA_2D
25 #define _RENDER_AREA_2D
31 #include <osg/ref_ptr>
33 #include <osg/StateSet>
35 #include <simgear/compiler.h>
36 #include <simgear/math/SGMath.hxx>
42 enum RA2DDrawingType {
48 struct RA2DPrimitive {
60 RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy);
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);
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();
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();
81 // Call Draw to have the buffer contents drawn and then cleared.
82 void Draw(osg::State& state);
84 // Clear the buffer contents
87 // Turn debugging on or off.
88 inline void SetDebugging(bool b) { _ra2d_debug = b; }
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
96 float _backgroundColor[4];
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();
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 );
110 vector<RA2DPrimitive> drawing_list;
112 // Control whether to output debugging output