summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2014-09-07 18:50:34 +0200
committerRobin Gareus <robin@gareus.org>2014-09-07 20:23:49 +0200
commitcb07f0f99b3b4c10ebf23c8ddeca6a0c93ae8a56 (patch)
tree29e712a46374119669a19542904e4dbfa2895d7b /gtk2_ardour
parent5dab88c3fa34692b2c7cedd2ac817a50fac193b4 (diff)
yet another button tweak..
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/ardour_button.cc32
-rw-r--r--gtk2_ardour/ardour_button.h4
2 files changed, 27 insertions, 9 deletions
diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc
index 34236f2bb0..f2d6d142e7 100644
--- a/gtk2_ardour/ardour_button.cc
+++ b/gtk2_ardour/ardour_button.cc
@@ -42,6 +42,7 @@
#include "i18n.h"
#define BASELINESTRETCH (1.25)
+#define TRACKHEADERBTNW (3.10)
using namespace Gdk;
using namespace Gtk;
@@ -60,6 +61,7 @@ ArdourButton::ArdourButton (Element e)
, _tweaks (Tweaks (0))
, _char_pixel_width (0)
, _char_pixel_height (0)
+ , _char_avg_pixel_width (0)
, _text_width (0)
, _text_height (0)
, _diameter (0)
@@ -128,6 +130,7 @@ ArdourButton::ArdourButton (const std::string& str, Element e)
{
set_text (str);
ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
+ ARDOUR_UI_UTILS::DPIReset.connect (sigc::mem_fun (*this, &ArdourButton::on_name_changed));
}
ArdourButton::~ArdourButton()
@@ -373,11 +376,11 @@ ArdourButton::render (cairo_t* cr, cairo_rectangle_t *)
layout_font = false;
fd = get_pango_context()->get_font_description();
}
- printf("%s: f:%dx%d bh:%.0f tw:%d (%dx%d) %s\"%s\"\n",
+ printf("%s: f:%dx%d aw:%.3f bh:%.0f t:%dx%d (%dx%d) %s\"%s\"\n",
get_name().c_str(),
- char_pixel_width(), char_pixel_height(),
+ char_pixel_width(), char_pixel_height(), char_avg_pixel_width(),
ceil(char_pixel_height() * BASELINESTRETCH),
- _text_width,
+ _text_width, _text_height,
get_width(), get_height(),
layout_font ? "L:" : "W:",
fd.to_string().c_str());
@@ -601,23 +604,35 @@ ArdourButton::on_size_request (Gtk::Requisition* req)
if (_elements & (RecButton | CloseCross)) {
assert(!(_elements & Text));
- const int wh = std::max(3.5 * char_pixel_width(), ceil(char_pixel_height() * BASELINESTRETCH + 1));
+ const int wh = std::max (rint (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.));
req->width += wh;
req->height = std::max(req->height, wh);
}
- if (_tweaks & Square) {
- // squared buttons are also grouped, we cannot align all texts
- // -> skip proper center adjustment
+ /* Tweaks to mess the nice stuff above up again. */
+ if (_tweaks & TrackHeader) {
+ // forget everything above and just use a fixed square [em] size
+ // "TrackHeader Buttons" are single letter (usually uppercase)
+ // a SizeGroup is much less efficient (lots of gtk work under the hood for each track)
+ const int wh = std::max (rint (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.));
+ req->width = wh;
+ req->height = wh;
+ }
+ else if (_tweaks & Square) {
+ // currerntly unused (again)
if (req->width < req->height)
req->width = req->height;
if (req->height < req->width)
req->height = req->width;
} else if (_text_width > 0 && !(_elements & (Menu | Indicator))) {
// properly centered text for those elements that are centered
+ // (no sub-pixel offset)
if ((req->width - _text_width) & 1) { ++req->width; }
if ((req->height - _text_height) & 1) { ++req->height; }
}
+#if 0
+ printf("REQ: %s: %dx%d\n", get_name().c_str(), req->width, req->height);
+#endif
}
/**
@@ -1094,7 +1109,8 @@ ArdourButton::recalc_char_pixel_geometry ()
// number of actual chars in the string (not bytes)
// Glib to the rescue.
Glib::ustring gx(x);
- _char_pixel_width = std::max(4, w / (int)gx.size());
+ _char_avg_pixel_width = w / (float)gx.size();
+ _char_pixel_width = std::max(4, (int) ceil (_char_avg_pixel_width));
_layout->set_text (_text);
}
diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h
index c2b20c3ba9..9d59f1a9ea 100644
--- a/gtk2_ardour/ardour_button.h
+++ b/gtk2_ardour/ardour_button.h
@@ -55,7 +55,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
enum Tweaks {
Square = 0x1,
- unused2 = 0x2,
+ TrackHeader = 0x2,
unused3 = 0x4,
};
@@ -105,6 +105,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
+ float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
protected:
void render (cairo_t *, cairo_rectangle_t *);
@@ -133,6 +134,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
void recalc_char_pixel_geometry ();
unsigned int _char_pixel_width;
unsigned int _char_pixel_height;
+ float _char_avg_pixel_width;
int _text_width;
int _text_height;