2006-04-11 16:59:08 -07:00
|
|
|
/**
|
|
|
|
|
* =========================================================================
|
|
|
|
|
* File : cursor.cpp
|
|
|
|
|
* Project : 0 A.D.
|
|
|
|
|
* Description : mouse cursors (either via OpenGL texture or hardware)
|
|
|
|
|
* =========================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
// license: GPL; see lib/license.txt
|
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
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include "lib/ogl.h"
|
|
|
|
|
#include "lib/sysdep/cursor.h"
|
|
|
|
|
#include "ogl_tex.h"
|
2007-12-20 12:14:21 -08:00
|
|
|
#include "../h_mgr.h"
|
|
|
|
|
#include "lib/file/vfs/vfs.h"
|
|
|
|
|
extern PIVFS g_VFS;
|
|
|
|
|
|
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)
|
2005-09-29 14:48:04 -07:00
|
|
|
#if OS_WIN
|
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
|
|
|
|
2005-12-06 19:38:39 -08:00
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
static LibError load_sys_cursor(const VfsPath& pathname, int hx, int hy, sys_cursor* cursor)
|
2005-12-06 19:38:39 -08:00
|
|
|
{
|
|
|
|
|
#if !ALLOW_SYS_CURSOR
|
2008-01-07 07:32:32 -08:00
|
|
|
UNUSED2(pathname);
|
2006-03-05 19:46:12 -08:00
|
|
|
UNUSED2(hx);
|
|
|
|
|
UNUSED2(hy);
|
2008-07-17 10:00:00 -07:00
|
|
|
UNUSED2(cursor);
|
2006-03-05 19:46:12 -08:00
|
|
|
|
2008-06-28 10:28:06 -07:00
|
|
|
return ERR::FAIL;
|
2005-12-06 19:38:39 -08:00
|
|
|
#else
|
2007-12-22 10:15:52 -08:00
|
|
|
shared_ptr<u8> file; size_t fileSize;
|
2008-06-22 04:11:59 -07:00
|
|
|
RETURN_ERR(g_VFS->LoadFile(pathname, file, fileSize));
|
2005-12-06 19:38:39 -08:00
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
ScopedTex t;
|
|
|
|
|
RETURN_ERR(tex_decode(file, fileSize, &t));
|
2005-12-06 19:38:39 -08:00
|
|
|
|
|
|
|
|
// convert to required BGRA format.
|
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
|
|
|
const int flags = (t.flags | TEX_BGR) & ~TEX_DXT;
|
2008-06-22 04:11:59 -07:00
|
|
|
RETURN_ERR(tex_transform_to(&t, flags));
|
2005-12-06 19:38:39 -08:00
|
|
|
void* bgra_img = tex_get_data(&t);
|
|
|
|
|
if(!bgra_img)
|
2008-06-22 04:11:59 -07:00
|
|
|
WARN_RETURN(ERR::FAIL);
|
2005-12-06 19:38:39 -08:00
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
RETURN_ERR(sys_cursor_create((int)t.w, (int)t.h, bgra_img, hx, hy, cursor));
|
|
|
|
|
return INFO::OK;
|
2005-12-06 19:38:39 -08:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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:
|
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
|
|
|
LibError create(const VfsPath& pathname, int hotspotx_, int hotspoty_)
|
2005-08-09 17:27:56 -07:00
|
|
|
{
|
2007-12-22 10:15:52 -08:00
|
|
|
ht = ogl_tex_load(pathname);
|
2005-09-28 22:00:20 -07:00
|
|
|
RETURN_ERR(ht);
|
|
|
|
|
|
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);
|
|
|
|
|
w = (GLint)width;
|
|
|
|
|
h = (GLint)height;
|
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
|
|
|
{
|
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);
|
|
|
|
|
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
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
// OpenGL's coordinate system is "upside-down"; correct for that.
|
|
|
|
|
y = g_yres - y;
|
|
|
|
|
|
2004-08-12 10:36:48 -07:00
|
|
|
glBegin(GL_QUADS);
|
2005-01-07 06:10:14 -08:00
|
|
|
glTexCoord2i(0, 0); glVertex2i( x-hotspotx, y+hotspoty );
|
|
|
|
|
glTexCoord2i(1, 0); glVertex2i( x-hotspotx+w, y+hotspoty );
|
|
|
|
|
glTexCoord2i(1, 1); glVertex2i( x-hotspotx+w, y+hotspoty-h );
|
|
|
|
|
glTexCoord2i(0, 1); glVertex2i( x-hotspotx, y+hotspoty-h );
|
2004-08-12 10:36:48 -07:00
|
|
|
glEnd();
|
|
|
|
|
}
|
2005-10-11 21:35:01 -07:00
|
|
|
|
2006-04-22 14:21:42 -07:00
|
|
|
LibError 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,
|
|
|
|
|
CK_System,
|
|
|
|
|
CK_OpenGL
|
|
|
|
|
};
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2004-08-12 10:36:48 -07:00
|
|
|
struct Cursor
|
|
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
CursorKind kind;
|
|
|
|
|
|
|
|
|
|
// valid iff kind == CK_System
|
|
|
|
|
sys_cursor system_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;
|
2008-06-22 04:11:59 -07:00
|
|
|
sys_cursor gl_empty_system_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
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
static void Cursor_init(Cursor* UNUSED(c), va_list UNUSED(args))
|
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
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
case CK_System:
|
|
|
|
|
sys_cursor_free(c->system_cursor);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
2005-08-09 17:27:56 -07:00
|
|
|
c->gl_cursor.destroy();
|
2008-06-22 04:11:59 -07:00
|
|
|
sys_cursor_free(c->gl_empty_system_cursor);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
debug_assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-08-12 10:36:48 -07:00
|
|
|
}
|
2004-07-29 09:14:22 -07:00
|
|
|
|
2007-12-22 10:15:52 -08:00
|
|
|
static LibError Cursor_reload(Cursor* c, const VfsPath& name, Handle)
|
2005-07-16 10:52:05 -07:00
|
|
|
{
|
2007-12-22 10:15:52 -08:00
|
|
|
const VfsPath path("art/textures/cursors");
|
|
|
|
|
const std::string basename = name.string();
|
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
|
|
|
{
|
2007-12-22 10:15:52 -08:00
|
|
|
const VfsPath pathname(path / (basename + ".txt"));
|
2007-12-20 12:14:21 -08:00
|
|
|
shared_ptr<u8> buf; size_t size;
|
2007-12-22 10:15:52 -08:00
|
|
|
RETURN_ERR(g_VFS->LoadFile(pathname, buf, size));
|
2007-12-20 12:14:21 -08:00
|
|
|
std::stringstream s(std::string((const char*)buf.get(), size));
|
2005-09-28 22:00:20 -07:00
|
|
|
s >> hotspotx >> hotspoty;
|
2005-07-16 10:52:05 -07:00
|
|
|
}
|
|
|
|
|
|
2007-12-22 10:15:52 -08:00
|
|
|
const VfsPath pathname(path / (basename + ".dds"));
|
2008-06-22 04:11:59 -07:00
|
|
|
|
|
|
|
|
// try loading as system cursor (2d, hardware accelerated)
|
|
|
|
|
if(load_sys_cursor(pathname, hotspotx, hotspoty, &c->system_cursor) == INFO::OK)
|
|
|
|
|
c->kind = CK_System;
|
|
|
|
|
// fall back to GLCursor (system cursor code is disabled or failed)
|
|
|
|
|
else if(c->gl_cursor.create(pathname, hotspotx, hotspoty) == INFO::OK)
|
2006-03-05 19:46:12 -08:00
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
c->kind = CK_OpenGL;
|
|
|
|
|
// (we need to hide the system cursor when using a OpenGL cursor)
|
|
|
|
|
sys_cursor_create_empty(&c->gl_empty_system_cursor);
|
2006-03-05 19:46:12 -08:00
|
|
|
}
|
2008-06-22 04:11:59 -07:00
|
|
|
// 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
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
static LibError 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
|
|
|
|
2008-06-22 04:11:59 -07:00
|
|
|
case CK_System:
|
|
|
|
|
if(c->system_cursor == 0)
|
|
|
|
|
WARN_RETURN(ERR::_1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
2005-10-11 21:35:01 -07:00
|
|
|
RETURN_ERR(c->gl_cursor.validate());
|
2008-06-22 04:11:59 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
WARN_RETURN(ERR::_2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2005-10-11 21:35:01 -07:00
|
|
|
}
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
static LibError Cursor_to_string(const Cursor* c, char* buf)
|
2005-10-21 00:47:38 -07:00
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
const char* type;
|
|
|
|
|
switch(c->kind)
|
|
|
|
|
{
|
|
|
|
|
case CK_Default:
|
|
|
|
|
type = "default";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CK_System:
|
|
|
|
|
type = "sys";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
|
|
|
|
type = "gl";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
debug_assert(0);
|
|
|
|
|
type = "?";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snprintf(buf, H_STRING_LEN, "cursor (%s)", 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.
|
|
|
|
|
|
|
|
|
|
static Handle cursor_load(const char* name)
|
2004-08-12 10:36:48 -07:00
|
|
|
{
|
|
|
|
|
return h_alloc(H_Cursor, name, 0);
|
|
|
|
|
}
|
2004-07-24 12:38:12 -07:00
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
static LibError 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
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
LibError cursor_draw(const char* name, int x, int y)
|
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
|
|
|
{
|
2008-06-22 04:11:59 -07:00
|
|
|
sys_cursor_set(0);
|
2006-09-22 06:19:40 -07:00
|
|
|
return INFO::OK;
|
2004-07-24 12:38:12 -07:00
|
|
|
}
|
|
|
|
|
|
2005-08-09 17:27:56 -07:00
|
|
|
Handle hc = cursor_load(name);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
case CK_System:
|
|
|
|
|
sys_cursor_set(c->system_cursor);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CK_OpenGL:
|
2005-08-09 17:27:56 -07:00
|
|
|
c->gl_cursor.draw(x, y);
|
2008-06-22 04:11:59 -07:00
|
|
|
// note: gl_empty_system_cursor can be 0 if sys_cursor_create_empty
|
|
|
|
|
// failed; in that case we don't want to sys_cursor_set because that
|
|
|
|
|
// would restore the default cursor (which is exactly what we're
|
|
|
|
|
// trying to avoid here)
|
|
|
|
|
if(c->gl_empty_system_cursor)
|
|
|
|
|
sys_cursor_set(c->gl_empty_system_cursor);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
debug_assert(0);
|
|
|
|
|
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
|
|
|
}
|