Computer Science Canada

Creating a button with drawbox (ptinrect function)

Author:  GullibleAmerican [ Sat Mar 24, 2012 5:33 pm ]
Post subject:  Creating a button with drawbox (ptinrect function)

What is it you are trying to achieve?
What I'm trying to achieve is, to create a button without using the GUI.


What is the problem you are having?
The problem is that it won't put 'Works.'


Describe what you have tried to solve this problem
Tried to change < to > and > to <, and added loop, still not working.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:

function ptinrect (ax, ay, ex, ey, val : int) : boolean
    loop
        Mouse.Where (mx, my, button)
        if mx - 16 > ax and my > ay and mx - 16 < ex and my < ey then
            Mouse.ButtonChoose ('multibutton')
            if button = val then
                result true
            end if
        end if
    end loop
    result false
end ptinrect

drawbox (10, maxy - 10, maxx - 20, 300, black)
if ptinrect (10, maxy - 10, maxx - 20, 300, 1) then
    View.Set ('nooffscreenonly')
    put "Works"
end if


Please specify what version of Turing you are using
4.1.0

Author:  Dreadnought [ Sat Mar 24, 2012 9:03 pm ]
Post subject:  Re: Creating a button with drawbox (ptinrect function)

The way you've written you're if statement, (ax, ay) will be the lower left corner of the rectangle and (ex, ey) will be the upper right corner of the rectangle.

But, is (10, maxy-10) the lower left corner of the rectangle you drew? Similarly, is (maxx-20, 300) the top right corner?

Also, why are you subtracting 16 from the x-coordinate of the mouse?


: