qwt_pixel_matrix.h
Go to the documentation of this file.
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::index
int index(int x, int y) const
Calculate the index in the bit field corresponding to a position.
Definition: qwt_pixel_matrix.h:86
qwt_global.h
mqtt_test_proto.x
x
Definition: mqtt_test_proto.py:34
mqtt_test_proto.y
y
Definition: mqtt_test_proto.py:35
QwtPixelMatrix
A bit field corresponding to the pixels of a rectangle.
Definition: qwt_pixel_matrix.h:24
QWT_EXPORT
#define QWT_EXPORT
Definition: qwt_global.h:38
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
QwtPixelMatrix::m_rect
QRect m_rect
Definition: qwt_pixel_matrix.h:46
QwtPixelMatrix::testPixel
bool testPixel(int x, int y) const
Test if a pixel has been set.
Definition: qwt_pixel_matrix.h:51


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45