mouse over boolean output ruby?

For general discussion related FlowStone
Post Reply
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

mouse over boolean output ruby?

Post by Nubeat7 »

hi all, just have a quick question, what's the easiest way to output a mouse over boolean in ruby?
i just used this

Code: Select all

def isInMouseArea (x,y,area)
   x1, y1 ,x2 , y2 = area
   x2 += x1
   y2 += y1
   x.between?(x1,x2) && y.between?(y1,y2)
end
def isInMousePoint(x,y)
   if isInMouseArea(x,y,@area)
       output 'mouseOver',true
       return true
   end
   output 'mouseOver',false
   return false
end

but isn't there an easier way?
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: mouse over boolean output ruby?

Post by tulamide »

Only another way, but not easier. You could activate mouse move on the mgui prim and in ruby then use

(Pseudo Code)

Code: Select all

def mouseMove x, y
    if (you're area code) then output true else output false end
end
"There lies the dog buried" (German saying translated literally)
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: mouse over boolean output ruby?

Post by Nubeat7 »

thanks tulamide,

another question, does there exist a fast way to get the view area? something like "getViewArea" ? or do i need to use getViewSize for it..
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: mouse over boolean output ruby?

Post by tulamide »

The latter. Unfortunately, no position offset is returned by any method I know of. It's always local coordinates (Top-left corner will always be [0, 0], no matter where that view is positioned within its parent.

I don't know where your question leads to, but here are some tips.

4-element-array building from getViewSize:

Code: Select all

area = [0, 0] + getViewSize

Code: Select all

area = Array.new(2,0) + getViewSize

Code: Select all

area = 0, 0, getViewSize
area.flatten!


4 objects assignment:

Code: Select all

x, y, w, h = 0, 0, getViewSize[0], getViewSize[1]
"There lies the dog buried" (German saying translated literally)
TheOm
Posts: 103
Joined: Tue Jan 28, 2014 7:35 pm
Location: Germany

Re: mouse over boolean output ruby?

Post by TheOm »

There's also the splat operator ('*'), which converts an enumerable to an argument list.

Code: Select all

view_area = 0.0, 0.0, *getViewSize
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: mouse over boolean output ruby?

Post by Nubeat7 »

thank you, tulamide and om, so many ways to do one thing, good to see this different ways :)
Post Reply