9317ec1caa48913bfad17f029b50fec7feb3a822
[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 ()
18 {
19         sys::path splash_file;
20
21         if (!find_file_in_search_path (ardour_search_path(), "splash.png", splash_file)) {
22                 throw failed_constructor();
23         }
24
25         try {
26                 pixbuf = Gdk::Pixbuf::create_from_file (splash_file.to_string());
27         }
28
29         catch (...) {
30                 throw failed_constructor();
31         }
32         
33         darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
34         set_keep_above (true);
35         set_position (WIN_POS_CENTER);
36         darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
37
38         layout = create_pango_layout ("");
39         string str = "<b>";
40         string i18n = _("Ardour loading ...");
41         str += i18n;
42         str += "</b>";
43
44         layout->set_markup (str);
45
46         darea.show ();
47         darea.signal_expose_event().connect (mem_fun (*this, &Splash::expose));
48
49         add (darea);
50 }
51
52 void
53 Splash::on_realize ()
54 {
55         Window::on_realize ();
56         get_window()->set_decorations (Gdk::WMDecoration(0));
57         layout->set_font_description (get_style()->get_font());
58 }
59
60
61 bool
62 Splash::on_button_release_event (GdkEventButton* ev)
63 {
64         hide ();
65         return true;
66 }
67
68 bool
69 Splash::expose (GdkEventExpose* ev)
70 {
71         RefPtr<Gdk::Window> window = darea.get_window();
72
73         window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
74                              ev->area.x, ev->area.y,
75                              ev->area.x, ev->area.y,
76                              ev->area.width, ev->area.height,
77                              Gdk::RGB_DITHER_NONE, 0, 0);
78
79         Glib::RefPtr<Gtk::Style> style = darea.get_style();
80         Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
81
82         window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
83
84         return true;
85 }
86
87 void
88 Splash::message (const string& msg)
89 {
90         string str ("<b>");
91         str += msg;
92         str += "</b>";
93
94         layout->set_markup (str);
95         darea.queue_draw ();
96         get_window()->process_updates (true);
97 }