splash updating on gdk/quartz; more filtering of automatable AU parameters
[ardour.git] / gtk2_ardour / splash.cc
1 #include <string>
2
3 #include <pbd/failed_constructor.h>
4 #include <ardour/ardour.h>
5
6 #include "gui_thread.h"
7 #include "splash.h"
8
9 #include "i18n.h"
10
11 using namespace Gtk;
12 using namespace Glib;
13 using namespace std;
14 using namespace ARDOUR;
15
16 Splash* Splash::the_splash = 0;
17
18 Splash::Splash ()
19 {
20         string path = find_data_file ("splash.png");
21
22         if (path.empty()) {
23                 throw failed_constructor();
24         }
25
26         try {
27                 pixbuf = Gdk::Pixbuf::create_from_file (path);
28         }
29
30         catch (...) {
31                 throw failed_constructor();
32         }
33         
34         darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
35         set_keep_above (true);
36         set_position (WIN_POS_CENTER);
37         darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
38         darea.set_double_buffered (false);
39
40         layout = create_pango_layout ("");
41         string str = "<b>";
42         string i18n = _("Ardour loading ...");
43         str += i18n;
44         str += "</b>";
45
46         layout->set_markup (str);
47
48         darea.show ();
49         darea.signal_expose_event().connect (mem_fun (*this, &Splash::expose));
50
51         add (darea);
52
53         set_default_size (pixbuf->get_width(), pixbuf->get_height());
54         the_splash = this;
55
56         ARDOUR::BootMessage.connect (mem_fun (*this, &Splash::boot_message));
57 }
58
59 void
60 Splash::pop_back ()
61 {
62         set_keep_above (false);
63 }
64
65 void
66 Splash::on_realize ()
67 {
68         Window::on_realize ();
69         get_window()->set_decorations (Gdk::WMDecoration(0));
70         layout->set_font_description (get_style()->get_font());
71 }
72
73
74 bool
75 Splash::on_button_release_event (GdkEventButton* ev)
76 {
77         hide ();
78         return true;
79 }
80
81 bool
82 Splash::expose (GdkEventExpose* ev)
83 {
84         RefPtr<Gdk::Window> window = darea.get_window();
85
86         /* note: height & width need to be constrained to the pixbuf size
87            in case a WM provides us with a screwy allocation
88         */
89
90         window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
91                              ev->area.x, ev->area.y,
92                              ev->area.x, ev->area.y,
93                              min ((pixbuf->get_width() - ev->area.x), ev->area.width), 
94                              min ((pixbuf->get_height() - ev->area.y), ev->area.height),
95                              Gdk::RGB_DITHER_NONE, 0, 0);
96         
97         Glib::RefPtr<Gtk::Style> style = darea.get_style();
98         Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
99
100         window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
101
102         return true;
103 }
104
105 void
106 Splash::boot_message (std::string msg)
107 {
108         message (msg);
109 }
110
111 void
112 Splash::message (const string& msg)
113 {
114         string str ("<b>");
115         str += msg;
116         str += "</b>";
117
118         layout->set_markup (str);
119         darea.queue_draw ();
120         
121         Glib::RefPtr<Gdk::Window> win = darea.get_window();
122         if (win) {
123                 win->process_updates (true);
124                 gdk_flush ();
125         }
126 }