Back to index

unity  6.0.0
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
unity::hud::HudButton Class Reference

#include <HudButton.h>

Inheritance diagram for unity::hud::HudButton:
Inheritance graph
[legend]
Collaboration diagram for unity::hud::HudButton:
Collaboration graph
[legend]

List of all members.

Public Types

typedef nux::ObjectPtr< HudButtonPtr
typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 HudButton (NUX_FILE_LINE_PROTO)
void SetQuery (Query::Ptr query)
std::shared_ptr< QueryGetQuery ()
void SetSkipDraw (bool skip_draw)
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Public Attributes

nux::Property< std::string > label
nux::Property< bool > is_rounded
nux::Property< bool > fake_focused

Protected Member Functions

virtual bool AcceptKeyNavFocus ()
virtual long ComputeContentSize ()
virtual void Draw (nux::GraphicsEngine &GfxContext, bool force_draw)
virtual void DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw)
std::string GetName () const
void AddProperties (GVariantBuilder *builder)
void InitTheme ()
void RedrawTheme (nux::Geometry const &geom, cairo_t *cr, nux::ButtonVisualState faked_state)
virtual std::string GetChildsName () const
 Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Private Types

typedef std::unique_ptr
< nux::CairoWrapper > 
NuxCairoPtr

Private Member Functions

 NUX_DECLARE_OBJECT_TYPE (HudButton, nux::Button)

Private Attributes

Query::Ptr query_
nux::Geometry cached_geometry_
bool is_focused_
bool skip_draw_
NuxCairoPtr prelight_
NuxCairoPtr active_
NuxCairoPtr normal_
nux::HLayout * hlayout_

Detailed Description

Definition at line 39 of file HudButton.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.

typedef std::unique_ptr<nux::CairoWrapper> unity::hud::HudButton::NuxCairoPtr [private]

Definition at line 70 of file HudButton.h.

typedef nux::ObjectPtr<HudButton> unity::hud::HudButton::Ptr

Definition at line 44 of file HudButton.h.


Constructor & Destructor Documentation

unity::hud::HudButton::HudButton ( NUX_FILE_LINE_PROTO  )

Definition at line 57 of file HudButton.cpp.

  : nux::Button(NUX_FILE_LINE_PARAM)
  , is_rounded(false)
  , is_focused_(false)
  , skip_draw_(true)
{
  hlayout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
  hlayout_->SetLeftAndRightPadding(hlayout_left_padding, -1);
  SetLayout(hlayout_);

  InitTheme();

  key_nav_focus_change.connect([&](nux::Area*, bool, nux::KeyNavDirection)
  {
    QueueDraw();
  });

  fake_focused.changed.connect([&](bool)
  {
    QueueDraw();
  });
}

Here is the call graph for this function:


Member Function Documentation

bool unity::hud::HudButton::AcceptKeyNavFocus ( ) [protected, virtual]

Definition at line 109 of file HudButton.cpp.

{
  // The button will not receive the keyboard focus. The keyboard focus is always to remain with the
  // text entry in the hud.
  return false;
}

Definition at line 78 of file Introspectable.cpp.

{
  _children.push_back(child);
  child->_parents.push_back(this);
}

Here is the caller graph for this function:

void unity::hud::HudButton::AddProperties ( GVariantBuilder *  builder) [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 231 of file HudButton.cpp.

{
  variant::BuilderWrapper(builder)
    .add("label", label())
    .add("focused", fake_focused());
}

Here is the call graph for this function:

long unity::hud::HudButton::ComputeContentSize ( ) [protected, virtual]

Definition at line 117 of file HudButton.cpp.

{
  long ret = nux::Button::ComputeContentSize();
  nux::Geometry const& geo = GetGeometry();

  if (cached_geometry_ != geo)
  {
    prelight_->Invalidate(geo);
    active_->Invalidate(geo);
    normal_->Invalidate(geo);

    cached_geometry_ = geo;
  }

  return ret;
}
void unity::hud::HudButton::Draw ( nux::GraphicsEngine &  GfxContext,
bool  force_draw 
) [protected, virtual]

Definition at line 134 of file HudButton.cpp.

{
  if (skip_draw_)
    return;

  nux::Geometry const& geo = GetGeometry();
  GfxContext.PushClippingRectangle(geo);
  gPainter.PaintBackground(GfxContext, geo);

  // set up our texture mode
  nux::TexCoordXForm texxform;
  texxform.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
  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().SetPremultipliedBlend(nux::SRC_OVER);
  GfxContext.GetRenderStates().SetBlend(true);

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

  nux::BaseTexture* texture = normal_->GetTexture();

  if (HasKeyFocus() || fake_focused())
    texture = active_->GetTexture();
  else if (HasKeyFocus())
    texture = prelight_->GetTexture();
  else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
    texture = active_->GetTexture();

  GfxContext.QRP_1Tex(geo.x,
                      geo.y,
                      texture->GetWidth(),
                      texture->GetHeight(),
                      texture->GetDeviceTexture(),
                      texxform,
                      nux::color::White);

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

  GfxContext.PopClippingRectangle();
}
void unity::hud::HudButton::DrawContent ( nux::GraphicsEngine &  GfxContext,
bool  force_draw 
) [protected, virtual]

Definition at line 184 of file HudButton.cpp.

{
  if (skip_draw_)
    return;

  if (IsFullRedraw())
  {
    GfxContext.PushClippingRectangle(GetGeometry());
    hlayout_->ProcessDraw(GfxContext, force_draw);
    GfxContext.PopClippingRectangle();
  }
}
std::string unity::debug::Introspectable::GetChildsName ( ) const [protected, virtual, inherited]

Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Definition at line 92 of file Introspectable.cpp.

{
  return "Children";
}

Here is the caller graph for this function:

Introspectable::IntrospectableList unity::debug::Introspectable::GetIntrospectableChildren ( ) [virtual, inherited]

Reimplemented in unity::hud::View, unity::launcher::LauncherModel, unity::QuicklistView, and unity::dash::ResultView.

Definition at line 41 of file Introspectable.cpp.

{
  return _children;
}

Here is the caller graph for this function:

guint64 unity::debug::Introspectable::GetIntrospectionId ( ) const [inherited]

Definition at line 97 of file Introspectable.cpp.

{
  return _id;
}

Here is the caller graph for this function:

std::string unity::hud::HudButton::GetName ( ) const [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 226 of file HudButton.cpp.

{
  return "HudButton";
}

Definition at line 214 of file HudButton.cpp.

{
  return query_;
}
void unity::hud::HudButton::InitTheme ( ) [protected]

Definition at line 80 of file HudButton.cpp.

{
  is_rounded.changed.connect([&](bool)
  {
    nux::Geometry const& geo = GetGeometry();
    prelight_->Invalidate(geo);
    active_->Invalidate(geo);
    normal_->Invalidate(geo);
  });

  SetMinimumHeight(42);

  if (!active_)
  {
    nux::Geometry const& geo = GetGeometry();

    prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
    active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
    normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

GVariant * unity::debug::Introspectable::Introspect ( ) [inherited]

Definition at line 47 of file Introspectable.cpp.

{
  GVariantBuilder  builder;
  GVariantBuilder  child_builder;
  gint             n_children = 0;

  g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
  g_variant_builder_add(&builder, "{sv}", "id", g_variant_new_uint64(_id));

  AddProperties(&builder);

  g_variant_builder_init(&child_builder, G_VARIANT_TYPE("as"));

  auto children = GetIntrospectableChildren();
  for (auto it = children.begin(); it != children.end(); it++)
  {
    if ((*it)->GetName() != "")
    {
      g_variant_builder_add(&child_builder, "s", (*it)->GetName().c_str());
      n_children++;
    }
  }

  GVariant* child_results = g_variant_builder_end(&child_builder);

  if (n_children > 0)
    g_variant_builder_add(&builder, "{sv}", GetChildsName().c_str(), child_results);
  return g_variant_builder_end(&builder);
}

Here is the call graph for this function:

unity::hud::HudButton::NUX_DECLARE_OBJECT_TYPE ( HudButton  ,
nux::Button   
) [private]
void unity::hud::HudButton::RedrawTheme ( nux::Geometry const &  geom,
cairo_t *  cr,
nux::ButtonVisualState  faked_state 
) [protected]

Definition at line 102 of file HudButton.cpp.

{
  dash::Style::Instance().SquareButton(cr, faked_state, "",
                                       is_rounded, 17,
                                       dash::Alignment::LEFT, true);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 85 of file Introspectable.cpp.

{
  _children.remove(child);
  child->_parents.remove(this);
}

Here is the caller graph for this function:

Definition at line 197 of file HudButton.cpp.

{
  query_ = query;
  label = query->formatted_text;

  auto items(impl::RefactorText(label));

  hlayout_->Clear();
  for (auto item : items)
  {
    nux::StaticCairoText* text = new nux::StaticCairoText(item.first);
    text->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, item.second ? 1.0f : 0.5f));
    text->SetFont(button_font);
    hlayout_->AddView(text, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
  }
}

Here is the call graph for this function:

void unity::hud::HudButton::SetSkipDraw ( bool  skip_draw)

Definition at line 219 of file HudButton.cpp.

{
  skip_draw_ = skip_draw;
}

Member Data Documentation

Definition at line 79 of file HudButton.h.

nux::Geometry unity::hud::HudButton::cached_geometry_ [private]

Definition at line 73 of file HudButton.h.

Definition at line 55 of file HudButton.h.

nux::HLayout* unity::hud::HudButton::hlayout_ [private]

Definition at line 82 of file HudButton.h.

Definition at line 75 of file HudButton.h.

nux::Property<bool> unity::hud::HudButton::is_rounded

Definition at line 54 of file HudButton.h.

nux::Property<std::string> unity::hud::HudButton::label

Definition at line 53 of file HudButton.h.

Definition at line 80 of file HudButton.h.

Definition at line 78 of file HudButton.h.

Definition at line 72 of file HudButton.h.

Definition at line 76 of file HudButton.h.


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