# WxRuby Region clearing

**URL:** <https://www.ruby-forum.com/t/wxruby-region-clearing/202024>\
**Category:** wxRuby\
**Created:** [January 20, 2011, 5:21am UTC](https://www.ruby-forum.com/t/wxruby-region-clearing/202024 "2011-01-20T05:21:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 20, 2011, 5:21am UTC](https://www.ruby-forum.com/t/wxruby-region-clearing/202024/1 "2011-01-20T05:21:46Z")

</div>

Hi !

I’m trying to understand how regions are working in wxRuby. For now, I  
tried only to draw a rectangle and to move it. In order to do that, I  
use a region to tell wxRuby to refresh only the rectangle and not the  
whole screen. But no matter how I try, it always refreshs only a part of  
the rectangle. Can somebody tell me why ?

I’m running wxRuby 2.0.1 on OSX, and wrote a script (attached to this  
post) as an example. Don’t hesitate to tell me if my code looks bad and  
how to improve it, I’m a beginner in WxRuby as in Ruby.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![shaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@shaz](https://www.ruby-forum.com/u/shaz)\
**Post date:** [January 22, 2011, 9:12pm UTC](https://www.ruby-forum.com/t/wxruby-region-clearing/202024/2 "2011-01-22T21:12:10Z")

</div>

Francis Toth wrote in post #976161:

> Hi !
> 
> I’m trying to understand how regions are working in wxRuby. For now, I  
> tried only to draw a rectangle and to move it. In order to do that, I  
> use a region to tell wxRuby to refresh only the rectangle and not the  
> whole screen. But no matter how I try, it always refreshs only a part of  
> the rectangle. Can somebody tell me why ?
> 
> I’m running wxRuby 2.0.1 on OSX, and wrote a script (attached to this  
> post) as an example. Don’t hesitate to tell me if my code looks bad and  
> how to improve it, I’m a beginner in WxRuby as in Ruby.
> 
> Thanks in advance.

Finally, I worked it out !  
I can’t explain why, but it seems that wxRuby acts strangely when a  
region is cleared and redrawn in the same event. I decided to proceed  
with two different events :

def refreshRectangle  
@frame.paint{|dc|  
clearRectangle(dc)  
}  
yield # move the rectangle  
@frame.paint{|dc|  
drawRectangle(dc)  
}  
end

For those interested, I’ve put the new script in attachment.

++

Francis.
