[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src hotkeys.cpp sdl_utils.cpp sdl_utils...
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src hotkeys.cpp sdl_utils.cpp sdl_utils... |
Date: |
Sat, 08 Jan 2005 19:17:28 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 05/01/09 00:02:52
Modified files:
src : hotkeys.cpp sdl_utils.cpp sdl_utils.hpp
Log message:
Allow hotkeys bound to oddball keys; patch #3419 from mark7.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/hotkeys.cpp.diff?tr1=1.65&tr2=1.66&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.cpp.diff?tr1=1.70&tr2=1.71&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.hpp.diff?tr1=1.50&tr2=1.51&r1=text&r2=text
Patches:
Index: wesnoth/src/hotkeys.cpp
diff -u wesnoth/src/hotkeys.cpp:1.65 wesnoth/src/hotkeys.cpp:1.66
--- wesnoth/src/hotkeys.cpp:1.65 Thu Nov 18 22:00:12 2004
+++ wesnoth/src/hotkeys.cpp Sun Jan 9 00:02:52 2005
@@ -1,4 +1,4 @@
-/* $Id: hotkeys.cpp,v 1.65 2004/11/18 22:00:12 ydirson Exp $ */
+/* $Id: hotkeys.cpp,v 1.66 2005/01/09 00:02:52 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -123,14 +123,18 @@
const std::string& code = cfg["key"];
if(code.empty()) {
keycode_ = 0;
- } else if(code.size() >= 2 && tolower(code[0]) == 'f') {
- const int num =
lexical_cast_default<int>(std::string(code.begin()+1,code.end()),1);
- keycode_ = num + SDLK_F1 - 1;
- std::cerr << "set key to F" << num << " = " << keycode_ << "\n";
} else {
- keycode_ = code[0];
+ keycode_ = sdl_keysym_from_name(code);
+ if (keycode_ == SDLK_UNKNOWN) {
+ if(code.size() >= 2 && code.size() <= 3 &&
tolower(code[0]) == 'f') {
+ const int num =
lexical_cast_default<int>(std::string(code.begin() + 1, code.end()), 1);
+ keycode_ = num + SDLK_F1 - 1;
+ } else if (code.size() == 1) {
+ keycode_ = code[0];
+ }
+ }
}
-
+
alt_ = (cfg["alt"] == "yes");
ctrl_ = (cfg["ctrl"] == "yes");
shift_ = (cfg["shift"] == "yes");
@@ -218,15 +222,7 @@
config& item = cfg.add_child("hotkey");
item["command"] = i->get_command();
-
- if(i->get_keycode() >= SDLK_F1 && i->get_keycode() <= SDLK_F12)
{
- std::string str = "FF";
- str[1] = '1' + i->get_keycode() - SDLK_F1;
- item["key"] = str;
- } else {
- item["key"] = i->get_keycode();
- }
-
+ item["key"] = SDL_GetKeyName(SDLKey(i->get_keycode()));
item["alt"] = i->get_alt() ? "yes" : "no";
item["ctrl"] = i->get_ctrl() ? "yes" : "no";
item["shift"] = i->get_shift() ? "yes" : "no";
Index: wesnoth/src/sdl_utils.cpp
diff -u wesnoth/src/sdl_utils.cpp:1.70 wesnoth/src/sdl_utils.cpp:1.71
--- wesnoth/src/sdl_utils.cpp:1.70 Sat Jan 8 23:06:27 2005
+++ wesnoth/src/sdl_utils.cpp Sun Jan 9 00:02:52 2005
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.cpp,v 1.70 2005/01/08 23:06:27 silene Exp $ */
+/* $Id: sdl_utils.cpp,v 1.71 2005/01/09 00:02:52 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -16,6 +16,7 @@
#include <algorithm>
#include <cmath>
#include <iostream>
+#include <map>
#include "config.hpp"
#include "game.hpp"
@@ -26,6 +27,28 @@
#include "video.hpp"
#include "wassert.hpp"
+SDLKey sdl_keysym_from_name(std::string const &keyname)
+{
+ static bool initialized = false;
+ typedef std::map<std::string const, SDLKey> keysym_map_t;
+ static keysym_map_t keysym_map;
+
+ if (!initialized) {
+ for(SDLKey i = SDLK_FIRST; i < SDLK_LAST; i = SDLKey(int(i) +
1)) {
+ std::string name = SDL_GetKeyName(i);
+ if (!name.empty())
+ keysym_map[name] = i;
+ }
+ initialized = true;
+ }
+
+ keysym_map_t::const_iterator it = keysym_map.find(keyname);
+ if (it != keysym_map.end())
+ return it->second;
+ else
+ return SDLK_UNKNOWN;
+}
+
bool point_in_rect(int x, int y, const SDL_Rect& rect)
{
return x >= rect.x && y >= rect.y && x < rect.x + rect.w && y < rect.y
+ rect.h;
Index: wesnoth/src/sdl_utils.hpp
diff -u wesnoth/src/sdl_utils.hpp:1.50 wesnoth/src/sdl_utils.hpp:1.51
--- wesnoth/src/sdl_utils.hpp:1.50 Sat Jan 8 23:06:27 2005
+++ wesnoth/src/sdl_utils.hpp Sun Jan 9 00:02:52 2005
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.hpp,v 1.50 2005/01/08 23:06:27 silene Exp $ */
+/* $Id: sdl_utils.hpp,v 1.51 2005/01/09 00:02:52 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -32,6 +32,8 @@
#define SDL_BUTTON_WHEELDOWN 5
#endif
+SDLKey sdl_keysym_from_name(std::string const &keyname);
+
bool point_in_rect(int x, int y, const SDL_Rect& rect);
bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2);
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src hotkeys.cpp sdl_utils.cpp sdl_utils...,
Guillaume Melquiond <=