Diffstat (limited to 'noncore/games/go/gowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/go/gowidget.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp index 8567b30..1d38c9f 100644 --- a/noncore/games/go/gowidget.cpp +++ b/noncore/games/go/gowidget.cpp | |||
@@ -33,31 +33,31 @@ | |||
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | //#include <stdio.h> | 35 | //#include <stdio.h> |
36 | 36 | ||
37 | #include "amigo.h" | 37 | #include "amigo.h" |
38 | #include "goplayutils.h" | 38 | #include "goplayutils.h" |
39 | 39 | ||
40 | static const enum bVal computer_color = BLACK; | 40 | static const enum bVal computer_color = BLACK; |
41 | 41 | ||
42 | static int current_handicap = 1; | 42 | static int current_handicap = 1; |
43 | 43 | ||
44 | static QBrush *goBrush; | 44 | static QBrush *goBrush; |
45 | //static QImage *newBlackStone; | 45 | //static QImage *newBlackStone; |
46 | //static QImage *blackStone; | 46 | //static QImage *blackStone; |
47 | //static QImage *whiteStone; | 47 | //static QImage *whiteStone; |
48 | static QPixmap *newBlackStone; | 48 | static QPixmap *newBlackStone; |
49 | static QPixmap *blackStone; | 49 | static QPixmap *blackStone; |
50 | static QPixmap *whiteStone; | 50 | static QPixmap *whiteStone; |
51 | 51 | ||
52 | static bool smallStones = FALSE; | 52 | static bool smallStones = FALSE; |
53 | 53 | ||
54 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name) : | 54 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name) : |
55 | QMainWindow( parent, name ) | 55 | QMainWindow( parent, name ) |
56 | { | 56 | { |
57 | setToolBarsMovable( FALSE ); | 57 | setToolBarsMovable( FALSE ); |
58 | GoWidget *go = new GoWidget(this); | 58 | GoWidget *go = new GoWidget(this); |
59 | 59 | ||
60 | setCentralWidget(go); | 60 | setCentralWidget(go); |
61 | toolbar = new QPEToolBar(this); | 61 | toolbar = new QPEToolBar(this); |
62 | toolbar->setHorizontalStretchable( TRUE ); | 62 | toolbar->setHorizontalStretchable( TRUE ); |
63 | addToolBar(toolbar); | 63 | addToolBar(toolbar); |
@@ -69,42 +69,42 @@ GoMainWidget::GoMainWidget( QWidget *parent, const char* name) : | |||
69 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); | 69 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); |
70 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); | 70 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); |
71 | a->addTo( file ); | 71 | a->addTo( file ); |
72 | 72 | ||
73 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); | 73 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); |
74 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); | 74 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); |
75 | a->addTo( file ); | 75 | a->addTo( file ); |
76 | a->addTo( toolbar ); | 76 | a->addTo( toolbar ); |
77 | 77 | ||
78 | 78 | ||
79 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); | 79 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); |
80 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); | 80 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); |
81 | a->addTo( file ); | 81 | a->addTo( file ); |
82 | 82 | ||
83 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); | 83 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); |
84 | a->setToggleAction( TRUE ); | 84 | a->setToggleAction( TRUE ); |
85 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); | 85 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); |
86 | a->addTo( file ); | 86 | a->addTo( file ); |
87 | 87 | ||
88 | mb->insertItem( tr( "Game" ), file ); | 88 | mb->insertItem( tr( "Game" ), file ); |
89 | 89 | ||
90 | QLabel *turnLabel = new QLabel( toolbar ); | 90 | QLabel *turnLabel = new QLabel( toolbar ); |
91 | turnLabel->setBackgroundMode( PaletteButton ); | 91 | turnLabel->setBackgroundMode( PaletteButton ); |
92 | connect( go, SIGNAL(showTurn(const QPixmap&)), | 92 | connect( go, SIGNAL(showTurn(const QPixmap&)), |
93 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); | 93 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); |
94 | 94 | ||
95 | 95 | ||
96 | QLabel * scoreLabel = new QLabel( toolbar ); | 96 | QLabel * scoreLabel = new QLabel( toolbar ); |
97 | scoreLabel->setBackgroundMode( PaletteButton ); | 97 | scoreLabel->setBackgroundMode( PaletteButton ); |
98 | connect( go, SIGNAL(showScore(const QString&)), | 98 | connect( go, SIGNAL(showScore(const QString&)), |
99 | scoreLabel, SLOT(setText(const QString&)) ); | 99 | scoreLabel, SLOT(setText(const QString&)) ); |
100 | 100 | ||
101 | toolbar->setStretchableWidget( scoreLabel ); | 101 | toolbar->setStretchableWidget( scoreLabel ); |
102 | 102 | ||
103 | go->readConfig(); | 103 | go->readConfig(); |
104 | } | 104 | } |
105 | 105 | ||
106 | void GoMainWidget::resizeEvent( QResizeEvent * ) | 106 | void GoMainWidget::resizeEvent( QResizeEvent * ) |
107 | { | 107 | { |
108 | //### this won't work because of the text label... | 108 | //### this won't work because of the text label... |
109 | /* | 109 | /* |
110 | if ( width() > height() ) | 110 | if ( width() > height() ) |
@@ -112,27 +112,27 @@ void GoMainWidget::resizeEvent( QResizeEvent * ) | |||
112 | else | 112 | else |
113 | moveToolBar( toolbar, Top ); | 113 | moveToolBar( toolbar, Top ); |
114 | */ | 114 | */ |
115 | } | 115 | } |
116 | 116 | ||
117 | GoWidget *GoWidget::self = 0; | 117 | GoWidget *GoWidget::self = 0; |
118 | 118 | ||
119 | GoWidget::GoWidget( QWidget *parent, const char* name) : | 119 | GoWidget::GoWidget( QWidget *parent, const char* name) : |
120 | QWidget( parent, name ) | 120 | QWidget( parent, name ) |
121 | { | 121 | { |
122 | if ( self ) | 122 | if ( self ) |
123 | fatal( "Only one Go widget allowed" ); | 123 | fatal( "Only one Go widget allowed" ); |
124 | self = this; | 124 | self = this; |
125 | twoplayer = FALSE; | 125 | twoplayer = FALSE; |
126 | 126 | ||
127 | 127 | ||
128 | d = bx = by = 1; | 128 | d = bx = by = 1; |
129 | 129 | ||
130 | QPixmap pix = Resource::loadPixmap( "pine" ); | 130 | QPixmap pix = Resource::loadPixmap( "go/pine" ); |
131 | goBrush = new QBrush( black, pix ); | 131 | goBrush = new QBrush( black, pix ); |
132 | /* | 132 | /* |
133 | QString fn = Resource::findPixmap("Go-black"); | 133 | QString fn = Resource::findPixmap("Go-black"); |
134 | blackStone = new QImage( fn ); | 134 | blackStone = new QImage( fn ); |
135 | fn = Resource::findPixmap("Go-black-highlight"); | 135 | fn = Resource::findPixmap("Go-black-highlight"); |
136 | newBlackStone = new QImage( fn ); | 136 | newBlackStone = new QImage( fn ); |
137 | fn = Resource::findPixmap("Go-white"); | 137 | fn = Resource::findPixmap("Go-white"); |
138 | whiteStone = new QImage( fn ); | 138 | whiteStone = new QImage( fn ); |
@@ -199,17 +199,17 @@ void GoWidget::resizeEvent( QResizeEvent * ) | |||
199 | // int r = (d/2-1); | 199 | // int r = (d/2-1); |
200 | bx = (width() - 18*d)/2 ; | 200 | bx = (width() - 18*d)/2 ; |
201 | by = (height() - 18*d)/2 ; | 201 | by = (height() - 18*d)/2 ; |
202 | 202 | ||
203 | if ( d < 10 && !smallStones ) { | 203 | if ( d < 10 && !smallStones ) { |
204 | blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); | 204 | blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); |
205 | whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); | 205 | whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); |
206 | newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); | 206 | newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); |
207 | 207 | ||
208 | smallStones = TRUE; | 208 | smallStones = TRUE; |
209 | } else if ( d >= 10 && smallStones ) { | 209 | } else if ( d >= 10 && smallStones ) { |
210 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); | 210 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); |
211 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); | 211 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); |
212 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); | 212 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); |
213 | smallStones = FALSE; | 213 | smallStones = FALSE; |
214 | } | 214 | } |
215 | } | 215 | } |
@@ -233,45 +233,45 @@ void GoWidget::init() | |||
233 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 233 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
234 | } | 234 | } |
235 | 235 | ||
236 | void GoWidget::paintEvent( QPaintEvent *e ) | 236 | void GoWidget::paintEvent( QPaintEvent *e ) |
237 | { | 237 | { |
238 | int i,j; | 238 | int i,j; |
239 | 239 | ||
240 | int r = whiteStone->width()/2; | 240 | int r = whiteStone->width()/2; |
241 | 241 | ||
242 | QPainter p(this); | 242 | QPainter p(this); |
243 | p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush ); | 243 | p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush ); |
244 | 244 | ||
245 | int xMin = QMAX( x2board(e->rect().left()), 0 ); | 245 | int xMin = QMAX( x2board(e->rect().left()), 0 ); |
246 | int xMax = QMIN( x2board(e->rect().right()), 18 ); | 246 | int xMax = QMIN( x2board(e->rect().right()), 18 ); |
247 | int yMin = QMAX( y2board(e->rect().top()), 0 ); | 247 | int yMin = QMAX( y2board(e->rect().top()), 0 ); |
248 | int yMax = QMIN( y2board(e->rect().bottom()), 18 ); | 248 | int yMax = QMIN( y2board(e->rect().bottom()), 18 ); |
249 | 249 | ||
250 | QColor pine( 255, 186, 89 ); | 250 | QColor pine( 255, 186, 89 ); |
251 | p.setPen( pine.dark() ); | 251 | p.setPen( pine.dark() ); |
252 | 252 | ||
253 | for ( i = xMin; i < xMax+1 ; i ++ ) { | 253 | for ( i = xMin; i < xMax+1 ; i ++ ) { |
254 | p.drawLine( bx+i*d, by, bx+i*d, by+18*d ); | 254 | p.drawLine( bx+i*d, by, bx+i*d, by+18*d ); |
255 | } | 255 | } |
256 | for ( j = yMin; j < yMax+1 ; j ++ ) { | 256 | for ( j = yMin; j < yMax+1 ; j ++ ) { |
257 | p.drawLine( bx, by+j*d, bx+18*d, by+j*d); | 257 | p.drawLine( bx, by+j*d, bx+18*d, by+j*d); |
258 | } | 258 | } |
259 | 259 | ||
260 | // dots are at (3,3), (3,9), (3,15) and so on | 260 | // dots are at (3,3), (3,9), (3,15) and so on |
261 | p.setBrush( black ); | 261 | p.setBrush( black ); |
262 | for ( i = 3; i < xMax+1; i+=6 ) | 262 | for ( i = 3; i < xMax+1; i+=6 ) |
263 | for ( j = 3; j < yMax+1; j+=6 ) | 263 | for ( j = 3; j < yMax+1; j+=6 ) |
264 | p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 ); | 264 | p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 ); |
265 | 265 | ||
266 | 266 | ||
267 | for ( i = xMin; i < xMax+1; i++ ) | 267 | for ( i = xMin; i < xMax+1; i++ ) |
268 | for ( j = yMin; j < yMax+1; j++ ) { | 268 | for ( j = yMin; j < yMax+1; j++ ) { |
269 | if ( board[i][j] == WHITE || | 269 | if ( board[i][j] == WHITE || |
270 | currentPlayer==WHITE && newX == i && newY == j ) | 270 | currentPlayer==WHITE && newX == i && newY == j ) |
271 | p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone ); | 271 | p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone ); |
272 | else if ( i == lastX && j == lastY ) | 272 | else if ( i == lastX && j == lastY ) |
273 | p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone ); | 273 | p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone ); |
274 | else if ( board[i][j] == BLACK || | 274 | else if ( board[i][j] == BLACK || |
275 | currentPlayer==BLACK && newX == i && newY == j) | 275 | currentPlayer==BLACK && newX == i && newY == j) |
276 | p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone ); | 276 | p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone ); |
277 | } | 277 | } |
@@ -389,29 +389,29 @@ void GoWidget::showStone( int x, int y, enum bVal c ) | |||
389 | newX = newY = -1; | 389 | newX = newY = -1; |
390 | return; | 390 | return; |
391 | } | 391 | } |
392 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { | 392 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { |
393 | newX = x; | 393 | newX = x; |
394 | newY = y; | 394 | newY = y; |
395 | refresh(x,y); | 395 | refresh(x,y); |
396 | } | 396 | } |
397 | 397 | ||
398 | } | 398 | } |
399 | 399 | ||
400 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) | 400 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) |
401 | { | 401 | { |
402 | if ( gameActive && newX > -1 ) | 402 | if ( gameActive && newX > -1 ) |
403 | doMove( newX, newY ); | 403 | doMove( newX, newY ); |
404 | newX = newY = -1; | 404 | newX = newY = -1; |
405 | } | 405 | } |
406 | 406 | ||
407 | void GoWidget::refresh( int x, int y ) | 407 | void GoWidget::refresh( int x, int y ) |
408 | { | 408 | { |
409 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); | 409 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); |
410 | } | 410 | } |
411 | 411 | ||
412 | void GoWidget::removeStone(short x, short y) | 412 | void GoWidget::removeStone(short x, short y) |
413 | { | 413 | { |
414 | board[x][y]=-1; | 414 | board[x][y]=-1; |
415 | refresh( x, y ); | 415 | refresh( x, y ); |
416 | } | 416 | } |
417 | 417 | ||