Page 1 of 2

SDL 1.2 without mouse emulation

Posted: Sat Feb 03, 2024 4:32 pm
by nebiun
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?

Re: SDL 1.2 without mouse emulation

Posted: Sun Feb 04, 2024 3:33 am
by WinterMute
Looks like I missed something when I consolidated wii & cube video in our repo. I'll stick it on the TODO list.

Re: SDL 1.2 without mouse emulation

Posted: Sun Feb 04, 2024 7:22 am
by barfoo34
If using SDL2 is an option, then the Wiimote is supported as a mouse there.

Re: SDL 1.2 without mouse emulation

Posted: Sun Feb 04, 2024 7:23 pm
by nebiun
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 :)

Re: SDL 1.2 without mouse emulation

Posted: Mon Feb 05, 2024 5:19 pm
by WinterMute
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;
}

Re: SDL 1.2 without mouse emulation

Posted: Mon Feb 05, 2024 5:55 pm
by nebiun
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?

Re: SDL 1.2 without mouse emulation

Posted: Mon Feb 05, 2024 6:07 pm
by nebiun
SDLvirtual_keyboard.7z
(194.13 KiB) Downloaded 29 times
This is an app that does not work.

Re: SDL 1.2 without mouse emulation

Posted: Mon Feb 05, 2024 6:08 pm
by WinterMute
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.

Re: SDL 1.2 without mouse emulation

Posted: Mon Feb 05, 2024 7:10 pm
by nebiun
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.

Re: SDL 1.2 without mouse emulation

Posted: Mon Feb 05, 2024 8:12 pm
by WinterMute
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.