[Solved] Managing SDL Buttons
BlitzMax Forums/Brucey's Modules/[Solved] Managing SDL Buttons
| ||
I'm curious to know how to change the X,Y location of Joy Buttons. I can only see AddButton(x,y,radius) as the only option and JoyDown(), JoyHit() methods. |
| ||
Think you are not talking about sdl.mod/sdljoystick.mod but the virtual joypads Brucey did a while ago (sdl.mod/virtualjoystick.mod). Each Joystick has the property "buttons" - which is an array of previously added buttons. Each of these buttons has the properties "centerX" and "centerY" So you could do: local jDriver:TVirtualJoystickDriver = GetJoystickDriver("Virtual Joystick") 'create your joystick '[...] if jDriver.currentJoystick jDriver.currentJoystick.buttons[0].currentX = 10 endif bye Ron |
| ||
Thanks Derron. To follow up on that, say I have 2 virtual joystick instances, 2 buttons on the first instance and 1 on the second, and I would like to access the only button on the 2nd instance, will that go back to index 0 or continue to 2 vjoy1 button1 (index 0) button2 (index 1) vjoy2 button1 (index 2???) like If JoyHit(2)?? |
| ||
each button-array starts at 0 vjoy1.button[0] and button[1] vjoy2.button[0] If you really desire - I could wrap up some Getters for the driver? "GetJoyButton(port, button)" or so. bye Ron |
| ||
awesome thanks, if you can spare the time. I'm just curious to know how that translates to checking input? usually you just use If JoyHit(index) Then ... like the virtualjoystick example |
| ||
I could wrap up some Getters for the driver Doesn't it work properly through the joystick API? The whole idea of the (now) abstract Pub.Joystick is that you use it like you would have previously - but now with the option of custom drivers, like the Virtual one. |
| ||
I have no access to the source now (just fast smartphone-response). The driver ddoes not expose a function to move the button after they got created. You need to tangle from driver to joystick to button. If you do not know the interna of the types...you do not know how to achieve that. I understand that this is contrary to the driver approach (as moving a button us kind of "difficult" for a physically existing joypad). Maybe "GetVirtualJoystick(port/num)" is already enough ... or an "GetVirtualJoystickButton(port/num, buttonNum)". of course this then only works for things based on that virtual joystick (assume this is the reason for you to not have done similar things yet). @Rusty The driver-approach defines some basic methods/properties all variants share. For joysticks that are functions returning states (hit, axisState). Moving buttons is not something "all joysticks have in common". Bye Ron |
| ||
Function GetVirtualJoystick:TVirtualJoystick(port:int) local drv:TVirtualJoystickDriver = TVirtualJoystickDriver(GetJoystickDriver("Virtual Joystick")) if not drv then return Null 'boundary check if drv.joysticks.length <= port or port < 0 then return Null return drv.joysticks[port] End Function Function GetVirtualJoystickButton:TVirtualButton(port:int, buttonNum:int) local joy:TVirtualJoystick = GetVirtualJoystick(port) if not joy then return Null 'boundary check if joy.buttons.length <= buttonNum or buttonNum < 0 then return Null return joy.buttons[buttonNum] End Function 'Adjust the button position: 'first joypad, first button local button:TVirtualButton = GetVirtualJoystickButton(0, 0) if button button.centerX = 10 button.radius = 15 endif 'if you know the button exists: GetVirtualJoystickButton(0, 0).centerX = 10 [...] Code is untested (written without syntax or functionality check) bye Ron |
| ||
The driver ddoes not expose a function to move the button after they got created I'm not sure I understand why you need that, since you will be extending TVirtualJoystick and rendering everything yourself anyway - see the provided example. I would like to access the only button on the 2nd instance You use the second parameter to access the "port"/device. The default is 0, because generally you are only interested in a single device. So... If JoyHit(0, 1) ... ...first button of second joystick. |
| ||
Thanks Brucey and Derron. I think I got all I need. |
| ||
I did not check the examples, just looked at the code - and RustyKristi seemed to want to directly access the x/y-position of the button. For which reason he wants that? Dunno. So I just exposed that information. Of course looking at examples would potentially have rendered this thread useless :-) bye Ron |
| ||
Not at all, it still helps getting more information. appreciate it. :D |