Scroom  0.14
HorizontalDrawStrategy Class Reference

#include <rulerstrategies.hh>

Inheritance diagram for HorizontalDrawStrategy:
Inheritance graph
Collaboration diagram for HorizontalDrawStrategy:
Collaboration graph

Public Member Functions

double getMajorTickLength (double percentage) override
 
double getDrawAreaSize () override
 
void drawOutline (cairo_t *cr, double lineWidth) override
 
void drawTickLine (cairo_t *cr, double linePosition, double lineWidth, double lineLength) override
 
void drawTickText (cairo_t *cr, const std::string &label, double linePosition, double labelOffset, double labelAlign, double lineLength) override
 
- Public Member Functions inherited from RulerDrawStrategy
void setAllocatedSize (int newWidth, int height)
 
int getWidth () const
 
int getHeight () const
 

Static Public Member Functions

static RulerDrawStrategy::Ptr create ()
 

Additional Inherited Members

- Public Types inherited from RulerDrawStrategy
using Ptr = boost::shared_ptr< RulerDrawStrategy >
 
- Static Protected Attributes inherited from RulerDrawStrategy
static constexpr double LINE_COORD_OFFSET {0.5}
 
static constexpr double TEXT_ANCHOR {0.5}
 

Detailed Description

This class implements the drawing code for a horizontal ruler.

Member Function Documentation

◆ create()

RulerDrawStrategy::Ptr HorizontalDrawStrategy::create ( )
static

Creates a new HorizontalDrawStrategy.

Returns
A new HorizontalDrawStrategy.

Referenced by Ruler::create().

Here is the caller graph for this function:

◆ drawOutline()

void HorizontalDrawStrategy::drawOutline ( cairo_t *  cr,
double  lineWidth 
)
overridevirtual

Draws the outline around the ruler.

Parameters
crCairo context to draw to.
lineWidthWidth of the outline in pixels.

Implements RulerDrawStrategy.

29 {
30  const int width_ = getWidth();
31  const int height_ = getHeight();
32 
33  cairo_set_line_width(cr, lineWidth);
34  const double DRAW_OFFSET = lineWidth * LINE_COORD_OFFSET;
35 
36  // Draw line along left side of ruler
37  cairo_move_to(cr, DRAW_OFFSET, 0);
38  cairo_line_to(cr, DRAW_OFFSET, height_);
39 
40  // Draw line along right side of ruler
41  cairo_move_to(cr, width_ - DRAW_OFFSET, 0);
42  cairo_line_to(cr, width_ - DRAW_OFFSET, height_);
43 
44  // Draw thicker border along bottom of ruler
45  cairo_move_to(cr, 0, height_ - DRAW_OFFSET);
46  cairo_line_to(cr, width_, height_ - DRAW_OFFSET);
47 
48  // Render all lines
49  cairo_stroke(cr);
50 }
Here is the call graph for this function:

◆ drawTickLine()

void HorizontalDrawStrategy::drawTickLine ( cairo_t *  cr,
double  linePosition,
double  lineWidth,
double  lineLength 
)
overridevirtual

Draws the line for a ruler tick.

Parameters
crCairo context to draw to.
linePositionPosition of the line along the ruler in pixels.
lineWidthWidth of the tick line in pixels.
lineLengthLength of the tick line in pixels.
widthAllocated width for the ruler in pixels.
heightAllocated height for the ruler in pixels.

Implements RulerDrawStrategy.

77 {
78  const int height_ = getHeight();
79 
80  cairo_set_line_width(cr, lineWidth);
81  const double DRAW_OFFSET = lineWidth * LINE_COORD_OFFSET;
82 
83  // Draw vertical line
84  cairo_move_to(cr, linePosition + DRAW_OFFSET, height_);
85  cairo_line_to(cr, linePosition + DRAW_OFFSET, height_ - round(lineLength));
86  cairo_stroke(cr);
87 }
Here is the call graph for this function:

◆ drawTickText()

void HorizontalDrawStrategy::drawTickText ( cairo_t *  cr,
const std::string &  label,
double  linePosition,
double  labelOffset,
double  labelAlign,
double  lineLength 
)
overridevirtual

Draws the label to the right of a tick line.

Parameters
crCairo context to draw to.
labelText to draw to right of tick line.
linePositionPosition of the line along the ruler in pixels.
labelOffsetOffset between tick line and label in pixels.
labelAlignAlignment of label along tick line as a fraction of line length.
lineLengthLength of the tick line in pixels.
widthAllocated width for the ruler in pixels.
heightAllocated height for the ruler in pixels.

Implements RulerDrawStrategy.

108 {
109  const int height_ = getHeight();
110 
111  // Get the extents of the text if it were drawn
112  cairo_text_extents_t textExtents;
113  cairo_text_extents(cr, label.c_str(), &textExtents);
114  // Center the text on the line
115  cairo_move_to(cr, linePosition + labelOffset, height_ - labelAlign * lineLength - TEXT_ANCHOR * textExtents.y_bearing);
116  cairo_show_text(cr, label.c_str());
117 }
Here is the call graph for this function:

◆ getDrawAreaSize()

double HorizontalDrawStrategy::getDrawAreaSize ( )
overridevirtual

Returns the length in pixels along the ruler. For a horizontal ruler, this is its width. For a vertical ruler, this is its height.

Parameters
widthAllocated width for the ruler in pixels.
heightAllocated height for the ruler in pixels.
Returns
The length in pixels along the ruler in pixels.

Implements RulerDrawStrategy.

24 { return getWidth(); }
Here is the call graph for this function:

◆ getMajorTickLength()

double HorizontalDrawStrategy::getMajorTickLength ( double  percentage)
overridevirtual

Returns the length of the major tick lines, given the ruler dimensions.

Parameters
widthAllocated width for the ruler in pixels.
heightAllocated height for the ruler in pixels.
percentagePercentage of the /p width or /p height to be the length of the major ticks.
Returns
The length of the major tick lines in pixels.

Implements RulerDrawStrategy.

20 { return percentage * getHeight(); }
Here is the call graph for this function:

The documentation for this class was generated from the following files:
RulerDrawStrategy::LINE_COORD_OFFSET
static constexpr double LINE_COORD_OFFSET
Definition: rulerstrategies.hh:95
RulerDrawStrategy::getHeight
int getHeight() const
Definition: rulerstrategies.cc:14
RulerDrawStrategy::TEXT_ANCHOR
static constexpr double TEXT_ANCHOR
Definition: rulerstrategies.hh:96
RulerDrawStrategy::Ptr
boost::shared_ptr< RulerDrawStrategy > Ptr
Definition: rulerstrategies.hh:17
HorizontalDrawStrategy
Definition: rulerstrategies.hh:108
RulerDrawStrategy::getWidth
int getWidth() const
Definition: rulerstrategies.cc:12