Skip to content

Commit

Permalink
Cleanup of gdi dependencies in Skin and General image
Browse files Browse the repository at this point in the history
Oops, I forgot some stuff on the last commit, so it won't build and
because of that did this commit end up cleaning up two files...
  • Loading branch information
TheAzack9 committed Apr 1, 2018
1 parent c0b0eac commit 942fd46
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 83 deletions.
51 changes: 25 additions & 26 deletions Library/GeneralImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "Logger.h"
#include "../Common/PathUtil.h"

using namespace Gdiplus;

// GrayScale Matrix
const D2D1_MATRIX_5X4_F GeneralImage::c_GreyScaleMatrix = {
0.299f, 0.299f, 0.299f, 0.0f,
Expand Down Expand Up @@ -70,7 +68,7 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const

if (!m_DisableTransform)
{
m_Options.m_Crop.X = m_Options.m_Crop.Y = m_Options.m_Crop.Width = m_Options.m_Crop.Height = -1;
m_Options.m_Crop.left = m_Options.m_Crop.top = m_Options.m_Crop.right = m_Options.m_Crop.bottom = -1;
m_Options.m_CropMode = ImageOptions::CROPMODE_TL;

const std::wstring& crop = parser.ReadString(section, m_OptionArray[OptionIndexImageCrop], L"");
Expand All @@ -85,22 +83,22 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const
token = wcstok(parseSz, L",", &context);
if (token)
{
m_Options.m_Crop.X = parser.ParseInt(token, 0);
m_Options.m_Crop.left = (FLOAT)parser.ParseInt(token, 0);

token = wcstok(nullptr, L",", &context);
if (token)
{
m_Options.m_Crop.Y = parser.ParseInt(token, 0);
m_Options.m_Crop.top = (FLOAT)parser.ParseInt(token, 0);

token = wcstok(nullptr, L",", &context);
if (token)
{
m_Options.m_Crop.Width = parser.ParseInt(token, 0);
m_Options.m_Crop.right = (FLOAT)parser.ParseInt(token, 0) + m_Options.m_Crop.left;

token = wcstok(nullptr, L",", &context);
if (token)
{
m_Options.m_Crop.Height = parser.ParseInt(token, 0);
m_Options.m_Crop.bottom = (FLOAT)parser.ParseInt(token, 0) + m_Options.m_Crop.top;

token = wcstok(nullptr, L",", &context);
if (token)
Expand All @@ -124,8 +122,8 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const

m_Options.m_GreyScale = parser.ReadBool(section, m_OptionArray[OptionIndexGreyscale], false);

Color tint = parser.ReadColor(section, m_OptionArray[OptionIndexImageTint], Color::White);
int alpha = parser.ReadInt(section, m_OptionArray[OptionIndexImageAlpha], tint.GetAlpha()); // for backwards compatibility
D2D1_COLOR_F tint = Gfx::Util::ToColorF(parser.ReadColor(section, m_OptionArray[OptionIndexImageTint], Gdiplus::Color::White));
int alpha = parser.ReadInt(section, m_OptionArray[OptionIndexImageAlpha], (INT)(tint.a * 255)); // for backwards compatibility
alpha = min(255, alpha);
alpha = max(0, alpha);

Expand All @@ -146,7 +144,7 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const
}
else
{
m_Options.m_ColorMatrix.m[0][0] = (Gdiplus::REAL)tint.GetRed() / 255.0f;
m_Options.m_ColorMatrix.m[0][0] = tint.r;
}

std::vector<Gdiplus::REAL> matrix2 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix2]);
Expand All @@ -159,7 +157,7 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const
}
else
{
m_Options.m_ColorMatrix.m[1][1] = (Gdiplus::REAL)tint.GetGreen() / 255.0f;
m_Options.m_ColorMatrix.m[1][1] = tint.g;
}

std::vector<Gdiplus::REAL> matrix3 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix3]);
Expand All @@ -172,7 +170,7 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const
}
else
{
m_Options.m_ColorMatrix.m[2][2] = (Gdiplus::REAL)tint.GetBlue() / 255.0f;
m_Options.m_ColorMatrix.m[2][2] = tint.b;
}

std::vector<Gdiplus::REAL> matrix4 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix4]);
Expand All @@ -185,7 +183,7 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const
}
else
{
m_Options.m_ColorMatrix.m[3][3] = (Gdiplus::REAL)alpha / 255.0f;
m_Options.m_ColorMatrix.m[3][3] = (FLOAT)alpha;
}

std::vector<Gdiplus::REAL> matrix5 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix5]);
Expand Down Expand Up @@ -221,7 +219,7 @@ void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const

if (!m_DisableTransform)
{
m_Options.m_Rotate = (REAL)parser.ReadFloat(section, m_OptionArray[OptionIndexImageRotate], 0.0);
m_Options.m_Rotate = (FLOAT)parser.ReadFloat(section, m_OptionArray[OptionIndexImageRotate], 0.0);
}

m_Options.m_UseExifOrientation = parser.ReadBool(section, m_OptionArray[OptionIndexUseExifOrientation], false);
Expand Down Expand Up @@ -294,7 +292,8 @@ bool GeneralImage::LoadImage(const std::wstring& imageName)

void GeneralImage::ApplyCrop(Gfx::Util::D2DEffectStream* stream) const
{
if (m_Options.m_Crop.Width >= 0 && m_Options.m_Crop.Height >= 0)
const auto& crop = m_Options.m_Crop;
if (crop.right - crop.left >= 0 && crop.bottom - crop.top >= 0)
{
const int imageW = m_Bitmap->GetBitmap()->GetWidth();
const int imageH = m_Bitmap->GetBitmap()->GetHeight();
Expand All @@ -306,32 +305,32 @@ void GeneralImage::ApplyCrop(Gfx::Util::D2DEffectStream* stream) const
{
case ImageOptions::CROPMODE_TL:
default:
x = m_Options.m_Crop.X;
y = m_Options.m_Crop.Y;
x = (int)crop.left;
y = (int)crop.top;
break;

case ImageOptions::CROPMODE_TR:
x = m_Options.m_Crop.X + imageW;
y = m_Options.m_Crop.Y;
x = (int)crop.left + imageW;
y = (int)crop.top;
break;

case ImageOptions::CROPMODE_BR:
x = m_Options.m_Crop.X + imageW;
y = m_Options.m_Crop.Y + imageH;
x = (int)crop.left + imageW;
y = (int)crop.top + imageH;
break;

case ImageOptions::CROPMODE_BL:
x = m_Options.m_Crop.X;
y = m_Options.m_Crop.Y + imageH;
x = (int)crop.left;
y = (int)crop.top + imageH;
break;

case ImageOptions::CROPMODE_C:
x = m_Options.m_Crop.X + (imageW / 2);
y = m_Options.m_Crop.Y + (imageH / 2);
x = (int)crop.left + (imageW / 2);
y = (int)crop.top + (imageH / 2);
break;
}

const D2D1_RECT_F rect = D2D1::RectF((FLOAT)x, (FLOAT)y, (FLOAT)(m_Options.m_Crop.Width + x), (FLOAT)(m_Options.m_Crop.Height + y));
const D2D1_RECT_F rect = D2D1::RectF((FLOAT)x, (FLOAT)y, (FLOAT)(crop.right - crop.left + x), (FLOAT)(crop.bottom - crop.top + y));
stream->Crop(m_Skin->GetCanvas(), rect);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Library/ImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ template <> struct hash<ImageOptions>
res = res * 31 + std::hash<DWORD>()(opt.m_FileSize);
res = res * 31 + std::hash<ULONGLONG>()(opt.m_FileTime);
res = res * 31 + std::hash<FLOAT>()(opt.m_Rotate);
res = res * 31 + std::hash<INT>()(opt.m_Crop.X);
res = res * 31 + std::hash<INT>()(opt.m_Crop.Y);
res = res * 31 + std::hash<INT>()(opt.m_Crop.Width);
res = res * 31 + std::hash<INT>()(opt.m_Crop.Height);
res = res * 31 + std::hash<FLOAT>()(opt.m_Crop.left);
res = res * 31 + std::hash<FLOAT>()(opt.m_Crop.top);
res = res * 31 + std::hash<FLOAT>()(opt.m_Crop.right);
res = res * 31 + std::hash<FLOAT>()(opt.m_Crop.bottom);
res = res * 31 + std::hash<INT>()((INT)opt.m_CropMode);
res = res * 31 + std::hash<INT>()((INT)opt.m_Flip);
res = res * 31 + std::hash<bool>()(opt.m_GreyScale);
Expand Down
12 changes: 6 additions & 6 deletions Library/ImageOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ImageOptions : Gfx::FileInfo
{
ImageOptions() :
m_ColorMatrix(),
m_Crop(-1, -1, -1, -1),
m_Crop({ -1, -1, -1, -1 }),
m_CropMode(CROPMODE_TL),
m_GreyScale(false),
m_Rotate(),
Expand Down Expand Up @@ -51,14 +51,14 @@ struct ImageOptions : Gfx::FileInfo
m_UseExifOrientation == other.m_UseExifOrientation &&
m_Flip == other.m_Flip &&
m_CropMode == other.m_CropMode &&
m_Crop.X == other.m_Crop.X &&
m_Crop.Y == other.m_Crop.Y &&
m_Crop.Width == other.m_Crop.Width &&
m_Crop.Height == other.m_Crop.Height;
m_Crop.left == other.m_Crop.left &&
m_Crop.top == other.m_Crop.top &&
m_Crop.right == other.m_Crop.right &&
m_Crop.bottom == other.m_Crop.bottom;
}

D2D1_MATRIX_5X4_F m_ColorMatrix;
Gdiplus::Rect m_Crop;
D2D1_RECT_F m_Crop;
CROPMODE m_CropMode;
bool m_GreyScale;
FLOAT m_Rotate;
Expand Down
88 changes: 45 additions & 43 deletions Library/Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "../Common/PathUtil.h"
#include "GeneralImage.h"

using namespace Gdiplus;

#define SNAPDISTANCE 10

#define ZPOS_FLAGS (SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING)
Expand Down Expand Up @@ -2129,9 +2127,10 @@ bool Skin::ReadSkin()
m_BackgroundMode = (BGMODE)m_Parser.ReadInt(L"Rainmeter", L"BackgroundMode", BGMODE_IMAGE);
m_SolidBevel = (BEVELTYPE)m_Parser.ReadInt(L"Rainmeter", L"BevelType", BEVELTYPE_NONE);

m_SolidColor = m_Parser.ReadColor(L"Rainmeter", L"SolidColor", Color::Gray);
m_SolidColor2 = m_Parser.ReadColor(L"Rainmeter", L"SolidColor2", m_SolidColor.GetValue());
m_SolidAngle = (Gdiplus::REAL)m_Parser.ReadFloat(L"Rainmeter", L"GradientAngle", 0.0);
auto color = m_Parser.ReadColor(L"Rainmeter", L"SolidColor", Gdiplus::Color::Gray);
m_SolidColor = Gfx::Util::ToColorF(color);
m_SolidColor2 = Gfx::Util::ToColorF(m_Parser.ReadColor(L"Rainmeter", L"SolidColor2", color));
m_SolidAngle = (FLOAT)m_Parser.ReadFloat(L"Rainmeter", L"GradientAngle", 0.0);

m_DynamicWindowSize = m_Parser.ReadBool(L"Rainmeter", L"DynamicWindowSize", false);

Expand All @@ -2148,8 +2147,10 @@ bool Skin::ReadSkin()
}
}

auto& color = GetRainmeter().GetDefaultSelectionColor();
m_SelectedColor = m_Parser.ReadColor(L"Rainmeter", L"SelectedColor", color.GetValue());
auto& selectionColor = GetRainmeter().GetDefaultSelectionColor();
Gdiplus::ARGB ARGBColor = Gdiplus::Color::MakeARGB((BYTE)(selectionColor.a * 255), (BYTE)(selectionColor.r * 255),
(BYTE)(selectionColor.g * 255), (BYTE)(selectionColor.b * 255));
m_SelectedColor = Gfx::Util::ToColorF(m_Parser.ReadColor(L"Rainmeter", L"SelectedColor", ARGBColor));

m_Mouse.ReadOptions(m_Parser, L"Rainmeter");

Expand Down Expand Up @@ -2531,9 +2532,9 @@ void Skin::Redraw()

if (m_BackgroundMode == BGMODE_IMAGE)
{
const Rect dst(0, 0, m_WindowW, m_WindowH);
const Rect src(0, 0, bitmap->GetWidth(), bitmap->GetHeight());
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(dst), Gfx::Util::ToRectF(src));
const D2D1_RECT_F dst = { 0, 0, (FLOAT)m_WindowW, (FLOAT)m_WindowH };
const D2D1_RECT_F src = { 0, 0, (FLOAT)bitmap->GetWidth(), (FLOAT)bitmap->GetHeight() };
m_Canvas.DrawBitmap(bitmap, dst, src);
}
else if (m_BackgroundMode == BGMODE_SCALED_IMAGE)
{
Expand All @@ -2544,97 +2545,98 @@ void Skin::Redraw()
if (m.left > 0)
{
// Top-Left
Rect r(0, 0, m.left, m.top);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(0, 0, m.left, m.top)));
D2D1_RECT_F r = { 0, 0, (FLOAT)m.left, (FLOAT)m.top };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF(0, 0, (FLOAT)m.left, (FLOAT)m.top));
}

// Top
Rect r(m.left, 0, m_WindowW - m.left - m.right, m.top);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(m.left, 0, m_BackgroundSize.cx - m.left - m.right, m.top)));
D2D1_RECT_F r = { (FLOAT)m.left, 0, (FLOAT)(m_WindowW - m.right), (FLOAT)m.top };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF((FLOAT)m.left, 0, (FLOAT)(m_BackgroundSize.cx - m.right), (FLOAT)m.top));

if (m.right > 0)
{
// Top-Right
Rect r(m_WindowW - m.right, 0, m.right, m.top);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(m_BackgroundSize.cx - m.right, 0, m.right, m.top)));
D2D1_RECT_F r = { (FLOAT)(m_WindowW - m.right), 0,(FLOAT)m_WindowW, (FLOAT)m.top };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF((FLOAT)(m_BackgroundSize.cx - m.right), 0, (FLOAT)m_BackgroundSize.cx, (FLOAT)m.top));
}
}

if (m.left > 0)
{
// Left
Rect r(0, m.top, m.left, m_WindowH - m.top - m.bottom);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(0, m.top, m.left, m_BackgroundSize.cy - m.top - m.bottom)));
D2D1_RECT_F r = { 0, (FLOAT)m.top, (FLOAT)m.left, (FLOAT)(m_WindowH - m.bottom) };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF(0, (FLOAT)m.top, (FLOAT)m.left, (FLOAT)(m_BackgroundSize.cy - m.bottom)));
}

// Center
Rect r(m.left, m.top, m_WindowW - m.left - m.right, m_WindowH - m.top - m.bottom);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(m.left, m.top, m_BackgroundSize.cx - m.left - m.right, m_BackgroundSize.cy - m.top - m.bottom)));
D2D1_RECT_F r = { (FLOAT)m.left, (FLOAT)m.top, (FLOAT)(m_WindowW - m.right), (FLOAT)(m_WindowH - m.bottom) };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF((FLOAT)m.left, (FLOAT)m.top, (FLOAT)(m_BackgroundSize.cx - m.right), (FLOAT)(m_BackgroundSize.cy - m.bottom)));

if (m.right > 0)
{
// Right
Rect r(m_WindowW - m.right, m.top, m.right, m_WindowH - m.top - m.bottom);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(m_BackgroundSize.cx - m.right, m.top, m.right, m_BackgroundSize.cy - m.top - m.bottom)));
D2D1_RECT_F r = { (FLOAT)(m_WindowW - m.right), (FLOAT)m.top, (FLOAT)m_WindowW, (FLOAT)(m_WindowH - m.bottom) };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF((FLOAT)(m_BackgroundSize.cx - m.right), (FLOAT)m.top, (FLOAT)m_BackgroundSize.cx, (FLOAT)(m_BackgroundSize.cy - m.bottom)));
}

if (m.bottom > 0)
{
if (m.left > 0)
{
// Bottom-Left
Rect r(0, m_WindowH - m.bottom, m.left, m.bottom);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(0, m_BackgroundSize.cy - m.bottom, m.left, m.bottom)));
D2D1_RECT_F r = { 0, (FLOAT)(m_WindowH - m.bottom), (FLOAT)m.left, (FLOAT)m_WindowH };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF(0, (FLOAT)(m_BackgroundSize.cy - m.bottom), (FLOAT)m.left, (FLOAT)m_BackgroundSize.cy));
}

// Bottom
Rect r(m.left, m_WindowH - m.bottom, m_WindowW - m.left - m.right, m.bottom);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(m.left, m_BackgroundSize.cy - m.bottom, m_BackgroundSize.cx - m.left - m.right, m.bottom)));
D2D1_RECT_F r = { (FLOAT)m.left, (FLOAT)(m_WindowH - m.bottom), (FLOAT)(m_WindowW - m.right), (FLOAT)m_WindowH };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF((FLOAT)m.left, (FLOAT)(m_BackgroundSize.cy - m.bottom), (FLOAT)(m_BackgroundSize.cx - m.right), (FLOAT)m_BackgroundSize.cy));

if (m.right > 0)
{
// Bottom-Right
Rect r(m_WindowW - m.right, m_WindowH - m.bottom, m.right, m.bottom);
m_Canvas.DrawBitmap(bitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(m_BackgroundSize.cx - m.right, m_BackgroundSize.cy - m.bottom, m.right, m.bottom)));
D2D1_RECT_F r = { (FLOAT)(m_WindowW - m.right), (FLOAT)(m_WindowH - m.bottom), (FLOAT)m_WindowW, (FLOAT)m_WindowH };
m_Canvas.DrawBitmap(bitmap, r, D2D1::RectF((FLOAT)(m_BackgroundSize.cx - m.right), (FLOAT)(m_BackgroundSize.cy - m.bottom), (FLOAT)m_BackgroundSize.cx, (FLOAT)m_BackgroundSize.cy));
}
}
}
else if (m_BackgroundMode == BGMODE_TILED_IMAGE)
{
const Rect dst(0, 0, m_WindowW, m_WindowH);
const Rect src(0, 0, bitmap->GetWidth(), bitmap->GetHeight());
m_Canvas.DrawTiledBitmap(bitmap, Gfx::Util::ToRectF(dst), Gfx::Util::ToRectF(src));
const D2D1_RECT_F dst = { 0, 0, (FLOAT)m_WindowW, (FLOAT)m_WindowH };
const D2D1_RECT_F src = { 0, 0, (FLOAT)bitmap->GetWidth(), (FLOAT)bitmap->GetHeight() };
m_Canvas.DrawTiledBitmap(bitmap, dst, src);
}
}
else if (m_BackgroundMode == BGMODE_SOLID)
{
// Draw the solid color background
Rect r(0, 0, m_WindowW, m_WindowH);
D2D1_RECT_F r = { 0, 0, (FLOAT)m_WindowW, (FLOAT)m_WindowH };

if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
if (m_SolidColor.a != 0 || m_SolidColor2.a != 0)
{
if (m_SolidColor.GetValue() == m_SolidColor2.GetValue())
if (m_SolidColor.r == m_SolidColor2.r && m_SolidColor.g == m_SolidColor2.g &&
m_SolidColor.b == m_SolidColor2.b && m_SolidColor.a == m_SolidColor2.a)
{
m_Canvas.Clear(Gfx::Util::ToColorF(m_SolidColor));
m_Canvas.Clear(m_SolidColor);
}
else
{
m_Canvas.FillGradientRectangle(Gfx::Util::ToRectF(r), Gfx::Util::ToColorF(m_SolidColor), Gfx::Util::ToColorF(m_SolidColor2), m_SolidAngle);
m_Canvas.FillGradientRectangle(r, m_SolidColor, m_SolidColor2, m_SolidAngle);
}
}

if (m_SolidBevel != BEVELTYPE_NONE)
{
Color lightColor(255, 255, 255, 255);
Color darkColor(255, 0, 0, 0);
D2D1_COLOR_F lightColor = { 1,1,1,1 };
D2D1_COLOR_F darkColor = { 0, 0, 0, 1 };

if (m_SolidBevel == BEVELTYPE_DOWN)
{
lightColor.SetValue(Color::MakeARGB(255, 0, 0, 0));
darkColor.SetValue(Color::MakeARGB(255, 255, 255, 255));
lightColor = { 0, 0, 0, 1 };
darkColor = { 1, 1, 1, 1 };
}

Meter::DrawBevel(m_Canvas, Gfx::Util::ToRectF(r), Gfx::Util::ToColorF(lightColor), Gfx::Util::ToColorF(darkColor));
Meter::DrawBevel(m_Canvas, r, lightColor, darkColor);
}
}

Expand All @@ -2658,8 +2660,8 @@ void Skin::Redraw()

if (m_Selected)
{
Gdiplus::Rect rect(0, 0, m_WindowW, m_WindowH);
m_Canvas.FillRectangle(Gfx::Util::ToRectF(rect), Gfx::Util::ToColorF(m_SelectedColor));
D2D1_RECT_F rect = { 0, 0, (FLOAT)m_WindowW, (FLOAT)m_WindowH };
m_Canvas.FillRectangle(rect, m_SelectedColor);
}
}

Expand Down
Loading

0 comments on commit 942fd46

Please sign in to comment.