summaryrefslogtreecommitdiffstats
path: root/ktux
diff options
context:
space:
mode:
Diffstat (limited to 'ktux')
-rw-r--r--ktux/AUTHORS2
-rw-r--r--ktux/Makefile.am38
-rw-r--r--ktux/hi16-app-ktux.pngbin0 -> 628 bytes
-rw-r--r--ktux/hi32-app-ktux.pngbin0 -> 1335 bytes
-rw-r--r--ktux/ktux.desktop212
-rw-r--r--ktux/sprite.cpp254
-rw-r--r--ktux/sprite.h72
-rw-r--r--ktux/spriteanim.cpp161
-rw-r--r--ktux/spriteanim.h96
-rw-r--r--ktux/spritemisc.cpp69
-rw-r--r--ktux/spritemisc.h41
-rw-r--r--ktux/spritepm.cpp176
-rw-r--r--ktux/spritepm.h85
-rw-r--r--ktux/sprites/Makefile.am8
-rw-r--r--ktux/sprites/anim0001.pngbin0 -> 23517 bytes
-rw-r--r--ktux/sprites/anim0002.pngbin0 -> 23245 bytes
-rw-r--r--ktux/sprites/anim0003.pngbin0 -> 23646 bytes
-rw-r--r--ktux/sprites/anim0004.pngbin0 -> 23725 bytes
-rw-r--r--ktux/sprites/anim0005.pngbin0 -> 23541 bytes
-rw-r--r--ktux/sprites/anim0006.pngbin0 -> 23573 bytes
-rw-r--r--ktux/sprites/anim0007.pngbin0 -> 23537 bytes
-rw-r--r--ktux/sprites/anim0008.pngbin0 -> 23680 bytes
-rw-r--r--ktux/sprites/anim0009.pngbin0 -> 23642 bytes
-rw-r--r--ktux/sprites/anim0010.pngbin0 -> 23257 bytes
-rw-r--r--ktux/sprites/bg.pngbin0 -> 7799 bytes
-rw-r--r--ktux/sprites/flare0001.pngbin0 -> 210 bytes
-rw-r--r--ktux/sprites/flare0002.pngbin0 -> 325 bytes
-rw-r--r--ktux/sprites/spriterc62
-rw-r--r--ktux/sprites/star0001.pngbin0 -> 194 bytes
-rw-r--r--ktux/sprites/star0002.pngbin0 -> 219 bytes
30 files changed, 1276 insertions, 0 deletions
diff --git a/ktux/AUTHORS b/ktux/AUTHORS
new file mode 100644
index 0000000..394a242
--- /dev/null
+++ b/ktux/AUTHORS
@@ -0,0 +1,2 @@
+Code: Martin Jones <mjones@kde.org>
+Graphics: Carlos Rego
diff --git a/ktux/Makefile.am b/ktux/Makefile.am
new file mode 100644
index 0000000..8a32552
--- /dev/null
+++ b/ktux/Makefile.am
@@ -0,0 +1,38 @@
+## Makefile.am for ktux
+
+# this has all of the subdirectories that make will recurse into. if
+# there are none, comment this out
+SUBDIRS = sprites
+
+# this is the program that gets installed. it's name is used for all
+# of the other Makefile.am variables
+bin_PROGRAMS = ktux
+
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes)
+
+# the library search path.
+ktux_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+
+# the libraries to link against.
+ktux_LDADD = $(LIB_KDEUI) -lkscreensaver
+
+# which sources should be compiled for ktux
+ktux_SOURCES = spriteanim.cpp spritemisc.cpp spritepm.cpp sprite.cpp
+
+# these are the headers for your project
+noinst_HEADERS = sprite.h spriteanim.h spritemisc.h spritepm.h
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+# make messages.po. Move this one to ../po/ and "make merge" in po
+# the -x is for skipping messages already translated in kdelibs
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/ktux.pot
+
+KDE_ICON = ktux
+
+appsdir = $(kde_appsdir)/System/ScreenSavers
+apps_DATA = ktux.desktop
+
diff --git a/ktux/hi16-app-ktux.png b/ktux/hi16-app-ktux.png
new file mode 100644
index 0000000..e21db29
--- /dev/null
+++ b/ktux/hi16-app-ktux.png
Binary files differ
diff --git a/ktux/hi32-app-ktux.png b/ktux/hi32-app-ktux.png
new file mode 100644
index 0000000..4ecd9ce
--- /dev/null
+++ b/ktux/hi32-app-ktux.png
Binary files differ
diff --git a/ktux/ktux.desktop b/ktux/ktux.desktop
new file mode 100644
index 0000000..9895467
--- /dev/null
+++ b/ktux/ktux.desktop
@@ -0,0 +1,212 @@
+[Desktop Entry]
+Name=KTux
+Name[af]=Ktux
+Name[bg]=Тъкс
+Name[bn]=কে-টাক্স
+Name[eo]=Tuĉjo
+Name[hi]=के-टक्स
+Name[ne]=केडीई टक्स
+Name[ta]= KTux
+Name[tg]=KТукс
+Name[th]=ตุ๊กซ์
+Exec=ktux %i %m -caption "%c"
+Icon=ktux
+Type=Application
+Actions=Setup;InWindow;Root;
+X-KDE-Category=Flying Things
+Terminal=false
+
+[Desktop Action Setup]
+Exec=ktux -setup
+Name=Setup...
+Name[af]=Opstelling...
+Name[ar]=اعداد...
+Name[az]=Qurulum...
+Name[be]=Настаўленні...
+Name[bg]=Настройване...
+Name[bn]=প্রস্তুতি...
+Name[br]=Kefluniadur ...
+Name[bs]=Postavke...
+Name[ca]=Configuració...
+Name[cs]=Nastavení...
+Name[cy]=Gosod ...
+Name[da]=Opsætning...
+Name[de]=Einrichtung ...
+Name[el]=Ρύθμιση...
+Name[eo]=Agordo...
+Name[es]=Configuración...
+Name[et]=Seadistused...
+Name[eu]=Konfigurazioa...
+Name[fa]=برپایی...
+Name[fi]=Asetukset...
+Name[fr]=Configuration...
+Name[ga]=Socraigh...
+Name[gl]=Configuración...
+Name[he]=הגדרות...
+Name[hi]=सेटअप...
+Name[hr]=Postavke...
+Name[hu]=Beállítás...
+Name[id]=Aturan...
+Name[is]=Stillingar...
+Name[it]=Impostazioni...
+Name[ja]=セットアップ...
+Name[km]=រៀបចំ...
+Name[ko]=설정...
+Name[lt]=Nustatymas...
+Name[lv]=Uzstādījumi...
+Name[mk]=Поставување...
+Name[ms]=Tetapan...
+Name[nb]=Oppsett …
+Name[nds]=Instellen...
+Name[ne]=सेटअप...
+Name[nl]=Instellingen...
+Name[nn]=Oppsett …
+Name[pa]=ਸੈੱਟਅੱਪ...
+Name[pl]=Ustawienia...
+Name[pt]=Configurar...
+Name[pt_BR]=Configurar...
+Name[ro]=Setări...
+Name[ru]=Настройка...
+Name[rw]=Iboneza...
+Name[sk]=Nastavenie...
+Name[sl]=Nastavitve ...
+Name[sr]=Подеси...
+Name[sr@Latn]=Podesi...
+Name[sv]=Inställningar...
+Name[ta]=அமைப்பு...
+Name[tg]=Соз кардан...
+Name[th]=ติดตั้ง...
+Name[tr]=Kurulum...
+Name[uk]=Встановити...
+Name[uz]=Oʻrnatish
+Name[uz@cyrillic]=Ўрнатиш
+Name[ven]=Vhekanya...
+Name[wa]=Apontyî...
+Name[xh]=Iyacwangciswa...
+Name[zh_CN]=设置...
+Name[zh_TW]=設定...
+Name[zu]=Iyalungiselela...
+Icon=kscreensaver
+
+[Desktop Action InWindow]
+Exec=ktux -window-id %w
+Name=Display in Specified Window
+Name[be]=Паказваць у зададзеным вакне
+Name[bg]=Стартиране в избран прозорец
+Name[bn]=উল্লেখকৃত উইন্ডোতে দেখাও
+Name[br]=Diskwel er prenestr spisaet
+Name[bs]=Prikaži u navedenom prozoru
+Name[ca]=Mostra a la finestra especificada
+Name[cs]=Zobrazit v určeném okně
+Name[cy]=Dangos mewn Ffenestr Benodol
+Name[da]=Visning i angivet vindue
+Name[de]=In vorgegebenem Fenster anzeigen
+Name[el]=Εμφάνιση σε προκαθορισμένο παράθυρο
+Name[eo]=Montru en indikita fenestro
+Name[es]=Mostrar en la ventana especificada
+Name[et]=Määratud aknas näitamine
+Name[eu]=Zehaztutako lehioan erakutsi
+Name[fa]=نمایش در پنجرۀ مشخص‌شده
+Name[fi]=Näytä määrätyssä ikkunassa
+Name[fr]=Affichage dans la fenêtre indiquée
+Name[ga]=Taispeáin san Fhuinneog Sonraithe
+Name[gl]=Mostrar na fiestra indicada
+Name[he]=הצג בחלון המצויין
+Name[hr]=Prikazianje u određenom prozoru
+Name[hu]=Megjelenítés a megadott ablakban
+Name[id]=Ditampilkan di Window Khusus
+Name[is]=Birta í ákveðnum glugga
+Name[it]=Mostra nella finestra specificata
+Name[ja]=指定ウィンドウで表示
+Name[km]=បង្ហាញ​ក្នុង​បង្អួច​ជាក់លាក់
+Name[ko]=지정한 창에 표시하기
+Name[lt]=Rodyti nurodytame lange
+Name[lv]=Rādīt norādītajā logā
+Name[mk]=Приказ во зададениот прозорец
+Name[mt]=Uri fil-window speċifikata
+Name[nb]=Vis i det oppgitte vinduet
+Name[nds]=In't angeven Finster wiesen
+Name[ne]=निर्दिष्ट सञ्झ्यालमा प्रदर्शन गर्नुहोस्
+Name[nl]=Weergeven in een gedefinieerd venster
+Name[nn]=Vis i oppgjeve vindauge
+Name[pl]=Wyświetl w zadanym oknie
+Name[pt]=Mostrar na Janela Indicada
+Name[pt_BR]=Mostrar em janela especificada
+Name[ro]=Afişează în fereastra specificată
+Name[ru]=Показывать в указанном окне
+Name[rw]=Kwerekana mu Idirishya Ryihariye
+Name[sk]=Zobraziť v zadanom okne
+Name[sl]=Prikaz v določenemu oknu
+Name[sr]=Прикажи у задатом прозору
+Name[sr@Latn]=Prikaži u zadatom prozoru
+Name[sv]=Visa i angivet fönster
+Name[ta]= குறிப்பிட்ட சாளர காட்சியை காட்டு
+Name[tg]=Дар Тирезаи Муайяншуда Намоиш додан
+Name[tr]=Belirtilen Pencerede Göster
+Name[uk]=Відобразити у вказаному вікні
+Name[wa]=Håyner dins l' purnea specifyî
+Name[zh_CN]=在指定的窗口中显示
+Name[zh_TW]=在指定的視窗中顯示
+NoDisplay=true
+
+[Desktop Action Root]
+Exec=ktux -root
+Name=Display in Root Window
+Name[be]=Паказваць у фанавым вакне
+Name[bg]=Стартиране в главния прозорец
+Name[bn]=রুট উইন্ডোতে দেখাও
+Name[br]=Diskwel er prenestr gwrizienn
+Name[bs]=Prikaži u korijenskom prozoru
+Name[ca]=Mostra a la finestra arrel
+Name[cs]=Zobrazit na pozadí plochy
+Name[cy]=Dangos mewn Ffenestr Wraidd
+Name[da]=Visning i root-vindue
+Name[de]=Im Hintergrundfenster anzeigen
+Name[el]=Προβολή στο βασικό παράθυρο
+Name[eo]=Montru en radika fenestro
+Name[es]=Mostrar en la ventana raíz
+Name[et]=Juuraknas näitamine
+Name[eu]=Lehio nagusian erakutsi
+Name[fa]=نمایش در پنجرۀ ریشه
+Name[fi]=Näytä juuri-ikkunassa
+Name[fr]=Affichage dans la fenêtre principale
+Name[ga]=Taispeáin sa bhFréamhfhuinneog
+Name[gl]=Mostrar na fiestra raiz
+Name[he]=הצג בחלון השורש
+Name[hr]=Prikazivanje u korijenskom prozoru
+Name[hu]=Megjelenítés a gyökérablakban
+Name[id]=Ditampilkan di Root Window
+Name[is]=Birta í rótarglugga
+Name[it]=Mostra sullo sfondo
+Name[ja]=ルートウィンドウで表示
+Name[km]=បង្ហាញ​ក្នុង​បង្អួច Root
+Name[ko]=주 창에 표시하기
+Name[lt]=Rodyti root lange
+Name[lv]=Rādīt galvenajā logā
+Name[mk]=Приказ во коренскиот прозорец
+Name[mt]=Uri fil-window ewlenija
+Name[nb]=Vis i rotvinduet
+Name[nds]=In't Hööftfinster wiesen
+Name[ne]=मूल सञ्झ्यालमा प्रदर्शन गर्नुहोस्
+Name[nl]=Weergeven in hoofdvenster
+Name[nn]=Vis i rotvindauget
+Name[pl]=Wyświetl w oknie głównym
+Name[pt]=Mostrar na Janela de Fundo
+Name[pt_BR]=Mostrar na janela raiz
+Name[ro]=Afişează în fereastra rădăcină
+Name[ru]=Показывать на фоне рабочего стола
+Name[rw]=Kwerekana mu Idirishya Umuzi
+Name[sk]=Zobraziť v koreňovom okne
+Name[sl]=Prikaz v korenskem oknu
+Name[sr]=Прикажи у кореном прозору
+Name[sr@Latn]=Prikaži u korenom prozoru
+Name[sv]=Visa i rotfönster
+Name[ta]=மூல சாளரத்தில் காட்டு
+Name[tg]=Дар Тирезаи Решавӣ Намоиш додан
+Name[tr]=Kök Pencerede Göster
+Name[uk]=Відобразити на тлі екрана
+Name[wa]=Håyner e purnea raecene (li fond do scribanne)
+Name[zh_CN]=在根窗口中显示
+Name[zh_TW]=在根視窗中顯示
+NoDisplay=true
+X-DCOP-ServiceType=Multi
diff --git a/ktux/sprite.cpp b/ktux/sprite.cpp
new file mode 100644
index 0000000..205c754
--- /dev/null
+++ b/ktux/sprite.cpp
@@ -0,0 +1,254 @@
+//-----------------------------------------------------------------------------
+//
+// KTux - QCanvas based screensaver
+//
+// Copyright (c) Martin R. Jones 1999
+//
+
+#include <stdlib.h>
+#include <time.h>
+#include <qlabel.h>
+#include <qmessagebox.h>
+#include <qlayout.h>
+#include <qslider.h>
+#include <kstandarddirs.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kstdguiitem.h>
+#include <kbuttonbox.h>
+
+#include "spritepm.h"
+#include "spritemisc.h"
+#include "sprite.h"
+#include "sprite.moc"
+
+
+// libkscreensaver interface
+extern "C"
+{
+ KDE_EXPORT const char *kss_applicationName = "ktux";
+ KDE_EXPORT const char *kss_description = I18N_NOOP( "Tux Screen Saver" );
+ KDE_EXPORT const char *kss_version = "1.0.0";
+
+ KDE_EXPORT KScreenSaver *kss_create( WId id )
+ {
+ return new KSpriteSaver( id );
+ }
+
+ KDE_EXPORT QDialog *kss_setup()
+ {
+ return new KSpriteSetup();
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+KSpriteSetup::KSpriteSetup( QWidget *parent, const char *name )
+ : QDialog( parent, name, TRUE )
+{
+ KGlobal::locale()->insertCatalogue("ktux");
+ saver = 0;
+
+ readSettings();
+
+ setCaption(i18n("Setup KTux") );
+
+ QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
+ QHBoxLayout *tl1 = new QHBoxLayout;
+ tl->addLayout(tl1);
+ QVBoxLayout *tl11 = new QVBoxLayout(5);
+ tl1->addLayout(tl11);
+
+ QLabel *label = new QLabel( i18n("Speed:"), this );
+ label->setMinimumSize(label->sizeHint());
+ tl11->addStretch(1);
+ tl11->addWidget(label);
+
+ QSlider *sb = new QSlider(0, 100, 10, speed, QSlider::Horizontal, this );
+ tl11->addWidget(sb);
+ connect( sb, SIGNAL( valueChanged( int ) ), SLOT( slotSpeed( int ) ) );
+
+ preview = new QWidget( this );
+ preview->setFixedSize( 220, 170 );
+ preview->setBackgroundColor( black );
+ preview->show(); // otherwise saver does not get correct size
+ saver = new KSpriteSaver( preview->winId() );
+ tl1->addWidget(preview);
+
+ KButtonBox *bbox = new KButtonBox(this);
+ QButton *button = bbox->addButton( i18n("About"));
+ connect( button, SIGNAL( clicked() ), SLOT(slotAbout() ) );
+ bbox->addStretch(1);
+
+ button = bbox->addButton( KStdGuiItem::ok());
+ connect( button, SIGNAL( clicked() ), SLOT( slotOkPressed() ) );
+
+ button = bbox->addButton(KStdGuiItem::cancel());
+ connect( button, SIGNAL( clicked() ), SLOT( reject() ) );
+ bbox->layout();
+ tl->addWidget(bbox);
+
+ tl->freeze();
+}
+
+KSpriteSetup::~KSpriteSetup()
+{
+ delete saver;
+}
+
+// read settings from config file
+void KSpriteSetup::readSettings()
+{
+ KConfig *config = KGlobal::config();
+ config->setGroup( "Settings" );
+
+ speed = config->readNumEntry( "Speed", 50 );
+ if (speed > 100)
+ speed = 100;
+ else if (speed < 0)
+ speed = 0;
+}
+
+void KSpriteSetup::slotSpeed(int s)
+{
+ speed = s;
+ if (saver)
+ saver->setSpeed(speed);
+}
+
+// Ok pressed - save settings and exit
+void KSpriteSetup::slotOkPressed()
+{
+ KConfig *config = KGlobal::config();
+ config->setGroup("Settings");
+ config->writeEntry("Speed", speed);
+ config->sync();
+ accept();
+}
+
+void KSpriteSetup::slotAbout()
+{
+ QMessageBox::message(i18n("About KTux"),
+ i18n("KTux Version 1.0\n\nWritten by Martin R. Jones 1999\nmjones@kde.org"),
+ i18n("OK"));
+}
+
+
+//-----------------------------------------------------------------------------
+
+KSpriteSaver::KSpriteSaver( WId id ) : KScreenSaver( id )
+{
+ KGlobal::dirs()->addResourceType("sprite", KStandardDirs::kde_default("data") + "ktux/sprites/");
+
+ initialise();
+ readSettings();
+ blank();
+
+ connect(&mTimer, SIGNAL(timeout()), SLOT(slotTimeout()));
+ mTimer.start(120-mSpeed, true);
+}
+
+//-----------------------------------------------------------------------------
+KSpriteSaver::~KSpriteSaver()
+{
+ mTimer.stop();
+ delete mView;
+ delete mCanvas;
+}
+
+//-----------------------------------------------------------------------------
+//
+void KSpriteSaver::setSpeed(int speed)
+{
+ mSpeed = speed;
+ mTimer.changeInterval(120-mSpeed);
+}
+
+//-----------------------------------------------------------------------------
+// read settings from config file
+//
+void KSpriteSaver::readSettings()
+{
+ QString str;
+
+ KConfig *config = KGlobal::config();
+ config->setGroup("Settings");
+
+ mSpeed = config->readNumEntry("Speed", 50);
+
+ QString path = KGlobal::dirs()->findResourceDir( "sprite", "bg.png" );
+
+ SpritePixmapManager::manager()->setPixmapDir(path);
+
+ path += "spriterc";
+
+ KSimpleConfig *mConfig = new KSimpleConfig(path, true);
+ mConfig->setGroup("Config");
+ QStrList list;
+ int groups = mConfig->readListEntry("Groups", list);
+ mTimerIds.resize(groups);
+ for (int i = 0; i < groups; i++)
+ {
+ kdDebug() << "Group: " << list.at(i) << endl;;
+ mConfig->setGroup(list.at(i));
+ SpriteGroup *obj = new SpriteGroup(mCanvas, *mConfig);
+ mTimerIds[i] = startTimer(obj->refreshTime());
+ mGroups.append(obj);
+ }
+ delete mConfig;
+}
+
+//-----------------------------------------------------------------------------
+void KSpriteSaver::initialise()
+{
+ mCanvas = new QCanvas();
+ QPixmap pm( locate("sprite", "bg.png") );
+ mCanvas->setBackgroundPixmap( pm );
+ mCanvas->resize( width(), height() );
+ mView = new QCanvasView(mCanvas);
+ mView->viewport()->setBackgroundColor( black );
+ mView->resize( size());
+ mView->setFrameStyle( QFrame::NoFrame );
+ mView->setVScrollBarMode( QScrollView::AlwaysOff );
+ mView->setHScrollBarMode( QScrollView::AlwaysOff );
+ embed( mView );
+ mView->show();
+ SpriteRange::setFieldSize(mView->size());
+}
+
+//-----------------------------------------------------------------------------
+void KSpriteSaver::slotTimeout()
+{
+ mTimer.start(120-mSpeed, true);
+ SpriteGroup *grp;
+
+ for (grp = mGroups.first(); grp; grp = mGroups.next())
+ {
+ grp->next();
+ }
+
+ mCanvas->advance();
+}
+
+//-----------------------------------------------------------------------------
+void KSpriteSaver::timerEvent(QTimerEvent *ev)
+{
+ for (unsigned i = 0; i < mTimerIds.size(); i++)
+ {
+ if (mTimerIds[i] == ev->timerId())
+ {
+ mGroups.at(i)->refresh();
+ killTimer(ev->timerId());
+ mTimerIds[i] = startTimer(mGroups.at(i)->refreshTime());
+ break;
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+void KSpriteSaver::blank()
+{
+ setBackgroundColor( black );
+ erase();
+}
+
diff --git a/ktux/sprite.h b/ktux/sprite.h
new file mode 100644
index 0000000..d93e285
--- /dev/null
+++ b/ktux/sprite.h
@@ -0,0 +1,72 @@
+//-----------------------------------------------------------------------------
+//
+// ksprite - QCanvas based screensaver
+//
+// Copyright (c) Martin R. Jones 1996
+//
+
+#ifndef __SPRITE_H__
+#define __SPRITE_H__
+
+#include <qtimer.h>
+#include <qpushbutton.h>
+#include <qptrlist.h>
+#include <qstrlist.h>
+#include <qcanvas.h>
+#include <kscreensaver.h>
+#include "spriteanim.h"
+
+//-----------------------------------------------------------------------------
+class KSpriteSaver : public KScreenSaver
+{
+ Q_OBJECT
+public:
+ KSpriteSaver( WId id );
+ virtual ~KSpriteSaver();
+
+ void setSpeed(int speed);
+
+private:
+ void readSettings();
+ void initialise();
+ void blank();
+
+protected slots:
+ void slotTimeout();
+
+protected:
+ virtual void timerEvent(QTimerEvent *);
+
+protected:
+ QCanvas *mCanvas;
+ QCanvasView *mView;
+ QTimer mTimer;
+ int mSpeed;
+ QPtrList<SpriteGroup> mGroups;
+ QMemArray<int> mTimerIds;
+};
+
+class KSpriteSetup : public QDialog
+{
+ Q_OBJECT
+public:
+ KSpriteSetup( QWidget *parent = NULL, const char *name = NULL );
+ ~KSpriteSetup();
+
+protected:
+ void readSettings();
+
+private slots:
+ void slotSpeed(int s);
+ void slotOkPressed();
+ void slotAbout();
+
+private:
+ int speed;
+ QWidget *preview;
+ KSpriteSaver *saver;
+};
+
+
+#endif
+
diff --git a/ktux/spriteanim.cpp b/ktux/spriteanim.cpp
new file mode 100644
index 0000000..2c21838
--- /dev/null
+++ b/ktux/spriteanim.cpp
@@ -0,0 +1,161 @@
+//---------------------------------------------------------------------------
+//
+// spriteanim.cpp
+//
+// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
+//
+
+#include "spritemisc.h"
+#include "spritepm.h"
+#include "spriteanim.h"
+#include <kdebug.h>
+
+//===========================================================================
+//
+// SpriteObject stores the animations that create an object
+//
+SpriteObject::SpriteObject(SpritePixmapSequence *seq, QCanvas *c )
+ : QCanvasSprite(seq, c),
+ mCycle(0),
+ mLifeSpan(-1),
+ mSeq(seq)
+{
+}
+
+//---------------------------------------------------------------------------
+void SpriteObject::age()
+{
+ if (mLifeSpan > 0)
+ {
+ mLifeSpan--;
+ }
+ mCycle++;
+ if (mCycle > mSeq->delay(frame()))
+ {
+ setFrame((frame()+1)%frameCount());
+ mCycle = 0;
+ }
+}
+
+void SpriteObject::setBounds( int x1, int y1, int x2, int y2 )
+{
+ mBound = QRect( x1, y1, x2-x1, y2-y1 );
+}
+
+bool SpriteObject::outOfBounds() const
+{
+ bool in = mBound.contains( static_cast<int>(x()), static_cast<int>(y()) );
+ return !in;
+}
+
+//===========================================================================
+//
+// SpriteDef stores the animations that create an object
+//
+SpriteDef::SpriteDef(KConfigBase &config)
+{
+ read(config);
+}
+
+//---------------------------------------------------------------------------
+SpriteObject *SpriteDef::create( QCanvas *c )
+{
+ SpriteObject *sprite = 0;
+ if (mSeq)
+ {
+ int startX = mStartX.random();
+ int startY = mStartY.random();
+ sprite = new SpriteObject(mSeq, c);
+ sprite->setVelocity(mDirX.random(), mDirY.random());
+ if ( mDirX.min() != 0 || mDirX.max() != 0 ||
+ mDirY.min() != 0 || mDirY.max() != 0 ) {
+ sprite->setAnimated( true );
+ }
+ sprite->move(startX, startY);
+ sprite->setBounds(startX-1, startY-1, mEndX.random()+1, mEndY.random()+1);
+ sprite->setLifeSpan(mLifeSpan);
+ sprite->setZ(mZ);
+ sprite->show();
+ }
+
+ return sprite;
+}
+
+//---------------------------------------------------------------------------
+void SpriteDef::read(KConfigBase &config)
+{
+ mDirX.set(config.readEntry("DirectionX", "0"));
+ mDirY.set(config.readEntry("DirectionY", "0"));
+ mStartX.set(config.readEntry("StartX", "0"));
+ mStartY.set(config.readEntry("StartY", "0"));
+ mEndX.set(config.readEntry("EndX", "10000"));
+ mEndY.set(config.readEntry("EndY", "10000"));
+ mLifeSpan = config.readNumEntry("LifeSpan", -1);
+ mZ = config.readNumEntry("Z", 1);
+ QString animation = config.readEntry("Animation", "");
+ mSeq = SpriteSequenceManager::manager()->load(config, animation);
+ kdDebug() << "Set Z = " << mZ << endl;
+}
+
+//===========================================================================
+//
+// SpriteGroup
+//
+SpriteGroup::SpriteGroup(QCanvas *c, KConfigBase &config)
+ : mCanvas(c)
+{
+ mAvailable.setAutoDelete(true);
+ mActive.setAutoDelete(true);
+ read(config);
+}
+
+//---------------------------------------------------------------------------
+void SpriteGroup::next()
+{
+ QPtrListIterator<SpriteObject> it(mActive);
+
+ for (; it.current(); ++it)
+ {
+ SpriteObject *sprite = it.current();
+ if (sprite->outOfBounds() || sprite->dead())
+ {
+ mActive.removeRef(sprite);
+ }
+ else
+ {
+// sprite->forward(1);
+ sprite->age();
+ }
+ }
+}
+
+//---------------------------------------------------------------------------
+void SpriteGroup::refresh()
+{
+ if (((int) mActive.count()) < mCount)
+ {
+ SpriteObject *sprite = mAvailable.first()->create(mCanvas);
+ mActive.append(sprite);
+ }
+}
+
+
+//---------------------------------------------------------------------------
+void SpriteGroup::read(KConfigBase &config)
+{
+ SpriteRange countRange(config.readEntry("Count", "1"));
+ mCount = countRange.random();
+
+ mRefresh.set(config.readEntry("Refresh", "1000"));
+
+ QStrList anims;
+ config.readListEntry("Animations", anims);
+
+ for (anims.first(); anims.current(); anims.next())
+ {
+ config.setGroup(anims.current());
+ SpriteDef *obj = new SpriteDef(config);
+ mAvailable.append(obj);
+ }
+}
+
diff --git a/ktux/spriteanim.h b/ktux/spriteanim.h
new file mode 100644
index 0000000..9d5417b
--- /dev/null
+++ b/ktux/spriteanim.h
@@ -0,0 +1,96 @@
+//---------------------------------------------------------------------------
+//
+// spriteanim.h
+//
+// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
+//
+
+#ifndef SPRITEANIM_H
+#define SPRITEANIM_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qpixmap.h>
+#include <qdict.h>
+#include <qptrlist.h>
+#include <qstrlist.h>
+#include <qcanvas.h>
+#include <kconfigbase.h>
+#include <ksimpleconfig.h>
+
+//---------------------------------------------------------------------------
+//
+// SpriteObject stores the animations that create an object
+//
+class SpriteObject : public QCanvasSprite
+{
+public:
+ SpriteObject(SpritePixmapSequence *seq, QCanvas *c);
+
+ void setLifeSpan(int l) { mLifeSpan = l; }
+ void age();
+ bool dead() const { return (mLifeSpan == 0); }
+ void setBounds( int x1, int y1, int x2, int y2 );
+ bool outOfBounds() const;
+
+protected:
+ int mCycle;
+ int mLifeSpan;
+ SpritePixmapSequence *mSeq;
+ QRect mBound;
+};
+
+//---------------------------------------------------------------------------
+//
+// SpriteDef stores the definition of a sprite
+//
+class SpriteDef
+{
+public:
+ SpriteDef(KConfigBase &config);
+
+ SpriteObject *create( QCanvas *c );
+
+protected:
+ void read(KConfigBase &config);
+
+protected:
+ SpriteRange mDirX;
+ SpriteRange mDirY;
+ SpriteRange mStartX;
+ SpriteRange mStartY;
+ SpriteRange mEndX;
+ SpriteRange mEndY;
+ int mLifeSpan;
+ int mZ;
+ SpritePixmapSequence *mSeq;
+};
+
+//---------------------------------------------------------------------------
+//
+// SpriteGroup
+//
+class SpriteGroup
+{
+public:
+ SpriteGroup(QCanvas *c, KConfigBase &config);
+
+ void next();
+ void refresh();
+ int refreshTime() const { return mRefresh.random(); }
+
+protected:
+ void read(KConfigBase &config);
+
+protected:
+ QPtrList<SpriteDef> mAvailable;
+ QPtrList<SpriteObject> mActive;
+ int mCount;
+ SpriteRange mRefresh;
+ QCanvas *mCanvas;
+};
+
+#endif // SPRITEANIM_H
+
diff --git a/ktux/spritemisc.cpp b/ktux/spritemisc.cpp
new file mode 100644
index 0000000..f3a9a73
--- /dev/null
+++ b/ktux/spritemisc.cpp
@@ -0,0 +1,69 @@
+//-----------------------------------------------------------------------------
+//
+// spritemisc
+//
+// Copyright (c) Martin R. Jones 1999
+//
+
+#include <kapplication.h>
+#include "spritemisc.h"
+
+QSize SpriteRange::mFieldSize;
+
+SpriteRange::SpriteRange(const QString &str)
+{
+ set(str);
+}
+
+int SpriteRange::random() const
+{
+ int val = mMin;
+
+ if (mMax != mMin)
+ {
+ val = (KApplication::random()%(mMax-mMin)) + mMin;
+ }
+
+ return val;
+}
+
+void SpriteRange::set(const QString &str)
+{
+ int r = str.find("..");
+
+ if (r > 0)
+ {
+ mMin = parse(str.left(r));
+ mMax = parse(str.mid(r+2, 10));
+ }
+ else
+ {
+ mMin = mMax = parse(str);
+ }
+}
+
+void SpriteRange::setFieldSize(const QSize &size)
+{
+ mFieldSize = size;
+}
+
+int SpriteRange::parse(const QString &str)
+{
+ int val = 0;
+
+ if (str == "WIDTH")
+ {
+ val = mFieldSize.width();
+ }
+ else if (str == "HEIGHT")
+ {
+ val = mFieldSize.height();
+ }
+ else
+ {
+ val = str.toInt();
+ }
+
+ return val;
+}
+
diff --git a/ktux/spritemisc.h b/ktux/spritemisc.h
new file mode 100644
index 0000000..0a0d058
--- /dev/null
+++ b/ktux/spritemisc.h
@@ -0,0 +1,41 @@
+//-----------------------------------------------------------------------------
+//
+// spritemisc
+//
+// Copyright (c) Martin R. Jones 1999
+//
+
+#ifndef __SPRITEMISC_H__
+#define __SPRITEMISC_H__
+
+#include <qstring.h>
+#include <qsize.h>
+
+class SpriteRange
+{
+public:
+ SpriteRange(const QString &str);
+ SpriteRange(int l=0, int h=0) : mMin(l), mMax(h) {}
+
+ int min() const { return mMin; }
+ int max() const { return mMax; }
+
+ int random() const;
+
+ void set(int l, int h) { mMin=l; mMax=h; }
+ void set(const QString &str);
+
+ static void setFieldSize(const QSize &size);
+ static QSize fieldSize() { return mFieldSize; }
+
+protected:
+ int parse(const QString &str);
+
+protected:
+ int mMin;
+ int mMax;
+ static QSize mFieldSize;
+};
+
+#endif
+
diff --git a/ktux/spritepm.cpp b/ktux/spritepm.cpp
new file mode 100644
index 0000000..ec9ba47
--- /dev/null
+++ b/ktux/spritepm.cpp
@@ -0,0 +1,176 @@
+//---------------------------------------------------------------------------
+//
+// spritepm.cpp
+//
+// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
+//
+
+#include <stdlib.h>
+#include <kdebug.h>
+#include "spritepm.h"
+
+// static
+SpritePixmapManager *SpritePixmapManager::mManager = 0;
+
+//---------------------------------------------------------------------------
+//
+// Constructor
+//
+SpritePixmapManager::SpritePixmapManager()
+ : mPixmapDir(".")
+{
+ mPixmaps.setAutoDelete(true);
+}
+
+//---------------------------------------------------------------------------
+//
+// Destructor
+//
+SpritePixmapManager::~SpritePixmapManager()
+{
+}
+
+//---------------------------------------------------------------------------
+//
+// Load an image into the image manager
+//
+// Returns:
+// pointer to pixmap if loaded successfully, 0 otherwise.
+//
+const QPixmap *SpritePixmapManager::load(const QString & img)
+{
+ QPixmap *pixmap = mPixmaps.find(img);
+
+ if (!pixmap)
+ {
+ // pixmap has not yet been loaded.
+ kdDebug() << "Reading pixmap: " << img << endl;
+ QString path = mPixmapDir + QString("/") + img;
+ pixmap = new QPixmap(path);
+
+ if (!pixmap->isNull())
+ {
+ mPixmaps.insert(img,pixmap);
+ }
+ else
+ {
+ delete pixmap;
+ pixmap = 0;
+ kdDebug() << "read failed" << endl;;
+ }
+ }
+
+ return pixmap;
+}
+
+//---------------------------------------------------------------------------
+//
+// returns a pointer to the pixmap manager.
+//
+SpritePixmapManager *SpritePixmapManager::manager()
+{
+ if (!mManager)
+ {
+ mManager = new SpritePixmapManager();
+ }
+
+ return mManager;
+}
+
+//===========================================================================
+//
+SpritePixmapSequence::SpritePixmapSequence(QPtrList<QPixmap> pm, QPtrList<QPoint> hs,
+ QMemArray<int> d)
+ : QCanvasPixmapArray(pm, hs), mDelays(d)
+{
+}
+
+// static
+SpriteSequenceManager *SpriteSequenceManager::mManager = 0;
+
+//===========================================================================
+//
+// Constructor
+//
+SpriteSequenceManager::SpriteSequenceManager()
+{
+ mSprites.setAutoDelete(true);
+}
+
+//---------------------------------------------------------------------------
+//
+// Destructor
+//
+SpriteSequenceManager::~SpriteSequenceManager()
+{
+}
+
+//---------------------------------------------------------------------------
+//
+// Load an image into the sprite manager
+//
+// Returns:
+// pointer to sprite if loaded successfully, 0 otherwise.
+//
+SpritePixmapSequence *SpriteSequenceManager::load(KConfigBase &config,
+ const QString & name)
+{
+ SpritePixmapSequence *sprite = mSprites.find(name);
+
+ if (!sprite)
+ {
+ kdDebug() << "Reading sprite: " << name << endl;
+ config.setGroup(name);
+ sprite = read(config);
+ if (sprite)
+ {
+ mSprites.insert(name, sprite);
+ }
+ }
+
+ return sprite;
+}
+
+//---------------------------------------------------------------------------
+//
+SpritePixmapSequence *SpriteSequenceManager::read(KConfigBase &config)
+{
+ QStrList strImages;
+ QStrList strDelays;
+ QPtrList<QPixmap> pixmaps;
+ QPtrList<QPoint> hotspots;
+
+ int frames = config.readListEntry("Images", strImages);
+ config.readListEntry("Delays", strDelays);
+
+ QMemArray<int> delays(frames);
+
+ for (int i = 0; i < frames; i++)
+ {
+ const QPixmap *pixmap =
+ SpritePixmapManager::manager()->load(strImages.at(i));
+ if (pixmap)
+ {
+ pixmaps.append(pixmap);
+ hotspots.append(new QPoint(0,0));
+ delays[i] = atoi(strDelays.at(i));
+ }
+ }
+
+ return new SpritePixmapSequence(pixmaps, hotspots, delays);
+}
+
+//---------------------------------------------------------------------------
+//
+// returns a pointer to the sprite manager.
+//
+SpriteSequenceManager *SpriteSequenceManager::manager()
+{
+ if (!mManager)
+ {
+ mManager = new SpriteSequenceManager();
+ }
+
+ return mManager;
+}
+
diff --git a/ktux/spritepm.h b/ktux/spritepm.h
new file mode 100644
index 0000000..e9f24be
--- /dev/null
+++ b/ktux/spritepm.h
@@ -0,0 +1,85 @@
+//---------------------------------------------------------------------------
+//
+// spritepm.h
+//
+// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
+//
+
+#ifndef SPRITEPM_H
+#define SPRITEPM_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qdict.h>
+#include <qpixmap.h>
+#include <qcanvas.h>
+#include <kconfigbase.h>
+#include <ksimpleconfig.h>
+
+//---------------------------------------------------------------------------
+//
+// SpritePixmapManager stores the frames used in animations.
+//
+class SpritePixmapManager
+{
+public:
+ SpritePixmapManager();
+ virtual ~SpritePixmapManager();
+
+ void setPixmapDir(const QString &dir)
+ { mPixmapDir = dir; }
+ void reset()
+ { mPixmapDir = "."; mPixmaps.clear(); }
+ const QPixmap *load(const QString & img);
+ const QPixmap *pixmap(const char *img) const
+ { return mPixmaps.find(img); }
+
+ static SpritePixmapManager *manager();
+
+public:
+ QString mPixmapDir; // get pixmaps from here
+ QDict<QPixmap> mPixmaps; // list of pixmaps
+ static SpritePixmapManager *mManager; // static pointer to instance
+};
+
+//---------------------------------------------------------------------------
+//
+class SpritePixmapSequence : public QCanvasPixmapArray
+{
+public:
+ SpritePixmapSequence(QPtrList<QPixmap> pm, QPtrList<QPoint> hs, QMemArray<int> d);
+
+ int delay(int i) const { return mDelays[i]; }
+
+protected:
+ QMemArray<int> mDelays;
+};
+
+//---------------------------------------------------------------------------
+//
+// SpriteManager stores the animation sequences
+//
+class SpriteSequenceManager
+{
+public:
+ SpriteSequenceManager();
+ ~SpriteSequenceManager();
+
+ SpritePixmapSequence *load(KConfigBase &config, const QString & name);
+ SpritePixmapSequence *sprite(const char *name)
+ { return mSprites.find(name); }
+
+ static SpriteSequenceManager *manager();
+
+protected:
+ SpritePixmapSequence *read(KConfigBase &config);
+
+protected:
+ QDict<SpritePixmapSequence> mSprites;
+ static SpriteSequenceManager *mManager;
+};
+
+#endif // SPRITEPM_H
+
diff --git a/ktux/sprites/Makefile.am b/ktux/sprites/Makefile.am
new file mode 100644
index 0000000..8f27a80
--- /dev/null
+++ b/ktux/sprites/Makefile.am
@@ -0,0 +1,8 @@
+# Add all of your pixmaps here
+sprite_DATA = anim0001.png anim0002.png anim0003.png anim0004.png \
+ anim0005.png anim0006.png anim0007.png anim0008.png \
+ anim0009.png anim0010.png bg.png flare0001.png \
+ flare0002.png spriterc star0001.png star0002.png
+
+# This is where it will all be installed
+spritedir = $(kde_datadir)/ktux/sprites
diff --git a/ktux/sprites/anim0001.png b/ktux/sprites/anim0001.png
new file mode 100644
index 0000000..f53aef7
--- /dev/null
+++ b/ktux/sprites/anim0001.png
Binary files differ
diff --git a/ktux/sprites/anim0002.png b/ktux/sprites/anim0002.png
new file mode 100644
index 0000000..ca06fe3
--- /dev/null
+++ b/ktux/sprites/anim0002.png
Binary files differ
diff --git a/ktux/sprites/anim0003.png b/ktux/sprites/anim0003.png
new file mode 100644
index 0000000..15c604c
--- /dev/null
+++ b/ktux/sprites/anim0003.png
Binary files differ
diff --git a/ktux/sprites/anim0004.png b/ktux/sprites/anim0004.png
new file mode 100644
index 0000000..b48da81
--- /dev/null
+++ b/ktux/sprites/anim0004.png
Binary files differ
diff --git a/ktux/sprites/anim0005.png b/ktux/sprites/anim0005.png
new file mode 100644
index 0000000..3c308ec
--- /dev/null
+++ b/ktux/sprites/anim0005.png
Binary files differ
diff --git a/ktux/sprites/anim0006.png b/ktux/sprites/anim0006.png
new file mode 100644
index 0000000..debe245
--- /dev/null
+++ b/ktux/sprites/anim0006.png
Binary files differ
diff --git a/ktux/sprites/anim0007.png b/ktux/sprites/anim0007.png
new file mode 100644
index 0000000..48ce5c8
--- /dev/null
+++ b/ktux/sprites/anim0007.png
Binary files differ
diff --git a/ktux/sprites/anim0008.png b/ktux/sprites/anim0008.png
new file mode 100644
index 0000000..2a299a4
--- /dev/null
+++ b/ktux/sprites/anim0008.png
Binary files differ
diff --git a/ktux/sprites/anim0009.png b/ktux/sprites/anim0009.png
new file mode 100644
index 0000000..11c4ea6
--- /dev/null
+++ b/ktux/sprites/anim0009.png
Binary files differ
diff --git a/ktux/sprites/anim0010.png b/ktux/sprites/anim0010.png
new file mode 100644
index 0000000..2d5cbf8
--- /dev/null
+++ b/ktux/sprites/anim0010.png
Binary files differ
diff --git a/ktux/sprites/bg.png b/ktux/sprites/bg.png
new file mode 100644
index 0000000..2ddefdb
--- /dev/null
+++ b/ktux/sprites/bg.png
Binary files differ
diff --git a/ktux/sprites/flare0001.png b/ktux/sprites/flare0001.png
new file mode 100644
index 0000000..0e7b146
--- /dev/null
+++ b/ktux/sprites/flare0001.png
Binary files differ
diff --git a/ktux/sprites/flare0002.png b/ktux/sprites/flare0002.png
new file mode 100644
index 0000000..46c9366
--- /dev/null
+++ b/ktux/sprites/flare0002.png
Binary files differ
diff --git a/ktux/sprites/spriterc b/ktux/sprites/spriterc
new file mode 100644
index 0000000..16e3929
--- /dev/null
+++ b/ktux/sprites/spriterc
@@ -0,0 +1,62 @@
+[Config]
+Groups=G_Ship,G_Star,G_Flare
+Background=bg.ppm
+
+# Ship
+[G_Ship]
+Animations=O_Fly
+Count=1
+Refresh=4000
+
+[O_Fly]
+Animation=A_Base
+DirectionX=5
+DirectionY=2
+StartX=-250
+StartY=-300..HEIGHT
+EndX=WIDTH
+EndY=HEIGHT
+Z=100
+
+[A_Base]
+Images=anim0001.png,anim0002.png,anim0003.png,anim0004.png,anim0005.png,anim0006.png,anim0007.png,anim0008.png,anim0009.png,anim0010.png
+Delays=1,1,1,1,1,1,1,1,1,1
+
+# Star
+[G_Star]
+Animations=O_Star
+Count=10
+Refresh=100..500
+
+[O_Star]
+Animation=A_Star
+DirectionX=0
+DirectionY=0
+StartX=0..WIDTH
+StartY=0..HEIGHT
+LifeSpan=2000
+Z=5
+
+[A_Star]
+Images=star0001.png,star0002.png
+Delays=3,3
+
+# Flare
+[G_Flare]
+Animations=O_Flare
+Count=2
+Refresh=500..5000
+
+[O_Flare]
+Animation=A_Flare
+DirectionX=0
+DirectionY=0
+StartX=0..WIDTH
+StartY=0..HEIGHT
+LifeSpan=110
+Z=10
+
+[A_Flare]
+Images=flare0001.png,flare0002.png,flare0001.png
+Delays=5,100,5
+
diff --git a/ktux/sprites/star0001.png b/ktux/sprites/star0001.png
new file mode 100644
index 0000000..9913b17
--- /dev/null
+++ b/ktux/sprites/star0001.png
Binary files differ
diff --git a/ktux/sprites/star0002.png b/ktux/sprites/star0002.png
new file mode 100644
index 0000000..a42d0e7
--- /dev/null
+++ b/ktux/sprites/star0002.png
Binary files differ