From 16b1918af35d2f73d544e95876f2ce342e9a29ed Mon Sep 17 00:00:00 2001 From: spx Date: Sat, 20 Feb 2010 00:39:08 +0000 Subject: [PATCH] Added "ImageAlpha" option to the IMAGE meter. Changed the interpolation mode in AntiAlias=1 to Default from Bicubic. There is a possibility that this change will be changed again in the future. --- Library/Meter.cpp | 3 ++- Library/MeterImage.cpp | 31 +++++++++++++++++++++++++++++-- Library/MeterImage.h | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 4886eab1..6eaf26de 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -419,7 +419,8 @@ bool CMeter::Draw(Graphics& graphics) if (m_AntiAlias) { - graphics.SetInterpolationMode(InterpolationModeBicubic); + //graphics.SetInterpolationMode(InterpolationModeBicubic); // Bicubic is not suitable for shrinking an image. + graphics.SetInterpolationMode(InterpolationModeDefault); graphics.SetSmoothingMode(SmoothingModeHighQuality); graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality); } diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index b144c0ec..0da89934 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -39,6 +39,7 @@ CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow) m_WidthDefined = false; m_HeightDefined = false; m_PreserveAspectRatio = false; + m_ImageAlpha = 255; m_hBuffer = NULL; m_Modified.dwHighDateTime = 0; m_Modified.dwLowDateTime = 0; @@ -205,7 +206,7 @@ void CMeterImage::ReadConfig(const WCHAR* section) } } - if (!m_Measure) + if (!m_Initialized || !m_Measure) { std::wstring oldImageName = m_ImageName; @@ -220,6 +221,10 @@ void CMeterImage::ReadConfig(const WCHAR* section) m_PreserveAspectRatio = 0!=parser.ReadInt(section, L"PreserveAspectRatio", 0); + m_ImageAlpha = parser.ReadInt(section, L"ImageAlpha", 255); + m_ImageAlpha = min(255, m_ImageAlpha); + m_ImageAlpha = max(0, m_ImageAlpha); + if (-1 != (int)parser.ReadFormula(section, L"W", -1)) { m_WidthDefined = true; @@ -316,7 +321,29 @@ bool CMeterImage::Draw(Graphics& graphics) } Rect r(x, y, drawW, drawH); - graphics.DrawImage(m_Bitmap, r, 0, 0, imageW, imageH, UnitPixel); + + if (m_ImageAlpha == 255) + { + graphics.DrawImage(m_Bitmap, r, 0, 0, imageW, imageH, UnitPixel); + } + else if (m_ImageAlpha > 0) + { + REAL alp = m_ImageAlpha / 255.0f; + + // Initialize the color matrix + ColorMatrix colorMatrix = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, alp, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; + + // Create an ImageAttributes object and set its color matrix + ImageAttributes imageAtt; + imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); + + // Draw the semi-transparent bitmap image + graphics.DrawImage(m_Bitmap, r, 0, 0, imageW, imageH, UnitPixel, &imageAtt); + } } return true; diff --git a/Library/MeterImage.h b/Library/MeterImage.h index 2978e307..e665a60c 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -49,6 +49,7 @@ private: bool m_WidthDefined; bool m_HeightDefined; bool m_PreserveAspectRatio; // If true, aspect ratio of the image is preserved when the image is scaled + int m_ImageAlpha; // Transparency value 0 - 255 HGLOBAL m_hBuffer; FILETIME m_Modified; };