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

#include <qpainter.h>
#include <klocale.h>


const KSPieceInfo::Form KSPieceInfo::FORMS[NB_FORMS] = {
    { {{-1, -1,  0,  0}, {-1,  0,  0,  1}, {-1, -1,  0,  0}, {-1,  0,  0,  1}},
      {{ 1,  0,  0, -1}, {-1, -1,  0,  0}, { 1,  0,  0, -1}, {-1, -1,  0,  0}},
      {{ 0,  0, -1, -1}, { 1,  0,  0, -1}, { 0,  0,  1,  1}, {-1,  0,  0,  1}},
      {{-1,  0,  0,  1}, { 0,  0, -1, -1}, { 1,  0,  0, -1}, { 0,  0,  1,  1}},
      2 }, // broken line Z
    { {{-1, -1,  0,  0}, {-1,  0,  0,  1}, {-1, -1,  0,  0}, {-1,  0,  0,  1}},
      {{-1,  0,  0,  1}, { 0,  0, -1, -1}, {-1,  0,  0,  1}, { 0,  0, -1, -1}},
      {{ 0,  0,  1,  1}, { 1,  0,  0, -1}, { 0,  0, -1, -1}, {-1,  0,  0,  1}},
      {{-1,  0,  0,  1}, { 0,  0,  1,  1}, { 1,  0,  0, -1}, { 0,  0, -1, -1}},
      2 }, // broken line S
	{ {{ 0,  0,  0,  0}, {-1,  0,  1,  2}, { 0,  0,  0,  0}, {-1,  0,  1,  2}},
      {{-1,  0,  1,  2}, { 0,  0,  0,  0}, {-1,  0,  1,  2}, { 0,  0,  0,  0}},
      {{ 0,  0,  0,  0}, { 1,  0, -1, -2}, { 0,  0,  0,  0}, {-1,  0,  1,  2}},
	  {{-1,  0,  1,  2}, { 0,  0,  0,  0}, { 1,  0, -1, -2}, { 0,  0,  0,  0}},
      2 }, // line
	{ {{ 0,  0,  1,  0}, {-1,  1,  0,  0}, { 0,  0, -1,  0}, { 1, -1,  0,  0}},
      {{ 1, -1,  0,  0}, { 0,  0,  1,  0}, {-1,  1,  0,  0}, { 0,  0, -1,  0}},
      {{-1,  0,  1,  0}, { 0,  0,  0,  1}, { 1,  0, -1,  0}, { 0,  0,  0, -1}},
	  {{ 0,  0,  0, -1}, {-1,  0,  1,  0}, { 0,  0,  0,  1}, { 1,  0, -1,  0}},
      4 }, // T
	{ {{-1,  0, -1,  0}, {-1,  0, -1,  0}, {-1,  0, -1,  0}, {-1,  0, -1,  0}},
	  {{ 0,  0, -1, -1}, { 0,  0, -1, -1}, { 0,  0, -1, -1}, { 0,  0, -1, -1}},
      {{-1,  0, -1,  0}, { 0,  0, -1, -1}, { 1,  0,  1,  0}, { 0,  0,  1,  1}},
	  {{ 0,  0,  1,  1}, {-1,  0, -1,  0}, { 0,  0, -1, -1}, { 1,  0,  1,  0}},
      1 }, // square
	{ {{ 1,  1,  1,  0}, {-1,  0,  1,  1}, {-1, -1, -1,  0}, { 1,  0, -1, -1}},
	  {{ 1,  0, -1, -1}, { 1,  1,  1,  0}, {-1,  0,  1,  1}, {-1, -1, -1,  0}},
      {{-1,  0,  0,  0}, { 1,  1,  0, -1}, { 1,  0,  0,  0}, {-1, -1,  0,  1}},
      {{-1, -1,  0,  1}, {-1,  0,  0,  0}, { 1,  1,  0, -1}, { 1,  0,  0,  0}},
       4 }, // backward L
    { {{-1, -1, -1,  0}, {-1,  0,  1,  1}, { 1,  1,  1,  0}, { 1,  0, -1, -1}},
	  {{ 1,  0, -1, -1}, {-1, -1, -1,  0}, {-1,  0,  1,  1}, { 1,  1,  1,  0}},
      {{ 1,  0,  0,  0}, { 1,  1,  0, -1}, {-1,  0,  0,  0}, {-1, -1,  0,  1}},
	  {{-1, -1,  0,  1}, { 1,  0,  0,  0}, { 1,  1,  0, -1}, {-1,  0,  0,  0}},
       4 }  // L
};

const char *KSPieceInfo::COLOR_LABELS[NB_FORMS+1] = {
    I18N_NOOP("Z piece color:"), I18N_NOOP("S piece color:"),
    I18N_NOOP("I piece color:"), I18N_NOOP("T piece color:"),
    I18N_NOOP("Square color:"), I18N_NOOP("Mirrored L piece color:"),
    I18N_NOOP("L piece color:"), I18N_NOOP("Garbage block color:")
};

const char *KSPieceInfo::DEFAULT_COLORS[NB_FORMS+1] = {
    "#C86464", "#64C864", "#6464C8", "#C8C864", "#C864C8","#64C8C8", "#DAAA00",
    "#C8C8C8"
};

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

void KSPieceInfo::draw(QPixmap *pixmap, uint blockType, uint,
                       bool lighted) const
{
    QColor col = color(blockType);
	if (lighted) col = col.light();
	pixmap->fill(col);

	QPainter p(pixmap);
    QRect r = pixmap->rect();

	p.setPen( col.light() );
	p.moveTo(r.bottomLeft());
	p.lineTo(r.topLeft());
	p.lineTo(r.topRight());

	p.setPen( col.dark() );
	p.moveTo(r.topRight() + QPoint(0,1));
	p.lineTo(r.bottomRight());
	p.lineTo(r.bottomLeft() + QPoint(1,0));
}