Jump to content


Photo

Know Sdl? Help With Mouse Cursor On Xbox.


  • Please log in to reply
7 replies to this topic

#1 bassquake

bassquake

    X-S Member

  • Members
  • Pip
  • 131 posts
  • Xbox Version:v1.2
  • 360 version:v1 (xenon)

Posted 04 August 2008 - 02:04 PM

Hope this is the right place to ask.

Im porting a game for the xbox using the SDL (libSDLx).

How do you show a cursor on the xbox for the mouse? I can select stuff so its active but theres no mouse cursor.

The mouse icon works on the windows version of my build but not on the xbox, so I cant ask on the official SDL forum. Is there something else used?

xbins seems to have been down for a long time now, and I cant looks at what other people have done. So Im hoping someone here can show me light!

#2 Code-Red

Code-Red

    X-S Member

  • Members
  • Pip
  • 86 posts
  • Location:Canada
  • Xbox Version:v1.4
  • 360 version:v3.0 (falcon)

Posted 04 August 2008 - 10:19 PM

Did you include an icon for the mouse cursor and make a reference to it in the SDL? I'm assuming the tracker is fully active, but the library doesn't have any graphical icons to represent it.

#3 bassquake

bassquake

    X-S Member

  • Members
  • Pip
  • 131 posts
  • Xbox Version:v1.2
  • 360 version:v1 (xenon)

Posted 05 August 2008 - 01:01 PM

Hi.

The images for the mouse icons are currently hardcoded into the source. It works fine on Windows, just not on the xbox. This leads me to think the sdl cursor stuff is for operating systems that have cursors as standard to take over.

Im currently testing some other way using an image thats mapped to the mouse, like so:

CODE

SDL_ShowCursor(0);//don't display the normal cursor
SDL_Surface *screen;//surface for mouse
SDL_Surface *MouseImage=SDL_LoadBMP("mouse.bmp");//load up some BMP

int MouseX, MouseY;//for mouse coordinates

while(game is running)
{
    SDL_GetMouseState(&MouseX, &MouseY);//get the coordinates of the mouse on the screen
    DrawBMP(MouseImage, MouseX, MouseY);//draw the mouse on the screen
}

void DrawBMP(SDL_Surface *bmp, int x, int y)//drawing function
{
    SDL_Rect rect;
    rect.x = x;
    rect.y = y;
    SDL_BlitSurface(bmp, NULL, screen, &rect);
}

But its making multiple copies of itself like so:

IPB Image

Just for a heads up, the original mouse cursor code is:
CODE
void SystemSDL::hideCursor()
{
    if (SDL_ShowCursor(-1))
        SDL_ShowCursor(SDL_DISABLE);
}

void SystemSDL::showCursor()
{
    if (!SDL_ShowCursor(-1))
        SDL_ShowCursor(SDL_ENABLE);
}

void SystemSDL::usePointerCursor()
{

static SDL_Cursor *pointerCursor = NULL;
if (pointerCursor == NULL) {
        int b = 0;
        int w = 12;
        int t = 255;
        // TODO: be nice to use the real sprite, but I can't find it.
        uint8 orig[32 * 32] = {
                    b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    b, w, b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, b, w, w, b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, b, w, w, w, w, b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, b, w, w, w, w, w, b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, b, w, w, w, w, w, w, w, b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, b, w, w, w, w, w, w, w, w, b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, b, w, w, w, w, w, w, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, b, w, w, w, w, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, b, w, w, w, w, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, b, w, w, w, w, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, b, w, w, b, b, w, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, b, b, t, t, b, w, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, b, t, t, t, t, b, w, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, b, w, w, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, b, b, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
                    t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t,
        };

        uint8 data[4 * 32], mask[4 * 32];
        memset(data, 0, sizeof(data));
        memset(mask, 0, sizeof(mask));
        for (int j = 0; j < 32; j++)
            for (int i = 0; i < 32; i++) {
                if (j < 6 || i < 6 || j >= 32 || i >= 32)
                    continue;
                if (orig[(i - 6) + (j - 6) * 32] == t)
                    continue;
                if (orig[(i - 6) + (j - 6) * 32] == b)
                data[(i / 8) + j * 4] |= 128 >> (i % 8);
                mask[(i / 8) + j * 4] |= 128 >> (i % 8);
            }
                    if (pointerCursor == NULL)
            pointerCursor = SDL_GetCursor();
        pointerCursor =
            SDL_CreateCursor(data, mask, 32, 32, 8, 8);
}
    SDL_SetCursor(pointerCursor);
}


Which is then called up with:
CODE
g_System.usePointerCursor();


Sorry for long post but Im desperate! tongue.gif

Edited by bassquake, 05 August 2008 - 01:02 PM.


#4 obcd

obcd

    X-S Hacker

  • Moderator
  • PipPipPipPipPipPip
  • 2,737 posts
  • Xbox Version:v1.0
  • 360 version:none

Posted 06 August 2008 - 10:46 AM

It is pretty normal that it behaves like that. There is nothing that automagically restores the screen under your bitmap when you draw a new one when the cursor has moved. So, you need to save the area you are overwriting, and you need to restore it when you redraw the cursor bitmap on another location. (storing the new location.) Sometimes this is done by xoring the cursor color information with the background color information. If you xor again, you get the same background pixel colors again.

regards.

#5 bassquake

bassquake

    X-S Member

  • Members
  • Pip
  • 131 posts
  • Xbox Version:v1.2
  • 360 version:v1 (xenon)

Posted 07 August 2008 - 06:11 PM

Finally got a mouse cursor to run on the app mapping a bmp to the mouse's coordinates. Works on both windows and xbox. Its a bit slow though and sluggish. Probably needs some refining. And doesnt have transparency so its an ugly square at the mo. 32bit bmp doesnt seem to make difference.

One other question is how can i get the program to run at high def resolutions? It keeps running at 480 yet I have the hd pack. I thought lantus's libsdlx libraries automatically scale video using the highest rez available. Im using the libsdlx_v0.11_beta_FDB libary.

ps. The game im working on is porting Syndicate! Will make a new thread on it at some point. smile.gif

Edited by bassquake, 07 August 2008 - 06:19 PM.


#6 obcd

obcd

    X-S Hacker

  • Moderator
  • PipPipPipPipPipPip
  • 2,737 posts
  • Xbox Version:v1.0
  • 360 version:none

Posted 07 August 2008 - 09:00 PM

16 * 16 should be large enough for a cursor.

Most cursor bitmaps use 2bit / pixel. If no bit is set, the background color should remain intact. If one bit is set, the pixel should have the foreground cursor color. If the other is set, it should have the cursor background color. Working that way, you can create a white arrow (foreground color) surrounded by a black line (background color). You will even see such a cursor on a white background.

Sorry, I can't help you with your other problem. Studying the sources of your sdlx should bring up the answer.

regards.

#7 bassquake

bassquake

    X-S Member

  • Members
  • Pip
  • 131 posts
  • Xbox Version:v1.2
  • 360 version:v1 (xenon)

Posted 07 August 2008 - 09:51 PM

That 2bit colour cursor would be something Id rather avoid. Otherwise itll look a bit nasty with white cursors. Its supposed to be green with a dark green outline. It must be doable somehow. I could hardcode the mouse corsor for the xbox using its own libraries but that does detract from its SDL roots. rolleyes.gif

#8 obcd

obcd

    X-S Hacker

  • Moderator
  • PipPipPipPipPipPip
  • 2,737 posts
  • Xbox Version:v1.0
  • 360 version:none

Posted 08 August 2008 - 10:21 AM

I don't think Sdl will be happy if you start manipulating your screen with the xdk functions.
It might be possible if you could create an extra layer and show that on top, independant of the sdl created one.
The 2 color cursor doesn't need to be white with a black border. You can choose wathever colors you want. You are just limited to 2 different colors.

regards.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users