push2: null handle on failed open
[ardour.git] / libs / surfaces / push2 / splash.cc
1 /*
2   Copyright (C) 2016 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #include <pangomm/layout.h>
20
21 #include "pbd/compose.h"
22 #include "pbd/failed_constructor.h"
23 #include "pbd/file_utils.h"
24 #include "pbd/i18n.h"
25 #include "pbd/search_path.h"
26
27 #include "ardour/debug.h"
28 #include "ardour/filesystem_paths.h"
29
30 #include "splash.h"
31
32 using namespace ARDOUR;
33 using namespace PBD;
34 using namespace std;
35 using namespace ArdourSurface;
36 using namespace ArdourCanvas;
37
38 SplashLayout::SplashLayout (Push2& p, Session& s)
39         : Push2Layout (p, s)
40 {
41         std::string splash_file;
42
43         Searchpath rc (ARDOUR::ardour_data_search_path());
44         rc.add_subdirectory_to_paths ("resources");
45
46         if (!find_file (rc, PROGRAM_NAME "-splash.png", splash_file)) {
47                 cerr << "Cannot find splash screen image file\n";
48                 throw failed_constructor();
49         }
50
51         img = Cairo::ImageSurface::create_from_png (splash_file);
52 }
53
54 SplashLayout::~SplashLayout ()
55 {
56 }
57
58 void
59 SplashLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
60 {
61         DEBUG_TRACE (DEBUG::Push2, string_compose ("splash render %1\n", area));
62
63         int rows = display_height ();
64         int cols = display_width ();
65
66         double x_ratio = (double) img->get_width() / (cols - 20);
67         double y_ratio = (double) img->get_height() / (rows - 20);
68         double scale = min (x_ratio, y_ratio);
69
70         /* background */
71
72         context->set_source_rgb (0.764, 0.882, 0.882);
73         context->paint ();
74
75         /* image */
76
77         context->save ();
78         context->translate (5, 5);
79         context->scale (scale, scale);
80         context->set_source (img, 0, 0);
81         context->paint ();
82         context->restore ();
83
84         /* text */
85
86         Glib::RefPtr<Pango::Layout> some_text = Pango::Layout::create (context);
87
88         Pango::FontDescription fd ("Sans 38");
89         some_text->set_font_description (fd);
90         some_text->set_text (string_compose ("%1 %2", PROGRAM_NAME, VERSIONSTRING));
91
92         context->move_to (200, 10);
93         context->set_source_rgb (0, 0, 0);
94         some_text->update_from_cairo_context (context);
95         some_text->show_in_cairo_context (context);
96
97         Pango::FontDescription fd2 ("Sans Italic 18");
98         some_text->set_font_description (fd2);
99         some_text->set_text (_("Ableton Push 2 Support"));
100
101         context->move_to (200, 80);
102         context->set_source_rgb (0, 0, 0);
103         some_text->update_from_cairo_context (context);
104         some_text->show_in_cairo_context (context);
105 }