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