Scroom  0.14
viewinterface.hh
Go to the documentation of this file.
1 /*
2  * Scroom - Generic viewer for 2D data
3  * Copyright (C) 2009-2022 Kees-Jan Dijkzeul
4  *
5  * SPDX-License-Identifier: LGPL-2.1
6  */
7 
8 #pragma once
9 
10 #include <cmath>
11 #include <cstdlib>
12 #include <string>
13 
14 #include <boost/shared_ptr.hpp>
15 #include <boost/weak_ptr.hpp>
16 
17 #include <gtk/gtk.h>
18 
19 #include <scroom/gtk-helpers.hh>
20 #include <scroom/interface.hh>
22 #include <scroom/rectangle.hh>
23 
25 class ViewInterface;
26 
27 namespace SelectionType
28 {
29  const std::string GRID("GridSelection");
30  const std::string PIXEL("PixelSelection");
31  const std::string DEFAULT(GRID);
32 } // namespace SelectionType
33 
38 struct Selection
39 {
40 public:
42 
43 public:
46 
47 public:
48  Selection(double x, double y)
49  : Selection(Scroom::Utils::make_point(x, y))
50  {
51  }
52 
53  explicit Selection(Point point)
54  : Selection(point, point)
55  {
56  }
57 
58  Selection(Point start_, Point end_)
59  : start(start_)
60  , end(end_)
61  {
62  }
63 
65  {
66  start = p;
67  end = p;
68  return *this;
69  }
70 
71  [[nodiscard]] double width() const { return abs(end.x - start.x); }
72  [[nodiscard]] double height() const { return abs(end.y - start.y); }
73  [[nodiscard]] double length() const { return std::hypot(width(), height()); }
74 };
75 
80 class PostRenderer : private Interface
81 {
82 public:
83  using Ptr = boost::shared_ptr<PostRenderer>;
84 
85 public:
99  virtual void render(boost::shared_ptr<ViewInterface> const& vi,
100  cairo_t* cr,
101  Scroom::Utils::Rectangle<double> presentationArea,
102  int zoom) = 0;
103 };
104 
116 {
117 public:
118  using Ptr = boost::shared_ptr<SelectionListener>;
119 
120 public:
121  virtual std::string getSelectionType() { return SelectionType::DEFAULT; }
122 
131  virtual void onSelectionStart(Selection selection, boost::shared_ptr<ViewInterface> view) = 0;
132 
142  virtual void onSelectionUpdate(Selection selection, boost::shared_ptr<ViewInterface> view) = 0;
143 
153  virtual void onSelectionEnd(Selection selection, boost::shared_ptr<ViewInterface> view) = 0;
154 };
155 
162 {
163 public:
164  using Ptr = boost::shared_ptr<ToolStateListener>;
165 
166 public:
171  virtual void onEnable() = 0;
172 
177  virtual void onDisable() = 0;
178 };
179 
190 class ViewInterface : private Interface
191 {
192 public:
193  using Ptr = boost::shared_ptr<ViewInterface>;
194  using WeakPtr = boost::weak_ptr<ViewInterface>;
195 
196 public:
204  virtual void invalidate() = 0;
205 
214 
222  virtual void addSideWidget(std::string title, GtkWidget* w) = 0;
223 
231  virtual void removeSideWidget(GtkWidget* w) = 0;
232 
240  virtual void addToToolbar(GtkToolItem* ti) = 0;
241 
249  virtual void removeFromToolbar(GtkToolItem* ti) = 0;
250 
259 
273  virtual void registerPostRenderer(PostRenderer::Ptr) = 0;
274 
278  virtual void setStatusMessage(const std::string&) = 0;
279 
285  virtual boost::shared_ptr<PresentationInterface> getCurrentPresentation() = 0;
286 
294  virtual void addToolButton(GtkToggleButton*, ToolStateListener::Ptr) = 0;
295 };
Selection::operator=
Selection & operator=(const Point &p)
Definition: viewinterface.hh:64
Selection::width
double width() const
Definition: viewinterface.hh:71
PresentationInterface
Definition: presentationinterface.hh:69
ViewInterface::removeSideWidget
virtual void removeSideWidget(GtkWidget *w)=0
ViewInterface::addSideWidget
virtual void addSideWidget(std::string title, GtkWidget *w)=0
SelectionListener::onSelectionUpdate
virtual void onSelectionUpdate(Selection selection, boost::shared_ptr< ViewInterface > view)=0
Scroom
Definition: assertions.hh:14
ViewInterface::getProgressInterface
virtual ProgressInterface::Ptr getProgressInterface()=0
SelectionListener
Definition: viewinterface.hh:115
ProgressInterface::Ptr
boost::shared_ptr< ProgressInterface > Ptr
Definition: progressinterface.hh:20
Selection::length
double length() const
Definition: viewinterface.hh:73
ViewInterface::Ptr
boost::shared_ptr< ViewInterface > Ptr
Definition: viewinterface.hh:193
Selection
Definition: viewinterface.hh:38
SelectionListener::onSelectionStart
virtual void onSelectionStart(Selection selection, boost::shared_ptr< ViewInterface > view)=0
SelectionType::PIXEL
const std::string PIXEL("PixelSelection")
SelectionType::DEFAULT
const std::string DEFAULT(GRID)
Selection::Selection
Selection(Point point)
Definition: viewinterface.hh:53
Scroom::Utils::Point::x
value_type x
Definition: point.hh:111
Scroom::Utils::make_point
Point< T > make_point(T x, T y)
Definition: point.hh:116
ToolStateListener
Definition: viewinterface.hh:161
Selection::Selection
Selection(Point start_, Point end_)
Definition: viewinterface.hh:58
ViewInterface::setStatusMessage
virtual void setStatusMessage(const std::string &)=0
ViewInterface::removeFromToolbar
virtual void removeFromToolbar(GtkToolItem *ti)=0
SelectionListener::Ptr
boost::shared_ptr< SelectionListener > Ptr
Definition: viewinterface.hh:118
SelectionType::GRID
const std::string GRID("GridSelection")
ViewInterface::invalidate
virtual void invalidate()=0
ToolStateListener::onEnable
virtual void onEnable()=0
ViewInterface::WeakPtr
boost::weak_ptr< ViewInterface > WeakPtr
Definition: viewinterface.hh:194
SelectionListener::getSelectionType
virtual std::string getSelectionType()
Definition: viewinterface.hh:121
progressinterface.hh
Selection::start
Point start
Definition: viewinterface.hh:44
PostRenderer::render
virtual void render(boost::shared_ptr< ViewInterface > const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > presentationArea, int zoom)=0
Interface
Definition: interface.hh:10
ViewInterface::getCurrentPresentation
virtual boost::shared_ptr< PresentationInterface > getCurrentPresentation()=0
SelectionType
Definition: viewinterface.hh:27
gtk-helpers.hh
ViewInterface::addToToolbar
virtual void addToToolbar(GtkToolItem *ti)=0
SelectionListener::onSelectionEnd
virtual void onSelectionEnd(Selection selection, boost::shared_ptr< ViewInterface > view)=0
Scroom::Utils::Rectangle< double >
interface.hh
ViewInterface::registerSelectionListener
virtual void registerSelectionListener(SelectionListener::Ptr)=0
Selection::height
double height() const
Definition: viewinterface.hh:72
rectangle.hh
ToolStateListener::Ptr
boost::shared_ptr< ToolStateListener > Ptr
Definition: viewinterface.hh:164
ViewInterface
Definition: viewinterface.hh:190
ViewInterface::registerPostRenderer
virtual void registerPostRenderer(PostRenderer::Ptr)=0
ViewInterface::addToolButton
virtual void addToolButton(GtkToggleButton *, ToolStateListener::Ptr)=0
Scroom::Utils::Point::y
value_type y
Definition: point.hh:112
Selection::end
Point end
Definition: viewinterface.hh:45
Selection::Selection
Selection(double x, double y)
Definition: viewinterface.hh:48
PostRenderer
Definition: viewinterface.hh:80
ToolStateListener::onDisable
virtual void onDisable()=0
Scroom::Utils::Point< double >
PostRenderer::Ptr
boost::shared_ptr< PostRenderer > Ptr
Definition: viewinterface.hh:83