summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/starpixmap.cpp
blob: 1b4e006a8ef76d38b34334beb5c15cf7cc47a21f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
                          starpixmap.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : Wed Sep 19 2001
    copyright            : (C) 2001 by Thomas Kabelmann
    email                : tk78@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#include "starpixmap.h"

#include <kimageeffect.h>
#include <tqbitmap.h>
#include <tqimage.h>
#include <tqpainter.h>

#define STARSIZE 24

StarPixmap::StarPixmap (int starColorMode, int starColorIntensity)
	: colorMode (starColorMode), colorIntensity (starColorIntensity)
{
	loadPixmaps (starColorMode, starColorIntensity);
}

TQPixmap* StarPixmap::getPixmap (TQChar *color, int size) {
	int c;
//	the colors from blue to red	+, O, B, A, F, G, K, M, N, P
// if *color is '+' use white star
	switch (*color) {
		case 'O' : c = 1; break;
		case 'B' : c = 2; break;
		case 'A' : c = 3; break;
		case 'F' : c = 4; break;
		case 'G' : c = 5; break;
		case 'K' : c = 6; break;
		case 'M' : c = 7; break;
		case 'N' : c = 8; break;
		case 'P' : c = 9; break;
		default : c = 0;
	}
	// don't overflow the array
	if (size > 25) size = 25;
	return &starPixmaps[c][size];
}

void StarPixmap::setColorMode( int newMode ) {
	colorMode = newMode;
	loadPixmaps ( colorMode, colorIntensity );
}

void StarPixmap::setIntensity ( int newIntensity ) {
	colorIntensity = newIntensity;
	loadPixmaps ( colorMode, colorIntensity );
}

void StarPixmap::loadPixmaps (int newColorMode, int newColorIntensity) {
	colorMode = newColorMode;
	colorIntensity = newColorIntensity;

	if (colorIntensity < 0) colorIntensity = 0;	// min

	TQPixmap pix (STARSIZE, STARSIZE);
	TQBitmap mask (STARSIZE, STARSIZE);
	TQImage image;
	TQPainter p;
	TQMemArray<TQColor> starColor;
	starColor.resize( 8 );
	image.setAlphaBuffer(true);

	starColor[0] = TQColor( 255, 255, 255 );   //default to white
	starColor[1] = TQColor(   0,   0, 255 );   //type O
	starColor[2] = TQColor(   0, 200, 255 );   //type B
	starColor[3] = TQColor(   0, 255, 255 );   //type A
	starColor[4] = TQColor( 200, 255, 100 );   //type F
	starColor[5] = TQColor( 255, 255,   0 );   //type G
	starColor[6] = TQColor( 255, 100,   0 );   //type K
	starColor[7] = TQColor( 255,   0,   0 );   //type M

// background of the star
	if ( colorMode==1 ) // night colors (fill red, no temperature colors)
		pix.fill (TQt::red);
	else if ( colorMode==2 ) //star chart colors (fill black, no temperature colors)
		pix.fill (TQt::black);
	else
		pix.fill (TQt::white);	// default (white)

	for (int color = 0; color < 10; color ++) {
		int ic = color;
		if ( color > 7 ) ic = 7;

		if (colorMode==0)	{
			p.begin (&pix);
			p.setPen (TQPen (starColor[ic], colorIntensity));	// the intensity of color determines the width of the pen
			p.drawEllipse (0, 0, STARSIZE, STARSIZE);
			p.end();
		}

		mask.fill (TQt::color0);

		p.begin (&mask);
		p.setPen (TQPen ( TQt::color1, 1));
		p.setBrush( TQBrush( TQt::color1 ) );
		p.drawEllipse(0, 0, STARSIZE, STARSIZE);
		p.end();

		//BLUR!! ugliness-- requires temporary conversion to pixmap, then back again.
		//       if we defer the blur until the end, we lose the transparency.  Bleh.
		TQImage tmp = pix.convertToImage();
		pix.convertFromImage( KImageEffect::blur( tmp, 100.0 ) );

		pix.setMask (mask);	// set the mask
		image = pix.convertToImage();	// create the image for smoothScale()

		for (int i = 0; i < 26; i++)
		{
			tmp = image.smoothScale( STARSIZE*(i+1)/26, STARSIZE*(i+1)/26 );
/*			if (i < 6)
				tmp = image.smoothScale (1+ i, 1+ i);	// size: 1x1 .. 6x6
			else	if (i < 12)
				tmp = image.smoothScale (int((1+ i)*1.25), int((1+ i)*1.25));	// size: 8x8 ... 16x16
			else	if (i < 18)
				tmp = image.smoothScale (int((1+ i)*1.5), int((1+ i)*1.5));	// size: 19x19 .. 27x27
			else
				tmp = image.smoothScale ((1+ i)*2, (1+ i)*2);	// size: 38 .. 52x52
*/
			starPixmaps[color][i].convertFromImage( tmp );  // fill the array of pixmaps
		}
	}
}