[Scummvm-git-logs] scummvm master -> 88b9dd3472883de36acd4d6fdc7fd6d097328808

sev- sev at scummvm.org
Tue Dec 20 21:49:36 CET 2016


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

Summary:
16b0cde5fb GRAPHICS: Implemented partial MacText drawing
2d6c582805 GRAPHICS: Implement surface reallocation in MacText
88b9dd3472 GRAPHICS: Simplify MacText


Commit: 16b0cde5fba7b16ff412710942e95ca91f87cecb
    https://github.com/scummvm/scummvm/commit/16b0cde5fba7b16ff412710942e95ca91f87cecb
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-12-20T21:49:29+01:00

Commit Message:
GRAPHICS: Implemented partial MacText drawing

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 2dc1fc8..389fca4 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -74,12 +74,12 @@ void MacText::splitString(Common::String &str) {
 }
 
 void MacText::reallocSurface() {
-	int lineHeight = _font->getFontHeight() + _interLinear;
-	int requiredHeight = (_text.size() + (_text.size() * 10 + 9) / 10) * lineHeight;
+	int lineH = _font->getFontHeight() + _interLinear;
+	int requiredH = (_text.size() + (_text.size() * 10 + 9) / 10) * lineH;
 
-	if (_surface.w < requiredHeight) {
+	if (_surface.w < requiredH) {
 		// realloc surface
-		_surface.create(_maxWidth == -1 ? _textMaxWidth : _maxWidth, requiredHeight);
+		_surface.create(_maxWidth == -1 ? _textMaxWidth : _maxWidth, requiredH);
 	}
 }
 
@@ -89,16 +89,28 @@ void MacText::render() {
 
 		_surface.clear(_bgcolor);
 
-		int y = 0;
+		render(0, _text.size());
 
-		for (uint i = 0; i < _text.size(); i++) {
-			_font->drawString(&_surface, _text[i], 0, y, _textMaxWidth, _fgcolor);
+		_fullRefresh = false;
+	}
+}
 
-			y += _font->getFontHeight() + _interLinear;
-		}
+void MacText::render(int from, int to) {
+	from = MAX<int>(0, from);
+	to = MIN<int>(to, _text.size());
 
-		_fullRefresh = false;
+	int lineH = _font->getFontHeight() + _interLinear;
+	int y = from * lineH;
+
+	// Clear the screen
+	_surface.fillRect(Common::Rect(0, y, _surface.w, to * lineH), _bgcolor);
+
+	for (uint i = from; i < to; i++) {
+		_font->drawString(&_surface, _text[i], 0, y, _textMaxWidth, _fgcolor);
+
+		y += _font->getFontHeight() + _interLinear;
 	}
+
 }
 
 void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) {
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 65e93ca..a133c5c 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -41,6 +41,7 @@ public:
 private:
 	void splitString(Common::String &s);
 	void render();
+	void render(int from, int to);
 	void calcMaxWidth();
 	void reallocSurface();
 


Commit: 2d6c582805105f78901d7f88a77510a79e3b65a1
    https://github.com/scummvm/scummvm/commit/2d6c582805105f78901d7f88a77510a79e3b65a1
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-12-20T21:49:29+01:00

Commit Message:
GRAPHICS: Implement surface reallocation in MacText

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 389fca4..412ddae 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -30,6 +30,7 @@ MacText::MacText(Common::String s, Graphics::Font *font, int fgcolor, int bgcolo
 	_fgcolor = fgcolor;
 	_bgcolor = bgcolor;
 	_maxWidth = maxWidth;
+	_surface = nullptr;
 
 	_interLinear = 0; // 0 pixels between the lines by default
 
@@ -75,11 +76,23 @@ void MacText::splitString(Common::String &str) {
 
 void MacText::reallocSurface() {
 	int lineH = _font->getFontHeight() + _interLinear;
+	// round to closest 10
 	int requiredH = (_text.size() + (_text.size() * 10 + 9) / 10) * lineH;
+	int surfW = _maxWidth == -1 ? _textMaxWidth : _maxWidth;
 
-	if (_surface.w < requiredH) {
-		// realloc surface
-		_surface.create(_maxWidth == -1 ? _textMaxWidth : _maxWidth, requiredH);
+	if (!_surface) {
+		_surface = new ManagedSurface(surfW, requiredH);
+
+		return;
+	}
+
+	if (_surface->h < requiredH) {
+		// realloc surface and copy old content
+		ManagedSurface *n = new ManagedSurface(surfW, requiredH);
+		n->blitFrom(*_surface, Common::Point(0, 0));
+
+		delete _surface;
+		_surface = n;
 	}
 }
 
@@ -87,7 +100,7 @@ void MacText::render() {
 	if (_fullRefresh) {
 		reallocSurface();
 
-		_surface.clear(_bgcolor);
+		_surface->clear(_bgcolor);
 
 		render(0, _text.size());
 
@@ -103,10 +116,10 @@ void MacText::render(int from, int to) {
 	int y = from * lineH;
 
 	// Clear the screen
-	_surface.fillRect(Common::Rect(0, y, _surface.w, to * lineH), _bgcolor);
+	_surface->fillRect(Common::Rect(0, y, _surface->w, to * lineH), _bgcolor);
 
 	for (uint i = from; i < to; i++) {
-		_font->drawString(&_surface, _text[i], 0, y, _textMaxWidth, _fgcolor);
+		_font->drawString(_surface, _text[i], 0, y, _textMaxWidth, _fgcolor);
 
 		y += _font->getFontHeight() + _interLinear;
 	}
@@ -116,22 +129,22 @@ void MacText::render(int from, int to) {
 void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) {
 	render();
 
-	if (x + w < _surface.w || y + h < _surface.h) {
+	if (x + w < _surface->w || y + h < _surface->h) {
 		g->fillRect(Common::Rect(x, y, x + w, y + w), _bgcolor);
 	}
 
-	g->blitFrom(_surface, Common::Rect(MIN<int>(_surface.w, x), MIN<int>(_surface.h, y),
-									   MIN<int>(_surface.w, x + w), MIN<int>(_surface.w, y + w)), Common::Point(xoff, yoff));
+	g->blitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y),
+									   MIN<int>(_surface->w, x + w), MIN<int>(_surface->w, y + w)), Common::Point(xoff, yoff));
 }
 
 void MacText::appendText(Common::String str) {
-	//int oldLen = _text.size();
+	int oldLen = _text.size();
 
 	splitString(str);
 
 	reallocSurface();
 
-	//render(oldLen + 1, _text.size());
+	render(oldLen + 1, _text.size());
 }
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index a133c5c..37fc125 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -57,7 +57,7 @@ private:
 
 	int _textMaxWidth;
 
-	Graphics::ManagedSurface _surface;
+	Graphics::ManagedSurface *_surface;
 	bool _fullRefresh;
 };
 


Commit: 88b9dd3472883de36acd4d6fdc7fd6d097328808
    https://github.com/scummvm/scummvm/commit/88b9dd3472883de36acd4d6fdc7fd6d097328808
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-12-20T21:49:29+01:00

Commit Message:
GRAPHICS: Simplify MacText

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 412ddae..2af31a9 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -70,7 +70,7 @@ void MacText::splitString(Common::String &str) {
 		tmp += *s;
 	}
 
-	if (_text.size())
+	if (tmp.size())
 		_maxWidth = MIN(_font->wordWrapText(tmp, _maxWidth, _text), _maxWidth);
 }
 
@@ -98,10 +98,6 @@ void MacText::reallocSurface() {
 
 void MacText::render() {
 	if (_fullRefresh) {
-		reallocSurface();
-
-		_surface->clear(_bgcolor);
-
 		render(0, _text.size());
 
 		_fullRefresh = false;
@@ -109,6 +105,8 @@ void MacText::render() {
 }
 
 void MacText::render(int from, int to) {
+	reallocSurface();
+
 	from = MAX<int>(0, from);
 	to = MIN<int>(to, _text.size());
 
@@ -133,8 +131,9 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
 		g->fillRect(Common::Rect(x, y, x + w, y + w), _bgcolor);
 	}
 
-	g->blitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y),
-									   MIN<int>(_surface->w, x + w), MIN<int>(_surface->w, y + w)), Common::Point(xoff, yoff));
+	g->blitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x),     MIN<int>(_surface->h, y),
+									    MIN<int>(_surface->w, x + w), MIN<int>(_surface->w, y + w)),
+										Common::Point(xoff, yoff));
 }
 
 void MacText::appendText(Common::String str) {
@@ -142,8 +141,6 @@ void MacText::appendText(Common::String str) {
 
 	splitString(str);
 
-	reallocSurface();
-
 	render(oldLen + 1, _text.size());
 }
 





More information about the Scummvm-git-logs mailing list