diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/popupmenu.cpp | 49 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 4 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 6 | ||||
-rw-r--r-- | src/gui/viewport.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 10 |
7 files changed, 80 insertions, 6 deletions
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 77c022ffe..544bc028c 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -55,6 +55,7 @@ #include "gui/widgets/browserbox.h" #include "gui/widgets/chattab.h" #include "gui/widgets/progressbar.h" +#include "gui/widgets/textfield.h" #include "gui/widgets/whispertab.h" #include "net/adminhandler.h" @@ -93,11 +94,11 @@ PopupMenu::PopupMenu(): mDialog(nullptr), mButton(nullptr), mNick(""), + mTextField(nullptr), mType(static_cast<int>(Being::UNKNOWN)), mX(0), mY(0) { - mBrowserBox->setPosition(4, 4); mBrowserBox->setHighlightMode(BrowserBox::BACKGROUND); mBrowserBox->setOpaque(false); mBrowserBox->setLinkHandler(this); @@ -1534,6 +1535,16 @@ void PopupMenu::handleLink(const std::string &link, if (outfitWindow) outfitWindow->clearCurrentOutfit(); } + else if (link == "clipboard copy") + { + if (mTextField) + mTextField->handleCopy(); + } + else if (link == "clipboard paste") + { + if (mTextField) + mTextField->handlePaste(); + } else if (!link.compare(0, 10, "guild-pos-")) { if (player_node) @@ -1611,7 +1622,13 @@ void PopupMenu::handleLink(const std::string &link, mItemId = 0; mItemColor = 1; mMapItem = nullptr; + mTab = nullptr; + mSpell = nullptr; + mWindow = nullptr; + mDialog = nullptr; + mButton = nullptr; mNick.clear(); + mTextField = nullptr; mType = static_cast<int>(Being::UNKNOWN); mX = 0; mY = 0; @@ -2040,12 +2057,33 @@ void PopupMenu::showUndressPopup(const int x, const int y, mBrowserBox->addRow("cancel", _("Cancel")); showPopup(x, y); +} + +void PopupMenu::showTextFieldPopup(int x, int y, TextField *input) +{ + mX = x; + mY = y; + mTextField = input; + + mBrowserBox->clearRows(); + mBrowserBox->addRow("clipboard copy", _("Copy")); + mBrowserBox->addRow("clipboard paste", _("Paste")); + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow("cancel", _("Cancel")); + + showPopup(x, y); } void PopupMenu::showPopup(int x, int y) { - setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8); + const int pad2 = 2 * getPadding(); + const int bPad2 = 2 * mBrowserBox->getPadding(); + mBrowserBox->setPosition(mPadding, mPadding); + // add padding to initial size before draw browserbox + mBrowserBox->setWidth(mBrowserBox->getWidth() + bPad2); + setContentSize(mBrowserBox->getWidth() + pad2, + mBrowserBox->getHeight() + pad2); if (mainGraphics->mWidth < (x + getWidth() + 5)) x = mainGraphics->mWidth - getWidth(); if (mainGraphics->mHeight < (y + getHeight() + 5)) @@ -2211,6 +2249,13 @@ void PopupMenu::clear() mDialog->close(); mDialog = nullptr; } + mItem = nullptr; + mMapItem = nullptr; + mTab = nullptr; + mSpell = nullptr; + mWindow = nullptr; + mButton = nullptr; + mTextField = nullptr; } RenameListener::RenameListener() : diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 95cc3f65c..e2397d7db 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -43,6 +43,7 @@ class ItemShortcut; class MapItem; class TextCommand; class TextDialog; +class TextField; class ProgressBar; class Window; @@ -168,6 +169,8 @@ class PopupMenu final : public Popup, public LinkHandler void showPopup(const int x, const int y, gcn::ListModel *model); + void showTextFieldPopup(int x, int y, TextField *input); + /** * Handles link action. */ @@ -207,6 +210,7 @@ class PopupMenu final : public Popup, public LinkHandler TextDialog *mDialog; Button *mButton; std::string mNick; + TextField *mTextField; int mType; int mX; int mY; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index ada563b8d..4b7a86fe6 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -44,6 +44,7 @@ #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" #include "gui/widgets/progressbar.h" +#include "gui/widgets/textfield.h" #include "net/net.h" @@ -815,6 +816,11 @@ void Viewport::showMapPopup(const int x, const int y) mPopupMenu->showMapPopup(getMouseX(), getMouseY(), x, y); } +void Viewport::showTextFieldPopup(TextField *input) +{ + mPopupMenu->showTextFieldPopup(getMouseX(), getMouseY(), input); +} + void Viewport::closePopupMenu() { if (mPopupMenu) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 7cf02aecf..6953a3827 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -46,6 +46,7 @@ class PopupMenu; class ProgressBar; class StatusPopup; class TextCommand; +class TextField; class TextPopup; class Window; @@ -182,6 +183,8 @@ class Viewport final : public WindowContainer, void showMapPopup(const int x, const int y); + void showTextFieldPopup(TextField *input); + /** * Closes the popup menu. Needed for when the player dies or switching * maps. diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 2f0313c37..fad731e5a 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -211,6 +211,9 @@ class BrowserBox final : public gcn::Widget, std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED; + int getPadding() const A_WARN_UNUSED + { return mPadding; } + private: int calcHeight() A_WARN_UNUSED; diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 260b0fe57..3a6212b79 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -27,6 +27,7 @@ #include "keyevent.h" #include "gui/sdlinput.h" +#include "gui/viewport.h" #include "resources/image.h" @@ -515,3 +516,13 @@ void TextField::fontChanged() { fixScroll(); } + +void TextField::mousePressed(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) + { + if (viewport) + viewport->showTextFieldPopup(this); + } + else gcn::TextField::mousePressed(mouseEvent); +} diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 34ca88b4a..9220f3dd7 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -115,6 +115,12 @@ class TextField : public gcn::TextField, void setCaretPosition(unsigned int position); + void mousePressed(gcn::MouseEvent &mouseEvent) override; + + void handlePaste(); + + void handleCopy() const; + protected: void drawCaret(gcn::Graphics* graphics, int x) override; @@ -127,10 +133,6 @@ class TextField : public gcn::TextField, static Skin *mSkin; private: - void handlePaste(); - - void handleCopy() const; - static int instances; static float mAlpha; static ImageRect skin; |