Scroom  0.14
TransformPresentation Class Reference

#include <transformpresentation.hh>

Inheritance diagram for TransformPresentation:
Inheritance graph
Collaboration diagram for TransformPresentation:
Collaboration graph

Public Types

using Ptr = boost::shared_ptr< TransformPresentation >
 
- Public Types inherited from PresentationInterface
using Ptr = boost::shared_ptr< PresentationInterface >
 
using WeakPtr = boost::weak_ptr< PresentationInterface >
 
- Public Types inherited from Viewable
using Ptr = boost::shared_ptr< Viewable >
 
using WeakPtr = boost::weak_ptr< Viewable >
 
- Public Types inherited from Scroom::Utils::Observable< T >
using Observer = boost::shared_ptr< T >
 
using Ptr = boost::shared_ptr< Observable< T > >
 
- Public Types inherited from Colormappable
using Ptr = boost::shared_ptr< Colormappable >
 
using WeakPtr = boost::weak_ptr< Colormappable >
 
- Public Types inherited from PipetteViewInterface
using Ptr = boost::shared_ptr< PipetteViewInterface >
 
- Public Types inherited from ShowMetadataInterface
using Ptr = boost::shared_ptr< ShowMetadataInterface >
 

Public Member Functions

void open (ViewInterface::WeakPtr vi) override
 
void close (ViewInterface::WeakPtr vi) override
 
Scroom::Utils::Rectangle< double > getRect () override
 
void redraw (ViewInterface::Ptr const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > presentationArea, int zoom) override
 
bool getProperty (const std::string &name, std::string &value) override
 
bool isPropertyDefined (const std::string &name) override
 
std::string getTitle () override
 
Scroom::Utils::Point< double > getAspectRatio () const override
 
PipetteLayerOperations::PipetteColor getPixelAverages (Scroom::Utils::Rectangle< double > area) override
 
void setColormap (Colormap::Ptr colormap) override
 
Colormap::Ptr getOriginalColormap () override
 
int getNumberOfColors () override
 
Color getMonochromeColor () override
 
void setMonochromeColor (const Color &c) override
 
void setTransparentBackground () override
 
void disableTransparentBackground () override
 
bool getTransparentBackground () override
 
void showMetadata (GtkWindow *parent) override
 
- Public Member Functions inherited from Scroom::Utils::Observable< T >
 Observable ()
 
 ~Observable () override
 
 Observable (const Observable &)=delete
 
 Observable (Observable &&)=delete
 
Observable operator= (const Observable &)=delete
 
Observable operator= (Observable &&)=delete
 
Scroom::Bookkeeping::Token registerStrongObserver (Observer const &observer)
 
Scroom::Bookkeeping::Token registerObserver (ObserverWeak const &observer)
 
For monochrome presentations: Set/Get the current color
Manipulate the "Transparent Background" setting of the presentation
- 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 >
boost::shared_ptr< R > shared_from_this ()
 
template<typename R >
boost::shared_ptr< R const > shared_from_this () const
 

Static Public Member Functions

static Ptr create (PresentationInterface::Ptr const &presentation, TransformationData::Ptr const &transformationData)
 

Private Member Functions

 TransformPresentation (PresentationInterface::Ptr const &presentation, TransformationData::Ptr transformationData)
 

Private Attributes

TransformationData::Ptr transformationData
 
PresentationInterface::Ptr presentation
 
Colormappable::Ptr colormappable
 
ShowMetadataInterface::Ptr showMetaDataInterface
 
std::map< ViewInterface::WeakPtr, Detail::ViewData::PtrviewData
 

Additional Inherited Members

- Protected Member Functions inherited from PresentationBase
void observerAdded (Viewable::Ptr const &viewable, Scroom::Bookkeeping::Token const &t) override
 
- Protected Member Functions inherited from Scroom::Utils::Observable< T >
std::list< ObservergetObservers ()
 
virtual void observerAdded (Observer const &observer, Scroom::Bookkeeping::Token const &token)
 

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ TransformPresentation()

TransformPresentation::TransformPresentation ( PresentationInterface::Ptr const &  presentation,
TransformationData::Ptr  transformationData 
)
private
44  : transformationData(std::move(transformationData_))
45  , presentation(presentation_)
46  , colormappable(boost::dynamic_pointer_cast<Colormappable>(presentation_))
47  , showMetaDataInterface(boost::dynamic_pointer_cast<ShowMetadataInterface>(presentation_))
48 {
49 }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ close()

void TransformPresentation::close ( ViewInterface::WeakPtr  vi)
overridevirtual

Gets called just before the View is destroyed

Precondition
Should be called from within a Gdk critical section (i.e. between gdk_threads_enter() and gdk_threads_leave() calls)

Reimplemented from PresentationBase.

73 {
74  auto data = viewData.at(viewInterface);
75  viewData.erase(viewInterface);
76 
77  PresentationBase::close(viewInterface);
78  presentation->close(data);
79 }
Here is the call graph for this function:

◆ create()

TransformPresentation::Ptr TransformPresentation::create ( PresentationInterface::Ptr const &  presentation,
TransformationData::Ptr const &  transformationData 
)
static
53 {
55 }

Referenced by anonymous_namespace{tiledbitmappresentation.cc}::OpenTiledBitmapAsPresentation::open(), and TEST().

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

◆ disableTransparentBackground()

void TransformPresentation::disableTransparentBackground ( )
overridevirtual

Implements Colormappable.

136 { colormappable->disableTransparentBackground(); }

◆ getAspectRatio()

Scroom::Utils::Point< double > TransformPresentation::getAspectRatio ( ) const
overridevirtual

Reimplemented from PresentationInterface.

149 { return transformationData->getAspectRatio(); }

Referenced by getPixelAverages().

Here is the caller graph for this function:

◆ getMonochromeColor()

Color TransformPresentation::getMonochromeColor ( )
overridevirtual

Implements Colormappable.

130 { return colormappable->getMonochromeColor(); }

◆ getNumberOfColors()

int TransformPresentation::getNumberOfColors ( )
overridevirtual

Retrieve the number of colors in use by the presentation

Implements Colormappable.

128 { return colormappable->getNumberOfColors(); }

◆ getOriginalColormap()

Colormap::Ptr TransformPresentation::getOriginalColormap ( )
overridevirtual

Retrieve the images colormap (if any)

Implements Colormappable.

126 { return colormappable->getOriginalColormap(); }

◆ getPixelAverages()

PipetteLayerOperations::PipetteColor TransformPresentation::getPixelAverages ( Scroom::Utils::Rectangle< double >  area)
overridevirtual

Returns the average pixel values for each component, contained in the area.

Parameters
areaselected area to get the pixel values from.

Implements PipetteViewInterface.

143 {
144  PipetteViewInterface::Ptr const pipettePresentation = boost::dynamic_pointer_cast<PipetteViewInterface>(presentation);
145  require(pipettePresentation);
146  return pipettePresentation->getPixelAverages(area / getAspectRatio());
147 }
Here is the call graph for this function:

◆ getProperty()

bool TransformPresentation::getProperty ( const std::string &  name,
std::string &  value 
)
overridevirtual

Return the value of the requested property

Parameters
[in]nameThe name of the requested property
[out]valueThe value of the requested property
Return values
trueif the property existed
falseif the property didn't exist

Implements PresentationInterface.

116 {
117  return presentation->getProperty(name, value);
118 }

◆ getRect()

Scroom::Utils::Rectangle< double > TransformPresentation::getRect ( )
overridevirtual

Return the dimensions of your presentation

Implements PresentationInterface.

58 {
59  return presentation->getRect() * transformationData->getAspectRatio();
60 }

◆ getTitle()

std::string TransformPresentation::getTitle ( )
overridevirtual

Return the title of the presentation

Implements PresentationInterface.

122 { return presentation->getTitle(); }

◆ getTransparentBackground()

bool TransformPresentation::getTransparentBackground ( )
overridevirtual

Implements Colormappable.

138 { return colormappable->getTransparentBackground(); }

◆ isPropertyDefined()

bool TransformPresentation::isPropertyDefined ( const std::string &  name)
overridevirtual

Return true if the named property exists

Implements PresentationInterface.

120 { return presentation->isPropertyDefined(name); }

◆ open()

void TransformPresentation::open ( ViewInterface::WeakPtr  vi)
overridevirtual

Gets called just after the View is created

Precondition
Should be called from within a Gdk critical section (i.e. between gdk_threads_enter() and gdk_threads_leave() calls)

Reimplemented from PresentationBase.

63 {
64  auto [it, inserted] = viewData.insert({viewInterface, Detail::ViewData::create(viewInterface)});
65  require(inserted);
66  auto& [_, data] = *it;
67 
68  presentation->open(data);
69  PresentationBase::open(viewInterface);
70 }
Here is the call graph for this function:

◆ redraw()

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

Draw the requested ara at the requested zoom level

Parameters
viThe ViewInterface on whose behalf the request is made
crThe context to draw the area on
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 of your presentation should have size 2**zoom when drawn. zoom may be negative.

Implements PresentationInterface.

85 {
86  Scroom::Utils::Point<double> const aspectRatio = transformationData->getAspectRatio();
87  const auto data = viewData.at(vi);
88 
89  if(data->presentationArea != presentationArea || data->zoom != zoom)
90  {
91  data->image.reset();
92  }
93  if(!data->image)
94  {
95  auto pixelSize = pixelSizeFromZoom(zoom);
96  auto viewArea = ceil((presentationArea * pixelSize / aspectRatio).getSize()).to<int>();
97 
98  data->image = Scroom::Bitmap::BitmapSurface::create(viewArea.x, viewArea.y, CAIRO_FORMAT_ARGB32);
99 
100  cairo_surface_t* surface = data->image->get();
101  cairo_t* image_cr = cairo_create(surface);
102 
103  presentation->redraw(data, image_cr, presentationArea / aspectRatio, zoom);
104 
105  cairo_destroy(image_cr);
106  }
107 
108  cairo_save(cr);
109  cairo_scale(cr, aspectRatio.x, aspectRatio.y);
110  cairo_set_source_surface(cr, data->image->get(), 0, 0);
111  cairo_paint(cr);
112  cairo_restore(cr);
113 }
Here is the call graph for this function:

◆ setColormap()

void TransformPresentation::setColormap ( Colormap::Ptr  colormap)
overridevirtual

Request that the presentation use the given colormap

Implements Colormappable.

124 { colormappable->setColormap(colormap); }

◆ setMonochromeColor()

void TransformPresentation::setMonochromeColor ( const Color c)
overridevirtual

Implements Colormappable.

132 { colormappable->setMonochromeColor(c); }

◆ setTransparentBackground()

void TransformPresentation::setTransparentBackground ( )
overridevirtual

Implements Colormappable.

134 { colormappable->setTransparentBackground(); }

◆ showMetadata()

void TransformPresentation::showMetadata ( GtkWindow *  parent)
overridevirtual

Request to show a window containing the presentation metadata

Parameters
parentthe parent window, if found. Nullptr otherwise

Implements ShowMetadataInterface.

140 { showMetaDataInterface->showMetadata(parent); }

Member Data Documentation

◆ colormappable

◆ presentation

◆ showMetaDataInterface

ShowMetadataInterface::Ptr TransformPresentation::showMetaDataInterface
private

Referenced by showMetadata().

◆ transformationData

TransformationData::Ptr TransformPresentation::transformationData
private

◆ viewData

std::map<ViewInterface::WeakPtr, Detail::ViewData::Ptr> TransformPresentation::viewData
private

Referenced by close(), open(), and redraw().


The documentation for this class was generated from the following files:
require
#define require(expr)
Definition: assertions.hh:28
TransformPresentation::getAspectRatio
Scroom::Utils::Point< double > getAspectRatio() const override
Definition: transformpresentation.cc:149
Scroom::Utils::Point::x
value_type x
Definition: point.hh:111
Scroom::Bitmap::BitmapSurface::create
static Ptr create(int width, int height, cairo_format_t format)
Definition: bitmap-helpers.cc:13
PipetteViewInterface::Ptr
boost::shared_ptr< PipetteViewInterface > Ptr
Definition: pipetteviewinterface.hh:21
Scroom::Utils::ceil
Point< T > ceil(Point< T > p)
Definition: point.hh:228
TransformPresentation::Ptr
boost::shared_ptr< TransformPresentation > Ptr
Definition: transformpresentation.hh:83
colormap
const Colormap::Ptr colormap
Definition: colormaphelpers_test.cc:54
TransformPresentation::showMetaDataInterface
ShowMetadataInterface::Ptr showMetaDataInterface
Definition: transformpresentation.hh:89
PresentationBase::open
void open(ViewInterface::WeakPtr vi) override
Definition: presentationinterface.cc:11
TransformPresentation::presentation
PresentationInterface::Ptr presentation
Definition: transformpresentation.hh:87
PresentationBase::close
void close(ViewInterface::WeakPtr vi) override
Definition: presentationinterface.cc:23
pixelSizeFromZoom
double pixelSizeFromZoom(int zoom)
Definition: cairo-helpers.cc:112
TransformPresentation::colormappable
Colormappable::Ptr colormappable
Definition: transformpresentation.hh:88
Detail::ViewData::create
static ViewData::Ptr create(const ViewInterface::WeakPtr &parent)
Definition: transformpresentation.cc:176
TransformPresentation::viewData
std::map< ViewInterface::WeakPtr, Detail::ViewData::Ptr > viewData
Definition: transformpresentation.hh:90
TransformPresentation::TransformPresentation
TransformPresentation(PresentationInterface::Ptr const &presentation, TransformationData::Ptr transformationData)
Definition: transformpresentation.cc:42
Scroom::Utils::Point::y
value_type y
Definition: point.hh:112
TransformPresentation::transformationData
TransformationData::Ptr transformationData
Definition: transformpresentation.hh:86
Scroom::Utils::Point< double >