Back to index

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

#include <HudIconTextureSource.h>

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

List of all members.

Public Types

enum  TransformIndex {
  TRANSFORM_TILE, TRANSFORM_IMAGE, TRANSFORM_HIT_AREA, TRANSFORM_GLOW,
  TRANSFORM_EMBLEM
}
typedef nux::ObjectPtr
< IconTextureSource
Ptr

Public Member Functions

 HudIconTextureSource (nux::ObjectPtr< nux::BaseTexture > texture)
 ~HudIconTextureSource ()
virtual nux::Color BackgroundColor () const
virtual nux::BaseTexture * TextureForSize (int size)
virtual nux::Color GlowColor ()
virtual nux::BaseTexture * Emblem ()
void ColorForIcon (GdkPixbuf *pixbuf)
std::vector< nux::Vector4 > & GetTransform (TransformIndex index, int monitor)

Private Attributes

nux::Color bg_color
nux::ObjectPtr< nux::BaseTexture > icon_texture_

Detailed Description

Definition at line 31 of file HudIconTextureSource.h.


Member Typedef Documentation

typedef nux::ObjectPtr<IconTextureSource> unity::ui::IconTextureSource::Ptr [inherited]

Member Enumeration Documentation

Enumerator:
TRANSFORM_TILE 
TRANSFORM_IMAGE 
TRANSFORM_HIT_AREA 
TRANSFORM_GLOW 
TRANSFORM_EMBLEM 

Definition at line 39 of file IconTextureSource.h.


Constructor & Destructor Documentation

unity::hud::HudIconTextureSource::HudIconTextureSource ( nux::ObjectPtr< nux::BaseTexture >  texture)

Definition at line 39 of file HudIconTextureSource.cpp.

Definition at line 45 of file HudIconTextureSource.cpp.

{
}

Member Function Documentation

nux::Color unity::hud::HudIconTextureSource::BackgroundColor ( ) const [virtual]

Implements unity::ui::IconTextureSource.

Definition at line 101 of file HudIconTextureSource.cpp.

{
  return bg_color;
}
void unity::hud::HudIconTextureSource::ColorForIcon ( GdkPixbuf *  pixbuf)

Definition at line 49 of file HudIconTextureSource.cpp.

{
  if (GDK_IS_PIXBUF(pixbuf))
  {
    unsigned int width = gdk_pixbuf_get_width(pixbuf);
    unsigned int height = gdk_pixbuf_get_height(pixbuf);
    unsigned int row_bytes = gdk_pixbuf_get_rowstride(pixbuf);
    
    long int rtotal = 0, gtotal = 0, btotal = 0;
    float total = 0.0f;
    
    guchar* img = gdk_pixbuf_get_pixels(pixbuf);
    
    for (unsigned int i = 0; i < width; i++)
    {
      for (unsigned int j = 0; j < height; j++)
      {
        guchar* pixels = img + (j * row_bytes + i * 4);
        guchar r = *(pixels + 0);
        guchar g = *(pixels + 1);
        guchar b = *(pixels + 2);
        guchar a = *(pixels + 3);
        
        float saturation = (MAX(r, MAX(g, b)) - MIN(r, MIN(g, b))) / 255.0f;
        float relevance = .1 + .9 * (a / 255.0f) * saturation;
        
        rtotal += (guchar)(r * relevance);
        gtotal += (guchar)(g * relevance);
        btotal += (guchar)(b * relevance);
        
        total += relevance * 255;
      }
    }
    
    nux::color::RedGreenBlue rgb(rtotal / total,
                                 gtotal / total,
                                 btotal / total);
    nux::color::HueSaturationValue hsv(rgb);
    
    if (hsv.saturation > 0.15f)
      hsv.saturation = 0.65f;
    
    hsv.value = 0.90f;
    bg_color = nux::Color(nux::color::RedGreenBlue(hsv));
  }
  else
  {
    LOG_ERROR(logger) << "Pixbuf (" << pixbuf << ") passed is non valid";
    bg_color = nux::Color(255,255,255,255);
  }
}
nux::BaseTexture * unity::hud::HudIconTextureSource::Emblem ( ) [virtual]

Implements unity::ui::IconTextureSource.

Definition at line 116 of file HudIconTextureSource.cpp.

{
  return nullptr;
}
std::vector< nux::Vector4 > & unity::ui::IconTextureSource::GetTransform ( TransformIndex  index,
int  monitor 
) [inherited]

Definition at line 34 of file IconTextureSource.cpp.

{
  auto iter = transform_map[monitor].find(index);
  if (iter == transform_map[monitor].end())
  {
    auto iter2 = transform_map[monitor].insert(std::map<TransformIndex, std::vector<nux::Vector4> >::value_type(index, std::vector<nux::Vector4>(4)));
    return iter2.first->second;
  }

  return iter->second;
}

Here is the caller graph for this function:

Implements unity::ui::IconTextureSource.

Definition at line 111 of file HudIconTextureSource.cpp.

{
 return nux::Color(0.0f, 0.0f, 0.0f, 0.0f); 
}
nux::BaseTexture * unity::hud::HudIconTextureSource::TextureForSize ( int  size) [virtual]

Implements unity::ui::IconTextureSource.

Definition at line 106 of file HudIconTextureSource.cpp.

{
  return icon_texture_.GetPointer();
}

Member Data Documentation

Definition at line 44 of file HudIconTextureSource.h.

nux::ObjectPtr<nux::BaseTexture> unity::hud::HudIconTextureSource::icon_texture_ [private]

Definition at line 45 of file HudIconTextureSource.h.


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