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
This commit is contained in:
Paul Davis 2006-04-20 18:14:00 +00:00
parent d7e728476a
commit 17b18acda3
15 changed files with 136 additions and 117 deletions

View File

@ -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);

View File

@ -2283,10 +2283,18 @@ Editor::set_state (const XMLNode& node)
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::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";
}
}

View File

@ -20,6 +20,7 @@
#include <libgnomecanvasmm/init.h>
#include <jack/types.h>
#include <gtkmm2ext/utils.h>
#include <ardour/audioregion.h>
@ -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 ("<span face=\"sans\" style=\"normal\" weight=\"bold\" size=\"x-large\">%1%2</span>",
_("Start a new session\n"), _("via Session menu"));
RefPtr<Pango::Layout> 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;
}
}

View File

@ -36,6 +36,8 @@ Editor::editor_mixer_button_toggled ()
Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
if (act) {
Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
bool yn = tact->get_active();
cerr << "button toggled, state = " << yn << endl;
show_editor_mixer (tact->get_active());
}
}

View File

@ -249,12 +249,10 @@ FFTGraph::draw_scales(Glib::RefPtr<Gdk::Window> 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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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();
int width;
ustring ustr = fit_to_pixels (item_name, (int) floor (pixel_width - NAME_X_OFFSET), NAME_FONT, width);
Glib::RefPtr<Pango::Layout> 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);
}
if (namelen == 0) {
if (ustr.empty()) {
name_text->hide ();

View File

@ -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);
Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
int namelen = str.length();
char cstr[namelen+1];
strcpy (cstr, str.c_str());
while (namelen) {
Glib::RefPtr<Pango::Layout> 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)) {
ustring ustr = str;
ustring::iterator last = ustr.end();
--last; /* now points at final entry */
while (!ustr.empty()) {
layout->set_text (ustr);
int width, height;
Gtkmm2ext::get_ink_pixel_size (layout, width, height);
if (width < pixel_width) {
actual_width = width;
break;
}
--namelen;
cstr[namelen] = '\0';
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];

View File

@ -26,6 +26,8 @@
#include <ardour/types.h>
#include <libgnomecanvasmm/line.h>
#include <gdkmm/types.h>
#include <glibmm/ustring.h>
#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&);

View File

@ -26,6 +26,7 @@
#include <midi++/controllable.h>
#include <gtkmm2ext/gtk_ui.h>
#include <gtkmm2ext/utils.h>
#include <gtkmm2ext/barcontroller.h>
#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());
break;
case 5:
adjustment.set_value (adjustment.get_value() -
adjustment.get_step_increment());
default:
break;
}
return TRUE;
return true;
}
gint
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;
}
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<Gdk::Window> 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

View File

@ -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*);
};

View File

@ -37,6 +37,8 @@ namespace Gtk {
namespace Gtkmm2ext {
void init ();
void get_ink_pixel_size (Glib::RefPtr<Pango::Layout>, int& width, int& height);
void set_size_request_to_display_given_text (Gtk::Widget &w,
const gchar *text,
gint hpadding,

View File

@ -18,16 +18,5 @@
$Id$
*/
#include <string>
#include <gtkmm.h>
#include <gtkmm2ext/gtkutils.h>
void
gtk_set_size_request_to_display_given_text (Gtk::Widget &w,
const std::string& text,
gint hpadding,
gint vpadding)
{
}

View File

@ -34,21 +34,27 @@
using namespace std;
void
Gtkmm2ext::get_ink_pixel_size (Glib::RefPtr<Pango::Layout> 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