QWT 7.0.1
Loading...
Searching...
No Matches
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 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_PIXEL_MATRIX_H
28#define QWT_PIXEL_MATRIX_H
29
30#include "qwt_global.h"
31
32#include <qbitarray.h>
33#include <qrect.h>
34
41class QWT_EXPORT QwtPixelMatrix : public QBitArray
42{
43 public:
44 explicit QwtPixelMatrix( const QRect& rect );
46
47 void setRect( const QRect& rect );
48 QRect rect() const;
49
50 bool testPixel( int x, int y ) const;
51 bool testAndSetPixel( int x, int y, bool on );
52
53 int index( int x, int y ) const;
54
55 private:
56 QRect m_rect;
57};
58
68inline bool QwtPixelMatrix::testPixel( int x, int y ) const
69{
70 const int idx = index( x, y );
71 return ( idx >= 0 ) ? testBit( idx ) : true;
72}
73
84inline bool QwtPixelMatrix::testAndSetPixel( int x, int y, bool on )
85{
86 const int idx = index( x, y );
87 if ( idx < 0 )
88 return true;
89
90 const bool onBefore = testBit( idx );
91 setBit( idx, on );
92
93 return onBefore;
94}
95
103inline int QwtPixelMatrix::index( int x, int y ) const
104{
105 const int dx = x - m_rect.x();
106 if ( dx < 0 || dx >= m_rect.width() )
107 return -1;
108
109 const int dy = y - m_rect.y();
110 if ( dy < 0 || dy >= m_rect.height() )
111 return -1;
112
113 return dy * m_rect.width() + dx;
114}
115
116#endif
A bit field corresponding to the pixels of a rectangle.
Definition qwt_pixel_matrix.h:42
bool testPixel(int x, int y) const
Test if a pixel has been set.
Definition qwt_pixel_matrix.h:68
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:84
int index(int x, int y) const
Calculate the index in the bit field corresponding to a position.
Definition qwt_pixel_matrix.h:103