Scroom  0.14
TransparentOverlayPresentation Class Reference

#include <transparentoverlaypresentation.hh>

Inheritance diagram for TransparentOverlayPresentation:
Inheritance graph
Collaboration diagram for TransparentOverlayPresentation:
Collaboration graph

Public Types

using Ptr = boost::shared_ptr< TransparentOverlayPresentation >
 
- 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 Aggregate
using Ptr = boost::shared_ptr< Aggregate >
 

Public Member Functions

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
 
void viewAdded (ViewInterface::WeakPtr vi) override
 
void viewRemoved (ViewInterface::WeakPtr vi) override
 
std::set< ViewInterface::WeakPtrgetViews () override
 
void addPresentation (PresentationInterface::Ptr const &p) override
 
- Public Member Functions inherited from PresentationBase
void open (ViewInterface::WeakPtr vi) override
 
void close (ViewInterface::WeakPtr vi) override
 
- Public Member Functions inherited from PresentationInterface
virtual Scroom::Utils::Point< double > getAspectRatio () const
 
- 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)
 

Static Public Member Functions

static Ptr create ()
 

Private Types

using ViewDataMap = std::map< ViewInterface::WeakPtr, TransparentOverlayViewInfo::Ptr >
 

Private Member Functions

 TransparentOverlayPresentation ()
 
void setOptimalColor (PresentationInterface::Ptr const &p)
 

Private Attributes

std::list< PresentationInterface::Ptrchildren
 
SizeDeterminer::Ptr sizeDeterminer
 
ViewDataMap viewData
 

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

◆ ViewDataMap

Constructor & Destructor Documentation

◆ TransparentOverlayPresentation()

TransparentOverlayPresentation::TransparentOverlayPresentation ( )
private
45 {
46 }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ addPresentation()

void TransparentOverlayPresentation::addPresentation ( PresentationInterface::Ptr const &  p)
overridevirtual

Implements Aggregate.

49 {
50  if(p)
51  {
52  if(p->isPropertyDefined(MONOCHROME_COLORMAPPABLE_PROPERTY_NAME))
53  {
54  setOptimalColor(p);
55  }
56 
57  children.push_back(p);
58  sizeDeterminer->add(p);
59 
60  for(ViewDataMap::value_type const& v: viewData)
61  {
62  v.second->addChild(p);
63  }
64  }
65  else
66  {
67  defect_message("Can't add a nonexistent presentation");
68  }
69 }
Here is the call graph for this function:

◆ create()

TransparentOverlayPresentation::Ptr TransparentOverlayPresentation::create ( )
static
41 { return Ptr(new TransparentOverlayPresentation()); }

Referenced by TransparentOverlay::createNew().

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

◆ getProperty()

bool TransparentOverlayPresentation::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.

145 {
146  UNUSED(name);
147  UNUSED(value);
148 
149  return false;
150 }

◆ getRect()

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

Return the dimensions of your presentation

Implements PresentationInterface.

102 { return sizeDeterminer->getRect(); }

◆ getTitle()

std::string TransparentOverlayPresentation::getTitle ( )
overridevirtual

Return the title of the presentation

Implements PresentationInterface.

159 {
160  std::stringstream s;
161  s << "Overlay(";
162  bool hasPrevious = false;
163  for(PresentationInterface::Ptr const& child: children)
164  {
165  if(hasPrevious)
166  {
167  s << ", ";
168  }
169  s << child->getTitle();
170  hasPrevious = true;
171  }
172  s << ")";
173 
174  return s.str();
175 }

◆ getViews()

std::set< ViewInterface::WeakPtr > TransparentOverlayPresentation::getViews ( )
overridevirtual

Implements PresentationBase.

122 {
123  std::set<ViewInterface::WeakPtr> result;
124  for(auto const& p: viewData)
125  {
126  result.insert(p.first);
127  }
128 
129  return result;
130 }

◆ isPropertyDefined()

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

Return true if the named property exists

Implements PresentationInterface.

152 {
153  UNUSED(name);
154 
155  return false;
156 }

◆ redraw()

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

136 {
137  auto e = viewData.find(vi);
138  if(e != viewData.end())
139  {
140  e->second->redraw(cr, presentationArea, zoom);
141  }
142 }

◆ setOptimalColor()

void TransparentOverlayPresentation::setOptimalColor ( PresentationInterface::Ptr const &  p)
private
72 {
73  Colormappable::Ptr const c = boost::dynamic_pointer_cast<Colormappable>(p);
74  if(c)
75  {
76  std::map<Color, int, ColorComparer> currentColors;
77  for(PresentationInterface::Ptr const& child: children)
78  {
79  Colormappable::Ptr const cChild = boost::dynamic_pointer_cast<Colormappable>(child);
80  if(cChild && child->isPropertyDefined(MONOCHROME_COLORMAPPABLE_PROPERTY_NAME))
81  {
82  currentColors[cChild->getMonochromeColor()]++;
83  }
84  }
85 
86  Color minimumColor = c->getMonochromeColor();
87  int minimumColorValue = currentColors[minimumColor];
88 
89  for(Color const& color: colors)
90  {
91  if(currentColors[color] < minimumColorValue)
92  {
93  minimumColor = color;
94  minimumColorValue = currentColors[color];
95  }
96  }
97 
98  c->setMonochromeColor(minimumColor);
99  }
100 }

Referenced by addPresentation().

Here is the caller graph for this function:

◆ viewAdded()

void TransparentOverlayPresentation::viewAdded ( ViewInterface::WeakPtr  vi)
overridevirtual

Implements PresentationBase.

105 {
107  tovi->addChildren(children);
108  viewData[vi] = tovi;
109 }
Here is the call graph for this function:

◆ viewRemoved()

void TransparentOverlayPresentation::viewRemoved ( ViewInterface::WeakPtr  vi)
overridevirtual

Implements PresentationBase.

112 {
113  auto e = viewData.find(vi);
114  if(e != viewData.end())
115  {
116  e->second->close();
117  viewData.erase(e->first);
118  }
119 }

Member Data Documentation

◆ children

std::list<PresentationInterface::Ptr> TransparentOverlayPresentation::children
private

◆ sizeDeterminer

SizeDeterminer::Ptr TransparentOverlayPresentation::sizeDeterminer
private

Referenced by addPresentation(), getRect(), and viewAdded().

◆ viewData

ViewDataMap TransparentOverlayPresentation::viewData
private

The documentation for this class was generated from the following files:
UNUSED
#define UNUSED(x)
Definition: unused.hh:10
anonymous_namespace{transparentoverlaypresentation.cc}::colors
const std::list< Color > colors
Definition: transparentoverlaypresentation.cc:21
MONOCHROME_COLORMAPPABLE_PROPERTY_NAME
const std::string MONOCHROME_COLORMAPPABLE_PROPERTY_NAME
Definition: colormappable.hh:22
SizeDeterminer::create
static Ptr create()
Definition: sizedeterminer.cc:66
TransparentOverlayPresentation::sizeDeterminer
SizeDeterminer::Ptr sizeDeterminer
Definition: transparentoverlaypresentation.hh:36
TransparentOverlayViewInfo::Ptr
boost::shared_ptr< TransparentOverlayViewInfo > Ptr
Definition: transparentoverlayviewinfo.hh:63
TransparentOverlayPresentation::viewData
ViewDataMap viewData
Definition: transparentoverlaypresentation.hh:38
PresentationInterface::Ptr
boost::shared_ptr< PresentationInterface > Ptr
Definition: presentationinterface.hh:74
TransparentOverlayPresentation::TransparentOverlayPresentation
TransparentOverlayPresentation()
Definition: transparentoverlaypresentation.cc:43
TransparentOverlayViewInfo::create
static Ptr create(const ViewInterface::WeakPtr &vi, SizeDeterminer::Ptr const &sizeDeterminer)
Definition: transparentoverlayviewinfo.cc:130
Colormappable::Ptr
boost::shared_ptr< Colormappable > Ptr
Definition: colormappable.hh:116
defect_message
#define defect_message(m)
Definition: assertions.hh:43
TransparentOverlayPresentation::Ptr
boost::shared_ptr< TransparentOverlayPresentation > Ptr
Definition: transparentoverlaypresentation.hh:29
TransparentOverlayPresentation::children
std::list< PresentationInterface::Ptr > children
Definition: transparentoverlaypresentation.hh:35
TransparentOverlayPresentation::setOptimalColor
void setOptimalColor(PresentationInterface::Ptr const &p)
Definition: transparentoverlaypresentation.cc:71
Color
Definition: color.hh:34