//----------------------------------------------------------------------------- // // kfountain - Partical Fountain Screen Saver for KDE // // Copyright (c) Ian Reinhart Geiser 2001 // // KConfig code and KScreenSaver "Setup..." improvements by // Nick Betcher 2001 // #include #include #include #include #include #include #include #include #include #include "fountain.h" #include "moc_fountain.cpp" #include #include #include #include #include #include #include #include #include #include #include // libkscreensaver interface class KFountainSaverInterface : public KScreenSaverInterface { public: virtual KAboutData* aboutData() { return new KAboutData( "kfountain.kss", "klock", ki18n( "Particle Fountain Screen Saver" ), "2.2.0", ki18n( "Particle Fountain Screen Saver" ) ); } virtual KScreenSaver* create( WId id ) { return new KFountainSaver( id ); } virtual QDialog* setup() { return new KFountainSetup(); } }; int main( int argc, char *argv[] ) { KFountainSaverInterface kss; return kScreenSaverMain( argc, argv, kss ); } //----------------------------------------------------------------------------- // dialog to setup screen saver parameters // KFountainSetup::KFountainSetup( QWidget *parent ) : KDialog( parent) { setCaption(i18n( "Particle Fountain Setup" )); setButtons(Ok|Cancel|Help); setDefaultButton(Ok); setModal(true); setButtonText( Help, i18n( "A&bout" ) ); QWidget *main = new QWidget(this); setMainWidget(main); cfg = new FountainWidget(main); readSettings(); cfg->preview->setFixedSize( 220, 170 ); { QPalette palette; palette.setColor( cfg->preview->backgroundRole(), Qt::black ); cfg->preview->setPalette( palette ); cfg->preview->setAutoFillBackground(true); } cfg->preview->show(); // otherwise saver does not get correct size saver = new KFountainSaver( cfg->preview->winId() ); connect( this, SIGNAL(okClicked()), SLOT(slotOkPressed()) ); connect( this, SIGNAL(helpClicked()), SLOT(aboutPressed()) ); connect( cfg->SpinBox1, SIGNAL(valueChanged(int)), saver, SLOT(updateSize(int))); connect( cfg->RadioButton1, SIGNAL(toggled(bool)), saver, SLOT(doStars(bool))); } KFountainSetup::~KFountainSetup() { } // read settings from config file void KFountainSetup::readSettings() { KConfig config(QLatin1String( "kssfountainrc" ), KConfig::NoGlobals); KConfigGroup grp = config.group("Settings"); bool boolval = grp.readEntry( "Stars", false ); if (boolval) { cfg->RadioButton1->setChecked(true); } else { cfg->RadioButton1_2->setChecked(true); } int starammount = grp.readEntry("StarSize", 75); cfg->SpinBox1->setValue(starammount); } // Ok pressed - save settings and exit void KFountainSetup::slotOkPressed() { KConfig _config(QLatin1String( "kssfountainrc" ), KConfig::NoGlobals); KConfigGroup config(&_config, "Settings" ); if (cfg->RadioButton1->isChecked() == true) { config.writeEntry( "Stars", true ); } else { if (cfg->RadioButton1_2->isChecked() == true) { config.writeEntry( "Stars", false ); } } config.writeEntry( "StarSize", cfg->SpinBox1->value() ); config.sync(); accept(); } void KFountainSetup::aboutPressed() { KMessageBox::about(this, i18n("

Particle Fountain

\n

Particle Fountain Screen Saver for KDE

\nCopyright (c) Ian Reinhart Geiser 2001
\n\n

KConfig code and KScreenSaver \"Setup...\" improvements by Nick Betcher 2001

")); } //----------------------------------------------------------------------------- KFountainSaver::KFountainSaver( WId id ) : KScreenSaver( id ) { kDebug() << "Blank"; timer = new QTimer( this ); timer->setSingleShot( true ); timer->start( 25 ); { QPalette palette; palette.setColor( backgroundRole(), Qt::black ); setPalette( palette ); } update(); fountain = new Fountain(); embed(fountain); fountain->show(); connect( timer, SIGNAL(timeout()), this, SLOT(blank()) ); show(); } KFountainSaver::~KFountainSaver() { } // read configuration settings from config file void KFountainSaver::readSettings() { // Please remove me } void KFountainSaver::blank() { // Play fountain fountain->updateGL(); timer->setSingleShot(true); timer->start( 25); } Fountain::Fountain( QWidget * parent ) : QGLWidget (parent) { rainbow=true; slowdown=2.0f; zoom=-40.0f; index=0; size = 0.75f; obj = gluNewQuadric(); // This has to be here because you can't update the fountain until 'fountain' is created! KConfig _config(QLatin1String( "kssfountainrc" ), KConfig::NoGlobals); KConfigGroup config(&_config, "Settings" ); bool boolval = config.readEntry( "Stars", false ); setStars(boolval); int starammount = config.readEntry("StarSize", 75); float passvalue = (starammount / 100.0); setSize(passvalue); } Fountain::~Fountain() { glDeleteTextures( 1, &texture[0] ); gluDeleteQuadric(obj); } /** load the particle file */ bool Fountain::loadParticle() { /* Status indicator */ bool Status = true; QImage buf; kDebug() << "Loading: " << KStandardDirs::locate("data", QLatin1String( "kscreensaver/particle.png" )); if (buf.load( KStandardDirs::locate("data", QLatin1String( "kscreensaver/particle.png" )) ) ) { tex = convertToGLFormat(buf); // flipped 32bit RGBA kDebug() << "Texture loaded: " << tex.numBytes (); } else { QImage dummy( 32, 32, QImage::Format_RGB32 ); dummy.fill( Qt::white ); buf = dummy; tex = convertToGLFormat( buf ); } /* Set the status to true */ //Status = true; glGenTextures(1, &texture[0]); /* create three textures */ glBindTexture(GL_TEXTURE_2D, texture[0]); /* use linear filtering */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* actually generate the texture */ glTexImage2D(GL_TEXTURE_2D, 0, 4, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits()); return Status; } /** setup the GL environment */ void Fountain::initializeGL () { kDebug() << "InitGL"; GLfloat colors[12][3]= {{1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f}, {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f}, {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f}}; if (loadParticle()) // Jump To Texture Loading Routine { /* Enable smooth shading */ glShadeModel( GL_SMOOTH ); /* Set the background black */ glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); /* Depth buffer setup */ glClearDepth( 1.0f ); /* Enables Depth Testing */ glDisable( GL_DEPTH_TEST ); /* Enable Blending */ glEnable( GL_BLEND ); /* Type Of Blending To Perform */ glBlendFunc( GL_SRC_ALPHA, GL_ONE ); /* Really Nice Perspective Calculations */ glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); /* Really Nice Point Smoothing */ glHint( GL_POINT_SMOOTH_HINT, GL_NICEST ); /* Enable Texture Mapping */ glEnable( GL_TEXTURE_2D ); /* Select Our Texture */ glBindTexture( GL_TEXTURE_2D, texture[0] ); for (loop=0;loopsetSize(newSize/100); } void KFountainSaver::doStars(bool starState) { fountain->setStars(starState); }