VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gxpixmap.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 // gxpixmap.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gxdef.h"
23 #include "gxpixmap.h"
24 #include "gxwindow.h"
25 #include "gxdisplay.h"
26 #include "gxcontext.h"
27 #include "gxcolourmap.h"
28 #include "gximage.h"
29 #include "gxerror.h"
30 #include "gassert.h"
31 
32 GX::Pixmap::Pixmap( Display & display , GX::Window & window , int dx , int dy ) :
33  Drawable(display) ,
34  m_display(display)
35 {
36  m_dx = dx ? dx : window.dx() ;
37  m_dy = dy ? dy : window.dy() ;
38  G_ASSERT( m_dx >= 0 && m_dy >= 0 ) ;
39  m_pixmap = XCreatePixmap( display.x() , window.x() ,
40  static_cast<unsigned int>(m_dx) , static_cast<unsigned int>(m_dy) ,
41  static_cast<unsigned int>(display.depth()) ) ;
42 }
43 
45 {
46  try
47  {
48  XFreePixmap( m_display.x() , m_pixmap ) ;
49  }
50  catch(...)
51  {
52  }
53 }
54 
56 {
57  return m_pixmap ;
58 }
59 
61 {
62  return m_pixmap ;
63 }
64 
65 int GX::Pixmap::dx() const
66 {
67  return m_dx ;
68 }
69 
70 int GX::Pixmap::dy() const
71 {
72  return m_dy ;
73 }
74 
75 void GX::Pixmap::blit( GX::Window & window , int src_x , int src_y , int dx , int dy , int dst_x , int dst_y )
76 {
77  Context gc = m_display.defaultContext() ;
78  blit( window , gc , src_x , src_y , dx , dy , dst_x , dst_y ) ;
79 }
80 
81 void GX::Pixmap::blit( GX::Window & window , Context & gc ,
82  int src_x , int src_y , int dx , int dy , int dst_x , int dst_y )
83 {
84  G_ASSERT( dx >= 0 && dy >= 0 ) ;
85  XCopyArea( m_display.x() , m_pixmap , window.x() , gc.x() , src_x , src_y ,
86  static_cast<unsigned int>(dx) , static_cast<unsigned int>(dy) , dst_x , dst_y ) ;
87 }
88 
89 void GX::Pixmap::readImage( unique_ptr<GX::Image> & image ) const
90 {
91  unsigned int mask = static_cast<unsigned int>(~0) ; // callee ignores extraneous bits, so set them all
92  XImage * p = XGetImage( m_display.x() , m_pixmap , 0 , 0 ,
93  static_cast<unsigned int>(m_dx) , static_cast<unsigned int>(m_dy) ,
94  mask , XYPixmap ) ;
95  if( p == nullptr )
96  throw Error( "XGetImage" ) ;
97  image.reset( new Image( m_display , p , m_dx , m_dy ) ) ;
98 }
99 
101 {
102  Context gc = m_display.defaultContext() ;
103  drawRectangle( gc , 0 , 0 , m_dx , m_dy ) ; // Drawable base-class
104 }
105 
106 /// \file gxpixmap.cpp
A window class that is-a GX::Drawable and a GX::EventHandler.
Definition: gxwindow.h:47
::Display * x()
Returns the X object.
Definition: gxdisplay.cpp:53
A class for xclient-side images that are drawn locally and then blitted to the xserver.
Definition: gximage.h:41
void readImage(unique_ptr< Image > &) const
Reads the image from the xserver.
Definition: gxpixmap.cpp:89
::Pixmap x()
Returns the X object.
Definition: gxpixmap.cpp:55
~Pixmap()
Destructor.
Definition: gxpixmap.cpp:44
int dx() const
Returns the current width.
Definition: gxwindow.cpp:186
Pixmap(Display &, GX::Window &window, int dx=0, int dy=0)
Constructor. The display reference is kept.
Definition: gxpixmap.cpp:32
An Xlib Display wrapper.
Definition: gxdisplay.h:38
void blit(GX::Window &, int src_x, int src_y, int dx, int dy, int dst_x, int dst_y)
Blits to a window.
Definition: gxpixmap.cpp:75
An exception class for GX classes.
Definition: gxerror.h:37
A pixmap class for xserver-side images.
Definition: gxpixmap.h:41
::GC x()
Returns the X object.
Definition: gxcontext.cpp:63
int dx() const
Returns the width.
Definition: gxpixmap.cpp:65
::Window x()
Returns the X object.
Definition: gxwindow.cpp:149
virtual ::Drawable xd()
From Drawable.
Definition: gxpixmap.cpp:60
int dy() const
Returns the current hieght.
Definition: gxwindow.cpp:191
void clear()
Draws a big rectangle to clear the pixmap.
Definition: gxpixmap.cpp:100
An Xlib GC wrapper.
Definition: gxcontext.h:37
int dy() const
Returns the height.
Definition: gxpixmap.cpp:70
int depth() const
Returns the color depth (in bits).
Definition: gxdisplay.cpp:85
An abstract base class for xserver-side drawables (windows, pixmaps, etc) with methods for drawing po...
Definition: gxdrawable.h:38