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 "OSystem.hxx" |
19 | #include "Widget.hxx" |
20 | #include "Dialog.hxx" |
21 | #include "Debugger.hxx" |
22 | #include "FBSurface.hxx" |
23 | #include "Font.hxx" |
24 | #include "ToggleBitWidget.hxx" |
25 | |
26 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
27 | ToggleBitWidget::ToggleBitWidget(GuiObject* boss, const GUI::Font& font, |
28 | int x, int y, int cols, int rows, int colchars) |
29 | : ToggleWidget(boss, font, x, y, cols, rows, 1) |
30 | { |
31 | _rowHeight = font.getLineHeight(); |
32 | _colWidth = colchars * font.getMaxCharWidth() + 8; |
33 | _bgcolorlo = kDlgColor; |
34 | |
35 | // Make sure all lists contain some default values |
36 | int size = _rows * _cols; |
37 | while(size--) |
38 | { |
39 | _offList.push_back("0" ); |
40 | _onList.push_back("1" ); |
41 | _stateList.push_back(false); |
42 | _changedList.push_back(false); |
43 | } |
44 | |
45 | // Calculate real dimensions |
46 | _w = _colWidth * cols + 1; |
47 | _h = _rowHeight * rows + 1; |
48 | } |
49 | |
50 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
51 | void ToggleBitWidget::setList(const StringList& off, const StringList& on) |
52 | { |
53 | _offList.clear(); |
54 | _offList = off; |
55 | _onList.clear(); |
56 | _onList = on; |
57 | |
58 | assert(int(_offList.size()) == _rows * _cols); |
59 | } |
60 | |
61 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
62 | void ToggleBitWidget::setState(const BoolArray& state, const BoolArray& changed) |
63 | { |
64 | _stateList.clear(); |
65 | _stateList = state; |
66 | _changedList.clear(); |
67 | _changedList = changed; |
68 | |
69 | setDirty(); |
70 | } |
71 | |
72 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
73 | void ToggleBitWidget::drawWidget(bool hilite) |
74 | { |
75 | //cerr << "ToggleBitWidget::drawWidget\n"; |
76 | FBSurface& s = dialog().surface(); |
77 | bool onTop = _boss->dialog().isOnTop(); |
78 | int row, col; |
79 | string buffer; |
80 | |
81 | s.frameRect(_x, _y, _w, _h, hilite && isEnabled() && isEditable() ? kWidColorHi : kColor); |
82 | |
83 | // Draw the internal grid and labels |
84 | int linewidth = _cols * _colWidth; |
85 | for(row = 1; row <= _rows - 1; row++) |
86 | s.hLine(_x + 1, _y + (row * _rowHeight), _x + linewidth - 1, kBGColorLo); |
87 | |
88 | int lineheight = _rows * _rowHeight; |
89 | for(col = 1; col <= _cols - 1; col++) |
90 | s.vLine(_x + (col * _colWidth), _y + 1, _y + lineheight - 1, kBGColorLo); |
91 | |
92 | // Draw the list items |
93 | for (row = 0; row < _rows; row++) |
94 | { |
95 | for (col = 0; col < _cols; col++) |
96 | { |
97 | ColorId textColor = kTextColor; |
98 | int x = _x + 4 + (col * _colWidth); |
99 | int y = _y + 2 + (row * _rowHeight); |
100 | int pos = row*_cols + col; |
101 | |
102 | // Draw the selected item inverted, on a highlighted background. |
103 | if(_currentRow == row && _currentCol == col && _hasFocus) |
104 | { |
105 | s.fillRect(x - 4, y - 2, _colWidth + 1, _rowHeight + 1, kTextColorHi); |
106 | textColor = kTextColorInv; |
107 | } |
108 | |
109 | if(_stateList[pos]) |
110 | buffer = _onList[pos]; |
111 | else |
112 | buffer = _offList[pos]; |
113 | |
114 | if(isEditable()) |
115 | { |
116 | // Highlight changes |
117 | if(_changedList[pos]) |
118 | { |
119 | s.fillRect(x - 3, y - 1, _colWidth-1, _rowHeight-1, |
120 | onTop ? kDbgChangedColor : _bgcolorlo); |
121 | s.drawString(_font, buffer, x, y, _colWidth, onTop ? kDbgChangedTextColor : kColor); |
122 | } |
123 | else |
124 | s.drawString(_font, buffer, x, y, _colWidth, |
125 | onTop ? textColor : kColor); |
126 | } |
127 | else |
128 | { |
129 | s.fillRect(x - 3, y - 1, _colWidth-1, _rowHeight-1, onTop ? kBGColorHi : kDlgColor); |
130 | s.drawString(_font, buffer, x, y, _colWidth, onTop ? kTextColor : kColor); |
131 | } |
132 | } |
133 | } |
134 | } |
135 | |