diff -ur ScummVM-cvs20050817/gui/PopUpWidget.cpp ScummVM-cvs20050817+hack/gui/PopUpWidget.cpp
old
|
new
|
|
38 | 38 | byte *_buffer; |
39 | 39 | int _selection; |
40 | 40 | uint32 _openTime; |
| 41 | bool _twoColumns; |
| 42 | int _entriesPerColumn; |
41 | 43 | public: |
42 | 44 | PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize ws = kDefaultWidgetSize); |
43 | 45 | |
… |
… |
|
78 | 80 | |
79 | 81 | const int screenH = g_system->getOverlayHeight(); |
80 | 82 | |
| 83 | // HACK: For now, we do not do scrolling. Instead, we draw the dialog |
| 84 | // in two columns if it's too tall. |
| 85 | |
| 86 | if (_h >= screenH) { |
| 87 | const int screenW = g_system->getOverlayWidth(); |
| 88 | |
| 89 | _twoColumns = true; |
| 90 | _entriesPerColumn = _popUpBoss->_entries.size() / 2; |
| 91 | |
| 92 | if (_popUpBoss->_entries.size() & 1) |
| 93 | _entriesPerColumn++; |
| 94 | |
| 95 | _h = _entriesPerColumn * kLineHeight + 2; |
| 96 | _w = 0; |
| 97 | |
| 98 | for (uint i = 0; i < _popUpBoss->_entries.size(); i++) { |
| 99 | int width = g_gui.getStringWidth(_popUpBoss->_entries[i].name); |
| 100 | |
| 101 | if (width > _w) |
| 102 | _w = width; |
| 103 | } |
| 104 | |
| 105 | _w = 2 * _w + 10; |
| 106 | |
| 107 | if (!(_w & 1)) |
| 108 | _w++; |
| 109 | |
| 110 | if (_popUpBoss->_selectedItem >= _entriesPerColumn) { |
| 111 | _x -= _w / 2; |
| 112 | _y = _popUpBoss->getAbsY() - (_popUpBoss->_selectedItem - _entriesPerColumn) * kLineHeight; |
| 113 | } |
| 114 | |
| 115 | if (_w >= screenW) |
| 116 | _w = screenW - 1; |
| 117 | if (_x < 0) |
| 118 | _x = 0; |
| 119 | if (_x + _w >= screenW) |
| 120 | _x = screenW - 1 - _w; |
| 121 | } else |
| 122 | _twoColumns = false; |
| 123 | |
81 | 124 | if (_h >= screenH) |
82 | 125 | _h = screenH - 1; |
83 | 126 | if (_y < 0) |
… |
… |
|
102 | 145 | g_gui.vLine(_x, _y, _y+_h - 1, g_gui._color); |
103 | 146 | g_gui.vLine(_x + _w - 1, _y, _y + _h - 1, g_gui._shadowcolor); |
104 | 147 | |
| 148 | if (_twoColumns) |
| 149 | g_gui.vLine(_x + _w / 2, _y, _y + _h - 2, g_gui._color); |
| 150 | |
105 | 151 | // Draw the entries |
106 | 152 | int count = _popUpBoss->_entries.size(); |
107 | 153 | for (int i = 0; i < count; i++) { |
108 | 154 | drawMenuEntry(i, i == _selection); |
109 | 155 | } |
110 | 156 | |
| 157 | // The last entry may be empty. Fill it with black. |
| 158 | if (_twoColumns && (count & 1)) { |
| 159 | g_gui.fillRect(_x + 1 + _w / 2, _y + 1 + kLineHeight * (_entriesPerColumn - 1), _w / 2 - 1, kLineHeight, g_gui._bgcolor); |
| 160 | } |
| 161 | |
111 | 162 | g_gui.addDirtyRect(_x, _y, _w, _h); |
112 | 163 | } |
113 | 164 | |
… |
… |
|
177 | 228 | |
178 | 229 | int PopUpDialog::findItem(int x, int y) const { |
179 | 230 | if (x >= 0 && x < _w && y >= 0 && y < _h) { |
| 231 | if (_twoColumns) { |
| 232 | uint entry = (y - 2) / kLineHeight; |
| 233 | if (x > _w / 2) { |
| 234 | entry += _entriesPerColumn; |
| 235 | |
| 236 | if (entry >= _popUpBoss->_entries.size()) |
| 237 | return -1; |
| 238 | } |
| 239 | return entry; |
| 240 | } |
180 | 241 | return (y - 2) / kLineHeight; |
181 | 242 | } |
182 | 243 | return -1; |
… |
… |
|
236 | 297 | void PopUpDialog::drawMenuEntry(int entry, bool hilite) { |
237 | 298 | // Draw one entry of the popup menu, including selection |
238 | 299 | assert(entry >= 0); |
239 | | int x = _x + 1; |
240 | | int y = _y + 1 + kLineHeight * entry; |
241 | | int w = _w - 2; |
| 300 | int x, y, w; |
| 301 | |
| 302 | if (_twoColumns) { |
| 303 | int n = _popUpBoss->_entries.size() / 2; |
| 304 | |
| 305 | if (_popUpBoss->_entries.size() & 1) |
| 306 | n++; |
| 307 | |
| 308 | if (entry >= n) { |
| 309 | x = _x + 1 + _w / 2; |
| 310 | y = _y + 1 + kLineHeight * (entry - n); |
| 311 | } else { |
| 312 | x = _x + 1; |
| 313 | y = _y + 1 + kLineHeight * entry; |
| 314 | } |
| 315 | |
| 316 | w = _w / 2 - 1; |
| 317 | } else { |
| 318 | x = _x + 1; |
| 319 | y = _y + 1 + kLineHeight * entry; |
| 320 | w = _w - 2; |
| 321 | } |
| 322 | |
242 | 323 | Common::String &name = _popUpBoss->_entries[entry].name; |
243 | 324 | |
244 | 325 | g_gui.fillRect(x, y, w, kLineHeight, hilite ? g_gui._textcolorhi : g_gui._bgcolor); |