~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/gtkmm2ext/cairo_packer.cc

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2012 Paul Davis 
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
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, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 
 
18
*/
 
19
 
 
20
#include "gtkmm2ext/utils.h"
 
21
#include "gtkmm2ext/cairo_widget.h"
 
22
#include "gtkmm2ext/cairo_packer.h"
 
23
 
 
24
void
 
25
CairoPacker::draw_background (Gtk::Widget& w, GdkEventExpose*)
 
26
{
 
27
        int x, y;
 
28
        Gtk::Widget* window_parent;
 
29
        Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (w, &window_parent);
 
30
        
 
31
        if (win) {
 
32
                
 
33
                Cairo::RefPtr<Cairo::Context> context = win->create_cairo_context();
 
34
                w.translate_coordinates (*window_parent, 0, 0, x, y);
 
35
 
 
36
                Gdk::Color bg = get_bg ();
 
37
 
 
38
                context->set_source_rgba (bg.get_red_p(), bg.get_green_p(), bg.get_blue_p(), 1.0);
 
39
                Gtkmm2ext::rounded_rectangle (context, x, y, w.get_allocation().get_width(), w.get_allocation().get_height(), 4);
 
40
                context->fill ();
 
41
        }
 
42
}
 
43
 
 
44
CairoHPacker::CairoHPacker ()
 
45
{
 
46
}
 
47
 
 
48
void
 
49
CairoHPacker::on_realize ()
 
50
{
 
51
        HBox::on_realize ();
 
52
        CairoWidget::provide_background_for_cairo_widget (*this, get_bg ());
 
53
}
 
54
 
 
55
Gdk::Color
 
56
CairoHPacker::get_bg () const
 
57
{
 
58
        return get_style()->get_bg (Gtk::STATE_NORMAL);
 
59
}
 
60
 
 
61
bool
 
62
CairoHPacker::on_expose_event (GdkEventExpose* ev)
 
63
{
 
64
        draw_background (*this, ev);
 
65
        return HBox::on_expose_event (ev);
 
66
}
 
67
 
 
68
CairoVPacker::CairoVPacker ()
 
69
{
 
70
}
 
71
 
 
72
bool
 
73
CairoVPacker::on_expose_event (GdkEventExpose* ev)
 
74
{
 
75
        draw_background (*this, ev);
 
76
        return VBox::on_expose_event (ev);
 
77
}
 
78
 
 
79
void
 
80
CairoVPacker::on_realize ()
 
81
{
 
82
        VBox::on_realize ();
 
83
        CairoWidget::provide_background_for_cairo_widget (*this, get_bg());
 
84
}
 
85
 
 
86
Gdk::Color
 
87
CairoVPacker::get_bg () const
 
88
{
 
89
        return get_style()->get_bg (Gtk::STATE_NORMAL);
 
90
}