Back to index

unity  6.0.0
Public Member Functions | Private Member Functions | Private Attributes
unity::BGHash Class Reference

#include <BGHash.h>

Collaboration diagram for unity::BGHash:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 BGHash ()
nux::Color const & CurrentColor () const
void RefreshColor ()
void OverrideColor (nux::Color const &color)

Private Member Functions

void OnTransitionUpdated (double progress)
void DoUbusColorEmit ()
void TransitionToNewColor (nux::Color const &new_color)
nux::Color InterpolateColor (nux::Color const &colora, nux::Color const &colorb, float value) const
nux::Color MatchColor (nux::Color const &base_color) const

Private Attributes

Animator transition_animator_
nux::Color current_color_
nux::Color new_color_
nux::Color old_color_
nux::Color override_color_
UBusManager ubus_manager_

Detailed Description

Definition at line 34 of file BGHash.h.


Constructor & Destructor Documentation


Member Function Documentation

nux::Color const & unity::BGHash::CurrentColor ( ) const

Definition at line 201 of file BGHash.cpp.

{
  return current_color_;
}
void unity::BGHash::DoUbusColorEmit ( ) [private]

Definition at line 131 of file BGHash.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nux::Color unity::BGHash::InterpolateColor ( nux::Color const &  colora,
nux::Color const &  colorb,
float  value 
) const [private]

Definition at line 103 of file BGHash.cpp.

{
  // takes two colours, transitions between them, we can do it linearly or whatever
  // i don't think it will matter that much
  // it doesn't happen too often
  return colora + ((colorb - colora) * value);
}

Here is the caller graph for this function:

nux::Color unity::BGHash::MatchColor ( nux::Color const &  base_color) const [private]

Definition at line 141 of file BGHash.cpp.

{
  nux::Color colors[12];

  colors[ 0] = nux::Color (0x540e44);
  colors[ 1] = nux::Color (0x6e0b2a);
  colors[ 2] = nux::Color (0x841617);
  colors[ 3] = nux::Color (0x84371b);
  colors[ 4] = nux::Color (0x864d20);
  colors[ 5] = nux::Color (0x857f31);
  colors[ 6] = nux::Color (0x1d6331);
  colors[ 7] = nux::Color (0x11582e);
  colors[ 8] = nux::Color (0x0e5955);
  colors[ 9] = nux::Color (0x192b59);
  colors[10] = nux::Color (0x1b134c);
  colors[11] = nux::Color (0x2c0d46);

  float closest_diff = 200.0f;
  nux::Color chosen_color;
  nux::color::HueSaturationValue base_hsv (base_color);

  if (base_hsv.saturation < 0.08)
  {
    // grayscale image
    LOG_DEBUG (logger) << "got a grayscale image";
    chosen_color = nux::Color (46 , 52 , 54 );
    chosen_color.alpha = 0.72f;
  }
  else
  {
    LOG_DEBUG (logger) << "got a colour image";
    // full colour image
    for (int i = 0; i < 11; i++)
    {
      nux::color::HueSaturationValue comparison_hsv (colors[i]);
      float color_diff = fabs(base_hsv.hue - comparison_hsv.hue);

      if (color_diff < closest_diff)
      {
        chosen_color = colors[i];
        closest_diff = color_diff;
      }
    }

    nux::color::HueSaturationValue hsv_color (chosen_color);
    hsv_color.saturation = std::min(base_hsv.saturation, hsv_color.saturation);
    hsv_color.saturation *= (2.0f - hsv_color.saturation);
    hsv_color.value = std::min(std::min(base_hsv.value, hsv_color.value), 0.26f);

    chosen_color = nux::Color (nux::color::RedGreenBlue(hsv_color));
    chosen_color.alpha = 0.72f;
  }

  LOG_DEBUG(logger) << "eventually chose "
                    << chosen_color.red << ", "
                    << chosen_color.green << ", "
                    << chosen_color.blue;
  return chosen_color;
}

Here is the caller graph for this function:

void unity::BGHash::OnTransitionUpdated ( double  progress) [private]

Definition at line 125 of file BGHash.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::BGHash::OverrideColor ( nux::Color const &  color)

Definition at line 47 of file BGHash.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 60 of file BGHash.cpp.

{
  Atom         real_type;
  gint         result;
  gint         real_format;
  gulong       items_read;
  gulong       items_left;
  gchar*       colors;
  Atom         representative_colors_atom;
  Display*     display;
  GdkRGBA      color_gdk;

  representative_colors_atom = gdk_x11_get_xatom_by_name("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS");
  display = gdk_x11_display_get_xdisplay(gdk_display_get_default ());

  gdk_error_trap_push();
  result = XGetWindowProperty (display,
             GDK_ROOT_WINDOW(),
             representative_colors_atom,
             0L,
             G_MAXLONG,
             False,
             XA_STRING,
             &real_type,
             &real_format,
             &items_read,
             &items_left,
             (guchar **) &colors);
  gdk_flush ();
  gdk_error_trap_pop_ignored ();

  if (result == Success && items_read)
  {
    gdk_rgba_parse(&color_gdk, colors);
    nux::Color new_color(color_gdk.red,
                         color_gdk.green,
                         color_gdk.blue,
                         1.0f);
    TransitionToNewColor(MatchColor(new_color));
    XFree (colors);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::BGHash::TransitionToNewColor ( nux::Color const &  new_color) [private]

Definition at line 111 of file BGHash.cpp.

{
  if (new_color == current_color_)
    return;

  LOG_DEBUG(logger) << "transitioning from: " << current_color_.red << " to " << new_color.red;

  old_color_ = current_color_;
  new_color_ = new_color;

  transition_animator_.Stop();
  transition_animator_.Start();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

nux::Color unity::BGHash::current_color_ [private]

Definition at line 53 of file BGHash.h.

nux::Color unity::BGHash::new_color_ [private]

Definition at line 54 of file BGHash.h.

nux::Color unity::BGHash::old_color_ [private]

Definition at line 55 of file BGHash.h.

nux::Color unity::BGHash::override_color_ [private]

Definition at line 56 of file BGHash.h.

Definition at line 51 of file BGHash.h.

Definition at line 58 of file BGHash.h.


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