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