Consolidation of ballooning colours.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2021-04-30 12:34:20 +01:00
parent 0fc835a194
commit 13cd1998b8
9 changed files with 54 additions and 135 deletions

View File

@ -1,51 +0,0 @@
/* Copyright (c) Citrix Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System.Drawing;
namespace XenAdmin.Controls.Ballooning
{
public static class BallooningColors
{
public static Color VMShinyBar_Used = Color.ForestGreen;
public static Color VMShinyBar_Unused = Color.Black;
public static Color VMShinyBar_Text = Color.White;
public static Color HostShinyBar_Xen = Color.DarkGray;
public static Color HostShinyBar_ControlDomain = Color.DimGray;
public static Color[] HostShinyBar_VMs = { Color.MidnightBlue, Color.SteelBlue };
public static Color HostShinyBar_Unused = Color.Black;
public static Color HostShinyBar_Text = Color.White;
public static Color Grid = Color.DarkGray;
public static Color SliderLimits = Color.LightGray;
}
}

View File

@ -29,12 +29,8 @@
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using XenAdmin.Core;
using XenAPI;
@ -82,10 +78,10 @@ namespace XenAdmin.Controls.Ballooning
// A bar for Xen memory
double left = (double)barArea.Left;
DrawSegment(g, xen_memory - dom0_memory, bytesPerPixel, BrandManager.ProductBrand, null, BallooningColors.HostShinyBar_Xen, ref left);
DrawSegment(g, xen_memory - dom0_memory, bytesPerPixel, BrandManager.ProductBrand, null, HostShinyBar_Xen, ref left);
// A bar for Dom0 memory
DrawSegment(g, dom0_memory, bytesPerPixel, string.Format(Messages.CONTROL_DOM_ON_HOST, host.Name()), null, BallooningColors.HostShinyBar_ControlDomain, ref left);
DrawSegment(g, dom0_memory, bytesPerPixel, string.Format(Messages.CONTROL_DOM_ON_HOST, host.Name()), null, HostShinyBar_ControlDomain, ref left);
// A bar for each VM
int i = 0;
@ -99,14 +95,14 @@ namespace XenAdmin.Controls.Ballooning
if (metrics != null)
{
DrawSegment(g, metrics.memory_actual, bytesPerPixel, vm.Name(), vm,
BallooningColors.HostShinyBar_VMs[i++ % BallooningColors.HostShinyBar_VMs.Length],
HostShinyBar_VMs[i++ % HostShinyBar_VMs.Length],
ref left);
}
}
// One final bar for free space
Rectangle rectFree = new Rectangle((int)left, barArea.Top, barArea.Right - (int)left, barArea.Height);
DrawToTarget(g, barArea, rectFree, BallooningColors.HostShinyBar_Unused);
DrawToTarget(g, barArea, rectFree, ShinyBar_Unused);
}
private void DrawSegment(Graphics g, long mem, double bytesPerPixel, string name, VM vm, Color color, ref double left)
@ -136,16 +132,10 @@ namespace XenAdmin.Controls.Ballooning
Messages.DYNAMIC_MAX, Util.MemorySizeStringSuitableUnits(vm.memory_dynamic_max, true),
Messages.STATIC_MAX, Util.MemorySizeStringSuitableUnits(vm.memory_static_max, true));
}
DrawToTarget(g, barArea, rect, color, caption, BallooningColors.HostShinyBar_Text, HorizontalAlignment.Center, toolTip);
DrawToTarget(g, barArea, rect, color, caption, ShinyBar_Text, HorizontalAlignment.Center, toolTip);
left += width;
}
protected override int barHeight
{
get
{
return 40;
}
}
protected override int barHeight => 40;
}
}

View File

@ -34,7 +34,6 @@ using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using XenAdmin.Core;
@ -44,7 +43,6 @@ namespace XenAdmin.Controls.Ballooning
public partial class ShinyBar : UserControl
{
private static readonly Font font = new Font("Segoe UI", 9);
//private static readonly Font font = FormFontFixer.DefaultFont;
private const int radius = 5;
private const int pad = 2;
private const int TEXT_PAD = 3;
@ -60,6 +58,19 @@ namespace XenAdmin.Controls.Ballooning
private string toolTipText;
private bool ignoreNextOnMouseMove;
//palette
protected Color VMShinyBar_Used = Color.ForestGreen;
protected Color HostShinyBar_Xen = Color.DarkGray;
protected Color HostShinyBar_ControlDomain = Color.DimGray;
protected Color[] HostShinyBar_VMs = { Color.MidnightBlue, Color.SteelBlue };
protected Color[] GpuShinyBar_VMs = { Color.FromArgb(83, 39, 139), Color.FromArgb(157, 115, 215) };
protected Color ShinyBar_Unused = Color.Black;
protected Color ShinyBar_Text = Color.White;
protected Color Grid = Color.DarkGray;
protected Color SliderLimits = Color.LightGray;
private readonly Func<Color, Color> _colorTransformer = ControlPaint.LightLight;
public ShinyBar()
{
InitializeComponent();
@ -90,7 +101,7 @@ namespace XenAdmin.Controls.Ballooning
// Outer rounded rectangle
{
Color topColor = color;
Color bottomColor = ControlPaint.LightLight(color);
Color bottomColor = _colorTransformer(color);
using (LinearGradientBrush outerBrush = new LinearGradientBrush(barBounds, topColor, bottomColor, LinearGradientMode.Vertical))
{
g.FillPath(outerBrush, outerPath);
@ -210,7 +221,7 @@ namespace XenAdmin.Controls.Ballooning
return path;
}
protected static void DrawGrid(Graphics g, Rectangle barArea, double bytesPerPixel, double max)
protected void DrawGrid(Graphics g, Rectangle barArea, double bytesPerPixel, double max)
{
const int min_gap = 40; // min gap between consecutive labels (which are on alternate ticks)
const int line_height = 12;
@ -231,7 +242,7 @@ namespace XenAdmin.Controls.Ballooning
incr *= 2;
// Draw the grid
using (Pen pen = new Pen(BallooningColors.Grid))
using (Pen pen = new Pen(Grid))
{
bool withLabel = true;
for (long x = 0; x <= max; x += incr)
@ -249,7 +260,7 @@ namespace XenAdmin.Controls.Ballooning
if (LabelShouldBeShown(max, label, x))
{
Drawing.DrawText(g, label, Program.DefaultFont, rect, BallooningColors.Grid, Color.Transparent);
Drawing.DrawText(g, label, Program.DefaultFont, rect, Grid, Color.Transparent);
}
}
withLabel = !withLabel;

View File

@ -60,8 +60,6 @@ namespace XenAdmin.Controls.Ballooning
// memoryRowLabel
//
resources.ApplyResources(this.memoryRowLabel, "memoryRowLabel");
this.memoryRowLabel.BackColor = System.Drawing.Color.Gainsboro;
this.memoryRowLabel.MinimumSize = new System.Drawing.Size(0, 26);
this.memoryRowLabel.Name = "memoryRowLabel";
this.memoryRowLabel.SizeChanged += new System.EventHandler(this.memoryRowLabel_SizeChanged);
//
@ -73,7 +71,6 @@ namespace XenAdmin.Controls.Ballooning
this.Controls.Add(this.panelControls);
this.Controls.Add(this.panelLabel);
this.DoubleBuffered = true;
this.MinimumSize = new System.Drawing.Size(700, 0);
this.Name = "VMMemoryRow";
this.panelControls.ResumeLayout(false);
this.panelLabel.ResumeLayout(false);

View File

@ -112,29 +112,32 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="panelControls.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
</data>
<data name="vmMemoryControls.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left, Right</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="vmMemoryControls.Location" type="System.Drawing.Point, System.Drawing">
<value>1, 1</value>
</data>
<data name="vmMemoryControls.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>0, 0, 0, 0</value>
</data>
<data name="vmMemoryControls.MinimumSize" type="System.Drawing.Size, System.Drawing">
<value>700, 90</value>
</data>
<data name="vmMemoryControls.Size" type="System.Drawing.Size, System.Drawing">
<value>786, 90</value>
</data>
<assembly alias="mscorlib" name="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="vmMemoryControls.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
@ -186,6 +189,9 @@
<data name="memoryRowLabel.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>0, 0, 0, 0</value>
</data>
<data name="memoryRowLabel.MinimumSize" type="System.Drawing.Size, System.Drawing">
<value>0, 26</value>
</data>
<data name="memoryRowLabel.Padding" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>10, 5, 10, 5</value>
</data>
@ -231,7 +237,7 @@
<data name="&gt;&gt;panelLabel.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
@ -240,6 +246,9 @@
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>0, 0, 0, 0</value>
</data>
<data name="$this.MinimumSize" type="System.Drawing.Size, System.Drawing">
<value>700, 0</value>
</data>
<data name="$this.Size" type="System.Drawing.Size, System.Drawing">
<value>788, 119</value>
</data>
@ -247,6 +256,6 @@
<value>VMMemoryRow</value>
</data>
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>System.Windows.Forms.UserControl, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
</root>

View File

@ -61,20 +61,11 @@ namespace XenAdmin.Controls.Ballooning
[Browsable(false)]
public double Increment { get; set; }
public double Dynamic_min
{
get { return dynamic_min; }
}
public double Dynamic_min => dynamic_min;
public double Dynamic_max
{
get { return dynamic_max; }
}
public double Dynamic_max => dynamic_max;
private bool Equal
{
get { return Dynamic_min == Dynamic_max; }
}
private bool Equal => Dynamic_min == Dynamic_max;
public void SetRanges(double dynamic_min_lowlimit, double dynamic_min_highlimit, double dynamic_max_lowlimit, double dynamic_max_highlimit, string units)
{
@ -225,10 +216,10 @@ namespace XenAdmin.Controls.Ballooning
Rectangle rect = new Rectangle(barArea.Left, barArea.Top, left_width, barArea.Height);
string bytesString = Util.MemorySizeStringSuitableUnits(memoryUsed, false);
string toolTip = string.Format(multiple ? Messages.CURRENT_MEMORY_USAGE_MULTIPLE : Messages.CURRENT_MEMORY_USAGE, bytesString);
DrawToTarget(g, barArea, rect, BallooningColors.VMShinyBar_Used, bytesString, BallooningColors.VMShinyBar_Text, HorizontalAlignment.Right, toolTip);
DrawToTarget(g, barArea, rect, VMShinyBar_Used, bytesString, ShinyBar_Text, HorizontalAlignment.Right, toolTip);
rect = new Rectangle(barArea.Left + left_width, barArea.Top, barArea.Width - left_width, barArea.Height);
DrawToTarget(g, barArea, rect, BallooningColors.VMShinyBar_Unused);
DrawToTarget(g, barArea, rect, ShinyBar_Unused);
// Sliders
@ -339,7 +330,7 @@ namespace XenAdmin.Controls.Ballooning
int min = barArea.Left + (int)(SliderMinLimit / BytesPerPixel);
int max = barArea.Left + (int)(SliderMaxLimit / BytesPerPixel);
using (Brush brush = new SolidBrush(BallooningColors.SliderLimits))
using (Brush brush = new SolidBrush(SliderLimits))
{
g.FillRectangle(brush, min, barRect.Bottom, max - min, Height);
}
@ -388,12 +379,6 @@ namespace XenAdmin.Controls.Ballooning
g.DrawImageUnscaled(max_image, max_pt);
}
protected override int barHeight
{
get
{
return 20;
}
}
protected override int barHeight => 20;
}
}

View File

@ -211,7 +211,7 @@
private System.Windows.Forms.Button clearAllButton;
private System.Windows.Forms.Button selectAllButton;
private PanelWithBorder panelWithBorder;
protected System.Windows.Forms.Panel multipleSelectionPanel;
private System.Windows.Forms.Panel multipleSelectionPanel;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button editButton;
}

View File

@ -103,14 +103,14 @@ namespace XenAdmin.Controls.GPU
var vGpuType = PGPU.Connection.Resolve(vgpu.type);
DrawSegment(g, segmentLength, vm.Name(), vGpuType != null ? vGpuType.model_name : "",
GpuShinyBarColors.GpuShinyBar_VMs[i++ % GpuShinyBarColors.GpuShinyBar_VMs.Length],
GpuShinyBar_VMs[i++ % GpuShinyBar_VMs.Length],
ref left);
}
}
// One final bar for free space
Rectangle rectFree = new Rectangle((int)left, barArea.Top, barArea.Right - (int)left, barArea.Height);
DrawToTarget(g, barArea, rectFree, GpuShinyBarColors.GpuShinyBar_Unused);
DrawToTarget(g, barArea, rectFree, ShinyBar_Unused);
}
private void DrawGrid(Graphics g, Rectangle barArea, long max)
@ -123,7 +123,7 @@ namespace XenAdmin.Controls.GPU
long incr = max / (capacity > 0 ? capacity : maxCapacity);
// Draw the grid
using (Pen pen = new Pen(GpuShinyBarColors.Grid))
using (Pen pen = new Pen(Grid))
{
for (long x = 0; x <= max; x += incr)
{
@ -143,33 +143,12 @@ namespace XenAdmin.Controls.GPU
(int)(left + width) - (int)left, // this is not necessarily the same as (int)width, which can leave a 1 pixel gap
barRect.Height);
var caption = name + "\n" + description;
DrawToTarget(g, barRect, rect, color, caption, GpuShinyBarColors.GpuShinyBar_Text, HorizontalAlignment.Center, caption);
DrawToTarget(g, barRect, rect, color, caption, ShinyBar_Text, HorizontalAlignment.Center, caption);
left += width;
}
protected override int barHeight
{
get
{
return 40;
}
}
protected override int barHeight => 40;
protected override Rectangle barRect
{
get
{
return new Rectangle(10, 20, this.Width - 25, barHeight);
}
}
}
public static class GpuShinyBarColors
{
public static Color[] GpuShinyBar_VMs = { Color.FromArgb(83, 39, 139), Color.FromArgb(157, 115, 215) };
public static Color GpuShinyBar_Unused = Color.Black;
public static Color GpuShinyBar_Text = Color.White;
public static Color Grid = Color.DarkGray;
protected override Rectangle barRect => new Rectangle(10, 20, this.Width - 25, barHeight);
}
}

View File

@ -141,7 +141,6 @@
<Compile Include="Controls\AffinityPicker.Designer.cs">
<DependentUpon>AffinityPicker.cs</DependentUpon>
</Compile>
<Compile Include="Controls\Ballooning\BallooningColors.cs" />
<Compile Include="Controls\Ballooning\MemorySpinner.cs">
<SubType>UserControl</SubType>
</Compile>