Ticket #8456: popup-twocolumns.diff

File popup-twocolumns.diff, 3.3 KB (added by eriktorbjorn, 19 years ago)

Patch against an August 17 CVS snapshot

  • gui/PopUpWidget.cpp

    diff -ur ScummVM-cvs20050817/gui/PopUpWidget.cpp ScummVM-cvs20050817+hack/gui/PopUpWidget.cpp
    old new  
    3838        byte            *_buffer;
    3939        int                     _selection;
    4040        uint32          _openTime;
     41        bool            _twoColumns;
     42        int                     _entriesPerColumn;
    4143public:
    4244        PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize ws = kDefaultWidgetSize);
    4345
     
    7880
    7981        const int screenH = g_system->getOverlayHeight();
    8082
     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
    81124        if (_h >= screenH)
    82125                _h = screenH - 1;
    83126        if (_y < 0)
     
    102145        g_gui.vLine(_x, _y, _y+_h - 1, g_gui._color);
    103146        g_gui.vLine(_x + _w - 1, _y, _y + _h - 1, g_gui._shadowcolor);
    104147
     148        if (_twoColumns)
     149                g_gui.vLine(_x + _w / 2, _y, _y + _h - 2, g_gui._color);
     150
    105151        // Draw the entries
    106152        int count = _popUpBoss->_entries.size();
    107153        for (int i = 0; i < count; i++) {
    108154                drawMenuEntry(i, i == _selection);
    109155        }
    110156
     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
    111162        g_gui.addDirtyRect(_x, _y, _w, _h);
    112163}
    113164
     
    177228
    178229int PopUpDialog::findItem(int x, int y) const {
    179230        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                }
    180241                return (y - 2) / kLineHeight;
    181242        }
    182243        return -1;
     
    236297void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
    237298        // Draw one entry of the popup menu, including selection
    238299        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
    242323        Common::String &name = _popUpBoss->_entries[entry].name;
    243324
    244325        g_gui.fillRect(x, y, w, kLineHeight, hilite ? g_gui._textcolorhi : g_gui._bgcolor);