79
void TimeBar::on_realize()
81
// FIXME: for some reason, the timebar get realized EACH TIME
82
// the timerbox is cycled...
83
// We need to call the base on_realize()
84
Gtk::DrawingArea::on_realize();
86
// Now we can allocate any additional resources we need
87
Glib::RefPtr<Gdk::Window> window = get_window();
88
window_gc = Gdk::GC::create(window);
90
Glib::RefPtr<Gtk::Style> style = get_style();
91
Gdk::Color bg = style->get_bg(Gtk::STATE_NORMAL);
92
bar_colors[COLOR_ID_BG] = bg;
94
Glib::RefPtr<Gdk::Colormap> colormap = get_colormap();
95
for (int i = 0; i < COLOR_ID_SIZEOF; i++)
97
colormap->alloc_color(bar_colors[i]);
104
TimeBar::on_size_request(GtkRequisition *requisition)
108
get_preferred_size(width, height);
110
if (rotation == 0 || rotation == 180)
112
requisition->width = width;
113
requisition->height = height;
117
requisition->width = height;
118
requisition->height = width;
79
//! Sets the time progress to be displayed.
81
TimeBar::set_progress(int value, int max_value)
83
if (value > max_value)
89
bar_max_value = max_value;
93
//! Sets the secondary time progress to be displayed.
95
TimeBar::set_secondary_progress(int value, int max_value)
97
if (value > max_value)
102
secondary_bar_value = value;
103
secondary_bar_max_value = max_value;
107
//! Sets the text to be displayed.
109
TimeBar::set_text(string text)
115
//! Sets text alignment
117
TimeBar::set_text_alignment(int align)
119
bar_text_align = align;
123
//! Sets the color of the bar.
125
TimeBar::set_bar_color(ColorId color)
131
//! Sets the color of the secondary bar.
133
TimeBar::set_secondary_bar_color(ColorId color)
135
secondary_bar_color = color;
139
//! Sets the text color.
141
TimeBar::set_text_color(Gdk::Color color)
143
bar_text_color = color;
148
TimeBar::set_rotation(int r)
155
//! Updates the screen.
156
void TimeBar::update()
503
506
window->draw_rectangle(gc, filled, y, winw - x - width, height, width);
513
TimeBar::get_request_mode_vfunc() const
515
return Gtk::Widget::get_request_mode_vfunc();
519
TimeBar::get_preferred_width_vfunc(int &minimum_width, int &natural_width) const
522
get_preferred_size(width, height);
524
if (rotation == 0 || rotation == 180)
526
minimum_width = natural_width = width;
530
minimum_width = natural_width = height;
535
TimeBar::get_preferred_height_vfunc(int &minimum_height, int &natural_height) const
538
get_preferred_size(width, height);
540
if (rotation == 0 || rotation == 180)
542
minimum_height = natural_height = height;
546
minimum_height = natural_height = width;
551
TimeBar::get_preferred_width_for_height_vfunc(int /* height */, int &minimum_width, int &natural_width) const
553
get_preferred_width_vfunc(minimum_width, natural_width);
557
TimeBar::get_preferred_height_for_width_vfunc(int /* width */, int &minimum_height, int &natural_height) const
559
get_preferred_height_vfunc(minimum_height, natural_height);
563
TimeBar::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
565
const int border_size = 1;
567
Glib::RefPtr<Gtk::StyleContext> style_context = get_style_context();
568
Gtk::Allocation allocation = get_allocation();
570
style_context->context_save();
571
style_context->add_class(GTK_STYLE_CLASS_FRAME);
573
// Physical width/height
574
int win_w = allocation.get_width() - 2; // FIXME:
575
int win_h = allocation.get_height();
577
// Logical width/height
578
// width = direction of bar
580
if (rotation == 0 || rotation == 180)
592
style_context->set_state(Gtk::STATE_FLAG_ACTIVE);
593
Gdk::RGBA back_color = style_context->get_background_color();
594
set_color(cr, back_color);
596
// clip to the area indicated by the expose event so that we only redraw
597
// the portion of the window that needs to be redrawn
598
cr->rectangle(0, 0, win_w, win_h);
601
style_context->context_save();
602
style_context->set_state((Gtk::StateFlags)Gtk::STATE_FLAG_ACTIVE);
603
style_context->render_background(cr, 0, 0, win_w - 1, win_h -1);
604
style_context->render_frame(cr, 0, 0, win_w - 1, win_h -1);
605
style_context->context_restore();
607
// set_color(cr, back_color);
608
// cr->rectangle(border_size, border_size, win_w - 2*border_size, win_h - 2*border_size);
613
if (bar_max_value > 0)
615
bar_width = (bar_value * (win_lw - 2 * border_size - 1)) / bar_max_value;
620
if (secondary_bar_max_value > 0)
622
sbar_width = (secondary_bar_value * (win_lw - 2 * border_size - 1)) / secondary_bar_max_value;
625
int bar_height = win_lh - 2 * border_size - 1;
631
// We should assert() because this is not supported
632
// but there are some weird boundary cases
633
// in which this still happens.. need to check
634
// this out some time.
635
// assert(secondary_bar_color == COLOR_ID_INACTIVE);
636
ColorId overlap_color;
639
case COLOR_ID_ACTIVE:
640
overlap_color = COLOR_ID_INACTIVE_OVER_ACTIVE;
642
case COLOR_ID_OVERDUE:
643
overlap_color = COLOR_ID_INACTIVE_OVER_OVERDUE;
646
// We could abort() because this is not supported
647
// but there are some weird boundary cases
648
// in which this still happens.. need to check
649
// this out some time.
650
overlap_color = COLOR_ID_INACTIVE_OVER_ACTIVE;
653
if (sbar_width >= bar_width)
657
set_color(cr, bar_colors[overlap_color]);
659
border_size, border_size,
660
bar_width, bar_height,
663
if (sbar_width > bar_width)
665
set_color(cr, bar_colors[secondary_bar_color]);
667
border_size + bar_width, border_size,
668
sbar_width - bar_width, bar_height,
676
set_color(cr, bar_colors[overlap_color]);
678
border_size, border_size,
679
sbar_width, bar_height,
682
set_color(cr, bar_colors[bar_color]);
684
border_size + sbar_width, border_size,
685
bar_width - sbar_width, bar_height,
692
set_color(cr, bar_colors[bar_color]);
694
border_size, border_size,
695
bar_width, bar_height, win_lw, win_lh);
700
Pango::Matrix matrix = PANGO_MATRIX_INIT;
701
pango_matrix_rotate(&matrix, 360 - rotation);
703
Glib::RefPtr<Pango::Layout> pl1 = create_pango_layout(bar_text);
704
Glib::RefPtr<Pango::Context> pc1 = pl1->get_context();
706
pc1->set_matrix(matrix);
708
int text_width, text_height;
709
pl1->get_pixel_size(text_width, text_height);
713
Gdk::Rectangle rect1, rect2;
715
if (rotation == 0 || rotation == 180)
717
if (win_w - text_width - MARGINX > 0)
719
if (bar_text_align > 0)
720
text_x = (win_w - text_width - MARGINX);
721
else if (bar_text_align < 0)
724
text_x = (win_w - text_width) / 2;
730
text_y = (win_h - text_height) / 2;
732
int left_width = (bar_width > sbar_width) ? bar_width : sbar_width;
733
left_width += border_size;
735
Gdk::Rectangle left_rect(0, 0, left_width, win_h);
736
Gdk::Rectangle right_rect(left_width, 0, win_w - left_width, win_h);
743
if (win_h - text_width - MARGINY > 0)
745
int a = bar_text_align;
751
text_y = (win_h - text_width - MARGINY);
755
text_y = (win_h - text_width) / 2;
762
text_x = (win_w - text_height) / 2;
764
int left_width = (bar_width > sbar_width) ? bar_width : sbar_width;
765
left_width += border_size;
767
Gdk::Rectangle up_rect(0, 0, win_w, left_width);
768
Gdk::Rectangle down_rect(0, left_width, win_w, win_h - left_width);
775
cr->rectangle(rect1.get_x(), rect1.get_y(), rect1.get_width(), rect1.get_height());
778
cr->move_to(text_x, text_y);
779
set_color(cr, bar_text_color);
780
pl1->show_in_cairo_context(cr);
782
Gdk::RGBA front_color = style_context->get_color();
784
cr->rectangle(rect2.get_x(), rect2.get_y(), rect2.get_width(), rect2.get_height());
786
cr->move_to(text_x, text_y);
787
set_color(cr, front_color);
788
pl1->show_in_cairo_context(cr);
790
style_context->context_restore();
792
return Gtk::Widget::on_draw(cr);
796
TimeBar::set_color(const Cairo::RefPtr<Cairo::Context>& cr, const Gdk::Color &color)
798
cr->set_source_rgb(color.get_red_p(), color.get_green_p(), color.get_blue_p());
803
TimeBar::set_color(const Cairo::RefPtr<Cairo::Context>& cr, const Gdk::RGBA &color)
805
cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue());
809
TimeBar::draw_bar(const Cairo::RefPtr<Cairo::Context>& cr,
810
int x, int y, int width, int height,
815
if (rotation == 0 || rotation == 180)
817
cr->rectangle(x, y, width, height);
822
cr->rectangle(y, winw - x- width, height, width);