private int CharWidth(byte ch) { if (ch < ' ') { ch = 64; } return(_resMan.ReadUInt16(new FrameHeader(_resMan.FetchFrame(_font, (uint)(ch - ' '))).width)); }
public Text(ObjectMan objMan, ResMan resMan, bool czechVersion) { _objMan = objMan; _resMan = resMan; _textCount = 0; _fontId = (uint)(czechVersion ? SwordRes.CZECH_GAME_FONT : SwordRes.GAME_FONT); _font = _resMan.OpenFetchRes(_fontId); _joinWidth = (ushort)(CharWidth((byte)' ') - 2 * Overlap); _charHeight = _resMan.ReadUInt16(new FrameHeader(_resMan.FetchFrame(_font, 0)).height); // all chars have the same height }
public ControlButton(ushort x, ushort y, uint resId, ButtonIds id, byte flag, ResMan pResMan, byte[] screenBuf, ISystem system) { _x = x; _y = y; _id = id; _flag = flag; _resId = resId; _resMan = pResMan; _frameIdx = 0; _resMan.ResOpen(_resId); FrameHeader tmp = new FrameHeader(_resMan.FetchFrame(_resMan.FetchRes(_resId), 0)); _width = _resMan.ReadUInt16(tmp.width); _width = (ushort)((_width > Screen.SCREEN_WIDTH) ? Screen.SCREEN_WIDTH : _width); _height = _resMan.ReadUInt16(tmp.height); if ((x == 0) && (y == 0)) { // center the frame (used for panels); _x = (ushort)((((640 - _width) / 2) < 0) ? 0 : ((640 - _width) / 2)); _y = (ushort)((((480 - _height) / 2) < 0) ? 0 : ((480 - _height) / 2)); } _dstBuf = new ByteAccess(screenBuf, _y * Screen.SCREEN_WIDTH + _x); _system = system; }
private void CreatePointer(uint ptrId, uint luggageId) { _currentPtr = null; if (ptrId != 0) { MousePtr lugg = null; MousePtr ptr = new MousePtr(_resMan.OpenFetchRes(ptrId)); ushort noFrames = _resMan.ReadUInt16(ptr.numFrames); ushort ptrSizeX = _resMan.ReadUInt16(ptr.sizeX); ushort ptrSizeY = _resMan.ReadUInt16(ptr.sizeY); ushort luggSizeX = 0; ushort luggSizeY = 0; ushort resSizeX; ushort resSizeY; if (Sword1.SystemVars.Platform == Platform.PSX) //PSX pointers are half height { ptrSizeY *= 2; } if (luggageId != 0) { lugg = new MousePtr(_resMan.OpenFetchRes(luggageId)); luggSizeX = _resMan.ReadUInt16(lugg.sizeX); luggSizeY = _resMan.ReadUInt16(lugg.sizeY); if (SystemVars.Platform == Platform.PSX) { luggSizeY *= 2; } resSizeX = Math.Max(ptrSizeX, (ushort)((ptrSizeX / 2) + luggSizeX)); resSizeY = Math.Max(ptrSizeY, (ushort)((ptrSizeY / 2) + luggSizeY)); } else { resSizeX = ptrSizeX; resSizeY = ptrSizeY; } _currentPtr = new MousePtr(new byte[MousePtr.Size + resSizeX * resSizeY * noFrames]); _currentPtr.hotSpotX = _resMan.ReadUInt16(ptr.hotSpotX); _currentPtr.hotSpotY = _resMan.ReadUInt16(ptr.hotSpotY); _currentPtr.numFrames = noFrames; _currentPtr.sizeX = resSizeX; _currentPtr.sizeY = resSizeY; var ptrData = _currentPtr; var ptrDataOff = MousePtr.Size; int dstDataOff = 0; ptrData.Data.Set(ptrData.Offset + ptrDataOff, 255, resSizeX * resSizeY * noFrames); if (luggageId != 0) { dstDataOff = ptrDataOff + resSizeX - luggSizeX; for (uint frameCnt = 0; frameCnt < noFrames; frameCnt++) { var luggSrc = MousePtr.Size; dstDataOff += (resSizeY - luggSizeY) * resSizeX; for (uint cnty = 0; cnty < (uint)(SystemVars.Platform == Platform.PSX ? luggSizeY / 2 : luggSizeY); cnty++) { for (uint cntx = 0; cntx < luggSizeX; cntx++) { if (lugg.Data[lugg.Offset + luggSrc + cntx] != 0) { ptrData.Data[ptrData.Offset + dstDataOff + cntx] = lugg.Data[lugg.Offset + luggSrc + cntx]; } } if (SystemVars.Platform == Platform.PSX) { dstDataOff += resSizeX; for (uint cntx = 0; cntx < luggSizeX; cntx++) { if (lugg.Data[lugg.Offset + luggSrc + cntx] != 0) { ptrData.Data[ptrData.Offset + dstDataOff + cntx] = lugg.Data[lugg.Offset + luggSrc + cntx]; } } } dstDataOff += resSizeX; luggSrc += luggSizeX; } } _resMan.ResClose(luggageId); } dstDataOff = ptrDataOff; var srcDataOff = MousePtr.Size; for (uint frameCnt = 0; frameCnt < noFrames; frameCnt++) { for (uint cnty = 0; cnty < (uint)(SystemVars.Platform == Platform.PSX ? ptrSizeY / 2 : ptrSizeY); cnty++) { for (uint cntx = 0; cntx < ptrSizeX; cntx++) { if (ptr.Data[ptr.Offset + srcDataOff + cntx] != 0) { ptrData.Data[ptrData.Offset + dstDataOff + cntx] = ptr.Data[ptr.Offset + srcDataOff + cntx]; } } if (SystemVars.Platform == Platform.PSX) { dstDataOff += resSizeX; for (uint cntx = 0; cntx < ptrSizeX; cntx++) { if (ptr.Data[ptr.Offset + srcDataOff + cntx] != 0) { ptrData.Data[ptrData.Offset + dstDataOff + cntx] = ptr.Data[ptr.Offset + srcDataOff + cntx]; } } } srcDataOff += ptrSizeX; dstDataOff += resSizeX; } dstDataOff += (resSizeY - ptrSizeY) * resSizeX; } _resMan.ResClose(ptrId); } }
private void PerformPostProcessing(byte[] screen) { // TODO: We don't support displaying these in true color yet, // nor using the PSX fonts to display subtitles. if (SystemVars.Platform == Core.IO.Platform.PSX /* || _decoderType == kVideoDecoderMP2*/) { return; } if (_movieTexts.Count > 0) { if (_decoder.CurrentFrame == _movieTexts[0]._startFrame) { var text = new ByteAccess(System.Text.Encoding.UTF8.GetBytes(_movieTexts[0]._text)); _textMan.MakeTextSprite(2, text, 600, Text.LetterCol); var frame = new FrameHeader(_textMan.GiveSpriteData(2)); _textWidth = _resMan.ReadUInt16(frame.width); _textHeight = _resMan.ReadUInt16(frame.height); _textX = 320 - _textWidth / 2; _textY = 420 - _textHeight; _textColor = _movieTexts[0]._color; } if (_decoder.CurrentFrame == _movieTexts[0]._endFrame) { _textMan.ReleaseText(2, false); _movieTexts.RemoveAt(0); } } ByteAccess src, dst; int x, y; if (_textMan.GiveSpriteData(2) != null) { src = new ByteAccess(_textMan.GiveSpriteData(2)); src.Offset += FrameHeader.Size; dst = new ByteAccess(screen, _textY * Screen.SCREEN_WIDTH + _textX * 1); for (y = 0; y < _textHeight; y++) { for (x = 0; x < _textWidth; x++) { switch (src[x]) { case Text.BorderCol: dst[x] = (byte)GetBlackColor(); break; case Text.LetterCol: dst[x] = (byte)FindTextColor(); break; } } src.Offset += _textWidth; dst.Offset += Screen.SCREEN_WIDTH; } } else if (_textX != 0 && _textY != 0) { // If the frame doesn't cover the entire screen, we have to // erase the subtitles manually. int frameWidth = _decoder.GetWidth(); int frameHeight = _decoder.GetHeight(); int frameX = (_vm.Settings.Game.Width - frameWidth) / 2; int frameY = (_vm.Settings.Game.Height - frameHeight) / 2; dst = new ByteAccess(screen, _textY * _vm.Settings.Game.Width); for (y = 0; y < _textHeight; y++) { if (_textY + y < frameY || _textY + y >= frameY + frameHeight) { dst.Data.Set(dst.Offset + _textX, (byte)GetBlackColor(), _textWidth); } else { if (frameX > _textX) { dst.Data.Set(dst.Offset + _textX, (byte)GetBlackColor(), frameX - _textX); } if (frameX + frameWidth < _textX + _textWidth) { dst.Data.Set(dst.Offset + frameX + frameWidth, (byte)GetBlackColor(), _textX + _textWidth - (frameX + frameWidth)); } } dst.Offset += _vm.Settings.Game.Width; } _textX = 0; _textY = 0; } }