Qwt User's Guide: qwt_pixel_matrix.h Source File

Qwt User's Guide 6.1.2

- Main Page
- Related Pages
- Classes

All Classes Functions Variables Typedefs Enumerations Enumerator Pages
qwt_pixel_matrix.h
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 #include <qbitarray.h>
15 #include <qrect.h>
16
23 class QWT_EXPORT QwtPixelMatrix: public QBitArray
24 {
25 public:
26 QwtPixelMatrix( const QRect& rect );
27 ~QwtPixelMatrix();
28
29 void setRect( const QRect& rect );
30 QRect rect() const;
31
32 bool testPixel( int x, int y ) const;
33 bool testAndSetPixel( int x, int y, bool on );
34
35 int index( int x, int y ) const;
36
37 private:
38 QRect d_rect;
39 };
40
50 inline bool QwtPixelMatrix::testPixel( int x, int y ) const
51 {
52 const int idx = index( x, y );
53 return ( idx >= 0 ) ? testBit( idx ) : true;
54 }
55
66 inline bool QwtPixelMatrix::testAndSetPixel( int x, int y, bool on )
67 {
68 const int idx = index( x, y );
69 if ( idx < 0 )
70 return true;
71
72 const bool onBefore = testBit( idx );
73 setBit( idx, on );
74
75 return onBefore;
76 }
77
85 inline int QwtPixelMatrix::index( int x, int y ) const
86 {
87 const int dx = x - d_rect.x();
88 if ( dx < 0 || dx >= d_rect.width() )
89 return -1;
90
91 const int dy = y - d_rect.y();
92 if ( dy < 0 || dy >= d_rect.height() )
93 return -1;
94
95 return dy * d_rect.width() + dx;
96 }
97
98 #endif
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:66
QwtPixelMatrix::testPixel
bool testPixel(int x, int y) const
Test if a pixel has been set.
Definition: qwt_pixel_matrix.h:50
QwtPixelMatrix::index
int index(int x, int y) const
Calculate the index in the bit field corresponding to a position.
Definition: qwt_pixel_matrix.h:85
QwtPixelMatrix
A bit field corresponding to the pixels of a rectangle.
Definition: qwt_pixel_matrix.h:23