本文整理汇总了C++中DeviceContext::draw方法的典型用法代码示例。如果您正苦于以下问题:C++ DeviceContext::draw方法的具体用法?C++ DeviceContext::draw怎么用?C++ DeviceContext::draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeviceContext
的用法示例。
在下文中一共展示了DeviceContext::draw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
/////////////////////////////////////////////////////////////////////////////////////////
// ThemedSkin::draw const
//! Draws a standard button control
//!
//! \param[in,out] &btn - Button to be drawn
//! \param[in,out] &dc - Output device context
//! \param[in] const &rc - Drawing rectangle
/////////////////////////////////////////////////////////////////////////////////////////
void draw(Button<ENC>& btn, DeviceContext& dc, const RectL& rc) const override
{
Theme theme(btn.handle(), L"Button");
// Determine state
::PUSHBUTTONSTATES state = PBS_NORMAL;
if (!btn.Enabled)
state = PBS_DISABLED;
else if (btn.State == ButtonState::Pushed) //else if (args.State && OwnerDrawState::Selected)
state = PBS_PRESSED;
else if (btn.isMouseOver())
state = PBS_HOT;
// Draw background
theme.fill(dc, BP_PUSHBUTTON, state, rc);
// Query content rect
RectL rcContent = theme.content(dc, BP_CHECKBOX, state, rc);
// Pressed: Offset drawing rect
if (state == PBS_PRESSED)
rcContent += PointL(1,1);
// Draw icon
if (btn.Icon.exists())
{
RectL rcIcon = rcContent.arrange(Metrics::WindowIcon, {RectL::FromLeft,Metrics::WindowEdge.Width}, RectL::Centre);
dc.draw(btn.Icon, rcIcon);
}
// Calculate text rectangle
RectL rcText = rcContent;
if (btn.Icon.exists())
rcText.Left += Metrics::WindowIcon.Width + Metrics::WindowEdge.Width;
// Draw text
if (state != PBS_DISABLED)
theme.write(dc, BP_PUSHBUTTON, state, btn.Text(), rcText, DrawTextFlags::Centre|DrawTextFlags::VCentre|DrawTextFlags::SingleLine);
else
{
const auto grayString = choose<ENC>(::GrayStringA,::GrayStringW);
grayString(dc.handle(), StockBrush::AppWorkspace, nullptr, (LPARAM)btn.Text().c_str(), btn.Text().size(), rcText.Left, rcText.Top, rcText.width(), rcText.height());
}
// [FOCUS] Draw focus rectangle
if (btn.Focus)
{
RectL rcFocus = rcContent.inflate(-Metrics::WindowEdge);
dc.focus(rcFocus);
}
}