summaryrefslogtreecommitdiff
path: root/src/resources/map/mapitem.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-11 15:42:53 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-11 15:42:53 +0300
commit50e0557d790ac007c2db63509b7beed6f8d15b1e (patch)
treebbc22a33ab9b392e731b9413c0c195a86e50eb14 /src/resources/map/mapitem.cpp
parent788f91b8b779a3b99cf4a7f8f53488f45b2edc09 (diff)
downloadmv-50e0557d790ac007c2db63509b7beed6f8d15b1e.tar.gz
mv-50e0557d790ac007c2db63509b7beed6f8d15b1e.tar.bz2
mv-50e0557d790ac007c2db63509b7beed6f8d15b1e.tar.xz
mv-50e0557d790ac007c2db63509b7beed6f8d15b1e.zip
Move mapitem into separate file.
Diffstat (limited to 'src/resources/map/mapitem.cpp')
-rw-r--r--src/resources/map/mapitem.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/src/resources/map/mapitem.cpp b/src/resources/map/mapitem.cpp
new file mode 100644
index 000000000..eee82d253
--- /dev/null
+++ b/src/resources/map/mapitem.cpp
@@ -0,0 +1,169 @@
+/*
+ * The ManaPlus Client
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/map/mapitem.h"
+
+#include "gui/font.h"
+#include "gui/gui.h"
+#include "gui/userpalette.h"
+
+#include "resources/image.h"
+#include "resources/resourcemanager.h"
+
+#include "render/graphics.h"
+
+#include "debug.h"
+
+MapItem::MapItem():
+ mImage(nullptr),
+ mComment(),
+ mName(),
+ mType(EMPTY),
+ mX(-1),
+ mY(-1)
+{
+ setType(EMPTY);
+}
+
+MapItem::MapItem(const int type):
+ mImage(nullptr),
+ mComment(),
+ mName(),
+ mType(type),
+ mX(-1),
+ mY(-1)
+{
+ setType(type);
+}
+
+MapItem::MapItem(const int type, std::string comment):
+ mImage(nullptr),
+ mComment(comment),
+ mName(),
+ mType(type),
+ mX(-1),
+ mY(-1)
+{
+ setType(type);
+}
+
+MapItem::MapItem(const int type, std::string comment,
+ const int x, const int y):
+ mImage(nullptr),
+ mComment(comment),
+ mName(),
+ mType(type),
+ mX(x),
+ mY(y)
+{
+ setType(type);
+}
+
+MapItem::~MapItem()
+{
+ if (mImage)
+ {
+ mImage->decRef();
+ mImage = nullptr;
+ }
+}
+
+void MapItem::setType(const int type)
+{
+ std::string name;
+ mType = type;
+ if (mImage)
+ mImage->decRef();
+
+ switch (type)
+ {
+ case ARROW_UP:
+ name = "graphics/sprites/arrow_up.png";
+ break;
+ case ARROW_DOWN:
+ name = "graphics/sprites/arrow_down.png";
+ break;
+ case ARROW_LEFT:
+ name = "graphics/sprites/arrow_left.png";
+ break;
+ case ARROW_RIGHT:
+ name = "graphics/sprites/arrow_right.png";
+ break;
+ default:
+ break;
+ }
+
+ if (!name.empty())
+ {
+ ResourceManager *const resman = ResourceManager::getInstance();
+ mImage = resman->getImage(name);
+ }
+ else
+ {
+ mImage = nullptr;
+ }
+}
+
+void MapItem::setPos(const int x, const int y)
+{
+ mX = x;
+ mY = y;
+}
+
+void MapItem::draw(Graphics *const graphics, const int x, const int y,
+ const int dx, const int dy) const
+{
+ BLOCK_START("MapItem::draw")
+ if (mImage)
+ graphics->drawImage(mImage, x, y);
+
+ switch (mType)
+ {
+ case ROAD:
+ case CROSS:
+ graphics->setColor(userPalette->getColorWithAlpha(
+ UserPalette::ROAD_POINT));
+ graphics->fillRectangle(Rect(x + dx / 3, y + dy / 3,
+ dx / 3, dy / 3));
+ break;
+ case HOME:
+ {
+ graphics->setColor(userPalette->getColorWithAlpha(
+ UserPalette::HOME_PLACE));
+ graphics->fillRectangle(Rect(x, y, dx, dy));
+ graphics->setColor(userPalette->getColorWithAlpha(
+ UserPalette::HOME_PLACE_BORDER));
+ graphics->drawRectangle(Rect(x, y, dx, dy));
+ break;
+ }
+ default:
+ break;
+ }
+ if (!mName.empty() && mType != PORTAL && mType != EMPTY)
+ {
+ Font *const font = gui->getFont();
+ if (font)
+ {
+ graphics->setColor(userPalette->getColor(UserPalette::BEING));
+ font->drawString(graphics, mName, x, y);
+ }
+ }
+ BLOCK_END("MapItem::draw")
+}