コード例 #1
0
ファイル: wsdl.cpp プロジェクト: javaphoon/spring
void mouse_update()
{
	// window not created yet or already shut down. no sense reporting
	// mouse position, and bail now to avoid ScreenToClient failing.
	if (g_hWnd == 0 || g_hWnd == INVALID_HANDLE_VALUE)
		return;

	// don't use DirectInput, because we want to respect the user's mouse
	// sensitivity settings. Windows messages are laggy, so query current
	// position directly.
	// note: GetCursorPos fails if the desktop is switched (e.g. after
	// pressing Ctrl+Alt+Del), which can be ignored.
	POINT screen_pt;
	if(!GetCursorPos(&screen_pt))
		return;
	int x, y;
	if(GetCoords(screen_pt.x, screen_pt.y, x, y))
	{
		active_change_state(GAIN, SDL_APPMOUSEFOCUS);
		mouse_moved(x, y);
	}
	// moved outside of window
	else
		active_change_state(LOSE, SDL_APPMOUSEFOCUS);
}
コード例 #2
0
ファイル: application.cpp プロジェクト: zheryu/RainSimulator
void Application::to_edit_mode() {
  if (mode == EDIT_MODE) return;
  pathtracer->stop();
  pathtracer->clear();
  mode = EDIT_MODE;
  mouse_moved(mouseX, mouseY);
}
コード例 #3
0
ファイル: application.cpp プロジェクト: zheryu/RainSimulator
void Application::cursor_event(float x, float y) {
  if (leftDown && !middleDown && !rightDown) {
    mouse1_dragged(x, y);
  } else if (!leftDown && !middleDown && rightDown) {
    mouse2_dragged(x, y);
  } else if (!leftDown && !middleDown && !rightDown) {
    mouse_moved(x, y);
  }

  mouseX = x;
  mouseY = y;
}
コード例 #4
0
static gboolean
video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self)
{
    g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
    auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);

    // if this widget already has focus, we want the focus to move to the next widget, otherwise we
    // will get stuck in a focus loop on the buttons
    if (gtk_widget_has_focus(widget))
        return FALSE;

    // otherwise we want the focus to go to and change between the call control buttons
    if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
        // selected a child, make sure call controls are shown
        mouse_moved(self);
        return TRUE;
    }

    // did not select the next child, propogate the event
    return FALSE;
}
コード例 #5
0
ファイル: event.c プロジェクト: e8johan/ovdisis
/*
** Description
** This is the event handler that handles keyboard, mouse and timer events
*/
static 
void
event_handler (VDI_Workstation * vwk) {
  Visual_Event     visual_event;

  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
  
  /* Endless loop that will pump events from the visual and pass them over
   * to the right manager (mouse, keyboard) */
  while (1) {
    VISUAL_GET_EVENT(vwk, &visual_event);

    switch(visual_event.type)
    {
    case Visual_Key_Press_Event  :
    case Visual_Key_Repeat_Event :
      key_event( visual_event );
      break;

    case Visual_Key_Release_Event :
      /* Do nothing */
      break;

    case Visual_Mouse_Button_Event :
      if (vwk->butv != NULL) {
        vwk->butv (visual_event.mouse_button.buttons);
      }
      set_mouse_buttons( visual_event.mouse_button.buttons );
      break;

    case Visual_Mouse_Move_Event :
      mouse_moved( visual_event.mouse_move.x,
		   visual_event.mouse_move.y );
      break;

    default:
      fprintf (stderr, "ovdisis: event.c: Unknown event 0x%x\n", visual_event.type);
    }
  }
}
コード例 #6
0
int dispatcher::execute( void )
{
	xcb_flush( _connection );
	_exit_code = 0;

	bool done = false;
	while ( !done )
	{
		auto event = core::wrap_cptr( xcb_wait_for_event( _connection ) );
		if ( !event )
			break;
		switch ( event->response_type & ~0x80 )
		{
			case XCB_EXPOSE:
			{
				auto *ev = reinterpret_cast<xcb_expose_event_t*>( event.get() );
				if ( ev->count == 0 )
					_windows[ev->window]->exposed();
				xcb_flush( _connection );
				break;
			}

			case XCB_CONFIGURE_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_configure_notify_event_t*>( event.get() );
				auto w = _windows[ev->window];
				if ( w->check_last_position( ev->x, ev->y ) )
					w->moved( ev->x, ev->y );
				if ( w->check_last_size( ev->width, ev->height ) )
					w->resize_canvas( ev->width, ev->height );
				break;
			}

			case XCB_DESTROY_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_destroy_notify_event_t*>( event.get() );
				auto w = _windows[ev->window];
				w->closed();
				break;
			}

			case XCB_MAP_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_map_notify_event_t*>( event.get() );
				auto w = _windows[ev->window];
				w->shown();
				w->restored();
				break;
			}

			case XCB_UNMAP_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_unmap_notify_event_t*>( event.get() );
				auto w = _windows[ev->window];
				w->hidden();
				w->minimized();
				break;
			}

			case XCB_ENTER_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_enter_notify_event_t*>( event.get() );
				auto w = _windows[ev->event];
				w->entered();
				break;
			}

			case XCB_LEAVE_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_leave_notify_event_t*>( event.get() );
				auto w = _windows[ev->event];
				w->exited();
				break;
			}

			case XCB_KEY_PRESS:
			{
				auto *ev = reinterpret_cast<xcb_key_press_event_t*>( event.get() );
				auto w = _windows[ev->event];
				platform::scancode sc = _keyboard->get_scancode( ev->detail );
				w->key_pressed( _keyboard, sc );
				break;
			}

			case XCB_KEY_RELEASE:
			{
				auto *ev = reinterpret_cast<xcb_key_press_event_t*>( event.get() );
				auto w = _windows[ev->event];
				platform::scancode sc = _keyboard->get_scancode( ev->detail );
				w->key_released( _keyboard, sc );
				break;
			}

			case XCB_MAPPING_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_mapping_notify_event_t*>( event.get() );
				if ( ev->request == XCB_MAPPING_MODIFIER || ev->request == XCB_MAPPING_KEYBOARD )
					_keyboard->update_mapping();
				break;
			}

			case XCB_BUTTON_PRESS:
			{
				auto *ev = reinterpret_cast<xcb_button_press_event_t*>( event.get() );
				auto w = _windows[ev->event];
				switch ( ev->detail )
				{
					case 1:
					case 2:
					case 3:
						w->mouse_pressed( _mouse, { double(ev->event_x), double(ev->event_y) }, ev->detail );
						break;

					case 4: // Mouse wheel up
					case 5: // Mouse wheel down
						break;
				}
				break;
			}

			case XCB_BUTTON_RELEASE:
			{
				auto *ev = reinterpret_cast<xcb_button_press_event_t*>( event.get() );
				auto w = _windows[ev->event];
				switch ( ev->detail )
				{
					case 1:
					case 2:
					case 3:
						w->mouse_released( _mouse, { double(ev->event_x), double(ev->event_y) }, ev->detail );
						break;

					case 4: // Mouse wheel up
					case 5: // Mouse wheel down
						break;
				}
				break;
			}

			case XCB_MOTION_NOTIFY:
			{
				auto *ev = reinterpret_cast<xcb_motion_notify_event_t*>( event.get() );
				auto w = _windows[ev->event];
				w->mouse_moved( _mouse, { double(ev->event_x), double(ev->event_y) } );
				break;
			}

			case XCB_VISIBILITY_NOTIFY:
			case XCB_REPARENT_NOTIFY:
				break;

			case XCB_CLIENT_MESSAGE:
			{
				auto *ev = reinterpret_cast<xcb_client_message_event_t*>( event.get() );
				if ( ev->data.data32[0] == _atom_delete_window )
				{
					auto w = _windows[ev->window];
					w->hide();
					_windows.erase( w->id() );
					done = _windows.empty();
				}
				break;
			}

			default:
				std::cout << "Unknown event: " << uint32_t( event->response_type & ~0x80 ) << ' ' << uint32_t( event->response_type ) << std::endl;
		}
	}

	return _exit_code;
}
コード例 #7
0
ファイル: shell.cpp プロジェクト: Aleph-One-Marathon/alephone
static void process_event(const SDL_Event &event)
{
	switch (event.type) {
	case SDL_MOUSEMOTION:
		if (get_game_state() == _game_in_progress)
		{
			mouse_moved(event.motion.xrel, event.motion.yrel);
		}
		break;
	case SDL_MOUSEWHEEL:
		if (get_game_state() == _game_in_progress)
		{
			bool up = (event.wheel.y > 0);
#if SDL_VERSION_ATLEAST(2,0,4)
			if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED)
				up = !up;
#endif
			mouse_scroll(up);
		}
		break;
	case SDL_MOUSEBUTTONDOWN:
		if (get_game_state() == _game_in_progress) 
		{
			if (!get_keyboard_controller_status())
			{
				hide_cursor();
				validate_world_window();
				set_keyboard_controller_status(true);
			}
			else
			{
				SDL_Event e2;
				memset(&e2, 0, sizeof(SDL_Event));
				e2.type = SDL_KEYDOWN;
				e2.key.keysym.sym = SDLK_UNKNOWN;
				e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_MOUSE_BUTTON + event.button.button - 1);
				process_game_key(e2);
			}
		}
		else
			process_screen_click(event);
		break;
	
	case SDL_JOYBUTTONDOWN:
		if (get_game_state() == _game_in_progress)
		{
			SDL_Event e2;
			memset(&e2, 0, sizeof(SDL_Event));
			e2.type = SDL_KEYDOWN;
			e2.key.keysym.sym = SDLK_UNKNOWN;
			e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_JOYSTICK_BUTTON + event.button.button);
			process_game_key(e2);
			
		}
		break;
		
	case SDL_KEYDOWN:
		process_game_key(event);
		break;

	case SDL_TEXTINPUT:
		if (Console::instance()->input_active()) {
		    Console::instance()->textEvent(event);
		}
		break;
		
	case SDL_QUIT:
		set_game_state(_quit_game);
		break;

	case SDL_WINDOWEVENT:
		switch (event.window.event) {
			case SDL_WINDOWEVENT_FOCUS_LOST:
				if (get_game_state() == _game_in_progress && get_keyboard_controller_status() && !Movie::instance()->IsRecording()) {
					darken_world_window();
					set_keyboard_controller_status(false);
					show_cursor();
				}
				break;
			case SDL_WINDOWEVENT_EXPOSED:
#if !defined(__APPLE__) && !defined(__MACH__) // double buffering :)
#ifdef HAVE_OPENGL
				if (MainScreenIsOpenGL())
					MainScreenSwap();
				else
#endif
					update_game_window();
#endif
				break;
		}
		break;
	}
	
}
コード例 #8
0
ファイル: Game.cpp プロジェクト: kikiotsuka/Solitaire
void Game::mouse_pressed(sf::Vector2f coord) {
    if (master_state == STATE_ANIMATION) {
        skip = true;
        while (master_state != STATE_PLAYING) {
            update();
        }
        skip = false;
        if (detailed_state != STATE_ANIMATION_FLIP_CARD && detailed_state != STATE_ANIMATION_MOVING_CARD) {
            return;
        }
    }
    int group, column, row;
    int status = locate_card(coord, group, column, row);
    if (status >= HOME && status <= PLAY_FIELD || status == DECK && column == 1) { //clicked some valid location on field
        //check if clicking on flipped deck
        if (status == DECK && row != field[DECK][1].size() - 1) {
            return;
        }
        //click on a face up card
        if (field[group][column][row].get_flip_state() == CARD_FACE_UP) { //add card(s) to cursor
            mouse_down = true;
            for (int i = row; i < field[group][column].size(); i++) {
                Card c = field[group][column][i];
                Position p = c.get_position_data();
                p.coord.first = field[group][column][i].get_center();
                p.loc.first = sf::Vector3i(group, column, i);
                c.set_position_data(p);
                cursor.push_back(c);
                field[group][column].erase(field[group][column].begin() + i--);
                mouse_moved(coord);
            }
            //check if ace is moved out of home area
            if (cursor.size() == 1 && cursor.front().get_value() == 1) {
                for (int i = 0; i < ace_locations.size(); i++) {
                    if (ace_locations[i] == cursor.front().get_suit()) {
                        ace_locations[i] = -1;
                        break;
                    }
                }
            }
        } else { //card is face down, see if its at the front of the pile
            if (field[group][column].size() - 1 == row) {
                anim_flip_card();
                field[group][column][row].init_animation(STATE_ANIMATION_FLIP_CARD, to_frame(0.3f));
                transit.push_back(field[group][column][row]);
                field[group][column].pop_back();
            }
        }
    } else if (status == DECK || status == EMPTY_SPOT && group == DECK) { //if deck group was clicked
        if (field[DECK][0].empty()) { //deck is empty, return deck contents
            if (!field[DECK][1].empty()) {
                anim_flip_deck();
                for (int i = 0; i < field[DECK][1].size(); i++) {
                    field[DECK][1][i].set_flip_state(CARD_FACE_DOWN);
                }
            }
        } else if (status == DECK) { //move and flip card
            anim_move_card();
            //recorrect the position of all previous cards
            int flipped_counter = 1;
            if (three_card_rule) {
                flipped_counter = field[DECK][0].size() >= 3 ? field[DECK][1].size() - 3 : 0;
            }
            for (int i = flipped_counter; i < field[DECK][1].size(); i++) {
                Card c = field[DECK][1][i];
                if (c.get_center() == field_rect[DECK][1].getPosition()) continue;
                Position p = c.get_position_data();
                p.coord.second = field_rect[DECK][1].getPosition();
                c.init_animation(STATE_ANIMATION_MOVING_CARD, p, to_frame(0.25f));
                transit.push_back(c);
                field[DECK][1].erase(field[DECK][1].begin() + i--);
            }
            //launch animation for moving card
            flipped_counter = 1;
            if (three_card_rule) {
                flipped_counter = field[DECK][0].size() >= 3 ? 3 : field[DECK][0].size();
            }
            for (int i = 0; i < flipped_counter; i++) {
                Card c = field[DECK][0].back();
                c.set_flip_state(CARD_FACE_UP);
                Position p = c.get_position_data();
                p.coord.second = field_rect[DECK][1].getPosition();
                p.coord.second.x += HORZ_CARD_SPACING * i;
                p.loc.second = sf::Vector3i(DECK, 1, field[DECK][1].size());
                c.init_animation(STATE_ANIMATION_MOVING_CARD, p, to_frame(0.25f));
                transit.push_back(c);
                field[DECK][0].pop_back();
            }
        }
    }
}
コード例 #9
0
window::window( const std::shared_ptr<platform::window> &win )
	: _window( win )
{
	precondition( bool(_window), "null window" );
	_window->exposed = [this] ( void ) { paint(); };
	_window->resized = [this] ( double w, double h ) { resized( w, h ); };
	_window->mouse_pressed = [this]( const std::shared_ptr<platform::mouse> &, const base::point &p, int b ) { mouse_press( p, b ); };
	_window->mouse_released = [this]( const std::shared_ptr<platform::mouse> &, const base::point &p, int b ) { mouse_release( p, b ); };
	_window->mouse_moved = [this]( const std::shared_ptr<platform::mouse> &, const base::point &p ) { mouse_moved( p ); };
	_window->mouse_wheel = [this]( const std::shared_ptr<platform::mouse> &, int i ) { mouse_wheel( i ); };
	_window->key_pressed = [this]( const std::shared_ptr<platform::keyboard> &, const platform::scancode &c ) { key_pressed( c ); };
	_window->key_released = [this]( const std::shared_ptr<platform::keyboard> &, const platform::scancode &c ) { key_released( c ); };
	_window->text_entered = [this]( const std::shared_ptr<platform::keyboard> &, const char32_t &c ) { text_entered( c ); };
	_canvas = std::make_shared<draw::canvas>();
}