コード例 #1
0
ファイル: GameAppearence.cs プロジェクト: DunkanDX/WordGame
 public void DrawTable(Graphics g)
 {
     if (cellSize == 0) {
         firstDraw = true;
         return;
     }
     if (firstDraw) {
         g.FillRectangle(Brushes.Snow, new RectangleF(new PointF(0f, 0f), screenSize));
     }
     for (int row = 0; row < game.MainTable.Height; row++) {
         for (int col = 0; col < game.MainTable.Width; col++) {
             GameCell cell = game.MainTable[row, col];
             GameCellPos objectPos;
             DrawCellInfo drawInfo;
             if (cell.GameObject == null || !game.MainTable.TryGetObjectPosition(cell.GameObject, out objectPos)) {
                 drawInfo = new DrawCellInfo(new GameCellPos(row, col));
             }else{
                 drawInfo = new DrawCellInfo(new GameCellPos(row, col), objectPos, cell.GameObject);
             }
             if (firstDraw || !drawInfo.Equals(prevDrawMap[row, col])) {
                 DrawCell(g, drawInfo);
                 prevDrawMap[row, col] = drawInfo;
             }
         }
     }
     firstDraw = false;
 }
コード例 #2
0
ファイル: GameAppearence.cs プロジェクト: DunkanDX/WordGame
 public RectangleF GetCellBounds(DrawCellInfo info)
 {
     return new RectangleF(
         (tableStart.X + cellSize * info.CellPos.Column),
         (tableStart.Y + cellSize * info.CellPos.Row),
         cellSize, cellSize);
 }
コード例 #3
0
ファイル: GameAppearence.cs プロジェクト: DunkanDX/WordGame
 public void DrawCell(Graphics g, DrawCellInfo info)
 {
     RectangleF cellBounds = GetCellBounds(info);
     Color cellColor = GetObjectColor(info.Object);
     Image cellImage = GetObjectImage(info.Object, cellColor);
     IStringMapProvider stringMapProvider = info.Object as IStringMapProvider;
     using(Brush brush = new SolidBrush(cellColor)){
         if (cellImage == null) {
             g.FillRectangle(brush, cellBounds);
         } else {
             g.DrawImage(cellImage, cellBounds);
         }
         g.DrawRectangle(Pens.Silver, cellBounds.Left, cellBounds.Top, cellBounds.Width, cellBounds.Height);
     }
     if (stringMapProvider == null) return;
     string text = stringMapProvider.StringMap[info.CellPos.Row - info.ObjectPos.Row, info.CellPos.Column - info.ObjectPos.Column];
     text = text.Replace(' ', '_');
     float fontSize = cellSize / 3.55555558f;
     using (Font currentFont = new Font(mainFont.FontFamily, fontSize, mainFont.Style, mainFont.Unit, mainFont.GdiCharSet, mainFont.GdiVerticalFont)) {
         SizeF stringSize = g.MeasureString(text, currentFont);
         if (stringSize.Width > cellSize) stringSize.Width = cellSize;
         if (stringSize.Height > cellSize) stringSize.Height = cellSize;
         PointF stringPos = new PointF(((cellSize - stringSize.Width) / 2) + cellBounds.Left,
                                     ((cellSize - stringSize.Height) / 2) + cellBounds.Top);
         RectangleF stringBounds = new RectangleF(stringPos, stringSize);
         RectangleF stringBoundsShadow = RectangleF.Inflate(stringBounds, 1, 1);
         g.DrawString(text, currentFont, Brushes.Black, stringBoundsShadow);
         g.DrawString(text, currentFont, Brushes.White, stringBounds);
     }
 }