diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-25 15:41:57 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-25 15:41:57 +0100 |
commit | 2c51c98625b225cecfb9628c30d62d4e30f7e3e1 (patch) | |
tree | 5f8f85a40785439b6a9ea249a75e81e26d1b44f1 /src/gui/widgets | |
parent | 8fdbae08d7f269c72889f89b56493071a2279350 (diff) | |
download | mana-2c51c98625b225cecfb9628c30d62d4e30f7e3e1.tar.gz mana-2c51c98625b225cecfb9628c30d62d4e30f7e3e1.tar.bz2 mana-2c51c98625b225cecfb9628c30d62d4e30f7e3e1.tar.xz mana-2c51c98625b225cecfb9628c30d62d4e30f7e3e1.zip |
Ported to SDL2
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/desktop.cpp | 24 | ||||
-rw-r--r-- | src/gui/widgets/emoteshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 43 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 6 |
5 files changed, 24 insertions, 53 deletions
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index ce609891..07d1d887 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -86,14 +86,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); } // Draw a thin border under the application version... @@ -125,19 +120,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/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/textfield.cpp b/src/gui/widgets/textfield.cpp index e7c279b2..c4c00ae4 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -36,6 +36,8 @@ #include <guichan/font.hpp> +#include <SDL.h> + #undef DELETE //Win32 compatibility hack int TextField::instances = 0; @@ -162,33 +164,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 +278,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 +288,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 +366,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; } |