Example #1
0
 /// <summary>
 /// 重绘文字层
 /// </summary>
 /// <param name="id">文字层id</param>
 /// <param name="descriptor">文字层描述子</param>
 /// <param name="forceReload">是否强制重新载入背景图资源文件</param>
 private void ReDrawMessageLayer(int id, MessageLayerDescriptor descriptor, bool forceReload)
 {
     // 不需要重绘的情况
     if (descriptor == null) { return; }
     MessageLayer msglay = this.messageLayerVec[id];
     if (msglay == null ||
         msglay.BackgroundSprite.ResourceName != descriptor.BackgroundResourceName ||
         forceReload)
     {
         YuriSprite bgSprite = ResourceManager.GetInstance().GetPicture(descriptor.BackgroundResourceName, new Int32Rect(-1, 0, 0, 0));
         MessageLayer newLayer = new MessageLayer();
         newLayer.BackgroundSprite = bgSprite;
         newLayer.Id = id;
         this.messageLayerVec[id] = msglay = newLayer;
     }
     // 重绘文本层
     this.RemoveMessageLayer(msglay);
     this.DrawMessageLayer(msglay, descriptor);
 }
Example #2
0
 /// <summary>
 /// 将文字层从画面移除
 /// </summary>
 /// <param name="msglay">文字层实例</param>
 private void RemoveMessageLayer(MessageLayer msglay)
 {
     if (msglay != null)
     {
         TextBlock msglayView = msglay.DisplayBinding;
         if (msglayView != null && this.view.BO_MainGrid.Children.Contains(msglayView))
         {
             this.view.BO_MainGrid.Children.Remove(msglayView);
         }
         msglay.DisplayBinding = null;
     }
 }
Example #3
0
 /// <summary>
 /// 为主窗体描绘一个文字层
 /// </summary>
 /// <param name="msglay">文字层</param>
 /// <param name="descriptor">文字层描述子</param>
 private void DrawMessageLayer(MessageLayer msglay, MessageLayerDescriptor descriptor)
 {
     TextBlock msgBlock = new TextBlock();
     msglay.DisplayBinding = msgBlock;
     if (msglay.BackgroundSprite != null && msglay.BackgroundSprite.SpriteBitmapImage != null)
     {
         ImageBrush ib = new ImageBrush(msglay.BackgroundSprite.SpriteBitmapImage);
         ib.Stretch = Stretch.None;
         ib.AlignmentX = AlignmentX.Left;
         ib.AlignmentY = AlignmentY.Top;
         msgBlock.Background = ib;
     }
     msglay.Width = descriptor.Width;
     msglay.Height = descriptor.Height;
     msglay.Opacity = descriptor.Opacity;
     msglay.Padding = (Thickness)descriptor.Padding;
     msglay.LineHeight = descriptor.LineHeight;
     msglay.HorizontalAlignment = descriptor.HorizonAlign;
     msglay.VerticalAlignment = descriptor.VertiAlign;
     msglay.FontColor = Color.FromRgb(descriptor.FontColorR, descriptor.FontColorG, descriptor.FontColorB);
     msglay.FontSize = descriptor.FontSize;
     msglay.FontName = descriptor.FontName;
     msglay.FontShadow = descriptor.FontShadow;
     msglay.DisplayBinding.TextWrapping = TextWrapping.Wrap;
     msglay.DisplayBinding.TextAlignment = TextAlignment.Left;
     Canvas.SetLeft(msgBlock, descriptor.X);
     Canvas.SetTop(msgBlock, descriptor.Y);
     Canvas.SetZIndex(msgBlock, descriptor.Z);
     msglay.Visibility = descriptor.Visible ? Visibility.Visible : Visibility.Hidden;
     this.view.BO_MainGrid.Children.Add(msgBlock);
 }