diff options
| author | Martin Kiewitz | 2009-11-04 21:03:57 +0000 | 
|---|---|---|
| committer | Martin Kiewitz | 2009-11-04 21:03:57 +0000 | 
| commit | 14447f7e017170913981a36407531f4f4b938ab4 (patch) | |
| tree | 6dd4868c1e6569a806d7d54854edd4ac7ff88441 | |
| parent | c975c288eedbe4f2e0fea320148e3318aed57c97 (diff) | |
| download | scummvm-rg350-14447f7e017170913981a36407531f4f4b938ab4.tar.gz scummvm-rg350-14447f7e017170913981a36407531f4f4b938ab4.tar.bz2 scummvm-rg350-14447f7e017170913981a36407531f4f4b938ab4.zip  | |
SCI/newgui: select() implemented (interactive modes not done yet)
svn-id: r45674
| -rw-r--r-- | engines/sci/gui/gui.cpp | 2 | ||||
| -rw-r--r-- | engines/sci/gui/gui_menu.cpp | 86 | ||||
| -rw-r--r-- | engines/sci/gui/gui_menu.h | 12 | 
3 files changed, 93 insertions, 7 deletions
diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp index cb8674f53a..46deb21a7f 100644 --- a/engines/sci/gui/gui.cpp +++ b/engines/sci/gui/gui.cpp @@ -62,7 +62,7 @@ SciGui::SciGui(EngineState *state, SciGuiScreen *screen, SciGuiPalette *palette,  	_text = new SciGuiText(_s->resMan, _gfx, _screen);  	_windowMgr = new SciGuiWindowMgr(this, _screen, _gfx, _text);  	_controls = new SciGuiControls(_s->_segMan, _gfx, _text); -	_menu = new SciGuiMenu(_s->_segMan, _gfx, _text, _screen); +	_menu = new SciGuiMenu(_s->_segMan, _gfx, _text, _screen, _cursor);  //  	_gui32 = new SciGui32(_s, _screen, _palette, _cursor); // for debug purposes  } diff --git a/engines/sci/gui/gui_menu.cpp b/engines/sci/gui/gui_menu.cpp index 9462522c0c..e1de704b1d 100644 --- a/engines/sci/gui/gui_menu.cpp +++ b/engines/sci/gui/gui_menu.cpp @@ -30,6 +30,7 @@  #include "sci/sci.h"  #include "sci/engine/state.h"  #include "sci/gui/gui_gfx.h" +#include "sci/gui/gui_cursor.h"  #include "sci/gui/gui_font.h"  #include "sci/gui/gui_text.h"  #include "sci/gui/gui_screen.h" @@ -37,8 +38,8 @@  namespace Sci { -SciGuiMenu::SciGuiMenu(SegManager *segMan, SciGuiGfx *gfx, SciGuiText *text, SciGuiScreen *screen) -	: _segMan(segMan), _gfx(gfx), _text(text), _screen(screen) { +SciGuiMenu::SciGuiMenu(SegManager *segMan, SciGuiGfx *gfx, SciGuiText *text, SciGuiScreen *screen, SciGuiCursor *cursor) +	: _segMan(segMan), _gfx(gfx), _text(text), _screen(screen), _cursor(cursor) {  	_listCount = 0;  } @@ -225,7 +226,7 @@ void SciGuiMenu::setAttribute(uint16 menuId, uint16 itemId, uint16 attributeId,  		itemEntry->textVmPtr = value;  		break;  	case SCI_MENU_ATTRIBUTE_KEYPRESS: -		itemEntry->keyPress = value.offset; +		itemEntry->keyPress = tolower(value.offset);  		itemEntry->keyModifier = 0;  		// TODO: Find out how modifier is handled  		printf("setAttr keypress %X %X\n", value.segment, value.offset); @@ -282,7 +283,86 @@ void SciGuiMenu::drawBar() {  	_gfx->BitsShow(_gfx->_menuRect);  } +void SciGuiMenu::calculateTextWidth() { +	GuiMenuList::iterator menuIterator; +	GuiMenuList::iterator menuEnd = _list.end(); +	GuiMenuEntry *menuEntry; +	GuiMenuItemList::iterator itemIterator; +	GuiMenuItemList::iterator itemEnd = _itemList.end(); +	GuiMenuItemEntry *itemEntry; +	int16 dummyHeight; + +	menuIterator = _list.begin(); +	while (menuIterator != menuEnd) { +		menuEntry = *menuIterator; +		_text->StringWidth(menuEntry->text.c_str(), 0, menuEntry->textWidth, dummyHeight); + +		menuIterator++; +	} + +	itemIterator = _itemList.begin(); +	while (itemIterator != itemEnd) { +		itemEntry = *itemIterator; +		_text->StringWidth(itemEntry->text.c_str(), 0, itemEntry->textWidth, dummyHeight); + +		itemIterator++; +	} +} + +GuiMenuItemEntry *SciGuiMenu::interactiveWithKeyboard() { +	calculateTextWidth(); + +	return NULL; +} + +GuiMenuItemEntry *SciGuiMenu::interactiveWithMouse() { +	calculateTextWidth(); + +	return NULL; +} +  reg_t SciGuiMenu::select(reg_t eventObject) { +	int16 eventType = GET_SEL32V(_segMan, eventObject, type); +	int16 keyPress = GET_SEL32V(_segMan, eventObject, message); +	int16 keyModifier = GET_SEL32V(_segMan, eventObject, modifiers); +	Common::Point mousePosition; +	GuiMenuItemList::iterator itemIterator = _itemList.begin(); +	GuiMenuItemList::iterator itemEnd = _itemList.end(); +	GuiMenuItemEntry *itemEntry = NULL; +	bool forceClaimed = false; + +	switch (eventType) { +	case SCI_EVT_KEYBOARD: +		if (keyPress == SCI_K_ESC) { +			itemEntry = interactiveWithKeyboard(); +			forceClaimed = true; +		} else if (keyPress) { +			while (itemIterator != itemEnd) { +				itemEntry = *itemIterator; +				if ((itemEntry->keyPress == keyPress) && (itemEntry->keyModifier == keyModifier)) +					break; +				itemIterator++; +			} +			if (itemIterator == itemEnd) +				itemEntry = NULL; +		} +		break; +	case SCI_EVT_SAID: +		break; +	case SCI_EVT_MOUSE_PRESS: +		mousePosition = _cursor->getPosition(); +		if (mousePosition.y < 10) { +			itemEntry = interactiveWithMouse(); +			forceClaimed = true; +		} +		break; +	} + +	if ((itemEntry) || (forceClaimed)) { +		PUT_SEL32(_segMan, eventObject, claimed, make_reg(0, 1)); +	} +	if (itemEntry) +		return make_reg(0, (itemEntry->menuId << 8) | (itemEntry->id));  	return NULL_REG;  } diff --git a/engines/sci/gui/gui_menu.h b/engines/sci/gui/gui_menu.h index 8953a1f7c8..6cd072fd35 100644 --- a/engines/sci/gui/gui_menu.h +++ b/engines/sci/gui/gui_menu.h @@ -45,9 +45,10 @@ enum {  struct GuiMenuEntry {  	uint16 id;  	Common::String text; +	int16 textWidth;  	GuiMenuEntry(uint16 curId) -	 : id(curId) { } +	 : id(curId), textWidth(0) { }  };  typedef Common::List<GuiMenuEntry *> GuiMenuList; @@ -63,11 +64,12 @@ struct GuiMenuItemEntry {  	reg_t saidVmPtr;  	Common::String text;  	reg_t textVmPtr; +	int16 textWidth;  	Common::String textRightAligned;  	GuiMenuItemEntry(uint16 curMenuId, uint16 curId)  	 : menuId(curMenuId), id(curId), -		enabled(true), tag(0), keyPress(0), keyModifier(0), separatorLine(false) { +		enabled(true), tag(0), keyPress(0), keyModifier(0), separatorLine(false), textWidth(0) {  		saidVmPtr = NULL_REG;  		textVmPtr = NULL_REG;  	} @@ -76,7 +78,7 @@ typedef Common::List<GuiMenuItemEntry *> GuiMenuItemList;  class SciGuiMenu {  public: -	SciGuiMenu(SegManager *segMan, SciGuiGfx *gfx, SciGuiText *text, SciGuiScreen *screen); +	SciGuiMenu(SegManager *segMan, SciGuiGfx *gfx, SciGuiText *text, SciGuiScreen *screen, SciGuiCursor *cursor);  	~SciGuiMenu();  	void add(Common::String title, Common::String content, reg_t contentVmPtr); @@ -88,11 +90,15 @@ public:  private:  	GuiMenuItemEntry *findItem(uint16 menuId, uint16 itemId); +	void calculateTextWidth(); +	GuiMenuItemEntry *interactiveWithKeyboard(); +	GuiMenuItemEntry *interactiveWithMouse();  	SegManager *_segMan;  	SciGuiGfx *_gfx;  	SciGuiText *_text;  	SciGuiScreen *_screen; +	SciGuiCursor *_cursor;  	uint16 _listCount;  	GuiMenuList _list;  | 
