Back to index

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

#include <IconTexture.h>

Inheritance diagram for unity::IconTexture:
Inheritance graph
[legend]
Collaboration diagram for unity::IconTexture:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 IconTexture (nux::BaseTexture *texture, guint width, guint height)
 IconTexture (std::string const &icon_name, unsigned int size, bool defer_icon_loading=false)
virtual ~IconTexture ()
void SetByIconName (std::string const &icon_name, unsigned int size)
void SetByFilePath (std::string const &file_path, unsigned int size)
void GetTextureSize (int *width, int *height)
void LoadIcon ()
void SetOpacity (float opacity)
void SetTexture (nux::BaseTexture *texture)
void SetAcceptKeyNavFocus (bool accept)
nux::BaseTexture * texture ()
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Public Attributes

sigc::signal< void,
nux::BaseTexture * > 
texture_updated

Protected Member Functions

virtual bool AcceptKeyNavFocus ()
std::string GetName () const
void AddProperties (GVariantBuilder *builder)
virtual bool DoCanFocus ()
void Draw (nux::GraphicsEngine &GfxContext, bool force_draw)
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'.

Protected Attributes

bool _accept_key_nav_focus
glib::Object< GdkPixbuf > _pixbuf_cached

Private Member Functions

nux::BaseTexture * CreateTextureCallback (std::string const &texid, int width, int height)
void Refresh (glib::Object< GdkPixbuf > const &pixbuf)
void IconLoaded (std::string const &icon_name, unsigned size, glib::Object< GdkPixbuf > const &pixbuf)

Private Attributes

std::string _icon_name
unsigned int _size
nux::ObjectPtr< nux::BaseTexture > _texture_cached
nux::Size _texture_size
bool _loading
float _opacity
int _handle

Detailed Description

Definition at line 37 of file IconTexture.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.


Constructor & Destructor Documentation

unity::IconTexture::IconTexture ( nux::BaseTexture *  texture,
guint  width,
guint  height 
)

Definition at line 46 of file IconTexture.cpp.

  : TextureArea(NUX_TRACKER_LOCATION),
    _accept_key_nav_focus(false),
    _size(height),
    _texture_cached(texture),
    _texture_size(width, height),
    _loading(false),
    _opacity(1.0f),
    _handle(0)
{
  SetMinMaxSize(width, height);
}
unity::IconTexture::IconTexture ( std::string const &  icon_name,
unsigned int  size,
bool  defer_icon_loading = false 
)

Definition at line 59 of file IconTexture.cpp.

  : TextureArea(NUX_TRACKER_LOCATION),
    _accept_key_nav_focus(false),
    _icon_name(!icon_name.empty() ? icon_name : DEFAULT_ICON),
    _size(size),
    _loading(false),
    _opacity(1.0f),
    _handle(0)
{
  if (!icon_name.empty () && !defer_icon_loading)
    LoadIcon();
}

Here is the call graph for this function:

Definition at line 72 of file IconTexture.cpp.

Here is the call graph for this function:


Member Function Documentation

bool unity::IconTexture::AcceptKeyNavFocus ( ) [protected, virtual]

Definition at line 257 of file IconTexture.cpp.

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::IconTexture::AddProperties ( GVariantBuilder *  builder) [protected, virtual]

Implements unity::debug::Introspectable.

Reimplemented in unity::dash::LensBarIcon.

Definition at line 241 of file IconTexture.cpp.

{
  unity::variant::BuilderWrapper(builder)
  .add(GetGeometry())
  .add("icon_name", _icon_name);
}

Here is the call graph for this function:

nux::BaseTexture * unity::IconTexture::CreateTextureCallback ( std::string const &  texid,
int  width,
int  height 
) [private]

Definition at line 131 of file IconTexture.cpp.

{
  return nux::CreateTexture2DFromPixbuf(_pixbuf_cached, true);
}

Here is the caller graph for this function:

bool unity::IconTexture::DoCanFocus ( ) [protected, virtual]

Definition at line 230 of file IconTexture.cpp.

{
  return false;
}
void unity::IconTexture::Draw ( nux::GraphicsEngine &  GfxContext,
bool  force_draw 
) [protected]

Reimplemented in unity::dash::LensBarIcon, and unity::hud::Icon.

Definition at line 178 of file IconTexture.cpp.

{
  nux::Geometry geo = GetGeometry();

  GfxContext.PushClippingRectangle(geo);

  nux::GetPainter().PaintBackground(GfxContext, geo);

  if (_texture_cached)
  {
    nux::Color col(1.0f * _opacity, 1.0f * _opacity, 1.0f * _opacity, _opacity);
    nux::TexCoordXForm texxform;
    texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
    texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER);

    GfxContext.QRP_1Tex(geo.x + ((geo.width - _texture_size.width) / 2),
                        geo.y + ((geo.height - _texture_size.height) / 2),
                        _texture_size.width,
                        _texture_size.height,
                        _texture_cached->GetDeviceTexture(),
                        texxform,
                        col);
  }

  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::IconTexture::GetName ( ) const [protected, virtual]

Implements unity::debug::Introspectable.

Reimplemented in unity::dash::LensBarIcon, and unity::hud::Icon.

Definition at line 235 of file IconTexture.cpp.

{
  return "IconTexture";
}
void unity::IconTexture::GetTextureSize ( int *  width,
int *  height 
)

Definition at line 205 of file IconTexture.cpp.

{
  if (width)
    *width = _texture_size.width;
  if (height)
    *height = _texture_size.height;
}

Here is the caller graph for this function:

void unity::IconTexture::IconLoaded ( std::string const &  icon_name,
unsigned  size,
glib::Object< GdkPixbuf > const &  pixbuf 
) [private]

Definition at line 154 of file IconTexture.cpp.

{
  _handle = 0;

  if (GDK_IS_PIXBUF(pixbuf.RawPtr()))
  {
    Refresh(pixbuf);
  }
  else
  {
    _pixbuf_cached = nullptr;
    _loading = false;

    // Protects against a missing default icon, we only request it if icon_name
    // doesn't match.
    if (icon_name != DEFAULT_ICON)
      SetByIconName(DEFAULT_ICON, _size);
  }

  texture_updated.emit(_texture_cached.GetPointer());
  QueueDraw();
}

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:

Definition at line 100 of file IconTexture.cpp.

{
  LOG_DEBUG(logger) << "LoadIcon called (" << _icon_name << ") - loading: " << _loading;
  static const char* const DEFAULT_GICON = ". GThemedIcon text-x-preview";

  if (_loading || _size == 0 || _handle)
    return;

  _loading = true;

  glib::Object<GIcon> icon(g_icon_new_for_string(_icon_name.empty() ?  DEFAULT_GICON : _icon_name.c_str(), NULL));

  if (G_IS_ICON(icon.RawPtr()))
  {
    _handle = IconLoader::GetDefault().LoadFromGIconString(_icon_name.empty() ? DEFAULT_GICON : _icon_name.c_str(),
                                                           _size,
                                                           sigc::mem_fun(this, &IconTexture::IconLoaded));
  }
  else if (_icon_name.find("http://") == 0)
  {
    _handle = IconLoader::GetDefault().LoadFromURI(_icon_name,
                                                   _size, sigc::mem_fun(this, &IconTexture::IconLoaded));
  }
  else
  {
    _handle = IconLoader::GetDefault().LoadFromIconName(_icon_name,
                                                        _size,
                                                        sigc::mem_fun(this, &IconTexture::IconLoaded));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::IconTexture::Refresh ( glib::Object< GdkPixbuf > const &  pixbuf) [private]

Definition at line 136 of file IconTexture.cpp.

{
  TextureCache& cache = TextureCache::GetDefault();
  _pixbuf_cached = pixbuf;

  // Cache the pixbuf dimensions so we scale correctly
  _texture_size.width = gdk_pixbuf_get_width(pixbuf);
  _texture_size.height = gdk_pixbuf_get_height(pixbuf);

  // Try and get a texture from the texture cache
  std::string id("IconTexture.");
  id += _icon_name.empty() ? DEFAULT_ICON : _icon_name;
  _texture_cached = cache.FindTexture(id, _texture_size.width, _texture_size.height,
                                      sigc::mem_fun(this, &IconTexture::CreateTextureCallback));
  QueueDraw();
  _loading = false;
}

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 252 of file IconTexture.cpp.

{
  _accept_key_nav_focus = accept;
}

Here is the caller graph for this function:

void unity::IconTexture::SetByFilePath ( std::string const &  file_path,
unsigned int  size 
)

Definition at line 95 of file IconTexture.cpp.

{
  SetByIconName(file_path, size);
}

Here is the call graph for this function:

void unity::IconTexture::SetByIconName ( std::string const &  icon_name,
unsigned int  size 
)

Definition at line 77 of file IconTexture.cpp.

{
  if (_icon_name == icon_name && _size == size)
    return;

  _icon_name = icon_name;
  _size = size;

  if (_size == 0)
  {
    _texture_cached = nullptr;
    return;
  }

  LoadIcon();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::IconTexture::SetOpacity ( float  opacity)

Definition at line 213 of file IconTexture.cpp.

{
  _opacity = opacity;

  QueueDraw();
}

Here is the caller graph for this function:

void unity::IconTexture::SetTexture ( nux::BaseTexture *  texture)

Definition at line 220 of file IconTexture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nux::BaseTexture * unity::IconTexture::texture ( )

Definition at line 225 of file IconTexture.cpp.

{
  return _texture_cached.GetPointer();
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 62 of file IconTexture.h.

Definition at line 85 of file IconTexture.h.

std::string unity::IconTexture::_icon_name [private]

Definition at line 77 of file IconTexture.h.

Definition at line 83 of file IconTexture.h.

Definition at line 84 of file IconTexture.h.

Definition at line 67 of file IconTexture.h.

unsigned int unity::IconTexture::_size [private]

Definition at line 78 of file IconTexture.h.

nux::ObjectPtr<nux::BaseTexture> unity::IconTexture::_texture_cached [private]

Definition at line 80 of file IconTexture.h.

nux::Size unity::IconTexture::_texture_size [private]

Definition at line 81 of file IconTexture.h.

sigc::signal<void, nux::BaseTexture*> unity::IconTexture::texture_updated

Definition at line 57 of file IconTexture.h.


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