lots of clock tweaks, but still, STILL! not done, really
git-svn-id: svn://localhost/ardour2/branches/3.0@9678 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
@@ -942,7 +942,7 @@ style "recording_big_clock_display" = "non_recording_big_clock_display"
|
||||
|
||||
style "transport_clock_display"
|
||||
{
|
||||
font_name = "monospace @FONT_BOLD_BIG@"
|
||||
font_name = "@FONT_BOLD_BIG@"
|
||||
|
||||
fg[ACTIVE] = darker(@@COLPREFIX@_bright_indicator)
|
||||
fg[SELECTED] = darker(@@COLPREFIX@_bright_indicator)
|
||||
@@ -991,7 +991,7 @@ style "default_clock_display" = "medium_text"
|
||||
|
||||
style "selection_clock_display"
|
||||
{
|
||||
font_name = "monospace @FONT_SMALLER@"
|
||||
font_name = "@FONT_SMALLER@"
|
||||
|
||||
text[NORMAL] = @@COLPREFIX@_contrasting_indicator
|
||||
text[ACTIVE] = @@COLPREFIX@_bright_indicator
|
||||
@@ -1006,7 +1006,7 @@ style "selection_clock_display"
|
||||
|
||||
style "punch_clock_display" = "very_small_text"
|
||||
{
|
||||
font_name = "monospace @FONT_SMALLER@"
|
||||
font_name = "@FONT_SMALLER@"
|
||||
|
||||
text[NORMAL] = @@COLPREFIX@_contrasting_indicator
|
||||
text[ACTIVE] = @@COLPREFIX@_bright_indicator
|
||||
|
||||
@@ -388,12 +388,10 @@ ARDOUR_UI::setup_transport ()
|
||||
|
||||
HBox* clock_box = manage (new HBox);
|
||||
clock_box->set_border_width (2);
|
||||
primary_clock->main_display().set_ypad (2);
|
||||
primary_clock->set_border_width (2);
|
||||
clock_box->pack_start (*primary_clock, false, false);
|
||||
if (!ARDOUR::Profile->get_small_screen()) {
|
||||
secondary_clock->set_border_width (2);
|
||||
secondary_clock->main_display().set_ypad (2);
|
||||
clock_box->pack_start (*secondary_clock, false, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,14 +108,14 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
|
||||
|
||||
display = new CairoEditableText ();
|
||||
|
||||
_fixed_cells[Colon1] = new CairoColonCell (Colon1);
|
||||
_fixed_cells[Colon2] = new CairoColonCell (Colon2);
|
||||
_fixed_cells[Colon3] = new CairoColonCell (Colon3);
|
||||
_fixed_cells[Bar1] = new CairoBarCell (Bar1);
|
||||
_fixed_cells[Bar2] = new CairoBarCell (Bar2);
|
||||
_fixed_cells[Colon1] = new CairoCharCell (Colon1, ':');
|
||||
_fixed_cells[Colon2] = new CairoCharCell (Colon2, ':');
|
||||
_fixed_cells[Colon3] = new CairoCharCell (Colon3, ':');
|
||||
_fixed_cells[Bar1] = new CairoCharCell (Bar1, '|');
|
||||
_fixed_cells[Bar2] = new CairoCharCell (Bar2, '|');
|
||||
|
||||
// add an extra 0.6 "average char width" for the negative sign
|
||||
_text_cells[Timecode_Hours] = new CairoTextCell (Timecode_Hours, field_length[Timecode_Hours] + 0.6);
|
||||
// add an extra character for the negative sign
|
||||
_text_cells[Timecode_Hours] = new CairoTextCell (Timecode_Hours, field_length[Timecode_Hours] + 1);
|
||||
_text_cells[Timecode_Minutes] = new CairoTextCell (Timecode_Minutes, field_length[Timecode_Minutes]);
|
||||
_text_cells[Timecode_Seconds] = new CairoTextCell (Timecode_Seconds, field_length[Timecode_Seconds]);
|
||||
_text_cells[Timecode_Frames] = new CairoTextCell (Timecode_Frames, field_length[Timecode_Frames]);
|
||||
@@ -137,7 +137,7 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
|
||||
|
||||
_text_cells[AudioFrames] = new CairoTextCell (AudioFrames, field_length[AudioFrames]);
|
||||
|
||||
packer.set_homogeneous (false);
|
||||
set_homogeneous (false);
|
||||
|
||||
if (with_info) {
|
||||
|
||||
@@ -159,14 +159,14 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
|
||||
|
||||
top.pack_start (*display, true, true);
|
||||
|
||||
packer.set_spacing (1);
|
||||
packer.pack_start (top, true, true);
|
||||
packer.pack_start (bottom, false, false);
|
||||
set_spacing (1);
|
||||
|
||||
pack_start (top, true, true);
|
||||
pack_start (bottom, true, true);
|
||||
} else {
|
||||
packer.pack_start (*display, true, true);
|
||||
pack_start (*display, true, true);
|
||||
}
|
||||
|
||||
add (packer);
|
||||
show_all ();
|
||||
|
||||
set_widget_name (widget_name);
|
||||
@@ -191,13 +191,6 @@ AudioClock::~AudioClock ()
|
||||
/* XXX need to delete all cells too */
|
||||
}
|
||||
|
||||
void
|
||||
AudioClock::set_font (const string& font)
|
||||
{
|
||||
display->set_font (font);
|
||||
/* XXX supplemental ... */
|
||||
}
|
||||
|
||||
void
|
||||
AudioClock::set_widget_name (const string& name)
|
||||
{
|
||||
@@ -226,9 +219,10 @@ AudioClock::set_theme ()
|
||||
|
||||
display->set_font (font);
|
||||
|
||||
if (supplemental_right) {
|
||||
Pango::FontDescription smaller_font ("Sans 8");
|
||||
|
||||
/* propagate font style,but smaller, into supplemental text */
|
||||
if (supplemental_left) {
|
||||
boost::shared_ptr<CairoFontDescription> smaller_font (new CairoFontDescription (*display->font().get()));
|
||||
smaller_font->set_size (12);
|
||||
supplemental_right->set_font (smaller_font);
|
||||
supplemental_left->set_font (smaller_font);
|
||||
}
|
||||
@@ -303,7 +297,7 @@ AudioClock::end_edit ()
|
||||
void
|
||||
AudioClock::on_realize ()
|
||||
{
|
||||
Alignment::on_realize ();
|
||||
VBox::on_realize ();
|
||||
|
||||
/* styles are not available until the widgets are bound to a window */
|
||||
|
||||
@@ -1859,6 +1853,12 @@ AudioClock::set_mode (Mode m)
|
||||
/* clear information cells */
|
||||
supplemental_left->set_text (_text_cells[LowerLeft2], _(""));
|
||||
supplemental_right->set_text (_text_cells[LowerRight2], _(""));
|
||||
|
||||
/* propagate font style,but smaller, into cells */
|
||||
boost::shared_ptr<CairoFontDescription> smaller_font (new CairoFontDescription (*display->font().get()));
|
||||
smaller_font->set_size (12);
|
||||
supplemental_right->set_font (smaller_font);
|
||||
supplemental_left->set_font (smaller_font);
|
||||
}
|
||||
|
||||
if (_mode != Off) {
|
||||
@@ -1885,7 +1885,7 @@ AudioClock::set_bbt_reference (framepos_t pos)
|
||||
void
|
||||
AudioClock::on_style_changed (const Glib::RefPtr<Gtk::Style>& old_style)
|
||||
{
|
||||
Alignment::on_style_changed (old_style);
|
||||
VBox::on_style_changed (old_style);
|
||||
set_theme ();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace ARDOUR {
|
||||
class Session;
|
||||
}
|
||||
|
||||
class AudioClock : public Gtk::Alignment, public ARDOUR::SessionHandlePtr
|
||||
class AudioClock : public Gtk::VBox, public ARDOUR::SessionHandlePtr
|
||||
{
|
||||
public:
|
||||
enum Mode {
|
||||
@@ -65,7 +65,6 @@ class AudioClock : public Gtk::Alignment, public ARDOUR::SessionHandlePtr
|
||||
void set_is_duration (bool);
|
||||
|
||||
void set_widget_name (const std::string&);
|
||||
void set_font (const std::string&);
|
||||
|
||||
std::string name() const { return _name; }
|
||||
|
||||
@@ -137,7 +136,6 @@ class AudioClock : public Gtk::Alignment, public ARDOUR::SessionHandlePtr
|
||||
CairoEditableText* supplemental_left;
|
||||
CairoEditableText* supplemental_right;
|
||||
|
||||
Gtk::VBox packer;
|
||||
Gtk::HBox top;
|
||||
Gtk::HBox bottom;
|
||||
|
||||
|
||||
@@ -45,35 +45,37 @@ TimeInfoBox::TimeInfoBox ()
|
||||
punch_start = new AudioClock ("punch-start", false, "PunchClockDisplay", false, false, false, false);
|
||||
punch_end = new AudioClock ("punch-end", false, "PunchClockDisplay", false, false, false, false);
|
||||
|
||||
bool bg = true;
|
||||
|
||||
CairoEditableText& ss (selection_start->main_display());
|
||||
ss.set_ypad (1);
|
||||
ss.set_xpad (1);
|
||||
ss.set_corner_radius (0);
|
||||
ss.set_draw_background (false);
|
||||
ss.set_draw_background (bg);
|
||||
|
||||
CairoEditableText& se (selection_end->main_display());
|
||||
se.set_ypad (1);
|
||||
se.set_xpad (1);
|
||||
se.set_corner_radius (0);
|
||||
se.set_draw_background (false);
|
||||
se.set_draw_background (bg);
|
||||
|
||||
CairoEditableText& sl (selection_length->main_display());
|
||||
sl.set_ypad (1);
|
||||
sl.set_xpad (2);
|
||||
sl.set_corner_radius (0);
|
||||
sl.set_draw_background (false);
|
||||
sl.set_draw_background (bg);
|
||||
|
||||
CairoEditableText& ps (punch_start->main_display());
|
||||
ps.set_ypad (1);
|
||||
ps.set_xpad (2);
|
||||
ps.set_corner_radius (0);
|
||||
ps.set_draw_background (false);
|
||||
ps.set_draw_background (bg);
|
||||
|
||||
CairoEditableText& pe (punch_end->main_display());
|
||||
pe.set_ypad (1);
|
||||
pe.set_xpad (2);
|
||||
pe.set_corner_radius (0);
|
||||
pe.set_draw_background (false);
|
||||
pe.set_draw_background (bg);
|
||||
|
||||
selection_title.set_markup (string_compose ("<span size=\"x-small\">%1</span>", _("Selection")));
|
||||
punch_title.set_markup (string_compose ("<span size=\"x-small\">%1</span>", _("Punch")));
|
||||
@@ -189,18 +191,27 @@ TimeInfoBox::punch_changed (Location* loc)
|
||||
bool
|
||||
TimeInfoBox::on_expose_event (GdkEventExpose* ev)
|
||||
{
|
||||
Table::on_expose_event (ev);
|
||||
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Context> context = get_window()->create_cairo_context();
|
||||
int x, y;
|
||||
Gtk::Widget* window_parent;
|
||||
Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (*this, &window_parent);
|
||||
|
||||
if (win) {
|
||||
|
||||
context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
context->clip ();
|
||||
|
||||
context->set_source_rgba (0.01, 0.02, 0.21, 1.0);
|
||||
Gtkmm2ext::rounded_rectangle (context, 0, 0, get_allocation().get_width(), get_allocation().get_height(), 5);
|
||||
context->fill ();
|
||||
Cairo::RefPtr<Cairo::Context> context = win->create_cairo_context();
|
||||
|
||||
translate_coordinates (*window_parent, 0, 0, x, y);
|
||||
|
||||
context->rectangle (x, y, ev->area.width, ev->area.height);
|
||||
context->clip ();
|
||||
|
||||
context->set_source_rgba (0.149, 0.149, 0.149, 1.0);
|
||||
Gtkmm2ext::rounded_rectangle (context, x, y, get_allocation().get_width(), get_allocation().get_height(), 5);
|
||||
context->fill ();
|
||||
}
|
||||
}
|
||||
|
||||
Table::on_expose_event (ev);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -26,14 +26,67 @@
|
||||
|
||||
using std::string;
|
||||
using std::map;
|
||||
using std::max;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
using namespace Gtkmm2ext;
|
||||
|
||||
static const double cairo_font_fudge = 1.5;
|
||||
|
||||
CairoFontDescription::CairoFontDescription (Pango::FontDescription& fd)
|
||||
{
|
||||
_size = cairo_font_fudge * (fd.get_size() / PANGO_SCALE);
|
||||
|
||||
switch (fd.get_style()) {
|
||||
case Pango::STYLE_NORMAL:
|
||||
slant = Cairo::FONT_SLANT_NORMAL;
|
||||
break;
|
||||
case Pango::STYLE_OBLIQUE:
|
||||
slant = Cairo::FONT_SLANT_OBLIQUE;
|
||||
break;
|
||||
case Pango::STYLE_ITALIC:
|
||||
slant = Cairo::FONT_SLANT_ITALIC;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (fd.get_weight()) {
|
||||
case Pango::WEIGHT_ULTRALIGHT:
|
||||
weight = Cairo::FONT_WEIGHT_NORMAL;
|
||||
break;
|
||||
|
||||
case Pango::WEIGHT_LIGHT:
|
||||
weight = Cairo::FONT_WEIGHT_NORMAL;
|
||||
break;
|
||||
|
||||
case Pango::WEIGHT_NORMAL:
|
||||
weight = Cairo::FONT_WEIGHT_NORMAL;
|
||||
break;
|
||||
|
||||
case Pango::WEIGHT_SEMIBOLD:
|
||||
weight = Cairo::FONT_WEIGHT_BOLD;
|
||||
break;
|
||||
|
||||
case Pango::WEIGHT_BOLD:
|
||||
weight = Cairo::FONT_WEIGHT_BOLD;
|
||||
break;
|
||||
|
||||
case Pango::WEIGHT_ULTRABOLD:
|
||||
weight = Cairo::FONT_WEIGHT_BOLD;
|
||||
break;
|
||||
|
||||
case Pango::WEIGHT_HEAVY:
|
||||
weight = Cairo::FONT_WEIGHT_BOLD;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
face = fd.get_family();
|
||||
}
|
||||
|
||||
CairoCell::CairoCell (int32_t id)
|
||||
: _id (id)
|
||||
, _visible (true)
|
||||
, _xpad (2)
|
||||
, _xpad (0)
|
||||
{
|
||||
bbox.x = 0;
|
||||
bbox.y = 0;
|
||||
@@ -41,34 +94,19 @@ CairoCell::CairoCell (int32_t id)
|
||||
bbox.height = 0;
|
||||
}
|
||||
|
||||
void
|
||||
CairoColonCell::render (Cairo::RefPtr<Cairo::Context>& context)
|
||||
{
|
||||
/* two very small circles */
|
||||
context->arc (bbox.x, bbox.y + (bbox.height/3.0), bbox.width/2.0, 0.0, M_PI*2.0);
|
||||
context->fill ();
|
||||
context->arc (bbox.x, bbox.y + (2.0 * bbox.height/3.0), bbox.width/2.0, 0.0, M_PI*2.0);
|
||||
context->fill ();
|
||||
}
|
||||
|
||||
void
|
||||
CairoColonCell::set_size (Glib::RefPtr<Pango::Context>& context, const Pango::FontDescription& font)
|
||||
{
|
||||
Pango::FontMetrics metrics = context->get_metrics (font);
|
||||
bbox.width = std::max (3.0, (0.25 * metrics.get_approximate_char_width() / PANGO_SCALE));
|
||||
bbox.height = (metrics.get_ascent() + metrics.get_descent()) / PANGO_SCALE;
|
||||
}
|
||||
|
||||
CairoTextCell::CairoTextCell (int32_t id, double wc)
|
||||
CairoTextCell::CairoTextCell (int32_t id, double wc, boost::shared_ptr<CairoFontDescription> font)
|
||||
: CairoCell (id)
|
||||
, _width_chars (wc)
|
||||
, _font (font)
|
||||
, y_offset (0)
|
||||
, x_offset (0)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
CairoTextCell::set_text (const std::string& txt)
|
||||
{
|
||||
layout->set_text (txt);
|
||||
_text = txt;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -78,36 +116,89 @@ CairoTextCell::render (Cairo::RefPtr<Cairo::Context>& context)
|
||||
return;
|
||||
}
|
||||
|
||||
context->move_to (bbox.x, bbox.y);
|
||||
pango_cairo_update_layout (context->cobj(), layout->gobj());
|
||||
pango_cairo_show_layout (context->cobj(), layout->gobj());
|
||||
_font->apply (context);
|
||||
context->move_to (bbox.x, bbox.y + bbox.height + y_offset);
|
||||
context->show_text (_text);
|
||||
}
|
||||
|
||||
void
|
||||
CairoTextCell::set_size (Glib::RefPtr<Pango::Context>& context, const Pango::FontDescription& font)
|
||||
CairoTextCell::set_size (Cairo::RefPtr<Cairo::Context>& context)
|
||||
{
|
||||
if (!layout) {
|
||||
layout = Pango::Layout::create (context);
|
||||
const uint32_t lim = (uint32_t) ceil (_width_chars);
|
||||
char buf[lim+1];
|
||||
uint32_t n;
|
||||
double max_width = 0.0;
|
||||
double max_height = 0.0;
|
||||
Cairo::TextExtents ext;
|
||||
double bsum = 0;
|
||||
|
||||
buf[lim] = '\0';
|
||||
|
||||
_font->apply (context);
|
||||
|
||||
for (int digit = 0; digit < 10; digit++) {
|
||||
|
||||
for (n = 0; n < lim; ++n) {
|
||||
buf[n] = '0' + digit;
|
||||
}
|
||||
|
||||
context->get_text_extents (buf, ext);
|
||||
|
||||
max_width = max (ext.width + ext.x_bearing, max_width);
|
||||
max_height = max (ext.height, max_height);
|
||||
bsum += ext.x_bearing;
|
||||
}
|
||||
|
||||
layout->set_font_description (font);
|
||||
/* add the average x-bearing for all digits as right hand side padding */
|
||||
|
||||
Pango::FontMetrics metrics = context->get_metrics (font);
|
||||
bbox.width = max_width + (bsum/10.0);
|
||||
|
||||
bbox.width = (_width_chars * metrics.get_approximate_digit_width ()) / PANGO_SCALE;
|
||||
bbox.height = (metrics.get_ascent() + metrics.get_descent()) / PANGO_SCALE;
|
||||
/* some fonts and some digits get their extents computed "too small", so fudge this
|
||||
by adding 2
|
||||
*/
|
||||
bbox.height = max_height;
|
||||
}
|
||||
|
||||
CairoEditableText::CairoEditableText ()
|
||||
CairoCharCell::CairoCharCell (int32_t id, char c)
|
||||
: CairoTextCell (id, 1)
|
||||
{
|
||||
_text = c;
|
||||
}
|
||||
|
||||
void
|
||||
CairoCharCell::set_size (Cairo::RefPtr<Cairo::Context>& context)
|
||||
{
|
||||
Cairo::TextExtents ext;
|
||||
|
||||
_font->apply (context);
|
||||
|
||||
{
|
||||
const char* buf = "8";
|
||||
context->get_text_extents (buf, ext);
|
||||
/* same height as an "8" */
|
||||
bbox.height = ext.height;
|
||||
}
|
||||
|
||||
{
|
||||
const char* buf = ":";
|
||||
context->get_text_extents (buf, ext);
|
||||
bbox.width = ext.width + (2.0 * ext.x_bearing);
|
||||
/* center vertically */
|
||||
y_offset = (ext.height - bbox.height) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
CairoEditableText::CairoEditableText (boost::shared_ptr<CairoFontDescription> font)
|
||||
: editing_cell (0)
|
||||
, _draw_bg (true)
|
||||
, width (0)
|
||||
, max_cell_width (0)
|
||||
, max_cell_height (0)
|
||||
, height (0)
|
||||
, _corner_radius (9)
|
||||
, _xpad (5)
|
||||
, _ypad (5)
|
||||
, _xpad (0)
|
||||
, _ypad (0)
|
||||
{
|
||||
set_font (font);
|
||||
|
||||
add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK |
|
||||
Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::SCROLL_MASK);
|
||||
set_flags (Gtk::CAN_FOCUS);
|
||||
@@ -152,11 +243,15 @@ CairoEditableText::on_focus_out_event (GdkEventFocus* ev)
|
||||
void
|
||||
CairoEditableText::add_cell (CairoCell* cell)
|
||||
{
|
||||
Glib::RefPtr<Pango::Context> context = get_pango_context ();
|
||||
cell->set_size (context, _font);
|
||||
cells.push_back (cell);
|
||||
|
||||
CairoTextCell* tc = dynamic_cast<CairoTextCell*>(cell);
|
||||
|
||||
if (tc) {
|
||||
tc->set_font (_font);
|
||||
}
|
||||
|
||||
queue_resize ();
|
||||
queue_draw ();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -164,7 +259,6 @@ CairoEditableText::clear_cells ()
|
||||
{
|
||||
cells.clear ();
|
||||
queue_resize ();
|
||||
queue_draw ();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -195,6 +289,10 @@ CairoEditableText::on_expose_event (GdkEventExpose* ev)
|
||||
context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
context->clip ();
|
||||
|
||||
Gtk::Allocation alloc = get_allocation ();
|
||||
double width = alloc.get_width();
|
||||
double height = alloc.get_height ();
|
||||
|
||||
if (_draw_bg) {
|
||||
context->set_source_rgba (bg_r, bg_g, bg_b, bg_a);
|
||||
if (_corner_radius) {
|
||||
@@ -204,14 +302,14 @@ CairoEditableText::on_expose_event (GdkEventExpose* ev)
|
||||
}
|
||||
context->fill ();
|
||||
}
|
||||
|
||||
|
||||
for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) {
|
||||
|
||||
CairoCell* cell = (*i);
|
||||
|
||||
/* is cell inside the expose area?
|
||||
*/
|
||||
|
||||
|
||||
if (cell->intersects (ev->area)) {
|
||||
if (cell == editing_cell) {
|
||||
context->set_source_rgba (edit_r, edit_b, edit_g, edit_a);
|
||||
@@ -294,40 +392,40 @@ CairoEditableText::stop_editing ()
|
||||
}
|
||||
|
||||
void
|
||||
CairoEditableText::on_size_request (GtkRequisition* req)
|
||||
CairoEditableText::set_cell_sizes ()
|
||||
{
|
||||
double x = 0;
|
||||
Glib::RefPtr<Gdk::Window> win = get_window();
|
||||
|
||||
max_cell_height = 0;
|
||||
|
||||
x = _xpad;
|
||||
|
||||
CellMap::iterator i = cells.begin();
|
||||
|
||||
while (i != cells.end()) {
|
||||
CairoCell* cell = (*i);
|
||||
|
||||
if (cell->visible()) {
|
||||
cell->set_position (x, _ypad);
|
||||
}
|
||||
|
||||
x += cell->width();
|
||||
max_cell_height = std::max ((double) cell->height(), max_cell_height);
|
||||
|
||||
++i;
|
||||
|
||||
if (i != cells.end()) {
|
||||
/* only add cell padding intra-cellularly */
|
||||
x += cell->xpad();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (!win) {
|
||||
return;
|
||||
}
|
||||
|
||||
Cairo::RefPtr<Cairo::Context> context = win->create_cairo_context();
|
||||
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
|
||||
x += _xpad;
|
||||
for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) {
|
||||
(*i)->set_size (context);
|
||||
}
|
||||
}
|
||||
|
||||
req->width = x;
|
||||
req->height = max_cell_height + (_ypad * 2);
|
||||
void
|
||||
CairoEditableText::on_size_request (GtkRequisition* req)
|
||||
{
|
||||
set_cell_sizes ();
|
||||
|
||||
max_cell_width = 0;
|
||||
max_cell_height = 0;
|
||||
|
||||
for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) {
|
||||
max_cell_width += (*i)->width();
|
||||
max_cell_height = std::max ((double) (*i)->height(), max_cell_height);
|
||||
}
|
||||
|
||||
req->width = max_cell_width;
|
||||
req->height = max_cell_height;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -335,27 +433,49 @@ CairoEditableText::on_size_allocate (Gtk::Allocation& alloc)
|
||||
{
|
||||
Misc::on_size_allocate (alloc);
|
||||
|
||||
width = alloc.get_width();
|
||||
height = alloc.get_height();
|
||||
/* position each cell so that its centered in the allocated space
|
||||
*/
|
||||
|
||||
double x = (alloc.get_width() - max_cell_width)/2.0;
|
||||
double y = (alloc.get_height() - max_cell_height)/2.0;
|
||||
|
||||
CellMap::iterator i = cells.begin();
|
||||
|
||||
while (i != cells.end()) {
|
||||
CairoCell* cell = (*i);
|
||||
|
||||
cell->set_position (x, y);
|
||||
x += cell->width ();
|
||||
|
||||
if (++i != cells.end()) {
|
||||
/* only add cell padding intra-cellularly */
|
||||
x += cell->xpad();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CairoEditableText::set_font (const std::string& str)
|
||||
CairoEditableText::set_font (Pango::FontDescription& fd)
|
||||
{
|
||||
set_font (Pango::FontDescription (str));
|
||||
boost::shared_ptr<CairoFontDescription> cd (new CairoFontDescription (fd));
|
||||
set_font (cd);
|
||||
}
|
||||
|
||||
void
|
||||
CairoEditableText::set_font (const Pango::FontDescription& fd)
|
||||
CairoEditableText::set_font (boost::shared_ptr<CairoFontDescription> fd)
|
||||
{
|
||||
Glib::RefPtr<Pango::Context> context = get_pango_context ();
|
||||
for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) {
|
||||
CairoTextCell* tc = dynamic_cast<CairoTextCell*>(*i);
|
||||
if (tc && (!tc->font() || tc->font() == _font)) {
|
||||
tc->set_font (fd);
|
||||
}
|
||||
}
|
||||
|
||||
_font = fd;
|
||||
|
||||
for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) {
|
||||
(*i)->set_size (context, _font);
|
||||
}
|
||||
|
||||
queue_resize ();
|
||||
queue_draw ();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
#include <map>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <cairomm/cairomm.h>
|
||||
#include <gtkmm.h>
|
||||
|
||||
@@ -41,7 +44,7 @@ class CairoCell
|
||||
double width() const { return bbox.width; }
|
||||
double height() const { return bbox.height; }
|
||||
|
||||
void set_position (double x, double y) {
|
||||
void set_position (double x, double y) {
|
||||
bbox.x = x;
|
||||
bbox.y = y;
|
||||
}
|
||||
@@ -60,8 +63,7 @@ class CairoCell
|
||||
|
||||
void set_visible (bool yn) { _visible = yn; }
|
||||
bool visible() const { return _visible; }
|
||||
virtual void set_size (Glib::RefPtr<Pango::Context>&,
|
||||
const Pango::FontDescription&) {}
|
||||
virtual void set_size (Cairo::RefPtr<Cairo::Context>&) {}
|
||||
|
||||
protected:
|
||||
int32_t _id;
|
||||
@@ -70,67 +72,79 @@ class CairoCell
|
||||
uint32_t _xpad;
|
||||
};
|
||||
|
||||
class CairoBarCell : public CairoCell
|
||||
{
|
||||
class CairoFontDescription {
|
||||
public:
|
||||
CairoBarCell(int32_t id) : CairoCell (id) {};
|
||||
CairoFontDescription (const std::string& f,
|
||||
Cairo::FontSlant s,
|
||||
Cairo::FontWeight w,
|
||||
double sz)
|
||||
: face (f)
|
||||
, slant (s)
|
||||
, weight (w)
|
||||
, _size (sz)
|
||||
{}
|
||||
CairoFontDescription (Pango::FontDescription&);
|
||||
|
||||
void render (Cairo::RefPtr<Cairo::Context>& context) {
|
||||
if (bbox.height > 4) {
|
||||
context->move_to (bbox.x, bbox.y + 2);
|
||||
context->set_line_width (bbox.width);
|
||||
context->rel_line_to (0, bbox.height - 2);
|
||||
context->stroke ();
|
||||
}
|
||||
void apply (Cairo::RefPtr<Cairo::Context> context) {
|
||||
context->select_font_face (face, slant, weight);
|
||||
context->set_font_size (_size);
|
||||
}
|
||||
|
||||
void set_size (Glib::RefPtr<Pango::Context>& context,
|
||||
const Pango::FontDescription& font) {
|
||||
Pango::FontMetrics metrics = context->get_metrics (font);
|
||||
bbox.width = std::max (1.5, (0.1 * metrics.get_approximate_digit_width() / PANGO_SCALE));
|
||||
bbox.height = (metrics.get_ascent() + metrics.get_descent()) / PANGO_SCALE;
|
||||
}
|
||||
void set_size (double sz) { _size = sz; }
|
||||
double size() const { return _size; }
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class CairoColonCell : public CairoCell
|
||||
{
|
||||
public:
|
||||
CairoColonCell (int32_t id) : CairoCell (id) {};
|
||||
|
||||
void render (Cairo::RefPtr<Cairo::Context>& context);
|
||||
void set_size (Glib::RefPtr<Pango::Context>& context,
|
||||
const Pango::FontDescription& font);
|
||||
std::string face;
|
||||
Cairo::FontSlant slant;
|
||||
Cairo::FontWeight weight;
|
||||
double _size;
|
||||
};
|
||||
|
||||
class CairoTextCell : public CairoCell
|
||||
{
|
||||
public:
|
||||
CairoTextCell (int32_t id, double width_chars);
|
||||
void set_size (Glib::RefPtr<Pango::Context>&, const Pango::FontDescription&);
|
||||
CairoTextCell (int32_t id, double width_chars, boost::shared_ptr<CairoFontDescription> font = boost::shared_ptr<CairoFontDescription>());
|
||||
~CairoTextCell() {}
|
||||
|
||||
virtual void set_size (Cairo::RefPtr<Cairo::Context>&);
|
||||
|
||||
boost::shared_ptr<CairoFontDescription> font() const { return _font; }
|
||||
|
||||
std::string get_text() const {
|
||||
return layout->get_text ();
|
||||
return _text;
|
||||
}
|
||||
double width_chars() const { return _width_chars; }
|
||||
|
||||
double width_chars() const { return _width_chars; }
|
||||
void render (Cairo::RefPtr<Cairo::Context>&);
|
||||
|
||||
protected:
|
||||
friend class CairoEditableText;
|
||||
void set_width_chars (double wc) { _width_chars = wc; }
|
||||
void set_text (const std::string& txt);
|
||||
void set_font (boost::shared_ptr<CairoFontDescription> font) {
|
||||
_font = font;
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
double _width_chars;
|
||||
Glib::RefPtr<Pango::Layout> layout;
|
||||
std::string _text;
|
||||
boost::shared_ptr<CairoFontDescription> _font;
|
||||
double y_offset;
|
||||
double x_offset;
|
||||
};
|
||||
|
||||
class CairoCharCell : public CairoTextCell
|
||||
{
|
||||
public:
|
||||
CairoCharCell(int32_t id, char c);
|
||||
|
||||
void set_size (Cairo::RefPtr<Cairo::Context>& context);
|
||||
};
|
||||
|
||||
class CairoEditableText : public Gtk::Misc
|
||||
{
|
||||
public:
|
||||
CairoEditableText ();
|
||||
CairoEditableText (boost::shared_ptr<CairoFontDescription> font = boost::shared_ptr<CairoFontDescription>());
|
||||
~CairoEditableText ();
|
||||
|
||||
void add_cell (CairoCell*);
|
||||
@@ -168,9 +182,6 @@ public:
|
||||
queue_draw ();
|
||||
}
|
||||
|
||||
void set_font (const std::string& str);
|
||||
void set_font (const Pango::FontDescription&);
|
||||
|
||||
double xpad() const { return _xpad; }
|
||||
void set_xpad (double x) { _xpad = x; queue_resize(); }
|
||||
double ypad() const { return _ypad; }
|
||||
@@ -178,7 +189,11 @@ public:
|
||||
|
||||
double corner_radius() const { return _corner_radius; }
|
||||
void set_corner_radius (double r) { _corner_radius = r; queue_draw (); }
|
||||
|
||||
|
||||
boost::shared_ptr<CairoFontDescription> font() const { return _font; }
|
||||
void set_font (boost::shared_ptr<CairoFontDescription> font);
|
||||
void set_font (Pango::FontDescription& font);
|
||||
|
||||
sigc::signal<bool,GdkEventScroll*,CairoCell*> scroll;
|
||||
sigc::signal<bool,GdkEventButton*,CairoCell*> button_press;
|
||||
sigc::signal<bool,GdkEventButton*,CairoCell*> button_release;
|
||||
@@ -188,21 +203,20 @@ protected:
|
||||
bool on_button_press_event (GdkEventButton*);
|
||||
bool on_button_release_event (GdkEventButton*);
|
||||
void on_size_request (GtkRequisition*);
|
||||
void on_size_allocate (Gtk::Allocation&);
|
||||
bool on_focus_in_event (GdkEventFocus*);
|
||||
bool on_focus_out_event (GdkEventFocus*);
|
||||
bool on_scroll_event (GdkEventScroll*);
|
||||
void on_size_allocate (Gtk::Allocation&);
|
||||
|
||||
private:
|
||||
typedef std::vector<CairoCell*> CellMap;
|
||||
|
||||
CellMap cells;
|
||||
Pango::FontDescription _font;
|
||||
boost::shared_ptr<CairoFontDescription> _font;
|
||||
CairoCell* editing_cell;
|
||||
bool _draw_bg;
|
||||
double width;
|
||||
double max_cell_width;
|
||||
double max_cell_height;
|
||||
double height;
|
||||
double _corner_radius;
|
||||
double _xpad;
|
||||
double _ypad;
|
||||
@@ -221,6 +235,8 @@ private:
|
||||
|
||||
CairoCell* find_cell (uint32_t x, uint32_t y);
|
||||
void queue_draw_cell (CairoCell* target);
|
||||
void position_cells_and_get_bbox (GdkRectangle&);
|
||||
void set_cell_sizes ();
|
||||
};
|
||||
|
||||
#endif /* __libgtmm2ext_cairocell_h__ */
|
||||
|
||||
@@ -88,6 +88,8 @@ namespace Gtkmm2ext {
|
||||
Glib::RefPtr<Gdk::Drawable> get_bogus_drawable();
|
||||
void detach_menu (Gtk::Menu&);
|
||||
|
||||
Glib::RefPtr<Gdk::Window> window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent);
|
||||
|
||||
bool possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval);
|
||||
uint32_t possibly_translate_legal_accelerator_to_real_key (uint32_t keyval);
|
||||
|
||||
|
||||
@@ -468,3 +468,23 @@ Gtkmm2ext::rounded_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, d
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Glib::RefPtr<Gdk::Window>
|
||||
Gtkmm2ext::window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent)
|
||||
{
|
||||
if (w.get_has_window()) {
|
||||
return w.get_window();
|
||||
}
|
||||
|
||||
(*parent) = w.get_parent();
|
||||
|
||||
while (*parent) {
|
||||
if ((*parent)->get_has_window()) {
|
||||
return (*parent)->get_window ();
|
||||
}
|
||||
(*parent) = (*parent)->get_parent ();
|
||||
}
|
||||
|
||||
return Glib::RefPtr<Gdk::Window> ();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user