Back to index

kdeartwork  4.3.2
gravity.h
Go to the documentation of this file.
00001 
00002 //
00003 // kgravity - Partical gravity Screen Saver for KDE 2
00004 //
00005 // Copyright (c)  Ian Reinhart Geiser 2001
00006 //
00008 //NOTE:
00009 // The base particle engine did not come from me, it was designed by Jeff Molofee <nehe@connect.ab.ca>
00010 // I did some extensive modifications to make it work with QT's OpenGL but the base principal is about
00011 // the same.
00013 
00014 #ifndef GRAVITY_H
00015 #define GRAVITY_H
00016 
00017 #include <qdialog.h>
00018 #include <qgl.h>
00019 #ifdef Q_WS_MACX
00020 #include <OpenGL/glu.h>
00021 #include <OpenGL/gl.h>
00022 #else
00023 #include <GL/glu.h>
00024 #include <GL/gl.h>
00025 #endif
00026 #include <kscreensaver.h>
00027 #include <qtimer.h>
00028 #include <qimage.h>
00029 #include "ui_gravitycfg.h"
00030 #include <kcomponentdata.h>
00031 #include <qfile.h>
00032 #include <qtextstream.h>
00033 
00034 #define       MAX_PARTICLES 100
00035 
00036 
00037 class Gravity : public QGLWidget
00038 {
00039 Q_OBJECT
00040        class particles                                         // Create A Structure For Particle
00041        {
00042        public:
00043               bool   active;                                   // Active (Yes/No)
00044               float  life;                              // Particle Life
00045               float  fade;                              // Fade Speed
00046               float  r;                                 // Red Value
00047               float  g;                                 // Green Value
00048               float  b;                                 // Blue Value
00049               float  x;                                 // X Position
00050               float  y;                                 // Y Position
00051               float  z;                                 // Z Position
00052               float  xo;                                // X Position
00053               float  yo;                                // Y Position
00054               float  zo;                                // Z Position
00055               float  index;                             // Index
00056               float  indexo;
00057               float  size;                              // Particle Size
00058        };
00059 
00060 public:
00061        Gravity( QWidget * parent=0 );
00062        ~Gravity();
00063        void setSize( float newSize );
00064        void setStars( bool doStars );
00065 protected:
00067        void paintGL ();
00069        void resizeGL ( int w, int h );
00071        void initializeGL ();
00072        void buildParticle(int loop);
00073 
00074 private:
00076        bool loadParticle();
00077 
00078        particles particle[MAX_PARTICLES];
00079 
00080 
00081        bool   rainbow;                                  // Rainbow Mode?
00082        bool   sp;                                       // Spacebar Pressed?
00083        bool   rp;                                       // Enter Key Pressed?
00084        float  slowdown;                                 // Slow Down Particles
00085        float  xspeed;                                          // Base X Speed (To Allow Keyboard Direction Of Tail)
00086        float  yspeed;                                          // Base Y Speed (To Allow Keyboard Direction Of Tail)
00087        float  zoom;                              // Used To Zoom Out
00088        float  size;
00089        float  stars;
00090        GLuint loop;                                     // Misc Loop Variable
00091        GLuint col;                                      // Current Color Selection
00092        GLuint delay;                                    // Rainbow Effect Delay
00093        GLuint texture[1];
00094        QImage  tex;
00095        float  index;
00096        float  transIndex;
00097        GLfloat scale;
00098        GLUquadricObj *obj;
00099 };
00100 
00101 class KGravitySaver : public KScreenSaver
00102 {
00103 Q_OBJECT
00104 public:
00105        KGravitySaver( WId drawable );
00106        virtual ~KGravitySaver();
00107        void readSettings();
00108 public slots:
00109        void blank();
00110        void updateSize(int newSize);
00111        void doStars(bool starState);
00112 //     void loadTextures(bool textures);
00113 private:
00114        Gravity *gravity;
00115        QTimer  *timer;
00116 };
00117 
00118 class KGravitySetup : public QDialog, public Ui::SetupUi
00119 {
00120        Q_OBJECT
00121 public:
00122        KGravitySetup( QWidget *parent = 0L);
00123         ~KGravitySetup();
00124 
00125 protected:
00126        void readSettings();
00127 
00128 private slots:
00129        void slotOkPressed();
00130        void aboutPressed();
00131 private:
00132        KGravitySaver *saver;
00133        float  size;
00134        float  stars;
00135        float  zoom;
00136        float  speed;
00137 };
00138 
00139 #endif
00140 
00141