2020-11-17 11:16:16 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001-2006, William Joseph.
|
|
|
|
All Rights Reserved.
|
|
|
|
|
|
|
|
This file is part of GtkRadiant.
|
|
|
|
|
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "image.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "string/string.h"
|
|
|
|
#include "stream/stringstream.h"
|
|
|
|
#include "stream/textstream.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
2021-08-04 20:23:18 +00:00
|
|
|
CopiedString g_bitmapsPath;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitmapsPath_set(const char *path)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
g_bitmapsPath = path;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GdkPixbuf *pixbuf_new_from_file_with_mask(const char *filename)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
GdkPixbuf *rgb = gdk_pixbuf_new_from_file(filename, 0);
|
|
|
|
if (rgb == 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
GdkPixbuf *rgba = gdk_pixbuf_add_alpha(rgb, FALSE, 255, 0, 255);
|
|
|
|
g_object_unref(rgb);
|
|
|
|
return rgba;
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Image image_new_from_file_with_mask(const char *filename)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
GdkPixbuf *rgba = pixbuf_new_from_file_with_mask(filename);
|
|
|
|
if (rgba == 0) {
|
|
|
|
return ui::Image(ui::null);
|
|
|
|
} else {
|
|
|
|
auto image = ui::Image::from(gtk_image_new_from_pixbuf(rgba));
|
|
|
|
g_object_unref(rgba);
|
|
|
|
return image;
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Image image_new_missing()
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
return ui::Image::from(gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_SMALL_TOOLBAR));
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Image new_image(const char *filename)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
if (auto image = image_new_from_file_with_mask(filename)) {
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
return image_new_missing();
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Image new_local_image(const char *filename)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
StringOutputStream fullPath(256);
|
|
|
|
fullPath << g_bitmapsPath.c_str() << filename;
|
|
|
|
return new_image(fullPath.c_str());
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|