Beispiel #1
0
void UserPromptView::AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const& promise)
{
  auto* text_input = new unity::TextInput();
  auto* text_entry = text_input->text_entry();

  text_input->scale = scale();
  text_input->input_hint = SanitizeMessage(message);
  text_input->hint_font_size = PROMPT_FONT_SIZE;
  text_input->show_caps_lock = true;
  text_input->show_activator = true;
  text_entry->SetPasswordMode(!visible);
  text_entry->SetPasswordChar("•");
  text_entry->SetToggleCursorVisibilityOnKeyFocus(true);
  text_entry->clipboard_enabled = false;

  text_input->SetMinimumHeight(Settings::GRID_SIZE.CP(scale));
  text_input->SetMaximumHeight(Settings::GRID_SIZE.CP(scale));
  prompt_layout_->AddView(text_input, 1);
  focus_queue_.push_back(text_input);

  // Don't remove it, it helps with a11y.
  if (focus_queue_.size() == 1)
    nux::GetWindowCompositor().SetKeyFocusArea(text_entry);

  text_entry->activated.connect([this, text_input, promise](){
    auto* text_entry = text_input->text_entry();

    if (!text_entry->GetInputEventSensitivity())
      return;

    if (focus_queue_.size() == 1)
    {
      text_input->SetSpinnerVisible(true);
      text_input->SetSpinnerState(STATE_SEARCHING);
    }

    focus_queue_.pop_front();
    cached_focused_geo_ = text_entry->GetGeometry();
    text_entry->SetInputEventSensitivity(false);
    QueueRelayout();
    QueueDraw();

    std::string const& password = text_entry->GetText();
    if (promise)
      promise->set_value(password);
  });

  GetLayout()->ComputeContentPosition(0, 0);
  ComputeContentSize();
  QueueRelayout();
  QueueDraw();
}
Beispiel #2
0
void RatingsButton::SetEditable(bool editable)
{
  editable_ = editable;
  if (!editable_)
    focused_star_ = -1;
  QueueDraw();
}
Beispiel #3
0
RatingsButton::RatingsButton(int star_size, int star_gap, NUX_FILE_LINE_DECL)
  : nux::ToggleButton(NUX_FILE_LINE_PARAM)
  , scale(1.0)
  , star_size_(star_size)
  , star_gap_(star_gap)
  , editable_(true)
  , rating_(0.0)
  , focused_star_(-1)
{
  SetAcceptKeyNavFocusOnMouseDown(false);
  SetAcceptKeyNavFocusOnMouseEnter(true);

  mouse_up.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseUp));
  mouse_move.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseMove));
  mouse_drag.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseDrag));

  key_nav_focus_change.connect([this](nux::Area* area, bool has_focus, nux::KeyNavDirection direction)
  {
    if (has_focus && direction != nux::KEY_NAV_NONE)
      focused_star_ = 0;
    else if (!has_focus)
      focused_star_ = -1;

    QueueDraw();
  });

  key_nav_focus_activate.connect([this](nux::Area*) { SetRating(static_cast<float>(focused_star_+1)/NUM_STARS); });
  key_down.connect(sigc::mem_fun(this, &RatingsButton::OnKeyDown));

  scale.changed.connect(sigc::hide(sigc::mem_fun(this, &RatingsButton::QueueDraw)));
}
Beispiel #4
0
void UserPromptView::ResetLayout()
{
  focus_queue_.clear();

  SetLayout(new nux::VLayout());

  GetLayout()->SetLeftAndRightPadding(PADDING.CP(scale));
  GetLayout()->SetTopAndBottomPadding(PADDING.CP(scale));
  static_cast<nux::VLayout*>(GetLayout())->SetVerticalInternalMargin(LAYOUT_MARGIN.CP(scale));

  auto const& real_name = session_manager_->RealName();
  auto const& name = (real_name.empty() ? session_manager_->UserName() : real_name);

  username_ = new unity::StaticCairoText(name);
  username_->SetScale(scale);
  username_->SetFont("Ubuntu "+std::to_string(PROMPT_FONT_SIZE));
  GetLayout()->AddView(username_);

  msg_layout_ = new nux::VLayout();
  msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale));
  msg_layout_->SetReconfigureParentLayoutOnGeometryChange(true);
  GetLayout()->AddLayout(msg_layout_);

  prompt_layout_ = new nux::VLayout();
  prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale));
  prompt_layout_->SetReconfigureParentLayoutOnGeometryChange(true);
  GetLayout()->AddLayout(prompt_layout_);

  QueueRelayout();
  QueueDraw();
}
void PlacesOverlayVScrollBar::UpdateConnectorTexture()
{
  if (connector_height_ < 0)
    return;

  int width = _slider->GetWidth();
  int height = connector_height_;

  if (connector_texture_ && connector_texture_->GetWidth() == width && connector_texture_->GetHeight() == height)
    return;

  nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t* cr = cairoGraphics.GetInternalContext();
  cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale);

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

  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba(cr, CONNECTOR_COLOR.red, CONNECTOR_COLOR.green, CONNECTOR_COLOR.blue, 0.8);
  cairo_rectangle(cr, 0, 0, static_cast<double>(width)/scale(), static_cast<double>(height)/scale());
  cairo_fill(cr);

  connector_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics);

  QueueDraw();
}
Beispiel #6
0
void SwrClearRenderTarget(
    HANDLE hContext,
    uint32_t clearMask,
    const float clearColor[4],
    float z,
    BYTE stencil)
{
    RDTSC_START(APIClearRenderTarget);

    SWR_CONTEXT *pContext = (SWR_CONTEXT*)hContext;

    DRAW_CONTEXT* pDC = GetDrawContext(pContext);

    SetupMacroTileScissors(pDC);

    pDC->inUse = true;

    CLEAR_FLAGS flags;
    flags.mask = clearMask;

    pDC->FeWork.type = CLEAR;
    pDC->FeWork.pfnWork = ProcessClear;
    pDC->FeWork.desc.clear.flags = flags;
    pDC->FeWork.desc.clear.clearDepth = z;
    pDC->FeWork.desc.clear.clearRTColor[0] = clearColor[0];
    pDC->FeWork.desc.clear.clearRTColor[1] = clearColor[1];
    pDC->FeWork.desc.clear.clearRTColor[2] = clearColor[2];
    pDC->FeWork.desc.clear.clearRTColor[3] = clearColor[3];
    pDC->FeWork.desc.clear.clearStencil = stencil;

    // enqueue draw
    QueueDraw(pContext);

    RDTSC_STOP(APIClearRenderTarget, 0, pDC->drawId);
}
Beispiel #7
0
// Deswizzles, converts and stores current contents of the hot tiles to surface
// described by pState
void SwrStoreTiles(
    HANDLE hContext,
    SWR_RENDERTARGET_ATTACHMENT attachment,
    SWR_TILE_STATE postStoreTileState) // TODO: Implement postStoreTileState
{
    RDTSC_START(APIStoreTiles);

    SWR_CONTEXT *pContext = (SWR_CONTEXT*)hContext;
    DRAW_CONTEXT* pDC = GetDrawContext(pContext);
    pDC->inUse = true;

    SetupMacroTileScissors(pDC);

    pDC->FeWork.type = STORETILES;
    pDC->FeWork.pfnWork = ProcessStoreTiles;
    pDC->FeWork.desc.storeTiles.attachment = attachment;
    pDC->FeWork.desc.storeTiles.postStoreTileState = postStoreTileState;

    //enqueue
    QueueDraw(pContext);

    RDTSC_STOP(APIStoreTiles, 0, 0);
    if (attachment == SWR_ATTACHMENT_COLOR0)
    {
        RDTSC_ENDFRAME();
    }
}
void FilterRatingsButton::SetRating(float rating)
{
  if (filter_)
    filter_->rating = rating;

  QueueDraw();
}
void PanelView::ForceUpdateBackground()
{
  is_dirty_ = true;
  UpdateBackground();

  QueueDraw();
}
Beispiel #10
0
void FilterExpanderLabel::BuildLayout()
{
  layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
  top_bar_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
  expander_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);

  expander_view_ = new ExpanderView(NUX_TRACKER_LOCATION);
  expander_view_->SetLayout(expander_layout_);
  top_bar_layout_->AddView(expander_view_, 1);

  cairo_label_ = new StaticCairoText("", NUX_TRACKER_LOCATION);
  cairo_label_->SetFont(FONT_EXPANDER_LABEL);
  cairo_label_->SetScale(scale);
  cairo_label_->SetTextColor(nux::color::White);
  cairo_label_->SetAcceptKeyboardEvent(false);

  expand_icon_ = new IconTexture(Style::Instance().GetGroupUnexpandIcon());
  expand_icon_->SetOpacity(EXPAND_DEFAULT_ICON_OPACITY);
  expand_icon_->SetDrawMode(IconTexture::DrawMode::STRETCH_WITH_ASPECT);
  expand_icon_->SetVisible(true);

  arrow_layout_  = new nux::VLayout();
  arrow_layout_->AddView(expand_icon_, 0, nux::MINOR_POSITION_CENTER);

  expander_layout_->AddView(cairo_label_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
  expander_layout_->AddView(arrow_layout_, 0, nux::MINOR_POSITION_CENTER);

  layout_->AddLayout(top_bar_layout_, 0, nux::MINOR_POSITION_START);
  layout_->SetVerticalInternalMargin(0);

  SetLayout(layout_);

  // Lambda functions
  auto mouse_expand = [this](int x, int y, unsigned long b, unsigned long k)
  {
    expanded = !expanded;
  };

  auto key_redraw = [this](nux::Area*, bool, nux::KeyNavDirection)
  {
    QueueDraw();
  };

  auto key_expand = [this](nux::Area*)
  {
    expanded = !expanded;
  };

  // Signals
  expander_view_->mouse_click.connect(mouse_expand);
  expander_view_->key_nav_focus_change.connect(key_redraw);
  expander_view_->key_nav_focus_activate.connect(key_expand);
  cairo_label_->mouse_click.connect(mouse_expand);
  expand_icon_->mouse_click.connect(mouse_expand);

  UpdateLayoutSizes();
}
Beispiel #11
0
void FilterExpanderLabel::SetContents(nux::Layout* contents)
{
  // Since the contents is initially unowned, we don't want to Adopt it, just assign.
  contents_ = contents;

  layout_->AddLayout(contents_.GetPointer(), 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);

  QueueDraw();
}
void PreviewRatingsWidget::UpdateScale(double scale)
{
  reviews_->SetScale(scale);
  ratings_->scale = scale;
  preview_container_.scale = scale;
  layout_->SetSpaceBetweenChildren(CHILDREN_SPACE.CP(scale));

  QueueRelayout();
  QueueDraw();
}
Icon::Icon()
  : IconTexture("", 0, true)
{
  texture_updated.connect([this] (nux::ObjectPtr<nux::BaseTexture> const& texture)
  {
    icon_texture_source_ = new HudIconTextureSource(texture);
    icon_texture_source_->ColorForIcon(_pixbuf_cached);
    QueueDraw();
    LOG_DEBUG(logger) << "got our texture";
  });
}
void ScopeBarIcon::UpdateScale(double scale)
{
  int overlay_width  = FOCUS_OVERLAY_WIDTH.CP(scale);
  int overlay_height = FOCUS_OVERLAY_HEIGHT.CP(scale);

  SetMinMaxSize(overlay_width, overlay_height);
  focus_layer_.reset(Style::Instance().FocusOverlay(overlay_width, overlay_height));

  SetSize(TEXTURE_SIZE.CP(scale));
  ReLoadIcon();
  QueueDraw();
}
Beispiel #15
0
void SearchBarSpinner::UpdateScale(double scale)
{
  auto& style = dash::Style::Instance();

  magnify_ = style.GetSearchMagnifyIcon(scale);
  circle_ = style.GetSearchCircleIcon(scale);
  close_ = style.GetSearchCloseIcon(scale);
  spin_ = style.GetSearchSpinIcon(scale);

  SetMinMaxSize(magnify_->GetWidth(), magnify_->GetHeight());
  QueueDraw();
}
void VScrollBarOverlayWindow::SetThumbOffsetY(int y)
{
  int const new_offset = GetValidOffsetYValue(y);

  if (new_offset != mouse_offset_y_)
  {
    if (HasState(ThumbState::MOUSE_DOWN))
      MouseDragging();

    mouse_offset_y_ = new_offset;
    QueueDraw();
  }
}
Beispiel #17
0
bool OverlaySpinner::OnFrameTimeout()
{
  rotation_ += 0.1f;

  if (rotation_ >= 360.0f)
    rotation_ = 0.0f;

  rotate_.Rotate_z(rotation_);
  QueueDraw();

  frame_timeout_.reset();
  return false;
}
void UserPromptView::AddMessage(std::string const& message, nux::Color const& color)
{
  auto* view = new unity::StaticCairoText("");
  view->SetFont(Settings::Instance().font_name());
  view->SetTextColor(color);
  view->SetText(message);

  msg_layout_->AddView(view);

  GetLayout()->ComputeContentPosition(0, 0);
  ComputeContentSize();
  QueueRelayout();
  QueueDraw();
}
void PanelView::OnObjectRemoved(indicator::Indicator::Ptr const& proxy)
{
  if (proxy->IsAppmenu())
  {
    menu_view_->RemoveIndicator(proxy);
  }
  else
  {
    indicators_->RemoveIndicator(proxy);
  }

  QueueRelayout();
  QueueDraw();
}
Beispiel #20
0
void UserPromptView::UpdateSize()
{
  auto width = 8 * Settings::GRID_SIZE.CP(scale);
  auto height = 3 * Settings::GRID_SIZE.CP(scale);

  SetMinimumWidth(width);
  SetMaximumWidth(width);
  SetMinimumHeight(height);

  if (nux::Layout* layout = GetLayout())
  {
    layout->SetLeftAndRightPadding(PADDING.CP(scale));
    layout->SetTopAndBottomPadding(PADDING.CP(scale));
    static_cast<nux::VLayout*>(layout)->SetVerticalInternalMargin(LAYOUT_MARGIN.CP(scale));
  }

  if (username_)
    username_->SetScale(scale);

  if (msg_layout_)
  {
    msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale));

    for (auto* area : msg_layout_->GetChildren())
    {
      area->SetMaximumWidth(width);
      static_cast<StaticCairoText*>(area)->SetScale(scale);
    }
  }

  if (prompt_layout_)
  {
    prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale));

    for (auto* area : prompt_layout_->GetChildren())
    {
      auto* text_input = static_cast<TextInput*>(area);
      text_input->SetMinimumHeight(Settings::GRID_SIZE.CP(scale));
      text_input->SetMaximumHeight(Settings::GRID_SIZE.CP(scale));
      text_input->scale = scale();
    }
  }

  bg_layer_.reset();

  ComputeContentSize();
  QueueRelayout();
  QueueDraw();
}
Beispiel #21
0
void RatingsButton::RecvMouseMove(int x, int y, int dx, int dy,
                                        unsigned long button_flags,
                                        unsigned long key_flags)
{
  if (!editable_)
    return;

  int width = NUM_STARS*star_size_.CP(scale)+ (NUM_STARS-1)*star_gap_.CP(scale);
  focused_star_ = std::max(0, std::min(static_cast<int>(ceil((static_cast<float>(x) / width) * NUM_STARS) - 1), NUM_STARS - 1));

  if (!HasKeyFocus())
    nux::GetWindowCompositor().SetKeyFocusArea(this);

  QueueDraw();
}
Beispiel #22
0
OverlaySpinner::OverlaySpinner()
  : nux::View(NUX_TRACKER_LOCATION)
  , scale(1.0)
  , rotation_(0.0f)
{
  spin_ = dash::Style::Instance().GetSearchSpinIcon(scale);

  rotate_.Identity();
  rotate_.Rotate_z(0.0);

  scale.changed.connect([this] (double scale) {
    spin_ = dash::Style::Instance().GetSearchSpinIcon(scale);
    QueueDraw();
  });
}
Beispiel #23
0
void PaymentPreview::ShowOverlay(bool isShown)
{
  if (!full_data_layout_)
    return;

  if (isShown)
  {
    full_data_layout_->SetActiveLayerN(1);
  }
  else
  {
    full_data_layout_->SetActiveLayerN(0);
  }
  QueueDraw();
}
Beispiel #24
0
// Attach surfaces to pipeline
void SwrInvalidateTiles(
    HANDLE hContext,
    uint32_t attachmentMask)
{
    SWR_CONTEXT *pContext = (SWR_CONTEXT*)hContext;
    DRAW_CONTEXT* pDC = GetDrawContext(pContext);
    pDC->inUse = true;

    // Queue a load to the hottile
    pDC->FeWork.type = INVALIDATETILES;
    pDC->FeWork.pfnWork = ProcessInvalidateTiles;
    pDC->FeWork.desc.invalidateTiles.attachmentMask = attachmentMask;

    //enqueue
    QueueDraw(pContext);
}
Beispiel #25
0
void UserPromptView::AddMessage(std::string const& message, nux::Color const& color)
{
  nux::Geometry const& geo = GetGeometry();
  auto* view = new unity::StaticCairoText("");
  view->SetScale(scale);
  view->SetFont(Settings::Instance().font_name());
  view->SetTextColor(color);
  view->SetText(message);
  view->SetMaximumWidth(geo.width - PADDING.CP(scale)*2);
  msg_layout_->AddView(view);

  GetLayout()->ComputeContentPosition(0, 0);
  ComputeContentSize();
  QueueRelayout();
  QueueDraw();
}
void PlacesOverlayVScrollBar::ResetConnector()
{
  if (animation_.CurrentState() == nux::animation::Animation::State::Stopped)
  {
    if (connector_height_ > 0)
    {
      StartConnectorAnimation();
    }
  }
  else
  {
    connector_height_ = 0;
  }

  QueueDraw();
}
//
// Signals
//
void PanelView::OnObjectAdded(indicator::Indicator::Ptr const& proxy)
{
  // Appmenu is treated differently as it needs to expand
  // We could do this in a more special way, but who has the time for special?
  if (proxy->IsAppmenu())
  {
    menu_view_->AddIndicator(proxy);
  }
  else
  {
    indicators_->AddIndicator(proxy);
  }

  QueueRelayout();
  QueueDraw();
}
Beispiel #28
0
void FilterExpanderLabel::UpdateLayoutSizes()
{
  auto& style = dash::Style::Instance();

  layout_->SetLeftAndRightPadding(style.GetFilterBarLeftPadding().CP(scale), style.GetFilterBarRightPadding().CP(scale));
  top_bar_layout_->SetTopAndBottomPadding(style.GetFilterHighlightPadding().CP(scale));
  expander_layout_->SetSpaceBetweenChildren(EXPANDER_LAYOUT_SPACE_BETWEEN_CHILDREN.CP(scale));

  auto const& tex = expand_icon_->texture();
  expand_icon_->SetMinMaxSize(RawPixel(tex->GetWidth()).CP(scale), RawPixel(tex->GetHeight()).CP(scale));

  arrow_layout_->SetLeftAndRightPadding(ARROW_HORIZONTAL_PADDING.CP(scale));
  arrow_layout_->SetTopAndBottomPadding(ARROW_TOP_PADDING.CP(scale), ARROW_BOTTOM_PADDING.CP(scale));

  QueueRelayout();
  QueueDraw();
}
void PlacesOverlayVScrollBar::StartScrollAnimation(ScrollDir dir, int stop)
{
  if (animation_.CurrentState() == nux::animation::Animation::State::Stopped)
  {
    SetupAnimation(0, stop, SCROLL_ANIMATION);

    tweening_connection_ = animation_.updated.connect([this, dir] (int const& update) {
      OnScroll(dir, update - delta_update_);
      delta_update_ = update;

      CheckIfThumbIsInsideSlider();
      UpdateConnectorPosition();
      QueueDraw();
    });

    animation_.Start();
  }
}
Beispiel #30
0
//////////////////////////////////////////////////////////////////////////
/// @brief Returns pointer to SWR stats.
/// @note The counters are atomically incremented by multiple threads.
///       When calling this, you need to ensure all previous operations
///       have completed.
/// @todo If necessary, add a callback to avoid stalling the pipe to
///       sample the counters.
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pStats - SWR will fill this out for caller.
void SwrGetStats(
    HANDLE hContext,
    SWR_STATS* pStats)
{
    SWR_CONTEXT *pContext = GetContext(hContext);
    DRAW_CONTEXT* pDC = GetDrawContext(pContext);

    pDC->inUse = true;

    pDC->FeWork.type = QUERYSTATS;
    pDC->FeWork.pfnWork = ProcessQueryStats;
    pDC->FeWork.desc.queryStats.pStats = pStats;

    // cannot execute until all previous draws have completed
    pDC->dependency = pDC->drawId - 1;

    //enqueue
    QueueDraw(pContext);
}