00001 #include "white_interface.h"
00002 #include "e:\AndrewWorkspace\Stratego\input.h"
00003
00042 void process_move(void);
00043
00054 void process_placing(void);
00055
00064 void process_button(void);
00065
00066
00073 int calc_x_square(int x, int square_width);
00074
00075
00083 int calc_y_square(int y, int square_height, int zero_pixel);
00084
00086 int down_x, down_y, up_x, up_y;
00087
00088
00089
00094
00095 void poin_entry_Init() {
00096 }
00097
00102
00103 void poin_entry_Run() {
00104
00105 mouse_drag input;
00106
00107 if (in_Enabled())
00108 {
00109 input = *in_Value();
00110
00111 down_x = input.down_x;
00112 down_y = input.down_y;
00113 up_x = input.up_x;
00114 up_y = input.up_y;
00115
00116
00117
00118
00119 if (down_x >= 0 && up_x >=0 && down_x < SCREEN_WIDTH && up_x < SCREEN_WIDTH)
00120 {
00121
00122 if (down_y < SCREEN_HEIGHT && up_y < SCREEN_HEIGHT &&
00123 down_y >= BOARD_PLACE_BOUNDARY && up_y >= BOARD_PLACE_BOUNDARY)
00124 {
00125 process_move();
00126 }
00127
00128
00129 if (down_y < BOARD_PLACE_BOUNDARY && down_y >= PLACE_BUTTONS_BOUNDARY &&
00130 up_y < SCREEN_HEIGHT && up_y >= BOARD_PLACE_BOUNDARY)
00131 {
00132 process_placing();
00133 }
00134
00135
00136 if (down_y < PLACE_BUTTONS_BOUNDARY && down_y >= 0 &&
00137 up_y < PLACE_BUTTONS_BOUNDARY && up_y >= 0)
00138 {
00139 process_button();
00140 }
00141 }
00142 }
00143 }
00144
00145
00146 void process_move(void)
00147 {
00148 int start_x_square, start_y_square, end_x_square, end_y_square;
00149 int square_width, square_height;
00150
00151 temp_move move;
00152
00153
00154 square_width = BOARD_WIDTH / BOARD_X_SQUARES;
00155 square_height = BOARD_HEIGHT / BOARD_Y_SQUARES;
00156
00157
00158
00159
00160 start_x_square = calc_x_square(down_x, square_width);
00161 end_x_square = calc_x_square(up_x, square_width);
00162
00163 start_y_square = calc_y_square(down_y, square_height, BOARD_PLACE_BOUNDARY);
00164 end_y_square = calc_y_square(up_y, square_height, BOARD_PLACE_BOUNDARY);
00165
00166
00167
00168
00169 if ((start_x_square != end_x_square) || (start_y_square != end_y_square))
00170 {
00171 move.start_x = start_x_square;
00172 move.start_y = start_y_square;
00173 move.end_x = end_x_square;
00174 move.end_y = end_y_square;
00175 move_out_Post(&move);
00176 }
00177 }
00178
00179
00180 void process_placing(void)
00181 {
00182 int start_x_square, start_y_square, end_x_square, end_y_square;
00183 int board_square_width, board_square_height;
00184 int place_square_width, place_square_height;
00185
00186 temp_move placing;
00187
00188
00189 board_square_width = BOARD_WIDTH / BOARD_X_SQUARES;
00190 board_square_height = BOARD_HEIGHT / BOARD_Y_SQUARES;
00191 place_square_width = PLACE_WIDTH / PLACE_X_SQUARES;
00192 place_square_height = PLACE_HEIGHT / PLACE_Y_SQUARES;
00193
00194
00195
00196 start_x_square = calc_x_square(down_x, place_square_width);
00197 end_x_square = calc_x_square(up_x, board_square_width);
00198
00199 start_y_square = calc_y_square(down_y, place_square_height, BOARD_PLACE_BOUNDARY);
00200 end_y_square = calc_y_square(up_y, board_square_height, BOARD_PLACE_BOUNDARY);
00201
00202
00203
00204 placing.start_x = start_x_square;
00205 placing.start_y = start_y_square;
00206 placing.end_x = end_x_square;
00207 placing.end_y = end_y_square;
00208 move_out_Post(&placing);
00209 }
00210
00211
00212 void process_button(void)
00213 {
00214 int down_square, up_square;
00215 int button_width;
00216
00217
00218 button_width = BUTTONS_WIDTH / NO_BUTTONS_X;
00219
00220
00221
00222 down_square = calc_x_square(down_x, button_width);
00223 up_square = calc_x_square(up_x, button_width);
00224
00225
00226
00227
00228
00229 if (down_square == up_square)
00230 button_out_Post(down_square + 1);
00231
00232 }
00233
00234
00235 int calc_x_square(int x, int square_width)
00236 {
00237 return (x / square_width);
00238 }
00239
00240
00241 int calc_y_square(int y, int square_height, int zero_pixel)
00242 {
00243 int new_y;
00244 int square;
00245
00246
00247
00248 new_y = y - zero_pixel;
00249
00250
00251 square = new_y / square_height;
00252
00253
00254
00255
00256 if (new_y < 0 && new_y % square_height != 0)
00257 square = square - 1;
00258
00259 return (square);
00260 }