diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2012-02-07 08:42:03 -0500 |
|---|---|---|
| committer | Tarmac <> | 2012-02-07 08:42:03 -0500 |
| commit | 8e738ebe857d06b11dde25003a93f850034f6f59 (patch) | |
| tree | 6c5dd36c9ea471cc67224e09a9b93f6bf8299fa8 | |
| parent | d3be0faa52e9f5498543df07c2e16fb60e5701e5 (diff) | |
| parent | 5d389fb18d36b15d0734d8c467537fd23ec19e85 (diff) | |
Implement the focus state for the filters label buttons.
For the momement you cannot directly test because in trunk the filter bar is not key navigable. You can test it changing: 139 + if (HasKeyboardFocus()) with 139 + if (IsMouseInside()) I've a branch for filters key navigation too, but the visual design is not ready... Mockup - https://chinstrap.canonical.com/~sabdfl/12_04/desktop_and_netbook/dash/video_lens_v1.2_2.png Branch - http://ubuntuone.com/4CwCQGcAuejfjQAY4Ky7Ry http://ubuntuone.com/3vHehMXz1KoBWKQ2uugZzL. Fixes: . Approved by Marco Trevisan (Treviño), Andrea Cimitan. (bzr r1909)
| -rw-r--r-- | plugins/unityshell/src/DashStyle.cpp | 33 | ||||
| -rw-r--r-- | plugins/unityshell/src/DashStyle.h | 2 | ||||
| -rw-r--r-- | plugins/unityshell/src/FilterBasicButton.cpp | 19 | ||||
| -rw-r--r-- | plugins/unityshell/src/FilterBasicButton.h | 3 |
4 files changed, 57 insertions, 0 deletions
diff --git a/plugins/unityshell/src/DashStyle.cpp b/plugins/unityshell/src/DashStyle.cpp index a3f39c585..c1fa30863 100644 --- a/plugins/unityshell/src/DashStyle.cpp +++ b/plugins/unityshell/src/DashStyle.cpp @@ -1720,6 +1720,39 @@ bool Style::SquareButton(cairo_t* cr, nux::ButtonVisualState state, return true; } +bool Style::ButtonFocusOverlay(cairo_t* cr) +{ + // sanity checks + if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) + return false; + + if (cairo_surface_get_type(cairo_get_target(cr)) != CAIRO_SURFACE_TYPE_IMAGE) + return false; + + unsigned int garnish = GetButtonGarnishSize(); + + double w = cairo_image_surface_get_width(cairo_get_target(cr)); + double h = cairo_image_surface_get_height(cairo_get_target(cr)); + + nux::Color color(nux::color::White); + color.alpha = 0.50f; + cairo_set_line_width(cr, pimpl->button_label_border_size_[nux::VISUAL_STATE_NORMAL]); + + RoundedRect(cr, + 1.0, + (double) (garnish), + (double) (garnish), + 7.0, + w - (double) (2 * garnish), + h - (double) (2 * garnish)); + + cairo_set_source_rgba(cr, color); + cairo_fill_preserve(cr); + cairo_stroke(cr); + + return true; +} + bool Style::StarEmpty(cairo_t* cr, nux::ButtonVisualState state) { // sanity checks diff --git a/plugins/unityshell/src/DashStyle.h b/plugins/unityshell/src/DashStyle.h index ba10f7c9d..93b165171 100644 --- a/plugins/unityshell/src/DashStyle.h +++ b/plugins/unityshell/src/DashStyle.h @@ -97,6 +97,8 @@ public: Alignment alignment = Alignment::CENTER, bool zeromargin=false); + virtual bool ButtonFocusOverlay(cairo_t* cr); + virtual bool StarEmpty(cairo_t* cr, nux::ButtonVisualState state); virtual bool StarHalf(cairo_t* cr, nux::ButtonVisualState state); diff --git a/plugins/unityshell/src/FilterBasicButton.cpp b/plugins/unityshell/src/FilterBasicButton.cpp index e75cdff11..aef95a990 100644 --- a/plugins/unityshell/src/FilterBasicButton.cpp +++ b/plugins/unityshell/src/FilterBasicButton.cpp @@ -65,6 +65,7 @@ FilterBasicButton::~FilterBasicButton() void FilterBasicButton::Init() { + InitTheme(); SetAcceptKeyNavFocusOnMouseDown(false); } @@ -78,6 +79,7 @@ void FilterBasicButton::InitTheme() prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT))); active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED))); normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL))); + focus_.reset(new nux::CairoWrapper(geo, sigc::mem_fun(this, &FilterBasicButton::RedrawFocusOverlay))); } SetMinimumHeight(kMinButtonHeight); @@ -89,6 +91,11 @@ void FilterBasicButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux: Style::Instance().Button(cr, faked_state, label_); } +void FilterBasicButton::RedrawFocusOverlay(nux::Geometry const& geom, cairo_t* cr) +{ + Style::Instance().ButtonFocusOverlay(cr); +} + long FilterBasicButton::ComputeContentSize() { long ret = nux::Button::ComputeContentSize(); @@ -100,6 +107,7 @@ long FilterBasicButton::ComputeContentSize() prelight_->Invalidate(geo); active_->Invalidate(geo); normal_->Invalidate(geo); + focus_->Invalidate(geo); cached_geometry_ = geo; } @@ -146,6 +154,17 @@ void FilterBasicButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) texxform, nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); + if (HasKeyboardFocus()) + { + GfxContext.QRP_1Tex(geo.x, + geo.y, + geo.width, + geo.height, + focus_->GetTexture()->GetDeviceTexture(), + texxform, + nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); + } + GfxContext.GetRenderStates().SetBlend(alpha, src, dest); } diff --git a/plugins/unityshell/src/FilterBasicButton.h b/plugins/unityshell/src/FilterBasicButton.h index 4de0e7292..7ee115b7f 100644 --- a/plugins/unityshell/src/FilterBasicButton.h +++ b/plugins/unityshell/src/FilterBasicButton.h @@ -49,12 +49,15 @@ protected: void Init(); void InitTheme(); void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state); + void RedrawFocusOverlay(nux::Geometry const& geom, cairo_t* cr); typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr; NuxCairoPtr prelight_; NuxCairoPtr active_; NuxCairoPtr normal_; + NuxCairoPtr focus_; + nux::Geometry cached_geometry_; private: |
