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