From 506a064c94e44d4f896fa9b2dc74d30e7f7f8c33 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 18 Aug 2014 18:11:02 +0300 Subject: Rename DropShortcutContainer into VirtShortcutContainer. --- src/gui/widgets/dropshortcutcontainer.cpp | 302 ------------------------------ src/gui/widgets/dropshortcutcontainer.h | 91 --------- src/gui/widgets/virtshortcutcontainer.cpp | 301 +++++++++++++++++++++++++++++ src/gui/widgets/virtshortcutcontainer.h | 91 +++++++++ 4 files changed, 392 insertions(+), 393 deletions(-) delete mode 100644 src/gui/widgets/dropshortcutcontainer.cpp delete mode 100644 src/gui/widgets/dropshortcutcontainer.h create mode 100644 src/gui/widgets/virtshortcutcontainer.cpp create mode 100644 src/gui/widgets/virtshortcutcontainer.h (limited to 'src/gui') diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp deleted file mode 100644 index 417cc2df2..000000000 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2009 The Mana World Development Team - * Copyright (C) 2009-2010 Andrei Karas - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "gui/widgets/dropshortcutcontainer.h" - -#include "dragdrop.h" -#include "dropshortcut.h" -#include "shortcutbase.h" -#include "settings.h" - -#include "being/playerinfo.h" - -#include "gui/popupmanager.h" -#include "gui/viewport.h" - -#include "gui/fonts/font.h" - -#include "gui/popups/itempopup.h" -#include "gui/popups/popupmenu.h" - -#include "gui/windows/inventorywindow.h" - -#include "resources/image.h" - -#include "utils/delete2.h" -#include "utils/stringutils.h" - -#include "debug.h" - -DropShortcutContainer::DropShortcutContainer(Widget2 *const widget, - ShortcutBase *const shortcut) : - ShortcutContainer(widget), - mItemClicked(false), - mEquipedColor(getThemeColor(Theme::ITEM_EQUIPPED)), - mEquipedColor2(getThemeColor(Theme::ITEM_EQUIPPED_OUTLINE)), - mUnEquipedColor(getThemeColor(Theme::ITEM_NOT_EQUIPPED)), - mUnEquipedColor2(getThemeColor(Theme::ITEM_NOT_EQUIPPED_OUTLINE)), - mShortcut(shortcut) -{ - if (mShortcut) - mMaxItems = mShortcut->getItemCount(); - else - mMaxItems = 0; -} - -DropShortcutContainer::~DropShortcutContainer() -{ -} - -void DropShortcutContainer::setWidget2(const Widget2 *const widget) -{ - Widget2::setWidget2(widget); - mEquipedColor = getThemeColor(Theme::ITEM_EQUIPPED); - mEquipedColor2 = getThemeColor(Theme::ITEM_EQUIPPED_OUTLINE); - mUnEquipedColor = getThemeColor(Theme::ITEM_NOT_EQUIPPED); - mUnEquipedColor2 = getThemeColor(Theme::ITEM_NOT_EQUIPPED_OUTLINE); -} - -void DropShortcutContainer::draw(Graphics *graphics) -{ - if (!mShortcut) - return; - - BLOCK_START("DropShortcutContainer::draw") - if (settings.guiAlpha != mAlpha) - { - mAlpha = settings.guiAlpha; - if (mBackgroundImg) - mBackgroundImg->setAlpha(mAlpha); - } - - drawBackground(graphics); - - const Inventory *const inv = PlayerInfo::getInventory(); - if (!inv) - { - BLOCK_END("DropShortcutContainer::draw") - return; - } - - Font *const font = getFont(); - - for (unsigned i = 0; i < mMaxItems; i++) - { - const int itemX = (i % mGridWidth) * mBoxWidth; - const int itemY = (i / mGridWidth) * mBoxHeight; - - if (mShortcut->getItem(i) < 0) - continue; - - const Item *const item = inv->findItem(mShortcut->getItem(i), - mShortcut->getItemColor(i)); - - if (item) - { - // Draw item icon. - Image *const image = item->getImage(); - - if (image) - { - std::string caption; - if (item->getQuantity() > 1) - caption = toString(item->getQuantity()); - else if (item->isEquipped()) - caption = "Eq."; - - image->setAlpha(1.0F); - graphics->drawImage(image, itemX, itemY); - if (item->isEquipped()) - graphics->setColorAll(mEquipedColor, mEquipedColor2); - else - graphics->setColorAll(mUnEquipedColor, mUnEquipedColor2); - font->drawString(graphics, caption, - itemX + (mBoxWidth - font->getWidth(caption)) / 2, - itemY + mBoxHeight - 14); - } - } - } - BLOCK_END("DropShortcutContainer::draw") -} - -void DropShortcutContainer::mouseDragged(MouseEvent &event) -{ - if (!mShortcut) - return; - - if (event.getButton() == MouseButton::LEFT) - { - if (dragDrop.isEmpty() && mItemClicked) - { - const int index = getIndexFromGrid(event.getX(), event.getY()); - - if (index == -1) - return; - - const int itemId = mShortcut->getItem(index); - const unsigned char itemColor = mShortcut->getItemColor(index); - - if (itemId < 0) - return; - - const Inventory *const inv = PlayerInfo::getInventory(); - if (!inv) - return; - - Item *const item = inv->findItem(itemId, itemColor); - - if (item) - { - dragDrop.dragItem(item, DRAGDROP_SOURCE_DROP); - mShortcut->removeItem(index); - } - else - { - dragDrop.clear(); - } - } - } -} - -void DropShortcutContainer::mousePressed(MouseEvent &event) -{ - if (!mShortcut || !inventoryWindow) - return; - - const int index = getIndexFromGrid(event.getX(), event.getY()); - - if (index == -1) - return; - - event.consume(); - - const MouseButton::Type eventButton = event.getButton(); - if (eventButton == MouseButton::LEFT) - { - if (mShortcut->getItem(index) > 0) - { - mItemClicked = true; - } - else - { - if (dragDrop.isSelected()) - { - mShortcut->setItems(index, dragDrop.getSelected(), - dragDrop.getSelectedColor()); - dragDrop.deselect(); - } - } - } - else if (eventButton == MouseButton::RIGHT) - { - const Inventory *const inv = PlayerInfo::getInventory(); - if (!inv) - return; - - Item *const item = inv->findItem(mShortcut->getItem(index), - mShortcut->getItemColor(index)); - - if (popupMenu) - { - popupMenu->showDropPopup(viewport->mMouseX, - viewport->mMouseY, - item); - } - } -} - -void DropShortcutContainer::mouseReleased(MouseEvent &event) -{ - if (!mShortcut) - return; - - if (event.getButton() == MouseButton::LEFT) - { - if (mShortcut->isItemSelected()) - mShortcut->setItemSelected(-1); - - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) - { - dragDrop.clear(); - return; - } - if (!dragDrop.isEmpty()) - { - if (dragDrop.isSourceItemContainer()) - { - mShortcut->setItems(index, dragDrop.getItem(), - dragDrop.getItemColor()); - dragDrop.clear(); - dragDrop.deselect(); - } - } - - mItemClicked = false; - } -} - -// Show ItemTooltip -void DropShortcutContainer::mouseMoved(MouseEvent &event) -{ - if (!mShortcut) - return; - - const int index = getIndexFromGrid(event.getX(), event.getY()); - - if (index == -1) - return; - - const int itemId = mShortcut->getItem(index); - const unsigned char itemColor = mShortcut->getItemColor(index); - - if (itemId < 0) - return; - - const Inventory *const inv = PlayerInfo::getInventory(); - if (!inv) - return; - - const Item *const item = inv->findItem(itemId, itemColor); - - if (item && viewport) - { - itemPopup->setItem(item); - itemPopup->position(viewport->mMouseX, viewport->mMouseY); - } - else - { - itemPopup->setVisible(false); - } -} - -void DropShortcutContainer::mouseExited(MouseEvent &event A_UNUSED) -{ - if (itemPopup) - itemPopup->setVisible(false); -} - -void DropShortcutContainer::widgetHidden(const Event &event A_UNUSED) -{ - if (itemPopup) - itemPopup->setVisible(false); -} diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h deleted file mode 100644 index 23addb8c2..000000000 --- a/src/gui/widgets/dropshortcutcontainer.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2009 The Mana World Development Team - * Copyright (C) 2009-2010 Andrei Karas - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef GUI_WIDGETS_DROPSHORTCUTCONTAINER_H -#define GUI_WIDGETS_DROPSHORTCUTCONTAINER_H - -#include "gui/widgets/shortcutcontainer.h" - -class ItemPopup; -class ShortcutBase; - -/** - * An item shortcut container. Used to quickly use items. - * - * \ingroup GUI - */ -class DropShortcutContainer final : public ShortcutContainer -{ - public: - /** - * Constructor. Initializes the graphic. - */ - DropShortcutContainer(Widget2 *const widget, - ShortcutBase *const shortcut); - - A_DELETE_COPY(DropShortcutContainer) - - /** - * Destructor. - */ - ~DropShortcutContainer(); - - /** - * Draws the items. - */ - void draw(Graphics *graphics) override final; - - /** - * Handles mouse when dragged. - */ - void mouseDragged(MouseEvent &event) override final; - - /** - * Handles mouse when pressed. - */ - void mousePressed(MouseEvent &event) override final; - - /** - * Handles mouse release. - */ - void mouseReleased(MouseEvent &event) override final; - - void widgetHidden(const Event &event) override final; - - void mouseExited(MouseEvent &event) override final; - - void mouseMoved(MouseEvent &event) override final; - - void setWidget2(const Widget2 *const widget) override final; - - private: - bool mItemClicked; - - Color mEquipedColor; - Color mEquipedColor2; - Color mUnEquipedColor; - Color mUnEquipedColor2; - - ShortcutBase *mShortcut; -}; - -#endif // GUI_WIDGETS_DROPSHORTCUTCONTAINER_H diff --git a/src/gui/widgets/virtshortcutcontainer.cpp b/src/gui/widgets/virtshortcutcontainer.cpp new file mode 100644 index 000000000..2b0353148 --- /dev/null +++ b/src/gui/widgets/virtshortcutcontainer.cpp @@ -0,0 +1,301 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui/widgets/virtshortcutcontainer.h" + +#include "dragdrop.h" +#include "shortcutbase.h" +#include "settings.h" + +#include "being/playerinfo.h" + +#include "gui/popupmanager.h" +#include "gui/viewport.h" + +#include "gui/fonts/font.h" + +#include "gui/popups/itempopup.h" +#include "gui/popups/popupmenu.h" + +#include "gui/windows/inventorywindow.h" + +#include "resources/image.h" + +#include "utils/delete2.h" +#include "utils/stringutils.h" + +#include "debug.h" + +VirtShortcutContainer::VirtShortcutContainer(Widget2 *const widget, + ShortcutBase *const shortcut) : + ShortcutContainer(widget), + mItemClicked(false), + mEquipedColor(getThemeColor(Theme::ITEM_EQUIPPED)), + mEquipedColor2(getThemeColor(Theme::ITEM_EQUIPPED_OUTLINE)), + mUnEquipedColor(getThemeColor(Theme::ITEM_NOT_EQUIPPED)), + mUnEquipedColor2(getThemeColor(Theme::ITEM_NOT_EQUIPPED_OUTLINE)), + mShortcut(shortcut) +{ + if (mShortcut) + mMaxItems = mShortcut->getItemCount(); + else + mMaxItems = 0; +} + +VirtShortcutContainer::~VirtShortcutContainer() +{ +} + +void VirtShortcutContainer::setWidget2(const Widget2 *const widget) +{ + Widget2::setWidget2(widget); + mEquipedColor = getThemeColor(Theme::ITEM_EQUIPPED); + mEquipedColor2 = getThemeColor(Theme::ITEM_EQUIPPED_OUTLINE); + mUnEquipedColor = getThemeColor(Theme::ITEM_NOT_EQUIPPED); + mUnEquipedColor2 = getThemeColor(Theme::ITEM_NOT_EQUIPPED_OUTLINE); +} + +void VirtShortcutContainer::draw(Graphics *graphics) +{ + if (!mShortcut) + return; + + BLOCK_START("VirtShortcutContainer::draw") + if (settings.guiAlpha != mAlpha) + { + mAlpha = settings.guiAlpha; + if (mBackgroundImg) + mBackgroundImg->setAlpha(mAlpha); + } + + drawBackground(graphics); + + const Inventory *const inv = PlayerInfo::getInventory(); + if (!inv) + { + BLOCK_END("VirtShortcutContainer::draw") + return; + } + + Font *const font = getFont(); + + for (unsigned i = 0; i < mMaxItems; i++) + { + const int itemX = (i % mGridWidth) * mBoxWidth; + const int itemY = (i / mGridWidth) * mBoxHeight; + + if (mShortcut->getItem(i) < 0) + continue; + + const Item *const item = inv->findItem(mShortcut->getItem(i), + mShortcut->getItemColor(i)); + + if (item) + { + // Draw item icon. + Image *const image = item->getImage(); + + if (image) + { + std::string caption; + if (item->getQuantity() > 1) + caption = toString(item->getQuantity()); + else if (item->isEquipped()) + caption = "Eq."; + + image->setAlpha(1.0F); + graphics->drawImage(image, itemX, itemY); + if (item->isEquipped()) + graphics->setColorAll(mEquipedColor, mEquipedColor2); + else + graphics->setColorAll(mUnEquipedColor, mUnEquipedColor2); + font->drawString(graphics, caption, + itemX + (mBoxWidth - font->getWidth(caption)) / 2, + itemY + mBoxHeight - 14); + } + } + } + BLOCK_END("VirtShortcutContainer::draw") +} + +void VirtShortcutContainer::mouseDragged(MouseEvent &event) +{ + if (!mShortcut) + return; + + if (event.getButton() == MouseButton::LEFT) + { + if (dragDrop.isEmpty() && mItemClicked) + { + const int index = getIndexFromGrid(event.getX(), event.getY()); + + if (index == -1) + return; + + const int itemId = mShortcut->getItem(index); + const unsigned char itemColor = mShortcut->getItemColor(index); + + if (itemId < 0) + return; + + const Inventory *const inv = PlayerInfo::getInventory(); + if (!inv) + return; + + Item *const item = inv->findItem(itemId, itemColor); + + if (item) + { + dragDrop.dragItem(item, DRAGDROP_SOURCE_DROP); + mShortcut->removeItem(index); + } + else + { + dragDrop.clear(); + } + } + } +} + +void VirtShortcutContainer::mousePressed(MouseEvent &event) +{ + if (!mShortcut || !inventoryWindow) + return; + + const int index = getIndexFromGrid(event.getX(), event.getY()); + + if (index == -1) + return; + + event.consume(); + + const MouseButton::Type eventButton = event.getButton(); + if (eventButton == MouseButton::LEFT) + { + if (mShortcut->getItem(index) > 0) + { + mItemClicked = true; + } + else + { + if (dragDrop.isSelected()) + { + mShortcut->setItems(index, dragDrop.getSelected(), + dragDrop.getSelectedColor()); + dragDrop.deselect(); + } + } + } + else if (eventButton == MouseButton::RIGHT) + { + const Inventory *const inv = PlayerInfo::getInventory(); + if (!inv) + return; + + Item *const item = inv->findItem(mShortcut->getItem(index), + mShortcut->getItemColor(index)); + + if (popupMenu) + { + popupMenu->showDropPopup(viewport->mMouseX, + viewport->mMouseY, + item); + } + } +} + +void VirtShortcutContainer::mouseReleased(MouseEvent &event) +{ + if (!mShortcut) + return; + + if (event.getButton() == MouseButton::LEFT) + { + if (mShortcut->isItemSelected()) + mShortcut->setItemSelected(-1); + + const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) + { + dragDrop.clear(); + return; + } + if (!dragDrop.isEmpty()) + { + if (dragDrop.isSourceItemContainer()) + { + mShortcut->setItems(index, dragDrop.getItem(), + dragDrop.getItemColor()); + dragDrop.clear(); + dragDrop.deselect(); + } + } + + mItemClicked = false; + } +} + +// Show ItemTooltip +void VirtShortcutContainer::mouseMoved(MouseEvent &event) +{ + if (!mShortcut) + return; + + const int index = getIndexFromGrid(event.getX(), event.getY()); + + if (index == -1) + return; + + const int itemId = mShortcut->getItem(index); + const unsigned char itemColor = mShortcut->getItemColor(index); + + if (itemId < 0) + return; + + const Inventory *const inv = PlayerInfo::getInventory(); + if (!inv) + return; + + const Item *const item = inv->findItem(itemId, itemColor); + + if (item && viewport) + { + itemPopup->setItem(item); + itemPopup->position(viewport->mMouseX, viewport->mMouseY); + } + else + { + itemPopup->setVisible(false); + } +} + +void VirtShortcutContainer::mouseExited(MouseEvent &event A_UNUSED) +{ + if (itemPopup) + itemPopup->setVisible(false); +} + +void VirtShortcutContainer::widgetHidden(const Event &event A_UNUSED) +{ + if (itemPopup) + itemPopup->setVisible(false); +} diff --git a/src/gui/widgets/virtshortcutcontainer.h b/src/gui/widgets/virtshortcutcontainer.h new file mode 100644 index 000000000..e740b9661 --- /dev/null +++ b/src/gui/widgets/virtshortcutcontainer.h @@ -0,0 +1,91 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H +#define GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H + +#include "gui/widgets/shortcutcontainer.h" + +class ItemPopup; +class ShortcutBase; + +/** + * An item shortcut container. Used to quickly use items. + * + * \ingroup GUI + */ +class VirtShortcutContainer final : public ShortcutContainer +{ + public: + /** + * Constructor. Initializes the graphic. + */ + VirtShortcutContainer(Widget2 *const widget, + ShortcutBase *const shortcut); + + A_DELETE_COPY(VirtShortcutContainer) + + /** + * Destructor. + */ + ~VirtShortcutContainer(); + + /** + * Draws the items. + */ + void draw(Graphics *graphics) override final; + + /** + * Handles mouse when dragged. + */ + void mouseDragged(MouseEvent &event) override final; + + /** + * Handles mouse when pressed. + */ + void mousePressed(MouseEvent &event) override final; + + /** + * Handles mouse release. + */ + void mouseReleased(MouseEvent &event) override final; + + void widgetHidden(const Event &event) override final; + + void mouseExited(MouseEvent &event) override final; + + void mouseMoved(MouseEvent &event) override final; + + void setWidget2(const Widget2 *const widget) override final; + + private: + bool mItemClicked; + + Color mEquipedColor; + Color mEquipedColor2; + Color mUnEquipedColor; + Color mUnEquipedColor2; + + ShortcutBase *mShortcut; +}; + +#endif // GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H -- cgit v1.2.3-60-g2f50