0 registered members (),
984
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Can't click buttons in Panel with Controller
#442605
06/26/14 15:23
06/26/14 15:23
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
I'm using an XBox360 controller to test the Controller code for my game. The A button (joy_1) is supposed to click whichever button the mouse cursor is hovering over at the time. I'm changing the mouse position with this code
mouse_pos.x += joy_force.x;
mouse_pos.y += joy_force.y
The mouse cursor moves but the buttons don't display their mouse_over images or run their mouse_over functions unless I use my real mouse to make sure the mouse pointer is in the game window. If my PC's mouse pointer is outside the game window, my XBox Controller will still move the mouse pointer within the game window. The bigger problem is the fact that I can't tell the Controller to click on the button the mouse is on. Someone here gave me a snippet that works, but I have to write a different mouse_over function for EACH button telling it to constantly check whether the mouse is over the button and then whether the joy_1 button was pressed, then wait for the button to be released before running the specific function mapped to that button. Basically, I can't get/set pointers to specific buttons within a panel or get pointers to which functions are mapped to the buttons, so I have to manually write such hover functions for each button. Any snippet that would make this task easier would be highly appreciated.
function ChooseCharacterOne() //function mapped to button
{
//some code here
}
function PadChooseCharacterOne() //typical hover function
{
play_mouse_over_sound();
while(joy_1)
wait(-1);
if(event_type = EVENT_TOUCH)
{
while(event_type != EVENT_RELEASE)
{
if(joy_1)
ChooseCharacterOne();
wait(1);
}
}
button(10, 10, 10, 10, ButtonOnImage, ButtonOffImage, ButtonHoverImage, ChooseCharacterOne, NULL, PadChooseCharacterOne); //typical button code
|
|
|
Re: Can't click buttons in Panel with Controller
[Re: tolu619]
#442609
06/26/14 16:59
06/26/14 16:59
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
You need to set the real mouse cursor instead SetCursorPos((int)mouse_pos.x,(int)mouse_pos.y); // using windows.h and for mouse clicks you can do something as follows: mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); wait(1); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Can't click buttons in Panel with Controller
[Re: Superku]
#442679
06/28/14 23:40
06/28/14 23:40
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
Thanks! Works like a charm! I only have one problem left. I can click via the controller now and the left analog stick controls both the pointer in the game window and the regular mouse cursor outside the game window simultaneously. My game window is 800 by 600. The regular mouse pointer is stuck in an imaginary rectangle 800 by 600 pixels in dimension starting at the upper left corner of my screen. The pointer in the game is also stuck inside the game window. Both cursors move at the same time, but the buttons within my panels only react to the game's pointer hovering over them if the regular windows cursor also happens to be inside the game window at that time. So for example, if I move the pointer to the upper left corner of the screen inside the game window (where I have my back button in my game menus), the pointer outside the game window will also move to the upper left corner of my monitor, so I can't click on the back button. It won't react to the game pointer hovering above it.
function ClickViaController()
{
while(joy_1)
wait(1);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
wait(1);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
Then in main function of project,
function main()
{
.....
....
while(GameStarted == 0)
{
if(num_joysticks > 0)
{
mouse_mode = 2;
mouse_pos.x = joy_force.x;
mouse_pos.y = joy_force.y;
SetCursorPos((int)mouse_pos.x, (int)mouse_pos.y);
if(joy_1)
ClickViaController();
}
else
mouse_mode = 4;
......
.....
}
|
|
|
Re: Can't click buttons in Panel with Controller
[Re: Superku]
#442685
06/29/14 14:53
06/29/14 14:53
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
this
SetCursorPos((int)window_pos.x+mouse_pos.x, (int)window_pos.y+mouse_pos.y)
did the job Thanks.
Last edited by tolu619; 07/04/14 23:11.
|
|
|
Re: Can't click buttons in Panel with Controller
[Re: tolu619]
#442823
07/03/14 23:17
07/03/14 23:17
|
Joined: Jan 2006
Posts: 968
EpsiloN
User
|
User
Joined: Jan 2006
Posts: 968
|
If you want to understand where the position problem comes, its from the fact that the mouse coordinates are separated from mouse_pos or your controller acceleration: I have this in my game:
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
What you did is equal to this:
mouse_pos.x += mouse_force.x;
mouse_pos.y += mouse_force.y;
This will move mouse_pos with a different speed than the actual pointer pos... Pointer.x/y isn't used anymore, but the concept is the same, I think.
|
|
|
|