mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-11 18:41:14 +00:00
Implement DirectDrawPalette methods (#106)
* Implement palettes * Update miniwin/miniwin/src/miniwin_ddsurface.cpp Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com> * Update miniwin/miniwin/src/miniwin_ddpalette.cpp * Update miniwin/miniwin/src/miniwin_ddraw.cpp --------- Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
This commit is contained in:
parent
51d88b6cd8
commit
44122f2f8a
@ -4,7 +4,11 @@
|
|||||||
|
|
||||||
struct DirectDrawPaletteImpl : public IDirectDrawPalette {
|
struct DirectDrawPaletteImpl : public IDirectDrawPalette {
|
||||||
DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable);
|
DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable);
|
||||||
|
~DirectDrawPaletteImpl() override;
|
||||||
HRESULT GetCaps(LPDWORD lpdwCaps) override;
|
HRESULT GetCaps(LPDWORD lpdwCaps) override;
|
||||||
HRESULT GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries) override;
|
HRESULT GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries) override;
|
||||||
HRESULT SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) override;
|
HRESULT SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SDL_Palette* m_palette;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
#include "miniwin_ddpalette_p.h"
|
#include "miniwin_ddpalette_p.h"
|
||||||
#include "miniwin_ddraw.h"
|
#include "miniwin_ddraw.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
DirectDrawPaletteImpl::DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable)
|
DirectDrawPaletteImpl::DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable)
|
||||||
{
|
{
|
||||||
|
m_palette = SDL_CreatePalette(256);
|
||||||
|
SetEntries(0, 0, 256, lpColorTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectDrawPaletteImpl::~DirectDrawPaletteImpl()
|
||||||
|
{
|
||||||
|
SDL_DestroyPalette(m_palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawPaletteImpl::GetCaps(LPDWORD lpdwCaps)
|
HRESULT DirectDrawPaletteImpl::GetCaps(LPDWORD lpdwCaps)
|
||||||
@ -12,10 +21,26 @@ HRESULT DirectDrawPaletteImpl::GetCaps(LPDWORD lpdwCaps)
|
|||||||
|
|
||||||
HRESULT DirectDrawPaletteImpl::GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries)
|
HRESULT DirectDrawPaletteImpl::GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries)
|
||||||
{
|
{
|
||||||
|
for (int i = dwBase; i < dwNumEntries; i++) {
|
||||||
|
lpEntries[i].peRed = m_palette->colors[i].r;
|
||||||
|
lpEntries[i].peGreen = m_palette->colors[i].g;
|
||||||
|
lpEntries[i].peBlue = m_palette->colors[i].b;
|
||||||
|
lpEntries[i].peFlags = PC_NONE;
|
||||||
|
}
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawPaletteImpl::SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries)
|
HRESULT DirectDrawPaletteImpl::SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries)
|
||||||
{
|
{
|
||||||
|
SDL_Color colors[256];
|
||||||
|
for (int i = 0; i < dwCount; i++) {
|
||||||
|
colors[i].r = lpEntries[i].peRed;
|
||||||
|
colors[i].g = lpEntries[i].peGreen;
|
||||||
|
colors[i].b = lpEntries[i].peBlue;
|
||||||
|
colors[i].a = SDL_ALPHA_OPAQUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetPaletteColors(m_palette, colors, dwStartingEntry, dwCount);
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,10 @@ HRESULT DirectDrawImpl::CreatePalette(
|
|||||||
IUnknown* pUnkOuter
|
IUnknown* pUnkOuter
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if ((dwFlags & DDPCAPS_8BIT) != DDPCAPS_8BIT) {
|
||||||
|
return DDERR_INVALIDPARAMS;
|
||||||
|
}
|
||||||
|
|
||||||
*lplpDDPalette = static_cast<LPDIRECTDRAWPALETTE>(new DirectDrawPaletteImpl(lpColorTable));
|
*lplpDDPalette = static_cast<LPDIRECTDRAWPALETTE>(new DirectDrawPaletteImpl(lpColorTable));
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,9 @@ DirectDrawSurfaceImpl::~DirectDrawSurfaceImpl()
|
|||||||
if (m_texture) {
|
if (m_texture) {
|
||||||
SDL_DestroyTexture(m_texture);
|
SDL_DestroyTexture(m_texture);
|
||||||
}
|
}
|
||||||
|
if (m_palette) {
|
||||||
|
m_palette->Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IUnknown interface
|
// IUnknown interface
|
||||||
@ -204,6 +207,8 @@ HRESULT DirectDrawSurfaceImpl::SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY
|
|||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette)
|
HRESULT DirectDrawSurfaceImpl::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette)
|
||||||
{
|
{
|
||||||
|
m_palette = lpDDPalette;
|
||||||
|
m_palette->AddRef();
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user