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