//----------------------------------------------------------------------------- // // kfountain - Partical Fountain Screen Saver for KDE 2 // // Copyright (c) Ian Reinhart Geiser 2001 // // TDEConfig code and KScreenSaver "Setup..." improvements by // Nick Betcher 2001 // #include #include #include #include #include #include #include #include #include #include #include "fountain.h" #include "fountain.moc" #ifdef TQ_WS_MACX #include #include #else #include #include #endif #include #include #include #include #include #include #include #include // libkscreensaver interface extern "C" { KDE_EXPORT const char *kss_applicationName = "kfountain.kss"; KDE_EXPORT const char *kss_description = I18N_NOOP( "Particle Fountain Screen Saver" ); KDE_EXPORT const char *kss_version = "2.2.0"; KDE_EXPORT KScreenSaver *kss_create( WId id ) { return new KFountainSaver( id ); } KDE_EXPORT TQDialog *kss_setup() { return new KFountainSetup(); } } //----------------------------------------------------------------------------- // dialog to setup screen saver parameters // KFountainSetup::KFountainSetup( TQWidget *parent, const char *name ) : SetupUi( parent, name, TRUE ) { readSettings(); //TQLabel *label; //TQPushButton *button; //setCaption( i18n("Setup Particle Fountain") ); //TQVBoxLayout *tl = new TQVBoxLayout(this, 10); //TQHBoxLayout *tl1 = new TQHBoxLayout; //tl->addLayout(tl1); //TQVBoxLayout *tl11 = new TQVBoxLayout(5); //tl1->addLayout(tl11); //label = new TQLabel( i18n("No options here yet...:"), this ); ///tl11->addWidget(label);; //preview = new TQWidget( this ); preview->setFixedSize( 220, 170 ); preview->setBackgroundColor( black ); preview->show(); // otherwise saver does not get correct size saver = new KFountainSaver( preview->winId() ); //tl1->addWidget(preview); //KButtonBox *bbox = new KButtonBox(this); //bbox->addStretch(1); ; connect( PushButton1, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOkPressed() ) ); connect( PushButton2, TQT_SIGNAL( clicked() ), TQT_SLOT( reject() ) ); connect( PushButton3, TQT_SIGNAL( clicked() ), TQT_SLOT( aboutPressed() ) ); connect( SpinBox1, TQT_SIGNAL( valueChanged(int)), saver, TQT_SLOT( updateSize(int))); connect( RadioButton1, TQT_SIGNAL( toggled(bool)), saver, TQT_SLOT( doStars(bool))); } // read settings from config file void KFountainSetup::readSettings() { TDEConfig config("kssfountainrc", false, false); config.setGroup( "Settings" ); TQString boolval = config.readEntry( "Stars", "false" ); if (boolval == "true") { RadioButton1->setDown(true); RadioButton1_2->setDown(false); } else { if (boolval == "false") { RadioButton1->setDown(false); RadioButton1_2->setDown(true); } } TQString starammount = config.readEntry("StarSize", "75"); SpinBox1->setValue(starammount.toInt()); } // Ok pressed - save settings and exit void KFountainSetup::slotOkPressed() { TDEConfig config("kssfountainrc", false, false); config.setGroup( "Settings" ); if (RadioButton1->isOn() == true) { config.writeEntry( "Stars", "true" ); } else { if (RadioButton1_2->isOn() == true) { config.writeEntry( "Stars", "false" ); } } config.writeEntry( "StarSize", TQString::number(SpinBox1->value()) ); config.sync(); accept(); } void KFountainSetup::aboutPressed() { KMessageBox::about(this, i18n("

Particle Fountain

\n

Particle Fountain Screen Saver for TDE

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

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

")); } //----------------------------------------------------------------------------- KFountainSaver::KFountainSaver( WId id ) : KScreenSaver( id ) { kdDebug() << "Blank" << endl; timer = new TQTimer( this ); timer->start( 25, TRUE ); setBackgroundColor( black ); erase(); fountain = new Fountain(); embed(fountain); fountain->show(); connect( timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(blank()) ); } KFountainSaver::~KFountainSaver() { } // read configuration settings from config file void KFountainSaver::readSettings() { // Please remove me } void KFountainSaver::blank() { // Play fountain fountain->updateGL(); timer->start( 25, TRUE ); } Fountain::Fountain( TQWidget * parent, const char * name) : TQGLWidget (parent,name) { 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! TDEConfig config("kssfountainrc", false, false); config.setGroup( "Settings" ); TQString boolval = config.readEntry( "Stars", "false" ); if (boolval == "true") { setStars(true); } else { if (boolval == "false") { setStars(false); } } TQString starammount = config.readEntry("StarSize", "75"); float passvalue = (starammount.toInt() / 100.0); setSize(passvalue); } Fountain::~Fountain() { glDeleteTextures( 1, &texture[0] ); gluDeleteQuadric(obj); } /** load the particle file */ bool Fountain::loadParticle() { /* Status indicator */ bool Status = TRUE; TQImage buf; kdDebug() << "Loading: " << locate("data", "kscreensaver/particle.png") << endl; if (buf.load( locate("data", "kscreensaver/particle.png") ) ) { tex = convertToGLFormat(buf); // flipped 32bit RGBA kdDebug() << "Texture loaded: " << tex.numBytes () << endl; } else { TQImage dummy( 32, 32, 32 ); dummy.fill( TQt::white.rgb() ); 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 enviroment */ void Fountain::initializeGL () { kdDebug() << "InitGL" << endl; 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); }