summaryrefslogtreecommitdiffstats
path: root/kfouleggs/piece.cpp
blob: bb5aad42112673dd23baf7fa0fde559e94975fc5 (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
#include "piece.h"

#include <math.h>

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

#include <klocale.h>

#include "base/board.h"


const FEPieceInfo::Form FEPieceInfo::FORM = {
    {{ 0,  0}, {-1,  0}, { 0,  0}, { 0, -1}},
    {{ 0, -1}, {-1, -1}, {-1,  0}, {-1, -1}}
};

const char *FEPieceInfo::DEFAULT_COLORS[NB_NORM_BLOCK_TYPES + 1] = {
    "#64C864", "#64C8C8", "#C86464", "#C864C8", "#C8C8C8"
};

TQColor FEPieceInfo::defaultColor(uint i) const
{ 
  if ( i>=nbColors() ) return TQColor();
  return TQColor(DEFAULT_COLORS[i]);
}

TQString FEPieceInfo::colorLabel(uint i) const
{
    return (i==NB_NORM_BLOCK_TYPES ? i18n("Garbage color:")
            : i18n("Color #%1:").arg(i+1));
}

void FEPieceInfo::draw(TQPixmap *pixmap, uint blockType, uint,
                       bool lighted) const
{
    TQColor col = color(blockType);
    if (lighted) col = col.light();
    pixmap->fill(col);
}

void FEPieceInfo::setMask(TQPixmap *pixmap, uint blockMode) const
{
    Q_ASSERT( pixmap->width()==pixmap->height() ); // drawing code assumes that
    TQBitmap bitmap(pixmap->size(), true);
    TQPainter p(&bitmap);
	p.setBrush(Qt::color1);
	p.setPen( TQPen(Qt::NoPen) );

	// base circle
    int w = pixmap->width();
	int d = (int)((sqrt(2)-2./3)*w);
	TQRect cr = TQRect(0, 0, d, d);
	cr.moveCenter(TQPoint(w/2, w/2));
	p.drawEllipse(cr);

	if (blockMode) {
        int a  = (int)(w/(3.*sqrt(2)));
        int ra = 2*w/3+1;
        cr = TQRect(0, 0, ra, ra);

        // first drawing with color1
        if ( blockMode & BaseBoard::Up    ) p.drawRect(    0,     0, w, a);
        if ( blockMode & BaseBoard::Right ) p.drawRect(w-a+1,     0, a, w);
        if ( blockMode & BaseBoard::Down  ) p.drawRect(    0, w-a+1, w, a);
        if ( blockMode & BaseBoard::Left  ) p.drawRect(    0,     0, a, w);

        // second drawing with color0
        p.setBrush(Qt::color0);
        if ( (blockMode & BaseBoard::Up) || (blockMode & BaseBoard::Left) ) {
            cr.moveCenter(TQPoint(0, 0));
            p.drawEllipse(cr);
        }
        if ( (blockMode & BaseBoard::Right) || (blockMode & BaseBoard::Up) ) {
            cr.moveCenter(TQPoint(w-1, 0));
            p.drawEllipse(cr);
        }
        if ( (blockMode & BaseBoard::Down) || (blockMode & BaseBoard::Right) ){
            cr.moveCenter(TQPoint(w-1, w-1));
            p.drawEllipse(cr);
        }
        if ( (blockMode & BaseBoard::Left) || (blockMode & BaseBoard::Down) ) {
            cr.moveCenter(TQPoint(0, w-1));
            p.drawEllipse(cr);
        }
    }

    p.end();
    pixmap->setMask(bitmap);
}