38 m_dx = dx_in ? dx_in : window.
dx() ;
39 m_dy = dy_in ? dy_in : window.
dy() ;
40 G_ASSERT( m_dx > 0 && m_dy > 0 ) ;
43 Visual visual( m_display ) ;
44 m_image = XCreateImage( display.
x() , visual.
x() ,
static_cast<unsigned int>(visual.
depth()) ,
45 ZPixmap , 0 , p , static_cast<unsigned int>(m_dx) ,
static_cast<unsigned int>(m_dy) , 8 , 0 ) ;
46 if( m_image ==
nullptr )
47 throw Error(
"XCreateImage failed" ) ;
49 int size = m_dy * m_image->bytes_per_line ;
50 G_ASSERT( size >= 0 ) ;
51 p =
static_cast<char*
>(std::malloc(static_cast<size_t>(size))) ;
53 throw std::bad_alloc() ;
70 XDestroyImage( m_image ) ;
79 Context gc = m_display.defaultContext() ;
80 blit( window , gc , src_x , src_y , dx , dy , dst_x , dst_y ) ;
84 int src_x ,
int src_y ,
int dx ,
int dy ,
int dst_x ,
int dst_y )
86 XPutImage( m_display.x() , window.
x() , gc.
x() , m_image , src_x , src_y , dst_x , dst_y ,
87 static_cast<unsigned int>(dx) , static_cast<unsigned int>(dy) ) ;
92 std::memset( m_image->data , white?255:0 , m_image->bytes_per_line * m_image->height ) ;
97 return XGetPixel( m_image , x , y ) ;
103 while( line_draw.
more() )
105 for(
int x = line_draw.
x1() ; x <= line_draw.
x2() ; x++ )
106 drawPoint( x , line_draw.
y() , p , or_ ) ;
112 if( y >= 0 && y < m_dy )
114 x1 = x1 < 0 ? 0 : ( x1 >= m_dx ? (m_dx-1) : x1 ) ;
115 x2 = x2 < 0 ? 0 : ( x2 >= m_dx ? (m_dx-1) : x2 ) ;
116 for(
int x = x1 ; x <= x2 ; x++ )
117 XPutPixel( m_image , x , y , p ) ;
123 if( x >= 0 && x < m_dx )
125 y1 = y1 < 0 ? 0 : ( y1 >= m_dy ? (m_dy-1) : y1 ) ;
126 y2 = y2 < 0 ? 0 : ( y2 >= m_dy ? (m_dy-1) : y2 ) ;
127 for(
int y = y1 ; y <= y2 ; y++ )
128 XPutPixel( m_image , x , y , p ) ;
A window class that is-a GX::Drawable and a GX::EventHandler.
::Display * x()
Returns the X object.
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().
int dx() const
Returns the current width.
T y() const
Returns the current y coordinate.
An exception class for GX classes.
A class template for drawing lines in terms of separate horizontal line segments. ...
::GC x()
Returns the X object.
::Window x()
Returns the X object.
int depth() const
Returns the depth.
int dy() const
Returns the current hieght.
void drawLineDown(int x, int y1, int y2, unsigned long p)
Draws a vertical line.
T x1() const
Returns the current smaller x coordinate.
void drawLineAcross(int x1, int x2, int y, unsigned long p)
Draws a horizontal line.
Image(Display &, const GX::Window &window, int dx=0, int dy=0)
Constructor. The display reference is kept.
void clear(bool white=false)
Clears the image.
void blit(GX::Window &, int src_x, int src_y, int dx, int dy, int dst_x, int dst_y)
Blits to a window.
unsigned long readPoint(int x, int y) const
Reads a pixel value at a point.
T x2() const
Returns the current larger x coordinate.
bool more()
Iterator for the next line segment. Returns true at least once.
::Visual * x()
Returns the X object.