//----------------------------------------------------------------------------- // // kwave - Waveing Flag Screen Saver for KDE // // Copyright (c) Ian Reinhart Geiser 2001 // #include #include #include #include #include #include #include #include #include #include "wave.h" #include "moc_wave.cpp" #include #include #include #include #include #include #include #include #include #include #ifndef GLU_NURBS_TEXTURE_COORD #define GLU_NURBS_TEXTURE_COORD 100168 #endif // libkscreensaver interface class KWaveSaverInterface : public KScreenSaverInterface { public: virtual KAboutData* aboutData() { return new KAboutData( "kwave.kss", "klock", ki18n( "Bitmap Wave Screen Saver" ), "2.2.0", ki18n( "Bitmap Wave Screen Saver" ) ); } virtual KScreenSaver* create( WId id ) { return new KWaveSaver( id ); } virtual QDialog* setup() { return new KWaveSetup(); } }; int main( int argc, char *argv[] ) { KWaveSaverInterface kss; return kScreenSaverMain( argc, argv, kss ); } //----------------------------------------------------------------------------- // dialog to setup screen saver parameters // KWaveSetup::KWaveSetup( QWidget *parent) : KDialog( parent ) { setModal(true); setCaption(i18n( "Bitmap Flag Setup" )); setButtons(Ok|Cancel|Help); setDefaultButton(Ok); setButtonText( Help, i18n( "A&bout" ) ); QWidget *main = new QWidget(this); setMainWidget(main); cfg = new WaveWidget(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 KWaveSaver( 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))); } KWaveSetup::~KWaveSetup( ) { delete saver; } // read settings from config file void KWaveSetup::readSettings() { KConfigGroup config(KGlobal::config(), "Settings"); // color = group.configColorEntry( "Color", &black ); } // Ok pressed - save settings and exit void KWaveSetup::slotOkPressed() { KConfigGroup config(KGlobal::config(), "Settings"); // group.writeEntry( "Color", color ); config.sync(); accept(); } void KWaveSetup::aboutPressed() { KMessageBox::about(this, i18n("

Bitmap Flag Screen Saver

\n

Waving Flag Screen Saver for KDE

\nCopyright (c) Ian Reinhart Geiser 2001")); } //----------------------------------------------------------------------------- KWaveSaver::KWaveSaver( WId id ) : KScreenSaver( id ) { kDebug() << "Blank"; readSettings(); timer = new QTimer( this ); timer->setSingleShot( true ); timer->start( 50 ); { QPalette palette; palette.setColor( backgroundRole(), Qt::black ); setPalette( palette ); setAutoFillBackground(true); } wave = new Wave(); embed(wave); wave->show(); connect( timer, SIGNAL(timeout()), this, SLOT(blank()) );; } KWaveSaver::~KWaveSaver() { } // read configuration settings from config file void KWaveSaver::readSettings() { KConfigGroup config(KGlobal::config(), "Settings"); // color = group.configColorEntry( "Color", &black ); } void KWaveSaver::blank() { // Play wave wave->updateGL(); timer->start( 100 ); } Wave::Wave( QWidget * parent ) : QGLWidget (parent) { pNurb = 0; nNumPoints = 4; index = 0; } Wave::~Wave() { glDeleteTextures( 1, &texture[0] ); gluDeleteNurbsRenderer(pNurb); } /** setup the GL environment */ void Wave::initializeGL () { kDebug() << "InitGL"; /* Load in the texture */ if ( !LoadGLTextures( ) ) exit(0); /* Enable Texture Mapping ( NEW ) */ glEnable( GL_TEXTURE_2D ); /* Enable smooth shading */ glShadeModel( GL_SMOOTH ); // Light values and coordinates GLfloat specular[] = { 0.7f, 0.0f, 0.0f, 1.0f}; GLfloat shine[] = { 75.0f }; glClearColor(0.0f, 0.0f, 0.0f, 0.0f ); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialfv(GL_FRONT, GL_SHININESS, shine); glEnable(GL_AUTO_NORMAL); pNurb = gluNewNurbsRenderer(); gluNurbsProperty(pNurb, GLU_SAMPLING_TOLERANCE, 25.0f); // Uncomment the next line and comment the one following to produce a // wire frame mesh. //gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON); gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, (GLfloat)GLU_FILL); glEnable(GL_MAP2_TEXTURE_COORD_3); glEnable(GL_MAP2_VERTEX_3); glEnable(GL_BLEND); } /** resize the gl view */ void Wave::resizeGL ( int w, int h) { kDebug() << "ResizeGL " << w << "," <