-rw-r--r-- | noncore/games/backgammon/moveengine.cpp | 6 | ||||
-rw-r--r-- | noncore/games/kbill/UI.cpp | 31 | ||||
-rw-r--r-- | noncore/games/kcheckers/echeckers.cpp | 12 | ||||
-rw-r--r-- | noncore/games/kcheckers/rcheckers.cpp | 36 | ||||
-rw-r--r-- | noncore/settings/sysinfo/contrib/fft.c | 2 | ||||
-rw-r--r-- | noncore/styles/theme/othemebase.cpp | 2 |
6 files changed, 51 insertions, 38 deletions
diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp index a4145cc..b102258 100644 --- a/noncore/games/backgammon/moveengine.cpp +++ b/noncore/games/backgammon/moveengine.cpp | |||
@@ -1,291 +1,293 @@ | |||
1 | #include "moveengine.h" | 1 | #include "moveengine.h" |
2 | 2 | ||
3 | #include <qtimer.h> | 3 | #include <qtimer.h> |
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | 5 | ||
6 | MoveEngine::MoveEngine() | 6 | MoveEngine::MoveEngine() |
7 | : QObject() | 7 | : QObject() |
8 | { | 8 | { |
9 | int offset=7; | 9 | int offset=7; |
10 | int a=0; //counter variable | 10 | int a=0; //counter variable |
11 | int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210}; | 11 | int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210}; |
12 | for(a=0;a<26;a++) | 12 | for(a=0;a<26;a++) |
13 | { | 13 | { |
14 | x_coord[a]=xfill[a]; | 14 | x_coord[a]=xfill[a]; |
15 | } | 15 | } |
16 | 16 | ||
17 | int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; | 17 | int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; |
18 | int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; | 18 | int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; |
19 | for(a=0;a<15;a++) | 19 | for(a=0;a<15;a++) |
20 | { | 20 | { |
21 | yup_coord[a]=yfill[a]; | 21 | yup_coord[a]=yfill[a]; |
22 | ylow_coord[a]=185-(yfill[a]); | 22 | ylow_coord[a]=185-(yfill[a]); |
23 | z_coord[a]=zfill[a]; | 23 | z_coord[a]=zfill[a]; |
24 | } | 24 | } |
25 | for(a=0;a<5;a++) | 25 | for(a=0;a<5;a++) |
26 | { | 26 | { |
27 | if(a<3) | 27 | if(a<3) |
28 | { | 28 | { |
29 | x_fin1[a]=65+a*15; | 29 | x_fin1[a]=65+a*15; |
30 | x_fin2[a]=155-a*15; | 30 | x_fin2[a]=155-a*15; |
31 | } | 31 | } |
32 | y_fin[a]=225-a*5; | 32 | y_fin[a]=225-a*5; |
33 | } | 33 | } |
34 | z_fin=1; | 34 | z_fin=1; |
35 | 35 | ||
36 | reset(); | 36 | reset(); |
37 | } | 37 | } |
38 | 38 | ||
39 | MoveEngine::~MoveEngine() | 39 | MoveEngine::~MoveEngine() |
40 | {} | 40 | {} |
41 | 41 | ||
42 | void MoveEngine::position(Pieces& pieces,bool non_qte) | 42 | void MoveEngine::position(Pieces& pieces,bool non_qte) |
43 | { | 43 | { |
44 | int player1_counter=0; | 44 | int player1_counter=0; |
45 | int player2_counter=0; | 45 | int player2_counter=0; |
46 | 46 | ||
47 | //non qte styles are smaller !! | 47 | //non qte styles are smaller !! |
48 | int offset=(non_qte) ? 5 : 0; | 48 | int offset=(non_qte) ? 5 : 0; |
49 | 49 | ||
50 | for(int a=0;a<28;a++) | 50 | for(int a=0;a<28;a++) |
51 | { | 51 | { |
52 | for(int b=0;b<abs(population[a].total);b++) | 52 | for(int b=0;b<abs(population[a].total);b++) |
53 | { | 53 | { |
54 | if(population[a].total>0) //player 1 pieces | 54 | if(population[a].total>0) //player 1 pieces |
55 | { | 55 | { |
56 | pieces.player1[player1_counter].x=x_coord[a]-offset; | 56 | if (a < 26) |
57 | pieces.player1[player1_counter].x=x_coord[a]-offset; | ||
57 | if(a>=0 && a<13) | 58 | if(a>=0 && a<13) |
58 | { | 59 | { |
59 | pieces.player1[player1_counter].y=yup_coord[b]-offset; | 60 | pieces.player1[player1_counter].y=yup_coord[b]-offset; |
60 | pieces.player1[player1_counter].z=z_coord[b]; | 61 | pieces.player1[player1_counter].z=z_coord[b]; |
61 | pieces.player1[player1_counter].side=false; | 62 | pieces.player1[player1_counter].side=false; |
62 | player1_counter++; | 63 | player1_counter++; |
63 | } | 64 | } |
64 | else if(a>12 && a<26) | 65 | else if(a>12 && a<26) |
65 | { | 66 | { |
66 | pieces.player1[player1_counter].y=ylow_coord[b]-offset; | 67 | pieces.player1[player1_counter].y=ylow_coord[b]-offset; |
67 | pieces.player1[player1_counter].z=z_coord[b]; | 68 | pieces.player1[player1_counter].z=z_coord[b]; |
68 | pieces.player1[player1_counter].side=false; | 69 | pieces.player1[player1_counter].side=false; |
69 | player1_counter++; | 70 | player1_counter++; |
70 | } | 71 | } |
71 | else if(a==26) | 72 | else if(a==26) |
72 | { | 73 | { |
73 | if(b<5) | 74 | if(b<5) |
74 | { | 75 | { |
75 | pieces.player1[player1_counter].x=x_fin1[0]-offset; | 76 | pieces.player1[player1_counter].x=x_fin1[0]-offset; |
76 | pieces.player1[player1_counter].y=y_fin[b]-offset; | 77 | pieces.player1[player1_counter].y=y_fin[b]-offset; |
77 | pieces.player1[player1_counter].z=z_fin; | 78 | pieces.player1[player1_counter].z=z_fin; |
78 | } | 79 | } |
79 | else if(b>=5 && b<10) | 80 | else if(b>=5 && b<10) |
80 | { | 81 | { |
81 | pieces.player1[player1_counter].x=x_fin1[1]-offset; | 82 | pieces.player1[player1_counter].x=x_fin1[1]-offset; |
82 | pieces.player1[player1_counter].y=y_fin[b-5]-offset; | 83 | pieces.player1[player1_counter].y=y_fin[b-5]-offset; |
83 | pieces.player1[player1_counter].z=z_fin; | 84 | pieces.player1[player1_counter].z=z_fin; |
84 | } | 85 | } |
85 | else | 86 | else |
86 | { | 87 | { |
87 | pieces.player1[player1_counter].x=x_fin1[2]-offset; | 88 | pieces.player1[player1_counter].x=x_fin1[2]-offset; |
88 | pieces.player1[player1_counter].y=y_fin[b-10]-offset; | 89 | pieces.player1[player1_counter].y=y_fin[b-10]-offset; |
89 | pieces.player1[player1_counter].z=z_fin; | 90 | pieces.player1[player1_counter].z=z_fin; |
90 | } | 91 | } |
91 | pieces.player1[player1_counter].side=true; | 92 | pieces.player1[player1_counter].side=true; |
92 | player1_counter++; | 93 | player1_counter++; |
93 | 94 | ||
94 | } | 95 | } |
95 | } | 96 | } |
96 | 97 | ||
97 | else if(population[a].total<0) //player 2 pieces | 98 | else if(population[a].total<0) //player 2 pieces |
98 | { | 99 | { |
99 | pieces.player2[player2_counter].x=x_coord[a]-offset; | 100 | if (a < 26) |
101 | pieces.player2[player2_counter].x=x_coord[a]-offset; | ||
100 | if(a>=0 && a<13) | 102 | if(a>=0 && a<13) |
101 | { | 103 | { |
102 | pieces.player2[player2_counter].y=yup_coord[b]-offset; | 104 | pieces.player2[player2_counter].y=yup_coord[b]-offset; |
103 | pieces.player2[player2_counter].z=z_coord[b]; | 105 | pieces.player2[player2_counter].z=z_coord[b]; |
104 | pieces.player2[player2_counter].side=false; | 106 | pieces.player2[player2_counter].side=false; |
105 | player2_counter++; | 107 | player2_counter++; |
106 | } | 108 | } |
107 | else if(a>12 && a<26) | 109 | else if(a>12 && a<26) |
108 | { | 110 | { |
109 | pieces.player2[player2_counter].y=ylow_coord[b]-offset; | 111 | pieces.player2[player2_counter].y=ylow_coord[b]-offset; |
110 | pieces.player2[player2_counter].z=z_coord[b]; | 112 | pieces.player2[player2_counter].z=z_coord[b]; |
111 | pieces.player2[player2_counter].side=false; | 113 | pieces.player2[player2_counter].side=false; |
112 | player2_counter++; | 114 | player2_counter++; |
113 | } | 115 | } |
114 | else if(a==27) | 116 | else if(a==27) |
115 | { | 117 | { |
116 | if(b<5) | 118 | if(b<5) |
117 | { | 119 | { |
118 | pieces.player2[player2_counter].x=x_fin2[0]-offset; | 120 | pieces.player2[player2_counter].x=x_fin2[0]-offset; |
119 | pieces.player2[player2_counter].y=y_fin[b]-offset; | 121 | pieces.player2[player2_counter].y=y_fin[b]-offset; |
120 | pieces.player2[player2_counter].z=z_fin; | 122 | pieces.player2[player2_counter].z=z_fin; |
121 | } | 123 | } |
122 | else if(b>=5 && b<10) | 124 | else if(b>=5 && b<10) |
123 | { | 125 | { |
124 | pieces.player2[player2_counter].x=x_fin2[1]-offset; | 126 | pieces.player2[player2_counter].x=x_fin2[1]-offset; |
125 | pieces.player2[player2_counter].y=y_fin[b-5]-offset; | 127 | pieces.player2[player2_counter].y=y_fin[b-5]-offset; |
126 | pieces.player2[player2_counter].z=z_fin; | 128 | pieces.player2[player2_counter].z=z_fin; |
127 | } | 129 | } |
128 | else | 130 | else |
129 | { | 131 | { |
130 | pieces.player2[player2_counter].x=x_fin2[2]-offset; | 132 | pieces.player2[player2_counter].x=x_fin2[2]-offset; |
131 | pieces.player2[player2_counter].y=y_fin[b-10]-offset; | 133 | pieces.player2[player2_counter].y=y_fin[b-10]-offset; |
132 | pieces.player2[player2_counter].z=z_fin; | 134 | pieces.player2[player2_counter].z=z_fin; |
133 | } | 135 | } |
134 | pieces.player2[player2_counter].side=true; | 136 | pieces.player2[player2_counter].side=true; |
135 | player2_counter++; | 137 | player2_counter++; |
136 | 138 | ||
137 | } | 139 | } |
138 | } | 140 | } |
139 | } | 141 | } |
140 | } | 142 | } |
141 | } | 143 | } |
142 | 144 | ||
143 | void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) | 145 | void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) |
144 | { | 146 | { |
145 | checkstate(); | 147 | checkstate(); |
146 | player=newplayer; | 148 | player=newplayer; |
147 | otherplayer=(player==1) ? 2 : 1; | 149 | otherplayer=(player==1) ? 2 : 1; |
148 | dice[0]=face1; | 150 | dice[0]=face1; |
149 | dice[1]=face2; | 151 | dice[1]=face2; |
150 | dice[2]=face3; | 152 | dice[2]=face3; |
151 | dice[3]=face4; | 153 | dice[3]=face4; |
152 | marker_current=-1; | 154 | marker_current=-1; |
153 | if(getPossibleMoves()==0) | 155 | if(getPossibleMoves()==0) |
154 | { | 156 | { |
155 | emit nomove(); | 157 | emit nomove(); |
156 | return; // player will be changed | 158 | return; // player will be changed |
157 | } | 159 | } |
158 | if(!computer) | 160 | if(!computer) |
159 | return; //human intervention required | 161 | return; //human intervention required |
160 | 162 | ||
161 | QTimer::singleShot(2000,this,SLOT(automove())); | 163 | QTimer::singleShot(2000,this,SLOT(automove())); |
162 | } | 164 | } |
163 | 165 | ||
164 | 166 | ||
165 | void MoveEngine::automove() | 167 | void MoveEngine::automove() |
166 | { | 168 | { |
167 | //the maximimum possibility | 169 | //the maximimum possibility |
168 | int maxpos=0; | 170 | int maxpos=0; |
169 | //the position in the moves array | 171 | //the position in the moves array |
170 | int from=-1; | 172 | int from=-1; |
171 | int to=-1; | 173 | int to=-1; |
172 | //dice1 or dice 2 ?? | 174 | //dice1 or dice 2 ?? |
173 | int index_dice=0; | 175 | int index_dice=0; |
174 | for(int counter=0;counter<26;counter++) | 176 | for(int counter=0;counter<26;counter++) |
175 | { | 177 | { |
176 | int a=(player==1) ? counter : 25-counter; | 178 | int a=(player==1) ? counter : 25-counter; |
177 | for(int b=0;b<4;b++) | 179 | for(int b=0;b<4;b++) |
178 | { | 180 | { |
179 | if(moves[a].weight[b]>maxpos) | 181 | if(moves[a].weight[b]>maxpos) |
180 | { | 182 | { |
181 | maxpos=moves[a].weight[b]; | 183 | maxpos=moves[a].weight[b]; |
182 | from=a; | 184 | from=a; |
183 | to=moves[a].to[b]; | 185 | to=moves[a].to[b]; |
184 | index_dice=b+1; | 186 | index_dice=b+1; |
185 | } | 187 | } |
186 | } | 188 | } |
187 | } | 189 | } |
188 | move(from,to,index_dice); | 190 | move(from,to,index_dice); |
189 | } | 191 | } |
190 | 192 | ||
191 | 193 | ||
192 | void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) | 194 | void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) |
193 | { | 195 | { |
194 | //get the position of the mouse click | 196 | //get the position of the mouse click |
195 | bool upper=true; | 197 | bool upper=true; |
196 | bool found=false; | 198 | bool found=false; |
197 | 199 | ||
198 | int offset=(non_qte) ? 5 : 0; | 200 | int offset=(non_qte) ? 5 : 0; |
199 | 201 | ||
200 | if(y<=85) // board slots 0 to 12 | 202 | if(y<=85) // board slots 0 to 12 |
201 | marker.y_current=0; | 203 | marker.y_current=0; |
202 | else if(y>=105) //board slots 13 to 25 | 204 | else if(y>=105) //board slots 13 to 25 |
203 | { | 205 | { |
204 | marker.y_current=195-2*offset; | 206 | marker.y_current=195-2*offset; |
205 | upper=false; | 207 | upper=false; |
206 | } | 208 | } |
207 | 209 | ||
208 | int index=13; // the clicked board slot | 210 | int index=13; // the clicked board slot |
209 | 211 | ||
210 | while(index<25 && !found) | 212 | while(index<25 && !found) |
211 | { | 213 | { |
212 | if(x>=x_coord[index] && x<x_coord[index+1]) | 214 | if(x>=x_coord[index] && x<x_coord[index+1]) |
213 | { | 215 | { |
214 | marker.x_current=x_coord[index]; | 216 | marker.x_current=x_coord[index]; |
215 | found=true; | 217 | found=true; |
216 | ; | 218 | ; |
217 | } | 219 | } |
218 | else | 220 | else |
219 | { | 221 | { |
220 | index++; | 222 | index++; |
221 | } | 223 | } |
222 | } | 224 | } |
223 | if(!found) | 225 | if(!found) |
224 | { | 226 | { |
225 | marker.x_current=x_coord[25]; | 227 | marker.x_current=x_coord[25]; |
226 | index=25; | 228 | index=25; |
227 | } | 229 | } |
228 | if(upper) | 230 | if(upper) |
229 | { | 231 | { |
230 | index=25-index; | 232 | index=25-index; |
231 | } | 233 | } |
232 | 234 | ||
233 | int a=0; | 235 | int a=0; |
234 | int usedice=-1; | 236 | int usedice=-1; |
235 | int dice_value=7; | 237 | int dice_value=7; |
236 | for(a=0;a<4;a++) | 238 | for(a=0;a<4;a++) |
237 | { | 239 | { |
238 | if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a]) | 240 | if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a]) |
239 | { | 241 | { |
240 | usedice=a; | 242 | usedice=a; |
241 | dice_value=dice[0]; | 243 | dice_value=dice[0]; |
242 | } | 244 | } |
243 | } | 245 | } |
244 | if(usedice!=-1) | 246 | if(usedice!=-1) |
245 | { | 247 | { |
246 | move(marker_current,marker_next[usedice],usedice+1); | 248 | move(marker_current,marker_next[usedice],usedice+1); |
247 | nomarker(marker); | 249 | nomarker(marker); |
248 | return; | 250 | return; |
249 | 251 | ||
250 | } | 252 | } |
251 | 253 | ||
252 | 254 | ||
253 | if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled | 255 | if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled |
254 | { | 256 | { |
255 | nomarker(marker); | 257 | nomarker(marker); |
256 | return; | 258 | return; |
257 | } | 259 | } |
258 | else if(fieldColor(index)==player) | 260 | else if(fieldColor(index)==player) |
259 | { | 261 | { |
260 | marker.visible_current=true; | 262 | marker.visible_current=true; |
261 | marker_current=index; | 263 | marker_current=index; |
262 | } | 264 | } |
263 | else | 265 | else |
264 | { | 266 | { |
265 | nomarker(marker); | 267 | nomarker(marker); |
266 | return; | 268 | return; |
267 | } | 269 | } |
268 | 270 | ||
269 | for(a=0;a<4;a++) | 271 | for(a=0;a<4;a++) |
270 | { | 272 | { |
271 | if(moves[index].weight[a]>0) | 273 | if(moves[index].weight[a]>0) |
272 | { | 274 | { |
273 | int nextfield=moves[index].to[a]; | 275 | int nextfield=moves[index].to[a]; |
274 | marker.x_next[a]=x_coord[nextfield]; | 276 | marker.x_next[a]=x_coord[nextfield]; |
275 | marker_next[a]=nextfield; | 277 | marker_next[a]=nextfield; |
276 | if(nextfield<13) //upper half | 278 | if(nextfield<13) //upper half |
277 | marker.y_next[a]=0; | 279 | marker.y_next[a]=0; |
278 | else //lower half | 280 | else //lower half |
279 | marker.y_next[a]=195-2*offset; | 281 | marker.y_next[a]=195-2*offset; |
280 | marker.visible_next[a]=true; | 282 | marker.visible_next[a]=true; |
281 | } | 283 | } |
282 | else | 284 | else |
283 | { | 285 | { |
284 | marker.x_next[a]=0; | 286 | marker.x_next[a]=0; |
285 | marker.y_next[a]=0; | 287 | marker.y_next[a]=0; |
286 | marker_next[a]=-1; | 288 | marker_next[a]=-1; |
287 | marker.visible_next[a]=false; | 289 | marker.visible_next[a]=false; |
288 | } | 290 | } |
289 | } | 291 | } |
290 | return; | 292 | return; |
291 | } | 293 | } |
diff --git a/noncore/games/kbill/UI.cpp b/noncore/games/kbill/UI.cpp index 611cebf..a49c3c1 100644 --- a/noncore/games/kbill/UI.cpp +++ b/noncore/games/kbill/UI.cpp | |||
@@ -1,172 +1,171 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | UI.cc - description | 2 | UI.cc - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 1999 | 4 | begin : Thu Dec 30 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include "objects.h" | 17 | #include "objects.h" |
18 | #include "Strings.h" | 18 | #include "Strings.h" |
19 | #ifdef KDEVER | 19 | #ifdef KDEVER |
20 | #include <kapplication.h> | 20 | #include <kapplication.h> |
21 | #endif | 21 | #endif |
22 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
23 | 23 | ||
24 | #include "inputbox.h" | 24 | #include "inputbox.h" |
25 | 25 | ||
26 | /**************************/ | 26 | /**************************/ |
27 | /* Timer control routines */ | 27 | /* Timer control routines */ |
28 | /**************************/ | 28 | /**************************/ |
29 | 29 | ||
30 | UI::~UI() { | 30 | UI::~UI() { |
31 | paint.end(); | 31 | paint.end(); |
32 | delete pix; | 32 | delete pix; |
33 | } | 33 | } |
34 | 34 | ||
35 | void UI::restart_timer() { | 35 | void UI::restart_timer() { |
36 | field->startTimer(); | 36 | field->startTimer(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void UI::kill_timer() { | 39 | void UI::kill_timer() { |
40 | field->stopTimer(); | 40 | field->stopTimer(); |
41 | } | 41 | } |
42 | 42 | ||
43 | /*******************/ | 43 | /*******************/ |
44 | /* Window routines */ | 44 | /* Window routines */ |
45 | /*******************/ | 45 | /*******************/ |
46 | 46 | ||
47 | void UI::initialize(int *argc, char **argv) { | 47 | void UI::initialize(int *argc, char **argv) { |
48 | #ifdef KDEVER | 48 | #ifdef KDEVER |
49 | app = new KApplication(*argc, argv, "kbill"); | 49 | app = new KApplication(*argc, argv, "kbill"); |
50 | #endif | 50 | #endif |
51 | app = new QPEApplication(*argc, argv); | 51 | app = new QPEApplication(*argc, argv); |
52 | } | 52 | } |
53 | 53 | ||
54 | void UI::graph_init() { | 54 | void UI::graph_init() { |
55 | pix = new QPixmap(Game::scrwidth, Game::scrheight); | 55 | pix = new QPixmap(Game::scrwidth, Game::scrheight); |
56 | paint.begin(pix, field); | 56 | paint.begin(pix, field); |
57 | paint.setPen(QPen(Qt::black, 3)); | 57 | paint.setPen(QPen(Qt::black, 3)); |
58 | } | 58 | } |
59 | 59 | ||
60 | void UI::make_mainwin() { | 60 | void UI::make_mainwin() { |
61 | main = new KBill(); | 61 | main = new KBill(); |
62 | app->showMainWidget(main,true); | 62 | app->showMainWidget(main,true); |
63 | main->showMaximized(); | 63 | main->showMaximized(); |
64 | field = main->getField(); | 64 | field = main->getField(); |
65 | } | 65 | } |
66 | 66 | ||
67 | void UI::popup_dialog (int dialog) { | 67 | void UI::popup_dialog (int dialog) { |
68 | kill_timer(); | 68 | kill_timer(); |
69 | switch (dialog) { | 69 | switch (dialog) { |
70 | case Game::ENDGAME: | 70 | case Game::ENDGAME: |
71 | QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr)); | 71 | QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr)); |
72 | break; | 72 | break; |
73 | case Game::HIGHSCORE: | 73 | case Game::HIGHSCORE: |
74 | //QMessageBox::message(("HighScore"), highscorestr); | 74 | break; |
75 | break; | 75 | case Game::ENTERNAME: |
76 | case Game::ENTERNAME: { | 76 | { |
77 | InputBox b(main, 0, ("Enter Name"), QT_TR_NOOP(enternamestr)); | 77 | InputBox b(main, 0, ("Enter Name"), QT_TR_NOOP(enternamestr)); |
78 | bool state = b.exec() == 2; | 78 | bool state = b.exec() == 2; |
79 | char str[20], *nl; | 79 | char str[20], *nl; |
80 | strcpy(str, b.getText()); | 80 | strncpy(str, b.getText(), 19); |
81 | if (!str[0] || state) | 81 | if (!str[0] || state) |
82 | strcpy(str, "Anonymous"); | 82 | strcpy(str, "Anonymous"); |
83 | else if ((nl = strchr(str, '\n'))) | 83 | else if ((nl = strchr(str, '\n'))) |
84 | *nl = '\0'; | 84 | *nl = '\0'; |
85 | if (strlen(str) > 20) | 85 | if (strlen(str) > 19) |
86 | str[20] = 0; /* truncate string if too long */ | 86 | str[19] = '\0'; /* truncate/terminate the string if it is too long */ |
87 | // scores.recalc(str); | 87 | } |
88 | } | 88 | break; |
89 | break; | ||
90 | case Game::SCORE: | 89 | case Game::SCORE: |
91 | QMessageBox::message(("Score"), scorestr); | 90 | QMessageBox::message(("Score"), scorestr); |
92 | break; | 91 | break; |
93 | } | 92 | } |
94 | restart_timer(); | 93 | restart_timer(); |
95 | } | 94 | } |
96 | 95 | ||
97 | /*********************/ | 96 | /*********************/ |
98 | /* Graphics routines */ | 97 | /* Graphics routines */ |
99 | /*********************/ | 98 | /*********************/ |
100 | 99 | ||
101 | void UI::set_cursor(int cursor) { | 100 | void UI::set_cursor(int cursor) { |
102 | QCursor *cur; | 101 | QCursor *cur; |
103 | switch (cursor) { | 102 | switch (cursor) { |
104 | case Game::BUCKETC: | 103 | case Game::BUCKETC: |
105 | cur = bucket.cursor.cursor; | 104 | cur = bucket.cursor.cursor; |
106 | break; | 105 | break; |
107 | case Game::DOWNC: | 106 | case Game::DOWNC: |
108 | cur = downcursor.cursor; | 107 | cur = downcursor.cursor; |
109 | break; | 108 | break; |
110 | case Game::DEFAULTC: | 109 | case Game::DEFAULTC: |
111 | cur = defaultcursor.cursor; | 110 | cur = defaultcursor.cursor; |
112 | break; | 111 | break; |
113 | default: | 112 | default: |
114 | cur = OS.cursor[cursor].cursor; | 113 | cur = OS.cursor[cursor].cursor; |
115 | } | 114 | } |
116 | field->setCursor(*cur); | 115 | field->setCursor(*cur); |
117 | } | 116 | } |
118 | 117 | ||
119 | void UI::load_cursors() { | 118 | void UI::load_cursors() { |
120 | defaultcursor.load("hand_up", MCursor::SEP_MASK); | 119 | defaultcursor.load("hand_up", MCursor::SEP_MASK); |
121 | field->setCursor(*defaultcursor.cursor); | 120 | field->setCursor(*defaultcursor.cursor); |
122 | downcursor.load("hand_down", MCursor::SEP_MASK); | 121 | downcursor.load("hand_down", MCursor::SEP_MASK); |
123 | } | 122 | } |
124 | 123 | ||
125 | void UI::clear() { | 124 | void UI::clear() { |
126 | paint.eraseRect(0, 0, field->width(), field->height()); | 125 | paint.eraseRect(0, 0, field->width(), field->height()); |
127 | } | 126 | } |
128 | 127 | ||
129 | void UI::refresh() { | 128 | void UI::refresh() { |
130 | paint.flush(); | 129 | paint.flush(); |
131 | field->setPixmap(pix); | 130 | field->setPixmap(pix); |
132 | field->repaint(FALSE); | 131 | field->repaint(FALSE); |
133 | } | 132 | } |
134 | 133 | ||
135 | void UI::draw (Picture pict, int x, int y) { | 134 | void UI::draw (Picture pict, int x, int y) { |
136 | paint.drawPixmap(x, y, *pict.pix); | 135 | paint.drawPixmap(x, y, *pict.pix); |
137 | } | 136 | } |
138 | 137 | ||
139 | void UI::draw_centered (Picture pict) { | 138 | void UI::draw_centered (Picture pict) { |
140 | draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2); | 139 | draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2); |
141 | } | 140 | } |
142 | 141 | ||
143 | void UI::draw_line(int x1, int y1, int x2, int y2) { | 142 | void UI::draw_line(int x1, int y1, int x2, int y2) { |
144 | paint.drawLine(x1, y1, x2, y2); | 143 | paint.drawLine(x1, y1, x2, y2); |
145 | 144 | ||
146 | } | 145 | } |
147 | 146 | ||
148 | void UI::draw_str(char *str, int x, int y) { | 147 | void UI::draw_str(char *str, int x, int y) { |
149 | paint.drawText(x, y, str); | 148 | paint.drawText(x, y, str); |
150 | } | 149 | } |
151 | 150 | ||
152 | 151 | ||
153 | /******************/ | 152 | /******************/ |
154 | /* Other routines */ | 153 | /* Other routines */ |
155 | /******************/ | 154 | /******************/ |
156 | 155 | ||
157 | void UI::set_pausebutton (int action) { | 156 | void UI::set_pausebutton (int action) { |
158 | main->file->setItemEnabled(main->pauseid, action); | 157 | main->file->setItemEnabled(main->pauseid, action); |
159 | } | 158 | } |
160 | 159 | ||
161 | 160 | ||
162 | int UI::MainLoop() { | 161 | int UI::MainLoop() { |
163 | return app->exec(); | 162 | return app->exec(); |
164 | } | 163 | } |
165 | 164 | ||
166 | void UI::update_hsbox(char *str) { | 165 | void UI::update_hsbox(char *str) { |
167 | highscorestr = str; | 166 | highscorestr = str; |
168 | } | 167 | } |
169 | 168 | ||
170 | void UI::update_scorebox(int level, int score) { | 169 | void UI::update_scorebox(int level, int score) { |
171 | scorestr.sprintf ("%s %d:\n%s: %d", QT_TR_NOOP("After Level"), level, QT_TR_NOOP("Your score"), score); | 170 | scorestr.sprintf ("%s %d:\n%s: %d", QT_TR_NOOP("After Level"), level, QT_TR_NOOP("Your score"), score); |
172 | } | 171 | } |
diff --git a/noncore/games/kcheckers/echeckers.cpp b/noncore/games/kcheckers/echeckers.cpp index 1146059..afe62eb 100644 --- a/noncore/games/kcheckers/echeckers.cpp +++ b/noncore/games/kcheckers/echeckers.cpp | |||
@@ -1,349 +1,349 @@ | |||
1 | // | 1 | // |
2 | // English Checkers | 2 | // English Checkers |
3 | 3 | ||
4 | 4 | ||
5 | #include "echeckers.h" | 5 | #include "echeckers.h" |
6 | 6 | ||
7 | 7 | ||
8 | /////////////////////////////////////////////////// | 8 | /////////////////////////////////////////////////// |
9 | // | 9 | // |
10 | // User Functions | 10 | // User Functions |
11 | // | 11 | // |
12 | /////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////// |
13 | 13 | ||
14 | 14 | ||
15 | bool ECheckers::go1(int from,int field) | 15 | bool ECheckers::go1(int from,int field) |
16 | { | 16 | { |
17 | to=field; | 17 | to=field; |
18 | 18 | ||
19 | if(checkCapture1()) | 19 | if(checkCapture1()) |
20 | { | 20 | { |
21 | bool capture=false; | 21 | bool capture=false; |
22 | switch(board[from]) | 22 | switch(board[from]) |
23 | { | 23 | { |
24 | case MAN1: | 24 | case MAN1: |
25 | if(manCapture1(from,UL,capture)) return true; | 25 | if(manCapture1(from,UL,capture)) return true; |
26 | if(manCapture1(from,UR,capture)) return true; | 26 | if(manCapture1(from,UR,capture)) return true; |
27 | return false; | 27 | return false; |
28 | case KING1: | 28 | case KING1: |
29 | if(kingCapture1(from,UL,capture)) return true; | 29 | if(kingCapture1(from,UL,capture)) return true; |
30 | if(kingCapture1(from,UR,capture)) return true; | 30 | if(kingCapture1(from,UR,capture)) return true; |
31 | if(kingCapture1(from,DL,capture)) return true; | 31 | if(kingCapture1(from,DL,capture)) return true; |
32 | if(kingCapture1(from,DR,capture)) return true; | 32 | if(kingCapture1(from,DR,capture)) return true; |
33 | return false; | 33 | return false; |
34 | } | 34 | } |
35 | } | 35 | } |
36 | else | 36 | else |
37 | { | 37 | { |
38 | switch(board[from]) | 38 | switch(board[from]) |
39 | { | 39 | { |
40 | case MAN1: | 40 | case MAN1: |
41 | if((to==(from-6))||(to==(from-5))) | 41 | if((to==(from-6))||(to==(from-5))) |
42 | { | 42 | { |
43 | board[from]=FREE; | 43 | board[from]=FREE; |
44 | if(to<10) board[to]=KING1; | 44 | if(to<10) board[to]=KING1; |
45 | else board[to]=MAN1; | 45 | else board[to]=MAN1; |
46 | return true; | 46 | return true; |
47 | } | 47 | } |
48 | return false; | 48 | return false; |
49 | case KING1: | 49 | case KING1: |
50 | if((to==(from-6))||(to==(from-5))|| | 50 | if((to==(from-6))||(to==(from-5))|| |
51 | (to==(from+5))||(to==(from+6)) ) | 51 | (to==(from+5))||(to==(from+6)) ) |
52 | { | 52 | { |
53 | board[from]=FREE; | 53 | board[from]=FREE; |
54 | board[to]=KING1; | 54 | board[to]=KING1; |
55 | return true; | 55 | return true; |
56 | } | 56 | } |
57 | return false; | 57 | return false; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | return false; | 60 | return false; |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | bool ECheckers::checkCapture1() | 64 | bool ECheckers::checkCapture1() |
65 | { | 65 | { |
66 | for(int i=6;i<48;i++) | 66 | for(int i=6;i<48;i++) |
67 | { | 67 | { |
68 | switch(board[i]) | 68 | switch(board[i]) |
69 | { | 69 | { |
70 | case MAN1: | 70 | case MAN1: |
71 | if(board[i-6]==MAN2 || board[i-6]==KING2) | 71 | if(board[i-6]==MAN2 || board[i-6]==KING2) |
72 | if(board[i-12]==FREE) return true; | 72 | if(board[i-12]==FREE) return true; |
73 | if(board[i-5]==MAN2 || board[i-5]==KING2) | 73 | if(board[i-5]==MAN2 || board[i-5]==KING2) |
74 | if(board[i-10]==FREE) return true; | 74 | if(board[i-10]==FREE) return true; |
75 | break; | 75 | break; |
76 | case KING1: | 76 | case KING1: |
77 | if(board[i-6]==MAN2 || board[i-6]==KING2) | 77 | if(board[i-6]==MAN2 || board[i-6]==KING2) |
78 | if(board[i-12]==FREE) return true; | 78 | if(board[i-12]==FREE) return true; |
79 | if(board[i-5]==MAN2 || board[i-5]==KING2) | 79 | if(board[i-5]==MAN2 || board[i-5]==KING2) |
80 | if(board[i-10]==FREE) return true; | 80 | if(board[i-10]==FREE) return true; |
81 | if(board[i+5]==MAN2 || board[i+5]==KING2) | 81 | if(board[i+5]==MAN2 || board[i+5]==KING2) |
82 | if(board[i+10]==FREE) return true; | 82 | if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; |
83 | if(board[i+6]==MAN2 || board[i+6]==KING2) | 83 | if(board[i+6]==MAN2 || board[i+6]==KING2) |
84 | if(board[i+12]==FREE) return true; | 84 | if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; |
85 | } | 85 | } |
86 | } | 86 | } |
87 | return false; | 87 | return false; |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | // Return TRUE if a course of the user true | 91 | // Return TRUE if a course of the user true |
92 | // Return FALSE if a course of the user incorrect | 92 | // Return FALSE if a course of the user incorrect |
93 | 93 | ||
94 | bool ECheckers::manCapture1(int from,int direction,bool &capture) | 94 | bool ECheckers::manCapture1(int from,int direction,bool &capture) |
95 | { | 95 | { |
96 | int i=from+direction; | 96 | int i=from+direction; |
97 | if(board[i]==MAN2 || board[i]==KING2) | 97 | if(board[i]==MAN2 || board[i]==KING2) |
98 | { | 98 | { |
99 | int k=i+direction; | 99 | int k=i+direction; |
100 | if(board[k]==FREE) | 100 | if(board[k]==FREE) |
101 | { | 101 | { |
102 | bool next=false; | 102 | bool next=false; |
103 | int save=board[i]; | 103 | int save=board[i]; |
104 | board[from]=FREE; | 104 | board[from]=FREE; |
105 | board[i]=NONE; | 105 | board[i]=NONE; |
106 | 106 | ||
107 | if(k<10) | 107 | if(k<10) |
108 | { | 108 | { |
109 | board[k]=KING1; | 109 | board[k]=KING1; |
110 | if(kingCapture1(k,direction+11,next)) {board[i]=FREE;return true;} | 110 | if(kingCapture1(k,direction+11,next)) {board[i]=FREE;return true;} |
111 | } | 111 | } |
112 | else | 112 | else |
113 | { | 113 | { |
114 | board[k]=MAN1; | 114 | board[k]=MAN1; |
115 | if(manCapture1(k,UL,next)) {board[i]=FREE;return true;} | 115 | if(manCapture1(k,UL,next)) {board[i]=FREE;return true;} |
116 | if(manCapture1(k,UR,next)) {board[i]=FREE;return true;} | 116 | if(manCapture1(k,UR,next)) {board[i]=FREE;return true;} |
117 | } | 117 | } |
118 | 118 | ||
119 | if((!next) && k==to) {board[i]=FREE;return true;} | 119 | if((!next) && k==to) {board[i]=FREE;return true;} |
120 | 120 | ||
121 | board[k]=FREE; | 121 | board[k]=FREE; |
122 | board[i]=save; | 122 | board[i]=save; |
123 | board[from]=MAN1; | 123 | board[from]=MAN1; |
124 | capture=true; | 124 | capture=true; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | return false; | 127 | return false; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | bool ECheckers::kingCapture1(int from,int direction,bool &capture) | 131 | bool ECheckers::kingCapture1(int from,int direction,bool &capture) |
132 | { | 132 | { |
133 | int i=from+direction; | 133 | int i=from+direction; |
134 | if(board[i]==MAN2 || board[i]==KING2) | 134 | if(board[i]==MAN2 || board[i]==KING2) |
135 | { | 135 | { |
136 | int k=i+direction; | 136 | int k=i+direction; |
137 | if(board[k]==FREE) | 137 | if(board[k]==FREE) |
138 | { | 138 | { |
139 | bool next=false; | 139 | bool next=false; |
140 | int save=board[i]; | 140 | int save=board[i]; |
141 | board[from]=FREE; | 141 | board[from]=FREE; |
142 | board[i]=NONE; | 142 | board[i]=NONE; |
143 | board[k]=KING1; | 143 | board[k]=KING1; |
144 | 144 | ||
145 | if(direction==UL || direction==DR) | 145 | if(direction==UL || direction==DR) |
146 | { | 146 | { |
147 | if(kingCapture1(k,UR,next)) {board[i]=FREE;return true;} | 147 | if(kingCapture1(k,UR,next)) {board[i]=FREE;return true;} |
148 | if(kingCapture1(k,DL,next)) {board[i]=FREE;return true;} | 148 | if(kingCapture1(k,DL,next)) {board[i]=FREE;return true;} |
149 | } | 149 | } |
150 | else | 150 | else |
151 | { | 151 | { |
152 | if(kingCapture1(k,UL,next)) {board[i]=FREE;return true;} | 152 | if(kingCapture1(k,UL,next)) {board[i]=FREE;return true;} |
153 | if(kingCapture1(k,DR,next)) {board[i]=FREE;return true;} | 153 | if(kingCapture1(k,DR,next)) {board[i]=FREE;return true;} |
154 | } | 154 | } |
155 | if(kingCapture1(k,direction,next)) {board[i]=FREE;return true;} | 155 | if(kingCapture1(k,direction,next)) {board[i]=FREE;return true;} |
156 | 156 | ||
157 | if((!next) && k==to) {board[i]=FREE;return true;} | 157 | if((!next) && k==to) {board[i]=FREE;return true;} |
158 | 158 | ||
159 | board[k]=FREE; | 159 | board[k]=FREE; |
160 | board[i]=save; | 160 | board[i]=save; |
161 | board[from]=KING1; | 161 | board[from]=KING1; |
162 | capture=true; | 162 | capture=true; |
163 | } | 163 | } |
164 | } | 164 | } |
165 | return false; | 165 | return false; |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | //////////////////////////////////////////////////// | 169 | //////////////////////////////////////////////////// |
170 | // | 170 | // |
171 | // Computer Functions | 171 | // Computer Functions |
172 | // | 172 | // |
173 | //////////////////////////////////////////////////// | 173 | //////////////////////////////////////////////////// |
174 | 174 | ||
175 | 175 | ||
176 | void ECheckers::kingMove2(int from,int &resMax) | 176 | void ECheckers::kingMove2(int from,int &resMax) |
177 | { | 177 | { |
178 | board[from]=FREE; | 178 | board[from]=FREE; |
179 | 179 | ||
180 | int i=from-6; | 180 | int i=from-6; |
181 | if(board[i]==FREE) | 181 | if(board[i]==FREE) |
182 | { | 182 | { |
183 | board[i]=KING2; | 183 | board[i]=KING2; |
184 | turn(resMax); | 184 | turn(resMax); |
185 | board[i]=FREE; | 185 | board[i]=FREE; |
186 | } | 186 | } |
187 | 187 | ||
188 | i=from-5; | 188 | i=from-5; |
189 | if(board[i]==FREE) | 189 | if(board[i]==FREE) |
190 | { | 190 | { |
191 | board[i]=KING2; | 191 | board[i]=KING2; |
192 | turn(resMax); | 192 | turn(resMax); |
193 | board[i]=FREE; | 193 | board[i]=FREE; |
194 | } | 194 | } |
195 | 195 | ||
196 | i=from+5; | 196 | i=from+5; |
197 | if(board[i]==FREE) | 197 | if(board[i]==FREE) |
198 | { | 198 | { |
199 | board[i]=KING2; | 199 | board[i]=KING2; |
200 | turn(resMax); | 200 | turn(resMax); |
201 | board[i]=FREE; | 201 | board[i]=FREE; |
202 | } | 202 | } |
203 | 203 | ||
204 | i=from+6; | 204 | i=from+6; |
205 | if(board[i]==FREE) | 205 | if(board[i]==FREE) |
206 | { | 206 | { |
207 | board[i]=KING2; | 207 | board[i]=KING2; |
208 | turn(resMax); | 208 | turn(resMax); |
209 | board[i]=FREE; | 209 | board[i]=FREE; |
210 | } | 210 | } |
211 | 211 | ||
212 | board[from]=KING2; | 212 | board[from]=KING2; |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | bool ECheckers::checkCapture2() | 216 | bool ECheckers::checkCapture2() |
217 | { | 217 | { |
218 | for(int i=6;i<48;i++) | 218 | for(int i=6;i<48;i++) |
219 | { | 219 | { |
220 | switch(board[i]) | 220 | switch(board[i]) |
221 | { | 221 | { |
222 | case MAN2: | 222 | case MAN2: |
223 | if(board[i+5]==MAN1 || board[i+5]==KING1) | 223 | if(board[i+5]==MAN1 || board[i+5]==KING1) |
224 | if(board[i+10]==FREE) return true; | 224 | if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; |
225 | if(board[i+6]==MAN1 || board[i+6]==KING1) | 225 | if(board[i+6]==MAN1 || board[i+6]==KING1) |
226 | if(board[i+12]==FREE) return true; | 226 | if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; |
227 | break; | 227 | break; |
228 | case KING2: | 228 | case KING2: |
229 | if(board[i-6]==MAN1 || board[i-6]==KING1) | 229 | if(board[i-6]==MAN1 || board[i-6]==KING1) |
230 | if(board[i-12]==FREE) return true; | 230 | if(board[i-12]==FREE) return true; |
231 | if(board[i-5]==MAN1 || board[i-5]==KING1) | 231 | if(board[i-5]==MAN1 || board[i-5]==KING1) |
232 | if(board[i-10]==FREE) return true; | 232 | if(board[i-10]==FREE) return true; |
233 | if(board[i+5]==MAN1 || board[i+5]==KING1) | 233 | if(board[i+5]==MAN1 || board[i+5]==KING1) |
234 | if(board[i+10]==FREE) return true; | 234 | if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; |
235 | if(board[i+6]==MAN1 || board[i+6]==KING1) | 235 | if(board[i+6]==MAN1 || board[i+6]==KING1) |
236 | if(board[i+12]==FREE) return true; | 236 | if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; |
237 | } | 237 | } |
238 | } | 238 | } |
239 | return false; | 239 | return false; |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | // Return TRUE if it is possible to capture | 243 | // Return TRUE if it is possible to capture |
244 | // Return FALSE if it is impossible to capture | 244 | // Return FALSE if it is impossible to capture |
245 | 245 | ||
246 | bool ECheckers::manCapture2(int from,int &resMax) | 246 | bool ECheckers::manCapture2(int from,int &resMax) |
247 | { | 247 | { |
248 | bool capture=false; | 248 | bool capture=false; |
249 | 249 | ||
250 | int i=from+5; | 250 | int i=from+5; |
251 | if(board[i]==MAN1 || board[i]==KING1) | 251 | if(board[i]==MAN1 || board[i]==KING1) |
252 | { | 252 | { |
253 | int k=from+10; | 253 | int k=from+10; |
254 | if(board[k]==FREE) | 254 | if(board[k]==FREE) |
255 | { | 255 | { |
256 | int save=board[i]; | 256 | int save=board[i]; |
257 | board[from]=FREE; | 257 | board[from]=FREE; |
258 | board[i]=NONE; | 258 | board[i]=NONE; |
259 | resMax--; | 259 | resMax--; |
260 | if(from>32) | 260 | if(from>32) |
261 | { | 261 | { |
262 | board[k]=KING2; | 262 | board[k]=KING2; |
263 | if(!kingCapture2(k,UL,resMax)) turn(resMax,true); | 263 | if(!kingCapture2(k,UL,resMax)) turn(resMax,true); |
264 | } | 264 | } |
265 | else | 265 | else |
266 | { | 266 | { |
267 | board[k]=MAN2; | 267 | board[k]=MAN2; |
268 | if(!manCapture2(k,resMax)) turn(resMax,true); | 268 | if(!manCapture2(k,resMax)) turn(resMax,true); |
269 | } | 269 | } |
270 | resMax++; | 270 | resMax++; |
271 | board[k]=FREE; | 271 | board[k]=FREE; |
272 | board[i]=save; | 272 | board[i]=save; |
273 | board[from]=MAN2; | 273 | board[from]=MAN2; |
274 | capture=true; | 274 | capture=true; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | i=from+6; | 278 | i=from+6; |
279 | if(board[i]==MAN1 || board[i]==KING1) | 279 | if(board[i]==MAN1 || board[i]==KING1) |
280 | { | 280 | { |
281 | int k=from+12; | 281 | int k=from+12; |
282 | if(board[k]==FREE) | 282 | if(board[k]==FREE) |
283 | { | 283 | { |
284 | int save=board[i]; | 284 | int save=board[i]; |
285 | board[from]=FREE; | 285 | board[from]=FREE; |
286 | board[i]=NONE; | 286 | board[i]=NONE; |
287 | resMax--; | 287 | resMax--; |
288 | if(from>32) | 288 | if(from>32) |
289 | { | 289 | { |
290 | board[k]=KING2; | 290 | board[k]=KING2; |
291 | if(!kingCapture2(k,UR,resMax)) turn(resMax,true); | 291 | if(!kingCapture2(k,UR,resMax)) turn(resMax,true); |
292 | } | 292 | } |
293 | else | 293 | else |
294 | { | 294 | { |
295 | board[k]=MAN2; | 295 | board[k]=MAN2; |
296 | if(!manCapture2(k,resMax)) turn(resMax,true); | 296 | if(!manCapture2(k,resMax)) turn(resMax,true); |
297 | } | 297 | } |
298 | resMax++; | 298 | resMax++; |
299 | board[k]=FREE; | 299 | board[k]=FREE; |
300 | board[i]=save; | 300 | board[i]=save; |
301 | board[from]=MAN2; | 301 | board[from]=MAN2; |
302 | capture=true; | 302 | capture=true; |
303 | } | 303 | } |
304 | } | 304 | } |
305 | 305 | ||
306 | if(capture) return true; | 306 | if(capture) return true; |
307 | return false; | 307 | return false; |
308 | } | 308 | } |
309 | 309 | ||
310 | 310 | ||
311 | bool ECheckers::kingCapture2(int from,int direction,int &resMax) | 311 | bool ECheckers::kingCapture2(int from,int direction,int &resMax) |
312 | { | 312 | { |
313 | int i=from+direction; | 313 | int i=from+direction; |
314 | if(board[i]==MAN1 || board[i]==KING1) | 314 | if(board[i]==MAN1 || board[i]==KING1) |
315 | { | 315 | { |
316 | int k=i+direction; | 316 | int k=i+direction; |
317 | if(board[k]==FREE) | 317 | if(board[k]==FREE) |
318 | { | 318 | { |
319 | bool capture=false; | 319 | bool capture=false; |
320 | int save=board[i]; | 320 | int save=board[i]; |
321 | board[from]=FREE; | 321 | board[from]=FREE; |
322 | board[i]=NONE; | 322 | board[i]=NONE; |
323 | resMax--; | 323 | resMax--; |
324 | 324 | ||
325 | board[k]=KING2; | 325 | board[k]=KING2; |
326 | if(direction==UL || direction==DR) | 326 | if(direction==UL || direction==DR) |
327 | { | 327 | { |
328 | if(kingCapture2(k,UR,resMax)) capture=true; | 328 | if(kingCapture2(k,UR,resMax)) capture=true; |
329 | if(kingCapture2(k,DL,resMax)) capture=true; | 329 | if(kingCapture2(k,DL,resMax)) capture=true; |
330 | } | 330 | } |
331 | else | 331 | else |
332 | { | 332 | { |
333 | if(kingCapture2(k,UL,resMax)) capture=true; | 333 | if(kingCapture2(k,UL,resMax)) capture=true; |
334 | if(kingCapture2(k,DR,resMax)) capture=true; | 334 | if(kingCapture2(k,DR,resMax)) capture=true; |
335 | } | 335 | } |
336 | if(kingCapture2(k,direction,resMax)) capture=true; | 336 | if(kingCapture2(k,direction,resMax)) capture=true; |
337 | 337 | ||
338 | if(!capture) turn(resMax,true); | 338 | if(!capture) turn(resMax,true); |
339 | board[k]=FREE; | 339 | board[k]=FREE; |
340 | 340 | ||
341 | resMax++; | 341 | resMax++; |
342 | board[i]=save; | 342 | board[i]=save; |
343 | board[from]=KING2; | 343 | board[from]=KING2; |
344 | return true; | 344 | return true; |
345 | } | 345 | } |
346 | } | 346 | } |
347 | return false; | 347 | return false; |
348 | } | 348 | } |
349 | 349 | ||
diff --git a/noncore/games/kcheckers/rcheckers.cpp b/noncore/games/kcheckers/rcheckers.cpp index a1c7afa..d808780 100644 --- a/noncore/games/kcheckers/rcheckers.cpp +++ b/noncore/games/kcheckers/rcheckers.cpp | |||
@@ -1,476 +1,488 @@ | |||
1 | // | 1 | // |
2 | // Russian Checkers | 2 | // Russian Checkers |
3 | 3 | ||
4 | 4 | ||
5 | #include "rcheckers.h" | 5 | #include "rcheckers.h" |
6 | 6 | ||
7 | 7 | ||
8 | /////////////////////////////////////////////////// | 8 | /////////////////////////////////////////////////// |
9 | // | 9 | // |
10 | // User Functions | 10 | // User Functions |
11 | // | 11 | // |
12 | /////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////// |
13 | 13 | ||
14 | 14 | ||
15 | bool RCheckers::go1(int from,int field) | 15 | bool RCheckers::go1(int from,int field) |
16 | { | 16 | { |
17 | to=field; | 17 | to=field; |
18 | 18 | ||
19 | if(checkCapture1()) | 19 | if(checkCapture1()) |
20 | { | 20 | { |
21 | bool capture=false; | 21 | bool capture=false; |
22 | switch(board[from]) | 22 | switch(board[from]) |
23 | { | 23 | { |
24 | case MAN1: | 24 | case MAN1: |
25 | if(manCapture1(from,UL,capture)) return true; | 25 | if(manCapture1(from,UL,capture)) return true; |
26 | if(manCapture1(from,UR,capture)) return true; | 26 | if(manCapture1(from,UR,capture)) return true; |
27 | if(manCapture1(from,DL,capture)) return true; | 27 | if(manCapture1(from,DL,capture)) return true; |
28 | if(manCapture1(from,DR,capture)) return true; | 28 | if(manCapture1(from,DR,capture)) return true; |
29 | return false; | 29 | return false; |
30 | case KING1: | 30 | case KING1: |
31 | if(kingCapture1(from,UL,capture)) return true; | 31 | if(kingCapture1(from,UL,capture)) return true; |
32 | if(kingCapture1(from,UR,capture)) return true; | 32 | if(kingCapture1(from,UR,capture)) return true; |
33 | if(kingCapture1(from,DL,capture)) return true; | 33 | if(kingCapture1(from,DL,capture)) return true; |
34 | if(kingCapture1(from,DR,capture)) return true; | 34 | if(kingCapture1(from,DR,capture)) return true; |
35 | return false; | 35 | return false; |
36 | } | 36 | } |
37 | } | 37 | } |
38 | else | 38 | else |
39 | { | 39 | { |
40 | switch(board[from]) | 40 | switch(board[from]) |
41 | { | 41 | { |
42 | case MAN1: | 42 | case MAN1: |
43 | if((to==(from-6))||(to==(from-5))) | 43 | if((to==(from-6))||(to==(from-5))) |
44 | { | 44 | { |
45 | board[from]=FREE; | 45 | board[from]=FREE; |
46 | if(to<10) board[to]=KING1; | 46 | if(to<10) board[to]=KING1; |
47 | else board[to]=MAN1; | 47 | else board[to]=MAN1; |
48 | return true; | 48 | return true; |
49 | } | 49 | } |
50 | return false; | 50 | return false; |
51 | case KING1: | 51 | case KING1: |
52 | for(int i=from-6;;i-=6) | 52 | for(int i=from-6;;i-=6) |
53 | { | 53 | { |
54 | if(i==to) | 54 | if(i==to) |
55 | { | 55 | { |
56 | board[from]=FREE; | 56 | board[from]=FREE; |
57 | board[to]=KING1; | 57 | board[to]=KING1; |
58 | return true; | 58 | return true; |
59 | } | 59 | } |
60 | else if(board[i]==FREE) continue; | 60 | else if(board[i]==FREE) continue; |
61 | else break; | 61 | else break; |
62 | } | 62 | } |
63 | for(int i=from-5;;i-=5) | 63 | for(int i=from-5;;i-=5) |
64 | { | 64 | { |
65 | if(i==to) | 65 | if(i==to) |
66 | { | 66 | { |
67 | board[from]=FREE; | 67 | board[from]=FREE; |
68 | board[to]=KING1; | 68 | board[to]=KING1; |
69 | return true; | 69 | return true; |
70 | } | 70 | } |
71 | else if(board[i]==FREE) continue; | 71 | else if(board[i]==FREE) continue; |
72 | else break; | 72 | else break; |
73 | } | 73 | } |
74 | for(int i=from+5;;i+=5) | 74 | for(int i=from+5;;i+=5) |
75 | { | 75 | { |
76 | if(i==to) | 76 | if(i==to) |
77 | { | 77 | { |
78 | board[from]=FREE; | 78 | board[from]=FREE; |
79 | board[to]=KING1; | 79 | board[to]=KING1; |
80 | return true; | 80 | return true; |
81 | } | 81 | } |
82 | else if(board[i]==FREE) continue; | 82 | else if(board[i]==FREE) continue; |
83 | else break; | 83 | else break; |
84 | } | 84 | } |
85 | for(int i=from+6;;i+=6) | 85 | for(int i=from+6;;i+=6) |
86 | { | 86 | { |
87 | if(i==to) | 87 | if(i==to) |
88 | { | 88 | { |
89 | board[from]=FREE; | 89 | board[from]=FREE; |
90 | board[to]=KING1; | 90 | board[to]=KING1; |
91 | return true; | 91 | return true; |
92 | } | 92 | } |
93 | else if(board[i]==FREE) continue; | 93 | else if(board[i]==FREE) continue; |
94 | else break; | 94 | else break; |
95 | } | 95 | } |
96 | return false; | 96 | return false; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | return false; | 99 | return false; |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | bool RCheckers::checkCapture1() | 103 | bool RCheckers::checkCapture1() |
104 | { | 104 | { |
105 | for(int i=6;i<48;i++) | 105 | for(int i=6;i<48;i++) |
106 | { | 106 | { |
107 | switch(board[i]) | 107 | switch(board[i]) |
108 | { | 108 | { |
109 | case MAN1: | 109 | case MAN1: |
110 | if(board[i-6]==MAN2 || board[i-6]==KING2) | 110 | if(board[i-6]==MAN2 || board[i-6]==KING2) |
111 | if(board[i-12]==FREE) return true; | 111 | if(board[i-12]==FREE) return true; |
112 | if(board[i-5]==MAN2 || board[i-5]==KING2) | 112 | if(board[i-5]==MAN2 || board[i-5]==KING2) |
113 | if(board[i-10]==FREE) return true; | 113 | if(board[i-10]==FREE) return true; |
114 | if(board[i+5]==MAN2 || board[i+5]==KING2) | 114 | if(board[i+5]==MAN2 || board[i+5]==KING2) |
115 | if(board[i+10]==FREE) return true; | 115 | if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; |
116 | if(board[i+6]==MAN2 || board[i+6]==KING2) | 116 | if(board[i+6]==MAN2 || board[i+6]==KING2) |
117 | if(board[i+12]==FREE) return true; | 117 | if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; |
118 | break; | 118 | break; |
119 | case KING1: | 119 | case KING1: |
120 | int k; | 120 | int k; |
121 | for(k=i-6;board[k]==FREE;k-=6); | 121 | for(k=i-6;board[k]==FREE;k-=6); |
122 | if(board[k]==MAN2 || board[k]==KING2) | 122 | if(board[k]==MAN2 || board[k]==KING2) |
123 | if(board[k-6]==FREE) return true; | 123 | if(board[k-6]==FREE) return true; |
124 | 124 | ||
125 | for(k=i-5;board[k]==FREE;k-=5); | 125 | for(k=i-5;board[k]==FREE;k-=5); |
126 | if(board[k]==MAN2 || board[k]==KING2) | 126 | if(board[k]==MAN2 || board[k]==KING2) |
127 | if(board[k-5]==FREE) return true; | 127 | if(board[k-5]==FREE) return true; |
128 | 128 | ||
129 | for(k=i+5;board[k]==FREE;k+=5); | 129 | for(k=i+5;board[k]==FREE;k+=5) { |
130 | if (k >= 49) | ||
131 | break; | ||
132 | } | ||
130 | if(board[k]==MAN2 || board[k]==KING2) | 133 | if(board[k]==MAN2 || board[k]==KING2) |
131 | if(board[k+5]==FREE) return true; | 134 | if(board[((k+5) < 54) ? k+5 : 53]==FREE) return true; |
132 | 135 | ||
133 | for(k=i+6;board[k]==FREE;k+=6); | 136 | for(k=i+6;board[k]==FREE;k+=6) { |
137 | if (k >=48) | ||
138 | break; | ||
139 | } | ||
134 | if(board[k]==MAN2 || board[k]==KING2) | 140 | if(board[k]==MAN2 || board[k]==KING2) |
135 | if(board[k+6]==FREE) return true; | 141 | if(board[((k+6) < 54) ? k+6 : 53]==FREE) return true; |
136 | } | 142 | } |
137 | } | 143 | } |
138 | return false; | 144 | return false; |
139 | } | 145 | } |
140 | 146 | ||
141 | 147 | ||
142 | // Return TRUE if a course of the user true | 148 | // Return TRUE if a course of the user true |
143 | // Return FALSE if a course of the user incorrect | 149 | // Return FALSE if a course of the user incorrect |
144 | 150 | ||
145 | bool RCheckers::manCapture1(int from,int direction,bool &capture) | 151 | bool RCheckers::manCapture1(int from,int direction,bool &capture) |
146 | { | 152 | { |
147 | int i=from+direction; | 153 | int i=from+direction; |
148 | if(board[i]==MAN2 || board[i]==KING2) | 154 | if(board[i]==MAN2 || board[i]==KING2) |
149 | { | 155 | { |
150 | int k=i+direction; | 156 | int k=i+direction; |
151 | if(board[k]==FREE) | 157 | if(board[k]==FREE) |
152 | { | 158 | { |
153 | bool next=false; | 159 | bool next=false; |
154 | int save=board[i]; | 160 | int save=board[i]; |
155 | board[from]=FREE; | 161 | board[from]=FREE; |
156 | board[i]=NONE; | 162 | board[i]=NONE; |
157 | 163 | ||
158 | if(k<10) | 164 | if(k<10) |
159 | { | 165 | { |
160 | board[k]=KING1; | 166 | board[k]=KING1; |
161 | if(kingCapture1(k,direction+11,next)) {board[i]=FREE;return true;} | 167 | if(kingCapture1(k,direction+11,next)) {board[i]=FREE;return true;} |
162 | } | 168 | } |
163 | else | 169 | else |
164 | { | 170 | { |
165 | board[k]=MAN1; | 171 | board[k]=MAN1; |
166 | if(direction==UL || direction==DR) | 172 | if(direction==UL || direction==DR) |
167 | { | 173 | { |
168 | if(manCapture1(k,UR,next)) {board[i]=FREE;return true;} | 174 | if(manCapture1(k,UR,next)) {board[i]=FREE;return true;} |
169 | if(manCapture1(k,DL,next)) {board[i]=FREE;return true;} | 175 | if(manCapture1(k,DL,next)) {board[i]=FREE;return true;} |
170 | } | 176 | } |
171 | else | 177 | else |
172 | { | 178 | { |
173 | if(manCapture1(k,UL,next)) {board[i]=FREE;return true;} | 179 | if(manCapture1(k,UL,next)) {board[i]=FREE;return true;} |
174 | if(manCapture1(k,DR,next)) {board[i]=FREE;return true;} | 180 | if(manCapture1(k,DR,next)) {board[i]=FREE;return true;} |
175 | } | 181 | } |
176 | if(manCapture1(k,direction,next)) {board[i]=FREE;return true;} | 182 | if(manCapture1(k,direction,next)) {board[i]=FREE;return true;} |
177 | } | 183 | } |
178 | 184 | ||
179 | if((!next) && k==to) {board[i]=FREE;return true;} | 185 | if((!next) && k==to) {board[i]=FREE;return true;} |
180 | 186 | ||
181 | board[k]=FREE; | 187 | board[k]=FREE; |
182 | board[i]=save; | 188 | board[i]=save; |
183 | board[from]=MAN1; | 189 | board[from]=MAN1; |
184 | capture=true; | 190 | capture=true; |
185 | } | 191 | } |
186 | } | 192 | } |
187 | return false; | 193 | return false; |
188 | } | 194 | } |
189 | 195 | ||
190 | 196 | ||
191 | bool RCheckers::kingCapture1(int from,int direction,bool &capture) | 197 | bool RCheckers::kingCapture1(int from,int direction,bool &capture) |
192 | { | 198 | { |
193 | int i; | 199 | int i; |
194 | for(i=from+direction;board[i]==FREE;i+=direction); | 200 | for(i=from+direction;board[i]==FREE;i+=direction); |
195 | 201 | ||
196 | if(board[i]==MAN2 || board[i]==KING2) | 202 | if(board[i]==MAN2 || board[i]==KING2) |
197 | { | 203 | { |
198 | int k=i+direction; | 204 | int k=i+direction; |
199 | if(board[k]==FREE) | 205 | if(board[k]==FREE) |
200 | { | 206 | { |
201 | bool next=false; | 207 | bool next=false; |
202 | int save=board[i]; | 208 | int save=board[i]; |
203 | board[from]=FREE; | 209 | board[from]=FREE; |
204 | board[i]=NONE; | 210 | board[i]=NONE; |
205 | 211 | ||
206 | for(;board[k]==FREE;k+=direction) | 212 | for(;board[k]==FREE;k+=direction) |
207 | { | 213 | { |
208 | board[k]=KING1; | 214 | board[k]=KING1; |
209 | if(direction==UL || direction==DR) | 215 | if(direction==UL || direction==DR) |
210 | { | 216 | { |
211 | if(kingCapture1(k,UR,next)) {board[i]=FREE;return true;} | 217 | if(kingCapture1(k,UR,next)) {board[i]=FREE;return true;} |
212 | if(kingCapture1(k,DL,next)) {board[i]=FREE;return true;} | 218 | if(kingCapture1(k,DL,next)) {board[i]=FREE;return true;} |
213 | } | 219 | } |
214 | else | 220 | else |
215 | { | 221 | { |
216 | if(kingCapture1(k,UL,next)) {board[i]=FREE;return true;} | 222 | if(kingCapture1(k,UL,next)) {board[i]=FREE;return true;} |
217 | if(kingCapture1(k,DR,next)) {board[i]=FREE;return true;} | 223 | if(kingCapture1(k,DR,next)) {board[i]=FREE;return true;} |
218 | } | 224 | } |
219 | board[k]=FREE; | 225 | board[k]=FREE; |
220 | } | 226 | } |
221 | 227 | ||
222 | board[k-=direction]=KING1; | 228 | board[k-=direction]=KING1; |
223 | if(kingCapture1(k,direction,next)) {board[i]=FREE;return true;} | 229 | if(kingCapture1(k,direction,next)) {board[i]=FREE;return true;} |
224 | board[k]=FREE; | 230 | board[k]=FREE; |
225 | 231 | ||
226 | if(!next) | 232 | if(!next) |
227 | for(;k!=i;k-=direction) | 233 | for(;k!=i;k-=direction) |
228 | if(k==to) {board[i]=FREE;board[k]=KING1;return true;} | 234 | if(k==to) {board[i]=FREE;board[k]=KING1;return true;} |
229 | 235 | ||
230 | board[i]=save; | 236 | board[i]=save; |
231 | board[from]=KING1; | 237 | board[from]=KING1; |
232 | capture=true; | 238 | capture=true; |
233 | } | 239 | } |
234 | } | 240 | } |
235 | return false; | 241 | return false; |
236 | } | 242 | } |
237 | 243 | ||
238 | 244 | ||
239 | //////////////////////////////////////////////////// | 245 | //////////////////////////////////////////////////// |
240 | // | 246 | // |
241 | // Computer Functions | 247 | // Computer Functions |
242 | // | 248 | // |
243 | //////////////////////////////////////////////////// | 249 | //////////////////////////////////////////////////// |
244 | 250 | ||
245 | 251 | ||
246 | void RCheckers::kingMove2(int from,int &resMax) | 252 | void RCheckers::kingMove2(int from,int &resMax) |
247 | { | 253 | { |
248 | board[from]=FREE; | 254 | board[from]=FREE; |
249 | for(int i=from-6;board[i]==FREE;i-=6) | 255 | for(int i=from-6;board[i]==FREE;i-=6) |
250 | { | 256 | { |
251 | board[i]=KING2; | 257 | board[i]=KING2; |
252 | turn(resMax); | 258 | turn(resMax); |
253 | board[i]=FREE; | 259 | board[i]=FREE; |
254 | } | 260 | } |
255 | for(int i=from-5;board[i]==FREE;i-=5) | 261 | for(int i=from-5;board[i]==FREE;i-=5) |
256 | { | 262 | { |
257 | board[i]=KING2; | 263 | board[i]=KING2; |
258 | turn(resMax); | 264 | turn(resMax); |
259 | board[i]=FREE; | 265 | board[i]=FREE; |
260 | } | 266 | } |
261 | for(int i=from+5;board[i]==FREE;i+=5) | 267 | for(int i=from+5;board[i]==FREE;i+=5) |
262 | { | 268 | { |
263 | board[i]=KING2; | 269 | board[i]=KING2; |
264 | turn(resMax); | 270 | turn(resMax); |
265 | board[i]=FREE; | 271 | board[i]=FREE; |
266 | } | 272 | } |
267 | for(int i=from+6;board[i]==FREE;i+=6) | 273 | for(int i=from+6;board[i]==FREE;i+=6) |
268 | { | 274 | { |
269 | board[i]=KING2; | 275 | board[i]=KING2; |
270 | turn(resMax); | 276 | turn(resMax); |
271 | board[i]=FREE; | 277 | board[i]=FREE; |
272 | } | 278 | } |
273 | board[from]=KING2; | 279 | board[from]=KING2; |
274 | } | 280 | } |
275 | 281 | ||
276 | 282 | ||
277 | bool RCheckers::checkCapture2() | 283 | bool RCheckers::checkCapture2() |
278 | { | 284 | { |
279 | for(int i=6;i<48;i++) | 285 | for(int i=6;i<48;i++) |
280 | { | 286 | { |
281 | switch(board[i]) | 287 | switch(board[i]) |
282 | { | 288 | { |
283 | case MAN2: | 289 | case MAN2: |
284 | if(board[i-6]==MAN1 || board[i-6]==KING1) | 290 | if(board[i-6]==MAN1 || board[i-6]==KING1) |
285 | if(board[i-12]==FREE) return true; | 291 | if(board[i-12]==FREE) return true; |
286 | if(board[i-5]==MAN1 || board[i-5]==KING1) | 292 | if(board[i-5]==MAN1 || board[i-5]==KING1) |
287 | if(board[i-10]==FREE) return true; | 293 | if(board[i-10]==FREE) return true; |
288 | if(board[i+5]==MAN1 || board[i+5]==KING1) | 294 | if(board[i+5]==MAN1 || board[i+5]==KING1) |
289 | if(board[i+10]==FREE) return true; | 295 | if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; |
290 | if(board[i+6]==MAN1 || board[i+6]==KING1) | 296 | if(board[i+6]==MAN1 || board[i+6]==KING1) |
291 | if(board[i+12]==FREE) return true; | 297 | if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; |
292 | break; | 298 | break; |
293 | case KING2: | 299 | case KING2: |
294 | int k; | 300 | int k; |
295 | for(k=i-6;board[k]==FREE;k-=6); | 301 | for(k=i-6;board[k]==FREE;k-=6); |
296 | if(board[k]==MAN1 || board[k]==KING1) | 302 | if(board[k]==MAN1 || board[k]==KING1) |
297 | if(board[k-6]==FREE) return true; | 303 | if(board[k-6]==FREE) return true; |
298 | 304 | ||
299 | for(k=i-5;board[k]==FREE;k-=5); | 305 | for(k=i-5;board[k]==FREE;k-=5); |
300 | if(board[k]==MAN1 || board[k]==KING1) | 306 | if(board[k]==MAN1 || board[k]==KING1) |
301 | if(board[k-5]==FREE) return true; | 307 | if(board[k-5]==FREE) return true; |
302 | 308 | ||
303 | for(k=i+5;board[k]==FREE;k+=5); | 309 | for(k=i+5;board[k]==FREE;k+=5) { |
310 | if (k>=49) | ||
311 | break; | ||
312 | } | ||
304 | if(board[k]==MAN1 || board[k]==KING1) | 313 | if(board[k]==MAN1 || board[k]==KING1) |
305 | if(board[k+5]==FREE) return true; | 314 | if(board[((k+5) < 54) ? k+5 : 53]==FREE) return true; |
306 | 315 | ||
307 | for(k=i+6;board[k]==FREE;k+=6); | 316 | for(k=i+6;board[k]==FREE;k+=6) { |
317 | if (k>=48) | ||
318 | break; | ||
319 | } | ||
308 | if(board[k]==MAN1 || board[k]==KING1) | 320 | if(board[k]==MAN1 || board[k]==KING1) |
309 | if(board[k+6]==FREE) return true; | 321 | if(board[((k+6) < 54) ? k+6 : 53]==FREE) return true; |
310 | } | 322 | } |
311 | } | 323 | } |
312 | return false; | 324 | return false; |
313 | } | 325 | } |
314 | 326 | ||
315 | 327 | ||
316 | // Return TRUE if it is possible to capture | 328 | // Return TRUE if it is possible to capture |
317 | // Return FALSE if it is impossible to capture | 329 | // Return FALSE if it is impossible to capture |
318 | 330 | ||
319 | bool RCheckers::manCapture2(int from,int &resMax) | 331 | bool RCheckers::manCapture2(int from,int &resMax) |
320 | { | 332 | { |
321 | bool capture=false; | 333 | bool capture=false; |
322 | 334 | ||
323 | int i=from-6; | 335 | int i=from-6; |
324 | if(board[i]==MAN1 || board[i]==KING1) | 336 | if(board[i]==MAN1 || board[i]==KING1) |
325 | { | 337 | { |
326 | int k=from-12; | 338 | int k=from-12; |
327 | if(board[k]==FREE) | 339 | if(board[k]==FREE) |
328 | { | 340 | { |
329 | int save=board[i]; | 341 | int save=board[i]; |
330 | board[from]=FREE; | 342 | board[from]=FREE; |
331 | board[i]=NONE; | 343 | board[i]=NONE; |
332 | board[k]=MAN2; | 344 | board[k]=MAN2; |
333 | resMax--; | 345 | resMax--; |
334 | if(!manCapture2(k,resMax)) turn(resMax,true); | 346 | if(!manCapture2(k,resMax)) turn(resMax,true); |
335 | resMax++; | 347 | resMax++; |
336 | board[k]=FREE; | 348 | board[k]=FREE; |
337 | board[i]=save; | 349 | board[i]=save; |
338 | board[from]=MAN2; | 350 | board[from]=MAN2; |
339 | capture=true; | 351 | capture=true; |
340 | } | 352 | } |
341 | } | 353 | } |
342 | 354 | ||
343 | i=from-5; | 355 | i=from-5; |
344 | if(board[i]==MAN1 || board[i]==KING1) | 356 | if(board[i]==MAN1 || board[i]==KING1) |
345 | { | 357 | { |
346 | int k=from-10; | 358 | int k=from-10; |
347 | if(board[k]==FREE) | 359 | if(board[k]==FREE) |
348 | { | 360 | { |
349 | int save=board[i]; | 361 | int save=board[i]; |
350 | board[from]=FREE; | 362 | board[from]=FREE; |
351 | board[i]=NONE; | 363 | board[i]=NONE; |
352 | board[k]=MAN2; | 364 | board[k]=MAN2; |
353 | resMax--; | 365 | resMax--; |
354 | if(!manCapture2(k,resMax)) turn(resMax,true); | 366 | if(!manCapture2(k,resMax)) turn(resMax,true); |
355 | resMax++; | 367 | resMax++; |
356 | board[k]=FREE; | 368 | board[k]=FREE; |
357 | board[i]=save; | 369 | board[i]=save; |
358 | board[from]=MAN2; | 370 | board[from]=MAN2; |
359 | capture=true; | 371 | capture=true; |
360 | } | 372 | } |
361 | } | 373 | } |
362 | 374 | ||
363 | i=from+5; | 375 | i=from+5; |
364 | if(board[i]==MAN1 || board[i]==KING1) | 376 | if(board[i]==MAN1 || board[i]==KING1) |
365 | { | 377 | { |
366 | int k=from+10; | 378 | int k=from+10; |
367 | if(board[k]==FREE) | 379 | if(board[k]==FREE) |
368 | { | 380 | { |
369 | int save=board[i]; | 381 | int save=board[i]; |
370 | board[from]=FREE; | 382 | board[from]=FREE; |
371 | board[i]=NONE; | 383 | board[i]=NONE; |
372 | resMax--; | 384 | resMax--; |
373 | if(from>32) | 385 | if(from>32) |
374 | { | 386 | { |
375 | board[k]=KING2; | 387 | board[k]=KING2; |
376 | if(!kingCapture2(k,UL,resMax)) turn(resMax,true); | 388 | if(!kingCapture2(k,UL,resMax)) turn(resMax,true); |
377 | } | 389 | } |
378 | else | 390 | else |
379 | { | 391 | { |
380 | board[k]=MAN2; | 392 | board[k]=MAN2; |
381 | if(!manCapture2(k,resMax)) turn(resMax,true); | 393 | if(!manCapture2(k,resMax)) turn(resMax,true); |
382 | } | 394 | } |
383 | resMax++; | 395 | resMax++; |
384 | board[k]=FREE; | 396 | board[k]=FREE; |
385 | board[i]=save; | 397 | board[i]=save; |
386 | board[from]=MAN2; | 398 | board[from]=MAN2; |
387 | capture=true; | 399 | capture=true; |
388 | } | 400 | } |
389 | } | 401 | } |
390 | 402 | ||
391 | i=from+6; | 403 | i=from+6; |
392 | if(board[i]==MAN1 || board[i]==KING1) | 404 | if(board[i]==MAN1 || board[i]==KING1) |
393 | { | 405 | { |
394 | int k=from+12; | 406 | int k=from+12; |
395 | if(board[k]==FREE) | 407 | if(board[k]==FREE) |
396 | { | 408 | { |
397 | int save=board[i]; | 409 | int save=board[i]; |
398 | board[from]=FREE; | 410 | board[from]=FREE; |
399 | board[i]=NONE; | 411 | board[i]=NONE; |
400 | resMax--; | 412 | resMax--; |
401 | if(from>32) | 413 | if(from>32) |
402 | { | 414 | { |
403 | board[k]=KING2; | 415 | board[k]=KING2; |
404 | if(!kingCapture2(k,UR,resMax)) turn(resMax,true); | 416 | if(!kingCapture2(k,UR,resMax)) turn(resMax,true); |
405 | } | 417 | } |
406 | else | 418 | else |
407 | { | 419 | { |
408 | board[k]=MAN2; | 420 | board[k]=MAN2; |
409 | if(!manCapture2(k,resMax)) turn(resMax,true); | 421 | if(!manCapture2(k,resMax)) turn(resMax,true); |
410 | } | 422 | } |
411 | resMax++; | 423 | resMax++; |
412 | board[k]=FREE; | 424 | board[k]=FREE; |
413 | board[i]=save; | 425 | board[i]=save; |
414 | board[from]=MAN2; | 426 | board[from]=MAN2; |
415 | capture=true; | 427 | capture=true; |
416 | } | 428 | } |
417 | } | 429 | } |
418 | 430 | ||
419 | if(capture) return true; | 431 | if(capture) return true; |
420 | return false; | 432 | return false; |
421 | } | 433 | } |
422 | 434 | ||
423 | 435 | ||
424 | bool RCheckers::kingCapture2(int from,int direction,int &resMax) | 436 | bool RCheckers::kingCapture2(int from,int direction,int &resMax) |
425 | { | 437 | { |
426 | int i; | 438 | int i; |
427 | for(i=from+direction;board[i]==FREE;i+=direction); | 439 | for(i=from+direction;board[i]==FREE;i+=direction); |
428 | 440 | ||
429 | if(board[i]==MAN1 || board[i]==KING1) | 441 | if(board[i]==MAN1 || board[i]==KING1) |
430 | { | 442 | { |
431 | int k=i+direction; | 443 | int k=i+direction; |
432 | if(board[k]==FREE) | 444 | if(board[k]==FREE) |
433 | { | 445 | { |
434 | bool capture=false; | 446 | bool capture=false; |
435 | int save=board[i]; | 447 | int save=board[i]; |
436 | board[from]=FREE; | 448 | board[from]=FREE; |
437 | board[i]=NONE; | 449 | board[i]=NONE; |
438 | resMax--; | 450 | resMax--; |
439 | 451 | ||
440 | for(;board[k]==FREE;k+=direction) | 452 | for(;board[k]==FREE;k+=direction) |
441 | { | 453 | { |
442 | board[k]=KING2; | 454 | board[k]=KING2; |
443 | if(direction==UL || direction==DR) | 455 | if(direction==UL || direction==DR) |
444 | { | 456 | { |
445 | if(kingCapture2(k,UR,resMax)) capture=true; | 457 | if(kingCapture2(k,UR,resMax)) capture=true; |
446 | if(kingCapture2(k,DL,resMax)) capture=true; | 458 | if(kingCapture2(k,DL,resMax)) capture=true; |
447 | } | 459 | } |
448 | else | 460 | else |
449 | { | 461 | { |
450 | if(kingCapture2(k,UL,resMax)) capture=true; | 462 | if(kingCapture2(k,UL,resMax)) capture=true; |
451 | if(kingCapture2(k,DR,resMax)) capture=true; | 463 | if(kingCapture2(k,DR,resMax)) capture=true; |
452 | } | 464 | } |
453 | board[k]=FREE; | 465 | board[k]=FREE; |
454 | } | 466 | } |
455 | 467 | ||
456 | board[k-=direction]=KING2; | 468 | board[k-=direction]=KING2; |
457 | if(kingCapture2(k,direction,resMax)) capture=true; | 469 | if(kingCapture2(k,direction,resMax)) capture=true; |
458 | board[k]=FREE; | 470 | board[k]=FREE; |
459 | 471 | ||
460 | if(!capture) | 472 | if(!capture) |
461 | for(;k!=i;k-=direction) | 473 | for(;k!=i;k-=direction) |
462 | { | 474 | { |
463 | board[k]=KING2; | 475 | board[k]=KING2; |
464 | turn(resMax,true); | 476 | turn(resMax,true); |
465 | board[k]=FREE; | 477 | board[k]=FREE; |
466 | } | 478 | } |
467 | 479 | ||
468 | resMax++; | 480 | resMax++; |
469 | board[i]=save; | 481 | board[i]=save; |
470 | board[from]=KING2; | 482 | board[from]=KING2; |
471 | return true; | 483 | return true; |
472 | } | 484 | } |
473 | } | 485 | } |
474 | return false; | 486 | return false; |
475 | } | 487 | } |
476 | 488 | ||
diff --git a/noncore/settings/sysinfo/contrib/fft.c b/noncore/settings/sysinfo/contrib/fft.c index 01a1b26..60ee27d 100644 --- a/noncore/settings/sysinfo/contrib/fft.c +++ b/noncore/settings/sysinfo/contrib/fft.c | |||
@@ -1,224 +1,224 @@ | |||
1 | 1 | ||
2 | // ****************************************************************** | 2 | // ****************************************************************** |
3 | // Copyright (c) 2002- Satoshi, All Rights Reserved. | 3 | // Copyright (c) 2002- Satoshi, All Rights Reserved. |
4 | // | 4 | // |
5 | // This program is free software; you can redistribute it and/or | 5 | // This program is free software; you can redistribute it and/or |
6 | // modify it under the terms of the GNU General Public License | 6 | // modify it under the terms of the GNU General Public License |
7 | // as published by the Free Software Foundation; either version 2 | 7 | // as published by the Free Software Foundation; either version 2 |
8 | // of the License, or (at your option) any later version. | 8 | // of the License, or (at your option) any later version. |
9 | // | 9 | // |
10 | // This program is distributed in the hope that it will be useful, | 10 | // This program is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. | 13 | // GNU General Public License for more details. |
14 | // | 14 | // |
15 | // You should have received a copy of the GNU General Public License | 15 | // You should have received a copy of the GNU General Public License |
16 | // along with this program; if not, write to the Free Software | 16 | // along with this program; if not, write to the Free Software |
17 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 17 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | // | 18 | // |
19 | // | 19 | // |
20 | // Author : Satoshi ( af230533@im07.alpha-net.ne.jp ) | 20 | // Author : Satoshi ( af230533@im07.alpha-net.ne.jp ) |
21 | // ****************************************************************** | 21 | // ****************************************************************** |
22 | 22 | ||
23 | //*********************************************************************** | 23 | //*********************************************************************** |
24 | // ¹â®¥Õ¡¼¥ê¥¨ÊÑ´¹¡Ê£Æ£Æ£Ô¡Ë | 24 | // ¹â®¥Õ¡¼¥ê¥¨ÊÑ´¹¡Ê£Æ£Æ£Ô¡Ë |
25 | // ¹¹¤Ë¥¹¥Ô¡¼¥É¡¦¥¢¥Ã¥×¤¹¤ë¤Ë¤Ï£Ã£Ï£Ó¤ò¸ÇÄê¤Ç»ý¤Ä¤³¤È¡ª | 25 | // ¹¹¤Ë¥¹¥Ô¡¼¥É¡¦¥¢¥Ã¥×¤¹¤ë¤Ë¤Ï£Ã£Ï£Ó¤ò¸ÇÄê¤Ç»ý¤Ä¤³¤È¡ª |
26 | // | 26 | // |
27 | // Copyright (C) Satoshi 1994-2002 All rights reserved. | 27 | // Copyright (C) Satoshi 1994-2002 All rights reserved. |
28 | // *********************************************************************** | 28 | // *********************************************************************** |
29 | 29 | ||
30 | #include <math.h> | 30 | #include <math.h> |
31 | 31 | ||
32 | #define FFT_TEST_COUNT 500 // Bench FFT | 32 | #define FFT_TEST_COUNT 332 // Bench FFT |
33 | 33 | ||
34 | // ----------------------------------------------------- FFT | 34 | // ----------------------------------------------------- FFT |
35 | #define OBJ_DATA_COUNT 128 | 35 | #define OBJ_DATA_COUNT 128 |
36 | #define OBJ_DATA_SISU 7 // 128 = 2 ** 7 | 36 | #define OBJ_DATA_SISU 7 // 128 = 2 ** 7 |
37 | #define OBJ_DATA_SLIDE 1 | 37 | #define OBJ_DATA_SLIDE 1 |
38 | 38 | ||
39 | #define FFT_TRN 1 | 39 | #define FFT_TRN 1 |
40 | #define IFFT_TRN -1 | 40 | #define IFFT_TRN -1 |
41 | 41 | ||
42 | typedef struct _fft { | 42 | typedef struct _fft { |
43 | int N; // ¥Ç¥¸¥¿¥ë¡¦¥Ç¡¼¥¿·ï¿ô | 43 | int N; // ¥Ç¥¸¥¿¥ë¡¦¥Ç¡¼¥¿·ï¿ô |
44 | int r; // N = 2^r | 44 | int r; // N = 2^r |
45 | double* result_A; // ¥µ¥ó¥×¥ê¥ó¥°¥Ç¡¼¥¿¤ò¤³¤³¤Ë¥»¥Ã¥È¤¹¤ë | 45 | double* result_A; // ¥µ¥ó¥×¥ê¥ó¥°¥Ç¡¼¥¿¤ò¤³¤³¤Ë¥»¥Ã¥È¤¹¤ë |
46 | // cos À®Ê¬¡Äµá¤á¤ë¥¹¥Ú¥¯¥È¥ëÀ®Ê¬¤Î¿ôʬ¤ÎÎΰ褬ɬÍ× | 46 | // cos À®Ê¬¡Äµá¤á¤ë¥¹¥Ú¥¯¥È¥ëÀ®Ê¬¤Î¿ôʬ¤ÎÎΰ褬ɬÍ× |
47 | double* result_B; // sin À®Ê¬¡Äµá¤á¤ë¥¹¥Ú¥¯¥È¥ëÀ®Ê¬¤Î¿ôʬ¤ÎÎΰ褬ɬÍ× | 47 | double* result_B; // sin À®Ê¬¡Äµá¤á¤ë¥¹¥Ú¥¯¥È¥ëÀ®Ê¬¤Î¿ôʬ¤ÎÎΰ褬ɬÍ× |
48 | } FFT; | 48 | } FFT; |
49 | #define FFT_SIZE sizeof( FFT ) | 49 | #define FFT_SIZE sizeof( FFT ) |
50 | 50 | ||
51 | 51 | ||
52 | void digital_fft( FFT* fft ); | 52 | void digital_fft( FFT* fft ); |
53 | 53 | ||
54 | 54 | ||
55 | double SpectA[OBJ_DATA_COUNT]; | 55 | double SpectA[OBJ_DATA_COUNT]; |
56 | double SpectB[OBJ_DATA_COUNT]; | 56 | double SpectB[OBJ_DATA_COUNT]; |
57 | 57 | ||
58 | double TestData[] = { | 58 | double TestData[] = { |
59 | 0.998795456205172405, | 59 | 0.998795456205172405, |
60 | 0.995184726672196929, | 60 | 0.995184726672196929, |
61 | 0.146735474455360860, | 61 | 0.146735474455360860, |
62 | 0.098217140329559660, | 62 | 0.098217140329559660, |
63 | 0.980784545503230431, | 63 | 0.980784545503230431, |
64 | 0.970031253194543974, | 64 | 0.970031253194543974, |
65 | 0.956940335252408824, | 65 | 0.956940335252408824, |
66 | -0.857728610000272118, | 66 | -0.857728610000272118, |
67 | -0.831465612302545236, | 67 | -0.831465612302545236, |
68 | -0.803205431480644943, | 68 | -0.803205431480644943, |
69 | -0.774010453362736882, | 69 | -0.774010453362736882, |
70 | -0.747954125354958995, | 70 | -0.747954125354958995, |
71 | -0.707116781186547351, | 71 | -0.707116781186547351, |
72 | -0.671125754847018219, | 72 | -0.671125754847018219, |
73 | -0.634394284163645266, | 73 | -0.634394284163645266, |
74 | -0.594619304492433024, | 74 | -0.594619304492433024, |
75 | -0.555545233019601845, | 75 | -0.555545233019601845, |
76 | 0.941544045483020806, | 76 | 0.941544045483020806, |
77 | 0.923879532511286738, | 77 | 0.923879532511286738, |
78 | 0.903989293123443338, | 78 | 0.903989293123443338, |
79 | 0.881541264344545050, | 79 | 0.881541264344545050, |
80 | 0.857728610000272118, | 80 | 0.857728610000272118, |
81 | 0.831469612544545236, | 81 | 0.831469612544545236, |
82 | 0.803207531420452543, | 82 | 0.803207531420452543, |
83 | 0.773010453362736882, | 83 | 0.773010453362736882, |
84 | 0.740451125354958995, | 84 | 0.740451125354958995, |
85 | 0.707106781186547351, | 85 | 0.707106781186547351, |
86 | -0.974034153194543974, | 86 | -0.974034153194543974, |
87 | -0.956940335732208824, | 87 | -0.956940335732208824, |
88 | -0.944144065183020806, | 88 | -0.944144065183020806, |
89 | -0.923211532511286738, | 89 | -0.923211532511286738, |
90 | -0.905989293123443338, | 90 | -0.905989293123443338, |
91 | -0.881112264348355050, | 91 | -0.881112264348355050, |
92 | -0.857728610000272118, | 92 | -0.857728610000272118, |
93 | 0.671558954847018219, | 93 | 0.671558954847018219, |
94 | 0.049167674327417023, | 94 | 0.049167674327417023, |
95 | -0.001212000000001049, | 95 | -0.001212000000001049, |
96 | -0.998791456205172405, | 96 | -0.998791456205172405, |
97 | -0.995214726672196929, | 97 | -0.995214726672196929, |
98 | -0.989176509964781014, | 98 | -0.989176509964781014, |
99 | -0.980782180403230431, | 99 | -0.980782180403230431, |
100 | -0.974034153194543974, | 100 | -0.974034153194543974, |
101 | -0.956940335732208824, | 101 | -0.956940335732208824, |
102 | -0.944144065183020806, | 102 | -0.944144065183020806, |
103 | -0.923211532511286738, | 103 | -0.923211532511286738, |
104 | -0.905989293123443338, | 104 | -0.905989293123443338, |
105 | 0.803207531420452543, | 105 | 0.803207531420452543, |
106 | 0.773010453362736882, | 106 | 0.773010453362736882, |
107 | 0.740451125354958995, | 107 | 0.740451125354958995, |
108 | 0.707106781186547351, | 108 | 0.707106781186547351, |
109 | 0.671558954847018219, | 109 | 0.671558954847018219, |
110 | 0.989576509964781014, | 110 | 0.989576509964781014, |
111 | 0.980784545503230431, | 111 | 0.980784545503230431, |
112 | 0.970031253194543974, | 112 | 0.970031253194543974, |
113 | 0.654634123783645266, | 113 | 0.654634123783645266, |
114 | 0.634646284163645266, | 114 | 0.634646284163645266, |
115 | 0.595624504492433024, | 115 | 0.595624504492433024, |
116 | 0.555570245019601845, | 116 | 0.555570245019601845, |
117 | 0.514442744193221328, | 117 | 0.514442744193221328, |
118 | 0.471356736825997198, | 118 | 0.471356736825997198, |
119 | 0.424551093430281585, | 119 | 0.424551093430281585, |
120 | 0.314683432365089171, | 120 | 0.314683432365089171, |
121 | -0.881112264348355050, | 121 | -0.881112264348355050, |
122 | -0.857728610000272118, | 122 | -0.857728610000272118, |
123 | -0.831465612302545236, | 123 | -0.831465612302545236, |
124 | -0.803205431480644943, | 124 | -0.803205431480644943, |
125 | -0.774010453362736882, | 125 | -0.774010453362736882, |
126 | -0.747954125354958995, | 126 | -0.747954125354958995, |
127 | -0.707116781186547351, | 127 | -0.707116781186547351, |
128 | -0.671125754847018219, | 128 | -0.671125754847018219, |
129 | -0.634394284163645266, | 129 | -0.634394284163645266, |
130 | -0.594619304492433024, | 130 | -0.594619304492433024, |
131 | -0.555545233019601845, | 131 | -0.555545233019601845, |
132 | -0.514102744193221328, | 132 | -0.514102744193221328, |
133 | -0.477396736825997198, | 133 | -0.477396736825997198, |
134 | -0.477555093430281585, | 134 | -0.477555093430281585, |
135 | -0.387688432365089171, | 135 | -0.387688432365089171, |
136 | -0.335879853392219440, | 136 | -0.335879853392219440, |
137 | -0.295878677254461665, | 137 | -0.295878677254461665, |
138 | 0.903989293123443338, | 138 | 0.903989293123443338, |
139 | 0.881541264344545050, | 139 | 0.881541264344545050, |
140 | 0.857728610000272118, | 140 | 0.857728610000272118, |
141 | 0.831469612544545236, | 141 | 0.831469612544545236, |
142 | 0.803207531420452543, | 142 | 0.803207531420452543, |
143 | 0.773010453362736882, | 143 | 0.773010453362736882, |
144 | 0.740451125354958995, | 144 | 0.740451125354958995, |
145 | -0.242980179903263122, | 145 | -0.242980179903263122, |
146 | -0.195057822016127443, | 146 | -0.195057822016127443, |
147 | -0.146775474455360860, | 147 | -0.146775474455360860, |
148 | -0.098897540329559660, | 148 | -0.098897540329559660, |
149 | -0.042866864327417023, | 149 | -0.042866864327417023, |
150 | 0.998795456205172405, | 150 | 0.998795456205172405, |
151 | 0.995184726672196929, | 151 | 0.995184726672196929, |
152 | 0.989576509964781014, | 152 | 0.989576509964781014, |
153 | 0.980784545503230431, | 153 | 0.980784545503230431, |
154 | 0.970031253194543974, | 154 | 0.970031253194543974, |
155 | 0.956940335252408824, | 155 | 0.956940335252408824, |
156 | 0.941544045483020806, | 156 | 0.941544045483020806, |
157 | 0.923879532511286738, | 157 | 0.923879532511286738, |
158 | -0.001212000000001049, | 158 | -0.001212000000001049, |
159 | -0.998791456205172405, | 159 | -0.998791456205172405, |
160 | -0.995214726672196929, | 160 | -0.995214726672196929, |
161 | -0.989176509964781014, | 161 | -0.989176509964781014, |
162 | -0.980782180403230431, | 162 | -0.980782180403230431, |
163 | -0.974034153194543974, | 163 | -0.974034153194543974, |
164 | 0.707106781186547351, | 164 | 0.707106781186547351, |
165 | 0.671558954847018219, | 165 | 0.671558954847018219, |
166 | 0.654634123783645266, | 166 | 0.654634123783645266, |
167 | 0.634646284163645266, | 167 | 0.634646284163645266, |
168 | 0.595624504492433024, | 168 | 0.595624504492433024, |
169 | 0.555570245019601845, | 169 | 0.555570245019601845, |
170 | 0.514442744193221328, | 170 | 0.514442744193221328, |
171 | 0.471356736825997198, | 171 | 0.471356736825997198, |
172 | 0.424551093430281585, | 172 | 0.424551093430281585, |
173 | 0.314683432365089171, | 173 | 0.314683432365089171, |
174 | 0.336441853392219440, | 174 | 0.336441853392219440, |
175 | 0.290284654254461665, | 175 | 0.290284654254461665, |
176 | 0.242980479903263122, | 176 | 0.242980479903263122, |
177 | 0.195094322016127443, | 177 | 0.195094322016127443, |
178 | 0.146735474455360860, | 178 | 0.146735474455360860, |
179 | 0.098217140329559660, | 179 | 0.098217140329559660, |
180 | 0.049167674327417023, | 180 | 0.049167674327417023, |
181 | -0.956940335732208824, | 181 | -0.956940335732208824, |
182 | -0.944144065183020806, | 182 | -0.944144065183020806, |
183 | -0.923211532511286738, | 183 | -0.923211532511286738, |
184 | -0.905989293123443338, | 184 | -0.905989293123443338, |
185 | -0.881112264348355050, | 185 | -0.881112264348355050, |
186 | -0.514102744193221328, | 186 | -0.514102744193221328, |
187 | -0.477396736825997198, | 187 | -0.477396736825997198, |
188 | -0.477555093430281585, | 188 | -0.477555093430281585, |
189 | -0.387688432365089171, | 189 | -0.387688432365089171, |
190 | -0.335879853392219440, | 190 | -0.335879853392219440, |
191 | -0.295878677254461665, | 191 | -0.295878677254461665, |
192 | -0.242980179903263122, | 192 | -0.242980179903263122, |
193 | -0.195057822016127443, | 193 | -0.195057822016127443, |
194 | -0.146775474455360860, | 194 | -0.146775474455360860, |
195 | -0.098897540329559660, | 195 | -0.098897540329559660, |
196 | -0.042866864327417023, | 196 | -0.042866864327417023, |
197 | 0.998795456205172405, | 197 | 0.998795456205172405, |
198 | 0.995184726672196929, | 198 | 0.995184726672196929, |
199 | 0.989576509964781014, | 199 | 0.989576509964781014, |
200 | 0.654634123783645266, | 200 | 0.654634123783645266, |
201 | 0.634646284163645266, | 201 | 0.634646284163645266, |
202 | 0.595624504492433024, | 202 | 0.595624504492433024, |
203 | 0.555570245019601845, | 203 | 0.555570245019601845, |
204 | 0.514442744193221328, | 204 | 0.514442744193221328, |
205 | -0.001212000000001049, | 205 | -0.001212000000001049, |
206 | -0.998791456205172405, | 206 | -0.998791456205172405, |
207 | -0.995214726672196929, | 207 | -0.995214726672196929, |
208 | -0.989176509964781014, | 208 | -0.989176509964781014, |
209 | -0.980782180403230431, | 209 | -0.980782180403230431, |
210 | -0.831465612302545236, | 210 | -0.831465612302545236, |
211 | -0.803205431480644943, | 211 | -0.803205431480644943, |
212 | -0.774010453362736882, | 212 | -0.774010453362736882, |
213 | -0.747954125354958995, | 213 | -0.747954125354958995, |
214 | -0.707116781186547351, | 214 | -0.707116781186547351, |
215 | -0.671125754847018219, | 215 | -0.671125754847018219, |
216 | 0.471356736825997198, | 216 | 0.471356736825997198, |
217 | 0.424551093430281585, | 217 | 0.424551093430281585, |
218 | 0.314683432365089171, | 218 | 0.314683432365089171, |
219 | 0.336441853392219440, | 219 | 0.336441853392219440, |
220 | 0.740451125354958995, | 220 | 0.740451125354958995, |
221 | 0.707106781186547351, | 221 | 0.707106781186547351, |
222 | 0.903989293123443338, | 222 | 0.903989293123443338, |
223 | 0.471356736825997198, | 223 | 0.471356736825997198, |
224 | 0.998795456205172405, | 224 | 0.998795456205172405, |
diff --git a/noncore/styles/theme/othemebase.cpp b/noncore/styles/theme/othemebase.cpp index 4275dd6..7fb12a3 100644 --- a/noncore/styles/theme/othemebase.cpp +++ b/noncore/styles/theme/othemebase.cpp | |||
@@ -815,385 +815,385 @@ void OThemeBase::applyMiscResourceGroup( Config *config ) | |||
815 | else if ( tmpStr == "3D" ) | 815 | else if ( tmpStr == "3D" ) |
816 | arrowStyle = MotifArrow; | 816 | arrowStyle = MotifArrow; |
817 | else { | 817 | else { |
818 | if ( tmpStr != "Normal" && !tmpStr.isEmpty() ) | 818 | if ( tmpStr != "Normal" && !tmpStr.isEmpty() ) |
819 | odebug << "OThemeBase: Unrecognized arrow option " << tmpStr.ascii() | 819 | odebug << "OThemeBase: Unrecognized arrow option " << tmpStr.ascii() |
820 | << ", using Normal." << oendl; | 820 | << ", using Normal." << oendl; |
821 | arrowStyle = LargeArrow; | 821 | arrowStyle = LargeArrow; |
822 | } | 822 | } |
823 | tmpStr = config->readEntry( "ShadeStyle" ); | 823 | tmpStr = config->readEntry( "ShadeStyle" ); |
824 | if ( tmpStr == "Motif" ) | 824 | if ( tmpStr == "Motif" ) |
825 | shading = Motif; | 825 | shading = Motif; |
826 | else if ( tmpStr == "Next" ) | 826 | else if ( tmpStr == "Next" ) |
827 | shading = Next; | 827 | shading = Next; |
828 | else if ( tmpStr == "KDE" ) | 828 | else if ( tmpStr == "KDE" ) |
829 | shading = KDE; | 829 | shading = KDE; |
830 | else | 830 | else |
831 | shading = Windows; | 831 | shading = Windows; |
832 | 832 | ||
833 | defaultFrame = config->readNumEntry( "FrameWidth", 2 ); | 833 | defaultFrame = config->readNumEntry( "FrameWidth", 2 ); |
834 | cacheSize = config->readNumEntry( "Cache", 1024 ); | 834 | cacheSize = config->readNumEntry( "Cache", 1024 ); |
835 | sbExtent = config->readNumEntry( "ScrollBarExtent", 16 ); | 835 | sbExtent = config->readNumEntry( "ScrollBarExtent", 16 ); |
836 | 836 | ||
837 | config-> setGroup ( "General" ); | 837 | config-> setGroup ( "General" ); |
838 | 838 | ||
839 | if ( config-> hasKey ( "foreground" )) fgcolor = strToColor ( config-> readEntry ( "foreground" )); | 839 | if ( config-> hasKey ( "foreground" )) fgcolor = strToColor ( config-> readEntry ( "foreground" )); |
840 | if ( config-> hasKey ( "background" )) bgcolor = strToColor ( config-> readEntry ( "background" )); | 840 | if ( config-> hasKey ( "background" )) bgcolor = strToColor ( config-> readEntry ( "background" )); |
841 | if ( config-> hasKey ( "selectForeground" )) selfgcolor = strToColor ( config-> readEntry ( "selectForeground" )); | 841 | if ( config-> hasKey ( "selectForeground" )) selfgcolor = strToColor ( config-> readEntry ( "selectForeground" )); |
842 | if ( config-> hasKey ( "selectBackground" )) selbgcolor = strToColor ( config-> readEntry ( "selectBackground" )); | 842 | if ( config-> hasKey ( "selectBackground" )) selbgcolor = strToColor ( config-> readEntry ( "selectBackground" )); |
843 | if ( config-> hasKey ( "windowForeground" )) winfgcolor = strToColor ( config-> readEntry ( "windowForeground" )); | 843 | if ( config-> hasKey ( "windowForeground" )) winfgcolor = strToColor ( config-> readEntry ( "windowForeground" )); |
844 | if ( config-> hasKey ( "windowBackground" )) winbgcolor = strToColor ( config-> readEntry ( "windowBackground" )); | 844 | if ( config-> hasKey ( "windowBackground" )) winbgcolor = strToColor ( config-> readEntry ( "windowBackground" )); |
845 | } | 845 | } |
846 | 846 | ||
847 | void OThemeBase::readMiscResourceGroup() | 847 | void OThemeBase::readMiscResourceGroup() |
848 | {} | 848 | {} |
849 | 849 | ||
850 | void OThemeBase::applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames ) | 850 | void OThemeBase::applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames ) |
851 | { | 851 | { |
852 | QString tmpStr; | 852 | QString tmpStr; |
853 | 853 | ||
854 | config-> setGroup ( widgetEntries [ i ] ); | 854 | config-> setGroup ( widgetEntries [ i ] ); |
855 | 855 | ||
856 | tmpStr = config->readEntry( "CopyWidget", "" ); | 856 | tmpStr = config->readEntry( "CopyWidget", "" ); |
857 | copyfrom [ i ] = tmpStr; | 857 | copyfrom [ i ] = tmpStr; |
858 | if ( !tmpStr.isEmpty() ) | 858 | if ( !tmpStr.isEmpty() ) |
859 | return ; | 859 | return ; |
860 | 860 | ||
861 | // Scale hint | 861 | // Scale hint |
862 | tmpStr = config->readEntry( "Scale" ); | 862 | tmpStr = config->readEntry( "Scale" ); |
863 | if ( tmpStr == "Full" ) | 863 | if ( tmpStr == "Full" ) |
864 | scaleHints [ i ] = FullScale; | 864 | scaleHints [ i ] = FullScale; |
865 | else if ( tmpStr == "Horizontal" ) | 865 | else if ( tmpStr == "Horizontal" ) |
866 | scaleHints [ i ] = HorizontalScale; | 866 | scaleHints [ i ] = HorizontalScale; |
867 | else if ( tmpStr == "Vertical" ) | 867 | else if ( tmpStr == "Vertical" ) |
868 | scaleHints [ i ] = VerticalScale; | 868 | scaleHints [ i ] = VerticalScale; |
869 | else { | 869 | else { |
870 | if ( tmpStr != "Tile" && !tmpStr.isEmpty() ) | 870 | if ( tmpStr != "Tile" && !tmpStr.isEmpty() ) |
871 | odebug << "OThemeBase: Unrecognized scale option " << tmpStr.ascii() | 871 | odebug << "OThemeBase: Unrecognized scale option " << tmpStr.ascii() |
872 | << ", using Tile." << oendl; | 872 | << ", using Tile." << oendl; |
873 | scaleHints [ i ] = TileScale; | 873 | scaleHints [ i ] = TileScale; |
874 | } | 874 | } |
875 | 875 | ||
876 | 876 | ||
877 | // Gradient type | 877 | // Gradient type |
878 | tmpStr = config->readEntry( "Gradient" ); | 878 | tmpStr = config->readEntry( "Gradient" ); |
879 | if ( tmpStr == "Diagonal" ) | 879 | if ( tmpStr == "Diagonal" ) |
880 | gradients [ i ] = GrDiagonal; | 880 | gradients [ i ] = GrDiagonal; |
881 | else if ( tmpStr == "Horizontal" ) | 881 | else if ( tmpStr == "Horizontal" ) |
882 | gradients [ i ] = GrHorizontal; | 882 | gradients [ i ] = GrHorizontal; |
883 | else if ( tmpStr == "Vertical" ) | 883 | else if ( tmpStr == "Vertical" ) |
884 | gradients [ i ] = GrVertical; | 884 | gradients [ i ] = GrVertical; |
885 | else if ( tmpStr == "Pyramid" ) | 885 | else if ( tmpStr == "Pyramid" ) |
886 | gradients [ i ] = GrPyramid; | 886 | gradients [ i ] = GrPyramid; |
887 | else if ( tmpStr == "Rectangle" ) | 887 | else if ( tmpStr == "Rectangle" ) |
888 | gradients [ i ] = GrRectangle; | 888 | gradients [ i ] = GrRectangle; |
889 | else if ( tmpStr == "Elliptic" ) | 889 | else if ( tmpStr == "Elliptic" ) |
890 | gradients [ i ] = GrElliptic; | 890 | gradients [ i ] = GrElliptic; |
891 | else if ( tmpStr == "ReverseBevel" ) | 891 | else if ( tmpStr == "ReverseBevel" ) |
892 | gradients [ i ] = GrReverseBevel; | 892 | gradients [ i ] = GrReverseBevel; |
893 | else { | 893 | else { |
894 | if ( tmpStr != "None" && !tmpStr.isEmpty() ) | 894 | if ( tmpStr != "None" && !tmpStr.isEmpty() ) |
895 | odebug << "OThemeBase: Unrecognized gradient option " << tmpStr.ascii() | 895 | odebug << "OThemeBase: Unrecognized gradient option " << tmpStr.ascii() |
896 | << ", using None." << oendl; | 896 | << ", using None." << oendl; |
897 | gradients [ i ] = GrNone; | 897 | gradients [ i ] = GrNone; |
898 | } | 898 | } |
899 | 899 | ||
900 | // Blend intensity | 900 | // Blend intensity |
901 | blends[ i ] = config->readEntry( "BlendIntensity", "0.0" ).toDouble(); | 901 | blends[ i ] = config->readEntry( "BlendIntensity", "0.0" ).toDouble(); |
902 | 902 | ||
903 | // Bevel contrast | 903 | // Bevel contrast |
904 | bContrasts[ i ] = config->readNumEntry( "BevelContrast", 0 ); | 904 | bContrasts[ i ] = config->readNumEntry( "BevelContrast", 0 ); |
905 | 905 | ||
906 | // Border width | 906 | // Border width |
907 | borders [ i ] = config->readNumEntry( "Border", 1 ); | 907 | borders [ i ] = config->readNumEntry( "Border", 1 ); |
908 | 908 | ||
909 | // Highlight width | 909 | // Highlight width |
910 | highlights [ i ] = config->readNumEntry( "Highlight", 1 ); | 910 | highlights [ i ] = config->readNumEntry( "Highlight", 1 ); |
911 | 911 | ||
912 | // Gradient low color or blend background | 912 | // Gradient low color or blend background |
913 | if ( config->hasKey( "GradientLow" ) && ( gradients[ i ] != GrNone || blends[ i ] != 0.0 )) | 913 | if ( config->hasKey( "GradientLow" ) && ( gradients[ i ] != GrNone || blends[ i ] != 0.0 )) |
914 | grLowColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientLow", qApp->palette().normal().background().name() ))); | 914 | grLowColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientLow", qApp->palette().normal().background().name() ))); |
915 | else | 915 | else |
916 | grLowColors[ i ] = NULL; | 916 | grLowColors[ i ] = NULL; |
917 | 917 | ||
918 | 918 | ||
919 | // Gradient high color | 919 | // Gradient high color |
920 | if ( config->hasKey( "GradientHigh" ) && ( gradients[ i ] != GrNone )) | 920 | if ( config->hasKey( "GradientHigh" ) && ( gradients[ i ] != GrNone )) |
921 | grHighColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientHigh", qApp->palette().normal().background().name() ))); | 921 | grHighColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientHigh", qApp->palette().normal().background().name() ))); |
922 | else | 922 | else |
923 | grHighColors[ i ] = NULL; | 923 | grHighColors[ i ] = NULL; |
924 | 924 | ||
925 | // Extended color attributes | 925 | // Extended color attributes |
926 | if ( config->hasKey( "Foreground" ) || config->hasKey( "Background" ) ) { | 926 | if ( config->hasKey( "Foreground" ) || config->hasKey( "Background" ) ) { |
927 | QColor bg = strToColor( config->readEntry( "Background", qApp->palette().normal().background().name() )); | 927 | QColor bg = strToColor( config->readEntry( "Background", qApp->palette().normal().background().name() )); |
928 | QColor fg = strToColor( config->readEntry( "Foreground", qApp->palette().normal().foreground().name() )); | 928 | QColor fg = strToColor( config->readEntry( "Foreground", qApp->palette().normal().foreground().name() )); |
929 | 929 | ||
930 | colors[ i ] = makeColorGroup( fg, bg, Qt::WindowsStyle ); | 930 | colors[ i ] = makeColorGroup( fg, bg, Qt::WindowsStyle ); |
931 | } | 931 | } |
932 | else | 932 | else |
933 | colors[ i ] = NULL; | 933 | colors[ i ] = NULL; |
934 | 934 | ||
935 | // Pixmap | 935 | // Pixmap |
936 | tmpStr = config->readEntry( "Pixmap", "" ); | 936 | tmpStr = config->readEntry( "Pixmap", "" ); |
937 | pixnames[ i ] = tmpStr; | 937 | pixnames[ i ] = tmpStr; |
938 | duplicate[ i ] = false; | 938 | duplicate[ i ] = false; |
939 | pixmaps[ i ] = NULL; | 939 | pixmaps[ i ] = NULL; |
940 | images[ i ] = NULL; | 940 | images[ i ] = NULL; |
941 | 941 | ||
942 | 942 | ||
943 | // Pixmap border | 943 | // Pixmap border |
944 | tmpStr = config->readEntry( "PixmapBorder", "" ); | 944 | tmpStr = config->readEntry( "PixmapBorder", "" ); |
945 | brdnames[ i ] = tmpStr; | 945 | brdnames[ i ] = tmpStr; |
946 | pbDuplicate[ i ] = false; | 946 | pbDuplicate[ i ] = false; |
947 | pbPixmaps[ i ] = NULL; | 947 | pbPixmaps[ i ] = NULL; |
948 | pbWidth[ i ] = 0; | 948 | pbWidth[ i ] = 0; |
949 | if ( !tmpStr.isEmpty() ) { | 949 | if ( !tmpStr.isEmpty() ) { |
950 | pbWidth[ i ] = config->readNumEntry( "PixmapBWidth", 0 ); | 950 | pbWidth[ i ] = config->readNumEntry( "PixmapBWidth", 0 ); |
951 | if ( pbWidth[ i ] == 0 ) { | 951 | if ( pbWidth[ i ] == 0 ) { |
952 | odebug << "OThemeBase: No border width specified for pixmapped border widget " | 952 | odebug << "OThemeBase: No border width specified for pixmapped border widget " |
953 | << widgetEntries[ i ] << oendl; | 953 | << widgetEntries[ i ] << oendl; |
954 | odebug << "OThemeBase: Using default of 2." << oendl; | 954 | odebug << "OThemeBase: Using default of 2." << oendl; |
955 | pbWidth[ i ] = 2; | 955 | pbWidth[ i ] = 2; |
956 | } | 956 | } |
957 | } | 957 | } |
958 | 958 | ||
959 | 959 | ||
960 | // Various widget specific settings. This was more efficent when bunched | 960 | // Various widget specific settings. This was more efficent when bunched |
961 | // together in the misc group, but this makes an easier to read config. | 961 | // together in the misc group, but this makes an easier to read config. |
962 | if ( i == SliderGroove ) | 962 | if ( i == SliderGroove ) |
963 | roundedSlider = config->readBoolEntry( "SmallGroove", false ); | 963 | roundedSlider = config->readBoolEntry( "SmallGroove", false ); |
964 | else if ( i == ActiveTab ) { | 964 | else if ( i == ActiveTab ) { |
965 | aTabLine = config->readBoolEntry( "BottomLine", true ); | 965 | aTabLine = config->readBoolEntry( "BottomLine", true ); |
966 | } | 966 | } |
967 | else if ( i == InactiveTab ) { | 967 | else if ( i == InactiveTab ) { |
968 | iTabLine = config->readBoolEntry( "BottomLine", true ); | 968 | iTabLine = config->readBoolEntry( "BottomLine", true ); |
969 | } | 969 | } |
970 | else if ( i == Splitter ) | 970 | else if ( i == Splitter ) |
971 | splitterWidth = config->readNumEntry( "Width", 10 ); | 971 | splitterWidth = config->readNumEntry( "Width", 10 ); |
972 | else if ( i == ComboBox || i == ComboBoxDown ) { | 972 | else if ( i == ComboBox || i == ComboBoxDown ) { |
973 | roundedCombo = config->readBoolEntry( "Round", false ); | 973 | roundedCombo = config->readBoolEntry( "Round", false ); |
974 | } | 974 | } |
975 | else if ( i == PushButton || i == PushButtonDown ) { | 975 | else if ( i == PushButton || i == PushButtonDown ) { |
976 | btnXShift = config->readNumEntry( "XShift", 0 ); | 976 | btnXShift = config->readNumEntry( "XShift", 0 ); |
977 | btnYShift = config->readNumEntry( "YShift", 0 ); | 977 | btnYShift = config->readNumEntry( "YShift", 0 ); |
978 | focus3D = config->readBoolEntry( "3DFocusRect", false ); | 978 | focus3D = config->readBoolEntry( "3DFocusRect", false ); |
979 | focus3DOffset = config->readBoolEntry( "3DFocusOffset", 0 ); | 979 | focus3DOffset = config->readBoolEntry( "3DFocusOffset", 0 ); |
980 | roundedButton = config->readBoolEntry( "Round", false ); | 980 | roundedButton = config->readBoolEntry( "Round", false ); |
981 | } | 981 | } |
982 | } | 982 | } |
983 | 983 | ||
984 | 984 | ||
985 | void OThemeBase::readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames, | 985 | void OThemeBase::readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames, |
986 | bool *loadArray ) | 986 | bool *loadArray ) |
987 | { | 987 | { |
988 | if ( loadArray[ i ] == true ) { | 988 | if ( loadArray[ i ] == true ) { |
989 | return ; // already been preloaded. | 989 | return ; // already been preloaded. |
990 | } | 990 | } |
991 | 991 | ||
992 | int tmpVal; | 992 | int tmpVal; |
993 | QString tmpStr; | 993 | QString tmpStr; |
994 | 994 | ||
995 | tmpStr = copyfrom [ i ]; | 995 | tmpStr = copyfrom [ i ]; |
996 | if ( !tmpStr.isEmpty() ) { // Duplicate another widget's config | 996 | if ( !tmpStr.isEmpty() ) { // Duplicate another widget's config |
997 | int sIndex; | 997 | int sIndex; |
998 | loadArray[ i ] = true; | 998 | loadArray[ i ] = true; |
999 | for ( sIndex = 0; sIndex < WIDGETS; ++sIndex ) { | 999 | for ( sIndex = 0; sIndex < WIDGETS; ++sIndex ) { |
1000 | if ( tmpStr == widgetEntries[ sIndex ] ) { | 1000 | if ( tmpStr == widgetEntries[ sIndex ] ) { |
1001 | if ( !loadArray[ sIndex ] ) // hasn't been loaded yet | 1001 | if ( !loadArray[ sIndex ] ) // hasn't been loaded yet |
1002 | readResourceGroup( sIndex, copyfrom, pixnames, brdnames, | 1002 | readResourceGroup( sIndex, copyfrom, pixnames, brdnames, |
1003 | loadArray ); | 1003 | loadArray ); |
1004 | break; | 1004 | break; |
1005 | } | 1005 | } |
1006 | } | 1006 | } |
1007 | if ( loadArray[ sIndex ] ) { | 1007 | if ( sIndex < 54 && loadArray[ sIndex ] ) { |
1008 | copyWidgetConfig( sIndex, i, pixnames, brdnames ); | 1008 | copyWidgetConfig( sIndex, i, pixnames, brdnames ); |
1009 | } | 1009 | } |
1010 | else | 1010 | else |
1011 | odebug << "OThemeBase: Unable to identify source widget for " << widgetEntries[ i ] << oendl; | 1011 | odebug << "OThemeBase: Unable to identify source widget for " << widgetEntries[ i ] << oendl; |
1012 | return ; | 1012 | return ; |
1013 | } | 1013 | } |
1014 | // special inheritance for disabled arrows (these are tri-state unlike | 1014 | // special inheritance for disabled arrows (these are tri-state unlike |
1015 | // the rest of what we handle). | 1015 | // the rest of what we handle). |
1016 | for ( tmpVal = DisArrowUp; tmpVal <= DisArrowRight; ++tmpVal ) { | 1016 | for ( tmpVal = DisArrowUp; tmpVal <= DisArrowRight; ++tmpVal ) { |
1017 | if ( tmpVal == i ) { | 1017 | if ( tmpVal == i ) { |
1018 | tmpStr = pixnames [ i ]; | 1018 | tmpStr = pixnames [ i ]; |
1019 | if ( tmpStr.isEmpty() ) { | 1019 | if ( tmpStr.isEmpty() ) { |
1020 | copyWidgetConfig( ArrowUp + ( tmpVal - DisArrowUp ), i, pixnames, | 1020 | copyWidgetConfig( ArrowUp + ( tmpVal - DisArrowUp ), i, pixnames, |
1021 | brdnames ); | 1021 | brdnames ); |
1022 | return ; | 1022 | return ; |
1023 | } | 1023 | } |
1024 | } | 1024 | } |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | // Pixmap | 1027 | // Pixmap |
1028 | int existing; | 1028 | int existing; |
1029 | // Scan for duplicate pixmaps(two identical pixmaps, tile scale, no blend, | 1029 | // Scan for duplicate pixmaps(two identical pixmaps, tile scale, no blend, |
1030 | // no pixmapped border) | 1030 | // no pixmapped border) |
1031 | if ( !pixnames [ i ].isEmpty() ) { | 1031 | if ( !pixnames [ i ].isEmpty() ) { |
1032 | for ( existing = 0; existing < i; ++existing ) { | 1032 | for ( existing = 0; existing < i; ++existing ) { |
1033 | if ( pixnames[ i ] == pixnames[ existing ] && scaleHints[ i ] == TileScale && | 1033 | if ( pixnames[ i ] == pixnames[ existing ] && scaleHints[ i ] == TileScale && |
1034 | scaleHints[ existing ] == TileScale && blends[ existing ] == 0.0 && | 1034 | scaleHints[ existing ] == TileScale && blends[ existing ] == 0.0 && |
1035 | blends[ i ] == 0.0 ) { | 1035 | blends[ i ] == 0.0 ) { |
1036 | pixmaps[ i ] = pixmaps[ existing ]; | 1036 | pixmaps[ i ] = pixmaps[ existing ]; |
1037 | duplicate[ i ] = true; | 1037 | duplicate[ i ] = true; |
1038 | break; | 1038 | break; |
1039 | } | 1039 | } |
1040 | } | 1040 | } |
1041 | } | 1041 | } |
1042 | // load | 1042 | // load |
1043 | if ( !duplicate[ i ] && !pixnames[ i ].isEmpty() ) { | 1043 | if ( !duplicate[ i ] && !pixnames[ i ].isEmpty() ) { |
1044 | pixmaps[ i ] = loadPixmap( pixnames[ i ] ); | 1044 | pixmaps[ i ] = loadPixmap( pixnames[ i ] ); |
1045 | // load and save images for scaled/blended widgets for speed. | 1045 | // load and save images for scaled/blended widgets for speed. |
1046 | if ( scaleHints[ i ] == TileScale && blends[ i ] == 0.0 ) | 1046 | if ( scaleHints[ i ] == TileScale && blends[ i ] == 0.0 ) |
1047 | images[ i ] = NULL; | 1047 | images[ i ] = NULL; |
1048 | else | 1048 | else |
1049 | images[ i ] = loadImage( pixnames[ i ] ); | 1049 | images[ i ] = loadImage( pixnames[ i ] ); |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | // Pixmap border | 1052 | // Pixmap border |
1053 | if ( !brdnames [ i ]. isEmpty () ) { | 1053 | if ( !brdnames [ i ]. isEmpty () ) { |
1054 | // duplicate check | 1054 | // duplicate check |
1055 | for ( existing = 0; existing < i; ++existing ) { | 1055 | for ( existing = 0; existing < i; ++existing ) { |
1056 | if ( brdnames [i] == brdnames[ existing ] ) { | 1056 | if ( brdnames [i] == brdnames[ existing ] ) { |
1057 | pbPixmaps[ i ] = pbPixmaps[ existing ]; | 1057 | pbPixmaps[ i ] = pbPixmaps[ existing ]; |
1058 | pbDuplicate[ i ] = true; | 1058 | pbDuplicate[ i ] = true; |
1059 | break; | 1059 | break; |
1060 | } | 1060 | } |
1061 | } | 1061 | } |
1062 | } | 1062 | } |
1063 | // load | 1063 | // load |
1064 | if ( !pbDuplicate[ i ] && !brdnames[ i ].isEmpty() ) | 1064 | if ( !pbDuplicate[ i ] && !brdnames[ i ].isEmpty() ) |
1065 | pbPixmaps[ i ] = loadPixmap( brdnames[ i ] ); | 1065 | pbPixmaps[ i ] = loadPixmap( brdnames[ i ] ); |
1066 | 1066 | ||
1067 | if ( pbPixmaps[ i ] && !pbDuplicate[ i ] ) | 1067 | if ( pbPixmaps[ i ] && !pbDuplicate[ i ] ) |
1068 | generateBorderPix( i ); | 1068 | generateBorderPix( i ); |
1069 | 1069 | ||
1070 | loadArray[ i ] = true; | 1070 | loadArray[ i ] = true; |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | 1073 | ||
1074 | OThemePixmap::OThemePixmap( bool timer ) | 1074 | OThemePixmap::OThemePixmap( bool timer ) |
1075 | : QPixmap() | 1075 | : QPixmap() |
1076 | { | 1076 | { |
1077 | if(timer){ | 1077 | if(timer){ |
1078 | t = new QTime; | 1078 | t = new QTime; |
1079 | t->start(); | 1079 | t->start(); |
1080 | } | 1080 | } |
1081 | else | 1081 | else |
1082 | t = NULL; | 1082 | t = NULL; |
1083 | int i; | 1083 | int i; |
1084 | for ( i = 0; i < 8; ++i ) | 1084 | for ( i = 0; i < 8; ++i ) |
1085 | b[ i ] = NULL; | 1085 | b[ i ] = NULL; |
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | OThemePixmap::OThemePixmap( const OThemePixmap &p ) | 1088 | OThemePixmap::OThemePixmap( const OThemePixmap &p ) |
1089 | : QPixmap( p ) | 1089 | : QPixmap( p ) |
1090 | { | 1090 | { |
1091 | if(p.t){ | 1091 | if(p.t){ |
1092 | t = new QTime; | 1092 | t = new QTime; |
1093 | t->start(); | 1093 | t->start(); |
1094 | } | 1094 | } |
1095 | else | 1095 | else |
1096 | t = NULL; | 1096 | t = NULL; |
1097 | int i; | 1097 | int i; |
1098 | for ( i = 0; i < 8; ++i ) | 1098 | for ( i = 0; i < 8; ++i ) |
1099 | if ( p.b[ i ] ) | 1099 | if ( p.b[ i ] ) |
1100 | b[ i ] = new QPixmap( *p.b[ i ] ); | 1100 | b[ i ] = new QPixmap( *p.b[ i ] ); |
1101 | else | 1101 | else |
1102 | b[ i ] = NULL; | 1102 | b[ i ] = NULL; |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | 1105 | ||
1106 | 1106 | ||
1107 | OThemePixmap::~OThemePixmap() | 1107 | OThemePixmap::~OThemePixmap() |
1108 | { | 1108 | { |
1109 | if(t) | 1109 | if(t) |
1110 | delete t; | 1110 | delete t; |
1111 | int i; | 1111 | int i; |
1112 | for ( i = 0; i < 8; ++i ) | 1112 | for ( i = 0; i < 8; ++i ) |
1113 | if ( b[ i ] ) | 1113 | if ( b[ i ] ) |
1114 | delete b[ i ]; | 1114 | delete b[ i ]; |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | OThemeCache::OThemeCache( int maxSize, QObject *parent, const char *name ) | 1117 | OThemeCache::OThemeCache( int maxSize, QObject *parent, const char *name ) |
1118 | : QObject( parent, name ) | 1118 | : QObject( parent, name ) |
1119 | { | 1119 | { |
1120 | cache.setMaxCost( maxSize * 1024 ); | 1120 | cache.setMaxCost( maxSize * 1024 ); |
1121 | cache.setAutoDelete( true ); | 1121 | cache.setAutoDelete( true ); |
1122 | flushTimer.start(300000); // 5 minutes | 1122 | flushTimer.start(300000); // 5 minutes |
1123 | connect(&flushTimer, SIGNAL(timeout()), SLOT(flushTimeout())); | 1123 | connect(&flushTimer, SIGNAL(timeout()), SLOT(flushTimeout())); |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | void OThemeCache::flushTimeout() | 1126 | void OThemeCache::flushTimeout() |
1127 | { | 1127 | { |
1128 | QIntCacheIterator<OThemePixmap> it( cache ); | 1128 | QIntCacheIterator<OThemePixmap> it( cache ); |
1129 | while ( it.current() ) { | 1129 | while ( it.current() ) { |
1130 | if ( it.current() ->isOld() ) | 1130 | if ( it.current() ->isOld() ) |
1131 | cache.remove( it.currentKey() ); | 1131 | cache.remove( it.currentKey() ); |
1132 | else | 1132 | else |
1133 | ++it; | 1133 | ++it; |
1134 | } | 1134 | } |
1135 | } | 1135 | } |
1136 | 1136 | ||
1137 | OThemePixmap* OThemeCache::pixmap( int w, int h, int widgetID, bool border, | 1137 | OThemePixmap* OThemeCache::pixmap( int w, int h, int widgetID, bool border, |
1138 | bool mask ) | 1138 | bool mask ) |
1139 | { | 1139 | { |
1140 | 1140 | ||
1141 | kthemeKey key; | 1141 | kthemeKey key; |
1142 | key.cacheKey = 0; // shut up, gcc | 1142 | key.cacheKey = 0; // shut up, gcc |
1143 | key.data.id = widgetID; | 1143 | key.data.id = widgetID; |
1144 | key.data.width = w; | 1144 | key.data.width = w; |
1145 | key.data.height = h; | 1145 | key.data.height = h; |
1146 | key.data.border = border; | 1146 | key.data.border = border; |
1147 | key.data.mask = mask; | 1147 | key.data.mask = mask; |
1148 | 1148 | ||
1149 | OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); | 1149 | OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); |
1150 | if ( pix ) | 1150 | if ( pix ) |
1151 | pix->updateAccessed(); | 1151 | pix->updateAccessed(); |
1152 | return ( pix ); | 1152 | return ( pix ); |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | OThemePixmap* OThemeCache::horizontalPixmap( int w, int widgetID ) | 1155 | OThemePixmap* OThemeCache::horizontalPixmap( int w, int widgetID ) |
1156 | { | 1156 | { |
1157 | kthemeKey key; | 1157 | kthemeKey key; |
1158 | key.cacheKey = 0; // shut up, gcc | 1158 | key.cacheKey = 0; // shut up, gcc |
1159 | key.data.id = widgetID; | 1159 | key.data.id = widgetID; |
1160 | key.data.width = w; | 1160 | key.data.width = w; |
1161 | key.data.height = 0; | 1161 | key.data.height = 0; |
1162 | key.data.border = false; | 1162 | key.data.border = false; |
1163 | key.data.mask = false; | 1163 | key.data.mask = false; |
1164 | OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); | 1164 | OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); |
1165 | if ( pix ) | 1165 | if ( pix ) |
1166 | pix->updateAccessed(); | 1166 | pix->updateAccessed(); |
1167 | return ( pix ); | 1167 | return ( pix ); |
1168 | } | 1168 | } |
1169 | 1169 | ||
1170 | OThemePixmap* OThemeCache::verticalPixmap( int h, int widgetID ) | 1170 | OThemePixmap* OThemeCache::verticalPixmap( int h, int widgetID ) |
1171 | { | 1171 | { |
1172 | kthemeKey key; | 1172 | kthemeKey key; |
1173 | key.cacheKey = 0; // shut up, gcc | 1173 | key.cacheKey = 0; // shut up, gcc |
1174 | key.data.id = widgetID; | 1174 | key.data.id = widgetID; |
1175 | key.data.width = 0; | 1175 | key.data.width = 0; |
1176 | key.data.height = h; | 1176 | key.data.height = h; |
1177 | key.data.border = false; | 1177 | key.data.border = false; |
1178 | key.data.mask = false; | 1178 | key.data.mask = false; |
1179 | OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); | 1179 | OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); |
1180 | if ( pix ) | 1180 | if ( pix ) |
1181 | pix->updateAccessed(); | 1181 | pix->updateAccessed(); |
1182 | return ( pix ); | 1182 | return ( pix ); |
1183 | } | 1183 | } |
1184 | 1184 | ||
1185 | bool OThemeCache::insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID, | 1185 | bool OThemeCache::insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID, |
1186 | bool border, bool mask ) | 1186 | bool border, bool mask ) |
1187 | { | 1187 | { |
1188 | kthemeKey key; | 1188 | kthemeKey key; |
1189 | key.cacheKey = 0; // shut up, gcc | 1189 | key.cacheKey = 0; // shut up, gcc |
1190 | key.data.id = widgetID; | 1190 | key.data.id = widgetID; |
1191 | key.data.width = ( scale == FullScale || scale == HorizontalScale ) ? | 1191 | key.data.width = ( scale == FullScale || scale == HorizontalScale ) ? |
1192 | pixmap->width() : 0; | 1192 | pixmap->width() : 0; |
1193 | key.data.height = ( scale == FullScale || scale == VerticalScale ) ? | 1193 | key.data.height = ( scale == FullScale || scale == VerticalScale ) ? |
1194 | pixmap->height() : 0; | 1194 | pixmap->height() : 0; |
1195 | key.data.border = border; | 1195 | key.data.border = border; |
1196 | key.data.mask = mask; | 1196 | key.data.mask = mask; |
1197 | 1197 | ||
1198 | if ( cache.find( ( unsigned long ) key.cacheKey, true ) != NULL ) { | 1198 | if ( cache.find( ( unsigned long ) key.cacheKey, true ) != NULL ) { |
1199 | return ( true ); // a pixmap of this scale is already in there | 1199 | return ( true ); // a pixmap of this scale is already in there |