summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-26 10:13:40 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-26 10:13:40 +0100
commiteb2e62609992ab8b47f8805f2bc2cafce271b66f (patch)
tree58d6c387f910e3a3348a6528127f4216b524ec57 /src/gui
parent05dc1666dc794ed6aa7f6568b768c652f8922c4e (diff)
parent8d06606835e3d01f537ebe96de8b216e64a1f969 (diff)
downloadmana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.tar.gz
mana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.tar.bz2
mana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.tar.xz
mana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.zip
Merge branch 'master' into lpc2012lpc2012
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp18
-rw-r--r--src/gui/gui.h2
-rw-r--r--src/gui/sdlinput.cpp120
-rw-r--r--src/gui/sdlinput.h22
-rw-r--r--src/gui/setup.cpp6
-rw-r--r--src/gui/setup_keyboard.cpp4
-rw-r--r--src/gui/setup_video.cpp37
-rw-r--r--src/gui/socialwindow.cpp5
-rw-r--r--src/gui/tradewindow.h2
-rw-r--r--src/gui/truetypefont.cpp4
-rw-r--r--src/gui/viewport.cpp2
-rw-r--r--src/gui/widgets/button.cpp2
-rw-r--r--src/gui/widgets/desktop.cpp24
-rw-r--r--src/gui/widgets/dropdown.cpp2
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/playerbox.cpp2
-rw-r--r--src/gui/widgets/progressbar.cpp2
-rw-r--r--src/gui/widgets/scrollarea.cpp6
-rw-r--r--src/gui/widgets/tab.cpp2
-rw-r--r--src/gui/widgets/textfield.cpp46
-rw-r--r--src/gui/widgets/textfield.h6
-rw-r--r--src/gui/windowmenu.cpp2
23 files changed, 171 insertions, 149 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 2e1d006e..cb6682bd 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -26,6 +26,7 @@
#include "gui/sdlinput.h"
#include "gui/truetypefont.h"
+#include "gui/widgets/textfield.h"
#include "gui/widgets/window.h"
#include "gui/widgets/windowcontainer.h"
@@ -190,6 +191,12 @@ void Gui::logic()
Palette::advanceGradients();
gcn::Gui::logic();
+
+ while (!guiInput->isTextQueueEmpty())
+ {
+ TextInput textInput = guiInput->dequeueTextInput();
+ handleTextInput(textInput);
+ }
}
void Gui::draw()
@@ -267,3 +274,14 @@ void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput)
gcn::Gui::handleMouseMoved(mouseInput);
mMouseInactivityTimer = 0;
}
+
+void Gui::handleTextInput(const TextInput &textInput)
+{
+ if (auto focused = mFocusHandler->getFocused())
+ {
+ if (auto textField = dynamic_cast<TextField*>(focused))
+ {
+ textField->textInput(textInput);
+ }
+ }
+}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 006987da..998b6ec8 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -26,6 +26,7 @@
#include <guichan/gui.hpp>
+class TextInput;
class Graphics;
class GuiConfigListener;
class ImageSet;
@@ -114,6 +115,7 @@ class Gui : public gcn::Gui
protected:
void handleMouseMoved(const gcn::MouseInput &mouseInput);
+ void handleTextInput(const TextInput &textInput);
private:
GuiConfigListener *mConfigListener;
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
index 46636d52..c0f24a7a 100644
--- a/src/gui/sdlinput.cpp
+++ b/src/gui/sdlinput.cpp
@@ -109,6 +109,23 @@ gcn::MouseInput SDLInput::dequeueMouseInput()
return mouseInput;
}
+bool SDLInput::isTextQueueEmpty() const
+{
+ return mTextInputQueue.empty();
+}
+
+TextInput SDLInput::dequeueTextInput()
+{
+ if (mTextInputQueue.empty())
+ {
+ throw GCN_EXCEPTION("The queue is empty.");
+ }
+
+ TextInput textInput(mTextInputQueue.front());
+ mTextInputQueue.pop();
+ return textInput;
+}
+
void SDLInput::pushInput(SDL_Event event)
{
gcn::KeyInput keyInput;
@@ -122,8 +139,8 @@ void SDLInput::pushInput(SDL_Event event)
keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT);
keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL);
keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT);
- keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META);
- keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0
+ keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI);
+ keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0
&& event.key.keysym.sym <= SDLK_KP_EQUALS);
mKeyInputQueue.push(keyInput);
@@ -135,8 +152,8 @@ void SDLInput::pushInput(SDL_Event event)
keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT);
keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL);
keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT);
- keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META);
- keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0
+ keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI);
+ keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0
&& event.key.keysym.sym <= SDLK_KP_EQUALS);
mKeyInputQueue.push(keyInput);
@@ -147,19 +164,7 @@ void SDLInput::pushInput(SDL_Event event)
mouseInput.setX(event.button.x);
mouseInput.setY(event.button.y);
mouseInput.setButton(convertMouseButton(event.button.button));
-
- if (event.button.button == SDL_BUTTON_WHEELDOWN)
- {
- mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_DOWN);
- }
- else if (event.button.button == SDL_BUTTON_WHEELUP)
- {
- mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_UP);
- }
- else
- {
- mouseInput.setType(gcn::MouseInput::PRESSED);
- }
+ mouseInput.setType(gcn::MouseInput::PRESSED);
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
break;
@@ -183,6 +188,35 @@ void SDLInput::pushInput(SDL_Event event)
mMouseInputQueue.push(mouseInput);
break;
+ case SDL_MOUSEWHEEL:
+ if (event.wheel.y) {
+#if SDL_VERSION_ATLEAST(2, 26, 0)
+ mouseInput.setX(event.wheel.mouseX);
+ mouseInput.setY(event.wheel.mouseY);
+#else
+ int x, y;
+ SDL_GetMouseState(&x, &y);
+ mouseInput.setX(x);
+ mouseInput.setY(y);
+#endif
+ mouseInput.setButton(gcn::MouseInput::EMPTY);
+ mouseInput.setType(event.wheel.y > 0 ? gcn::MouseInput::WHEEL_MOVED_UP
+ : gcn::MouseInput::WHEEL_MOVED_DOWN);
+ mouseInput.setTimeStamp(SDL_GetTicks());
+ mMouseInputQueue.push(mouseInput);
+ }
+ break;
+
+ case SDL_TEXTINPUT:
+ mTextInputQueue.emplace(event.text.text);
+ break;
+
+ // TODO_SDL2: This is now a window event
+ // case SDL_WINDOWEVENT:
+ // switch (event.window.event) {
+ // }
+ // break;
+#if 0
case SDL_ACTIVEEVENT:
/*
* This occurs when the mouse leaves the window and the Gui-chan
@@ -209,7 +243,7 @@ void SDLInput::pushInput(SDL_Event event)
mMouseInWindow = true;
}
break;
-
+#endif
} // end switch
}
@@ -231,9 +265,9 @@ int SDLInput::convertMouseButton(int button)
int SDLInput::convertKeyCharacter(SDL_Event event)
{
- SDL_keysym keysym = event.key.keysym;
+ SDL_Keysym keysym = event.key.keysym;
- int value = keysym.unicode;
+ int value = keysym.sym;
switch (keysym.sym)
{
@@ -265,16 +299,10 @@ int SDLInput::convertKeyCharacter(SDL_Event event)
value = Key::PAUSE;
break;
case SDLK_SPACE:
- // Special characters like ~ (tilde) ends up
- // with the keysym.sym SDLK_SPACE which
- // without this check would be lost. The check
- // is only valid on key down events in SDL.
- if (event.type == SDL_KEYUP || keysym.unicode == ' ')
- {
- value = Key::SPACE;
- }
+ value = Key::SPACE;
break;
case SDLK_ESCAPE:
+ case SDLK_AC_BACK:
value = Key::ESCAPE;
break;
case SDLK_DELETE:
@@ -292,7 +320,7 @@ int SDLInput::convertKeyCharacter(SDL_Event event)
case SDLK_PAGEUP:
value = Key::PAGE_UP;
break;
- case SDLK_PRINT:
+ case SDLK_PRINTSCREEN:
value = Key::PRINT_SCREEN;
break;
case SDLK_PAGEDOWN:
@@ -343,27 +371,21 @@ int SDLInput::convertKeyCharacter(SDL_Event event)
case SDLK_F15:
value = Key::F15;
break;
- case SDLK_NUMLOCK:
+ case SDLK_NUMLOCKCLEAR:
value = Key::NUM_LOCK;
break;
case SDLK_CAPSLOCK:
value = Key::CAPS_LOCK;
break;
- case SDLK_SCROLLOCK:
+ case SDLK_SCROLLLOCK:
value = Key::SCROLL_LOCK;
break;
- case SDLK_RMETA:
+ case SDLK_RGUI:
value = Key::RIGHT_META;
break;
- case SDLK_LMETA:
+ case SDLK_LGUI:
value = Key::LEFT_META;
break;
- case SDLK_LSUPER:
- value = Key::LEFT_SUPER;
- break;
- case SDLK_RSUPER:
- value = Key::RIGHT_SUPER;
- break;
case SDLK_MODE:
value = Key::ALT_GR;
break;
@@ -394,34 +416,34 @@ int SDLInput::convertKeyCharacter(SDL_Event event)
{
switch (keysym.sym)
{
- case SDLK_KP0:
+ case SDLK_KP_0:
value = Key::INSERT;
break;
- case SDLK_KP1:
+ case SDLK_KP_1:
value = Key::END;
break;
- case SDLK_KP2:
+ case SDLK_KP_2:
value = Key::DOWN;
break;
- case SDLK_KP3:
+ case SDLK_KP_3:
value = Key::PAGE_DOWN;
break;
- case SDLK_KP4:
+ case SDLK_KP_4:
value = Key::LEFT;
break;
- case SDLK_KP5:
+ case SDLK_KP_5:
value = 0;
break;
- case SDLK_KP6:
+ case SDLK_KP_6:
value = Key::RIGHT;
break;
- case SDLK_KP7:
+ case SDLK_KP_7:
value = Key::HOME;
break;
- case SDLK_KP8:
+ case SDLK_KP_8:
value = Key::UP;
break;
- case SDLK_KP9:
+ case SDLK_KP_9:
value = Key::PAGE_UP;
break;
default:
diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h
index 90f70df3..09bb788e 100644
--- a/src/gui/sdlinput.h
+++ b/src/gui/sdlinput.h
@@ -61,13 +61,15 @@
#include <queue>
-#include <SDL/SDL.h>
+#include <SDL.h>
#include <guichan/input.hpp>
#include <guichan/keyinput.hpp>
#include <guichan/mouseinput.hpp>
#include <guichan/platform.hpp>
+#include <string>
+
namespace Key
{
enum
@@ -122,6 +124,19 @@ namespace Key
};
}
+class TextInput
+{
+public:
+ TextInput(const char *text)
+ : mText(text)
+ {}
+
+ const std::string &getText() const { return mText; }
+
+private:
+ std::string mText;
+};
+
/**
* SDL implementation of Input.
*/
@@ -160,6 +175,10 @@ public:
virtual gcn::MouseInput dequeueMouseInput();
+ bool isTextQueueEmpty() const;
+
+ TextInput dequeueTextInput();
+
protected:
/**
* Converts a mouse button from SDL to a Guichan mouse button
@@ -181,6 +200,7 @@ protected:
std::queue<gcn::KeyInput> mKeyInputQueue;
std::queue<gcn::MouseInput> mMouseInputQueue;
+ std::queue<TextInput> mTextInputQueue;
bool mMouseDown;
bool mMouseInWindow;
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index c468490c..eb59c4ea 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -38,6 +38,8 @@
#include "utils/dtor.h"
#include "utils/gettext.h"
+#include <functional>
+
extern Window *statusWindow;
Setup::Setup():
@@ -103,12 +105,12 @@ void Setup::action(const gcn::ActionEvent &event)
if (event.getId() == "Apply")
{
setVisible(false);
- for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTab::apply));
+ for_each(mTabs.begin(), mTabs.end(), std::mem_fn(&SetupTab::apply));
}
else if (event.getId() == "Cancel")
{
setVisible(false);
- for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTab::cancel));
+ for_each(mTabs.begin(), mTabs.end(), std::mem_fn(&SetupTab::cancel));
}
else if (event.getId() == "Reset Windows")
{
diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp
index 5e29519b..b66ba3aa 100644
--- a/src/gui/setup_keyboard.cpp
+++ b/src/gui/setup_keyboard.cpp
@@ -178,8 +178,8 @@ void Setup_Keyboard::refreshAssignedKey(int index)
caption = keyboard.getKeyCaption(index) + ": ";
else
{
- char *temp = SDL_GetKeyName(
- (SDLKey) keyboard.getKeyValue(index));
+ const char *temp = SDL_GetKeyName(
+ (SDL_Scancode) keyboard.getKeyValue(index));
caption = strprintf("%-25s",
(keyboard.getKeyCaption(index) + ": ").c_str()) + toString(temp);
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 5a697160..ac419de5 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -26,8 +26,6 @@
#include "game.h"
#include "graphics.h"
#include "localplayer.h"
-#include "log.h"
-#include "main.h"
#include "gui/okdialog.h"
@@ -38,8 +36,6 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/slider.h"
#include "gui/widgets/spacer.h"
-#include "gui/widgets/textfield.h"
-#include "gui/widgets/dropdown.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -90,26 +86,21 @@ class ModeListModel : public gcn::ListModel
ModeListModel::ModeListModel()
{
/* Get available fullscreen/hardware modes */
- SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
-
- /* Check which modes are available */
- if (modes == (SDL_Rect **)0)
- logger->log("No modes available");
- else if (modes == (SDL_Rect **)-1)
- logger->log("All resolutions available");
- else
+ const int numModes = SDL_GetNumDisplayModes(0);
+ for (int i = 0; i < numModes; i++)
{
- for (int i = 0; modes[i]; ++i)
- {
- const int width = modes[i]->w;
- const int height = modes[i]->h;
+ SDL_DisplayMode mode;
+ if (SDL_GetDisplayMode(0, i, &mode) != 0)
+ continue;
- // Skip the unreasonably small modes
- if (width < 640 || height < 360)
- continue;
+ // Skip the unreasonably small modes
+ if (mode.w < 640 || mode.h < 360)
+ continue;
- mVideoModes.push_back(toString(width) + "x" + toString(height));
- }
+ // TODO_SDL2: Modes now dinstinguish between pixel format and refresh rate as well
+ // TODO_SDL2: Fullscreen mode needs display selection
+
+ mVideoModes.push_back(toString(mode.w) + "x" + toString(mode.h));
}
}
@@ -255,9 +246,7 @@ void Setup_Video::apply()
{
if (!graphics->changeVideoMode(screenWidth,
screenHeight,
- graphics->getBpp(),
- fullscreen,
- graphics->getHWAccel()))
+ fullscreen))
{
std::stringstream errorMessage;
if (fullscreen)
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index 1b960d64..437f9d01 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -33,8 +33,6 @@
#include "gui/widgets/avatarlistbox.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/button.h"
-#include "gui/widgets/container.h"
-#include "gui/widgets/label.h"
#include "gui/widgets/linkhandler.h"
#include "gui/widgets/popup.h"
#include "gui/widgets/scrollarea.h"
@@ -47,7 +45,6 @@
#include "resources/theme.h"
-#include "utils/dtor.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -618,7 +615,7 @@ void SocialWindow::showPartyCreate()
{
new OkDialog(_("Create Party"),
_("Cannot create party. You are already in a party"),
- this);
+ true, this);
return;
}
diff --git a/src/gui/tradewindow.h b/src/gui/tradewindow.h
index 59ddcbdc..20da4574 100644
--- a/src/gui/tradewindow.h
+++ b/src/gui/tradewindow.h
@@ -117,7 +117,7 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener
*/
void setStatus(Status s);
- typedef const std::auto_ptr<Inventory> InventoryPtr;
+ typedef const std::unique_ptr<Inventory> InventoryPtr;
InventoryPtr mMyInventory;
InventoryPtr mPartnerInventory;
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp
index 620ba191..443adaa5 100644
--- a/src/gui/truetypefont.cpp
+++ b/src/gui/truetypefont.cpp
@@ -28,6 +28,7 @@
#include "utils/stringutils.h"
+#include <guichan/color.hpp>
#include <guichan/exception.hpp>
const unsigned int CACHE_SIZE = 256;
@@ -53,9 +54,10 @@ class TextChunk
void generate(TTF_Font *font)
{
SDL_Color sdlCol;
- sdlCol.b = color.b;
sdlCol.r = color.r;
sdlCol.g = color.g;
+ sdlCol.b = color.b;
+ sdlCol.a = color.a;
const char *str = getSafeUtf8String(text);
SDL_Surface *surface = TTF_RenderUTF8_Blended(
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 0f737fb0..b2945617 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -311,7 +311,7 @@ void Viewport::_followMouse()
if (mPlayerFollowMouse && button & SDL_BUTTON(1))
{
// We create a mouse event and send it to mouseDragged.
- Uint8 *keys = SDL_GetKeyState(NULL);
+ const Uint8 *keys = SDL_GetKeyboardState(NULL);
gcn::MouseEvent mouseEvent(NULL,
(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]),
false,
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 4a31fa63..9247f67a 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -182,7 +182,7 @@ Button::~Button()
{
for (int mode = 0; mode < BUTTON_COUNT; ++mode)
{
- for_each(mButton[mode].grid, mButton[mode].grid + 9,
+ std::for_each(mButton[mode].grid, mButton[mode].grid + 9,
dtor<Image*>());
}
delete[] mButton;
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index ec76f861..c9974fec 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -94,14 +94,9 @@ void Desktop::draw(gcn::Graphics *graphics)
if (mWallpaper)
{
- if (!Image::useOpenGL())
- g->drawImage(mWallpaper,
- (getWidth() - mWallpaper->getWidth()) / 2,
- (getHeight() - mWallpaper->getHeight()) / 2);
- else
- g->drawRescaledImage(mWallpaper, 0, 0, 0, 0,
- mWallpaper->getWidth(), mWallpaper->getHeight(),
- getWidth(), getHeight(), false);
+ g->drawRescaledImage(mWallpaper, 0, 0, 0, 0,
+ mWallpaper->getWidth(), mWallpaper->getHeight(),
+ getWidth(), getHeight(), false);
}
mBgSkin->setAlpha(1.0f);
@@ -168,19 +163,6 @@ void Desktop::setBestFittingWallpaper()
mWallpaper->decRef(Resource::DeleteImmediately);
mWallpaper = wallpaper;
-
- // In software mode we try to prescale the image for performance
- if (!wallpaper->useOpenGL() &&
- (wallpaper->getWidth() != width ||
- wallpaper->getHeight() != height))
- {
- if (Image *prescaled = wallpaper->SDLgetScaledImage(width, height))
- {
- // Make sure the original can be freed
- wallpaper->decRef();
- mWallpaper = prescaled;
- }
- }
}
else
{
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index e90f6073..101afaef 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -102,7 +102,7 @@ DropDown::~DropDown()
buttons[1][0]->decRef();
buttons[1][1]->decRef();
- for_each(skin.grid, skin.grid + 9, dtor<Image*>());
+ std::for_each(skin.grid, skin.grid + 9, dtor<Image*>());
}
delete mScrollArea;
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 3105a762..cdb2d3c4 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -92,7 +92,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
// Draw emote keyboard shortcut.
const char *key = SDL_GetKeyName(
- (SDLKey) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i));
+ (SDL_Scancode) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i));
graphics->setColor(Theme::getThemeColor(Theme::TEXT));
g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT);
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index f1690d43..396de3bd 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -86,7 +86,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
// Draw item keyboard shortcut.
const char *key = SDL_GetKeyName(
- (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i));
+ (SDL_Scancode) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i));
graphics->setColor(Theme::getThemeColor(Theme::TEXT));
g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
index 5c5976c1..4f341af0 100644
--- a/src/gui/widgets/playerbox.cpp
+++ b/src/gui/widgets/playerbox.cpp
@@ -75,7 +75,7 @@ PlayerBox::~PlayerBox()
if (instances == 0)
{
- for_each(background.grid, background.grid + 9, dtor<Image*>());
+ std::for_each(background.grid, background.grid + 9, dtor<Image*>());
}
}
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index 27b194ff..4695f5ab 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -88,7 +88,7 @@ ProgressBar::~ProgressBar()
if (mInstances == 0)
{
- for_each(mBorder.grid, mBorder.grid + 9, dtor<Image*>());
+ std::for_each(mBorder.grid, mBorder.grid + 9, dtor<Image*>());
}
}
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index d5e824e1..c95adeaa 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -66,9 +66,9 @@ ScrollArea::~ScrollArea()
if (instances == 0)
{
- for_each(background.grid, background.grid + 9, dtor<Image*>());
- for_each(vMarker.grid, vMarker.grid + 9, dtor<Image*>());
- for_each(vMarkerHi.grid, vMarkerHi.grid + 9, dtor<Image*>());
+ std::for_each(background.grid, background.grid + 9, dtor<Image*>());
+ std::for_each(vMarker.grid, vMarker.grid + 9, dtor<Image*>());
+ std::for_each(vMarkerHi.grid, vMarkerHi.grid + 9, dtor<Image*>());
buttons[UP][0]->decRef();
buttons[UP][1]->decRef();
diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp
index 17b7108f..c8ed2141 100644
--- a/src/gui/widgets/tab.cpp
+++ b/src/gui/widgets/tab.cpp
@@ -76,7 +76,7 @@ Tab::~Tab()
{
for (int mode = 0; mode < TAB_COUNT; mode++)
{
- for_each(tabImg[mode].grid, tabImg[mode].grid + 9, dtor<Image*>());
+ std::for_each(tabImg[mode].grid, tabImg[mode].grid + 9, dtor<Image*>());
}
}
}
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index ec57f1c7..35ce09c5 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -24,7 +24,6 @@
#include "configuration.h"
#include "graphics.h"
-#include "gui/palette.h"
#include "gui/sdlinput.h"
#include "resources/image.h"
@@ -36,6 +35,8 @@
#include <guichan/font.hpp>
+#include <SDL.h>
+
#undef DELETE //Win32 compatibility hack
int TextField::instances = 0;
@@ -84,7 +85,7 @@ TextField::~TextField()
instances--;
if (instances == 0)
- for_each(skin.grid, skin.grid + 9, dtor<Image*>());
+ std::for_each(skin.grid, skin.grid + 9, dtor<Image*>());
}
void TextField::updateAlpha()
@@ -162,33 +163,7 @@ int TextField::getValue() const
void TextField::keyPressed(gcn::KeyEvent &keyEvent)
{
- int val = keyEvent.getKey().getValue();
-
- if (val >= 32)
- {
- int l;
- if (val < 128) l = 1; // 0xxxxxxx
- else if (val < 0x800) l = 2; // 110xxxxx 10xxxxxx
- else if (val < 0x10000) l = 3; // 1110xxxx 10xxxxxx 10xxxxxx
- else l = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-
- char buf[4];
- for (int i = 0; i < l; ++i)
- {
- buf[i] = val >> (6 * (l - i - 1));
- if (i > 0) buf[i] = (buf[i] & 63) | 128;
- }
-
- if (l > 1) buf[0] |= 255 << (8 - l);
-
- mText.insert(mCaretPosition, std::string(buf, buf + l));
- mCaretPosition += l;
- }
-
- /* In UTF-8, 10xxxxxx is only used for inner parts of characters. So skip
- them when processing key presses. */
-
- switch (val)
+ switch (keyEvent.getKey().getValue())
{
case Key::LEFT:
{
@@ -302,8 +277,9 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
return;
break;
- case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v
- handlePaste();
+ case SDLK_v:
+ if (keyEvent.isControlPressed())
+ handlePaste();
break;
}
@@ -311,6 +287,12 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
fixScroll();
}
+void TextField::textInput(const TextInput &textInput)
+{
+ mText.insert(mCaretPosition, textInput.getText());
+ mCaretPosition += textInput.getText().length();
+}
+
void TextField::autoComplete()
{
if (mAutoComplete && mText.size() > 0)
@@ -383,7 +365,7 @@ void TextField::handlePaste()
std::string text = getText();
std::string::size_type caretPos = getCaretPosition();
- if (RetrieveBuffer(text, caretPos)) {
+ if (insertFromClipboard(text, caretPos)) {
setText(text);
setCaretPosition(caretPos);
}
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index 94cada41..bf60cbc3 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -26,6 +26,7 @@
#include <vector>
+class TextInput;
class ImageRect;
class TextField;
@@ -116,6 +117,11 @@ class TextField : public gcn::TextField
void keyPressed(gcn::KeyEvent &keyEvent);
/**
+ * Handle text input (should possibly be new event in Guichan).
+ */
+ void textInput(const TextInput &textInput);
+
+ /**
* Set the minimum value for a range
*/
void setMinimum(int min) { mMinimum = min; }
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index a06415fb..ff75e5d1 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -167,7 +167,7 @@ static std::string createShortcutCaption(const std::string& text,
if (key != KeyboardConfig::KEY_NO_VALUE)
{
caption += " (";
- caption += SDL_GetKeyName((SDLKey) keyboard.getKeyValue(key));
+ caption += SDL_GetKeyName((SDL_Scancode) keyboard.getKeyValue(key));
caption += ")";
}
return caption;