ManaPlus
itemcontainer.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WIDGETS_ITEMCONTAINER_H
25 #define GUI_WIDGETS_ITEMCONTAINER_H
26 
27 #include "listeners/keylistener.h"
30 
33 
34 #include "gui/widgets/widget.h"
35 
36 #include "localconsts.h"
37 
38 class Image;
39 class ImageCollection;
40 class Inventory;
41 class Item;
42 class SelectionListener;
43 
49 class ItemContainer final : public Widget,
50  public KeyListener,
51  public MouseListener,
52  public WidgetListener
53 {
54  public:
55  ItemContainer(const Widget2 *const widget,
56  Inventory *const inventory,
57  const int maxColumns,
58  const ShowEmptyRows showEmptyRows,
59  const ForceQuantity forceQuantity);
60 
62 
63 
66  ~ItemContainer() override final;
67 
71  void logic() override final;
72 
76  void draw(Graphics *const graphics) override final A_NONNULL(2);
77 
78  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
79 
80  // KeyListener
81  void keyPressed(KeyEvent &event) override final;
82  void keyReleased(KeyEvent &event) override final;
83 
84  // MouseListener
85  void mousePressed(MouseEvent &event) override final;
86  void mouseDragged(MouseEvent &event) override final;
87  void mouseReleased(MouseEvent &event) override final;
88  void mouseMoved(MouseEvent &event) override final;
89  void mouseExited(MouseEvent &event) override final;
90 
91  // WidgetListener
92  void widgetResized(const Event &event) override final;
93 
94  void widgetMoved(const Event &event) override final;
95 
100 
104  void selectNone();
105 
111  { mSelectionListeners.push_back(listener); }
112 
118  { mSelectionListeners.remove(listener); }
119 
120  void setFilter(const int tag);
121 
122  void setSortType(const int sortType);
123 
124  void setName(const std::string &str)
125  { mName = str; }
126 
127  int updateMatrix();
128 
130  { return mClicks != 0; }
131 
133  { mInventory = nullptr; }
134 
135  void setInventory(Inventory *const inventory) noexcept2
136  { mInventory = inventory; }
137 
138  void setCellBackgroundImage(const std::string &xmlName);
139 
140  void setMaxColumns(const int maxColumns);
141 
142  private:
144  {
145  Left = 0,
147  Up,
148  Down
149  };
150 
152  {
153  SEL_NONE = 0,
158  };
159 
163  void setSelectedIndex(const int index);
164 
168  void adjustHeight();
169 
174 
175  void updateSize();
176 
184  int getSlotIndex(int x, int y) const;
185 
186  int getSlotByXY(int x, int y) const;
187 
192  std::string mName;
193 
201  typedef std::list<SelectionListener*> SelectionListenerList;
202  typedef SelectionListenerList::iterator SelectionListenerIterator;
209  int mTag;
211  int mClicks;
222 };
223 
224 #endif // GUI_WIDGETS_ITEMCONTAINER_H
Definition: color.h:76
Definition: event.h:79
Image * mCellBackgroundImg
SelectionListenerList::iterator SelectionListenerIterator
int getSlotIndex(int x, int y) const
void setFilter(const int tag)
void setSelectedIndex(const int index)
void unsetInventory()
void keyReleased(KeyEvent &event)
Color mEquipedColor2
SelectionState mSelectionStatus
Color mUnEquipedColor
void setCellBackgroundImage(const std::string &xmlName)
void mouseExited(MouseEvent &event)
void draw(Graphics *const graphics)
void keyPressed(KeyEvent &event)
ShowEmptyRows mShowEmptyRows
void setInventory(Inventory *const inventory)
void widgetMoved(const Event &event)
std::list< SelectionListener * > SelectionListenerList
void setName(const std::string &str)
void mouseReleased(MouseEvent &event)
std::string mName
int getSlotByXY(int x, int y) const
void addSelectionListener(SelectionListener *listener)
void safeDraw(Graphics *const graphics)
void setMaxColumns(const int maxColumns)
int mEquippedTextPadding
void widgetResized(const Event &event)
Item * getSelectedItem() const
Color mUnEquipedColor2
ForceQuantity mForceQuantity
void distributeValueChangedEvent()
void setSortType(const int sortType)
void mousePressed(MouseEvent &event)
ImageCollection * mVertexes
void removeSelectionListener(SelectionListener *listener)
Inventory * mInventory
ItemContainer(const Widget2 *const widget, Inventory *const inventory, const int maxColumns, const ShowEmptyRows showEmptyRows, const ForceQuantity forceQuantity)
void mouseDragged(MouseEvent &event)
SelectionListenerList mSelectionListeners
Image * mProtectedImg
bool getClickCount() const
void mouseMoved(MouseEvent &event)
Definition: item.h:50
Definition: skin.h:37
Definition: widget.h:99
bool ForceQuantity
Definition: forcequantity.h:30
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
bool ShowEmptyRows
Definition: showemptyrows.h:30