diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2005-10-09 12:51:04 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2005-10-09 12:51:04 +0000 |
commit | 8e591b058786c842c46790c96b806ad1eca6cbec (patch) | |
tree | 44cb2eadc11cd3436559aa28635e0c5f5f8212ad /gtk2_ardour | |
parent | c38fdbc64c73c686f9f55729b352f8d0f4c09070 (diff) |
fixes for utils.cc in gtk2_ardour and gtkmm2ext, including switch to Pango::FontDescription rather than string
git-svn-id: svn://localhost/trunk/ardour2@53 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/editor.cc | 52 | ||||
-rw-r--r-- | gtk2_ardour/marker.cc | 18 | ||||
-rw-r--r-- | gtk2_ardour/time_axis_view_item.cc | 6 | ||||
-rw-r--r-- | gtk2_ardour/time_axis_view_item.h | 3 | ||||
-rw-r--r-- | gtk2_ardour/utils.cc | 87 | ||||
-rw-r--r-- | gtk2_ardour/utils.h | 9 |
6 files changed, 102 insertions, 73 deletions
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 928b3bd137..601eda7733 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -830,14 +830,14 @@ Editor::initialize_canvas () /* stuff for the verbose canvas cursor */ - string fontname = get_font_for_style (N_("VerboseCanvasCursor")); + Pango::FontDescription font = get_font_for_style (N_("VerboseCanvasCursor")); verbose_canvas_cursor = gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(track_gnome_canvas)), - gnome_canvas_text_get_type(), - "font", fontname.c_str(), - "anchor", GTK_ANCHOR_NW, - "fill_color_rgba", color_map[cVerboseCanvasCursor], - NULL); + gnome_canvas_text_get_type(), + "font-desc", fontname, + "anchor", GTK_ANCHOR_NW, + "fill_color_rgba", color_map[cVerboseCanvasCursor], + NULL); verbose_cursor_visible = false; /* a group to hold time (measure) lines */ @@ -1389,7 +1389,7 @@ Editor::track_canvas_allocate (GtkAllocation *alloc) if (session == 0 && !ARDOUR_UI::instance()->will_create_new_session_automatically()) { - string fontname = get_font_for_style (N_("FirstActionMessage")); + Pango::FontDescription font = get_font_for_style (N_("FirstActionMessage")); const char *txt1 = _("Start a new session\n"); const char *txt2 = _("via Session menu"); @@ -1400,27 +1400,21 @@ Editor::track_canvas_allocate (GtkAllocation *alloc) compute width, and multiply the height by 2. */ - gint width; - gint lbearing; - gint rbearing; - gint ascent; - gint descent; + int pixel_height; + int pixel_width; /* this is a dummy widget that exists so that we can get the style from the RC file. */ Label foo (_(txt2)); + Glib::RefPtr<Pango::Layout> layout; foo.set_name ("NoSessionMessage"); foo.ensure_style (); - gdk_string_extents (foo.get_style()->get_font(), - _(txt2), - &lbearing, - &rbearing, - &width, - &ascent, - &descent); + layout = foo.create_pango_layout (_(txt2)); + layout->set_font_description (font); + layout->get_pixel_size (pixel_width, pixel_height); if (first_action_message == 0) { @@ -1432,22 +1426,22 @@ Editor::track_canvas_allocate (GtkAllocation *alloc) strcat (txt, _(txt2)); first_action_message = gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(track_gnome_canvas)), - gnome_canvas_text_get_type(), - "font", fontname.c_str(), - "fill_color_rgba", color_map[cFirstActionMessage], - "x", (gdouble) (canvas_width - width) / 2.0, - "y", (gdouble) (canvas_height/2.0) - (2.0 * (ascent+descent)), - "anchor", GTK_ANCHOR_NORTH_WEST, - "text", txt, - NULL); + gnome_canvas_text_get_type(), + "fontdesc", font, + "fill_color_rgba", color_map[cFirstActionMessage], + "x", (gdouble) (canvas_width - pixel_width) / 2.0, + "y", (gdouble) (canvas_height/2.0) - (2.0 * (pixel_height)), + "anchor", GTK_ANCHOR_NORTH_WEST, + "text", txt, + NULL); } else { /* center it */ gnome_canvas_item_set (first_action_message, - "x", (gdouble) (canvas_width - width) / 2.0, - "y", (gdouble) (canvas_height/2.0) - (2.0 * (ascent+descent)), + "x", (gdouble) (canvas_width - pixel_width) / 2.0, + "y", (gdouble) (canvas_height/2.0) - (2.0 * (pixel_height)), NULL); } } diff --git a/gtk2_ardour/marker.cc b/gtk2_ardour/marker.cc index 2621102865..0d124f556c 100644 --- a/gtk2_ardour/marker.cc +++ b/gtk2_ardour/marker.cc @@ -351,17 +351,17 @@ Marker::Marker (PublicEditor& ed, GnomeCanvasGroup *parent, guint32 rgba, const "outline_color", "black", NULL); - string fontname = get_font_for_style (N_("MarkerText")); + Pango::FontDescription font = get_font_for_style (N_("MarkerText")); text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_text_get_type (), - "text", annotation.c_str(), - "x", label_offset, - "y", 0.0, - "font", fontname.c_str(), - "anchor", GTK_ANCHOR_NW, - "fill_color", "black", - NULL); + gnome_canvas_text_get_type (), + "text", annotation.c_str(), + "x", label_offset, + "y", 0.0, + "fontdesc", font, + "anchor", GTK_ANCHOR_NW, + "fill_color", "black", + NULL); gtk_object_set_data (GTK_OBJECT(group), "marker", this); gtk_signal_connect (GTK_OBJECT(group), "event", (GtkSignalFunc) callback, &editor); diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc index 7f1bfc53e5..62a1e7d9e6 100644 --- a/gtk2_ardour/time_axis_view_item.cc +++ b/gtk2_ardour/time_axis_view_item.cc @@ -38,7 +38,8 @@ using namespace Editing; //------------------------------------------------------------------------------ /** Initialize static memeber data */ -std::string TimeAxisViewItem::NAME_FONT; +Pango::FontDescription TimeAxisViewItem::NAME_FONT; +bool TimeAxisViewItem::have_name_font = false; const double TimeAxisViewItem::NAME_X_OFFSET = 15.0; const double TimeAxisViewItem::NAME_Y_OFFSET = 15.0 ; /* XXX depends a lot on the font size, sigh. */ const double TimeAxisViewItem::NAME_HIGHLIGHT_SIZE = 15.0 ; /* ditto */ @@ -65,8 +66,9 @@ TimeAxisViewItem::TimeAxisViewItem(std::string it_name, GnomeCanvasGroup* parent Visibility visibility) : trackview (tv) { - if (NAME_FONT.empty()) { + if (!have_name_font) { NAME_FONT = get_font_for_style (N_("TimeAxisViewItemName")); + have_name_font = true; } item_name = it_name ; diff --git a/gtk2_ardour/time_axis_view_item.h b/gtk2_ardour/time_axis_view_item.h index d4e852461a..ff651b9649 100644 --- a/gtk2_ardour/time_axis_view_item.h +++ b/gtk2_ardour/time_axis_view_item.h @@ -264,7 +264,8 @@ class TimeAxisViewItem : public sigc::trackable, public Selectable bool name_active() const { return name_connected; } // Default sizes, font and spacing - static std::string NAME_FONT ; + static Pango::FontDescription NAME_FONT ; + static bool have_name_font; static const double NAME_X_OFFSET ; static const double NAME_Y_OFFSET ; static const double NAME_HIGHLIGHT_SIZE ; diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index 21a8233d44..e0a31e5844 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -25,6 +25,10 @@ #include <gtkmm/combo.h> #include <gtkmm/label.h> #include <gtkmm/paned.h> +#include <gtkmm/action.h> +#include <gtkmm/actiongroup.h> +#include <gtkmm/accelgroup.h> +#include <gtkmm/accelmap.h> #include <gtk/gtkpaned.h> #include <gtkmm2ext/utils.h> @@ -36,6 +40,7 @@ using namespace std; using namespace Gtk; +using namespace sigc; string short_version (string orig, string::size_type target_length) @@ -102,27 +107,22 @@ short_version (string orig, string::size_type target_length) } string -fit_to_pixels (string str, int32_t pixel_width, Gdk_Font& font) +fit_to_pixels (string str, int pixel_width, string font) { - gint width; - gint lbearing; - gint rbearing; - gint ascent; - gint descent; - + Label foo; + int width; + int height; + Pango::FontDescription fontdesc (font); + int namelen = str.length(); char cstr[namelen+1]; strcpy (cstr, str.c_str()); while (namelen) { - - gdk_string_extents (font, - cstr, - &lbearing, - &rbearing, - &width, - &ascent, - &descent); + Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (cstr); + + layout->set_font_description (fontdesc); + layout->get_pixel_size (width, height); if (width < (pixel_width)) { break; @@ -415,26 +415,19 @@ url_decode (string& url) } } -string +Pango::FontDescription get_font_for_style (string widgetname) { Gtk::Label foobar; + Glib::RefPtr<Style> style; foobar.set_name (widgetname); foobar.ensure_style(); - if (foobar.get_style() == 0 || foobar.get_style()->gobj()->rc_style == 0 || foobar.get_style()->gobj()->rc_style->font_name == 0) { - return "fixed"; - } - - string str = foobar.get_style()->gobj()->rc_style->font_name; - - if (str.empty()) { - return "fixed"; // standard X Window fallback font - } else { - return str; - } + style = foobar.get_style (); + return style->get_font(); } + gint pane_handler (GdkEventButton* ev, Gtk::Paned* pane) { @@ -446,8 +439,8 @@ pane_handler (GdkEventButton* ev, Gtk::Paned* pane) gint pos; gint cmp; - - pos = Gtkmm2ext::gtk_paned_get_position (pane->gobj()); + + pos = pane->get_position (); if (dynamic_cast<VPaned*>(pane)) { cmp = pane->get_height(); @@ -522,5 +515,39 @@ rgba_from_style (string style, uint32_t r, uint32_t g, uint32_t b, uint32_t a) void decorate (Gtk::Window& w, Gdk::WMDecoration d) { - w.get_window().set_decorations (d); + w.get_window()->set_decorations (d); +} + +Glib::RefPtr<Action> +register_action (Glib::RefPtr<ActionGroup> group, string name, string label, slot<void> sl, guint key, Gdk::ModifierType mods) +{ + Glib::RefPtr<Action> act; + + act = Action::create (name, label); + group->add (act, sl); + AccelMap::add_entry (act->get_accel_path(), key, mods); + + return act; +} + +Glib::RefPtr<Action> +register_action (Glib::RefPtr<ActionGroup> group, string name, string label, slot<void> sl) +{ + Glib::RefPtr<Action> act; + + act = Action::create (name, label); + group->add (act, sl); + + return act; +} + +Glib::RefPtr<Action> +register_action (Glib::RefPtr<ActionGroup> group, string name, string label) +{ + Glib::RefPtr<Action> act; + + act = Action::create (name, label); + group->add (act); + + return act; } diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index b844e0eb30..1b33db7a4a 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -51,7 +51,7 @@ slider_position_to_gain (double pos) } std::string short_version (std::string, std::string::size_type target_length); -std::string fit_to_pixels (std::string, int32_t pixel_width, Gdk::Font&); +std::string fit_to_pixels (std::string, int pixel_width, std::string font); int atoi (const std::string&); double atof (const std::string&); @@ -66,9 +66,14 @@ unsigned char* xpm2rgba (const char** xpm, uint32_t& w, uint32_t& h); GnomeCanvasPoints* get_canvas_points (std::string who, uint32_t npoints); int channel_combo_get_channel_count (Gtk::ComboBoxText& combo); -std::string get_font_for_style (std::string widgetname); +Pango::FontDescription get_font_for_style (std::string widgetname); gint pane_handler (GdkEventButton*, Gtk::Paned*); uint32_t rgba_from_style (std::string style, uint32_t, uint32_t, uint32_t, uint32_t); +Glib::RefPtr<Gtk::Action> register_action (Glib::RefPtr<Gtk::ActionGroup> group, string name, string label, sigc::slot<void> sl, guint key, Gdk::ModifierType mods); +Glib::RefPtr<Gtk::Action> register_action (Glib::RefPtr<Gtk::ActionGroup> group, string name, string label, sigc::slot<void> sl); +Glib::RefPtr<Gtk::Action> register_action (Glib::RefPtr<Gtk::ActionGroup> group, string name, string label); + + #endif /* __ardour_gtk_utils_h__ */ |