0

我正在尝试在 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();
}
4

1 回答 1

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

于 2019-06-02T07:16:16.737 回答