Exemple #1
0
        public override void Draw(
            float offsetX,
            float offsetY,
            Renderer2D renderer)
        {
            // 罫線を描く
            renderer.Color = BorderColor;
            // まず縦
            int   end             = _widths.Length - 1; // 最後の右端線は不要
            float x               = offsetX + LocalLeftX + BorderWidth;
            float topY            = offsetY + LocalTopY;
            float halfBorderWidth = BorderWidth * 0.5f;

            for (int i = 0; i < end; i++)
            {
                x += _widths[i];
                x += halfBorderWidth; // 線の中心までずらす
                renderer.AddVerticalLine(
                    x,
                    topY,
                    Height,
                    BorderWidth);
                x += halfBorderWidth;
            }
            // 次に横
            end = _heights.Length - 1; // 最後の下端線は不要
            float y     = offsetY + LocalTopY + BorderWidth;
            float leftX = offsetX + LocalLeftX;

            for (int i = 0; i < end; i++)
            {
                y += _heights[i];
                y += halfBorderWidth; // 線の中心までずらす
                renderer.AddHorizontalLine(
                    leftX,
                    y,
                    Width,
                    BorderWidth);
                y += halfBorderWidth;
            }

            y = offsetY + LocalTopY + BorderWidth;
            for (int rowIndex = 0; rowIndex < _heights.Length; rowIndex++)
            {
                float cellHeight = _heights[rowIndex];
                x = offsetX + LocalLeftX + BorderWidth;
                for (int colIndex = 0; colIndex < _widths.Length; colIndex++)
                {
                    float cellWidth = _widths[colIndex];
                    var   cell      = Cells[rowIndex, colIndex];
                    if (string.IsNullOrEmpty(cell.Text) == false)
                    {
                        renderer.Color = TextColor;
                        renderer.AddText(
                            cell.Text,
                            x,
                            y,
                            _fontSize);
                    }
                    x += cellWidth + BorderWidth;
                }
                y += cellHeight + BorderWidth;
            }
        }