~lubuntu-software-center-team/lubuntu-software-center/vala-port

« back to all changes in this revision

Viewing changes to src/Widgets/RoundBox.vala

  • Committer: Stephen Smally
  • Date: 2012-03-04 12:59:13 UTC
  • Revision ID: eco.stefi@fastwebnet.it-20120304125913-bk1iutifwoeoyo0i
Worked a lot!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using Gtk;
 
3
using Cairo;
 
4
 
 
5
namespace Lsc.Widgets {
 
6
    public class RoundBox : Box {
 
7
        private Cairo.Context cr;
 
8
        
 
9
        private enum Colors {
 
10
            BACKGROUND,
 
11
            BORDER
 
12
        }
 
13
        
 
14
        public RoundBox (Orientation or, int spacing) {
 
15
            orientation = or;
 
16
            this.spacing = spacing;
 
17
            set_has_window(false);
 
18
        }
 
19
        
 
20
        private void draw_rounded_rectangle (Colors rgb, uint x, uint y, int width, int height, double radius) {
 
21
            if (rgb == Colors.BACKGROUND)
 
22
                cr.set_source_rgb (1, 1, 1);
 
23
            else
 
24
                cr.set_source_rgb (0.8, 0.8, 0.8);
 
25
            
 
26
            cr.new_path();
 
27
            cr.move_to (x + radius, y);
 
28
            cr.arc (width - x - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
 
29
            cr.arc (width - x - radius, height - y - radius, radius, 0, Math.PI * 0.5);
 
30
            cr.arc (x + radius, height - y - radius, radius, Math.PI * 0.5, Math.PI);
 
31
            cr.arc (x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
 
32
            cr.close_path ();
 
33
            
 
34
            cr.fill();
 
35
        }
 
36
        
 
37
        public override bool draw (Cairo.Context cr) {
 
38
            this.cr = cr;
 
39
            
 
40
            int width = get_allocated_width ();
 
41
            int height = get_allocated_height ();
 
42
            double arc_radius = 10.0;
 
43
            
 
44
            draw_rounded_rectangle(Colors.BORDER, 0, 0, width, height, arc_radius);
 
45
            draw_rounded_rectangle(Colors.BACKGROUND, 1, 1, width, height, arc_radius-1);
 
46
            
 
47
            return base.draw(cr);
 
48
        }
 
49
    
 
50
        public override void size_allocate (Allocation allocation) {
 
51
            base.size_allocate (allocation);
 
52
        }
 
53
    }
 
54
}