qwt_pixel_matrix.h
Go to the documentation of this file.
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #ifndef QWT_PIXEL_MATRIX_H
00011 #define QWT_PIXEL_MATRIX_H
00012 
00013 #include "qwt_global.h"
00014 #include <qbitarray.h>
00015 #include <qrect.h>
00016 
00023 class QWT_EXPORT QwtPixelMatrix: public QBitArray
00024 {
00025 public:
00026     explicit QwtPixelMatrix( const QRect& rect );
00027     ~QwtPixelMatrix();
00028 
00029     void setRect( const QRect& rect );
00030     QRect rect() const;
00031 
00032     bool testPixel( int x, int y ) const;
00033     bool testAndSetPixel( int x, int y, bool on );
00034 
00035     int index( int x, int y ) const;
00036 
00037 private:
00038     QRect d_rect;
00039 };
00040 
00050 inline bool QwtPixelMatrix::testPixel( int x, int y ) const
00051 {
00052     const int idx = index( x, y );
00053     return ( idx >= 0 ) ? testBit( idx ) : true;
00054 }
00055 
00066 inline bool QwtPixelMatrix::testAndSetPixel( int x, int y, bool on )
00067 {
00068     const int idx = index( x, y );
00069     if ( idx < 0 )
00070         return true;
00071 
00072     const bool onBefore = testBit( idx );
00073     setBit( idx, on );
00074 
00075     return onBefore;
00076 }
00077 
00085 inline int QwtPixelMatrix::index( int x, int y ) const
00086 {
00087     const int dx = x - d_rect.x();
00088     if ( dx < 0 || dx >= d_rect.width() )
00089         return -1;
00090 
00091     const int dy = y - d_rect.y();
00092     if ( dy < 0 || dy >= d_rect.height() )
00093         return -1;
00094 
00095     return dy * d_rect.width() + dx;
00096 }
00097 
00098 #endif


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:56