Forum: Ruby-Gnome 2 vr: using drawingarea1

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?

BR
Pat
3396e4a3df8a840faec520af8555a400?d=identicon&s=25 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
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. <
ruby-forum-incoming@andreas-s.net> wrote:

> --
> ruby-gnome2-devel-en mailing list
> ruby-gnome2-devel-en@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ruby-...
>



--
Mario Steele
Fleet Captain
CO - Geo 99
CO - USS T'hy'la
XO - Diplomatic Corps - Second Life
http://www.iftcommand.com/chapters/thyla/
http://www.trekfederation.com
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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.