diff options
| -rw-r--r-- | engines/macventure/dialog.cpp | 253 | ||||
| -rw-r--r-- | engines/macventure/dialog.h | 79 | ||||
| -rw-r--r-- | engines/macventure/prebuilt_dialogs.cpp | 65 | ||||
| -rw-r--r-- | engines/macventure/prebuilt_dialogs.h | 50 | 
4 files changed, 223 insertions, 224 deletions
diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 7cbf0cb610..0edec40c4d 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -27,216 +27,215 @@ namespace MacVenture {  Dialog::Dialog(Gui *gui, Common::Point pos, uint width, uint height) : -  _gui(gui), _bounds(Common::Rect(pos.x, pos.y, pos.x + width, pos.y + height)) {} +	_gui(gui), _bounds(Common::Rect(pos.x, pos.y, pos.x + width, pos.y + height)) {}  Dialog::Dialog(Gui *gui, PrebuiltDialogs prebuilt) { -  _gui = gui; -  const PrebuiltDialog &dialog = prebuiltDialogs[prebuilt]; -  _bounds = dialog.bounds; -  for (int i = 0; dialog.elements[i].type != kDEEnd; i++) { -    addPrebuiltElement(dialog.elements[i]); -  } +	_gui = gui; +	const PrebuiltDialog &dialog = prebuiltDialogs[prebuilt]; +	_bounds = dialog.bounds; +	for (int i = 0; dialog.elements[i].type != kDEEnd; i++) { +		addPrebuiltElement(dialog.elements[i]); +	}  }  Dialog::~Dialog() { -  for (Common::Array<DialogElement*>::iterator it = _elements.begin(); it != _elements.end(); it++) { -    delete *it; -  } +	for (Common::Array<DialogElement*>::iterator it = _elements.begin(); it != _elements.end(); it++) { +		delete *it; +	}  }  void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) {  	switch(action) { - 		case kDACloseDialog: -			_gui->closeDialog(); -			break; - 		case kDASubmit: -			_gui->setTextInput(_userInput); -			_gui->closeDialog(); -			break; -		case kDASaveAs: -			_gui->saveGame(); -			_gui->closeDialog(); -			break; -		case kDALoadGame: -			_gui->loadGame(); -			_gui->closeDialog(); -			break; -		case kDANewGame: -			_gui->newGame(); -			_gui->closeDialog(); -			break; -		case kDAQuit: -			_gui->quitGame(); -			_gui->closeDialog(); -			break; +		case kDACloseDialog: +		_gui->closeDialog(); +		break; +		case kDASubmit: +		_gui->setTextInput(_userInput); +		_gui->closeDialog(); +		break; +	case kDASaveAs: +		_gui->saveGame(); +		_gui->closeDialog(); +		break; +	case kDALoadGame: +		_gui->loadGame(); +		_gui->closeDialog(); +		break; +	case kDANewGame: +		_gui->newGame(); +		_gui->closeDialog(); +		break; +	case kDAQuit: +		_gui->quitGame(); +		_gui->closeDialog(); +		break; +	default: +		break;    }  }  const Graphics::Font& Dialog::getFont() { -  return _gui->getCurrentFont(); +	return _gui->getCurrentFont();  }  bool Dialog::processEvent(Common::Event event) { -  for (Common::Array<DialogElement*>::iterator it = _elements.begin(); it != _elements.end(); it++) { -    if ((*it)->processEvent(this, event)) return true; -  } +	for (Common::Array<DialogElement*>::iterator it = _elements.begin(); it != _elements.end(); it++) { +		if ((*it)->processEvent(this, event)) return true; +	}  }  void Dialog::addButton(Common::String title, MacVenture::DialogAction action, Common::Point position, uint width, uint height)  { -  _elements.push_back(new DialogButton(this, title, action, position, width, height)); +	_elements.push_back(new DialogButton(this, title, action, position, width, height));  }  void Dialog::addText(Common::String content, Common::Point position)  { -  _elements.push_back(new DialogPlainText(this, content, position)); +	_elements.push_back(new DialogPlainText(this, content, position));  }  void Dialog::addTextInput(Common::Point position, int width, int height) { -  _elements.push_back(new DialogTextInput(this, position, width, height)); +	_elements.push_back(new DialogTextInput(this, position, width, height));  }  void Dialog::draw()  { -  Graphics::ManagedSurface compose; -  // Compose the surface -  compose.create(_bounds.width(), _bounds.height()); -  Common::Rect base(0, 0, _bounds.width(), _bounds.height()); -  compose.fillRect(base, kColorWhite); -  compose.frameRect(base, kColorBlack); -  for (Common::Array<DialogElement*>::iterator it = _elements.begin(); it != _elements.end(); it++) { -    (*it)->draw(this, compose); -  } - -  g_system->copyRectToScreen(compose.getPixels(), compose.pitch, -    _bounds.left, _bounds.top, _bounds.width(), _bounds.height()); -} +	Graphics::ManagedSurface compose; +	// Compose the surface +	compose.create(_bounds.width(), _bounds.height()); +	Common::Rect base(0, 0, _bounds.width(), _bounds.height()); +	compose.fillRect(base, kColorWhite); +	compose.frameRect(base, kColorBlack); +	for (Common::Array<DialogElement*>::iterator it = _elements.begin(); it != _elements.end(); it++) { +		(*it)->draw(this, compose); +	} + +	g_system->copyRectToScreen(compose.getPixels(), compose.pitch, +		_bounds.left, _bounds.top, _bounds.width(), _bounds.height()); +	}  void Dialog::localize(Common::Point &point) { -  point.x -= _bounds.left; -  point.y -= _bounds.top; +	point.x -= _bounds.left; +	point.y -= _bounds.top;  }  void Dialog::setUserInput(Common::String content) { -  _userInput = content; +	_userInput = content;  }  void Dialog::addPrebuiltElement(const MacVenture::PrebuiltDialogElement &element) { -  switch(element.type) { -    case kDEButton: -      addButton(element.title, element.action, element.position, element.width, element.height); -      break; -    case kDEPlainText: -      addText(element.title, element.position); -      break; -    case kDETextInput: -      addTextInput(element.position, element.width, element.height); -      break; -  } +	switch(element.type) { +	case kDEButton: +		addButton(element.title, element.action, element.position, element.width, element.height); +		break; +	case kDEPlainText: +		addText(element.title, element.position); +		break; +	case kDETextInput: +		addTextInput(element.position, element.width, element.height); +		break; +	default: +		break; +	}  }  // Dialog Element  DialogElement::DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width, uint height) : -  _text(title), _action(action) { -    if (width == 0) { -      width = dialog->getFont().getStringWidth(title); -    } -    if (height == 0) { -      height = dialog->getFont().getFontHeight(); -    } -    _bounds = Common::Rect(position.x, position.y, position.x + width, position.y + height); -  } +	_text(title), _action(action) { +	if (width == 0) { +		width = dialog->getFont().getStringWidth(title); +	} +	if (height == 0) { +		height = dialog->getFont().getFontHeight(); +	} +	_bounds = Common::Rect(position.x, position.y, position.x + width, position.y + height); +}  bool DialogElement::processEvent(MacVenture::Dialog *dialog, Common::Event event)  { -  return doProcessEvent(dialog, event); +	return doProcessEvent(dialog, event);  }  void DialogElement::draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { -  doDraw(dialog, target); +	doDraw(dialog, target);  }  const Common::String& DialogElement::getText() { -  return doGetText(); +	return doGetText();  }  const Common::String& DialogElement::doGetText() { -  return _text; +	return _text;  }  // CONCRETE DIALOG ELEMENTS  DialogButton::DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width, uint height): -  DialogElement(dialog, title, action, position, width, height) {} +	DialogElement(dialog, title, action, position, width, height) {}  bool DialogButton::doProcessEvent(MacVenture::Dialog *dialog, Common::Event event) { -  Common::Point mouse = event.mouse; -  if (event.type == Common::EVENT_LBUTTONDOWN) { -    dialog->localize(mouse); -    if (_bounds.contains(mouse)) { -      debugC(1, kMVDebugGUI, "Click! Button: %s", _text.c_str()); -      dialog->handleDialogAction(this, _action); -      return true; -    } -  } -  return false; +	Common::Point mouse = event.mouse; +	if (event.type == Common::EVENT_LBUTTONDOWN) { +		dialog->localize(mouse); +		if (_bounds.contains(mouse)) { +			debugC(1, kMVDebugGUI, "Click! Button: %s", _text.c_str()); +			dialog->handleDialogAction(this, _action); +			return true; +		} + 	} + 	return false;  }  void DialogButton::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { -  target.fillRect(_bounds, kColorWhite); -  target.frameRect(_bounds, kColorBlack); -  // Draw title -  dialog->getFont().drawString( -    &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); +	target.fillRect(_bounds, kColorWhite); +	target.frameRect(_bounds, kColorBlack); +	// Draw title +	dialog->getFont().drawString( +		&target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter);  }  DialogPlainText::DialogPlainText(Dialog *dialog, Common::String content, Common::Point position) : -  DialogElement(dialog, content, kDANone, position, 0, 0) { } +	DialogElement(dialog, content, kDANone, position, 0, 0) { }  DialogPlainText::~DialogPlainText() {}  bool DialogPlainText::doProcessEvent(MacVenture::Dialog *dialog, Common::Event event) { -  return false; +	return false;  }  void DialogPlainText::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { -  // Draw contents -  dialog->getFont().drawString( -    &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); +	// Draw contents +	dialog->getFont().drawString( +		&target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter);  }  DialogTextInput::DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height) : -  DialogElement(dialog, "", kDANone, position, width, height) {} +	DialogElement(dialog, "", kDANone, position, width, height) {}  DialogTextInput::~DialogTextInput() {}  bool DialogTextInput::doProcessEvent(Dialog *dialog, Common::Event event) { -  if (event.type == Common::EVENT_KEYDOWN) { -    switch (event.kbd.keycode) { -			case Common::KEYCODE_BACKSPACE: -				if (!_text.empty()) { -					_text.deleteLastChar(); -          dialog->setUserInput(_text); -          return true; -				} -				break; - -			default: -				if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) { -					_text += (char)event.kbd.ascii; -          dialog->setUserInput(_text); -          return true; -				} - -				break; +	if (event.type == Common::EVENT_KEYDOWN) { +		switch (event.kbd.keycode) { +		case Common::KEYCODE_BACKSPACE: +			if (!_text.empty()) { +				_text.deleteLastChar(); +				dialog->setUserInput(_text); +      			return true; +			} +			break; +		default: +			if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) { +				_text += (char)event.kbd.ascii; +				dialog->setUserInput(_text); +				return true; +			} +			break;      }    }    return false;  } +  void DialogTextInput::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { -  target.fillRect(_bounds, kColorWhite); -  target.frameRect(_bounds, kColorBlack); -  dialog->getFont().drawString( -    &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack); +	target.fillRect(_bounds, kColorWhite); +	target.frameRect(_bounds, kColorBlack); +	dialog->getFont().drawString(&target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack);  } - - -  } // End of namespace MacVenture diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index a01011f2b8..2ea38b1548 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -35,85 +35,86 @@ class Gui;  class DialogElement;  extern PrebuiltDialog prebuiltDialogs[]; -  class Dialog {  public:  	Dialog(Gui *gui, Common::Point pos, uint width, uint height); - 	Dialog(Gui *gui, PrebuiltDialogs prebuilt); +	Dialog(Gui *gui, PrebuiltDialogs prebuilt);  	~Dialog(); -  bool processEvent(Common::Event event); -  void draw(); -  void localize(Common::Point &point); -  void handleDialogAction(DialogElement *trigger, DialogAction action); +	bool processEvent(Common::Event event); +	void draw(); +	void localize(Common::Point &point); +	void handleDialogAction(DialogElement *trigger, DialogAction action); -  const Graphics::Font& getFont(); +	const Graphics::Font& getFont(); -  void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); -  void addText(Common::String content, Common::Point position); -  void addTextInput(Common::Point position, int width, int height); +	void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); +	void addText(Common::String content, Common::Point position); +	void addTextInput(Common::Point position, int width, int height); -  void setUserInput(Common::String content); +	void setUserInput(Common::String content);  private: -  void addPrebuiltElement(const PrebuiltDialogElement &element); +	void addPrebuiltElement(const PrebuiltDialogElement &element);  private: -  Gui *_gui; +	Gui *_gui; -  Common::String _userInput; -  Common::Array<DialogElement*> _elements; -  Common::Rect _bounds; +	Common::String _userInput; +	Common::Array<DialogElement*> _elements; +	Common::Rect _bounds;  };  class DialogElement {  public: -  DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); -  virtual ~DialogElement() {} +	DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); +	virtual ~DialogElement() {} -  bool processEvent(Dialog *dialog, Common::Event event); -  void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); -  const Common::String& getText(); +	bool processEvent(Dialog *dialog, Common::Event event); +	void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); +	const Common::String& getText();  private: -  virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0; -  virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0; -  virtual const Common::String& doGetText(); +	virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0; +	virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0; +	virtual const Common::String& doGetText();  protected: -  Common::String _text; -  Common::Rect _bounds; -  DialogAction _action; +	Common::String _text; +	Common::Rect _bounds; +	DialogAction _action;  };  // Dialog elements  class DialogButton : public DialogElement {  public: -  DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); -  ~DialogButton() {} +	DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); +	~DialogButton() {}  private: -  bool doProcessEvent(Dialog *dialog, Common::Event event); -  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); +	bool doProcessEvent(Dialog *dialog, Common::Event event); +	void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target);  };  class DialogPlainText : public DialogElement {  public: -  DialogPlainText(Dialog *dialog, Common::String content, Common::Point position); -  ~DialogPlainText(); +	DialogPlainText(Dialog *dialog, Common::String content, Common::Point position); +	~DialogPlainText(); +  private: -  bool doProcessEvent(Dialog *dialog, Common::Event event); -  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); +	bool doProcessEvent(Dialog *dialog, Common::Event event); +	void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target);  };  class DialogTextInput : public DialogElement {  public: -  DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height); -  ~DialogTextInput(); +	DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height); +	~DialogTextInput(); +  private: -  bool doProcessEvent(Dialog *dialog, Common::Event event); -  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); +	bool doProcessEvent(Dialog *dialog, Common::Event event); +	void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target);  };  } // End of namespace MacVenture diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp index 945808bfcc..bb9ea65b68 100644 --- a/engines/macventure/prebuilt_dialogs.cpp +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -26,40 +26,39 @@ namespace MacVenture {  PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { -  {/* kSaveAsDialog */ -    Common::Rect(0, 146, 456, 254), -    { -      {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, -      {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, -      {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, -      {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, -      {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, -      {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} -    } -  }, +	{/* kSaveAsDialog */ +		Common::Rect(0, 146, 456, 254), +		{ +			{kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, +			{kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, +			{kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, +			{kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, +			{kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, +			{kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} +		} +	}, -  { /* kSpeakDialog */ -    Common::Rect(20, 92, 400, 200), -    { -      {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, -      {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, -      {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, -      {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, -      {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} -    } -}, - -  { /* kWinGameDialog */ -	  Common::Rect(20, 100, 400, 200), -	  { -		  {kDEPlainText, "You Won!", kDANone, Common::Point(10, 10), 400, 20}, -		  {kDEPlainText, "What do you want to do?", kDANone, Common::Point(10, 30), 400, 20}, -		  {kDEButton, "New Game", kDANewGame, Common::Point(40, 30), 50, 20}, -		  {kDEButton, "Load", kDALoadGame, Common::Point(100, 30), 50, 20}, -		  {kDEButton, "Quit", kDAQuit, Common::Point(160, 30), 50, 20}, -		  {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} -	  } -  } +	{ /* kSpeakDialog */ +		Common::Rect(20, 92, 400, 200), +		{ +			{kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, +			{kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, +			{kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, +			{kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, +			{kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} +		} +	}, +	{ /* kWinGameDialog */ +		Common::Rect(20, 100, 400, 200), +		{ +			{kDEPlainText, "You Won!", kDANone, Common::Point(10, 10), 400, 20}, +			{kDEPlainText, "What do you want to do?", kDANone, Common::Point(10, 30), 400, 20}, +			{kDEButton, "New Game", kDANewGame, Common::Point(40, 30), 50, 20}, +			{kDEButton, "Load", kDALoadGame, Common::Point(100, 30), 50, 20}, +			{kDEButton, "Quit", kDAQuit, Common::Point(160, 30), 50, 20}, +			{kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} +		} +	}  };  } // End of namespace MacVenture diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 5deda1b7e9..4c6f386770 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -28,47 +28,47 @@  namespace MacVenture {  enum DialogAction { -  kDANone, -  kDACloseDialog, -  kDASubmit, -  kDASaveAs, -  kDALoadGame, -  kDAQuit, -  kDANewGame +	kDANone, +	kDACloseDialog, +	kDASubmit, +	kDASaveAs, +	kDALoadGame, +	kDAQuit, +	kDANewGame  };  enum PrebuiltDialogs { -  kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead. -  kSpeakDialog = 1, -  kWinGameDialog = 2, -  kPrebuiltDialogCount +	kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead. +	kSpeakDialog = 1, +	kWinGameDialog = 2, +	kPrebuiltDialogCount  };  enum PrebuiltElementType { -  kDEPlainText, -  kDEButton, -  kDETextInput, -  kDEEnd +	kDEPlainText, +	kDEButton, +	kDETextInput, +	kDEEnd  };  struct PrebuiltDialogElement { -  PrebuiltElementType type; -  Common::String title; -  DialogAction action; -  Common::Point position; -  uint width; -  uint height; +	PrebuiltElementType type; +	Common::String title; +	DialogAction action; +	Common::Point position; +	uint width; +	uint height;  };  // Prebuilt dialogs  enum { -  // HACK -  kMaxPrebuiltDialogElements = 10 +	// HACK +	kMaxPrebuiltDialogElements = 10  };  struct PrebuiltDialog { -  Common::Rect bounds; -  PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; +	Common::Rect bounds; +	PrebuiltDialogElement elements[kMaxPrebuiltDialogElements];  };  } // End of namespace MacVenture  | 
