Before I get back to mousemode and Blargg stuff, I decided to

make another pass at getting rid of raw pointers.  As I've come
to realize over the years (and in particular with reading the C++11
standard), raw pointers are evil and error-prone.  So this fixes
some of them at least.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2438 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2012-04-11 16:10:24 +00:00
parent 8af1211d7c
commit 186fa5c1be
18 changed files with 50 additions and 64 deletions

View File

@ -99,10 +99,10 @@ void FBSurfaceGL::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceGL::drawChar(const GUI::Font* font, uInt8 chr,
void FBSurfaceGL::drawChar(const GUI::Font& font, uInt8 chr,
uInt32 tx, uInt32 ty, uInt32 color)
{
const FontDesc& desc = font->desc();
const FontDesc& desc = font.desc();
// If this character is not included in the font, use the default char.
if(chr < desc.firstchar || chr >= desc.firstchar + desc.size)

View File

@ -44,7 +44,7 @@ class FBSurfaceGL : public FBSurface
void hLine(uInt32 x, uInt32 y, uInt32 x2, uInt32 color);
void vLine(uInt32 x, uInt32 y, uInt32 y2, uInt32 color);
void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color);
void drawChar(const GUI::Font* font, uInt8 c, uInt32 x, uInt32 y, uInt32 color);
void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y, uInt32 color);
void drawBitmap(uInt32* bitmap, uInt32 x, uInt32 y, uInt32 color, uInt32 h = 8);
void drawPixels(uInt32* data, uInt32 x, uInt32 y, uInt32 numpixels);
void drawSurface(const FBSurface* surface, uInt32 x, uInt32 y);

View File

@ -587,10 +587,10 @@ void FBSurfaceSoft::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 colo
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSoft::drawChar(const GUI::Font* font, uInt8 chr,
void FBSurfaceSoft::drawChar(const GUI::Font& font, uInt8 chr,
uInt32 tx, uInt32 ty, uInt32 color)
{
const FontDesc& desc = font->desc();
const FontDesc& desc = font.desc();
// If this character is not included in the font, use the default char.
if(chr < desc.firstchar || chr >= desc.firstchar + desc.size)

View File

@ -196,7 +196,7 @@ class FBSurfaceSoft : public FBSurface
void hLine(uInt32 x, uInt32 y, uInt32 x2, uInt32 color);
void vLine(uInt32 x, uInt32 y, uInt32 y2, uInt32 color);
void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color);
void drawChar(const GUI::Font* font, uInt8 c, uInt32 x, uInt32 y, uInt32 color);
void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y, uInt32 color);
void drawBitmap(uInt32* bitmap, uInt32 x, uInt32 y, uInt32 color, uInt32 h = 8);
void drawPixels(uInt32* data, uInt32 x, uInt32 y, uInt32 numpixels);
void drawSurface(const FBSurface* surface, uInt32 x, uInt32 y);

View File

@ -37,8 +37,8 @@ DataGridOpsWidget::DataGridOpsWidget(GuiObject* boss, const GUI::Font& font,
{
_type = kDataGridOpsWidget;
const int bwidth = _font->getMaxCharWidth() * 4,
bheight = _font->getFontHeight() + 3,
const int bwidth = _font.getMaxCharWidth() * 4,
bheight = _font.getFontHeight() + 3,
space = 6;
int xpos, ypos;

View File

@ -104,7 +104,7 @@ void PromptWidget::drawWidget(bool hilite)
} else {
fgcolor = c >> 8;
}
s.drawChar(&instance().consoleFont(), c & 0x7f, x, y, fgcolor);
s.drawChar(instance().consoleFont(), c & 0x7f, x, y, fgcolor);
x += _kConsoleCharWidth;
}
y += _kConsoleLineHeight;
@ -833,7 +833,7 @@ void PromptWidget::drawCaret()
char c = buffer(_currentPos);
s.fillRect(x, y, _kConsoleCharWidth, _kConsoleLineHeight, kTextColor);
s.drawChar(&_boss->instance().consoleFont(), c, x, y + 2, kBGColor);
s.drawChar(_boss->instance().consoleFont(), c, x, y + 2, kBGColor);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -221,9 +221,9 @@ void FrameBuffer::update()
myOSystem->console().tia().scanlines(),
myOSystem->console().getFramerate(), info.DisplayFormat.c_str());
myStatsMsg.surface->fillRect(0, 0, myStatsMsg.w, myStatsMsg.h, kBGColor);
myStatsMsg.surface->drawString(&myOSystem->consoleFont(),
myStatsMsg.surface->drawString(myOSystem->consoleFont(),
msg, 1, 1, myStatsMsg.w, myStatsMsg.color, kTextAlignLeft);
myStatsMsg.surface->drawString(&myOSystem->consoleFont(),
myStatsMsg.surface->drawString(myOSystem->consoleFont(),
info.BankSwitch, 1, 15, myStatsMsg.w, myStatsMsg.color, kTextAlignLeft);
myStatsMsg.surface->addDirtyRect(0, 0, 0, 0); // force a full draw
myStatsMsg.surface->setPos(myImageRect.x() + 1, myImageRect.y() + 1);
@ -414,7 +414,7 @@ inline void FrameBuffer::drawMessage()
myMsg.surface->setPos(myMsg.x + myImageRect.x(), myMsg.y + myImageRect.y());
myMsg.surface->fillRect(1, 1, myMsg.w-2, myMsg.h-2, kBtnColor);
myMsg.surface->box(0, 0, myMsg.w, myMsg.h, kColor, kShadowColor);
myMsg.surface->drawString(&myOSystem->font(), myMsg.text, 4, 4,
myMsg.surface->drawString(myOSystem->font(), myMsg.text, 4, 4,
myMsg.w, myMsg.color, kTextAlignLeft);
myMsg.counter--;
@ -1275,14 +1275,14 @@ void FBSurface::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::drawString(const GUI::Font* font, const string& s,
void FBSurface::drawString(const GUI::Font& font, const string& s,
int x, int y, int w,
uInt32 color, TextAlignment align,
int deltax, bool useEllipsis)
{
const int leftX = x, rightX = x + w;
unsigned int i;
int width = font->getStringWidth(s);
int width = font.getStringWidth(s);
string str;
if(useEllipsis && width > w)
@ -1293,7 +1293,7 @@ void FBSurface::drawString(const GUI::Font* font, const string& s,
// What is best really depends on the context; but unless we want to
// make this configurable, replacing the middle probably is a good
// compromise.
const int ellipsisWidth = font->getStringWidth("...");
const int ellipsisWidth = font.getStringWidth("...");
// SLOW algorithm to remove enough of the middle. But it is good enough for now.
const int halfWidth = (w - ellipsisWidth) / 2;
@ -1301,7 +1301,7 @@ void FBSurface::drawString(const GUI::Font* font, const string& s,
for(i = 0; i < s.size(); ++i)
{
int charWidth = font->getCharWidth(s[i]);
int charWidth = font.getCharWidth(s[i]);
if(w2 + charWidth > halfWidth)
break;
@ -1321,13 +1321,13 @@ void FBSurface::drawString(const GUI::Font* font, const string& s,
// (width + ellipsisWidth - w)
int skip = width + ellipsisWidth - w;
for(; i < s.size() && skip > 0; ++i)
skip -= font->getCharWidth(s[i]);
skip -= font.getCharWidth(s[i]);
// Append the remaining chars, if any
for(; i < s.size(); ++i)
str += s[i];
width = font->getStringWidth(str);
width = font.getStringWidth(str);
}
else
str = s;
@ -1340,7 +1340,7 @@ void FBSurface::drawString(const GUI::Font* font, const string& s,
x += deltax;
for(i = 0; i < str.size(); ++i)
{
w = font->getCharWidth(str[i]);
w = font.getCharWidth(str[i]);
if(x+w > rightX)
break;
if(x >= leftX)

View File

@ -684,7 +684,7 @@ class FBSurface
@param y The y coordinate
@param color The color of the character
*/
virtual void drawChar(const GUI::Font* font, uInt8 c, uInt32 x, uInt32 y,
virtual void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y,
uInt32 color) { }
/**
@ -825,7 +825,7 @@ class FBSurface
@param useEllipsis Whether to use '...' when the string is too long
*/
virtual void drawString(
const GUI::Font* font, const string& str, int x, int y, int w,
const GUI::Font& font, const string& str, int x, int y, int w,
uInt32 color, TextAlignment align = kTextAlignLeft,
int deltax = 0, bool useEllipsis = true);
};

View File

@ -41,7 +41,7 @@ ContextMenu::ContextMenu(GuiObject* boss, const GUI::Font& font,
_isScrolling(false),
_scrollUpColor(kColor),
_scrollDnColor(kColor),
_font(&font),
_font(font),
_cmd(cmd),
_xorig(0),
_yorig(0)
@ -65,7 +65,7 @@ void ContextMenu::addItems(const StringMap& items)
int maxwidth = 0;
for(unsigned int i = 0; i < _entries.size(); ++i)
{
int length = _font->getStringWidth(_entries[i].first);
int length = _font.getStringWidth(_entries[i].first);
if(length > maxwidth)
maxwidth = length;
}

View File

@ -106,7 +106,7 @@ class ContextMenu : public Dialog, public CommandSender
bool _isScrolling;
uInt32 _scrollUpColor, _scrollDnColor;
const GUI::Font* _font;
const GUI::Font& _font;
int _cmd;
uInt32 _xorig, _yorig;

View File

@ -62,7 +62,7 @@ void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount)
for (i = 0; i < _editString.size(); ++i)
{
width += _font->getCharWidth(_editString[i]);
width += _font.getCharWidth(_editString[i]);
if (width >= x)
break;
}

View File

@ -58,7 +58,7 @@ void EditableWidget::setEditString(const string& str, bool)
_editString = str;
_caretPos = _editString.size();
_editScrollOffset = (_font->getStringWidth(_editString) - (getEditRect().width()));
_editScrollOffset = (_font.getStringWidth(_editString) - (getEditRect().width()));
if (_editScrollOffset < 0)
_editScrollOffset = 0;
@ -177,7 +177,7 @@ int EditableWidget::getCaretOffset() const
{
int caretpos = 0;
for (int i = 0; i < _caretPos; i++)
caretpos += _font->getCharWidth(_editString[i]);
caretpos += _font.getCharWidth(_editString[i]);
caretpos -= _editScrollOffset;
@ -238,7 +238,7 @@ bool EditableWidget::adjustOffset()
}
else if (_editScrollOffset > 0)
{
const int strWidth = _font->getStringWidth(_editString);
const int strWidth = _font.getStringWidth(_editString);
if (strWidth - _editScrollOffset < editWidth)
{
// scroll right

View File

@ -59,12 +59,12 @@ PopUpWidget::PopUpWidget(GuiObject* boss, const GUI::Font& font,
_textcolorhi = kTextColor;
if(!_label.empty() && _labelWidth == 0)
_labelWidth = _font->getStringWidth(_label);
_labelWidth = _font.getStringWidth(_label);
_w = w + _labelWidth + 15;
// vertically center the arrows and text
myTextY = (_h - _font->getFontHeight()) / 2;
myTextY = (_h - _font.getFontHeight()) / 2;
myArrowsY = (_h - 8) / 2;
myMenu = new ContextMenu(this, font, list, cmd);
@ -147,7 +147,7 @@ void PopUpWidget::drawWidget(bool hilite)
// Draw the selected entry, if any
const string& name = myMenu->getSelectedName();
TextAlignment align = (_font->getStringWidth(name) > w-6) ?
TextAlignment align = (_font.getStringWidth(name) > w-6) ?
kTextAlignRight : kTextAlignLeft;
s.drawString(_font, name, x+2, _y+myTextY, w-6,
!isEnabled() ? kColor : kTextColor, align);

View File

@ -155,16 +155,16 @@ void RomInfoWidget::drawWidget(bool hilite)
}
else if(mySurfaceErrorMsg != "")
{
const GUI::Font* font = &instance().font();
uInt32 x = _x + ((_w - font->getStringWidth(mySurfaceErrorMsg)) >> 1);
uInt32 y = _y + ((yoff - font->getLineHeight()) >> 1);
const GUI::Font& font = instance().font();
uInt32 x = _x + ((_w - font.getStringWidth(mySurfaceErrorMsg)) >> 1);
uInt32 y = _y + ((yoff - font.getLineHeight()) >> 1);
s.drawString(font, mySurfaceErrorMsg, x, y, _w - 10, _textcolor);
}
int xpos = _x + 5, ypos = _y + yoff + 10;
for(unsigned int i = 0; i < myRomInfo.size(); ++i)
{
s.drawString(_font, myRomInfo[i], xpos, ypos, _w - 10, _textcolor);
ypos += _font->getLineHeight();
ypos += _font.getLineHeight();
}
}

View File

@ -121,7 +121,7 @@ GUI::Rect StringListWidget::getEditRect() const
char temp[10];
// FIXME: Assumes that all digits have the same width.
BSPF_snprintf(temp, 9, "%2d. ", (_list.size() - 1 + _numberingMode));
r.left += _font->getStringWidth(temp);
r.left += _font.getStringWidth(temp);
}
return r;

View File

@ -82,7 +82,7 @@ int TabWidget::addTab(const string& title)
int numTabs = _tabs.size();
// Determine the new tab width
int newWidth = _font->getStringWidth(title) + 2 * kTabPadding;
int newWidth = _font.getStringWidth(title) + 2 * kTabPadding;
if (_tabWidth < newWidth)
_tabWidth = newWidth;

View File

@ -39,7 +39,7 @@ Widget::Widget(GuiObject* boss, const GUI::Font& font,
: GuiObject(boss->instance(), boss->parent(), boss->dialog(), x, y, w, h),
_type(0),
_boss(boss),
_font((GUI::Font*)&font),
_font(font),
_id(-1),
_flags(0),
_hasFocus(false),
@ -52,8 +52,8 @@ Widget::Widget(GuiObject* boss, const GUI::Font& font,
_next = _boss->_firstWidget;
_boss->_firstWidget = this;
_fontWidth = _font->getMaxCharWidth();
_fontHeight = _font->getLineHeight();
_fontWidth = _font.getMaxCharWidth();
_fontHeight = _font.getLineHeight();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -182,37 +182,23 @@ Widget* Widget::findWidgetInChain(Widget *w, int x, int y)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Widget::isWidgetInChain(Widget* w, Widget* find)
{
bool found = false;
while(w)
{
// Stop as soon as we find the widget
if(w == find)
{
found = true;
break;
}
if(w == find) return true;
w = w->_next;
}
return found;
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Widget::isWidgetInChain(WidgetArray& list, Widget* find)
{
bool found = false;
for(int i = 0; i < (int)list.size(); ++i)
{
if(list[i] == find)
{
found = true;
break;
}
}
return true;
return found;
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -469,7 +455,7 @@ CheckboxWidget::CheckboxWidget(GuiObject *boss, const GUI::Font& font,
if(_h > 14) // center box
_boxY = (_h - 14) / 2;
else // center text
_textY = (14 - _font->getFontHeight()) / 2;
_textY = (14 - _font.getFontHeight()) / 2;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -546,7 +532,7 @@ SliderWidget::SliderWidget(GuiObject *boss, const GUI::Font& font,
_bgcolorhi = kDlgColor;
if(!_label.empty() && _labelWidth == 0)
_labelWidth = _font->getStringWidth(_label);
_labelWidth = _font.getStringWidth(_label);
_w = w + _labelWidth;
}

View File

@ -133,9 +133,9 @@ class Widget : public GuiObject
bool wantsRaw() const { return _flags & WIDGET_WANTS_RAWDATA; }
void setID(int id) { _id = id; }
int getID() { return _id; }
int getID() const { return _id; }
virtual const GUI::Font* font() { return _font; }
virtual const GUI::Font& font() const { return _font; }
void setTextColor(uInt32 color) { _textcolor = color; }
void setTextColorHi(uInt32 color) { _textcolorhi = color; }
@ -161,7 +161,7 @@ class Widget : public GuiObject
protected:
int _type;
GuiObject* _boss;
GUI::Font* _font;
const GUI::Font& _font;
Widget* _next;
int _id;
int _flags;