mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Improved the drawing performance by using PixelFormat32bppPARGB instead of PixelFormat32bppARGB. (PARGB is faster than ARGB.)
This commit is contained in:
parent
7c09acb889
commit
89ea706055
@ -113,7 +113,7 @@ void CMeterButton::Initialize()
|
|||||||
|
|
||||||
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
||||||
{
|
{
|
||||||
Bitmap bitmapPart(m_W, m_H, PixelFormat32bppARGB);
|
Bitmap bitmapPart(m_W, m_H, PixelFormat32bppPARGB);
|
||||||
Graphics graphics(&bitmapPart);
|
Graphics graphics(&bitmapPart);
|
||||||
Rect r(0, 0, m_W, m_H);
|
Rect r(0, 0, m_W, m_H);
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ bool CMeterButton::HitTest2(int px, int py, bool checkAlpha)
|
|||||||
{
|
{
|
||||||
if (checkAlpha)
|
if (checkAlpha)
|
||||||
{
|
{
|
||||||
if (m_SolidColor.GetA() > 0 || m_SolidColor2.GetA() > 0)
|
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -260,7 +260,7 @@ bool CMeterButton::HitTest2(int px, int py, bool checkAlpha)
|
|||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
Status status = m_Image.GetImage()->GetPixel(px - x + m_W * m_State, py - y, &color);
|
Status status = m_Image.GetImage()->GetPixel(px - x + m_W * m_State, py - y, &color);
|
||||||
if (status != Ok || color.GetA() > 0)
|
if (status != Ok || color.GetA() != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ int CMeterWindow::Initialize(CRainmeter& Rainmeter)
|
|||||||
IgnoreAeroPeek();
|
IgnoreAeroPeek();
|
||||||
|
|
||||||
// Gotta have some kind of buffer during initialization
|
// Gotta have some kind of buffer during initialization
|
||||||
m_DoubleBuffer = new Bitmap(1, 1, PixelFormat32bppARGB);
|
m_DoubleBuffer = new Bitmap(1, 1, PixelFormat32bppPARGB);
|
||||||
|
|
||||||
Refresh(true, true);
|
Refresh(true, true);
|
||||||
if (!m_WindowStartHidden)
|
if (!m_WindowStartHidden)
|
||||||
@ -2233,7 +2233,12 @@ bool CMeterWindow::ResizeWindow(bool reset)
|
|||||||
|
|
||||||
if (m_BackgroundMode == BGMODE_IMAGE)
|
if (m_BackgroundMode == BGMODE_IMAGE)
|
||||||
{
|
{
|
||||||
m_Background = tempBackground->Clone(0, 0, m_BackgroundSize.cx, m_BackgroundSize.cy, PixelFormat32bppARGB);
|
PixelFormat format = tempBackground->GetPixelFormat();
|
||||||
|
if (format == PixelFormat32bppARGB)
|
||||||
|
{
|
||||||
|
format = PixelFormat32bppPARGB;
|
||||||
|
}
|
||||||
|
m_Background = tempBackground->Clone(0, 0, m_BackgroundSize.cx, m_BackgroundSize.cy, format);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2241,7 +2246,7 @@ bool CMeterWindow::ResizeWindow(bool reset)
|
|||||||
h = max(h, m_BackgroundSize.cy);
|
h = max(h, m_BackgroundSize.cy);
|
||||||
|
|
||||||
// Scale the background to fill the whole window
|
// Scale the background to fill the whole window
|
||||||
Bitmap* background = new Bitmap(w, h, PixelFormat32bppARGB);
|
Bitmap* background = new Bitmap(w, h, PixelFormat32bppPARGB);
|
||||||
|
|
||||||
Graphics graphics(background);
|
Graphics graphics(background);
|
||||||
|
|
||||||
@ -2423,30 +2428,45 @@ void CMeterWindow::Redraw()
|
|||||||
CreateRegion(true);
|
CreateRegion(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_DoubleBuffer) delete m_DoubleBuffer;
|
// Create or clear the doublebuffer
|
||||||
if (m_WindowW == 0 || m_WindowH == 0)
|
|
||||||
{
|
{
|
||||||
// Create a dummy bitmap to avoid invalid state
|
int cx = m_WindowW;
|
||||||
m_DoubleBuffer = new Bitmap(1, 1, PixelFormat32bppARGB);
|
int cy = m_WindowH;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_DoubleBuffer = new Bitmap(m_WindowW, m_WindowH, PixelFormat32bppARGB);
|
|
||||||
}
|
|
||||||
|
|
||||||
Graphics graphics(GetDoubleBuffer());
|
if (cx == 0 || cy == 0)
|
||||||
|
|
||||||
if (m_Background)
|
|
||||||
{
|
|
||||||
// Copy the background over the doublebuffer
|
|
||||||
Rect r(0, 0, m_WindowW, m_WindowH);
|
|
||||||
graphics.DrawImage(m_Background, r, 0, 0, m_Background->GetWidth(), m_Background->GetHeight(), UnitPixel);
|
|
||||||
}
|
|
||||||
else if (m_BackgroundMode == BGMODE_SOLID)
|
|
||||||
{
|
|
||||||
// Draw the solid color background
|
|
||||||
if (m_WindowW != 0 && m_WindowH != 0)
|
|
||||||
{
|
{
|
||||||
|
// Set dummy size to avoid invalid state
|
||||||
|
cx = 1;
|
||||||
|
cy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BitmapData buf;
|
||||||
|
if (cx != m_DoubleBuffer->GetWidth() || cy != m_DoubleBuffer->GetHeight() ||
|
||||||
|
Ok != m_DoubleBuffer->LockBits(&Rect(0, 0, cx, cy), ImageLockModeWrite, PixelFormat32bppPARGB, &buf))
|
||||||
|
{
|
||||||
|
if (m_DoubleBuffer) delete m_DoubleBuffer;
|
||||||
|
m_DoubleBuffer = new Bitmap(cx, cy, PixelFormat32bppPARGB);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset(buf.Scan0, 0, buf.Stride * cy); // assume that the bitmap is top-down
|
||||||
|
m_DoubleBuffer->UnlockBits(&buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_WindowW != 0 && m_WindowH != 0)
|
||||||
|
{
|
||||||
|
Graphics graphics(m_DoubleBuffer);
|
||||||
|
|
||||||
|
if (m_Background)
|
||||||
|
{
|
||||||
|
// Copy the background over the doublebuffer
|
||||||
|
Rect r(0, 0, m_WindowW, m_WindowH);
|
||||||
|
graphics.DrawImage(m_Background, r, 0, 0, m_Background->GetWidth(), m_Background->GetHeight(), UnitPixel);
|
||||||
|
}
|
||||||
|
else if (m_BackgroundMode == BGMODE_SOLID)
|
||||||
|
{
|
||||||
|
// Draw the solid color background
|
||||||
Rect r(0, 0, m_WindowW, m_WindowH);
|
Rect r(0, 0, m_WindowW, m_WindowH);
|
||||||
|
|
||||||
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
|
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
|
||||||
@ -2479,25 +2499,25 @@ void CMeterWindow::Redraw()
|
|||||||
CMeter::DrawBevel(graphics, r, light, dark);
|
CMeter::DrawBevel(graphics, r, light, dark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the meters
|
// Draw the meters
|
||||||
std::list<CMeter*>::const_iterator j = m_Meters.begin();
|
std::list<CMeter*>::const_iterator j = m_Meters.begin();
|
||||||
for( ; j != m_Meters.end(); ++j)
|
for( ; j != m_Meters.end(); ++j)
|
||||||
{
|
|
||||||
if (!(*j)->GetTransformationMatrix().IsIdentity())
|
|
||||||
{
|
{
|
||||||
// Change the world matrix
|
if (!(*j)->GetTransformationMatrix().IsIdentity())
|
||||||
graphics.SetTransform(&((*j)->GetTransformationMatrix()));
|
{
|
||||||
|
// Change the world matrix
|
||||||
|
graphics.SetTransform(&((*j)->GetTransformationMatrix()));
|
||||||
|
|
||||||
(*j)->Draw(graphics);
|
(*j)->Draw(graphics);
|
||||||
|
|
||||||
// Set back to identity matrix
|
// Set back to identity matrix
|
||||||
graphics.ResetTransform();
|
graphics.ResetTransform();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(*j)->Draw(graphics);
|
(*j)->Draw(graphics);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2726,19 +2746,14 @@ void CMeterWindow::UpdateTransparency(int alpha, bool reset)
|
|||||||
BLENDFUNCTION blendPixelFunction= {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
|
BLENDFUNCTION blendPixelFunction= {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
|
||||||
POINT ptWindowScreenPosition = {m_ScreenX, m_ScreenY};
|
POINT ptWindowScreenPosition = {m_ScreenX, m_ScreenY};
|
||||||
POINT ptSrc = {0, 0};
|
POINT ptSrc = {0, 0};
|
||||||
SIZE szWindow;
|
SIZE szWindow = {m_WindowW, m_WindowH};
|
||||||
|
|
||||||
if (m_WindowW == 0 || m_WindowH == 0)
|
if (szWindow.cx == 0 || szWindow.cy == 0)
|
||||||
{
|
{
|
||||||
// Set dummy size to avoid invalid state
|
// Set dummy size to avoid invalid state
|
||||||
szWindow.cx = 1;
|
szWindow.cx = 1;
|
||||||
szWindow.cy = 1;
|
szWindow.cy = 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
szWindow.cx = m_WindowW;
|
|
||||||
szWindow.cy = m_WindowH;
|
|
||||||
}
|
|
||||||
|
|
||||||
HDC dcScreen = GetDC(0);
|
HDC dcScreen = GetDC(0);
|
||||||
HDC dcMemory = CreateCompatibleDC(dcScreen);
|
HDC dcMemory = CreateCompatibleDC(dcScreen);
|
||||||
@ -3095,7 +3110,7 @@ bool CMeterWindow::HitTest(int x, int y)
|
|||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
Status status = m_DoubleBuffer->GetPixel(x, y, &color);
|
Status status = m_DoubleBuffer->GetPixel(x, y, &color);
|
||||||
if (status != Ok || color.GetA() > 0)
|
if (status != Ok || color.GetA() != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ void CTintedImage::ApplyCrop()
|
|||||||
{
|
{
|
||||||
if (m_Crop.Width == 0 || m_Crop.Height == 0)
|
if (m_Crop.Width == 0 || m_Crop.Height == 0)
|
||||||
{
|
{
|
||||||
m_BitmapTint = new Bitmap(0, 0, PixelFormat32bppARGB); // create dummy bitmap
|
m_BitmapTint = new Bitmap(0, 0, PixelFormat32bppPARGB); // create dummy bitmap
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -306,7 +306,7 @@ void CTintedImage::ApplyCrop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rect r(0, 0, m_Crop.Width, m_Crop.Height);
|
Rect r(0, 0, m_Crop.Width, m_Crop.Height);
|
||||||
m_BitmapTint = new Bitmap(r.Width, r.Height, PixelFormat32bppARGB);
|
m_BitmapTint = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);
|
||||||
|
|
||||||
Graphics graphics(m_BitmapTint);
|
Graphics graphics(m_BitmapTint);
|
||||||
graphics.DrawImage(m_Bitmap, r, x, y, r.Width, r.Height, UnitPixel);
|
graphics.DrawImage(m_Bitmap, r, x, y, r.Width, r.Height, UnitPixel);
|
||||||
@ -331,7 +331,7 @@ void CTintedImage::ApplyTint()
|
|||||||
|
|
||||||
Rect r(0, 0, original->GetWidth(), original->GetHeight());
|
Rect r(0, 0, original->GetWidth(), original->GetHeight());
|
||||||
|
|
||||||
Bitmap* tint = new Bitmap(r.Width, r.Height, PixelFormat32bppARGB);
|
Bitmap* tint = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);
|
||||||
|
|
||||||
Graphics graphics(tint);
|
Graphics graphics(tint);
|
||||||
|
|
||||||
@ -365,7 +365,7 @@ Bitmap* CTintedImage::TurnGreyscale(Bitmap* source)
|
|||||||
|
|
||||||
// We need a blank bitmap to paint our greyscale to in case of alpha
|
// We need a blank bitmap to paint our greyscale to in case of alpha
|
||||||
Rect r(0, 0, source->GetWidth(), source->GetHeight());
|
Rect r(0, 0, source->GetWidth(), source->GetHeight());
|
||||||
Bitmap* bitmap = new Bitmap(r.Width, r.Height, PixelFormat32bppARGB);
|
Bitmap* bitmap = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);
|
||||||
|
|
||||||
Graphics graphics(bitmap);
|
Graphics graphics(bitmap);
|
||||||
graphics.DrawImage(source, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr);
|
graphics.DrawImage(source, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr);
|
||||||
@ -393,7 +393,7 @@ void CTintedImage::ApplyTransform()
|
|||||||
REAL transformW = fabs(originalW * cos_f) + fabs(originalH * sin_f);
|
REAL transformW = fabs(originalW * cos_f) + fabs(originalH * sin_f);
|
||||||
REAL transformH = fabs(originalW * sin_f) + fabs(originalH * cos_f);
|
REAL transformH = fabs(originalW * sin_f) + fabs(originalH * cos_f);
|
||||||
|
|
||||||
Bitmap* transform = new Bitmap((int)(transformW + 0.5f), (int)(transformH + 0.5f), PixelFormat32bppARGB);
|
Bitmap* transform = new Bitmap((int)(transformW + 0.5f), (int)(transformH + 0.5f), PixelFormat32bppPARGB);
|
||||||
|
|
||||||
Graphics graphics(transform);
|
Graphics graphics(transform);
|
||||||
graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality);
|
graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality);
|
||||||
@ -427,7 +427,7 @@ void CTintedImage::ApplyTransform()
|
|||||||
Bitmap* original = GetImage();
|
Bitmap* original = GetImage();
|
||||||
|
|
||||||
Rect r(0, 0, original->GetWidth(), original->GetHeight());
|
Rect r(0, 0, original->GetWidth(), original->GetHeight());
|
||||||
Bitmap* transform = new Bitmap(r.Width, r.Height, PixelFormat32bppARGB);
|
Bitmap* transform = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);
|
||||||
|
|
||||||
Graphics graphics(transform);
|
Graphics graphics(transform);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user