Merge with 2.0-ongoing R2943.
[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_type_hint (Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
35         set_keep_above (true);
36         set_position (WIN_POS_CENTER);
37         darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
38
39         layout = create_pango_layout ("");
40
41         darea.show ();
42         darea.signal_expose_event().connect (mem_fun (*this, &Splash::expose));
43
44         add (darea);
45 }
46
47 void
48 Splash::on_realize ()
49 {
50         Window::on_realize ();
51         layout->set_font_description (get_style()->get_font());
52 }
53
54
55 bool
56 Splash::on_button_release_event (GdkEventButton* ev)
57 {
58         hide ();
59         return true;
60 }
61
62 bool
63 Splash::expose (GdkEventExpose* ev)
64 {
65         RefPtr<Gdk::Window> window = darea.get_window();
66
67         window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
68                              ev->area.x, ev->area.y,
69                              ev->area.x, ev->area.y,
70                              ev->area.width, ev->area.height,
71                              Gdk::RGB_DITHER_NONE, 0, 0);
72
73         Glib::RefPtr<Gtk::Style> style = darea.get_style();
74         Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
75
76         window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
77
78         return true;
79 }
80
81 void
82 Splash::message (const string& msg)
83 {
84         string str ("<b>");
85         str += msg;
86         str += "</b>";
87
88         layout->set_markup (str);
89         darea.queue_draw ();
90         get_window()->process_updates (true);
91 }