- MeterImage: Added ScaleMargins option.

- MeterWindow: Changed !RainmeterPluginBang to allow specifying only MeasureName. If Arguments is not specified, "" (empty string) is given as args to plugin.
!RainmeterPluginBang "[MeasureName] (Arguments)"
This commit is contained in:
spx 2010-12-13 08:19:45 +00:00
parent c469fce770
commit 3fc3566937
3 changed files with 97 additions and 21 deletions

View File

@ -39,6 +39,11 @@ CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow)
m_HeightDefined = false;
m_PreserveAspectRatio = false;
m_Tile = false;
m_ScaleMargins.left = 0;
m_ScaleMargins.top = 0;
m_ScaleMargins.right = 0;
m_ScaleMargins.bottom = 0;
}
/*
@ -144,6 +149,9 @@ void CMeterImage::ReadConfig(const WCHAR* section)
m_PreserveAspectRatio = 0!=parser.ReadInt(section, L"PreserveAspectRatio", 0);
m_Tile = 0!=parser.ReadInt(section, L"Tile", 0);
static const RECT defMargins = {0};
m_ScaleMargins = parser.ReadRECT(section, L"ScaleMargins", defMargins);
if (parser.IsValueDefined(section, L"W"))
{
m_WidthDefined = true;
@ -244,16 +252,13 @@ bool CMeterImage::Draw(Graphics& graphics)
int drawW = m_W;
int drawH = m_H;
ImageAttributes imgAttr;
bool useImgAttr = false;
if (m_Tile)
{
imageW = m_W;
imageH = m_H;
ImageAttributes imgAttr;
imgAttr.SetWrapMode(WrapModeTile);
useImgAttr = true;
Rect r(x, y, drawW, drawH);
graphics.DrawImage(drawBitmap, r, 0, 0, drawW, drawH, UnitPixel, &imgAttr);
}
else if (m_PreserveAspectRatio)
{
@ -277,10 +282,74 @@ bool CMeterImage::Draw(Graphics& graphics)
x += (m_W - drawW) / 2;
y += (m_H - drawH) / 2;
}
}
Rect r(x, y, drawW, drawH);
graphics.DrawImage(drawBitmap, r, 0, 0, imageW, imageH, UnitPixel, (useImgAttr) ? &imgAttr : NULL);
Rect r(x, y, drawW, drawH);
graphics.DrawImage(drawBitmap, r, 0, 0, imageW, imageH, UnitPixel);
}
else
{
const RECT m = m_ScaleMargins;
if (m.top > 0)
{
if (m.left > 0)
{
// Top-Left
Rect r(x, y, m.left, m.top);
graphics.DrawImage(drawBitmap, r, 0, 0, m.left, m.top, UnitPixel);
}
// Top
Rect r(x + m.left, y, drawW - m.left - m.right, m.top);
graphics.DrawImage(drawBitmap, r, m.left, 0, imageW - m.left - m.right, m.top, UnitPixel);
if (m.right > 0)
{
// Top-Right
Rect r(x + drawW - m.right, y, m.right, m.top);
graphics.DrawImage(drawBitmap, r, imageW - m.right, 0, m.right, m.top, UnitPixel);
}
}
if (m.left > 0)
{
// Left
Rect r(x, y + m.top, m.left, drawH - m.top - m.bottom);
graphics.DrawImage(drawBitmap, r, 0, m.top, m.left, imageH - m.top - m.bottom, UnitPixel);
}
// Center
Rect r(x + m.left, y + m.top, drawW - m.left - m.right, drawH - m.top - m.bottom);
graphics.DrawImage(drawBitmap, r, m.left, m.top, imageW - m.left - m.right, imageH - m.top - m.bottom, UnitPixel);
if (m.right > 0)
{
// Right
Rect r(x + drawW - m.right, y + m.top, m.right, drawH - m.top - m.bottom);
graphics.DrawImage(drawBitmap, r, imageW - m.right, m.top, m.right, imageH - m.top - m.bottom, UnitPixel);
}
if (m.bottom > 0)
{
if (m.left > 0)
{
// Bottom-Left
Rect r(x, y + drawH - m.bottom, m.left, m.bottom);
graphics.DrawImage(drawBitmap, r, 0, imageH - m.bottom, m.left, m.bottom, UnitPixel);
}
// Bottom
Rect r(x + m.left, y + drawH - m.bottom, drawW - m.left - m.right, m.bottom);
graphics.DrawImage(drawBitmap, r, m.left, imageH - m.bottom, imageW - m.left - m.right, m.bottom, UnitPixel);
if (m.right > 0)
{
// Bottom-Right
Rect r(x + drawW - m.right, y + drawH - m.bottom, m.right, m.bottom);
graphics.DrawImage(drawBitmap, r, imageW - m.right, imageH - m.bottom, m.right, m.bottom, UnitPixel);
}
}
}
}
return true;

View File

@ -49,6 +49,8 @@ protected:
bool m_PreserveAspectRatio; // If true, aspect ratio of the image is preserved when the image is scaled
bool m_Tile;
RECT m_ScaleMargins;
std::vector<std::wstring> m_MeasureNames;
std::vector<CMeasure*> m_Measures;
};

View File

@ -883,24 +883,29 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
case BANG_PLUGIN:
{
std::wstring args = arg;
std::wstring measure = arg;
size_t pos = std::wstring::npos;
std::wstring measure;
std::wstring::size_type pos3;
do
{
pos = args.find('\"');
if (pos != std::wstring::npos)
pos3 = args.find(L'\"');
if (pos3 != std::wstring::npos)
{
args.erase(pos, 1);
args.erase(pos3, 1);
}
} while(pos != std::wstring::npos);
} while(pos3 != std::wstring::npos);
pos = args.find(' ');
if (pos != std::wstring::npos)
pos3 = args.find(L' ');
if (pos3 != std::wstring::npos)
{
measure = args.substr(0, pos);
args.erase(0, pos + 1);
measure = args.substr(0, pos3);
++pos3;
}
else
{
measure = args;
}
args.erase(0, pos3);
if (!measure.empty())
{
@ -2158,7 +2163,7 @@ bool CMeterWindow::ResizeWindow(bool reset)
if (m_BackgroundMode == BGMODE_SCALED_IMAGE)
{
const RECT& m = m_BackgroundMargins;
const RECT m = m_BackgroundMargins;
if (m.top > 0)
{