Back to index

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

#include <ResultRendererHorizontalTile.h>

Inheritance diagram for unity::dash::ResultRendererHorizontalTile:
Inheritance graph
[legend]
Collaboration diagram for unity::dash::ResultRendererHorizontalTile:
Collaboration graph
[legend]

List of all members.

Public Types

enum  ResultRendererState {
  RESULT_RENDERER_NORMAL, RESULT_RENDERER_ACTIVE, RESULT_RENDERER_PRELIGHT, RESULT_RENDERER_SELECTED,
  RESULT_RENDERER_INSENSITIVE
}

Public Member Functions

 NUX_DECLARE_OBJECT_TYPE (ResultRendererHorizontalTile, ResultRendererTile)
 ResultRendererHorizontalTile (NUX_FILE_LINE_PROTO)
 ~ResultRendererHorizontalTile ()
virtual void Render (nux::GraphicsEngine &GfxContext, Result &row, ResultRendererState state, nux::Geometry &geometry, int x_offset, int y_offset)
 NUX_DECLARE_OBJECT_TYPE (ResultRendererTile, ResultRenderer)
 NUX_DECLARE_OBJECT_TYPE (ResultRenderer, nux::InitiallyUnownedObject)
virtual void Preload (Result &row)
virtual void Unload (Result &row)

Public Attributes

int highlight_padding
int spacing
int padding
nux::Property< int > width
nux::Property< int > height
sigc::signal< void > NeedsRedraw

Protected Member Functions

virtual void LoadText (Result &row)
void LoadIcon (Result &row)

Protected Attributes

nux::ObjectPtr< nux::BaseTexture > prelight_cache_
nux::ObjectPtr< nux::BaseTexture > normal_cache_

Private Member Functions

nux::BaseTexture * DrawHighlight (std::string const &texid, int width, int height)
nux::BaseTexture * DrawNormal (std::string const &texid, int width, int height)

Detailed Description

Definition at line 42 of file ResultRendererHorizontalTile.h.


Member Enumeration Documentation

Enumerator:
RESULT_RENDERER_NORMAL 
RESULT_RENDERER_ACTIVE 
RESULT_RENDERER_PRELIGHT 
RESULT_RENDERER_SELECTED 
RESULT_RENDERER_INSENSITIVE 

Definition at line 45 of file ResultRenderer.h.


Constructor & Destructor Documentation

Definition at line 72 of file ResultRendererHorizontalTile.cpp.

  : ResultRendererTile(NUX_FILE_LINE_PARAM)
{
  width = CARD_VIEW_WIDTH;
  height = CARD_VIEW_HEIGHT;

  // pre-load the highlight texture
  // try and get a texture from the texture cache
  TextureCache& cache = TextureCache::GetDefault();
  prelight_cache_ = cache.FindTexture("ResultRendererHorizontalTile.PreLightTexture",
                                      CARD_VIEW_WIDTH,
                                      CARD_VIEW_HEIGHT,
                                      sigc::mem_fun(this, &ResultRendererHorizontalTile::DrawHighlight));
  normal_cache_ = cache.FindTexture("ResultRendererHorizontalTile.NormalTexture",
                                      CARD_VIEW_WIDTH,
                                      CARD_VIEW_HEIGHT,
                                      sigc::mem_fun(this, &ResultRendererHorizontalTile::DrawNormal));

}

Here is the call graph for this function:

Definition at line 92 of file ResultRendererHorizontalTile.cpp.

{
}

Member Function Documentation

nux::BaseTexture * unity::dash::ResultRendererHorizontalTile::DrawHighlight ( std::string const &  texid,
int  width,
int  height 
) [private]

Reimplemented from unity::dash::ResultRendererTile.

Definition at line 193 of file ResultRendererHorizontalTile.cpp.

{
  nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t* cr = cairo_graphics.GetInternalContext();

  cairo_scale(cr, 1.0f, 1.0f);

  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.0);
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);

  // draw the highlight
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.2f);
  cairo_graphics.DrawRoundedRectangle(cr,
                                      1.0f,
                                      0.0f,
                                      0.0f,
                                      CARD_VIEW_HIGHLIGHT_CORNER_RADIUS,
                                      width,
                                      height,
                                      false);
  cairo_fill(cr);

  return texture_from_cairo_graphics(cairo_graphics);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nux::BaseTexture * unity::dash::ResultRendererHorizontalTile::DrawNormal ( std::string const &  texid,
int  width,
int  height 
) [private]

Definition at line 221 of file ResultRendererHorizontalTile.cpp.

{
  nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t* cr = cairo_graphics.GetInternalContext();

  cairo_scale(cr, 1.0f, 1.0f);

  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.0);
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);

  // draw the normal bg
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.075f);
  cairo_graphics.DrawRoundedRectangle(cr,
                                      1.0f,
                                      0.0f,
                                      0.0f,
                                      CARD_VIEW_HIGHLIGHT_CORNER_RADIUS,
                                      width,
                                      height,
                                      false);
  cairo_fill(cr);

  return texture_from_cairo_graphics(cairo_graphics);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::ResultRendererTile::LoadIcon ( Result row) [protected, inherited]

Definition at line 248 of file ResultRendererTile.cpp.

{
  Style& style = Style::Instance();
  std::string const& icon_hint = row.icon_hint;
#define DEFAULT_GICON ". GThemedIcon text-x-preview"
  std::string icon_name;
  if (G_UNLIKELY(neko))
  {
    int tmp1 = style.GetTileIconSize() + (rand() % 16) - 8;
    gsize tmp3;
    gchar* tmp2 = (gchar*)g_base64_decode("aHR0cDovL3BsYWNla2l0dGVuLmNvbS8laS8laS8=", &tmp3);
    gchar* tmp4 = g_strdup_printf(tmp2, tmp1, tmp1);
    icon_name = tmp4;
    g_free(tmp4);
    g_free(tmp2);
  }
  else
  {
    icon_name = !icon_hint.empty() ? icon_hint : DEFAULT_GICON;
  }

  GIcon*  icon = g_icon_new_for_string(icon_name.c_str(), NULL);
  TextureContainer* container = row.renderer<TextureContainer*>();

  IconLoader::IconLoaderCallback slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_hint, row);

  if (g_strrstr(icon_name.c_str(), "://"))
  {
    container->slot_handle = IconLoader::GetDefault().LoadFromURI(icon_name, style.GetTileIconSize(), slot);
  }
  else if (G_IS_ICON(icon))
  {
    container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name, style.GetTileIconSize(), slot);
  }
  else
  {
    container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name, style.GetTileIconSize(), slot);
  }

  if (icon != NULL)
    g_object_unref(icon);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::ResultRendererHorizontalTile::LoadText ( Result row) [protected, virtual]

Reimplemented from unity::dash::ResultRendererTile.

Definition at line 249 of file ResultRendererHorizontalTile.cpp.

{
  std::stringstream final_text;
  char *name = g_markup_escape_text(row.name().c_str()  , -1);
  char *comment = g_markup_escape_text(row.comment().c_str()  , -1);

  if(row.comment().empty())
    final_text << "<b>" << name << "</b>";
  else
    final_text << "<b>" << name << "</b>" << "\n" << comment;

  g_free(name);
  g_free(comment);

  nux::CairoGraphics _cairoGraphics(CAIRO_FORMAT_ARGB32,
                                    CARD_VIEW_WIDTH - CARD_VIEW_ICON_SIZE - 2 * CARD_VIEW_ICON_OUTLINE_WIDTH - 2 * CARD_VIEW_PADDING - CARD_VIEW_ICON_TEXT_GAP,
                                    CARD_VIEW_HEIGHT - 2 * CARD_VIEW_PADDING);

  cairo_t* cr = _cairoGraphics.GetContext();

  PangoLayout*          layout     = NULL;
  PangoFontDescription* desc       = NULL;
  PangoContext*         pango_context   = NULL;
  GdkScreen*            screen     = gdk_screen_get_default();    // not ref'ed
  int                   dpi = -1;

  g_object_get(gtk_settings_get_default(), "gtk-xft-dpi", &dpi, NULL);

  cairo_set_font_options(cr, gdk_screen_get_font_options(screen));
  layout = pango_cairo_create_layout(cr);
  desc = pango_font_description_from_string("Ubuntu 10");

  pango_layout_set_font_description(layout, desc);
  pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);

  pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
  pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
  pango_layout_set_spacing(layout, CARD_VIEW_TEXT_LINE_SPACING * PANGO_SCALE);
  pango_layout_set_width(layout, (CARD_VIEW_WIDTH - CARD_VIEW_ICON_SIZE - 2 * CARD_VIEW_ICON_OUTLINE_WIDTH - 2 * CARD_VIEW_PADDING - CARD_VIEW_ICON_TEXT_GAP) * PANGO_SCALE);
  pango_layout_set_height(layout, -4);

  pango_layout_set_markup(layout, final_text.str().c_str(), -1);

  pango_context = pango_layout_get_context(layout);  // is not ref'ed
  pango_cairo_context_set_font_options(pango_context,
                                       gdk_screen_get_font_options(screen));
  pango_cairo_context_set_resolution(pango_context,
                                     dpi == -1 ? 96.0f : dpi/(float) PANGO_SCALE);
  pango_layout_context_changed(layout);

  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);

  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);

  double offset = 0.0;
  PangoRectangle logRect = {0, 0, 0, 0};
  pango_layout_get_extents(layout, NULL, &logRect);
  if (pango_layout_get_line_count(layout) < 4)
    offset = ((CARD_VIEW_HEIGHT - 2 * CARD_VIEW_PADDING) - (logRect.height / PANGO_SCALE)) / 2.0;
  cairo_move_to(cr, 0.0f, offset);
  pango_cairo_show_layout(cr, layout);

  // clean up
  pango_font_description_free(desc);
  g_object_unref(layout);

  cairo_destroy(cr);

  TextureContainer *container = row.renderer<TextureContainer*>();
  if (container)
    container->text = texture_ptr_from_cairo_graphics(_cairoGraphics);
}

Here is the call graph for this function:

unity::dash::ResultRenderer::NUX_DECLARE_OBJECT_TYPE ( ResultRenderer  ,
nux::InitiallyUnownedObject   
) [inherited]
void unity::dash::ResultRendererTile::Preload ( Result row) [virtual, inherited]

Reimplemented from unity::dash::ResultRenderer.

Definition at line 231 of file ResultRendererTile.cpp.

{
  if (row.renderer<TextureContainer*>() == nullptr)
  {
    row.set_renderer(new TextureContainer());
    LoadIcon(row);
    LoadText(row);
  }
}

Here is the call graph for this function:

void unity::dash::ResultRendererHorizontalTile::Render ( nux::GraphicsEngine &  GfxContext,
Result row,
ResultRendererState  state,
nux::Geometry &  geometry,
int  x_offset,
int  y_offset 
) [virtual]

Reimplemented from unity::dash::ResultRendererTile.

Definition at line 96 of file ResultRendererHorizontalTile.cpp.

{
  TextureContainer* container = row.renderer<TextureContainer*>();
  if (container == nullptr)
    return;

  // set up our texture mode
  nux::TexCoordXForm texxform;

  int icon_left_hand_side = geometry.x + padding;
  int icon_top_side = geometry.y + ((geometry.height - CARD_VIEW_ICON_SIZE) / 2);

  // render overall tile background "rectangle"
  if (state == ResultRendererState::RESULT_RENDERER_NORMAL)
  {
    int x = icon_left_hand_side;
    int y = icon_top_side;
    int w = CARD_VIEW_WIDTH;
    int h = CARD_VIEW_HEIGHT;

    unsigned int alpha = 0;
    unsigned int src   = 0;
    unsigned int dest  = 0;
    GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
    GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

    GfxContext.QRP_1Tex(x,
                        y,
                        w,
                        h,
                        normal_cache_->GetDeviceTexture(),
                        texxform,
                        nux::Color(1.0f, 1.0f, 1.0f, 1.0f));

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

  // render highlight if its needed
  if (state != ResultRendererState::RESULT_RENDERER_NORMAL)
  {
    int x = icon_left_hand_side;
    int y = icon_top_side;
    int w = CARD_VIEW_WIDTH;
    int h = CARD_VIEW_HEIGHT;

    GfxContext.QRP_1Tex(x,
                        y,
                        w,
                        h,
                        prelight_cache_->GetDeviceTexture(),
                        texxform,
                        nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
  }

  // draw the icon
  if (container->icon)
  {
    int x = icon_left_hand_side + CARD_VIEW_PADDING + CARD_VIEW_ICON_OUTLINE_WIDTH;
    int y = icon_top_side + CARD_VIEW_PADDING + CARD_VIEW_ICON_OUTLINE_WIDTH;
    int w = CARD_VIEW_ICON_SIZE;
    int h = CARD_VIEW_ICON_SIZE;
    gPainter.Paint2DQuadColor(GfxContext,
                              x - CARD_VIEW_ICON_OUTLINE_WIDTH,
                              y - CARD_VIEW_ICON_OUTLINE_WIDTH,
                              w + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH,
                              h + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH,
                              nux::color::Black);
    GfxContext.QRP_1Tex(x,
                        y,
                        w,
                        h,
                        container->icon->GetDeviceTexture(),
                        texxform,
                        nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
  }

  if (container->text)
  {
    int x = icon_left_hand_side + CARD_VIEW_PADDING + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH + CARD_VIEW_ICON_SIZE + CARD_VIEW_ICON_TEXT_GAP;
    int y = icon_top_side + CARD_VIEW_PADDING;
    int w = container->text->GetWidth();
    int h = container->text->GetHeight();

    GfxContext.QRP_1Tex(x,
                        y,
                        w,
                        h,
                        container->text->GetDeviceTexture(),
                        texxform,
                        nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
  }
}

Here is the call graph for this function:

void unity::dash::ResultRendererTile::Unload ( Result row) [virtual, inherited]

Reimplemented from unity::dash::ResultRenderer.

Definition at line 241 of file ResultRendererTile.cpp.

{
  TextureContainer *container = row.renderer<TextureContainer*>();
  delete container;
  row.set_renderer<TextureContainer*>(nullptr);
}

Here is the call graph for this function:


Member Data Documentation

nux::Property<int> unity::dash::ResultRenderer::height [inherited]

Definition at line 70 of file ResultRenderer.h.

Definition at line 83 of file ResultRendererTile.h.

sigc::signal<void> unity::dash::ResultRenderer::NeedsRedraw [inherited]

Definition at line 72 of file ResultRenderer.h.

nux::ObjectPtr<nux::BaseTexture> unity::dash::ResultRendererTile::normal_cache_ [protected, inherited]

Definition at line 91 of file ResultRendererTile.h.

Definition at line 85 of file ResultRendererTile.h.

nux::ObjectPtr<nux::BaseTexture> unity::dash::ResultRendererTile::prelight_cache_ [protected, inherited]

Definition at line 90 of file ResultRendererTile.h.

Definition at line 84 of file ResultRendererTile.h.

nux::Property<int> unity::dash::ResultRenderer::width [inherited]

Definition at line 69 of file ResultRenderer.h.


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