From 9641f4c6c24656a73ee759f7c176ba682ae01acf Mon Sep 17 00:00:00 2001
From: Angelo Castellani <udp.castellani@gmail.com>
Date: Thu, 12 May 2011 01:25:29 -0400
Subject: Made the setup keyboard tab prettier.

Incidentally I added support for a monospaced font (which may come in handy).
---
 data/fonts/dejavusans-mono.ttf | Bin 0 -> 333636 bytes
 src/defaults.cpp               |   1 +
 src/gui/gui.cpp                |  17 +++++++++++++++++
 src/gui/gui.h                  |   5 +++++
 src/gui/setup_keyboard.cpp     |  16 +++++++++++++---
 src/gui/widgets/listbox.h      |  13 +++++++++++++
 src/keyboardconfig.cpp         |   9 +++++----
 7 files changed, 54 insertions(+), 7 deletions(-)
 create mode 100644 data/fonts/dejavusans-mono.ttf

diff --git a/data/fonts/dejavusans-mono.ttf b/data/fonts/dejavusans-mono.ttf
new file mode 100644
index 00000000..7260bd65
Binary files /dev/null and b/data/fonts/dejavusans-mono.ttf differ
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 87f7953e..443795a8 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -144,6 +144,7 @@ DefaultsData* getBrandingDefaults()
     AddDEF(brandingData, "theme", "");
     AddDEF(brandingData, "font", "fonts/dejavusans.ttf");
     AddDEF(brandingData, "boldFont", "fonts/dejavusans-bold.ttf");
+    AddDEF(brandingData, "monoFont", "fonts/dejavusans-mono.ttf");
 
     return brandingData;
 }
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index d1c18ab2..593bed10 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -50,6 +50,9 @@ SDLInput *guiInput = 0;
 // Bolded font
 gcn::Font *boldFont = 0;
 
+// Mono font
+gcn::Font *monoFont = 0;
+
 class GuiConfigListener : public EventListener
 {
     public:
@@ -136,6 +139,19 @@ Gui::Gui(Graphics *graphics):
                       std::string("': ") + e.getMessage());
     }
 
+    // Set mono font
+    fontFile = branding.getValue("monoFont", "fonts/dejavusans-mono.ttf");
+    path = resman->getPath(fontFile);
+    try
+    {
+        monoFont = new TrueTypeFont(path, fontSize);
+    }
+    catch (gcn::Exception e)
+    {
+        logger->error(std::string("Unable to load '") + fontFile +
+                      std::string("': ") + e.getMessage());
+    }
+
     gcn::Widget::setGlobalFont(mGuiFont);
 
     // Initialize mouse cursor and listen for changes to the option
@@ -153,6 +169,7 @@ Gui::~Gui()
 
     delete mGuiFont;
     delete boldFont;
+    delete monoFont;
     delete mInfoParticleFont;
     delete getTop();
 
diff --git a/src/gui/gui.h b/src/gui/gui.h
index fa7102fe..6b40282f 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -129,4 +129,9 @@ extern SDLInput *guiInput;                    /**< GUI input */
  */
 extern gcn::Font *boldFont;
 
+/**
+ * Monospaced text font
+ */
+extern gcn::Font *monoFont;
+
 #endif // GUI_H
diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp
index 57a21270..31fd6e39 100644
--- a/src/gui/setup_keyboard.cpp
+++ b/src/gui/setup_keyboard.cpp
@@ -24,6 +24,7 @@
 
 #include "keyboardconfig.h"
 
+#include "gui/gui.h"
 #include "gui/okdialog.h"
 
 #include "gui/widgets/button.h"
@@ -79,6 +80,7 @@ Setup_Keyboard::Setup_Keyboard():
     refreshKeys();
 
     mKeyList->addActionListener(this);
+    mKeyList->setFont(monoFont);
 
     ScrollArea *scrollArea = new ScrollArea(mKeyList);
     scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -176,9 +178,17 @@ void Setup_Keyboard::action(const gcn::ActionEvent &event)
 void Setup_Keyboard::refreshAssignedKey(int index)
 {
     std::string caption;
-    char *temp = SDL_GetKeyName(
-        (SDLKey) keyboard.getKeyValue(index));
-    caption = keyboard.getKeyCaption(index) + ": " + toString(temp);
+    if (keyboard.getKeyValue(index) == keyboard.KEY_NO_VALUE)
+        caption = keyboard.getKeyCaption(index) + ": ";
+    else
+    {
+        char *temp = SDL_GetKeyName(
+            (SDLKey) keyboard.getKeyValue(index));
+
+        caption = strprintf("%-25s",
+            (keyboard.getKeyCaption(index) + ": ").c_str()) + toString(temp);
+
+    }
     mKeyListModel->setElementAt(index, caption);
 }
 
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h
index 92505c15..4984a3ce 100644
--- a/src/gui/widgets/listbox.h
+++ b/src/gui/widgets/listbox.h
@@ -40,6 +40,16 @@ class ListBox : public gcn::ListBox
 
         ~ListBox();
 
+        /**
+         * Sets the font to render the text in.
+         *
+         * @param font the font to use.
+         */
+        inline void setFont(gcn::Font *font)
+        {
+            mFont = font;
+        }
+
         /**
          * Draws the list box.
          */
@@ -62,6 +72,9 @@ class ListBox : public gcn::ListBox
 
         void mouseDragged(gcn::MouseEvent &event);
 
+    private:
+        gcn::Font *mFont;
+
     protected:
         static float mAlpha;
 };
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index ec2bf6ed..08ee8896 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -162,7 +162,8 @@ bool KeyboardConfig::hasConflicts()
                 continue;
 
             // Allow collisions between shortcut and emote keys
-            if ((i >= KEY_SHORTCUT_1 && i <= KEY_SHORTCUT_12) && (j >= KEY_EMOTE_1 && j <= KEY_EMOTE_12))
+            if ((i >= KEY_SHORTCUT_1 && i <= KEY_SHORTCUT_12) &&
+                    (j >= KEY_EMOTE_1 && j <= KEY_EMOTE_12))
                 continue;
 
             // Why?
@@ -181,9 +182,9 @@ bool KeyboardConfig::hasConflicts()
             if (mKey[i].value == mKey[j].value)
             {
                 mBindError = strprintf(_("Conflict \"%s\" and \"%s\" keys. "
-                                         "Resolve them, or gameplay may result"
-                                         " in strange behaviour."),
-                                       mKey[i].caption.c_str(), mKey[j].caption.c_str());
+                    "Resolve them, or gameplay may result"
+                    " in strange behaviour."),
+                    mKey[i].caption.c_str(), mKey[j].caption.c_str());
                 return true;
             }
         }
-- 
cgit v1.2.3-70-g09d2