aboutsummaryrefslogtreecommitdiff
path: root/graphics/macgui
diff options
context:
space:
mode:
authorEugene Sandulenko2019-10-14 21:30:17 +0200
committerEugene Sandulenko2019-10-14 21:31:25 +0200
commit5acaaed860dd206528726462eb72e2273e1988e2 (patch)
treed739a31f0f00003f75c351a46c56b4e9a5dc0e9d /graphics/macgui
parentdfc0a5127e354ea959edc508db2316505785d85e (diff)
downloadscummvm-rg350-5acaaed860dd206528726462eb72e2273e1988e2.tar.gz
scummvm-rg350-5acaaed860dd206528726462eb72e2273e1988e2.tar.bz2
scummvm-rg350-5acaaed860dd206528726462eb72e2273e1988e2.zip
GRAPHICS: MACGUI: Crash-proof window management.
Diffstat (limited to 'graphics/macgui')
-rw-r--r--graphics/macgui/macwindowmanager.cpp27
-rw-r--r--graphics/macgui/macwindowmanager.h4
2 files changed, 18 insertions, 13 deletions
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 1e8a4bac77..cd72d5cf1f 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -184,8 +184,8 @@ MacWindowManager::MacWindowManager() {
}
MacWindowManager::~MacWindowManager() {
- for (int i = 0; i < _lastId; i++)
- delete _windows[i];
+ for (Common::HashMap<uint, BaseMacWindow *>::iterator it = _windows.begin(); it != _windows.end(); it++)
+ delete it->_value;
delete _fontMan;
delete _screenCopy;
@@ -223,14 +223,14 @@ MacTextWindow *MacWindowManager::addTextWindow(const MacFont *font, int fgcolor,
void MacWindowManager::addWindowInitialized(MacWindow *macwindow) {
- _windows.push_back(macwindow);
+ _windows[macwindow->getId()] = macwindow;
_windowStack.push_back(macwindow);
}
MacMenu *MacWindowManager::addMenu() {
_menu = new MacMenu(getNextId(), _screen->getBounds(), this);
- _windows.push_back(_menu);
+ _windows[_menu->getId()] = _menu;
return _menu;
}
@@ -431,7 +431,13 @@ void MacWindowManager::removeMarked() {
}
_windowsToRemove.clear();
_needsRemoval = false;
- _lastId = _windows.size();
+
+ // Do we need compact lastid?
+ _lastId = 0;
+ for (Common::HashMap<uint, BaseMacWindow *>::iterator lit = _windows.begin(); lit != _windows.end(); lit++) {
+ if (lit->_key > (uint)_lastId)
+ _lastId = lit->_key;
+ }
}
void MacWindowManager::removeFromStack(BaseMacWindow *target) {
@@ -445,14 +451,13 @@ void MacWindowManager::removeFromStack(BaseMacWindow *target) {
}
void MacWindowManager::removeFromWindowList(BaseMacWindow *target) {
- int size = _windows.size();
- int ndx = 0;
- for (int i = 0; i < size; i++) {
- if (_windows[i] == target) {
- ndx = i;
+ // _windows.erase(target->getId()); // Is applicable?
+ for (Common::HashMap<uint, BaseMacWindow *>::iterator it = _windows.begin(); it != _windows.end(); it++) {
+ if (it->_value == target) {
+ _windows.erase(it);
+ break;
}
}
- _windows.remove_at(ndx);
}
/////////////////
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index f288a09fd8..1719bee317 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -23,7 +23,7 @@
#ifndef GRAPHICS_MACGUI_MACWINDOWMANAGER_H
#define GRAPHICS_MACGUI_MACWINDOWMANAGER_H
-#include "common/array.h"
+#include "common/hashmap.h"
#include "common/list.h"
#include "common/events.h"
@@ -243,7 +243,7 @@ public:
private:
Common::List<BaseMacWindow *> _windowStack;
- Common::Array<BaseMacWindow *> _windows;
+ Common::HashMap<uint, BaseMacWindow *> _windows;
Common::List<BaseMacWindow *> _windowsToRemove;
bool _needsRemoval;