2017-07-10 07:26:24 -07:00
|
|
|
/* Copyright (C) 2017 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
*
|
2010-02-08 08:23:39 -08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
2016-11-23 05:02:58 -08:00
|
|
|
*
|
2010-02-08 08:23:39 -08:00
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
|
* in all copies or substantial portions of the Software.
|
2016-11-23 05:02:58 -08:00
|
|
|
*
|
2010-02-08 08:23:39 -08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-04-18 10:00:33 -07:00
|
|
|
*/
|
|
|
|
|
|
2009-04-18 10:51:05 -07:00
|
|
|
/*
|
|
|
|
|
* mouse cursors (either via OpenGL texture or hardware)
|
2006-04-11 16:59:08 -07:00
|
|
|
*/
|
|
|
|
|
|
2004-07-24 12:38:12 -07:00
|
|
|
#include "precompiled.h"
|
2007-01-01 13:25:47 -08:00
|
|
|
#include "cursor.h"
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2009-08-07 10:22:05 -07:00
|
|
|
#include <cstdio>
|
2014-09-20 05:12:35 -07:00
|
|
|
#include <cstring>
|
2008-06-22 04:11:59 -07:00
|
|
|
#include <sstream>
|
|
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
#include "lib/external_libraries/libsdl.h"
|
2008-06-22 04:11:59 -07:00
|
|
|
#include "lib/ogl.h"
|
2014-09-20 05:12:35 -07:00
|
|
|
#include "lib/res/h_mgr.h"
|
2008-06-22 04:11:59 -07:00
|
|
|
#include "lib/sysdep/cursor.h"
|
|
|
|
|
#include "ogl_tex.h"
|
2007-12-20 12:14:21 -08:00
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
// On Windows, allow runtime choice between system cursors and OpenGL
|
|
|
|
|
// cursors (Windows = more responsive, OpenGL = more consistent with what
|
|
|
|
|
// the game sees)
|
2012-04-21 00:53:53 -07:00
|
|
|
#if OS_WIN || OS_UNIX
|
2005-11-18 08:23:39 -08:00
|
|
|
# define ALLOW_SYS_CURSOR 1
|
|
|
|
|
#else
|
|
|
|
|
# define ALLOW_SYS_CURSOR 0
|
2005-09-29 14:48:04 -07:00
|
|
|
#endif
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
class SDLCursor
|
|
|
|
|
{
|
|
|
|
|
SDL_Surface* surface;
|
|
|
|
|
SDL_Cursor* cursor;
|
|
|
|
|
|
|
|
|
|
public:
|
2017-05-27 02:24:04 -07:00
|
|
|
Status create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_, double scale)
|
2014-09-20 05:12:35 -07:00
|
|
|
{
|
|
|
|
|
shared_ptr<u8> file; size_t fileSize;
|
|
|
|
|
RETURN_STATUS_IF_ERR(vfs->LoadFile(pathname, file, fileSize));
|
|
|
|
|
|
|
|
|
|
Tex t;
|
|
|
|
|
RETURN_STATUS_IF_ERR(t.decode(file, fileSize));
|
|
|
|
|
|
|
|
|
|
// convert to required BGRA format.
|
|
|
|
|
const size_t flags = (t.m_Flags | TEX_BGR) & ~TEX_DXT;
|
|
|
|
|
RETURN_STATUS_IF_ERR(t.transform_to(flags));
|
|
|
|
|
void* bgra_img = t.get_data();
|
|
|
|
|
if(!bgra_img)
|
|
|
|
|
WARN_RETURN(ERR::FAIL);
|
|
|
|
|
|
|
|
|
|
surface = SDL_CreateRGBSurfaceFrom(bgra_img, (int)t.m_Width, (int)t.m_Height, 32, (int)t.m_Width*4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
|
2017-05-28 19:56:34 -07:00
|
|
|
if(!surface)
|
2014-09-20 05:12:35 -07:00
|
|
|
return ERR::FAIL;
|
2017-05-28 10:45:17 -07:00
|
|
|
if(scale != 1.0)
|
2017-05-27 02:24:04 -07:00
|
|
|
{
|
|
|
|
|
SDL_Surface* scaled_surface = SDL_CreateRGBSurface(0, surface->w * scale, surface->h * scale, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
|
2017-05-28 19:56:34 -07:00
|
|
|
if(!scaled_surface)
|
2017-05-27 02:24:04 -07:00
|
|
|
return ERR::FAIL;
|
2017-05-28 19:56:34 -07:00
|
|
|
if(SDL_BlitScaled(surface, NULL, scaled_surface, NULL))
|
2017-05-27 02:24:04 -07:00
|
|
|
return ERR::FAIL;
|
|
|
|
|
SDL_FreeSurface(surface);
|
|
|
|
|
surface = scaled_surface;
|
|
|
|
|
}
|
2014-09-20 05:12:35 -07:00
|
|
|
cursor = SDL_CreateColorCursor(surface, hotspotx_, hotspoty_);
|
2017-05-28 19:56:34 -07:00
|
|
|
if(!cursor)
|
2014-09-20 05:12:35 -07:00
|
|
|
return ERR::FAIL;
|
|
|
|
|
|
|
|
|
|
return INFO::OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set()
|
|
|
|
|
{
|
|
|
|
|
SDL_SetCursor(cursor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroy()
|
|
|
|
|
{
|
|
|
|
|
SDL_FreeCursor(cursor);
|
|
|
|
|
SDL_FreeSurface(surface);
|
|
|
|
|
}
|
|
|
|
|
};
|
2005-12-06 19:38:39 -08:00
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
// no init is necessary because this is stored in struct Cursor, which
|
|
|
|
|
// is 0-initialized by h_mgr.
|
|
|
|
|
class GLCursor
|
|
|
|
|
{
|
|
|
|
|
Handle ht;
|
2005-10-11 21:35:01 -07:00
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
GLint w, h;
|
|
|
|
|
int hotspotx, hotspoty;
|
2005-08-09 17:27:56 -07:00
|
|
|
|
|
|
|
|
public:
|
2017-05-27 02:24:04 -07:00
|
|
|
Status create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_, double scale)
|
2005-08-09 17:27:56 -07:00
|
|
|
{
|
2010-07-04 03:15:53 -07:00
|
|
|
ht = ogl_tex_load(vfs, pathname);
|
2011-05-03 05:38:42 -07:00
|
|
|
RETURN_STATUS_IF_ERR(ht);
|
2005-09-28 22:00:20 -07:00
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
size_t width, height;
|
|
|
|
|
(void)ogl_tex_get_size(ht, &width, &height, 0);
|
2017-05-27 02:24:04 -07:00
|
|
|
w = (GLint)(width * scale);
|
|
|
|
|
h = (GLint)(height * scale);
|
2005-09-28 22:00:20 -07:00
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
hotspotx = hotspotx_; hotspoty = hotspoty_;
|
|
|
|
|
|
2005-09-28 22:00:20 -07:00
|
|
|
(void)ogl_tex_set_filter(ht, GL_NEAREST);
|
|
|
|
|
(void)ogl_tex_upload(ht);
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2005-08-09 17:27:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroy()
|
|
|
|
|
{
|
2005-10-11 21:35:01 -07:00
|
|
|
// note: we're stored in a resource => ht is initially 0 =>
|
|
|
|
|
// this is safe, no need for an is_valid flag
|
2005-09-28 22:00:20 -07:00
|
|
|
(void)ogl_tex_free(ht);
|
2005-08-09 17:27:56 -07:00
|
|
|
}
|
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
void draw(int x, int y) const
|
2004-08-12 10:36:48 -07:00
|
|
|
{
|
2012-01-15 15:15:31 -08:00
|
|
|
#if CONFIG2_GLES
|
|
|
|
|
UNUSED2(x); UNUSED2(y);
|
|
|
|
|
#warning TODO: implement cursors for GLES
|
|
|
|
|
#else
|
2005-09-28 22:00:20 -07:00
|
|
|
(void)ogl_tex_bind(ht);
|
2004-08-12 10:36:48 -07:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
2012-02-13 12:53:24 -08:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2004-08-12 10:36:48 -07:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2004-08-12 10:36:48 -07:00
|
|
|
glBegin(GL_QUADS);
|
2005-01-07 06:10:14 -08:00
|
|
|
glTexCoord2i(1, 0); glVertex2i( x-hotspotx+w, y+hotspoty );
|
2012-01-30 04:13:43 -08:00
|
|
|
glTexCoord2i(0, 0); glVertex2i( x-hotspotx, y+hotspoty );
|
2005-01-07 06:10:14 -08:00
|
|
|
glTexCoord2i(0, 1); glVertex2i( x-hotspotx, y+hotspoty-h );
|
2012-01-30 04:13:43 -08:00
|
|
|
glTexCoord2i(1, 1); glVertex2i( x-hotspotx+w, y+hotspoty-h );
|
2004-08-12 10:36:48 -07:00
|
|
|
glEnd();
|
2012-02-13 12:53:24 -08:00
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2012-01-15 15:15:31 -08:00
|
|
|
#endif
|
2004-08-12 10:36:48 -07:00
|
|
|
}
|
2005-10-11 21:35:01 -07:00
|
|
|
|
2011-05-03 05:38:42 -07:00
|
|
|
Status validate() const
|
2005-10-11 21:35:01 -07:00
|
|
|
{
|
2008-07-17 10:00:00 -07:00
|
|
|
const GLint A = 128; // no cursor is expected to get this big
|
2005-10-11 21:35:01 -07:00
|
|
|
if(w > A || h > A || hotspotx > A || hotspoty > A)
|
2006-09-22 06:19:40 -07:00
|
|
|
WARN_RETURN(ERR::_1);
|
2005-10-11 21:35:01 -07:00
|
|
|
if(ht < 0)
|
2006-09-22 06:19:40 -07:00
|
|
|
WARN_RETURN(ERR::_2);
|
|
|
|
|
return INFO::OK;
|
2005-10-11 21:35:01 -07:00
|
|
|
}
|
2004-08-12 10:36:48 -07:00
|
|
|
};
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
enum CursorKind
|
|
|
|
|
{
|
|
|
|
|
CK_Default,
|
2014-09-20 05:12:35 -07:00
|
|
|
CK_SDL,
|
2008-06-22 04:11:59 -07:00
|
|
|
CK_OpenGL
|
|
|
|
|
};
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2004-08-12 10:36:48 -07:00
|
|
|
struct Cursor
|
|
|
|
|
{
|
2017-05-27 02:24:04 -07:00
|
|
|
double scale;
|
|
|
|
|
|
2012-02-12 12:45:31 -08:00
|
|
|
// require kind == CK_OpenGL after reload
|
|
|
|
|
bool forceGL;
|
|
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
CursorKind kind;
|
|
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
// valid iff kind == CK_SDL
|
|
|
|
|
SDLCursor sdl_cursor;
|
2005-08-09 17:27:56 -07:00
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
// valid iff kind == CK_OpenGL
|
2005-08-09 17:27:56 -07:00
|
|
|
GLCursor gl_cursor;
|
2004-08-12 10:36:48 -07:00
|
|
|
};
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2004-08-12 10:36:48 -07:00
|
|
|
H_TYPE_DEFINE(Cursor);
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2012-02-12 12:45:31 -08:00
|
|
|
static void Cursor_init(Cursor* c, va_list args)
|
2004-08-12 10:36:48 -07:00
|
|
|
{
|
2017-05-27 02:24:04 -07:00
|
|
|
c->scale = va_arg(args, double);
|
2012-02-12 13:05:13 -08:00
|
|
|
c->forceGL = (va_arg(args, int) != 0);
|
2004-08-12 10:36:48 -07:00
|
|
|
}
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2004-08-12 10:36:48 -07:00
|
|
|
static void Cursor_dtor(Cursor* c)
|
|
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
switch(c->kind)
|
|
|
|
|
{
|
|
|
|
|
case CK_Default:
|
|
|
|
|
break; // nothing to do
|
2005-10-11 21:35:01 -07:00
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
case CK_SDL:
|
|
|
|
|
c->sdl_cursor.destroy();
|
|
|
|
|
break;
|
2008-06-22 04:11:59 -07:00
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
2005-08-09 17:27:56 -07:00
|
|
|
c->gl_cursor.destroy();
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2011-05-04 05:10:17 -07:00
|
|
|
DEBUG_WARN_ERR(ERR::LOGIC);
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2004-08-12 10:36:48 -07:00
|
|
|
}
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2011-05-03 05:38:42 -07:00
|
|
|
static Status Cursor_reload(Cursor* c, const PIVFS& vfs, const VfsPath& name, Handle)
|
2005-07-16 10:52:05 -07:00
|
|
|
{
|
2011-03-23 06:36:20 -07:00
|
|
|
const VfsPath pathname(VfsPath(L"art/textures/cursors") / name);
|
2005-07-16 10:52:05 -07:00
|
|
|
|
2005-09-28 22:00:20 -07:00
|
|
|
// read pixel offset of the cursor's hotspot [the bit of it that's
|
|
|
|
|
// drawn at (g_mouse_x,g_mouse_y)] from file.
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
int hotspotx = 0, hotspoty = 0;
|
2005-07-16 10:52:05 -07:00
|
|
|
{
|
2011-03-23 06:36:20 -07:00
|
|
|
const VfsPath pathnameHotspot = pathname.ChangeExtension(L".txt");
|
2007-12-20 12:14:21 -08:00
|
|
|
shared_ptr<u8> buf; size_t size;
|
2011-05-03 05:38:42 -07:00
|
|
|
RETURN_STATUS_IF_ERR(vfs->LoadFile(pathnameHotspot, buf, size));
|
2009-11-03 13:46:35 -08:00
|
|
|
std::wstringstream s(std::wstring((const wchar_t*)buf.get(), size));
|
2005-09-28 22:00:20 -07:00
|
|
|
s >> hotspotx >> hotspoty;
|
2005-07-16 10:52:05 -07:00
|
|
|
}
|
|
|
|
|
|
2011-03-23 06:36:20 -07:00
|
|
|
const VfsPath pathnameImage = pathname.ChangeExtension(L".png");
|
2008-06-22 04:11:59 -07:00
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
// try loading as SDL2 cursor
|
2017-05-28 19:56:34 -07:00
|
|
|
if(!c->forceGL && c->sdl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty, c->scale) == INFO::OK)
|
2014-09-20 05:12:35 -07:00
|
|
|
c->kind = CK_SDL;
|
2008-06-22 04:11:59 -07:00
|
|
|
// fall back to GLCursor (system cursor code is disabled or failed)
|
2017-05-28 19:56:34 -07:00
|
|
|
else if(c->gl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty, c->scale) == INFO::OK)
|
2008-06-22 04:11:59 -07:00
|
|
|
c->kind = CK_OpenGL;
|
|
|
|
|
// everything failed, leave cursor unchanged
|
|
|
|
|
else
|
|
|
|
|
c->kind = CK_Default;
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2004-08-12 10:36:48 -07:00
|
|
|
}
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2011-05-03 05:38:42 -07:00
|
|
|
static Status Cursor_validate(const Cursor* c)
|
2005-10-11 21:35:01 -07:00
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
switch(c->kind)
|
|
|
|
|
{
|
|
|
|
|
case CK_Default:
|
|
|
|
|
break; // nothing to do
|
2005-10-11 21:35:01 -07:00
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
case CK_SDL:
|
|
|
|
|
break; // nothing to do
|
2008-06-22 04:11:59 -07:00
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
2011-05-03 05:38:42 -07:00
|
|
|
RETURN_STATUS_IF_ERR(c->gl_cursor.validate());
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
WARN_RETURN(ERR::_2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-01-15 15:15:31 -08:00
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2005-10-11 21:35:01 -07:00
|
|
|
}
|
|
|
|
|
|
2011-05-03 05:38:42 -07:00
|
|
|
static Status Cursor_to_string(const Cursor* c, wchar_t* buf)
|
2005-10-21 00:47:38 -07:00
|
|
|
{
|
2009-11-06 02:59:10 -08:00
|
|
|
const wchar_t* type;
|
2008-06-22 04:11:59 -07:00
|
|
|
switch(c->kind)
|
|
|
|
|
{
|
|
|
|
|
case CK_Default:
|
2009-11-06 02:59:10 -08:00
|
|
|
type = L"default";
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
case CK_SDL:
|
|
|
|
|
type = L"sdl";
|
|
|
|
|
break;
|
2008-06-22 04:11:59 -07:00
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
2009-11-06 02:59:10 -08:00
|
|
|
type = L"gl";
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2011-05-04 05:10:17 -07:00
|
|
|
DEBUG_WARN_ERR(ERR::LOGIC);
|
2009-11-06 02:59:10 -08:00
|
|
|
type = L"?";
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-06 02:59:10 -08:00
|
|
|
swprintf_s(buf, H_STRING_LEN, L"cursor (%ls)", type);
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2005-10-21 00:47:38 -07:00
|
|
|
}
|
|
|
|
|
|
2005-10-11 21:35:01 -07:00
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
// note: these standard resource interface functions are not exposed to the
|
|
|
|
|
// caller. all we need here is storage for the sys_cursor / GLCursor and
|
|
|
|
|
// a name -> data lookup mechanism, both provided by h_mgr.
|
|
|
|
|
// in other words, we continually create/free the cursor resource in
|
|
|
|
|
// cursor_draw and trust h_mgr's caching to absorb it.
|
|
|
|
|
|
2017-05-27 02:24:04 -07:00
|
|
|
static Handle cursor_load(const PIVFS& vfs, const VfsPath& name, double scale, bool forceGL)
|
2004-08-12 10:36:48 -07:00
|
|
|
{
|
2017-05-27 02:24:04 -07:00
|
|
|
return h_alloc(H_Cursor, vfs, name, 0, scale, (int)forceGL);
|
2004-08-12 10:36:48 -07:00
|
|
|
}
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2012-08-03 09:48:02 -07:00
|
|
|
void cursor_shutdown()
|
|
|
|
|
{
|
|
|
|
|
h_mgr_free_type(H_Cursor);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-03 05:38:42 -07:00
|
|
|
static Status cursor_free(Handle& h)
|
2004-08-12 10:36:48 -07:00
|
|
|
{
|
|
|
|
|
return h_free(h, H_Cursor);
|
|
|
|
|
}
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2017-05-27 02:24:04 -07:00
|
|
|
Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, double scale, bool forceGL)
|
2004-08-12 10:36:48 -07:00
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
// hide the cursor
|
2005-08-09 17:27:56 -07:00
|
|
|
if(!name)
|
2004-07-24 12:38:12 -07:00
|
|
|
{
|
2014-09-20 05:12:35 -07:00
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2004-07-24 12:38:12 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-27 02:24:04 -07:00
|
|
|
Handle hc = cursor_load(vfs, name, scale, forceGL);
|
2012-02-12 12:45:31 -08:00
|
|
|
// TODO: if forceGL changes at runtime after a cursor is first created,
|
|
|
|
|
// we might reuse a cached version of the cursor with the old forceGL flag
|
2010-11-13 11:15:29 -08:00
|
|
|
|
2011-05-03 05:38:42 -07:00
|
|
|
RETURN_STATUS_IF_ERR(hc); // silently ignore failures
|
2010-11-13 11:15:29 -08:00
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
H_DEREF(hc, Cursor, c);
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
switch(c->kind)
|
2006-03-05 19:46:12 -08:00
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
case CK_Default:
|
|
|
|
|
break;
|
|
|
|
|
|
2014-09-20 05:12:35 -07:00
|
|
|
case CK_SDL:
|
|
|
|
|
c->sdl_cursor.set();
|
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
|
|
|
|
break;
|
2008-06-22 04:11:59 -07:00
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
2005-08-09 17:27:56 -07:00
|
|
|
c->gl_cursor.draw(x, y);
|
2014-09-20 05:12:35 -07:00
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2011-05-04 05:10:17 -07:00
|
|
|
DEBUG_WARN_ERR(ERR::LOGIC);
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
2006-03-05 19:46:12 -08:00
|
|
|
}
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
(void)cursor_free(hc);
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2004-08-12 10:36:48 -07:00
|
|
|
}
|