Mana
Loading...
Searching...
No Matches
emoteshortcutcontainer.cpp
Go to the documentation of this file.
1/*
2 * Extended support for activating emotes
3 * Copyright (C) 2009 Aethyra Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "emoteshortcut.h"
25#include "graphics.h"
26#include "keyboardconfig.h"
27
28#include "gui/gui.h"
29
30#include "resources/emotedb.h"
31#include "resources/image.h"
32#include "resources/theme.h"
33
34static const int MAX_ITEMS = 12;
35
40
42{
43 auto *g = static_cast<Graphics*>(graphics);
44 auto theme = gui->getTheme();
45
46 graphics->setFont(getFont());
47
48 for (int i = 0; i < mMaxItems; i++)
49 {
50 WidgetState state;
51 state.x = (i % mGridWidth) * mBoxWidth;
52 state.y = (i / mGridWidth) * mBoxHeight;
53 theme->drawSkin(g, SkinType::ShortcutBox, state);
54
55 // Draw emote keyboard shortcut.
56 const char *key = SDL_GetKeyName(
59 g->drawText(key, state.x + 2, state.y + 2, gcn::Graphics::LEFT);
60
61 int emoteId = emoteShortcut->getEmote(i);
62 if (emoteId != -1)
63 {
64 if (auto image = EmoteDB::get(emoteId).image)
65 {
66 image->setAlpha(1.0f);
67 g->drawImage(image, state.x + 2, state.y + 10);
68 }
69 }
70 }
71
72 if (mEmoteMoved != -1)
73 {
74 // Draw the emote image being dragged by the cursor.
75 if (auto image = EmoteDB::get(mEmoteMoved).image)
76 {
77 image->setAlpha(1.0f);
78
79 const int tPosX = mCursorPosX - (image->getWidth() / 2);
80 const int tPosY = mCursorPosY - (image->getHeight() / 2);
81
82 g->drawImage(image, tPosX, tPosY);
83 }
84 }
85}
86
87void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event)
88{
89 if (event.getButton() == gcn::MouseEvent::LEFT)
90 {
91 if (mEmoteMoved == -1 && mEmoteClicked)
92 {
93 const int index = getIndexFromGrid(event.getX(), event.getY());
94 if (index == -1)
95 return;
96
97 const int emoteId = emoteShortcut->getEmote(index);
98 if (emoteId != -1)
99 {
100 mEmoteMoved = emoteId;
102 }
103 }
104
105 if (mEmoteMoved != -1)
106 {
107 mCursorPosX = event.getX();
108 mCursorPosY = event.getY();
109 }
110 }
111}
112
113void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event)
114{
115 const int index = getIndexFromGrid(event.getX(), event.getY());
116 if (index == -1)
117 return;
118
119 // Stores the selected emote if there is one.
121 {
122 emoteShortcut->setEmote(index);
124 }
125 else if (emoteShortcut->getEmote(index) != -1)
126 {
127 mEmoteClicked = true;
128 }
129}
130
131void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event)
132{
133 if (event.getButton() == gcn::MouseEvent::LEFT)
134 {
135 const int index = getIndexFromGrid(event.getX(), event.getY());
136
139
140 if (index == -1)
141 {
142 mEmoteMoved = -1;
143 return;
144 }
145
146 if (mEmoteMoved != -1)
147 {
149 mEmoteMoved = -1;
150 }
151 else if (mEmoteClicked)
152 {
153 emoteShortcut->useEmote(index);
154 }
155
156 mEmoteClicked = false;
157 }
158}
void mousePressed(gcn::MouseEvent &event) override
Handles mouse when pressed.
void draw(gcn::Graphics *graphics) override
Draws the items.
void mouseReleased(gcn::MouseEvent &event) override
Handles mouse release.
void mouseDragged(gcn::MouseEvent &event) override
Handles mouse when dragged.
void useEmote(int index)
Try to use the Emote specified by the index.
void setEmoteSelected(int emoteId)
Set the Emote that is selected.
bool isEmoteSelected() const
A flag to check if the Emote is selected.
void removeEmote(int index)
Remove a Emote from the shortcut.
int getEmote(int index) const
Returns the shortcut Emote ID specified by the index.
void setEmote(int index)
Adds the selected emote ID to the emotes specified by the index.
void setEmotes(int index, int emoteId)
Adds a emoticon to the emotes store specified by the index.
A central point of control for graphics.
Definition graphics.h:78
void setColor(const gcn::Color &color) override
Definition graphics.h:255
Theme * getTheme() const
The global GUI theme.
Definition gui.h:138
int getKeyValue(int index) const
Obtain the value stored in memory.
int getIndexFromGrid(int pointX, int pointY) const
Gets the index from the grid provided the point is in an item box.
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
Definition theme.cpp:313
@ TEXT
Definition theme.h:214
Graphics * graphics
Definition client.cpp:104
KeyboardConfig keyboard
Definition client.cpp:101
EmoteShortcut * emoteShortcut
Gui * gui
The GUI system.
Definition gui.cpp:50
const Emote & get(int id)
Definition emotedb.cpp:115
int getEmoteCount()
Definition emotedb.cpp:134