示例#1
0
        /// <summary>
        /// 評価値を数字として描画リストに加えます。
        /// </summary>
        private void AddRenderValue(GLUtil.RenderBuffer renderBuffer, Score score)
        {
            var textTexture = GLUtil.TextureCache.GetTextTexture(
                score.Value.ToString(), ValueFont);
            var texture = textTexture.Texture;

            var textTexture2 = GLUtil.TextureCache.GetTextTexture(
                score.Name ?? string.Empty, NameFont);
            var texture2 = textTexture2.Texture;

            if (texture != null && texture.IsAvailable)
            {
                var Margin = 0.02f;

                // 描画領域はテクスチャサイズの割合から決定します。
                // 評価値は画像の下部or上部の
                // 横幅が全体の 3/4 以上になるか、
                // 縦幅が全体の 1/5 以上になるまで
                // 拡大します。拡大は縦横比を保存した状態で行います。

                // フォントの描画サイズを全体の高さからの割合で指定。
                var eh = this.valueHeight;
                var ew = eh * texture.OriginalWidth / texture.OriginalHeight; 

                // 文字幅がエレメントサイズを超えていたら、
                // 文字列サイズの調整を行います。
                if (ew > 0.9f)
                {
                    ew = 0.9f;
                    eh = ew * texture.OriginalHeight / texture.OriginalWidth;
                }

                // 評価値の背景描画
                var bounds = new RectangleF(
                    -0.5f, this.valueTop, 1.0f, this.valueHeight);
                renderBuffer.AddRender(
                    BlendType.Diffuse, Color.FromArgb(128, Color.Black),
                    bounds, Transform, 1.0);

                // 先手後手の描画 (左側のマージンはつけません)
                bounds = new RectangleF(
                    -0.5f, this.valueTop, eh * texture2.OriginalWidth / texture2.OriginalHeight, eh);
                renderBuffer.AddRender(
                    texture2, BlendType.Diffuse,
                    bounds, Transform, 1.0);

                // 評価値の描画
                bounds = new RectangleF(
                    0.5f - Margin - ew, this.valueTop, ew, eh);
                renderBuffer.AddRender(
                    texture, BlendType.Diffuse,
                    bounds, Transform, 1.0);
            }
        }
示例#2
0
        /// <summary>
        /// 文字列の描画を行います。
        /// </summary>
        private void AddRenderText(GLUtil.RenderBuffer renderBuffer, string text,
                                   GLUtil.TextTextureFont font, RectangleF bounds,
                                   double zorder, double opacity = 1.0)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var textTexture = GLUtil.TextureCache.GetTextTexture(text, font);
            if (textTexture == null || textTexture.Texture == null)
            {
                // エラーだけどどうしようか。
                return;
            }

            var texture = textTexture.Texture;
            var r = (float)texture.OriginalWidth / texture.OriginalHeight;
            var br = (float)bounds.Width / bounds.Height;
            var w = (r >= br ? bounds.Width : bounds.Height * r);
            var h = (r >= br ? bounds.Width / r : bounds.Height);

            var result = new RectangleF(
                (bounds.Left + bounds.Right) / 2 - w / 2,
                (bounds.Top + bounds.Bottom) / 2 - h / 2,
                w, h);
            renderBuffer.AddRender(
                texture, BlendType.Diffuse,
                result, Transform, zorder, 1.0);
        }
示例#3
0
        /// <summary>
        /// 自動再生用のエフェクト描画を行います。
        /// </summary>
        private void AddRenderAutoPlayEffect(GLUtil.RenderBuffer renderBuffer)
        {
            if (AutoPlayState != AutoPlayState.Playing)
            {
                return;
            }

            if (AutoPlayOpacity == 0.0)
            {
                return;
            }

            var bounds = new RectangleF(0.0f, 0.0f, 640.0f, 480.0f);
            var alpha = (byte)(AutoPlayColor.A * AutoPlayOpacity);

            renderBuffer.AddRender(
                BlendType.Diffuse, bounds, Transform,
                Color.FromArgb(alpha, AutoPlayColor), ShogiZOrder.PostEffectZ2);
        }
示例#4
0
        /// <summary>
        /// 駒の描画を行います。
        /// </summary>
        private void AddRenderPiece(GLUtil.RenderBuffer renderBuffer, BoardPiece piece,
                                    int count, PointF cpos, double zorder)
        {
            if (this.pieceTexture == null || !this.pieceTexture.IsAvailable)
            {
                return;
            }

            if (count <= 0)
            {
                return;
            }

            var s = SquareSize;
            var bounds = new RectangleF(
                cpos.X - s.Width / 2, cpos.Y - s.Height / 2,
                s.Width, s.Height);

            // 駒自体の描画を行います。
            renderBuffer.AddRender(
                this.pieceTexture, BlendType.Diffuse,
                bounds, Transform, GetPieceMesh(piece), zorder);

            // 必要なら持ち駒の数も描画します。
            if (count >= 2)
            {
                var text = IntConverter.Convert(NumberType.Big, count);
                bounds = new RectangleF(
                    cpos.X - s.Width * 0.1f, cpos.Y - s.Height * 0.6f,
                    s.Width * 0.8f, s.Height * 0.5f);
                AddRenderText(
                    renderBuffer, text, this.pieceCountFont,
                    bounds, zorder + 0.05);
            }
        }
示例#5
0
        /// <summary>
        /// indexに対応した駒台を描画します。
        /// </summary>
        /// <param name="index">0なら駒箱、1なら先手用、2なら後手用の駒台となります。</param>
        private void AddRenderPieceBox(GLUtil.RenderBuffer renderBuffer, int index)
        {
            // テクスチャがないときは帰ります。
            if (this.pieceTexture == null || this.pieceTexture.TextureName == 0)
            {
                return;
            }

            // 駒箱の場合はキャンセルするかもしれません
            if (index == 0 && !IsKomaBoxVisible)
            {
                return;
            }

            // 盤面が反転している場合は、見た目の先後を入れ替えます。
            var viewIndex = (
                ViewSide != BWType.Black ? 
                (index == 0 ? 0 : index == 1 ? 2 : 1) :
                index);
            var pieceBoxBounds = this.pieceBoxBounds[viewIndex];

            // 駒箱テクスチャ
            renderBuffer.AddRender(
                this.pieceBoxTexture, BlendType.Diffuse,
                pieceBoxBounds, Transform,
                ShogiZOrder.BoardZ,  BoardOpacity);

            // 駒台の上に対局者名を描画します。
            {
                var y = (viewIndex == 2 ?
                    pieceBoxBounds.Bottom - 5 - 15 :
                    pieceBoxBounds.Top + 5);
                var bounds = new RectangleF(
                    pieceBoxBounds.Left + 5, y,
                    pieceBoxBounds.Width - 10, 15);

                // 名前の背景に色をつけます。
                var color = (
                    Board.Turn == (BWType)index ?
                    TebanPlayerNameBackgroundColor :
                    UnTebanPlayerNameBackgroundColor);
                renderBuffer.AddRender(
                    BlendType.Diffuse, bounds, Transform,
                    color, ShogiZOrder.PostBoardZ);

                // 対局者名を描画
                var name = (
                    index == 1 ? BlackPlayerName :
                    index == 2 ? WhitePlayerName :
                    "駒箱");
                if (name.HankakuLength() > 17)
                {
                    name = name.HankakuSubstring(14) + "...";
                }
                bounds.Inflate(-1, -1);
                AddRenderText(
                    renderBuffer, name, this.nameFont,
                    bounds, ShogiZOrder.PostBoardZ);
            }

            // 合計時間や消費時間の描画を行います。
            // 局面編集中など駒箱が表示されているときは残り時間を表示しません。
            if (IsTimeVisible && !IsKomaBoxVisible)
            {
                var y = (viewIndex == 2 ?
                    pieceBoxBounds.Bottom :
                    pieceBoxBounds.Top - 15);
                var bounds = new RectangleF(
                    pieceBoxBounds.Left, y,
                    pieceBoxBounds.Width, 15);
                renderBuffer.AddRender(
                    BlendType.Diffuse, bounds, Transform,
                    TimeBackgroundColor, ShogiZOrder.PostBoardZ);

                // 消費時間などを描画
                // 時間のフォーマットは '消費時間 / 合計時間' となっています。
                var totalTime = (index == 1 ? BlackTotalTime : WhiteTotalTime);
                var time = (index == 1 ? BlackTime : WhiteTime);
                var str = string.Format(
                    "{0:000}:{1:00} / {2:000}:{3:00}",
                    (int)time.TotalMinutes, time.Seconds,
                    (int)totalTime.TotalMinutes, totalTime.Seconds);
                bounds.Inflate(-4, -1);
                AddRenderText(
                    renderBuffer, str, this.timeFont,
                    bounds, ShogiZOrder.PostBoardZ);
            }
        }
示例#6
0
        /// <summary>
        /// 盤の描画を行います。
        /// </summary>
        private void AddRenderBoard(GLUtil.RenderBuffer renderBuffer)
        {
            // 盤
            renderBuffer.AddRender(
                this.boardTexture, BlendType.Diffuse,
                BoardBounds, Transform,
                ShogiZOrder.BoardZ, BoardOpacity);

            // 上部に描画する盤の符号の領域
            var totalBounds = RectangleF.FromLTRB(
                BoardSquareBounds.Left,
                BoardBounds.Top,
                BoardSquareBounds.Right,
                BoardSquareBounds.Top); // Topはミスではありません。
            var w = totalBounds.Width / Board.BoardSize;
            for (int n = 1; n <= Board.BoardSize; ++n)
            {
                // 符号を描画する領域
                var bounds = new RectangleF(
                    totalBounds.Left + w * (n - 1),
                    totalBounds.Top,
                    w,
                    totalBounds.Height);
                bounds.Inflate(0, -2.5f);
                var str = IntConverter.Convert(
                    NumberType.Big,
                    ViewSide == BWType.Black ? 10 - n : n);
                AddRenderText(
                    renderBuffer, str, this.boardSignFont,
                    bounds, ShogiZOrder.BoardZ);
            }

            // 右側に描画する盤の符号の領域
            totalBounds = RectangleF.FromLTRB(
                BoardSquareBounds.Right, // Rightはミスではありません。
                BoardSquareBounds.Top,
                BoardBounds.Right,
                BoardSquareBounds.Bottom);
            var h = totalBounds.Height / Board.BoardSize;
            for (int n = 1; n <= Board.BoardSize; ++n)
            {
                // 符号を描画する領域
                var bounds = new RectangleF(
                    totalBounds.Left,
                    totalBounds.Top + h * (n - 1),
                    totalBounds.Width,
                    w);
                bounds.Inflate(-1.5f, 0);
                var str = IntConverter.Convert(
                    NumberType.Kanji,
                    ViewSide == BWType.Black ? n : 10 - n);
                AddRenderText(
                    renderBuffer, str, this.boardSignFont,
                    bounds, ShogiZOrder.BoardZ);
            }
        }