vcl/source/control/button.cxx | 6 +++- vcl/source/window/decoview.cxx | 53 +++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 25 deletions(-)
New commits: commit f61b6a3a23303aff75051bc704375db92ae8f345 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Wed Oct 5 12:47:33 2022 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Wed Oct 5 15:53:08 2022 +0200 Resolves: tdf#151351 rework flat button rendering Change-Id: Idf98c5bb96e5646e25b1ccd70b3774c7de479d18 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140979 Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index 0edb9d9002d1..f9d9408fa3ca 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -976,6 +976,9 @@ void PushButton::ImplDrawPushButton(vcl::RenderContext& rRenderContext) if (mbPressed || mbIsActive) nButtonStyle |= DrawButtonFlags::Pressed; + if (GetStyle() & WB_FLATBUTTON) + nButtonStyle |= DrawButtonFlags::Flat; + // TODO: move this to Window class or make it a member !!! ControlType aCtrlType = ControlType::Generic; switch(GetParent()->GetType()) @@ -1151,8 +1154,7 @@ void PushButton::ImplDrawPushButton(vcl::RenderContext& rRenderContext) if (GetStyle() & WB_FLATBUTTON) { tools::Rectangle aTempRect(aInRect); - if (bRollOver) - ImplDrawPushButtonFrame(rRenderContext, aTempRect, nButtonStyle); + ImplDrawPushButtonFrame(rRenderContext, aTempRect, nButtonStyle); aInRect.AdjustLeft(2 ); aInRect.AdjustTop(2 ); aInRect.AdjustRight( -2 ); diff --git a/vcl/source/window/decoview.cxx b/vcl/source/window/decoview.cxx index 62c60f4e1336..d6bbd2d61982 100644 --- a/vcl/source/window/decoview.cxx +++ b/vcl/source/window/decoview.cxx @@ -23,11 +23,6 @@ #include <vcl/window.hxx> #include <vcl/ctrl.hxx> -constexpr auto BUTTON_DRAW_FLATTEST = DrawButtonFlags::Flat | - DrawButtonFlags::Pressed | - DrawButtonFlags::Checked | - DrawButtonFlags::Highlight; - namespace { tools::Long AdjustRectToSquare( tools::Rectangle &rRect ) @@ -481,6 +476,9 @@ void ImplDrawButton( OutputDevice *const pDev, tools::Rectangle aFillRect, } else { + const bool bFlat(nStyle & DrawButtonFlags::Flat); + const bool bDepressed(nStyle & (DrawButtonFlags::Pressed | DrawButtonFlags::Checked)); + if ( nStyle & DrawButtonFlags::Default ) { const Color aDefBtnColor = rStyleSettings.GetDarkShadowColor(); @@ -495,30 +493,28 @@ void ImplDrawButton( OutputDevice *const pDev, tools::Rectangle aFillRect, aFillRect.AdjustLeft( 1 ); } + bool bNoFace = false; Color aColor1; Color aColor2; - if ( nStyle & (DrawButtonFlags::Pressed | DrawButtonFlags::Checked) ) + if (!bFlat) { - aColor1 = rStyleSettings.GetDarkShadowColor(); - aColor2 = rStyleSettings.GetLightColor(); - } - else - { - if ( nStyle & DrawButtonFlags::NoLightBorder ) - aColor1 = rStyleSettings.GetLightBorderColor(); - else - aColor1 = rStyleSettings.GetLightColor(); - if ( (nStyle & BUTTON_DRAW_FLATTEST) == DrawButtonFlags::Flat ) - aColor2 = rStyleSettings.GetShadowColor(); + if (bDepressed) + { + aColor1 = rStyleSettings.GetDarkShadowColor(); + aColor2 = rStyleSettings.GetLightColor(); + } else + { + if ( nStyle & DrawButtonFlags::NoLightBorder ) + aColor1 = rStyleSettings.GetLightBorderColor(); + else + aColor1 = rStyleSettings.GetLightColor(); aColor2 = rStyleSettings.GetDarkShadowColor(); - } + } - ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 ); + ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 ); - if ( (nStyle & BUTTON_DRAW_FLATTEST) != DrawButtonFlags::Flat ) - { - if ( nStyle & (DrawButtonFlags::Pressed | DrawButtonFlags::Checked) ) + if (bDepressed) { aColor1 = rStyleSettings.GetShadowColor(); aColor2 = rStyleSettings.GetLightBorderColor(); @@ -533,11 +529,22 @@ void ImplDrawButton( OutputDevice *const pDev, tools::Rectangle aFillRect, } ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 ); } + else // flat buttons + { + // draw a border if the flat button is highlighted + if (nStyle & DrawButtonFlags::Highlight) + { + aColor1 = rStyleSettings.GetShadowColor(); + ImplDraw2ColorFrame(pDev, aFillRect, aColor1, aColor1); + } + // fill in the button if it is pressed in + bNoFace = !bDepressed; + } pDev->SetLineColor(); if ( nStyle & (DrawButtonFlags::Checked | DrawButtonFlags::DontKnow) ) pDev->SetFillColor( rStyleSettings.GetCheckedColor() ); - else + else if (!bNoFace) pDev->SetFillColor( rStyleSettings.GetFaceColor() ); pDev->DrawRect( aFillRect ); }