2 Copyright (C) 20002-2013 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "ardour_ui.h"
24 #include "audio_clock.h"
25 #include "big_clock_window.h"
26 #include "public_editor.h"
34 BigClockWindow::BigClockWindow (AudioClock& c)
35 : ArdourWindow (_("Big Clock"))
37 , resize_in_progress (false)
40 , original_font_size (0)
42 ARDOUR_UI::Clock.connect (sigc::mem_fun (clock, &AudioClock::set));
44 clock.set_corner_radius (0.0);
45 clock.mode_changed.connect (sigc::mem_fun (*this, &BigClockWindow::reset_aspect_ratio));
47 set_keep_above (true);
54 BigClockWindow::on_unmap ()
56 PublicEditor::instance().reset_focus ();
60 BigClockWindow::on_key_press_event (GdkEventKey* ev)
62 return relay_key_press (ev, this);
66 BigClockWindow::on_realize ()
70 ArdourWindow::on_realize ();
72 get_window()->set_decorations (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH);
73 get_window()->get_geometry (x, y, w, h, d);
75 reset_aspect_ratio ();
80 Pango::FontDescription fd (clock.get_style()->get_font());
81 original_font_size = fd.get_size ();
83 if (!fd.get_size_is_absolute ()) {
84 original_font_size /= PANGO_SCALE;
89 BigClockWindow::on_size_allocate (Gtk::Allocation& alloc)
91 ArdourWindow::on_size_allocate (alloc);
93 if (!resize_in_progress) {
94 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &BigClockWindow::text_resizer), 0, 0));
95 resize_in_progress = true;
100 BigClockWindow::reset_aspect_ratio ()
102 Gtk::Requisition req;
104 clock.size_request (req);
106 float aspect = req.width/(float)req.height;
109 geom.min_aspect = aspect;
110 geom.max_aspect = aspect;
112 set_geometry_hints (clock, geom, Gdk::HINT_ASPECT);
116 BigClockWindow::text_resizer (int, int)
118 resize_in_progress = false;
120 Glib::RefPtr<Gdk::Window> win = get_window();
121 Pango::FontDescription fd (clock.get_style()->get_font());
122 int current_size = fd.get_size ();
125 if (!fd.get_size_is_absolute ()) {
126 current_size /= PANGO_SCALE;
129 win->get_geometry (x, y, w, h, d);
131 double scale = min (((double) w / (double) original_width),
132 ((double) h / (double) original_height));
134 int size = (int) lrintf (original_font_size * scale);
136 if (size != current_size) {
138 string family = fd.get_family();
139 char buf[family.length()+16];
140 snprintf (buf, family.length()+16, "%s %d", family.c_str(), size);
143 Pango::FontDescription fd (buf);
144 Glib::RefPtr<Gtk::RcStyle> rcstyle = clock.get_modifier_style ();
145 rcstyle->set_font (fd);
146 clock.modify_style (rcstyle);
150 /* oh well, do nothing */