コード例 #1
0
        public void drawMapView(Graphics g, PictureBox pb, long scrollPosition, ImageList icons)
        {
            // draw the relevant set of sector icons on to the picturebox
            long totalSectors = i.Length / i.sectorSize;

            int sectorsPerRow = pb.Width / sectorSquareSize;
            int sectorsPerCol = pb.Height / sectorSquareSize;

            int sectorsToDisplay = sectorsPerCol * sectorsPerRow;

            long startSector = scrollPosition * sectorsPerRow;

            sectorIDs = getSectorIDs(sectorsPerRow, sectorsPerCol, startSector);

            Point p = new Point(0, 0);
            long  j = startSector;

            Bitmap   bmp;
            Graphics gOff;

            bmp  = new Bitmap(pb.Width, pb.Height);
            gOff = Graphics.FromImage(bmp);

            map = new imageMap(i);

            while (j < startSector + sectorsToDisplay)
            {
                for (int k = 0; k < sectorsPerRow; k++)
                {
                    bool selected = false;
                    if (this.selectedSector == j + k)
                    {
                        selected = true;
                        SolidBrush outline = new SolidBrush(Color.Red);
                        gOff.FillRectangle(outline, p.X, p.Y, sectorSquareSize, sectorSquareSize);
                    }
                    SolidBrush b = getSectorType(j + k, map, selected);
                    gOff.FillRectangle(b, new Rectangle(p.X + 1, p.Y + 1, sectorSquareSize - 2, sectorSquareSize - 2));
                    p.X += sectorSquareSize;
                }
                p.Y += sectorSquareSize;
                p.X  = 0;
                j   += sectorsPerRow;
            }

            g.DrawImage(bmp, 0, 0);
            gOff.Dispose();
        }
コード例 #2
0
        private SolidBrush getSectorType(long sector, imageMap im, bool selected)
        {
            // look up a position in the partition map and return a
            // colour-coded brush depending on the sector type
            SolidBrush b;

            imageMap.mapBlock block = im.sectorIsIn(sector);
            string            type  = block.type.ToString();

            if (sector > i.Length / i.sectorSize)
            {
                type = "";
            }

            switch (type)
            {
            case "GPT":
                if (!selected)
                {
                    b = new SolidBrush(Color.Green);
                }
                else
                {
                    b = new SolidBrush(Color.LawnGreen);
                }
                break;

            case "MBR":
                if (!selected)
                {
                    b = new SolidBrush(Color.DarkRed);
                }
                else
                {
                    b = new SolidBrush(Color.Red);
                }
                break;

            case "vol_unknown":
                if (block.allocationMap != null)
                {
                    // work out which bit in allocation map is the right one
                    // and display allocated/unallocated depending on its value


                    // there's an off-by-one error somewhere in here
                    long bitposition  = (sector - block.location) / block.mapSectorsPerBlock;
                    long byteposition = bitposition / 8;

                    byte bits = block.allocationMap[byteposition];

                    long positioninbyte = bitposition % 8;

                    if (dataOperations.is_bit_set(bits, (short)positioninbyte))
                    {
                        if (!selected)
                        {
                            b = new SolidBrush(Color.CadetBlue);
                        }
                        else
                        {
                            b = new SolidBrush(Color.PowderBlue);
                        }
                    }
                    else
                    {
                        if (!selected)
                        {
                            b = new SolidBrush(Color.MediumBlue);
                        }
                        else
                        {
                            b = new SolidBrush(Color.SlateBlue);
                        }
                    }
                }
                else
                {
                    if (!selected)
                    {
                        b = new SolidBrush(Color.DarkBlue);
                    }
                    else
                    {
                        b = new SolidBrush(Color.MediumSlateBlue);
                    }
                }
                break;

            case "disk_unallocated":
                b = new SolidBrush(Color.LightGray);
                break;

            default:
                // unknown sector = light grey
                b = new SolidBrush(Color.White);
                break;
            }

            return(b);
        }
コード例 #3
0
        public void drawMapView(Graphics g, PictureBox pb, long scrollPosition, ImageList icons)
        {
            // draw the relevant set of sector icons on to the picturebox
            long totalSectors = i.Length / i.sectorSize;

            int sectorsPerRow = pb.Width / sectorSquareSize;
            int sectorsPerCol = pb.Height / sectorSquareSize;

            int sectorsToDisplay = sectorsPerCol * sectorsPerRow;

            long startSector = scrollPosition * sectorsPerRow;

            sectorIDs = getSectorIDs(sectorsPerRow, sectorsPerCol, startSector);

            Point p = new Point(0,0);
            long j = startSector;

            Bitmap bmp;
            Graphics gOff;

            bmp = new Bitmap(pb.Width, pb.Height);
            gOff = Graphics.FromImage(bmp);

            map = new imageMap(i);

            while (j < startSector + sectorsToDisplay)
            {
                for (int k = 0; k < sectorsPerRow; k++)
                {
                    bool selected = false;
                    if (this.selectedSector == j + k)
                    {
                        selected = true;
                        SolidBrush outline = new SolidBrush(Color.Red);
                        gOff.FillRectangle(outline, p.X, p.Y, sectorSquareSize, sectorSquareSize);
                    }
                    SolidBrush b = getSectorType(j + k, map, selected);
                    gOff.FillRectangle(b, new Rectangle(p.X + 1, p.Y + 1, sectorSquareSize-2, sectorSquareSize-2));
                    p.X += sectorSquareSize;
                }
                p.Y += sectorSquareSize;
                p.X = 0;
                j += sectorsPerRow;
            }

            g.DrawImage(bmp, 0, 0);
            gOff.Dispose();
        }
コード例 #4
0
        private SolidBrush getSectorType(long sector, imageMap im, bool selected)
        {
            // look up a position in the partition map and return a
            // colour-coded brush depending on the sector type
            SolidBrush b;
            imageMap.mapBlock block = im.sectorIsIn(sector);
            string type = block.type.ToString();
            if (sector > i.Length / i.sectorSize)
            {
                type = "";
            }

            switch (type)
            {
                case "GPT":
                    if (!selected) b = new SolidBrush(Color.Green);
                    else b = new SolidBrush(Color.LawnGreen);
                    break;
                case "MBR":
                    if (!selected) b = new SolidBrush(Color.DarkRed);
                    else b = new SolidBrush(Color.Red);
                    break;
                case "vol_unknown":
                    if (block.allocationMap != null)
                    {
                        // work out which bit in allocation map is the right one
                        // and display allocated/unallocated depending on its value

                        // there's an off-by-one error somewhere in here
                        long bitposition = (sector - block.location) / block.mapSectorsPerBlock;
                        long byteposition = bitposition / 8;

                        byte bits = block.allocationMap[byteposition];

                        long positioninbyte = bitposition % 8;

                        if (dataOperations.is_bit_set(bits, (short)positioninbyte))
                        {
                            if (!selected) b = new SolidBrush(Color.CadetBlue);
                            else b = new SolidBrush(Color.PowderBlue);
                        }
                        else
                        {
                            if (!selected) b = new SolidBrush(Color.MediumBlue);
                            else b = new SolidBrush(Color.SlateBlue);
                        }
                    }
                    else
                    {
                        if (!selected) b = new SolidBrush(Color.DarkBlue);
                        else b = new SolidBrush(Color.MediumSlateBlue);
                    }
                    break;
                case "disk_unallocated":
                    b = new SolidBrush(Color.LightGray);
                    break;
                default:
                    // unknown sector = light grey
                    b = new SolidBrush(Color.White);
                    break;
            }

            return b;
        }