Forum: Ruby-Gnome 2 vr: using drawingarea1

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
15451874210a5b7a7ae12ce9d9cf4ae4?d=identicon&s=25 Patrik K. (patrik_k)
on 2012-12-15 22:38
Hi there

I put a drawing area into my GUI class:
window1 / vbox1 / drawingarea1

Can someone tell me how to draw lines circles and boxes on it by mouse?

Mario Steele (Guest)
on 2012-12-17 04:53
(Received via mailing list)
You can do it by doing the following, mind you none of this code has
"tested", so you will need to tweak a few things, but these are the
of what you need to do, to ensure that you capture mouse down, and mouse
events, as well as motion events for when the user moves the mouse over
drawing area.

def drawingarea1__button_press_event(*args)
  @capture = true
  if args[1].button == 1  # Left Button down
    @button = :left
  elsif args[1].button == 2 # Middle Button down
    @button = :middle
  elsif args[1].button == 3 # Right Button down
    @button = :right
  @start_x = args[1].x
  @start_y = args[1].y

def drawingarea1__button_release_event(*args)
  @capture = false
  @button = nil
  @end_x = args[1].x
  @end_y = args[1].y

def drawingarea1__motion_notify_event(*args)
  x, y = @builder["drawingarea1"].pointer

  if @capture
    # Do drawing logic here



On Sat, Dec 15, 2012 at 4:38 PM, Patrik K. <> wrote:

> --
> ruby-gnome2-devel-en mailing list

Mario Steele
Fleet Captain
CO - Geo 99
CO - USS T'hy'la
XO - Diplomatic Corps - Second Life
15451874210a5b7a7ae12ce9d9cf4ae4?d=identicon&s=25 Patrik K. (patrik_k)
on 2012-12-18 22:52
> def drawingarea1__motion_notify_event(*args)
>   x, y = @builder["drawingarea1"].pointer
>   if @capture
>     # Do drawing logic here
>   end
> end

So far, so fine!

by consequently using argv (not args) in the code and enabling all the
events in Glade for the drawingarea1, I can now capture my mouse actions
in the drawingarea.

By using:
argv[1].x and argv[1].y

So, I can read the "mouse pressed" position,
but how can I draw?

>     # Do drawing logic here
This topic is locked and can not be replied to.