[Kstars-devel] branches/work/kdeedu_kstars_htm/kstars/kstars

James Bowlin bowlin at mindspring.com
Sun Aug 12 23:41:59 CEST 2007


SVN commit 699382 by jbowlin:

Labels are now never overlapping the info boxes.  The problem _was_
that the coordinates were changing when the boxes weren't being drawn.
[Holy Heisenberg Batman!]

I fixed the problem with the kludge of copying the coordinates every
time the boxes are drawn and then using the copies when it came time
to reserve space for the boxes in the SkyLabeler.  If the coordinates
stop changing (when the labels don't move) then this code can be
removed.

I made an array of InfoBox* which greatly simplified the drawBoxes()
routine and also the new reserveBoxes() routine.  The array can be
used to simplify a lot of the other code in InfoBoxes but I haven't
done that yet.

I also noticed that the InfoBoxes seem to get drawn more often than
is needed.  The get drawn about 20 times in quick succession at
startup and then they get drawn twice per second thereafter.  The
two draws are in rapid succession and I suspect that just one would
suffice.

I'm returning out of SkyMap::drawHighlightConstellation to keep my
draws fast.  The code that lets the user select this should be
waiting for me in the trunk.

CCMAIL: kstars-devel at kde.org


 M  +25 -36    infoboxes.cpp  
 M  +3 -0      infoboxes.h  
 M  +1 -0      skymapdraw.cpp  


--- branches/work/kdeedu_kstars_htm/kstars/kstars/infoboxes.cpp #699381:699382
@@ -35,7 +35,6 @@
 		boxColor(colorText), grabColor(colorGrab), bgColor(colorBG),
 		GeoBox(0), FocusBox(0), TimeBox(0)
 {
-
 	int tx = tp.x();
 	int ty = tp.y();
 	int gx = gp.x();
@@ -54,6 +53,9 @@
 	GeoBox   = new InfoBox( gx, gy, gshade, QString(), QString() );
 	TimeBox  = new InfoBox( tx, ty, tshade, QString(), QString(), QString() );
 	FocusBox = new InfoBox( fx, fy, fshade, QString(), QString(), QString() );
+	m_box[0] = GeoBox;
+	m_box[1] = TimeBox;
+	m_box[2] = FocusBox;
 
 	fixCollisions( TimeBox );
 	fixCollisions( FocusBox );
@@ -77,6 +79,9 @@
 	GeoBox   = new InfoBox( gx, gy, gshade, QString(), QString() );
 	TimeBox  = new InfoBox( tx, ty, tshade, QString(), QString(), QString() );
 	FocusBox = new InfoBox( fx, fy, fshade, QString(), QString(), QString() );
+	m_box[0] = GeoBox;
+	m_box[1] = TimeBox;
+	m_box[2] = FocusBox;
 
 	fixCollisions( TimeBox );
 	fixCollisions( FocusBox );
@@ -98,52 +103,36 @@
 
 void InfoBoxes::drawBoxes( QPainter &p, const QColor &FGColor, const QColor &grabColor,
 		const QColor &bgColor, unsigned int bgMode ) {
-	if ( isVisible() ) {
-		if ( GeoBox->isVisible() ) {
-			p.setPen( QPen( FGColor ) );
-			if ( GrabbedBox == 1 ) {
-				p.setPen( QPen( grabColor ) );
-				p.drawRect( GeoBox->x(), GeoBox->y(), GeoBox->width(), GeoBox->height() );
-			}
-			GeoBox->draw( p, bgColor, bgMode );
-		}
 
-		if ( TimeBox->isVisible() ) {
-			p.setPen( QPen( FGColor ) );
-			if ( GrabbedBox == 2 ) {
-				p.setPen( QPen( grabColor ) );
-				p.drawRect( TimeBox->x(), TimeBox->y(), TimeBox->width(), TimeBox->height() );
-			}
-			TimeBox->draw( p, bgColor, bgMode );
-		}
+	if (  ! isVisible() ) return;
 
-		if ( FocusBox->isVisible() ) {
-			p.setPen( QPen( FGColor ) );
-			if ( GrabbedBox == 3 ) {
-				p.setPen( QPen( grabColor ) );
-				p.drawRect( FocusBox->x(), FocusBox->y(), FocusBox->width(), FocusBox->height() );
-			}
-			FocusBox->draw( p, bgColor, bgMode );
+	p.setPen( QPen( FGColor ) );
+
+	for ( int i = 0; i < 3; i++ ) {
+		InfoBox* box = m_box[i];
+		if ( ! box->isVisible() ) continue;
+		if ( GrabbedBox == i + 1 ) {
+			p.setPen( QPen( grabColor ) );
+			p.drawRect( box->x(), box->y(), box->width(), box->height() );
 		}
+		box->draw( p, bgColor, bgMode );
+		m_saveFocus[i][0] = box->x();
+		m_saveFocus[i][1] = box->y();
 	}
 }
 
 void InfoBoxes::reserveBoxes( QPainter& psky )
 {
 	if ( ! isVisible() ) return;
-	SkyLabeler* skyLabeler = SkyLabeler::Instance();
 
-	if ( GeoBox->isVisible() ) {
-		skyLabeler->markRect( GeoBox->x(), GeoBox->y(), GeoBox->width(), GeoBox->height(), psky );
+	SkyLabeler* skyLabeler = SkyLabeler::Instance();
+	for ( int i = 0; i < 3; i++ ) {
+		InfoBox* box = m_box[i];
+		if ( ! box->isVisible() ) continue;
+		int x = m_saveFocus[i][0];
+		int y = m_saveFocus[i][1];
+		skyLabeler->markRect( x, y, box->width(), box->height(), psky );
 	}
-
-	if ( TimeBox->isVisible() ) {
-		skyLabeler->markRect( TimeBox->x(), TimeBox->y(), TimeBox->width(), TimeBox->height(), psky );
-	}
-
-	if ( FocusBox->isVisible() ) {
-		skyLabeler->markRect( FocusBox->x(), FocusBox->y(), FocusBox->width(), FocusBox->height(), psky );
-	}
 }
 
 bool InfoBoxes::grabBox( QMouseEvent *e ) {
--- branches/work/kdeedu_kstars_htm/kstars/kstars/infoboxes.h #699381:699382
@@ -261,6 +261,9 @@
 	const QColor boxColor, grabColor, bgColor;
 	QPoint GrabPos;
 	InfoBox *GeoBox, *FocusBox, *TimeBox;
+	InfoBox* m_box[3];
+
+	int m_saveFocus[3][2];
 };
 
 #endif
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skymapdraw.cpp #699381:699382
@@ -166,6 +166,7 @@
 }
 
 void SkyMap::drawHighlightConstellation( QPainter &psky, double scale ) {
+	return; // -jbb
 	const QPolygonF* cbound =
 		ConstellationBoundary::Instance()->constellationPoly( focus() );
 


More information about the Kstars-devel mailing list