src/video/cocoa/SDL_cocoamouse.m
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Feb 2011 10:50:53 -0800
changeset 5371 fc3d3d580777
parent 5262 b530ef003506
child 5376 183ec2d4485c
permissions -rw-r--r--
Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
The only reason we need a custom view is to handle right mouse down.

Implemented mouse grabbing, although it's kind of clunky right now. I'll be adding a relative mode that will be smoother soon.
slouken@1931
     1
/*
slouken@1931
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 Sam Lantinga
slouken@1931
     4
slouken@1931
     5
    This library is free software; you can redistribute it and/or
slouken@1931
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1931
     7
    License as published by the Free Software Foundation; either
slouken@1931
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1931
     9
slouken@1931
    10
    This library is distributed in the hope that it will be useful,
slouken@1931
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1931
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1931
    13
    Lesser General Public License for more details.
slouken@1931
    14
slouken@1931
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1931
    16
    License along with this library; if not, write to the Free Software
slouken@1931
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1931
    18
slouken@1931
    19
    Sam Lantinga
slouken@1931
    20
    slouken@libsdl.org
slouken@1931
    21
*/
slouken@1931
    22
#include "SDL_config.h"
slouken@1931
    23
slouken@3517
    24
#include "SDL_events.h"
slouken@1931
    25
#include "SDL_cocoavideo.h"
slouken@1931
    26
slouken@1931
    27
#include "../../events/SDL_mouse_c.h"
slouken@1931
    28
slouken@1931
    29
void
slouken@1931
    30
Cocoa_InitMouse(_THIS)
slouken@1931
    31
{
slouken@1931
    32
}
slouken@1931
    33
slouken@3517
    34
static int
slouken@3517
    35
ConvertMouseButtonToSDL(int button)
slouken@3517
    36
{
slouken@3517
    37
    switch (button)
slouken@3517
    38
    {
slouken@3517
    39
        case 0:
slouken@3517
    40
            return(SDL_BUTTON_LEFT);   /* 1 */
slouken@3517
    41
        case 1:
slouken@3517
    42
            return(SDL_BUTTON_RIGHT);  /* 3 */
slouken@3517
    43
        case 2:
slouken@3517
    44
            return(SDL_BUTTON_MIDDLE); /* 2 */
slouken@3517
    45
    }
slouken@5060
    46
    return button+1;
slouken@3517
    47
}
slouken@3517
    48
slouken@3517
    49
void
slouken@3517
    50
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
slouken@3517
    51
{
slouken@5371
    52
    /* We're correctly using views even in fullscreen mode now */
slouken@3517
    53
}
slouken@3517
    54
slouken@1931
    55
void
gzjjgod@5057
    56
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
gzjjgod@5057
    57
{
gzjjgod@5057
    58
    float x = [event deltaX];
gzjjgod@5057
    59
    float y = [event deltaY];
gzjjgod@5057
    60
gzjjgod@5057
    61
    if (x > 0) {
gzjjgod@5057
    62
        x += 0.9f;
gzjjgod@5057
    63
    } else if (x < 0) {
gzjjgod@5057
    64
        x -= 0.9f;
gzjjgod@5057
    65
    }
gzjjgod@5057
    66
    if (y > 0) {
gzjjgod@5057
    67
        y += 0.9f;
gzjjgod@5057
    68
    } else if (y < 0) {
gzjjgod@5057
    69
        y -= 0.9f;
gzjjgod@5057
    70
    }
gzjjgod@5057
    71
    SDL_SendMouseWheel(window, (int)x, (int)y);
gzjjgod@5057
    72
}
gzjjgod@5057
    73
slouken@5058
    74
void
slouken@5058
    75
Cocoa_QuitMouse(_THIS)
slouken@5058
    76
{
slouken@5058
    77
}
slouken@5058
    78
slouken@1931
    79
/* vi: set ts=4 sw=4 expandtab: */