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