示例#1
0
        public RelateDirection GetCellRelation(int idx, int offset)
        {
            RelateDirection direction = RelateDirection.None;

            int  r_idx = idx + offset;
            Cell rela  = GetCell(r_idx);

            if (rela != null)
            {
                Cell cell = GetCell(idx);
                if (rela.Row > cell.Row)
                {
                    direction = RelateDirection.Bottom;
                }
                else if (rela.Row < cell.Row)
                {
                    direction = RelateDirection.Top;
                }
                else if (rela.Col > cell.Col)
                {
                    direction = RelateDirection.Right;
                }
                else if (rela.Col < cell.Col)
                {
                    direction = RelateDirection.Left;
                }
            }
            return(direction);
        }
示例#2
0
        public void DrawSerpentCell(Serpent serpent, int idx)
        {
            Cell            cell   = serpent.GetCell(idx);
            Rectangle       rect   = GetCellRect(cell.Row, cell.Col);
            RelateDirection before = serpent.GetCellRelation(idx, -1);
            RelateDirection after  = serpent.GetCellRelation(idx, 1);

            cell.Draw(_graphic, rect, CellMargin, idx, before, after);
        }
示例#3
0
        public void Draw(Graphics g, Rectangle rect, int margin, int idx, RelateDirection before, RelateDirection after)
        {
            if (IsNormal() || IsHinder())
            {
                DrawSimple(g, rect);
                return;
            }

            Brush brObj  = new SolidBrush(ObjColor);
            Brush brBack = new SolidBrush(NormalColor);
            Pen   pen    = new Pen(BdrColor, 1);

            if (!Global.DrawCellMargin)
            {
                g.FillRectangle(brObj, rect);
                if (Global.DrawCellGridLine)
                {
                    g.DrawRectangle(pen, rect);
                }
                if (idx != -1 && Global.DisplaySerpentItemNumber)
                {
                    g.DrawString(idx.ToString(), SystemFonts.DefaultFont, brBack, rect.Left + 2, rect.Top + 2);
                }
            }
            else
            {
                g.FillRectangle(brBack, rect);
                if (Global.DrawCellGridLine)
                {
                    g.DrawRectangle(pen, rect);
                }

                Rectangle rcCenter = new Rectangle(rect.Left + margin, rect.Top + margin, rect.Width - margin * 2, rect.Height - margin * 2);

                g.FillRectangle(brObj, rcCenter);
                if (idx != -1 && Global.DisplaySerpentItemNumber)
                {
                    g.DrawString(idx.ToString(), SystemFonts.DefaultFont, Brushes.Black, rcCenter.Left + 2, rcCenter.Top + 2);
                }

                if (before != RelateDirection.None)
                {
                    Rectangle rcBefore = GetRelationRect(rect, margin, before);
                    g.FillRectangle(brObj, rcBefore);
                }

                if (after != RelateDirection.None)
                {
                    Rectangle rcAfter = GetRelationRect(rect, margin, after);
                    g.FillRectangle(brObj, rcAfter);
                }
            }
            brObj.Dispose();
            brBack.Dispose();
            pen.Dispose();
        }
示例#4
0
 public void DrawSerpentCells(Serpent serpent)
 {
     for (int i = 0; i < serpent.Body.Count; i++)
     {
         Cell            cell   = serpent.Body[i];
         Rectangle       rect   = GetCellRect(cell.Row, cell.Col);
         RelateDirection before = serpent.GetCellRelation(i, -1);
         RelateDirection after  = serpent.GetCellRelation(i, 1);
         cell.Draw(_graphic, rect, CellMargin, i, before, after);
     }
 }
示例#5
0
        private Rectangle GetRelationRect(Rectangle rect, int margin, RelateDirection direction)
        {
            if (!Global.DrawCellMargin)
            {
                return(rect);
            }
            Rectangle rcDirection = Rectangle.Empty;
            int       x = 0, y = 0, w = 0, h = 0;

            switch (direction)
            {
            case RelateDirection.None:
                return(rcDirection);

            case RelateDirection.Center:
                x = rect.Left + margin;
                y = rect.Top + margin;
                w = rect.Width - margin * 2;
                h = rect.Height - margin * 2;
                break;

            case RelateDirection.Left:
                x = rect.Left;
                y = rect.Top + margin;
                w = margin;
                h = rect.Height - margin * 2;
                break;

            case RelateDirection.Right:
                x = rect.Right - margin;
                y = rect.Top + margin;
                w = margin;
                h = rect.Height - margin * 2;
                break;

            case RelateDirection.Top:
                x = rect.Left + margin;
                y = rect.Top;
                w = rect.Width - margin * 2;
                h = margin;
                break;

            case RelateDirection.Bottom:
                x = rect.Left + margin;
                y = rect.Bottom - margin;
                w = rect.Width - margin * 2;
                h = margin;
                break;
            }
            rcDirection = new Rectangle(x, y, w, h);
            return(rcDirection);
        }
示例#6
0
        public void DrawSerpentCells2(Serpent serpent)
        {
            Graphics g = Graphics.FromImage(_bitmap);

            for (int i = 0; i < serpent.Body.Count; i++)
            {
                Cell            cell   = serpent.Body[i];
                Rectangle       rect   = GetCellRect(cell.Row, cell.Col);
                RelateDirection before = serpent.GetCellRelation(i, -1);
                RelateDirection after  = serpent.GetCellRelation(i, 1);
                cell.Draw(g, rect, CellMargin, i, before, after);
            }
            g.Dispose();

            _graphic.DrawImage(_bitmap, 0, 0);
        }