From 17b18acda3447214bd739107d9a46eecfaa6ef70 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 20 Apr 2006 18:14:00 +0000 Subject: a) use ink extents in most places where we used to use logical extents for text sizing b) add back scroll-wheel functionality to plugin parameter controls git-svn-id: svn://localhost/trunk/ardour2@460 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui2.cc | 3 ++ gtk2_ardour/editor.cc | 8 ++++ gtk2_ardour/editor_canvas.cc | 15 +++--- gtk2_ardour/editor_mixer.cc | 2 + gtk2_ardour/fft_graph.cc | 8 ++-- gtk2_ardour/gain_meter.cc | 10 ++-- gtk2_ardour/time_axis_view.cc | 2 +- gtk2_ardour/time_axis_view_item.cc | 27 ++--------- gtk2_ardour/utils.cc | 43 +++++++++-------- gtk2_ardour/utils.h | 4 +- libs/gtkmm2ext/barcontroller.cc | 79 +++++++++++++++++++++----------- libs/gtkmm2ext/gtkmm2ext/barcontroller.h | 11 +++-- libs/gtkmm2ext/gtkmm2ext/utils.h | 2 + libs/gtkmm2ext/gtkutils.cc | 11 ----- libs/gtkmm2ext/utils.cc | 26 +++++++---- 15 files changed, 135 insertions(+), 116 deletions(-) diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index 47b457e594..847b1b236b 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -699,6 +699,9 @@ ARDOUR_UI::shuttle_box_scroll (GdkEventScroll* ev) case GDK_SCROLL_DOWN: shuttle_fract -= 0.005; break; + default: + /* scroll left/right */ + return false; } use_shuttle_fract (true); diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 1a44041f73..1ad81e18ef 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2283,10 +2283,18 @@ Editor::set_state (const XMLNode& node) Glib::RefPtr tact = Glib::RefPtr::cast_dynamic(act); bool yn = (prop->value() == X_("yes")); + cerr << "at load time, show-editor-mixer = " << prop->value() << endl; + /* do it twice to force the change */ tact->set_active (!yn); + + cerr << "now reset to " << yn << endl; + tact->set_active (yn); + + cerr << "should be done\n"; + } } diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 73e6e22668..bd6c1c99ab 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -20,6 +20,7 @@ #include #include +#include #include @@ -279,32 +280,30 @@ Editor::track_canvas_allocate (Gtk::Allocation alloc) /* this mess of code is here to find out how wide this text is and position the message in the center of the editor window. */ - - int pixel_height; - int pixel_width; ustring msg = string_compose ("%1%2", _("Start a new session\n"), _("via Session menu")); RefPtr layout = create_pango_layout (msg); Pango::FontDescription font = get_font_for_style (N_("FirstActionMessage")); - layout->get_pixel_size (pixel_width, pixel_height); + int width, height; + get_ink_pixel_size (layout, width, height); if (first_action_message == 0) { first_action_message = new ArdourCanvas::Text (*track_canvas.root()); first_action_message->property_font_desc() = font; first_action_message->property_fill_color_rgba() = color_map[cFirstActionMessage]; - first_action_message->property_x() = (canvas_width - pixel_width) / 2.0; - first_action_message->property_y() = (canvas_height/2.0) - pixel_height; + first_action_message->property_x() = (canvas_width - width) / 2.0; + first_action_message->property_y() = (canvas_height/2.0) - height; first_action_message->property_anchor() = ANCHOR_NORTH_WEST; first_action_message->property_markup() = msg; } else { /* center it */ - first_action_message->property_x() = (canvas_width - pixel_width) / 2.0; - first_action_message->property_y() = (canvas_height/2.0) - pixel_height; + first_action_message->property_x() = (canvas_width - width) / 2.0; + first_action_message->property_y() = (canvas_height/2.0) - height; } } diff --git a/gtk2_ardour/editor_mixer.cc b/gtk2_ardour/editor_mixer.cc index f6fe3b66c9..410474114a 100644 --- a/gtk2_ardour/editor_mixer.cc +++ b/gtk2_ardour/editor_mixer.cc @@ -36,6 +36,8 @@ Editor::editor_mixer_button_toggled () Glib::RefPtr act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer")); if (act) { Glib::RefPtr tact = Glib::RefPtr::cast_dynamic(act); + bool yn = tact->get_active(); + cerr << "button toggled, state = " << yn << endl; show_editor_mixer (tact->get_active()); } } diff --git a/gtk2_ardour/fft_graph.cc b/gtk2_ardour/fft_graph.cc index 0989247e09..f7b2e249b7 100644 --- a/gtk2_ardour/fft_graph.cc +++ b/gtk2_ardour/fft_graph.cc @@ -249,12 +249,10 @@ FFTGraph::draw_scales(Glib::RefPtr window) window->draw_line(graph_gc, coord, v_margin, coord, height - v_margin); - int layoutWidth; - int layoutHeight; - layout->get_pixel_size(layoutWidth,layoutHeight); - + int width, height; + get_ink_pixel_size (layout, width, height); - window->draw_layout(white, coord - layoutWidth / 2, v_margin / 2, layout); + window->draw_layout(white, coord - width / 2, v_margin / 2, layout); } diff --git a/gtk2_ardour/gain_meter.cc b/gtk2_ardour/gain_meter.cc index 55ffac2063..237e0787ea 100644 --- a/gtk2_ardour/gain_meter.cc +++ b/gtk2_ardour/gain_meter.cc @@ -230,8 +230,6 @@ GainMeter::render_metrics (Gtk::Widget& w) gint x, y, width, height, depth; int db_points[] = { -50, -40, -20, -30, -10, -3, 0, 4 }; char buf[32]; - int theight; - int twidth; win->get_geometry (x, y, width, height, depth); @@ -251,10 +249,14 @@ GainMeter::render_metrics (Gtk::Widget& w) snprintf (buf, sizeof (buf), "%d", abs (db_points[i])); layout->set_text (buf); - layout->get_pixel_size (twidth, theight); + + /* we want logical extents, not ink extents here */ + + int width, height; + layout->get_pixel_size (width, height); pixmap->draw_line (fg_gc, 0, pos, 4, pos); - pixmap->draw_layout (fg_gc, 6, pos - (theight/2), layout); + pixmap->draw_layout (fg_gc, 6, pos - (height/2), layout); } return pixmap; diff --git a/gtk2_ardour/time_axis_view.cc b/gtk2_ardour/time_axis_view.cc index 44b3541826..1b6c1f390c 100644 --- a/gtk2_ardour/time_axis_view.cc +++ b/gtk2_ardour/time_axis_view.cc @@ -108,7 +108,7 @@ TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisVie name_entry.signal_activate().connect (mem_fun(*this, &TimeAxisView::name_entry_activated)); name_entry.signal_focus_in_event().connect (mem_fun (*this, &TimeAxisView::name_entry_focus_in)); name_entry.signal_focus_out_event().connect (mem_fun (*this, &TimeAxisView::name_entry_focus_out)); - Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 2, 2); // just represents a short name + Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name name_label.set_name ("TrackLabel"); name_label.set_alignment (0.0, 0.5); diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc index a9663b8630..270cbde0b8 100644 --- a/gtk2_ardour/time_axis_view_item.cc +++ b/gtk2_ardour/time_axis_view_item.cc @@ -867,35 +867,14 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width) void TimeAxisViewItem::reset_name_width (double pixel_width) { - int width; - int height; - ustring ustr; - Pango::FontDescription fd (NAME_FONT); - if (name_text == 0) { return; } - ustr = item_name; - int namelen = ustr.length(); - - Glib::RefPtr layout = group->get_canvas()->create_pango_layout (ustr); - layout->set_font_description (fd); - - while (namelen) { - - layout->set_text (ustr); - layout->get_pixel_size (width, height); - - if (width < (pixel_width - NAME_X_OFFSET)) { - break; - } - - --namelen; - ustr = ustr.substr (0, namelen); - } + int width; + ustring ustr = fit_to_pixels (item_name, (int) floor (pixel_width - NAME_X_OFFSET), NAME_FONT, width); - if (namelen == 0) { + if (ustr.empty()) { name_text->hide (); diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index c96f9a3da1..c3afcb7919 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -108,34 +108,37 @@ short_version (string orig, string::size_type target_length) return orig; } -string -fit_to_pixels (const string & str, int pixel_width, const string & font) +ustring +fit_to_pixels (const ustring& str, int pixel_width, Pango::FontDescription& font, int& actual_width) { Label foo; - int width; - int height; - Pango::FontDescription fontdesc (font); - - int namelen = str.length(); - char cstr[namelen+1]; - strcpy (cstr, str.c_str()); + Glib::RefPtr layout = foo.create_pango_layout (""); - while (namelen) { - Glib::RefPtr layout = foo.create_pango_layout (cstr); + layout->set_font_description (font); - layout->set_font_description (fontdesc); - layout->get_pixel_size (width, height); + actual_width = 0; - if (width < (pixel_width)) { - break; - } + ustring ustr = str; + ustring::iterator last = ustr.end(); + --last; /* now points at final entry */ + + while (!ustr.empty()) { - --namelen; - cstr[namelen] = '\0'; + layout->set_text (ustr); + int width, height; + Gtkmm2ext::get_ink_pixel_size (layout, width, height); + + if (width < pixel_width) { + actual_width = width; + break; + } + + ustr.erase (last); + --last; } - return cstr; + return ustr; } int @@ -602,7 +605,7 @@ length2string (const int32_t frames, const float sample_rate) secs -= (mins * 60); int total_secs = (hrs * 3600) + (mins * 60) + secs; - int frames_remaining = frames - (total_secs * sample_rate); + int frames_remaining = (int) floor (frames - (total_secs * sample_rate)); float fractional_secs = (float) frames_remaining / sample_rate; char duration_str[32]; diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index 608ba10529..1f1d702261 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -26,6 +26,8 @@ #include #include #include +#include + #include "canvas.h" namespace Gtk { @@ -51,7 +53,7 @@ slider_position_to_gain (double pos) } std::string short_version (std::string, std::string::size_type target_length); -std::string fit_to_pixels (const std::string &, int pixel_width, const std::string & font); +Glib::ustring fit_to_pixels (const Glib::ustring&, int pixel_width, Pango::FontDescription& font, int& actual_width); int atoi (const std::string&); double atof (const std::string&); diff --git a/libs/gtkmm2ext/barcontroller.cc b/libs/gtkmm2ext/barcontroller.cc index c8a211a48f..3529d23e12 100644 --- a/libs/gtkmm2ext/barcontroller.cc +++ b/libs/gtkmm2ext/barcontroller.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include "i18n.h" @@ -67,12 +68,14 @@ BarController::BarController (Gtk::Adjustment& adj, Gdk::BUTTON_PRESS_MASK| Gdk::POINTER_MOTION_MASK| Gdk::ENTER_NOTIFY_MASK| - Gdk::LEAVE_NOTIFY_MASK); + Gdk::LEAVE_NOTIFY_MASK| + Gdk::SCROLL_MASK); darea.signal_expose_event().connect (mem_fun (*this, &BarController::expose)); darea.signal_motion_notify_event().connect (mem_fun (*this, &BarController::motion)); darea.signal_button_press_event().connect (mem_fun (*this, &BarController::button_press)); darea.signal_button_release_event().connect (mem_fun (*this, &BarController::button_release)); + darea.signal_scroll_event().connect (mem_fun (*this, &BarController::scroll)); prompter.signal_unmap_event().connect (mem_fun (*this, &BarController::prompter_hiding)); @@ -107,13 +110,15 @@ BarController::get_bind_button_state (guint &button, guint &statemask) } -gint +bool BarController::button_press (GdkEventButton* ev) { switch (ev->button) { case 1: if (ev->type == GDK_2BUTTON_PRESS) { switch_on_release = true; + grabbed = false; + darea.remove_modal_grab(); } else { switch_on_release = false; darea.add_modal_grab(); @@ -122,7 +127,7 @@ BarController::button_press (GdkEventButton* ev) grab_window = ev->window; StartGesture (); } - return TRUE; + return true; break; case 2: @@ -134,17 +139,17 @@ BarController::button_press (GdkEventButton* ev) break; } - return FALSE; + return false; } -gint +bool BarController::button_release (GdkEventButton* ev) { switch (ev->button) { case 1: if (switch_on_release) { Glib::signal_idle().connect (mem_fun (*this, &BarController::switch_to_spinner)); - return TRUE; + return true; } if ((ev->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK)) == GDK_SHIFT_MASK) { @@ -162,7 +167,6 @@ BarController::button_release (GdkEventButton* ev) mouse_control (ev->x, ev->window, scale); } - grabbed = false; darea.remove_modal_grab(); StopGesture (); break; @@ -176,29 +180,51 @@ BarController::button_release (GdkEventButton* ev) adjustment.set_value (adjustment.get_lower() + fract * (adjustment.get_upper() - adjustment.get_lower())); } - return TRUE; + return true; case 3: if ((ev->state & bind_statemask) && bind_button == 3) { midi_learn (); return TRUE; } - return FALSE; + return false; - case 4: - adjustment.set_value (adjustment.get_value() + - adjustment.get_step_increment()); + default: break; - case 5: - adjustment.set_value (adjustment.get_value() - - adjustment.get_step_increment()); + } + + return true; +} + +bool +BarController::scroll (GdkEventScroll* ev) +{ + double scale; + + if (ev->state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK) == (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) { + scale = 0.01; + } else if (ev->state & GDK_CONTROL_MASK) { + scale = 0.1; + } else { + scale = 1.0; + } + + switch (ev->direction) { + case GDK_SCROLL_UP: + case GDK_SCROLL_RIGHT: + adjustment.set_value (adjustment.get_value() + (scale * adjustment.get_step_increment())); + break; + + case GDK_SCROLL_DOWN: + case GDK_SCROLL_LEFT: + adjustment.set_value (adjustment.get_value() - (scale * adjustment.get_step_increment())); break; } - return TRUE; + return true; } -gint +bool BarController::motion (GdkEventMotion* ev) { double scale; @@ -254,7 +280,7 @@ BarController::mouse_control (double x, GdkWindow* window, double scaling) return TRUE; } -gint +bool BarController::expose (GdkEventExpose* event) { Glib::RefPtr win (darea.get_window()); @@ -350,12 +376,11 @@ BarController::expose (GdkEventExpose* event) if (buf[0] != '\0') { - int width; - int height; - - layout->set_text (buf); - layout->get_pixel_size(width, height); - + layout->set_text (buf); + + int width, height; + layout->get_pixel_size (width, height); + int xpos; xpos = max (3, 1 + (x2 - (width/2))); @@ -368,7 +393,7 @@ BarController::expose (GdkEventExpose* event) } } - return TRUE; + return true; } void @@ -498,11 +523,11 @@ BarController::entry_activated () switch_to_bar (); } -gint +bool BarController::entry_focus_out (GdkEventFocus* ev) { entry_activated (); - return TRUE; + return true; } void diff --git a/libs/gtkmm2ext/gtkmm2ext/barcontroller.h b/libs/gtkmm2ext/gtkmm2ext/barcontroller.h index 64f5068d03..67c8221a55 100644 --- a/libs/gtkmm2ext/gtkmm2ext/barcontroller.h +++ b/libs/gtkmm2ext/gtkmm2ext/barcontroller.h @@ -89,10 +89,12 @@ class BarController : public Gtk::Frame guint bind_statemask; bool prompting, unprompting; - gint button_press (GdkEventButton *); - gint button_release (GdkEventButton *); - gint motion (GdkEventMotion *); - gint expose (GdkEventExpose *); + bool button_press (GdkEventButton *); + bool button_release (GdkEventButton *); + bool motion (GdkEventMotion *); + bool expose (GdkEventExpose *); + bool scroll (GdkEventScroll *); + bool entry_focus_out (GdkEventFocus*); gint mouse_control (double x, GdkWindow* w, double scaling); @@ -105,7 +107,6 @@ class BarController : public Gtk::Frame gint switch_to_spinner (); void entry_activated (); - gint entry_focus_out (GdkEventFocus*); }; diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h index 6f34866ce9..97dab523aa 100644 --- a/libs/gtkmm2ext/gtkmm2ext/utils.h +++ b/libs/gtkmm2ext/gtkmm2ext/utils.h @@ -37,6 +37,8 @@ namespace Gtk { namespace Gtkmm2ext { void init (); + void get_ink_pixel_size (Glib::RefPtr, int& width, int& height); + void set_size_request_to_display_given_text (Gtk::Widget &w, const gchar *text, gint hpadding, diff --git a/libs/gtkmm2ext/gtkutils.cc b/libs/gtkmm2ext/gtkutils.cc index 2f63fb2eb5..23bf4d6b2f 100644 --- a/libs/gtkmm2ext/gtkutils.cc +++ b/libs/gtkmm2ext/gtkutils.cc @@ -18,16 +18,5 @@ $Id$ */ -#include - -#include #include -void -gtk_set_size_request_to_display_given_text (Gtk::Widget &w, - const std::string& text, - gint hpadding, - gint vpadding) -{ - -} diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc index 0a0737becd..57661a05af 100644 --- a/libs/gtkmm2ext/utils.cc +++ b/libs/gtkmm2ext/utils.cc @@ -34,21 +34,27 @@ using namespace std; +void +Gtkmm2ext::get_ink_pixel_size (Glib::RefPtr layout, + int& width, + int& height) +{ + Pango::Rectangle ink_rect = layout->get_ink_extents (); + + width = (ink_rect.get_width() + PANGO_SCALE / 2) / PANGO_SCALE; + height = (ink_rect.get_height() + PANGO_SCALE / 2) / PANGO_SCALE; +} + void Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, const gchar *text, gint hpadding, gint vpadding) - + { - int height = 0; - int width = 0; - + int width, height; w.ensure_style (); - w.create_pango_layout (text)->get_pixel_size (width, height); - - height += vpadding; - width += hpadding; - - w.set_size_request(width, height); + + get_ink_pixel_size (w.create_pango_layout (text), width, height); + w.set_size_request(width + hpadding, height + vpadding); } void -- cgit v1.2.3