src/video/ps2gs/SDL_gsmouse.c
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 17:06:37 +0000
branchgsoc2008_force_feedback
changeset 2498 ab567bd667bf
parent 1895 c121d94672cb
child 2859 99210400e8b9
permissions -rw-r--r--
Fixed various mistakes in the doxygen.
slouken@70
     1
/*
slouken@70
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@70
     4
slouken@70
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@70
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@70
     9
slouken@70
    10
    This library is distributed in the hope that it will be useful,
slouken@70
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@70
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@70
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@70
    18
slouken@70
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@70
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@70
    23
slouken@70
    24
#include <sys/ioctl.h>
slouken@70
    25
slouken@70
    26
#include "SDL_mouse.h"
slouken@1361
    27
#include "../../events/SDL_events_c.h"
slouken@1361
    28
#include "../SDL_cursor_c.h"
slouken@70
    29
#include "SDL_gsvideo.h"
slouken@70
    30
#include "SDL_gsmouse_c.h"
slouken@70
    31
slouken@70
    32
slouken@70
    33
/* The implementation dependent data for the window manager cursor */
slouken@1895
    34
struct WMcursor
slouken@1895
    35
{
slouken@1895
    36
    int unused;
slouken@70
    37
};
slouken@70
    38
slouken@70
    39
/* There isn't any implementation dependent data */
slouken@1895
    40
void
slouken@1895
    41
GS_FreeWMCursor(_THIS, WMcursor * cursor)
slouken@70
    42
{
slouken@1895
    43
    return;
slouken@70
    44
}
slouken@70
    45
slouken@70
    46
/* There isn't any implementation dependent data */
slouken@1895
    47
WMcursor *
slouken@1895
    48
GS_CreateWMCursor(_THIS,
slouken@1895
    49
                  Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
slouken@1895
    50
                  int hot_y)
slouken@70
    51
{
slouken@1895
    52
    return ((WMcursor *) 0x01);
slouken@70
    53
}
slouken@70
    54
slouken@1895
    55
static void
slouken@1895
    56
GS_MoveCursor(_THIS, SDL_Cursor * cursor, int x, int y)
slouken@70
    57
{
slouken@1895
    58
    SDL_Surface *screen;
slouken@1895
    59
    struct ps2_image image;
slouken@1895
    60
    SDL_Rect area;
slouken@1895
    61
    int mouse_y1, mouse_y2;
slouken@1895
    62
    void *saved_pixels;
slouken@1895
    63
    int screen_updated;
slouken@70
    64
slouken@1895
    65
    /* Lock so we don't interrupt an update with mouse motion */
slouken@1895
    66
    SDL_LockCursor();
slouken@70
    67
slouken@1895
    68
    /* Make sure any pending DMA has completed */
slouken@1895
    69
    if (dma_pending) {
slouken@1895
    70
        ioctl(console_fd, PS2IOC_SENDQCT, 1);
slouken@1895
    71
        dma_pending = 0;
slouken@1895
    72
    }
slouken@70
    73
slouken@1895
    74
    /* Remove the cursor image from the DMA area */
slouken@1895
    75
    screen = this->screen;
slouken@1895
    76
    saved_pixels = screen->pixels;
slouken@1895
    77
    screen->pixels = mapped_mem + screen->offset;
slouken@1895
    78
    screen_updated = 0;
slouken@1895
    79
    if (cursor_drawn) {
slouken@1895
    80
        SDL_EraseCursorNoLock(screen);
slouken@1895
    81
        cursor_drawn = 0;
slouken@1895
    82
        screen_updated = 1;
slouken@1895
    83
    }
slouken@70
    84
slouken@1895
    85
    /* Save the current mouse area */
slouken@1895
    86
    SDL_MouseRect(&area);
slouken@1895
    87
    mouse_y1 = area.y;
slouken@1895
    88
    mouse_y2 = area.y + area.h;
slouken@70
    89
slouken@1895
    90
    /* Only draw the new cursor if there was one passed in */
slouken@1895
    91
    if (cursor) {
slouken@1895
    92
        /* Set the new location */
slouken@1895
    93
        cursor->area.x = (x - cursor->hot_x);
slouken@1895
    94
        cursor->area.y = (y - cursor->hot_y);
slouken@70
    95
slouken@1895
    96
        /* Draw the cursor at the new location */
slouken@1895
    97
        if ((SDL_cursorstate & CURSOR_VISIBLE) && screen->pixels) {
slouken@1895
    98
            SDL_DrawCursorNoLock(screen);
slouken@1895
    99
            cursor_drawn = 1;
slouken@1895
   100
            screen_updated = 1;
slouken@1895
   101
        }
slouken@1895
   102
    }
slouken@1895
   103
    screen->pixels = saved_pixels;
slouken@70
   104
slouken@1895
   105
    /* Update the affected area of the screen */
slouken@1895
   106
    if (screen_updated) {
slouken@1895
   107
        SDL_MouseRect(&area);
slouken@1895
   108
        if (area.y < mouse_y1) {
slouken@1895
   109
            mouse_y1 = area.y;
slouken@1895
   110
        }
slouken@1895
   111
        if ((area.y + area.h) > mouse_y2) {
slouken@1895
   112
            mouse_y2 = area.y + area.h;
slouken@1895
   113
        }
slouken@1895
   114
        image = screen_image;
slouken@1895
   115
        image.y += screen->offset / screen->pitch + mouse_y1;
slouken@1895
   116
        image.h = mouse_y2 - mouse_y1;
slouken@1895
   117
        image.ptr = mapped_mem + (image.y - screen_image.y) * screen->pitch;
slouken@1895
   118
        ioctl(console_fd, PS2IOC_LOADIMAGE, &image);
slouken@136
   119
slouken@1895
   120
        /* Need to scale offscreen image to TV output */
slouken@1895
   121
        if (image.y > 0) {
slouken@1895
   122
            scaleimage_nonblock(console_fd, tex_tags_mem, scale_tags_mem);
slouken@1895
   123
        }
slouken@1895
   124
    }
slouken@70
   125
slouken@1895
   126
    /* We're finished */
slouken@1895
   127
    SDL_UnlockCursor();
slouken@70
   128
}
slouken@70
   129
slouken@1895
   130
void
slouken@1895
   131
GS_MoveWMCursor(_THIS, int x, int y)
slouken@70
   132
{
slouken@1895
   133
    GS_MoveCursor(this, SDL_cursor, x, y);
slouken@70
   134
}
slouken@70
   135
slouken@1895
   136
int
slouken@1895
   137
GS_ShowWMCursor(_THIS, WMcursor * wmcursor)
slouken@70
   138
{
slouken@1895
   139
    SDL_Cursor *cursor;
slouken@1895
   140
    int x, y;
slouken@70
   141
slouken@1895
   142
    /* Draw the cursor at the appropriate location */
slouken@1895
   143
    SDL_GetMouseState(&x, &y);
slouken@1895
   144
    if (wmcursor) {
slouken@1895
   145
        cursor = SDL_cursor;
slouken@1895
   146
    } else {
slouken@1895
   147
        cursor = NULL;
slouken@1895
   148
    }
slouken@1895
   149
    GS_MoveCursor(this, cursor, x, y);
slouken@1895
   150
    return (1);
slouken@70
   151
}
slouken@1895
   152
slouken@1895
   153
/* vi: set ts=4 sw=4 expandtab: */