summaryrefslogtreecommitdiff
path: root/noncore/games/solitaire/canvascard.cpp
Unidiff
Diffstat (limited to 'noncore/games/solitaire/canvascard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/canvascard.cpp71
1 files changed, 51 insertions, 20 deletions
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp
index ae3c859..7c4a5ba 100644
--- a/noncore/games/solitaire/canvascard.cpp
+++ b/noncore/games/solitaire/canvascard.cpp
@@ -18,24 +18,25 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "cardgame.h" 21#include "cardgame.h"
22#include "canvascard.h" 22#include "canvascard.h"
23 23
24#include <qpe/resource.h> 24#include <qpe/resource.h>
25 25
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qimage.h> 27#include <qimage.h>
28#include <qpaintdevice.h> 28#include <qpaintdevice.h>
29#include <qbitmap.h> 29#include <qbitmap.h>
30#include <qgfx_qws.h> // Needed to get the device's width
30 31
31#include <math.h> 32#include <math.h>
32 33
33#if defined( QT_QWS_CASSIOPEIA ) 34#if defined( QT_QWS_CASSIOPEIA )
34#define SLOW_HARDWARE 35#define SLOW_HARDWARE
35#endif 36#endif
36 37
37// Seems to be fast enough to me even without Transformations in the library 38// Seems to be fast enough to me even without Transformations in the library
38//#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) 39//#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ )
39//#define SLOW_HARDWARE 40//#define SLOW_HARDWARE
40//#endif 41//#endif
41 42
@@ -93,59 +94,81 @@ QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY)
93QPixmap *CanvasCard::cardsFaces = NULL; 94QPixmap *CanvasCard::cardsFaces = NULL;
94QPixmap *CanvasCard::cardsBacks = NULL; 95QPixmap *CanvasCard::cardsBacks = NULL;
95QBitmap *CanvasCard::cardsChars = NULL; 96QBitmap *CanvasCard::cardsChars = NULL;
96QBitmap *CanvasCard::cardsSuits = NULL; 97QBitmap *CanvasCard::cardsSuits = NULL;
97QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; 98QBitmap *CanvasCard::cardsCharsUpsideDown = NULL;
98QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; 99QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL;
99 100
100 101
101CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) : 102CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) :
102 Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0) 103 Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0)
103{ 104{
104 if ( !cardsFaces ) { 105 if ( !cardsFaces ) {
105 cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) ); 106 if ( qt_screen->deviceWidth() < 200 ) {
106 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); 107 cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face_small" ) );
107 cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) ); 108 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) );
108 cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) ); 109 cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars_small" ) );
110 cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits_small" ) );
111 } else {
112 cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) );
113 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) );
114 cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) );
115 cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) );
116 }
109 cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); 117 cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars );
110 cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); 118 cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits );
111 } 119 }
112 xOff = cardsFaces->width() / 2; 120 xOff = cardsFaces->width() / 2;
113 yOff = cardsFaces->height() / 2; 121 yOff = cardsFaces->height() / 2;
114 setSize( cardsFaces->width(), cardsFaces->height() ); 122 setSize( cardsFaces->width(), cardsFaces->height() );
115 setPen( NoPen ); 123 setPen( NoPen );
116 flipping = FALSE; 124 flipping = FALSE;
117} 125}
118 126
119 127
120void CanvasCard::setCardBack(int b) 128void CanvasCard::setCardBack(int b)
121{ 129{
122 if ( cardBack != b ) { 130 if ( cardBack != b ) {
123 131
124 cardBack = b; 132 cardBack = b;
125 133
126 if ( cardsBacks ) 134 if ( cardsBacks )
127 delete cardsBacks; 135 delete cardsBacks;
128 136
129 switch (cardBack) { 137 if ( qt_screen->deviceWidth() < 200 ) {
130 case 0: 138 switch (cardBack) {
131 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break; 139 case 0:
132 case 1: 140 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); break;
133 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break; 141 case 1:
134 case 2: 142 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002_small" ) ); break;
135 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break; 143 case 2:
136 case 3: 144 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003_small" ) ); break;
137 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break; 145 case 3:
138 case 4: 146 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004_small" ) ); break;
139 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break; 147 case 4:
148 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005_small" ) ); break;
149 }
150 } else {
151 switch (cardBack) {
152 case 0:
153 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break;
154 case 1:
155 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break;
156 case 2:
157 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break;
158 case 3:
159 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break;
160 case 4:
161 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break;
162 }
140 } 163 }
141 164
142 if ( !isFacing() ) 165 if ( !isFacing() )
143 redraw(); 166 redraw();
144 } 167 }
145} 168}
146 169
147 170
148void CanvasCard::draw(QPainter &painter) 171void CanvasCard::draw(QPainter &painter)
149{ 172{
150 int ix = (int)x(), iy = (int)y(); 173 int ix = (int)x(), iy = (int)y();
151 174
@@ -172,29 +195,37 @@ void CanvasCard::draw(QPainter &painter)
172*/ 195*/
173 196
174 int w = cardsFaces->width(), h = cardsFaces->height(); 197 int w = cardsFaces->width(), h = cardsFaces->height();
175 198
176 //p->setBrush( NoBrush ); 199 //p->setBrush( NoBrush );
177 p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); 200 p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) );
178 201
179 if ( isRed() == TRUE ) 202 if ( isRed() == TRUE )
180 p->setPen( QColor( 0xFF, 0, 0 ) ); 203 p->setPen( QColor( 0xFF, 0, 0 ) );
181 else 204 else
182 p->setPen( QColor( 0, 0, 0 ) ); 205 p->setPen( QColor( 0, 0, 0 ) );
183 206
184 p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); 207 if ( qt_screen->deviceWidth() < 200 ) {
185 p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); 208 p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
186 p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); 209 p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 );
187 p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); 210 p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 );
188 p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); 211 p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 );
212 p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 );
213 } else {
214 p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
215 p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 );
216 p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 );
217 p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 );
218 p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 );
219 }
189 220
190 } else { 221 } else {
191 222
192 p->drawPixmap( ix, iy, *cardsBacks ); 223 p->drawPixmap( ix, iy, *cardsBacks );
193 224
194 } 225 }
195 226
196 if (p != &painter) 227 if (p != &painter)
197 { 228 {
198 p->end(); 229 p->end();
199 QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); 230 QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY );
200 int xoff = scaledCard->width() / 2; 231 int xoff = scaledCard->width() / 2;