Back to index

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

#include <Tooltip.h>

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

List of all members.

Public Types

typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 Tooltip ()
void Draw (nux::GraphicsEngine &gfxContext, bool forceDraw)
void DrawContent (nux::GraphicsEngine &gfxContext, bool forceDraw)
void SetText (std::string const &text)
void ShowTooltipWithTipAt (int anchor_tip_x, int anchor_tip_y)
std::string GetName () const
void AddProperties (GVariantBuilder *builder)
virtual nux::Area * FindAreaUnderMouse (const nux::Point &mouse_position, nux::NuxEventType event_type)
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Protected Member Functions

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

nux::ObjectPtr< nux::BaseTexture > texture_bg_
nux::ObjectPtr< nux::BaseTexture > texture_mask_
nux::ObjectPtr< nux::BaseTexture > texture_outline_
bool _use_blurred_background
bool _compute_blur_bkg

Private Member Functions

 NUX_DECLARE_OBJECT_TYPE (Tooltip, CairoBaseWindow)
void RecvCairoTextChanged (nux::StaticCairoText *cairo_text)
void PreLayoutManagement ()
long PostLayoutManagement (long layoutResult)
void PositionChildLayout (float offsetX, float offsetY)
void LayoutWindowElements ()
void NotifyConfigurationChange (int width, int height)
void UpdateTexture ()

Private Attributes

int _anchorX
int _anchorY
std::string _labelText
nux::ObjectPtr
< nux::StaticCairoText
_tooltip_text
nux::HLayout * _hlayout
nux::VLayout * _vlayout
nux::SpaceLayout * _left_space
 Space from the left of the widget to the left of the text.
nux::SpaceLayout * _right_space
 Space from the right of the text to the right of the widget.
nux::SpaceLayout * _top_space
 Space from the left of the widget to the left of the text.
nux::SpaceLayout * _bottom_space
 Space from the right of the text to the right of the widget.
bool _cairo_text_has_changed

Detailed Description

Definition at line 36 of file Tooltip.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.


Constructor & Destructor Documentation

Definition at line 46 of file Tooltip.cpp.

                 :
  _anchorX(0),
  _anchorY(0),
  _labelText(TEXT("Unity")),
  _cairo_text_has_changed(true)
{
  _use_blurred_background = true;
  _compute_blur_bkg = true;

  _hlayout = new nux::HLayout(TEXT(""), NUX_TRACKER_LOCATION);
  _vlayout = new nux::VLayout(TEXT(""), NUX_TRACKER_LOCATION);

  _left_space = new nux::SpaceLayout(PADDING + ANCHOR_WIDTH, PADDING + ANCHOR_WIDTH, 1, 1000);
  _right_space = new nux::SpaceLayout(PADDING + CORNER_RADIUS, PADDING + CORNER_RADIUS, 1, 1000);

  _top_space = new nux::SpaceLayout(1, 1000, PADDING, PADDING);
  _bottom_space = new nux::SpaceLayout(1, 1000, PADDING, PADDING);

  _vlayout->AddLayout(_top_space, 0);

  _tooltip_text = new nux::StaticCairoText(_labelText, NUX_TRACKER_LOCATION);
  _tooltip_text->SetTextAlignment(nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);
  _tooltip_text->SetTextVerticalAlignment(nux::StaticCairoText::AlignState::NUX_ALIGN_CENTRE);
  _tooltip_text->SetMinimumWidth(MINIMUM_TEXT_WIDTH);

  _tooltip_text->sigTextChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));
  _tooltip_text->sigFontChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));

  _vlayout->AddView(_tooltip_text.GetPointer(), 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);

  _vlayout->AddLayout(_bottom_space, 0);

  _hlayout->AddLayout(_left_space, 0);
  _hlayout->AddLayout(_vlayout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
  _hlayout->AddLayout(_right_space, 0);

  SetWindowSizeMatchLayout(true);
  SetLayout(_hlayout);
}

Here is the call graph for this function:


Member Function Documentation

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

Implements unity::debug::Introspectable.

Definition at line 550 of file Tooltip.cpp.

{
  variant::BuilderWrapper(builder)
    .add("text", _labelText)
    .add("x", GetBaseX())
    .add("y", GetBaseY())
    .add("width", GetBaseWidth())
    .add("height", GetBaseHeight())
    .add("active", IsVisible());
}

Here is the call graph for this function:

void unity::Tooltip::Draw ( nux::GraphicsEngine &  gfxContext,
bool  forceDraw 
)

Reimplemented from unity::CairoBaseWindow.

Definition at line 112 of file Tooltip.cpp.

{
  CairoBaseWindow::Draw(gfxContext, forceDraw);
  _tooltip_text->ProcessDraw(gfxContext, forceDraw);
}
void unity::Tooltip::DrawContent ( nux::GraphicsEngine &  gfxContext,
bool  forceDraw 
)

Definition at line 118 of file Tooltip.cpp.

{}
nux::Area * unity::Tooltip::FindAreaUnderMouse ( const nux::Point &  mouse_position,
nux::NuxEventType  event_type 
) [virtual]

Definition at line 86 of file Tooltip.cpp.

{
  // No area under mouse to allow click through to entities below
  return nullptr;
}
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::Tooltip::GetName ( ) const [virtual]

Implements unity::debug::Introspectable.

Definition at line 545 of file Tooltip.cpp.

{
  return "ToolTip";
}
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 523 of file Tooltip.cpp.

{
}
void unity::Tooltip::NotifyConfigurationChange ( int  width,
int  height 
) [private]

Definition at line 527 of file Tooltip.cpp.

{
}
void unity::Tooltip::PositionChildLayout ( float  offsetX,
float  offsetY 
) [private]

Definition at line 518 of file Tooltip.cpp.

{
}
long unity::Tooltip::PostLayoutManagement ( long  layoutResult) [private]

Definition at line 145 of file Tooltip.cpp.

{
  long result = CairoBaseWindow::PostLayoutManagement(LayoutResult);
  UpdateTexture();

  return result;
}

Here is the call graph for this function:

Definition at line 121 of file Tooltip.cpp.

{
  int text_width;
  int text_height;
  int text_min_width = MINIMUM_TEXT_WIDTH;

  _tooltip_text->GetTextExtents(text_width, text_height);

  if (text_width + TEXT_PADDING * 2 > text_min_width)
  {
    text_min_width = text_width + TEXT_PADDING * 2;
  }

  _tooltip_text->SetMinimumWidth(text_min_width);

  if (text_height < ANCHOR_HEIGHT)
  {
    _top_space->SetMinMaxSize(1, (ANCHOR_HEIGHT - text_height) / 2 + PADDING + CORNER_RADIUS);
    _bottom_space->SetMinMaxSize(1, (ANCHOR_HEIGHT - text_height) / 2 + 1 + PADDING + CORNER_RADIUS);
  }

  CairoBaseWindow::PreLayoutManagement();
}

Definition at line 153 of file Tooltip.cpp.

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:

void unity::Tooltip::SetText ( std::string const &  text)

Definition at line 532 of file Tooltip.cpp.

{
  if (_labelText == text)
    return;

  _labelText = text;
  _tooltip_text->SetText(_labelText);

  QueueRelayout();
}
void unity::Tooltip::ShowTooltipWithTipAt ( int  anchor_tip_x,
int  anchor_tip_y 
)

Definition at line 92 of file Tooltip.cpp.

{
  _anchorX = anchor_tip_x;
  _anchorY = anchor_tip_y;

  int x = _anchorX - PADDING;
  int y = anchor_tip_y - ANCHOR_HEIGHT / 2 - TOP_SIZE - CORNER_RADIUS - PADDING;

  _compute_blur_bkg = true;

  SetBaseX(x);
  SetBaseY(y);

  PushToFront();

  ShowWindow(true);
  UBusServer* ubus = ubus_server_get_default();
  ubus_server_send_message(ubus, UBUS_TOOLTIP_SHOWN, NULL);
}

Here is the call graph for this function:

void unity::Tooltip::UpdateTexture ( ) [private]

Definition at line 434 of file Tooltip.cpp.

{
  if (_cairo_text_has_changed == false)
    return;

  int width = GetBaseWidth();
  int height = GetBaseHeight();

  int x = _anchorX - PADDING;
  int y = _anchorY - height / 2;

  float blur_coef = 6.0f;

  SetBaseX(x);
  SetBaseY(y);

  nux::CairoGraphics cairo_bg(CAIRO_FORMAT_ARGB32, width, height);
  nux::CairoGraphics cairo_mask(CAIRO_FORMAT_ARGB32, width, height);
  nux::CairoGraphics cairo_outline(CAIRO_FORMAT_ARGB32, width, height);

  cairo_t* cr_bg      = cairo_bg.GetContext();
  cairo_t* cr_mask    = cairo_mask.GetContext();
  cairo_t* cr_outline = cairo_outline.GetContext();

  float   tint_color[4]    = {0.074f, 0.074f, 0.074f, 0.80f};
  float   hl_color[4]      = {1.0f, 1.0f, 1.0f, 0.8f};
  float   dot_color[4]     = {1.0f, 1.0f, 1.0f, 0.20f};
  float   shadow_color[4]  = {0.0f, 0.0f, 0.0f, 1.00f};
  float   outline_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};
  float   mask_color[4]    = {1.0f, 1.0f, 1.0f, 1.00f};

  tint_dot_hl(cr_bg,
              width,
              height,
              width / 2.0f,
              0,
              nux::Max<float>(width / 1.3f, height / 1.3f),
              tint_color,
              hl_color,
              dot_color);

  compute_full_outline_shadow
  (
    cr_outline,
    cairo_outline.GetSurface(),
    width,
    height,
    ANCHOR_WIDTH,
    ANCHOR_HEIGHT,
    -1,
    CORNER_RADIUS,
    blur_coef,
    shadow_color,
    1.0f,
    PADDING,
    outline_color);

  compute_full_mask(
    cr_mask,
    cairo_mask.GetSurface(),
    width,
    height,
    CORNER_RADIUS, // radius,
    16,             // shadow_radius,
    ANCHOR_WIDTH,  // anchor_width,
    ANCHOR_HEIGHT, // anchor_height,
    -1,             // upper_size,
    true,           // negative,
    false,          // outline,
    1.0,            // line_width,
    PADDING,       // padding_size,
    mask_color);

  cairo_destroy(cr_bg);
  cairo_destroy(cr_outline);
  cairo_destroy(cr_mask);

  texture_bg_ = texture_ptr_from_cairo_graphics(cairo_bg);
  texture_mask_ = texture_ptr_from_cairo_graphics(cairo_mask);
  texture_outline_ = texture_ptr_from_cairo_graphics(cairo_outline);

  _cairo_text_has_changed = false;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int unity::Tooltip::_anchorX [private]

Definition at line 70 of file Tooltip.h.

int unity::Tooltip::_anchorY [private]

Definition at line 71 of file Tooltip.h.

nux::SpaceLayout* unity::Tooltip::_bottom_space [private]

Space from the right of the text to the right of the widget.

Definition at line 81 of file Tooltip.h.

Definition at line 83 of file Tooltip.h.

bool unity::CairoBaseWindow::_compute_blur_bkg [protected, inherited]

Definition at line 43 of file CairoBaseWindow.h.

nux::HLayout* unity::Tooltip::_hlayout [private]

Definition at line 76 of file Tooltip.h.

std::string unity::Tooltip::_labelText [private]

Definition at line 72 of file Tooltip.h.

nux::SpaceLayout* unity::Tooltip::_left_space [private]

Space from the left of the widget to the left of the text.

Definition at line 78 of file Tooltip.h.

nux::SpaceLayout* unity::Tooltip::_right_space [private]

Space from the right of the text to the right of the widget.

Definition at line 79 of file Tooltip.h.

Definition at line 74 of file Tooltip.h.

nux::SpaceLayout* unity::Tooltip::_top_space [private]

Space from the left of the widget to the left of the text.

Definition at line 80 of file Tooltip.h.

Definition at line 42 of file CairoBaseWindow.h.

nux::VLayout* unity::Tooltip::_vlayout [private]

Definition at line 77 of file Tooltip.h.

nux::ObjectPtr<nux::BaseTexture> unity::CairoBaseWindow::texture_bg_ [protected, inherited]

Definition at line 38 of file CairoBaseWindow.h.

nux::ObjectPtr<nux::BaseTexture> unity::CairoBaseWindow::texture_mask_ [protected, inherited]

Definition at line 39 of file CairoBaseWindow.h.

nux::ObjectPtr<nux::BaseTexture> unity::CairoBaseWindow::texture_outline_ [protected, inherited]

Definition at line 40 of file CairoBaseWindow.h.


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