Example #1
0
GUI_status InputDialog::KeyDown(SDL_keysym key) {
	KeyBinder *keybinder = Game::get_game()->get_keybinder();
	ActionType a = keybinder->get_ActionType(key);

	switch(keybinder->GetActionKeyType(a))
	{
		case NORTH_KEY:
		case WEST_KEY:
			if(b_index_num != -1)
				button_index[b_index_num]->set_highlighted(false);

			if(b_index_num <= 0)
				b_index_num = last_index;
			else
				b_index_num = b_index_num - 1;
			button_index[b_index_num]->set_highlighted(true); break;
		case SOUTH_KEY:
		case EAST_KEY:
			if(b_index_num != -1)
				button_index[b_index_num]->set_highlighted(false);

			if(b_index_num == last_index)
				b_index_num = 0;
			else
				b_index_num += 1;
			button_index[b_index_num]->set_highlighted(true); break;
		case DO_ACTION_KEY: if(b_index_num != -1) return button_index[b_index_num]->Activate_button(); break;
		case CANCEL_ACTION_KEY: return close_dialog();
		default: keybinder->handle_always_available_keys(a); break;
	}
	return GUI_YUM;
}
Example #2
0
GUI_status GUI_TextInput::KeyDown(SDL_keysym key)
{
// char ascii;
 char ascii = 0;

 if(!focused)
   return GUI_PASS;
 if((key.unicode & 0xFF80) == 0) // high 9bits 0 == ascii code
   ascii = (char)(key.unicode & 0x7F); // (in low 7bits)

 if(!isprint(ascii) && key.sym != SDLK_BACKSPACE)
 {
    KeyBinder *keybinder = Game::get_game()->get_keybinder();
    ActionType a = keybinder->get_ActionType(key);
    switch(keybinder->GetActionKeyType(a))
    {
      case NORTH_KEY: key.sym = SDLK_UP; break;
      case SOUTH_KEY: key.sym = SDLK_DOWN; break;
      case WEST_KEY: key.sym = SDLK_LEFT; break;
      case EAST_KEY: key.sym = SDLK_RIGHT; break;
      case TOGGLE_CURSOR_KEY: release_focus(); return GUI_PASS; // can tab through to SaveDialog
      case DO_ACTION_KEY: key.sym = SDLK_RETURN; break;
      case CANCEL_ACTION_KEY: key.sym = SDLK_ESCAPE; break;
      case HOME_KEY: key.sym = SDLK_HOME;
      case END_KEY: key.sym = SDLK_END;
      default : if(keybinder->handle_always_available_keys(a)) return GUI_YUM; break;
    }
 }

 switch(key.sym)
   {
    case SDLK_LSHIFT   :
    case SDLK_RSHIFT   :
    case SDLK_LCTRL    :
    case SDLK_RCTRL    :
    case SDLK_CAPSLOCK : break;

    case SDLK_KP_ENTER:
    case SDLK_RETURN : if(callback_object)
                         callback_object->callback(TEXTINPUT_CB_TEXT_READY, this, text);
    case SDLK_ESCAPE : release_focus(); break;

    case SDLK_HOME : pos = 0; break;
    case SDLK_END  : pos = length; break;

    case SDLK_KP4  :
    case SDLK_LEFT : if(pos > 0)
                       pos--;
                     break;

    case SDLK_KP6   :
    case SDLK_RIGHT : if(pos < length)
                       pos++;
                      break;

    case SDLK_DELETE    : if(pos < length) //delete the character to the right of the cursor
                            {
                             pos++;
                             remove_char(); break;
                            }
                          break;

    case SDLK_BACKSPACE : remove_char(); break; //delete the character to the left of the cursor

    case SDLK_UP :
    case SDLK_KP8 :
                    if(pos == length)
                    {
                        if(length+1 > max_width * max_height)
                            break;
                        length++;
                        if(pos == 0 || text[pos-1] == ' ')
                            text[pos] = 'A';
                        else
                            text[pos] = 'a';
                        break;
                    }
                    text[pos]++;
                    // We want alphanumeric characters or space
                    if(text[pos] < ' ' || text[pos] > 'z')
                    {
                        text[pos] = ' ';
                        break;
                    }
                    while(!isalnum(text[pos]))
                        text[pos]++;
                    break;

    case SDLK_KP2 :
    case SDLK_DOWN : if(pos == length)
                     {
                         if(length+1 > max_width * max_height)
                             break;
                         length++;
                         if(pos == 0 || text[pos-1] == ' ')
                             text[pos] = 'Z';
                         else
                             text[pos] = 'z';
                         break;
                     }
                     text[pos]--;
                     // We want alphanumeric characters or space
                     if(text[pos] < ' ' || text[pos] > 'z')
                     {
                         text[pos] = 'z';
                         break;
                     }
                     else if(text[pos] < '0')
                     {
                         text[pos] = ' ';
                         break;
                     }
                     while(!isalnum(text[pos]))
                         text[pos]--;
                     break;

    default :
              if(isprint(ascii))
                  add_char(ascii); break;
   }



 return(GUI_YUM);
}
Example #3
0
GUI_status CommandBarNewUI::KeyDown(SDL_keysym key)
{
    KeyBinder *keybinder = Game::get_game()->get_keybinder();
    ActionType a = keybinder->get_ActionType(key);

    switch(keybinder->GetActionKeyType(a))
    {
        case NORTH_KEY:
        	do
        	{
				if(cur_pos - icon_w < 0)
					cur_pos = icon_w * icon_h - (icon_w - cur_pos%icon_w);
				else
					cur_pos -= icon_w;
        	} while(cur_pos >= num_icons);
            break;
        case SOUTH_KEY:
        	do
        	{
        		cur_pos = (cur_pos + icon_w) % (icon_w * icon_h);
        	} while(cur_pos >= num_icons);
            break;
        case WEST_KEY:
        	do
        	{
				if(cur_pos%icon_w == 0)
					cur_pos = (cur_pos/icon_w)*icon_w+icon_w-1;
				else
					cur_pos--;
        	} while(cur_pos >= num_icons);
            break;
        case EAST_KEY:
        	do
        	{
        		cur_pos = (cur_pos/icon_w)*icon_w + (cur_pos+1) % icon_w;
        	} while(cur_pos >= num_icons);
            break;
        case DO_ACTION_KEY:
        	if(cur_pos < num_icons)
        	{
				hit((sint8)cur_pos);
#ifdef HAVE_JOYSTICK_SUPPORT
				keybinder->set_enable_joy_repeat(true);
#endif
				Hide();
        	}
        	break;
        case CANCEL_ACTION_KEY:
        case NEW_COMMAND_BAR_KEY:
#ifdef HAVE_JOYSTICK_SUPPORT
        	keybinder->set_enable_joy_repeat(true);
#endif
        	Hide();
        	break;

        default : keybinder->handle_always_available_keys(a);
        	break;
    }

    return GUI_YUM;
}