本文整理汇总了C++中gfx::Canvas::DrawBitmap方法的典型用法代码示例。如果您正苦于以下问题:C++ Canvas::DrawBitmap方法的具体用法?C++ Canvas::DrawBitmap怎么用?C++ Canvas::DrawBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gfx::Canvas
的用法示例。
在下文中一共展示了Canvas::DrawBitmap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
/*
** Draws the meter on the double buffer
**
*/
bool MeterButton::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;
const auto image = m_Image.GetImage();
D2D1_RECT_F meterRect = GetMeterRectPadding();
if (image)
{
canvas.DrawBitmap(
image,
D2D1::RectF(
meterRect.left,
meterRect.top,
meterRect.left + (FLOAT)m_W,
meterRect.top + (FLOAT)m_H),
m_BitmapsRects[m_State]);
}
return true;
}
示例2: Draw
/*
** Draws the meter on the double buffer
**
*/
bool MeterImage::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;
if (m_Image.IsLoaded())
{
// Copy the image over the doublebuffer
Bitmap* drawBitmap = m_Image.GetImage();
int imageW = drawBitmap->GetWidth();
int imageH = drawBitmap->GetHeight();
if (imageW == 0 || imageH == 0 || m_W == 0 || m_H == 0) return true;
int x = GetX();
int y = GetY();
int drawW = m_W;
int drawH = m_H;
if (drawW == imageW && drawH == imageH &&
m_ScaleMargins.left == 0 && m_ScaleMargins.top == 0 && m_ScaleMargins.right == 0 && m_ScaleMargins.bottom == 0)
{
canvas.DrawBitmap(drawBitmap, Rect(x, y, drawW, drawH), Rect(0, 0, imageW, imageH));
}
else if (m_DrawMode == DRAWMODE_TILE)
{
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
ImageAttributes imgAttr;
imgAttr.SetWrapMode(WrapModeTile);
Rect r(x, y, drawW, drawH);
graphics.DrawImage(drawBitmap, r, 0, 0, drawW, drawH, UnitPixel, &imgAttr);
canvas.EndGdiplusContext();
}
else if (m_DrawMode == DRAWMODE_KEEPRATIO || m_DrawMode == DRAWMODE_KEEPRATIOANDCROP)
{
int cropX = 0;
int cropY = 0;
int cropW = imageW;
int cropH = imageH;
if (m_WDefined && m_HDefined)
{
REAL imageRatio = imageW / (REAL)imageH;
REAL meterRatio = m_W / (REAL)m_H;
if (imageRatio != meterRatio)
{
if (m_DrawMode == DRAWMODE_KEEPRATIO)
{
if (imageRatio > meterRatio)
{
drawH = m_W * imageH / imageW;
y += (m_H - drawH) / 2;
}
else
{
drawW = m_H * imageW / imageH;
x += (m_W - drawW) / 2;
}
}
else
{
if (imageRatio > meterRatio)
{
cropW = (int)(imageH * meterRatio);
cropX = (imageW - cropW) / 2;
}
else
{
cropH = (int)(imageW / meterRatio);
cropY = (imageH - cropH) / 2;
}
}
}
}
Rect r(x, y, drawW, drawH);
canvas.DrawBitmap(drawBitmap, r, Rect(cropX, cropY, cropW, cropH));
}
else
{
const RECT& m = m_ScaleMargins;
if (m.top > 0)
{
if (m.left > 0)
{
// Top-Left
Rect r(x, y, m.left, m.top);
canvas.DrawBitmap(drawBitmap, r, Rect(0, 0, m.left, m.top));
}
//.........这里部分代码省略.........
示例3: Draw
//.........这里部分代码省略.........
int diffTicks = (int)(System::GetTickCount64() - m_TransitionStartTicks);
int range = ((value % realFrames) - (transitionValue % realFrames)) * (m_TransitionFrameCount + 1);
if (range < 0)
{
range += m_FrameCount;
}
int frameAdjustment = range * diffTicks / ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate());
if (frameAdjustment > range)
{
m_TransitionStartTicks = 0; // The transition is over. Draw with the real value.
}
else
{
frame = (transitionValue % realFrames) * (m_TransitionFrameCount + 1);
frame += frameAdjustment;
frame %= m_FrameCount;
}
}
// LogDebugF(L"[%u] Value: %f Frame: %i (Transition = %s)", GetTickCount(), m_Value, frame, m_TransitionStartTicks > 0 ? L"true" : L"false");
if (bitmap->GetHeight() > bitmap->GetWidth())
{
newX = 0;
newY = m_H * frame;
}
else
{
newX = m_W * frame;
newY = 0;
}
canvas.DrawBitmap(bitmap, Rect(x + offset, y, m_W, m_H), Rect(newX, newY, m_W, m_H));
if (m_FrameCount == 1)
{
value /= 2;
transitionValue /= 2;
}
else
{
value /= realFrames;
transitionValue /= realFrames;
}
--numOfNums;
}
while (numOfNums > 0);
}
else
{
int frame = 0;
int realFrames = (m_FrameCount / (m_TransitionFrameCount + 1));
if (m_ZeroFrame)
{
// Use the first frame only if the value is zero
if (m_Value > 0)
{
frame = (int)(m_Value * (realFrames - 1)) * (m_TransitionFrameCount + 1);
}
}
else
{
// Select the correct frame linearly
frame = (int)(m_Value * realFrames) * (m_TransitionFrameCount + 1);
}
示例4: Draw
/*
** Draws the meter on the double buffer
**
*/
bool MeterBar::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;
const D2D1_RECT_F rect = GetMeterRectPadding();
const FLOAT width = rect.right - rect.left;
const FLOAT height = rect.bottom - rect.top;
const FLOAT border = (FLOAT)m_Border;
Gfx::D2DBitmap* drawBitmap = m_Image.GetImage();
if (m_Orientation == VERTICAL)
{
const FLOAT barSize = height - 2.0f * border;
FLOAT size = barSize * (FLOAT)m_Value;
size = min(barSize, size);
size = max(0.0f, size);
if (drawBitmap)
{
if (m_Flip)
{
if (border > 0.0f)
{
const auto d = Gfx::Util::ToRectF(rect.left, rect.top, width, border);
const auto s = Gfx::Util::ToRectF(0.0f, 0.0f, width, border);
canvas.DrawBitmap(drawBitmap, d, s);
const auto d2 = Gfx::Util::ToRectF(rect.left, rect.top + size + border, width, border);
const auto s2 = Gfx::Util::ToRectF(0.0f, height - border, width, border);
canvas.DrawBitmap(drawBitmap, d2, s2);
}
const auto d = Gfx::Util::ToRectF(rect.left, rect.top + border, width, size);
const auto s = Gfx::Util::ToRectF(0.0f, border, width, size);
canvas.DrawBitmap(drawBitmap, d, s);
}
else
{
if (border > 0.0f)
{
const auto d = Gfx::Util::ToRectF(rect.left, rect.bottom - size - 2.0f * border, width, border);
const auto s = Gfx::Util::ToRectF(0.0f, 0.0f, width, border);
canvas.DrawBitmap(drawBitmap, d, s);
const auto d2 = Gfx::Util::ToRectF(rect.left, rect.bottom - border, width, border);
const auto s2 = Gfx::Util::ToRectF(0.0f, height - border, width, border);
canvas.DrawBitmap(drawBitmap, d2, s2);
}
const auto d = Gfx::Util::ToRectF(rect.left, rect.bottom - size - border, width, size);
const auto s = Gfx::Util::ToRectF(0.0f, height - size - border, width, size);
canvas.DrawBitmap(drawBitmap, d, s);
}
}
else
{
if (m_Flip)
{
const auto r = Gfx::Util::ToRectF(rect.left, rect.top, width, size);
canvas.FillRectangle(r, m_Color);
}
else
{
const auto r = Gfx::Util::ToRectF(rect.left, rect.bottom - size, width, size);
canvas.FillRectangle(r, m_Color);
}
}
}
else
{
const FLOAT barSize = width - 2.0f * border;
FLOAT size = barSize * (FLOAT)m_Value;
size = min(barSize, size);
size = max(0.0f, size);
if (drawBitmap)
{
if (m_Flip)
{
if (border > 0.0f)
{
const auto d = Gfx::Util::ToRectF(rect.right - size - 2.0f * border, rect.top, border, height);
const auto s = Gfx::Util::ToRectF(0.0f, 0.0f, border, height);
canvas.DrawBitmap(drawBitmap, d, s);
const auto d2 = Gfx::Util::ToRectF(rect.right - border, rect.top, border, height);
const auto s2 = Gfx::Util::ToRectF(width - border, 0.0f, border, height);
canvas.DrawBitmap(drawBitmap, d2, s2);
}
const auto d = Gfx::Util::ToRectF(rect.right - size - border, rect.top, size, height);
const auto s = Gfx::Util::ToRectF(width - size - border, 0.0f, size, height);
canvas.DrawBitmap(drawBitmap, d, s);
}
else
//.........这里部分代码省略.........
示例5: Draw
/*
** Draws the meter on the double buffer
**
*/
bool MeterImage::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;
if (m_Image.IsLoaded())
{
// Copy the image over the doublebuffer
Bitmap* drawBitmap = m_Image.GetImage();
int imageW = drawBitmap->GetWidth();
int imageH = drawBitmap->GetHeight();
if (imageW == 0 || imageH == 0 || m_W == 0 || m_H == 0) return true;
Gdiplus::Rect meterRect = GetMeterRectPadding();
int drawW = meterRect.Width;
int drawH = meterRect.Height;
bool hasMask = (m_Skin->GetUseD2D() && m_MaskImage.IsLoaded());
if (hasMask)
{
Bitmap* maskBitmap = m_MaskImage.GetImage();
imageW = maskBitmap->GetWidth();
imageH = maskBitmap->GetHeight();
int imageMW = drawBitmap->GetWidth();
int imageMH = drawBitmap->GetHeight();
int cropX = 0;
int cropY = 0;
int cropW = imageMW;
int cropH = imageMH;
REAL imageratio = imageMW / (REAL)imageMH;
REAL meterRatio = meterRect.Width / (REAL)meterRect.Height;
if (imageratio != meterRatio)
{
if (imageratio > meterRatio)
{
cropW = (int)(imageMH * meterRatio);
cropX = (imageMW - cropW) / 2;
}
else
{
cropH = (int)(imageMW / meterRatio);
cropY = (imageMH - cropH) / 2;
}
}
canvas.DrawMaskedBitmap(drawBitmap, maskBitmap, meterRect, Rect(0, 0, imageW, imageH), Gdiplus::Rect(cropX, cropY, cropW, cropH));
}
else if (drawW == imageW && drawH == imageH &&
m_ScaleMargins.left == 0 && m_ScaleMargins.top == 0 && m_ScaleMargins.right == 0 && m_ScaleMargins.bottom == 0)
{
canvas.DrawBitmap(drawBitmap, Rect(meterRect.X, meterRect.Y, drawW, drawH), Rect(0, 0, imageW, imageH));
}
else if (m_DrawMode == DRAWMODE_TILE)
{
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
ImageAttributes imgAttr;
imgAttr.SetWrapMode(WrapModeTile);
Rect r(meterRect.X, meterRect.Y, drawW, drawH);
graphics.DrawImage(drawBitmap, r, 0, 0, drawW, drawH, UnitPixel, &imgAttr);
canvas.EndGdiplusContext();
}
else if (m_DrawMode == DRAWMODE_KEEPRATIO || m_DrawMode == DRAWMODE_KEEPRATIOANDCROP)
{
int cropX = 0;
int cropY = 0;
int cropW = imageW;
int cropH = imageH;
if (m_WDefined && m_HDefined)
{
REAL imageRatio = imageW / (REAL)imageH;
REAL meterRatio = meterRect.Width / (REAL)meterRect.Height;
if (imageRatio != meterRatio)
{
if (m_DrawMode == DRAWMODE_KEEPRATIO)
{
if (imageRatio > meterRatio)
{
drawH = meterRect.Width * imageH / imageW;
meterRect.Y += (meterRect.Height - drawH) / 2;
}
else
{
drawW = meterRect.Height * imageW / imageH;
meterRect.X += (meterRect.Width - drawW) / 2;
//.........这里部分代码省略.........
示例6: Draw
/*
** Draws the meter on the double buffer
**
*/
bool CMeterBar::Draw(Gfx::Canvas& canvas)
{
if (!CMeter::Draw(canvas)) return false;
int x = GetX();
int y = GetY();
Bitmap* drawBitmap = m_Image.GetImage();
if (m_Orientation == VERTICAL)
{
int barSize = m_H - 2 * m_Border;
int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size);
if (drawBitmap)
{
if (m_Flip)
{
if (m_Border > 0)
{
Rect r2(x, y, m_W, m_Border);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_W, m_Border));
r2.Y = y + size + m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(0, m_H - m_Border, m_W, m_Border));
}
Rect r(x, y + m_Border, m_W, size);
canvas.DrawBitmap(drawBitmap, r, Rect(0, m_Border, m_W, size));
}
else
{
if (m_Border > 0)
{
Rect r2(x, y + m_H - size - 2 * m_Border, m_W, m_Border);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_W, m_Border));
r2.Y = y + m_H - m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(0, m_H - m_Border, m_W, m_Border));
}
Rect r(x, y + m_H - size - m_Border, m_W, size);
canvas.DrawBitmap(drawBitmap, r, Rect(0, m_H - size - m_Border, m_W, size));
}
}
else
{
SolidBrush brush(m_Color);
if (m_Flip)
{
Rect r(x, y, m_W, size);
canvas.FillRectangle(r, brush);
}
else
{
Rect r(x, y + m_H - size, m_W, size);
canvas.FillRectangle(r, brush);
}
}
}
else
{
int barSize = m_W - 2 * m_Border;
int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size);
if (drawBitmap)
{
if (m_Flip)
{
if (m_Border > 0)
{
Rect r2(x + m_W - size - 2 * m_Border, y, m_Border, m_H);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_Border, m_H));
r2.X = x + m_W - m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(m_W - m_Border, 0, m_Border, m_H));
}
Rect r(x + m_W - size - m_Border, y, size, m_H);
canvas.DrawBitmap(drawBitmap, r, Rect(m_W - size - m_Border, 0, size, m_H));
}
else
{
if (m_Border > 0)
{
Rect r2(x, y, m_Border, m_H);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_Border, m_H));
r2.X = x + size + m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(m_W - m_Border, 0, m_Border, m_H));
}
Rect r(x + m_Border, y, size, m_H);
canvas.DrawBitmap(drawBitmap, r, Rect(m_Border, 0, size, m_H));
}
}
//.........这里部分代码省略.........