left/bottom align of labels in meterbridge

This commit is contained in:
Robin Gareus 2013-07-05 03:04:40 +02:00
parent 4726339f4c
commit 94fbfb9658
3 changed files with 33 additions and 6 deletions

View File

@ -62,6 +62,8 @@ ArdourButton::ArdourButton (Element e)
, _corner_radius (4.0)
, _corner_mask (0xf)
, _angle(0)
, _xalign(.5)
, _yalign(.5)
, border_color (0)
, fill_color_active (0)
, fill_color_inactive (0)
@ -89,6 +91,8 @@ ArdourButton::ArdourButton (const std::string& str, Element e)
, _corner_radius (4.0)
, _corner_mask (0xf)
, _angle(0)
, _xalign(.5)
, _yalign(.5)
, border_color (0)
, fill_color_active (0)
, fill_color_inactive (0)
@ -168,6 +172,13 @@ ArdourButton::set_angle (const double angle)
_angle = angle;
}
void
ArdourButton::set_alignment (const float xa, const float ya)
{
_xalign = xa;
_yalign = ya;
}
void
ArdourButton::render (cairo_t* cr)
{
@ -303,20 +314,32 @@ ArdourButton::render (cairo_t* cr)
}
pango_cairo_show_layout (cr, _layout->gobj());
} else {
/* center text */
/* align text */
double ww, wh;
ww= get_width();
wh= get_height();
double xa, ya;
ww = get_width();
wh = get_height();
cairo_save (cr); // TODO retain rotataion.. adj. LED,...
cairo_rotate(cr, _angle * M_PI / 180.0);
cairo_device_to_user(cr, &ww, &wh);
cairo_move_to (cr,
(ww - _text_width) / 2.0,
(wh - _text_height) / 2.0);
xa = (ww - _text_width) * _xalign;
ya = (wh - _text_height) * _yalign;
/* quick hack for left/bottom alignment at -90deg
* TODO this should be generalized incl rotation.
* currently only 'user' of this API is meter_strip.cc
*/
if (_xalign < 0) xa = (ww * fabs(_xalign) + text_margin);
// TODO honor left/right text_margin with min/max()
cairo_move_to (cr, xa, ya);
pango_cairo_update_layout(cr, _layout->gobj());
pango_cairo_show_layout (cr, _layout->gobj());
cairo_restore (cr);
/* use old center'ed layout for follow up items - until rotation/aligment code is completed */
cairo_move_to (cr, (get_width() - _text_width)/2.0, get_height()/2.0 - _text_height/2.0);
}

View File

@ -74,6 +74,8 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
void set_text (const std::string&);
void set_markup (const std::string&);
void set_angle (const double);
void set_alignment (const float, const float);
void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
void set_led_left (bool yn);
void set_distinct_led_click (bool yn);
@ -120,6 +122,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
int _corner_mask;
double _angle;
float _xalign, _yalign;
uint32_t bg_color;
uint32_t border_color;

View File

@ -159,6 +159,7 @@ MeterStrip::MeterStrip (Session* sess, boost::shared_ptr<ARDOUR::Route> rt)
name_label.layout()->set_ellipsize (Pango::ELLIPSIZE_END);
name_label.layout()->set_width(48 * PANGO_SCALE);
name_label.set_size_request(18, 50);
name_label.set_alignment(-1.0, .5);
namebx.set_size_request(18, 52);
namebx.pack_start(name_label, true, false, 3);