Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 984 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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
T
tolu619 Offline OP
Junior Member
tolu619  Offline OP
Junior Member
T

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
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.

Code:
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 Offline
Senior Expert
Superku  Offline
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
T
tolu619 Offline OP
Junior Member
tolu619  Offline OP
Junior Member
T

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.
Code:
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: tolu619] #442680
06/28/14 23:54
06/28/14 23:54
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Hm try adding window_pos.x and *.y in the SetCursorPos() arguments.


"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] #442685
06/29/14 14:53
06/29/14 14:53
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
T
tolu619 Offline OP
Junior Member
tolu619  Offline OP
Junior Member
T

Joined: Jun 2014
Posts: 97
Lagos, Nigeria
this
Code:
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 Offline
User
EpsiloN  Offline
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:
Code:
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;


What you did is equal to this:
Code:
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.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Can't click buttons in Panel with Controller [Re: EpsiloN] #442852
07/04/14 23:10
07/04/14 23:10
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
T
tolu619 Offline OP
Junior Member
tolu619  Offline OP
Junior Member
T

Joined: Jun 2014
Posts: 97
Lagos, Nigeria
Ok thanks. I'll toy around with this and see if I can get better results. It's working now though.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1