src/video/photon/SDL_ph_mouse.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 20 Jan 2003 01:38:37 +0000
changeset 571 8e3ce997621c
parent 380 bce7171e7a85
child 663 8bedd6d61642
permissions -rw-r--r--
Date: Thu, 16 Jan 2003 13:48:31 +0200
From: "Mike Gorchak"
Subject: All QNX patches

whole patches concerning QNX. Almost all code has been rewritten by Julian
and me. Added initial support for hw overlays in QNX and many many others
fixes.

P.S. This patches has been reviewed by Dave Rempel from QSSL and included in
SDL 1.2.5 distribution, which coming on 3rd party CD for newest 6.2.1
version of QNX, which will be available soon.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
#include <stdlib.h>
slouken@0
    29
#include <stdio.h>
slouken@0
    30
#include <string.h>
slouken@0
    31
slouken@0
    32
#include "SDL_error.h"
slouken@0
    33
#include "SDL_mouse.h"
slouken@0
    34
#include "SDL_events_c.h"
slouken@0
    35
#include "SDL_cursor_c.h"
slouken@0
    36
#include "SDL_ph_mouse_c.h"
slouken@0
    37
slouken@571
    38
struct WMcursor
slouken@571
    39
{
slouken@315
    40
    PhCursorDef_t *ph_cursor ;
slouken@0
    41
};
slouken@0
    42
slouken@0
    43
void ph_FreeWMCursor(_THIS, WMcursor *cursor)
slouken@0
    44
{
slouken@315
    45
    if (window != NULL)
slouken@315
    46
    {
slouken@315
    47
        SDL_Lock_EventThread();
slouken@0
    48
slouken@571
    49
        if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) < 0)
slouken@315
    50
        {
slouken@315
    51
            /* TODO: output error msg */
slouken@315
    52
        }
slouken@315
    53
slouken@315
    54
        SDL_Unlock_EventThread();
slouken@315
    55
    }	
slouken@315
    56
    /* free(cursor->ph_cursor.images); */
slouken@315
    57
    free(cursor);
slouken@0
    58
}
slouken@0
    59
slouken@0
    60
WMcursor *ph_CreateWMCursor(_THIS,
slouken@0
    61
		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
slouken@0
    62
{
slouken@571
    63
    WMcursor* cursor;
slouken@571
    64
    int clen, i;
slouken@571
    65
    unsigned char bit, databit, maskbit;
slouken@0
    66
slouken@571
    67
    /* Allocate and initialize the cursor memory */
slouken@571
    68
    if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL)
slouken@571
    69
    {
slouken@571
    70
        SDL_OutOfMemory();
slouken@571
    71
        return(NULL);
slouken@571
    72
    }
slouken@571
    73
    memset(cursor,0,sizeof(WMcursor));
slouken@283
    74
slouken@571
    75
    cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2);
slouken@571
    76
    if (cursor->ph_cursor == NULL)
slouken@571
    77
        printf("cursor malloc failed\n");
slouken@0
    78
slouken@571
    79
    memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
slouken@283
    80
slouken@571
    81
    cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;   
slouken@571
    82
    cursor->ph_cursor->size1.x = (short)w;
slouken@571
    83
    cursor->ph_cursor->size1.y = (short)h;
slouken@571
    84
    cursor->ph_cursor->offset1.x = (short)hot_x;
slouken@571
    85
    cursor->ph_cursor->offset1.y = (short)hot_y;
slouken@571
    86
    cursor->ph_cursor->bytesperline1 = (char)w/8;
slouken@571
    87
    cursor->ph_cursor->color1 = Pg_WHITE;
slouken@571
    88
    cursor->ph_cursor->size2.x = (short)w;
slouken@571
    89
    cursor->ph_cursor->size2.y = (short)h;
slouken@571
    90
    cursor->ph_cursor->offset2.x = (short)hot_x;
slouken@571
    91
    cursor->ph_cursor->offset2.y = (short)hot_y;
slouken@571
    92
    cursor->ph_cursor->bytesperline2 = (char)w/8;
slouken@571
    93
    cursor->ph_cursor->color2 = Pg_BLACK;
slouken@283
    94
slouken@571
    95
    clen = (w/8)*h;
slouken@0
    96
slouken@571
    97
    /* Copy the mask and the data to different bitmap planes */
slouken@571
    98
    for (i=0; i<clen; ++i)
slouken@571
    99
    {
slouken@571
   100
        for (bit = 0; bit < 8; bit++)
slouken@571
   101
        {
slouken@571
   102
            databit = data[i] & (1 << bit);
slouken@571
   103
            maskbit = mask[i] & (1 << bit);
slouken@283
   104
slouken@571
   105
            cursor->ph_cursor->images[i] |= (databit == 0) ? maskbit : 0;
slouken@571
   106
            /* If the databit != 0, treat it as a black pixel and
slouken@571
   107
             * ignore the maskbit (can't do an inverted color) */
slouken@571
   108
            cursor->ph_cursor->images[i+clen] |= databit;
slouken@571
   109
        }
slouken@571
   110
    }
slouken@283
   111
slouken@571
   112
    /* #bytes following the hdr struct */
slouken@571
   113
    cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); 
slouken@0
   114
slouken@571
   115
    return (cursor);
slouken@0
   116
}
slouken@0
   117
slouken@0
   118
PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
slouken@0
   119
{
slouken@315
   120
    return(*cursor->ph_cursor);
slouken@0
   121
}
slouken@0
   122
slouken@0
   123
int ph_ShowWMCursor(_THIS, WMcursor *cursor)
slouken@0
   124
{
slouken@571
   125
    PtArg_t args[3];
slouken@571
   126
    int nargs = 0;
slouken@0
   127
slouken@571
   128
    /* Don't do anything if the display is gone */
slouken@571
   129
    if (window == NULL)
slouken@571
   130
    {
slouken@571
   131
        return (0);
slouken@571
   132
    }
slouken@0
   133
slouken@571
   134
    /* looks like photon can't draw mouse cursor in direct mode */
slouken@571
   135
    if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
slouken@571
   136
    {
slouken@571
   137
        return (0);
slouken@571
   138
    }
slouken@571
   139
slouken@571
   140
    /* Set the photon cursor cursor, or blank if cursor is NULL */
slouken@571
   141
    if (cursor!=NULL)
slouken@571
   142
    {
slouken@571
   143
        PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
slouken@571
   144
        /* Could set next to any PgColor_t value */
slouken@571
   145
        PtSetArg(&args[1], Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR , 0);
slouken@571
   146
        PtSetArg(&args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)));
slouken@571
   147
        nargs = 3;
slouken@571
   148
    }
slouken@571
   149
    else /* Ph_CURSOR_NONE */
slouken@571
   150
    {
slouken@571
   151
        PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
slouken@571
   152
        nargs = 1;
slouken@571
   153
    }
slouken@571
   154
slouken@571
   155
    SDL_Lock_EventThread();
slouken@571
   156
slouken@571
   157
    if (PtSetResources(window, nargs, args) < 0 )
slouken@571
   158
    {
slouken@571
   159
        return (0);
slouken@571
   160
    }	
slouken@571
   161
slouken@571
   162
    SDL_Unlock_EventThread();
slouken@571
   163
slouken@571
   164
    return (1);
slouken@0
   165
}
slouken@0
   166
slouken@0
   167
void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
slouken@0
   168
{
slouken@315
   169
    short abs_x, abs_y;
slouken@283
   170
slouken@315
   171
    SDL_Lock_EventThread();
slouken@315
   172
    PtGetAbsPosition( window, &abs_x, &abs_y );
slouken@315
   173
    PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
slouken@315
   174
    SDL_Unlock_EventThread();
slouken@0
   175
}
slouken@0
   176
slouken@0
   177
slouken@0
   178
void ph_CheckMouseMode(_THIS)
slouken@0
   179
{
slouken@315
   180
    /* If the mouse is hidden and input is grabbed, we use relative mode */
slouken@315
   181
    if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF))
slouken@315
   182
    {
slouken@315
   183
        mouse_relative = 1;
slouken@315
   184
    }
slouken@315
   185
    else
slouken@315
   186
    {
slouken@315
   187
        mouse_relative = 0;
slouken@315
   188
    }
slouken@0
   189
}