summaryrefslogtreecommitdiff
path: root/gtk2_ardour/ardour_button.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2013-07-05 03:04:40 +0200
committerRobin Gareus <robin@gareus.org>2013-07-10 15:27:08 +0200
commit94fbfb9658df9feeccd7681e58c60feebc89da03 (patch)
tree5a48f6024482db3050b629ca1f72b36394c37aad /gtk2_ardour/ardour_button.cc
parent4726339f4c51d1a4a3b628370e809e2a242d59b6 (diff)
left/bottom align of labels in meterbridge
Diffstat (limited to 'gtk2_ardour/ardour_button.cc')
-rw-r--r--gtk2_ardour/ardour_button.cc35
1 files changed, 29 insertions, 6 deletions
diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc
index 750a87e831..2c191385f4 100644
--- a/gtk2_ardour/ardour_button.cc
+++ b/gtk2_ardour/ardour_button.cc
@@ -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)
@@ -169,6 +173,13 @@ ArdourButton::set_angle (const double angle)
}
void
+ArdourButton::set_alignment (const float xa, const float ya)
+{
+ _xalign = xa;
+ _yalign = ya;
+}
+
+void
ArdourButton::render (cairo_t* cr)
{
void (*rounded_function)(cairo_t*, double, double, double, double, double);
@@ -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);
}