SDL 1.2 without mouse emulation

nebiun
Posts: 90
Joined: Sat Dec 28, 2013 2:42 pm

SDL 1.2 without mouse emulation

Post by nebiun » Sat Feb 03, 2024 4:32 pm

Hi,
in the old version of SDL 1.2 library you can use wiimote as mouse.
Why this option is not available in devkitPro version?

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: SDL 1.2 without mouse emulation

Post by WinterMute » Sun Feb 04, 2024 3:33 am

Looks like I missed something when I consolidated wii & cube video in our repo. I'll stick it on the TODO list.
Help keep devkitPro toolchains free, Donate today

Personal Blog

barfoo34
Posts: 3
Joined: Tue Jan 10, 2023 8:27 pm

Re: SDL 1.2 without mouse emulation

Post by barfoo34 » Sun Feb 04, 2024 7:22 am

If using SDL2 is an option, then the Wiimote is supported as a mouse there.

nebiun
Posts: 90
Joined: Sat Dec 28, 2013 2:42 pm

Re: SDL 1.2 without mouse emulation

Post by nebiun » Sun Feb 04, 2024 7:23 pm

barfoo34 wrote: Sun Feb 04, 2024 7:22 am If using SDL2 is an option, then the Wiimote is supported as a mouse there.
I'm trying to port OpenXcom on Wii. The project uses SDL1.2, so SDL2 is not and option :)

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: SDL 1.2 without mouse emulation

Post by WinterMute » Mon Feb 05, 2024 5:19 pm

nebiun wrote: Sat Feb 03, 2024 4:32 pm Hi,
in the old version of SDL 1.2 library you can use wiimote as mouse.
Why this option is not available in devkitPro version?
Now I've had a chance to look there doesn't appear to be a problem. This code shows a mouse pointer that moves with the wiimote for me.

Code: Select all

#include "SDL.h"

int main ( int argc, char *argv[] )
{
  /* initialize SDL */
  SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

  SDL_Surface* screen = SDL_SetVideoMode(640, 480, 0, 0);

  SDL_Event event;
  int gameover = 0;

  SDL_JoystickOpen(0);

  /* message pump */
  while (!gameover)
  {
    SDL_JoystickUpdate();
    /* look for an event */
    if (SDL_PollEvent(&event)) {
      /* an event was found */
      switch (event.type) {

        case SDL_QUIT:
          gameover = 1;
          break;

        case SDL_JOYBUTTONDOWN:
          switch(event.jbutton.button) {
           case 6: // home button
            gameover =1;
             break; 
          }
          break;
      }
    }

    /* update the screen */
    SDL_UpdateRect(screen, 0, 0, 0, 0);
  }

  SDL_Quit();

  return 0;
}
Help keep devkitPro toolchains free, Donate today

Personal Blog

nebiun
Posts: 90
Joined: Sat Dec 28, 2013 2:42 pm

Re: SDL 1.2 without mouse emulation

Post by nebiun » Mon Feb 05, 2024 5:55 pm

Hi,
My problem is not the joystick, but the mouse emulation via Wiimote.
Application uses the mouse, so I need a mouse emulation via Wiimote: when application looks for mouse movements (using mouse routines) these must be "emulated" reading Wiimote.
In SDL_wiievents.c from the old SDL port there is this code:

Code: Select all

	if (wd->ir.valid)
	{
		int newx = wd->ir.x;
		int newy = wd->ir.y;
		int diffx = newx - lastx;
		int diffy = newy - lasty;
		lastx = newx;
		lasty = newy;

		posted += SDL_PrivateMouseMotion(0, 1, diffx, diffy);

		Uint8 stateA = SDL_RELEASED;
		Uint8 stateB = SDL_RELEASED;

		if (wd->btns_h & WPAD_BUTTON_A)
		{
			stateA = SDL_PRESSED;
		}
		if (wd->btns_h & WPAD_BUTTON_B)
		{
			stateB = SDL_PRESSED;
		}
		if (stateA != lastButtonStateA)
		{
			lastButtonStateA = stateA;
			posted += SDL_PrivateMouseButton(stateA, SDL_BUTTON_LEFT, 0, 0);
		}
		if (stateB != lastButtonStateB)
		{
			lastButtonStateB = stateB;
			posted += SDL_PrivateMouseButton(stateB, SDL_BUTTON_RIGHT, 0, 0);
		}
	}
that does the dirty work :D
Can we have the same in the *official* porting?

nebiun
Posts: 90
Joined: Sat Dec 28, 2013 2:42 pm

Re: SDL 1.2 without mouse emulation

Post by nebiun » Mon Feb 05, 2024 6:07 pm

SDLvirtual_keyboard.7z
(194.13 KiB) Downloaded 29 times
This is an app that does not work.

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: SDL 1.2 without mouse emulation

Post by WinterMute » Mon Feb 05, 2024 6:08 pm

Our equivalent is here https://github.com/devkitPro/SDL/blob/o ... .c#L54-L71

If you run the code I posted you'll see a mouse pointer that can be controlled with the wiimote. You need to open joystick 0 for this to work.
Help keep devkitPro toolchains free, Donate today

Personal Blog

nebiun
Posts: 90
Joined: Sat Dec 28, 2013 2:42 pm

Re: SDL 1.2 without mouse emulation

Post by nebiun » Mon Feb 05, 2024 7:10 pm

Excuse me. These are the same sources and a Makefile to compile on MSYS2 in Windows with SDL library (I think it is work on Linux, too).
And it works as I expect.
So I think that the problem is in the Wii porting of the SDL library and not in the app code.
Can you give it a try?
Thanks.
Attachments
SDLvirtual_keyboard.7z
App in windows version
(194.42 KiB) Downloaded 21 times

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: SDL 1.2 without mouse emulation

Post by WinterMute » Mon Feb 05, 2024 8:12 pm

Ok, but if you plug a mouse into your Wii then it does just work. I'm not entirely sure it's reasonable to expect the WiiMote to work this way unless you take steps to enable it.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests