Diffstat (limited to 'noncore/games/go/gowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/go/gowidget.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp index d134540..ec03c1d 100644 --- a/noncore/games/go/gowidget.cpp +++ b/noncore/games/go/gowidget.cpp | |||
@@ -1,131 +1,132 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "gowidget.h" | 21 | #include "gowidget.h" |
22 | 22 | ||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
23 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
24 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | using namespace Opie::Core; | ||
25 | 28 | ||
29 | /* QT */ | ||
26 | #include <qpainter.h> | 30 | #include <qpainter.h> |
27 | #include <qtoolbar.h> | 31 | #include <qtoolbar.h> |
28 | #include <qmenubar.h> | 32 | #include <qmenubar.h> |
29 | #include <qaction.h> | 33 | #include <qaction.h> |
30 | #include <qapplication.h> //processEvents() | 34 | #include <qapplication.h> //processEvents() |
31 | #include <qlabel.h> | 35 | #include <qlabel.h> |
32 | 36 | ||
33 | //#include <stdio.h> | ||
34 | |||
35 | |||
36 | static const enum bVal computer_color = BLACK; | 37 | static const enum bVal computer_color = BLACK; |
37 | 38 | ||
38 | static int current_handicap = 1; | 39 | static int current_handicap = 1; |
39 | 40 | ||
40 | static QBrush *goBrush; | 41 | static QBrush *goBrush; |
41 | //static QImage *newBlackStone; | 42 | //static QImage *newBlackStone; |
42 | //static QImage *blackStone; | 43 | //static QImage *blackStone; |
43 | //static QImage *whiteStone; | 44 | //static QImage *whiteStone; |
44 | static QPixmap *newBlackStone; | 45 | static QPixmap *newBlackStone; |
45 | static QPixmap *blackStone; | 46 | static QPixmap *blackStone; |
46 | static QPixmap *whiteStone; | 47 | static QPixmap *whiteStone; |
47 | 48 | ||
48 | static bool smallStones = FALSE; | 49 | static bool smallStones = FALSE; |
49 | 50 | ||
50 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name, WFlags fl) : | 51 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name, WFlags fl) : |
51 | QMainWindow( parent, name, fl ) | 52 | QMainWindow( parent, name, fl ) |
52 | { | 53 | { |
53 | setToolBarsMovable( FALSE ); | 54 | setToolBarsMovable( FALSE ); |
54 | GoWidget *go = new GoWidget(this); | 55 | GoWidget *go = new GoWidget(this); |
55 | 56 | ||
56 | setCentralWidget(go); | 57 | setCentralWidget(go); |
57 | toolbar = new QToolBar(this); | 58 | toolbar = new QToolBar(this); |
58 | toolbar->setHorizontalStretchable( TRUE ); | 59 | toolbar->setHorizontalStretchable( TRUE ); |
59 | addToolBar(toolbar); | 60 | addToolBar(toolbar); |
60 | 61 | ||
61 | QMenuBar *mb = new QMenuBar( toolbar ); | 62 | QMenuBar *mb = new QMenuBar( toolbar ); |
62 | mb->setMargin(0); | 63 | mb->setMargin(0); |
63 | QPopupMenu *file = new QPopupMenu( this ); | 64 | QPopupMenu *file = new QPopupMenu( this ); |
64 | 65 | ||
65 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); | 66 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); |
66 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); | 67 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); |
67 | a->addTo( file ); | 68 | a->addTo( file ); |
68 | 69 | ||
69 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); | 70 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); |
70 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); | 71 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); |
71 | a->addTo( file ); | 72 | a->addTo( file ); |
72 | a->addTo( toolbar ); | 73 | a->addTo( toolbar ); |
73 | 74 | ||
74 | 75 | ||
75 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); | 76 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); |
76 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); | 77 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); |
77 | a->addTo( file ); | 78 | a->addTo( file ); |
78 | 79 | ||
79 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); | 80 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); |
80 | a->setToggleAction( TRUE ); | 81 | a->setToggleAction( TRUE ); |
81 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); | 82 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); |
82 | a->addTo( file ); | 83 | a->addTo( file ); |
83 | 84 | ||
84 | mb->insertItem( tr( "Game" ), file ); | 85 | mb->insertItem( tr( "Game" ), file ); |
85 | 86 | ||
86 | QLabel *turnLabel = new QLabel( toolbar ); | 87 | QLabel *turnLabel = new QLabel( toolbar ); |
87 | turnLabel->setBackgroundMode( PaletteButton ); | 88 | turnLabel->setBackgroundMode( PaletteButton ); |
88 | connect( go, SIGNAL(showTurn(const QPixmap&)), | 89 | connect( go, SIGNAL(showTurn(const QPixmap&)), |
89 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); | 90 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); |
90 | 91 | ||
91 | 92 | ||
92 | QLabel * scoreLabel = new QLabel( toolbar ); | 93 | QLabel * scoreLabel = new QLabel( toolbar ); |
93 | scoreLabel->setBackgroundMode( PaletteButton ); | 94 | scoreLabel->setBackgroundMode( PaletteButton ); |
94 | connect( go, SIGNAL(showScore(const QString&)), | 95 | connect( go, SIGNAL(showScore(const QString&)), |
95 | scoreLabel, SLOT(setText(const QString&)) ); | 96 | scoreLabel, SLOT(setText(const QString&)) ); |
96 | 97 | ||
97 | toolbar->setStretchableWidget( scoreLabel ); | 98 | toolbar->setStretchableWidget( scoreLabel ); |
98 | 99 | ||
99 | go->readConfig(); | 100 | go->readConfig(); |
100 | } | 101 | } |
101 | 102 | ||
102 | void GoMainWidget::resizeEvent( QResizeEvent * ) | 103 | void GoMainWidget::resizeEvent( QResizeEvent * ) |
103 | { | 104 | { |
104 | //### this won't work because of the text label... | 105 | //### this won't work because of the text label... |
105 | /* | 106 | /* |
106 | if ( width() > height() ) | 107 | if ( width() > height() ) |
107 | moveToolBar( toolbar, Left ); | 108 | moveToolBar( toolbar, Left ); |
108 | else | 109 | else |
109 | moveToolBar( toolbar, Top ); | 110 | moveToolBar( toolbar, Top ); |
110 | */ | 111 | */ |
111 | } | 112 | } |
112 | 113 | ||
113 | GoWidget *GoWidget::self = 0; | 114 | GoWidget *GoWidget::self = 0; |
114 | 115 | ||
115 | GoWidget::GoWidget( QWidget *parent, const char* name) : | 116 | GoWidget::GoWidget( QWidget *parent, const char* name) : |
116 | QWidget( parent, name ) | 117 | QWidget( parent, name ) |
117 | { | 118 | { |
118 | if ( self ) | 119 | if ( self ) |
119 | fatal( "Only one Go widget allowed" ); | 120 | fatal( "Only one Go widget allowed" ); |
120 | self = this; | 121 | self = this; |
121 | twoplayer = FALSE; | 122 | twoplayer = FALSE; |
122 | 123 | ||
123 | 124 | ||
124 | d = bx = by = 1; | 125 | d = bx = by = 1; |
125 | 126 | ||
126 | QPixmap pix = Resource::loadPixmap( "go/pine" ); | 127 | QPixmap pix = Resource::loadPixmap( "go/pine" ); |
127 | goBrush = new QBrush( black, pix ); | 128 | goBrush = new QBrush( black, pix ); |
128 | /* | 129 | /* |
129 | QString fn = Resource::findPixmap("Go-black"); | 130 | QString fn = Resource::findPixmap("Go-black"); |
130 | blackStone = new QImage( fn ); | 131 | blackStone = new QImage( fn ); |
131 | fn = Resource::findPixmap("Go-black-highlight"); | 132 | fn = Resource::findPixmap("Go-black-highlight"); |
@@ -355,106 +356,106 @@ void GoWidget::doComputerMove() | |||
355 | } | 356 | } |
356 | } | 357 | } |
357 | 358 | ||
358 | void GoWidget::mousePressEvent( QMouseEvent *me ) | 359 | void GoWidget::mousePressEvent( QMouseEvent *me ) |
359 | { | 360 | { |
360 | if ( !gameActive ) | 361 | if ( !gameActive ) |
361 | return; | 362 | return; |
362 | int x = x2board(me->x()); | 363 | int x = x2board(me->x()); |
363 | int y = y2board(me->y()); | 364 | int y = y2board(me->y()); |
364 | showStone(x,y,currentPlayer); | 365 | showStone(x,y,currentPlayer); |
365 | } | 366 | } |
366 | 367 | ||
367 | void GoWidget::mouseMoveEvent( QMouseEvent *me ) | 368 | void GoWidget::mouseMoveEvent( QMouseEvent *me ) |
368 | { | 369 | { |
369 | if ( !gameActive ) | 370 | if ( !gameActive ) |
370 | return; | 371 | return; |
371 | int x = x2board(me->x()); | 372 | int x = x2board(me->x()); |
372 | int y = y2board(me->y()); | 373 | int y = y2board(me->y()); |
373 | if ( x != newX || y != newY ) | 374 | if ( x != newX || y != newY ) |
374 | showStone(x,y,currentPlayer); | 375 | showStone(x,y,currentPlayer); |
375 | } | 376 | } |
376 | 377 | ||
377 | void GoWidget::showStone( int x, int y, enum bVal c ) | 378 | void GoWidget::showStone( int x, int y, enum bVal c ) |
378 | { | 379 | { |
379 | 380 | ||
380 | if ( newX > -1 ) { | 381 | if ( newX > -1 ) { |
381 | refresh( newX, newY ); | 382 | refresh( newX, newY ); |
382 | newY = newX = -1; | 383 | newY = newX = -1; |
383 | } | 384 | } |
384 | if ( x < 0 || x > 18 || y < 0 || y > 18 ) { | 385 | if ( x < 0 || x > 18 || y < 0 || y > 18 ) { |
385 | newX = newY = -1; | 386 | newX = newY = -1; |
386 | return; | 387 | return; |
387 | } | 388 | } |
388 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { | 389 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { |
389 | newX = x; | 390 | newX = x; |
390 | newY = y; | 391 | newY = y; |
391 | refresh(x,y); | 392 | refresh(x,y); |
392 | } | 393 | } |
393 | 394 | ||
394 | } | 395 | } |
395 | 396 | ||
396 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) | 397 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) |
397 | { | 398 | { |
398 | if ( gameActive && newX > -1 ) | 399 | if ( gameActive && newX > -1 ) |
399 | doMove( newX, newY ); | 400 | doMove( newX, newY ); |
400 | newX = newY = -1; | 401 | newX = newY = -1; |
401 | } | 402 | } |
402 | 403 | ||
403 | void GoWidget::refresh( int x, int y ) | 404 | void GoWidget::refresh( int x, int y ) |
404 | { | 405 | { |
405 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); | 406 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); |
406 | } | 407 | } |
407 | 408 | ||
408 | void GoWidget::removeStone(short x, short y) | 409 | void GoWidget::removeStone(short x, short y) |
409 | { | 410 | { |
410 | board[x][y]=-1; | 411 | board[x][y]=-1; |
411 | refresh( x, y ); | 412 | refresh( x, y ); |
412 | } | 413 | } |
413 | 414 | ||
414 | void GoWidget::placeStone (enum bVal c, short x, short y ) | 415 | void GoWidget::placeStone (enum bVal c, short x, short y ) |
415 | { | 416 | { |
416 | board[x][y]=c; | 417 | board[x][y]=c; |
417 | refresh( x, y ); | 418 | refresh( x, y ); |
418 | } | 419 | } |
419 | 420 | ||
420 | void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) | 421 | void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) |
421 | { | 422 | { |
422 | QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); | 423 | QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); |
423 | emit showScore( s ); | 424 | emit showScore( s ); |
424 | } | 425 | } |
425 | 426 | ||
426 | void GoWidget::setTwoplayer( bool b ) | 427 | void GoWidget::setTwoplayer( bool b ) |
427 | { | 428 | { |
428 | twoplayer = b; | 429 | twoplayer = b; |
429 | } | 430 | } |
430 | 431 | ||
431 | void GoWidget::setHandicap( int h ) | 432 | void GoWidget::setHandicap( int h ) |
432 | { | 433 | { |
433 | current_handicap = h; | 434 | current_handicap = h; |
434 | } | 435 | } |
435 | 436 | ||
436 | 437 | ||
437 | extern "C" { | 438 | extern "C" { |
438 | 439 | ||
439 | voidremovestone(short x, short y) | 440 | voidremovestone(short x, short y) |
440 | { | 441 | { |
441 | GoWidget::self->removeStone(x,y); | 442 | GoWidget::self->removeStone(x,y); |
442 | } | 443 | } |
443 | 444 | ||
444 | voidplacestone (enum bVal c, short x, short y ) | 445 | voidplacestone (enum bVal c, short x, short y ) |
445 | { | 446 | { |
446 | GoWidget::self->placeStone(c,x,y); | 447 | GoWidget::self->placeStone(c,x,y); |
447 | } | 448 | } |
448 | 449 | ||
449 | voidintrMoveReport(enum bVal c ,char *coord ,char *reason ) | 450 | voidintrMoveReport(enum bVal c ,char *coord ,char *reason ) |
450 | { | 451 | { |
451 | qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason ); | 452 | odebug << "intrMoveReport colour " << c << ", " << coord << " " << reason << "" << oendl; |
452 | } | 453 | } |
453 | 454 | ||
454 | voidintrPrisonerReport( short blackcnt, short whitecnt ) | 455 | voidintrPrisonerReport( short blackcnt, short whitecnt ) |
455 | { | 456 | { |
456 | GoWidget::self->reportPrisoners(blackcnt,whitecnt); | 457 | GoWidget::self->reportPrisoners(blackcnt,whitecnt); |
457 | } | 458 | } |
458 | 459 | ||
459 | } | 460 | } |
460 | 461 | ||