mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
yet another button tweak..
This commit is contained in:
parent
5dab88c3fa
commit
cb07f0f99b
2 changed files with 27 additions and 9 deletions
|
|
@ -42,6 +42,7 @@
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
||||||
#define BASELINESTRETCH (1.25)
|
#define BASELINESTRETCH (1.25)
|
||||||
|
#define TRACKHEADERBTNW (3.10)
|
||||||
|
|
||||||
using namespace Gdk;
|
using namespace Gdk;
|
||||||
using namespace Gtk;
|
using namespace Gtk;
|
||||||
|
|
@ -60,6 +61,7 @@ ArdourButton::ArdourButton (Element e)
|
||||||
, _tweaks (Tweaks (0))
|
, _tweaks (Tweaks (0))
|
||||||
, _char_pixel_width (0)
|
, _char_pixel_width (0)
|
||||||
, _char_pixel_height (0)
|
, _char_pixel_height (0)
|
||||||
|
, _char_avg_pixel_width (0)
|
||||||
, _text_width (0)
|
, _text_width (0)
|
||||||
, _text_height (0)
|
, _text_height (0)
|
||||||
, _diameter (0)
|
, _diameter (0)
|
||||||
|
|
@ -128,6 +130,7 @@ ArdourButton::ArdourButton (const std::string& str, Element e)
|
||||||
{
|
{
|
||||||
set_text (str);
|
set_text (str);
|
||||||
ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
|
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()
|
ArdourButton::~ArdourButton()
|
||||||
|
|
@ -373,11 +376,11 @@ ArdourButton::render (cairo_t* cr, cairo_rectangle_t *)
|
||||||
layout_font = false;
|
layout_font = false;
|
||||||
fd = get_pango_context()->get_font_description();
|
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(),
|
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),
|
ceil(char_pixel_height() * BASELINESTRETCH),
|
||||||
_text_width,
|
_text_width, _text_height,
|
||||||
get_width(), get_height(),
|
get_width(), get_height(),
|
||||||
layout_font ? "L:" : "W:",
|
layout_font ? "L:" : "W:",
|
||||||
fd.to_string().c_str());
|
fd.to_string().c_str());
|
||||||
|
|
@ -601,23 +604,35 @@ ArdourButton::on_size_request (Gtk::Requisition* req)
|
||||||
|
|
||||||
if (_elements & (RecButton | CloseCross)) {
|
if (_elements & (RecButton | CloseCross)) {
|
||||||
assert(!(_elements & Text));
|
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->width += wh;
|
||||||
req->height = std::max(req->height, wh);
|
req->height = std::max(req->height, wh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_tweaks & Square) {
|
/* Tweaks to mess the nice stuff above up again. */
|
||||||
// squared buttons are also grouped, we cannot align all texts
|
if (_tweaks & TrackHeader) {
|
||||||
// -> skip proper center adjustment
|
// 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)
|
if (req->width < req->height)
|
||||||
req->width = req->height;
|
req->width = req->height;
|
||||||
if (req->height < req->width)
|
if (req->height < req->width)
|
||||||
req->height = req->width;
|
req->height = req->width;
|
||||||
} else if (_text_width > 0 && !(_elements & (Menu | Indicator))) {
|
} else if (_text_width > 0 && !(_elements & (Menu | Indicator))) {
|
||||||
// properly centered text for those elements that are centered
|
// properly centered text for those elements that are centered
|
||||||
|
// (no sub-pixel offset)
|
||||||
if ((req->width - _text_width) & 1) { ++req->width; }
|
if ((req->width - _text_width) & 1) { ++req->width; }
|
||||||
if ((req->height - _text_height) & 1) { ++req->height; }
|
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)
|
// number of actual chars in the string (not bytes)
|
||||||
// Glib to the rescue.
|
// Glib to the rescue.
|
||||||
Glib::ustring gx(x);
|
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);
|
_layout->set_text (_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
|
||||||
|
|
||||||
enum Tweaks {
|
enum Tweaks {
|
||||||
Square = 0x1,
|
Square = 0x1,
|
||||||
unused2 = 0x2,
|
TrackHeader = 0x2,
|
||||||
unused3 = 0x4,
|
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_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; }
|
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:
|
protected:
|
||||||
void render (cairo_t *, cairo_rectangle_t *);
|
void render (cairo_t *, cairo_rectangle_t *);
|
||||||
|
|
@ -133,6 +134,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
|
||||||
void recalc_char_pixel_geometry ();
|
void recalc_char_pixel_geometry ();
|
||||||
unsigned int _char_pixel_width;
|
unsigned int _char_pixel_width;
|
||||||
unsigned int _char_pixel_height;
|
unsigned int _char_pixel_height;
|
||||||
|
float _char_avg_pixel_width;
|
||||||
|
|
||||||
int _text_width;
|
int _text_width;
|
||||||
int _text_height;
|
int _text_height;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue