Page 1 of 1

mouse over boolean output ruby?

Posted: Fri Dec 12, 2014 6:35 pm
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?

Re: mouse over boolean output ruby?

Posted: Fri Dec 12, 2014 7:38 pm
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

Re: mouse over boolean output ruby?

Posted: Fri Dec 12, 2014 9:52 pm
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..

Re: mouse over boolean output ruby?

Posted: Sat Dec 13, 2014 4:35 pm
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]

Re: mouse over boolean output ruby?

Posted: Sat Dec 13, 2014 7:27 pm
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

Re: mouse over boolean output ruby?

Posted: Mon Dec 15, 2014 2:46 pm
by Nubeat7
thank you, tulamide and om, so many ways to do one thing, good to see this different ways :)