~smspillaz/unity/untiy.less-paint-insanity

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/UnityWindowView.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
 
2
/*
 
3
 * Copyright (C) 2012 Canonical Ltd
 
4
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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/>.
 
16
 *
 
17
 * Authored by: Jason Smith <jason.smith@canonical.com>
 
18
 */
 
19
 
 
20
#include "UnityWindowView.h"
 
21
 
 
22
namespace unity {
 
23
namespace ui {
 
24
 
 
25
NUX_IMPLEMENT_OBJECT_TYPE(UnityWindowView);
 
26
 
 
27
UnityWindowView::UnityWindowView(NUX_FILE_LINE_DECL) : View(NUX_FILE_LINE_PARAM)
 
28
{
 
29
  style = UnityWindowStyle::Ptr(new UnityWindowStyle());
 
30
  bg_helper_.owner = this;
 
31
}
 
32
 
 
33
UnityWindowView::~UnityWindowView()
 
34
{
 
35
 
 
36
}
 
37
 
 
38
void
 
39
UnityWindowView::SetupBackground(bool enabled)
 
40
{
 
41
  bg_helper_.enabled = enabled;
 
42
}
 
43
 
 
44
void UnityWindowView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
 
45
{
 
46
  // fixme???
 
47
}
 
48
 
 
49
void UnityWindowView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
 
50
{
 
51
  PreDraw(GfxContext, force_draw);
 
52
 
 
53
  nux::Geometry base = GetGeometry();
 
54
  GfxContext.PushClippingRectangle(base);
 
55
 
 
56
  // clear region
 
57
  gPainter.PaintBackground(GfxContext, base);
 
58
 
 
59
  nux::Geometry background_geo = GetBackgroundGeometry();
 
60
  int internal_offset = style()->GetInternalOffset();
 
61
 
 
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);
 
67
 
 
68
 
 
69
  nux::Geometry geo_absolute = GetAbsoluteGeometry ();
 
70
  if (BackgroundEffectHelper::blur_type != BLUR_NONE)
 
71
  {
 
72
    nux::Geometry blur_geo(geo_absolute.x, geo_absolute.y, base.width, base.height);
 
73
    auto blur_texture = bg_helper_.GetBlurRegion(blur_geo);
 
74
 
 
75
    if (blur_texture.IsValid())
 
76
    {
 
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;
 
82
 
 
83
      nux::ROPConfig rop;
 
84
      rop.Blend = false;
 
85
      rop.SrcBlend = GL_ONE;
 
86
      rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
 
87
 
 
88
      gPainter.PushDrawTextureLayer(GfxContext, base,
 
89
                                    blur_texture,
 
90
                                    texxform_blur_bg,
 
91
                                    nux::color::White,
 
92
                                    true,
 
93
                                    rop);
 
94
    }
 
95
  }
 
96
 
 
97
  nux::ROPConfig rop;
 
98
  rop.Blend = true;
 
99
  rop.SrcBlend = GL_ONE;
 
100
  rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
 
101
  gPainter.PushDrawColorLayer (GfxContext, internal_clip, background_color, false, rop);
 
102
 
 
103
  // Make round corners
 
104
  rop.Blend = true;
 
105
  rop.SrcBlend = GL_ZERO;
 
106
  rop.DstBlend = GL_SRC_ALPHA;
 
107
  gPainter.PaintShapeCornerROP(GfxContext,
 
108
                               internal_clip,
 
109
                               nux::color::White,
 
110
                               nux::eSHAPE_CORNER_ROUND4,
 
111
                               nux::eCornerTopLeft | nux::eCornerTopRight |
 
112
                               nux::eCornerBottomLeft | nux::eCornerBottomRight,
 
113
                               true,
 
114
                               rop);
 
115
 
 
116
  DrawOverlay(GfxContext, force_draw, internal_clip);
 
117
 
 
118
  GfxContext.PopClippingRectangle();
 
119
  GfxContext.PopClippingRectangle();
 
120
 
 
121
  DrawBackground(GfxContext, background_geo);
 
122
 
 
123
  PostDraw(GfxContext, force_draw);
 
124
}
 
125
 
 
126
void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)
 
127
{
 
128
  int border = style()->GetBorderSize();
 
129
 
 
130
  GfxContext.GetRenderStates().SetBlend (TRUE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
131
 
 
132
  nux::TexCoordXForm texxform;
 
133
  texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
 
134
  texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
 
135
 
 
136
  // Draw TOP-LEFT CORNER
 
137
  texxform.u0 = 0;
 
138
  texxform.v0 = 0;
 
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);
 
143
 
 
144
  // Draw TOP-RIGHT CORNER
 
145
  texxform.u0 = 0;
 
146
  texxform.v0 = 0;
 
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);
 
153
 
 
154
  // Draw BOTTOM-LEFT CORNER
 
155
  texxform.u0 = 0;
 
156
  texxform.v0 = 0;
 
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);
 
163
 
 
164
  // Draw BOTTOM-RIGHT CORNER
 
165
  texxform.u0 = 0;
 
166
  texxform.v0 = 0;
 
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);
 
173
 
 
174
  int top_width = style()->GetBackgroundTop()->GetWidth();
 
175
  int top_height = style()->GetBackgroundTop()->GetHeight();
 
176
 
 
177
  // Draw TOP BORDER
 
178
  texxform.u0 = 0;
 
179
  texxform.v0 = 0;
 
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);
 
185
 
 
186
  // Draw BOTTOM BORDER
 
187
  texxform.u0 = 0;
 
188
  texxform.v0 = 0;
 
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);
 
194
 
 
195
 
 
196
  int left_width = style()->GetBackgroundLeft()->GetWidth();
 
197
  int left_height = style()->GetBackgroundLeft()->GetHeight();
 
198
 
 
199
  // Draw LEFT BORDER
 
200
  texxform.u0 = 0;
 
201
  texxform.v0 = 0;
 
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);
 
207
 
 
208
  // Draw RIGHT BORDER
 
209
  texxform.u0 = 0;
 
210
  texxform.v0 = 0;
 
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);
 
216
 
 
217
  GfxContext.GetRenderStates().SetBlend (FALSE);
 
218
}
 
219
 
 
220
 
 
221
}
 
222
}