mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Icon refactor
This commit is contained in:
@@ -44,8 +44,6 @@ namespace PortabilityLayer
|
||||
{
|
||||
public:
|
||||
bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) override;
|
||||
THandle<PixMapImpl> LoadSimpleColorIcon(const THandle<void> &hdl) override;
|
||||
THandle<PixMapImpl> LoadBWIcon(const THandle<void> &hdl) override;
|
||||
|
||||
static IconLoaderImpl *GetInstance();
|
||||
|
||||
@@ -317,87 +315,6 @@ namespace PortabilityLayer
|
||||
return true;
|
||||
}
|
||||
|
||||
THandle<PixMapImpl> IconLoaderImpl::LoadSimpleColorIcon(const THandle<void> &hdl)
|
||||
{
|
||||
if (hdl == nullptr || hdl.MMBlock()->m_size != 1024)
|
||||
return THandle<PixMapImpl>();
|
||||
|
||||
const Rect rect = Rect::Create(0, 0, 32, 32);
|
||||
|
||||
GpPixelFormat_t pixelFormat = DisplayDeviceManager::GetInstance()->GetPixelFormat();
|
||||
|
||||
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, pixelFormat);
|
||||
if (!pixMap)
|
||||
return THandle<PixMapImpl>();
|
||||
|
||||
const uint8_t *inData = static_cast<const uint8_t*>(*hdl);
|
||||
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
|
||||
const size_t outPitch = (*pixMap)->GetPitch();
|
||||
|
||||
if (pixelFormat == GpPixelFormats::kRGB32)
|
||||
{
|
||||
const PortabilityLayer::RGBAColor *palette = StandardPalette::GetInstance()->GetColors();
|
||||
|
||||
for (size_t row = 0; row < 32; row++)
|
||||
{
|
||||
uint32_t *outU32 = reinterpret_cast<uint32_t*>(outData);
|
||||
for (size_t col = 0; col < 32; col++)
|
||||
outU32[col] = palette[inData[col]].AsUInt32();
|
||||
|
||||
inData += 32;
|
||||
outData += outPitch;
|
||||
}
|
||||
}
|
||||
else if (pixelFormat == GpPixelFormats::k8BitStandard)
|
||||
{
|
||||
for (size_t row = 0; row < 32; row++)
|
||||
{
|
||||
for (size_t col = 0; col < 32; col++)
|
||||
outData[col] = inData[col];
|
||||
|
||||
inData += 32;
|
||||
outData += outPitch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
return pixMap;
|
||||
}
|
||||
|
||||
THandle<PixMapImpl> IconLoaderImpl::LoadBWIcon(const THandle<void> &hdl)
|
||||
{
|
||||
if (hdl == nullptr || hdl.MMBlock()->m_size != 128)
|
||||
return THandle<PixMapImpl>();
|
||||
|
||||
const Rect rect = Rect::Create(0, 0, 32, 32);
|
||||
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, GpPixelFormats::kBW1);
|
||||
if (!pixMap)
|
||||
return THandle<PixMapImpl>();
|
||||
|
||||
const uint8_t *inData = static_cast<const uint8_t*>(*hdl);
|
||||
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
|
||||
const size_t outPitch = (*pixMap)->GetPitch();
|
||||
|
||||
for (size_t row = 0; row < 32; row++)
|
||||
{
|
||||
for (size_t col = 0; col < 32; col++)
|
||||
{
|
||||
if (inData[col / 8] & (0x80 >> (col & 7)))
|
||||
outData[col] = 0xff;
|
||||
else
|
||||
outData[col] = 0x00;
|
||||
}
|
||||
|
||||
inData += 4;
|
||||
outData += outPitch;
|
||||
}
|
||||
|
||||
return pixMap;
|
||||
}
|
||||
|
||||
IconLoaderImpl *IconLoaderImpl::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
|
@@ -9,13 +9,11 @@ namespace PortabilityLayer
|
||||
{
|
||||
class PixMapImpl;
|
||||
class SimpleImage;
|
||||
|
||||
|
||||
class IconLoader
|
||||
{
|
||||
public:
|
||||
virtual bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) = 0;
|
||||
virtual THandle<PixMapImpl> LoadSimpleColorIcon(const THandle<void> &hdl) = 0;
|
||||
virtual THandle<PixMapImpl> LoadBWIcon(const THandle<void> &hdl) = 0;
|
||||
|
||||
static IconLoader *GetInstance();
|
||||
};
|
||||
|
@@ -11,14 +11,18 @@ namespace PortabilityLayer
|
||||
|
||||
enum FinderFileFlags
|
||||
{
|
||||
FINDER_FILE_FLAG_LOCKED = (1 << 15),
|
||||
FINDER_FILE_FLAG_ALIAS = (1 << 15),
|
||||
FINDER_FILE_FLAG_INVISIBLE = (1 << 14),
|
||||
FINDER_FILE_FLAG_BUNDLE = (1 << 13),
|
||||
FINDER_FILE_FLAG_SYSTEM = (1 << 12),
|
||||
FINDER_FILE_FLAG_COPY_PROTECTED = (1 << 11),
|
||||
FINDER_FILE_FLAG_BUSY = (1 << 10),
|
||||
FINDER_FILE_FLAG_CHANGED = (1 << 9),
|
||||
FINDER_FILE_FLAG_NAME_LOCKED = (1 << 12),
|
||||
FINDER_FILE_FLAG_STATIONARY = (1 << 11),
|
||||
FINDER_FILE_FLAG_CUSTOM_ICON = (1 << 10),
|
||||
FINDER_FILE_FLAG_INITED = (1 << 8),
|
||||
FINDER_FILE_FLAG_NO_INITS = (1 << 7),
|
||||
FINDER_FILE_FLAG_SHARED = (1 << 6),
|
||||
FINDER_FILE_FLAG_COLOR_BIT2 = (1 << 3),
|
||||
FINDER_FILE_FLAG_COLOR_BIT1 = (1 << 2),
|
||||
FINDER_FILE_FLAG_COLOR_BIT0 = (1 << 1),
|
||||
};
|
||||
|
||||
struct MacFileProperties
|
||||
|
@@ -892,13 +892,41 @@ namespace PortabilityLayer
|
||||
void *storage = static_cast<GraphicType_t*>(NewPtr(sizeof(GraphicType_t)));
|
||||
if (storage)
|
||||
{
|
||||
memcpy(m_iconMask, static_cast<const uint8_t*>(*icsHandle) + 32, 32);
|
||||
memcpy(m_iconColors, static_cast<const uint8_t*>(*ics8Handle), 16 * 16);
|
||||
DrawSurface *iconMaskTemp = nullptr;
|
||||
DrawSurface *iconColorTemp = nullptr;
|
||||
|
||||
GraphicType_t *graphic = new (storage) GraphicType_t(m_iconColors);
|
||||
if (NewGWorld(&iconMaskTemp, GpPixelFormats::kBW1, Rect::Create(0, 0, 16, 16)) == PLErrors::kNone)
|
||||
{
|
||||
if (NewGWorld(&iconColorTemp, GpPixelFormats::k8BitStandard, Rect::Create(0, 0, 16, 16)) == PLErrors::kNone)
|
||||
{
|
||||
iconMaskTemp->DrawPicture(icsHandle.StaticCast<BitmapImage>(), Rect::Create(-16, 0, 16, 16));
|
||||
iconColorTemp->DrawPicture(ics8Handle.StaticCast<BitmapImage>(), Rect::Create(0, 0, 16, 16));
|
||||
|
||||
m_iconGraphic = graphic;
|
||||
const PixMap *maskPixMap = (*iconMaskTemp->m_port.GetPixMap());
|
||||
const PixMap *colorPixMap = (*iconColorTemp->m_port.GetPixMap());
|
||||
|
||||
memset(m_iconMask, 0, 16 * 16 / 8);
|
||||
|
||||
for (size_t row = 0; row < 16; row++)
|
||||
{
|
||||
const uint8_t *maskSourceRow = static_cast<const uint8_t*>(maskPixMap->m_data) + maskPixMap->m_pitch * row;
|
||||
|
||||
for (size_t col = 0; col < 16; col++)
|
||||
{
|
||||
if (maskSourceRow[col] != 0)
|
||||
m_iconMask[row * 2 + col / 8] |= (1 << (7 - (col & 7)));
|
||||
}
|
||||
memcpy(m_iconColors + row * 16, static_cast<const uint8_t*>(colorPixMap->m_data) + colorPixMap->m_pitch * row, 16);
|
||||
}
|
||||
|
||||
GraphicType_t *graphic = new (storage) GraphicType_t(m_iconColors);
|
||||
|
||||
m_iconGraphic = graphic;
|
||||
DisposeGWorld(iconColorTemp);
|
||||
}
|
||||
|
||||
DisposeGWorld(iconMaskTemp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -923,7 +951,7 @@ namespace PortabilityLayer
|
||||
|
||||
if (m_menuBarGraf == nullptr)
|
||||
{
|
||||
if (qdManager->NewGWorld(&m_menuBarGraf, pixelFormat, menuRect, nullptr) != 0)
|
||||
if (qdManager->NewGWorld(&m_menuBarGraf, pixelFormat, menuRect) != 0)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1529,7 +1557,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
GpPixelFormat_t pixelFormat = DisplayDeviceManager::GetInstance()->GetPixelFormat();
|
||||
|
||||
if (qdManager->NewGWorld(&m_menuGraf, pixelFormat, menuRect, nullptr) != 0)
|
||||
if (qdManager->NewGWorld(&m_menuGraf, pixelFormat, menuRect) != 0)
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -233,7 +233,7 @@ void AnimationManager::RefreshPlayer(AnimationPlayer *player)
|
||||
else
|
||||
{
|
||||
DrawSurface *renderSurface = nullptr;
|
||||
if (PortabilityLayer::QDManager::GetInstance()->NewGWorld(&renderSurface, surface->m_port.GetPixelFormat(), player->m_renderRect, nullptr) != PLErrors::kNone)
|
||||
if (PortabilityLayer::QDManager::GetInstance()->NewGWorld(&renderSurface, surface->m_port.GetPixelFormat(), player->m_renderRect) != PLErrors::kNone)
|
||||
return;
|
||||
|
||||
renderSurface->DrawPicture(img, player->m_renderRect);
|
||||
|
@@ -18,9 +18,9 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
PLError_t NewGWorld(DrawSurface **gworld, GpPixelFormat_t pixelFormat, const Rect *bounds, CTabHandle colorTable)
|
||||
PLError_t NewGWorld(DrawSurface **gworld, GpPixelFormat_t pixelFormat, const Rect &bounds)
|
||||
{
|
||||
return PortabilityLayer::QDManager::GetInstance()->NewGWorld(gworld, pixelFormat, *bounds, colorTable);
|
||||
return PortabilityLayer::QDManager::GetInstance()->NewGWorld(gworld, pixelFormat, bounds);
|
||||
}
|
||||
|
||||
void DisposeGWorld(DrawSurface *gworld)
|
||||
|
@@ -17,7 +17,7 @@ typedef CTabPtr *CTabHandle;
|
||||
typedef PixMap *PixMapPtr;
|
||||
typedef PixMapPtr *PixMapHandle;
|
||||
|
||||
PLError_t NewGWorld(DrawSurface **gworld, GpPixelFormat_t pixelFormat, const Rect *bounds, CTabHandle colorTable);
|
||||
PLError_t NewGWorld(DrawSurface **gworld, GpPixelFormat_t pixelFormat, const Rect &bounds);
|
||||
void DisposeGWorld(DrawSurface *gworld);
|
||||
|
||||
PixMapHandle GetGWorldPixMap(DrawSurface *gworld);
|
||||
|
@@ -584,7 +584,7 @@ void DrawSurface::DrawPicture(THandle<BitmapImage> pictHdl, const Rect &bounds,
|
||||
PL_NotYetImplemented_TODO("Palette");
|
||||
|
||||
DrawSurface *scaleSurface = nullptr;
|
||||
if (PortabilityLayer::QDManager::GetInstance()->NewGWorld(&scaleSurface, this->m_port.GetPixelFormat(), picRect, nullptr) != PLErrors::kNone)
|
||||
if (PortabilityLayer::QDManager::GetInstance()->NewGWorld(&scaleSurface, this->m_port.GetPixelFormat(), picRect) != PLErrors::kNone)
|
||||
return;
|
||||
|
||||
scaleSurface->DrawPicture(pictHdl, picRect);
|
||||
|
@@ -311,7 +311,7 @@ namespace PortabilityLayer
|
||||
extension = ".wav";
|
||||
outValidationRule = ResourceValidationRules::kWAV;
|
||||
}
|
||||
else if (resTypeID == ResTypeID('Date') || resTypeID == ResTypeID('PICT'))
|
||||
else if (resTypeID == ResTypeID('Date') || resTypeID == ResTypeID('PICT') || resTypeID == ResTypeID('ICN#') || resTypeID == ResTypeID('icl8') || resTypeID == ResTypeID('icl4') || resTypeID == ResTypeID('ics#') || resTypeID == ResTypeID('ics8') || resTypeID == ResTypeID('ics4'))
|
||||
{
|
||||
extension = kPICTExtension;
|
||||
outValidationRule = ResourceValidationRules::kBMP;
|
||||
|
@@ -15,7 +15,7 @@ namespace PortabilityLayer
|
||||
QDManagerImpl();
|
||||
|
||||
void Init() override;
|
||||
PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) override;
|
||||
PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds) override;
|
||||
void DisposeGWorld(DrawSurface *gw) override;
|
||||
|
||||
static QDManagerImpl *GetInstance();
|
||||
@@ -32,7 +32,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
}
|
||||
|
||||
PLError_t QDManagerImpl::NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable)
|
||||
PLError_t QDManagerImpl::NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds)
|
||||
{
|
||||
void *grafStorage = MemoryManager::GetInstance()->Alloc(sizeof(DrawSurface));
|
||||
if (!grafStorage)
|
||||
|
@@ -15,7 +15,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
public:
|
||||
virtual void Init() = 0;
|
||||
virtual PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) = 0;
|
||||
virtual PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds) = 0;
|
||||
virtual void DisposeGWorld(DrawSurface *gw) = 0;
|
||||
|
||||
static QDManager *GetInstance();
|
||||
|
@@ -299,4 +299,36 @@ namespace PortabilityLayer
|
||||
}
|
||||
|
||||
StandardPalette StandardPalette::ms_instance;
|
||||
|
||||
Icon4BitPalette::Icon4BitPalette()
|
||||
{
|
||||
m_colors[0] = RGBAColor::Create(255, 255, 255, 255);
|
||||
m_colors[1] = RGBAColor::Create(251, 243, 5, 255);
|
||||
m_colors[2] = RGBAColor::Create(255, 100, 3, 255);
|
||||
m_colors[3] = RGBAColor::Create(221, 9, 7, 255);
|
||||
m_colors[4] = RGBAColor::Create(242, 8, 132, 255);
|
||||
m_colors[5] = RGBAColor::Create(71, 0, 165, 255);
|
||||
m_colors[6] = RGBAColor::Create(0, 0, 211, 255);
|
||||
m_colors[7] = RGBAColor::Create(2, 171, 234, 255);
|
||||
m_colors[8] = RGBAColor::Create(31, 183, 20, 255);
|
||||
m_colors[9] = RGBAColor::Create(0, 100, 18, 255);
|
||||
m_colors[10] = RGBAColor::Create(86, 44, 5, 255);
|
||||
m_colors[11] = RGBAColor::Create(144, 113, 58, 255);
|
||||
m_colors[12] = RGBAColor::Create(191, 191, 191, 255);
|
||||
m_colors[13] = RGBAColor::Create(128, 128, 128, 255);
|
||||
m_colors[14] = RGBAColor::Create(64, 64, 64, 255);
|
||||
m_colors[15] = RGBAColor::Create(0, 0, 0, 255);
|
||||
}
|
||||
|
||||
Icon4BitPalette *Icon4BitPalette::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
}
|
||||
|
||||
const RGBAColor *Icon4BitPalette::GetColors() const
|
||||
{
|
||||
return m_colors;
|
||||
}
|
||||
|
||||
Icon4BitPalette Icon4BitPalette::ms_instance;
|
||||
}
|
||||
|
@@ -56,4 +56,19 @@ namespace PortabilityLayer
|
||||
|
||||
uint8_t m_lut[16 * 16 * 16];
|
||||
};
|
||||
|
||||
class Icon4BitPalette
|
||||
{
|
||||
public:
|
||||
static const unsigned int kSize = 16;
|
||||
|
||||
Icon4BitPalette();
|
||||
|
||||
static Icon4BitPalette *GetInstance();
|
||||
const RGBAColor *GetColors() const;
|
||||
|
||||
private:
|
||||
static Icon4BitPalette ms_instance;
|
||||
RGBAColor m_colors[kSize];
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user