VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gximage.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 gximage.h
19 ///
20 
21 #ifndef GX_IMAGE_H
22 #define GX_IMAGE_H
23 
24 #include "gdef.h"
25 #include "gxdef.h"
26 #include "gxvisual.h"
27 
28 namespace GX
29 {
30  class Image ;
31  class Display ;
32  class Context ;
33  class Visual ;
34  class Window ;
35 }
36 
37 /// \class GX::Image
38 /// A class for xclient-side images that are drawn locally and then blitted
39 /// to the xserver.
40 ///
41 class GX::Image
42 {
43 public:
44  Image( Display & , const GX::Window & window , int dx = 0 , int dy = 0 ) ;
45  ///< Constructor. The display reference is kept.
46 
47  Image( Display & display , XImage * p , int dx , int dy ) ;
48  ///< A private constructor used by Pixmap::getImage().
49 
50  ~Image() ;
51  ///< Destructor.
52 
53  ::XImage * x() ;
54  ///< Returns the X object.
55 
56  void blit( GX::Window & , int src_x , int src_y , int dx , int dy , int dst_x , int dst_y ) ;
57  ///< Blits to a window. Uses the display's default
58  ///< graphics context.
59 
60  int dx() const ;
61  ///< Returns the width.
62 
63  int dy() const ;
64  ///< Returns the height.
65 
66  void drawPoint( int x , int y , unsigned long p , bool or_ = false ) ;
67  ///< Draws a point. The pixel value typically comes from GX::ColourMap::get().
68 
69  bool fastable() const ;
70  ///< Returns true if drawFastPoint() can be used.
71 
72  void drawFastPoint( int x , int y , unsigned long p ) ;
73  ///< Draws a point fast.
74 
75  unsigned long readPoint( int x , int y ) const ;
76  ///< Reads a pixel value at a point.
77 
78  void drawLine( int x1 , int y1 , int x2 , int y2 , unsigned long p , bool or_ = false ) ;
79  ///< Draws a line. The pixel value typically comes from GX::ColourMap::get().
80 
81  void drawLineAcross( int x1 , int x2 , int y , unsigned long p ) ;
82  ///< Draws a horizontal line.
83 
84  void drawLineDown( int x , int y1 , int y2 , unsigned long p ) ;
85  ///< Draws a vertical line.
86 
87  void clear( bool white = false ) ;
88  ///< Clears the image.
89 
90 private:
91  Image( const Image & ) ;
92  void operator=( const Image & ) ;
93  void blit( GX::Window & , Context & , int src_x , int src_y , int dx , int dy , int dst_x , int dst_y ) ;
94 
95 private:
96  Display & m_display ;
97  ::XImage * m_image ;
98  int m_dx ;
99  int m_dy ;
100 } ;
101 
102 inline
103 ::XImage * GX::Image::x()
104 {
105  return m_image ;
106 }
107 
108 inline
109 void GX::Image::drawPoint( int x , int y , unsigned long p , bool or_ )
110 {
111  if( x >= 0 && x < m_dx && y >= 0 && y < m_dy )
112  {
113  if( or_ )
114  XPutPixel( m_image , x , y , p | XGetPixel(m_image,x,y) ) ;
115  else
116  XPutPixel( m_image , x , y , p ) ;
117  }
118 }
119 
120 inline
122 {
123  return true ;
124 }
125 
126 inline
127 void GX::Image::drawFastPoint( int x , int y , unsigned long p )
128 {
129  XPutPixel( m_image , x , y , p ) ;
130 }
131 
132 inline
133 int GX::Image::dx() const
134 {
135  return m_dx ;
136 }
137 
138 inline
139 int GX::Image::dy() const
140 {
141  return m_dy ;
142 }
143 
144 #endif
A window class that is-a GX::Drawable and a GX::EventHandler.
Definition: gxwindow.h:47
A class for xclient-side images that are drawn locally and then blitted to the xserver.
Definition: gximage.h:41
void drawLine(int x1, int y1, int x2, int y2, unsigned long p, bool or_=false)
Draws a line. The pixel value typically comes from GX::ColourMap::get().
Definition: gximage.cpp:100
An Xlib Display wrapper.
Definition: gxdisplay.h:38
void drawPoint(int x, int y, unsigned long p, bool or_=false)
Draws a point. The pixel value typically comes from GX::ColourMap::get().
Definition: gximage.h:109
bool fastable() const
Returns true if drawFastPoint() can be used.
Definition: gximage.h:121
void drawLineDown(int x, int y1, int y2, unsigned long p)
Draws a vertical line.
Definition: gximage.cpp:121
int dy() const
Returns the height.
Definition: gximage.h:139
void drawLineAcross(int x1, int x2, int y, unsigned long p)
Draws a horizontal line.
Definition: gximage.cpp:110
An Xlib GC wrapper.
Definition: gxcontext.h:37
::XImage * x()
Returns the X object.
Definition: gximage.h:103
~Image()
Destructor.
Definition: gximage.cpp:65
Image(Display &, const GX::Window &window, int dx=0, int dy=0)
Constructor. The display reference is kept.
Definition: gximage.cpp:34
void drawFastPoint(int x, int y, unsigned long p)
Draws a point fast.
Definition: gximage.h:127
void clear(bool white=false)
Clears the image.
Definition: gximage.cpp:90
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: gximage.cpp:77
unsigned long readPoint(int x, int y) const
Reads a pixel value at a point.
Definition: gximage.cpp:95
int dx() const
Returns the width.
Definition: gximage.h:133