VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gxwindow.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 gxwindow.h
19 ///
20 
21 #ifndef GX_WINDOW_H
22 #define GX_WINDOW_H
23 
24 #include "gdef.h"
25 #include "gxdef.h"
26 #include "gxdrawable.h"
27 #include "gxcapture.h"
28 #include "gxeventhandler.h"
29 #include <string>
30 
31 namespace GX
32 {
33  class Window ;
34  class Display ;
35  class ColourMap ;
36  class Capture ;
37 }
38 
39 /// \class GX::Window
40 /// A window class that is-a GX::Drawable and a GX::EventHandler.
41 ///
42 /// The window is empty and inherently drawable, and this class does not create
43 /// any sub-windows or embedded drawables. However, if a separate drawable is
44 /// used then it is typically blitted into this window in response to this
45 /// window's expose events.
46 ///
47 class GX::Window : public GX::Drawable , public GX::EventHandler
48 {
49 public:
50  Window( GX::Display & , int dx , int dy ) ;
51  ///< Constructor. The display reference is kept.
52 
53  Window( GX::Display & , int dx , int dy , int background , const std::string & title = std::string() ) ;
54  ///< Constructor for a window with a solid background. The display
55  ///< reference is kept.
56 
57  virtual ~Window() ;
58  ///< Destructor.
59 
60  void clear() ;
61  ///< Clears the window.
62 
63  void show() ;
64  ///< Shows ("maps") the window.
65 
66  ::Window x() ;
67  ///< Returns the X object.
68 
69  int dx() const ;
70  ///< Returns the current width.
71 
72  int dy() const ;
73  ///< Returns the current hieght.
74 
75  virtual ::Drawable xd() ;
76  ///< From Drawable.
77 
78  void enableEvents( long mask ) ;
79  ///< Enables the specified event types.
80 
81  static long events( bool with_mouse_moves ) ;
82  ///< Returns a default event mask for enableEvents().
83 
84  void install( GX::ColourMap & ) ;
85  ///< Installs a colourmap.
86 
88  ///< Returns a reference to the display
89  ///< as passed in to the ctor.
90 
91  const GX::Display & windowDisplay() const ;
92  ///< Const overload.
93 
94  GX::Capture * capture() ;
95  ///< Starts capturing the mouse. Returns a new-ed Capture pointer
96  ///< that should be put into a unique_ptr.
97 
98  virtual void onKeyPress( ::XKeyEvent & ) override ;
99  ///< An override from EventHandler that calls onKey() doing the
100  ///< translation from opaque keycode to meaningful keysym.
101 
102  virtual void onKey( const std::string & key ) ;
103  ///< Called from this class's override of EventHandler::onKeyPress().
104  ///< The parameter is something like "a", "X", "F1", "END", "^C", etc.
105 
106  virtual void onChar( char c ) ;
107  ///< Called from this class's override of EventHandler::onKeyPress()
108  ///< in the case of simple character keys.
109 
110  void sendUserEvent() ;
111  ///< Posts a message back to itself so that onUser() gets called.
112 
113  std::string key() const ;
114  ///< Returns the last onKey() string.
115 
116  void invalidate() ;
117  ///< Invalidates the window by posting an expose event (see
118  ///< GX::EventHandler::onExpose()). This is not normally needed
119  ///< because the X server will generate all the necessary expose
120  ///< events without the help of user code.
121 
122 private:
123  Window( const Window & ) ;
124  void operator=( const Window & ) ;
125  void create( GX::Display & , int , int , unsigned long , const ::XSetWindowAttributes & ) ;
126  static std::string keysymToString( ::KeySym , bool ) ;
127 
128 private:
129  GX::Display & m_display ;
130  ::Window m_window ;
131  int m_dx ;
132  int m_dy ;
133  std::string m_key ;
134 } ;
135 
136 #endif
A window class that is-a GX::Drawable and a GX::EventHandler.
Definition: gxwindow.h:47
void invalidate()
Invalidates the window by posting an expose event (see GX::EventHandler::onExpose()).
Definition: gxwindow.cpp:209
void install(GX::ColourMap &)
Installs a colourmap.
Definition: gxwindow.cpp:181
virtual ::Drawable xd()
From Drawable.
Definition: gxwindow.cpp:154
GX::Capture * capture()
Starts capturing the mouse.
Definition: gxwindow.cpp:224
int dx() const
Returns the current width.
Definition: gxwindow.cpp:186
virtual void onChar(char c)
Called from this class's override of EventHandler::onKeyPress() in the case of simple character keys...
Definition: gxwindow.cpp:113
An Xlib Display wrapper.
Definition: gxdisplay.h:38
A colourmap class that provides pixel values for a set of mapped colours.
Definition: gxcolourmap.h:41
void clear()
Clears the window.
Definition: gxwindow.cpp:176
An interface for delivering GX::EventLoop events, with do-nothing default method implementations.
GX::Display & windowDisplay()
Returns a reference to the display as passed in to the ctor.
Definition: gxwindow.cpp:122
Window(GX::Display &, int dx, int dy)
Constructor. The display reference is kept.
Definition: gxwindow.cpp:30
::Window x()
Returns the X object.
Definition: gxwindow.cpp:149
virtual void onKeyPress(::XKeyEvent &) override
An override from EventHandler that calls onKey() doing the translation from opaque keycode to meaning...
Definition: gxwindow.cpp:88
int dy() const
Returns the current hieght.
Definition: gxwindow.cpp:191
std::string key() const
Returns the last onKey() string.
Definition: gxwindow.cpp:117
virtual void onKey(const std::string &key)
Called from this class's override of EventHandler::onKeyPress().
Definition: gxwindow.cpp:109
void enableEvents(long mask)
Enables the specified event types.
Definition: gxwindow.cpp:159
virtual ~Window()
Destructor.
Definition: gxwindow.cpp:137
void show()
Shows ("maps") the window.
Definition: gxwindow.cpp:132
RAII class to capture Xlib mouse events.
Definition: gxcapture.h:37
static long events(bool with_mouse_moves)
Returns a default event mask for enableEvents().
Definition: gxwindow.cpp:164
void sendUserEvent()
Posts a message back to itself so that onUser() gets called.
Definition: gxwindow.cpp:196
An abstract base class for xserver-side drawables (windows, pixmaps, etc) with methods for drawing po...
Definition: gxdrawable.h:38