diff options
| -rw-r--r-- | gui/EditTextWidget.cpp | 52 | ||||
| -rw-r--r-- | gui/EditTextWidget.h | 6 | ||||
| -rw-r--r-- | gui/ListWidget.cpp | 74 | ||||
| -rw-r--r-- | gui/PopUpWidget.cpp | 86 | ||||
| -rw-r--r-- | gui/ScrollBarWidget.cpp | 38 | ||||
| -rw-r--r-- | gui/browser.cpp | 37 | ||||
| -rw-r--r-- | gui/browser.h | 6 | ||||
| -rw-r--r-- | gui/chooser.cpp | 18 | ||||
| -rw-r--r-- | gui/chooser.h | 2 | ||||
| -rw-r--r-- | gui/console.cpp | 138 | ||||
| -rw-r--r-- | gui/console.h | 13 | ||||
| -rw-r--r-- | gui/dialog.cpp | 71 | ||||
| -rw-r--r-- | gui/dialog.h | 14 | ||||
| -rw-r--r-- | gui/launcher.cpp | 78 | ||||
| -rw-r--r-- | gui/message.cpp | 17 | ||||
| -rw-r--r-- | gui/newgui.cpp | 97 | ||||
| -rw-r--r-- | gui/options.cpp | 16 | ||||
| -rw-r--r-- | gui/widget.cpp | 84 | ||||
| -rw-r--r-- | gui/widget.h | 17 | 
19 files changed, 337 insertions, 527 deletions
| diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp index 25326eb868..5ae561b756 100644 --- a/gui/EditTextWidget.cpp +++ b/gui/EditTextWidget.cpp @@ -24,8 +24,7 @@  #include "newgui.h"  EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text) -	: StaticTextWidget(boss, x, y-1, w, h+2, text, kTextAlignLeft), _backupString(text) -{ +	: StaticTextWidget(boss, x, y-1, w, h+2, text, kTextAlignLeft), _backupString(text) {  	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;  	_type = kEditTextWidget; @@ -35,8 +34,7 @@ EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const S  	_pos = _label.size();  } -void EditTextWidget::handleTickle() -{ +void EditTextWidget::handleTickle() {  	uint32 time = _boss->getGui()->get_time();  	if (_caretTime < time) {  		_caretTime = time + kCaretBlinkTime; @@ -48,14 +46,12 @@ void EditTextWidget::handleTickle()  	}  } -void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) -{ +void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {  	// TODO - once we support "real editing" (i.e. caret can be at any spot),  	// a mouse click should place the caret.  } -bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) -{ +bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {  	bool handled = true;  	bool dirty = false; @@ -84,19 +80,19 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)  			_label.deleteChar(_pos);  			dirty = true;  			break; -		case 256+20:	// left arrow +		case 256 + 20:	// left arrow  			if (_pos > 0)  				_pos--;  			break; -		case 256+19:	// right arrow +		case 256 + 19:	// right arrow  			if (_pos < _label.size())  				_pos++;  			break;  			break; -		case 256+22:	// home +		case 256 + 22:	// home  			_pos = 0;  			break; -		case 256+23:	// end +		case 256 + 23:	// end  			_pos = _label.size();  			break;  		default: @@ -111,33 +107,31 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)  	if (dirty)  		draw(); -	 +  	return handled;  } -void EditTextWidget::drawWidget(bool hilite) -{ -	NewGui			*gui = _boss->getGui(); +void EditTextWidget::drawWidget(bool hilite) { +	NewGui *gui = _boss->getGui();  	// Draw a thin frame around us. -	gui->hline(_x, _y, _x+_w-1, gui->_color); -	gui->hline(_x, _y+_h-1, _x+_w-1, gui->_shadowcolor); -	gui->vline(_x, _y, _y+_h-1, gui->_color); -	gui->vline(_x+_w-1, _y, _y+_h-1, gui->_shadowcolor); +	gui->hline(_x, _y, _x + _w - 1, gui->_color); +	gui->hline(_x, _y + _h - 1, _x +_w - 1, gui->_shadowcolor); +	gui->vline(_x, _y, _y + _h - 1, gui->_color); +	gui->vline(_x + _w - 1, _y, _y + _h - 1, gui->_shadowcolor);  	// Draw the text -	_align = (gui->getStringWidth(_label) > _w-6) ? kTextAlignRight : kTextAlignLeft; -	gui->drawString(_label, _x+2, _y+3, _w-6, gui->_textcolor, _align); +	_align = (gui->getStringWidth(_label) > _w - 6) ? kTextAlignRight : kTextAlignLeft; +	gui->drawString(_label, _x + 2, _y + 3, _w - 6, gui->_textcolor, _align);  } -void EditTextWidget::drawCaret(bool erase) -{ +void EditTextWidget::drawCaret(bool erase) {  	// Only draw if item is visible  	if (!isVisible() || !_boss->isVisible())  		return;  	NewGui *gui = _boss->getGui(); -	 +  	int16 color = erase ? gui->_bgcolor : gui->_textcolorhi;  	int x = _x + _boss->getX() + 2;  	int y = _y + _boss->getY() + 1; @@ -146,12 +140,12 @@ void EditTextWidget::drawCaret(bool erase)  	for (int i = 0; i < _pos; i++)  		width += gui->getCharWidth(_label[i]); -	if (width > _w-6) -		width = _w-6; +	if (width > _w - 6) +		width = _w - 6;  	x += width; -	gui->vline(x, y, y+kLineHeight, color); +	gui->vline(x, y, y + kLineHeight, color);  	gui->addDirtyRect(x, y, 2, kLineHeight); -	 +  	_caretVisible = !erase;  } diff --git a/gui/EditTextWidget.h b/gui/EditTextWidget.h index fa4b4dbc20..d9dea94a45 100644 --- a/gui/EditTextWidget.h +++ b/gui/EditTextWidget.h @@ -30,10 +30,10 @@ class EditTextWidget : public StaticTextWidget {  	typedef ScummVM::StringList StringList;  	typedef ScummVM::String String;  protected: -	String			_backupString; +	String		_backupString;  	bool			_caretVisible; -	uint32			_caretTime; -	int			_pos; +	uint32		_caretTime; +	int				_pos;  public:  	EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text); diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index f16a57659d..ec8e5451ac 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -26,8 +26,7 @@  ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h) -	: Widget(boss, x, y, w - kScrollBarWidth, h), CommandSender(boss) -{ +	: Widget(boss, x, y, w - kScrollBarWidth, h), CommandSender(boss) {  	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;  	_type = kListWidget;  	_numberingMode = kListNumberingOne; @@ -47,12 +46,10 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h)  	_editMode = false;  } -ListWidget::~ListWidget() -{ +ListWidget::~ListWidget() {  } -void ListWidget::setList(const StringList& list) -{ +void ListWidget::setList(const StringList &list) {  	if (_editMode && _caretVisible)  		drawCaret(true);  	int size = list.size(); @@ -66,8 +63,7 @@ void ListWidget::setList(const StringList& list)  	scrollBarRecalc();  } -void ListWidget::scrollTo(int item) -{ +void ListWidget::scrollTo(int item) {  	int size = _list.size();  	if (item >= size)  		item = size - 1; @@ -80,16 +76,14 @@ void ListWidget::scrollTo(int item)  	}  } -void ListWidget::scrollBarRecalc() -{ +void ListWidget::scrollBarRecalc() {  	_scrollBar->_numEntries = _list.size();  	_scrollBar->_entriesPerPage = _entriesPerPage;  	_scrollBar->_currentPos = _currentPos;  	_scrollBar->recalc();  } -void ListWidget::handleTickle() -{ +void ListWidget::handleTickle() {  	uint32 time = _boss->getGui()->get_time();  	if (_editMode && _caretTime < time) {  		_caretTime = time + kCaretBlinkTime; @@ -101,8 +95,7 @@ void ListWidget::handleTickle()  	}  } -void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) -{ +void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) {  	if (isEnabled()) {  		int oldSelectedItem = _selectedItem;  		_selectedItem = (y - 1) / kLineHeight + _currentPos; @@ -122,8 +115,7 @@ void ListWidget::handleMouseDown(int x, int y, int button, int clickCount)  	}  } -void ListWidget::handleMouseUp(int x, int y, int button, int clickCount) -{ +void ListWidget::handleMouseUp(int x, int y, int button, int clickCount) {  	// If this was a double click and the mouse is still over the selected item,  	// send the double click command  	if (clickCount > 1 && (_selectedItem == (y - 1) / kLineHeight + _currentPos)) { @@ -131,13 +123,11 @@ void ListWidget::handleMouseUp(int x, int y, int button, int clickCount)  	}  } -void ListWidget::handleMouseWheel(int x, int y, int direction) -{ +void ListWidget::handleMouseWheel(int x, int y, int direction) {  	_scrollBar->handleMouseWheel(x, y, direction);  } -bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) -{ +bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {  	bool handled = true;  	bool dirty = false;  	int oldSelectedItem = _selectedItem; @@ -237,26 +227,23 @@ bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)  	_currentKeyDown = keycode;  #endif -	 +  	return handled;  } -bool ListWidget::handleKeyUp(uint16 ascii, int keycode, int modifiers) -{ +bool ListWidget::handleKeyUp(uint16 ascii, int keycode, int modifiers) {  	if (keycode == _currentKeyDown)  		_currentKeyDown = 0;  	return true;  } -void ListWidget::lostFocusWidget() -{ +void ListWidget::lostFocusWidget() {  	_editMode = false;  	drawCaret(true);  	draw();  } -void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	switch (cmd) {  	case kSetPositionCmd:  		if (_currentPos != (int)data) { @@ -267,16 +254,15 @@ void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)  	}  } -void ListWidget::drawWidget(bool hilite) -{ -	NewGui			*gui = _boss->getGui(); -	int				i, pos, len = _list.size(); -	ScummVM::String	buffer; +void ListWidget::drawWidget(bool hilite) { +	NewGui *gui = _boss->getGui(); +	int i, pos, len = _list.size(); +	ScummVM::String buffer;  	// Draw a thin frame around the list. -	gui->hline(_x, _y, _x+_w-1, gui->_color); -	gui->hline(_x, _y+_h-1, _x+_w-1, gui->_shadowcolor); -	gui->vline(_x, _y, _y+_h-1, gui->_color); +	gui->hline(_x, _y, _x + _w - 1, gui->_color); +	gui->hline(_x, _y + _h - 1, _x + _w - 1, gui->_shadowcolor); +	gui->vline(_x, _y, _y + _h - 1, gui->_color);  	// Draw the list items  	for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) { @@ -290,17 +276,16 @@ void ListWidget::drawWidget(bool hilite)  		if (_selectedItem == pos) {  			if (_hasFocus) -				gui->fillRect(_x+1, _y+1 + kLineHeight * i, _w - 1, kLineHeight, gui->_textcolorhi); +				gui->fillRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, gui->_textcolorhi);  			else -				gui->frameRect(_x+1, _y+1 + kLineHeight * i, _w - 1, kLineHeight, gui->_textcolorhi); +				gui->frameRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, gui->_textcolorhi);  		} -		gui->drawString(buffer, _x+2, _y+3 + kLineHeight * i, _w - 4, +		gui->drawString(buffer, _x + 2, _y + 3 + kLineHeight * i, _w - 4,  							(_selectedItem == pos && _hasFocus) ? gui->_bgcolor : gui->_textcolor);  	}  } -void ListWidget::drawCaret(bool erase) -{ +void ListWidget::drawCaret(bool erase) {  	// Only draw if item is visible  	if (_selectedItem < _currentPos || _selectedItem >= _currentPos + _entriesPerPage)  		return; @@ -308,7 +293,7 @@ void ListWidget::drawCaret(bool erase)  		return;  	NewGui *gui = _boss->getGui(); -	 +  	// The item is selected, thus _bgcolor is used to draw the caret and _textcolorhi to erase it  	int16 color = erase ? gui->_textcolorhi : gui->_bgcolor;  	int x = _x + _boss->getX() + 3; @@ -334,7 +319,6 @@ void ListWidget::drawCaret(bool erase)  }  void ListWidget::scrollToCurrent() { -  	// Only do something if the current item is not in our view port  	if (_selectedItem < _currentPos) {  		// it's above our view @@ -351,8 +335,7 @@ void ListWidget::scrollToCurrent() {  	_scrollBar->recalc();  } -void ListWidget::startEditMode() -{ +void ListWidget::startEditMode() {  	if (_editable && !_editMode && _selectedItem >= 0) {  		_editMode = true;  		_backupString = _list[_selectedItem]; @@ -360,8 +343,7 @@ void ListWidget::startEditMode()  	}  } -void ListWidget::abortEditMode() -{ +void ListWidget::abortEditMode() {  	if (_editMode) {  		_editMode = false;  		_list[_selectedItem] = _backupString; diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp index ea7a005b96..03d23ef84b 100644 --- a/gui/PopUpWidget.cpp +++ b/gui/PopUpWidget.cpp @@ -77,11 +77,10 @@ protected:  PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)  	: Dialog(boss->_boss->getGui(), 0, 0, 16, 16), -	_popUpBoss(boss) -{ +	_popUpBoss(boss) {  	// Copy the selection index  	_selection = _popUpBoss->_selectedItem; -	 +  	// Calculate real popup dimensions  	_x = _popUpBoss->_boss->getX() + _popUpBoss->_x;  	_y = _popUpBoss->_boss->getY() + _popUpBoss->_y - _popUpBoss->_selectedItem * kLineHeight; @@ -104,18 +103,17 @@ PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)  	// Remember original mouse position  	_clickX = clickX - _x;  	_clickY = clickY - _y; -	 +  	// Time the popup was opened  	_openTime = g_system->get_msecs();  } -void PopUpDialog::drawDialog() -{ +void PopUpDialog::drawDialog() {  	// Draw the menu border -	_gui->hline(_x, _y, _x+_w-1, _gui->_color); -	_gui->hline(_x, _y+_h-1, _x+_w-1, _gui->_shadowcolor); -	_gui->vline(_x, _y, _y+_h-1, _gui->_color); -	_gui->vline(_x+_w-1, _y, _y+_h-1, _gui->_shadowcolor); +	_gui->hline(_x, _y, _x+_w - 1, _gui->_color); +	_gui->hline(_x, _y + _h - 1, _x + _w - 1, _gui->_shadowcolor); +	_gui->vline(_x, _y, _y+_h - 1, _gui->_color); +	_gui->vline(_x + _w - 1, _y, _y + _h - 1, _gui->_shadowcolor);  	// Draw the entries  	int count = _popUpBoss->_entries.size(); @@ -126,12 +124,11 @@ void PopUpDialog::drawDialog()  	_gui->addDirtyRect(_x, _y, _w, _h);  } -void PopUpDialog::handleMouseUp(int x, int y, int button, int clickCount) -{ +void PopUpDialog::handleMouseUp(int x, int y, int button, int clickCount) {  	// Mouse was released. If it wasn't moved much since the original mouse down,   	// let the popup stay open. If it did move, assume the user made his selection.  	int dist = (_clickX - x) * (_clickX - x) + (_clickY - y) * (_clickY - y); -	if (dist > 3*3 || g_system->get_msecs() - _openTime > 300) { +	if (dist > 3 * 3 || g_system->get_msecs() - _openTime > 300) {  		setResult(_selection);  		close();  	} @@ -140,16 +137,14 @@ void PopUpDialog::handleMouseUp(int x, int y, int button, int clickCount)  	_openTime = (uint32)-1;  } -void PopUpDialog::handleMouseWheel(int x, int y, int direction) -{ +void PopUpDialog::handleMouseWheel(int x, int y, int direction) {  	if (direction < 0)  		moveUp();  	else if (direction > 0)  		moveDown();  } -void PopUpDialog::handleMouseMoved(int x, int y, int button) -{ +void PopUpDialog::handleMouseMoved(int x, int y, int button) {  	// Compute over which item the mouse is...  	int item = findItem(x, y); @@ -163,8 +158,7 @@ void PopUpDialog::handleMouseMoved(int x, int y, int button)  	setSelection(item);  } -void PopUpDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) -{ +void PopUpDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {  	if (keycode == 27) {	// escape  		close();  		return; @@ -194,16 +188,14 @@ void PopUpDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  	}  } -int PopUpDialog::findItem(int x, int y) const -{ +int PopUpDialog::findItem(int x, int y) const {  	if (x >= 0 && x < _w && y >= 0 && y < _h) {  		return (y-2) / kLineHeight;  	}  	return -1;  } -void PopUpDialog::setSelection(int item) -{ +void PopUpDialog::setSelection(int item) {  	if (item != _selection) {  		// Undraw old selection  		if (_selection >= 0) @@ -218,8 +210,7 @@ void PopUpDialog::setSelection(int item)  	}  } -bool PopUpDialog::isMouseDown() -{ +bool PopUpDialog::isMouseDown() {  	// TODO/FIXME - need a way to determine whether any mouse buttons are pressed or not.  	// Sure, we could just count mouse button up/down events, but that is cumbersome and  	// error prone. Would be much nicer to add an API to OSystem for this... @@ -227,8 +218,7 @@ bool PopUpDialog::isMouseDown()  	return false;  } -void PopUpDialog::moveUp() -{ +void PopUpDialog::moveUp() {  	if (_selection < 0) {  		setSelection(_popUpBoss->_entries.size() - 1);  	} else if (_selection > 0) { @@ -241,8 +231,7 @@ void PopUpDialog::moveUp()  	}  } -void PopUpDialog::moveDown() -{ +void PopUpDialog::moveDown() {  	int lastItem = _popUpBoss->_entries.size() - 1;  	if (_selection < 0) { @@ -257,9 +246,7 @@ void PopUpDialog::moveDown()  	}  } - -void PopUpDialog::drawMenuEntry(int entry, bool hilite) -{ +void PopUpDialog::drawMenuEntry(int entry, bool hilite) {  	// Draw one entry of the popup menu, including selection  	assert(entry >= 0);  	int x = _x + 1; @@ -270,30 +257,27 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite)  	_gui->fillRect(x, y, w, kLineHeight, hilite ? _gui->_textcolorhi : _gui->_bgcolor);  	if (name.size() == 0) {  		// Draw a seperator -		_gui->hline(x, y+kLineHeight/2, x+w-1, _gui->_color); -		_gui->hline(x+1, y+1+kLineHeight/2, x+w-1, _gui->_shadowcolor); +		_gui->hline(x, y + kLineHeight / 2, x + w - 1, _gui->_color); +		_gui->hline(x + 1, y + 1 + kLineHeight / 2, x + w - 1, _gui->_shadowcolor);  	} else { -		_gui->drawString(name, x+1, y+2, w-2, hilite ? _gui->_bgcolor : _gui->_textcolor); +		_gui->drawString(name, x + 1, y + 2, w - 2, hilite ? _gui->_bgcolor : _gui->_textcolor);  	}  	_gui->addDirtyRect(x, y, w, kLineHeight);  } -  //  // PopUpWidget  //  PopUpWidget::PopUpWidget(Dialog *boss, int x, int y, int w, int h) -	: Widget(boss, x, y-1, w, h+2), CommandSender(boss) -{ +	: Widget(boss, x, y - 1, w, h + 2), CommandSender(boss) {  	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;  	_type = 'POPU';  	_selectedItem = -1;  } -void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) -{ +void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) {  	PopUpDialog popupDialog(this, x + _x + _boss->getX(), y + _y + _boss->getY());  	int newSel = popupDialog.runModal();  	if (newSel != -1 && _selectedItem != newSel) { @@ -302,22 +286,19 @@ void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount)  	}  } -void PopUpWidget::appendEntry(const String &entry, uint32 tag) -{ +void PopUpWidget::appendEntry(const String &entry, uint32 tag) {  	Entry e;  	e.name = entry;  	e.tag = tag;  	_entries.push_back(e);  } -void PopUpWidget::clearEntries() -{ +void PopUpWidget::clearEntries() {  	_entries.clear();  	_selectedItem = -1;  } -void PopUpWidget::setSelected(int item) -{ +void PopUpWidget::setSelected(int item) {  	// FIXME  	if (item != _selectedItem) {  		if (item >= 0 && item < _entries.size()) { @@ -328,20 +309,19 @@ void PopUpWidget::setSelected(int item)  	}  } -void PopUpWidget::drawWidget(bool hilite) -{ +void PopUpWidget::drawWidget(bool hilite) {  	NewGui	*gui = _boss->getGui();  	// Draw a thin frame around us.  	// TODO - should look different than the EditTextWidget fram -	gui->hline(_x, _y, _x+_w-1, gui->_color); -	gui->hline(_x, _y+_h-1, _x+_w-1, gui->_shadowcolor); +	gui->hline(_x, _y, _x + _w - 1, gui->_color); +	gui->hline(_x, _y +_h-1, _x + _w - 1, gui->_shadowcolor);  	gui->vline(_x, _y, _y+_h-1, gui->_color); -	gui->vline(_x+_w-1, _y, _y+_h-1, gui->_shadowcolor); -	 +	gui->vline(_x + _w - 1, _y, _y +_h - 1, gui->_shadowcolor); +  	// Draw an arrow pointing down at the right end to signal this is a dropdown/popup  	gui->drawBitmap(up_down_arrows, _x+_w - 10, _y+2, hilite ? gui->_textcolorhi : gui->_textcolor); -	 +  	// Draw the selected entry, if any  	if (_selectedItem >= 0) {  		int align = (gui->getStringWidth(_entries[_selectedItem].name) > _w-6) ? kTextAlignRight : kTextAlignLeft; diff --git a/gui/ScrollBarWidget.cpp b/gui/ScrollBarWidget.cpp index 232dbc8053..f3db980795 100644 --- a/gui/ScrollBarWidget.cpp +++ b/gui/ScrollBarWidget.cpp @@ -61,8 +61,7 @@ static uint32 down_arrow[8] = {  };  ScrollBarWidget::ScrollBarWidget(Dialog *boss, int x, int y, int w, int h) -	: Widget (boss, x, y, w, h), CommandSender(boss) -{ +	: Widget (boss, x, y, w, h), CommandSender(boss) {  	_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG | WIDGET_WANT_TICKLE;  	_type = kScrollBarWidget; @@ -78,8 +77,7 @@ ScrollBarWidget::ScrollBarWidget(Dialog *boss, int x, int y, int w, int h)  	_currentPos = 0;  } -void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount) -{ +void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount) {  	int old_pos = _currentPos;  	// Do nothing if there are less items than fit on one page @@ -107,13 +105,11 @@ void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount)  	checkBounds(old_pos);  } -void ScrollBarWidget::handleMouseUp(int x, int y, int button, int clickCount) -{ +void ScrollBarWidget::handleMouseUp(int x, int y, int button, int clickCount) {  	_draggingPart = kNoPart;  } -void ScrollBarWidget::handleMouseWheel(int x, int y, int direction) -{ +void ScrollBarWidget::handleMouseWheel(int x, int y, int direction) {  	int old_pos = _currentPos;  	if (_numEntries < _entriesPerPage) @@ -129,8 +125,7 @@ void ScrollBarWidget::handleMouseWheel(int x, int y, int direction)  	checkBounds(old_pos);  } -void ScrollBarWidget::handleMouseMoved(int x, int y, int button) -{ +void ScrollBarWidget::handleMouseMoved(int x, int y, int button) {  	// Do nothing if there are less items than fit on one page  	if (_numEntries <= _entriesPerPage)  		return; @@ -167,8 +162,7 @@ void ScrollBarWidget::handleMouseMoved(int x, int y, int button)  	}  } -void ScrollBarWidget::handleTickle() -{ +void ScrollBarWidget::handleTickle() {  /*  	// FIXME - this code is supposed to allow for "click-repeat" (like key repeat),  	// i.e. if you click on one of the arrows and keep clicked, it will scroll @@ -188,8 +182,7 @@ void ScrollBarWidget::handleTickle()  */  } -void ScrollBarWidget::checkBounds(int old_pos) -{ +void ScrollBarWidget::checkBounds(int old_pos) {  	if (_numEntries <= _entriesPerPage || _currentPos < 0)  		_currentPos = 0;  	else if (_currentPos > _numEntries - _entriesPerPage) @@ -202,8 +195,7 @@ void ScrollBarWidget::checkBounds(int old_pos)  	}  } -void ScrollBarWidget::recalc() -{ +void ScrollBarWidget::recalc() {  	if (_numEntries > _entriesPerPage) {  		_sliderHeight = (_h - 2 * UP_DOWN_BOX_HEIGHT) * _entriesPerPage / _numEntries;  		if (_sliderHeight < UP_DOWN_BOX_HEIGHT) @@ -219,9 +211,7 @@ void ScrollBarWidget::recalc()  	}  } - -void ScrollBarWidget::drawWidget(bool hilite) -{ +void ScrollBarWidget::drawWidget(bool hilite) {  	NewGui *gui = _boss->getGui();  	int bottomY = _y + _h;  	bool isSinglePage = (_numEntries <= _entriesPerPage); @@ -234,19 +224,19 @@ void ScrollBarWidget::drawWidget(bool hilite)  	// Up arrow  	gui->frameRect(_x, _y, _w, UP_DOWN_BOX_HEIGHT, gui->_color);  	gui->drawBitmap(up_arrow, _x, _y, -	                isSinglePage ? gui->_color : -	                (hilite && _part == kUpArrowPart) ? gui->_textcolorhi : gui->_textcolor); +									isSinglePage ? gui->_color : +									(hilite && _part == kUpArrowPart) ? gui->_textcolorhi : gui->_textcolor);  	// Down arrow  	gui->frameRect(_x, bottomY - UP_DOWN_BOX_HEIGHT, _w, UP_DOWN_BOX_HEIGHT, gui->_color);  	gui->drawBitmap(down_arrow, _x, bottomY - UP_DOWN_BOX_HEIGHT, -	                isSinglePage ? gui->_color : -	                (hilite && _part == kDownArrowPart) ? gui->_textcolorhi : gui->_textcolor); +									isSinglePage ? gui->_color : +									(hilite && _part == kDownArrowPart) ? gui->_textcolorhi : gui->_textcolor);  	// Slider  	if (!isSinglePage) {  		gui->checkerRect(_x, _y + _sliderPos, _w, _sliderHeight, -		                 (hilite && _part == kSliderPart) ? gui->_textcolorhi : gui->_textcolor); +										(hilite && _part == kSliderPart) ? gui->_textcolorhi : gui->_textcolor);  		gui->frameRect(_x, _y + _sliderPos, _w, _sliderHeight, gui->_color);  	}  } diff --git a/gui/browser.cpp b/gui/browser.cpp index 767aa96558..4c32f60d25 100644 --- a/gui/browser.cpp +++ b/gui/browser.cpp @@ -36,37 +36,33 @@ enum {  };  BrowserDialog::BrowserDialog(NewGui *gui) -	: Dialog(gui, 40, 10, 320-2*40, 200-2*10), -	  _node(0), _nodeContent(0) -{ +	: Dialog(gui, 40, 10, 320 -2 * 40, 200 - 2 * 10), +	  _node(0), _nodeContent(0) {  	// Headline - TODO: should be customizable during creation time -	new StaticTextWidget(this, 10, 8, _w-2*10, kLineHeight, +	new StaticTextWidget(this, 10, 8, _w-2 * 10, kLineHeight,  		"Select directory with game data", kTextAlignCenter); -	 +  	// Current path - TODO: handle long paths ? -	_currentPath = -	new StaticTextWidget(this, 10, 20, _w-2*10, kLineHeight, -		"DUMMY", kTextAlignLeft); +	_currentPath = new StaticTextWidget(this, 10, 20, _w - 2 * 10, kLineHeight, +								"DUMMY", kTextAlignLeft);  	// Add file list -	_fileList = new ListWidget(this, 10, 34, _w-2*10, _h-34-24-10); +	_fileList = new ListWidget(this, 10, 34, _w - 2 * 10, _h - 34 - 24 - 10);  	_fileList->setNumberingMode(kListNumberingOff); -	 +  	// Buttons -	addButton(10, _h-24, "Go up", kGoUpCmd, 0); -	addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0); +	addButton(10, _h - 24, "Go up", kGoUpCmd, 0); +	addButton(_w-2 * (kButtonWidth+10), _h - 24, "Cancel", kCloseCmd, 0);  	addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0);  } -BrowserDialog::~BrowserDialog() -{ +BrowserDialog::~BrowserDialog() {  	delete _node;  	delete _nodeContent;  	delete _choice;  } -void BrowserDialog::open() -{ +void BrowserDialog::open() {  	// If no node has been set, or the last used one is now invalid,  	// go back to the root/default dir.  	if (_node == NULL || !_node->isValid()) { @@ -86,8 +82,7 @@ void BrowserDialog::open()  	Dialog::open();  } -void BrowserDialog::close() -{ +void BrowserDialog::close() {  	delete _nodeContent;  	_nodeContent = 0; @@ -95,8 +90,7 @@ void BrowserDialog::close()  	Dialog::close();  } -void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	FilesystemNode *tmp;  	switch (cmd) { @@ -130,8 +124,7 @@ void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data  	}  } -void BrowserDialog::updateListing() -{ +void BrowserDialog::updateListing() {  	assert(_node != NULL);  	// Update the path display diff --git a/gui/browser.h b/gui/browser.h index 139ac3d26a..51bfb64562 100644 --- a/gui/browser.h +++ b/gui/browser.h @@ -41,8 +41,8 @@ public:  	virtual void open();  	virtual void close();  	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); -	 -	FilesystemNode	*getResult()	{ return _choice; }; + +	FilesystemNode	*getResult() { return _choice; };  protected:  	ListWidget		*_fileList; @@ -50,7 +50,7 @@ protected:  	FilesystemNode	*_node;  	FSList			*_nodeContent;  	FilesystemNode	*_choice; -	 +  	void updateListing();  }; diff --git a/gui/chooser.cpp b/gui/chooser.cpp index c6068e2b45..6ebfc18885 100644 --- a/gui/chooser.cpp +++ b/gui/chooser.cpp @@ -27,27 +27,25 @@ enum {  };  ChooserDialog::ChooserDialog(NewGui *gui, const String title, const StringList& list) -	: Dialog(gui, 8, 24, 320-2*8, 141) -{ +	: Dialog(gui, 8, 24, 320 -2 * 8, 141) {  	// Headline -	new StaticTextWidget(this, 10, 8, _w-2*10, kLineHeight, title, kTextAlignCenter); -	 +	new StaticTextWidget(this, 10, 8, _w - 2 * 10, kLineHeight, title, kTextAlignCenter); +  	// Add choice list -	_list = new ListWidget(this, 10, 22, _w-2*10, _h-22-24-10); +	_list = new ListWidget(this, 10, 22, _w - 2 * 10, _h - 22 - 24 - 10);  	_list->setNumberingMode(kListNumberingOff);  	_list->setList(list);  	// Buttons -	addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0); -	_chooseButton = addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0); +	addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0); +	_chooseButton = addButton(_w-(kButtonWidth + 10), _h - 24, "Choose", kChooseCmd, 0);  	_chooseButton->setEnabled(false); -	 +  	// Result = -1 -> no choice was made  	setResult(-1);  } -void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	int item = _list->getSelected();  	switch (cmd) {  	case kChooseCmd: diff --git a/gui/chooser.h b/gui/chooser.h index b01c27718d..50f48da1b8 100644 --- a/gui/chooser.h +++ b/gui/chooser.h @@ -36,7 +36,7 @@ class ChooserDialog : public Dialog {  	typedef ScummVM::String String;  	typedef ScummVM::StringList StringList;  public: -	ChooserDialog(NewGui *gui, const String title, const StringList& list); +	ChooserDialog(NewGui *gui, const String title, const StringList &list);  	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); diff --git a/gui/console.cpp b/gui/console.cpp index ce043f26ce..cf27e2ba1f 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -48,20 +48,19 @@ This code is not finished, so please don't complain :-)   * - a *lot* of others things, this code is in no way complete and heavily under progress   */  ConsoleDialog::ConsoleDialog(NewGui *gui, int _realWidth) -	: Dialog(gui, 0, 0, _realWidth, 12*kLineHeight+2) -{ +	: Dialog(gui, 0, 0, _realWidth, 12 * kLineHeight + 2) {  	_lineWidth = (_w - kScrollBarWidth - 2) / kCharWidth;  	_linesPerPage = (_h - 2) / kLineHeight;  	memset(_buffer, ' ', kBufferSize);  	_linesInBuffer = kBufferSize / _lineWidth; -	 +  	_currentPos = 0;  	_scrollLine = _linesPerPage - 1; -	 +  	_caretVisible = false;  	_caretTime = 0; -	 +  	// Add scrollbar  	_scrollBar = new ScrollBarWidget(this, _w - kScrollBarWidth - 1, 0, kScrollBarWidth, _h);  	_scrollBar->setTarget(this); @@ -69,23 +68,22 @@ ConsoleDialog::ConsoleDialog(NewGui *gui, int _realWidth)  	// Display greetings & prompt  	print("ScummVM "SCUMMVM_VERSION" (" SCUMMVM_CVS ")\n");  	print("Console is ready\n"); -	 +  	_promptStartPos = _promptEndPos = -1; -	 +  	// Init callback  	_callbackProc = 0;  	_callbackRefCon = 0; -  - 	// Init History - 	_historyIndex = 0; - 	_historyLine = 0; - 	_historySize = 0; - 	for (int i = 0; i < kHistorySize; i++) - 		_history[i][0] = '\0'; + +	// Init History +	_historyIndex = 0; +	_historyLine = 0; +	_historySize = 0; +	for (int i = 0; i < kHistorySize; i++) +		_history[i][0] = '\0';  } -void ConsoleDialog::open() -{ +void ConsoleDialog::open() {  	Dialog::open();  	if (_promptStartPos == -1) {  		print(PROMPT); @@ -93,13 +91,12 @@ void ConsoleDialog::open()  	}  } -void ConsoleDialog::drawDialog() -{ +void ConsoleDialog::drawDialog() {  	// Blend over the background  	_gui->blendRect(_x, _y, _w, _h, _gui->_bgcolor, 2); -	 +  	// Draw a border -	_gui->hline(_x, _y+_h-1, _x+_w-1, _gui->_color); +	_gui->hline(_x, _y + _h - 1, _x + _w - 1, _gui->_color);  	// Draw text  	int start = _scrollLine - _linesPerPage + 1; @@ -107,7 +104,7 @@ void ConsoleDialog::drawDialog()  	for (int line = 0; line < _linesPerPage; line++) {  		int x = _x + 1;  		for (int column = 0; column < _lineWidth; column++) { -			int l = (start+line) % _linesInBuffer; +			int l = (start + line) % _linesInBuffer;  			byte c = _buffer[l * _lineWidth + column];  			_gui->drawChar(c, x, y, _gui->_textcolor);  			x += kCharWidth; @@ -122,8 +119,7 @@ void ConsoleDialog::drawDialog()  	_gui->addDirtyRect(_x, _y, _w, _h);  } -void ConsoleDialog::handleTickle() -{ +void ConsoleDialog::handleTickle() {  	uint32 time = _gui->get_time();  	if (_caretTime < time) {  		_caretTime = time + kCaretBlinkTime; @@ -135,15 +131,13 @@ void ConsoleDialog::handleTickle()  	}  } -void ConsoleDialog::handleMouseWheel(int x, int y, int direction) -{ +void ConsoleDialog::handleMouseWheel(int x, int y, int direction) {  	_scrollBar->handleMouseWheel(x, y, direction);  } -void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) -{ +void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {  	int i; -	 +  	switch (keycode) {  		case '\n':	// enter/return  		case '\r': { @@ -158,7 +152,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  			// FIXME - len should NEVER be negative. If anything makes it negative,  			// then the code doing that is buggy and needs to be fixed.  			assert(len >= 0); -			 +  			if (len > 0) {  				// We have to allocate the string buffer with new, since VC++ sadly does not @@ -169,21 +163,21 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  				for (i = 0; i < len; i++)  					str[i] = _buffer[(_promptStartPos + i) % kBufferSize];  				str[len] = '\0'; -				 +  				// Add the input to the history  				addToHistory(str); -				 +  				// Pass it to the input callback, if any  				if (_callbackProc)  					keepRunning = (*_callbackProc)(this, str, _callbackRefCon); -	 +  					// Get rid of the string buffer  				delete [] str;  			} -			 +  			print(PROMPT);  			_promptStartPos = _promptEndPos = _currentPos; -			 +  			draw();  			if (!keepRunning)  				close(); @@ -195,7 +189,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  		case 8:		// backspace  			if (_caretVisible)  				drawCaret(true); -		 +  			if (_currentPos > _promptStartPos) {  				_currentPos--;  				killChar(); @@ -208,23 +202,23 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  			draw();  			break;  /* -		case 256+24:	// pageup +		case 256 + 24:	// pageup  			_selectedItem -= _entriesPerPage - 1;  			if (_selectedItem < 0)  				_selectedItem = 0;  			break; -		case 256+25:	// pagedown +		case 256 + 25:	// pagedown  			_selectedItem += _entriesPerPage - 1;  			if (_selectedItem >= _list.size() )  				_selectedItem = _list.size() - 1;  			break;  */ -		case 256+22:	// home +		case 256 + 22:	// home  			_scrollLine = _linesPerPage - 1;	// FIXME - this is not correct after a wrap around  			updateScrollBar();  			draw();  			break; -		case 256+23:	// end +		case 256 + 23:	// end  			_scrollLine = _currentPos / _lineWidth;  			updateScrollBar();  			draw(); @@ -253,7 +247,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  				specialKeys(keycode);  			} else if (isprint((char)ascii)) {  				for (i = _promptEndPos-1; i >= _currentPos; i--) -					_buffer[(i+1) % kBufferSize] = _buffer[i % kBufferSize]; +					_buffer[(i + 1) % kBufferSize] = _buffer[i % kBufferSize];  				_promptEndPos++;  				putchar((char)ascii);  				scrollToCurrent(); @@ -261,8 +255,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  	}  } -void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	switch (cmd) {  	case kSetPositionCmd:  		int newPos = (int)data + _linesPerPage - 1; @@ -274,8 +267,7 @@ void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data  	}  } -void ConsoleDialog::specialKeys(int keycode) -{ +void ConsoleDialog::specialKeys(int keycode) {  	switch (keycode) {  		case 'a':  			_currentPos = _promptStartPos; @@ -302,23 +294,20 @@ void ConsoleDialog::specialKeys(int keycode)  	}  } -void ConsoleDialog::killChar() -{ +void ConsoleDialog::killChar() {  	for (int i = _currentPos; i < _promptEndPos; i++)  		_buffer[i % kBufferSize] = _buffer[(i+1) % kBufferSize];  	_buffer[_promptEndPos % kBufferSize] = ' ';  	_promptEndPos--;  } -void ConsoleDialog::killLine() -{ +void ConsoleDialog::killLine() {  	for (int i = _currentPos; i < _promptEndPos; i++)  		_buffer[i % kBufferSize] = ' ';  	_promptEndPos = _currentPos;  } -void ConsoleDialog::killLastWord() -{ +void ConsoleDialog::killLastWord() {  	int pos;  	int cnt = 0;  	while (_currentPos > _promptStartPos) { @@ -336,8 +325,7 @@ void ConsoleDialog::killLastWord()  	_promptEndPos -= cnt + 1;  } -void ConsoleDialog::addToHistory(const char *str) -{ +void ConsoleDialog::addToHistory(const char *str) {  	strcpy(_history[_historyIndex], str);  	_historyIndex = (_historyIndex + 1) % kHistorySize;  	_historyLine = 0; @@ -345,8 +333,7 @@ void ConsoleDialog::addToHistory(const char *str)  		_historySize++;  } -void ConsoleDialog::historyScroll(int direction) -{ +void ConsoleDialog::historyScroll(int direction) {  	if (_historySize == 0)  		return; @@ -383,26 +370,23 @@ void ConsoleDialog::historyScroll(int direction)  	for (int i = 0; i < kLineBufferSize && _history[idx][i] != '\0'; i++)  		putcharIntern(_history[idx][i]);  	_promptEndPos = _currentPos; -	 +  	// Ensure once more the caret is visible (in case of very long history entries)  	scrollToCurrent(); -	 +  	draw();  } - -void ConsoleDialog::nextLine() -{ +void ConsoleDialog::nextLine() {  	int line = _currentPos / _lineWidth;  	if (line == _scrollLine)  		_scrollLine++;  	_currentPos = (line + 1) * _lineWidth; -	 +  	updateScrollBar();  } -void ConsoleDialog::updateScrollBar() -{ +void ConsoleDialog::updateScrollBar() {  	int line = _currentPos / _lineWidth;  	_scrollBar->_numEntries = (line < _linesInBuffer) ? line + 1 : _linesInBuffer;  	_scrollBar->_currentPos = _scrollBar->_numEntries - (line - _scrollLine + _linesPerPage); @@ -410,8 +394,7 @@ void ConsoleDialog::updateScrollBar()  	_scrollBar->recalc();  } -int ConsoleDialog::printf(const char *format, ...) -{ +int ConsoleDialog::printf(const char *format, ...) {  	va_list	argptr;  	va_start(argptr, format); @@ -420,8 +403,7 @@ int ConsoleDialog::printf(const char *format, ...)  	return count;  } -int ConsoleDialog::vprintf(const char *format, va_list argptr) -{ +int ConsoleDialog::vprintf(const char *format, va_list argptr) {  	char	buf[2048];  #if defined(WIN32) @@ -433,18 +415,15 @@ int ConsoleDialog::vprintf(const char *format, va_list argptr)  	return count;  } -void ConsoleDialog::putchar(int c) -{ +void ConsoleDialog::putchar(int c) {  	if (_caretVisible)  		drawCaret(true);  	putcharIntern(c); -  	draw();	// FIXME - not nice to redraw the full console just for one char!  } -void ConsoleDialog::putcharIntern(int c) -{ +void ConsoleDialog::putcharIntern(int c) {  	if (c == '\n')  		nextLine();  	else { @@ -457,8 +436,7 @@ void ConsoleDialog::putcharIntern(int c)  	}  } -void ConsoleDialog::print(const char *str) -{ +void ConsoleDialog::print(const char *str) {  	if (_caretVisible)  		drawCaret(true); @@ -468,8 +446,7 @@ void ConsoleDialog::print(const char *str)  	draw();  } -void ConsoleDialog::drawCaret(bool erase) -{ +void ConsoleDialog::drawCaret(bool erase) {  	int line = _currentPos / _lineWidth;  	int displayLine = line - _scrollLine + _linesPerPage - 1; @@ -485,21 +462,20 @@ void ConsoleDialog::drawCaret(bool erase)  	char c = _buffer[getBufferPos()];  	if (erase) {  		_gui->fillRect(x, y, kCharWidth, kLineHeight, _gui->_bgcolor); -		_gui->drawChar(c, x, y+2, _gui->_textcolor); +		_gui->drawChar(c, x, y + 2, _gui->_textcolor);  	} else {  		_gui->fillRect(x, y, kCharWidth, kLineHeight, _gui->_textcolor); -		_gui->drawChar(c, x, y+2, _gui->_bgcolor); +		_gui->drawChar(c, x, y + 2, _gui->_bgcolor);  	}  	_gui->addDirtyRect(x, y, kCharWidth, kLineHeight); -	 +  	_caretVisible = !erase;  } -void ConsoleDialog::scrollToCurrent() -{ +void ConsoleDialog::scrollToCurrent() {  	int line = _currentPos / _lineWidth;  	int displayLine = line - _scrollLine + _linesPerPage - 1; -	 +  	if (displayLine < 0) {  		// TODO - this should only occur for loong edit lines, though  	} else if (displayLine >= _linesPerPage) { diff --git a/gui/console.h b/gui/console.h index 31d2b3c789..fbb7d39d52 100644 --- a/gui/console.h +++ b/gui/console.h @@ -46,7 +46,7 @@ protected:  	int		_lineWidth;  	int		_linesPerPage; -	 +  	int		_currentPos;  	int		_scrollLine; @@ -55,13 +55,13 @@ protected:  	bool	_caretVisible;  	uint32	_caretTime; -	 -	ScrollBarWidget	*_scrollBar; -	 + +	ScrollBarWidget *_scrollBar; +  	// The _callbackProc is called whenver a data line is entered  	//   	InputCallbackProc _callbackProc; -	void	*_callbackRefCon; +	void *_callbackRefCon;  	char _history[kHistorySize][kLineBufferSize];  	int _historySize; @@ -84,8 +84,7 @@ public:  #undef putchar  	void putchar(int c); -	void setInputeCallback(InputCallbackProc proc, void *refCon) -	{ +	void setInputeCallback(InputCallbackProc proc, void *refCon) {  		_callbackProc = proc;  		_callbackRefCon = refCon;  	} diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 6286bbfaf9..8ba97f160c 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -38,8 +38,7 @@   * ...   */ -Dialog::~Dialog() -{ +Dialog::~Dialog() {  	Widget *w = _firstWidget, *next;  	while (w) {  		next = w->_next; @@ -50,22 +49,20 @@ Dialog::~Dialog()  	_firstWidget = 0;  } -int Dialog::runModal() -{ +int Dialog::runModal() {  	// Open up  	open(); -	 +  	// Start processing events  	_gui->runLoop(); -	 +  	// Return the result code  	return _result;  } -void Dialog::open() -{ +void Dialog::open() {  	Widget *w = _firstWidget; -	 +  	_result = 0;  	_visible = true;  	_gui->openDialog(this); @@ -74,15 +71,14 @@ void Dialog::open()  	while (w && !w->wantsFocus()) {  		w = w->_next;  	} -	 +  	if (w) {  		w->receivedFocus();  		_focusedWidget = w;  	}  } -void Dialog::close() -{ +void Dialog::close() {  	_visible = false;  	_gui->closeTopDialog(); @@ -93,22 +89,18 @@ void Dialog::close()  	releaseFocus();  } -void Dialog::releaseFocus() -{ +void Dialog::releaseFocus() {  	if (_focusedWidget) {  		_focusedWidget->lostFocus();  		_focusedWidget = 0;  	}  } - -void Dialog::draw() -{ +void Dialog::draw() {  	_gui->_needRedraw = true;  } -void Dialog::drawDialog() -{ +void Dialog::drawDialog() {  	Widget *w = _firstWidget;  	if (!isVisible()) @@ -125,8 +117,7 @@ void Dialog::drawDialog()  	_gui->addDirtyRect(_x, _y, _w, _h);  } -void Dialog::handleMouseDown(int x, int y, int button, int clickCount) -{ +void Dialog::handleMouseDown(int x, int y, int button, int clickCount) {  	Widget *w;  	w = findWidget(x, y); @@ -141,11 +132,11 @@ void Dialog::handleMouseDown(int x, int y, int button, int clickCount)  		// The focus will change. Tell the old focused widget (if any)  		// that it lost the focus.  		releaseFocus(); -	 +  		// Tell the new focused widget (if any) that it just gained the focus.  		if (w)  			w->receivedFocus(); -	 +  		_focusedWidget = w;  	} @@ -153,10 +144,9 @@ void Dialog::handleMouseDown(int x, int y, int button, int clickCount)  		_focusedWidget->handleMouseDown(x - _focusedWidget->_x, y - _focusedWidget->_y, button, clickCount);  } -void Dialog::handleMouseUp(int x, int y, int button, int clickCount) -{ +void Dialog::handleMouseUp(int x, int y, int button, int clickCount) {  	Widget *w; -	 +  	if (_focusedWidget) {  		w = _focusedWidget; @@ -173,8 +163,7 @@ void Dialog::handleMouseUp(int x, int y, int button, int clickCount)  		w->handleMouseUp(x - w->_x, y - w->_y, button, clickCount);  } -void Dialog::handleMouseWheel(int x, int y, int direction) -{ +void Dialog::handleMouseWheel(int x, int y, int direction) {  	Widget *w;  	// This may look a bit backwards, but I think it makes more sense for @@ -188,8 +177,7 @@ void Dialog::handleMouseWheel(int x, int y, int direction)  		w->handleMouseWheel(x, y, direction);  } -void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) -{ +void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {  	if (_focusedWidget) {  		if (_focusedWidget->handleKeyDown(ascii, keycode, modifiers))  			return; @@ -212,19 +200,17 @@ void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)  	// ESC closes all dialogs by default  	if (keycode == 27)  		close(); -	 +  	// TODO: tab/shift-tab should focus the next/previous focusable widget  } -void Dialog::handleKeyUp(uint16 ascii, int keycode, int modifiers) -{ +void Dialog::handleKeyUp(uint16 ascii, int keycode, int modifiers) {  	// Focused widget recieves keyup events  	if (_focusedWidget)  		_focusedWidget->handleKeyUp(ascii, keycode, modifiers);  } -void Dialog::handleMouseMoved(int x, int y, int button) -{ +void Dialog::handleMouseMoved(int x, int y, int button) {  	Widget *w;  	if (_focusedWidget) { @@ -261,16 +247,14 @@ void Dialog::handleMouseMoved(int x, int y, int button)  	w->handleMouseMoved(x - w->_x, y - w->_y, button);  } -void Dialog::handleTickle() -{ +void Dialog::handleTickle() {  	// Focused widget recieves tickle notifications  	if (_focusedWidget && _focusedWidget->getFlags() & WIDGET_WANT_TICKLE) {  		_focusedWidget->handleTickle();  	}  } -void Dialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void Dialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	switch (cmd) {  	case kCloseCmd:  		close(); @@ -282,8 +266,7 @@ void Dialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)   * Determine the widget at location (x,y) if any. Assumes the coordinates are   * in the local coordinate system, i.e. relative to the top left of the dialog.   */ -Widget *Dialog::findWidget(int x, int y) -{ +Widget *Dialog::findWidget(int x, int y) {  	Widget *w = _firstWidget;  	while (w) {  		// Stop as soon as we find a widget that contains the point (x,y) @@ -294,13 +277,11 @@ Widget *Dialog::findWidget(int x, int y)  	return w;  } -ButtonWidget *Dialog::addButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey) -{ +ButtonWidget *Dialog::addButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey) {  	return new ButtonWidget(this, x, y, kButtonWidth, 16, label, cmd, hotkey);  } -PushButtonWidget *Dialog::addPushButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey) -{ +PushButtonWidget *Dialog::addPushButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey) {  	return new PushButtonWidget(this, x, y, kButtonWidth, 16, label, cmd, hotkey);  } diff --git a/gui/dialog.h b/gui/dialog.h index 2468275e31..b4e76e1170 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -47,14 +47,14 @@ protected:  private:  	int		_result; -	 +  public:  	Dialog(NewGui *gui, int x, int y, int w, int h)  		: _gui(gui), _x(x), _y(y), _w(w), _h(h), _firstWidget(0), -		  _mouseWidget(0), _focusedWidget(0), _visible(false) -		{} +		  _mouseWidget(0), _focusedWidget(0), _visible(false) { +	}  	virtual ~Dialog(); -	 +  	virtual int runModal();  	NewGui	*getGui()			{ return _gui; } @@ -80,10 +80,10 @@ protected:  	virtual void handleMouseMoved(int x, int y, int button);  	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); -	Widget* findWidget(int x, int y); // Find the widget at pos x,y if any +	Widget *findWidget(int x, int y); // Find the widget at pos x,y if any -	ButtonWidget* addButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey); -	PushButtonWidget* addPushButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey); +	ButtonWidget *addButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey); +	PushButtonWidget *addPushButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey);  	void setResult(int result) { _result = result; }  }; diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 6b5f5e90cf..9eb4c69c08 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -44,7 +44,6 @@ enum {  typedef ScummVM::List<const VersionSettings *> GameList; -  /*   * A dialog that allows the user to edit a config game entry.   * TODO: add widgets for some/all of the following @@ -78,17 +77,16 @@ public:  	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);  protected: -	Config			&_config; -	const String	&_domain; -	EditTextWidget	*_descriptionWidget; -	EditTextWidget	*_domainWidget; -	CheckboxWidget  *_fullscreenCheckbox; -	CheckboxWidget  *_amigaPalCheckbox; +	Config &_config; +	const String &_domain; +	EditTextWidget *_descriptionWidget; +	EditTextWidget *_domainWidget; +	CheckboxWidget *_fullscreenCheckbox; +	CheckboxWidget *_amigaPalCheckbox;  };  EditGameDialog::EditGameDialog(NewGui *gui, Config &config, const String &domain) -	: Dialog(gui, 8, 50, 320-2*8, 200-2*40), _config(config), _domain(domain) -{ +	: Dialog(gui, 8, 50, 320 - 2 * 8, 200 - 2 * 40), _config(config), _domain(domain) {  	// Determine the description string  	String gameid(_config.get("gameid", _domain));  	String description(_config.get("description", _domain)); @@ -111,18 +109,18 @@ EditGameDialog::EditGameDialog(NewGui *gui, Config &config, const String &domain  	// Label & edit widget for the game ID  	new StaticTextWidget(this, 10, 10, 40, kLineHeight, "ID: ", kTextAlignRight);  	_domainWidget = -		new EditTextWidget(this, 50, 10, _w-50-10, kLineHeight, _domain); -	 +		new EditTextWidget(this, 50, 10, _w - 50 - 10, kLineHeight, _domain); +  	// Label & edit widget for the description  	new StaticTextWidget(this, 10, 26, 40, kLineHeight, "Name: ", kTextAlignRight);  	_descriptionWidget = -		new EditTextWidget(this, 50, 26, _w-50-10, kLineHeight, description); +		new EditTextWidget(this, 50, 26, _w - 50 - 10, kLineHeight, description);  	// Path to game data (view only)  	String path(_config.get("path", _domain));  	new StaticTextWidget(this, 10, 42, 40, kLineHeight, "Path: ", kTextAlignRight); -	new StaticTextWidget(this, 50, 42, _w-50-10, kLineHeight, path, kTextAlignLeft); -	 +	new StaticTextWidget(this, 50, 42, _w - 50 - 10, kLineHeight, path, kTextAlignLeft); +  	// Full screen checkbox  	_fullscreenCheckbox = new CheckboxWidget(this, 15, 62, 200, 16, "Use Fullscreen Mode", 0, 'F');  	_fullscreenCheckbox->setState(_config.getBool("fullscreen", false, _domain)); @@ -136,12 +134,11 @@ EditGameDialog::EditGameDialog(NewGui *gui, Config &config, const String &domain  	}  	// Add OK & Cancel buttons -	addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0); -	addButton(_w-(kButtonWidth+10), _h-24, "OK", kOKCmd, 0); +	addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0); +	addButton(_w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0);  } -void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	if (cmd == kOKCmd) {  		// Write back changes made to config object  		String newDomain(_domainWidget->getLabel()); @@ -164,7 +161,6 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat  	}  } -  /*   * TODO list   * - add an text entry widget @@ -177,29 +173,28 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat   */  LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector) -	: Dialog(gui, 0, 0, 320, 200), _detector(detector) -{ +	: Dialog(gui, 0, 0, 320, 200), _detector(detector) {  	// Show game name  	new StaticTextWidget(this, 10, 8, 300, kLineHeight,  								"ScummVM "SCUMMVM_VERSION " (" SCUMMVM_CVS ")",   								kTextAlignCenter);  	// Add three buttons at the bottom -	addButton(1*(_w - kButtonWidth)/6, _h - 24, "Quit", kQuitCmd, 'Q'); -	addButton(3*(_w - kButtonWidth)/6, _h - 24, "Options", kOptionsCmd, 'O'); -	_startButton = addButton(5*(_w - kButtonWidth)/6, _h - 24, "Start", kStartCmd, 'S'); +	addButton(1 * (_w - kButtonWidth) / 6, _h - 24, "Quit", kQuitCmd, 'Q'); +	addButton(3 * (_w - kButtonWidth) / 6, _h - 24, "Options", kOptionsCmd, 'O'); +	_startButton = addButton(5 * (_w - kButtonWidth)/6, _h - 24, "Start", kStartCmd, 'S');  	// Add list with game titles  	_list = new ListWidget(this, 10, 28, 300, 112);  	_list->setEditable(false);  	_list->setNumberingMode(kListNumberingOff); -	 +  	// Two more buttons directly below the list box  	const int kBigButtonWidth = 90;  	new ButtonWidget(this, 10, 144, kBigButtonWidth, 16, "Add Game...", kAddGameCmd, 'A'); -	_editButton = new ButtonWidget(this, (320-kBigButtonWidth)/2, 144, kBigButtonWidth, 16, "Edit Game...", kEditGameCmd, 'E'); -	_removeButton = new ButtonWidget(this, 320-kBigButtonWidth-10, 144, kBigButtonWidth, 16, "Remove Game", kRemoveGameCmd, 'R'); -	 +	_editButton = new ButtonWidget(this, (320-kBigButtonWidth) / 2, 144, kBigButtonWidth, 16, "Edit Game...", kEditGameCmd, 'E'); +	_removeButton = new ButtonWidget(this, 320-kBigButtonWidth - 10, 144, kBigButtonWidth, 16, "Remove Game", kRemoveGameCmd, 'R'); +  	// Populate the list  	updateListing(); @@ -211,29 +206,24 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)  	// Create file browser dialog  	_browser = new BrowserDialog(_gui); -  } -LauncherDialog::~LauncherDialog() -{ +LauncherDialog::~LauncherDialog() {  	delete _browser;  } -void LauncherDialog::open() -{ +void LauncherDialog::open() {  	Dialog::open();  	g_config->set_writing(true);  } -void LauncherDialog::close() -{ +void LauncherDialog::close() {  	g_config->flush();  	g_config->set_writing(false);  	Dialog::close();  } -void LauncherDialog::updateListing() -{ +void LauncherDialog::updateListing() {  	int i;  	const VersionSettings *v = version_settings;  	ScummVM::StringList l; @@ -244,7 +234,7 @@ void LauncherDialog::updateListing()  	for (i = 0; i < domains.size(); i++) {  		String name(g_config->get("gameid", domains[i]));  		String description(g_config->get("description", domains[i])); -		 +  		if (name.isEmpty())  			name = domains[i];  		if (description.isEmpty()) { @@ -276,8 +266,7 @@ void LauncherDialog::updateListing()  /*   * Return a list of all games which might be the game in the specified directory.   */ -GameList findGame(FilesystemNode *dir) -{ +GameList findGame(FilesystemNode *dir) {  	GameList list;  	FSList *files = dir->listDir(FilesystemNode::kListFilesOnly); @@ -322,8 +311,7 @@ GameList findGame(FilesystemNode *dir)  	return list;  } -void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	int item =  _list->getSelected();  	switch (cmd) { @@ -342,12 +330,12 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat  		if (_browser->runModal()) {  			// User did make a choice...  			FilesystemNode *dir = _browser->getResult(); -			 +  			// ...so let's determine a list of candidates, games that  			// could be contained in the specified directory.  			GameList candidates = findGame(dir);  			const VersionSettings *v = 0; -			 +  			if (candidates.isEmpty()) {  				// No game was found in the specified directory  				MessageDialog alert(_gui, "ScummVM could not find any game in the specified directory!"); @@ -367,7 +355,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat  				if (0 <= i && i < candidates.size())  					v = candidates[i];  			} -			 +  			if (v != 0) {  				// The auto detector or the user made a choice.  				// Pick a domain name which does not yet exist (after all, we diff --git a/gui/message.cpp b/gui/message.cpp index 06d4ff643a..dee02ca533 100644 --- a/gui/message.cpp +++ b/gui/message.cpp @@ -23,14 +23,12 @@  #include "newgui.h"  enum { -        kOkCmd = 'OK  ', -        kCancelCmd = 'CNCL' +	kOkCmd = 'OK  ', +	kCancelCmd = 'CNCL'  }; -  MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, bool showOkButton, bool showCancelButton) -	: Dialog(gui, 30, 20, 260, 124) -{ +	: Dialog(gui, 30, 20, 260, 124) {  	// First, determine the size the dialog needs. For this we have to break  	// down the string into lines, and taking the maximum of their widths.  	// Using this, and accounting for the space the button(s) need, we can set @@ -96,15 +94,13 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, b  		_timer = 0;  } -void MessageDialog::handleTickle() -{ +void MessageDialog::handleTickle() {  	Dialog::handleTickle();  	if (_timer && _gui->get_time() > _timer)  		close();  } -int MessageDialog::addLine(StringList &lines, const char *line, int size) -{ +int MessageDialog::addLine(StringList &lines, const char *line, int size) {  	int width = 0, maxWidth = 0;  	const char *start = line, *pos = line, *end = start + size;  	String tmp; @@ -149,8 +145,7 @@ int MessageDialog::addLine(StringList &lines, const char *line, int size)  	return maxWidth;  } -void MessageDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void MessageDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	if (cmd == kOkCmd) {  		setResult(1);  		close(); diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 901db4d503..fa4ba93dbd 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -43,9 +43,8 @@   */  enum { -	kDoubleClickDelay = 500,    // milliseconds +	kDoubleClickDelay = 500, // milliseconds  	kCursorAnimateDelay = 500, -	  	kKeyRepeatInitialDelay = 400,  	kKeyRepeatSustainDelay = 100  }; @@ -82,17 +81,15 @@ static byte guifont[] = {  // Constructor  NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false), -	_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) -{ +	_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {  	// Clear the cursor  	memset(_cursor, 0xFF, sizeof(_cursor)); -	 +  	// Reset key repeat  	_currentKeyDown.keycode = 0;  } -void NewGui::runLoop() -{ +void NewGui::runLoop() {  	Dialog *activeDialog = _dialogStack.top();  	bool didSaveState = false; @@ -110,7 +107,7 @@ void NewGui::runLoop()  	_shadowcolor = _system->RBGToColor(64, 64, 64);  	_textcolor = _system->RBGToColor(32, 160, 32);  	_textcolorhi = _system->RBGToColor(0, 255, 0); -	 +  	if (!_stateIsSaved) {  		saveState();  		didSaveState = true; @@ -119,7 +116,7 @@ void NewGui::runLoop()  	while (!_dialogStack.empty() && activeDialog == _dialogStack.top()) {  		activeDialog->handleTickle(); -	 +  		if (_needRedraw) {  			// Restore the overlay to its initial state, then draw all dialogs.  			// This is necessary to get the blending right. @@ -129,7 +126,7 @@ void NewGui::runLoop()  				_dialogStack[i]->drawDialog();  			_needRedraw = false;  		} -		 +  		animateCursor();  		_system->update_screen();		 @@ -165,8 +162,8 @@ void NewGui::runLoop()  				case OSystem::EVENT_LBUTTONDOWN:  				case OSystem::EVENT_RBUTTONDOWN: {  					if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay) -					      && ABS(_lastClick.x - event.mouse.x) < 3 -					      && ABS(_lastClick.y - event.mouse.y) < 3) { +								&& ABS(_lastClick.x - event.mouse.x) < 3 +								&& ABS(_lastClick.y - event.mouse.y) < 3) {  						_lastClick.count++;  					} else {  						_lastClick.x = event.mouse.x; @@ -191,10 +188,8 @@ void NewGui::runLoop()  		}  		// check if event should be sent again (keydown) -		if (_currentKeyDown.keycode != 0) -		{ -			if (_keyRepeatTime < time) -			{ +		if (_currentKeyDown.keycode != 0) { +			if (_keyRepeatTime < time) {  				// fire event  				activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags);  				_keyRepeatTime = time + kKeyRepeatSustainDelay; @@ -211,14 +206,13 @@ void NewGui::runLoop()  #pragma mark - -void NewGui::saveState() -{ +void NewGui::saveState() {  	int sys_height = _system->get_height();  	int sys_width = _system->get_width();  	// Backup old cursor  	_oldCursorMode = _system->show_mouse(true); -	 +  	_system->show_overlay();  	// TODO - add getHeight & getWidth methods to OSystem.  	_screen = new int16[sys_width * sys_height]; @@ -233,8 +227,7 @@ void NewGui::saveState()  	_stateIsSaved = true;  } -void NewGui::restoreState() -{ +void NewGui::restoreState() {  	_system->show_mouse(_oldCursorMode);  	_system->hide_overlay(); @@ -242,40 +235,34 @@ void NewGui::restoreState()  		delete [] _screen;  		_screen = 0;  	} -	 +  	_system->update_screen();  	_stateIsSaved = false;  } -void NewGui::openDialog(Dialog *dialog) -{ +void NewGui::openDialog(Dialog *dialog) {  	_dialogStack.push(dialog);  	_needRedraw = true;  } -void NewGui::closeTopDialog() -{ +void NewGui::closeTopDialog() {  	// Don't do anything if no dialog is open  	if (_dialogStack.empty())  		return; -	 +  	// Remove the dialog from the stack  	_dialogStack.pop();  	_needRedraw = true;  } -  #pragma mark - - -int16 *NewGui::getBasePtr(int x, int y) -{ +int16 *NewGui::getBasePtr(int x, int y) {  	return _screen + x + y * _screenPitch;  } -void NewGui::box(int x, int y, int width, int height, bool inverted) -{ +void NewGui::box(int x, int y, int width, int height, bool inverted) {  	int16 colorA = inverted ? _shadowcolor : _color;  	int16 colorB = inverted ? _color : _shadowcolor; @@ -290,8 +277,7 @@ void NewGui::box(int x, int y, int width, int height, bool inverted)  	vline(x + width - 2, y + 1, y + height - 1, colorB);  } -void NewGui::line(int x, int y, int x2, int y2, int16 color) -{ +void NewGui::line(int x, int y, int x2, int y2, int16 color) {  	int16 *ptr;  	if (x2 < x) @@ -316,8 +302,7 @@ void NewGui::line(int x, int y, int x2, int y2, int16 color)  	}  } -void NewGui::blendRect(int x, int y, int w, int h, int16 color, int level) -{ +void NewGui::blendRect(int x, int y, int w, int h, int16 color, int level) {  	int r, g, b;  	uint8 ar, ag, ab;  	_system->colorToRBG(color, ar, ag, ab); @@ -338,8 +323,7 @@ void NewGui::blendRect(int x, int y, int w, int h, int16 color, int level)  	}  } -void NewGui::fillRect(int x, int y, int w, int h, int16 color) -{ +void NewGui::fillRect(int x, int y, int w, int h, int16 color) {  	int i;  	int16 *ptr = getBasePtr(x, y); @@ -351,8 +335,7 @@ void NewGui::fillRect(int x, int y, int w, int h, int16 color)  	}  } -void NewGui::checkerRect(int x, int y, int w, int h, int16 color) -{ +void NewGui::checkerRect(int x, int y, int w, int h, int16 color) {  	int i;  	int16 *ptr = getBasePtr(x, y); @@ -365,8 +348,7 @@ void NewGui::checkerRect(int x, int y, int w, int h, int16 color)  	}  } -void NewGui::frameRect(int x, int y, int w, int h, int16 color) -{ +void NewGui::frameRect(int x, int y, int w, int h, int16 color) {  	int i;  	int16 *ptr, *basePtr = getBasePtr(x, y);  	if (basePtr == NULL) @@ -386,8 +368,7 @@ void NewGui::frameRect(int x, int y, int w, int h, int16 color)  		*ptr = color;  } -void NewGui::addDirtyRect(int x, int y, int w, int h) -{ +void NewGui::addDirtyRect(int x, int y, int w, int h) {  	// For now we don't keep yet another list of dirty rects but simply  	// blit the affected area directly to the overlay. At least for our current  	// GUI/widget/dialog code that is just fine. @@ -395,8 +376,7 @@ void NewGui::addDirtyRect(int x, int y, int w, int h)  	_system->copy_rect_overlay(buf, _screenPitch, x, y, w, h);  } -void NewGui::drawChar(const byte chr, int xx, int yy, int16 color) -{ +void NewGui::drawChar(const byte chr, int xx, int yy, int16 color) {  	unsigned int buffer = 0, mask = 0, x, y;  	byte *tmp; @@ -419,8 +399,7 @@ void NewGui::drawChar(const byte chr, int xx, int yy, int16 color)  	}  } -int NewGui::getStringWidth(const String &str) -{ +int NewGui::getStringWidth(const String &str) {  	int space = 0;  	for (int i = 0; i < str.size(); ++i) @@ -428,13 +407,11 @@ int NewGui::getStringWidth(const String &str)  	return space;  } -int NewGui::getCharWidth(byte c) -{ +int NewGui::getCharWidth(byte c) {  	return guifont[c+6];  } -void NewGui::drawString(const String &str, int x, int y, int w, int16 color, int align) -{ +void NewGui::drawString(const String &str, int x, int y, int w, int16 color, int align) {  	const int leftX = x, rightX = x + w;  	int width = getStringWidth(str);  	if (align == kTextAlignCenter) @@ -455,8 +432,7 @@ void NewGui::drawString(const String &str, int x, int y, int w, int16 color, int  //  // Blit from a buffer to the display  // -void NewGui::blitFromBuffer(int x, int y, int w, int h, const byte *buf, int pitch) -{ +void NewGui::blitFromBuffer(int x, int y, int w, int h, const byte *buf, int pitch) {  	int16 *ptr = getBasePtr(x, y);  	assert(buf); @@ -467,12 +443,10 @@ void NewGui::blitFromBuffer(int x, int y, int w, int h, const byte *buf, int pit  	}  } -  //  // Blit from the display to a buffer  // -void NewGui::blitToBuffer(int x, int y, int w, int h, byte *buf, int pitch) -{ +void NewGui::blitToBuffer(int x, int y, int w, int h, byte *buf, int pitch) {  	int16 *ptr = getBasePtr(x, y);  	assert(buf); @@ -483,12 +457,10 @@ void NewGui::blitToBuffer(int x, int y, int w, int h, byte *buf, int pitch)  	}  } -  //  // Draw an 8x8 bitmap at location (x,y)  // -void NewGui::drawBitmap(uint32 *bitmap, int x, int y, int16 color, int h) -{ +void NewGui::drawBitmap(uint32 *bitmap, int x, int y, int16 color, int h) {  	int16 *ptr = getBasePtr(x, y);  	for (y = 0; y < h; y++) { @@ -506,8 +478,7 @@ void NewGui::drawBitmap(uint32 *bitmap, int x, int y, int16 color, int h)  // Draw the mouse cursor (animated). This is mostly ripped from the cursor code in gfx.cpp  // We could plug in a different cursor here if we like to.  // -void NewGui::animateCursor() -{ +void NewGui::animateCursor() {  	int time = get_time();   	if (time > _cursorAnimateTimer + kCursorAnimateDelay) {  		const byte colors[4] = { 15, 15, 7, 8 }; diff --git a/gui/options.cpp b/gui/options.cpp index c6345e768e..0f025d74e3 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -53,8 +53,7 @@ enum {  };  GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui) -	: Dialog(gui, 10, 15, 320-2*10, 200-2*15) -{ +	: Dialog(gui, 10, 15, 320 - 2 * 10, 200 - 2 * 15) {  	// The GFX mode popup & a label  	// TODO - add an API to query the list of available GFX modes, and to get/set the mode  	new StaticTextWidget(this, 5, 10+1, 100, kLineHeight, "Graphics mode: ", kTextAlignRight); @@ -87,7 +86,6 @@ GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui)  	}  	midiPopUp->setSelected(0); -  	//  	// Sound controllers  	// @@ -107,7 +105,7 @@ GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui)  	sfxVolumeSlider->setMinValue(0);	sfxVolumeSlider->setMaxValue(255);  	Widget *masterVolumeLabel, *musicVolumeLabel, *sfxVolumeLabel; -	 +  	masterVolumeLabel = new StaticTextWidget(this, 200, yoffset+10, 24, 16, "100%", kTextAlignLeft);  	musicVolumeLabel  = new StaticTextWidget(this, 200, yoffset+26, 24, 16, "100%", kTextAlignLeft);  	sfxVolumeLabel    = new StaticTextWidget(this, 200, yoffset+42, 24, 16, "100%", kTextAlignLeft); @@ -128,16 +126,14 @@ GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui)  	//  	// Add OK & Cancel buttons  	// -	addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0); -	addButton(_w-(kButtonWidth+10), _h-24, "OK", kOKCmd, 0); +	addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0); +	addButton(_w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0);  } -GlobalOptionsDialog::~GlobalOptionsDialog() -{ +GlobalOptionsDialog::~GlobalOptionsDialog() {  } -void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) -{ +void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {  	if (cmd == kOKCmd) {  		// TODO Write back changes made to config object  		setResult(1); diff --git a/gui/widget.cpp b/gui/widget.cpp index 9afb874524..0265ac5820 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -24,26 +24,22 @@  #include "newgui.h" -  #ifdef _MSC_VER  #	pragma warning( disable : 4068 ) // unknown pragma  #endif -  Widget::Widget (Dialog *boss, int x, int y, int w, int h)  	: _type(0), _boss(boss), _x(x), _y(y), _w(w), _h(h), -	  _id(0), _flags(0), _hasFocus(false) -{ +	  _id(0), _flags(0), _hasFocus(false) {  	// Insert into the widget list of the boss  	_next = _boss->_firstWidget;  	_boss->_firstWidget = this;  } -void Widget::draw() -{ +void Widget::draw() {  	NewGui *gui = _boss->getGui(); -	 +  	if (!isVisible() || !_boss->isVisible())  		return; @@ -62,7 +58,7 @@ void Widget::draw()  		_y += 4;  		_w -= 8;  	} -	 +  	// Now perform the actual widget draw  	drawWidget((_flags & WIDGET_HILITED) ? true : false); @@ -72,7 +68,7 @@ void Widget::draw()  		_y -= 4;  		_w += 8;  	} -	 +  	// Flag the draw area as dirty  	gui->addDirtyRect(_x, _y, _w, _h); @@ -80,69 +76,55 @@ void Widget::draw()  	_y -= _boss->_y;  } -  #pragma mark - -  StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align) -	: Widget (boss, x, y, w, h), _align(align) -{ +	: Widget (boss, x, y, w, h), _align(align) {  	_type = kStaticTextWidget;  	setLabel(text);  } -void StaticTextWidget::setValue(int value) -{ +void StaticTextWidget::setValue(int value) {  	char buf[256];  	sprintf(buf, "%d", value);  	_label = buf;  } -void StaticTextWidget::drawWidget(bool hilite) -{ +void StaticTextWidget::drawWidget(bool hilite) {  	NewGui *gui = _boss->getGui();  	gui->drawString(_label, _x, _y, _w, gui->_textcolor, _align);  } -  #pragma mark - -  ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)  	: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), CommandSender(boss), -	  _cmd(cmd), _hotkey(hotkey) -{ +	  _cmd(cmd), _hotkey(hotkey) {  	_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG;  	_type = kButtonWidget;  } -void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) -{ +void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {  	if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)  		sendCommand(_cmd, 0);  } -void ButtonWidget::drawWidget(bool hilite) -{ +void ButtonWidget::drawWidget(bool hilite) {  	NewGui *gui = _boss->getGui();  	gui->drawString(_label, _x, _y, _w, -	                !isEnabled() ? gui->_color : -	                hilite ? gui->_textcolorhi : gui->_textcolor, _align); +									!isEnabled() ? gui->_color : +									hilite ? gui->_textcolorhi : gui->_textcolor, _align);  } -  #pragma mark - -  PushButtonWidget::PushButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey) -	: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) -{ +	: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) {  	_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG;  	_type = kButtonWidget;  } -void PushButtonWidget::setState(bool state) -{ +void PushButtonWidget::setState(bool state) {  	if (_state != state) {  		_state = state;  		_flags ^= WIDGET_INV_BORDER; @@ -150,10 +132,8 @@ void PushButtonWidget::setState(bool state)  	}  } -  #pragma mark - -  /* 8x8 checkbox bitmap */  static uint32 checked_img[8] = {  	0x00000000, @@ -167,33 +147,30 @@ static uint32 checked_img[8] = {  };  CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey) -	: PushButtonWidget(boss, x, y, w, h, label, cmd, hotkey) -{ +	: PushButtonWidget(boss, x, y, w, h, label, cmd, hotkey) {  	_flags = WIDGET_ENABLED;  	_type = kCheckboxWidget;  } -void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) -{ +void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) {  	if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) {  		toggleState();  		sendCommand(_cmd, 0);  	}  } -void CheckboxWidget::drawWidget(bool hilite) -{ +void CheckboxWidget::drawWidget(bool hilite) {  	NewGui *gui = _boss->getGui(); -	 +  	// Draw the box  	gui->box(_x, _y, 14, 14); -	 +  	// If checked, draw cross inside the box  	if (_state)  		gui->drawBitmap(checked_img, _x + 3, _y + 3, gui->_textcolor);  	else  		gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor); -	 +  	// Finally draw the label  	gui->drawString(_label, _x + 20, _y + 3, _w, gui->_textcolor);  } @@ -202,8 +179,7 @@ void CheckboxWidget::drawWidget(bool hilite)  SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)  	: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), -	  _value(0), _valueMin(0), _valueMax(100) -{ +	  _value(0), _valueMin(0), _valueMax(100) {  	_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;  	_type = kSliderWidget;  } @@ -227,7 +203,6 @@ void SliderWidget::handleMouseMoved(int x, int y, int button) {  }  void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) { -	  	if (isEnabled()) {  		_isDragging = true;  		handleMouseMoved(x, y, button); @@ -235,31 +210,26 @@ void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) {  }  void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) { -  	if (isEnabled() && _isDragging) {  		sendCommand(_cmd, _value);  	} -  	_isDragging = false;  } -void SliderWidget::drawWidget(bool hilite) -{ +void SliderWidget::drawWidget(bool hilite) {  	NewGui *gui = _boss->getGui(); -	 +  	// Draw the box  	gui->box(_x, _y, _w, _h); -	 +  	// Draw the 'bar'  	gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);  } -int SliderWidget::valueToPos(int value) -{ +int SliderWidget::valueToPos(int value) {  	return ((_w - 4) * (value - _valueMin) / (_valueMax - _valueMin));  } -int SliderWidget::posToValue(int pos) -{ +int SliderWidget::posToValue(int pos) {  	return (pos) * (_valueMax - _valueMin) / (_w - 4) + _valueMin;  } diff --git a/gui/widget.h b/gui/widget.h index 49362a838c..99cb78c165 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -79,8 +79,7 @@ public:  	void setTarget(CommandReceiver *target)	{ _target = target; }  	CommandReceiver *getTarget() const		{ return _target; } -	virtual void sendCommand(uint32 cmd, uint32 data) -	{ +	virtual void sendCommand(uint32 cmd, uint32 data) {  		if (_target && cmd)  			_target->handleCommand(this, cmd, data);  	} @@ -120,7 +119,7 @@ public:  	void setFlags(int flags)	{ _flags |= flags; }  	void clearFlags(int flags)	{ _flags &= ~flags; }  	int getFlags() const		{ return _flags; } -	 +  	void setEnabled(bool e)		{ if (e) setFlags(WIDGET_ENABLED); else clearFlags(WIDGET_ENABLED); }  	bool isEnabled() const		{ return _flags & WIDGET_ENABLED; }  	bool isVisible() const		{ return !(_flags & WIDGET_INVISIBLE); } @@ -132,7 +131,6 @@ protected:  	virtual void lostFocusWidget() {}  }; -  /* StaticTextWidget */  class StaticTextWidget : public Widget {  protected: @@ -143,16 +141,15 @@ protected:  public:  	StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align);  	void setValue(int value); -	void setLabel(const String &label) { _label = label; } -	const String &getLabel() const     { return _label; } -	void setAlign(int align)           { _align = align; } -	int getAlign() const               { return _align; } +	void setLabel(const String &label)	{ _label = label; } +	const String &getLabel() const			{ return _label; } +	void setAlign(int align)						{ _align = align; } +	int getAlign() const								{ return _align; }  protected:  	void drawWidget(bool hilite);  }; -  /* ButtonWidget */  class ButtonWidget : public StaticTextWidget, public CommandSender {  	friend class Dialog;	// Needed for the hotkey handling @@ -221,7 +218,7 @@ public:  protected:  	void drawWidget(bool hilite); -	 +  	int valueToPos(int value);  	int posToValue(int pos);  }; | 
