示例#1
0
文件: TextBox.cs 项目: pzaps/CrossGFX
 public override void DrawMiddle(IRenderTarget renderTarget)
 {
     if (string.IsNullOrEmpty(this.Value.Text) || this.Value.Font == null) return;
     base.DrawMiddle(renderTarget);
     string text = this.VisibleText;
     if (selectionEnd - selectionStart > 0) {
         string selection = text.Substring(selectionStart, selectionEnd - selectionStart);
         Size size = this.Value.Font.MeasureTextSize(selection, this.Value.TextSize, this.Value.Bold);
         Size offset = this.Value.Font.MeasureTextSize(text.Substring(0, selectionStart), this.Value.TextSize, this.Value.Bold);
         Rectangle highlightRectangle = new Rectangle(
             offset.Width + base.textPosition.X, base.textPosition.Y - 2,
             size.Width, this.Value.TextSize + 4
             );
         renderTarget.Fill(highlightRectangle, this.Value.Color);
         renderTarget.DrawString(new Point(this.textPosition.X + offset.Width, this.textPosition.Y), this.Value.Font, selection,
             this.Value.TextSize, this.Value.Color.Invert(), this.Value.Bold, this.Value.Italic, this.Value.Underline);
     }
 }
示例#2
0
文件: TextBox.cs 项目: pzaps/CrossGFX
        public override void DrawOver(IRenderTarget renderTarget)
        {
            if (this.HasFocus && this.caretVisible) {
                Point pA = GetCharacterPosition(cursorPos);

                Rectangle caretRectangle = new Rectangle(pA.X + base.textPosition.X, base.textPosition.Y - 2, 1, this.Value.TextSize + 4);
                renderTarget.Fill(caretRectangle,
                    ((selectionEnd - selectionStart > 0) ? this.Value.Color.Invert() : this.Value.Color));
            }
        }
示例#3
0
文件: Control.cs 项目: pzaps/CrossGFX
        public virtual void DrawUnder(IRenderTarget renderTarget)
        {
            if (this.BackgroundColor != null)
                renderTarget.Fill(new Rectangle(0, 0, this.Bounds.Width, this.Bounds.Height), this.BackgroundColor.Value);
            if (Skinnable != null) {
                Rectangle region;
                ITexture texture;
                switch (State) {
                    case ControlState.Base:
                        if (!this.Active) {
                            region = Skinnable.TextureBaseRegion;
                            texture = this.TextureBase;
                        } else {
                            region = Skinnable.TextureBaseActiveRegion;
                            texture = this.TextureBaseActive;
                        } break;
                    case ControlState.Disabled:
                        if (!this.Active) {
                            region = Skinnable.TextureDisabledRegion;
                            texture = this.TextureDisabled;
                        } else {
                            region = Skinnable.TextureDisabledActiveRegion;
                            texture = this.TextureDisabledActive;
                        } break;
                    case ControlState.Hover:
                        if (!this.Active) {
                            region = Skinnable.TextureHoverRegion;
                            texture = this.TextureHover;
                        } else {
                            region = Skinnable.TextureHoverActiveRegion;
                            texture = this.TextureHoverActive;
                        } break;
                    case ControlState.Down:
                        if (!this.Active) {
                            region = Skinnable.TextureDownRegion;
                            texture = this.TextureDown;
                        } else {
                            region = Skinnable.TextureDownActiveRegion;
                            texture = this.TextureDownActive;
                        } break;
                    default:
                        region = new Rectangle(0, 0, 0, 0);
                        texture = null;
                        break;
                }
                if (texture != null) {
                    region = new Rectangle(0, 0, texture.Width, texture.Height);
                } else {
                    texture = GUI.Instance.Skin.SkinTexture.Texture;
                }

                if (Skinnable.SubRegions.Length != 1) {
                    for (int i = 0; i < Skinnable.SubRegions.Length; i++) {
                        renderTarget.DrawStretched(texture, subRegionsStretched[i], new Rectangle(
                                region.X + Skinnable.SubRegions[i].X, region.Y + Skinnable.SubRegions[i].Y,
                                Skinnable.SubRegions[i].Width, Skinnable.SubRegions[i].Height));
                    }
                } else {
                    renderTarget.DrawStretched(texture, new Rectangle(0, 0, Bounds.Width, Bounds.Height), region);
                }

            }
        }