Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Renderer / GlassRenderer.cpp
bloba30f537e4c71294961ac151da60e913b2ae8fff8
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "GlassRenderer.hpp"
25 #include "Screen/Canvas.hpp"
27 #if defined(EYE_CANDY) && defined(ENABLE_OPENGL)
29 #include "Screen/OpenGL/Scissor.hpp"
30 #include "Util/Macros.hpp"
32 constexpr
33 static unsigned
34 Shadow(unsigned c)
36 return c * 15 / 16;
39 constexpr
40 static Color
41 Shadow(Color c)
43 return Color(Shadow(c.Red()), Shadow(c.Green()), Shadow(c.Blue()));
46 #endif
48 void
49 DrawGlassBackground(Canvas &canvas, const PixelRect &rc, Color color)
51 canvas.DrawFilledRectangle(rc, color);
53 #if defined(EYE_CANDY) && defined(ENABLE_OPENGL)
54 if (color != COLOR_WHITE)
55 /* apply only to white background for now */
56 return;
58 const GLCanvasScissor scissor(rc);
60 const Color shadow = Shadow(color);
62 const RasterPoint center = rc.GetCenter();
63 const int size = std::min(rc.right - rc.left, rc.bottom - rc.top) / 4;
65 const RasterPoint vertices[] = {
66 { center.x + 1024, center.y - 1024 },
67 { center.x + 1024 + size, center.y - 1024 + size },
68 { center.x - 1024, center.y + 1024 },
69 { center.x - 1024 + size, center.y + 1024 + size },
72 glVertexPointer(2, GL_VALUE, 0, vertices);
74 const Color colors[] = {
75 shadow, color,
76 shadow, color,
79 glEnableClientState(GL_COLOR_ARRAY);
81 #ifdef HAVE_GLES
82 glColorPointer(4, GL_FIXED, 0, colors);
83 #else
84 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
85 #endif
87 static_assert(ARRAY_SIZE(vertices) == ARRAY_SIZE(colors),
88 "Array size mismatch");
90 glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAY_SIZE(vertices));
92 glDisableClientState(GL_COLOR_ARRAY);
93 #endif