Back to index

unity  6.0.0
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
unity::dash::FilterRatingsButton Class Reference

#include <FilterRatingsButton.h>

List of all members.

Public Member Functions

 FilterRatingsButton (NUX_FILE_LINE_PROTO)
virtual ~FilterRatingsButton ()
void SetFilter (Filter::Ptr const &filter)
RatingsFilter::Ptr GetFilter ()
std::string GetFilterType ()

Protected Member Functions

virtual void Draw (nux::GraphicsEngine &GfxContext, bool force_draw)
virtual bool AcceptKeyNavFocus ()
virtual bool InspectKeyEvent (unsigned int eventType, unsigned int keysym, const char *character)

Private Member Functions

void OnKeyDown (unsigned long event_type, unsigned long event_keysym, unsigned long event_state, const TCHAR *character, unsigned short key_repeat_count)
void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
void RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
void OnRatingsChanged (int rating)

Private Attributes

dash::RatingsFilter::Ptr filter_
int focused_star_

Detailed Description

Definition at line 37 of file FilterRatingsButton.h.


Constructor & Destructor Documentation

Definition at line 41 of file FilterRatingsButton.cpp.

  : nux::ToggleButton(NUX_FILE_LINE_PARAM)
  , focused_star_(-1)
{
  SetAcceptKeyNavFocusOnMouseDown(false);
  SetAcceptKeyNavFocusOnMouseEnter(true);

  mouse_up.connect(sigc::mem_fun(this, &FilterRatingsButton::RecvMouseUp));
  mouse_move.connect(sigc::mem_fun(this, &FilterRatingsButton::RecvMouseMove));
  mouse_drag.connect(sigc::mem_fun(this, &FilterRatingsButton::RecvMouseDrag));

  key_nav_focus_change.connect([&](nux::Area* area, bool has_focus, nux::KeyNavDirection direction)
  {
    if (has_focus && direction != nux::KEY_NAV_NONE)
      focused_star_ = 0;
    else if (!has_focus)
      focused_star_ = -1;

    QueueDraw();
  });
  key_nav_focus_activate.connect([&](nux::Area*) { filter_->rating = static_cast<float>(focused_star_+1)/num_stars; });
  key_down.connect(sigc::mem_fun(this, &FilterRatingsButton::OnKeyDown));
}

Here is the call graph for this function:

Definition at line 65 of file FilterRatingsButton.cpp.

{
}

Member Function Documentation

Definition at line 260 of file FilterRatingsButton.cpp.

{
  return true;
}
void unity::dash::FilterRatingsButton::Draw ( nux::GraphicsEngine &  GfxContext,
bool  force_draw 
) [protected, virtual]

Definition at line 81 of file FilterRatingsButton.cpp.

{
  int rating = 0;
  if (filter_ && filter_->filtering)
    rating = static_cast<int>(filter_->rating * num_stars);
  // FIXME: 9/26/2011
  // We should probably support an API for saying whether the ratings
  // should or shouldn't support half stars...but our only consumer at
  // the moment is the applications lens which according to design
  // (Bug #839759) shouldn't. So for now just force rounding.
  //    int total_half_stars = rating % 2;
  //    int total_full_stars = rating / 2;
  int total_full_stars = rating;

  nux::Geometry const& geo = GetGeometry();
  nux::Geometry geo_star(geo);
  geo_star.width = star_size;

  gPainter.PaintBackground(GfxContext, geo);
  // set up our texture mode
  nux::TexCoordXForm texxform;
  texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
  texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);

  // clear what is behind us
  unsigned int alpha = 0, src = 0, dest = 0;

  GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
  GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

  nux::Color col = nux::color::Black;
  col.alpha = 0;
  GfxContext.QRP_Color(geo.x,
                       geo.y,
                       geo.width,
                       geo.height,
                       col);

  for (int index = 0; index < num_stars; ++index)
  {
       Style& style = Style::Instance();
    nux::BaseTexture* texture = style.GetStarSelectedIcon();
    if (index < total_full_stars)
    {
      if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
        texture = style.GetStarSelectedIcon();
      else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
        texture = style.GetStarSelectedIcon();
      else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
        texture = style.GetStarSelectedIcon();
    }
    else
    {
      if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
        texture = style.GetStarDeselectedIcon();
      else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
        texture = style.GetStarDeselectedIcon();
      else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
        texture = style.GetStarDeselectedIcon();
    }

    GfxContext.QRP_1Tex(geo_star.x,
                        geo_star.y,
                        geo_star.width,
                        geo_star.height,
                        texture->GetDeviceTexture(),
                        texxform,
                        nux::Color(1.0f, 1.0f, 1.0f, 1.0f));

    if (focused_star_ == index)
    {
      GfxContext.QRP_1Tex(geo_star.x,
                          geo_star.y,
                          geo_star.width,
                          geo_star.height,
                          style.GetStarHighlightIcon()->GetDeviceTexture(),
                          texxform,
                          nux::Color(1.0f, 1.0f, 1.0f, 0.5f));
    }

    geo_star.x += geo_star.width + star_gap;

  }

  GfxContext.GetRenderStates().SetBlend(alpha, src, dest);

}

Here is the call graph for this function:

Definition at line 76 of file FilterRatingsButton.cpp.

{
  return "FilterRatingsButton";
}
bool unity::dash::FilterRatingsButton::InspectKeyEvent ( unsigned int  eventType,
unsigned int  keysym,
const char *  character 
) [protected, virtual]

Definition at line 213 of file FilterRatingsButton.cpp.

{
  nux::KeyNavDirection direction = nux::KEY_NAV_NONE;

  switch (keysym)
  {
    case NUX_VK_LEFT:
      direction = nux::KeyNavDirection::KEY_NAV_LEFT;
      break;
    case NUX_VK_RIGHT:
      direction = nux::KeyNavDirection::KEY_NAV_RIGHT;
      break;
    default:
      direction = nux::KeyNavDirection::KEY_NAV_NONE;
      break;
  }

  if (direction == nux::KeyNavDirection::KEY_NAV_NONE)
    return false;
  else if (direction == nux::KEY_NAV_LEFT && (focused_star_ <= 0))
    return false;
  else if (direction == nux::KEY_NAV_RIGHT && (focused_star_ >= num_stars - 1))
    return false;
  else
   return true;
}
void unity::dash::FilterRatingsButton::OnKeyDown ( unsigned long  event_type,
unsigned long  event_keysym,
unsigned long  event_state,
const TCHAR *  character,
unsigned short  key_repeat_count 
) [private]

Definition at line 241 of file FilterRatingsButton.cpp.

{
  switch (event_keysym)
  {
    case NUX_VK_LEFT:
      --focused_star_;
      break;
    case NUX_VK_RIGHT:
      ++focused_star_;
      break;
    default:
      return;
  }

  QueueDraw();
}

Here is the caller graph for this function:

Definition at line 194 of file FilterRatingsButton.cpp.

{
  NeedRedraw();
}

Here is the caller graph for this function:

void unity::dash::FilterRatingsButton::RecvMouseDrag ( int  x,
int  y,
int  dx,
int  dy,
unsigned long  button_flags,
unsigned long  key_flags 
) [private]

Definition at line 187 of file FilterRatingsButton.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::FilterRatingsButton::RecvMouseMove ( int  x,
int  y,
int  dx,
int  dy,
unsigned long  button_flags,
unsigned long  key_flags 
) [private]

Definition at line 199 of file FilterRatingsButton.cpp.

{
  int width = 180;
  focused_star_ = std::max(0, std::min(static_cast<int>(ceil((static_cast<float>(x) / width) * num_stars) - 1), num_stars - 1));

  if (!HasKeyFocus())
    nux::GetWindowCompositor().SetKeyFocusArea(this);

  QueueDraw();
}

Here is the caller graph for this function:

void unity::dash::FilterRatingsButton::RecvMouseUp ( int  x,
int  y,
unsigned long  button_flags,
unsigned long  key_flags 
) [private]

Definition at line 182 of file FilterRatingsButton.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 69 of file FilterRatingsButton.cpp.

{
  filter_ = std::static_pointer_cast<RatingsFilter>(filter);
  filter_->rating.changed.connect(sigc::mem_fun(this, &FilterRatingsButton::OnRatingsChanged));
  NeedRedraw();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 64 of file FilterRatingsButton.h.

Definition at line 65 of file FilterRatingsButton.h.


The documentation for this class was generated from the following files: