1
//---------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2012 LenMus project
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation,
7
// either version 3 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program. If not, see <http://www.gnu.org/licenses/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//---------------------------------------------------------------------------------------
21
#include "lenmus_art_provider.h"
23
#include "lenmus_injectors.h"
24
#include "lenmus_paths.h"
26
#include <wx/wxprec.h>
33
// images to use when error in opening a PNG file
34
static const char *error_16_xpm[] = {
35
/* columns rows colors chars-per-pixel */
58
/* TODO: Can this be removed? */
59
static const char *null_xpm[] = {
60
/* columns rows colors chars-per-pixel */
86
//---------------------------------------------------------------------------------------
87
ArtProvider::ArtProvider(ApplicationScope& appScope)
88
: m_appScope(appScope)
92
//---------------------------------------------------------------------------------------
93
// resources are identified by an wxArtId. It is just a string.
94
wxFileName ArtProvider::get_filepath(const wxArtID& id, const wxArtClient& client,
97
Paths* pPaths = m_appScope.get_paths();
98
wxString sPath = pPaths->GetImagePath();
101
//set size. 16x16 is the default
102
wxString sSize = _T("_16.png");
103
if (size.GetHeight() == size.GetWidth())
105
if (size.GetHeight() == 24) {
106
sSize = _T("_24.png");
108
else if (size.GetHeight() == 32) {
109
sSize = _T("_32.png");
111
else if (size.GetHeight() == 22) {
112
sSize = _T("_22.png");
114
else if (size.GetHeight() == 48) {
115
sSize = _T("_48.png");
119
sSize = wxString::Format(_T("_%dx%d.png"), size.GetWidth(), size.GetHeight());
121
//icon for text book controller
122
if ( client == wxART_HELP_BROWSER ) {
123
if ( id == wxART_HELP ) {
124
return wxFileName(_T("null"));
128
//TextBookController buttons
129
if ( id == wxART_ADD_BOOKMARK ) {
130
return wxFileName(_T("null"));
132
else if ( id == wxART_DEL_BOOKMARK ) {
133
return wxFileName(_T("null"));
135
else if ( id == wxART_ERROR ) {
136
sFile = _T("msg_error");
138
else if ( id == wxART_FILE_OPEN ) {
139
return wxFileName(_T("null"));
141
else if ( id == wxART_GO_BACK ) {
142
sFile = _T("tool_previous");
144
else if ( id == wxART_GO_FORWARD ) {
145
sFile = _T("tool_next");
147
else if ( id == wxART_GO_TO_PARENT ) {
148
return wxFileName(_T("null"));
150
else if ( id == wxART_GO_UP ) {
151
sFile = _T("tool_page_previous");
153
else if ( id == wxART_GO_DOWN ) {
154
sFile = _T("tool_page_next");
156
else if ( id == wxART_HELP_BOOK ) {
157
sFile = _T("app_book");
159
else if ( id == wxART_HELP_FOLDER ) {
160
sFile = _T("app_book");
162
else if ( id == wxART_HELP_PAGE ) {
163
return wxFileName(_T("null"));
165
else if ( id == wxART_HELP_SETTINGS ) {
166
sFile = _T("tool_font_size");
168
else if ( id == wxART_HELP_SIDE_PANEL ) {
169
sFile = _T("tool_index_panel");
171
else if ( id == wxART_INFORMATION ) {
172
sFile = _T("msg_info");
174
else if ( id == wxART_PRINT ) {
175
sFile = _T("tool_print");
177
else if ( id == wxART_WARNING ) {
178
sFile = _T("msg_info");
182
else if (id.Left(5) == _T("tool_")) {
185
else if (id.Left(4) == _T("msg_")) {
188
else if (id.Left(4) == _T("opt_")) {
191
else if (id.Left(7) == _T("button_")) {
194
else if (id.Left(8) == _T("welcome_")) {
200
else if (id == _T("backgrnd")) {
201
sFile = _T("backgrnd");
204
else if (id == _T("app_icon")) {
205
sFile = _T("app_icon");
208
else if (id == _T("app_splash")) {
209
sFile = _T("splash");
212
else if (id == _T("banner_updater")) {
213
sFile = _T("UpdaterBanner");
216
else if (id == _T("logo50x67")) {
217
sFile = _T("logo50x67");
220
else if (id == _T("preview")) {
221
sFile = _T("preview");
224
else if (id == _T("right_answers")) {
225
sFile = _T("right_answers");
226
sSize = _T("_24.png");
228
else if (id == _T("wrong_answers")) {
229
sFile = _T("wrong_answers");
230
sSize = _T("_24.png");
232
else if (id == _T("total_marks")) {
233
sFile = _T("total_marks");
234
sSize = _T("_24.png");
241
return wxFileName(sPath, sFile + sSize, wxPATH_NATIVE);
244
//---------------------------------------------------------------------------------------
245
wxBitmap ArtProvider::CreateBitmap(const wxArtID& id,
246
const wxArtClient& client,
249
wxImage image = get_image(id, client, size);
250
return wxBitmap(image);
253
//---------------------------------------------------------------------------------------
254
wxImage ArtProvider::get_image(const wxArtID& id, const wxArtClient& client,
257
wxFileName oFilename = get_filepath(id, client, size);
259
if (oFilename.GetFullPath() == _T("null"))
261
wxBitmap oBitmap(null_xpm);
262
return oBitmap.ConvertToImage();
266
if (image.LoadFile(oFilename.GetFullPath(), wxBITMAP_TYPE_PNG))
270
// if file not found we need to return something. Otherwise, for tool bars
271
// and other objects a crash will be produced
272
wxLogMessage(_T("[ArtProvider::CreateImage] File %s not found. Error icon returned"),
273
oFilename.GetFullPath().c_str() );
274
wxBitmap oBitmap(error_16_xpm);
275
return oBitmap.ConvertToImage();