src/video/directfb/SDL_DirectFB_mouse.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 14 Mar 2011 23:16:05 -0700
changeset 5490 352473883732
parent 5488 c20436fd5627
child 5535 96594ac5fd1a
permissions -rw-r--r--
There's a function to do that... :)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     3
    Copyright (C) 1997-2011 Sam Lantinga
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
    Lesser General Public License for more details.
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
5199
164f20ba08eb Updated the DirectFB support, from Couriersud
Sam Lantinga <slouken@libsdl.org>
parents: 4636
diff changeset
    21
164f20ba08eb Updated the DirectFB support, from Couriersud
Sam Lantinga <slouken@libsdl.org>
parents: 4636
diff changeset
    22
    SDL1.3 DirectFB driver by couriersud@arcor.de
164f20ba08eb Updated the DirectFB support, from Couriersud
Sam Lantinga <slouken@libsdl.org>
parents: 4636
diff changeset
    23
	
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
*/
5199
164f20ba08eb Updated the DirectFB support, from Couriersud
Sam Lantinga <slouken@libsdl.org>
parents: 4636
diff changeset
    25
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_config.h"
5488
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    27
#include "SDL_assert.h"
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_DirectFB_video.h"
5488
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    30
#include "SDL_DirectFB_mouse.h"
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    31
#include "SDL_DirectFB_modes.h"
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    32
#include "SDL_DirectFB_window.h"
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "../SDL_sysvideo.h"
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "../../events/SDL_mouse_c.h"
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
5488
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    37
static SDL_Cursor *DirectFB_CreateDefaultCursor(void);
3023
d72a0dd80e8b DirectFB cleanups & simple window manager
Couriersud <couriersud@arcor.de>
parents: 3013
diff changeset
    38
static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface,
d72a0dd80e8b DirectFB cleanups & simple window manager
Couriersud <couriersud@arcor.de>
parents: 3013
diff changeset
    39
                                         int hot_x, int hot_y);
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
static int DirectFB_ShowCursor(SDL_Cursor * cursor);
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
static void DirectFB_MoveCursor(SDL_Cursor * cursor);
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
static void DirectFB_FreeCursor(SDL_Cursor * cursor);
5488
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    43
static void DirectFB_WarpMouse(SDL_Window * window, int x, int y);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    44
static void DirectFB_FreeMouse(SDL_Mouse * mouse);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    45
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    46
static const char *arrow[] = {
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    47
    /* pixels */
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    48
    "X                               ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    49
    "XX                              ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    50
    "X.X                             ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    51
    "X..X                            ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    52
    "X...X                           ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    53
    "X....X                          ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    54
    "X.....X                         ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    55
    "X......X                        ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    56
    "X.......X                       ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    57
    "X........X                      ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    58
    "X.....XXXXX                     ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    59
    "X..X..X                         ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    60
    "X.X X..X                        ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    61
    "XX  X..X                        ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    62
    "X    X..X                       ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    63
    "     X..X                       ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    64
    "      X..X                      ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    65
    "      X..X                      ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    66
    "       XX                       ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    67
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    68
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    69
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    70
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    71
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    72
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    73
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    74
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    75
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    76
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    77
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    78
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    79
    "                                ",
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    80
};
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    81
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    82
static SDL_Cursor *
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    83
DirectFB_CreateDefaultCursor(void)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    84
{
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    85
    SDL_VideoDevice *dev = SDL_GetVideoDevice();
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    86
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    87
    SDL_DFB_DEVICEDATA(dev);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    88
    DFB_CursorData *curdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    89
    DFBResult ret;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    90
    DFBSurfaceDescription dsc;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    91
    SDL_Cursor *cursor;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    92
    Uint32 *dest;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    93
    Uint32 *p;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    94
    int pitch, i, j;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    95
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    96
    SDL_DFB_ALLOC_CLEAR( cursor, sizeof(*cursor));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    97
    SDL_DFB_ALLOC_CLEAR(curdata, sizeof(*curdata));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    98
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    99
    dsc.flags =
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   100
        DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   101
    dsc.caps = DSCAPS_VIDEOONLY;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   102
    dsc.width = 32;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   103
    dsc.height = 32;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   104
    dsc.pixelformat = DSPF_ARGB;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   105
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   106
    SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   107
                                                 &curdata->surf));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   108
    curdata->hotx = 0;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   109
    curdata->hoty = 0;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   110
    cursor->driverdata = curdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   111
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   112
    SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   113
                                         (void *) &dest, &pitch));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   114
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   115
    /* Relies on the fact that this is only called with ARGB surface. */
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   116
    for (i = 0; i < 32; i++)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   117
    {
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   118
        for (j = 0; j < 32; j++)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   119
        {
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   120
        	switch (arrow[i][j])
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   121
        	{
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   122
        	case ' ': dest[j] = 0x00000000; break;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   123
        	case '.': dest[j] = 0xffffffff; break;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   124
        	case 'X': dest[j] = 0xff000000; break;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   125
        	}
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   126
        }
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   127
        dest += (pitch >> 2);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   128
    }
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   129
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   130
    curdata->surf->Unlock(curdata->surf);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   131
    return cursor;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   132
  error:
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   133
    return NULL;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   134
}
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   135
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   136
/* Create a cursor from a surface */
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   137
static SDL_Cursor *
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   138
DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   139
{
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   140
    SDL_VideoDevice *dev = SDL_GetVideoDevice();
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   141
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   142
    SDL_DFB_DEVICEDATA(dev);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   143
    DFB_CursorData *curdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   144
    DFBResult ret;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   145
    DFBSurfaceDescription dsc;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   146
    SDL_Cursor *cursor;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   147
    Uint32 *dest;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   148
    Uint32 *p;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   149
    int pitch, i;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   150
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   151
    SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   152
    SDL_assert(surface->pitch == surface->w * 4);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   153
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   154
    SDL_DFB_ALLOC_CLEAR( cursor, sizeof(*cursor));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   155
    SDL_DFB_ALLOC_CLEAR(curdata, sizeof(*curdata));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   156
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   157
    dsc.flags =
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   158
        DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   159
    dsc.caps = DSCAPS_VIDEOONLY;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   160
    dsc.width = surface->w;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   161
    dsc.height = surface->h;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   162
    dsc.pixelformat = DSPF_ARGB;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   163
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   164
    SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   165
                                                 &curdata->surf));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   166
    curdata->hotx = hot_x;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   167
    curdata->hoty = hot_y;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   168
    cursor->driverdata = curdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   169
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   170
    SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   171
                                         (void *) &dest, &pitch));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   172
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   173
    p = surface->pixels;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   174
    for (i = 0; i < surface->h; i++)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   175
        memcpy((char *) dest + i * pitch,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   176
               (char *) p + i * surface->pitch, 4 * surface->w);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   177
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   178
    curdata->surf->Unlock(curdata->surf);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   179
    return cursor;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   180
  error:
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   181
    return NULL;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   182
}
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   183
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   184
/* Show the specified cursor, or hide if cursor is NULL */
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   185
static int
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   186
DirectFB_ShowCursor(SDL_Cursor * cursor)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   187
{
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   188
    SDL_DFB_CURSORDATA(cursor);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   189
    DFBResult ret;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   190
    SDL_Window *window;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   191
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   192
    window = SDL_GetFocusWindow();
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   193
    if (!window)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   194
        return -1;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   195
    else {
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   196
        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   197
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   198
        if (display) {
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   199
            DFB_DisplayData *dispdata =
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   200
                (DFB_DisplayData *) display->driverdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   201
            DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   202
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   203
            if (cursor)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   204
                SDL_DFB_CHECKERR(windata->dfbwin->
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   205
                                 SetCursorShape(windata->dfbwin,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   206
                                                curdata->surf, curdata->hotx,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   207
                                                curdata->hoty));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   208
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   209
            SDL_DFB_CHECKERR(dispdata->layer->
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   210
                             SetCooperativeLevel(dispdata->layer,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   211
                                                 DLSCL_ADMINISTRATIVE));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   212
            SDL_DFB_CHECKERR(dispdata->layer->
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   213
                             SetCursorOpacity(dispdata->layer,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   214
                                              cursor ? 0xC0 : 0x00));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   215
            SDL_DFB_CHECKERR(dispdata->layer->
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   216
                             SetCooperativeLevel(dispdata->layer,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   217
                                                 DLSCL_SHARED));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   218
        }
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   219
    }
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   220
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   221
    return 0;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   222
  error:
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   223
    return -1;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   224
}
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   225
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   226
/* Free a window manager cursor */
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   227
static void
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   228
DirectFB_FreeCursor(SDL_Cursor * cursor)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   229
{
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   230
    SDL_DFB_CURSORDATA(cursor);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   231
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   232
    SDL_DFB_RELEASE(curdata->surf);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   233
    SDL_DFB_FREE(cursor->driverdata);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   234
    SDL_DFB_FREE(cursor);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   235
}
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   236
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   237
/* Warp the mouse to (x,y) */
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   238
static void
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   239
DirectFB_WarpMouse(SDL_Window * window, int x, int y)
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   240
{
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   241
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   242
    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   243
    DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   244
    DFBResult ret;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   245
    int cx, cy;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   246
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   247
    SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   248
    SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   249
                                                 cx + x + windata->client.x,
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   250
                                                 cy + y + windata->client.y));
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   251
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   252
  error:
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   253
    return;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   254
}
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   255
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   256
#if USE_MULTI_API
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   257
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3023
diff changeset
   258
static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window,
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
                               int x, int y);
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   261
static int id_mask;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   262
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   263
static DFBEnumerationResult
3023
d72a0dd80e8b DirectFB cleanups & simple window manager
Couriersud <couriersud@arcor.de>
parents: 3013
diff changeset
   264
EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
d72a0dd80e8b DirectFB cleanups & simple window manager
Couriersud <couriersud@arcor.de>
parents: 3013
diff changeset
   265
         void *callbackdata)
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   266
{
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   267
    DFB_DeviceData *devdata = callbackdata;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   268
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   269
    if ((desc.type & DIDTF_MOUSE) && (device_id & id_mask)) {
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   270
        SDL_Mouse mouse;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   271
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   272
        SDL_zero(mouse);
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2860
diff changeset
   273
        mouse.id = device_id;
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   274
        mouse.CreateCursor = DirectFB_CreateCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   275
        mouse.ShowCursor = DirectFB_ShowCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   276
        mouse.MoveCursor = DirectFB_MoveCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   277
        mouse.FreeCursor = DirectFB_FreeCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   278
        mouse.WarpMouse = DirectFB_WarpMouse;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   279
        mouse.FreeMouse = DirectFB_FreeMouse;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   280
        mouse.cursor_shown = 1;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   281
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2860
diff changeset
   282
        SDL_AddMouse(&mouse, desc.name, 0, 0, 1);
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2860
diff changeset
   283
        devdata->mouse_id[devdata->num_mice++] = device_id;
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   284
    }
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   285
    return DFENUM_OK;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   286
}
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   287
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
void
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
DirectFB_InitMouse(_THIS)
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
{
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
    SDL_DFB_DEVICEDATA(_this);
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   292
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   293
    devdata->num_mice = 0;
2998
d364ee9b9c15 Date: Sun, 04 Jan 2009 20:53:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2940
diff changeset
   294
    if (devdata->use_linux_input) {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   295
        /* try non-core devices first */
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   296
        id_mask = 0xF0;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   297
        devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   298
        if (devdata->num_mice == 0) {
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   299
            /* try core devices */
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   300
            id_mask = 0x0F;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   301
            devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   302
        }
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   303
    }
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   304
    if (devdata->num_mice == 0) {
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   305
        SDL_Mouse mouse;
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   307
        SDL_zero(mouse);
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   308
        mouse.CreateCursor = DirectFB_CreateCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   309
        mouse.ShowCursor = DirectFB_ShowCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   310
        mouse.MoveCursor = DirectFB_MoveCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   311
        mouse.FreeCursor = DirectFB_FreeCursor;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   312
        mouse.WarpMouse = DirectFB_WarpMouse;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   313
        mouse.FreeMouse = DirectFB_FreeMouse;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   314
        mouse.cursor_shown = 1;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   315
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2860
diff changeset
   316
        SDL_AddMouse(&mouse, "Mouse", 0, 0, 1);
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   317
        devdata->num_mice = 1;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   318
    }
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
}
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
void
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
DirectFB_QuitMouse(_THIS)
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
{
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
    SDL_DFB_DEVICEDATA(_this);
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
2998
d364ee9b9c15 Date: Sun, 04 Jan 2009 20:53:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2940
diff changeset
   326
    if (devdata->use_linux_input) {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   327
        SDL_MouseQuit();
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   328
    } else {
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   329
        SDL_DelMouse(0);
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   330
    }
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
}
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
/* This is called when a mouse motion event occurs */
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
static void
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
DirectFB_MoveCursor(SDL_Cursor * cursor)
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
{
2737
140a7edcf2bd Date: Sun, 31 Aug 2008 17:53:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   338
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
}
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
/* Warp the mouse to (x,y) */
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
static void
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3023
diff changeset
   343
DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y)
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
{
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5199
diff changeset
   345
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
    DFBResult ret;
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
    int cx, cy;
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
5199
164f20ba08eb Updated the DirectFB support, from Couriersud
Sam Lantinga <slouken@libsdl.org>
parents: 4636
diff changeset
   351
    SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy));
3023
d72a0dd80e8b DirectFB cleanups & simple window manager
Couriersud <couriersud@arcor.de>
parents: 3013
diff changeset
   352
    SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
d72a0dd80e8b DirectFB cleanups & simple window manager
Couriersud <couriersud@arcor.de>
parents: 3013
diff changeset
   353
                                                 cx + x + windata->client.x,
d72a0dd80e8b DirectFB cleanups & simple window manager
Couriersud <couriersud@arcor.de>
parents: 3013
diff changeset
   354
                                                 cy + y + windata->client.y));
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
  error:
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
    return;
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
}
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
/* Free the mouse when it's time */
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
static void
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
DirectFB_FreeMouse(SDL_Mouse * mouse)
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
{
2737
140a7edcf2bd Date: Sun, 31 Aug 2008 17:53:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   364
    /* nothing yet */
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
}
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
4568
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   367
#else /* USE_MULTI_API */
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   368
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   369
void
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   370
DirectFB_InitMouse(_THIS)
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   371
{
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   372
    SDL_DFB_DEVICEDATA(_this);
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   373
5488
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   374
    SDL_Mouse *mouse = SDL_GetMouse();
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   375
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   376
    mouse->CreateCursor = DirectFB_CreateCursor;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   377
    mouse->ShowCursor = DirectFB_ShowCursor;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   378
    mouse->WarpMouse = DirectFB_WarpMouse;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   379
    mouse->FreeCursor = DirectFB_FreeCursor;
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   380
5490
352473883732 There's a function to do that... :)
Sam Lantinga <slouken@libsdl.org>
parents: 5488
diff changeset
   381
    SDL_SetDefaultCursor(DirectFB_CreateDefaultCursor());
5488
c20436fd5627 DirectFB driver update
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   382
4568
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   383
    devdata->num_mice = 1;
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   384
}
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   385
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   386
void
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   387
DirectFB_QuitMouse(_THIS)
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   388
{
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   389
}
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   390
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   391
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   392
#endif
25b9cd8bdc30 Couriersud to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   393
2226
0e70b4b8cf84 Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
/* vi: set ts=4 sw=4 expandtab: */