Пример #1
0
//------------ Start of MouseSDL::init ------------//
//
void MouseSDL::init()
{
	update_skey_state();

	//------- initialize VGA update buffer -------//

	vga_update_buf = mem_add( VGA_UPDATE_BUF_SIZE );

	// ------ initialize mouse boundary ---------//
	reset_boundary();

	// ------- initialize event queue ---------//
	head_ptr = tail_ptr = 0;

	SDL_ShowCursor(SDL_DISABLE);
}
Пример #2
0
//--------- Begin of MouseSDL::poll_event ----------//
//
// Poll mouse events from the direct mouse VXD.
//
void MouseSDL::poll_event()
{
	SDL_Event event;
	int moveFlag;

	while (SDL_PeepEvents(&event,
			1,
			SDL_GETEVENT,
			SDL_KEYEVENTMASK |
			SDL_MOUSEEVENTMASK |
			SDL_JOYEVENTMASK) > 0) {

		MouseEvent ev;

		switch (event.type) {
		case SDL_MOUSEMOTION:
			cur_x += micky_to_displacement(event.motion.xrel);
			cur_y += micky_to_displacement(event.motion.yrel);
			if(cur_x < bound_x1)
				cur_x = bound_x1;
			if(cur_x > bound_x2)
				cur_x = bound_x2;
			if(cur_y < bound_y1)
				cur_y = bound_y1;
			if(cur_y > bound_y2)
				cur_y = bound_y2;
			moveFlag = 1;
			break;
		case SDL_MOUSEBUTTONDOWN:
			ev.x = cur_x;
			ev.y = cur_y;
			ev.time = m.get_time(); //mouseMsg->dwTimeStamp;
			ev.scan_code = 0;
			ev.skey_state = skey_state;

			if (event.button.button == SDL_BUTTON_LEFT) {
	//			left_press = (event.button.state == SDL_PRESSED);
				left_press = LEFT_BUTTON_MASK;
				ev.event_type = LEFT_BUTTON;
				add_event(&ev);
			} else if (event.button.button == SDL_BUTTON_RIGHT) {
				//right_press = (event.button.state == SDL_PRESSED);
				right_press = RIGHT_BUTTON_MASK;
				ev.event_type = RIGHT_BUTTON;
				add_event(&ev);
			}
			break;
		case SDL_MOUSEBUTTONUP:
			ev.x = cur_x;
			ev.y = cur_y;
			ev.time = m.get_time(); //mouseMsg->dwTimeStamp;
			ev.scan_code = 0;
			ev.skey_state = skey_state;

			if (event.button.button == SDL_BUTTON_LEFT) {
//				left_press = !(event.button.state == SDL_RELEASED);
				left_press = 0;
				ev.event_type = LEFT_BUTTON_RELEASE;
				add_event(&ev);
				reset_boundary();
			} else if (event.button.button == SDL_BUTTON_RIGHT) {
				//right_press = !(event.button.state == SDL_RELEASED);
				right_press = 0;
				ev.event_type = RIGHT_BUTTON_RELEASE;
				add_event(&ev);
			}
			break;
		case SDL_KEYDOWN:
			update_skey_state();
			add_key_event(event.key.keysym.sym, m.get_time());
			break;
		case SDL_KEYUP:
			update_skey_state();
			break;
		case SDL_JOYAXISMOTION:
		case SDL_JOYBALLMOTION:
		case SDL_JOYHATMOTION:
		case SDL_JOYBUTTONDOWN:
		case SDL_JOYBUTTONUP:
		default:
			ERR("unhandled event %d\n", event.type);
			break;
		}
	}


	if(moveFlag)
	{
		mouse_cursor.process(cur_x, cur_y);     // repaint mouse cursor
		power.mouse_handler();
	}
}
Пример #3
0
//--------- Begin of MouseSDL::poll_event ----------//
//
// Poll mouse events from the direct mouse VXD.
//
void MouseSDL::poll_event()
{
	SDL_Event event;
	int moveFlag;

	moveFlag = 0;

	while (SDL_PeepEvents(&event,
			1,
			SDL_GETEVENT,
			SDL_KEYDOWN,
			SDL_JOYBUTTONUP)) {

		MouseEvent ev;

		switch (event.type) {
		case SDL_MOUSEMOTION:
		// SDL already accelerates relative mouse motions.
		// Disable to let the user control speed outside of game.
#ifdef MOUSE_RELATIVE
			cur_x += micky_to_displacement(event.motion.xrel);
			cur_y += micky_to_displacement(event.motion.yrel);
#else
			cur_x = event.motion.x;
			cur_y = event.motion.y;
#endif
			if(cur_x < bound_x1)
				cur_x = bound_x1;
			if(cur_x > bound_x2)
				cur_x = bound_x2;
			if(cur_y < bound_y1)
				cur_y = bound_y1;
			if(cur_y > bound_y2)
				cur_y = bound_y2;
			moveFlag = 1;
			break;
		case SDL_MOUSEBUTTONDOWN:
			ev.x = cur_x;
			ev.y = cur_y;
			ev.time = misc.get_time(); //mouseMsg->dwTimeStamp;
			ev.scan_code = 0;
			ev.skey_state = skey_state;

			if (event.button.button == SDL_BUTTON_LEFT) {
	//			left_press = (event.button.state == SDL_PRESSED);
				left_press = LEFT_BUTTON_MASK;
				ev.event_type = LEFT_BUTTON;
				add_event(&ev);
			} else if (event.button.button == SDL_BUTTON_RIGHT) {
				//right_press = (event.button.state == SDL_PRESSED);
				right_press = RIGHT_BUTTON_MASK;
				ev.event_type = RIGHT_BUTTON;
				add_event(&ev);
			}
			break;
		case SDL_MOUSEBUTTONUP:
			ev.x = cur_x;
			ev.y = cur_y;
			ev.time = misc.get_time(); //mouseMsg->dwTimeStamp;
			ev.scan_code = 0;
			ev.skey_state = skey_state;

			if (event.button.button == SDL_BUTTON_LEFT) {
//				left_press = !(event.button.state == SDL_RELEASED);
				left_press = 0;
				ev.event_type = LEFT_BUTTON_RELEASE;
				add_event(&ev);
				reset_boundary();
			} else if (event.button.button == SDL_BUTTON_RIGHT) {
				//right_press = !(event.button.state == SDL_RELEASED);
				right_press = 0;
				ev.event_type = RIGHT_BUTTON_RELEASE;
				add_event(&ev);
			}
			break;
		case SDL_KEYDOWN:
		{
			int bypass = 0;
			int mod = event.key.keysym.mod &
					(KMOD_CTRL|KMOD_SHIFT|KMOD_ALT);
			if (mod == KMOD_LALT || mod == KMOD_RALT) {
				if (event.key.keysym.sym == SDLK_RETURN) {
					bypass = 1;
					sys.toggle_full_screen_flag = 1;
					sys.need_redraw_flag = 1;
				} else if (event.key.keysym.sym == SDLK_F4) {
					bypass = 1;
					sys.signal_exit_flag = 1;
				} else if (event.key.keysym.sym == SDLK_TAB) {
					bypass = 1;
					SDL_Window *window = SDL_GetWindowFromID(event.key.windowID);
					SDL_MinimizeWindow(window);
				}
			} else if (mod == KMOD_LCTRL || mod == KMOD_RCTRL) {
				if (event.key.keysym.sym == SDLK_g &&
						!vga.is_full_screen()) {
					static int grabbed = 0;
					bypass = 1;
					SDL_Window *window = SDL_GetWindowFromID(event.key.windowID);
					if (!grabbed) {
						SDL_SetWindowGrab(window, SDL_TRUE);
						grabbed = 1;
					} else {
						SDL_SetWindowGrab(window, SDL_FALSE);
						grabbed = 0;
					}
				}
			}
			if (!bypass) {
				update_skey_state();
				add_key_event(event.key.keysym.sym,
					      misc.get_time());
			}
			break;
		}
		case SDL_KEYUP:
			update_skey_state();
			break;
		case SDL_TEXTINPUT:
		case SDL_JOYAXISMOTION:
		case SDL_JOYBALLMOTION:
		case SDL_JOYHATMOTION:
		case SDL_JOYBUTTONDOWN:
		case SDL_JOYBUTTONUP:
		default:
			ERR("unhandled event %d\n", event.type);
			break;
		}
	}


	if(moveFlag)
	{
		mouse_cursor.process(cur_x, cur_y);     // repaint mouse cursor
		power.mouse_handler();
	}
}
Пример #4
0
// ------- begin of Mouse::update_skey_state --------//
//
void Mouse::init_keyboard()
{
	update_skey_state();
}