public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); ButtonState state = info.ButtonState; Color color = ColorFromState * info.Opacity * Opacity; NinePatchImage image = _imageReleased; switch (state & ButtonState.Mask) { case ButtonState.Disabled: if (_imageDisabled != null) { image = _imageDisabled; } break; case ButtonState.Pushed: if (_imagePushed != null) { image = _imagePushed; } break; } float scale = _scaleByUnit ? (float)UiUnit.Unit : 1; Rectangle target = _margin.ComputeRect(info.Target); drawBatch.DrawNinePatchRect(image, target, color, scale * _scale); }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); Rectangle target = _margin.ComputeRect(info.Target); drawBatch.DrawRectangle(target, ColorFromState * info.Opacity * Opacity); }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); Color color = ColorFromState * info.Opacity * Opacity; Texture2D image = _image; if (image != null) { float scale = _scale.Value(true); if (scale == 0) { scale = Math.Min(info.Target.Width / (float)image.Width, info.Target.Height / (float)image.Height); scale = Math.Min(1, scale); } Rectangle textureSrc = new Rectangle(0, 0, image.Width, image.Height); int width = (int)(scale * image.Width); int height = (int)(scale * image.Height); Rectangle target = _margin.ComputeRect(info.Target); switch (_horizontalAlignment) { case HorizontalContentAlignment.Center: target.X = target.Center.X - width / 2; break; case HorizontalContentAlignment.Right: target.X = target.Right - width; break; } switch (_verticalAlignment) { case VerticalContentAlignment.Center: target.Y = target.Center.Y - height / 2; break; case VerticalContentAlignment.Bottom: target.Y = target.Bottom - height; break; } target.Width = width; target.Height = height; drawBatch.DrawImage(image, target, textureSrc, color); } }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); SharedString str = _text != null ? _text : info.Text; float scale = _font.Scale; UniversalFont font = _font.Font; Color color = ColorFromState * info.Opacity * Opacity; Rectangle target = _margin.ComputeRect(info.Target); drawBatch.DrawText(font, str, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation); }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); float opacity; Matrix transform; _transitionPushed.Get(_reverse ? 1 - PushedState : PushedState, info.Target, info.Target, out transform, out opacity); drawBatch.PushTransform(transform); info.Opacity *= opacity; for (int idx = 0; idx < _drawables.Count; ++idx) { _drawables[idx].Draw(drawBatch, info); } drawBatch.PopTransform(); }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); SharedString str = _text != null ? _text : info.Text; float scale = _font.Scale; UniversalFont font = _font.Font; Color color = ColorFromState * info.Opacity * Opacity; Rectangle target = _margin.ComputeRect(info.Target); bool drawWithEllipsis = false; int ellipsisSize = _textRotation == TextRotation.Rotate90 || _textRotation == TextRotation.Rotate270 ? target.Height : target.Width; if (_pathEllipsis) { int length = (int)_font.MeasureString(str).X; if (length >= ellipsisSize) { drawWithEllipsis = true; } } if (drawWithEllipsis) { int cut = 3; while (drawWithEllipsis) { lock (str) { ComputeEllipsis(_stringBuilder, str.StringBuilder, cut); } int length = (int)_font.MeasureString(_stringBuilder).X; if (length < ellipsisSize) { break; } cut += 2; } drawBatch.DrawText(font, _stringBuilder, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation); } else if (_line >= 0) { _stringBuilder.Clear(); lock (str) { StringBuilder textStringBuilder = str.StringBuilder; int line = 0; for (int idx = 0; idx < textStringBuilder.Length; ++idx) { char character = textStringBuilder[idx]; if (character == '\n') { line++; if (line > _line) { break; } } if (character == '\r') { continue; } if (line == _line) { _stringBuilder.Append(textStringBuilder[idx]); } } } drawBatch.DrawText(font, _stringBuilder, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation); } else { drawBatch.DrawText(font, str, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation); } }
public override object OnAction(DrawButtonInfo info, params object[] parameters) { return(null); }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { Update(info.EllapsedTime, info.ButtonState); if (info.Icon == null) { return; } float scale = (float)UiUnit.Unit * _scale; float scaleX = scale; float scaleY = scale; Rectangle target = info.Target; Texture2D image = info.Icon; Rectangle bounds = _margin.ComputeRect(target); switch (_stretch) { case Stretch.Uniform: scaleX = scaleY = Math.Min((float)target.Width / (float)image.Width, (float)target.Height / (float)image.Height); break; case Stretch.UniformToFill: scaleX = scaleY = Math.Max((float)target.Width / (float)image.Width, (float)target.Height / (float)image.Height); break; case Stretch.Fill: scaleX = (float)target.Width / (float)image.Width; scaleY = (float)target.Height / (float)image.Height; break; } Color color = ColorFromState * info.Opacity * Opacity; Rectangle source = new Rectangle(0, 0, info.Icon.Width, info.Icon.Height); Vector2 size = new Vector2(source.Width * scaleX, source.Height * scaleY); target.Width = (int)size.X; target.Height = (int)size.Y; switch (_horzAlign) { case HorizontalContentAlignment.Center: case HorizontalContentAlignment.Auto: target.X = bounds.Center.X - target.Width / 2; break; case HorizontalContentAlignment.Left: target.X = bounds.X; break; case HorizontalContentAlignment.Right: target.X = bounds.Right - target.Width; break; } switch (_vertAlign) { case VerticalContentAlignment.Center: case VerticalContentAlignment.Auto: target.Y = bounds.Center.Y - target.Height / 2; break; case VerticalContentAlignment.Top: target.Y = bounds.Y; break; case VerticalContentAlignment.Bottom: target.Y = bounds.Bottom - target.Height; break; } drawBatch.DrawImage(info.Icon, target, source, color); }
public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info) { int carretPosition = info.Additional != null ? (int)info.Additional : -1; bool focused = false; Update(info.EllapsedTime, info.ButtonState); if (info.ButtonState.HasFlag(ButtonState.Checked) && carretPosition >= 0) { _flash += info.EllapsedTime * 2; _flash %= 2; focused = true; } else { _flash = 0; } SharedString str = info.Text; float scale = _font.Scale; UniversalFont font = _font.Font; Color color = ColorFromState * info.Opacity * Opacity; Rectangle target = _margin.ComputeRect(info.Target); float spacing = _font.Spacing; lock (str) { StringBuilder builder = str.StringBuilder; if (_flash > 1) { _string.Clear(); carretPosition = Math.Min(builder.Length, carretPosition); for (int idx = 0; idx < carretPosition; ++idx) { _string.Append(builder[idx]); } carretPosition = (int)(font.MeasureString(_string, spacing, 0) * scale).X; } _string.Clear(); _string.Append(builder); } Vector2 size = font.MeasureString(_string, spacing, 0) * scale; if (focused) { size.X += font.MeasureString("|", spacing).X *scale; } int positionX = target.X; if (size.X >= target.Width) { positionX = target.Right - (int)size.X; } else { switch (_textAlign & TextAlign.Horz) { case TextAlign.Right: positionX = target.Right - (int)size.X; break; case TextAlign.Center: positionX = target.Center.X - (int)size.X / 2; break; } } drawBatch.PushClip(target); target.X = positionX; drawBatch.DrawText(font, _string, target, _textAlign & TextAlign.Vert, color, spacing, 0, scale, TextRotation.None); if (_flash > 1) { target.X += carretPosition; drawBatch.DrawText(font, "|", target, _textAlign & TextAlign.Vert, color, spacing, 0, scale); } drawBatch.PopClip(); }