cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

SDL_mirmouse.c (3839B)


      1/*
      2  Simple DirectMedia Layer
      3  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
      4
      5  This software is provided 'as-is', without any express or implied
      6  warranty.  In no event will the authors be held liable for any damages
      7  arising from the use of this software.
      8
      9  Permission is granted to anyone to use this software for any purpose,
     10  including commercial applications, and to alter it and redistribute it
     11  freely, subject to the following restrictions:
     12
     13  1. The origin of this software must not be misrepresented; you must not
     14     claim that you wrote the original software. If you use this software
     15     in a product, an acknowledgment in the product documentation would be
     16     appreciated but is not required.
     17  2. Altered source versions must be plainly marked as such, and must not be
     18     misrepresented as being the original software.
     19  3. This notice may not be removed or altered from any source distribution.
     20*/
     21
     22/*
     23  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
     24*/
     25
     26#include "../../SDL_internal.h"
     27
     28#if SDL_VIDEO_DRIVER_MIR
     29
     30#include "SDL_mirmouse.h"
     31
     32#include "../../events/SDL_mouse_c.h"
     33#include "SDL_assert.h"
     34
     35#include "SDL_mirdyn.h"
     36
     37static SDL_Cursor*
     38MIR_CreateDefaultCursor()
     39{
     40    SDL_Cursor* cursor;
     41
     42    cursor = SDL_calloc(1, sizeof(SDL_Cursor));
     43    if (cursor) {
     44    }
     45    else {
     46        SDL_OutOfMemory();
     47    }
     48
     49    return cursor;
     50}
     51
     52static SDL_Cursor*
     53MIR_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
     54{
     55    return MIR_CreateDefaultCursor();
     56}
     57
     58static SDL_Cursor*
     59MIR_CreateSystemCursor(SDL_SystemCursor id)
     60{
     61    switch(id) {
     62        case SDL_SYSTEM_CURSOR_ARROW:
     63            break;
     64        case SDL_SYSTEM_CURSOR_IBEAM:
     65            break;
     66        case SDL_SYSTEM_CURSOR_WAIT:
     67            break;
     68        case SDL_SYSTEM_CURSOR_CROSSHAIR:
     69            break;
     70        case SDL_SYSTEM_CURSOR_WAITARROW:
     71            break;
     72        case SDL_SYSTEM_CURSOR_SIZENWSE:
     73            break;
     74        case SDL_SYSTEM_CURSOR_SIZENESW:
     75            break;
     76        case SDL_SYSTEM_CURSOR_SIZEWE:
     77            break;
     78        case SDL_SYSTEM_CURSOR_SIZENS:
     79            break;
     80        case SDL_SYSTEM_CURSOR_SIZEALL:
     81            break;
     82        case SDL_SYSTEM_CURSOR_NO:
     83            break;
     84        case SDL_SYSTEM_CURSOR_HAND:
     85            break;
     86        default:
     87            SDL_assert(0);
     88            return NULL;
     89    }
     90
     91    return MIR_CreateDefaultCursor();
     92}
     93
     94static void
     95MIR_FreeCursor(SDL_Cursor* cursor)
     96{
     97    if (cursor)
     98      SDL_free(cursor);
     99}
    100
    101static int
    102MIR_ShowCursor(SDL_Cursor* cursor)
    103{
    104    return 0;
    105}
    106
    107static void
    108MIR_WarpMouse(SDL_Window* window, int x, int y)
    109{
    110    SDL_Unsupported();
    111}
    112
    113static void
    114MIR_WarpMouseGlobal(int x, int y)
    115{
    116    SDL_Unsupported();
    117}
    118
    119static int
    120MIR_SetRelativeMouseMode(SDL_bool enabled)
    121{
    122    return SDL_Unsupported();
    123}
    124
    125/* TODO Actually implement the cursor, need to wait for mir support */
    126void
    127MIR_InitMouse()
    128{
    129    SDL_Mouse* mouse = SDL_GetMouse();
    130
    131    mouse->CreateCursor         = MIR_CreateCursor;
    132    mouse->ShowCursor           = MIR_ShowCursor;
    133    mouse->FreeCursor           = MIR_FreeCursor;
    134    mouse->WarpMouse            = MIR_WarpMouse;
    135    mouse->WarpMouseGlobal      = MIR_WarpMouseGlobal;
    136    mouse->CreateSystemCursor   = MIR_CreateSystemCursor;
    137    mouse->SetRelativeMouseMode = MIR_SetRelativeMouseMode;
    138
    139    SDL_SetDefaultCursor(MIR_CreateDefaultCursor());
    140}
    141
    142void
    143MIR_FiniMouse()
    144{
    145    SDL_Mouse* mouse = SDL_GetMouse();
    146
    147    MIR_FreeCursor(mouse->def_cursor);
    148    mouse->def_cursor = NULL;
    149
    150    mouse->CreateCursor         = NULL;
    151    mouse->ShowCursor           = NULL;
    152    mouse->FreeCursor           = NULL;
    153    mouse->WarpMouse            = NULL;
    154    mouse->CreateSystemCursor   = NULL;
    155    mouse->SetRelativeMouseMode = NULL;
    156}
    157
    158#endif /* SDL_VIDEO_DRIVER_MIR */
    159
    160/* vi: set ts=4 sw=4 expandtab: */
    161