Vr: using drawingarea1

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?

BR
Pat

You can do it by doing the following, mind you none of this code has
been
“tested”, so you will need to tweak a few things, but these are the
basics
of what you need to do, to ensure that you capture mouse down, and mouse
up
events, as well as motion events for when the user moves the mouse over
the
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
end
@start_x = args[1].x
@start_y = args[1].y
end

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

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

if @capture
# Do drawing logic here
end
end

hth,

Mario

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


ruby-gnome2-devel-en mailing list
[email protected]
ruby-gnome2-devel-en List Signup and Options


Mario S.
Fleet Captain
CO - Geo 99
CO - USS T’hy’la
XO - Diplomatic Corps - Second Life
http://www.iftcommand.com/chapters/thyla/

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