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