Source

pino3 / src / bg_box.vala

Full commit
tro...@gmail.com d68bc1a 







































tro...@gmail.com c5b23a6 
tro...@gmail.com d68bc1a 

















tro...@gmail.com c5b23a6 
tro...@gmail.com d68bc1a 














using Gtk;
using Cairo;


/** Just for custom background */
public class BgBox : HBox {
	
	public bool fresh {get; set; default = false;}
	private const double MAX_RGB = (double) uint16.MAX;
	
	public BgBox(bool homogeneous, int spacing) {
		GLib.Object(homogeneous: homogeneous, spacing: spacing);
		
		//when we fresh or not
		notify["fresh"].connect((s) => {
			redraw();
		});
	}
	
	public override bool expose_event(Gdk.EventExpose event) {
		if(fresh) {
			Context ctx = Gdk.cairo_create(this.window);
			Gdk.Color color = Gdk.Color();
			Gdk.Color.parse("blue", out color);
			
			ctx.set_source_rgba(color.red / MAX_RGB, color.green / MAX_RGB,
					color.blue / MAX_RGB, 0.5);
			
			Allocation alloc;
			get_allocation(out alloc);
			
			Gdk.cairo_rectangle(ctx, {0, 0, alloc.width, alloc.height});
			
			Cairo.Pattern grad = new Cairo.Pattern.linear(10, 0, 10, alloc.height);
			grad.add_color_stop_rgb(0, 233/256.0, 249/256.0, 234/256.0);
			grad.add_color_stop_rgb(1, 1, 1, 1);
			ctx.set_source(grad);
			
			ctx.fill();
		} else {
			/*
			Context ctx = Gdk.cairo_create(this.window);
			//Gdk.Color color = Gdk.Color();
			//Gdk.Color.parse("blue", out color);
			
			//ctx.set_source_rgba(color.red / MAX_RGB, color.green / MAX_RGB,
			//		color.blue / MAX_RGB, 0.5);
			
			Allocation alloc;
			get_allocation(out alloc);
			
			Gdk.cairo_rectangle(ctx, {0, 0, alloc.width, alloc.height});
			
			Cairo.Pattern grad = new Cairo.Pattern.linear(10, 0, 10, alloc.height);
			grad.add_color_stop_rgb(0, 1, 1, 1);
			grad.add_color_stop_rgb(1, 233/256.0, 233/256.0, 233/256.0);
			ctx.set_source(grad);
			
			ctx.fill();
			*/
		}
		
		base.expose_event(event);
		
		return false;
	}
	
	private void redraw() {
		if (null == this.window)
			return;

		unowned Gdk.Region region = this.window.get_clip_region ();
		this.window.invalidate_region (region, true);
		this.window.process_updates (true);
    }
}