///////////////////////////////////////////////////////////////////////////////////////// // 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); } }
///////////////////////////////////////////////////////////////////////////////////////// // ThemedSkin::draw const //! Draws a standard checkbox control //! //! \param[in,out] &chk - CheckBox to be drawn //! \param[in,out] &dc - Output device context //! \param[in] const &rc - Drawing rectangle ///////////////////////////////////////////////////////////////////////////////////////// void draw(CheckBox<ENC>& chk, DeviceContext& dc, const RectL& rc) const override { Theme theme(chk.handle(), L"Button"); // Determine state CHECKBOXSTATES state = CBS_UNCHECKEDNORMAL; if (!chk.Enabled) state = CBS_UNCHECKEDDISABLED; else if (chk.Check == ButtonState::Checked) //else if (args.State && OwnerDrawState::Selected) state = CBS_UNCHECKEDPRESSED; else if (chk.isMouseOver()) state = CBS_UNCHECKEDHOT; //if (chk.Checked == ButtonState::Checked) //if (args.State && OwnerDrawState::Checked) // state += (CBS_CHECKEDNORMAL-1); //if (chk.State && ButtonState::Checked) // state += (CBS_CHECKEDNORMAL-1); //else if (chk.Checked == ButtonState::Indeterminate) // state += (CBS_MIXEDNORMAL-1); // Query content rect RectL rcContent = theme.content(dc, BP_CHECKBOX, state, rc); // Draw background dc.fill(rc, StockBrush::ButtonFace); // Calculate checkbox / text rectangles SizeL szCheckBox = theme.measure(dc, BP_CHECKBOX, state); RectL rcCheckBox = rcContent.arrange(szCheckBox, {RectL::FromLeft,Metrics::WindowEdge.Width}, RectL::Centre); // Draw checkbox theme.fill(dc, BP_CHECKBOX, state, rcCheckBox); // Draw text rcContent.Left = rcCheckBox.Right + Metrics::WindowEdge.Width; theme.write(dc, BP_CHECKBOX, state, chk.Text(), rcContent, DrawTextFlags::Left|DrawTextFlags::VCentre|DrawTextFlags::SingleLine); // [FOCUS] Draw focus rectangle if (chk.Focus) //if (args.State && OwnerDrawState::Focus) { RectL rcText = theme.measure(dc, BP_CHECKBOX, state, chk.Text(), rcContent, DrawTextFlags::Left|DrawTextFlags::VCentre|DrawTextFlags::SingleLine); dc.focus(rcText); } }