Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Getting mouse coordinates. Possible bug?  (Read 5908 times)

0 Members and 1 Guest are viewing this topic.

noodlesgc

  • Guest
Getting mouse coordinates. Possible bug?
« on: September 30, 2009, 09:58:32 pm »
I'm writing some code where the user will be able to select a group of units, using a box select mechanism.

The problem is when the cursor moves past either the top, or the left side of the window, the mouse coordinates will jump to a huge number (4294967296).
Right now, I have a quick fix that checks if the coordinate is that number, and sets it to 0 if so.
Any ideas on why this is happening, or any cleaner way to fix this?

Here is a screenshot displaying the problem.
http://img18.imageshack.us/img18/6347/screenshot1qz.png

And here is the code:
Code: [Select]

from PySFML import sf

window = sf.RenderWindow(sf.VideoMode(800, 600), "2Engine")

img = sf.Image()

class BoxSelect(sf.Shape):
    def __init__(self):

        self._center_color = sf.Color(255,255,255);

        self.AddPoint(0,0,self._center_color,self._center_color);
        self.AddPoint(0,0,self._center_color,self._center_color);
        self.AddPoint(0,0,self._center_color,self._center_color);
        self.AddPoint(0,0,self._center_color,self._center_color);

        self.EnableFill(0)
        self.EnableOutline(1)
        self.SetOutlineWidth(1)

        self.selecting = False


box_sel = BoxSelect()
running = 1
while running:
    event = sf.Event()
    while window.GetEvent(event):
        if event.Type == sf.Event.Closed:
            running = False
        elif event.Type == sf.Event.MouseButtonPressed:
            click = window.ConvertCoords(window.GetInput().GetMouseX(),window.GetInput().GetMouseY())
            for i in range(0,box_sel.GetNbPoints()):
                box_sel.SetPointPosition(i,click[0],click[1])
            box_sel.selecting = True

        elif event.Type == sf.Event.MouseButtonReleased:
            box_sel.selecting = False

        elif event.Type == sf.Event.MouseMoved:
            if box_sel.selecting:
                click = window.ConvertCoords(window.GetInput().GetMouseX(),window.GetInput().GetMouseY())
                print click
                if not click[1]==1:
                    box_sel.SetPointPosition(3,click[0],click[1])
                    box_sel.SetPointPosition(0,click[0],box_sel.GetPointPosition(1)[1])
                    box_sel.SetPointPosition(2,box_sel.GetPointPosition(2)[0],click[1])

    window.Clear(sf.Color(0,0,0))
    if box_sel.selecting:
        window.Draw(box_sel)
    window.Display()


Thanks.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Getting mouse coordinates. Possible bug?
« Reply #1 on: October 03, 2009, 02:48:49 am »
You're probably using an unsigned number, because the number you say it jumps to is the maximum unsigned integer value in C++, but it would also be equal to -1 if you used a signed number.
I use the latest build of SFML2

 

anything