void PnlSlot_Paint(object sender, PaintEventArgs e)
{
Panel pnl = (Panel)sender;
Graphics g = e.Graphics;
int slot = (int)pnl.Tag;
int width = pnl.ClientSize.Width;
SlotTypes slotType = strategy.GetSlotType(slot);
Color colorBackground = LayoutColors.ColorSlotBackground;
Color colorCaptionText = LayoutColors.ColorSlotCaptionText;
Color colorCaptionBackOpen = LayoutColors.ColorSlotCaptionBackOpen;
Color colorCaptionBackOpenFilter = LayoutColors.ColorSlotCaptionBackOpenFilter;
Color colorCaptionBackClose = LayoutColors.ColorSlotCaptionBackClose;
Color colorCaptionBackCloseFilter = LayoutColors.ColorSlotCaptionBackCloseFilter;
Color colorIndicatorNameText = LayoutColors.ColorSlotIndicatorText;
Color colorLogicText = LayoutColors.ColorSlotLogicText;
Color colorParamText = LayoutColors.ColorSlotParamText;
Color colorValueText = LayoutColors.ColorSlotValueText;
Color colorDash = LayoutColors.ColorSlotDash;
// Caption
string stringCaptionText = string.Empty;
Color colorCaptionBack = LayoutColors.ColorSignalRed;
switch (slotType)
{
case SlotTypes.Open:
stringCaptionText = Language.T("Opening Point of the Position");
colorCaptionBack = colorCaptionBackOpen;
break;
case SlotTypes.OpenFilter:
stringCaptionText = Language.T("Opening Logic Condition");
colorCaptionBack = colorCaptionBackOpenFilter;
break;
case SlotTypes.Close:
stringCaptionText = Language.T("Closing Point of the Position");
colorCaptionBack = colorCaptionBackClose;
break;
case SlotTypes.CloseFilter:
stringCaptionText = Language.T("Closing Logic Condition");
colorCaptionBack = colorCaptionBackCloseFilter;
break;
default:
break;
}
Pen penBorder = new Pen(Data.GetGradientColor(colorCaptionBack, -LayoutColors.DepthCaption), border);
Font fontCaptionText = new Font(Font.FontFamily, 9);
float fCaptionHeight = (float)Math.Max(fontCaptionText.Height, 18);
float fCaptionWidth = width;
Brush brushCaptionText = new SolidBrush(colorCaptionText);
StringFormat stringFormatCaption = new StringFormat();
stringFormatCaption.LineAlignment = StringAlignment.Center;
stringFormatCaption.Trimming = StringTrimming.EllipsisCharacter;
stringFormatCaption.FormatFlags = StringFormatFlags.NoWrap;
stringFormatCaption.Alignment = StringAlignment.Center;
RectangleF rectfCaption = new RectangleF(0, 0, fCaptionWidth, fCaptionHeight);
Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);
if (showRemoveSlotButtons && slot != strategy.OpenSlot && slot != strategy.CloseSlot)
{
int iButtonDimentions = (int)fCaptionHeight - 2;
int iButtonX = width - iButtonDimentions - 1;
abtnRemoveSlot[slot].Size = new Size(iButtonDimentions, iButtonDimentions);
abtnRemoveSlot[slot].Location = new Point(iButtonX, 1);
float fCaptionTextWidth = g.MeasureString(stringCaptionText, fontCaptionText).Width;
float fCaptionTextX = (float)Math.Max((fCaptionWidth - fCaptionTextWidth) / 2f, 0);
PointF pfCaptionText = new PointF(fCaptionTextX, 0);
SizeF sfCaptionText = new SizeF(iButtonX - fCaptionTextX, fCaptionHeight);
rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);
stringFormatCaption.Alignment = StringAlignment.Near;
}
g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption);
// Border
g.DrawLine(penBorder, 1, fCaptionHeight, 1, pnl.Height);
g.DrawLine(penBorder, pnl.Width - border + 1, fCaptionHeight, pnl.Width - border + 1, pnl.Height);
g.DrawLine(penBorder, 0, pnl.Height - border + 1, pnl.Width, pnl.Height - border + 1);
// Paints the panel
RectangleF rectfPanel = new RectangleF(border, fCaptionHeight, pnl.Width - 2 * border, pnl.Height - fCaptionHeight - border);
Data.GradientPaint(g, rectfPanel, colorBackground, LayoutColors.DepthControl);
int iVPosition = (int)fCaptionHeight + 3;
// Padlock image
if (showPadlockImg)
{
if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Locked)
g.DrawImage(Properties.Resources.padlock_img, 1, 1, 16, 16);
else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Open)
g.DrawImage(Properties.Resources.open_padlock, 1, 1, 16, 16);
else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked)
g.DrawImage(Properties.Resources.linked, 1, 1, 16, 16);
}
// Indicator name
StringFormat stringFormatIndicatorName = new StringFormat();
stringFormatIndicatorName.Alignment = StringAlignment.Center;
stringFormatIndicatorName.LineAlignment = StringAlignment.Center;
stringFormatIndicatorName.FormatFlags = StringFormatFlags.NoWrap;
Font fontIndicator = new Font(Font.FontFamily, 11f, FontStyle.Regular);
Brush brushIndName = new SolidBrush(colorIndicatorNameText);
float fIndNameHeight = fontIndicator.Height;
float fGroupWidth = 0;
if (Configs.UseLogicalGroups && (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter))
{
string sLogicalGroup = "[" + strategy.Slot[slot].LogicalGroup + "]";
fGroupWidth = g.MeasureString(sLogicalGroup, fontIndicator).Width;
RectangleF rectGroup = new RectangleF(0, iVPosition, fGroupWidth, fIndNameHeight);
g.DrawString(sLogicalGroup, fontIndicator, brushIndName, rectGroup, stringFormatIndicatorName);
}
stringFormatIndicatorName.Trimming = StringTrimming.EllipsisCharacter;
string sIndicatorName = strategy.Slot[slot].IndicatorName;
float fIndicatorWidth = g.MeasureString(sIndicatorName, fontIndicator).Width;
RectangleF rectIndName;
if (width >= 2 * fGroupWidth + fIndicatorWidth)
rectIndName = new RectangleF(0, iVPosition, width, fIndNameHeight);
else
rectIndName = new RectangleF(fGroupWidth, iVPosition, width - fGroupWidth, fIndNameHeight);
g.DrawString(sIndicatorName, fontIndicator, brushIndName, rectIndName, stringFormatIndicatorName);
iVPosition += (int)fIndNameHeight;
if (slotMinMidMax == SlotSizeMinMidMax.min)
return;
// Logic
StringFormat stringFormatLogic = new StringFormat();
stringFormatLogic.Alignment = StringAlignment.Center;
stringFormatLogic.LineAlignment = StringAlignment.Center;
stringFormatLogic.Trimming = StringTrimming.EllipsisCharacter;
stringFormatLogic.FormatFlags = StringFormatFlags.NoClip;
float padding = space;
if (strategy.Slot[slot].IndParam.ListParam[0].Enabled)
{
string sValue = strategy.Slot[slot].IndParam.ListParam[0].Text;
Font fontLogic = new Font(Font.FontFamily, 10.5f, FontStyle.Regular);
SizeF sizeValue = g.MeasureString(sValue, fontLogic, (int)(width - 2 * padding), stringFormatLogic);
RectangleF rectValue = new RectangleF(padding, iVPosition, width - 2 * padding, sizeValue.Height);
Brush brushLogic = new SolidBrush(colorLogicText);
g.DrawString(sValue, fontLogic, brushLogic, rectValue, stringFormatLogic);
iVPosition += (int)sizeValue.Height;
}
if (slotMinMidMax == SlotSizeMinMidMax.mid)
return;
// Parameters
StringFormat stringFormat = new StringFormat();
stringFormat.Trimming = StringTrimming.EllipsisCharacter;
stringFormat.FormatFlags = StringFormatFlags.NoWrap;
Font fontParam = new Font(Font.FontFamily, 9f, FontStyle.Regular);
Font fontValue = new Font(Font.FontFamily, 9f, FontStyle.Regular);
Brush brushParam = new SolidBrush(colorParamText);
Brush brushValue = new SolidBrush(colorValueText);
Pen penDash = new Pen(colorDash);
// Find Maximum width of the strings
float maxParamWidth = 0;
float maxValueWidth = 0;
for (int i = 1; i < 5; i++)
{
if (!strategy.Slot[slot].IndParam.ListParam[i].Enabled)
continue;
string sParam = strategy.Slot[slot].IndParam.ListParam[i].Caption;
string sValue = strategy.Slot[slot].IndParam.ListParam[i].Text;
SizeF sizeParam = g.MeasureString(sParam, fontParam);
SizeF sizeValue = g.MeasureString(sValue, fontValue);
if (maxParamWidth < sizeParam.Width)
maxParamWidth = sizeParam.Width;
if (maxValueWidth < sizeValue.Width)
maxValueWidth = sizeValue.Width;
}
foreach (NumericParam numericParam in strategy.Slot[slot].IndParam.NumParam)
{
if (!numericParam.Enabled) continue;
string sParam = numericParam.Caption;
string sValue = numericParam.ValueToString;
SizeF sizeParam = g.MeasureString(sParam, fontParam);
SizeF sizeValue = g.MeasureString(sValue, fontValue);
if (maxParamWidth < sizeParam.Width)
maxParamWidth = sizeParam.Width;
if (maxValueWidth < sizeValue.Width)
maxValueWidth = sizeValue.Width;
}
foreach (CheckParam checkParam in strategy.Slot[slot].IndParam.CheckParam)
{
if (!checkParam.Enabled) continue;
string param = checkParam.Caption;
string value = checkParam.Checked ? "Yes" : "No";
SizeF sizeParam = g.MeasureString(param, fontParam);
SizeF sizeValue = g.MeasureString(value, fontValue);
if (maxParamWidth < sizeParam.Width)
maxParamWidth = sizeParam.Width;
if (maxValueWidth < sizeValue.Width)
maxValueWidth = sizeValue.Width;
}
// Padding Param Padding Dash Padding Value Padding
float dashWidth = 5;
float necessaryWidth = 4 * padding + maxParamWidth + maxValueWidth + dashWidth;
if (width > necessaryWidth)
{ // 2*Padding Param Padding Dash Padding Value 2*Padding
padding = (float)Math.Max((pnl.ClientSize.Width - maxParamWidth - maxValueWidth - dashWidth) / 6, padding);
}
else
{
padding = 2;
}
float tabParam = 2 * padding;
float tabDash = tabParam + maxParamWidth + padding;
float tabValue = tabDash + dashWidth + padding;
// List Params
for (int i = 1; i < 5; i++)
{
if (!strategy.Slot[slot].IndParam.ListParam[i].Enabled)
continue;
string sParam = strategy.Slot[slot].IndParam.ListParam[i].Caption;
string sValue = strategy.Slot[slot].IndParam.ListParam[i].Text;
PointF pointParam = new PointF(tabParam, iVPosition);
PointF pointDash1 = new PointF(tabDash, iVPosition + fontParam.Height / 2 + 2);
PointF pointDash2 = new PointF(tabDash + dashWidth, iVPosition + fontParam.Height / 2 + 2);
PointF pointValue = new PointF(tabValue, iVPosition);
SizeF sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
RectangleF rectfValue = new RectangleF(pointValue, sizefValue);
g.DrawString(sParam, fontParam, brushParam, pointParam);
g.DrawLine(penDash, pointDash1, pointDash2);
g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
iVPosition += fontValue.Height;
}
// Num Params
foreach (NumericParam numericParam in strategy.Slot[slot].IndParam.NumParam)
{
if (!numericParam.Enabled) continue;
string sParam = numericParam.Caption;
string sValue = numericParam.ValueToString;
PointF pointParam = new PointF(tabParam, iVPosition);
PointF pointDash1 = new PointF(tabDash, iVPosition + fontParam.Height / 2 + 2);
PointF pointDash2 = new PointF(tabDash + dashWidth, iVPosition + fontParam.Height / 2 + 2);
PointF pointValue = new PointF(tabValue, iVPosition);
SizeF sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
RectangleF rectfValue = new RectangleF(pointValue, sizefValue);
g.DrawString(sParam, fontParam, brushParam, pointParam);
g.DrawLine(penDash, pointDash1, pointDash2);
g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
iVPosition += fontValue.Height;
}
// Check Params
foreach (CheckParam checkParam in strategy.Slot[slot].IndParam.CheckParam)
{
if (!checkParam.Enabled) continue;
string param = checkParam.Caption;
string salue = checkParam.Checked ? "Yes" : "No";
PointF pointParam = new PointF(tabParam, iVPosition);
PointF pointDash1 = new PointF(tabDash, iVPosition + fontParam.Height / 2 + 2);
PointF pointDash2 = new PointF(tabDash + dashWidth, iVPosition + fontParam.Height / 2 + 2);
PointF pointValue = new PointF(tabValue, iVPosition);
SizeF sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
RectangleF rectfValue = new RectangleF(pointValue, sizefValue);
g.DrawString(param, fontParam, brushParam, pointParam);
g.DrawLine(penDash, pointDash1, pointDash2);
g.DrawString(salue, fontValue, brushValue, rectfValue, stringFormat);
iVPosition += fontValue.Height;
}
return;
}