Merge lp:~unity-team/unity/unity.fix-750374 into lp:unity

Proposed by Mirco Müller on 2011-04-12
Status: Merged
Approved by: Gord Allott on 2011-04-13
Approved revision: 1117
Merged at revision: 1122
Proposed branch: lp:~unity-team/unity/unity.fix-750374
Merge into: lp:unity
Diff against target: 406 lines (+21/-288)
2 files modified
src/PlacesVScrollBar.cpp (+19/-248)
src/PlacesVScrollBar.h (+2/-40)
To merge this branch: bzr merge lp:~unity-team/unity/unity.fix-750374
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve on 2011-04-13
David Barth (community) 2011-04-12 Approve on 2011-04-13
Review via email: mp+57359@code.launchpad.net

Description of the change

Adapt to late design-change. Remove state-handling for vertical Dash-scrollbar. Change rendering of said scrollbar. Fixes LP: #750374

To post a comment you must log in.
David Barth (dbarth) wrote :

line 319: is the returned value always defined? the next line relies on that assumption.

review: Needs Information
1117. By Mirco Müller on 2011-04-13

Avoid potential segfaults and check against NULL-pointers being returned

Mirco Müller (macslow) wrote :

Added additional checks to protect against potential segfaults.

David Barth (dbarth) wrote :

LTGM

review: Approve
Gord Allott (gordallott) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/PlacesVScrollBar.cpp'
--- src/PlacesVScrollBar.cpp 2011-04-10 16:45:40 +0000
+++ src/PlacesVScrollBar.cpp 2011-04-13 09:01:38 +0000
@@ -25,33 +25,10 @@
25const int BLUR_SIZE = 7;25const int BLUR_SIZE = 7;
2626
27PlacesVScrollBar::PlacesVScrollBar (NUX_FILE_LINE_DECL)27PlacesVScrollBar::PlacesVScrollBar (NUX_FILE_LINE_DECL)
28 : VScrollBar (NUX_FILE_LINE_PARAM)28 : VScrollBar (NUX_FILE_LINE_PARAM),
29 _slider (NULL),
30 _track (NULL)
29{31{
30 m_SlideBar->OnMouseEnter.connect (sigc::mem_fun (this,
31 &PlacesVScrollBar::RecvMouseEnter));
32
33 m_SlideBar->OnMouseLeave.connect (sigc::mem_fun (this,
34 &PlacesVScrollBar::RecvMouseLeave));
35
36 m_SlideBar->OnMouseDown.connect (sigc::mem_fun (this,
37 &PlacesVScrollBar::RecvMouseDown));
38
39 m_SlideBar->OnMouseUp.connect (sigc::mem_fun (this,
40 &PlacesVScrollBar::RecvMouseUp));
41
42 m_SlideBar->OnMouseDrag.connect (sigc::mem_fun (this,
43 &PlacesVScrollBar::RecvMouseDrag));
44
45 _drag = false;
46 _entered = false;
47
48 _slider[STATE_OFF] = NULL;
49 _slider[STATE_OVER] = NULL;
50 _slider[STATE_DOWN] = NULL;
51 _track = NULL;
52
53 _state = STATE_OFF;
54
55 m_SlideBar->SetMinimumSize (PLACES_VSCROLLBAR_WIDTH + 2 * BLUR_SIZE,32 m_SlideBar->SetMinimumSize (PLACES_VSCROLLBAR_WIDTH + 2 * BLUR_SIZE,
56 PLACES_VSCROLLBAR_HEIGHT + 2 * BLUR_SIZE);33 PLACES_VSCROLLBAR_HEIGHT + 2 * BLUR_SIZE);
57 m_Track->SetMinimumSize (PLACES_VSCROLLBAR_WIDTH + 2 * BLUR_SIZE,34 m_Track->SetMinimumSize (PLACES_VSCROLLBAR_WIDTH + 2 * BLUR_SIZE,
@@ -62,84 +39,14 @@
6239
63PlacesVScrollBar::~PlacesVScrollBar ()40PlacesVScrollBar::~PlacesVScrollBar ()
64{41{
65 if (_slider[STATE_OFF])42 if (_slider)
66 _slider[STATE_OFF]->UnReference ();43 _slider->UnReference ();
67
68 if (_slider[STATE_OVER])
69 _slider[STATE_OVER]->UnReference ();
70
71 if (_slider[STATE_DOWN])
72 _slider[STATE_DOWN]->UnReference ();
7344
74 if (_track)45 if (_track)
75 _track->UnReference ();46 _track->UnReference ();
76}47}
7748
78void49void
79PlacesVScrollBar::RecvMouseEnter (int x,
80 int y,
81 unsigned long button_flags,
82 unsigned long key_flags)
83{
84 _entered = true;
85 if (!_drag)
86 {
87 _state = STATE_OVER;
88 NeedRedraw ();
89 }
90}
91
92void
93PlacesVScrollBar::RecvMouseLeave (int x,
94 int y,
95 unsigned long button_flags,
96 unsigned long key_flags)
97{
98 _entered = false;
99 if (!_drag)
100 {
101 _state = STATE_OFF;
102 NeedRedraw ();
103 }
104}
105
106void
107PlacesVScrollBar::RecvMouseDown (int x,
108 int y,
109 unsigned long button_flags,
110 unsigned long key_flags)
111{
112 _state = STATE_DOWN;
113 NeedRedraw ();
114}
115
116void
117PlacesVScrollBar::RecvMouseUp (int x,
118 int y,
119 unsigned long button_flags,
120 unsigned long key_flags)
121{
122 _drag = false;
123 if (_entered)
124 _state = STATE_OVER;
125 else
126 _state = STATE_OFF;
127 NeedRedraw ();
128}
129
130void
131PlacesVScrollBar::RecvMouseDrag (int x,
132 int y,
133 int dx,
134 int dy,
135 unsigned long button_flags,
136 unsigned long key_flags)
137{
138 _drag = true;
139 NeedRedraw ();
140}
141
142void
143PlacesVScrollBar::PreLayoutManagement ()50PlacesVScrollBar::PreLayoutManagement ()
144{51{
145 nux::VScrollBar::PreLayoutManagement ();52 nux::VScrollBar::PreLayoutManagement ();
@@ -166,7 +73,7 @@
166 nux::GetPainter().PaintBackground (gfxContext, base);73 nux::GetPainter().PaintBackground (gfxContext, base);
16774
168 // check if textures have been computed... if they haven't, exit function75 // check if textures have been computed... if they haven't, exit function
169 if (!_slider[STATE_OFF])76 if (!_slider)
170 return;77 return;
17178
172 //texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);79 //texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
@@ -194,7 +101,7 @@
194 slider_geo.y,101 slider_geo.y,
195 slider_geo.width,102 slider_geo.width,
196 slider_geo.height,103 slider_geo.height,
197 _slider[_state]->GetDeviceTexture (),104 _slider->GetDeviceTexture (),
198 texxform,105 texxform,
199 color);106 color);
200 }107 }
@@ -212,145 +119,8 @@
212 nux::CairoGraphics* cairoGraphics = NULL;119 nux::CairoGraphics* cairoGraphics = NULL;
213 cairo_t* cr = NULL;120 cairo_t* cr = NULL;
214 nux::NBitmapData* bitmap = NULL;121 nux::NBitmapData* bitmap = NULL;
215 double half_height = 0.0f;122
216123 // update texture of slider
217 // update texture of off-state of slider
218 width = m_SlideBar->GetBaseWidth ();
219 height = m_SlideBar->GetBaseHeight ();
220 cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);
221 width -= 2 * BLUR_SIZE;
222 height -= 2 * BLUR_SIZE;
223
224 cr = cairoGraphics->GetContext ();
225
226 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
227 cairo_paint (cr);
228
229 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
230 cairo_set_line_width (cr, 1.0f);
231 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.75f);
232 cairoGraphics->DrawRoundedRectangle (cr,
233 1.0f,
234 BLUR_SIZE + 1.5f,
235 BLUR_SIZE + 1.5f,
236 (double) (width - 1) / 2.0f,
237 (double) width - 3.0f,
238 (double) height - 3.0f);
239 cairo_fill_preserve (cr);
240 cairoGraphics->BlurSurface (BLUR_SIZE - 3);
241 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
242 cairo_fill_preserve (cr);
243 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
244 cairo_set_source_rgba (cr, 0.125f, 0.125f, 0.125f, 0.75f);
245 cairo_fill_preserve (cr);
246 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.5f);
247 cairo_stroke (cr);
248
249 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
250 half_height = (double) (height + 2 * BLUR_SIZE) / 2.0f;
251 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height - 2.0f);
252 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height - 2.0f);
253 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height);
254 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height);
255 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height + 2.0f);
256 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height + 2.0f);
257 cairo_stroke (cr);
258
259 //cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/slider_off.png");
260
261 bitmap = cairoGraphics->GetBitmap ();
262
263 if (_slider[STATE_OFF])
264 _slider[STATE_OFF]->UnReference ();
265
266 _slider[STATE_OFF] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
267 _slider[STATE_OFF]->Update (bitmap);
268
269 cairo_destroy (cr);
270 delete bitmap;
271 delete cairoGraphics;
272
273 // update texture of over-state of slider
274 width = m_SlideBar->GetBaseWidth ();
275 height = m_SlideBar->GetBaseHeight ();
276 cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);
277 width -= 2 * BLUR_SIZE;
278 height -= 2 * BLUR_SIZE;
279
280 cr = cairoGraphics->GetContext ();
281
282 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
283 cairo_paint (cr);
284
285 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
286 cairo_set_line_width (cr, 1.0f);
287 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.25f);
288 cairoGraphics->DrawRoundedRectangle (cr,
289 1.0f,
290 BLUR_SIZE + 1.5f,
291 BLUR_SIZE + 1.5f,
292 (double) (width - 1) / 2.0f,
293 (double) width - 3.0f,
294 (double) height - 3.0f);
295
296 cairo_fill_preserve (cr);
297 cairoGraphics->BlurSurface (BLUR_SIZE - 3);
298 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
299 cairo_fill_preserve (cr);
300 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
301
302 cairo_surface_t* tmp_surf = NULL;
303 cairo_t* tmp_cr = NULL;
304 tmp_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 6, 4);
305 tmp_cr = cairo_create (tmp_surf);
306 cairo_set_line_width (tmp_cr, 1.0f);
307 cairo_set_antialias (tmp_cr, CAIRO_ANTIALIAS_NONE);
308 cairo_set_operator (tmp_cr, CAIRO_OPERATOR_CLEAR);
309 cairo_paint (tmp_cr);
310 cairo_set_operator (tmp_cr, CAIRO_OPERATOR_OVER);
311 cairo_set_source_rgba (tmp_cr, 1.0f, 1.0f, 1.0f, 0.25f);
312 cairo_paint (tmp_cr);
313 cairo_set_source_rgba (tmp_cr, 1.0f, 1.0f, 1.0f, 0.5f);
314 cairo_rectangle (tmp_cr, 0.f, 0.f, 1.0f, 1.0f);
315 cairo_rectangle (tmp_cr, 1.f, 1.f, 1.0f, 1.0f);
316 cairo_rectangle (tmp_cr, 2.f, 2.f, 1.0f, 1.0f);
317 cairo_rectangle (tmp_cr, 3.f, 3.f, 1.0f, 1.0f);
318 cairo_rectangle (tmp_cr, 4.f, 0.f, 1.0f, 1.0f);
319 cairo_rectangle (tmp_cr, 5.f, 1.f, 1.0f, 1.0f);
320 cairo_fill (tmp_cr);
321 cairo_destroy (tmp_cr);
322 cairo_set_source_surface (cr, tmp_surf, BLUR_SIZE + 1.5f, BLUR_SIZE + 1.5f);
323 cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
324 //cairo_surface_write_to_png (tmp_surf, "/tmp/tmp_surf.png");
325
326 cairo_fill_preserve (cr);
327 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.5f);
328 cairo_stroke (cr);
329
330 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
331 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height - 2.0f);
332 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height - 2.0f);
333 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height);
334 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height);
335 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height + 2.0f);
336 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height + 2.0f);
337 cairo_stroke (cr);
338
339 //cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/slider_over.png");
340
341 bitmap = cairoGraphics->GetBitmap ();
342
343 if (_slider[STATE_OVER])
344 _slider[STATE_OVER]->UnReference ();
345
346 _slider[STATE_OVER] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
347 _slider[STATE_OVER]->Update (bitmap);
348
349 cairo_destroy (cr);
350 delete bitmap;
351 delete cairoGraphics;
352
353 // update texture of down-state of slider
354 width = m_SlideBar->GetBaseWidth ();124 width = m_SlideBar->GetBaseWidth ();
355 height = m_SlideBar->GetBaseHeight ();125 height = m_SlideBar->GetBaseHeight ();
356 cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);126 cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);
@@ -375,7 +145,7 @@
375 cairoGraphics->BlurSurface (BLUR_SIZE - 3);145 cairoGraphics->BlurSurface (BLUR_SIZE - 3);
376 cairo_fill (cr);146 cairo_fill (cr);
377147
378 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);148 /*cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
379 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);149 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
380 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height - 2.0f);150 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height - 2.0f);
381 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height - 2.0f);151 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height - 2.0f);
@@ -383,17 +153,18 @@
383 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height);153 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height);
384 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height + 2.0f);154 cairo_move_to (cr, BLUR_SIZE + 2.5f, half_height + 2.0f);
385 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height + 2.0f);155 cairo_line_to (cr, BLUR_SIZE + 2.5f + 5.0f, half_height + 2.0f);
386 cairo_stroke (cr);156 cairo_stroke (cr);*/
387157
388 //cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/slider_down.png");158 //cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/slider.png");
389159
390 bitmap = cairoGraphics->GetBitmap ();160 bitmap = cairoGraphics->GetBitmap ();
391161
392 if (_slider[STATE_DOWN])162 if (_slider)
393 _slider[STATE_DOWN]->UnReference ();163 _slider->UnReference ();
394164
395 _slider[STATE_DOWN] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();165 _slider = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
396 _slider[STATE_DOWN]->Update (bitmap);166 if (_slider)
167 _slider->Update (bitmap);
397168
398 cairo_destroy (cr);169 cairo_destroy (cr);
399 delete bitmap;170 delete bitmap;
@@ -437,10 +208,10 @@
437 _track->UnReference ();208 _track->UnReference ();
438209
439 _track = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();210 _track = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
440 _track->Update (bitmap);211 if (_track)
212 _track->Update (bitmap);
441213
442 cairo_destroy (cr);214 cairo_destroy (cr);
443 delete bitmap;215 delete bitmap;
444 delete cairoGraphics;216 delete cairoGraphics;
445 cairo_surface_destroy (tmp_surf);
446}217}
447218
=== modified file 'src/PlacesVScrollBar.h'
--- src/PlacesVScrollBar.h 2011-03-24 02:44:38 +0000
+++ src/PlacesVScrollBar.h 2011-04-13 09:01:38 +0000
@@ -27,47 +27,12 @@
27#include "Nux/VScrollBar.h"27#include "Nux/VScrollBar.h"
28#include "NuxImage/CairoGraphics.h"28#include "NuxImage/CairoGraphics.h"
2929
30typedef enum
31{
32 STATE_OFF = 0,
33 STATE_OVER,
34 STATE_DOWN,
35 STATE_LAST
36} State;
37
38class PlacesVScrollBar : public nux::VScrollBar30class PlacesVScrollBar : public nux::VScrollBar
39{31{
40 public:32 public:
41 PlacesVScrollBar (NUX_FILE_LINE_PROTO);33 PlacesVScrollBar (NUX_FILE_LINE_PROTO);
42 ~PlacesVScrollBar ();34 ~PlacesVScrollBar ();
4335
44 void RecvMouseEnter (int x,
45 int y,
46 unsigned long button_flags,
47 unsigned long key_flags);
48
49 void RecvMouseLeave (int x,
50 int y,
51 unsigned long button_flags,
52 unsigned long key_flags);
53
54 void RecvMouseDown (int x,
55 int y,
56 unsigned long button_flags,
57 unsigned long key_flags);
58
59 void RecvMouseUp (int x,
60 int y,
61 unsigned long button_flags,
62 unsigned long key_flags);
63
64 void RecvMouseDrag (int x,
65 int y,
66 int dx,
67 int dy,
68 unsigned long button_flags,
69 unsigned long key_flags);
70
71 protected:36 protected:
72 virtual void PreLayoutManagement ();37 virtual void PreLayoutManagement ();
73 virtual long PostLayoutManagement (long LayoutResult);38 virtual long PostLayoutManagement (long LayoutResult);
@@ -79,11 +44,8 @@
79 void UpdateTexture ();44 void UpdateTexture ();
8045
81 private:46 private:
82 bool _drag;47 nux::BaseTexture* _slider;
83 bool _entered;48 nux::BaseTexture* _track;
84 State _state;
85 nux::BaseTexture* _slider[STATE_LAST];
86 nux::BaseTexture* _track;
87};49};
8850
89#endif // PLACES_VSCROLLBAR_H51#endif // PLACES_VSCROLLBAR_H