From 611210b1e0fd9cbaed38b229462e109d8f4be385 Mon Sep 17 00:00:00 2001 From: Forge Date: Fri, 9 Jan 2009 00:03:53 +0100 Subject: Now, the real stage 2.0 of smiley window. All is done, and all files are now in the tree. (ok, copyright of new files is still opened... do as you want, if you care) Signed-off-by: Forge --- src/gui/shortcutcontainer.cpp | 165 +----------------------------------------- 1 file changed, 1 insertion(+), 164 deletions(-) (limited to 'src/gui/shortcutcontainer.cpp') diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index f1a60189..32d7c6af 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -35,101 +35,10 @@ ShortcutContainer::ShortcutContainer(): mGridWidth(1), - mGridHeight(1), - mItemClicked(false), - mItemMoved(NULL) + mGridHeight(1) { - addMouseListener(this); - addWidgetListener(this); - - ResourceManager *resman = ResourceManager::getInstance(); - - mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png"); - mMaxItems = itemShortcut->getItemCount(); - - mBoxHeight = 42; - mBoxWidth = 36; -} - -ShortcutContainer::~ShortcutContainer() -{ - mBackgroundImg->decRef(); } -void -ShortcutContainer::logic() -{ - gcn::Widget::logic(); - - int i = itemShortcut->getItemCount(); - - if (i != mMaxItems) - { - mMaxItems = i; - setWidth(getWidth()); - } -} - -void -ShortcutContainer::draw(gcn::Graphics *graphics) -{ - Graphics *g = static_cast(graphics); - - graphics->setFont(getFont()); - - for (int i = 0; i < mMaxItems; i++) - { - const int itemX = (i % mGridWidth) * mBoxWidth; - const int itemY = (i / mGridWidth) * mBoxHeight; - - g->drawImage(mBackgroundImg, itemX, itemY); - - // Draw item keyboard shortcut. - const char *key = SDL_GetKeyName( - (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0 + i)); - graphics->setColor(0x000000); - g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); - - if (itemShortcut->getItem(i) < 0) - continue; - - Item *item = - player_node->getInventory()->findItem(itemShortcut->getItem(i)); - if (item) { - // Draw item icon. - const std::string label = - item->isEquipped() ? "Eq." : toString(item->getQuantity()); - Image* image = item->getImage(); - if (image) { - const std::string label = - item->isEquipped() ? "Eq." : toString(item->getQuantity()); - g->drawImage(image, itemX, itemY); - g->drawText( - label, - itemX + mBoxWidth / 2, - itemY + mBoxHeight - 14, - gcn::Graphics::CENTER); - } - } - } - if (mItemMoved) - { - // Draw the item image being dragged by the cursor. - Image* image = mItemMoved->getImage(); - if (image) - { - const int tPosX = mCursorPosX - (image->getWidth() / 2); - const int tPosY = mCursorPosY - (image->getHeight() / 2); - - g->drawImage(image, tPosX, tPosY); - g->drawText( - toString(mItemMoved->getQuantity()), - tPosX + mBoxWidth / 2, - tPosY + mBoxHeight - 14, - gcn::Graphics::CENTER); - } - } -} void ShortcutContainer::widgetResized(const gcn::Event &event) { @@ -147,78 +56,6 @@ void ShortcutContainer::widgetResized(const gcn::Event &event) } } -void -ShortcutContainer::mouseDragged(gcn::MouseEvent &event) -{ - if (event.getButton() == gcn::MouseEvent::LEFT) { - if (!mItemMoved && mItemClicked) { - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - return; - } - const int itemId = itemShortcut->getItem(index); - if (itemId < 0) - return; - Item *item = player_node->getInventory()->findItem(itemId); - if (item) - { - mItemMoved = item; - itemShortcut->removeItem(index); - } - } - if (mItemMoved) { - mCursorPosX = event.getX(); - mCursorPosY = event.getY(); - } - } -} - -void -ShortcutContainer::mousePressed(gcn::MouseEvent &event) -{ - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - return; - } - - // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) { - itemShortcut->setItem(index); - itemShortcut->setItemSelected(-1); - } - else if (itemShortcut->getItem(index)) { - mItemClicked = true; - } -} - -void -ShortcutContainer::mouseReleased(gcn::MouseEvent &event) -{ - if (event.getButton() == gcn::MouseEvent::LEFT) - { - if (itemShortcut->isItemSelected()) - { - itemShortcut->setItemSelected(-1); - } - const int index = getIndexFromGrid(event.getX(), event.getY()); - if (index == -1) { - mItemMoved = NULL; - return; - } - if (mItemMoved) { - itemShortcut->setItems(index, mItemMoved->getId()); - mItemMoved = NULL; - } - else if (itemShortcut->getItem(index) && mItemClicked) - { - itemShortcut->useItem(index); - } - if (mItemClicked) { - mItemClicked = false; - } - } -} - int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const { -- cgit v1.2.3-70-g09d2