Beispiel #1
0
        void DumpRoomObjectImages(Room room, ObjectData obj, Gdi gdi)
        {
            var text = new ScummText(obj.Name);
            var sb   = new StringBuilder();

            sb.Append("Object #" + obj.Number).Append(" ");

            var decoder = new TextDecoder(sb);

            text.Decode(decoder);

            sb.AppendFormat(" size: {0}x{1}", obj.Width, obj.Height);
            Console.WriteLine(sb);

            var j = 0;

            foreach (var img in obj.Images)
            {
//                try
//                {
                var screen = new VirtScreen(0, obj.Width, obj.Height, PixelFormat.Indexed8, 2);
                if (img.IsBomp)
                {
                    var bdd = new BompDrawData();
                    bdd.Src = img.Data;
                    bdd.Dst = new PixelNavigator(screen.Surfaces[0]);
                    bdd.X   = 0;
                    bdd.Y   = 0;

                    bdd.Width  = obj.Width;
                    bdd.Height = obj.Height;

                    bdd.ScaleX = 255;
                    bdd.ScaleY = 255;
                    bdd.DrawBomp();
                }
                else
                {
                    gdi.DrawBitmap(img, screen, new Point(0, 0), obj.Width, obj.Height & 0xFFF8, 0, obj.Width / 8, room.Header.Width, DrawBitmaps.None, true);
                }

                using (var bmp = ToBitmap(room, screen))
                {
                    bmp.Save("obj_" + obj.Number + "_" + (++j) + ".png");
                }
//                }
//                catch (Exception e)
//                {
//                    Console.ForegroundColor = ConsoleColor.Red;
//                    Console.WriteLine(e);
//                    Console.ResetColor();
//                    Console.ReadLine();
//                }
            }
        }
Beispiel #2
0
        protected void DrawVerbBitmap(int verb, int x, int y)
        {
            var vst = Verbs[verb];
            var vs  = FindVirtScreen(y);

            if (vs == null)
            {
                return;
            }

            Gdi.IsZBufferEnabled = false;

            var hasTwoBufs = vs.HasTwoBuffers;

            vs.HasTwoBuffers = false;

            var xStrip = x / 8;
            var yDiff  = y - vs.TopLine;

            for (var i = 0; i < vst.ImageWidth / 8; i++)
            {
                if (vst.ImageData != null)
                {
                    Gdi.DrawBitmap(vst.ImageData, vs, xStrip + i, yDiff,
                                   vst.ImageWidth, vst.ImageHeight,
                                   i, 1, roomData.Header.Width, DrawBitmaps.AllowMaskOr | DrawBitmaps.ObjectMode);
                }
            }

            vst.CurRect.Right  = vst.CurRect.Left + vst.ImageWidth;
            vst.CurRect.Bottom = vst.CurRect.Top + vst.ImageHeight;
            vst.OldRect        = vst.CurRect;

            Gdi.IsZBufferEnabled = true;
            vs.HasTwoBuffers     = hasTwoBufs;
        }
Beispiel #3
0
        void DumpRoomImage(Room room, Gdi gdi)
        {
            var name = room.Name ?? "room_" + room.Number;

            var screen    = new VirtScreen(0, room.Header.Width, room.Header.Height, PixelFormat.Indexed8, 2);
            var numStrips = room.Header.Width / 8;

            gdi.NumStrips        = numStrips;
            gdi.IsZBufferEnabled = false;
            if (room.Header.Height > 0)
            {
                gdi.RoomChanged(room);
                gdi.DrawBitmap(room.Image, screen, new Point(), room.Header.Width, room.Header.Height, 0, numStrips, room.Header.Width, 0, true);

                using (var bmpRoom = ToBitmap(room, screen))
                {
                    bmpRoom.Save(name + ".png");
                }
            }

            DumpZPlanes(room, name);
        }
Beispiel #4
0
        byte[] GrabPixels(ImageData im, int w, int h)
        {
            // Backup the screen content
            var backup = (byte[])MainVirtScreen.Surfaces[0].Pixels.Clone();

            // Do some drawing
            DrawBox(0, 0, w - 1, h - 1, 0xFF);

            MainVirtScreen.HasTwoBuffers = false;
            Gdi.IsZBufferEnabled         = false;
            Gdi.DrawBitmap(im, MainVirtScreen, _screenStartStrip, 0, w, h, 0, w / 8, MainVirtScreen.Width, DrawBitmaps.None);
            MainVirtScreen.HasTwoBuffers = true;
            Gdi.IsZBufferEnabled         = true;

            // Grab the data we just drew and setup the cursor with it
            var pixels = Capture(MainVirtScreen, MainVirtScreen.XStart, 0, w, h);

            // Restore the screen content
            Array.Copy(backup, MainVirtScreen.Surfaces[0].Pixels, backup.Length);

            return(pixels);
        }
        private void DrawData(PaintEventArgs e, List <RollColumn> visibleColumns)
        {
            if (QueryItemText != null)
            {
                if (HorizontalOrientation)
                {
                    int startRow = FirstVisibleRow;
                    int range    = Math.Min(LastVisibleRow, RowCount - 1) - startRow + 1;

                    Gdi.PrepDrawString(NormalFont, _foreColor);
                    for (int i = 0, f = 0; f < range; i++, f++)
                    {
                        f += lagFrames[i];
                        int LastVisible = LastVisibleColumnIndex;
                        for (int j = FirstVisibleColumn; j <= LastVisible; j++)
                        {
                            Bitmap image         = null;
                            int    x             = 0;
                            int    y             = 0;
                            int    bitmapOffsetX = 0;
                            int    bitmapOffsetY = 0;

                            if (QueryItemIcon != null)
                            {
                                QueryItemIcon(f + startRow, visibleColumns[j], ref image, ref bitmapOffsetX, ref bitmapOffsetY);
                            }

                            if (image != null)
                            {
                                x = RowsToPixels(i) + CellWidthPadding + bitmapOffsetX;
                                y = (j * CellHeight) + (CellHeightPadding * 2) + bitmapOffsetY;
                                Gdi.DrawBitmap(image, new Point(x, y), true);
                            }

                            string text;
                            int    strOffsetX = 0;
                            int    strOffsetY = 0;
                            QueryItemText(f + startRow, visibleColumns[j], out text, ref strOffsetX, ref strOffsetY);

                            // Center Text
                            x = RowsToPixels(i) + (CellWidth - text.Length * _charSize.Width) / 2;
                            y = (j * CellHeight) + CellHeightPadding - VBar.Value;
                            var point = new Point(x + strOffsetX, y + strOffsetY);

                            var rePrep = false;
                            if (j == 1)
                            {
                                if (SelectedItems.Contains(new Cell {
                                    Column = visibleColumns[j], RowIndex = i + startRow
                                }))
                                {
                                    Gdi.PrepDrawString(RotatedFont, SystemColors.HighlightText);
                                    rePrep = true;
                                }
                                else if (j == 1)
                                {
                                    //1. not sure about this; 2. repreps may be excess, but if we render one column at a time, we do need to change back after rendering the header
                                    rePrep = true;
                                    Gdi.PrepDrawString(RotatedFont, _foreColor);
                                }
                            }



                            if (!string.IsNullOrWhiteSpace(text))
                            {
                                Gdi.DrawString(text, point);
                            }

                            if (rePrep)
                            {
                                Gdi.PrepDrawString(NormalFont, _foreColor);
                            }
                        }
                    }
                }
                else
                {
                    int startRow = FirstVisibleRow;
                    int range    = Math.Min(LastVisibleRow, RowCount - 1) - startRow + 1;

                    Gdi.PrepDrawString(NormalFont, _foreColor);
                    int xPadding = CellWidthPadding + 1 - HBar.Value;
                    for (int i = 0, f = 0; f < range; i++, f++)                     // Vertical
                    {
                        f += lagFrames[i];
                        int LastVisible = LastVisibleColumnIndex;
                        for (int j = FirstVisibleColumn; j <= LastVisible; j++)                         // Horizontal
                        {
                            RollColumn col = visibleColumns[j];

                            string text;
                            int    strOffsetX = 0;
                            int    strOffsetY = 0;
                            Point  point      = new Point(col.Left.Value + xPadding, RowsToPixels(i) + CellHeightPadding);

                            Bitmap image         = null;
                            int    bitmapOffsetX = 0;
                            int    bitmapOffsetY = 0;

                            if (QueryItemIcon != null)
                            {
                                QueryItemIcon(f + startRow, visibleColumns[j], ref image, ref bitmapOffsetX, ref bitmapOffsetY);
                            }

                            if (image != null)
                            {
                                Gdi.DrawBitmap(image, new Point(point.X + bitmapOffsetX, point.Y + bitmapOffsetY + CellHeightPadding), true);
                            }

                            QueryItemText(f + startRow, visibleColumns[j], out text, ref strOffsetX, ref strOffsetY);

                            bool rePrep = false;
                            if (SelectedItems.Contains(new Cell {
                                Column = visibleColumns[j], RowIndex = f + startRow
                            }))
                            {
                                Gdi.PrepDrawString(NormalFont, SystemColors.HighlightText);
                                rePrep = true;
                            }

                            if (!string.IsNullOrWhiteSpace(text))
                            {
                                Gdi.DrawString(text, new Point(point.X + strOffsetX, point.Y + strOffsetY));
                            }

                            if (rePrep)
                            {
                                Gdi.PrepDrawString(NormalFont, _foreColor);
                            }
                        }
                    }
                }
            }
        }
Beispiel #6
0
        void DrawObject(int obj, int arg)
        {
            var od = _objs[obj];

            if (_bgNeedsRedraw)
            {
                arg = 0;
            }

            if (od.Number == 0)
            {
                return;
            }

            var xpos = (od.Position.X / 8);
            var ypos = od.Position.Y;

            var width  = od.Width / 8;
            var height = (od.Height &= 0xFFF8); // Mask out last 3 bits

            // Short circuit for objects which aren't visible at all.
            if (width == 0 || xpos > _screenEndStrip || xpos + width < _screenStartStrip)
            {
                return;
            }

            if (od == null || od.Images == null || od.Images.Count == 0)
            {
                return;
            }

            var x = 0xFFFF;

            int numstrip;

            for (var a = numstrip = 0; a < width; a++)
            {
                var tmp = xpos + a;
                if (tmp < _screenStartStrip || _screenEndStrip < tmp)
                {
                    continue;
                }
                if (arg > 0 && _screenStartStrip + arg <= tmp)
                {
                    continue;
                }
                if (arg < 0 && tmp <= _screenEndStrip + arg)
                {
                    continue;
                }
                Gdi.SetGfxUsageBit(tmp, Gdi.UsageBitDirty);
                if (tmp < x)
                {
                    x = tmp;
                }
                numstrip++;
            }

            if (numstrip != 0)
            {
                var flags = od.Flags | DrawBitmaps.ObjectMode;
                // Sam & Max needs this to fix object-layering problems with
                // the inventory and conversation icons.
                if ((_game.GameId == GameId.SamNMax && GetClass(od.Number, ObjectClass.IgnoreBoxes)) ||
                    (_game.GameId == GameId.FullThrottle && GetClass(od.Number, ObjectClass.Player)))
                {
                    flags |= DrawBitmaps.DrawMaskOnAll;
                }

                ImageData img = null;
                if (Game.Version > 4)
                {
                    var state = GetStateCore(od.Number);
                    if (state > 0 && (state - 1) < od.Images.Count)
                    {
                        img = od.Images[state - 1];
                    }
                }
                else
                {
                    img = od.Images.FirstOrDefault();
                }

                if (img != null)
                {
                    Gdi.DrawBitmap(img, _mainVirtScreen, x, ypos, width * 8, height, x - xpos, numstrip, roomData.Header.Width, flags);
                }
            }
        }