我正在尝试在 Gtkmm DrawingArea 中绘制一个 cairo_surface_t。
cairo_surface_t * 可以用来初始化可以传递给 Cairo::Context::set_source 的 Glib::RefPtr 吗?
#include <gtkmm.h>
class CDrawingArea : Gtk::DrawingArea
{
public:
CDrawingArea();
virtual ~CDrawingArea();
void DrawSurface (cairo_surface_t * surface);
protected:
bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
cairo_surface_t * m_surface;
};
#include "CDrawingArea.h"
CDrawingArea::CDrawingArea()
{
}
CDrawingArea::~CDrawingArea()
{
}
void CDrawingArea::DrawSurface (cairo_surface_t * surface)
{
m_surface = surface;
Glib::RefPtr<Gdk::Window> win = get_window();
if (win)
{
Gdk::Rectangle r(0, 0, get_allocation().get_width(), get_allocation().get_height());
win->invalidate_rect(r, false);
}
}
bool CDrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
// Cairo::RefPtr<Cairo::Surface> refSurface ??;
// cr->set_source(refSurface, 0, 0);
cr->paint();
}