VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvviewerwindow.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gvviewerwindow.h
19 ///
20 
21 #ifndef GV_VIEWERWINDOW__H
22 #define GV_VIEWERWINDOW__H
23 
24 #include "gdef.h"
25 #include <exception>
26 
27 namespace Gv
28 {
29  class ViewerWindowConfig ;
30  class ViewerWindowHandler ;
31  class ViewerWindow ;
32 }
33 
34 /// \class Gv::ViewerWindowConfig
35 /// A configuration structure for Gv::ViewerWindow.
36 ///
38 {
39  std::string m_title ;
40  std::string m_mask_file ;
41  bool m_static ;
42  bool m_mouse_moves ;
43 } ;
44 
45 /// \class Gv::ViewerWindowHandler
46 /// A callback interface for Gv::ViewerWindow.
47 ///
49 {
50 public:
51  virtual void onChar( char ) = 0 ;
52  ///< Called when a key is pressed.
53 
54  virtual void onMouseButtonDown( int x , int y , bool shift , bool control ) = 0 ;
55  ///< Called when the left mouse button is pressed.
56 
57  virtual void onMouseButtonUp( int x , int y , bool shift , bool control ) = 0 ;
58  ///< Called when the left mouse button is released.
59 
60  virtual void onMouseMove( int x , int y ) = 0 ;
61  ///< Called when the mouse moves (typically also depending on whether
62  ///< ViewerWindowConfig::m_mouse_moves is set). Coordinates can be negative
63  ///< if the mouse is moved outside the window with the button pressed.
64 
65  virtual void onInvalid() = 0 ;
66  ///< Called when the window needs to be re-display()ed.
67 
68  virtual ~ViewerWindowHandler() {}
69  ///< Destructor.
70 } ;
71 
72 /// \class Gv::ViewerWindow
73 /// An abstract base class for a viewer window. The concrete derived class
74 /// is chosen by the factory class.
75 ///
77 {
78 public:
80  typedef ViewerWindowConfig Config ;
81 
82  static ViewerWindow * create( Handler & , ViewerWindow::Config , int image_dx , int image_dy ) ;
83  ///< A factory function that returns a new'ed ViewerWindow.
84  ///<
85  ///< The dx and dy parameters are the size of the image
86  ///< that triggered the creation of the window, not necessarily
87  ///< the size of the window.
88  ///<
89  ///< The new window should have its init() method called immediately
90  ///< after construction.
91 
92  virtual void init() = 0 ;
93  ///< An initialisation function that is called after contstruction.
94  ///< Keeping it as a separate function makes cleanup simpler in the
95  ///< face of exceptions, for some derived classes.
96 
97  virtual void display( int dx , int dy , int channels , const char * , size_t ) = 0 ;
98  ///< Displays the given image.
99 
100  virtual int dx() const = 0 ;
101  ///< Returns the width of the window. This may not be the same as what was
102  ///< passed to the constructor. The mouse coordinates relate to this value.
103 
104  virtual int dy() const = 0 ;
105  ///< Returns the height of the window. This may not be the same as what was
106  ///< passed to the constructor. The mouse coordinates relate to this value.
107 
108  virtual ~ViewerWindow() ;
109  ///< Destructor.
110 } ;
111 
112 #endif
virtual void display(int dx, int dy, int channels, const char *, size_t)=0
Displays the given image.
virtual void onMouseButtonUp(int x, int y, bool shift, bool control)=0
Called when the left mouse button is released.
virtual void init()=0
An initialisation function that is called after contstruction.
An abstract base class for a viewer window.
virtual int dy() const =0
Returns the height of the window.
virtual ~ViewerWindowHandler()
Destructor.
A configuration structure for Gv::ViewerWindow.
virtual ~ViewerWindow()
Destructor.
virtual void onChar(char)=0
Called when a key is pressed.
virtual void onMouseMove(int x, int y)=0
Called when the mouse moves (typically also depending on whether ViewerWindowConfig::m_mouse_moves is...
virtual void onMouseButtonDown(int x, int y, bool shift, bool control)=0
Called when the left mouse button is pressed.
static ViewerWindow * create(Handler &, ViewerWindow::Config, int image_dx, int image_dy)
A factory function that returns a new'ed ViewerWindow.
virtual int dx() const =0
Returns the width of the window.
virtual void onInvalid()=0
Called when the window needs to be re-display()ed.
A callback interface for Gv::ViewerWindow.