VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gxdisplay.cpp
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 // gxdisplay.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gxdef.h"
23 #include "gxdisplay.h"
24 #include "gxerror.h"
25 #include <sstream>
26 
28 {
29  m_display = XOpenDisplay(0) ;
30  if( m_display == nullptr )
31  throw Error( "XOpenDisplay" ) ;
32 
33  m_black = XBlackPixel( m_display , DefaultScreen(m_display) ) ;
34  m_white = XWhitePixel( m_display , DefaultScreen(m_display) ) ;
35 
36  int screen = XDefaultScreen( m_display ) ;
37  m_depth = XDefaultDepth( m_display , screen ) ;
38  m_dx = XDisplayWidth( m_display , screen ) ;
39  m_dy = XDisplayHeight( m_display , screen ) ;
40 }
41 
43 {
44  try
45  {
46  XCloseDisplay( m_display ) ;
47  }
48  catch(...)
49  {
50  }
51 }
52 
54 {
55  return m_display ;
56 }
57 
58 int GX::Display::fd() const
59 {
60  return ConnectionNumber(m_display) ; // ie. m_display->fd ;
61 }
62 
64 {
65  int screen = XDefaultScreen( m_display ) ;
66  return XDefaultColormap( m_display , screen ) ;
67 }
68 
70 {
71  int screen = XDefaultScreen( m_display ) ;
72  return Context( *this , XDefaultGC(m_display,screen) ) ;
73 }
74 
75 int GX::Display::white() const
76 {
77  return m_white ;
78 }
79 
80 int GX::Display::black() const
81 {
82  return m_black ;
83 }
84 
85 int GX::Display::depth() const
86 {
87  return m_depth ;
88 }
89 
90 int GX::Display::dx() const
91 {
92  return m_dx ;
93 }
94 
95 int GX::Display::dy() const
96 {
97  return m_dy ;
98 }
99 
100 std::list<GX::Display::PixmapFormat> GX::Display::pixmapFormats() const
101 {
102  int n = 0 ;
103  XPixmapFormatValues * p = XListPixmapFormats( m_display , &n ) ;
104  if( p == nullptr )
105  throw Error( "XListPixmapFormats" ) ;
106 
107  std::list<PixmapFormat> result ;
108  for( int i = 0 ; i < n ; i++ )
109  {
110  PixmapFormat item = { p[i].depth , p[i].bits_per_pixel , p[i].scanline_pad } ;
111  result.push_back( item ) ;
112  }
113  XFree( p ) ;
114  return result ;
115 }
116 
117 /// \file gxdisplay.cpp
::Display * x()
Returns the X object.
Definition: gxdisplay.cpp:53
An Xlib Display wrapper.
Definition: gxdisplay.h:38
An exception class for GX classes.
Definition: gxerror.h:37
int fd() const
Returns a select()able file descriptor.
Definition: gxdisplay.cpp:58
std::list< PixmapFormat > pixmapFormats() const
Returns a list of supported pixmap formats.
Definition: gxdisplay.cpp:100
Context defaultContext()
Returns the default graphics context for the default screen.
Definition: gxdisplay.cpp:69
A summary of one item in an Xlib XPixmapFormatValues list.
Definition: gxdisplay.h:42
int dy() const
Returns the default screen's height.
Definition: gxdisplay.cpp:95
An Xlib GC wrapper.
Definition: gxcontext.h:37
::Colormap defaultColourmap()
Returns the default colour map of the default screen.
Definition: gxdisplay.cpp:63
int white() const
Returns the white colour value.
Definition: gxdisplay.cpp:75
int black() const
Returns the black colour value.
Definition: gxdisplay.cpp:80
int depth() const
Returns the color depth (in bits).
Definition: gxdisplay.cpp:85
Display()
Constructor.
Definition: gxdisplay.cpp:27
~Display()
Destructor.
Definition: gxdisplay.cpp:42
int dx() const
Returns the default screen's width.
Definition: gxdisplay.cpp:90