Made icon loading more robust, and tidied up some code

This commit is contained in:
Joel Holdsworth 2008-08-13 19:15:13 +01:00
parent f0b30ff3f9
commit 833404c27b
15 changed files with 244 additions and 196 deletions

View file

@ -34,21 +34,21 @@ iconcommand = python $(top_srcdir)/admin/render-icon.py
lumigui_DEPENDENCIES += \
rsvg-convert \
$(16x16)/arrow.png $(22x22)/arrow.png $(24x24)/arrow.png $(32x32)/arrow.png $(48x48)/arrow.png \
$(16x16)/i-beam.png $(22x22)/i-beam.png $(24x24)/i-beam.png $(32x32)/i-beam.png $(48x48)/i-beam.png \
$(16x16)/assets-panel.png \
$(16x16)/timeline-panel.png \
$(16x16)/viewer-panel.png
$(16x16)/tool-arrow.png $(22x22)/tool-arrow.png $(24x24)/tool-arrow.png $(32x32)/tool-arrow.png $(48x48)/tool-arrow.png \
$(16x16)/tool-i-beam.png $(22x22)/tool-i-beam.png $(24x24)/tool-i-beam.png $(32x32)/tool-i-beam.png $(48x48)/tool-i-beam.png \
$(16x16)/panel-assets.png \
$(16x16)/panel-timeline.png \
$(16x16)/panel-viewer.png
$(16x16)/arrow.png $(22x22)/arrow.png $(24x24)/arrow.png $(32x32)/arrow.png $(48x48)/arrow.png : $(svgdir)/arrow.svg
$(16x16)/tool-arrow.png $(22x22)/tool-arrow.png $(24x24)/tool-arrow.png $(32x32)/tool-arrow.png $(48x48)/tool-arrow.png : $(svgdir)/tool-arrow.svg
$(iconcommand) $< $(icondir)
$(16x16)/i-beam.png $(22x22)/i-beam.png $(24x24)/i-beam.png $(32x32)/i-beam.png $(48x48)/i-beam.png : $(svgdir)/i-beam.svg
$(16x16)/tool-i-beam.png $(22x22)/tool-i-beam.png $(24x24)/tool-i-beam.png $(32x32)/tool-i-beam.png $(48x48)/tool-i-beam.png : $(svgdir)/tool-i-beam.svg
$(iconcommand) $< $(icondir)
$(16x16)/assets-panel.png:
cp $(16x16pre)/assets-panel.png $(16x16)
$(16x16)/timeline-panel.png:
cp $(16x16pre)/timeline-panel.png $(16x16)
$(16x16)/viewer-panel.png:
cp $(16x16pre)/viewer-panel.png $(16x16)
$(16x16)/panel-assets.png:
cp $(16x16pre)/panel-assets.png $(16x16)
$(16x16)/panel-timeline.png:
cp $(16x16pre)/panel-timeline.png $(16x16)
$(16x16)/panel-viewer.png:
cp $(16x16pre)/panel-viewer.png $(16x16)

View file

Before

Width:  |  Height:  |  Size: 540 B

After

Width:  |  Height:  |  Size: 540 B

View file

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 453 B

View file

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 631 B

View file

@ -15,7 +15,7 @@
sodipodi:version="0.32"
inkscape:version="0.46"
version="1.0"
sodipodi:docname="arrow.svg"
sodipodi:docname="tool-arrow.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs4">
@ -522,10 +522,10 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.6568543"
inkscape:cx="90.247594"
inkscape:cx="64.614973"
inkscape:cy="46.534319"
inkscape:document-units="px"
inkscape:current-layer="layer4"
inkscape:current-layer="layer3"
showgrid="true"
inkscape:snap-nodes="false"
inkscape:snap-bbox="true"
@ -559,7 +559,7 @@
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="artwork:arrow"
inkscape:label="artwork:tool-arrow"
style="display:inline">
<path
transform="matrix(0.989175,0,0,1.31555,167.22388,56.536408)"

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View file

@ -15,7 +15,7 @@
sodipodi:version="0.32"
inkscape:version="0.46"
version="1.0"
sodipodi:docname="i-beam.svg"
sodipodi:docname="tool-i-beam.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs4">
@ -592,7 +592,7 @@
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="artwork:i-beam"
inkscape:label="artwork:tool-i-beam"
style="display:inline">
<path
transform="matrix(0.989175,0,0,1.31555,164.72395,56.536408)"

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View file

@ -35,6 +35,7 @@
NOBUG_CPP_DEFINE_FLAG(gui);
using namespace Gtk;
using namespace Glib;
using namespace lumiera::gui;
using namespace lumiera::gui::workspace;
using namespace lumiera::gui::model;
@ -43,39 +44,47 @@ GtkLumiera the_application;
int
main (int argc, char *argv[])
{
return the_application.main(argc, argv);
}
{
return the_application.main(argc, argv);
}
namespace lumiera {
namespace gui {
int
GtkLumiera::main(int argc, char *argv[])
{
NOBUG_INIT;
int
GtkLumiera::main(int argc, char *argv[])
{
NOBUG_INIT;
Main kit(argc, argv);
Main kit(argc, argv);
Glib::set_application_name(AppTitle);
Glib::set_application_name(AppTitle);
Project project;
WindowManager window_manager;
Project project;
WindowManager window_manager;
window_manager.set_theme("lumiera_ui.rc");
window_manager.set_theme("lumiera_ui.rc");
WorkspaceWindow main_window(&project);
kit.run(main_window);
}
WorkspaceWindow main_window(&project);
GtkLumiera&
application()
{
return the_application;
}
kit.run(main_window);
}
Glib::ustring
GtkLumiera::get_home_data_path()
{
const ustring app_name("lumiera");
const ustring path(Glib::get_home_dir());
return ustring::compose("%1/.%2", path, app_name);
}
GtkLumiera&
application()
{
return the_application;
}
} // namespace gui
} // namespace lumiera

View file

@ -53,49 +53,51 @@ NOBUG_DECLARE_FLAG(gui);
namespace lumiera {
namespace gui {
/**
* The name of the application
*/
static const gchar* AppTitle = "Lumiera";
/**
* The name of the application
*/
static const gchar* AppTitle = "Lumiera";
/**
* The version number of the application
*/
static const gchar* AppVersion = N_("0.1-dev");
/**
* The version number of the application
*/
static const gchar* AppVersion = N_("0.1-dev");
/**
* The copyright of the application
*/
static const gchar* AppCopyright = N_("© 2008 The Lumiera Team");
/**
* The copyright of the application
*/
static const gchar* AppCopyright = N_("© 2008 The Lumiera Team");
/**
* The website of the application
*/
static const gchar* AppWebsite = "www.lumiera.org";
/**
* The website of the application
*/
static const gchar* AppWebsite = "www.lumiera.org";
/**
* An alphabetical list of the application's authors
*/
static const gchar* AppAuthors[] = {
"Joel Holdsworth",
"Christian Thaeter",
"Hermann Vosseler",
"<Other Authors Here>"};
/**
* An alphabetical list of the application's authors
*/
static const gchar* AppAuthors[] = {
"Joel Holdsworth",
"Christian Thaeter",
"Hermann Vosseler",
"<Other Authors Here>"};
/**
* The main application class.
*/
class GtkLumiera
{
public:
int main(int argc, char *argv[]);
/**
* The main application class.
*/
class GtkLumiera
{
public:
int main(int argc, char *argv[]);
static Glib::ustring get_home_data_path();
};
};
/**
* Returns a reference to the global application object
*/
GtkLumiera& application();
/**
* Returns a reference to the global application object
*/
GtkLumiera& application();
} // namespace gui
} // namespace lumiera

View file

@ -28,7 +28,7 @@ namespace gui {
namespace panels {
AssetsPanel::AssetsPanel() :
Panel("assets", _("Assets"), "assets_panel"),
Panel("assets", _("Assets"), "panel_assets"),
placeholder("Placeholder label. Is this supposed to be titled assets\nas in the proc layer? or resources\nas in cinelerra?")
{
pack_start(placeholder);

View file

@ -34,9 +34,9 @@ namespace panels {
const int TimelinePanel::ZoomToolSteps = 2; // 2 seems comfortable
TimelinePanel::TimelinePanel() :
Panel("timeline", _("Timeline"), "timeline_panel"),
arrowTool(Gtk::StockID("arrow")),
iBeamTool(Gtk::StockID("i_beam")),
Panel("timeline", _("Timeline"), "panel_timeline"),
arrowTool(Gtk::StockID("tool_arrow")),
iBeamTool(Gtk::StockID("tool_i_beam")),
zoomIn(Stock::ZOOM_IN),
zoomOut(Stock::ZOOM_OUT),
updatingToolbar(false)

View file

@ -31,7 +31,7 @@ namespace gui {
namespace panels {
ViewerPanel::ViewerPanel() :
Panel("viewer", _("Viewer"), "viewer_panel"),
Panel("viewer", _("Viewer"), "panel_viewer"),
previousButton(Stock::MEDIA_PREVIOUS),
rewindButton(Stock::MEDIA_REWIND),
playPauseButton(Stock::MEDIA_PLAY),

View file

@ -22,52 +22,154 @@
#include "window-manager.hpp"
using namespace Gtk;
using namespace Glib;
namespace lumiera {
namespace gui {
WindowManager::WindowManager()
{
{
register_stock_items();
}
g_message("get_home_dir() : %s", get_home_dir().c_str());
g_message("get_tmp_dir() : %s", get_tmp_dir().c_str());
g_message("get_current_dir() : %s", get_current_dir().c_str());
g_message("get_user_data_dir() : %s", get_user_data_dir().c_str());
g_message("get_user_config_dir() : %s", get_user_config_dir().c_str());
g_message("get_user_cache_dir () : %s", get_user_cache_dir().c_str());
}
bool
WindowManager::set_theme(Glib::ustring path)
{
if(access(path.c_str(), R_OK))
{
ERROR(gui, "WindowManger: Unable to load rc file \"%s\"", path.c_str());
return false;
}
gtk_rc_parse(path.c_str());
gtk_rc_reset_styles (gtk_settings_get_default());
{
if(access(path.c_str(), R_OK))
{
ERROR(gui, "WindowManger: Unable to load rc file \"%s\"",
path.c_str());
return false;
}
gtk_rc_parse(path.c_str());
gtk_rc_reset_styles (gtk_settings_get_default());
return true;
}
return true;
}
GdkColor
WindowManager::read_style_colour_property(
Gtk::Widget &widget, const gchar *property_name,
guint16 red, guint16 green, guint16 blue)
{
GdkColor *colour;
gtk_widget_style_get(widget.gobj(), property_name, &colour, NULL);
// Did the color load successfully?
if(colour != NULL)
return *colour;
else
{
GdkColor *colour;
gtk_widget_style_get(widget.gobj(), property_name, &colour, NULL);
// Did the color load successfully?
if(colour != NULL)
return *colour;
else
{
WARN(gui, "%s style value failed to load", property_name);
GdkColor default_colour;
default_colour.red = red;
default_colour.green = green;
default_colour.blue = blue;
return default_colour;
}
WARN(gui, "%s style value failed to load", property_name);
GdkColor default_colour;
default_colour.red = red;
default_colour.green = green;
default_colour.blue = blue;
return default_colour;
}
}
void
WindowManager::register_stock_items()
{
RefPtr<IconFactory> factory = IconFactory::create();
add_stock_item_set(factory, "panel-assets", "panel_assets", _("_Assets"));
add_stock_item_set(factory, "panel-timeline", "panel_timeline", _("_Timeline"));
add_stock_item_set(factory, "panel-viewer", "panel_viewer", _("_Viewer"));
add_stock_item_set(factory, "tool-arrow", "tool_arrow", _("_Arrow"));
add_stock_item_set(factory, "tool-i-beam", "tool_i_beam", _("_I-Beam"));
factory->add_default(); //Add factory to list of factories.
}
bool
WindowManager::add_stock_item_set(
const Glib::RefPtr<IconFactory>& factory,
const Glib::ustring& icon_name,
const Glib::ustring& id,
const Glib::ustring& label)
{
Gtk::IconSet icon_set;
add_stock_icon(icon_set, icon_name, 16);
add_stock_icon(icon_set, icon_name, 22);
add_stock_icon(icon_set, icon_name, 24);
add_stock_icon(icon_set, icon_name, 32);
add_stock_icon(icon_set, icon_name, 48);
if(!icon_set.get_sizes().empty())
{
const Gtk::StockID stock_id(id);
factory->add(stock_id, icon_set);
Gtk::Stock::add(Gtk::StockItem(stock_id, label));
return true;
}
ERROR(gui, "Unable to load icon \"%s\"", icon_name.c_str());
return false;
}
bool
WindowManager::add_stock_icon(Gtk::IconSet &icon_set,
const Glib::ustring& icon_name, int size)
{
// Try the ~/.lumiera/icons folder
if(add_stock_icon_source(icon_set, ustring::compose("%1/%2",
GtkLumiera::get_home_data_path(), ustring("icons")),
icon_name, size))
return true;
if(add_stock_icon_source(
icon_set, get_current_dir(), icon_name, size))
return true;
return false;
}
bool
WindowManager::add_stock_icon_source(Gtk::IconSet &icon_set,
const Glib::ustring& base_dir, const Glib::ustring& icon_name,
int size)
{
Gtk::IconSource source;
try
{
ustring path = ustring::compose("%1/%2x%2/%3.png",
base_dir, size, icon_name);
g_message("%s", path.c_str());
// This throws an exception if the file is not found:
source.set_pixbuf(Gdk::Pixbuf::create_from_file(path));
}
catch(const Glib::Exception& ex)
{
g_message("Failed");
return false;
}
source.set_size(IconSize(size));
//source.set_size_wildcarded(); // Icon may be scaled.
icon_set.add_source(source);
return true;
}
} // namespace gui
} // namespace lumiera

View file

@ -44,9 +44,25 @@ namespace gui {
static GdkColor read_style_colour_property(
Gtk::Widget &widget, const gchar *property_name,
guint16 red, guint16 green, guint16 blue);
private:
/**
* Registers application stock items: icons and
* labels associated with IDs */
static void register_stock_items();
protected:
static bool add_stock_item_set(
const Glib::RefPtr<Gtk::IconFactory>& factory,
const Glib::ustring& icon_name,
const Glib::ustring& id,
const Glib::ustring& label);
static bool add_stock_icon(Gtk::IconSet &icon_set,
const Glib::ustring& icon_name, int size);
static bool add_stock_icon_source(Gtk::IconSet &icon_set,
const Glib::ustring& base_dir,
const Glib::ustring& icon_name, int size);
};
} // namespace gui

View file

@ -39,8 +39,6 @@ Actions::Actions(WorkspaceWindow &workspace_window) :
workspaceWindow(workspace_window),
is_updating_action_state(false)
{
register_stock_items();
workspace_window.signal_show ().connect_notify(mem_fun(this, &Actions::update_action_state));
//----- Create the Action Group -----//
@ -91,71 +89,6 @@ Actions::Actions(WorkspaceWindow &workspace_window) :
sigc::mem_fun(*this, &Actions::on_menu_help_about) );
}
void
Actions::register_stock_items()
{
RefPtr<IconFactory> factory = IconFactory::create();
add_stock_item_set(factory, "assets-panel.png", "assets_panel", _("_Assets"));
add_stock_item_set(factory, "timeline-panel.png", "timeline_panel", _("_Timeline"));
add_stock_item_set(factory, "viewer-panel.png", "viewer_panel", _("_Viewer"));
add_stock_item_set(factory, "arrow.png", "arrow", _("_Arrow"));
add_stock_item_set(factory, "i-beam.png", "i_beam", _("_I-Beam"));
factory->add_default(); //Add factory to list of factories.
}
bool
Actions::add_stock_item_set(const Glib::RefPtr<IconFactory>& factory,
const Glib::ustring& filename,
const Glib::ustring& id,
const Glib::ustring& label)
{
Gtk::IconSet icon_set;
add_stock_icon_source(icon_set, 16, filename);
add_stock_icon_source(icon_set, 22, filename);
add_stock_icon_source(icon_set, 24, filename);
add_stock_icon_source(icon_set, 32, filename);
add_stock_icon_source(icon_set, 48, filename);
if(!icon_set.get_sizes().empty())
{
const Gtk::StockID stock_id(id);
factory->add(stock_id, icon_set);
Gtk::Stock::add(Gtk::StockItem(stock_id, label));
return true;
}
return false;
}
bool
Actions::add_stock_icon_source(Gtk::IconSet &icon_set,
int size, const Glib::ustring& filename)
{
Gtk::IconSource source;
try
{
//This throws an exception if the file is not found:
source.set_pixbuf( Gdk::Pixbuf::create_from_file(
Glib::ustring::compose("%1x%1/%2", size, filename) ) );
}
catch(const Glib::Exception& ex)
{
return false;
}
source.set_size(IconSize(size));
//source.set_size_wildcarded(); // Icon may be scaled.
icon_set.add_source(source);
return true;
}
void
Actions::update_action_state()
{

View file

@ -48,20 +48,6 @@ private:
/* ===== Internals ===== */
private:
/**
* Registers application stock items: icons and
* labels associated with IDs */
static void register_stock_items();
static bool add_stock_item_set(
const Glib::RefPtr<Gtk::IconFactory>& factory,
const Glib::ustring& filename,
const Glib::ustring& id,
const Glib::ustring& label);
static bool add_stock_icon_source(Gtk::IconSet &icon_set,
int size, const Glib::ustring& filename);
/**
* Updates the state of the menu/toolbar actions
* to reflect the current state of the workspace */
@ -102,7 +88,7 @@ private:
/* ===== Internals ===== */
private:
bool is_updating_action_state;
friend class WorkspaceWindow;
};