private static void SetState(UIRenderContext context, ThemeState state) { if (state != null) context.Data[StateId] = state; else context.Data.Remove(StateId); }
/// <summary> /// Gets the foreground with pre-multiplied alpha for the given opacity. /// </summary> private static Color GetForeground(UIControl control, ThemeState state, float opacity) { Color foreground = (state != null && state.Foreground.HasValue) ? state.Foreground.Value : control.Foreground; // Premultiply with alpha. return Color.FromNonPremultiplied(foreground.ToVector4() * new Vector4(1, 1, 1, opacity)); #else return ColorFromNonPremultiplied(foreground.ToVector4() * new Vector4(1, 1, 1, opacity)); }
/// <summary> /// RenderCallback for the style "ProgressBar". /// </summary> private void RenderProgressBar(UIControl control, UIRenderContext context) { // See comments of RenderSlider above. ThemeImage indicatorImage = null; ThemeState state = GetState(context); if (state != null) { foreach (var image in state.Images) { if (image.Name == "Indicator") indicatorImage = image; else if (!image.IsOverlay) RenderImage(GetActualBoundsRounded(control), image, context.Opacity, context.RenderTransform); } } ProgressBar bar = control as ProgressBar; if (indicatorImage != null && bar != null) { RectangleF indicatorBounds = GetContentBoundsRounded(bar); // Render indicator. if (!bar.IsIndeterminate) { indicatorBounds.Width = (int)((bar.Value - bar.Minimum) / (bar.Maximum - bar.Minimum) * indicatorBounds.Width); } else { // In indeterminate mode the indicator is 1/4 wide and moves left and right. float width = indicatorBounds.Width / 4.0f; float range = width * 3; float center = indicatorBounds.X + width / 2 + (bar.Value - bar.Minimum) / (bar.Maximum - bar.Minimum) * range; indicatorBounds.X = (int)(center - width / 2); indicatorBounds.Width = (int)(width); } if (indicatorBounds.Width > 0 && indicatorBounds.Height > 0) RenderImage(indicatorBounds, indicatorImage, context.Opacity, context.RenderTransform); } foreach (var child in control.VisualChildren) child.Render(context); RenderImages(control, context, true); }
/// <summary> /// RenderCallback for the style "Slider". /// </summary> private void RenderSlider(UIControl control, UIRenderContext context) { // Special: An image with the name "Indicator" is drawn from the left up to the slider // position. ThemeImage indicatorImage = null; ThemeState state = GetState(context); if (state != null) { // Background images - except the image called "Indicator". foreach (var image in state.Images) { if (image.Name == "Indicator") indicatorImage = image; else if (!image.IsOverlay) RenderImage(GetActualBoundsRounded(control), image, context.Opacity, context.RenderTransform); } } // Render indicator image. Slider slider = control as Slider; if (indicatorImage != null && slider != null) { RectangleF indicatorBounds = GetContentBoundsRounded(slider); // Size of indicator image depends on the slider value. indicatorBounds.Width = (int)((slider.Value - slider.Minimum)/ (slider.Maximum - slider.Minimum) * indicatorBounds.Width); if (indicatorBounds.Width > 0 && indicatorBounds.Height > 0) RenderImage(indicatorBounds, indicatorImage, context.Opacity, context.RenderTransform); } // Visual children. foreach (var child in control.VisualChildren) child.Render(context); // Overlay images. RenderImages(control, context, true); }
/// <summary> /// Gets the effective opacity (the product of the opacities of all visual ancestors). /// </summary> private static float GetOpacity(UIControl control, UIRenderContext context, ThemeState state) { float opacity = (state != null && state.Opacity.HasValue) ? state.Opacity.Value : control.Opacity; return opacity * context.Opacity; }