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

#include <measure.hh>

Inheritance diagram for MeasureHandler:
Inheritance graph
Collaboration diagram for MeasureHandler:
Collaboration graph

Public Types

using Ptr = std::shared_ptr< MeasureHandler >
 
- Public Types inherited from ToolStateListener
using Ptr = std::shared_ptr< ToolStateListener >
 
- Public Types inherited from PostRenderer
using Ptr = std::shared_ptr< PostRenderer >
 
- Public Types inherited from SelectionListener
using Ptr = std::shared_ptr< SelectionListener >
 

Public Member Functions

void render (ViewInterface::Ptr const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > presentationArea, int zoom) override
 
void onSelectionStart (Selection p, ViewInterface::Ptr view) override
 
void onSelectionUpdate (Selection s, ViewInterface::Ptr view) override
 
void onSelectionEnd (Selection s, ViewInterface::Ptr view) override
 
void onEnable () override
 
void onDisable () override
 
- Public Member Functions inherited from SelectionListener
virtual std::string getSelectionType ()
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
std::shared_ptr< R > shared_from_this ()
 
template<typename R >
std::shared_ptr< R const > shared_from_this () const
 

Static Public Member Functions

static Ptr create ()
 

Private Member Functions

virtual void displayMeasurement (const ViewInterface::Ptr &view)
 
virtual void drawCross (cairo_t *cr, Scroom::Utils::Point< double > p)
 

Private Attributes

std::optional< Selectionselection
 
bool enabled {false}
 

Member Typedef Documentation

◆ Ptr

using MeasureHandler::Ptr = std::shared_ptr<MeasureHandler>

Member Function Documentation

◆ create()

MeasureHandler::Ptr MeasureHandler::create ( )
static
64{ return std::make_shared<MeasureHandler>(); }

Referenced by Measure::viewAdded().

Here is the caller graph for this function:

◆ displayMeasurement()

void MeasureHandler::displayMeasurement ( const ViewInterface::Ptr view)
privatevirtual
67{
68 const auto aspectRatio = getAspectRatio(view->getCurrentPresentation());
69 const Selection tweaked(selection->start / aspectRatio, selection->end / aspectRatio);
70
71 view->setStatusMessage(
72 fmt::format(
73 "l: {:.1f}, dx: {}, dy: {}, from: {}, to: {}",
74 tweaked.length(),
75 tweaked.width(),
76 tweaked.height(),
77 tweaked.start,
78 tweaked.end
79 )
80 );
81}
std::optional< Selection > selection
Definition measure.hh:27
const auto view
Definition pipette-tests.cc:227
Definition viewinterface.hh:37
Scroom::Utils::Point< double > getAspectRatio(const PresentationInterface::Ptr &presentation)
Definition transformpresentation.cc:162

Referenced by onSelectionEnd(), and onSelectionUpdate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawCross()

void MeasureHandler::drawCross ( cairo_t *  cr,
Scroom::Utils::Point< double >  p 
)
privatevirtual
84{
85 static const int size = 10;
86 cairo_move_to(cr, p.x - size, p.y);
87 cairo_line_to(cr, p.x + size, p.y);
88 cairo_move_to(cr, p.x, p.y - size);
89 cairo_line_to(cr, p.x, p.y + size);
90}
PresentationInterfaceStub::Ptr const p
Definition determine-size-test.cc:172
cairo_t * cr
Definition transformpresentation_test.cc:72

Referenced by render().

Here is the caller graph for this function:

◆ onDisable()

void MeasureHandler::onDisable ( )
overridevirtual

Then function is called whenever the tool button is deselected.

Implements ToolStateListener.

150{
151 selection.reset();
152 enabled = false;
153}
bool enabled
Definition measure.hh:28

◆ onEnable()

void MeasureHandler::onEnable ( )
overridevirtual

This function is called whenever the tool button is selected.

Implements ToolStateListener.

155{ enabled = true; }

◆ onSelectionEnd()

void MeasureHandler::onSelectionEnd ( Selection  selection,
ViewInterface::Ptr  view 
)
overridevirtual

This function is called whenever the selection ends. That is, whenever the user releases the mouse button that was pressed.

The final selection is passed as an argument.

See also
Selection

Implements SelectionListener.

108{
109 if(enabled)
110 {
111 selection = s;
113 }
114}
virtual void displayMeasurement(const ViewInterface::Ptr &view)
Definition measure.cc:66
BitmapSurface::Ptr const s
Definition transformpresentation_test.cc:70
Here is the call graph for this function:

◆ onSelectionStart()

void MeasureHandler::onSelectionStart ( Selection  selection,
ViewInterface::Ptr  view 
)
overridevirtual

This function is called whenever the user clicks a view. The point that is clicked is passed as an argument.

The passed point is a point in the presentation coordinate space.

Implements SelectionListener.

96{}

◆ onSelectionUpdate()

void MeasureHandler::onSelectionUpdate ( Selection  selection,
ViewInterface::Ptr  view 
)
overridevirtual

This function is called whenever the selection updates. That is, whenever the user moves the mouse while keeping the mouse button pressed.

The updated selection is passed as an argument.

See also
Selection

Implements SelectionListener.

99{
100 if(enabled)
101 {
102 selection = s;
104 }
105}
Here is the call graph for this function:

◆ render()

void MeasureHandler::render ( ViewInterface::Ptr const &  vi,
cairo_t *  cr,
Scroom::Utils::Rectangle< double >  presentationArea,
int  zoom 
)
overridevirtual

This function is called after the presentation finishes redrawing.

Parameters
viThe ViewInterface on whose behalf the request is made
crThe context to with, the origin of the context is translated to be the same as the origin of the presentation.
presentationAreathe area that is to be drawn. The given x and y coordinates should map on 0,0 of the given context cr.
zoomThe requested zoom level. One pixel should have size 2**zoom when drawn. zoom may be negative.

Implements PostRenderer.

126{
127 if(selection)
128 {
129 const auto pixelSize = pixelSizeFromZoom(zoom);
130 const auto start = (selection->start - presentationArea.getTopLeft()) * pixelSize;
131 const auto end = (selection->end - presentationArea.getTopLeft()) * pixelSize;
132
133 cairo_set_line_width(cr, 1);
134 cairo_set_source_rgb(cr, 0.75, 0, 0); // Dark Red
136 drawCross(cr, end);
137 cairo_stroke(cr);
138 cairo_set_source_rgb(cr, 1, 0, 0); // Red
139 cairo_move_to(cr, start.x, start.y);
140 cairo_line_to(cr, end.x, end.y);
141 cairo_stroke(cr);
142 }
143}
double pixelSizeFromZoom(int zoom)
Definition cairo-helpers.cc:123
virtual void drawCross(cairo_t *cr, Scroom::Utils::Point< double > p)
Definition measure.cc:83
xy_type getTopLeft() const
Definition rectangle.hh:133
const SampleIterator< const uint8_t > start(nullptr, initial_offset, bps)
Here is the call graph for this function:

Member Data Documentation

◆ enabled

bool MeasureHandler::enabled {false}
private
28{false};

Referenced by onDisable(), onEnable(), onSelectionEnd(), and onSelectionUpdate().

◆ selection

std::optional<Selection> MeasureHandler::selection
private

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