Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
ruler.hh
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <memory>
5
6#include <gtk/gtk.h>
7
8#include "rulerstrategies.hh"
9
15class Ruler
16{
17
18public:
19 using Ptr = std::shared_ptr<Ruler>;
20
26
33 static Ptr create(Orientation orientation, GtkWidget* drawArea);
34
35 ~Ruler();
36 Ruler(const Ruler&) = delete;
37 Ruler(Ruler&&) = delete;
38 Ruler operator=(const Ruler&) = delete;
39 Ruler operator=(Ruler&&) = delete;
40
46 void setRange(double lower, double upper);
47
48private:
49 GtkWidget* drawingArea{};
50
51 static constexpr double DEFAULT_LOWER{0};
52 static constexpr double DEFAULT_UPPER{10};
53
58 constexpr static std::array<int, 2> SUBTICK_SEGMENTS{5, 2};
59
60 // The range to be displayed.
63
64 // The allocated width and height for the drawing area widget.
65 int width{};
66 int height{};
67
70
73
74 // ==== DRAWING PROPERTIES ====
75
77
79 static constexpr int MIN_SPACE_SUBTICKS{5};
80
81 static constexpr double FONT_SIZE{11};
82
84 static constexpr double LABEL_OFFSET{4};
85
87 static constexpr double LABEL_ALIGN{0.7};
88
90 static constexpr double LINE_MULTIPLIER{0.6};
91
92 GdkRGBA lineColor{0, 0, 0, 1};
93
94 static constexpr double LINE_WIDTH{1};
95
97 static constexpr double MAJOR_TICK_LENGTH{0.8};
98
104 Ruler(RulerDrawStrategy::Ptr strategy, GtkWidget* drawingArea);
105
114 static gboolean drawCallback(GtkWidget* widget, cairo_t* cr, gpointer data);
115
121 void draw(GtkWidget* widget, cairo_t* cr);
122
130 static void sizeAllocateCallback(GtkWidget* widget, GdkRectangle* allocation, gpointer data);
131
137 void updateAllocatedSize(int newWidth, int newHeight);
138
143
151 void drawTicks(cairo_t* cr, double lower, double upper, double lineLength);
152
161 void drawSingleTick(cairo_t* cr, double linePosition, double lineLength, bool drawLabel, const std::string& label);
162
171 void drawSubTicks(cairo_t* cr, double lower, double upper, int depth, double lineLength);
172};
173
178{
179private:
181 constexpr static std::array<int, 4> VALID_INTERVALS{1, 5, 10, 25};
182
183public:
185 static constexpr int MIN_SPACE_MAJORTICKS{80};
186
194 static int calculateInterval(double lower, double upper, double allocatedSize);
195
204 static int intervalPixelSpacing(double interval, double lower, double upper, double allocatedSize);
205
212 static int firstTick(double lower, int interval);
213
224 static double scaleToRange(double x, double src_lower, double src_upper, double dest_lower, double dest_upper);
225};
uint8_t data
Definition blob-tests.cc:36
Definition ruler.hh:178
static double scaleToRange(double x, double src_lower, double src_upper, double dest_lower, double dest_upper)
Definition ruler.cc:235
static int calculateInterval(double lower, double upper, double allocatedSize)
Definition ruler.cc:244
static int firstTick(double lower, int interval)
Definition ruler.cc:303
static constexpr std::array< int, 4 > VALID_INTERVALS
Definition ruler.hh:181
static constexpr int MIN_SPACE_MAJORTICKS
Definition ruler.hh:185
static int intervalPixelSpacing(double interval, double lower, double upper, double allocatedSize)
Definition ruler.cc:294
std::shared_ptr< RulerDrawStrategy > Ptr
Definition rulerstrategies.hh:17
Definition ruler.hh:16
int width
Definition ruler.hh:65
double lowerLimit
Definition ruler.hh:61
int majorInterval
Definition ruler.hh:69
static constexpr int MIN_SPACE_SUBTICKS
Definition ruler.hh:79
static gboolean drawCallback(GtkWidget *widget, cairo_t *cr, gpointer data)
Definition ruler.cc:106
int height
Definition ruler.hh:66
void drawSingleTick(cairo_t *cr, double linePosition, double lineLength, bool drawLabel, const std::string &label)
Definition ruler.cc:168
static constexpr double MAJOR_TICK_LENGTH
Definition ruler.hh:97
static Ptr create(Orientation orientation, GtkWidget *drawArea)
Definition ruler.cc:12
static constexpr std::array< int, 2 > SUBTICK_SEGMENTS
Definition ruler.hh:58
Ruler(Ruler &&)=delete
void draw(GtkWidget *widget, cairo_t *cr)
Definition ruler.cc:114
static constexpr double LINE_WIDTH
Definition ruler.hh:94
void drawSubTicks(cairo_t *cr, double lower, double upper, int depth, double lineLength)
Definition ruler.cc:193
Ruler(const Ruler &)=delete
static constexpr double LINE_MULTIPLIER
Definition ruler.hh:90
GdkRGBA lineColor
Definition ruler.hh:92
void drawTicks(cairo_t *cr, double lower, double upper, double lineLength)
Definition ruler.cc:144
std::shared_ptr< Ruler > Ptr
Definition ruler.hh:19
Ruler operator=(Ruler &&)=delete
int majorTickSpacing
Definition ruler.hh:72
double upperLimit
Definition ruler.hh:62
Orientation
Definition ruler.hh:22
@ VERTICAL
Definition ruler.hh:24
@ HORIZONTAL
Definition ruler.hh:23
static constexpr double DEFAULT_UPPER
Definition ruler.hh:52
GtkWidget * drawingArea
Definition ruler.hh:49
Ruler operator=(const Ruler &)=delete
static constexpr double FONT_SIZE
Definition ruler.hh:81
RulerDrawStrategy::Ptr drawStrategy
Definition ruler.hh:76
static constexpr double LABEL_ALIGN
Definition ruler.hh:87
~Ruler()
Definition ruler.cc:48
void updateMajorTickInterval()
Definition ruler.cc:86
static void sizeAllocateCallback(GtkWidget *widget, GdkRectangle *allocation, gpointer data)
Definition ruler.cc:76
void updateAllocatedSize(int newWidth, int newHeight)
Definition ruler.cc:67
static constexpr double DEFAULT_LOWER
Definition ruler.hh:51
static constexpr double LABEL_OFFSET
Definition ruler.hh:84
void setRange(double lower, double upper)
Definition ruler.cc:56
cairo_t * cr
Definition transformpresentation_test.cc:72