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

m_kiewitz at users.sourceforge.net m_kiewitz at users.sourceforge.net
Wed Nov 11 20:43:51 CET 2009


Revision: 45838
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45838&view=rev
Author:   m_kiewitz
Date:     2009-11-11 19:43:51 +0000 (Wed, 11 Nov 2009)

Log Message:
-----------
SCI/newgui: Almost done with menu support

Modified Paths:
--------------
    scummvm/trunk/engines/sci/gui/gui.cpp
    scummvm/trunk/engines/sci/gui/gui_gfx.cpp
    scummvm/trunk/engines/sci/gui/gui_gfx.h
    scummvm/trunk/engines/sci/gui/gui_menu.cpp
    scummvm/trunk/engines/sci/gui/gui_menu.h

Modified: scummvm/trunk/engines/sci/gui/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.cpp	2009-11-11 15:23:44 UTC (rev 45837)
+++ scummvm/trunk/engines/sci/gui/gui.cpp	2009-11-11 19:43:51 UTC (rev 45838)
@@ -296,12 +296,12 @@
 void SciGui::drawStatus(const char *text, int16 colorPen, int16 colorBack) {
 	GuiPort *oldPort = _gfx->SetPort(_gfx->_menuPort);
 
-	_gfx->FillRect(_gfx->_menuRect, 1, colorBack);
+	_gfx->FillRect(_gfx->_menuBarRect, 1, colorBack);
 	_gfx->PenColor(colorPen);
 	_gfx->MoveTo(0, 1);
 	_text->Draw_String(text);
 	if (_screen->_picNotValid == 0)
-		_gfx->BitsShow(_gfx->_menuRect);
+		_gfx->BitsShow(_gfx->_menuBarRect);
 	_gfx->SetPort(oldPort);
 }
 
@@ -310,7 +310,7 @@
 		GuiPort *oldPort = _gfx->SetPort(_gfx->_menuPort);
 		_menu->drawBar();
 		if (_screen->_picNotValid == 0)
-			_gfx->BitsShow(_gfx->_menuRect);
+			_gfx->BitsShow(_gfx->_menuBarRect);
 		_gfx->SetPort(oldPort);
 	} else {
 		drawStatus("", 0, 0);

Modified: scummvm/trunk/engines/sci/gui/gui_gfx.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.cpp	2009-11-11 15:23:44 UTC (rev 45837)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.cpp	2009-11-11 19:43:51 UTC (rev 45838)
@@ -65,7 +65,7 @@
 	OpenPort(_menuPort);
 	_text->SetFont(0);
 	_menuPort->rect = Common::Rect(0, 0, _screen->_width, _screen->_height);
-	_menuRect = Common::Rect(0, 0, _screen->_width, 9);
+	_menuBarRect = Common::Rect(0, 0, _screen->_width, 9);
 }
 
 void SciGuiGfx::purgeCache() {

Modified: scummvm/trunk/engines/sci/gui/gui_gfx.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.h	2009-11-11 15:23:44 UTC (rev 45837)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.h	2009-11-11 19:43:51 UTC (rev 45838)
@@ -100,7 +100,7 @@
 	void SetNowSeen(reg_t objectReference);
 
 	GuiPort *_menuPort;
-	Common::Rect _menuRect;
+	Common::Rect _menuBarRect;
 	GuiPort *_curPort;
 
 	SciGuiView *getView(GuiResourceId viewNum);

Modified: scummvm/trunk/engines/sci/gui/gui_menu.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_menu.cpp	2009-11-11 15:23:44 UTC (rev 45837)
+++ scummvm/trunk/engines/sci/gui/gui_menu.cpp	2009-11-11 19:43:51 UTC (rev 45838)
@@ -284,7 +284,7 @@
 	GuiMenuList::iterator listEnd = _list.end();
 
 	// Hardcoded black on white
-	_gfx->FillRect(_gfx->_menuRect, 1, _screen->_colorWhite);
+	_gfx->FillRect(_gfx->_menuBarRect, 1, _screen->_colorWhite);
 	_gfx->PenColor(0);
 	_gfx->MoveTo(8, 1);
 
@@ -319,6 +319,7 @@
 	while (itemIterator != itemEnd) {
 		itemEntry = *itemIterator;
 		_text->StringWidth(itemEntry->text.c_str(), 0, itemEntry->textWidth, dummyHeight);
+		_text->StringWidth(itemEntry->textRightAligned.c_str(), 0, itemEntry->textRightAlignedWidth, dummyHeight);
 
 		itemIterator++;
 	}
@@ -379,8 +380,12 @@
 
 	if (!_menuSaveHandle.isNull()) {
 		_gfx->BitsRestore(_menuSaveHandle);
-		_gfx->BitsShow(_gfx->_menuRect);
+		_gfx->BitsShow(_menuRect);
 	}
+	if (!_barSaveHandle.isNull()) {
+		_gfx->BitsRestore(_barSaveHandle);
+		_gfx->BitsShow(_gfx->_menuBarRect);
+	}
 	if (_oldPort)
 		_gfx->SetPort(_oldPort);
 
@@ -398,7 +403,10 @@
 	GuiMenuItemEntry *lastItemEntry = NULL;
 
 	// Fixup menuId if needed
-	menuId = CLIP<uint16>(menuId, 1, _listCount);
+	if (menuId > _listCount)
+		menuId = 1;
+	if (menuId == 0)
+		menuId = _listCount;
 	// Fixup itemId as well
 	if (itemId == 0)
 		itemId = 32678;
@@ -415,6 +423,79 @@
 	return lastItemEntry;
 }
 
+void SciGuiMenu::drawMenu(uint16 menuId) {
+	GuiMenuEntry *listEntry;
+	GuiMenuList::iterator listIterator;
+	GuiMenuList::iterator listEnd = _list.end();
+	GuiMenuItemEntry *listItemEntry;
+	GuiMenuItemList::iterator listItemIterator;
+	GuiMenuItemList::iterator listItemEnd = _itemList.end();
+	uint16 listNr = 0;
+	int16 maxTextWidth = 0, maxTextRightAlignedWidth = 0;
+	int16 topPos;
+
+	// Remove menu, if one is displayed
+	if (!_menuSaveHandle.isNull()) {
+		_gfx->BitsRestore(_menuSaveHandle);
+		_gfx->BitsShow(_menuRect);
+	}
+
+	// First calculate rect of menu
+	_menuRect.top = _gfx->_menuBarRect.bottom;
+	_menuRect.left = 7;
+	listIterator = _list.begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		listNr++;
+		if (listNr == menuId)
+			break;
+		_menuRect.left += listEntry->textWidth;
+
+		listIterator++;
+	}
+
+	_menuRect.bottom = _menuRect.top + 2;
+	listItemIterator = _itemList.begin();
+	while (listItemIterator != listItemEnd) {
+		listItemEntry = *listItemIterator;
+		if (listItemEntry->menuId == menuId) {
+			_menuRect.bottom += _gfx->_curPort->fontHeight;
+			maxTextWidth = MAX<int16>(maxTextWidth, listItemEntry->textWidth);
+			maxTextRightAlignedWidth = MAX<int16>(maxTextRightAlignedWidth, listItemEntry->textRightAlignedWidth);
+		}
+		listItemIterator++;
+	}
+	_menuRect.right = _menuRect.left + 16 + 4 + 2;
+	_menuRect.right += maxTextWidth + maxTextRightAlignedWidth;
+
+	// Save background
+	_menuSaveHandle = _gfx->BitsSave(_menuRect, SCI_SCREEN_MASK_VISUAL);
+
+	// Do the drawing
+	_gfx->FillRect(_menuRect, SCI_SCREEN_MASK_VISUAL, 0);
+	_menuRect.left++; _menuRect.right--; _menuRect.bottom--;
+	_gfx->FillRect(_menuRect, SCI_SCREEN_MASK_VISUAL, _screen->_colorWhite);
+
+	_menuRect.left += 8;
+	topPos = _menuRect.top + 1;
+	listItemIterator = _itemList.begin();
+	while (listItemIterator != listItemEnd) {
+		listItemEntry = *listItemIterator;
+		if (listItemEntry->menuId == menuId) {
+			_gfx->MoveTo(_menuRect.left, topPos);
+			_text->Draw_String(listItemEntry->text.c_str());
+			_gfx->MoveTo(_menuRect.right - listItemEntry->textRightAlignedWidth - 3, topPos);
+			_text->Draw_String(listItemEntry->textRightAligned.c_str());
+			topPos += _gfx->_curPort->fontHeight;
+		}
+		listItemIterator++;
+	}
+
+	_menuRect.left -= 8;
+	_menuRect.left--; _menuRect.right++; _menuRect.bottom++;
+	_gfx->BitsShow(_menuRect);
+}
+
 GuiMenuItemEntry *SciGuiMenu::interactiveWithKeyboard() {
 	sci_event_t curEvent;
 	uint16 newMenuId = _curMenuId;
@@ -424,11 +505,12 @@
 
 	calculateTextWidth();
 	_oldPort = _gfx->SetPort(_gfx->_menuPort);
-	_menuSaveHandle = _gfx->BitsSave(_gfx->_menuRect, SCI_SCREEN_MASK_VISUAL);
+	_barSaveHandle = _gfx->BitsSave(_gfx->_menuBarRect, SCI_SCREEN_MASK_VISUAL);
 	drawBar();
+	drawMenu(curItemEntry->menuId);
+	_gfx->BitsShow(_gfx->_menuBarRect);
+	_gfx->BitsShow(_menuRect);
 
-	_gfx->BitsShow(_gfx->_menuRect);
-
 	while (true) {
 		curEvent = gfxop_get_event(_gfxstate, SCI_EVT_ANY);
 
@@ -461,6 +543,7 @@
 
 				if (newMenuId != curItemEntry->menuId) {
 					// Menu changed, remove cur menu and paint new menu
+					drawMenu(newMenuId);
 				}
 
 				curItemEntry = newItemEntry;

Modified: scummvm/trunk/engines/sci/gui/gui_menu.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_menu.h	2009-11-11 15:23:44 UTC (rev 45837)
+++ scummvm/trunk/engines/sci/gui/gui_menu.h	2009-11-11 19:43:51 UTC (rev 45838)
@@ -66,10 +66,11 @@
 	reg_t textVmPtr;
 	int16 textWidth;
 	Common::String textRightAligned;
+	int16 textRightAlignedWidth;
 
 	GuiMenuItemEntry(uint16 curMenuId, uint16 curId)
 	 : menuId(curMenuId), id(curId),
-		enabled(true), tag(0), keyPress(0), keyModifier(0), separatorLine(false), textWidth(0) {
+		enabled(true), tag(0), keyPress(0), keyModifier(0), separatorLine(false), textWidth(0), textRightAlignedWidth(0) {
 		saidVmPtr = NULL_REG;
 		textVmPtr = NULL_REG;
 	}
@@ -92,6 +93,7 @@
 private:
 	GuiMenuItemEntry *findItem(uint16 menuId, uint16 itemId);
 	void calculateTextWidth();
+	void drawMenu(uint16 menuId);
 	GuiMenuItemEntry *interactiveWithKeyboard();
 	GuiMenuItemEntry *interactiveWithMouse();
 	GuiMenuItemEntry *interactiveGetItem(uint16 menuId, uint16 itemId);
@@ -111,7 +113,9 @@
 	uint16 _curItemId;
 
 	GuiPort *_oldPort;
+	GuiMemoryHandle _barSaveHandle;
 	GuiMemoryHandle _menuSaveHandle;
+	Common::Rect _menuRect;
 };
 
 } // End of namespace Sci


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