~unity-team/unity/trusty-1066971

« back to all changes in this revision

Viewing changes to unity-shared/PlacesOverlayVScrollBar.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2014-08-06 14:09:30 UTC
  • mto: This revision was merged to the branch mainline in revision 3802.
  • Revision ID: mail@3v1n0.net-20140806140930-knkc0x43ree376r1
PlacesOverlayVScrollBar and VScrollBarOverlayWindow: add support for scaling

Add a new ScrollView class to create ScrollViews with an OverlayScrollbar and with scaling support.
Using them in dash Scopes and Previews.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include <Nux/Nux.h>
21
21
 
 
22
#include "CairoTexture.h"
22
23
#include "PlacesOverlayVScrollBar.h"
23
 
#include "CairoTexture.h"
24
 
 
25
 
namespace
26
 
{
27
 
  int const PROXIMITY = 7;
28
 
  int const SCROLL_ANIMATION = 400;
29
 
  int const MAX_CONNECTOR_ANIMATION = 200;
30
 
}
 
24
#include "RawPixel.h"
31
25
 
32
26
namespace unity
33
27
{
34
28
namespace dash
35
29
{
 
30
namespace
 
31
{
 
32
  const RawPixel PROXIMITY = 7_em;
 
33
  const int SCROLL_ANIMATION = 400;
 
34
  const int MAX_CONNECTOR_ANIMATION = 200;
 
35
  const nux::Color CONNECTOR_COLOR = nux::color::Gray;
 
36
}
 
37
 
 
38
class PlacesOverlayVScrollBar::ProximityArea : public nux::InputAreaProximity, public sigc::trackable
 
39
{
 
40
public:
 
41
  ProximityArea(nux::InputArea* area, unsigned prox)
 
42
    : nux::InputAreaProximity(area, prox)
 
43
    , proximity([this] { return proximity_; }, [this] (unsigned px) { proximity_ = px; return false; })
 
44
  {}
 
45
 
 
46
  nux::RWProperty<unsigned> proximity;
 
47
};
36
48
 
37
49
PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL)
38
50
  : PlacesVScrollBar(NUX_FILE_LINE_PARAM)
39
51
  , overlay_window_(new VScrollBarOverlayWindow(_track->GetAbsoluteGeometry()))
40
 
  , area_prox_(this, PROXIMITY)
 
52
  , area_prox_(std::make_shared<ProximityArea>(this, PROXIMITY.CP(scale)))
41
53
  , thumb_above_slider_(false)
42
54
  , connector_height_(0)
43
55
  , mouse_down_offset_(0)
44
56
  , delta_update_(0)
45
57
{
46
 
  area_prox_.mouse_near.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseNear));
47
 
  area_prox_.mouse_beyond.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseBeyond));
 
58
  area_prox_->mouse_near.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseNear));
 
59
  area_prox_->mouse_beyond.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseBeyond));
48
60
 
 
61
  overlay_window_->scale = scale();
49
62
  overlay_window_->mouse_enter.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseEnter));
50
63
  overlay_window_->mouse_leave.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseLeave));
51
64
  overlay_window_->mouse_down.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseDown));
58
71
  _track->geometry_changed.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnTrackGeometryChanged));
59
72
  OnVisibleChanged.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnVisibilityChanged));
60
73
  OnSensitiveChanged.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnSensitivityChanged));
 
74
 
 
75
  scale.changed.connect([this] (double scale) {
 
76
    area_prox_->proximity = PROXIMITY.CP(scale);
 
77
    overlay_window_->scale = scale;
 
78
  });
61
79
}
62
80
 
63
81
void PlacesOverlayVScrollBar::OnTrackGeometryChanged(nux::Area* /*area*/, nux::Geometry& /*geo*/)
410
428
  if (connector_height_ < 0)
411
429
    return;
412
430
 
413
 
  int width = 3;
 
431
  int width = _slider->GetWidth();
414
432
  int height = connector_height_;
415
 
  float const radius = 1.5f;
416
 
  float const aspect = 1.0f;
417
 
 
418
 
  cairo_t* cr = NULL;
419
 
 
420
 
  nux::color::RedGreenBlue const& connector_bg = nux::color::Gray;
 
433
 
 
434
  if (connector_texture_ && connector_texture_->GetWidth() == width && connector_texture_->GetHeight() == height)
 
435
    return;
421
436
 
422
437
  nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
423
 
  cr = cairoGraphics.GetInternalContext();
424
 
  cairo_save(cr);
 
438
  cairo_t* cr = cairoGraphics.GetInternalContext();
 
439
  cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale);
425
440
 
426
441
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
427
442
  cairo_paint(cr);
428
443
 
429
444
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
430
 
  cairo_save(cr);
431
 
 
432
 
  cairo_set_source_rgba(cr, connector_bg.red, connector_bg.green, connector_bg.blue, 0.8);
433
 
  cairoGraphics.DrawRoundedRectangle(cr, aspect, 0.0f, 0.0f, radius, width, height);
434
 
  cairo_fill_preserve(cr);
435
 
 
436
 
  connector_texture_.Adopt(texture_from_cairo_graphics(cairoGraphics));
 
445
  cairo_set_source_rgba(cr, CONNECTOR_COLOR.red, CONNECTOR_COLOR.green, CONNECTOR_COLOR.blue, 0.8);
 
446
  cairo_rectangle(cr, 0, 0, static_cast<double>(width)/scale(), static_cast<double>(height)/scale());
 
447
  cairo_fill(cr);
 
448
 
 
449
  connector_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics);
437
450
 
438
451
  QueueDraw();
439
452
}