1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2012 Canonical Ltd
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Jason Smith <jason.smith@canonical.com>
20
#include "UnityWindowView.h"
25
NUX_IMPLEMENT_OBJECT_TYPE(UnityWindowView);
27
UnityWindowView::UnityWindowView(NUX_FILE_LINE_DECL) : View(NUX_FILE_LINE_PARAM)
29
style = UnityWindowStyle::Ptr(new UnityWindowStyle());
30
bg_helper_.owner = this;
33
UnityWindowView::~UnityWindowView()
39
UnityWindowView::SetupBackground(bool enabled)
41
bg_helper_.enabled = enabled;
44
void UnityWindowView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
49
void UnityWindowView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
51
PreDraw(GfxContext, force_draw);
53
nux::Geometry base = GetGeometry();
54
GfxContext.PushClippingRectangle(base);
57
gPainter.PaintBackground(GfxContext, base);
59
nux::Geometry background_geo = GetBackgroundGeometry();
60
int internal_offset = style()->GetInternalOffset();
62
nux::Geometry internal_clip(background_geo.x + internal_offset,
63
background_geo.y + internal_offset,
64
background_geo.width - internal_offset * 2,
65
background_geo.height - internal_offset * 2);
66
GfxContext.PushClippingRectangle(internal_clip);
69
nux::Geometry geo_absolute = GetAbsoluteGeometry ();
70
if (BackgroundEffectHelper::blur_type != BLUR_NONE)
72
nux::Geometry blur_geo(geo_absolute.x, geo_absolute.y, base.width, base.height);
73
auto blur_texture = bg_helper_.GetBlurRegion(blur_geo);
75
if (blur_texture.IsValid())
77
nux::TexCoordXForm texxform_blur_bg;
78
texxform_blur_bg.flip_v_coord = true;
79
texxform_blur_bg.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
80
texxform_blur_bg.uoffset = ((float) base.x) / geo_absolute.width;
81
texxform_blur_bg.voffset = ((float) base.y) / geo_absolute.height;
85
rop.SrcBlend = GL_ONE;
86
rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
88
gPainter.PushDrawTextureLayer(GfxContext, base,
99
rop.SrcBlend = GL_ONE;
100
rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
101
gPainter.PushDrawColorLayer (GfxContext, internal_clip, background_color, false, rop);
103
// Make round corners
105
rop.SrcBlend = GL_ZERO;
106
rop.DstBlend = GL_SRC_ALPHA;
107
gPainter.PaintShapeCornerROP(GfxContext,
110
nux::eSHAPE_CORNER_ROUND4,
111
nux::eCornerTopLeft | nux::eCornerTopRight |
112
nux::eCornerBottomLeft | nux::eCornerBottomRight,
116
DrawOverlay(GfxContext, force_draw, internal_clip);
118
GfxContext.PopClippingRectangle();
119
GfxContext.PopClippingRectangle();
121
DrawBackground(GfxContext, background_geo);
123
PostDraw(GfxContext, force_draw);
126
void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)
128
int border = style()->GetBorderSize();
130
GfxContext.GetRenderStates().SetBlend (TRUE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
132
nux::TexCoordXForm texxform;
133
texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
134
texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
136
// Draw TOP-LEFT CORNER
139
texxform.u1 = border;
140
texxform.v1 = border;
141
GfxContext.QRP_1Tex (geo.x, geo.y,
142
border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
144
// Draw TOP-RIGHT CORNER
147
texxform.u1 = border;
148
texxform.v1 = border;
149
texxform.flip_u_coord = true;
150
texxform.flip_v_coord = false;
151
GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y,
152
border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
154
// Draw BOTTOM-LEFT CORNER
157
texxform.u1 = border;
158
texxform.v1 = border;
159
texxform.flip_u_coord = false;
160
texxform.flip_v_coord = true;
161
GfxContext.QRP_1Tex (geo.x, geo.y + geo.height - border,
162
border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
164
// Draw BOTTOM-RIGHT CORNER
167
texxform.u1 = border;
168
texxform.v1 = border;
169
texxform.flip_u_coord = true;
170
texxform.flip_v_coord = true;
171
GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + geo.height - border,
172
border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
174
int top_width = style()->GetBackgroundTop()->GetWidth();
175
int top_height = style()->GetBackgroundTop()->GetHeight();
180
texxform.u1 = top_width;
181
texxform.v1 = top_height;
182
texxform.flip_u_coord = false;
183
texxform.flip_v_coord = false;
184
GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);
186
// Draw BOTTOM BORDER
189
texxform.u1 = top_width;
190
texxform.v1 = top_height;
191
texxform.flip_u_coord = false;
192
texxform.flip_v_coord = true;
193
GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);
196
int left_width = style()->GetBackgroundLeft()->GetWidth();
197
int left_height = style()->GetBackgroundLeft()->GetHeight();
202
texxform.u1 = left_width;
203
texxform.v1 = left_height;
204
texxform.flip_u_coord = false;
205
texxform.flip_v_coord = false;
206
GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);
211
texxform.u1 = left_width;
212
texxform.v1 = left_height;
213
texxform.flip_u_coord = true;
214
texxform.flip_v_coord = false;
215
GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);
217
GfxContext.GetRenderStates().SetBlend (FALSE);