[Kstars-devel] KDE/kdeedu/kstars/kstars
Jason Harris
kstars at 30doradus.org
Tue Dec 25 01:28:27 CET 2007
SVN commit 752585 by harris:
Applying patch to improve rendering time for stars by a factor of
twenty. Stars are now drawn as pixmaps, rather than calling
drawEllipse() for each star. The star pixmaps are stored in a static
QHash in StarObject. The hash contains images for all spectral types,
and all sizes. This is how stars were rendered in 3,5, so this is a
regression fix.
The star pixmaps are regenerated when the user selects a new color
saturation level for stars (this is effected by modifying the width of
the QPen used to draw the colored rim of the circle), and when the
user chooses a color scheme that uses solid red, black or white star
images (without a colored rim).
Also, stars are now rendered slightly larger on-screen, closer to what
was done in 3.5.
CCMAIL: kstars-devel at kde.org
M +11 -0 colorscheme.cpp
M +2 -2 colorscheme.h
M +3 -0 opscolors.cpp
M +18 -14 skycomponents/starcomponent.cpp
M +3 -3 skymapevents.cpp
M +95 -10 starobject.cpp
M +3 -0 starobject.h
--- trunk/KDE/kdeedu/kstars/kstars/colorscheme.cpp #752584:752585
@@ -28,6 +28,7 @@
#include <kconfiggroup.h>
#include "ksutils.h"
+#include "Options.h"
ColorScheme::ColorScheme() : FileName() {
//Each color has two names associated with it. The KeyName is its
@@ -336,3 +337,13 @@
cg.writeEntry( "StarColorMode", starColorMode() );
cg.writeEntry( "StarColorIntensity", starColorIntensity() );
}
+
+void ColorScheme::setStarColorMode( int mode ) {
+ StarColorMode = mode;
+ Options::setStarColorMode( mode );
+}
+
+void ColorScheme::setStarColorIntensity( int intens ) {
+ StarColorIntensity = intens;
+ Options::setStarColorIntensity( intens );
+}
--- trunk/KDE/kdeedu/kstars/kstars/colorscheme.h #752584:752585
@@ -153,13 +153,13 @@
*Set the star color mode used by the color scheme
*@p mode the star color mode to use
*/
- void setStarColorMode( int mode ) { StarColorMode = mode; }
+ void setStarColorMode( int mode );
/**
*Set the star color intensity value used by the color scheme
*@p intens The star color intensity value
*/
- void setStarColorIntensity( int intens) { StarColorIntensity = intens; }
+ void setStarColorIntensity( int intens);
private:
int StarColorMode, StarColorIntensity;
--- trunk/KDE/kdeedu/kstars/kstars/opscolors.cpp #752584:752585
@@ -34,6 +34,7 @@
#include "kstarsdata.h"
#include "skymap.h"
#include "colorscheme.h"
+#include "starobject.h"
static int ItemColorData = Qt::UserRole + 1;
@@ -233,6 +234,7 @@
void OpsColors::slotStarColorMode( int i ) {
ksw->data()->colorScheme()->setStarColorMode( i );
+ StarObject::initImages();
if ( ksw->data()->colorScheme()->starColorMode() != 0 ) //mode is not "Real Colors"
kcfg_StarColorIntensity->setEnabled( false );
@@ -242,6 +244,7 @@
void OpsColors::slotStarColorIntensity( int i ) {
ksw->data()->colorScheme()->setStarColorIntensity( i );
+ StarObject::initImages();
}
#include "opscolors.moc"
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #752584:752585
@@ -74,6 +74,8 @@
readLineNumbers();
readData( Options::magLimitDrawStar() );
+
+ StarObject::initImages();
}
void StarComponent::update( KStarsData *data, KSNumbers *num )
@@ -206,25 +208,27 @@
m_zoomMagLimit = maglim;
- float sizeFactor = 6.0 + (lgz - lgmin);
+ float sizeFactor = 10.0 + (lgz - lgmin);
double labelMagLim = Options::starLabelDensity() / 5.0;
labelMagLim += ( 12.0 - labelMagLim ) * ( lgz - lgmin) / (lgmax - lgmin );
if ( labelMagLim > 8.0 ) labelMagLim = 8.0;
- //Set the brush
- QColor fillColor( Qt::white );
- if ( starColorMode() == 1 ) fillColor = Qt::red;
- if ( starColorMode() == 2 ) fillColor = Qt::black;
- psky.setBrush( QBrush( fillColor ) );
- if ( starColorMode() > 0 )
- psky.setPen( QPen( fillColor ) );
- else
- //Reset the colors before drawing the stars.
- //Strictly speaking, we don't need to do this every time, but once per
- //draw loop isn't too expensive.
- StarObject::updateColors( (! Options::useAntialias() ||
- map->isSlewing()), starColorIntensity() );
+//REMOVE
+// //Set the brush
+// QColor fillColor( Qt::white );
+// if ( starColorMode() == 1 ) fillColor = Qt::red;
+// if ( starColorMode() == 2 ) fillColor = Qt::black;
+// psky.setBrush( QBrush( fillColor ) );
+// if ( starColorMode() > 0 )
+// psky.setPen( QPen( fillColor ) );
+// else
+// //Reset the colors before drawing the stars.
+// //Strictly speaking, we don't need to do this every time, but once per
+// //draw loop isn't too expensive.
+// StarObject::updateColors( (! Options::useAntialias() ||
+// map->isSlewing()), starColorIntensity() );
+//END_REMOVE
//Loop for drawing star images
MeshIterator region(m_skyMesh, DRAW_BUF);
--- trunk/KDE/kdeedu/kstars/kstars/skymapevents.cpp #752584:752585
@@ -781,14 +781,14 @@
psky.fillRect( 0, 0, width(), height(), QBrush( data->colorScheme()->colorNamed( "SkyColor" ) ) );
//TIMING
- // QTime t2;
- // t2.start();
+// QTime t2;
+// t2.start();
//Draw all sky elements
data->skyComposite()->draw( psky );
//TIMING
- // kDebug() << QString("SkyMapComposite::draw() took %1 ms").arg(t2.elapsed());
+// kDebug() << QString("SkyMapComposite::draw() took %1 ms").arg(t2.elapsed());
//Finish up
psky.end();
--- trunk/KDE/kdeedu/kstars/kstars/starobject.cpp #752584:752585
@@ -32,6 +32,7 @@
#include "skycomponents/skylabeler.h"
QMap<QString, QColor> StarObject::ColorMap;
+QHash<QString, QPixmap> StarObject::StarImage;
//----- Static Methods -----
//
@@ -104,6 +105,74 @@
updateID = updateNumID = 0;
}
+void StarObject::initImages() {
+ if ( Options::starColorMode() == 0 ) { //Real colors
+ ColorMap.insert( "O", QColor::fromRgb( 0, 0, 255 ) );
+ ColorMap.insert( "B", QColor::fromRgb( 0, 200, 255 ) );
+ ColorMap.insert( "A", QColor::fromRgb( 0, 255, 255 ) );
+ ColorMap.insert( "F", QColor::fromRgb( 200, 255, 100 ) );
+ ColorMap.insert( "G", QColor::fromRgb( 255, 255, 0 ) );
+ ColorMap.insert( "K", QColor::fromRgb( 255, 100, 0 ) );
+ ColorMap.insert( "M", QColor::fromRgb( 255, 0, 0 ) );
+ } else if ( Options::starColorMode() == 1 ) { //Red stars
+ ColorMap.insert( "O", QColor::fromRgb( 255, 0, 0 ) );
+ ColorMap.insert( "B", QColor::fromRgb( 255, 0, 0 ) );
+ ColorMap.insert( "A", QColor::fromRgb( 255, 0, 0 ) );
+ ColorMap.insert( "F", QColor::fromRgb( 255, 0, 0 ) );
+ ColorMap.insert( "G", QColor::fromRgb( 255, 0, 0 ) );
+ ColorMap.insert( "K", QColor::fromRgb( 255, 0, 0 ) );
+ ColorMap.insert( "M", QColor::fromRgb( 255, 0, 0 ) );
+ } else if ( Options::starColorMode() == 2 ) { //Black stars
+ ColorMap.insert( "O", QColor::fromRgb( 0, 0, 0 ) );
+ ColorMap.insert( "B", QColor::fromRgb( 0, 0, 0 ) );
+ ColorMap.insert( "A", QColor::fromRgb( 0, 0, 0 ) );
+ ColorMap.insert( "F", QColor::fromRgb( 0, 0, 0 ) );
+ ColorMap.insert( "G", QColor::fromRgb( 0, 0, 0 ) );
+ ColorMap.insert( "K", QColor::fromRgb( 0, 0, 0 ) );
+ ColorMap.insert( "M", QColor::fromRgb( 0, 0, 0 ) );
+ } else if ( Options::starColorMode() == 3 ) { //White stars
+ ColorMap.insert( "O", QColor::fromRgb( 255, 255, 255 ) );
+ ColorMap.insert( "B", QColor::fromRgb( 255, 255, 255 ) );
+ ColorMap.insert( "A", QColor::fromRgb( 255, 255, 255 ) );
+ ColorMap.insert( "F", QColor::fromRgb( 255, 255, 255 ) );
+ ColorMap.insert( "G", QColor::fromRgb( 255, 255, 255 ) );
+ ColorMap.insert( "K", QColor::fromRgb( 255, 255, 255 ) );
+ ColorMap.insert( "M", QColor::fromRgb( 255, 255, 255 ) );
+ }
+
+ foreach ( QString color, ColorMap.keys() ) {
+ QString imKey = color+"14";
+ QPixmap BigImage( 14, 14 );
+ BigImage.fill( Qt::transparent );
+
+ QPainter p;
+ p.begin( &BigImage );
+ p.setRenderHint(QPainter::Antialiasing, true );
+
+ //Set the width of the pen according to starColorIntensity()
+ float w=2.0;
+ if ( Options::starColorMode() == 0 ) {
+ w = 2.0*float(Options::starColorIntensity())/4.0;
+ }
+
+ p.setPen( QPen(ColorMap[color], w) );
+ if ( Options::starColorMode() == 0 ) {
+ p.setBrush( QColor(Qt::white) );
+ } else {
+ p.setBrush( p.pen().color() );
+ }
+
+ p.drawEllipse( QRect( 2, 2, 10, 10 ) );
+ p.end();
+ StarImage.insert( imKey, BigImage );
+
+ for ( int size = 13; size > 0; size-- ) {
+ imKey = color+QString("%1").arg(size);
+ StarImage.insert( imKey, BigImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
+ }
+ }
+}
+
void StarObject::showPopupMenu( KSPopupMenu *pmenu, const QPoint &pos ) {
pmenu->createStarMenu( this ); pmenu->popup( pos );
}
@@ -325,23 +394,39 @@
void StarObject::draw( QPainter &psky, float x, float y, float size,
bool useRealColors, int scIntensity, bool /*showMultiple*/ ) {
- if ( useRealColors ) {
+//REMOVE
+// if ( useRealColors ) {
//Realistic colors
//Stars rendered as a white core with a colored ring.
//With antialiasing, we can just set the ring thickness to 0.1*scIntensity
//However, this won't work without antialiasing, because the ring thickness
//cant be <1 in this case. So we desaturate the pen color instead
- if ( Options::useAntialias() )
- psky.setPen( QPen( color(), 0.1*scIntensity ) );
- else {
- psky.setPen( QPen( color(), 1 ) );
+
+// if ( Options::useAntialias() )
+// psky.setPen( QPen( color(), 0.1*scIntensity ) );
+// else {
+// psky.setPen( QPen( color(), 1 ) );
+// }
+// }
+//END_REMOVE
+
+ int isize = int(size);
+ if ( isize >= 14 ) {
+ kDebug() << "Star too big: " << size << endl;
+ isize = 14;
}
- }
- if ( Options::useAntialias() )
- psky.drawEllipse( QRectF( x - 0.5*size, y - 0.5*size, size, size ) );
- else
- psky.drawEllipse( QRect( int(x - 0.5*size), int(y - 0.5*size), int(size), int(size) ) );
+ float offset = 0.5*float(isize);
+ QString imKey = SpType.at(0)+QString("%1").arg(isize);
+ psky.drawPixmap( QPointF(x-offset, y-offset), StarImage[imKey] );
+
+//REMOVE
+// if ( Options::useAntialias() )
+// psky.drawEllipse( QRectF( x - 0.5*size, y - 0.5*size, size, size ) );
+// else
+// psky.drawEllipse( QRect( int(x - 0.5*size), int(y - 0.5*size), int(size), int(size) ) );
+//END_REMOVE
+
}
// The two routines below seem overly complicated but at least they are doing
--- trunk/KDE/kdeedu/kstars/kstars/starobject.h #752584:752585
@@ -283,11 +283,14 @@
*/
static void updateColors( bool desaturateColors, int saturation );
+ static void initImages();
+
quint64 updateID;
quint64 updateNumID;
protected:
static QMap<QString, QColor> ColorMap;
+ static QHash<QString, QPixmap> StarImage;
private:
QString SpType;
More information about the Kstars-devel
mailing list