summaryrefslogtreecommitdiffstats
path: root/knights/dlg_promote.cpp
blob: 23a930d4a5cfe69bac25eb030c58ba14254eb680 (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
/***************************************************************************
                          dlg_promote.cpp  -  description
                             -------------------
    begin                : Fri Jul 13 2001
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "definitions.h"
#include "dlg_promote.moc"
#include "knightspixcache.h"
#include <tqimage.h>

dlg_promote::dlg_promote(TQWidget *parent, const char *name, resource *Rsrc  ) :
	TQDialog( parent, name, TRUE, TQt::WStyle_Customize | TQt::WStyle_DialogBorder )
{
	Resource = Rsrc;
	Queen = new TQPushButton( this );
	Bishop = new TQPushButton( this );
	Knight = new TQPushButton( this );
	Rook = new TQPushButton( this );
	Description = new TQLabel( this );
}

dlg_promote::~dlg_promote()
{
	delete Queen;
	delete Bishop;
	delete Knight;
	delete Rook;
	delete Description;
}

void dlg_promote::Init( bool Army )
{
	KnightsPixCache *cache = Resource->pixCache;
	TQImage tempImage;
	TQPixmap buffer;
	int margin;

	margin = 2;
	buffer.resize( Resource->ThemeSize, Resource->ThemeSize );
	Description->setFixedSize( Resource->ThemeSize * 2 , 20 );
	Queen->setFixedSize( Resource->ThemeSize, Resource->ThemeSize );
	Bishop->setFixedSize( Resource->ThemeSize, Resource->ThemeSize );
	Knight->setFixedSize( Resource->ThemeSize, Resource->ThemeSize );
	Rook->setFixedSize( Resource->ThemeSize, Resource->ThemeSize );
	setFixedSize(	( margin * 4 ) + ( Resource->ThemeSize * 2 ),
								( margin * 6 ) + ( Resource->ThemeSize * 2 ) + 20 );

	Description->move( margin, margin );
	Queen->move( margin, ( margin * 3 ) + 20 );
	Bishop->move( ( margin * 3 ) + Resource->ThemeSize, ( margin * 3 ) + 20 );
	Knight->move( margin, ( margin * 5 ) + 20 + Resource->ThemeSize );
	Rook->move( ( margin * 3 ) + Resource->ThemeSize, ( margin * 5 ) + 20 + Resource->ThemeSize );
	
	/* Queen */
	buffer = cache->SquareLight;
	if( Army == WHITE ) bitBlt( &buffer, 0, 0, &cache->WhiteQueen, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	else bitBlt( &buffer, 0, 0, &cache->BlackQueen, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	Queen->setPixmap( buffer );
	Queen->show();

	/* Bishop */
	buffer = cache->SquareDark;
	if( Army == WHITE ) bitBlt( &buffer, 0, 0, &cache->WhiteBishop, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	else bitBlt( &buffer, 0, 0, &cache->BlackBishop, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	Bishop->setPixmap( buffer );
	Bishop->show();

	/* Knight */
	buffer = cache->SquareDark;
	if( Army == WHITE ) bitBlt( &buffer, 0, 0, &cache->WhiteKnight, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	else bitBlt( &buffer, 0, 0, &cache->BlackKnight, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	Knight->setPixmap( buffer );
	Knight->show();

	/* Rook */
	buffer = cache->SquareLight;
	if( Army == WHITE ) bitBlt( &buffer, 0, 0, &cache->WhiteRook, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	else bitBlt( &buffer, 0, 0, &cache->BlackRook, 0, 0, -1, -1, TQt::CopyROP, FALSE);
	Rook->setPixmap( buffer );	
	Rook->show();

	Description->setText( i18n( "Promote your pawn to..." ) );
	Description->show();
	connect( Queen, TQT_SIGNAL( clicked() ), this, TQT_SLOT( queenClick() ) );
	connect( Bishop, TQT_SIGNAL( clicked() ), this, TQT_SLOT( bishopClick() ) );
	connect( Knight, TQT_SIGNAL( clicked() ), this, TQT_SLOT( knightClick() ) );
	connect( Rook, TQT_SIGNAL( clicked() ), this, TQT_SLOT( rookClick() ) );
	Queen->setFocus();
	setCaption( i18n( "Pawn Promotion" ) );
}

void dlg_promote::queenClick( void )
{
	done( 'q' );
}

void dlg_promote::bishopClick( void )
{
	done( 'b' );
}

void dlg_promote::knightClick( void )
{
	done( 'n' );
}

void dlg_promote::rookClick( void )
{
	done( 'r' );
}