| 1 | //============================================================================ | 
| 2 | // | 
| 3 | //   SSSS    tt          lll  lll | 
| 4 | //  SS  SS   tt           ll   ll | 
| 5 | //  SS     tttttt  eeee   ll   ll   aaaa | 
| 6 | //   SSSS    tt   ee  ee  ll   ll      aa | 
| 7 | //      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator" | 
| 8 | //  SS  SS   tt   ee      ll   ll  aa  aa | 
| 9 | //   SSSS     ttt  eeeee llll llll  aaaaa | 
| 10 | // | 
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony | 
| 12 | // and the Stella Team | 
| 13 | // | 
| 14 | // See the file "License.txt" for information on usage and redistribution of | 
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. | 
| 16 | //============================================================================ | 
| 17 |  | 
| 18 | #include "bspf.hxx" | 
| 19 | #include "Dialog.hxx" | 
| 20 | #include "FBSurface.hxx" | 
| 21 | #include "Settings.hxx" | 
| 22 | #include "ScrollBarWidget.hxx" | 
| 23 | #include "StringListWidget.hxx" | 
| 24 |  | 
| 25 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 26 | StringListWidget::StringListWidget(GuiObject* boss, const GUI::Font& font, | 
| 27 |                                    int x, int y, int w, int h, bool hilite) | 
| 28 |   : ListWidget(boss, font, x, y, w, h), | 
| 29 |     _hilite(hilite) | 
| 30 | { | 
| 31 |   _bgcolorlo = kDlgColor; | 
| 32 | } | 
| 33 |  | 
| 34 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 35 | void StringListWidget::setList(const StringList& list) | 
| 36 | { | 
| 37 |   _list = list; | 
| 38 |  | 
| 39 |   ListWidget::recalc(); | 
| 40 | } | 
| 41 |  | 
| 42 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 43 | void StringListWidget::handleMouseEntered() | 
| 44 | { | 
| 45 |   setFlags(Widget::FLAG_HILITED); | 
| 46 |   setDirty(); | 
| 47 | } | 
| 48 |  | 
| 49 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 50 | void StringListWidget::handleMouseLeft() | 
| 51 | { | 
| 52 |   clearFlags(Widget::FLAG_HILITED); | 
| 53 |   setDirty(); | 
| 54 | } | 
| 55 |  | 
| 56 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 57 | void StringListWidget::drawWidget(bool hilite) | 
| 58 | { | 
| 59 |   FBSurface& s = _boss->dialog().surface(); | 
| 60 |   bool onTop = _boss->dialog().isOnTop(); | 
| 61 |   int i, pos, len = int(_list.size()); | 
| 62 |  | 
| 63 |   // Draw a thin frame around the list. | 
| 64 |   s.frameRect(_x, _y, _w + 1, _h, onTop && hilite && _hilite ? kWidColorHi : kColor); | 
| 65 |  | 
| 66 |   if (!isEnabled()) | 
| 67 |     s.fillRect(_x + 1, _y + 1, _w - 1, _h - 2, onTop ? kDlgColor : kBGColorLo); | 
| 68 |  | 
| 69 |   // Draw the list items | 
| 70 |   for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++) | 
| 71 |   { | 
| 72 |     const int y = _y + 2 + _fontHeight * i; | 
| 73 |     ColorId textColor = onTop ? kTextColor : kShadowColor; | 
| 74 |  | 
| 75 |     // Draw the selected item inverted, on a highlighted background. | 
| 76 |     if (onTop && _selectedItem == pos && _hilite) | 
| 77 |     { | 
| 78 |       if(_hasFocus && !_editMode) | 
| 79 |       { | 
| 80 |         s.fillRect(_x + 1, _y + 1 + _fontHeight * i, _w - 1, _fontHeight, kTextColorHi); | 
| 81 |         textColor = kTextColorInv; | 
| 82 |       } | 
| 83 |       else | 
| 84 |         s.frameRect(_x + 1, _y + 1 + _fontHeight * i, _w - 1, _fontHeight, onTop ? kWidColorHi : kBGColorLo); | 
| 85 |     } | 
| 86 |  | 
| 87 |     Common::Rect r(getEditRect()); | 
| 88 |     if (_selectedItem == pos && _editMode) | 
| 89 |     { | 
| 90 |       adjustOffset(); | 
| 91 |  | 
| 92 |       s.drawString(_font, editString(), _x + r.x(), y, r.w(), textColor, | 
| 93 |                    TextAlign::Left, -_editScrollOffset, false); | 
| 94 |     } | 
| 95 |     else | 
| 96 |       s.drawString(_font, _list[pos], _x + r.x(), y, r.w(), textColor); | 
| 97 |   } | 
| 98 |  | 
| 99 |   // Only draw the caret while editing, and if it's in the current viewport | 
| 100 |   if(_editMode && (_selectedItem >= _scrollBar->_currentPos) && | 
| 101 |     (_selectedItem < _scrollBar->_currentPos + _rows)) | 
| 102 |     drawCaret(); | 
| 103 | } | 
| 104 |  | 
| 105 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 106 | Common::Rect StringListWidget::getEditRect() const | 
| 107 | { | 
| 108 |   const int offset = std::max(0, (_selectedItem - _currentPos) * _fontHeight); | 
| 109 |   return Common::Rect(2, 1 + offset, _w - 2, _fontHeight + offset); | 
| 110 | } | 
| 111 |  |