# Drawing with a Cairo context outside an expose signal

**URL:** <https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566>\
**Category:** Ruby-Gnome 2\
**Created:** [June 16, 2008, 10:38am UTC](https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566 "2008-06-16T10:38:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![genericguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@genericguy](https://www.ruby-forum.com/u/genericguy)\
**Post date:** [June 16, 2008, 10:38am UTC](https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566/1 "2008-06-16T10:38:24Z")

</div>

Hi,  
I’m trying to allow a user to draw to a DrawingArea with Cairo.  
The only problem is that I cannot figure out how to draw without using  
create\_cairo\_context in the expose event.  
I realize that I need to draw then if I want anything to be displayed,  
but I’d like to be able to draw to a ‘buffer’ in other parts of the  
script and then draw the buffer in the expose event.

There are two ways that I can think of doing this.  
The first would be to create my own Cairo::Context. Since I don’t know  
how create\_cairo\_context links a context to the DrawingArea, is stuck  
for that.  
The other way would be to draw to a surface and call  
context.set\_source\_surface. For some reason, though, this function  
doesn’t seem to be present in the ruby binding.

Thanks!

---

<div class="post-metadata">

**Author:** ![genericguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@genericguy](https://www.ruby-forum.com/u/genericguy)\
**Post date:** [June 16, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566/2 "2008-06-16T13:44:10Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] Drawing with a Cairo context outside an expose  
signal” on Mon, 16 Jun 2008 10:38:24 +0200,  
“Lucas L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The other way would be to draw to a surface and call  
> context.set\_source\_surface. For some reason, though, this function  
> doesn’t seem to be present in the ruby binding.

Use Cairo::Context#set\_source. It’s general method. It  
accepts (r, g, b), (r, g, b, a), ([r, g, b]), ([r, g, b,  
a]), (pattern) or (surface, x, y).

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![genericguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@genericguy](https://www.ruby-forum.com/u/genericguy)\
**Post date:** [June 16, 2008, 2:17pm UTC](https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566/3 "2008-06-16T14:17:43Z")

</div>

Ah, I was searching the docs for surface\_source.  
rcairo really needs English documentation.

Thanks!

Kouhei S. wrote:

> Hi,
> 
> In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> “[ruby-gnome2-devel-en] Drawing with a Cairo context outside an expose  
> signal” on Mon, 16 Jun 2008 10:38:24 +0200,  
> “Lucas L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The other way would be to draw to a surface and call  
> > context.set\_source\_surface. For some reason, though, this function  
> > doesn’t seem to be present in the ruby binding.
> 
> Use Cairo::Context#set\_source. It’s general method. It  
> accepts (r, g, b), (r, g, b, a), ([r, g, b]), ([r, g, b,  
> a]), (pattern) or (surface, x, y).
> 
> ## Thanks,
> 
> kou

---

<div class="post-metadata">

**Author:** ![genericguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@genericguy](https://www.ruby-forum.com/u/genericguy)\
**Post date:** [June 16, 2008, 2:22pm UTC](https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566/4 "2008-06-16T14:22:02Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Drawing with a Cairo context outside an  
expose signal” on Mon, 16 Jun 2008 14:17:43 +0200,  
“Lucas L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ah, I was searching the docs for surface\_source.  
> rcairo really needs English documentation.

I need your help.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![genericguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@genericguy](https://www.ruby-forum.com/u/genericguy)\
**Post date:** [June 16, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566/5 "2008-06-16T14:30:16Z")

</div>

Kouhei S. wrote:

> Hi,
> 
> In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> “Re: [ruby-gnome2-devel-en] Drawing with a Cairo context outside an  
> expose signal” on Mon, 16 Jun 2008 14:17:43 +0200,  
> “Lucas L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Ah, I was searching the docs for surface\_source.  
> > rcairo really needs English documentation.
> 
> I need your help.
> 
> ## Thanks,
> 
> kou

Is there a wiki or something? I’d gladly help.  
Right now I just try to make sense of Google’s translation of the  
Japanese docs:D

---

<div class="post-metadata">

**Author:** ![genericguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@genericguy](https://www.ruby-forum.com/u/genericguy)\
**Post date:** [June 16, 2008, 2:38pm UTC](https://www.ruby-forum.com/t/drawing-with-a-cairo-context-outside-an-expose-signal/140566/6 "2008-06-16T14:38:48Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Drawing with a Cairo context outside an  
expose signal” on Mon, 16 Jun 2008 14:30:16 +0200,  
“Lucas L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Ah, I was searching the docs for surface\_source.  
> > > rcairo really needs English documentation.
> > 
> > I need your help.
> 
> Is there a wiki or something? I’d gladly help.

Thanks!  
There is a Subversion repository:  
[https://www.cozmixng.org/repos/rcairo-doc/](https://www.cozmixng.org/repos/rcairo-doc/)

Could you mail your prefer account name and salted password  
(you may use htpasswd) to me?

> Right now I just try to make sense of Google’s translation of the  
> Japanese docs:D

The Japanese documentations are based on cairo’s documents:  
[http://www.cairographics.org/manual/](http://www.cairographics.org/manual/)

Most of them will help you.

## Thanks,

kou
