2 Copyright (C) 2008 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "pbd/failed_constructor.h"
23 #include "pbd/file_utils.h"
25 #include "ardour/ardour.h"
26 #include "ardour/filesystem_paths.h"
28 #include "gui_thread.h"
37 using namespace ARDOUR;
39 Splash* Splash::the_splash = 0;
43 assert (the_splash == 0);
45 std::string splash_file;
47 if (!find_file_in_search_path (ardour_data_search_path(), "splash.png", splash_file)) {
48 cerr << "Cannot find splash screen image file\n";
49 throw failed_constructor();
53 pixbuf = Gdk::Pixbuf::create_from_file (splash_file);
57 cerr << "Cannot construct splash screen image\n";
58 throw failed_constructor();
61 darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
63 set_position (WIN_POS_CENTER);
64 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
65 darea.set_double_buffered (false);
67 layout = create_pango_layout ("");
69 string i18n = string_compose (_("%1 loading ..."), PROGRAM_NAME);
73 layout->set_markup (str);
76 darea.signal_expose_event().connect (sigc::mem_fun (*this, &Splash::expose));
80 set_default_size (pixbuf->get_width(), pixbuf->get_height());
81 set_resizable (false);
82 set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
87 ARDOUR::BootMessage.connect (msg_connection, invalidator (*this), boost::bind (&Splash::boot_message, this, _1), gui_context());
96 Splash::pop_back_for (Gtk::Window& win)
98 set_keep_above (false);
99 get_window()->restack (win.get_window(), false);
100 win.signal_hide().connect (sigc::mem_fun (*this, &Splash::pop_front));
106 set_keep_above (true);
110 Splash::on_realize ()
112 Window::on_realize ();
113 get_window()->set_decorations (Gdk::WMDecoration(0));
114 layout->set_font_description (get_style()->get_font());
118 Splash::on_button_release_event (GdkEventButton* ev)
120 RefPtr<Gdk::Window> window = get_window();
122 if (!window || ev->window != window->gobj()) {
131 Splash::expose (GdkEventExpose* ev)
133 RefPtr<Gdk::Window> window = darea.get_window();
135 /* note: height & width need to be constrained to the pixbuf size
136 in case a WM provides us with a screwy allocation
139 window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
140 ev->area.x, ev->area.y,
141 ev->area.x, ev->area.y,
142 min ((pixbuf->get_width() - ev->area.x), ev->area.width),
143 min ((pixbuf->get_height() - ev->area.y), ev->area.height),
144 Gdk::RGB_DITHER_NONE, 0, 0);
146 Glib::RefPtr<Gtk::Style> style = darea.get_style();
147 Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
149 window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
151 /* this must execute AFTER the GDK idle update mechanism
154 Glib::signal_idle().connect (sigc::mem_fun (this, &Splash::idle_after_expose),
155 GDK_PRIORITY_REDRAW+2);
161 Splash::boot_message (std::string msg)
167 Splash::idle_after_expose ()
176 bool was_mapped = is_mapped ();
186 while (!expose_done) {
187 gtk_main_iteration ();
193 Splash::message (const string& msg)
196 str += Glib::Markup::escape_text (msg);
199 layout->set_markup (str);
200 Glib::RefPtr<Gdk::Window> win = darea.get_window();
205 if (win->is_visible ()) {
206 win->invalidate_rect (Gdk::Rectangle (0, darea.get_height() - 30, darea.get_width(), 30), true);
211 while (!expose_done) {
212 gtk_main_iteration ();