diff options
author | Robin Gareus <robin@gareus.org> | 2014-10-28 02:18:46 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2014-10-28 02:18:46 +0100 |
commit | dc39448a224ec6a3dc80a3f4972ce69e5f82231c (patch) | |
tree | 9e8588f4bca5f594f6e3dab470793b12753077ef /libs | |
parent | b04414d170bff6d3d7cbfdcedd2dcab917fa3e18 (diff) |
turn pixfader into a cairowidget
Diffstat (limited to 'libs')
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/pixfader.h | 6 | ||||
-rw-r--r-- | libs/gtkmm2ext/pixfader.cc | 41 |
2 files changed, 19 insertions, 28 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/pixfader.h b/libs/gtkmm2ext/gtkmm2ext/pixfader.h index 6cf966f1b3..5227f9f50d 100644 --- a/libs/gtkmm2ext/gtkmm2ext/pixfader.h +++ b/libs/gtkmm2ext/gtkmm2ext/pixfader.h @@ -23,7 +23,7 @@ #include <cmath> #include <stdint.h> -#include <gtkmm/drawingarea.h> +#include "gtkmm2ext/cairo_widget.h" #include <gtkmm/adjustment.h> #include <gdkmm.h> @@ -31,7 +31,7 @@ namespace Gtkmm2ext { -class LIBGTKMM2EXT_API PixFader : public Gtk::DrawingArea +class LIBGTKMM2EXT_API PixFader : public CairoWidget { public: PixFader (Gtk::Adjustment& adjustment, int orientation, int span, int girth); @@ -57,7 +57,7 @@ class LIBGTKMM2EXT_API PixFader : public Gtk::DrawingArea void on_size_request (GtkRequisition*); void on_size_allocate (Gtk::Allocation& alloc); - bool on_expose_event (GdkEventExpose*); + void render (cairo_t *, cairo_rectangle_t*); bool on_button_press_event (GdkEventButton*); bool on_button_release_event (GdkEventButton*); bool on_motion_notify_event (GdkEventMotion*); diff --git a/libs/gtkmm2ext/pixfader.cc b/libs/gtkmm2ext/pixfader.cc index 9a250efa52..c04764ac6a 100644 --- a/libs/gtkmm2ext/pixfader.cc +++ b/libs/gtkmm2ext/pixfader.cc @@ -74,9 +74,9 @@ PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int _adjustment.signal_changed().connect (mem_fun (*this, &PixFader::adjustment_changed)); if (_orien == VERT) { - DrawingArea::set_size_request(_girth, _span); + CairoWidget::set_size_request(_girth, _span); } else { - DrawingArea::set_size_request(_span, _girth); + CairoWidget::set_size_request(_span, _girth); } } @@ -196,16 +196,9 @@ PixFader::create_patterns () cairo_surface_destroy (surface); } -bool -PixFader::on_expose_event (GdkEventExpose* ev) +void +PixFader::render (cairo_t *cr, cairo_rectangle_t* area) { - Cairo::RefPtr<Cairo::Context> context = get_window()->create_cairo_context(); - cairo_t* cr = context->cobj(); - - // clip to expose area - cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); - cairo_clip (cr); - if (!_pattern) { create_patterns(); } @@ -219,9 +212,9 @@ PixFader::on_expose_event (GdkEventExpose* ev) */ CairoWidget::set_source_rgb_a (cr, get_style()->get_bg (get_state()), 1); - cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); + cairo_rectangle (cr, area->x, area->y, area->width, area->height); cairo_fill (cr); - return true; + return; } OnExpose(); @@ -294,21 +287,21 @@ PixFader::on_expose_event (GdkEventExpose* ev) /* draw the unity-position line if it's not at either end*/ if (!(_tweaks & NoShowUnityLine) && _unity_loc > CORNER_RADIUS) { - context->set_line_width (1); - context->set_line_cap (Cairo::LINE_CAP_ROUND); + cairo_set_line_width(cr, 1); + cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); Gdk::Color c = get_style()->get_fg (Gtk::STATE_ACTIVE); - context->set_source_rgba (c.get_red_p() * 1.5, c.get_green_p() * 1.5, c.get_blue_p() * 1.5, 0.85); + cairo_set_source_rgba (cr, c.get_red_p() * 1.5, c.get_green_p() * 1.5, c.get_blue_p() * 1.5, 0.85); if (_orien == VERT) { if (_unity_loc < h - CORNER_RADIUS) { - context->move_to (1.5, _unity_loc + CORNER_OFFSET + .5); - context->line_to (_girth - 1.5, _unity_loc + CORNER_OFFSET + .5); - context->stroke (); + cairo_move_to (cr, 1.5, _unity_loc + CORNER_OFFSET + .5); + cairo_line_to (cr, _girth - 1.5, _unity_loc + CORNER_OFFSET + .5); + cairo_stroke (cr); } } else { if (_unity_loc < w - CORNER_RADIUS) { - context->move_to (_unity_loc - CORNER_OFFSET + .5, 1.5); - context->line_to (_unity_loc - CORNER_OFFSET + .5, _girth - 1.5); - context->stroke (); + cairo_move_to (cr, _unity_loc - CORNER_OFFSET + .5, 1.5); + cairo_line_to (cr, _unity_loc - CORNER_OFFSET + .5, _girth - 1.5); + cairo_stroke (cr); } } } @@ -340,8 +333,6 @@ PixFader::on_expose_event (GdkEventExpose* ev) } _last_drawn = ds; - - return true; } void @@ -359,7 +350,7 @@ PixFader::on_size_request (GtkRequisition* req) void PixFader::on_size_allocate (Gtk::Allocation& alloc) { - DrawingArea::on_size_allocate(alloc); + CairoWidget::on_size_allocate(alloc); if (_orien == VERT) { _girth = alloc.get_width (); |