Rev 25 | Rev 30 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 1 | pmbaty | 1 | // window_main.cpp | 
        
| 2 | |||
| 3 | #include "../common.h" | 
        ||
| 4 | |||
| 5 | |||
| 21 | pmbaty | 6 | // global variables used in this module only | 
        
| 7 | static wchar_t folder_path[MAX_PATH];  | 
        ||
| 8 | |||
| 9 | |||
| 1 | pmbaty | 10 | // prototypes of local functions | 
        
| 11 | static bool Button_IsHovered (guibutton_t *button, int gui_x, int gui_y);  | 
        ||
| 12 | static bool Button_UpdateHoverState (guibutton_t *button, int gui_x, int gui_y);  | 
        ||
| 13 | |||
| 14 | |||
| 15 | LRESULT CALLBACK WindowProc_Main (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)  | 
        ||
| 16 | { | 
        ||
| 17 |    // this is the main message handler for the program | 
        ||
| 18 | |||
| 19 | static wchar_t fen_string[128];  | 
        ||
| 20 | static char selectable_parts[14] = "PRNBQK kqbnrp";  | 
        ||
| 21 | static int prevgui_x = 0;  | 
        ||
| 22 | static int prevgui_y = 0;  | 
        ||
| 3 | pmbaty | 23 | static bool ctrl_pressed = false;  | 
        
| 1 | pmbaty | 24 | static bool rbutton_pushed = false;  | 
        
| 25 | |||
| 26 | unsigned short wParam_hiword;  | 
        ||
| 27 | unsigned short wParam_loword;  | 
        ||
| 28 | int prev_hovered_position[2];  | 
        ||
| 29 | player_t *current_player;  | 
        ||
| 30 | player_t *opposite_player;  | 
        ||
| 31 | player_t *local_player;  | 
        ||
| 32 | player_t *remote_player;  | 
        ||
| 33 | ccreply_t *entered_ccreply;  | 
        ||
| 34 | boardmove_t *current_move;  | 
        ||
| 35 | float board_x;  | 
        ||
| 36 | float board_y;  | 
        ||
| 37 | int gui_x;  | 
        ||
| 38 | int gui_y;  | 
        ||
| 39 | int line;  | 
        ||
| 40 | int column;  | 
        ||
| 41 | int index_line;  | 
        ||
| 42 | int index_column;  | 
        ||
| 43 | int part_index;  | 
        ||
| 44 | int part_color;  | 
        ||
| 24 | pmbaty | 45 | int viewer_index;  | 
        
| 1 | pmbaty | 46 | |
| 47 |    // filter out the commonly used message values | 
        ||
| 48 | wParam_hiword = HIWORD (wParam);  | 
        ||
| 49 | wParam_loword = LOWORD (wParam);  | 
        ||
| 50 | |||
| 51 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 52 |    // has the window just been fired up ? | 
        ||
| 53 | if (message == WM_CREATE)  | 
        ||
| 54 |    { | 
        ||
| 55 | the_scene.gui.is_entering_text = false; // we are NOT entering text yet  | 
        ||
| 56 | |||
| 57 |       // call the default window message processing function to keep things going | 
        ||
| 58 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 59 |    } | 
        ||
| 60 | |||
| 61 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 62 |    // else have we clicked on the close button ? | 
        ||
| 63 | else if (message == WM_CLOSE)  | 
        ||
| 64 |    { | 
        ||
| 65 | if (the_board.game_state == STATE_PLAYING)  | 
        ||
| 66 | DialogBox_Quit (); // if a game has started, ask for confirmation  | 
        ||
| 67 |       else | 
        ||
| 68 | is_dialogbox_quit_validated = true; // if game hasn't started yet, quit without question  | 
        ||
| 69 | |||
| 70 | return (0); // don't let Windows do the default processing on this message  | 
        ||
| 71 |    } | 
        ||
| 72 | |||
| 73 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 74 |    // else is the user closing its session OR the window is being destroyed ? | 
        ||
| 75 | else if ((message == WM_QUERYENDSESSION) || (message == WM_ENDSESSION) || (message == WM_DESTROY))  | 
        ||
| 76 | terminate_everything = true; // suicide (for some reason, PostQuitMessage() is unreliable !?)  | 
        ||
| 77 | |||
| 21 | pmbaty | 78 |    ///////////////// | 
        
| 79 |    // MENU EVENTS // | 
        ||
| 80 |    ///////////////// | 
        ||
| 81 | |||
| 82 |    /////////////// | 
        ||
| 83 |    // menu command | 
        ||
| 1 | pmbaty | 84 | else if (message == WM_COMMAND)  | 
        
| 85 |    { | 
        ||
| 86 |       // game menu, new game | 
        ||
| 87 | if (wParam_loword == MENUID_GAME_NEWGAME)  | 
        ||
| 88 |       { | 
        ||
| 89 | if ((the_board.game_state == STATE_PLAYING) && (the_board.move_count > 1))  | 
        ||
| 90 | DialogBox_Resign (); // if a game is playing, ask to resign first  | 
        ||
| 91 |          else | 
        ||
| 92 | DialogBox_NewGame (); // game not started yet, show the new game dialog box  | 
        ||
| 93 |       } | 
        ||
| 94 | |||
| 95 |       // game menu, setup start position | 
        ||
| 96 | else if (wParam_loword == MENUID_GAME_SETUPPOSITION)  | 
        ||
| 97 |       { | 
        ||
| 98 | if ((the_board.game_state == STATE_PLAYING) && (the_board.move_count > 1))  | 
        ||
| 99 | DialogBox_Resign (); // if a game is playing, ask to resign first  | 
        ||
| 100 |          else | 
        ||
| 101 |          { | 
        ||
| 102 | current_move = &the_board.moves[0]; // quick access to start move  | 
        ||
| 103 | memset (¤t_move->slots, 0, sizeof (current_move->slots)); // erase all slots  | 
        ||
| 104 | |||
| 105 | the_board.game_state = STATE_SETUPPOSITION; // game not started yet, enter board setup mode  | 
        ||
| 106 | the_board.reevaluate = true; // evaluate board again  | 
        ||
| 107 | |||
| 108 |             // display the "please choose start position" phrase in the middle of the screen | 
        ||
| 109 | Scene_SetText (&the_scene.gui.central_text, 50.0f, 50.0f, -1, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 191),  | 
        ||
| 110 | 999999.0f, true, LOCALIZE (L"SetupMode"));  | 
        ||
| 111 | the_scene.gui.partspick_selectedpart = ' '; // no selected part yet  | 
        ||
| 112 | the_scene.update = true; // and update the 3D scene  | 
        ||
| 113 |          } | 
        ||
| 114 |       } | 
        ||
| 115 | |||
| 116 |       // game menu, load game | 
        ||
| 117 | else if (wParam_loword == MENUID_GAME_LOAD)  | 
        ||
| 118 | DialogBox_Load (); // fire up the load dialog box  | 
        ||
| 119 | |||
| 120 |       // game menu, save game | 
        ||
| 121 | else if (wParam_loword == MENUID_GAME_SAVE)  | 
        ||
| 122 |       { | 
        ||
| 123 | if (save_pathname[0] != 0)  | 
        ||
| 124 | is_dialogbox_save_validated = true; // if the filename is known, save it directly  | 
        ||
| 125 |          else | 
        ||
| 126 | DialogBox_Save (); // else fire up the save dialog box  | 
        ||
| 127 |       } | 
        ||
| 128 | |||
| 129 |       // game menu, save as | 
        ||
| 130 | else if (wParam_loword == MENUID_GAME_SAVEAS)  | 
        ||
| 131 | DialogBox_Save (); // fire up the save dialog box  | 
        ||
| 132 | |||
| 133 |       // game menu, save position as | 
        ||
| 134 | else if (wParam_loword == MENUID_GAME_SAVEPOSITIONAS)  | 
        ||
| 135 | DialogBox_SavePosition (); // fire up the save position dialog box  | 
        ||
| 136 | |||
| 137 |       // game menu, resign | 
        ||
| 138 | else if (wParam_loword == MENUID_GAME_RESIGN)  | 
        ||
| 139 | DialogBox_Resign (); // if a game has started, ask for confirmation  | 
        ||
| 140 | |||
| 141 |       // game menu, statistics (stats are only available in online mode) | 
        ||
| 142 | else if (wParam_loword == MENUID_GAME_STATISTICS)  | 
        ||
| 143 |       { | 
        ||
| 144 | local_player = Player_FindByType (PLAYER_HUMAN);  | 
        ||
| 145 | if (local_player != NULL)  | 
        ||
| 146 | PlayerCard_FindOrCreate (local_player->name); // display player's own player card  | 
        ||
| 147 |       } | 
        ||
| 148 | |||
| 149 |       // game menu, options | 
        ||
| 150 | else if (wParam_loword == MENUID_GAME_OPTIONS)  | 
        ||
| 151 | DialogBox_Options (); // fire up the options dialog box  | 
        ||
| 152 | |||
| 153 |       // game menu, quit | 
        ||
| 154 | else if (wParam_loword == MENUID_GAME_QUIT)  | 
        ||
| 155 |       { | 
        ||
| 156 | if (the_board.game_state == STATE_PLAYING)  | 
        ||
| 157 | DialogBox_Quit (); // if a game has started, ask for confirmation  | 
        ||
| 158 |          else | 
        ||
| 159 | is_dialogbox_quit_validated = true; // if game hasn't started yet, quit without question  | 
        ||
| 160 |       } | 
        ||
| 161 | |||
| 162 |       // chessboard menu, suggest move | 
        ||
| 163 | else if (wParam_loword == MENUID_CHESSBOARD_SUGGESTMOVE)  | 
        ||
| 164 | the_board.players[current_viewer].wants_hint = true; // remember this player wants a hint  | 
        ||
| 165 | |||
| 166 |       // chessboard menu, cancel last move | 
        ||
| 167 | else if (wParam_loword == MENUID_CHESSBOARD_CANCELLASTMOVE)  | 
        ||
| 168 | the_board.players[current_viewer].wants_cancel = true; // remember this player wants to cancel his last move  | 
        ||
| 169 | |||
| 170 |       // chessboard menu, comment move | 
        ||
| 171 | else if (wParam_loword == MENUID_CHESSBOARD_COMMENTMOVE)  | 
        ||
| 172 | DialogBox_Comment (); // fire up the comment dialog box  | 
        ||
| 173 | |||
| 174 |       // chessboard menu, go to move | 
        ||
| 175 | else if (wParam_loword == MENUID_CHESSBOARD_GOTOMOVE)  | 
        ||
| 176 | DialogBox_GoToMove (); // fire up the go to move dialog box  | 
        ||
| 177 | |||
| 178 |       // chessboard menu, swap sides | 
        ||
| 179 | else if (wParam_loword == MENUID_CHESSBOARD_SWAPSIDES)  | 
        ||
| 180 | the_board.want_playerswap = true; // remember board sides are to be swapped  | 
        ||
| 181 | |||
| 182 |       // chessboard menu, beginning of game | 
        ||
| 183 | else if (wParam_loword == MENUID_CHESSBOARD_BEGINNINGOFGAME)  | 
        ||
| 184 |       { | 
        ||
| 185 | the_board.viewed_move = 0; // enter view mode and go to the beginning of the game  | 
        ||
| 186 | Audio_PlaySound (SOUNDTYPE_CLICK); // make a click sound  | 
        ||
| 187 | the_board.reevaluate = true; // evaluate board again  | 
        ||
| 188 |       } | 
        ||
| 189 | |||
| 190 |       // chessboard menu, previous move (only if arrow is enabled) | 
        ||
| 191 | else if ((wParam_loword == MENUID_CHESSBOARD_PREVIOUSMOVE) && (the_scene.gui.larrow.state != 0))  | 
        ||
| 192 |       { | 
        ||
| 193 | the_board.viewed_move--; // enter view mode and go back one move  | 
        ||
| 194 | Audio_PlaySound (SOUNDTYPE_CLICK); // make a click sound  | 
        ||
| 195 | the_board.reevaluate = true; // evaluate board again  | 
        ||
| 196 |       } | 
        ||
| 197 | |||
| 198 |       // chessboard menu, next move (only if arrow is enabled) | 
        ||
| 199 | else if ((wParam_loword == MENUID_CHESSBOARD_NEXTMOVE) && (the_scene.gui.rarrow.state != 0))  | 
        ||
| 200 |       { | 
        ||
| 201 | the_board.viewed_move++; // enter view mode and go forward one move  | 
        ||
| 202 | Audio_PlaySound (SOUNDTYPE_CLICK); // make a click sound  | 
        ||
| 203 | the_board.reevaluate = true; // evaluate board again  | 
        ||
| 204 |       } | 
        ||
| 205 | |||
| 206 |       // chessboard menu, current state of game | 
        ||
| 207 | else if (wParam_loword == MENUID_CHESSBOARD_CURRENTSTATEOFGAME)  | 
        ||
| 208 |       { | 
        ||
| 209 | the_board.viewed_move = the_board.move_count - 1; // enter view mode and go to the current state of the game  | 
        ||
| 210 | Audio_PlaySound (SOUNDTYPE_CLICK); // make a click sound  | 
        ||
| 211 | the_board.reevaluate = true; // evaluate board again  | 
        ||
| 212 |       } | 
        ||
| 213 | |||
| 214 |       // chessboard menu, top view | 
        ||
| 215 | else if (wParam_loword == MENUID_CHESSBOARD_TOPVIEW)  | 
        ||
| 216 |       { | 
        ||
| 24 | pmbaty | 217 |          // cycle through both players and change their view angles EXCEPT the opponent if he's human | 
        
| 218 | for (viewer_index = 0; viewer_index < 2; viewer_index++)  | 
        ||
| 219 | if ((the_board.players[viewer_index].type == PLAYER_COMPUTER)  | 
        ||
| 220 | || (the_board.players[viewer_index].type == PLAYER_INTERNET)  | 
        ||
| 221 | || (viewer_index == current_viewer))  | 
        ||
| 222 |             { | 
        ||
| 25 | pmbaty | 223 | the_board.players[viewer_index].view_pitch = 89.99f;  | 
        
| 24 | pmbaty | 224 | the_board.players[viewer_index].view_yaw = (current_viewer == COLOR_BLACK ? 90.0f : -90.0f);  | 
        
| 225 | the_board.players[viewer_index].view_distance = 58.0f;  | 
        ||
| 226 |             } | 
        ||
| 1 | pmbaty | 227 |       } | 
        
| 228 | |||
| 229 |       // chessboard menu, default view | 
        ||
| 230 | else if (wParam_loword == MENUID_CHESSBOARD_DEFAULTVIEW)  | 
        ||
| 231 |       { | 
        ||
| 24 | pmbaty | 232 |          // cycle through both players and change their view angles EXCEPT the opponent if he's human | 
        
| 233 | for (viewer_index = 0; viewer_index < 2; viewer_index++)  | 
        ||
| 234 | if ((the_board.players[viewer_index].type == PLAYER_COMPUTER)  | 
        ||
| 235 | || (the_board.players[viewer_index].type == PLAYER_INTERNET)  | 
        ||
| 236 | || (viewer_index == current_viewer))  | 
        ||
| 237 |             { | 
        ||
| 238 | the_board.players[viewer_index].view_pitch = 55.0f;  | 
        ||
| 239 | the_board.players[viewer_index].view_yaw = (current_viewer == COLOR_BLACK ? 90.0f : -90.0f);  | 
        ||
| 240 | the_board.players[viewer_index].view_distance = 70.0f;  | 
        ||
| 241 |             } | 
        ||
| 1 | pmbaty | 242 |       } | 
        
| 243 | |||
| 244 |       // chessboard menu, reset view | 
        ||
| 245 | else if (wParam_loword == MENUID_CHESSBOARD_RESETVIEW)  | 
        ||
| 246 |       { | 
        ||
| 24 | pmbaty | 247 |          // cycle through both players and change their view angles EXCEPT the opponent if he's human | 
        
| 248 | for (viewer_index = 0; viewer_index < 2; viewer_index++)  | 
        ||
| 249 | if ((the_board.players[viewer_index].type == PLAYER_COMPUTER)  | 
        ||
| 250 | || (the_board.players[viewer_index].type == PLAYER_INTERNET)  | 
        ||
| 251 | || (viewer_index == current_viewer))  | 
        ||
| 252 |             { | 
        ||
| 253 | the_board.players[viewer_index].view_pitch = the_board.players[current_viewer].custom_pitch;  | 
        ||
| 254 | the_board.players[viewer_index].view_yaw = the_board.players[current_viewer].custom_yaw;  | 
        ||
| 255 | the_board.players[viewer_index].view_distance = the_board.players[current_viewer].custom_distance;  | 
        ||
| 256 |             } | 
        ||
| 1 | pmbaty | 257 |       } | 
        
| 258 | |||
| 259 |       // chessboard menu, zoom in | 
        ||
| 260 | else if (wParam_loword == MENUID_CHESSBOARD_ZOOMIN)  | 
        ||
| 261 |       { | 
        ||
| 262 |          // scroll up & save this as the new custom distance | 
        ||
| 263 | the_board.players[current_viewer].view_distance = max (48.0f, the_board.players[current_viewer].view_distance - 2.0f);  | 
        ||
| 264 | the_board.players[current_viewer].custom_distance = the_board.players[current_viewer].view_distance;  | 
        ||
| 265 | the_scene.update = true; // update the 3D scene  | 
        ||
| 266 |       } | 
        ||
| 267 | |||
| 268 |       // chessboard menu, zoom out | 
        ||
| 269 | else if (wParam_loword == MENUID_CHESSBOARD_ZOOMOUT)  | 
        ||
| 270 |       { | 
        ||
| 271 |          // scroll down & save this as the new custom distance | 
        ||
| 272 | the_board.players[current_viewer].view_distance = min (100.0f, the_board.players[current_viewer].view_distance + 2.0f);  | 
        ||
| 273 | the_board.players[current_viewer].custom_distance = the_board.players[current_viewer].view_distance;  | 
        ||
| 274 | the_scene.update = true; // update the 3D scene  | 
        ||
| 275 |       } | 
        ||
| 276 | |||
| 277 |       // chessboard menu, change appearance | 
        ||
| 278 | else if (wParam_loword == MENUID_CHESSBOARD_CHANGEAPPEARANCE)  | 
        ||
| 279 | DialogBox_ChangeAppearance ();  | 
        ||
| 280 | |||
| 281 |       // chessboard menu, display windows desktop | 
        ||
| 282 | else if (wParam_loword == MENUID_CHESSBOARD_DISPLAYWINDOWSDESKTOP)  | 
        ||
| 283 | ShowWindow (hWnd, SW_MINIMIZE);  | 
        ||
| 284 | |||
| 285 |       // internet menu, show online players | 
        ||
| 286 | else if (wParam_loword == MENUID_INTERNET_SHOWONLINEPLAYERS)  | 
        ||
| 287 | Window_Opponents ();  | 
        ||
| 288 | |||
| 289 |       // internet menu, show sought games | 
        ||
| 290 | else if (wParam_loword == MENUID_INTERNET_SHOWSOUGHTGAMES)  | 
        ||
| 291 | Window_Sought ();  | 
        ||
| 292 | |||
| 293 |       // internet menu, seek game | 
        ||
| 294 | else if (wParam_loword == MENUID_INTERNET_SEEKGAME)  | 
        ||
| 295 | DialogBox_SendSeek ();  | 
        ||
| 296 | |||
| 297 |       // internet menu, chatter channels | 
        ||
| 298 | else if (wParam_loword == MENUID_INTERNET_CHATTERCHANNELS)  | 
        ||
| 299 | Window_ChatterChannels ();  | 
        ||
| 300 | |||
| 301 |       // internet menu, enter chat text | 
        ||
| 302 | else if (wParam_loword == MENUID_INTERNET_ENTERCHATTEXT)  | 
        ||
| 303 | PostMessage (hWnd, WM_CHAR, L' ', 0); // emulate a space bar hit  | 
        ||
| 304 | |||
| 305 |       // internet menu, display player card | 
        ||
| 306 | else if (wParam_loword == MENUID_INTERNET_DISPLAYPLAYERCARD)  | 
        ||
| 307 | DialogBox_PlayerInfoName ();  | 
        ||
| 308 | |||
| 309 |       // internet menu, display your card | 
        ||
| 310 | else if (wParam_loword == MENUID_INTERNET_DISPLAYYOURCARD)  | 
        ||
| 311 |       { | 
        ||
| 312 | local_player = Player_FindByType (PLAYER_HUMAN);  | 
        ||
| 313 | if (local_player != NULL)  | 
        ||
| 314 | PlayerCard_FindOrCreate (local_player->name); // display player's own player card  | 
        ||
| 315 |       } | 
        ||
| 316 | |||
| 317 |       // internet menu, MOTD | 
        ||
| 318 | else if (wParam_loword == MENUID_INTERNET_MOTD)  | 
        ||
| 319 | Window_MOTD ();  | 
        ||
| 320 | |||
| 321 |       // help menu, help | 
        ||
| 322 | else if (wParam_loword == MENUID_HELP_HELP)  | 
        ||
| 29 | pmbaty | 323 |       { | 
        
| 324 | swprintf_s (folder_path, WCHAR_SIZEOF (folder_path), L"Chess Giants (%s).html", os_language);  | 
        ||
| 325 | ShellExecute (NULL, L"open", folder_path, NULL, NULL, SW_MAXIMIZE); // fire up the help file  | 
        ||
| 326 |       } | 
        ||
| 1 | pmbaty | 327 | |
| 328 |       // help menu, get chess games | 
        ||
| 329 | else if (wParam_loword == MENUID_HELP_GETCHESSGAMES)  | 
        ||
| 330 | ShellExecute (NULL, L"open", L"http://www.chessgames.com", NULL, NULL, SW_MAXIMIZE); // fire up the browser  | 
        ||
| 331 | |||
| 21 | pmbaty | 332 |       // help menu, add/modify visual themes | 
        
| 333 | else if (wParam_loword == MENUID_HELP_ADDMODIFYVISUALTHEMES)  | 
        ||
| 334 |       { | 
        ||
| 335 | swprintf_s (folder_path, WCHAR_SIZEOF (folder_path), L"%s\\themes", app_path);  | 
        ||
| 336 | ShellExecute (NULL, L"open", folder_path, NULL, NULL, SW_SHOWNORMAL); // fire up Windows Explorer  | 
        ||
| 337 |       } | 
        ||
| 338 | |||
| 339 |       // help menu, add/modify translations | 
        ||
| 340 | else if (wParam_loword == MENUID_HELP_ADDMODIFYTRANSLATIONS)  | 
        ||
| 341 |       { | 
        ||
| 342 | swprintf_s (folder_path, WCHAR_SIZEOF (folder_path), L"%s\\data\\languages", app_path);  | 
        ||
| 343 | ShellExecute (NULL, L"open", folder_path, NULL, NULL, SW_SHOWNORMAL); // fire up Windows Explorer  | 
        ||
| 344 |       } | 
        ||
| 345 | |||
| 1 | pmbaty | 346 |       // help menu, about | 
        
| 347 | else if (wParam_loword == MENUID_HELP_ABOUT)  | 
        ||
| 348 | DialogBox_About (); // show the About dialog box  | 
        ||
| 349 | |||
| 350 |       // call the default window message processing function to keep things going | 
        ||
| 351 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 352 |    } | 
        ||
| 353 | |||
| 3 | pmbaty | 354 |    ///////////////////////////////////////////////////// | 
        
| 355 |    // ctrl key press or release (while not in animation) | 
        ||
| 356 | else if ((message == WM_KEYDOWN) && (wParam == VK_CONTROL) && (animation_endtime + 1.0f < current_time))  | 
        ||
| 357 |    { | 
        ||
| 358 | ctrl_pressed = true; // remember the ctrl key is pressed  | 
        ||
| 359 | |||
| 360 |       // call the default window message processing function to keep things going | 
        ||
| 361 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 362 |    } | 
        ||
| 363 | else if ((message == WM_KEYUP) && (wParam == VK_CONTROL) && (animation_endtime + 1.0f < current_time))  | 
        ||
| 364 |    { | 
        ||
| 365 | ctrl_pressed = false; // remember the ctrl key is released  | 
        ||
| 366 | rbutton_pushed = false; // remember button is released  | 
        ||
| 367 | the_scene.update = true; // update the 3D scene  | 
        ||
| 368 | |||
| 369 |       // call the default window message processing function to keep things going | 
        ||
| 370 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 371 |    } | 
        ||
| 372 | |||
| 21 | pmbaty | 373 |    ////////////////// | 
        
| 374 |    // MOUSE EVENTS // | 
        ||
| 375 |    ////////////////// | 
        ||
| 376 | |||
| 1 | pmbaty | 377 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        
| 21 | pmbaty | 378 |    // left mouse button push | 
        
| 379 | else if (message == WM_LBUTTONDOWN)  | 
        ||
| 3 | pmbaty | 380 |    { | 
        
| 21 | pmbaty | 381 |       // are we in animation OR are mouse commands NOT allowed ? | 
        
| 382 | if ((animation_endtime + 1.0f >= current_time) || (command_ignoretime >= current_time))  | 
        ||
| 383 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default message proc to keep things going  | 
        ||
| 384 | |||
| 3 | pmbaty | 385 |       // is the ctrl key pressed (emulates a right click) ? | 
        
| 386 | if (ctrl_pressed)  | 
        ||
| 387 |       { | 
        ||
| 388 | prevgui_x = GET_X_LPARAM (lParam); // remember mouse coordinates  | 
        ||
| 389 | prevgui_y = GET_Y_LPARAM (lParam);  | 
        ||
| 390 | |||
| 391 |          // if we click something, stop moving the table immediately | 
        ||
| 392 | |||
| 24 | pmbaty | 393 |          // cycle through both players and change their view angles EXCEPT the opponent if he's human | 
        
| 394 | for (viewer_index = 0; viewer_index < 2; viewer_index++)  | 
        ||
| 395 | if ((the_board.players[viewer_index].type == PLAYER_COMPUTER)  | 
        ||
| 396 | || (the_board.players[viewer_index].type == PLAYER_INTERNET)  | 
        ||
| 397 | || (viewer_index == current_viewer))  | 
        ||
| 398 |             { | 
        ||
| 399 | the_board.players[viewer_index].view_pitch = current_pitch;  | 
        ||
| 400 | the_board.players[viewer_index].view_yaw = current_yaw;  | 
        ||
| 401 |             } | 
        ||
| 402 | |||
| 3 | pmbaty | 403 | rbutton_pushed = true; // remember button is clicked  | 
        
| 404 |       } | 
        ||
| 405 | |||
| 406 |       // call the default window message processing function to keep things going | 
        ||
| 407 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 408 |    } | 
        ||
| 409 | |||
| 410 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 21 | pmbaty | 411 |    // left mouse button release | 
        
| 412 | else if (message == WM_LBUTTONUP)  | 
        ||
| 1 | pmbaty | 413 |    { | 
        
| 21 | pmbaty | 414 |       // are we in animation OR are mouse commands NOT allowed ? | 
        
| 415 | if ((animation_endtime + 1.0f >= current_time) || (command_ignoretime >= current_time))  | 
        ||
| 416 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default message proc to keep things going  | 
        ||
| 417 | |||
| 3 | pmbaty | 418 |       // is the ctrl key pressed (emulates a right click) ? | 
        
| 419 | if (ctrl_pressed)  | 
        ||
| 420 |       { | 
        ||
| 421 | rbutton_pushed = false; // remember button is released  | 
        ||
| 422 | the_scene.update = true; // update the 3D scene  | 
        ||
| 423 | |||
| 424 |          // call the default window message processing function to keep things going | 
        ||
| 425 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 426 |       } | 
        ||
| 427 | |||
| 1 | pmbaty | 428 | prevgui_x = GET_X_LPARAM (lParam); // remember mouse coordinates  | 
        
| 429 | prevgui_y = GET_Y_LPARAM (lParam);  | 
        ||
| 430 | |||
| 431 |       // get mouse coordinates | 
        ||
| 432 | gui_x = GET_X_LPARAM (lParam);  | 
        ||
| 433 | gui_y = GET_Y_LPARAM (lParam);  | 
        ||
| 434 | |||
| 435 |       // is the left arrow displayed AND is the mouse hovering it ? | 
        ||
| 436 | if ((the_scene.gui.larrow.state != 0) && Button_IsHovered (&the_scene.gui.larrow, gui_x, gui_y))  | 
        ||
| 437 | SendMessage (hWnd, WM_COMMAND, MENUID_CHESSBOARD_PREVIOUSMOVE, NULL); // send a "previous move" event  | 
        ||
| 438 | |||
| 439 |       // is the right arrow displayed AND is the mouse hovering it ? | 
        ||
| 440 | if ((the_scene.gui.rarrow.state != 0) && Button_IsHovered (&the_scene.gui.rarrow, gui_x, gui_y))  | 
        ||
| 441 | SendMessage (hWnd, WM_COMMAND, MENUID_CHESSBOARD_NEXTMOVE, NULL); // send a "next move" event  | 
        ||
| 442 | |||
| 443 |       // is the chat button displayed AND is the mouse hovering it ? | 
        ||
| 444 | if ((the_scene.gui.chatbutton.state != 0) && Button_IsHovered (&the_scene.gui.chatbutton, gui_x, gui_y))  | 
        ||
| 445 |       { | 
        ||
| 446 | opposite_player = Player_FindByType (PLAYER_INTERNET); // get a hand on the remote player  | 
        ||
| 447 | |||
| 448 |          // find or create the corresponding interlocutor structure and fire it up | 
        ||
| 449 | if (opposite_player != NULL)  | 
        ||
| 450 | Interlocutor_FindOrCreate (opposite_player->name);  | 
        ||
| 451 |       } | 
        ||
| 452 | |||
| 453 |       // is the games button displayed AND is the mouse hovering it ? | 
        ||
| 454 | if ((the_scene.gui.gamesbutton.state != 0) && Button_IsHovered (&the_scene.gui.gamesbutton, gui_x, gui_y))  | 
        ||
| 455 | Window_Sought (); // if so, display the sought games window  | 
        ||
| 456 | |||
| 457 |       // is the people button displayed AND is the mouse hovering it ? | 
        ||
| 458 | if ((the_scene.gui.peoplebutton.state != 0) && Button_IsHovered (&the_scene.gui.peoplebutton, gui_x, gui_y))  | 
        ||
| 459 | Window_Opponents (); // if so, display the opponents window  | 
        ||
| 460 | |||
| 461 |       // is the parts selection line displayed AND is the mouse anywhere near it ? | 
        ||
| 462 | if (the_scene.gui.is_partspick_displayed && Render_IsMouseInBox (gui_x, gui_y, 0.0f, 0.0f, 100.0f, 11.0f))  | 
        ||
| 463 |       { | 
        ||
| 464 |          // for each selectable part, if the mouse is on it, mark it as selected | 
        ||
| 465 | for (part_index = 0; part_index < 13; part_index++)  | 
        ||
| 466 | if (Render_IsMouseInBox (gui_x, gui_y, part_index * (100.0f / 13.0f), 0, 100.0f / 13.0f, 11.0f))  | 
        ||
| 467 |             { | 
        ||
| 468 | the_scene.gui.partspick_selectedpart = selectable_parts[part_index]; // mark it as selected  | 
        ||
| 469 | Audio_PlaySound (SOUNDTYPE_CLICK); // make a click sound  | 
        ||
| 470 | break; // no need to search further if one selection was found  | 
        ||
| 471 |             } | 
        ||
| 472 |       } | 
        ||
| 473 | |||
| 474 |       // get current player and see if we're online | 
        ||
| 475 | current_player = Player_GetCurrent ();  | 
        ||
| 476 | remote_player = Player_FindByType (PLAYER_INTERNET);  | 
        ||
| 477 | |||
| 478 |       // if we are not allowed to select anything, don't even try | 
        ||
| 479 | if ((current_player->type != PLAYER_HUMAN) || (the_board.viewed_move != the_board.move_count - 1)  | 
        ||
| 480 | || ((remote_player != NULL) && !remote_player->is_in_game))  | 
        ||
| 481 |       { | 
        ||
| 482 | the_scene.update = true; // update the 3D scene  | 
        ||
| 483 | |||
| 484 |          // call the default window message processing function to keep things going | 
        ||
| 485 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 486 |       } | 
        ||
| 487 | |||
| 488 |       // it's a single click. The user clicked on a square. | 
        ||
| 489 | |||
| 490 |       // figure out the coordinates on table | 
        ||
| 491 | Render_MouseToFloor (gui_x, gui_y, &board_x, &board_y);  | 
        ||
| 492 | |||
| 493 |       // translate them to board coordinates | 
        ||
| 494 | the_board.hovered_position[0] = (int) floor ((20.0f - board_y) / 5.0f);  | 
        ||
| 495 | the_board.hovered_position[1] = 7 - (int) floor ((20.0f - board_x) / 5.0f);  | 
        ||
| 496 | highlight_endtime = 0; // stop highlighting anything  | 
        ||
| 497 | |||
| 498 |       // if it's outside the table, end the job | 
        ||
| 499 | if (!IS_VALID_POSITION (the_board.hovered_position))  | 
        ||
| 500 |       { | 
        ||
| 501 | the_scene.update = true; // update the 3D scene  | 
        ||
| 502 | |||
| 503 |          // call the default window message processing function to keep things going | 
        ||
| 504 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 505 |       } | 
        ||
| 506 | |||
| 507 |       // we clicked a valid slot on the table | 
        ||
| 508 | |||
| 509 | current_move = &the_board.moves[the_board.viewed_move]; // quick access to current move  | 
        ||
| 510 | |||
| 511 |       /////////////////////////////////// | 
        ||
| 512 |       // are we in parts placement mode ? | 
        ||
| 513 | if (the_board.game_state == STATE_SETUPPOSITION)  | 
        ||
| 514 |       { | 
        ||
| 515 |          // quick access to line and column | 
        ||
| 516 | line = the_board.hovered_position[0];  | 
        ||
| 517 | column = the_board.hovered_position[1];  | 
        ||
| 518 | |||
| 519 |          // figure out the color of the part we are placing | 
        ||
| 520 | if (the_scene.gui.partspick_selectedpart == tolower (the_scene.gui.partspick_selectedpart))  | 
        ||
| 521 | part_color = COLOR_BLACK; // black color  | 
        ||
| 522 |          else | 
        ||
| 523 | part_color = COLOR_WHITE; // white color  | 
        ||
| 524 | |||
| 525 |          // are we erasing a king ? if so, replace it at its default location | 
        ||
| 526 | if ((current_move->slots[line][column].part == PART_KING) && (current_move->slots[line][column].color == COLOR_BLACK)  | 
        ||
| 527 | && (the_scene.gui.partspick_selectedpart != 'k'))  | 
        ||
| 528 |          { | 
        ||
| 529 |             // is it ALREADY the king's default location ? if so, give up | 
        ||
| 530 | if ((line == 7) && (column == 4))  | 
        ||
| 531 |             { | 
        ||
| 532 | Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE); // play the "illegal move" sound  | 
        ||
| 533 | return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc  | 
        ||
| 534 |             } | 
        ||
| 535 | |||
| 536 | Move_SetSlot (current_move, 7, 4, COLOR_BLACK, PART_KING); // replace black king  | 
        ||
| 537 |          } | 
        ||
| 538 | else if ((current_move->slots[line][column].part == PART_KING) && (current_move->slots[line][column].color == COLOR_WHITE)  | 
        ||
| 539 | && (the_scene.gui.partspick_selectedpart != 'K'))  | 
        ||
| 540 |          { | 
        ||
| 541 |             // is it ALREADY the king's default location ? if so, give up | 
        ||
| 542 | if ((line == 0) && (column == 4))  | 
        ||
| 543 |             { | 
        ||
| 544 | Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE); // play the "illegal move" sound  | 
        ||
| 545 | return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc  | 
        ||
| 546 |             } | 
        ||
| 547 | |||
| 548 | Move_SetSlot (current_move, 0, 4, COLOR_WHITE, PART_KING); // replace white king  | 
        ||
| 549 |          } | 
        ||
| 550 | |||
| 551 |          // place the selected part on the board | 
        ||
| 552 | if (tolower (the_scene.gui.partspick_selectedpart) == 'p')  | 
        ||
| 553 | Move_SetSlot (current_move, line, column, part_color, PART_PAWN); // pawn  | 
        ||
| 554 | else if (tolower (the_scene.gui.partspick_selectedpart) == 'r')  | 
        ||
| 555 | Move_SetSlot (current_move, line, column, part_color, PART_ROOK); // rook  | 
        ||
| 556 | else if (tolower (the_scene.gui.partspick_selectedpart) == 'n')  | 
        ||
| 557 | Move_SetSlot (current_move, line, column, part_color, PART_KNIGHT); // knight  | 
        ||
| 558 | else if (tolower (the_scene.gui.partspick_selectedpart) == 'b')  | 
        ||
| 559 | Move_SetSlot (current_move, line, column, part_color, PART_BISHOP); // bishop  | 
        ||
| 560 | else if (tolower (the_scene.gui.partspick_selectedpart) == 'q')  | 
        ||
| 561 | Move_SetSlot (current_move, line, column, part_color, PART_QUEEN); // queen  | 
        ||
| 562 | else if (tolower (the_scene.gui.partspick_selectedpart) == 'k')  | 
        ||
| 563 |          { | 
        ||
| 564 |             // parse the board for other kings of the same color and erase them | 
        ||
| 565 | for (index_line = 0; index_line < 8; index_line++)  | 
        ||
| 566 | for (index_column = 0; index_column < 8; index_column++)  | 
        ||
| 567 | if ((current_move->slots[index_line][index_column].color == part_color)  | 
        ||
| 568 | && (current_move->slots[index_line][index_column].part == PART_KING))  | 
        ||
| 569 | memset (¤t_move->slots[index_line][index_column], 0, sizeof (boardslot_t)); // erase this slot  | 
        ||
| 570 | |||
| 571 | Move_SetSlot (current_move, line, column, part_color, PART_KING); // king  | 
        ||
| 572 |          } | 
        ||
| 573 |          else | 
        ||
| 574 | Move_SetSlot (current_move, line, column, 0, PART_NONE); // no part  | 
        ||
| 575 | |||
| 576 |          // figure out which sound to play | 
        ||
| 577 | if (the_scene.gui.partspick_selectedpart != ' ')  | 
        ||
| 578 | Audio_PlaySound (SOUNDTYPE_MOVE); // play a move sound when placing a part  | 
        ||
| 579 | |||
| 580 | the_scene.update = true; // update the 3D scene  | 
        ||
| 581 | |||
| 582 |          // call the default window message processing function to keep things going | 
        ||
| 583 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 584 |       } | 
        ||
| 585 |       // end of parts placement mode | 
        ||
| 586 |       ////////////////////////////// | 
        ||
| 587 | |||
| 588 |       // does a selection NOT exist yet ? | 
        ||
| 589 | if (!IS_VALID_POSITION (the_board.selected_position))  | 
        ||
| 590 |       { | 
        ||
| 591 |          // is there a selectable part at this location ? | 
        ||
| 592 | if ((current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].part != PART_NONE)  | 
        ||
| 593 | && (current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].color == Board_ColorToMove (&the_board)))  | 
        ||
| 594 |          { | 
        ||
| 595 |             // mark the selected position as selected (and remember it) | 
        ||
| 596 | the_board.selected_position[0] = the_board.hovered_position[0];  | 
        ||
| 597 | the_board.selected_position[1] = the_board.hovered_position[1];  | 
        ||
| 598 |          } | 
        ||
| 599 | |||
| 600 | the_scene.update = true; // update the 3D scene  | 
        ||
| 601 | |||
| 602 |          // call the default window message processing function to keep things going | 
        ||
| 603 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 604 |       } | 
        ||
| 605 | |||
| 606 |       // a selection exists already | 
        ||
| 607 | |||
| 608 |       // is it the slot that was previously selected ? (i.e, user wants to "unselect" it) | 
        ||
| 609 | if ((the_board.hovered_position[0] == the_board.selected_position[0]) && (the_board.hovered_position[1] == the_board.selected_position[1]))  | 
        ||
| 610 |       { | 
        ||
| 611 |          // forget the selected position | 
        ||
| 612 | the_board.selected_position[0] = -1;  | 
        ||
| 613 | the_board.selected_position[1] = -1;  | 
        ||
| 614 | |||
| 615 | the_scene.update = true; // update the 3D scene  | 
        ||
| 616 | |||
| 617 |          // call the default window message processing function to keep things going | 
        ||
| 618 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 619 |       } | 
        ||
| 620 | |||
| 621 |       // else is it another part of the same color ? (i.e, user wants to change the part he selected) | 
        ||
| 622 | else if ((current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].part != PART_NONE)  | 
        ||
| 623 | && (current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].color == Board_ColorToMove (&the_board)))  | 
        ||
| 624 |       { | 
        ||
| 625 |          // mark the selected position as selected (and remember it) | 
        ||
| 626 | the_board.selected_position[0] = the_board.hovered_position[0];  | 
        ||
| 627 | the_board.selected_position[1] = the_board.hovered_position[1];  | 
        ||
| 628 | |||
| 629 | the_scene.update = true; // update the 3D scene  | 
        ||
| 630 | |||
| 631 |          // call the default window message processing function to keep things going | 
        ||
| 632 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 633 |       } | 
        ||
| 634 | |||
| 635 |       // else is it a possible move ? | 
        ||
| 636 | else if ((current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].flags & FLAG_POSSIBLEMOVE)  | 
        ||
| 637 | || (current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].flags & FLAG_TAKEABLE))  | 
        ||
| 638 |       { | 
        ||
| 639 |          // are we in check after the move ? (FIXME: call EP version of this func for en passant moves) | 
        ||
| 640 | if (Move_IsColorInCheckAfterTestMove (current_move, the_board.selected_position[0], the_board.selected_position[1], the_board.hovered_position[0], the_board.hovered_position[1], Board_ColorToMove (&the_board)))  | 
        ||
| 641 |          { | 
        ||
| 642 | Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE); // play the "illegal move" sound  | 
        ||
| 643 | |||
| 644 | the_scene.update = true; // update the 3D scene  | 
        ||
| 645 | |||
| 646 |             // call the default window message processing function to keep things going | 
        ||
| 647 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 648 |          } | 
        ||
| 649 | |||
| 650 |          //////////////////// | 
        ||
| 651 |          // movement is valid | 
        ||
| 652 | |||
| 653 |          // do it | 
        ||
| 654 | Board_AppendMove (&the_board, the_board.selected_position[0], the_board.selected_position[1], the_board.hovered_position[0], the_board.hovered_position[1], PART_NONE, NULL);  | 
        ||
| 655 | current_move = &the_board.moves[the_board.move_count - 1]; // update current move pointer  | 
        ||
| 656 | |||
| 657 |          // are we in internet mode ? | 
        ||
| 658 | if (remote_player != NULL)  | 
        ||
| 659 | the_board.reevaluate = false; // if so, don't reevaluate the board yet, let the server do it  | 
        ||
| 660 | |||
| 661 |          // was it a pawn being promoted ? if so, display the dialog box and wait for the reply | 
        ||
| 662 | if ((current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].part == PART_PAWN)  | 
        ||
| 663 | && ((the_board.hovered_position[0] == 0) || (the_board.hovered_position[0] == 7)))  | 
        ||
| 664 | DialogBox_PawnPromotion (); // display the pawn promotion dialog box  | 
        ||
| 665 | |||
| 666 |          // else it was a normal move | 
        ||
| 667 |          else | 
        ||
| 668 |          { | 
        ||
| 669 | Board_SetSelectedAndHovered (&the_board, -1, -1, -1, -1); // forget the hovered and selected positions  | 
        ||
| 670 | the_board.has_playerchanged = true; // and switch players  | 
        ||
| 671 |          } | 
        ||
| 672 | |||
| 673 | the_scene.update = true; // update the 3D scene  | 
        ||
| 674 | animation_endtime = current_time + ANIMATION_DURATION; // play animation now  | 
        ||
| 675 | sound_playtime = current_time + ANIMATION_DURATION - 0.1f; // play sound near the end of animation  | 
        ||
| 676 | |||
| 677 |          // call the default window message processing function to keep things going | 
        ||
| 678 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 679 |       } | 
        ||
| 680 | |||
| 681 |       // else it's another location | 
        ||
| 682 | |||
| 683 | Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE); // play the "illegal move" sound  | 
        ||
| 684 | |||
| 685 | the_scene.update = true; // update the 3D scene  | 
        ||
| 686 | |||
| 687 |       // call the default window message processing function to keep things going | 
        ||
| 688 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 689 |    } | 
        ||
| 690 | |||
| 691 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 21 | pmbaty | 692 |    // right mouse button push | 
        
| 693 | else if (message == WM_RBUTTONDOWN)  | 
        ||
| 1 | pmbaty | 694 |    { | 
        
| 21 | pmbaty | 695 |       // are we in animation OR are mouse commands NOT allowed ? | 
        
| 696 | if ((animation_endtime + 1.0f >= current_time) || (command_ignoretime >= current_time))  | 
        ||
| 697 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default message proc to keep things going  | 
        ||
| 698 | |||
| 1 | pmbaty | 699 | prevgui_x = GET_X_LPARAM (lParam); // remember mouse coordinates  | 
        
| 700 | prevgui_y = GET_Y_LPARAM (lParam);  | 
        ||
| 701 | |||
| 702 |       // if we click something, stop moving the table immediately | 
        ||
| 703 | |||
| 24 | pmbaty | 704 |       // cycle through both players and change their view angles EXCEPT the opponent if he's human | 
        
| 705 | for (viewer_index = 0; viewer_index < 2; viewer_index++)  | 
        ||
| 706 | if ((the_board.players[viewer_index].type == PLAYER_COMPUTER)  | 
        ||
| 707 | || (the_board.players[viewer_index].type == PLAYER_INTERNET)  | 
        ||
| 708 | || (viewer_index == current_viewer))  | 
        ||
| 709 |          { | 
        ||
| 710 | the_board.players[viewer_index].view_pitch = current_pitch;  | 
        ||
| 711 | the_board.players[viewer_index].view_yaw = current_yaw;  | 
        ||
| 712 |          } | 
        ||
| 713 | |||
| 1 | pmbaty | 714 | rbutton_pushed = true; // remember button is clicked  | 
        
| 715 | |||
| 716 |       // call the default window message processing function to keep things going | 
        ||
| 717 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 718 |    } | 
        ||
| 719 | |||
| 720 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 21 | pmbaty | 721 |    // right mouse button release | 
        
| 722 | else if (message == WM_RBUTTONUP)  | 
        ||
| 1 | pmbaty | 723 |    { | 
        
| 21 | pmbaty | 724 |       // are we in animation OR are mouse commands NOT allowed ? | 
        
| 725 | if ((animation_endtime + 1.0f >= current_time) || (command_ignoretime >= current_time))  | 
        ||
| 726 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default message proc to keep things going  | 
        ||
| 727 | |||
| 1 | pmbaty | 728 | rbutton_pushed = false; // remember button is released  | 
        
| 729 | the_scene.update = true; // update the 3D scene  | 
        ||
| 730 | |||
| 731 |       // call the default window message processing function to keep things going | 
        ||
| 732 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 733 |    } | 
        ||
| 734 | |||
| 21 | pmbaty | 735 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        
| 1 | pmbaty | 736 |    // left mouse button DOUBLE-click | 
        
| 21 | pmbaty | 737 | else if (message == WM_LBUTTONDBLCLK)  | 
        
| 1 | pmbaty | 738 |    { | 
        
| 21 | pmbaty | 739 |       // are we in animation OR are mouse commands NOT allowed ? | 
        
| 740 | if ((animation_endtime + 1.0f >= current_time) || (command_ignoretime >= current_time))  | 
        ||
| 741 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default message proc to keep things going  | 
        ||
| 742 | |||
| 1 | pmbaty | 743 |       // get mouse coordinates | 
        
| 744 | gui_x = GET_X_LPARAM (lParam);  | 
        ||
| 745 | gui_y = GET_Y_LPARAM (lParam);  | 
        ||
| 746 | |||
| 747 |       // are we in game and did we click the move comments area ? | 
        ||
| 748 | if ((the_board.game_state >= STATE_PLAYING) && (the_board.viewed_move > 0) && Render_IsMouseInBox (gui_x, gui_y, 10.0f, 0.0f, 80.0f, 10.0f))  | 
        ||
| 749 |       { | 
        ||
| 750 | DialogBox_Comment (); // fire up the comment dialog box  | 
        ||
| 751 | return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message processing function to keep things going  | 
        ||
| 752 |       } | 
        ||
| 21 | pmbaty | 753 | |
| 754 |       // call the default window message processing function to keep things going | 
        ||
| 755 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 1 | pmbaty | 756 |    } | 
        
| 757 | |||
| 758 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 759 |    // mouse move (while not in animation) | 
        ||
| 21 | pmbaty | 760 | else if (message == WM_MOUSEMOVE)  | 
        
| 1 | pmbaty | 761 |    { | 
        
| 21 | pmbaty | 762 |       // are we in animation OR are mouse commands NOT allowed ? | 
        
| 763 | if ((animation_endtime + 1.0f >= current_time) || (command_ignoretime >= current_time))  | 
        ||
| 764 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default message proc to keep things going  | 
        ||
| 765 | |||
| 1 | pmbaty | 766 |       // get mouse coordinates | 
        
| 767 | gui_x = GET_X_LPARAM (lParam);  | 
        ||
| 768 | gui_y = GET_Y_LPARAM (lParam);  | 
        ||
| 769 | |||
| 770 |       // handle button update status | 
        ||
| 771 | the_scene.update |= Button_UpdateHoverState (&the_scene.gui.larrow, gui_x, gui_y);  | 
        ||
| 772 | the_scene.update |= Button_UpdateHoverState (&the_scene.gui.rarrow, gui_x, gui_y);  | 
        ||
| 773 | the_scene.update |= Button_UpdateHoverState (&the_scene.gui.chatbutton, gui_x, gui_y);  | 
        ||
| 774 | the_scene.update |= Button_UpdateHoverState (&the_scene.gui.gamesbutton, gui_x, gui_y);  | 
        ||
| 775 | the_scene.update |= Button_UpdateHoverState (&the_scene.gui.peoplebutton, gui_x, gui_y);  | 
        ||
| 776 | |||
| 777 |       // see if we're online | 
        ||
| 778 | remote_player = Player_FindByType (PLAYER_INTERNET);  | 
        ||
| 779 | |||
| 780 |       // are we online AND do we NOT have the right to select anything ? | 
        ||
| 781 | if ((remote_player != NULL) && !remote_player->is_in_game)  | 
        ||
| 782 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default window message processing function to keep things going  | 
        ||
| 783 | |||
| 784 |       // is the parts selection line displayed AND is the mouse anywhere in it ? | 
        ||
| 785 | if (the_scene.gui.is_partspick_displayed && Render_IsMouseInBox (gui_x, gui_y, 0.0f, 0.0f, 100.0f, 11.0f))  | 
        ||
| 786 |       { | 
        ||
| 787 |          // for each selectable part... | 
        ||
| 788 | for (part_index = 0; part_index < 13; part_index++)  | 
        ||
| 789 |          { | 
        ||
| 790 |             // is the mouse hovering it ? | 
        ||
| 791 | if (Render_IsMouseInBox (gui_x, gui_y, part_index * (100.0f / 13.0f), 0, 100.0f / 13.0f, 11.0f))  | 
        ||
| 792 |             { | 
        ||
| 793 |                // was it NOT hovered before ? | 
        ||
| 794 | if (the_scene.gui.partspick_hoveredpart != selectable_parts[part_index])  | 
        ||
| 795 |                { | 
        ||
| 796 | the_scene.gui.partspick_hoveredpart = selectable_parts[part_index]; // mark it as hovered  | 
        ||
| 797 | the_scene.update = true; // update the scene  | 
        ||
| 798 |                } | 
        ||
| 799 |             } | 
        ||
| 800 | |||
| 801 |             // else was it hovered before ? | 
        ||
| 802 | else if (the_scene.gui.partspick_hoveredpart == selectable_parts[part_index])  | 
        ||
| 803 |             { | 
        ||
| 804 | the_scene.gui.partspick_hoveredpart = 0; // clear the hovered part  | 
        ||
| 805 | the_scene.update = true; // update the scene  | 
        ||
| 806 |             } | 
        ||
| 807 |          } | 
        ||
| 808 |       } | 
        ||
| 809 |       else | 
        ||
| 810 | the_scene.gui.partspick_hoveredpart = 0; // clear the hovered part  | 
        ||
| 811 | |||
| 812 |       // get current and opposite players | 
        ||
| 813 | current_player = Player_GetCurrent ();  | 
        ||
| 814 | opposite_player = Player_GetOpposite ();  | 
        ||
| 815 | |||
| 816 |       // if right button was clicked, compute new pitch and yaw | 
        ||
| 817 | if (rbutton_pushed)  | 
        ||
| 818 |       { | 
        ||
| 24 | pmbaty | 819 |          // cycle through both players and change their view angles EXCEPT the opponent if he's human | 
        
| 820 | for (viewer_index = 0; viewer_index < 2; viewer_index++)  | 
        ||
| 821 | if ((the_board.players[viewer_index].type == PLAYER_COMPUTER)  | 
        ||
| 822 | || (the_board.players[viewer_index].type == PLAYER_INTERNET)  | 
        ||
| 823 | || (viewer_index == current_viewer))  | 
        ||
| 824 |             { | 
        ||
| 825 | the_board.players[viewer_index].view_pitch += (gui_y - prevgui_y) * 0.3f;  | 
        ||
| 826 | if (the_board.players[viewer_index].view_pitch < 10.0f)  | 
        ||
| 827 | the_board.players[viewer_index].view_pitch = 10.0f; // wrap angles around so that they  | 
        ||
| 25 | pmbaty | 828 | if (the_board.players[viewer_index].view_pitch > 89.99f)  | 
        
| 829 | the_board.players[viewer_index].view_pitch = 89.99f; // stay in the [10, 89.99] bounds  | 
        ||
| 1 | pmbaty | 830 | |
| 24 | pmbaty | 831 | the_board.players[viewer_index].view_yaw += (gui_x - prevgui_x) * 0.3f;  | 
        
| 832 | the_board.players[viewer_index].view_yaw = WrapAngle (the_board.players[viewer_index].view_yaw);  | 
        ||
| 1 | pmbaty | 833 | |
| 24 | pmbaty | 834 |                // save these as the new custom angles | 
        
| 835 | the_board.players[viewer_index].custom_pitch = the_board.players[viewer_index].view_pitch;  | 
        ||
| 836 | the_board.players[viewer_index].custom_yaw = the_board.players[viewer_index].view_yaw;  | 
        ||
| 1 | pmbaty | 837 | |
| 24 | pmbaty | 838 |                // when moving the table around, jump to ideal angles immediately | 
        
| 839 | current_pitch = the_board.players[viewer_index].view_pitch;  | 
        ||
| 840 | current_yaw = the_board.players[viewer_index].view_yaw;  | 
        ||
| 841 |             } | 
        ||
| 1 | pmbaty | 842 | |
| 843 | the_scene.update = true; // button was clicked, update the 3D scene  | 
        ||
| 844 |       } | 
        ||
| 845 | |||
| 846 |       // else it's just the mouse wandering around ; have we the right to select something ? | 
        ||
| 847 | else if ((the_board.viewed_move == the_board.move_count - 1) && (current_player->type == PLAYER_HUMAN) && (highlight_endtime < current_time))  | 
        ||
| 848 |       { | 
        ||
| 849 |          // save the old positions | 
        ||
| 850 | prev_hovered_position[0] = the_board.hovered_position[0];  | 
        ||
| 851 | prev_hovered_position[1] = the_board.hovered_position[1];  | 
        ||
| 852 | |||
| 853 |          // figure out the coordinates on table | 
        ||
| 854 | Render_MouseToFloor (gui_x, gui_y, &board_x, &board_y);  | 
        ||
| 855 | |||
| 856 |          // translate them to board coordinates | 
        ||
| 857 | the_board.hovered_position[0] = (int) floor ((20.0f - board_y) / 5.0f);  | 
        ||
| 858 | the_board.hovered_position[1] = 7 - (int) floor ((20.0f - board_x) / 5.0f);  | 
        ||
| 859 | |||
| 860 |          // do they differ from last time ? | 
        ||
| 861 | if ((the_board.hovered_position[0] != prev_hovered_position[0]) || (the_board.hovered_position[1] != prev_hovered_position[1]))  | 
        ||
| 862 | the_scene.update = true; // if so, update scene  | 
        ||
| 863 |       } | 
        ||
| 864 | |||
| 865 |       // has the user the right to leave a command AND is there no comment yet ? | 
        ||
| 866 | if ((the_board.game_state >= STATE_PLAYING) && (the_board.viewed_move > 0)  | 
        ||
| 867 | && ((the_board.moves[the_board.viewed_move].comment == NULL) || (the_board.moves[the_board.viewed_move].comment[0] == 0)))  | 
        ||
| 868 |       { | 
        ||
| 869 |          // is the mouse above the comments zone ? if so, display a dimmed hint text | 
        ||
| 870 | if (Render_IsMouseInBox (gui_x, gui_y, 30.0f, 0.0f, 40.0f, 10.0f))  | 
        ||
| 871 |          { | 
        ||
| 872 | if (!the_scene.gui.comment_text.is_displayed)  | 
        ||
| 873 |             { | 
        ||
| 874 | Scene_SetText (&the_scene.gui.comment_text, 50.0f, 5.0f, 40.0f, ALIGN_CENTER, ALIGN_CENTER, ALIGN_LEFT, chat_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 127), 999999.0f, false, LOCALIZE (L"DoubleClickToEnterComment"));  | 
        ||
| 875 | the_scene.update = true; // and update the scene  | 
        ||
| 876 |             } | 
        ||
| 877 |          } | 
        ||
| 878 |          else | 
        ||
| 879 |          { | 
        ||
| 880 | if (the_scene.gui.comment_text.is_displayed)  | 
        ||
| 881 |             { | 
        ||
| 882 | the_scene.gui.comment_text.is_displayed = false; // if not, erase the hint text  | 
        ||
| 883 | the_scene.update = true; // and update the scene  | 
        ||
| 884 |             } | 
        ||
| 885 |          } | 
        ||
| 886 |       } | 
        ||
| 887 | |||
| 888 |       // remember these coordinates for next time | 
        ||
| 889 | prevgui_x = gui_x;  | 
        ||
| 890 | prevgui_y = gui_y;  | 
        ||
| 891 | |||
| 892 |       // call the default window message processing function to keep things going | 
        ||
| 893 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 894 |    } | 
        ||
| 895 | |||
| 896 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 21 | pmbaty | 897 |    // mouse scroll | 
        
| 898 | else if (message == WM_MOUSEWHEEL)  | 
        ||
| 1 | pmbaty | 899 |    { | 
        
| 21 | pmbaty | 900 |       // are we in animation OR are mouse commands NOT allowed ? | 
        
| 901 | if ((animation_endtime + 1.0f >= current_time) || (command_ignoretime >= current_time))  | 
        ||
| 902 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default message proc to keep things going  | 
        ||
| 903 | |||
| 1 | pmbaty | 904 |       // see if we're online | 
        
| 905 | remote_player = Player_FindByType (PLAYER_INTERNET);  | 
        ||
| 906 | |||
| 907 |       // are we online AND do we NOT have the right to select anything ? | 
        ||
| 908 | if ((remote_player != NULL) && !remote_player->is_in_game)  | 
        ||
| 909 | return (DefWindowProc (hWnd, message, wParam, lParam)); // if so, call the default window message processing function to keep things going  | 
        ||
| 910 | |||
| 911 |       // scroll up / scroll down ? | 
        ||
| 912 | if (GET_WHEEL_DELTA_WPARAM (wParam) > 0)  | 
        ||
| 913 | the_board.players[current_viewer].view_distance = max (48.0f, the_board.players[current_viewer].view_distance - 2.0f);  | 
        ||
| 914 | else if (GET_WHEEL_DELTA_WPARAM (wParam) < 0)  | 
        ||
| 915 | the_board.players[current_viewer].view_distance = min (100.0f, the_board.players[current_viewer].view_distance + 2.0f);  | 
        ||
| 916 | |||
| 917 |       // save this as the new custom distance | 
        ||
| 918 | the_board.players[current_viewer].custom_distance = the_board.players[current_viewer].view_distance;  | 
        ||
| 919 | |||
| 920 |       // when moving the table around, jump to ideal angles immediately | 
        ||
| 921 | current_distance = the_board.players[current_viewer].view_distance;  | 
        ||
| 922 | |||
| 923 | the_scene.update = true; // update the 3D scene  | 
        ||
| 924 | |||
| 925 |       // call the default window message processing function to keep things going | 
        ||
| 926 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 927 |    } | 
        ||
| 928 | |||
| 929 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 930 |    // keyboard release | 
        ||
| 931 | else if (message == WM_CHAR)  | 
        ||
| 932 |    { | 
        ||
| 933 |       // are we in position setup mode ? | 
        ||
| 934 | if (the_board.game_state == STATE_SETUPPOSITION)  | 
        ||
| 935 |       { | 
        ||
| 936 |          // is it the enter key ? if so, exit setup mode and start playing | 
        ||
| 937 | if (wParam == L'\r')  | 
        ||
| 938 |          { | 
        ||
| 939 | current_move = &the_board.moves[the_board.viewed_move]; // quick access to current move  | 
        ||
| 940 | |||
| 941 |             // (in)validate the castling positions | 
        ||
| 942 | if ((current_move->slots[0][0].color == COLOR_WHITE) && (current_move->slots[0][0].part == PART_ROOK)  | 
        ||
| 943 | && (current_move->slots[0][4].color == COLOR_WHITE) && (current_move->slots[0][4].part == PART_KING))  | 
        ||
| 944 | current_move->sides[COLOR_WHITE].longcastle_allowed = true; // white castling queenside allowed  | 
        ||
| 945 |             else | 
        ||
| 946 | current_move->sides[COLOR_WHITE].longcastle_allowed = false; // white castling queenside no longer possible  | 
        ||
| 947 | if ((current_move->slots[0][7].color == COLOR_WHITE) && (current_move->slots[0][7].part == PART_ROOK)  | 
        ||
| 948 | && (current_move->slots[0][4].color == COLOR_WHITE) && (current_move->slots[0][4].part == PART_KING))  | 
        ||
| 949 | current_move->sides[COLOR_WHITE].shortcastle_allowed = true; // white castling kingside allowed  | 
        ||
| 950 |             else | 
        ||
| 951 | current_move->sides[COLOR_WHITE].shortcastle_allowed = false; // white castling kingside no longer possible  | 
        ||
| 952 | if ((current_move->slots[7][0].color == COLOR_BLACK) && (current_move->slots[7][0].part == PART_ROOK)  | 
        ||
| 953 | && (current_move->slots[7][4].color == COLOR_BLACK) && (current_move->slots[7][4].part == PART_KING))  | 
        ||
| 954 | current_move->sides[COLOR_BLACK].longcastle_allowed = true; // white castling queenside allowed  | 
        ||
| 955 |             else | 
        ||
| 956 | current_move->sides[COLOR_BLACK].longcastle_allowed = false; // white castling queenside no longer possible  | 
        ||
| 957 | if ((current_move->slots[7][7].color == COLOR_BLACK) && (current_move->slots[7][7].part == PART_ROOK)  | 
        ||
| 958 | && (current_move->slots[7][4].color == COLOR_BLACK) && (current_move->slots[7][4].part == PART_KING))  | 
        ||
| 959 | current_move->sides[COLOR_BLACK].shortcastle_allowed = true; // white castling kingside allowed  | 
        ||
| 960 |             else | 
        ||
| 961 | current_move->sides[COLOR_BLACK].shortcastle_allowed = false; // white castling kingside no longer possible  | 
        ||
| 962 | |||
| 963 | current_move->color = COLOR_BLACK; // so that game starts with white  | 
        ||
| 964 | |||
| 965 |             // validate this board in Forsyth-Edwards Notation and reset it | 
        ||
| 966 | Move_DescribeInFEN (current_move);  | 
        ||
| 967 | wcscpy_s (fen_string, WCHAR_SIZEOF (fen_string), current_move->fen_string); // have a copy of fen string  | 
        ||
| 968 | Board_Reset (&the_board, fen_string);  | 
        ||
| 969 | |||
| 970 | the_board.game_state = STATE_PLAYING; // start the game now  | 
        ||
| 971 | the_board.reevaluate = true; // evaluate board again  | 
        ||
| 972 | |||
| 973 | the_scene.gui.central_text.disappear_time = current_time + 1.0f; // fade out help text now (FIXME: ugly)  | 
        ||
| 974 | the_scene.update = true; // update the 3D scene  | 
        ||
| 975 | |||
| 976 |             // call the default window message processing function to keep things going | 
        ||
| 977 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 978 |          } | 
        ||
| 979 |       } | 
        ||
| 980 | |||
| 981 |       // else are we in internet mode ? | 
        ||
| 982 | else if (Player_FindByType (PLAYER_INTERNET) != NULL)  | 
        ||
| 983 |       { | 
        ||
| 984 | entered_ccreply = &the_scene.gui.entered_ccreply; // quick access to entered ccreply  | 
        ||
| 985 | local_player = Player_FindByType (PLAYER_HUMAN); // quick access to local player  | 
        ||
| 986 | if (local_player == NULL)  | 
        ||
| 987 | return (DefWindowProc (hWnd, message, wParam, lParam)); // theoretically impossible condition, but better be sure  | 
        ||
| 988 | if (selected_chatterchannel == NULL)  | 
        ||
| 989 | return (DefWindowProc (hWnd, message, wParam, lParam)); // theoretically impossible condition, but better be sure  | 
        ||
| 990 | |||
| 991 |          // are we NOT entering text yet ? | 
        ||
| 992 | if (!the_scene.gui.is_entering_text)  | 
        ||
| 993 |          { | 
        ||
| 994 |             // is it the space bar ? | 
        ||
| 995 | if (wParam == L' ')  | 
        ||
| 996 |             { | 
        ||
| 997 | the_scene.gui.is_entering_text = true; // remember we are entering text  | 
        ||
| 998 | |||
| 999 |                // reset the entered text buffer | 
        ||
| 1000 | entered_ccreply->text = (wchar_t *) SAFE_malloc (1, sizeof (wchar_t), false);  | 
        ||
| 1001 | entered_ccreply->text[0] = 0; // only the null terminator will fit  | 
        ||
| 1002 | entered_ccreply->text_length = 0; // and set its length to zero  | 
        ||
| 1003 |             } | 
        ||
| 1004 |          } | 
        ||
| 1005 | |||
| 1006 |          // else we are currently in text entering mode | 
        ||
| 1007 |          else | 
        ||
| 1008 |          { | 
        ||
| 1009 |             // is the typed character a printable character ? | 
        ||
| 1010 | if (iswprint (wParam))  | 
        ||
| 1011 |             { | 
        ||
| 1012 |                // if so, reallocate space in the typed buffer (include null terminator) | 
        ||
| 1013 | entered_ccreply->text = (wchar_t *) SAFE_realloc (entered_ccreply->text, entered_ccreply->text_length + 1, entered_ccreply->text_length + 1 + 1, sizeof (wchar_t), false);  | 
        ||
| 1014 | swprintf_s (&entered_ccreply->text[entered_ccreply->text_length], 1 + 1, L"%c", wParam); // append character  | 
        ||
| 1015 | entered_ccreply->text_length++; // buffer holds now one character more  | 
        ||
| 1016 |             } | 
        ||
| 1017 | |||
| 1018 |             // else is the typed character a backspace AND is there text to erase ? | 
        ||
| 1019 | else if ((wParam == 0x08) && (entered_ccreply->text_length > 0))  | 
        ||
| 1020 |             { | 
        ||
| 1021 |                // if so, reallocate space in the typed buffer (include null terminator) | 
        ||
| 1022 | entered_ccreply->text = (wchar_t *) SAFE_realloc (entered_ccreply->text, entered_ccreply->text_length + 1, entered_ccreply->text_length + 1 - 1, sizeof (wchar_t), false);  | 
        ||
| 1023 | entered_ccreply->text[entered_ccreply->text_length - 1] = 0; // backspace, delete one character  | 
        ||
| 1024 | entered_ccreply->text_length--; // buffer holds now one character less  | 
        ||
| 1025 |             } | 
        ||
| 1026 | |||
| 1027 |             // else is the typed character the escape key ? | 
        ||
| 1028 | else if (wParam == 0x1b)  | 
        ||
| 1029 |             { | 
        ||
| 1030 | SAFE_free ((void **) &entered_ccreply->text); // reset the entered text buffer  | 
        ||
| 1031 | entered_ccreply->text_length = 0; // and set its length to zero  | 
        ||
| 1032 | the_scene.gui.is_entering_text = false; // and exit from the text entering mode  | 
        ||
| 1033 |             } | 
        ||
| 1034 | |||
| 1035 |             // else is the typed character the enter key ? | 
        ||
| 1036 | else if (wParam == 0x0d)  | 
        ||
| 1037 | the_scene.gui.is_entering_text = false; // enter, exit from the text entering mode (this will validate our reply)  | 
        ||
| 1038 | |||
| 1039 |             // else it's an illegal character | 
        ||
| 1040 |             else | 
        ||
| 1041 | Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE); // illegal character, beep the illegal move sound  | 
        ||
| 1042 |          } | 
        ||
| 1043 | |||
| 1044 | the_scene.update = true; // update the 3D scene  | 
        ||
| 1045 | |||
| 1046 |          // call the default window message processing function to keep things going | 
        ||
| 1047 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 1048 |       } | 
        ||
| 1049 |    } | 
        ||
| 1050 | |||
| 1051 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 1052 |    // mouse move outside the window | 
        ||
| 1053 | else if (message == WM_NCMOUSEMOVE)  | 
        ||
| 1054 |    { | 
        ||
| 1055 | rbutton_pushed = false; // remember right button is released  | 
        ||
| 1056 | |||
| 1057 |       // call the default window message processing function to keep things going | 
        ||
| 1058 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 1059 |    } | 
        ||
| 1060 | |||
| 1061 |    //////////////////////////////////////////////////////////////////////////////////////////////// | 
        ||
| 1062 |    // window repaint | 
        ||
| 1063 | else if (message == WM_PAINT)  | 
        ||
| 1064 |    { | 
        ||
| 1065 | the_scene.update = true; // update the 3D scene  | 
        ||
| 1066 | |||
| 1067 |       // call the default window message processing function to keep things going | 
        ||
| 1068 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 1069 |    } | 
        ||
| 1070 | |||
| 1071 |    // call the default window message processing function to keep things going | 
        ||
| 1072 | return (DefWindowProc (hWnd, message, wParam, lParam));  | 
        ||
| 1073 | } | 
        ||
| 1074 | |||
| 1075 | |||
| 1076 | static bool Button_IsHovered (guibutton_t *button, int gui_x, int gui_y)  | 
        ||
| 1077 | { | 
        ||
| 1078 |    // handy wrapper that returns whether a particular GUI button is hovered when the mouse is at the given coordinates | 
        ||
| 1079 | |||
| 1080 | return (Render_IsMouseInBox (gui_x, gui_y, button->left, button->top, button->width, button->height));  | 
        ||
| 1081 | } | 
        ||
| 1082 | |||
| 1083 | |||
| 1084 | static bool Button_UpdateHoverState (guibutton_t *button, int gui_x, int gui_y)  | 
        ||
| 1085 | { | 
        ||
| 1086 |    // this function updates the hover state of a GUI button, and returns TRUE if the | 
        ||
| 1087 |    // scene needs to be updated, FALSE otherwise. | 
        ||
| 1088 | |||
| 1089 |    // is the button displayed ? | 
        ||
| 1090 | if (button->state != 0)  | 
        ||
| 1091 |    { | 
        ||
| 1092 |       // is the mouse hovering it ? | 
        ||
| 1093 | if (Render_IsMouseInBox (gui_x, gui_y, button->left, button->top, button->width, button->height))  | 
        ||
| 1094 |       { | 
        ||
| 1095 |          // was it NOT hovered before ? | 
        ||
| 1096 | if (button->state != 2)  | 
        ||
| 1097 |          { | 
        ||
| 1098 | button->state = 2; // mark it as hovered  | 
        ||
| 1099 | return (true); // return TRUE so as to update the scene  | 
        ||
| 1100 |          } | 
        ||
| 1101 |       } | 
        ||
| 1102 | |||
| 1103 |       // else was it hovered before ? | 
        ||
| 1104 | else if (button->state == 2)  | 
        ||
| 1105 |       { | 
        ||
| 1106 | button->state = 1; // else mark it as not hovered  | 
        ||
| 1107 | return (true); // return TRUE so as to update the scene  | 
        ||
| 1108 |       } | 
        ||
| 1109 |    } | 
        ||
| 1110 | |||
| 1111 | return (false); // no need to update the scene  | 
        ||
| 1112 | } |