如何在Gtkmm DrawingArea中绘制cairo_surface_t

时间:2019-06-01 15:56:13

标签: gtk gnome cairo gtkmm glibmm

我正在尝试在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)
{
   // Glib::RefPtr<Surface> refSurface  ??;
   // cr->set_source(refSurface, 0, 0);
   cr->paint();
}

1 个答案:

答案 0 :(得分:1)

您在寻找Surface的构造函数吗?

Cairo::Surface::Surface (   cairo_surface_t *   cobject,
bool    has_reference = false    
)           [explicit]
Create a C++ wrapper for the C instance.

This C++ instance should then be given to a RefPtr.

(复制并粘贴破坏了格式,抱歉) https://cairographics.org/documentation/cairomm/reference/classCairo_1_1Surface.html#a47b90669a5a85d187cc0d28dc99915c8