// ------------------------------------------------------------------------ // window to display an adventure map // ------------------------------------------------------------------------ bool t_adventure_map_window::is_visible( t_screen_point const& point ) const { t_screen_point view_size = get_view_size(); t_screen_point view_pos = get_view_pos(); t_screen_rect rect( view_pos, view_size ); rect.top += 64 * 4; rect.left += 64 * 4; rect.right -= 64 * 4; rect.bottom -= 64 * 4; if (rect.height() < 64) { int center = (rect.top + rect.bottom) / 2; rect.top = center - 32; rect.bottom = center + 32; } if (rect.width() < 64) { int center = (rect.left + rect.right) / 2; rect.left = center - 32; rect.right = center + 32; } return is_point_in_rect( point, rect ); }
// ------------------------------------------------------------------------ // window to display an adventure map // determine correct cursor to display // ------------------------------------------------------------------------ void t_adventure_map_window::update_cursor() { t_screen_point point = get_mouse_position( this ); t_screen_rect rect = get_client_rect(); if (!is_point_in_rect( point, rect )) return; update_cursor( point ); }
// -------------------------------------------------------- // check if point is over the bitmap // -------------------------------------------------------- bool t_bitmap_layer_window::is_contained( t_screen_point point ) const { if (!is_point_in_rect( point, get_client_rect() )) return false; if (!m_has_transparency) return true; if (m_bitmap == 0) return false; return m_bitmap->contains( point + m_bitmap->get_rect().top_left() ); }
// ------------------------------------------------------------- // update the cursor, if neccessary // ------------------------------------------------------------- void t_game_application::update_cursor( t_window* window, t_screen_point const& point ) { // check if we need to change the cursor. t_mouse_window_ptr cursor; t_window* main_window = t_window::get_main_window(); if (main_window && is_point_in_rect( point, main_window->get_screen_rect() )) { if (window == 0) window = t_window::get_modal_window(); } else { window = 0; } if (window != 0) cursor = window->get_cursor(); if (cursor == g_cursor) { if (cursor != 0) cursor->move_to_front(); return; } // set the cursor bitmaps. if (g_cursor != 0) { g_cursor->close( false ); } g_cursor = cursor; if (cursor == 0) return; // move the cursor to the correct location. cursor->open(); cursor->set_visible( g_cursor_visible ); cursor->move( cursor->to_parent( point ) - cursor->get_hot_spot() ); // make it the topmost window cursor->move_to_front(); }
static void mouse_move( HWND window_handle, WPARAM word_param, LPARAM long_param ) { t_mouse_event event; t_game_application::close_help_balloon(); t_window* window = create_mouse_event( window_handle, word_param, long_param, event ); // check if the mouse is in our main window. RECT window_rect; GetWindowRect( window_handle, &window_rect ); t_screen_rect rect = from_windows_rect( window_rect ); POINT point; point.x = event.screen_point.x; point.y = event.screen_point.y; if ( is_point_in_rect( event.screen_point, rect ) && ::WindowFromPoint( point ) == window_handle ) { if (!g_mouse_captured) { SetCapture( window_handle ); g_mouse_captured = true; t_game_application::update_cursor(); } } else { if (g_mouse_captured) { ReleaseCapture(); g_mouse_captured = false; t_game_application::update_cursor(); } } g_game->mouse_move( window, event ); if (g_send_drag_event && window != 0) window->drag_event( event ); g_send_drag_event = false; }
//---------------------------------------------------------------------------------------------- // GET HIT SCROB //---------------------------------------------------------------------------------------------- cScrobIm * cScrobMgrIm::get_hit_scrob ( int x, int y ) { HDC hdc = GetDC ( hwnd ); for ( cScrobIm * s = ScrobList.end(); s; s = s->pPrev ) // draw forwards, hit-test backwards { cRectI r ( s->Pos, s->Dim ); cPtI hit ( x, y ); if ( is_point_in_rect ( &r, &hit ) ) { int iIndex = 0; if ( ! s->point_is_transparent ( hdc, iIndex, x, y ) ) return s; } } ReleaseDC ( hwnd, hdc ); return NULL; }
// -------------------------------------------------------- // check if a screen point is "owned" by this button // -------------------------------------------------------- bool t_button::is_contained( t_screen_point point ) const { if (!is_point_in_rect( point, get_client_rect() )) return false; if (!m_has_transparency) return true; if (m_current_image == 0) return false; t_window_list::const_reverse_iterator it; t_screen_point screen_point = to_screen( point ); // We're going to check ALL our children when evaluating if we want to claim // a point so that when the button changes state (like when it is clicked) // the answer doesn't suddenly change. for (it = get_children_rbegin(); it != get_children_rend(); it++) { if ( (*it)->is_contained( (*it)->to_client( screen_point ) ) ) return true; } return false; }
/* Check for the quit event, return true if detected*/ char getEvent(display *d, Button *buttons[NUM_BUTTONS], Button *HomeButtons[HOME_BUTTON_NUM], Button *OptionButtons[O_B_TOTAL]) { char what = NONE; int sym; //avoid repeating inputs --------------------- while (SDL_PollEvent(d->event) != 0) { int x, y; SDL_GetMouseState(&x, &y); switch (d->event->type) { case SDL_QUIT: what = QUIT; break; case SDL_TEXTINPUT: if ((what != CLICK1) && (what != HINT)) { what = d->event->text.text[0]; printf("ordinary character form keyboard %c\n", what); fflush(stdout); break; } case SDL_KEYDOWN: sym = d->event->key.keysym.sym; if (sym == ENTER) { what = (char)sym; } else if ((sym == SDLK_LCTRL) || (sym == SDLK_RCTRL)) { ctrl_pressed = true; //ctrl part-------------- } else if (ctrl_pressed) { if (sym == MUTE) { if (Mix_PausedMusic() == true) { Mix_ResumeMusic(); m_state = MUSIC_ON; } else { Mix_PauseMusic(); m_state = MUSIC_OFF; } } if (sym == SDLK_q) { what = QUIT; } //----------next song if (sym == SDLK_n) { NextSong(); m_state = MUSIC_ON; } ctrl_pressed = false; } else if (sym == BS || sym == TAB || sym == ENTER || sym == DEL) { what = (char)sym; } else if (sym == SDLK_UP) { what = (char)UP; } else if (sym == SDLK_DOWN) { what = (char)DOWN; } else if (sym == SDLK_LEFT) { what = (char)LEFT; } else if (sym == SDLK_RIGHT) { what = (char)RIGHT; } break; case SDL_MOUSEBUTTONDOWN: printf("in mouse %d %d\n", d->event->button.x, d->event->button.y); fflush(stdout); //------------------------------------- if (gScene == HOME_SCREEN) { if (is_point_in_rect(d->event->button.x, d->event->button.y, &HomeButtons[0]->rectangle)) { what = ENTER_GAME; } if (is_point_in_rect(d->event->button.x, d->event->button.y, &HomeButtons[1]->rectangle)) { what = ENTER_OPTION; } if (is_point_in_rect(d->event->button.x, d->event->button.y, &HomeButtons[2]->rectangle)) { what = ENTER_ABOUT; } } else if (gScene == GAME_SCREEN) { if (is_point_in_rect(d->event->button.x, d->event->button.y, &buttons[0]->rectangle)) { what = CLICK1; } else if (is_point_in_rect(d->event->button.x, d->event->button.y, &buttons[1]->rectangle)) { what = HINT; } else if (is_point_in_rect(d->event->button.x, d->event->button.y, &buttons[2]->rectangle)) { what = NEWGAME; } else if (is_point_in_rect(d->event->button.x, d->event->button.y, &buttons[3]->rectangle)) { what = STOOL; } else if (is_point_in_rect(d->event->button.x, d->event->button.y, &buttons[4]->rectangle)) { what = BOOTH; } else if (is_point_in_rect(d->event->button.x, d->event->button.y, &buttons[5]->rectangle)) { what = GREEN; } } break; case SDL_MOUSEMOTION: if (gScene == HOME_SCREEN) { if (is_point_in_rect(x, y, &HomeButtons[0]->rectangle)) { what = HOVER_GAME; } else if (is_point_in_rect(x, y, &HomeButtons[1]->rectangle)) { what = HOVER_OPTION; } else if (is_point_in_rect(x, y, &HomeButtons[2]->rectangle)) { what = HOVER_ABOUT; } else { what = OUT_BUTTON; } } else if (gScene == OPTION_SCREEN) { if (is_point_in_rect(x, y, &OptionButtons[BACK]->rectangle)) { what = BACK_HOVER; } else { what = OUT_BACK; } } break; case SDL_MOUSEBUTTONUP: if (gScene == OPTION_SCREEN) { if (is_point_in_rect(x, y, &OptionButtons[BACK]->rectangle)) { what = BACK_HOME; } } break; default: break; } } return what; }