Can't track if mouse buttons are pressed using D.Button?

I was attempting to get a drag-and-drop system working with DirectButton - but I’ve run into a problem. I use


base.accept("mouse1-up",setDragOff) 

to turn off drag, but to find out if the button is pressed, I had trouble.

My intention was to use

base.accept("mouse1",setDrag)

and some position checking to initiate dragging, since the command property doesn’t register until release. However, it seems that clicking on a direct button will not fire the ‘mouse1’ event.

Is there any better way to go about this?

You can set suppressMouse = 0 on your buttons to disable the default suppression of the mouse input over the button.

David

Ahh, thank you. I had seen that earlier, but figured it was 0 by default.

Works now, thanks :smiley:

One more question, actually.

Currently I’m working on detecting what button the mouse was over when the mouse was clicked. To do so, I’m creating a “bounding box” using getX() to getX() + getWidth(), etc. However, the coordinates these create don’t seem to be correct. What single point on a button do getX() and getY() return? (Also, is there a better way to go about this?)

Slight development: GetWidth and getHeight are independent of the scale I’ve set, so I can get the actual width and height by multiplying by my scale. However, I’m still uncertain what getX() and getY() really are pointing to.

The (0, 0) origin of a gui item is arbitrary. Use guiItem.getBounds() instead. This returns a VBase4 whose components are the (left, right, bottom, top) boundaries of the gui item, excluding any bevel width.

David

Cool - however, I’m using ‘scale’ to make the buttons a little less ginormous, and from my testing it looks like getBounds() will return the same coordinates no matter what ‘scale’ is set to. Should I be setting some sort of geom scale too?

Thanks for the help,

Ny

Actually, no, that’s not the issue.

GetBounds seems to return the distance from some x and y of the object - is that correct, and what are these x and y coordinates?

EDIT:

centerX = item_icons[i].getPos()[0]
            centerY = item_icons[i].getPos()[2]            
            radius = item_icons[i].getWidth()/2
            
            toL = item_icons[i].getBounds()[0]
            toR = item_icons[i].getBounds()[1]
            toB = item_icons[i].getBounds()[2]
            toT = item_icons[i].getBounds()[3]
            
            indicator["pos"] = (centerX+toL,centerY+toT)
            
            leftX = centerX+toL
            rightX = centerX+toR
            topY = centerY + toT
            bottomY = centerY + toB

Does the trick.

So yeah, getX() and getY() are the mystical coordinates that getBounds() bases its values off of. Thanks again for the help!