home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / life / life.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  1KB  |  60 lines

  1. /****************************************************************************
  2. ** $Id:  qt/life.h   3.0.0   edited Jun 22 13:24 $
  3. **
  4. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  5. **
  6. ** This file is part of an example program for Qt.  This example
  7. ** program may be used, distributed and modified without limitation.
  8. **
  9. *****************************************************************************/
  10.  
  11. #ifndef LIFE_H
  12. #define LIFE_H
  13.  
  14. #include <qframe.h>
  15.  
  16.  
  17. class LifeWidget : public QFrame
  18. {
  19.     Q_OBJECT
  20. public:
  21.     LifeWidget( int s = 10, QWidget *parent = 0, const char *name = 0 );
  22.  
  23.     void    setPoint( int i, int j );
  24.  
  25.     int        maxCol() { return maxi; }
  26.     int        maxRow() { return maxj; }
  27.  
  28. public slots:
  29.     void    nextGeneration();
  30.     void    clear();
  31.  
  32. protected:
  33.     virtual void paintEvent( QPaintEvent * );
  34.     virtual void mouseMoveEvent( QMouseEvent * );
  35.     virtual void mousePressEvent( QMouseEvent * );
  36.     virtual void resizeEvent( QResizeEvent * );
  37.     void     mouseHandle( const QPoint &pos );
  38.  
  39. private:
  40.     enum { MAXSIZE = 50, MINSIZE = 10, BORDER = 5 };
  41.  
  42.     bool    cells[2][MAXSIZE + 2][MAXSIZE + 2];
  43.     int        current;
  44.     int        maxi, maxj;
  45.  
  46.     int pos2index( int x )
  47.     {
  48.     return ( x - BORDER ) / SCALE + 1;
  49.     }
  50.     int index2pos( int i )
  51.     {
  52.     return    ( i - 1 ) * SCALE + BORDER;
  53.     }
  54.  
  55.     int SCALE;
  56. };
  57.  
  58.  
  59. #endif // LIFE_H
  60.