/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * $URL$ * $Id$ * */ #include "common/scummsys.h" #include "common/config-manager.h" #include "common/events.h" #include "common/file.h" #include "common/random.h" #include "common/fs.h" #include "common/keyboard.h" #include "common/substream.h" #include "common/savefile.h" #include "graphics/cursorman.h" #include "graphics/surface.h" #include "graphics/pixelformat.h" #include "engines/util.h" #include "engines/advancedDetector.h" #include "audio/audiostream.h" #include "composer/composer.h" #include "composer/graphics.h" #include "composer/resource.h" namespace Composer { // new script ops enum { kOpPlusPlus = 0x1, kOpMinusMinus = 0x2, kOpAssign = 0x3, kOpAdd = 0x4, kOpSubtract = 0x5, kOpMultiply = 0x6, kOpDivide = 0x7, kOpModulo = 0x8, kOpMaybeAlsoAssign = 0x9, kOpBooleanAssign = 0xA, kOpNegate = 0xB, kOpAnd = 0xC, kOpOr = 0xD, kOpXor = 0xE, kOpNot = 0xF, kOpSqrt = 0x10, kOpRandom = 0x11, kOpExecuteScript = 0x12, kOpCallFunc = 0x13, kOpBoolLessThanEq = 0x17, kOpBoolLessThan = 0x16, kOpBoolGreaterThanEq = 0x15, kOpBoolGreaterThan = 0x14, kOpBoolEqual = 0x18, kOpBoolNotEqual = 0x19, kOpSaveArgs = 0x1A, kOpRestoreArgs = 0x1B, kOpReturn = 0x20, kOpLessThanEq = 0x22, kOpLessThan = 0x21, kOpGreaterThanEq = 0x24, kOpGreaterThan = 0x23, kOpEqual = 0x25, kOpNotEqual = 0x26, kOpJump = 0x80, kOpJumpIfNot = 0x81, kOpJumpIf = 0x82, kOpJumpIfNotValue = 0x83, kOpJumpIfValue = 0x84 }; enum { kFuncPlayAnim = 35001, kFuncStopAnim = 35002, // (no 35003) kFuncQueueScript = 35004, kFuncDequeueScript = 35005, kFuncSetCursor = 35006, kFuncGetCursor = 35007, kFuncShowCursor = 35008, kFuncHideCursor = 35009, // (no 35010) kFuncActivateButton = 35011, kFuncDeactivateButton = 35012, kFuncNewPage = 35013, kFuncLoadPage = 35014, kFuncUnloadPage = 35015, kFuncSetPalette = 35016, kFuncSaveVars = 35017, kFuncLoadVars = 35018, kFuncQueueScriptOnce = 35019, kFuncGetMousePos = 35020, kFuncChangeBackground = 35021, kFuncSetBackgroundColor = 35022, kFuncClearSprites = 35023, kFuncAddSprite = 35024, kFuncRemoveSprite = 35025, kFuncQuit = 35026, kFuncSaveData = 35027, kFuncLoadData = 35028, kFuncGetSpriteSize = 35029 }; Button::Button(Common::SeekableReadStream *stream, uint16 id) { _id = id; _type = stream->readUint16LE(); _active = (_type & 0x8000) ? true : false; _type &= 0xfff; debug(9, "button: type %d, active %d", _type, _active); _zorder = stream->readUint16LE(); _scriptId = stream->readUint16LE(); _scriptIdRollOn = stream->readUint16LE(); _scriptIdRollOff = stream->readUint16LE(); stream->skip(4); uint16 size = stream->readUint16LE(); switch (_type) { case kButtonRect: case kButtonEllipse: if (size != 4) error("button %d of type %d had %d points, not 4", id, _type, size); _rect.left = stream->readSint16LE(); _rect.top = stream->readSint16LE(); _rect.right = stream->readSint16LE(); _rect.bottom = stream->readSint16LE(); debug(9, "button: (%d, %d, %d, %d)", _rect.left, _rect.top, _rect.right, _rect.bottom); break; case kButtonSprites: for (uint i = 0; i < size; i++) { _spriteIds.push_back(stream->readSint16LE()); } break; default: error("unknown button type %d", _type); } delete stream; } bool Button::contains(const Common::Point &pos) const { switch (_type) { case kButtonRect: return _rect.contains(pos); case kButtonEllipse: if (!_rect.contains(pos)) return false; { int16 a = _rect.width() / 2; int16 b = _rect.height() / 2; if (!a || !b) return false; Common::Point adjustedPos = pos - Common::Point(_rect.left + a, _rect.top + b); return ((adjustedPos.x*adjustedPos.x)/(a*a) + (adjustedPos.y*adjustedPos.y)/(b*b) < 1); } case kButtonSprites: return false; default: error("internal error (button type %d)", _type); } } const Button *ComposerEngine::getButtonFor(const Sprite *sprite, const Common::Point &pos) { for (Common::List