use clock text scaling for big clock window
This commit is contained in:
parent
d8405e2ebe
commit
9ca0ce4b7f
@ -36,15 +36,12 @@ using namespace ARDOUR_UI_UTILS;
|
|||||||
BigClockWindow::BigClockWindow (AudioClock& c)
|
BigClockWindow::BigClockWindow (AudioClock& c)
|
||||||
: ArdourWindow (_("Big Clock"))
|
: ArdourWindow (_("Big Clock"))
|
||||||
, clock (c)
|
, clock (c)
|
||||||
, resize_in_progress (false)
|
|
||||||
, original_height (0)
|
, original_height (0)
|
||||||
, original_width (0)
|
, original_width (0)
|
||||||
, original_font_size (0)
|
|
||||||
{
|
{
|
||||||
ARDOUR_UI::Clock.connect (sigc::mem_fun (clock, &AudioClock::set));
|
ARDOUR_UI::Clock.connect (sigc::mem_fun (clock, &AudioClock::set));
|
||||||
|
|
||||||
clock.set_corner_radius (0.0);
|
clock.set_corner_radius (0.0);
|
||||||
clock.mode_changed.connect (sigc::mem_fun (*this, &BigClockWindow::reset_aspect_ratio));
|
|
||||||
|
|
||||||
set_keep_above (true);
|
set_keep_above (true);
|
||||||
set_border_width (0);
|
set_border_width (0);
|
||||||
@ -69,24 +66,11 @@ BigClockWindow::on_key_press_event (GdkEventKey* ev)
|
|||||||
void
|
void
|
||||||
BigClockWindow::on_realize ()
|
BigClockWindow::on_realize ()
|
||||||
{
|
{
|
||||||
int x, y, w, d, h;
|
|
||||||
|
|
||||||
ArdourWindow::on_realize ();
|
ArdourWindow::on_realize ();
|
||||||
|
|
||||||
get_window()->set_decorations (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH);
|
get_window()->set_decorations (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH);
|
||||||
get_window()->get_geometry (x, y, w, h, d);
|
|
||||||
|
|
||||||
reset_aspect_ratio ();
|
int x, y, d;
|
||||||
|
get_window()->get_geometry (x, y, original_width, original_height, d);
|
||||||
original_height = h;
|
|
||||||
original_width = w;
|
|
||||||
|
|
||||||
Pango::FontDescription fd (clock.get_style()->get_font());
|
|
||||||
original_font_size = fd.get_size ();
|
|
||||||
|
|
||||||
if (!fd.get_size_is_absolute ()) {
|
|
||||||
original_font_size /= PANGO_SCALE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -94,67 +78,21 @@ BigClockWindow::on_size_allocate (Gtk::Allocation& alloc)
|
|||||||
{
|
{
|
||||||
ArdourWindow::on_size_allocate (alloc);
|
ArdourWindow::on_size_allocate (alloc);
|
||||||
|
|
||||||
if (!resize_in_progress) {
|
if (original_width) {
|
||||||
Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &BigClockWindow::text_resizer), 0, 0));
|
clock.set_scale ((double) alloc.get_width() / original_width,
|
||||||
resize_in_progress = true;
|
(double) alloc.get_height() / original_height);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::cerr << "Rescale to "
|
||||||
|
<< (double) alloc.get_width() / original_width
|
||||||
|
<< " x "
|
||||||
|
<< (double) alloc.get_height() / original_height
|
||||||
|
<< " using " << alloc.get_width() << " vs. " << original_width
|
||||||
|
<< " and " << alloc.get_height() << " vs. " << original_height
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
BigClockWindow::reset_aspect_ratio ()
|
|
||||||
{
|
|
||||||
Gtk::Requisition req = { 0, 0 };
|
|
||||||
|
|
||||||
clock.size_request (req);
|
|
||||||
|
|
||||||
float aspect = req.width/(float)req.height;
|
|
||||||
Gdk::Geometry geom;
|
|
||||||
|
|
||||||
geom.min_aspect = aspect;
|
|
||||||
geom.max_aspect = aspect;
|
|
||||||
|
|
||||||
set_geometry_hints (clock, geom, Gdk::HINT_ASPECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
BigClockWindow::text_resizer (int, int)
|
|
||||||
{
|
|
||||||
resize_in_progress = false;
|
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Window> win = get_window();
|
|
||||||
Pango::FontDescription fd (clock.get_style()->get_font());
|
|
||||||
int current_size = fd.get_size ();
|
|
||||||
int x, y, w, h, d;
|
|
||||||
|
|
||||||
if (!fd.get_size_is_absolute ()) {
|
|
||||||
current_size /= PANGO_SCALE;
|
|
||||||
}
|
|
||||||
|
|
||||||
win->get_geometry (x, y, w, h, d);
|
|
||||||
|
|
||||||
double scale = min (((double) w / (double) original_width),
|
|
||||||
((double) h / (double) original_height));
|
|
||||||
|
|
||||||
int size = (int) lrintf (original_font_size * scale);
|
|
||||||
|
|
||||||
if (size != current_size) {
|
|
||||||
|
|
||||||
string family = fd.get_family();
|
|
||||||
std::vector<char> buf(family.length()+16);
|
|
||||||
snprintf (&buf[0], family.length()+16, "%s %d", family.c_str(), size);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Pango::FontDescription fd (&buf[0]);
|
|
||||||
Glib::RefPtr<Gtk::RcStyle> rcstyle = clock.get_modifier_style ();
|
|
||||||
rcstyle->set_font (fd);
|
|
||||||
clock.modify_style (rcstyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (...) {
|
|
||||||
/* oh well, do nothing */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -26,23 +26,18 @@ class AudioClock;
|
|||||||
|
|
||||||
class BigClockWindow : public ArdourWindow
|
class BigClockWindow : public ArdourWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BigClockWindow (AudioClock&);
|
BigClockWindow (AudioClock&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AudioClock& clock;
|
AudioClock& clock;
|
||||||
bool resize_in_progress;
|
int original_height;
|
||||||
int original_height;
|
int original_width;
|
||||||
int original_width;
|
|
||||||
int original_font_size;
|
|
||||||
|
|
||||||
void on_size_allocate (Gtk::Allocation&);
|
void on_size_allocate (Gtk::Allocation&);
|
||||||
void on_realize ();
|
void on_realize ();
|
||||||
void on_unmap ();
|
void on_unmap ();
|
||||||
bool on_key_press_event (GdkEventKey*);
|
bool on_key_press_event (GdkEventKey*);
|
||||||
|
|
||||||
bool text_resizer (int, int);
|
|
||||||
void reset_aspect_ratio ();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __ardour_window_h__
|
#endif // __ardour_window_h__
|
||||||
|
Loading…
Reference in New Issue
Block a user