[Scummvm-cvs-logs] SF.net SVN: scummvm:[45224] scummvm/trunk/engines/sci

m_kiewitz at users.sourceforge.net m_kiewitz at users.sourceforge.net
Sun Oct 18 17:38:49 CEST 2009


Revision: 45224
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45224&view=rev
Author:   m_kiewitz
Date:     2009-10-18 15:38:49 +0000 (Sun, 18 Oct 2009)

Log Message:
-----------
SCI: cleanup text alignment

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/gui/gui.cpp
    scummvm/trunk/engines/sci/gui/gui.h
    scummvm/trunk/engines/sci/gui/gui_gfx.cpp
    scummvm/trunk/engines/sci/gui/gui_gfx.h
    scummvm/trunk/engines/sci/gui/gui_helpers.h
    scummvm/trunk/engines/sci/gui/gui_windowmgr.cpp
    scummvm/trunk/engines/sci/gui32/gui32.cpp
    scummvm/trunk/engines/sci/gui32/gui32.h

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-10-18 15:38:49 UTC (rev 45224)
@@ -670,6 +670,7 @@
 	reg_t textReference = GET_SEL32(controlObject, text);
 	Common::String text;
 	Common::Rect rect;
+	GuiTextAlignment alignment;
 	int16 mode, maxChars, cursorPos, upperPos, listCount, i;
 	int16 upperOffset, cursorOffset;
 	GuiResourceId viewId;
@@ -692,9 +693,9 @@
 		return;
 
 	case SCI_CONTROLS_TYPE_TEXT:
-		mode = GET_SEL32V(controlObject, mode);
-		debugC(2, kDebugLevelGraphics, "drawing text %04x:%04x ('%s') to %d,%d, mode=%d\n", PRINT_REG(controlObject), text.c_str(), x, y, mode);
-		s->_gui->drawControlText(rect, controlObject, s->strSplit(text.c_str(), NULL).c_str(), fontId, mode, style, hilite);
+		alignment = GET_SEL32V(controlObject, mode);
+		debugC(2, kDebugLevelGraphics, "drawing text %04x:%04x ('%s') to %d,%d, mode=%d\n", PRINT_REG(controlObject), text.c_str(), x, y, alignment);
+		s->_gui->drawControlText(rect, controlObject, s->strSplit(text.c_str(), NULL).c_str(), fontId, alignment, style, hilite);
 		return;
 
 	case SCI_CONTROLS_TYPE_TEXTEDIT:

Modified: scummvm/trunk/engines/sci/gui/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.cpp	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui/gui.cpp	2009-10-18 15:38:49 UTC (rev 45224)
@@ -174,7 +174,7 @@
 
 void SciGui::display(const char *text, int argc, reg_t *argv) {
 	int displayArg;
-	int16 align = 0;
+	GuiTextAlignment alignment = SCI_TEXT_ALIGNMENT_LEFT;
 	int16 bgcolor = -1, width = -1, bRedraw = 1;
 	bool doSaveUnder = false;
 	Common::Rect rect, *orect = &((GuiWindow *)_gfx->GetPort())->dims;
@@ -196,7 +196,7 @@
 			argc -= 2; argv += 2;
 			break;
 		case SCI_DISPLAY_SETALIGNMENT:
-			align = argv[0].toUint16();
+			alignment = argv[0].toSint16();
 			argc--; argv++;
 			break;
 		case SCI_DISPLAY_SETPENCOLOR:
@@ -247,7 +247,7 @@
 		_s->r_acc = _gfx->BitsSave(rect, SCI_SCREEN_MASK_VISUAL);
 	if (bgcolor != -1)
 		_gfx->FillRect(rect, SCI_SCREEN_MASK_VISUAL, bgcolor, 0, 0);
-	_gfx->TextBox(text, 0, rect, align, -1);
+	_gfx->TextBox(text, 0, rect, alignment, -1);
 	if (_screen->_picNotValid == 0 && bRedraw)
 		_gfx->BitsShow(rect);
 	// restoring port and cursor pos
@@ -321,7 +321,7 @@
 		_gfx->FrameRect(rect);
 		rect.grow(-2);
 		_gfx->TextFace(style & 1 ? 0 : 1);
-		_gfx->TextBox(text, 0, rect, 1, fontId);
+		_gfx->TextBox(text, 0, rect, SCI_TEXT_ALIGNMENT_CENTER, fontId);
 		_gfx->TextFace(0);
 		rect.grow(1);
 		if (style & 8) // selected
@@ -336,12 +336,12 @@
 	}
 }
 
-void SciGui::drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, bool hilite) {
+void SciGui::drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, GuiTextAlignment alignment, int16 style, bool hilite) {
 	if (!hilite) {
 		rect.grow(1);
 		_gfx->EraseRect(rect);
 		rect.grow(-1);
-		_gfx->TextBox(text, 0, rect, mode, fontId);
+		_gfx->TextBox(text, 0, rect, alignment, fontId);
 		if (style & 8) { // selected
 			_gfx->FrameRect(rect);
 		}
@@ -362,7 +362,7 @@
 	rect.grow(1);
 	_gfx->TexteditCursorErase();
 	_gfx->EraseRect(rect);
-	_gfx->TextBox(text, 0, textRect, 0, fontId);
+	_gfx->TextBox(text, 0, textRect, SCI_TEXT_ALIGNMENT_LEFT, fontId);
 	_gfx->FrameRect(rect);
 	if (style & 8) {
 		_gfx->SetFont(fontId);

Modified: scummvm/trunk/engines/sci/gui/gui.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.h	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui/gui.h	2009-10-18 15:38:49 UTC (rev 45224)
@@ -83,7 +83,7 @@
 	virtual void drawPicture(GuiResourceId pictureId, int16 animationNr, bool animationBlackoutFlag, bool mirroredFlag, bool addToFlag, int16 EGApaletteNo);
 	virtual void drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, uint16 leftPos, uint16 topPos, int16 priority, uint16 paletteNo);
 	virtual void drawControlButton(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 style, bool hilite);
-	virtual void drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, bool hilite);
+	virtual void drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 alignment, int16 style, bool hilite);
 	virtual void drawControlTextEdit(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, int16 cursorPos, int16 maxChars, bool hilite);
 	virtual void drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 style, bool hilite);
 	virtual void drawControlList(Common::Rect rect, reg_t obj, int16 maxChars, int16 count, const char **entries, GuiResourceId fontId, int16 style, int16 upperPos, int16 cursorPos, bool isAlias, bool hilite);

Modified: scummvm/trunk/engines/sci/gui/gui_gfx.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.cpp	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.cpp	2009-10-18 15:38:49 UTC (rev 45224)
@@ -545,7 +545,7 @@
 }
 
 // Draws a text in rect.
-void SciGuiGfx::TextBox(const char *text, int16 bshow, const Common::Rect &rect, int16 align, GuiResourceId fontId) {
+void SciGuiGfx::TextBox(const char *text, int16 bshow, const Common::Rect &rect, GuiTextAlignment alignment, GuiResourceId fontId) {
 	int16 textWidth, textHeight, charCount, offset;
 	int16 hline = 0;
 	GuiResourceId orgFontId = GetFontId();
@@ -563,15 +563,19 @@
 		if (charCount == 0)
 			break;
 		TextWidth(text, 0, charCount, orgFontId, textWidth, textHeight);
-		switch (align) {
-		case -1: // right-aligned
+		switch (alignment) {
+		case SCI_TEXT_ALIGNMENT_RIGHT:
 			offset = rect.width() - textWidth;
 			break;
-		case 1: // center text
+		case SCI_TEXT_ALIGNMENT_CENTER:
 			offset = (rect.width() - textWidth) / 2;
 			break;
+		case SCI_TEXT_ALIGNMENT_LEFT:
+			offset = 0;
+			break;
+
 		default: // left-aligned
-			offset = 0;
+			warning("Invalid alignment %d used in TextBox()", alignment);
 		}
 		MoveTo(rect.left + offset, rect.top + hline);
 
@@ -754,9 +758,9 @@
 
 	// draw UP/DOWN arrows
 	workerRect.top++;
-	TextBox(controlListUpArrow, 0, workerRect, 1, 0);
+	TextBox(controlListUpArrow, 0, workerRect, SCI_TEXT_ALIGNMENT_CENTER, 0);
 	workerRect.top = workerRect.bottom - 10;
-	TextBox(controlListDownArrow, 0, workerRect, 1, 0);
+	TextBox(controlListDownArrow, 0, workerRect, SCI_TEXT_ALIGNMENT_CENTER, 0);
 
 	// Draw inner lines
 	workerRect.top = rect.top + 9;
@@ -891,7 +895,7 @@
 		rect.top++;
 		TexteditCursorErase();
 		EraseRect(rect);
-		TextBox(text.c_str(), 0, rect, 0, fontId);
+		TextBox(text.c_str(), 0, rect, SCI_TEXT_ALIGNMENT_LEFT, fontId);
 		BitsShow(rect);
 		SetFont(fontId);
 		rect.top--;

Modified: scummvm/trunk/engines/sci/gui/gui_gfx.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.h	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.h	2009-10-18 15:38:49 UTC (rev 45224)
@@ -30,6 +30,10 @@
 
 namespace Sci {
 
+#define SCI_TEXT_ALIGNMENT_RIGHT -1
+#define SCI_TEXT_ALIGNMENT_CENTER 1
+#define SCI_TEXT_ALIGNMENT_LEFT	0
+
 class SciGuiScreen;
 class SciGuiPalette;
 class SciGuiFont;
@@ -87,7 +91,7 @@
 	void DrawString(const char *str, GuiResourceId orgFontId, int16 orgPenColor) {
 		DrawText(str, 0, (int16)strlen(str), orgFontId, orgPenColor);
 	}
-	void TextBox(const char *str, int16 bshow, const Common::Rect &rect, int16 align, GuiResourceId fontId);
+	void TextBox(const char *str, int16 bshow, const Common::Rect &rect, GuiTextAlignment alignment, GuiResourceId fontId);
 	void BitsShow(const Common::Rect &r);
 	GuiMemoryHandle BitsSave(const Common::Rect &rect, byte screenFlags);
 	void BitsGetRect(GuiMemoryHandle memoryHandle, Common::Rect *destRect);

Modified: scummvm/trunk/engines/sci/gui/gui_helpers.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_helpers.h	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui/gui_helpers.h	2009-10-18 15:38:49 UTC (rev 45224)
@@ -40,6 +40,8 @@
 typedef int16 GuiViewLoopNo;
 typedef int16 GuiViewCelNo;
 
+typedef int16 GuiTextAlignment;
+
 struct GuiPort {
 	uint16 id;
 	int16 top, left;

Modified: scummvm/trunk/engines/sci/gui/gui_windowmgr.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_windowmgr.cpp	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui/gui_windowmgr.cpp	2009-10-18 15:38:49 UTC (rev 45224)
@@ -223,7 +223,7 @@
 				if (!pWnd->title.empty()) {
 					int16 oldcolor = _gfx->GetPort()->penClr;
 					_gfx->PenColor(255);
-					_gfx->TextBox(pWnd->title.c_str(), 1, r, 1, 0);
+					_gfx->TextBox(pWnd->title.c_str(), 1, r, SCI_TEXT_ALIGNMENT_CENTER, 0);
 					_gfx->PenColor(oldcolor);
 				}
 				

Modified: scummvm/trunk/engines/sci/gui32/gui32.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui32/gui32.cpp	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui32/gui32.cpp	2009-10-18 15:38:49 UTC (rev 45224)
@@ -965,10 +965,10 @@
 	if (!_s->pic_not_valid) FULL_REDRAW();
 }
 
-void SciGui32::drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, bool hilite) {
+void SciGui32::drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 alignment, int16 style, bool hilite) {
 	rect_t area = gfx_rect(rect.left, rect.top, rect.width(), rect.height());
 
-	ADD_TO_CURRENT_PICTURE_PORT(sciw_new_text_control(_s->port, obj, area, text, fontId, (gfx_alignment_t) mode,
+	ADD_TO_CURRENT_PICTURE_PORT(sciw_new_text_control(_s->port, obj, area, text, fontId, (gfx_alignment_t) alignment,
 								(int8)(!!(style & kControlStateDitherFramed)), (int8)hilite));
 	if (!_s->pic_not_valid) FULL_REDRAW();
 }

Modified: scummvm/trunk/engines/sci/gui32/gui32.h
===================================================================
--- scummvm/trunk/engines/sci/gui32/gui32.h	2009-10-18 14:35:36 UTC (rev 45223)
+++ scummvm/trunk/engines/sci/gui32/gui32.h	2009-10-18 15:38:49 UTC (rev 45224)
@@ -61,7 +61,7 @@
 	void drawPicture(GuiResourceId pictureId, int16 animationNr, bool animationBlackoutFlag, bool mirroredFlag, bool addToFlag, int16 EGApaletteNo);
 	void drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, uint16 leftPos, uint16 topPos, int16 priority, uint16 paletteNo);
 	void drawControlButton(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 style, bool hilite);
-	void drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, bool hilite);
+	void drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 alignment, int16 style, bool hilite);
 	void drawControlTextEdit(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, int16 cursorPos, int16 maxChars, bool hilite);
 	void drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo, int16 style, bool hilite);
 	void drawControlList(Common::Rect rect, reg_t obj, int16 maxChars, int16 count, const char **entries, GuiResourceId fontId, int16 style, int16 upperPos, int16 cursorPos, bool isAlias, bool hilite);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list