diff options
author | Martin Kiewitz | 2009-11-11 19:43:51 +0000 |
---|---|---|
committer | Martin Kiewitz | 2009-11-11 19:43:51 +0000 |
commit | 429d8be2dc86b93416adf387353a30e3c0bd97dd (patch) | |
tree | 45d5908aa04522d27d5af16834b44abb189643b2 /engines/sci/gui | |
parent | 1b3a3de946d0ba404b9666f16cfc46661512d66b (diff) | |
download | scummvm-rg350-429d8be2dc86b93416adf387353a30e3c0bd97dd.tar.gz scummvm-rg350-429d8be2dc86b93416adf387353a30e3c0bd97dd.tar.bz2 scummvm-rg350-429d8be2dc86b93416adf387353a30e3c0bd97dd.zip |
SCI/newgui: Almost done with menu support
svn-id: r45838
Diffstat (limited to 'engines/sci/gui')
-rw-r--r-- | engines/sci/gui/gui.cpp | 6 | ||||
-rw-r--r-- | engines/sci/gui/gui_gfx.cpp | 2 | ||||
-rw-r--r-- | engines/sci/gui/gui_gfx.h | 2 | ||||
-rw-r--r-- | engines/sci/gui/gui_menu.cpp | 95 | ||||
-rw-r--r-- | engines/sci/gui/gui_menu.h | 6 |
5 files changed, 99 insertions, 12 deletions
diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp index c6ca37427e..7b5769130c 100644 --- a/engines/sci/gui/gui.cpp +++ b/engines/sci/gui/gui.cpp @@ -296,12 +296,12 @@ void SciGui::textColors(int argc, reg_t *argv) { 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 @@ void SciGui::drawMenuBar(bool clear) { 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); diff --git a/engines/sci/gui/gui_gfx.cpp b/engines/sci/gui/gui_gfx.cpp index e30e61107e..ee144a5bf0 100644 --- a/engines/sci/gui/gui_gfx.cpp +++ b/engines/sci/gui/gui_gfx.cpp @@ -65,7 +65,7 @@ void SciGuiGfx::init(SciGuiText *text) { 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() { diff --git a/engines/sci/gui/gui_gfx.h b/engines/sci/gui/gui_gfx.h index 74334e5a39..587e6bff40 100644 --- a/engines/sci/gui/gui_gfx.h +++ b/engines/sci/gui/gui_gfx.h @@ -100,7 +100,7 @@ public: void SetNowSeen(reg_t objectReference); GuiPort *_menuPort; - Common::Rect _menuRect; + Common::Rect _menuBarRect; GuiPort *_curPort; SciGuiView *getView(GuiResourceId viewNum); diff --git a/engines/sci/gui/gui_menu.cpp b/engines/sci/gui/gui_menu.cpp index 5c204cbe2b..130c42f0d0 100644 --- a/engines/sci/gui/gui_menu.cpp +++ b/engines/sci/gui/gui_menu.cpp @@ -284,7 +284,7 @@ void SciGuiMenu::drawBar() { 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 @@ void SciGuiMenu::calculateTextWidth() { 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,7 +380,11 @@ reg_t SciGuiMenu::select(reg_t eventObject) { 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 *SciGuiMenu::interactiveGetItem(uint16 menuId, uint16 itemId) { 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 @@ GuiMenuItemEntry *SciGuiMenu::interactiveGetItem(uint16 menuId, uint16 itemId) { 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,10 +505,11 @@ GuiMenuItemEntry *SciGuiMenu::interactiveWithKeyboard() { 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(); - - _gfx->BitsShow(_gfx->_menuRect); + drawMenu(curItemEntry->menuId); + _gfx->BitsShow(_gfx->_menuBarRect); + _gfx->BitsShow(_menuRect); while (true) { curEvent = gfxop_get_event(_gfxstate, SCI_EVT_ANY); @@ -461,6 +543,7 @@ GuiMenuItemEntry *SciGuiMenu::interactiveWithKeyboard() { if (newMenuId != curItemEntry->menuId) { // Menu changed, remove cur menu and paint new menu + drawMenu(newMenuId); } curItemEntry = newItemEntry; diff --git a/engines/sci/gui/gui_menu.h b/engines/sci/gui/gui_menu.h index a3eb9e8443..66d0c3d7e0 100644 --- a/engines/sci/gui/gui_menu.h +++ b/engines/sci/gui/gui_menu.h @@ -66,10 +66,11 @@ struct GuiMenuItemEntry { 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 @@ public: 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 @@ private: uint16 _curItemId; GuiPort *_oldPort; + GuiMemoryHandle _barSaveHandle; GuiMemoryHandle _menuSaveHandle; + Common::Rect _menuRect; }; } // End of namespace Sci |