aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/widgets
diff options
context:
space:
mode:
authorĽubomír Remák2018-04-11 21:15:01 +0200
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commitc25ed8957228cfd580216383c3391ccc7e512bb5 (patch)
treefff52e7d5e588719ced3b164b6ea48c9779236af /engines/mutationofjb/widgets
parent9af3d8a2381fe7c7440330a9aa338f51cd734990 (diff)
downloadscummvm-rg350-c25ed8957228cfd580216383c3391ccc7e512bb5.tar.gz
scummvm-rg350-c25ed8957228cfd580216383c3391ccc7e512bb5.tar.bz2
scummvm-rg350-c25ed8957228cfd580216383c3391ccc7e512bb5.zip
MUTATIONOFJB: Refactor inventory UI into separate widget, add button widgets.
Diffstat (limited to 'engines/mutationofjb/widgets')
-rw-r--r--engines/mutationofjb/widgets/buttonwidget.cpp70
-rw-r--r--engines/mutationofjb/widgets/buttonwidget.h58
-rw-r--r--engines/mutationofjb/widgets/inventorywidget.cpp75
-rw-r--r--engines/mutationofjb/widgets/inventorywidget.h48
-rw-r--r--engines/mutationofjb/widgets/widget.cpp50
-rw-r--r--engines/mutationofjb/widgets/widget.h66
6 files changed, 367 insertions, 0 deletions
diff --git a/engines/mutationofjb/widgets/buttonwidget.cpp b/engines/mutationofjb/widgets/buttonwidget.cpp
new file mode 100644
index 0000000000..9f9a401eb6
--- /dev/null
+++ b/engines/mutationofjb/widgets/buttonwidget.cpp
@@ -0,0 +1,70 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 (at your option) 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/widgets/buttonwidget.h"
+#include "common/events.h"
+#include "graphics/managed_surface.h"
+
+namespace MutationOfJB {
+
+ButtonWidget::ButtonWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface) :
+ Widget(gui, area),
+ _normalSurface(normalSurface),
+ _pressedSurface(pressedSurface),
+ _callback(nullptr),
+ _pressed(false) {}
+
+void ButtonWidget::setCallback(ButtonWidgetCallback *callback) {
+ _callback = callback;
+}
+
+void ButtonWidget::handleEvent(const Common::Event &event) {
+ switch(event.type) {
+ case Common::EVENT_LBUTTONDOWN:
+ {
+ const int16 x = event.mouse.x;
+ const int16 y = event.mouse.y;
+ if (_area.contains(x, y)) {
+ _pressed = true;
+ markDirty();
+ }
+ break;
+ }
+ case Common::EVENT_LBUTTONUP:
+ {
+ if (_pressed) {
+ _pressed = false;
+ markDirty();
+ if (_callback) {
+ _callback->onButtonClicked(this);
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+void ButtonWidget::_draw(Graphics::ManagedSurface &surface) {
+ surface.blitFrom(_pressed ? _pressedSurface : _normalSurface, Common::Point(_area.left, _area.top));
+}
+}
diff --git a/engines/mutationofjb/widgets/buttonwidget.h b/engines/mutationofjb/widgets/buttonwidget.h
new file mode 100644
index 0000000000..de8cb631f5
--- /dev/null
+++ b/engines/mutationofjb/widgets/buttonwidget.h
@@ -0,0 +1,58 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 (at your option) 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MUTATIONOFJB_BUTTONWIDGET_H
+#define MUTATIONOFJB_BUTTONWIDGET_H
+
+#include "mutationofjb/widgets/widget.h"
+#include "graphics/surface.h"
+
+namespace MutationOfJB {
+
+class ButtonWidget;
+
+class ButtonWidgetCallback {
+public:
+ virtual ~ButtonWidgetCallback() {}
+ virtual void onButtonClicked(ButtonWidget *) = 0;
+};
+
+class ButtonWidget : public Widget {
+public:
+ ButtonWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface);
+ void setCallback(ButtonWidgetCallback *callback);
+
+ virtual void handleEvent(const Common::Event &event) override;
+
+protected:
+ virtual void _draw(Graphics::ManagedSurface &) override;
+
+private:
+ Graphics::Surface _normalSurface;
+ Graphics::Surface _pressedSurface;
+ ButtonWidgetCallback *_callback;
+ bool _pressed;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/widgets/inventorywidget.cpp b/engines/mutationofjb/widgets/inventorywidget.cpp
new file mode 100644
index 0000000000..d78ef10adc
--- /dev/null
+++ b/engines/mutationofjb/widgets/inventorywidget.cpp
@@ -0,0 +1,75 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 (at your option) 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/widgets/inventorywidget.h"
+#include "mutationofjb/game.h"
+#include "mutationofjb/gamedata.h"
+#include "mutationofjb/gui.h"
+#include "mutationofjb/inventory.h"
+#include "common/str.h"
+#include "common/rect.h"
+#include "common/util.h"
+#include "graphics/managed_surface.h"
+
+namespace MutationOfJB {
+
+enum {
+ INVENTORY_START_X = 88,
+ INVENTORY_START_Y = 149,
+ INVENTORY_ITEM_WIDTH = 34,
+ INVENTORY_ITEM_HEIGHT = 33,
+ INVENTORY_ITEMS_PER_LINE = 8,
+ INVENTORY_ITEMS_LINES = 5
+};
+
+InventoryWidget::InventoryWidget(Gui &gui, Gui::InventoryMap &inventoryMap, const Common::Array<Graphics::Surface>& inventorySurfaces) :
+ Widget(gui, Common::Rect(INVENTORY_START_X, INVENTORY_START_Y, INVENTORY_START_X + Inventory::VISIBLE_ITEMS * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y + INVENTORY_ITEM_HEIGHT)),
+ _inventoryMap(inventoryMap),
+ _surfaces(inventorySurfaces) {}
+
+void InventoryWidget::drawInventoryItem(Graphics::ManagedSurface &surface, const Common::String &item, int pos) {
+ Gui::InventoryMap::iterator it = _inventoryMap.find(item);
+ if (it == _inventoryMap.end()) {
+ return;
+ }
+
+ const int index = it->_value;
+ const int surfaceNo = index / (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE);
+ const int indexInSurface = index % (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE);
+ const int itemX = indexInSurface % INVENTORY_ITEMS_PER_LINE;
+ const int itemY = indexInSurface / INVENTORY_ITEMS_PER_LINE;
+
+ Common::Point destStartPos(INVENTORY_START_X + pos * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y);
+ Common::Rect sourceRect(itemX * INVENTORY_ITEM_WIDTH, itemY * INVENTORY_ITEM_HEIGHT, (itemX + 1) * INVENTORY_ITEM_WIDTH, (itemY + 1) * INVENTORY_ITEM_HEIGHT);
+ surface.blitFrom(_surfaces[surfaceNo], sourceRect, destStartPos);
+}
+
+void InventoryWidget::_draw(Graphics::ManagedSurface &surface) {
+ Inventory &inventory = _gui.getGame().getGameData().getInventory();
+ const Inventory::Items &items = inventory.getItems();
+ surface.fillRect(_area, 0x00);
+ for (int i = 0; i < MIN((int) items.size(), (int) Inventory::VISIBLE_ITEMS); ++i) {
+ drawInventoryItem(surface, items[i], i);
+ }
+}
+
+}
diff --git a/engines/mutationofjb/widgets/inventorywidget.h b/engines/mutationofjb/widgets/inventorywidget.h
new file mode 100644
index 0000000000..f0bc4baeee
--- /dev/null
+++ b/engines/mutationofjb/widgets/inventorywidget.h
@@ -0,0 +1,48 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 (at your option) 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MUTATIONOFJB_INVENTORYWIDGET_H
+#define MUTATIONOFJB_INVENTORYWIDGET_H
+
+#include "mutationofjb/widgets/widget.h"
+#include "mutationofjb/gui.h"
+
+namespace Common {
+class String;
+}
+
+namespace MutationOfJB {
+
+class InventoryWidget : public Widget {
+public:
+ InventoryWidget(Gui &gui, Gui::InventoryMap &inventoryMap, const Common::Array<Graphics::Surface>& inventorySurfaces);
+ virtual void _draw(Graphics::ManagedSurface &) override;
+
+private:
+ void drawInventoryItem(Graphics::ManagedSurface &surface, const Common::String &item, int pos);
+ Gui::InventoryMap &_inventoryMap;
+ const Common::Array<Graphics::Surface>& _surfaces;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/widgets/widget.cpp b/engines/mutationofjb/widgets/widget.cpp
new file mode 100644
index 0000000000..fea7f6fbe0
--- /dev/null
+++ b/engines/mutationofjb/widgets/widget.cpp
@@ -0,0 +1,50 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 (at your option) 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/widgets/widget.h"
+
+namespace MutationOfJB {
+
+int Widget::getId() const {
+ return _id;
+}
+
+void Widget::setId(int id) {
+ _id = id;
+}
+
+void Widget::markDirty() {
+ _dirty = true;
+}
+
+bool Widget::isDirty() const {
+ return _dirty;
+}
+
+void Widget::update(Graphics::ManagedSurface &surface) {
+ if (_dirty) {
+ _draw(surface);
+ _dirty = false;
+ }
+}
+
+}
diff --git a/engines/mutationofjb/widgets/widget.h b/engines/mutationofjb/widgets/widget.h
new file mode 100644
index 0000000000..f81d466c1c
--- /dev/null
+++ b/engines/mutationofjb/widgets/widget.h
@@ -0,0 +1,66 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 (at your option) 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MUTATIONOFJB_WIDGET_H
+#define MUTATIONOFJB_WIDGET_H
+
+#include <common/scummsys.h>
+#include <common/rect.h>
+
+namespace Common {
+class Event;
+}
+
+namespace Graphics {
+class ManagedSurface;
+}
+
+namespace MutationOfJB {
+
+class Gui;
+
+class Widget {
+public:
+ Widget(Gui &gui, const Common::Rect &area) : _gui(gui), _area(area), _id(0), _dirty(true) {}
+ virtual ~Widget() {}
+
+ int getId() const;
+ void setId(int id);
+
+ bool isDirty() const;
+ void markDirty();
+ void update(Graphics::ManagedSurface &);
+
+ virtual void handleEvent(const Common::Event &) {}
+protected:
+ virtual void _draw(Graphics::ManagedSurface &) = 0;
+
+ Gui &_gui;
+ Common::Rect _area;
+ int _id;
+ bool _dirty;
+};
+
+}
+
+#endif
+