20
20
#include <Nux/Nux.h>
22
#include "CairoTexture.h"
22
23
#include "PlacesOverlayVScrollBar.h"
23
#include "CairoTexture.h"
27
int const PROXIMITY = 7;
28
int const SCROLL_ANIMATION = 400;
29
int const MAX_CONNECTOR_ANIMATION = 200;
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;
38
class PlacesOverlayVScrollBar::ProximityArea : public nux::InputAreaProximity, public sigc::trackable
41
ProximityArea(nux::InputArea* area, unsigned prox)
42
: nux::InputAreaProximity(area, prox)
43
, proximity([this] { return proximity_; }, [this] (unsigned px) { proximity_ = px; return false; })
46
nux::RWProperty<unsigned> proximity;
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)
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));
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));
75
scale.changed.connect([this] (double scale) {
76
area_prox_->proximity = PROXIMITY.CP(scale);
77
overlay_window_->scale = scale;
63
81
void PlacesOverlayVScrollBar::OnTrackGeometryChanged(nux::Area* /*area*/, nux::Geometry& /*geo*/)
410
428
if (connector_height_ < 0)
431
int width = _slider->GetWidth();
414
432
int height = connector_height_;
415
float const radius = 1.5f;
416
float const aspect = 1.0f;
420
nux::color::RedGreenBlue const& connector_bg = nux::color::Gray;
434
if (connector_texture_ && connector_texture_->GetWidth() == width && connector_texture_->GetHeight() == height)
422
437
nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
423
cr = cairoGraphics.GetInternalContext();
438
cairo_t* cr = cairoGraphics.GetInternalContext();
439
cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale);
426
441
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
429
444
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
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);
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());
449
connector_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics);