Merge with 2.0-ongoing R2988
[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 "splash.h"
9
10 #include "i18n.h"
11
12 using namespace Gtk;
13 using namespace Glib;
14 using namespace std;
15 using namespace ARDOUR;
16
17 Splash* Splash::the_splash = 0;
18
19 Splash::Splash ()
20 {
21         sys::path splash_file;
22
23         if (!find_file_in_search_path (ardour_search_path(), "splash.png", splash_file)) {
24                 throw failed_constructor();
25         }
26
27         try {
28                 pixbuf = Gdk::Pixbuf::create_from_file (splash_file.to_string());
29         }
30
31         catch (...) {
32                 throw failed_constructor();
33         }
34         
35         darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
36         set_keep_above (true);
37         set_position (WIN_POS_CENTER);
38         darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
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         the_splash = this;
54 }
55
56 void
57 Splash::pop_back ()
58 {
59         set_keep_above (false);
60 }
61
62 void
63 Splash::on_realize ()
64 {
65         Window::on_realize ();
66         get_window()->set_decorations (Gdk::WMDecoration(0));
67         layout->set_font_description (get_style()->get_font());
68 }
69
70
71 bool
72 Splash::on_button_release_event (GdkEventButton* ev)
73 {
74         hide ();
75         return true;
76 }
77
78 bool
79 Splash::expose (GdkEventExpose* ev)
80 {
81         RefPtr<Gdk::Window> window = darea.get_window();
82
83         window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
84                              ev->area.x, ev->area.y,
85                              ev->area.x, ev->area.y,
86                              ev->area.width, ev->area.height,
87                              Gdk::RGB_DITHER_NONE, 0, 0);
88
89         Glib::RefPtr<Gtk::Style> style = darea.get_style();
90         Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
91
92         window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
93
94         return true;
95 }
96
97 void
98 Splash::message (const string& msg)
99 {
100         string str ("<b>");
101         str += msg;
102         str += "</b>";
103
104         layout->set_markup (str);
105         darea.queue_draw ();
106         get_window()->process_updates (true);
107 }