summaryrefslogtreecommitdiff
path: root/noncore/games/solitaire
Unidiff
Diffstat (limited to 'noncore/games/solitaire') (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/solitaire/canvascard.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp
index cd298ef..3ed9ea0 100644
--- a/noncore/games/solitaire/canvascard.cpp
+++ b/noncore/games/solitaire/canvascard.cpp
@@ -121,183 +121,183 @@ CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) :
121 setSize( cardsFaces->width(), cardsFaces->height() ); 121 setSize( cardsFaces->width(), cardsFaces->height() );
122 setPen( NoPen ); 122 setPen( NoPen );
123 flipping = FALSE; 123 flipping = FALSE;
124} 124}
125 125
126 126
127void CanvasCard::setCardBack(int b) 127void CanvasCard::setCardBack(int b)
128{ 128{
129 if ( cardBack != b ) { 129 if ( cardBack != b ) {
130 130
131 cardBack = b; 131 cardBack = b;
132 132
133 if ( cardsBacks ) 133 if ( cardsBacks )
134 delete cardsBacks; 134 delete cardsBacks;
135 135
136 if ( qt_screen->deviceWidth() < 200 ) { 136 if ( qt_screen->deviceWidth() < 200 ) {
137 switch (cardBack) { 137 switch (cardBack) {
138 case 0: 138 case 0:
139 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001_small" ) ); break; 139 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001_small" ) ); break;
140 case 1: 140 case 1:
141 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0002_small" ) ); break; 141 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0002_small" ) ); break;
142 case 2: 142 case 2:
143 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0003_small" ) ); break; 143 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0003_small" ) ); break;
144 case 3: 144 case 3:
145 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0004_small" ) ); break; 145 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0004_small" ) ); break;
146 case 4: 146 case 4:
147 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0005_small" ) ); break; 147 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0005_small" ) ); break;
148 } 148 }
149 } else { 149 } else {
150 switch (cardBack) { 150 switch (cardBack) {
151 case 0: 151 case 0:
152 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001" ) ); break; 152 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0001" ) ); break;
153 case 1: 153 case 1:
154 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0002" ) ); break; 154 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0002" ) ); break;
155 case 2: 155 case 2:
156 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0003" ) ); break; 156 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0003" ) ); break;
157 case 3: 157 case 3:
158 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0004" ) ); break; 158 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0004" ) ); break;
159 case 4: 159 case 4:
160 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0005" ) ); break; 160 cardsBacks = new QPixmap( Opie::Core::OResource::loadPixmap( "cards/card_back0005" ) ); break;
161 } 161 }
162 } 162 }
163 163
164 if ( !isFacing() ) 164 if ( !isFacing() )
165 redraw(); 165 redraw();
166 } 166 }
167} 167}
168 168
169 169
170void CanvasCard::draw(QPainter &painter) 170void CanvasCard::draw(QPainter &painter)
171{ 171{
172 int ix = (int)x(), iy = (int)y(); 172 int ix = (int)x(), iy = (int)y();
173 173
174 QPainter *p = &painter; 174 QPainter *p = &painter;
175 QPixmap *unscaledCard = NULL; 175 QPixmap *unscaledCard = NULL;
176 176
177 if ((scaleX <= 0.98) || (scaleY <= 0.98)) 177 if ((scaleX <= 0.98) || (scaleY <= 0.98))
178 { 178 {
179 p = new QPainter(); 179 p = new QPainter();
180 unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); 180 unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() );
181 p->begin(unscaledCard); 181 p->begin(unscaledCard);
182 ix = 0; 182 ix = 0;
183 iy = 0; 183 iy = 0;
184 } 184 }
185 185
186 if ( isFacing() ) { 186 if ( isFacing() ) {
187 187
188 int w = cardsFaces->width(), h = cardsFaces->height(); 188 int w = cardsFaces->width(), h = cardsFaces->height();
189 189
190 p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); 190 p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) );
191 191
192 if ( isRed() == TRUE ) 192 if ( isRed() == TRUE )
193 p->setPen( QColor( 0xFF, 0, 0 ) ); 193 p->setPen( QColor( 0xFF, 0, 0 ) );
194 else 194 else
195 p->setPen( QColor( 0, 0, 0 ) ); 195 p->setPen( QColor( 0, 0, 0 ) );
196 196
197 if ( qt_screen->deviceWidth() < 200 ) { 197 if ( qt_screen->deviceWidth() < 200 ) {
198 p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); 198 p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
199 p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 ); 199 p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 );
200 p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 ); 200 p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 );
201 p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 ); 201 p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 );
202 p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 ); 202 p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 );
203 } else { 203 } else {
204 p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); 204 p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
205 p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); 205 p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 );
206 p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); 206 p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 );
207 p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); 207 p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 );
208 p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); 208 p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 );
209 } 209 }
210 210
211 } else { 211 } else {
212 212
213 p->drawPixmap( ix, iy, *cardsBacks ); 213 p->drawPixmap( ix, iy, *cardsBacks );
214 214
215 } 215 }
216 216
217 if (p != &painter) 217 if (p != &painter && unscaledCard)
218 { 218 {
219 p->end(); 219 p->end();
220 QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); 220 QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY );
221 int xoff = scaledCard->width() / 2; 221 int xoff = scaledCard->width() / 2;
222 int yoff = scaledCard->height() / 2; 222 int yoff = scaledCard->height() / 2;
223 painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); 223 painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard );
224 delete p; 224 delete p;
225 delete unscaledCard; 225 delete unscaledCard;
226 delete scaledCard; 226 delete scaledCard;
227 } 227 }
228} 228}
229 229
230 230
231static const double flipLift = 1.5; 231static const double flipLift = 1.5;
232 232
233 233
234void CanvasCard::flipTo(int x2, int y2, int steps) 234void CanvasCard::flipTo(int x2, int y2, int steps)
235{ 235{
236 flipSteps = steps; 236 flipSteps = steps;
237 237
238#ifdef SLOW_HARDWARE 238#ifdef SLOW_HARDWARE
239 move(x2,y2); 239 move(x2,y2);
240 Card::flipTo(x2,y2,steps); 240 Card::flipTo(x2,y2,steps);
241#else 241#else
242 int x1 = (int)x(); 242 int x1 = (int)x();
243 int y1 = (int)y(); 243 int y1 = (int)y();
244 double dx = x2 - x1; 244 double dx = x2 - x1;
245 double dy = y2 - y1; 245 double dy = y2 - y1;
246 246
247 flipping = TRUE; 247 flipping = TRUE;
248 destX = x2; 248 destX = x2;
249 destY = y2; 249 destY = y2;
250 animSteps = flipSteps; 250 animSteps = flipSteps;
251 setVelocity(dx/animSteps, dy/animSteps-flipLift); 251 setVelocity(dx/animSteps, dy/animSteps-flipLift);
252 setAnimated(TRUE); 252 setAnimated(TRUE);
253#endif 253#endif
254} 254}
255 255
256 256
257void CanvasCard::advance(int stage) 257void CanvasCard::advance(int stage)
258{ 258{
259 if ( stage==1 ) { 259 if ( stage==1 ) {
260 if ( animSteps-- <= 0 ) { 260 if ( animSteps-- <= 0 ) {
261 scaleX = 1.0; 261 scaleX = 1.0;
262 scaleY = 1.0; 262 scaleY = 1.0;
263 flipping = FALSE; 263 flipping = FALSE;
264 setVelocity(0,0); 264 setVelocity(0,0);
265 setAnimated(FALSE); 265 setAnimated(FALSE);
266 move(destX,destY); // exact 266 move(destX,destY); // exact
267 } else { 267 } else {
268 if ( flipping ) { 268 if ( flipping ) {
269 if ( animSteps > flipSteps / 2 ) { 269 if ( animSteps > flipSteps / 2 ) {
270 // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0 270 // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0
271 scaleX = ((double)animSteps/flipSteps-0.5)*2; 271 scaleX = ((double)animSteps/flipSteps-0.5)*2;
272 } else { 272 } else {
273 // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1 273 // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1
274 scaleX = 1-((double)animSteps/flipSteps)*2; 274 scaleX = 1-((double)animSteps/flipSteps)*2;
275 } 275 }
276 if ( animSteps == flipSteps / 2-1 ) { 276 if ( animSteps == flipSteps / 2-1 ) {
277 setYVelocity(yVelocity()+flipLift*2); 277 setYVelocity(yVelocity()+flipLift*2);
278 setFace( !isFacing() ); 278 setFace( !isFacing() );
279 } 279 }
280 } 280 }
281 } 281 }
282 } 282 }
283 QCanvasRectangle::advance(stage); 283 QCanvasRectangle::advance(stage);
284} 284}
285 285
286 286
287void CanvasCard::animatedMove(int x2, int y2, int steps) 287void CanvasCard::animatedMove(int x2, int y2, int steps)
288{ 288{
289 destX = x2; 289 destX = x2;
290 destY = y2; 290 destY = y2;
291 291
292 double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; 292 double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1;
293 293
294 // Ensure a good speed 294 // Ensure a good speed
295 while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) 295 while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 )
296 steps--; 296 steps--;
297 297
298 setAnimated(TRUE); 298 setAnimated(TRUE);
299 setVelocity(dx/steps, dy/steps); 299 setVelocity(dx/steps, dy/steps);
300 300
301 animSteps = steps; 301 animSteps = steps;
302} 302}
303 303