Scroom  0.14
ruler.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/shared_ptr.hpp>
4 
5 #include <gtk/gtk.h>
6 
7 #include "rulerstrategies.hh"
8 
14 class Ruler
15 {
16 
17 public:
18  using Ptr = boost::shared_ptr<Ruler>;
19 
21  {
24  };
25 
32  static Ptr create(Orientation orientation, GtkWidget* drawArea);
33 
34  ~Ruler();
35  Ruler(const Ruler&) = delete;
36  Ruler(Ruler&&) = delete;
37  Ruler operator=(const Ruler&) = delete;
38  Ruler operator=(Ruler&&) = delete;
39 
45  void setRange(double lower, double upper);
46 
47 private:
48  GtkWidget* drawingArea{};
49 
50  static constexpr double DEFAULT_LOWER{0};
51  static constexpr double DEFAULT_UPPER{10};
52 
57  constexpr static std::array<int, 2> SUBTICK_SEGMENTS{5, 2};
58 
59  // The range to be displayed.
62 
63  // The allocated width and height for the drawing area widget.
64  int width{};
65  int height{};
66 
68  int majorInterval{1};
69 
72 
73  // ==== DRAWING PROPERTIES ====
74 
76 
78  static constexpr int MIN_SPACE_SUBTICKS{5};
79 
80  static constexpr double FONT_SIZE{11};
81 
83  static constexpr double LABEL_OFFSET{4};
84 
86  static constexpr double LABEL_ALIGN{0.7};
87 
89  static constexpr double LINE_MULTIPLIER{0.6};
90 
91  GdkRGBA lineColor{0, 0, 0, 1};
92 
93  static constexpr double LINE_WIDTH{1};
94 
96  static constexpr double MAJOR_TICK_LENGTH{0.8};
97 
103  Ruler(RulerDrawStrategy::Ptr strategy, GtkWidget* drawingArea);
104 
113  static gboolean drawCallback(GtkWidget* widget, cairo_t* cr, gpointer data);
114 
120  void draw(GtkWidget* widget, cairo_t* cr);
121 
129  static void sizeAllocateCallback(GtkWidget* widget, GdkRectangle* allocation, gpointer data);
130 
136  void updateAllocatedSize(int newWidth, int newHeight);
137 
142 
150  void drawTicks(cairo_t* cr, double lower, double upper, double lineLength);
151 
160  void drawSingleTick(cairo_t* cr, double linePosition, double lineLength, bool drawLabel, const std::string& label);
161 
170  void drawSubTicks(cairo_t* cr, double lower, double upper, int depth, double lineLength);
171 };
172 
177 {
178 private:
180  constexpr static std::array<int, 4> VALID_INTERVALS{1, 5, 10, 25};
181 
182 public:
184  static constexpr int MIN_SPACE_MAJORTICKS{80};
185 
193  static int calculateInterval(double lower, double upper, double allocatedSize);
194 
203  static int intervalPixelSpacing(double interval, double lower, double upper, double allocatedSize);
204 
211  static int firstTick(double lower, int interval);
212 
223  static double scaleToRange(double x, double src_lower, double src_upper, double dest_lower, double dest_upper);
224 };
Ruler::Ruler
Ruler(const Ruler &)=delete
Ruler::drawSingleTick
void drawSingleTick(cairo_t *cr, double linePosition, double lineLength, bool drawLabel, const std::string &label)
Definition: ruler.cc:168
RulerCalculations::intervalPixelSpacing
static int intervalPixelSpacing(double interval, double lower, double upper, double allocatedSize)
Definition: ruler.cc:294
Ruler::drawCallback
static gboolean drawCallback(GtkWidget *widget, cairo_t *cr, gpointer data)
Definition: ruler.cc:106
Ruler::LABEL_ALIGN
static constexpr double LABEL_ALIGN
Definition: ruler.hh:86
Ruler::drawTicks
void drawTicks(cairo_t *cr, double lower, double upper, double lineLength)
Definition: ruler.cc:144
Ruler::sizeAllocateCallback
static void sizeAllocateCallback(GtkWidget *widget, GdkRectangle *allocation, gpointer data)
Definition: ruler.cc:76
Ruler::Orientation
Orientation
Definition: ruler.hh:20
Ruler::width
int width
Definition: ruler.hh:64
Ruler::updateMajorTickInterval
void updateMajorTickInterval()
Definition: ruler.cc:86
RulerCalculations::MIN_SPACE_MAJORTICKS
static constexpr int MIN_SPACE_MAJORTICKS
Definition: ruler.hh:184
Ruler::LINE_MULTIPLIER
static constexpr double LINE_MULTIPLIER
Definition: ruler.hh:89
RulerCalculations::firstTick
static int firstTick(double lower, int interval)
Definition: ruler.cc:303
Ruler::lineColor
GdkRGBA lineColor
Definition: ruler.hh:91
Ruler::MAJOR_TICK_LENGTH
static constexpr double MAJOR_TICK_LENGTH
Definition: ruler.hh:96
Ruler::DEFAULT_LOWER
static constexpr double DEFAULT_LOWER
Definition: ruler.hh:50
Ruler::DEFAULT_UPPER
static constexpr double DEFAULT_UPPER
Definition: ruler.hh:51
Ruler::majorInterval
int majorInterval
Definition: ruler.hh:68
Ruler::draw
void draw(GtkWidget *widget, cairo_t *cr)
Definition: ruler.cc:114
Ruler::VERTICAL
@ VERTICAL
Definition: ruler.hh:23
Ruler::updateAllocatedSize
void updateAllocatedSize(int newWidth, int newHeight)
Definition: ruler.cc:67
Ruler::LABEL_OFFSET
static constexpr double LABEL_OFFSET
Definition: ruler.hh:83
RulerDrawStrategy::Ptr
boost::shared_ptr< RulerDrawStrategy > Ptr
Definition: rulerstrategies.hh:17
Ruler::create
static Ptr create(Orientation orientation, GtkWidget *drawArea)
Definition: ruler.cc:12
Ruler::SUBTICK_SEGMENTS
constexpr static std::array< int, 2 > SUBTICK_SEGMENTS
Definition: ruler.hh:57
RulerCalculations::scaleToRange
static double scaleToRange(double x, double src_lower, double src_upper, double dest_lower, double dest_upper)
Definition: ruler.cc:235
Ruler::LINE_WIDTH
static constexpr double LINE_WIDTH
Definition: ruler.hh:93
Ruler::height
int height
Definition: ruler.hh:65
Ruler::drawSubTicks
void drawSubTicks(cairo_t *cr, double lower, double upper, int depth, double lineLength)
Definition: ruler.cc:193
Ruler::operator=
Ruler operator=(const Ruler &)=delete
Ruler::upperLimit
double upperLimit
Definition: ruler.hh:61
Ruler::drawStrategy
RulerDrawStrategy::Ptr drawStrategy
Definition: ruler.hh:75
Ruler::~Ruler
~Ruler()
Definition: ruler.cc:48
RulerCalculations::VALID_INTERVALS
constexpr static std::array< int, 4 > VALID_INTERVALS
Definition: ruler.hh:180
RulerCalculations
Definition: ruler.hh:176
Ruler::lowerLimit
double lowerLimit
Definition: ruler.hh:60
rulerstrategies.hh
Ruler::drawingArea
GtkWidget * drawingArea
Definition: ruler.hh:48
Ruler::MIN_SPACE_SUBTICKS
static constexpr int MIN_SPACE_SUBTICKS
Definition: ruler.hh:78
Ruler::Ptr
boost::shared_ptr< Ruler > Ptr
Definition: ruler.hh:18
Ruler::FONT_SIZE
static constexpr double FONT_SIZE
Definition: ruler.hh:80
Ruler
Definition: ruler.hh:14
Ruler::majorTickSpacing
int majorTickSpacing
Definition: ruler.hh:71
RulerCalculations::calculateInterval
static int calculateInterval(double lower, double upper, double allocatedSize)
Definition: ruler.cc:244
Ruler::HORIZONTAL
@ HORIZONTAL
Definition: ruler.hh:22
Ruler::setRange
void setRange(double lower, double upper)
Definition: ruler.cc:56