Forex_Strategy_Builder.Strategy.GetSlotType C# (CSharp) Method

GetSlotType() public method

Gets the type of the slot.
public GetSlotType ( int slot ) : SlotTypes
slot int
return SlotTypes
        public SlotTypes GetSlotType(int slot)
        {
            SlotTypes st = SlotTypes.NotDefined;

            if (slot == OpenSlot)
                st = SlotTypes.Open;
            else if (slot < CloseSlot)
                st = SlotTypes.OpenFilter;
            else if (slot == CloseSlot)
                st = SlotTypes.Close;
            else
                st = SlotTypes.CloseFilter;

            return st;
        }

Usage Example

示例#1
0
        /// <summary>
        /// Panel Slot Paint
        /// </summary>
        private void PnlSlotPaint(object sender, PaintEventArgs e)
        {
            var       pnl      = (ContextPanel)sender;
            Graphics  g        = e.Graphics;
            var       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;
            }

            var penBorder = new Pen(Data.GetGradientColor(colorCaptionBack, -LayoutColors.DepthCaption), Border);

            var   fontCaptionText     = new Font(Font.FontFamily, 9);
            float captionHeight       = Math.Max(fontCaptionText.Height, 18);
            float captionWidth        = width;
            Brush brushCaptionText    = new SolidBrush(colorCaptionText);
            var   stringFormatCaption = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Center
            };

            var rectfCaption = new RectangleF(0, 0, captionWidth, captionHeight);

            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);

            if (ShowRemoveSlotButtons && slot != _strategy.OpenSlot && slot != _strategy.CloseSlot)
            {
                int   buttonDimentions = (int)captionHeight - 2;
                int   buttonX          = width - buttonDimentions - 1;
                float captionTextWidth = g.MeasureString(stringCaptionText, fontCaptionText).Width;
                float captionTextX     = Math.Max((captionWidth - captionTextWidth) / 2f, 0);
                var   pfCaptionText    = new PointF(captionTextX, 0);
                var   sfCaptionText    = new SizeF(buttonX - captionTextX, captionHeight);
                rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);
                stringFormatCaption.Alignment = StringAlignment.Near;
            }
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption);

            // Border
            g.DrawLine(penBorder, 1, captionHeight, 1, pnl.Height);
            g.DrawLine(penBorder, pnl.Width - Border + 1, captionHeight, pnl.Width - Border + 1, pnl.Height);
            g.DrawLine(penBorder, 0, pnl.Height - Border + 1, pnl.Width, pnl.Height - Border + 1);

            // Paints the panel
            var rectfPanel = new RectangleF(Border, captionHeight, pnl.Width - 2 * Border,
                                            pnl.Height - captionHeight - Border);

            Data.GradientPaint(g, rectfPanel, colorBackground, LayoutColors.DepthControl);

            int vPosition = (int)captionHeight + 3;

            // Padlock image
            if (ShowPadlockImg)
            {
                if (_strategy.Slot[slot].SlotStatus == StrategySlotStatus.Locked)
                {
                    g.DrawImage(Resources.padlock_img, 1, 1, 16, 16);
                }
                else if (_strategy.Slot[slot].SlotStatus == StrategySlotStatus.Open)
                {
                    g.DrawImage(Resources.open_padlock, 1, 1, 16, 16);
                }
                else if (_strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked)
                {
                    g.DrawImage(Resources.linked, 1, 1, 16, 16);
                }
            }

            // Indicator name
            var stringFormatIndicatorName = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                FormatFlags   = StringFormatFlags.NoWrap
            };

            var   fontIndicator = new Font(Font.FontFamily, 11f, FontStyle.Regular);
            Brush brushIndName  = new SolidBrush(colorIndicatorNameText);
            float indNameHeight = 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;
                var rectGroup = new RectangleF(0, vPosition, fGroupWidth, indNameHeight);
                g.DrawString(sLogicalGroup, fontIndicator, brushIndName, rectGroup, stringFormatIndicatorName);
            }
            stringFormatIndicatorName.Trimming = StringTrimming.EllipsisCharacter;
            string indicatorName = _strategy.Slot[slot].IndicatorName;
            float  nameWidth     = g.MeasureString(indicatorName, fontIndicator).Width;

            RectangleF rectIndName = width >= 2 * fGroupWidth + nameWidth
                                         ? new RectangleF(0, vPosition, width, indNameHeight)
                                         : new RectangleF(fGroupWidth, vPosition, width - fGroupWidth, indNameHeight);

            g.DrawString(indicatorName, fontIndicator, brushIndName, rectIndName, stringFormatIndicatorName);
            vPosition += (int)indNameHeight;


            if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)
            {
                pnl.CloseButton.ColorBack = colorCaptionBack;
                pnl.CloseButton.ColorFore = colorCaptionText;
                pnl.CloseButton.Visible   = ShowRemoveSlotButtons;
            }

            if (SlotMinMidMax == SlotSizeMinMidMax.min)
            {
                return;
            }

            // Logic
            var stringFormatLogic = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoClip
            };
            float padding = Space;

            if (_strategy.Slot[slot].IndParam.ListParam[0].Enabled)
            {
                string value      = _strategy.Slot[slot].IndParam.ListParam[0].Text;
                var    fontLogic  = new Font(Font.FontFamily, 10.5f, FontStyle.Regular);
                SizeF  sizeValue  = g.MeasureString(value, fontLogic, (int)(width - 2 * padding), stringFormatLogic);
                var    rectValue  = new RectangleF(padding, vPosition, width - 2 * padding, sizeValue.Height);
                Brush  brushLogic = new SolidBrush(colorLogicText);

                g.DrawString(value, fontLogic, brushLogic, rectValue, stringFormatLogic);
                vPosition += (int)sizeValue.Height;
            }

            if (SlotMinMidMax == SlotSizeMinMidMax.mid)
            {
                return;
            }

            // Parameters
            var stringFormat = new StringFormat {
                Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap
            };
            var   fontParam  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            var   fontValue  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Brush brushParam = new SolidBrush(colorParamText);
            Brush brushValue = new SolidBrush(colorValueText);
            var   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 caption   = _strategy.Slot[slot].IndParam.ListParam[i].Caption;
                string value     = _strategy.Slot[slot].IndParam.ListParam[i].Text;
                SizeF  sizeParam = g.MeasureString(caption, fontParam);
                SizeF  sizeValue = g.MeasureString(value, 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 caption   = numericParam.Caption;
                string value     = numericParam.ValueToString;
                SizeF  sizeParam = g.MeasureString(caption, fontParam);
                SizeF  sizeValue = g.MeasureString(value, 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 Parameter Padding Dash Padding Value Padding
            const float dashWidth      = 5;
            float       necessaryWidth = 4 * padding + maxParamWidth + maxValueWidth + dashWidth;

            padding = width > necessaryWidth
                          ? Math.Max((pnl.ClientSize.Width - maxParamWidth - maxValueWidth - dashWidth) / 6, padding)
                          : 2;

            float tabParam = 2 * padding;
            float tabDash  = tabParam + maxParamWidth + padding;
            float tabValue = tabDash + dashWidth + padding;

            // List Parameters
            for (int i = 1; i < 5; i++)
            {
                if (!_strategy.Slot[slot].IndParam.ListParam[i].Enabled)
                {
                    continue;
                }

                string caption    = _strategy.Slot[slot].IndParam.ListParam[i].Caption;
                string value      = _strategy.Slot[slot].IndParam.ListParam[i].Text;
                var    pointParam = new PointF(tabParam, vPosition);
                var    pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(tabValue, vPosition);
                var    sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(caption, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(value, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height;
            }

            // Num Parameters
            foreach (NumericParam numericParam in _strategy.Slot[slot].IndParam.NumParam)
            {
                if (!numericParam.Enabled)
                {
                    continue;
                }

                string caption    = numericParam.Caption;
                string value      = numericParam.ValueToString;
                var    pointParam = new PointF(tabParam, vPosition);
                var    pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(tabValue, vPosition);
                var    sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(caption, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(value, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height;
            }

            // Check Parameters
            foreach (CheckParam checkParam in _strategy.Slot[slot].IndParam.CheckParam)
            {
                if (!checkParam.Enabled)
                {
                    continue;
                }

                string param      = checkParam.Caption;
                string salue      = checkParam.Checked ? "Yes" : "No";
                var    pointParam = new PointF(tabParam, vPosition);
                var    pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(tabValue, vPosition);
                var    sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectfValue = new RectangleF(pointValue, sizefValue);

                g.DrawString(param, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(salue, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height;
            }
        }
All Usage Examples Of Forex_Strategy_Builder.Strategy::GetSlotType