ardour
cairo_packer.cc
Go to the documentation of this file.
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 
45 {
46 }
47 
48 void
50 {
51  HBox::on_realize ();
53 }
54 
55 Gdk::Color
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 
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
81 {
82  VBox::on_realize ();
84 }
85 
86 Gdk::Color
88 {
89  return get_style()->get_bg (Gtk::STATE_NORMAL);
90 }
LIBGTKMM2EXT_API Glib::RefPtr< Gdk::Window > window_to_draw_on(Gtk::Widget &w, Gtk::Widget **parent)
Definition: utils.cc:676
Gdk::Color get_bg() const
Definition: cairo_packer.cc:56
virtual void draw_background(Gtk::Widget &, GdkEventExpose *)
Definition: cairo_packer.cc:25
void on_realize()
Definition: cairo_packer.cc:49
Gdk::Color get_bg() const
Definition: cairo_packer.cc:87
bool on_expose_event(GdkEventExpose *)
Definition: cairo_packer.cc:73
LIBGTKMM2EXT_API void rounded_rectangle(Cairo::RefPtr< Cairo::Context > context, double x, double y, double w, double h, double r=10)
Definition: utils.cc:520
virtual Gdk::Color get_bg() const =0
bool on_expose_event(GdkEventExpose *)
Definition: cairo_packer.cc:62
void on_realize()
Definition: cairo_packer.cc:80
static void provide_background_for_cairo_widget(Gtk::Widget &w, const Gdk::Color &bg)