~ubuntu-branches/ubuntu/saucy/manaplus/saucy-proposed

« back to all changes in this revision

Viewing changes to src/gui/widgets/dropshortcutcontainer.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi, Andrei Karas, Patrick Matthäi
  • Date: 2013-06-10 10:53:26 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130610105326-c3xqk5ebcgy3jxmb
Tags: 1.3.6.9-1
[ Andrei Karas ]
* Add new files to copyright file.

[ Patrick Matthäi ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "gui/widgets/dropshortcutcontainer.h"
24
24
 
25
 
#include "gui/inventorywindow.h"
26
 
#include "gui/itempopup.h"
27
 
#include "gui/viewport.h"
28
 
 
29
25
#include "client.h"
 
26
#include "dragdrop.h"
30
27
#include "dropshortcut.h"
31
28
#include "keyboardconfig.h"
32
29
#include "localplayer.h"
33
30
#include "playerinfo.h"
34
31
 
 
32
#include "gui/inventorywindow.h"
 
33
#include "gui/itempopup.h"
 
34
#include "gui/viewport.h"
 
35
 
35
36
#include "resources/image.h"
36
37
#include "resources/resourcemanager.h"
37
38
 
42
43
DropShortcutContainer::DropShortcutContainer():
43
44
    ShortcutContainer(),
44
45
    mItemClicked(false),
45
 
    mItemMoved(nullptr),
46
46
    mItemPopup(new ItemPopup),
47
47
    mEquipedColor(getThemeColor(Theme::ITEM_EQUIPPED)),
48
48
    mEquipedColor2(getThemeColor(Theme::ITEM_EQUIPPED_OUTLINE)),
153
153
            }
154
154
        }
155
155
    }
156
 
 
157
 
    if (mItemMoved)
158
 
    {
159
 
        // Draw the item image being dragged by the cursor.
160
 
        const Image *const image = mItemMoved->getImage();
161
 
        if (image)
162
 
        {
163
 
            const int tPosX = mCursorPosX - (image->mBounds.w / 2);
164
 
            const int tPosY = mCursorPosY - (image->mBounds.h / 2);
165
 
            const std::string str = toString(mItemMoved->getQuantity());
166
 
 
167
 
            g->drawImage(image, tPosX, tPosY);
168
 
            font->drawString(g, str,
169
 
                tPosX + (mBoxWidth / 2 - font->getWidth(str)) / 2,
170
 
                tPosY + mBoxHeight - 14);
171
 
        }
172
 
    }
173
156
    BLOCK_END("DropShortcutContainer::draw")
174
157
}
175
158
 
180
163
 
181
164
    if (event.getButton() == gcn::MouseEvent::LEFT)
182
165
    {
183
 
        if (!mItemMoved && mItemClicked)
 
166
        if (dragDrop.isEmpty() && mItemClicked)
184
167
        {
185
168
            const int index = getIndexFromGrid(event.getX(), event.getY());
186
169
 
201
184
 
202
185
            if (item)
203
186
            {
204
 
                mItemMoved = item;
 
187
                dragDrop.dragItem(item, DRAGDROP_SOURCE_DROP);
205
188
                dropShortcut->removeItem(index);
206
189
            }
207
 
        }
208
 
        if (mItemMoved)
209
 
        {
210
 
            mCursorPosX = event.getX();
211
 
            mCursorPosY = event.getY();
 
190
            else
 
191
            {
 
192
                dragDrop.clear();
 
193
            }
212
194
        }
213
195
    }
214
196
}
223
205
    if (index == -1)
224
206
        return;
225
207
 
226
 
    if (event.getButton() == gcn::MouseEvent::LEFT)
 
208
    const int eventButton = event.getButton();
 
209
    if (eventButton == gcn::MouseEvent::LEFT)
227
210
    {
228
 
        // Stores the selected item if theirs one.
229
 
        if (dropShortcut->isItemSelected()
230
 
            && inventoryWindow->isWindowVisible())
231
 
        {
232
 
            dropShortcut->setItem(index);
233
 
            dropShortcut->setItemSelected(-1);
234
 
            inventoryWindow->unselectItem();
235
 
        }
236
 
        else if (dropShortcut->getItem(index))
 
211
        if (dropShortcut->getItem(index) > 0)
237
212
        {
238
213
            mItemClicked = true;
239
214
        }
 
215
        else
 
216
        {
 
217
            if (dragDrop.isSelected())
 
218
            {
 
219
                dropShortcut->setItems(index, dragDrop.getSelected(),
 
220
                    dragDrop.getSelectedColor());
 
221
                dragDrop.deselect();
 
222
            }
 
223
        }
240
224
    }
241
 
    else if (event.getButton() == gcn::MouseEvent::RIGHT)
 
225
    else if (eventButton == gcn::MouseEvent::RIGHT)
242
226
    {
243
227
        const Inventory *const inv = PlayerInfo::getInventory();
244
228
        if (!inv)
265
249
        const int index = getIndexFromGrid(event.getX(), event.getY());
266
250
        if (index == -1)
267
251
        {
268
 
            mItemMoved = nullptr;
 
252
            dragDrop.clear();
269
253
            return;
270
254
        }
271
 
        if (mItemMoved)
 
255
        if (!dragDrop.isEmpty())
272
256
        {
273
 
            dropShortcut->setItems(index, mItemMoved->getId(),
274
 
                mItemMoved->getColor());
275
 
            mItemMoved = nullptr;
 
257
            dropShortcut->setItems(index, dragDrop.getItem(),
 
258
                dragDrop.getItemColor());
 
259
            dragDrop.clear();
 
260
            dragDrop.deselect();
276
261
        }
277
262
 
278
 
        if (mItemClicked)
279
 
            mItemClicked = false;
 
263
        mItemClicked = false;
280
264
    }
281
265
}
282
266
 
314
298
    }
315
299
}
316
300
 
317
 
// Hide ItemTooltip
318
301
void DropShortcutContainer::mouseExited(gcn::MouseEvent &event A_UNUSED)
319
302
{
320
303
    if (mItemPopup)