Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
viewinterface.hh
Go to the documentation of this file.
1/*
2 * Scroom - Generic viewer for 2D data
3 * Copyright (C) 2009-2026 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 <memory>
13#include <string>
14
15#include <gtk/gtk.h>
16
17#include <scroom/gtk-helpers.hh>
18#include <scroom/interface.hh>
20#include <scroom/rectangle.hh>
21
23class ViewInterface;
24
26{
27 const std::string GRID("GridSelection");
28 const std::string PIXEL("PixelSelection");
29 const std::string DEFAULT(GRID);
30} // namespace SelectionType
31
37{
38public:
40
41public:
44
45public:
46 Selection(double x, double y)
47 : Selection(Scroom::Utils::make_point(x, y))
48 {
49 }
50
51 explicit Selection(Point point)
52 : Selection(point, point)
53 {
54 }
55
56 Selection(Point start_, Point end_)
57 : start(start_)
58 , end(end_)
59 {
60 }
61
63 {
64 start = p;
65 end = p;
66 return *this;
67 }
68
69 [[nodiscard]] double width() const { return abs(end.x - start.x); }
70 [[nodiscard]] double height() const { return abs(end.y - start.y); }
71 [[nodiscard]] double length() const { return std::hypot(width(), height()); }
72};
73
78class PostRenderer : private Interface
79{
80public:
81 using Ptr = std::shared_ptr<PostRenderer>;
82
83public:
97 virtual void render(
98 std::shared_ptr<ViewInterface> const& vi,
99 cairo_t* cr,
100 Scroom::Utils::Rectangle<double> presentationArea,
101 int zoom
102 ) = 0;
103};
104
116{
117public:
118 using Ptr = std::shared_ptr<SelectionListener>;
119
120public:
121 virtual std::string getSelectionType() { return SelectionType::DEFAULT; }
122
131 virtual void onSelectionStart(Selection selection, std::shared_ptr<ViewInterface> view) = 0;
132
142 virtual void onSelectionUpdate(Selection selection, std::shared_ptr<ViewInterface> view) = 0;
143
153 virtual void onSelectionEnd(Selection selection, std::shared_ptr<ViewInterface> view) = 0;
154};
155
162{
163public:
164 using Ptr = std::shared_ptr<ToolStateListener>;
165
166public:
171 virtual void onEnable() = 0;
172
177 virtual void onDisable() = 0;
178};
179
191{
192public:
193 using Ptr = std::shared_ptr<ViewInterface>;
194 using WeakPtr = std::weak_ptr<ViewInterface>;
195
196public:
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
274
278 virtual void setStatusMessage(const std::string&) = 0;
279
285 virtual std::shared_ptr<PresentationInterface> getCurrentPresentation() = 0;
286
294 virtual void addToolButton(GtkToggleButton*, ToolStateListener::Ptr) = 0;
295};
Definition interface.hh:11
Definition viewinterface.hh:79
virtual void render(std::shared_ptr< ViewInterface > const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > presentationArea, int zoom)=0
std::shared_ptr< PostRenderer > Ptr
Definition viewinterface.hh:81
Definition presentationinterface.hh:71
std::shared_ptr< ProgressInterface > Ptr
Definition progressinterface.hh:20
value_type y
Definition point.hh:112
value_type x
Definition point.hh:111
Definition rectangle.hh:29
Definition viewinterface.hh:116
virtual void onSelectionEnd(Selection selection, std::shared_ptr< ViewInterface > view)=0
virtual std::string getSelectionType()
Definition viewinterface.hh:121
virtual void onSelectionStart(Selection selection, std::shared_ptr< ViewInterface > view)=0
virtual void onSelectionUpdate(Selection selection, std::shared_ptr< ViewInterface > view)=0
std::shared_ptr< SelectionListener > Ptr
Definition viewinterface.hh:118
Definition viewinterface.hh:162
virtual void onDisable()=0
std::shared_ptr< ToolStateListener > Ptr
Definition viewinterface.hh:164
virtual void onEnable()=0
Definition viewinterface.hh:191
virtual void addToolButton(GtkToggleButton *, ToolStateListener::Ptr)=0
virtual void invalidate()=0
virtual void registerPostRenderer(PostRenderer::Ptr)=0
virtual void removeSideWidget(GtkWidget *w)=0
virtual std::shared_ptr< PresentationInterface > getCurrentPresentation()=0
virtual ProgressInterface::Ptr getProgressInterface()=0
std::weak_ptr< ViewInterface > WeakPtr
Definition viewinterface.hh:194
virtual void removeFromToolbar(GtkToolItem *ti)=0
virtual void addToToolbar(GtkToolItem *ti)=0
virtual void registerSelectionListener(SelectionListener::Ptr)=0
virtual void addSideWidget(std::string title, GtkWidget *w)=0
virtual void setStatusMessage(const std::string &)=0
std::shared_ptr< ViewInterface > Ptr
Definition viewinterface.hh:193
PresentationInterfaceStub::Ptr const p
Definition determine-size-test.cc:172
std::pair< GSourceFunc, gpointer > const w
Definition gtkhelper-tests.cc:42
Definition blockallocator.hh:18
Definition viewinterface.hh:26
const std::string GRID("GridSelection")
const std::string PIXEL("PixelSelection")
const std::string DEFAULT(GRID)
auto selection
Definition pipette-tests.cc:157
ViewInterface::Ptr const vi
Definition pipette-tests.cc:186
const auto view
Definition pipette-tests.cc:227
Definition viewinterface.hh:37
Point end
Definition viewinterface.hh:43
Selection(double x, double y)
Definition viewinterface.hh:46
Selection(Point start_, Point end_)
Definition viewinterface.hh:56
double length() const
Definition viewinterface.hh:71
Point start
Definition viewinterface.hh:42
Selection & operator=(const Point &p)
Definition viewinterface.hh:62
double height() const
Definition viewinterface.hh:70
Selection(Point point)
Definition viewinterface.hh:51
double width() const
Definition viewinterface.hh:69
cairo_t * cr
Definition transformpresentation_test.cc:72