#include <ruler.hh>
|
| | Ruler (RulerDrawStrategy::Ptr strategy, GtkWidget *drawingArea) |
| |
| void | draw (GtkWidget *widget, cairo_t *cr) |
| |
| void | updateAllocatedSize (int newWidth, int newHeight) |
| |
| void | updateMajorTickInterval () |
| |
| void | drawTicks (cairo_t *cr, double lower, double upper, double lineLength) |
| |
| void | drawSingleTick (cairo_t *cr, double linePosition, double lineLength, bool drawLabel, const std::string &label) |
| |
| void | drawSubTicks (cairo_t *cr, double lower, double upper, int depth, double lineLength) |
| |
|
| static gboolean | drawCallback (GtkWidget *widget, cairo_t *cr, gpointer data) |
| |
| static void | sizeAllocateCallback (GtkWidget *widget, GdkRectangle *allocation, gpointer data) |
| |
This class draws a ruler to a GtkDrawingArea. It is intended as a replacement for the old GTK2 ruler widget and is written to mimic that widget's behavior as close as possible.
◆ Ptr
◆ Orientation
| Enumerator |
|---|
| HORIZONTAL | |
| VERTICAL | |
◆ ~Ruler()
51 g_signal_handlers_disconnect_by_data(
drawingArea,
this);
◆ Ruler() [1/3]
| Ruler::Ruler |
( |
const Ruler & |
| ) |
|
|
delete |
◆ Ruler() [2/3]
| Ruler::Ruler |
( |
Ruler && |
| ) |
|
|
delete |
◆ Ruler() [3/3]
Creates a Ruler.
- Parameters
-
| rulerOrientation | The rulerOrientation of the ruler. |
| drawingArea | The GtkDrawingArea to draw the ruler to. |
29 ,
width{gtk_widget_get_allocated_width(drawingAreaWidget)}
30 ,
height{gtk_widget_get_allocated_height(drawingAreaWidget)}
42 g_signal_connect(drawingAreaWidget,
"draw", G_CALLBACK(
drawCallback),
this);
◆ create()
Creates a ruler.
- Parameters
-
| orientation | The orientation of the ruler. |
| drawArea | The GtkDrawingArea to draw the ruler to. |
- Returns
- The newly created ruler.
Referenced by BOOST_AUTO_TEST_CASE().
◆ draw()
| void Ruler::draw |
( |
GtkWidget * |
widget, |
|
|
cairo_t * |
cr |
|
) |
| |
|
private |
Draws the ruler to the given Cairo context.
- Parameters
-
| widget | The widget that received the draw signal. |
| cr | Cairo context to draw to. |
117 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
118 cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
121 GtkStyleContext* context = gtk_widget_get_style_context(widget);
122 gtk_render_background(context, cr, 0, 0,
width,
height);
125 gdk_cairo_set_source_rgba(cr, &
lineColor);
Referenced by drawCallback().
◆ drawCallback()
| gboolean Ruler::drawCallback |
( |
GtkWidget * |
widget, |
|
|
cairo_t * |
cr, |
|
|
gpointer |
data |
|
) |
| |
|
staticprivate |
A callback to be connected to a GtkDrawingArea's "draw" signal. Draws the ruler to the drawing area.
- Parameters
-
| widget | The widget that received the signal. |
| cr | Cairo context to draw to. |
| data | Pointer to a ruler instance. |
- Returns
- TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
108 auto* ruler =
static_cast<Ruler*
>(data);
109 ruler->
draw(widget, cr);
◆ drawSingleTick()
| void Ruler::drawSingleTick |
( |
cairo_t * |
cr, |
|
|
double |
linePosition, |
|
|
double |
lineLength, |
|
|
bool |
drawLabel, |
|
|
const std::string & |
label |
|
) |
| |
|
private |
Draws a single tick, taking into account the ruler's orientation.
- Parameters
-
| cr | Cairo context to draw to. |
| linePosition | The position of the line along the ruler. |
| lineLength | Length of the line in pixels. |
| drawLabel | True if a label should be drawn to the right/top of the line. |
| label | The label to draw if drawLabel is true. |
170 const double DRAW_AREA_SIZE =
drawStrategy->getDrawAreaSize();
172 if(0 < linePosition && linePosition < DRAW_AREA_SIZE)
184 cairo_select_font_face(cr,
"sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
Referenced by drawSubTicks(), and drawTicks().
◆ drawSubTicks()
| void Ruler::drawSubTicks |
( |
cairo_t * |
cr, |
|
|
double |
lower, |
|
|
double |
upper, |
|
|
int |
depth, |
|
|
double |
lineLength |
|
) |
| |
|
private |
Draws the smaller ticks in between the major ticks from left-to-right / bottom-to-top.
- Parameters
-
| cr | Cairo context to draw to. |
| lower | The lower limit of the range in draw space. |
| upper | The upper limit of the range in draw space. |
| depth | The depth of this recursive function. Functions as an index into the ruler's SUBTICK_SEGMENTS array. |
| lineLength | Length of the lines in pixels. |
202 const double interval = abs(upper - lower) / numSegments;
211 const double DRAW_AREA_SIZE =
drawStrategy->getDrawAreaSize();
212 const double limit = DRAW_AREA_SIZE;
219 while(tick < numSegments && pos < limit)
Referenced by drawTicks().
◆ drawTicks()
| void Ruler::drawTicks |
( |
cairo_t * |
cr, |
|
|
double |
lower, |
|
|
double |
upper, |
|
|
double |
lineLength |
|
) |
| |
|
private |
Draws the tick marks of the ruler for a given subset of the range from left-to-right / bottom-to-top.
- Parameters
-
| cr | Cairo context to draw to. |
| lower | The lower limit of the range to draw. |
| upper | The upper limit of the range to draw. |
| lineLength | Length of the lines in pixels. |
149 const double DRAW_AREA_ORIGIN = 0;
152 const double DRAW_AREA_SIZE =
drawStrategy->getDrawAreaSize();
Referenced by draw().
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ setRange()
| void Ruler::setRange |
( |
double |
lower, |
|
|
double |
upper |
|
) |
| |
Sets the range for the ruler to display.
- Parameters
-
| lower | Lower limit of the ruler range. Must be strictly less than upper. |
| upper | Upper limit of the ruler range. Must be strictly greater than lower. |
◆ sizeAllocateCallback()
| void Ruler::sizeAllocateCallback |
( |
GtkWidget * |
widget, |
|
|
GdkRectangle * |
allocation, |
|
|
gpointer |
data |
|
) |
| |
|
staticprivate |
A callback to be connected to a GtkDrawingArea's "size-allocate" signal. Updates the internal state of the ruler when the size of the ruler changes.
- Parameters
-
| widget | The widget that received the signal. |
| allocation | The region which has been allocated to the widget. |
| data | Pointer to a ruler instance. |
78 auto* ruler =
static_cast<Ruler*
>(data);
80 const int width = gtk_widget_get_allocated_width(widget);
81 const int height = gtk_widget_get_allocated_height(widget);
◆ updateAllocatedSize()
| void Ruler::updateAllocatedSize |
( |
int |
newWidth, |
|
|
int |
newHeight |
|
) |
| |
|
private |
Updates the stored allocated size of the ruler.
- Parameters
-
| newWidth | The newWidth of the ruler in pixels. |
| newHeight | The newHeight of the ruler in pixels. |
69 this->
width = newWidth;
◆ updateMajorTickInterval()
| void Ruler::updateMajorTickInterval |
( |
| ) |
|
|
private |
◆ DEFAULT_LOWER
| constexpr double Ruler::DEFAULT_LOWER {0} |
|
staticconstexprprivate |
◆ DEFAULT_UPPER
| constexpr double Ruler::DEFAULT_UPPER {10} |
|
staticconstexprprivate |
◆ drawingArea
| GtkWidget* Ruler::drawingArea {} |
|
private |
◆ drawStrategy
◆ FONT_SIZE
| constexpr double Ruler::FONT_SIZE {11} |
|
staticconstexprprivate |
◆ height
◆ LABEL_ALIGN
| constexpr double Ruler::LABEL_ALIGN {0.7} |
|
staticconstexprprivate |
Alignment of tick label along the tick line as a fraction of line height.
Referenced by drawSingleTick().
◆ LABEL_OFFSET
| constexpr double Ruler::LABEL_OFFSET {4} |
|
staticconstexprprivate |
Offset of tick label from the tick line in pixels.
Referenced by drawSingleTick().
◆ LINE_MULTIPLIER
| constexpr double Ruler::LINE_MULTIPLIER {0.6} |
|
staticconstexprprivate |
The length of a tick one "level" down, as a fraction of the line length of the ticks one level up.
Referenced by drawSubTicks(), and drawTicks().
◆ LINE_WIDTH
| constexpr double Ruler::LINE_WIDTH {1} |
|
staticconstexprprivate |
◆ lineColor
| GdkRGBA Ruler::lineColor {0, 0, 0, 1} |
|
private |
◆ lowerLimit
◆ MAJOR_TICK_LENGTH
| constexpr double Ruler::MAJOR_TICK_LENGTH {0.8} |
|
staticconstexprprivate |
Length of the major tick lines as a fraction of the width/height.
Referenced by draw().
◆ majorInterval
| int Ruler::majorInterval {1} |
|
private |
◆ majorTickSpacing
| int Ruler::majorTickSpacing {} |
|
private |
◆ MIN_SPACE_SUBTICKS
| constexpr int Ruler::MIN_SPACE_SUBTICKS {5} |
|
staticconstexprprivate |
◆ SUBTICK_SEGMENTS
| constexpr static std::array<int, 2> Ruler::SUBTICK_SEGMENTS {5, 2} |
|
staticconstexprprivate |
Each space between major ticks is split into 5 smaller segments and those segments are split into 2. (Assuming there's enough space.)
Referenced by drawSubTicks().
◆ upperLimit
◆ width
The documentation for this class was generated from the following files:
Ruler(const Ruler &)=delete
void drawSingleTick(cairo_t *cr, double linePosition, double lineLength, bool drawLabel, const std::string &label)
Definition: ruler.cc:168
static int intervalPixelSpacing(double interval, double lower, double upper, double allocatedSize)
Definition: ruler.cc:294
static gboolean drawCallback(GtkWidget *widget, cairo_t *cr, gpointer data)
Definition: ruler.cc:106
static constexpr double LABEL_ALIGN
Definition: ruler.hh:86
void drawTicks(cairo_t *cr, double lower, double upper, double lineLength)
Definition: ruler.cc:144
static void sizeAllocateCallback(GtkWidget *widget, GdkRectangle *allocation, gpointer data)
Definition: ruler.cc:76
int width
Definition: ruler.hh:64
void updateMajorTickInterval()
Definition: ruler.cc:86
static constexpr double LINE_MULTIPLIER
Definition: ruler.hh:89
static RulerDrawStrategy::Ptr create()
Definition: rulerstrategies.cc:18
#define require(expr)
Definition: assertions.hh:28
static int firstTick(double lower, int interval)
Definition: ruler.cc:303
GdkRGBA lineColor
Definition: ruler.hh:91
static constexpr double MAJOR_TICK_LENGTH
Definition: ruler.hh:96
int majorInterval
Definition: ruler.hh:68
void draw(GtkWidget *widget, cairo_t *cr)
Definition: ruler.cc:114
@ VERTICAL
Definition: ruler.hh:23
static constexpr double LABEL_OFFSET
Definition: ruler.hh:83
constexpr static std::array< int, 2 > SUBTICK_SEGMENTS
Definition: ruler.hh:57
static double scaleToRange(double x, double src_lower, double src_upper, double dest_lower, double dest_upper)
Definition: ruler.cc:235
static constexpr double LINE_WIDTH
Definition: ruler.hh:93
int height
Definition: ruler.hh:65
std::string to_string(const BitmapMetaData &bmd)
Definition: layerspecforbitmap.cc:30
void drawSubTicks(cairo_t *cr, double lower, double upper, int depth, double lineLength)
Definition: ruler.cc:193
double upperLimit
Definition: ruler.hh:61
RulerDrawStrategy::Ptr drawStrategy
Definition: ruler.hh:75
double lowerLimit
Definition: ruler.hh:60
GtkWidget * drawingArea
Definition: ruler.hh:48
static constexpr int MIN_SPACE_SUBTICKS
Definition: ruler.hh:78
boost::shared_ptr< Ruler > Ptr
Definition: ruler.hh:18
static constexpr double FONT_SIZE
Definition: ruler.hh:80
int majorTickSpacing
Definition: ruler.hh:71
static int calculateInterval(double lower, double upper, double allocatedSize)
Definition: ruler.cc:244
@ HORIZONTAL
Definition: ruler.hh:22
static RulerDrawStrategy::Ptr create()
Definition: rulerstrategies.cc:16