From c63ccd1ec9b9856c682265d8ed87a0a0001416ec Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 18 May 2010 02:21:14 +0300
Subject: [PATCH 2/3] Add UI:HotKeyOfCaption for Lua

---
 engine/include/ui.h    |    1 +
 engine/tolua/tolua.cpp |   37 ++++++++++++++++++++++++++++++++++++-
 engine/tolua/ui.pkg    |    2 ++
 engine/ui/ui.cpp       |   17 +++++++++++++++++
 4 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/engine/include/ui.h b/engine/include/ui.h
index d233aed..e92fe39 100644
--- a/engine/include/ui.h
+++ b/engine/include/ui.h
@@ -348,6 +348,7 @@ public:
 
 	void Load();
 
+	std::string HotKeyOfCaption(const std::string &caption);
 
 	bool MouseScroll;                   /// Enable mouse scrolling
 	bool KeyScroll;                     /// Enable keyboard scrolling
diff --git a/engine/tolua/tolua.cpp b/engine/tolua/tolua.cpp
index 758bf26..82a6eb3 100644
--- a/engine/tolua/tolua.cpp
+++ b/engine/tolua/tolua.cpp
@@ -1,6 +1,6 @@
 /*
 ** Lua binding: stratagus
-** Generated automatically by tolua++-1.0.92 on Tue May 18 00:55:23 2010.
+** Generated automatically by tolua++-1.0.92 on Tue May 18 02:22:15 2010.
 */
 
 #ifndef __cplusplus
@@ -3990,6 +3990,40 @@ static int tolua_set_CUITimer_Font_ptr(lua_State* tolua_S)
 }
 #endif //#ifndef TOLUA_DISABLE
 
+/* method: HotKeyOfCaption of class  CUserInterface */
+#ifndef TOLUA_DISABLE_tolua_stratagus_CUserInterface_HotKeyOfCaption00
+static int tolua_stratagus_CUserInterface_HotKeyOfCaption00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"CUserInterface",0,&tolua_err) ||
+     !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+     !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+#endif
+ {
+  CUserInterface* self = (CUserInterface*)  tolua_tousertype(tolua_S,1,0);
+  std::string caption = ((std::string)  tolua_tocppstring(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HotKeyOfCaption'", NULL);
+#endif
+  {
+   std::string tolua_ret = (std::string)  self->HotKeyOfCaption(caption);
+   tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
+  }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'HotKeyOfCaption'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
 /* get function: NormalFontColor of class  CUserInterface */
 #ifndef TOLUA_DISABLE_tolua_get_CUserInterface_NormalFontColor
 static int tolua_get_CUserInterface_NormalFontColor(lua_State* tolua_S)
@@ -19798,6 +19832,7 @@ TOLUA_API int tolua_stratagus_open (lua_State* tolua_S)
   tolua_endmodule(tolua_S);
   tolua_cclass(tolua_S,"CUserInterface","CUserInterface","",NULL);
   tolua_beginmodule(tolua_S,"CUserInterface");
+   tolua_function(tolua_S,"HotKeyOfCaption",tolua_stratagus_CUserInterface_HotKeyOfCaption00);
    tolua_variable(tolua_S,"NormalFontColor",tolua_get_CUserInterface_NormalFontColor,tolua_set_CUserInterface_NormalFontColor);
    tolua_variable(tolua_S,"ReverseFontColor",tolua_get_CUserInterface_ReverseFontColor,tolua_set_CUserInterface_ReverseFontColor);
    tolua_variable(tolua_S,"Fillers",tolua_get_CUserInterface_Fillers,tolua_set_CUserInterface_Fillers);
diff --git a/engine/tolua/ui.pkg b/engine/tolua/ui.pkg
index 14e8f5b..85083a2 100644
--- a/engine/tolua/ui.pkg
+++ b/engine/tolua/ui.pkg
@@ -139,6 +139,8 @@ class CUITimer
 
 class CUserInterface
 {
+	std::string HotKeyOfCaption(std::string caption);
+
 	string NormalFontColor;
 	string ReverseFontColor;
 	
diff --git a/engine/ui/ui.cpp b/engine/ui/ui.cpp
index 23e3a7f..d8d1810 100644
--- a/engine/ui/ui.cpp
+++ b/engine/ui/ui.cpp
@@ -200,6 +200,23 @@ void CUserInterface::Load(void)
 }
 
 /**
+**  Extract the name of the hot key from a caption.
+**
+**  @param caption  Caption of a widget.
+**
+**  @return The canonical name of the hot key, or "" if none.
+*/
+std::string CUserInterface::HotKeyOfCaption(const std::string &caption)
+{
+	int key = GetHotKey(caption);
+	if (key == 0) {
+		return "";
+	} else {
+		return SdlKey2Str(key);
+	}
+}
+
+/**
 **  Save the viewports.
 **
 **  @param file  Save file handle
-- 
1.7.1

