diff options
author | Marisa-Chan | 2014-08-04 16:35:54 +0700 |
---|---|---|
committer | Marisa-Chan | 2014-08-04 16:35:54 +0700 |
commit | 550c4dbc359ece732684e0733e1925283f31c257 (patch) | |
tree | 288b384a6eb0b2c6f6a9de8fe2d79b89fea168c1 /engines/zvision | |
parent | 73d26bc2337e8afd03bfd73e6ccc0c0fb44a5950 (diff) | |
download | scummvm-rg350-550c4dbc359ece732684e0733e1925283f31c257.tar.gz scummvm-rg350-550c4dbc359ece732684e0733e1925283f31c257.tar.bz2 scummvm-rg350-550c4dbc359ece732684e0733e1925283f31c257.zip |
ZVISION: Implement full code for input control
Diffstat (limited to 'engines/zvision')
-rw-r--r-- | engines/zvision/scripting/controls/input_control.cpp | 149 | ||||
-rw-r--r-- | engines/zvision/scripting/controls/input_control.h | 20 | ||||
-rw-r--r-- | engines/zvision/scripting/scr_file_handling.cpp | 3 |
3 files changed, 147 insertions, 25 deletions
diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp index bebf3fae11..e35b300cb9 100644 --- a/engines/zvision/scripting/controls/input_control.cpp +++ b/engines/zvision/scripting/controls/input_control.cpp @@ -23,6 +23,7 @@ #include "common/scummsys.h" #include "zvision/scripting/controls/input_control.h" +#include "zvision/cursors/cursor_manager.h" #include "zvision/zvision.h" #include "zvision/scripting/script_manager.h" @@ -42,7 +43,11 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre _nextTabstop(0), _focused(false), _textChanged(false), - _cursorOffset(0) { + _cursorOffset(0), + _enterPressed(false), + _readOnly(false), + _txtWidth(0), + _animation(NULL) { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -71,21 +76,30 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre sscanf(line.c_str(), "%*[^(](%u)", &fontFormatNumber); - _textStyle = _engine->getStringManager()->getTextStyle(fontFormatNumber); + _string_init.readAllStyle(_engine->getStringManager()->getTextLine(fontFormatNumber)); + } else if (line.matchString("*chooser_init_string*", true)) { + uint fontFormatNumber; + + sscanf(line.c_str(), "%*[^(](%u)", &fontFormatNumber); + + _string_chooser_init.readAllStyle(_engine->getStringManager()->getTextLine(fontFormatNumber)); } else if (line.matchString("*next_tabstop*", true)) { sscanf(line.c_str(), "%*[^(](%u)", &_nextTabstop); + } else if (line.matchString("*cursor_dimensions*", true)) { + // Ignore, use the dimensions in the animation file + } else if (line.matchString("*cursor_animation_frames*", true)) { + // Ignore, use the frame count in the animation file } else if (line.matchString("*cursor_animation*", true)) { char fileName[25]; sscanf(line.c_str(), "%*[^(](%25s %*u)", fileName); - _cursorAnimationFileName = Common::String(fileName); - } else if (line.matchString("*cursor_dimensions*", true)) { - // Ignore, use the dimensions in the animation file - } else if (line.matchString("*cursor_animation_frames*", true)) { - // Ignore, use the frame count in the animation file + _animation = new MetaAnimation(fileName, _engine); + _frame = -1; + _frameDelay = 0; } else if (line.matchString("*focus*", true)) { _focused = true; + _engine->getScriptManager()->setFocusControlKey(_key); } line = stream.readLine(); @@ -94,51 +108,140 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre } bool InputControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { - _engine->getScriptManager()->focusControl(_key); + if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED) + return false; + + if (_textRectangle.contains(backgroundImageSpacePos)) { + if (!_readOnly) { + // Save + _engine->getScriptManager()->focusControl(_key); + } else { + // Restore + if (_currentInputText.size()) + _enterPressed = true; + } + } + return false; +} + +bool InputControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED) + return false; + + if (_textRectangle.contains(backgroundImageSpacePos)) { + if (!_readOnly) { + // Save + _engine->getCursorManager()->changeCursor(CursorIndex_Active); + return true; + } else { + // Restore + if (_currentInputText.size()) { + _engine->getCursorManager()->changeCursor(CursorIndex_Active); + _engine->getScriptManager()->focusControl(_key); + return true; + } + } + } return false; } bool InputControl::onKeyDown(Common::KeyState keyState) { + if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED) + return false; + if (!_focused) { return false; } if (keyState.keycode == Common::KEYCODE_BACKSPACE) { - _currentInputText.deleteLastChar(); + if (!_readOnly) { + _currentInputText.deleteLastChar(); + _textChanged = true; + } + } else if (keyState.keycode == Common::KEYCODE_RETURN) { + _enterPressed = true; } else if (keyState.keycode == Common::KEYCODE_TAB) { - _focused = false; + unfocus(); // Focus the next input control _engine->getScriptManager()->focusControl(_nextTabstop); + // Don't process this event for other controls + return true; } else { - // Otherwise, append the new character to the end of the current text - - uint16 asciiValue = keyState.ascii; - // We only care about text values - if (asciiValue >= 32 && asciiValue <= 126) { - _currentInputText += (char)asciiValue; - _textChanged = true; + if (!_readOnly) { + // Otherwise, append the new character to the end of the current text + uint16 asciiValue = keyState.ascii; + // We only care about text values + if (asciiValue >= 32 && asciiValue <= 126) { + _currentInputText += (char)asciiValue; + _textChanged = true; + } } } return false; } bool InputControl::process(uint32 deltaTimeInMillis) { - if (!_focused) { + if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED) return false; - } // First see if we need to render the text if (_textChanged) { // Blit the text using the RenderManager - //Common::Rect destRect = _engine->getRenderManager()->renderTextToWorkingWindow(_key, _currentInputText, _textStyle.font, _textRectangle.left, _textRectangle.top, _textStyle.color, _textRectangle.width()); - //_cursorOffset = destRect.left - _textRectangle.left; + Graphics::Surface txt; + txt.create(_textRectangle.width(), _textRectangle.height(), _engine->_pixelFormat); + + if (!_readOnly || !_focused) + _txtWidth = _engine->getTextRenderer()->drawTxt(_currentInputText, _string_init, txt); + else + _txtWidth = _engine->getTextRenderer()->drawTxt(_currentInputText, _string_chooser_init, txt); + + _engine->getRenderManager()->blitSurfaceToBkg(txt, _textRectangle.left, _textRectangle.top); + + txt.free(); + } + + if (_animation && !_readOnly && _focused) { + bool need_draw = true;// = _textChanged; + _frameDelay -= deltaTimeInMillis; + if (_frameDelay <= 0) { + _frame = (_frame + 1) % _animation->frameCount(); + _frameDelay = _animation->frameTime(); + need_draw = true; + } + + if (need_draw) { + const Graphics::Surface *srf = _animation->getFrameData(_frame); + uint32 xx = _textRectangle.left + _txtWidth; + if (xx >= _textRectangle.left + (_textRectangle.width() - _animation->width())) + xx = _textRectangle.left + _textRectangle.width() - _animation->width(); + _engine->getRenderManager()->blitSurfaceToBkg(*srf, xx, _textRectangle.top); + } } - // Render the next frame of the animation - // TODO: Implement animation handling + _textChanged = false; + return false; +} +bool InputControl::enterPress() { + if (_enterPressed) { + _enterPressed = false; + return true; + } return false; } +void InputControl::setText(const Common::String &_str) { + _currentInputText = _str; + _textChanged = true; +} + +const Common::String InputControl::getText() { + return _currentInputText; +} + +void InputControl::setReadOnly(bool readonly) { + _readOnly = readonly; +} + } // End of namespace ZVision diff --git a/engines/zvision/scripting/controls/input_control.h b/engines/zvision/scripting/controls/input_control.h index 91fcd364cd..5e2190f369 100644 --- a/engines/zvision/scripting/controls/input_control.h +++ b/engines/zvision/scripting/controls/input_control.h @@ -24,6 +24,8 @@ #define ZVISION_INPUT_CONTROL_H #include "zvision/scripting/control.h" +#include "zvision/animation/meta_animation.h" +#include "zvision/text/text.h" #include "zvision/text/string_manager.h" #include "common/rect.h" @@ -38,25 +40,39 @@ public: private: Common::Rect _textRectangle; Common::Rect _headerRectangle; - StringManager::TextStyle _textStyle; + cTxtStyle _string_init; + cTxtStyle _string_chooser_init; uint32 _nextTabstop; - Common::String _cursorAnimationFileName; bool _focused; Common::String _currentInputText; bool _textChanged; uint _cursorOffset; + bool _enterPressed; + bool _readOnly; + + int16 _txtWidth; + MetaAnimation *_animation; + int32 _frameDelay; + int16 _frame; public: void focus() { _focused = true; + _textChanged = true; } void unfocus() { _focused = false; + _textChanged = true; } bool onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); bool onKeyDown(Common::KeyState keyState); bool process(uint32 deltaTimeInMillis); + void setText(const Common::String &_str); + const Common::String getText(); + bool enterPress(); + void setReadOnly(bool); }; } // End of namespace ZVision diff --git a/engines/zvision/scripting/scr_file_handling.cpp b/engines/zvision/scripting/scr_file_handling.cpp index 5d697bd841..d1d6e2862d 100644 --- a/engines/zvision/scripting/scr_file_handling.cpp +++ b/engines/zvision/scripting/scr_file_handling.cpp @@ -31,6 +31,7 @@ #include "zvision/scripting/controls/push_toggle_control.h" #include "zvision/scripting/controls/lever_control.h" #include "zvision/scripting/controls/slot_control.h" +#include "zvision/scripting/controls/input_control.h" #include "common/textconsole.h" #include "common/file.h" @@ -346,6 +347,8 @@ Control *ScriptManager::parseControl(Common::String &line, Common::SeekableReadS return new LeverControl(_engine, key, stream); } else if (controlType.equalsIgnoreCase("slot")) { return new SlotControl(_engine, key, stream); + } else if (controlType.equalsIgnoreCase("input")) { + return new InputControl(_engine, key, stream); } return NULL; } |