Ejemplo n.º 1
0
void deactivate()
{
	/* all buttons up */
	mouse_button(0,BUTTON1|BUTTON2|BUTTON3,0);
	ms.active=0;
	mouse_circle(CIRCLE,-1,1);
}
Ejemplo n.º 2
0
static void mouse(int glut_button, int glut_state, int x, int glut_y) {
	int button = mouse_button(glut_button);
	int state = mouse_state(glut_state);
    
	// do cam transform in nav mode
	if(camera_mouse(button, state, x, glut_y))
		return;
    
}
Ejemplo n.º 3
0
  void WindowProfiler::mouse(MouseButton Button, ButtonAction Action, int mods, int x, int y)
  {
    WindowProfiler::Window  &window   = m_window;
    m_profiler.reset();

    if (!window.m_mouseButtonFlags && mouse_button(Button,Action)) return;

    switch(Action)
    {
    case BUTTON_PRESS:
      {
        switch(Button)
        {
        case MOUSE_BUTTON_LEFT:
          {
            window.m_mouseButtonFlags |= MOUSE_BUTTONFLAG_LEFT;
          }
          break;
        case MOUSE_BUTTON_MIDDLE:
          {
            window.m_mouseButtonFlags |= MOUSE_BUTTONFLAG_MIDDLE;
          }
          break;
        case MOUSE_BUTTON_RIGHT:
          {
            window.m_mouseButtonFlags |= MOUSE_BUTTONFLAG_RIGHT;
          }
          break;
        }
      }
      break;
    case BUTTON_RELEASE:
      {
        if (!window.m_mouseButtonFlags) break;

        switch(Button)
        {
        case MOUSE_BUTTON_LEFT:
          {
            window.m_mouseButtonFlags &= ~MOUSE_BUTTONFLAG_LEFT;
          }
          break;
        case MOUSE_BUTTON_MIDDLE:
          {
            window.m_mouseButtonFlags &= ~MOUSE_BUTTONFLAG_MIDDLE;
          }
          break;
        case MOUSE_BUTTON_RIGHT:
          {
            window.m_mouseButtonFlags &= ~MOUSE_BUTTONFLAG_RIGHT;
          }
          break;
        }
      }
      break;
    }
  }
Ejemplo n.º 4
0
void OVR_SDL2_app::dispatch(SDL_Event& e)
{
    switch (e.type)
    {
        case SDL_KEYDOWN:
            keyboard(e.key.keysym.scancode, true,  (e.key.repeat != 0));
            break;
        case SDL_KEYUP:
            keyboard(e.key.keysym.scancode, false, (e.key.repeat != 0));
            break;
        case SDL_MOUSEBUTTONDOWN:
            mouse_button(e.button.button, true);
            break;
        case SDL_MOUSEBUTTONUP:
            mouse_button(e.button.button, false);
            break;
        case SDL_MOUSEMOTION:
            mouse_motion(e.motion.xrel, e.motion.yrel);
            break;
        case SDL_MOUSEWHEEL:
            mouse_wheel(e.wheel.x, e.wheel.y);
            break;
        case SDL_CONTROLLERAXISMOTION:
            game_axis(e.caxis.which, e.caxis.axis, e.caxis.value / 32768.f);
            break;
        case SDL_CONTROLLERBUTTONDOWN:
            game_button(e.caxis.which, e.cbutton.button, true);
            break;
        case SDL_CONTROLLERBUTTONUP:
            game_button(e.caxis.which, e.cbutton.button, false);
            break;
        case SDL_CONTROLLERDEVICEADDED:
            game_connect(e.cdevice.which, true);
            break;
        case SDL_CONTROLLERDEVICEREMOVED:
            game_connect(e.cdevice.which, false);
            break;
        case SDL_QUIT:
            running = false;
            break;
    }
}
Ejemplo n.º 5
0
void OSIPhone::touches_cancelled() {

	for (int i=0; i<MAX_MOUSE_COUNT; i++) {

		if (mouse_list.pressed[i]) {

			// send a mouse_up outside the screen
			mouse_button(i, -1, -1, false, false, false);
		};
	};
};
Ejemplo n.º 6
0
Archivo: main.c Proyecto: cout/sx3
// SDL doesn't use callbacks, so we must check the events ourselves
void main_loop() {
    SDL_Event event;
    SDL_Event prev_event;
    int retval;

    for(;;) {
        // We can wait on an event (as we are doing here), or we can poll for
        // events and, if there are no events waiting to be processed, we can
        // call our idle function.  This allows for a slightly more versatile
        // event handler than with a callback-based approach, as with GLUT.
        if(!SDL_WaitEvent(&event)) continue;
event_switch:
        switch(event.type) {
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                mouse_button(event.button.button, event.button.state,
                    event.button.x, event.button.y);
                break;
            case SDL_MOUSEMOTION:
                // This is a hack to keep the motion from being so jumpy on
                // slow cards
                do {
                    prev_event = event;
                    retval = SDL_PollEvent(&event);
                } while(retval != 0 && event.type == SDL_MOUSEMOTION);
                if(retval != 0) {
                    // SDL_PushEvent(&event);
                    // event = prev_event;
                    mouse_motion(prev_event.motion.state,
                        prev_event.motion.x, prev_event.motion.y);
                    goto event_switch;
                }
                mouse_motion(event.motion.state,
                    event.motion.x, event.motion.y);
                break;
            case SDL_KEYUP:
                keyfunc(event.key.keysym.sym);
                break;
            case SDL_VIDEORESIZE:
                set_window_size(event.resize.w, event.resize.h);
                break;
            case SDL_QUIT:
                return;
        }
    }
}
Ejemplo n.º 7
0
Archivo: test.c Proyecto: mdurrer/cgd
int main(int argc, char **argv)
{
	int mbn, prev_mx = -1, prev_my = -1, prev_mbn = 0;

	if(parse_args(argc, argv) == -1) {
		return 1;
	}

	if(init() == -1) {
		return 1;
	}

	reset_timer();

	for(;;) {
        if(kbhit()) {
			if(keyb(getch()) == 0) {
				break;
            }
        }

		mbn = read_mouse(&mx, &my);
		if(mbn != prev_mbn) {
			mouse_button(mbn, mx, my);
			prev_mbn = mbn;
		}
		if(mx != prev_mx || my != prev_my) {
			if(mbn) {
				mouse_motion(mx, my);
			}
			prev_mx = mx;
			prev_my = my;
		}

		redraw();
	}

	shutdown();
	print_perf();
	return 0;
}
Ejemplo n.º 8
0
void mouse(int bn, int st, int x, int y)
{
	mouse_button(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN ? 1 : 0, x, y);
}
Ejemplo n.º 9
0
void mouse_conv(int rep,char *button,char *remote)
{
	struct trans_mouse *tm;
	int found=0;
	
	tm=tm_first;
	while(tm!=NULL)
	{
		if(tm->tm_remote!=ALL)
		{
			if(strcasecmp(remote,tm->tm_remote)!=0)
			{
				tm=tm->tm_next;
				continue;
			}
		}
		if(tm->tm_button!=ALL)
		{
			if(strcasecmp(button,tm->tm_button)!=0)
			{
				tm=tm->tm_next;
				continue;
			}
		}
		if(tm->tm_directive==mouse_activate)
		{
			if(ms.active==0 && ms.always_active==0)
			{
				activate();
			}
		}
		else if(tm->tm_directive==mouse_toggle_activate && rep==0)
		{
			if(ms.always_active==0)
			{
				if(ms.active==0)
				{
					activate();
					ms.toggle_active=1;
				}
				else
				{
					deactivate();
				}
			}
		}
		
		if(ms.active || ms.always_active)
		{
			int i;
			for(i=0;config_table[i].string!=NULL;i++)
			{
				if(tm->tm_directive==config_table[i].d)
				{
					int x,y,z,up,down,toggle;

					x=config_table[i].x;
					y=config_table[i].y;
					z=config_table[i].z;
					down=config_table[i].down;
					up=config_table[i].up;
					toggle=config_table[i].toggle;

					if(x || y || z)
					{
						mouse_move(x,y,z,rep);
					}
					if(toggle)
					{
						/*
						  assert(down==up); 
						  assert(up==BUTTON1
						  || up==BUTTON2
						  || up==BUTTON3);
						*/
						if(ms.buttons[map_buttons(up)]==button_up)
							mouse_button(down,0,rep);
						else
							mouse_button(0,up,rep);
					}
					else
					{
						if(down && up) /* click */
						{
							mouse_button(down,0,rep);
#ifdef CLICK_DELAY
							usleep(CLICK_DELAY);
#endif
							mouse_button(0,up,rep);
						}
						else if(down || up);
						{
							mouse_button(down,up,rep);
						}
					}
					break;
				}
			}

		}
		found=1;
		tm=tm->tm_next;
	}
	if(found==0)
	{
		if(ms.active==1 &&
		   ms.always_active==0 &&
		   ms.toggle_active==0)
		{
			deactivate();
		}
	}
}
Ejemplo n.º 10
0
void OSNacl::handle_event(const pp::InputEvent& p_event) {

	int type = p_event.GetType();
	switch (type) {

	case PP_INPUTEVENT_TYPE_MOUSEDOWN:
	case PP_INPUTEVENT_TYPE_MOUSEUP:
	case PP_INPUTEVENT_TYPE_WHEEL: {

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::MOUSE_BUTTON;
		event.device=0;

		pp::MouseInputEvent mevent(p_event);
		if (type == PP_INPUTEVENT_TYPE_WHEEL) {

			pp::WheelInputEvent wevent(p_event);;
			float ticks = wevent.GetTicks().y();
			if (ticks == 0)
				break; // whut?

			event.mouse_button.pressed = true;
			event.mouse_button.button_index = ticks > 0 ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN;
			event.mouse_button.doubleclick = false;

		} else {

			event.mouse_button.pressed = (type == PP_INPUTEVENT_TYPE_MOUSEDOWN);
			event.mouse_button.button_index = mouse_button(mevent.GetButton());
			event.mouse_button.doubleclick = (mevent.GetClickCount() % 2) == 0;

			mouse_mask &= ~(1<< (event.mouse_button.button_index - 1));
			mouse_mask |= (event.mouse_button.pressed << (event.mouse_button.button_index - 1));
		};
		pp::Point pos = mevent.GetPosition();
		event.mouse_button.button_mask = mouse_mask;
		event.mouse_button.global_x = pos.x();
		event.mouse_button.x = pos.x();
		event.mouse_button.global_y = pos.y();
		event.mouse_button.y = pos.y();
		event.mouse_button.pointer_index = 0;
		event.mouse_button.mod = modifier(p_event.GetModifiers());
		queue_event(event);

	} break;

	case PP_INPUTEVENT_TYPE_MOUSEMOVE: {

		pp::MouseInputEvent mevent(p_event);
		pp::Point pos = mevent.GetPosition();

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::MOUSE_MOTION;
		event.mouse_motion.pointer_index = 0;
		event.mouse_motion.global_x = pos.x();
		event.mouse_motion.global_y = pos.y();
		event.mouse_motion.x = pos.x();
		event.mouse_motion.y = pos.y();
		event.mouse_motion.button_mask = mouse_mask;
		event.mouse_motion.mod = modifier(p_event.GetModifiers());

		event.mouse_motion.relative_x = pos.x() - mouse_last_x;
		event.mouse_motion.relative_y = pos.y() - mouse_last_y;
		mouse_last_x = pos.x();
		mouse_last_y = pos.y();

		queue_event(event);

	} break;

	case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
	case PP_INPUTEVENT_TYPE_KEYDOWN:
	case PP_INPUTEVENT_TYPE_KEYUP: {

		pp::KeyboardInputEvent kevent(p_event);
		bool is_char;
		uint32_t key = godot_key(kevent.GetKeyCode(), is_char);
		if (type != PP_INPUTEVENT_TYPE_KEYUP && is_char) {

			last_scancode = key;
			break;
		};

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::KEY;
		event.key.pressed = (type != PP_INPUTEVENT_TYPE_KEYUP);
		event.key.scancode = key;
		event.key.unicode = key;

		event.key.echo = p_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT;
		event.key.mod = modifier(p_event.GetModifiers());
		queue_event(event);
	} break;

	case PP_INPUTEVENT_TYPE_CHAR: {

		pp::KeyboardInputEvent kevent(p_event);
		InputEvent event;
		event.ID = ++event_id;
		event.type = InputEvent::KEY;
		event.key.pressed = true;
		event.key.scancode = last_scancode;
		event.key.unicode = kevent.GetCharacterText().AsString().c_str()[0];
		event.key.mod = modifier(p_event.GetModifiers());
		event.key.echo = p_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT;
		queue_event(event);

	} break;

	/*
	case NPEventType_Minimize: {

		minimized = p_event->u.minimize.value == 1;

	} break;


	case NPEventType_Focus: {

		if (p_event->u.focus.value == 1) {
			main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
		} else {
			main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
		};
	} break;

	*/

	default:
		;
	};
};
Ejemplo n.º 11
0
void EventHandler::handle_events()
{
  SDL_Event event;
  while (SDL_PollEvent(&event))
  {
    switch (event.type)
    {
      case SDL_VIDEORESIZE:
        resize_window(event.resize.w, event.resize.h);
        break;

      case SDL_JOYAXISMOTION:
        joystick_motion(&event.jaxis);
        break;

      case SDL_JOYBUTTONDOWN:
        if (nJoystickDlg)
          joystickDlg->joystickDlgButton(&event.jbutton);
        else
          joystick_button(&event.jbutton);
        break;

      case SDL_MOUSEMOTION:
        /**
         * GUI_MOUSE_MOTION_WORKAROUND
         * The GUI sometimes returns that it used the event, although it is not visible anymore!
         * Therefore we need to check whether it is visible at all.
         * Where it works:
         *   -ESC to show GUI
         *   -open dialog (for example video)
         *   -close dialog
         *   -ESC to hide GUI
         * Everything is fine, the mouse-motions are not used by the GUI.
         *   -ESC to show GUI
         *   -toggle something from the menu bar (for example Verbosity)
         *   -ESC to hide GUI
         * Now the GUI still uses the mouse motions, although it is invisible!
         */
        if (Global::TXInterface->inputMethod() == T_TX_Interface::eIM_mouse)
        {
          // always update the mouse interface
          mouse_motion(&event.motion);
          if (Global::gui)
            Global::gui->mouseMotionHandler(event.motion.x, event.motion.y);
        }
        else if (!Global::gui || !Global::gui->isVisible()
            ||
            !Global::gui->mouseMotionHandler(event.motion.x, event.motion.y))
        {
          // GUI did not use the event, pass it to the simulation itself
          mouse_motion(&event.motion);
        }
        break;

      case SDL_MOUSEBUTTONDOWN:
#if TEST_WITHOUT_JOYSTICK > 0
        if (nJoystickDlg && event.button.button != SDL_BUTTON_LEFT)
        {
          SDL_JoyButtonEvent jevent;
          jevent.type   = SDL_JOYBUTTONDOWN;
          jevent.state  = SDL_PRESSED;
          jevent.which  = 0;
          switch (event.button.button)
          {
            case SDL_BUTTON_MIDDLE:
              jevent.button = 0;
              break;
            case SDL_BUTTON_RIGHT:
              jevent.button = 1;
              break;
            default:
              jevent.button = 2;
              break;
          }
          joystickDlg->joystickDlgButton(&jevent);
        }
#endif
        if (!Global::gui || !Global::gui->mouseButtonDownHandler(event.button.button, event.button.x, event.button.y))
        {
          // GUI did not use the event, pass it to the simulation itself
          mouse_button(&event.button);
        }
        break;

      case SDL_MOUSEBUTTONUP:
        if (Global::gui)
          Global::gui->mouseButtonUpHandler(event.button.button, event.button.x, event.button.y);
        break;

      case SDL_KEYDOWN:
        if (!Global::gui || !Global::gui->keyDownEventHandler(event.key.keysym))
        {
          // GUI did not use the event, pass it to the simulation itself
          key_down(&event.key.keysym);
        }
        break;

      case SDL_KEYUP:
        if (Global::gui)
          Global::gui->keyUpEventHandler(event.key.keysym);
        break;

      case SDL_QUIT:
        if (Global::gui)
          Global::gui->doQuitDialog();
        else
          Global::Simulation->quit();
        break;
    }
  }
}
Ejemplo n.º 12
0
static void mouse_handler(GtkWidget *w, GdkEvent *event, gpointer data)
{
    video_canvas_t *canvas = (video_canvas_t *)data;

    if (event->type == GDK_BUTTON_PRESS) {
        GdkEventButton *bevent = (GdkEventButton*)event;
        if (_mouse_enabled || lightpen_enabled) {
            mouse_button(bevent->button-1, TRUE);
            gtk_lightpen_setbutton(bevent->button, TRUE);
        } else {
            if (bevent->button == 1) {
                ui_menu_update_all_GTK();
                gtk_menu_popup(GTK_MENU(left_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
            } else if (bevent->button == 3) {
                ui_menu_update_all_GTK();
                gtk_menu_popup(GTK_MENU(right_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
            }
        }
    } else if (event->type == GDK_BUTTON_RELEASE && (_mouse_enabled || lightpen_enabled)) {
        GdkEventButton *bevent = (GdkEventButton*)event;
        mouse_button(bevent->button-1, FALSE);
        gtk_lightpen_setbutton(bevent->button, FALSE);
   } else if (event->type == GDK_MOTION_NOTIFY) {
        GdkEventMotion *mevent = (GdkEventMotion*)event;
        if (_mouse_enabled) {
            /* handle pointer motion events for mouse emulation */
            gint x=0, y=0, w=0, h=0, warp=0;
            gint xoff=0, yoff=0;
            gint ptrx, ptry;
            GdkDisplay *display = NULL;
            GdkScreen *screen = NULL;

            /* get default display and screen */
            display = gdk_display_get_default ();
            screen = gdk_display_get_default_screen (display);

            /* get cursor position */
            gdk_display_get_pointer (display, NULL, &x, &y, NULL);

            ptrx = (int)mevent->x;
            ptry = (int)mevent->y;
            xoff = x - ptrx;
            yoff = y - ptry;

            /* w = canvas->draw_buffer->canvas_physical_width; */
            w = gtk_widget_get_allocated_width(canvas->emuwindow);
            h = canvas->draw_buffer->canvas_physical_height;

            /* DBG(("ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", ptrx, ptry, x, y, w, h)); */

            if (mouse_warpx == 1) {
                /* from left to right */
                if ((ptrx > mouse_lasteventx) && (ptrx >= (w - (MOUSE_WRAP_MARGIN * 2))) && (ptrx <= (w - MOUSE_WRAP_MARGIN))) {
                    mouse_warpx = 0;
                    mouse_lasteventx = ptrx;
                }
            } else if (mouse_warpx == 2) {
                /* from right to left */
                if ((ptrx < mouse_lasteventx) && (ptrx <= (MOUSE_WRAP_MARGIN * 2)) && (ptrx >= MOUSE_WRAP_MARGIN)) {
                    mouse_warpx = 0;
                    mouse_lasteventx = ptrx;
                }
            }

            if (mouse_warpy == 1) {
                /* from top to bottom */
                if ((ptry > mouse_lasteventy) && (ptry >= (h - (MOUSE_WRAP_MARGIN * 2))) && (ptry <= (h - MOUSE_WRAP_MARGIN))) {
                    mouse_warpy = 0;
                    mouse_lasteventy = ptry;
                }
            } else if (mouse_warpy == 2) {
                /* from bottom to top */
                if ((ptry < mouse_lasteventy) && (ptry <= (MOUSE_WRAP_MARGIN * 2)) && (ptry >= MOUSE_WRAP_MARGIN)) {
                    mouse_warpy = 0;
                    mouse_lasteventy = ptry;
                }
            }

            if (mouse_warped || mouse_warpx || mouse_warpy) {
                /* ignore this event, its the result of us having moved the pointer */
                /* DBG(("warped!:%d/%d/%d ptrx:%d ptry:%d lastx:%d lasty:%d", mouse_warped, mouse_warpx, mouse_warpy, ptrx, ptry, mouse_lasteventx, mouse_lasteventy)); */
                if (mouse_warped) {
                    --mouse_warped;
                }
            } else {

                if (ptrx < MOUSE_WRAP_MARGIN) {
                    /* from left to right */
                    mouse_lasteventx = ptrx;
                    ptrx = w - (MOUSE_WRAP_MARGIN + 10);
                    mouse_warpx = 1;
                    warp = 1;
                }
                else if (ptrx > (w - MOUSE_WRAP_MARGIN)) {
                    /* from right to left */
                    mouse_lasteventx = ptrx;
                    ptrx = (MOUSE_WRAP_MARGIN + 10);
                    mouse_warpx = 2;
                    warp = 1;
                }

                if (ptry < (MOUSE_WRAP_MARGIN)) {
                    /* from top to bottom */
                    mouse_lasteventy = ptry;
                    ptry = (h - (MOUSE_WRAP_MARGIN + 10));
                    mouse_warpy = 1;
                    warp = 1;
                } else if (ptry > (h - MOUSE_WRAP_MARGIN)) {
                    /* from bottom to top */
                    mouse_lasteventy = ptry;
                    ptry = (MOUSE_WRAP_MARGIN + 10);
                    mouse_warpy = 2;
                    warp = 1;
                }
                /* DBG(("warp:%d ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", warp, ptrx, ptry, x, y, w, h)); */

                if (warp) {
                    /* set new cusor position */
                    ++mouse_warped;
                    /* DBG(("warp to: x:%d y:%d", ptrx, ptry)); */
                    gdk_display_warp_pointer (display, screen, ptrx + xoff, ptry + yoff);
                } else {
                    mouse_dx = (ptrx - mouse_lasteventx) / (canvas->videoconfig->doublesizex + 1);
                    mouse_dy = (ptry - mouse_lasteventy) / (canvas->videoconfig->doublesizey + 1);
                    DBG(("mouse move dx:%8d dy:%8d", mouse_dx, mouse_dy));
                    mouse_move((float)mouse_dx, (float)mouse_dy);
                    mouse_lasteventx = ptrx;
                    mouse_lasteventy = ptry;
                }
            }
        }
#ifdef HAVE_FULLSCREEN
        fullscreen_mouse_moved(canvas, (int)mevent->x, (int)mevent->y, 0);
#endif
   }
}
Ejemplo n.º 13
0
/* unused ? */
void ui_dispatch_next_event(void)
{
#ifdef ANDROID_COMPILE
    struct locnet_al_event event;

    if (Android_PollEvent(&event)) {
#else
    SDL_Event e;

    if (SDL_PollEvent(&e)) {
        ui_handle_misc_sdl_event(e);
#endif
    } else {
        /* Add a small delay to not hog the host CPU when remote
           monitor is being used. */
        SDL_Delay(10);
    }
}
#endif

/* Main event handler */
ui_menu_action_t ui_dispatch_events(void)
{
    SDL_Event e;
    ui_menu_action_t retval = MENU_ACTION_NONE;

#ifdef ANDROID_COMPILE
    struct locnet_al_event event1;

    if (loader_showinfo) {
        int value = loader_showinfo;

        loader_showinfo = 0;
        loader_set_statusbar((value == 1) ? 1 : 0);
    }
    if (loader_true_drive) {
        int value = loader_true_drive;

        loader_true_drive = 0;
        loader_set_drive_true_emulation((value == 1) ? 1 : 0);
    }
    if (loader_turbo) {
        int value = loader_turbo;

        loader_turbo = 0;
        loader_set_warpmode((value == 1) ? 1 : 0);
    }
    if (loadf->frameskip) {
        int value = loadf->frameskip;

        loadf->frameskip = 0;
        resources_set_int("RefreshRate", ((value > 0) && (value <= 10)) ? (value + 1) : 1);
    }
    if (loadf->abort) {
        loadf->abort = 0;
        ui_pause_emulation(1);
        ui_sdl_quit();
        ui_pause_emulation(0);
        return MENU_ACTION_NONE;
    } else if (loader_loadstate) {
        loader_loadstate = 0;
        loader_load_snapshot(savestate_filename);
        ui_pause_emulation(0);
        return MENU_ACTION_NONE;
    } else if (loader_savestate) {
        loader_savestate = 0;
        loader_save_snapshot(savestate_filename);
        ui_pause_emulation(0);
        return MENU_ACTION_NONE;
    }

    int stopPoll = 0;

    while ((!stopPoll) && Android_PollEvent(&event1)) {
        struct locnet_al_event *event = &event1;

        switch (event->eventType) {
            case SDL_MOUSEMOTION:
                {
                    //locnet, 2011-06-16, detect auto calibrate
                    if ((event->x == -2048) && (event->y == -2048)) {
                        down_x = -1;
                        down_y = -1;
                        oldx = 0;
                        oldy = 0;
                        stopPoll = 1;
                    //locnet, 2011-07-01, detect pure relative move
                    } else if ((event->down_x == -1024) && (event->down_y == -1024)) {
                        down_x = 0;
                        down_y = 0;
                        oldx = 0;
                        oldy = 0;
                    } else if ((down_x != event->down_x) || (down_y != event->down_y)) {
                        down_x = event->down_x;
                        down_y = event->down_y;
                        oldx = down_x;
                        oldy = down_y;
                    }
                    mouse_move((int)(event->x - oldx), (int)(event->y - oldy));
                    oldx = event->x;
                    oldy = event->y;
                }
                break;
            case SDL_MOUSEBUTTONDOWN:
                {
                    if ((event->down_x >= 0) && (event->down_y >= 0)) {
                        mouse_x = 640 * event->down_x / 1000.0f - 64;
                        mouse_y = 400 * (1000 - event->down_y) / 1000.0f - 200;
                    }
                    if (event->keycode >= 0) {
                        mouse_button((int)(event->keycode) ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT, 1);
                    }
                    stopPoll = 1;
                }
                break;
            case SDL_MOUSEBUTTONUP:
                {
                    if (event->keycode >= 0) {
                        mouse_button((int)(event->keycode) ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT, 0);
                    }
                    stopPoll = 1;
                }
                break;
            case SDL_JOYAXISMOTION:
                {
                    float x = event->x / 256.0f;
                    float y = event->y / 256.0f;
                    int left = 0, top = 0, right = 0, bot = 0;
                    int value;

                    if (y < -DEAD_ZONE) {
                        top = 1;
                    }
                    if (y > DEAD_ZONE) {
                        bot = 1;
                    }
                    if (x < -DEAD_ZONE) {
                        left = 1;
                    }
                    if (x > DEAD_ZONE) {
                        right = 1;
                    }

                    value = 0;

                    if (left) {
                        value |= 4;
                    }
                    if (right) {
                        value |= 8;
                    }
                    if (top) {
                        value |= 1;
                    }
                    if (bot) {
                        value |= 2;
                    }
                    retval = sdljoy_axis_event(0, 0, event->x / 256.0f * 32767);
                    ui_menu_action_t retval2 = sdljoy_axis_event(0, 1, event->y / 256.0f * 32767);
                    if (retval == MENU_ACTION_NONE) {
                        retval = retval2;
                    }
                    old_joy_direction = value;
                    stopPoll = 1;
                }
                break;
            case SDL_JOYBUTTONDOWN:
                {
                    retval = sdljoy_button_event(0, event->keycode, 1);

                    //2011-09-20, buffer overflow when autofire if stopPoll
                    if (!Android_HasRepeatEvent(SDL_JOYBUTTONDOWN, event->keycode)) {
                        stopPoll = 1;
                    }
                }
                break;
            case SDL_JOYBUTTONUP:
                {
                    retval = sdljoy_button_event(0, event->keycode, 0);

                    //2011-09-20, buffer overflow when autofire if stopPoll
                    if (!Android_HasRepeatEvent(SDL_JOYBUTTONUP, event->keycode)) {
                        stopPoll = 1;
                    }
                }
                break;
            case SDL_KEYUP:
            case SDL_KEYDOWN:
                {
                    static int ctrl_down = 0;
                    static int alt_down = 0;
                    static int shift_down = 0;

                    int down = (event->eventType == SDL_KEYDOWN);
                    unsigned long modifier = event->modifier;
                    int ctrl = ((modifier & KEYBOARD_CTRL_FLAG) != 0);
                    int alt = ((modifier & KEYBOARD_ALT_FLAG) != 0);
                    int shift = ((modifier & KEYBOARD_SHIFT_FLAG) != 0);
                    unsigned long kcode = (unsigned long)event->keycode;

                    int kmod = 0;

                    if (ctrl) {
                        kmod |= KMOD_LCTRL;
                    }
                    if (alt) {
                        kmod |= KMOD_LALT;
                    }
                    if (shift) {
                        kmod |= KMOD_LSHIFT;
                    }
                    if (down) {
                        if (ctrl || (kcode == SDLK_TAB)) {
                            if (!ctrl_down) {
                                keyboard_key_pressed((unsigned long)SDLK_TAB);
                            }
                            ctrl_down++;
                        }
                        if (alt || (kcode == SDLK_LCTRL)) {
                            if (!alt_down) {
                                keyboard_key_pressed((unsigned long)SDLK_LCTRL);
                            }
                            alt_down++;
                        }
                        if (shift || (kcode == SDLK_LSHIFT)) {
                            if (!shift_down) {
                                keyboard_key_pressed((unsigned long)SDLK_LSHIFT);
                            }
                            shift_down++;
                        }
                        retval = sdlkbd_press(kcode, 0);
                    } else {
                        retval = sdlkbd_release(kcode, 0);

                        if (ctrl || (kcode == SDLK_TAB)) {
                            if (kcode == SDLK_TAB) {
                                ctrl_down = 0;
                            }
                            if (ctrl_down) {
                                ctrl_down--;
                            }
                            if (!ctrl_down) {
                                keyboard_key_released((unsigned long)SDLK_TAB);
                            }
                        }
                        if (alt || (kcode == SDLK_LCTRL)) {
                            if (kcode == SDLK_LCTRL) {
                                alt_down = 0;
                            }
                            if (alt_down) {
                                alt_down--;
                            }
                            if (!alt_down) {
                                keyboard_key_released((unsigned long)SDLK_LCTRL);
                            }
                        }
                        if (shift || (kcode == SDLK_LSHIFT)) {
                            if (kcode == SDLK_LSHIFT) {
                                shift_down = 0;
                            }
                            if (shift_down) {
                                shift_down--;
                            }
                            if (!shift_down) {
                                keyboard_key_released((unsigned long)SDLK_LSHIFT);
                            }
                        }
                    }
                    stopPoll = 1;
                }
                break;
        }
    }
#else
    while (SDL_PollEvent(&e)) {
        switch (e.type) {
            case SDL_KEYDOWN:
                retval = sdlkbd_press(e.key.keysym.sym, e.key.keysym.mod);
                break;
            case SDL_KEYUP:
                retval = sdlkbd_release(e.key.keysym.sym, e.key.keysym.mod);
                break;
#ifdef HAVE_SDL_NUMJOYSTICKS
            case SDL_JOYAXISMOTION:
                retval = sdljoy_axis_event(e.jaxis.which, e.jaxis.axis, e.jaxis.value);
                break;
            case SDL_JOYBUTTONDOWN:
                retval = sdljoy_button_event(e.jbutton.which, e.jbutton.button, 1);
                break;
            case SDL_JOYBUTTONUP:
                retval = sdljoy_button_event(e.jbutton.which, e.jbutton.button, 0);
                break;
            case SDL_JOYHATMOTION:
                retval = sdljoy_hat_event(e.jhat.which, e.jhat.hat, e.jhat.value);
                break;
#endif
            case SDL_MOUSEMOTION:
                if (_mouse_enabled) {
                    mouse_move((int)(e.motion.xrel), (int)(e.motion.yrel));
                }
                break;
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                if (_mouse_enabled) {
                    mouse_button((int)(e.button.button), (e.button.state == SDL_PRESSED));
                }
                break;
            default:
                /* SDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE); */
                ui_handle_misc_sdl_event(e);
                /* SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE); */
                break;
        }
        /* When using the menu or vkbd, pass every meaningful event to the caller */
        if (((sdl_menu_state) || (sdl_vkbd_state & SDL_VKBD_ACTIVE)) && (retval != MENU_ACTION_NONE) && (retval != MENU_ACTION_NONE_RELEASE)) {
            break;
        }
    }
#endif
    return retval;
}
Ejemplo n.º 14
0
int Retro_PollEvent()
{
    //   RETRO        B    Y    SLT  STA  UP   DWN  LEFT RGT  A    X    L    R    L2   R2   L3   R3
    //   INDEX        0    1    2    3    4    5    6    7    8    9    10   11   12   13   14   15
    //   C64          BOOT VKB  M/J  R/S  UP   DWN  LEFT RGT  B1   GUI  F7   F1   F5   F3   SPC  1

    int SAVPAS=PAS;
    int i;

    input_poll_cb();

    int mouse_l;
    int mouse_r;
    int16_t mouse_x,mouse_y;
    mouse_x=mouse_y=0;

    if(SHOWKEY==-1 && pauseg==0)Process_key();

    if(pauseg==0) {

        i=1;//show vkbd toggle
        if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
            mbt[i]=1;
        else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
        {
            mbt[i]=0;
            SHOWKEY=-SHOWKEY;
            Screen_SetFullUpdate(0);
        }

    }
    i=2;//mouse/joy toggle
    if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
        mbt[i]=1;
    else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) ) {
        mbt[i]=0;
        MOUSE_EMULATED=-MOUSE_EMULATED;
    }
    /*
       i=3;//push r/s
       if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 ){
          mbt[i]=1;kbd_handle_keydown(RETROK_ESCAPE);
       }
       else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) ){
          mbt[i]=0;kbd_handle_keyup(RETROK_ESCAPE));
       }
    */

    if(MOUSE_EMULATED==1) {

        if(slowdown>0)return 1;

        if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT))mouse_x += PAS;
        if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT))mouse_x -= PAS;
        if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN))mouse_y += PAS;
        if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))mouse_y -= PAS;
        mouse_l=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
        mouse_r=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);

        PAS=SAVPAS;

        slowdown=1;
    }
    else {

        mouse_x = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
        mouse_y = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
        mouse_l    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
        mouse_r    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT);
    }

    static int mmbL=0,mmbR=0;

    if(mmbL==0 && mouse_l) {

        mmbL=1;
        pushi=1;
        touch=1;

    }
    else if(mmbL==1 && !mouse_l) {

        mmbL=0;
        pushi=0;
        touch=-1;
    }

    if(mmbR==0 && mouse_r) {
        mmbR=1;
    }
    else if(mmbR==1 && !mouse_r) {
        mmbR=0;
    }

    if(pauseg==0 && c64mouse_enable) {

        mouse_move((int)mouse_x, (int)mouse_y);
        mouse_button(0,mmbL);
        mouse_button(1,mmbR);
    }

    gmx+=mouse_x;
    gmy+=mouse_y;
    if(gmx<0)gmx=0;
    if(gmx>retrow-1)gmx=retrow-1;
    if(gmy<0)gmy=0;
    if(gmy>retroh-1)gmy=retroh-1;



    return 1;

}