[Scummvm-git-logs] scummvm master -> 92f8ad94d2c83c338e53002dc9afb30b19ff997e

dreammaster paulfgilbert at gmail.com
Thu Jan 17 06:22:56 CET 2019


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
795e23c05d GLK: Constifying attribute, width calc methods
92f8ad94d2 GLK: Clean up use of TextBufferRow in buffer windows


Commit: 795e23c05d81ca40f46f38bac0872272de6f9851
    https://github.com/scummvm/scummvm/commit/795e23c05d81ca40f46f38bac0872272de6f9851
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-01-16T21:12:03-08:00

Commit Message:
GLK: Constifying attribute, width calc methods

Changed paths:
    engines/glk/window_text_buffer.cpp
    engines/glk/window_text_buffer.h
    engines/glk/windows.cpp
    engines/glk/windows.h


diff --git a/engines/glk/window_text_buffer.cpp b/engines/glk/window_text_buffer.cpp
index ce4dd7c..0faafc8 100644
--- a/engines/glk/window_text_buffer.cpp
+++ b/engines/glk/window_text_buffer.cpp
@@ -1587,8 +1587,7 @@ void TextBufferWindow::scrollResize() {
 	_scrollBack += SCROLLBACK;
 }
 
-int TextBufferWindow::calcWidth(uint32 *chars, Attributes *attrs, int startchar,
-								int numChars, int spw) {
+int TextBufferWindow::calcWidth(const uint32 *chars, const Attributes *attrs, int startchar, int numChars, int spw) {
 	Screen &screen = *g_vm->_screen;
 	int w = 0;
 	int a, b;
diff --git a/engines/glk/window_text_buffer.h b/engines/glk/window_text_buffer.h
index 47d87a4..0ac74d2 100644
--- a/engines/glk/window_text_buffer.h
+++ b/engines/glk/window_text_buffer.h
@@ -91,7 +91,7 @@ private:
 
 	void scrollOneLine(bool forced);
 	void scrollResize();
-	int calcWidth(uint32 *chars, Attributes *attrs, int startchar, int numchars, int spw);
+	int calcWidth(const uint32 *chars, const Attributes *attrs, int startchar, int numchars, int spw);
 public:
 	int _width, _height;
 	int _spaced;
diff --git a/engines/glk/windows.cpp b/engines/glk/windows.cpp
index c8ab447..624defa 100644
--- a/engines/glk/windows.cpp
+++ b/engines/glk/windows.cpp
@@ -730,7 +730,7 @@ void Attributes::clear() {
 	style = 0;
 }
 
-byte *Attributes::attrBg(WindowStyle *styles) {
+const byte *Attributes::attrBg(const WindowStyle *styles) {
 	int revset = reverse || (styles[style].reverse && !Windows::_overrideReverse);
 
 	int zfset = fgset ? fgset : Windows::_overrideFgSet;
@@ -771,7 +771,7 @@ byte *Attributes::attrBg(WindowStyle *styles) {
 	}
 }
 
-byte *Attributes::attrFg(WindowStyle *styles) {
+const byte *Attributes::attrFg(const WindowStyle *styles) {
 	int revset = reverse || (styles[style].reverse && !Windows::_overrideReverse);
 
 	int zfset = fgset ? fgset : Windows::_overrideFgSet;
diff --git a/engines/glk/windows.h b/engines/glk/windows.h
index c905556..c917d2f 100644
--- a/engines/glk/windows.h
+++ b/engines/glk/windows.h
@@ -328,7 +328,7 @@ struct Attributes {
 	/**
 	 * Equality comparison
 	 */
-	bool operator==(const Attributes &src) {
+	bool operator==(const Attributes &src) const {
 		return fgset == src.fgset && bgset == src.bgset && reverse == src.reverse
 			   && style == src.style && fgcolor == src.fgcolor && bgcolor == src.bgcolor
 			   && hyper == src.hyper;
@@ -336,7 +336,7 @@ struct Attributes {
 	/**
 	 * Inequality comparison
 	 */
-	bool operator!=(const Attributes &src) {
+	bool operator!=(const Attributes &src) const {
 		return fgset != src.fgset || bgset != src.bgset || reverse != src.reverse
 			   || style != src.style || fgcolor != src.fgcolor || bgcolor != src.bgcolor
 			   || hyper != src.hyper;
@@ -345,17 +345,17 @@ struct Attributes {
 	/**
 	 * Return the background color for the current font style
 	 */
-	byte *attrBg(WindowStyle *styles);
+	const byte *attrBg(const WindowStyle *styles);
 
 	/**
 	 * Return the foreground color for the current font style
 	 */
-	byte *attrFg(WindowStyle *styles);
+	const byte *attrFg(const WindowStyle *styles);
 
 	/**
 	 * Get the font for the current font style
 	 */
-	FACES attrFont(WindowStyle *styles) const {
+	FACES attrFont(const WindowStyle *styles) const {
 		return styles[style].font;
 	}
 };


Commit: 92f8ad94d2c83c338e53002dc9afb30b19ff997e
    https://github.com/scummvm/scummvm/commit/92f8ad94d2c83c338e53002dc9afb30b19ff997e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-01-16T21:16:38-08:00

Commit Message:
GLK: Clean up use of TextBufferRow in buffer windows

Changed paths:
    engines/glk/window_text_buffer.cpp


diff --git a/engines/glk/window_text_buffer.cpp b/engines/glk/window_text_buffer.cpp
index 0faafc8..ec5b6bc 100644
--- a/engines/glk/window_text_buffer.cpp
+++ b/engines/glk/window_text_buffer.cpp
@@ -781,7 +781,6 @@ void TextBufferWindow::cancelLineEvent(Event *ev) {
 }
 
 void TextBufferWindow::redraw() {
-	TextBufferRow *ln;
 	int linelen;
 	int nsp, spw, pw;
 	int x0, y0, x1, y1;
@@ -802,10 +801,6 @@ void TextBufferWindow::redraw() {
 	_lines[0]._len = _numChars;
 	sx0 = sx1 = selleft = selright = 0;
 
-	ln = new TextBufferRow();
-	if (!ln)
-		return;
-
 	x0 = (_bbox.left + g_conf->_tMarginX) * GLI_SUBPIX;
 	x1 = (_bbox.right - g_conf->_tMarginX - g_conf->_scrollWidth) * GLI_SUBPIX;
 	y0 = _bbox.top + g_conf->_tMarginY;
@@ -834,14 +829,14 @@ void TextBufferWindow::redraw() {
 		if (selrow)
 			_lines[i]._dirty = true;
 
-		memcpy(ln, &_lines[i], sizeof(TextBufferRow));
+		TextBufferRow ln(_lines[i]);
 
 		// skip if we can
-		if (!ln->_dirty && !ln->_repaint && !Windows::_forceRedraw && _scrollPos == 0)
+		if (!ln._dirty && !ln._repaint && !Windows::_forceRedraw && _scrollPos == 0)
 			continue;
 
 		// repaint previously selected lines if needed
-		if (ln->_repaint && !Windows::_forceRedraw)
+		if (ln._repaint && !Windows::_forceRedraw)
 			_windows->redrawRect(Rect(x0 / GLI_SUBPIX, y,
 									  x1 / GLI_SUBPIX, y + _font._leading));
 
@@ -857,29 +852,29 @@ void TextBufferWindow::redraw() {
 		if (i == _scrollPos && i > 0)
 			continue;
 
-		linelen = ln->_len;
+		linelen = ln._len;
 
 		// kill spaces at the end unless they're a different color
 		color = Windows::_overrideBgSet ? g_conf->_windowColor : _bgColor;
-		while (i > 0 && linelen > 1 && ln->_chars[linelen - 1] == ' '
-				&& _styles[ln->_attrs[linelen - 1].style].bg == color
-				&& !_styles[ln->_attrs[linelen - 1].style].reverse)
+		while (i > 0 && linelen > 1 && ln._chars[linelen - 1] == ' '
+				&& _styles[ln._attrs[linelen - 1].style].bg == color
+				&& !_styles[ln._attrs[linelen - 1].style].reverse)
 			linelen --;
 
 		// kill characters that would overwrite the scroll bar
-		while (linelen > 1 && calcWidth(ln->_chars, ln->_attrs, 0, linelen, -1) >= pw)
+		while (linelen > 1 && calcWidth(ln._chars, ln._attrs, 0, linelen, -1) >= pw)
 			linelen --;
 
 		/*
 		 * count spaces and width for justification
 		 */
-		if (_font._justify && !ln->_newLine && i > 0) {
+		if (_font._justify && !ln._newLine && i > 0) {
 			for (a = 0, nsp = 0; a < linelen; a++)
-				if (ln->_chars[a] == ' ')
+				if (ln._chars[a] == ' ')
 					nsp ++;
-			w = calcWidth(ln->_chars, ln->_attrs, 0, linelen, 0);
+			w = calcWidth(ln._chars, ln._attrs, 0, linelen, 0);
 			if (nsp)
-				spw = (x1 - x0 - ln->_lm - ln->_rm - 2 * SLOP - w) / nsp;
+				spw = (x1 - x0 - ln._lm - ln._rm - 2 * SLOP - w) / nsp;
 			else
 				spw = 0;
 		} else {
@@ -894,20 +889,20 @@ void TextBufferWindow::redraw() {
 			// optimized case for all chars selected
 			if (selleft && selright) {
 				rsc = linelen > 0 ? linelen - 1 : 0;
-				selchar = calcWidth(ln->_chars, ln->_attrs, lsc, rsc, spw) / GLI_SUBPIX;
+				selchar = calcWidth(ln._chars, ln._attrs, lsc, rsc, spw) / GLI_SUBPIX;
 			} else {
 				// optimized case for leftmost char selected
 				if (selleft) {
 					tsc = linelen > 0 ? linelen - 1 : 0;
-					selchar = calcWidth(ln->_chars, ln->_attrs, lsc, tsc, spw) / GLI_SUBPIX;
+					selchar = calcWidth(ln._chars, ln._attrs, lsc, tsc, spw) / GLI_SUBPIX;
 				} else {
 					// find the substring contained by the selection
-					tx = (x0 + SLOP + ln->_lm) / GLI_SUBPIX;
+					tx = (x0 + SLOP + ln._lm) / GLI_SUBPIX;
 					// measure string widths until we find left char
 					for (tsc = 0; tsc < linelen; tsc++) {
-						tsw = calcWidth(ln->_chars, ln->_attrs, 0, tsc, spw) / GLI_SUBPIX;
+						tsw = calcWidth(ln._chars, ln._attrs, 0, tsc, spw) / GLI_SUBPIX;
 						if (tsw + tx >= sx0 ||
-								((tsw + tx + GLI_SUBPIX) >= sx0 && ln->_chars[tsc] != ' ')) {
+								((tsw + tx + GLI_SUBPIX) >= sx0 && ln._chars[tsc] != ' ')) {
 							lsc = tsc;
 							selchar = true;
 							break;
@@ -921,7 +916,7 @@ void TextBufferWindow::redraw() {
 					} else {
 						// measure string widths until we find right char
 						for (tsc = lsc; tsc < linelen; tsc++) {
-							tsw = calcWidth(ln->_chars, ln->_attrs, lsc, tsc, spw) / GLI_SUBPIX;
+							tsw = calcWidth(ln._chars, ln._attrs, lsc, tsc, spw) / GLI_SUBPIX;
 							if (tsw + sx0 < sx1)
 								rsc = tsc;
 						}
@@ -933,13 +928,13 @@ void TextBufferWindow::redraw() {
 			// reverse colors for selected chars
 			if (selchar) {
 				for (tsc = lsc; tsc <= rsc; tsc++) {
-					ln->_attrs[tsc].reverse = !ln->_attrs[tsc].reverse;
-					_copyBuf[_copyPos] = ln->_chars[tsc];
+					ln._attrs[tsc].reverse = !ln._attrs[tsc].reverse;
+					_copyBuf[_copyPos] = ln._chars[tsc];
 					_copyPos++;
 				}
 			}
 			// add newline if we reach the end of the line
-			if (ln->_len == 0 || ln->_len == (rsc + 1)) {
+			if (ln._len == 0 || ln._len == (rsc + 1)) {
 				_copyBuf[_copyPos] = '\n';
 				_copyPos++;
 			}
@@ -956,14 +951,14 @@ void TextBufferWindow::redraw() {
 		screen.fillRect(Rect::fromXYWH(x0 / GLI_SUBPIX, y, (x1 - x0) / GLI_SUBPIX, _font._leading),
 						color);
 
-		x = x0 + SLOP + ln->_lm;
+		x = x0 + SLOP + ln._lm;
 		a = 0;
 		for (b = 0; b < linelen; b++) {
-			if (ln->_attrs[a] != ln->_attrs[b]) {
-				link = ln->_attrs[a].hyper;
-				font = ln->_attrs[a].attrFont(_styles);
-				color = ln->_attrs[a].attrBg(_styles);
-				w = screen.stringWidthUni(font, Common::U32String(ln->_chars + a, b - a), spw);
+			if (ln._attrs[a] != ln._attrs[b]) {
+				link = ln._attrs[a].hyper;
+				font = ln._attrs[a].attrFont(_styles);
+				color = ln._attrs[a].attrBg(_styles);
+				w = screen.stringWidthUni(font, Common::U32String(ln._chars + a, b - a), spw);
 				screen.fillRect(Rect::fromXYWH(x / GLI_SUBPIX, y, w / GLI_SUBPIX, _font._leading),
 								color);
 				if (link) {
@@ -977,10 +972,10 @@ void TextBufferWindow::redraw() {
 				a = b;
 			}
 		}
-		link = ln->_attrs[a].hyper;
-		font = ln->_attrs[a].attrFont(_styles);
-		color = ln->_attrs[a].attrBg(_styles);
-		w = screen.stringWidthUni(font, Common::U32String(ln->_chars + a, b - a), spw);
+		link = ln._attrs[a].hyper;
+		font = ln._attrs[a].attrFont(_styles);
+		color = ln._attrs[a].attrBg(_styles);
+		w = screen.stringWidthUni(font, Common::U32String(ln._chars + a, b - a), spw);
 		screen.fillRect(Rect::fromXYWH(x / GLI_SUBPIX, y, w / GLI_SUBPIX, _font._leading), color);
 		if (link) {
 			screen.fillRect(Rect::fromXYWH(x / GLI_SUBPIX + 1, y + _font._baseLine + 1,
@@ -1001,29 +996,29 @@ void TextBufferWindow::redraw() {
 		if (_windows->getFocusWindow() == this && i == 0 && (_lineRequest || _lineRequestUni)) {
 			w = calcWidth(_chars, _attrs, 0, _inCurs, spw);
 			if (w < pw - _font._caretShape * 2 * GLI_SUBPIX)
-				_font.drawCaret(Point(x0 + SLOP + ln->_lm + w, y + _font._baseLine));
+				_font.drawCaret(Point(x0 + SLOP + ln._lm + w, y + _font._baseLine));
 		}
 
 		/*
 		 * draw text
 		 */
 
-		x = x0 + SLOP + ln->_lm;
+		x = x0 + SLOP + ln._lm;
 		a = 0;
 		for (b = 0; b < linelen; b++) {
-			if (ln->_attrs[a] != ln->_attrs[b]) {
-				link = ln->_attrs[a].hyper;
-				font = ln->_attrs[a].attrFont(_styles);
-				color = link ? _font._linkColor : ln->_attrs[a].attrFg(_styles);
+			if (ln._attrs[a] != ln._attrs[b]) {
+				link = ln._attrs[a].hyper;
+				font = ln._attrs[a].attrFont(_styles);
+				color = link ? _font._linkColor : ln._attrs[a].attrFg(_styles);
 				x = screen.drawStringUni(Point(x, y + _font._baseLine),
-										 font, color, Common::U32String(ln->_chars + a, b - a), spw);
+										 font, color, Common::U32String(ln._chars + a, b - a), spw);
 				a = b;
 			}
 		}
-		link = ln->_attrs[a].hyper;
-		font = ln->_attrs[a].attrFont(_styles);
-		color = link ? _font._linkColor : ln->_attrs[a].attrFg(_styles);
-		screen.drawStringUni(Point(x, y + _font._baseLine), font, color, Common::U32String(ln->_chars + a, linelen - a), spw);
+		link = ln._attrs[a].hyper;
+		font = ln._attrs[a].attrFont(_styles);
+		color = link ? _font._linkColor : ln._attrs[a].attrFg(_styles);
+		screen.drawStringUni(Point(x, y + _font._baseLine), font, color, Common::U32String(ln._chars + a, linelen - a), spw);
 	}
 
 	/*
@@ -1065,34 +1060,34 @@ void TextBufferWindow::redraw() {
 	 * draw the images
 	 */
 	for (i = 0; i < _scrollBack; i++) {
-		memcpy(ln, &_lines[i], sizeof(TextBufferRow));
+		TextBufferRow ln(_lines[i]);
 
 		y = y0 + (_height - (i - _scrollPos) - 1) * _font._leading;
 
-		if (ln->_lPic) {
-			if (y < y1 && y + ln->_lPic->h > y0) {
-				ln->_lPic->drawPicture(Point(x0 / GLI_SUBPIX, y),
+		if (ln._lPic) {
+			if (y < y1 && y + ln._lPic->h > y0) {
+				ln._lPic->drawPicture(Point(x0 / GLI_SUBPIX, y),
 					Rect(x0 / GLI_SUBPIX, y0, x1 / GLI_SUBPIX, y1));
-				link = ln->_lHyper;
+				link = ln._lHyper;
 				hy0 = y > y0 ? y : y0;
-				hy1 = y + ln->_lPic->h < y1 ? y + ln->_lPic->h : y1;
+				hy1 = y + ln._lPic->h < y1 ? y + ln._lPic->h : y1;
 				hx0 = x0 / GLI_SUBPIX;
-				hx1 = x0 / GLI_SUBPIX + ln->_lPic->w < x1 / GLI_SUBPIX
-					  ? x0 / GLI_SUBPIX + ln->_lPic->w
+				hx1 = x0 / GLI_SUBPIX + ln._lPic->w < x1 / GLI_SUBPIX
+					  ? x0 / GLI_SUBPIX + ln._lPic->w
 					  : x1 / GLI_SUBPIX;
 				g_vm->_selection->putHyperlink(link, hx0, hy0, hx1, hy1);
 			}
 		}
 
-		if (ln->_rPic) {
-			if (y < y1 && y + ln->_rPic->h > y0) {
-				ln->_rPic->drawPicture(Point(x1 / GLI_SUBPIX - ln->_rPic->w, y),
+		if (ln._rPic) {
+			if (y < y1 && y + ln._rPic->h > y0) {
+				ln._rPic->drawPicture(Point(x1 / GLI_SUBPIX - ln._rPic->w, y),
 					Rect(x0 / GLI_SUBPIX, y0, x1 / GLI_SUBPIX, y1));
-				link = ln->_rHyper;
+				link = ln._rHyper;
 				hy0 = y > y0 ? y : y0;
-				hy1 = y + ln->_rPic->h < y1 ? y + ln->_rPic->h : y1;
-				hx0 = x1 / GLI_SUBPIX - ln->_rPic->w > x0 / GLI_SUBPIX
-					  ? x1 / GLI_SUBPIX - ln->_rPic->w
+				hy1 = y + ln._rPic->h < y1 ? y + ln._rPic->h : y1;
+				hx0 = x1 / GLI_SUBPIX - ln._rPic->w > x0 / GLI_SUBPIX
+					  ? x1 / GLI_SUBPIX - ln._rPic->w
 					  : x0 / GLI_SUBPIX;
 				hx1 = x1 / GLI_SUBPIX;
 				g_vm->_selection->putHyperlink(link, hx0, hy0, hx1, hy1);
@@ -1153,8 +1148,6 @@ void TextBufferWindow::redraw() {
 	// no more prompt means all text has been seen
 	if (!_moreRequest)
 		_lastSeen = 0;
-
-	delete ln;
 }
 
 int TextBufferWindow::acceptScroll(uint arg) {





More information about the Scummvm-git-logs mailing list