Qwt User's Guide 6.2.0

qwt_pixel_matrix.h
1 /******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10 #ifndef QWT_PIXEL_MATRIX_H
11 #define QWT_PIXEL_MATRIX_H
12
13 #include "qwt_global.h"
14
15 #include <qbitarray.h>
16 #include <qrect.h>
17
24 class QWT_EXPORT QwtPixelMatrix : public QBitArray
25 {
26 public:
27 explicit QwtPixelMatrix( const QRect& rect );
28 ~QwtPixelMatrix();
29
30 void setRect( const QRect& rect );
31 QRect rect() const;
32
33 bool testPixel( int x, int y ) const;
34 bool testAndSetPixel( int x, int y, bool on );
35
36 int index( int x, int y ) const;
37
38 private:
39 QRect m_rect;
40 };
41
51 inline bool QwtPixelMatrix::testPixel( int x, int y ) const
52 {
53 const int idx = index( x, y );
54 return ( idx >= 0 ) ? testBit( idx ) : true;
55 }
56
67 inline bool QwtPixelMatrix::testAndSetPixel( int x, int y, bool on )
68 {
69 const int idx = index( x, y );
70 if ( idx < 0 )
71 return true;
72
73 const bool onBefore = testBit( idx );
74 setBit( idx, on );
75
76 return onBefore;
77 }
78
86 inline int QwtPixelMatrix::index( int x, int y ) const
87 {
88 const int dx = x - m_rect.x();
89 if ( dx < 0 || dx >= m_rect.width() )
90 return -1;
91
92 const int dy = y - m_rect.y();
93 if ( dy < 0 || dy >= m_rect.height() )
94 return -1;
95
96 return dy * m_rect.width() + dx;
97 }
98
99 #endif
QwtPixelMatrix
A bit field corresponding to the pixels of a rectangle.
Definition: qwt_pixel_matrix.h:25
QwtPixelMatrix::testPixel
bool testPixel(int x, int y) const
Test if a pixel has been set.
Definition: qwt_pixel_matrix.h:51
QwtPixelMatrix::testAndSetPixel
bool testAndSetPixel(int x, int y, bool on)
Set a pixel and test if a pixel has been set before.
Definition: qwt_pixel_matrix.h:67