Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
VerticalDrawStrategy Class Reference

#include <rulerstrategies.hh>

Inheritance diagram for VerticalDrawStrategy:
Inheritance graph
Collaboration diagram for VerticalDrawStrategy:
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 = std::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 vertical ruler.

Member Function Documentation

◆ create()

RulerDrawStrategy::Ptr VerticalDrawStrategy::create ( )
static

Creates a new VerticalDrawStrategy.

Returns
A new VerticalDrawStrategy.
std::shared_ptr< RulerDrawStrategy > Ptr
Definition rulerstrategies.hh:17
Definition rulerstrategies.hh:138

Referenced by Ruler::create().

Here is the caller graph for this function:

◆ drawOutline()

void VerticalDrawStrategy::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.

53{
54 const int width_ = getWidth();
55 const int height_ = getHeight();
56
57 cairo_set_line_width(cr, lineWidth);
58 const double DRAW_OFFSET = lineWidth * LINE_COORD_OFFSET;
59
60 // Draw line along top side of ruler
61 cairo_move_to(cr, 0, DRAW_OFFSET);
62 cairo_line_to(cr, width_, DRAW_OFFSET);
63
64 // Draw line along bottom side of ruler
65 cairo_move_to(cr, 0, height_ - DRAW_OFFSET);
66 cairo_line_to(cr, width_, height_ - DRAW_OFFSET);
67
68 // Draw thicker border along right of ruler
69 cairo_move_to(cr, width_ - DRAW_OFFSET, 0);
70 cairo_line_to(cr, width_ - DRAW_OFFSET, height_);
71
72 // Render all lines
73 cairo_stroke(cr);
74}
static constexpr double LINE_COORD_OFFSET
Definition rulerstrategies.hh:97
int getWidth() const
Definition rulerstrategies.cc:12
int getHeight() const
Definition rulerstrategies.cc:14
cairo_t * cr
Definition transformpresentation_test.cc:72
Here is the call graph for this function:

◆ drawTickLine()

void VerticalDrawStrategy::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.

90{
91 const int width_ = getWidth();
92
93 cairo_set_line_width(cr, lineWidth);
94 const double DRAW_OFFSET = lineWidth * LINE_COORD_OFFSET;
95
96 // Draw horizontal line
97 cairo_move_to(cr, width_, linePosition + DRAW_OFFSET);
98 cairo_line_to(cr, width_ - round(lineLength), linePosition + DRAW_OFFSET);
99 cairo_stroke(cr);
100}
Here is the call graph for this function:

◆ drawTickText()

void VerticalDrawStrategy::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.

129{
130 const int width_ = getWidth();
131
132 // Get the extents of the text if it were drawn
133 cairo_text_extents_t textExtents;
134 cairo_text_extents(cr, label.c_str(), &textExtents);
135 // Center the text on the line
136 cairo_move_to(cr, width_ - labelAlign * lineLength - TEXT_ANCHOR * textExtents.y_bearing, linePosition - labelOffset);
137 // Draw text rotated 90 degrees anti-clockwise
138 cairo_rotate(cr, -M_PI / 2);
139 cairo_show_text(cr, label.c_str());
140}
static constexpr double TEXT_ANCHOR
Definition rulerstrategies.hh:98
Here is the call graph for this function:

◆ getDrawAreaSize()

double VerticalDrawStrategy::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.

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

◆ getMajorTickLength()

double VerticalDrawStrategy::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.

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

The documentation for this class was generated from the following files: