Debian Codegraph @

src/board/stone.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 /*
24 * stone.cpp
25 * This class handles the graphical appearance of the stones on the board
26 * Is is used only by the 'board' class
27 */
28
29 #include "../defines.h"cxx . . $ `<file>/src/defines.h`/
30 #include "stone.h"cxx . . $ `<file>/src/board/stone.h`/
31 #include "imagehandler.h"cxx . . $ `<file>/src/board/imagehandler.h`/
32
33 #include <QGraphicsScene>
34
35 /*
36 * Creates the stone as a GraphicsScene item
37 */
38 Stonecxx . . $ Stone#::Stonecxx . . $ Stone#Stone(72804590282d8142).(QListcxx . . $ QList#<QPixmapcxx . . $ QPixmap#> *a, QGraphicsScenecxx . . $ QGraphicsScene# *canvas, StoneColorcxx . . $ StoneColor# c, int x, int y , bool has_shadow)
39 : QGraphicsPixmapItemcxx . . $ QGraphicsPixmapItem#(0), colorcxx . . $ Stone#color.(c), myXcxx . . $ Stone#myX.(x), myYcxx . . $ Stone#myY.(y)
40 {
41 canvas->addItemcxx . . $ QGraphicsScene#addItem(af50d9c5bfd58279).(this);
42
43 pixmapListcxx . . $ Stone#pixmapList. = a;
44
45 // We use a trick here with the count of the pixmap list
46 // because the alternate ghosts list has only 2 images
47 if (pixmapListcxx . . $ Stone#pixmapList.->countcxx . . $ QList#count(455f465bc33b4cdf).() <= 2)
48 setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(pixmapListcxx . . $ Stone#pixmapList.->atcxx . . $ QList#at(e2681f9bb6b2f357).( colorcxx . . $ Stone#color. == stoneBlackcxx . . $ stoneBlack. ? 0 : 1));
49 else
50 setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(pixmapListcxx . . $ Stone#pixmapList.->atcxx . . $ QList#at(e2681f9bb6b2f357).( colorcxx . . $ Stone#color. == stoneBlackcxx . . $ stoneBlack. ? 0 : (rand() % (pixmapListcxx . . $ Stone#pixmapList.->countcxx . . $ QList#count(455f465bc33b4cdf).() -2) ) + 1));
51
52 shadowcxx . . $ Stone#shadow. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
53
54 if (has_shadow)
55 {
56 shadowcxx . . $ Stone#shadow. = new QGraphicsPixmapItemcxx . . $ QGraphicsPixmapItem#(0);
57 shadowcxx . . $ Stone#shadow.->setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(pixmapListcxx . . $ Stone#pixmapList.->lastcxx . . $ QList#last(19b2b6f17af048b).());
58 shadowcxx . . $ Stone#shadow.->setZValuecxx . . $ QGraphicsItem#setZValue(ba8836b59fb42830).(4);
59 canvas->addItemcxx . . $ QGraphicsScene#addItem(af50d9c5bfd58279).(shadowcxx . . $ Stone#shadow.);
60 }
61
62 moveNumcxx . . $ Stone#moveNum. = new QGraphicsSimpleTextItemcxx . . $ QGraphicsSimpleTextItem#(""cxx . . $ QString#QString(85c52e162fed56f9).,this);
63 moveNumcxx . . $ Stone#moveNum.->setPencxx . . $ QAbstractGraphicsShapeItem#setPen(af0a25dfda3214db).(QPencxx . . $ QPen#QPen(129a55e114526ad3).((cxx . . $ QColor#QColor(408ec4d5924bfb00). colorcxx . . $ Stone#color. == stoneBlackcxx . . $ stoneBlack. ? Qtcxx . . $ Qt/::whitecxx . . $ Qt/white. : Qtcxx . . $ Qt/::blackcxx . . $ Qt/black.)));
64
65 setZValuecxx . . $ QGraphicsItem#setZValue(ba8836b59fb42830).(5);
66 showcxx . . $ Stone#show(49f6e7a06ebc5aa8).();
67
68 deadcxx . . $ Stone#dead. = false;
69 sekicxx . . $ Stone#seki. = false;
70 checkedcxx . . $ Stone#checked. = false;
71
72 }
73
74 Stonecxx . . $ Stone#::~cxx . . $ Stone#`~Stone`(ced63f7c635d850d).Stonecxx . . $ Stone#()
75 {
76 if (shadowcxx . . $ Stone#shadow.)
77 delete shadowcxx . . $ Stone#shadow.;
78 }
79
80 /*
81 * Resets the stone image with the color (used when resizing the board)
82 */
83 void Stonecxx . . $ Stone#::setColorcxx . . $ Stone#setColor(42096433316d3db3).(StoneColorcxx . . $ StoneColor# c)
84 {
85 if (pixmapListcxx . . $ Stone#pixmapList.->countcxx . . $ QList#count(455f465bc33b4cdf).() <= 2)
86 setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(pixmapListcxx . . $ Stone#pixmapList.->atcxx . . $ QList#at(e2681f9bb6b2f357).( c == stoneBlackcxx . . $ stoneBlack. ? 0 : 1));
87 else
88 setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(pixmapListcxx . . $ Stone#pixmapList.->atcxx . . $ QList#at(e2681f9bb6b2f357).( c == stoneBlackcxx . . $ stoneBlack. ? 0 : (rand() % (pixmapListcxx . . $ Stone#pixmapList.->countcxx . . $ QList#count(455f465bc33b4cdf).() -2) ) + 1));
89
90 colorcxx . . $ Stone#color. = c;
91
92 if (shadowcxx . . $ Stone#shadow.)
93 shadowcxx . . $ Stone#shadow.->setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(pixmapListcxx . . $ Stone#pixmapList.->lastcxx . . $ QList#last(19b2b6f17af048b).());
94
95 // int w= pixmap().width();
96
97 // QFont f("",w);
98 // QString xx = moveNum->text();
99 // if (num)
100 // num->font().setPointSize(12);
101 }
102
103 /*
104 * self expl.
105 */
106 void Stonecxx . . $ Stone#::toggleOneColorGocxx . . $ Stone#toggleOneColorGo(b45ddcbc8423892c).(bool oneColor)
107 {
108 // if we play one color go, the black stones are repainted white, else normal black
109 if (colorcxx . . $ Stone#color. == stoneBlackcxx . . $ stoneBlack.)
110 setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(pixmapListcxx . . $ Stone#pixmapList.->atcxx . . $ QList#at(e2681f9bb6b2f357).( oneColor ? (rand() % WHITE_STONES_NBcxx . . $ `src/defines.h:40:9`!) + 1 : 0 ));
111 }
112
113 /*
114 * Moves the stone to position (in pixels)
115 */
116 void Stonecxx . . $ Stone#::setPoscxx . . $ Stone#setPos(bc12c9ec15586e6a).(double x, double y)
117 {
118
119 QGraphicsPixmapItemcxx . . $ QGraphicsPixmapItem#::setPoscxx . . $ QGraphicsItem#setPos(bc12c9ec15586e6a).((qrealcxx . . $ qreal#)x,(qrealcxx . . $ qreal#)y);
120 qrealcxx . . $ qreal# offset;
121 if (shadowcxx . . $ Stone#shadow.) {
122 offset = shadowcxx . . $ Stone#shadow.->boundingRectcxx . . $ QGraphicsPixmapItem#boundingRect(19f9350443f914b1).().heightcxx . . $ QRectF#height(d8440c0a87ad7443).();
123 shadowcxx . . $ Stone#shadow.->setPoscxx . . $ QGraphicsItem#setPos(bc12c9ec15586e6a).((qrealcxx . . $ qreal#)(x-offset / 8 ), (qrealcxx . . $ qreal#)(y+ offset / 8));
124 }
125
126 moveNumcxx . . $ Stone#moveNum.->setFontcxx . . $ QGraphicsSimpleTextItem#setFont(d0a4bd0c8524b912).(QFontcxx . . $ QFont#QFont(7ae16150a604556).(""cxx . . $ QString#QString(85c52e162fed56f9).,pixmapcxx . . $ QGraphicsPixmapItem#pixmap(3b2d5b7187256452).().widthcxx . . $ QPixmap#width(455f465bc33b4cdf).()/3, 1));
127
128 // qreal h = moveNum->boundingRect().height();
129 // qreal w = 0;
130 qrealcxx . . $ qreal# h = (boundingRectcxx . . $ QGraphicsPixmapItem#boundingRect(19f9350443f914b1).().heightcxx . . $ QRectF#height(d8440c0a87ad7443).() - moveNumcxx . . $ Stone#moveNum.->boundingRectcxx . . $ QGraphicsSimpleTextItem#boundingRect(19f9350443f914b1).().heightcxx . . $ QRectF#height(d8440c0a87ad7443).())/2 ;
131 qrealcxx . . $ qreal# w = (boundingRectcxx . . $ QGraphicsPixmapItem#boundingRect(19f9350443f914b1).().widthcxx . . $ QRectF#width(d8440c0a87ad7443).() - moveNumcxx . . $ Stone#moveNum.->boundingRectcxx . . $ QGraphicsSimpleTextItem#boundingRect(19f9350443f914b1).().widthcxx . . $ QRectF#width(d8440c0a87ad7443).())/2 ;
132
133 moveNumcxx . . $ Stone#moveNum.->setPoscxx . . $ QGraphicsItem#setPos(bc12c9ec15586e6a).(w,h);
134
135 }
136
137 void Stonecxx . . $ Stone#::hidecxx . . $ Stone#hide(49f6e7a06ebc5aa8).()
138 {
139 QGraphicsPixmapItemcxx . . $ QGraphicsPixmapItem#::hidecxx . . $ QGraphicsItem#hide(49f6e7a06ebc5aa8).();
140 if (shadowcxx . . $ Stone#shadow.) shadowcxx . . $ Stone#shadow.->hidecxx . . $ QGraphicsItem#hide(49f6e7a06ebc5aa8).();
141
142 }
143
144 void Stonecxx . . $ Stone#::showcxx . . $ Stone#show(49f6e7a06ebc5aa8).()
145 {
146 QGraphicsPixmapItemcxx . . $ QGraphicsPixmapItem#::showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
147 if (shadowcxx . . $ Stone#shadow.) shadowcxx . . $ Stone#shadow.->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
148
149 }
150
151 /*
152 * This allocates a new pixmap list to the stone (used for toggling dead stones when counting)
153 */
154 void Stonecxx . . $ Stone#::togglePixmapcxx . . $ Stone#togglePixmap(45848267e7fc80b8).(QListcxx . . $ QList#<QPixmapcxx . . $ QPixmap#> *a, bool showShadow)
155 {
156 //if the list is only B + W , or if the list is B + several white
157 if (a->countcxx . . $ QList#count(455f465bc33b4cdf).() <= 2)
158 setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(a->atcxx . . $ QList#at(e2681f9bb6b2f357).( colorcxx . . $ Stone#color. == stoneBlackcxx . . $ stoneBlack. ? 0 : 1));
159 else
160 setPixmapcxx . . $ QGraphicsPixmapItem#setPixmap(8887f7d25b86c3f4).(a->atcxx . . $ QList#at(e2681f9bb6b2f357).( colorcxx . . $ Stone#color. == stoneBlackcxx . . $ stoneBlack. ? 0 : (rand() % (a->countcxx . . $ QList#count(455f465bc33b4cdf).() -2) ) + 1));
161
162 if (shadowcxx . . $ Stone#shadow.)
163 {
164 if (showShadow)
165 shadowcxx . . $ Stone#shadow.->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
166 else
167 shadowcxx . . $ Stone#shadow.->hidecxx . . $ QGraphicsItem#hide(49f6e7a06ebc5aa8).();
168 }
169 }