2009-06-20 09:47:10 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2009 Paul Davis
|
2009-06-20 09:47:10 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-06-20 09:44:47 -04:00
|
|
|
#include "cairo_widget.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
|
|
|
|
CairoWidget::CairoWidget ()
|
2011-10-26 17:01:14 -04:00
|
|
|
: _width (1)
|
|
|
|
, _height (1)
|
2011-10-27 07:24:43 -04:00
|
|
|
, _active_state (CairoWidget::ActiveState (0))
|
|
|
|
, _visual_state (CairoWidget::VisualState (0))
|
2011-10-27 16:10:49 -04:00
|
|
|
, _dirty (true)
|
2009-06-20 09:44:47 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CairoWidget::~CairoWidget ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-27 16:24:29 -04:00
|
|
|
CairoWidget::on_expose_event (GdkEventExpose *ev)
|
2009-06-20 09:44:47 -04:00
|
|
|
{
|
2011-10-27 16:24:29 -04:00
|
|
|
cairo_t* cr = gdk_cairo_create (get_window ()->gobj());
|
|
|
|
cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
|
|
|
cairo_clip (cr);
|
|
|
|
render (cr);
|
|
|
|
cairo_destroy (cr);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-20 09:44:47 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-21 11:56:16 -04:00
|
|
|
/** Marks the widget as dirty, so that render () will be called on
|
|
|
|
* the next GTK expose event.
|
|
|
|
*/
|
|
|
|
|
2009-06-20 09:44:47 -04:00
|
|
|
void
|
|
|
|
CairoWidget::set_dirty ()
|
|
|
|
{
|
2009-12-11 18:29:48 -05:00
|
|
|
ENSURE_GUI_THREAD (*this, &CairoWidget::set_dirty)
|
2009-06-20 09:44:47 -04:00
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Handle a size allocation.
|
|
|
|
* @param alloc GTK allocation.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CairoWidget::on_size_allocate (Gtk::Allocation& alloc)
|
|
|
|
{
|
|
|
|
Gtk::EventBox::on_size_allocate (alloc);
|
|
|
|
|
|
|
|
_width = alloc.get_width ();
|
|
|
|
_height = alloc.get_height ();
|
|
|
|
|
|
|
|
set_dirty ();
|
|
|
|
}
|
2011-10-26 17:01:14 -04:00
|
|
|
|
|
|
|
Gdk::Color
|
|
|
|
CairoWidget::get_parent_bg ()
|
|
|
|
{
|
|
|
|
Widget* parent;
|
|
|
|
|
|
|
|
parent = get_parent ();
|
|
|
|
|
|
|
|
while (parent && !parent->get_has_window()) {
|
|
|
|
parent = parent->get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent && parent->get_has_window()) {
|
|
|
|
return parent->get_style ()->get_bg (parent->get_state());
|
|
|
|
}
|
|
|
|
|
|
|
|
return get_style ()->get_bg (get_state());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-27 07:24:43 -04:00
|
|
|
CairoWidget::set_active_state (CairoWidget::ActiveState s)
|
2011-10-26 17:01:14 -04:00
|
|
|
{
|
2011-10-27 07:24:43 -04:00
|
|
|
if (_active_state != s) {
|
|
|
|
_active_state = s;
|
|
|
|
StateChanged ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CairoWidget::set_visual_state (CairoWidget::VisualState s)
|
|
|
|
{
|
|
|
|
if (_visual_state != s) {
|
|
|
|
_visual_state = s;
|
|
|
|
StateChanged ();
|
2011-10-26 17:01:14 -04:00
|
|
|
}
|
|
|
|
}
|