# wxRuby + rcairo ... are driving me mad

**URL:** <https://www.ruby-forum.com/t/wxruby-rcairo-are-driving-me-mad/178648>\
**Category:** Ruby\
**Created:** [November 8, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/wxruby-rcairo-are-driving-me-mad/178648 "2009-11-08T23:31:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [November 8, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/wxruby-rcairo-are-driving-me-mad/178648/1 "2009-11-08T23:31:52Z")

</div>

How is it possible to use Wx::GraphicsContext#get\_native\_context with  
rcairo? Let me quote the wxRuby documentation from

[http://wxruby.rubyforge.org/doc/graphicscontext.html#GraphicsContext\_getnativecontext](http://wxruby.rubyforge.org/doc/graphicscontext.html#GraphicsContext_getnativecontext)

“Returns the native context (CGContextRef for Core Graphics, Graphics  
pointer for GDIPlus and cairo\_t pointer for cairo).” [1]

Is there a way to cast the data the cairo\_t pointer points to into a  
Cairo::Context? Everything I tried resulted in an ‘called on  
terminated object’ error. Well, at least the reasonable attempts.

— snip ---------------------------------------------------------

#!/usr/bin/env ruby

require ‘rubygems’  
require ‘wx’

# require ‘cairo’

include Wx

class MyCanvas \< Window  
def initialize(parent)  
super(parent)  
timer = Timer.new(self, 1000)  
evt\_paint do  
paint do |dc|  
puts “painting on #{dc}”  
gdc = GraphicsContext.create(dc)  
# whatever I do with the native context, I get  
# method ‘…’ called on terminated object  
gdc.get\_native\_context  
end  
end  
evt\_timer(1000, :refresh)  
timer.start(100)  
end  
end

class MyFrame \< Frame  
def initialize  
super(nil, -1, ‘MyTitle’, :style =\> DEFAULT\_FRAME\_STYLE)  
canvas = MyCanvas.new(self)  
end  
end

class MyApp \< App  
def on\_init  
frame = MyFrame.new  
frame.show(true)  
end  
end

myapp = MyApp.new  
myapp.main\_loop

— snip ---------------------------------------------------------

Any help is highly appreciated  
Best phil

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [November 10, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/wxruby-rcairo-are-driving-me-mad/178648/2 "2009-11-10T14:10:58Z")

</div>

Philipp H. wrote:

> terminated object’ error. Well, at least the reasonable attempts.  
> I suggest you post this on the wxRuby list.

I don’t know of anyone who’s tried to do this. If it doesn’t work at the  
moment, it should be pretty easy to get a Integer corresponding to a C  
pointer out of the wrapper. But we’d need to know a bit more about what  
the Cairo wrapping expects.

a
