/// <summary> /// 文字列の描画を行います。 /// </summary> private void AddRenderText(RenderBuffer renderBuffer, string text, TextTextureFont font, RectangleF bounds, double zorder, double opacity = 1.0) { if (string.IsNullOrEmpty(text)) { return; } var textTexture = 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); }
/// <summary> /// コンストラクタ /// </summary> public ShogiTextObject() { Font = new TextTextureFont(); Color = Color.White; this.needToUpdateTexture = false; PropertyChanged += OnPropertyChanged; }
/// <summary> /// 指し手を表示する矢印メッシュを追加します。 /// </summary> private void AddRenderMoveArrow(RenderBuffer renderBuffer, Move move, int priority, string label) { if (move == null || !move.Validate()) { return; } // 手番が違う場合は、前に設定された指し手が残っている可能性がある。 if (move.BWType != Board.Turn || move.IsSpecialMove) { return; } // 駒の移動を開始した地点と終了した地点の座標を求めます。 var fromPoint = ( move.ActionType == ActionType.Drop ? HandPieceToPoint(move.DropPieceType, move.BWType) : SquareToPoint(move.SrcSquare)).ToPointd(); var toPoint = SquareToPoint(move.DstSquare).ToPointd(); var diff = toPoint - fromPoint; // 矢印を決められた位置に描画します。 var data = CreateArrowData(priority, fromPoint, toPoint); renderBuffer.AddRender( BlendType.Diffuse, CreateArrowColor(move.BWType, priority), data.Item1, data.Item2, ShogiZOrder.PostPieceZ); // ラベルを描画 if (!string.IsNullOrEmpty(label)) { var font = new TextTextureFont { Font = new Font(TextTextureFont.DefaultFont, FontStyle.Bold), Color = Color.White, EdgeColor = Color.Black, EdgeLength = 1, IsStretchSize = true, }; var rect = new RectangleF( (float)(fromPoint.X + diff.X * 0.7), (float)(fromPoint.Y + diff.Y * 0.7), SquareSize.Width / 3, SquareSize.Height / 3); rect.Offset(-rect.Width / 2, -rect.Height / 2); AddRenderText( renderBuffer, label, font, rect, ShogiZOrder.PostPieceZ); } }
/// <summary> /// 指し手を表示する矢印メッシュを追加します。 /// </summary> private void AddRenderMoveArrow(RenderBuffer renderBuffer, MoveArrowInfo info, int priority, string label) { var move = info.Move; if (move == null || !move.Validate()) { return; } // 手番が違う場合は、前に設定された指し手が残っている可能性がある。 if (move.BWType != Board.Turn || move.IsSpecialMove) { return; } // 駒の移動を開始した地点と終了した地点の座標を求めます。 var fromPoint = ( move.ActionType == ActionType.Drop ? HandPieceToPoint(move.DropPieceType, move.BWType) : SquareToPoint(move.SrcSquare)).ToPointd(); var toPoint = SquareToPoint(move.DstSquare).ToPointd(); var diff = toPoint - fromPoint; // 優先順位の高い矢印ほど、小さくなる値 var priorityRate = MathEx.Between(0.0, 1.0, 1.0 / 3.0 * (priority - 1)); // 矢印を決められた位置に描画します。 AddRenderArrow(renderBuffer, fromPoint, toPoint, priorityRate, info.Color); // ラベルを描画 if (!string.IsNullOrEmpty(label)) { var font = new TextTextureFont { Font = new Font(TextTextureFont.DefaultFont, FontStyle.Bold), Color = Color.White, EdgeColor = Color.Black, EdgeLength = 4, IsStretchSize = true, }; var rect = new RectangleF( (float)(fromPoint.X + diff.X * 1), (float)(fromPoint.Y + diff.Y * 1), SquareSize.Width / 3, SquareSize.Height / 3); rect.Offset(-rect.Width / 2, -rect.Height / 2); AddRenderText( renderBuffer, label, font, rect, ShogiZOrder.PreEffectZ2 - priorityRate); } }
/// <summary> /// コンストラクタ /// </summary> public GLEvaluationElement() { this.valueHeight = 0.12f; this.valueTop = 0.5f - this.valueHeight + 0.04f; this.contextMenu = CreateContextMenu(); // 評価値モードはデフォルトでは何でも許可します。 EvaluationMode = EvaluationMode.Programmable; IsEnableUserScore = true; IsEnableServerScore = true; IsVisibleValue = true; IsValueFullWidth = false; MaxValue = 9999; ValueFont = new TextTextureFont { Color = Color.White, EdgeColor = Color.LightGray, EdgeLength = 0.5, IsStretchSize = true, }; NameFont = new TextTextureFont { Color = Color.White, EdgeColor = Color.LightGray, EdgeLength = 1, }; // 内部描画オブジェクトの初期化 AddInternalType("image", typeof(GLEvaluationElementImage)); // CurrentScoreの場合はDependOnProperty属性で指定している // プロパティが変わった時に、これが呼ばれます。 this.AddPropertyChangedHandler( "CurrentScore", (_, __) => UpdateCurrentScore()); this.AddPropertyChangedHandler( "EvaluationMode", (_, __) => EvaluationModeUpdated()); // this.manager this.manager.AddPropertyChangedHandler( "InternalObj", (_, __) => InternalObjUpdated()); this.AddDependModel(this.manager); }
/// <summary> /// 指定のフォントで指定の文字列を描画するためのテクスチャを取得します。 /// </summary> public static TextTexture GetTextTexture(string text, TextTextureFont font) { var context = GraphicsContext.CurrentContext; if (context == null) { throw new ArgumentNullException("context"); } if (text == null) { throw new ArgumentNullException("text"); } if (font == null) { throw new ArgumentNullException("font"); } var cache = GetTextTextureCache(context); return cache.GetTextTexture(text, font); }