///////////////////////////////////////////////////////////////////////////////////////// // 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); } }
DeviceCompatibleBitmap::DeviceCompatibleBitmap ( const DeviceContext& context, const Size& size ) : Bitmap(claim(::create(context.handle(), size.data()))) { }