Add mouse cursor handling

This commit is contained in:
elasota
2019-12-22 00:35:30 -05:00
parent 8354d13a84
commit eed82e2960
32 changed files with 835 additions and 72 deletions

View File

@@ -0,0 +1,12 @@
#pragma once
namespace EGpStandardCursors
{
enum EGpStandardCursor
{
kArrow,
kHidden,
};
}
typedef EGpStandardCursors::EGpStandardCursor EGpStandardCursor_t;

View File

@@ -0,0 +1,58 @@
#include "GpColorCursor_Win32.h"
#include <stdlib.h>
#include <new>
void GpColorCursor_Win32::Destroy()
{
this->DecRef();
}
GpColorCursor_Win32 *GpColorCursor_Win32::Load(const wchar_t *path)
{
HANDLE imageH = LoadImageW(nullptr, path, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
if (imageH == nullptr)
return nullptr;
HCURSOR cursor = reinterpret_cast<HCURSOR>(imageH);
void *storage = malloc(sizeof(GpColorCursor_Win32));
if (!storage)
{
DestroyCursor(cursor);
return nullptr;
}
return new (storage) GpColorCursor_Win32(reinterpret_cast<HCURSOR>(cursor));
}
GpColorCursor_Win32::GpColorCursor_Win32(HCURSOR cursor)
: m_cursor(cursor)
, m_refCount(1)
{
}
GpColorCursor_Win32::~GpColorCursor_Win32()
{
DestroyCursor(m_cursor);
}
const HCURSOR &GpColorCursor_Win32::GetHCursor() const
{
return m_cursor;
}
void GpColorCursor_Win32::IncRef()
{
m_refCount++;
}
void GpColorCursor_Win32::DecRef()
{
m_refCount--;
if (m_refCount == 0)
{
this->~GpColorCursor_Win32();
free(this);
}
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include "IGpColorCursor.h"
#include "GpWindows.h"
class GpColorCursor_Win32 final : public IGpColorCursor
{
public:
void Destroy() override;
const HCURSOR &GetHCursor() const;
void IncRef();
void DecRef();
static GpColorCursor_Win32 *Load(const wchar_t *path);
private:
GpColorCursor_Win32(HCURSOR cursor);
~GpColorCursor_Win32();
HCURSOR m_cursor;
int m_refCount;
};

View File

@@ -21,6 +21,8 @@ struct GpDisplayDriverProperties
unsigned int m_frameTimeLockMaxNumerator;
unsigned int m_frameTimeLockMaxDenominator;
void *m_osGlobals;
// Tick function and context to call when a frame needs to be served.
TickFunc_t m_tickFunc;
void *m_tickFuncContext;

View File

@@ -1,18 +1,20 @@
#pragma once
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
struct GPWindowsGlobals
{
HINSTANCE m_hInstance;
HINSTANCE m_hPrevInstance;
LPSTR m_cmdLine;
int m_nCmdShow;
};
extern GPWindowsGlobals g_gpWindowsGlobals;
#pragma once
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#define OEMRESOURCE
#include <Windows.h>
struct GpWindowsGlobals
{
HINSTANCE m_hInstance;
HINSTANCE m_hPrevInstance;
LPCSTR m_cmdLine;
LPCWSTR m_baseDir;
int m_nCmdShow;
};
extern GpWindowsGlobals g_gpWindowsGlobals;
#undef CreateMutex

View File

@@ -0,0 +1,6 @@
#pragma once
struct IGpColorCursor
{
virtual void Destroy() = 0;
};

View File

@@ -1,8 +1,10 @@
#pragma once
#include "PixelFormat.h"
#include "EGpStandardCursor.h"
struct IGpDisplayDriverSurface;
struct IGpColorCursor;
// Display drivers are responsible for timing and calling the game tick function.
struct IGpDisplayDriver
@@ -16,5 +18,9 @@ public:
virtual IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, PortabilityLayer::PixelFormat pixelFormat) = 0;
virtual void DrawSurface(IGpDisplayDriverSurface *surface, size_t x, size_t y, size_t width, size_t height) = 0;
virtual IGpColorCursor *LoadColorCursor(int cursorID) = 0;
virtual void SetColorCursor(IGpColorCursor *colorCursor) = 0;
virtual void SetStandardCursor(EGpStandardCursor_t standardCursor) = 0;
virtual void UpdatePalette(const void *paletteData) = 0;
};