当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_GetModState函数代码示例

本文整理汇总了C++中SDL_GetModState函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetModState函数的具体用法?C++ SDL_GetModState怎么用?C++ SDL_GetModState使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_GetModState函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: l_get_key_modifiers

static int l_get_key_modifiers(lua_State *L)
{
    l_push_modifiers_table(L, SDL_GetModState());
    return 1;
}
开发者ID:MarkL1961,项目名称:CorsixTH,代码行数:5,代码来源:sdl_core.cpp

示例2: SDL_GetModState

/**
 * \brief Returns whether the caps lock key is currently active.
 * \return \c true if the caps lock key is currently active.
 */
bool InputEvent::is_caps_lock_on() {

  SDL_Keymod mod = SDL_GetModState();
  return mod & KMOD_CAPS;
}
开发者ID:Codex-NG,项目名称:solarus,代码行数:9,代码来源:InputEvent.cpp

示例3: sdl_refresh

static void sdl_refresh(DisplayState *ds)
{
    SDL_Event ev1, *ev = &ev1;
    int mod_state;
    int buttonstate = SDL_GetMouseState(NULL, NULL);

    if (last_vm_running != vm_running) {
        last_vm_running = vm_running;
        sdl_update_caption();
    }

    vga_hw_update();
    SDL_EnableUNICODE(!is_graphic_console());

    while (SDL_PollEvent(ev)) {
        switch (ev->type) {
        case SDL_VIDEOEXPOSE:
            sdl_update(ds, 0, 0, real_screen->w, real_screen->h);
            break;
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            if (ev->type == SDL_KEYDOWN) {
                if (!alt_grab) {
                    mod_state = (SDL_GetModState() & gui_grab_code) ==
                                gui_grab_code;
                } else {
                    mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
                                (gui_grab_code | KMOD_LSHIFT);
                }
                gui_key_modifier_pressed = mod_state;
                if (gui_key_modifier_pressed) {
                    int keycode;
                    keycode = sdl_keyevent_to_keycode(&ev->key);
                    switch(keycode) {
                    case 0x21: /* 'f' key on US keyboard */
                        toggle_full_screen(ds);
                        gui_keysym = 1;
                        break;
                    case 0x02 ... 0x0a: /* '1' to '9' keys */
                        /* Reset the modifiers sent to the current console */
                        reset_keys();
                        console_select(keycode - 0x02);
                        if (!is_graphic_console()) {
                            /* display grab if going to a text console */
                            if (gui_grab)
                                sdl_grab_end();
                        }
                        gui_keysym = 1;
                        break;
                    default:
                        break;
                    }
                } else if (!is_graphic_console()) {
                    int keysym;
                    keysym = 0;
                    if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
                        default: break;
                        }
                    } else {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break;
                        case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break;
                        case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break;
                        default: break;
                        }
                    }
                    if (keysym) {
                        kbd_put_keysym(keysym);
                    } else if (ev->key.keysym.unicode != 0) {
                        kbd_put_keysym(ev->key.keysym.unicode);
                    }
                }
            } else if (ev->type == SDL_KEYUP) {
                if (!alt_grab) {
                    mod_state = (ev->key.keysym.mod & gui_grab_code);
                } else {
                    mod_state = (ev->key.keysym.mod &
                                 (gui_grab_code | KMOD_LSHIFT));
                }
                if (!mod_state) {
                    if (gui_key_modifier_pressed) {
                        gui_key_modifier_pressed = 0;
                        if (gui_keysym == 0) {
                            /* exit/enter grab if pressing Ctrl-Alt */
//.........这里部分代码省略.........
开发者ID:cailiwei,项目名称:mini2440-qemu,代码行数:101,代码来源:sdl.c

示例4: select_difficulty

bool select_difficulty( void )
{
	JE_loadPic(VGAScreen, 2, false);
	JE_dString(VGAScreen, JE_fontCenter(difficulty_name[0], FONT_SHAPES), 20, difficulty_name[0], FONT_SHAPES);

	difficultyLevel = 2;
	int difficulty_max = 3;

	bool fade_in = true;
	for (; ; )
	{
		for (int i = 1; i <= difficulty_max; i++)
		{
			JE_outTextAdjust(VGAScreen, JE_fontCenter(difficulty_name[i], SMALL_FONT_SHAPES), i * 24 + 30, difficulty_name[i], 15, -4 + (i == difficultyLevel ? 2 : 0), SMALL_FONT_SHAPES, true);
		}
		JE_showVGA();

		if (fade_in)
		{
			fade_palette(colors, 10, 0, 255);
			fade_in = false;
		}

		JE_word temp = 0;
		JE_textMenuWait(&temp, false);

		if (SDL_GetModState() & KMOD_SHIFT)
		{
			if ((difficulty_max < 4 && keysactive[SDLK_g]) ||
			    (difficulty_max == 4 && keysactive[SDLK_RIGHTBRACKET]))
			{
				difficulty_max++;
			}
		} else if (difficulty_max == 5 && keysactive[SDLK_l] && keysactive[SDLK_o] && keysactive[SDLK_r] && keysactive[SDLK_d]) {
			difficulty_max++;
		}

		if (newkey)
		{
			switch (lastkey_sym)
			{
			case SDLK_UP:
				difficultyLevel--;
				if (difficultyLevel < 1)
				{
					difficultyLevel = difficulty_max;
				}
				JE_playSampleNum(S_CURSOR);
				break;
			case SDLK_DOWN:
				difficultyLevel++;
				if (difficultyLevel > difficulty_max)
				{
					difficultyLevel = 1;
				}
				JE_playSampleNum(S_CURSOR);
				break;

			case SDLK_RETURN:
				JE_playSampleNum(S_SELECT);
				/* fading handled elsewhere
				fade_black(10); */

				if (difficultyLevel == 6)
				{
					difficultyLevel = 8;
				} else if (difficultyLevel == 5) {
					difficultyLevel = 6;
				}
				return true;

			case SDLK_ESCAPE:
				JE_playSampleNum(S_SPRING);
				/* fading handled elsewhere
				fade_black(10); */

				return false;

			default:
				break;
			}
		}
	}
}
开发者ID:EuPhobos,项目名称:opentyrian,代码行数:84,代码来源:menus.c

示例5: switch

void Runtime::pollEvents(bool blocking) {
  if (isActive() && !isRestart()) {
    SDL_Event ev;
    SDL_Keymod mod;
    if (blocking ? SDL_WaitEvent(&ev) : SDL_PollEvent(&ev)) {
      MAEvent *maEvent = NULL;
      switch (ev.type) {
      case SDL_TEXTINPUT:
        // pre-transformed/composted text
        mod = SDL_GetModState();
        if (!mod || (mod & (KMOD_SHIFT|KMOD_CAPS))) {
          // ALT + CTRL keys handled in SDL_KEYDOWN
          for (int i = 0; ev.text.text[i] != 0; i++) {
            MAEvent *keyEvent = new MAEvent();
            keyEvent->type = EVENT_TYPE_KEY_PRESSED;
            keyEvent->key = ev.text.text[i];
            keyEvent->nativeKey = 0;
            pushEvent(keyEvent);
          }
        }
        break;
      case SDL_QUIT:
        setExit(true);
        break;
      case SDL_KEYDOWN:
        if (!isEditing() && ev.key.keysym.sym == SDLK_c
            && (ev.key.keysym.mod & KMOD_CTRL)) {
          setExit(true);
        } else if (ev.key.keysym.sym == SDLK_m && (ev.key.keysym.mod & KMOD_CTRL)) {
          showMenu();
        } else if (ev.key.keysym.sym == SDLK_b && (ev.key.keysym.mod & KMOD_CTRL)) {
          setBack();
        } else if (ev.key.keysym.sym == SDLK_BACKSPACE &&
                   get_focus_edit() == NULL &&
                   ((ev.key.keysym.mod & KMOD_CTRL) || !isRunning())) {
          setBack();
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEUP &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(true, true);
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEDOWN &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(false, true);
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_UP &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(true, false);
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_DOWN &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(false, false);
        } else if (ev.key.keysym.sym == SDLK_p && (ev.key.keysym.mod & KMOD_CTRL)) {
          ::screen_dump();
        } else {
          int lenMap = sizeof(keymap) / sizeof(keymap[0]);
          for (int i = 0; i < lenMap; i++) {
            if (ev.key.keysym.sym == keymap[i][0]) {
              maEvent = new MAEvent();
              maEvent->type = EVENT_TYPE_KEY_PRESSED;
              maEvent->key = keymap[i][1];
              maEvent->nativeKey = ev.key.keysym.mod;
              break;
            }
          }
          if (maEvent == NULL &&
              ((ev.key.keysym.sym >= SDLK_KP_1 && ev.key.keysym.sym <= SDLK_KP_9) ||
               ((ev.key.keysym.mod & KMOD_CTRL) &&
                ev.key.keysym.sym != SDLK_LSHIFT &&
                ev.key.keysym.sym != SDLK_RSHIFT &&
                ev.key.keysym.sym != SDLK_LCTRL &&
                ev.key.keysym.sym != SDLK_RCTRL) ||
               (ev.key.keysym.mod & KMOD_ALT))) {
            maEvent = new MAEvent();
            maEvent->type = EVENT_TYPE_KEY_PRESSED;
            maEvent->key = ev.key.keysym.sym;
            maEvent->nativeKey = ev.key.keysym.mod;
          }
        }
        break;
      case SDL_MOUSEBUTTONDOWN:
        if (ev.button.button == SDL_BUTTON_RIGHT) {
          _menuX = ev.motion.x;
          _menuY = ev.motion.y;
          showMenu();
        } else if (ev.motion.x != 0 && ev.motion.y != 0) {
          // avoid phantom down message when launching in windows
          maEvent = getMotionEvent(EVENT_TYPE_POINTER_PRESSED, &ev);
        }
        break;
      case SDL_MOUSEMOTION:
        maEvent = getMotionEvent(EVENT_TYPE_POINTER_DRAGGED, &ev);
        break;
      case SDL_MOUSEBUTTONUP:
        SDL_SetCursor(_cursorArrow);
        maEvent = getMotionEvent(EVENT_TYPE_POINTER_RELEASED, &ev);
        break;
      case SDL_WINDOWEVENT:
        switch (ev.window.event) {
        case SDL_WINDOWEVENT_FOCUS_GAINED:
          SDL_SetModState(KMOD_NONE);
          break;
        case SDL_WINDOWEVENT_RESIZED:
          onResize(ev.window.data1, ev.window.data2);
//.........这里部分代码省略.........
开发者ID:MarcusWellby,项目名称:SmallBASIC,代码行数:101,代码来源:runtime.cpp

示例6: GetTypedChar

// Get the equivalent ASCII (Unicode?) character for a keypress.
static int GetTypedChar(SDL_Keysym *sym)
{
    // We only return typed characters when entering text, after
    // I_StartTextInput() has been called. Otherwise we return nothing.
    if (!text_input_enabled)
    {
        return 0;
    }

    // If we're strictly emulating Vanilla, we should always act like
    // we're using a US layout keyboard (in ev_keydown, data1=data2).
    // Otherwise we should use the native key mapping.
    if (vanilla_keyboard_mapping)
    {
        int result = TranslateKey(sym);

        // If shift is held down, apply the original uppercase
        // translation table used under DOS.
        if ((SDL_GetModState() & KMOD_SHIFT) != 0
         && result >= 0 && result < arrlen(shiftxform))
        {
            result = shiftxform[result];
        }

        return result;
    }
    else
    {
        SDL_Event next_event;

        // Special cases, where we always return a fixed value.
        switch (sym->sym)
        {
            case SDLK_BACKSPACE: return KEY_BACKSPACE;
            case SDLK_RETURN:    return KEY_ENTER;
            default:
                break;
        }

        // The following is a gross hack, but I don't see an easier way
        // of doing this within the SDL2 API (in SDL1 it was easier).
        // We want to get the fully transformed input character associated
        // with this keypress - correct keyboard layout, appropriately
        // transformed by any modifier keys, etc. So peek ahead in the SDL
        // event queue and see if the key press is immediately followed by
        // an SDL_TEXTINPUT event. If it is, it's reasonable to assume the
        // key press and the text input are connected. Technically the SDL
        // API does not guarantee anything of the sort, but in practice this
        // is what happens and I've verified it through manual inspect of
        // the SDL source code.
        //
        // In an ideal world we'd split out ev_keydown into a separate
        // ev_textinput event, as SDL2 has done. But this doesn't work
        // (I experimented with the idea), because lots of Doom's code is
        // based around different responders "eating" events to stop them
        // being passed on to another responder. If code is listening for
        // a text input, it cannot block the corresponding keydown events
        // which can affect other responders.
        //
        // So we're stuck with this as a rather fragile alternative.

        if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT,
                           SDL_FIRSTEVENT, SDL_LASTEVENT) == 1
         && next_event.type == SDL_TEXTINPUT)
        {
            // If an SDL_TEXTINPUT event is found, we always assume it
            // matches the key press. The input text must be a single
            // ASCII character - if it isn't, it's possible the input
            // char is a Unicode value instead; better to send a null
            // character than the unshifted key.
            if (strlen(next_event.text.text) == 1
             && (next_event.text.text[0] & 0x80) == 0)
            {
                return next_event.text.text[0];
            }
        }

        // Failed to find anything :/
        return 0;
    }
}
开发者ID:Azarien,项目名称:chocolate-doom,代码行数:82,代码来源:i_input.c

示例7: fixedModifiers

Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseMoveEvent::modifiers() {
    if(modifiersLoaded) return _modifiers;
    modifiersLoaded = true;
    return _modifiers = fixedModifiers(Uint16(SDL_GetModState()));
}
开发者ID:smspillaz,项目名称:magnum,代码行数:5,代码来源:Sdl2Application.cpp

示例8: main

int main(int argc, char *argv[])
{
  SDL_Init(SDL_INIT_VIDEO);
  SDL_WM_SetCaption("La grue !", NULL);
  SDL_SetVideoMode(LARGEUR_ECRAN, HAUTEUR_ECRAN, 32, SDL_OPENGL);
  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0, LARGEUR_ECRAN, 0, HAUTEUR_ECRAN);
  

  bool continuer = true;
  SDL_Event event;
  SDLMod mod = KMOD_NONE;

  int angle_grand_bras = 45;
  int angle_petit_bras = -10;
  int longueur_fils = 50;

  while (continuer)
    {
      SDL_WaitEvent(&event);
      mod = SDL_GetModState();
      switch(event.type)
        {
	case SDL_QUIT:
	  continuer = false;
	  break;
	case SDL_KEYDOWN:
	  switch (event.key.keysym.sym)
            {
	    case SDLK_ESCAPE: /* Appui sur la touche Echap, on arrête le programme */
	      continuer = false;
	      break;
	    case SDLK_UP:
	      if (longueur_fils > LONGUEUR_FILS_MIN)
		longueur_fils -= 1;
	      break;
	    case SDLK_DOWN:
	      if (longueur_fils < LONGUEUR_FILS_MAX)
		longueur_fils += 1;
	      break;
	    case SDLK_LEFT:
	      if (mod & KMOD_SHIFT) {
		if (angle_grand_bras < ANGLE_GD_BRAS_MAX)
		  angle_grand_bras += 5;
	      } else {
		if (angle_petit_bras < ANGLE_PT_BRAS_MAX)
		  angle_petit_bras += 5;
	      }
	      break;
	    case SDLK_RIGHT:
	      if (mod & KMOD_SHIFT) {
		if (angle_grand_bras > ANGLE_GD_BRAS_MIN)
		  angle_grand_bras -= 5;
	      } else {
		if (angle_petit_bras > ANGLE_PT_BRAS_MIN)
		  angle_petit_bras -= 5;
	      }
	      break;
	    case SDLK_h:
	      /* dessinerRepere(50); */
	      break;
	    default:
	      break;
            }
	  break;
	default:
	  break;
        }

      /* efface le tampon d'affichage */
      glClear(GL_COLOR_BUFFER_BIT);

      /* dessine */

      /* base */
      glPushMatrix();
      glTranslated(20, 20, 0);
      glBegin(GL_QUADS);
      glColor3ub(255, 150, 0);
      glVertex2d(0, 0);
      glVertex2d(0, 40);
      glVertex2d(100, 40);
      glVertex2d(100, 0);
      glEnd();
      glPopMatrix();

      /* grand bras */
      glPushMatrix();
      glTranslated(70, 60, 0);
      glRotated(angle_grand_bras, 0, 0, 1);
      glBegin(GL_QUADS);
      glColor3ub(255, 250, 0);
      glVertex2d(0, -15);
      glVertex2d(0, 15);
      glVertex2d(LONGUEUR_GD_BRAS, 15);
      glVertex2d(LONGUEUR_GD_BRAS, -15);
      glEnd();
//.........这里部分代码省略.........
开发者ID:ARO17,项目名称:prog,代码行数:101,代码来源:grue_opengl.cpp

示例9: handle_keydown

static void handle_keydown(DisplayState *ds, SDL_Event *ev)
{
    int mod_state;
    int keycode;

    if (alt_grab) {
//    	LOGV("Found alt grab\n");
        mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
                    (gui_grab_code | KMOD_LSHIFT);
    } else if (ctrl_grab) {
//    	LOGV("Found ctrl grab\n");
        mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
    } else {
//    	LOGV("Default grab\n");
        mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code;
    }
    gui_key_modifier_pressed = mod_state;

    if (gui_key_modifier_pressed) {
        keycode = sdl_keyevent_to_keycode(&ev->key);
//        LOGV("Found modifier pressed for key/keycode = %d/%d\n", ev->key.keysym.sym, keycode);
        switch (keycode) {
        case 1: /* 'f' key on US keyboard */
        	LOGV("Keycode Pressed 'f' Fullscreen\n");
            toggle_full_screen(ds);
            gui_keysym = 1;
            break;
        case 16: /* 'u' key on US keyboard */
        	LOGV("Keycode Pressed 'u' unset Scale\n");
            if (scaling_active) {
            	LOGV("Found scaling active Unsetting...\n");
                scaling_active = 0;
                sdl_resize(ds);
                vga_hw_invalidate();
                vga_hw_update();
                reset_keys();
            }
            gui_keysym = 1;
            break;

        case 22 ... 23: /* '1' to '9' keys */ //MK hack
            /* Reset the modifiers sent to the current console */
        	LOGV("Keycode Pressed '1-9' console\n");
            reset_keys();
            console_select(keycode - 22);
            gui_keysym = 1;
//            if (gui_fullscreen) {
//            	LOGV("Found fullscreen breaking...\n");
//                break;
//            }
            if (!is_graphic_console()) {
                /* release grab if going to a text console */
            	LOGV("Found text console releasing grab...\n");
                if (gui_grab) {
                	LOGV("Found grab, grab ending...\n");
                    sdl_grab_end();
                } else if (absolute_enabled) {
                	LOGV("Found absolute_enabled, show cursor...\n");
                    sdl_show_cursor();
                }
            } else if (absolute_enabled) {
            	LOGV("Found absolute_enabled, hiding cursor and grabing mouse...\n");
                sdl_hide_cursor();
                absolute_mouse_grab();
            }
            break;
        case 24: /* '4' Zoom In */
        case 25: /* '3' Zoom Out*/
        	LOGV("Keycode Pressed '3/4' Zoom\n");
//            if (!gui_fullscreen) {
        	{

                int width = MAX(real_screen->w + (keycode == 25 ? 50 : -50),
                                160);
                int height = (ds_get_height(ds) * width) / ds_get_width(ds);
                LOGV("Found no fullscreen, scaling to: %dx%d \n", width, height);
                sdl_scale(ds, width, height);
                vga_hw_invalidate();
                vga_hw_update();
                reset_keys();
                gui_keysym = 1;
        	}
//            }
            break;
        case 26: /* Fit to Screen */
        	LOGV("Keycode Pressed '5' Fit to Screen\n");
//            if (!gui_fullscreen) {
        	{
            	int width;
            	int height;
            	AndroidGetWindowSize(&width, &height);
            	LOGV("Got Android window size=%dx%d", width, height);
            	LOGV("Got VM  resolution=%dx%d", ds_get_width(ds), ds_get_height(ds));
            	float aspectRatio = (float) ds_get_height(ds) / (float) ds_get_width(ds);
            	LOGV("Got aspectRatio=%f", aspectRatio);
            	int new_width = (int) (height / aspectRatio);
            	if(new_width > width){
            		LOGV("Width is overrun, modifying height");
            		new_width = width;
            		height = width * aspectRatio;
//.........这里部分代码省略.........
开发者ID:yoshikirby43,项目名称:seancatiebenwill-coolpc,代码行数:101,代码来源:sdl.c

示例10: Sys_GetEvent

/*
================
Sys_GetEvent
================
*/
sysEvent_t Sys_GetEvent() {
	SDL_Event ev;
	sysEvent_t res = { };
	byte key;

	static const sysEvent_t res_none = { SE_NONE, 0, 0, 0, NULL };

#if SDL_VERSION_ATLEAST(2, 0, 0)
	static char *s = NULL;
	static size_t s_pos = 0;

	if (s) {
		res.evType = SE_CHAR;
		res.evValue = s[s_pos];

		s_pos++;
		if (!s[s_pos]) {
			free(s);
			s = NULL;
			s_pos = 0;
		}

		return res;
	}
#endif

	static byte c = 0;

	if (c) {
		res.evType = SE_CHAR;
		res.evValue = c;

		c = 0;

		return res;
	}

	if (SDL_PollEvent(&ev)) {
		switch (ev.type) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
		case SDL_WINDOWEVENT:
			switch (ev.window.event) {
				case SDL_WINDOWEVENT_FOCUS_GAINED: {
						// unset modifier, in case alt-tab was used to leave window and ALT is still set
						// as that can cause fullscreen-toggling when pressing enter...
						SDL_Keymod currentmod = SDL_GetModState();
					
						int newmod = KMOD_NONE;
						if (currentmod & KMOD_CAPS) // preserve capslock
							newmod |= KMOD_CAPS;

						SDL_SetModState((SDL_Keymod)newmod);
					} // new context because visual studio complains about newmod and currentmod not initialized because of the case SDL_WINDOWEVENT_FOCUS_LOST

					GLimp_GrabInput(GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR);
					break;
				case SDL_WINDOWEVENT_FOCUS_LOST:
					GLimp_GrabInput(0);
					break;
			}

			return res_none;
#else
		case SDL_ACTIVEEVENT:
			{
				int flags = 0;

				if (ev.active.gain) {
					flags = GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR;

					// unset modifier, in case alt-tab was used to leave window and ALT is still set
					// as that can cause fullscreen-toggling when pressing enter...
					SDLMod currentmod = SDL_GetModState();
					int newmod = KMOD_NONE;
					if (currentmod & KMOD_CAPS) // preserve capslock
						newmod |= KMOD_CAPS;

					SDL_SetModState((SDLMod)newmod);
				}

				GLimp_GrabInput(flags);
			}

			return res_none;

		case SDL_VIDEOEXPOSE:
			return res_none;
#endif

		case SDL_KEYDOWN:
			if (ev.key.keysym.sym == SDLK_RETURN && (ev.key.keysym.mod & KMOD_ALT) > 0) {
				cvarSystem->SetCVarBool("r_fullscreen", !renderSystem->IsFullScreen());
				PushConsoleEvent("vid_restart");
				return res_none;
			}
//.........这里部分代码省略.........
开发者ID:Debug-,项目名称:dhewm3,代码行数:101,代码来源:events.cpp

示例11: _process_mouse_event

static int _process_mouse_event(void)
{
    SDLMod keymods;
    short shift_flags = 0;

    memset(&pdc_mouse_status, 0, sizeof(MOUSE_STATUS));

    keymods = SDL_GetModState();

    if (keymods & KMOD_SHIFT)
        shift_flags |= BUTTON_SHIFT;

    if (keymods & KMOD_CTRL)
        shift_flags |= BUTTON_CONTROL;

    if (keymods & KMOD_ALT)
        shift_flags |= BUTTON_ALT;

    if (event.type == SDL_MOUSEMOTION)
    {
        int i;

        pdc_mouse_status.x = event.motion.x / pdc_fwidth;
        pdc_mouse_status.y = event.motion.y / pdc_fheight;

        if (!event.motion.state ||
           (pdc_mouse_status.x == old_mouse_status.x &&
            pdc_mouse_status.y == old_mouse_status.y))
            return -1;

        pdc_mouse_status.changes = PDC_MOUSE_MOVED;

        for (i = 0; i < 3; i++)
        {
            if (event.motion.state & SDL_BUTTON(i + 1))
            {
                pdc_mouse_status.button[i] = BUTTON_MOVED | shift_flags;
                pdc_mouse_status.changes |= (1 << i);
            }
        }
    }
    else
    {
        short action = (event.button.state == SDL_PRESSED) ?
                       BUTTON_PRESSED : BUTTON_RELEASED;
        Uint8 btn = event.button.button;

        /* handle scroll wheel */

        if ((btn == 4 || btn == 5) && action == BUTTON_RELEASED)
        {
            pdc_mouse_status.x = pdc_mouse_status.y = -1;

            pdc_mouse_status.changes = (btn == 5) ?
                PDC_MOUSE_WHEEL_DOWN : PDC_MOUSE_WHEEL_UP;

            return KEY_MOUSE;
        }

        if (btn < 1 || btn > 3)
            return -1;

        /* check for a click -- a press followed immediately by a release */

        if (action == BUTTON_PRESSED && SP->mouse_wait)
        {
            SDL_Event rel;

            napms(SP->mouse_wait);

            if (SDL_PollEvent(&rel))
            {
                if (rel.type == SDL_MOUSEBUTTONUP && rel.button.button == btn)
                    action = BUTTON_CLICKED;
                else
                    SDL_PushEvent(&rel);
            }
        }

        pdc_mouse_status.x = event.button.x / pdc_fwidth;
        pdc_mouse_status.y = event.button.y / pdc_fheight;

        btn--;

        pdc_mouse_status.button[btn] = action | shift_flags;
        pdc_mouse_status.changes = (1 << btn);
    }

    old_mouse_status = pdc_mouse_status;

    return KEY_MOUSE;
}
开发者ID:freddyb,项目名称:curses.js,代码行数:92,代码来源:pdckbd.c

示例12: switch

/**
 * Handles screen key shortcuts.
 * @param action Pointer to an action.
 */
void Screen::handle(Action *action)
{
	if (Options::debug)
	{
		if (action->getDetails()->type == SDL_KEYDOWN && action->getDetails()->key.keysym.sym == SDLK_F8)
		{
			switch(Timer::gameSlowSpeed)
			{
				case 1: Timer::gameSlowSpeed = 5; break;
				case 5: Timer::gameSlowSpeed = 15; break;
				default: Timer::gameSlowSpeed = 1; break;
			}
		}
	}
	
	if (action->getDetails()->type == SDL_KEYDOWN && action->getDetails()->key.keysym.sym == SDLK_RETURN && (SDL_GetModState() & KMOD_ALT) != 0)
	{
		Options::fullscreen = !Options::fullscreen;
		resetDisplay();
	}
	else if (action->getDetails()->type == SDL_KEYDOWN && action->getDetails()->key.keysym.sym == Options::keyScreenshot)
	{
		std::ostringstream ss;
		int i = 0;
		do
		{
			ss.str("");
			ss << Options::getMasterUserFolder() << "screen" << std::setfill('0') << std::setw(3) << i << ".png";
			i++;
		}
		while (CrossPlatform::fileExists(ss.str()));
		screenshot(ss.str());
		return;
	}
}
开发者ID:AndO3131,项目名称:OpenXcom,代码行数:39,代码来源:Screen.cpp

示例13: SDL_GetMouseState

void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
{
	if(!enabled())
		return;

	scrollarea::handle_event(event);
	if(hidden())
		return;

	bool changed = false;

	const int old_selstart = selstart_;
	const int old_selend = selend_;

	//Sanity check: verify that selection start and end are within text
	//boundaries
	if(is_selection() && !(size_t(selstart_) <= text_.size() && size_t(selend_) <= text_.size())) {
		WRN_DP << "out-of-boundary selection\n";
		selstart_ = selend_ = -1;
	}

	int mousex, mousey;
	const Uint8 mousebuttons = SDL_GetMouseState(&mousex,&mousey);
	if(!(mousebuttons & SDL_BUTTON(1))) {
		grabmouse_ = false;
	}

	SDL_Rect const &loc = inner_location();
	bool clicked_inside = !mouse_locked() && (event.type == SDL_MOUSEBUTTONDOWN
					   && (mousebuttons & SDL_BUTTON(1))
					   && point_in_rect(mousex, mousey, loc));
	if(clicked_inside) {
		set_focus(true);
	}
	if ((grabmouse_ && (!mouse_locked() && event.type == SDL_MOUSEMOTION)) || clicked_inside) {
		const int x = mousex - loc.x + text_pos_;
		const int y = mousey - loc.y;
		int pos = 0;
		int distance = x;

		for(unsigned int i = 1; i < char_x_.size(); ++i) {
			if(static_cast<int>(yscroll_) + y < char_y_[i]) {
				break;
			}

			// Check individually each distance (if, one day, we support
			// RTL languages, char_x_[c] may not be monotonous.)
			if(abs(x - char_x_[i]) < distance && yscroll_ + y < char_y_[i] + line_height_) {
				pos = i;
				distance = abs(x - char_x_[i]);
			}
		}

		cursor_ = pos;

		if(grabmouse_)
			selend_ = cursor_;

		update_text_cache(false);

		if(!grabmouse_ && mousebuttons & SDL_BUTTON(1)) {
			grabmouse_ = true;
			selstart_ = selend_ = cursor_;
		} else if (! (mousebuttons & SDL_BUTTON(1))) {
			grabmouse_ = false;
		}

		set_dirty();
	}

	//if we don't have the focus, then see if we gain the focus,
	//otherwise return
	if(!was_forwarded && focus(&event) == false) {
		if (!mouse_locked() && event.type == SDL_MOUSEMOTION && point_in_rect(mousex, mousey, loc))
			events::focus_handler(this);

		return;
	}

	if(event.type != SDL_KEYDOWN || (!was_forwarded && focus(&event) != true)) {
		draw();
		return;
	}

	const SDL_keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym;
	const SDLMod modifiers = SDL_GetModState();

	const int c = key.sym;
	const int old_cursor = cursor_;

	if(editable_) {
		if(c == SDLK_LEFT && cursor_ > 0)
			--cursor_;

		if(c == SDLK_RIGHT && cursor_ < static_cast<int>(text_.size()))
			++cursor_;

		// ctrl-a, ctrl-e and ctrl-u are readline style shortcuts, even on Macs
		if(c == SDLK_END || (c == SDLK_e && (modifiers & KMOD_CTRL)))
			cursor_ = text_.size();
//.........这里部分代码省略.........
开发者ID:Aishiko,项目名称:wesnoth,代码行数:101,代码来源:textbox.cpp

示例14: show

void SDLViewer::execute()
{
  bool redisplay = true;
  MouseButton button = NoButton;
  unsigned char key;
  int x, y;
  SDL_Event event;
  int modifiers = 0;
  static unsigned int stimer;

  //Ensure window visible for interaction
  show();

  // Enter event loop processing
  while ( !quitProgram )
  {
    // Check for events
    // Delay redisplay & resize until event queue empty
    if (SDL_PollEvent(&event) == 0)
    {
      // Resize window
      if (resized)
      {
        if (stimer < SDL_GetTicks())
        {
          // Create in new dimensions
          resized = false;
          open(width, height);
          redisplay = true;
        }
        else
          continue;   //Cycle until timer runs out
      }

      if (redisplay)
      {
        // Redraw Viewer (Call virtual to display)
        display();
        redisplay = false;
      }

      // Wait for next event
      SDL_WaitEvent( &event );
    }

    //Save shift states
    modifiers = SDL_GetModState();
    keyState.shift = (modifiers & KMOD_SHIFT);
    keyState.ctrl = (modifiers & KMOD_CTRL);
    keyState.alt = (modifiers & KMOD_ALT);

    // Process event
    switch (event.type)
    {
    case SDL_QUIT:
      quitProgram = true;
      break;
    case SDL_VIDEORESIZE:
      //Adjust viewport metrics etc...
      resize(event.resize.w, event.resize.h);
      resized = true;
      //Start timer to wait for sizing events to cease before calling actual context resize
      stimer = SDL_GetTicks() + 200;
      break;
    case SDL_KEYDOWN:
      //Pass keystrokes on KEYDOWN only, char info not provided by SDL on KEYUP
      key = event.key.keysym.unicode;
      if (!key)
      {
        int code = (int)event.key.keysym.sym;
        if (code == SDLK_KP8 || code == SDLK_UP) key = KEY_UP;
        if (code == SDLK_KP2 || code == SDLK_DOWN) key = KEY_DOWN;
        if (code == SDLK_KP4 || code == SDLK_LEFT) key = KEY_LEFT;
        if (code == SDLK_KP6 || code == SDLK_RIGHT) key = KEY_RIGHT;
        if (code == SDLK_KP9 || code == SDLK_PAGEUP) key = KEY_PAGEUP;
        if (code == SDLK_KP3 || code == SDLK_PAGEDOWN) key = KEY_PAGEDOWN;
        if (code == SDLK_KP7 || code == SDLK_HOME) key = KEY_HOME;
        if (code == SDLK_KP1 || code == SDLK_END) key = KEY_END;
        //key = (unsigned char)code;
        if (!key) continue;
      }
      SDL_GetMouseState(&x, &y);
      if (keyPress(key, x, y)) redisplay = true;
      break;
    case SDL_MOUSEMOTION:
      if (mouseState)
      {
        mouseMove(event.motion.x, event.motion.y);
        redisplay = true;
      }
      break;
    case SDL_MOUSEBUTTONDOWN:
      button = (MouseButton)event.button.button;
      // XOR state of three mouse buttons to the mouseState variable
      if (button <= RightButton) mouseState ^= (int)pow(2.0,button);
      mousePress( button, true, event.button.x, event.button.y);
      break;
    case SDL_MOUSEBUTTONUP:
      mouseState = 0;
      button = (MouseButton)event.button.button;
//.........这里部分代码省略.........
开发者ID:lmoresi,项目名称:LavaVu,代码行数:101,代码来源:SDLViewer.cpp

示例15: WinMain

int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine, int nCmdShow)
{
#else
int main(int argc, char** argv) {
#endif

	SDL_Surface *screen_sfc;
	F1SpiritApp *game;
	KEYBOARDSTATE *k;

	int time, act_time;
	SDL_Event event;
	bool quit = false;
	bool need_to_redraw = true;

#ifdef F1SPIRIT_DEBUG_MESSAGES

	output_debug_message("Application started\n");
#endif
#ifdef HAVE_GLES
	fullscreen = true;
#endif
	screen_sfc = initialization((fullscreen ? SDL_FULLSCREEN : 0));

	if (screen_sfc == 0)
		return 0;

	k = new KEYBOARDSTATE();

	game = new F1SpiritApp();

	#if 0//ndef HAVE_GLES
	// why recreating the context ???
	if (fullscreen) {
	#ifdef HAVE_GLES
		EGL_Close();
		screen_sfc = SDL_SetVideoMode((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y, COLOUR_DEPTH, (fullscreen ? SDL_FULLSCREEN : 0));
		EGL_Open((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y);
	#else
		screen_sfc = SDL_SetVideoMode((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y, COLOUR_DEPTH, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0));
	#endif
		SDL_WM_SetCaption(application_name, 0);
		SDL_ShowCursor(SDL_DISABLE);
		reload_textures++;

	#ifndef HAVE_GLES
		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	#endif
	} 
	#endif

	time = init_time = SDL_GetTicks();
	
	IMG_Init(IMG_INIT_JPG|IMG_INIT_PNG);

	while (!quit) {
		while ( SDL_PollEvent( &event ) ) {
			switch ( event.type ) {
					/* Keyboard event */

				case SDL_KEYDOWN:
#ifdef __APPLE__

					if (event.key.keysym.sym == SDLK_q) {
						SDLMod modifiers;
						modifiers = SDL_GetModState();

						if ((modifiers &KMOD_META) != 0) {
							quit = true;
						}
					}

#else
					if (event.key.keysym.sym == SDLK_F12) {
						quit = true;
					} 

#endif
					if (event.key.keysym.sym == SDLK_F10) {
						game->save_configuration("f1spirit.cfg");
						game->load_configuration("f1spirit.cfg");
					} 

#ifdef _WIN32
					if (event.key.keysym.sym == SDLK_F4) {
						SDLMod modifiers;

						modifiers = SDL_GetModState();

						if ((modifiers&KMOD_ALT) != 0)
							quit = true;
					} 

#endif
#ifdef __APPLE__
					if (event.key.keysym.sym == SDLK_f) {
//.........这里部分代码省略.........
开发者ID:ptitSeb,项目名称:f1spirit,代码行数:101,代码来源:main.cpp


注:本文中的SDL_GetModState函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。