/// <summary>
        /// Measures a couple of items and prepares them for being drawn.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="font">Font used.</param>
        /// <param name="strfmt">String format used.</param>
        /// <param name="items">Array of items to be drawn.</param>
        /// <returns>An array of <see cref="IMeasuredLabelItem" /> that can be used to determine the size of each item and to draw it.</returns>
        public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, System.Drawing.StringFormat strfmt, AltaxoVariant[] items)
        {
            string[] titems = FormatItems(items);
            if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix))
            {
                for (int i = 0; i < titems.Length; ++i)
                {
                    titems[i] = _prefix + titems[i] + _suffix;
                }
            }

            var litems = new MeasuredLabelItem[titems.Length];

            FontX localfont   = font;
            var   localstrfmt = (StringFormat)strfmt.Clone();

            StringAlignment horizontalAlignment = localstrfmt.Alignment;
            StringAlignment verticalAlignment   = localstrfmt.LineAlignment;

            localstrfmt.Alignment     = StringAlignment.Near;
            localstrfmt.LineAlignment = StringAlignment.Near;

            for (int i = 0; i < titems.Length; ++i)
            {
                litems[i] = new MeasuredLabelItem(g, localfont, localstrfmt, titems[i], _relativeLineSpacing, horizontalAlignment, verticalAlignment, _textBlockAlignment);
            }

            return(litems);
        }
Beispiel #2
0
 public Entry(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
 {
     this.s               = s;
     this.font            = (Font)font.Clone();      // An owner could possibly call Dispose()!
     this.brush           = (Brush)brush.Clone();
     this.layoutRectangle = layoutRectangle;
     this.format          = (StringFormat)format.Clone();
 }
Beispiel #3
0
        public static SizeF MeasureString(Graphics g, string str, Font font, Rectangle rect, StringFormat sf)
        {
            var sfTemp = sf.Clone() as StringFormat;
            var ranges = new CharacterRange[] { new CharacterRange(0, str.Length) };
            sfTemp.SetMeasurableCharacterRanges(ranges);

            var regions = g.MeasureCharacterRanges(str, font, rect, sfTemp);
            if (regions != null && regions.Length > 0) return regions[0].GetBounds(g).Size;
            return new SizeF();
        }
Beispiel #4
0
        /// <summary>
        /// Measured a couple of items and prepares them for being drawn.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="font">Font used.</param>
        /// <param name="strfmt">String format used.</param>
        /// <param name="items">Array of items to be drawn.</param>
        /// <returns>An array of <see cref="IMeasuredLabelItem" /> that can be used to determine the size of each item and to draw it.</returns>
        public virtual IMeasuredLabelItem[] GetMeasuredItems(Graphics g, System.Drawing.Font font, System.Drawing.StringFormat strfmt, AltaxoVariant[] items)
        {
            string[] titems = FormatItems(items);

            MeasuredLabelItem[] litems = new MeasuredLabelItem[titems.Length];

            Font         localfont   = (Font)font.Clone();
            StringFormat localstrfmt = (StringFormat)strfmt.Clone();

            for (int i = 0; i < titems.Length; ++i)
            {
                litems[i] = new MeasuredLabelItem(g, localfont, localstrfmt, titems[i]);
            }

            return(litems);
        }
Beispiel #5
0
        public void DrawTextLayout(object backend, TextLayout layout, double x, double y)
        {
            var   c       = (DrawingContext)backend;
            Size  measure = layout.GetSize();
            float h       = layout.Height > 0 ? (float)layout.Height : (float)measure.Height;

            System.Drawing.StringFormat stringFormat = TextLayoutContext.StringFormat;
            StringTrimming trimming = layout.Trimming.ToDrawingStringTrimming();

            if (layout.Height > 0 && stringFormat.Trimming != trimming)
            {
                stringFormat          = (System.Drawing.StringFormat)stringFormat.Clone();
                stringFormat.Trimming = trimming;
            }

            c.Graphics.DrawString(layout.Text, layout.Font.ToDrawingFont(), c.Brush,
                                  new RectangleF((float)x, (float)y, (float)measure.Width, h),
                                  stringFormat);
        }
Beispiel #6
0
        /// <summary>
        /// Measures a couple of items and prepares them for being drawn.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="font">Font used.</param>
        /// <param name="strfmt">String format used.</param>
        /// <param name="items">Array of items to be drawn.</param>
        /// <returns>An array of <see cref="IMeasuredLabelItem" /> that can be used to determine the size of each item and to draw it.</returns>
        public virtual IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, System.Drawing.StringFormat strfmt, AltaxoVariant[] items)
        {
            string[] titems = FormatItems(items);
            if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix))
            {
                for (int i = 0; i < titems.Length; ++i)
                {
                    titems[i] = _prefix + titems[i] + _suffix;
                }
            }

            var litems = new MeasuredLabelItem[titems.Length];

            FontX localfont   = font;
            var   localstrfmt = (StringFormat)strfmt.Clone();

            for (int i = 0; i < titems.Length; ++i)
            {
                litems[i] = new MeasuredLabelItem(g, localfont, localstrfmt, titems[i]);
            }

            return(litems);
        }
        private void HighlightString(Graphics g, PageText dtext, RectangleF r, Font f, StringFormat sf)
        {
            if (_HighlightText == null || _HighlightText.Length == 0)
                return;         // nothing to highlight
            bool bhighlightItem = dtext == _HighlightItem ||
                    (_HighlightItem != null && dtext.HtmlParent == _HighlightItem);
            if (!(_HighlightAll || bhighlightItem))
                return;         // not highlighting all and not on current highlight item

            string hlt = _HighlightCaseSensitive ? _HighlightText : _HighlightText.ToLower();
            string text = _HighlightCaseSensitive ? dtext.Text : dtext.Text.ToLower();

            if (text.IndexOf(hlt) < 0)
                return;         // string not in text

            StringFormat sf2 = null;
            try
            {
                // Create a CharacterRange array with the highlight location and length
                // Handle multiple occurences of text
                List<CharacterRange> rangel = new List<CharacterRange>();
                int loc = text.IndexOf(hlt);
                int hlen = hlt.Length;
                int len = text.Length;
                while (loc >= 0)
                {
                    rangel.Add(new CharacterRange(loc, hlen));
                    if (loc + hlen < len)  // out of range of text
                        loc = text.IndexOf(hlt, loc + hlen);
                    else
                        loc = -1;
                }

                if (rangel.Count <= 0)      // we should have gotten one; but
                    return;

                CharacterRange[] ranges = rangel.ToArray();

                // Construct a new StringFormat object.
                sf2 = sf.Clone() as StringFormat;

                // Set the ranges on the StringFormat object.
                sf2.SetMeasurableCharacterRanges(ranges);

                // Get the Regions to highlight by calling the
                // MeasureCharacterRanges method.
                if (r.Width <= 0 || r.Height <= 0)
                {
                    SizeF ts = g.MeasureString(dtext.Text, f);
                    r.Height = ts.Height;
                    r.Width = ts.Width;
                }
                Region[] charRegion = g.MeasureCharacterRanges(dtext.Text, f, r, sf2);

                // Fill in the region using a semi-transparent color to highlight
                foreach (Region rg in charRegion)
                {
                    Color hl = bhighlightItem ? _HighlightItemColor : _HighlightAllColor;
                    g.FillRegion(new SolidBrush(Color.FromArgb(50, hl)), rg);
                }
            }
            catch { }   // if highlighting fails we don't care; need to continue
            finally
            {
                if (sf2 != null)
                    sf2.Dispose();
            }
        }
Beispiel #8
0
            private void DrawBackground(Graphics graphics, float angle, int num5, int num8, int num13, int x)
            {
                // What is "angle?"
                // it's the angle m8...

                // If there is a need to redraw the background
                if (((this.background == null) || (this.background.Size != wsplit.Size)) || this.bgRedrawRequested)
                {
                    this.bgRedrawRequested = false;
                    GC.Collect();   // Hardcoded Garbage Collection? Mmh...

                    // Creating the bitmap
                    if ((this.background == null) || (this.background.Size != wsplit.Size))
                        this.background = new Bitmap(wsplit.Width, wsplit.Height);

                    Graphics bgGraphics = Graphics.FromImage(this.background);
                    bgGraphics.Clear(Color.Black);
                    bgGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    //
                    // If display mode is NOT Timer Only
                    //
                    if (wsplit.currentDispMode != DisplayMode.Timer)
                    {
                        Rectangle statusBarEctangle;
                        Rectangle headerTextRectangle;
                        Rectangle statusTextRectangle;
                        Rectangle timesaverectangle;
                        Rectangle sobrectangle;
                        Rectangle timesaverectangle1;
                        Rectangle sobrectangle1;
                        Rectangle timesaverectangle2;
                        Rectangle sobrectangle2;
                        Rectangle pbrectangle;
                        Rectangle pbrectangle1;
                        Rectangle pbrectangle2;
                        Rectangle bestrectangle;
                        Rectangle bestrectangle1;
                        Rectangle bestrectangle2;
                        Rectangle goalTextRectangle;

                        int ps_y, ts_y, sob_y, pb_y, best_y = 0;
                        ps_y = wsplit.clockRect.Bottom;
                        if (Settings.Profile.ShowPrevSeg) { ts_y = ps_y + 18; } else { ts_y = ps_y; };
                        if (Settings.Profile.ShowTimeSave) { sob_y = ts_y + 18; } else { sob_y = ts_y; };
                        if (Settings.Profile.ShowSoB) { pb_y = sob_y + 18; } else { pb_y = sob_y; };
                        if (Settings.Profile.PredPB) { best_y = pb_y + 18; } else { best_y = pb_y; };

                        if (wsplit.currentDispMode == DisplayMode.Wide)
                        {
                            statusBarEctangle = new Rectangle(wsplit.Width - 120, 0, 120, wsplit.Height);                       // Status bar
                            statusTextRectangle = new Rectangle(wsplit.Width - 119, wsplit.Height / 2, 118, wsplit.Height / 2); // Run status
                            timesaverectangle = new Rectangle(0, 0, 0, 0);
                            sobrectangle = new Rectangle(0, 0, 0, 0);
                            timesaverectangle1 = new Rectangle(0, 0, 0, 0);
                            sobrectangle1 = new Rectangle(0, 0, 0, 0);
                            timesaverectangle2 = new Rectangle(0, 0, 0, 0);
                            sobrectangle2 = new Rectangle(0, 0, 0, 0);
                            pbrectangle = new Rectangle(0, 0, 0, 0);
                            pbrectangle1 = new Rectangle(0, 0, 0, 0);
                            pbrectangle2 = new Rectangle(0, 0, 0, 0);
                            bestrectangle = new Rectangle(0, 0, 0, 0);
                            bestrectangle1 = new Rectangle(0, 0, 0, 0);
                            bestrectangle2 = new Rectangle(0, 0, 0, 0);

                            headerTextRectangle = new Rectangle(wsplit.Width - 119, (wsplit.Height / 4) - 4, 59, 12);          // Run title
                            if ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal)
                            {
                                statusTextRectangle = new Rectangle(headerTextRectangle.X + headerTextRectangle.Width, (wsplit.Height / 4) - 4, 59, 12); //Run goal
                                goalTextRectangle = new Rectangle(wsplit.Width - 119, wsplit.Height / 2, 118, wsplit.Height / 2); //Run status
                            }
                            else
                            {
                                statusTextRectangle = new Rectangle(wsplit.Width - 119, wsplit.Height / 2, 118, wsplit.Height / 2); // Run status
                                goalTextRectangle = new Rectangle(0, 0, 0, 0);  //Nothing...
                            }
                        }
                        else if (wsplit.currentDispMode == DisplayMode.Detailed)
                        {
                            headerTextRectangle = new Rectangle(0, 0, 0, 0);

                            if (Settings.Profile.ShowPrevSeg)
                            {
                                statusBarEctangle = new Rectangle(0, ps_y, wsplit.Width, 18);
                                statusTextRectangle = new Rectangle(1, ps_y + 2, wsplit.Width - 2, 16);
                            }
                            else
                            {
                                statusBarEctangle = new Rectangle(0, ps_y - 18, wsplit.Width, 18);
                                statusTextRectangle = new Rectangle(1, ps_y + 2 - 18, wsplit.Width - 2, 16);
                            };

                            timesaverectangle = new Rectangle(0, ts_y, wsplit.Width, 18);
                            sobrectangle = new Rectangle(0, sob_y, wsplit.Width, 18);
                            timesaverectangle1 = new Rectangle(0, ts_y + 2, wsplit.Width - 2, 16);
                            sobrectangle1 = new Rectangle(0, sob_y + 2, wsplit.Width - 2, 16);
                            timesaverectangle2 = new Rectangle(0, ts_y + 2, wsplit.Width - 2, 16);
                            sobrectangle2 = new Rectangle(0, sob_y + 2, wsplit.Width - 2, 16);
                            pbrectangle = new Rectangle(0, pb_y, wsplit.Width, 18);
                            bestrectangle = new Rectangle(0, best_y, wsplit.Width, 18);
                            pbrectangle1 = new Rectangle(0, pb_y + 2, wsplit.Width - 2, 16);
                            bestrectangle1 = new Rectangle(0, best_y + 2, wsplit.Width - 2, 16);
                            pbrectangle2 = new Rectangle(0, pb_y + 2, wsplit.Width - 2, 16);
                            bestrectangle2 = new Rectangle(0, best_y + 2, wsplit.Width - 2, 16);
                            statusBarEctangle = new Rectangle(0, wsplit.clockRect.Bottom, wsplit.Width, 18);            // Status bar
                            headerTextRectangle = new Rectangle(0, 0, 0, 0);                                            // Nothing? Why?
                            statusTextRectangle = new Rectangle(1, wsplit.clockRect.Bottom + 2, wsplit.Width - 2, 16);  // Run status
                            goalTextRectangle = new Rectangle(0, 0, 0, 0);                                              // Nothing...
                        }
                        else
                        {
                            statusBarEctangle = new Rectangle(0, wsplit.clockRect.Bottom, wsplit.Width, 16);            // Status bar
                            headerTextRectangle = new Rectangle(1, 2, (wsplit.Width / 2) - 2, 13);                            // Segment name
                            statusTextRectangle = new Rectangle(1, wsplit.clockRect.Bottom + 2, wsplit.Width - 2, 14);  // Run status
                            timesaverectangle = new Rectangle(0, 0, 0, 0);
                            sobrectangle = new Rectangle(0, 0, 0, 0);
                            timesaverectangle1 = new Rectangle(0, 0, 0, 0);
                            sobrectangle1 = new Rectangle(0, 0, 0, 0);
                            timesaverectangle2 = new Rectangle(0, 0, 0, 0);
                            sobrectangle2 = new Rectangle(0, 0, 0, 0);
                            pbrectangle = new Rectangle(0, 0, 0, 0);
                            pbrectangle1 = new Rectangle(0, 0, 0, 0);
                            pbrectangle2 = new Rectangle(0, 0, 0, 0);
                            bestrectangle = new Rectangle(0, 0, 0, 0);
                            bestrectangle1 = new Rectangle(0, 0, 0, 0);
                            bestrectangle2 = new Rectangle(0, 0, 0, 0);

                            if ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal)
                            {
                                goalTextRectangle = new Rectangle(headerTextRectangle.X + headerTextRectangle.Width, 2, (wsplit.Width / 2) - 2, 13); // Run goal
                            }
                            else
                            {
                                goalTextRectangle = new Rectangle(0, 0, 0, 0); // Nothing...
                            }
                            // If the segment icon will be shown, the segment name have to be pushed right
                            if ((Settings.Profile.SegmentIcons > 0) && !wsplit.split.Done)
                            {
                                headerTextRectangle.Width -= 4 + (8 * (Settings.Profile.SegmentIcons + 1));
                                headerTextRectangle.X += 4 + (8 * (Settings.Profile.SegmentIcons + 1));
                            }
                        }

                        // If the background isn't black
                        if (!Settings.Profile.BackgroundBlack)
                        {
                            // Fill the status bar
                            if (Settings.Profile.BackgroundPlain)
                            {
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBackPlain), statusBarEctangle);
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBackPlain), timesaverectangle);
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBackPlain), sobrectangle);
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBackPlain), pbrectangle);
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBackPlain), bestrectangle);
                            }
                            else
                            {
                                bgGraphics.FillRectangle(new LinearGradientBrush(statusBarEctangle, ColorSettings.Profile.StatusBack, ColorSettings.Profile.StatusBack2, angle), statusBarEctangle);
                                bgGraphics.FillRectangle(new LinearGradientBrush(statusBarEctangle, ColorSettings.Profile.StatusBack, ColorSettings.Profile.StatusBack2, angle), timesaverectangle);
                                bgGraphics.FillRectangle(new LinearGradientBrush(statusBarEctangle, ColorSettings.Profile.StatusBack, ColorSettings.Profile.StatusBack2, angle), sobrectangle);
                                bgGraphics.FillRectangle(new LinearGradientBrush(statusBarEctangle, ColorSettings.Profile.StatusBack, ColorSettings.Profile.StatusBack2, angle), pbrectangle);
                                bgGraphics.FillRectangle(new LinearGradientBrush(statusBarEctangle, ColorSettings.Profile.StatusBack, ColorSettings.Profile.StatusBack2, angle), bestrectangle);
                            };
                            // Detailed mode - Draw the title bar
                            if (wsplit.currentDispMode == DisplayMode.Detailed)
                            {
                                int titleX = 0;
                                int titleY = 0;
                                int goalX = 0;
                                int goalY = 0;

                                if (((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle) && ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal) && !Settings.Profile.BackgroundPlain)
                                {
                                    bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack), titleX, titleY, wsplit.Width, 32);
                                    bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack2), titleX, titleY, wsplit.Width, 16);

                                }
                                else
                                {
                                    if ((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle)
                                    {
                                        if (Settings.Profile.BackgroundPlain)
                                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBackPlain), titleX, titleY, wsplit.Width, 16);
                                        else
                                        {
                                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack), titleX, titleY, wsplit.Width, 16);
                                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack2), titleX, titleY, wsplit.Width, 8);
                                        }
                                    }
                                    if ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal)
                                    {
                                        if ((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle)
                                        {
                                            goalY = 16;
                                        }
                                        if (Settings.Profile.BackgroundPlain)
                                        {
                                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBackPlain), 0, goalY, wsplit.Width, 16);
                                        }
                                        else
                                        {
                                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack), 0, goalY, wsplit.Width, 16);
                                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack2), 0, goalY, wsplit.Width, 8);
                                        }
                                    }
                                }
                            }

                            // Compact mode - Draw the title bar
                            else if (wsplit.currentDispMode == DisplayMode.Compact)
                            {
                                if (Settings.Profile.BackgroundPlain)
                                    bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBackPlain), 0, 0, wsplit.Width, 18);
                                else
                                {
                                    bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack), 0, 0, wsplit.Width, 15);
                                    bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack2), 0, 0, wsplit.Width, 7);
                                }
                            }
                        }

                        // Refactor? Only used once, never changes
                        StringFormat format3 = new StringFormat
                        {
                            LineAlignment = StringAlignment.Center,
                            Trimming = StringTrimming.EllipsisCharacter
                        };

                        // Only used once, Alignment changes
                        StringFormat format4 = (StringFormat)format3.Clone();

                        if (wsplit.currentDispMode == DisplayMode.Compact)
                            format4.Alignment = StringAlignment.Far;

                        string s = "";
                        string statusText = "";

                        // The run is not started yet
                        if (wsplit.timer.ElapsedTicks == 0L)
                        {
                            if (wsplit.currentDispMode != DisplayMode.Wide)
                                format4.Alignment = StringAlignment.Far;

                            if (wsplit.startDelay != null)
                                statusText = "Delay";
                            else
                            {
                                statusText = "Ready";
                                if (Settings.Profile.ShowAttempts && ((wsplit.currentDispMode != DisplayMode.Detailed) || !Settings.Profile.ShowTitle))
                                    statusText += ", Attempt #" + (wsplit.split.AttemptsCount + 1);
                            }
                        }

                        // The run is done
                        else if (wsplit.split.Done)
                        {
                            if (wsplit.split.CompTime(wsplit.split.LastIndex) == 0.0)
                            {
                                if (wsplit.currentDispMode != DisplayMode.Wide)
                                    format4.Alignment = StringAlignment.Far;

                                statusText = "Done";
                            }
                            else if (wsplit.split.LastSegment.LiveTime < wsplit.split.CompTime(wsplit.split.LastIndex))
                                statusText = "New Record";
                            else
                                statusText = "Done";
                        }

                        // The run is going
                        else if ((wsplit.currentDispMode == DisplayMode.Compact) && (wsplit.split.CompTime(wsplit.split.LiveIndex) != 0.0))
                            statusText = wsplit.split.ComparingType.ToString() + ": " + wsplit.timeFormatter(wsplit.split.CompTime(wsplit.split.LiveIndex), TimeFormat.Long);
                        else if (this.segLosingTime)
                            statusText = "Live Segment";
                        else if (((wsplit.split.LiveIndex > 0) && (wsplit.split.segments[wsplit.split.LiveIndex - 1].LiveTime > 0.0)) && (wsplit.split.CompTime(wsplit.split.LiveIndex - 1) != 0.0))
                            statusText = "Previous Segment";

                        // Detailed mode
                        if (wsplit.currentDispMode == DisplayMode.Detailed)
                        {
                            int goalTextY = 0;
                            if ((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle)
                            {
                                bgGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                                Rectangle rectangle7 = new Rectangle(0, 1, wsplit.Width, 17);
                                goalTextY = 16;

                                // Draws the hotkey toggle indicator
                                if (Settings.Profile.HotkeyToggleKey != Keys.None)
                                {
                                    if (Settings.Profile.EnabledHotkeys)
                                    {
                                        bgGraphics.FillRectangle(Brushes.GreenYellow, wsplit.Width - 10, 4, 6, 6);
                                    }
                                    else
                                    {
                                        bgGraphics.FillRectangle(Brushes.OrangeRed, wsplit.Width - 10, 4, 6, 6);
                                    }
                                    rectangle7.Width -= 10;
                                }

                                string str8 = "";
                                if (Settings.Profile.ShowAttempts)
                                {
                                    if (wsplit.timer.IsRunning)
                                    {
                                        str8 = "#" + wsplit.split.AttemptsCount + " / ";
                                    }
                                    else
                                    {
                                        str8 = "#" + (wsplit.split.AttemptsCount + 1) + " / ";
                                    }
                                }

                                StringFormat format5 = new StringFormat
                                {
                                    Alignment = StringAlignment.Center,
                                    LineAlignment = StringAlignment.Center,
                                    Trimming = StringTrimming.EllipsisCharacter
                                };

                                bgGraphics.DrawString(str8 + wsplit.split.RunTitle, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.TitleFore), rectangle7, format5);
                            }

                            if ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal)
                            {
                                bgGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                                Rectangle goalRectangle = new Rectangle(0, 19, wsplit.Width, 17);
                                goalRectangle.Y = goalTextY;

                                if (Settings.Profile.HotkeyToggleKey != Keys.None)
                                {
                                    goalRectangle.Width -= 10;
                                }

                                StringFormat format5 = new StringFormat
                                {
                                    Alignment = StringAlignment.Center,
                                    LineAlignment = StringAlignment.Center,
                                    Trimming = StringTrimming.EllipsisCharacter
                                };
                                bgGraphics.DrawString("Goal: " + wsplit.split.RunGoal, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.TitleFore), goalRectangle, format5);
                            }
                        }

                        else if (wsplit.split.Done)
                        {
                            if (wsplit.currentDispMode == DisplayMode.Wide)
                            {
                                s = statusText;
                                statusText = "Final";
                            }
                            else
                                s = "Final";
                        }
                        else if (wsplit.currentDispMode == DisplayMode.Compact)
                            s = wsplit.split.CurrentSegment.Name;
                        else if ((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle)
                            s = wsplit.split.RunTitle;
                        else
                            s = "Run";

                        if (wsplit.currentDispMode == DisplayMode.Compact)
                        {
                            headerTextRectangle.Width -= this.segDeltaWidth;
                            statusTextRectangle.Width -= this.runDeltaWidth;
                            statusTextRectangle.X += this.runDeltaWidth;
                        }
                        else
                        {
                            headerTextRectangle.Width -= this.runDeltaWidth;
                            statusTextRectangle.Width -= this.segDeltaWidth;
                        }

                        bgGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                        bgGraphics.DrawString(s, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), headerTextRectangle, format3);   // To be verified, but it seems like this line writes f**k all in a negative rectangle when in Detailed mode...
                        bgGraphics.DrawString(statusText, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), statusTextRectangle, format4);
                        // u wote m8
                        StringFormat strleft = new StringFormat
                        {
                            Alignment = StringAlignment.Near,
                            LineAlignment = StringAlignment.Center,
                            Trimming = StringTrimming.EllipsisCharacter
                        };
                        StringFormat strright = new StringFormat
                        {
                            Alignment = StringAlignment.Far,
                            LineAlignment = StringAlignment.Center,
                            Trimming = StringTrimming.EllipsisCharacter
                        };
                        // text
                        string sobtext = "-";
                        string tstext = "0:00";
                        if (Settings.Profile.ShowSoB)
                        {
                            bgGraphics.DrawString("Sum of Best", wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), sobrectangle1, strleft);
                            if (wsplit.split.SumOfBests(wsplit.split.LastIndex) > 0.0)
                            {
                                sobtext = wsplit.timeFormatter(wsplit.split.SumOfBests(wsplit.split.LastIndex), TimeFormat.Short);
                            };
                            bgGraphics.DrawString(sobtext, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), sobrectangle2, strright);
                        };//yeah
                        //int j;
                        double segtime = 0.0;
                        //segtime = wsplit.split.segments[wsplit.split.LiveIndex].BestTime;
                        if (wsplit.split.LiveIndex > 0 && (wsplit.split.LiveIndex <= wsplit.split.LastIndex))
                        {
                            segtime = wsplit.split.segments[wsplit.split.LiveIndex].BestTime;
                            segtime -= wsplit.split.segments[wsplit.split.LiveIndex - 1].BestTime;
                        }
                        else if (wsplit.split.LiveIndex == 0)
                        {
                            segtime = wsplit.split.segments[0].BestTime;
                        };
                        if ((segtime > 0.0) && (wsplit.split.segments[wsplit.split.LiveIndex].BestSegment > 0.0) && (segtime >= wsplit.split.segments[wsplit.split.LiveIndex].BestSegment))
                        {
                            tstext = wsplit.timeFormatter(Math.Abs(segtime - wsplit.split.segments[wsplit.split.LiveIndex].BestSegment), TimeFormat.Short);
                        };
                        if ((wsplit.split.LiveIndex > 0) && (wsplit.split.LiveIndex <= wsplit.split.LastIndex) && ((wsplit.split.segments[wsplit.split.LiveIndex].BestTime == 0.0) || (wsplit.split.segments[wsplit.split.LiveIndex - 1].BestTime == 0.0)))
                        {
                            tstext = "-";
                        };
                        if (Settings.Profile.ShowTimeSave)
                        {
                            bgGraphics.DrawString("Possible Gain", wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), timesaverectangle1, strleft);
                            bgGraphics.DrawString(tstext, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), timesaverectangle2, strright);
                        };
                        if (Settings.Profile.PredPB)
                        {
                            bgGraphics.DrawString("Predicted (PB)", wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), pbrectangle1, strleft);
                            if (wsplit.split.CompTime(wsplit.split.LastIndex) > 0.0)
                            {
                                string pbtime = "";
                                //if (wsplit.split.LiveIndex <= 0)
                                //{
                                //    pbtime = wsplit.timeFormatter(wsplit.split.CompTime(wsplit.split.LastIndex), TimeFormat.Short);
                                //}
                                //else
                                //{
                                pbtime = wsplit.timeFormatter(wsplit.split.CompTime(wsplit.split.LastIndex) + wsplit.split.LastDelta(wsplit.split.LiveIndex), TimeFormat.Short);
                                //};
                                bgGraphics.DrawString(pbtime, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), pbrectangle2, strright);
                            }
                            else
                            {
                                bgGraphics.DrawString("-", wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), pbrectangle2, strright);
                            };
                        };
                        if (Settings.Profile.PredBest)
                        {
                            bgGraphics.DrawString("Predicted (Best)", wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), bestrectangle1, strleft);
                            if (wsplit.split.SumOfBests(wsplit.split.LastIndex) > 0.0)
                            {
                                double best = wsplit.split.SumOfBests(wsplit.split.LastIndex);
                                if ((wsplit.split.LiveIndex > 0) && (wsplit.split.LiveIndex <= wsplit.split.LastIndex))
                                {
                                    int i;
                                    for (i = wsplit.split.LiveIndex; i >= 0; i--)
                                    {
                                        if (wsplit.split.segments[i].LiveTime != 0)
                                        {
                                            best += wsplit.split.segments[i].LiveTime - wsplit.split.SumOfBests(i);
                                            break;
                                        };
                                    };
                                };
                                string besttime = wsplit.timeFormatter(best, TimeFormat.Short);
                                bgGraphics.DrawString(besttime, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), bestrectangle2, strright);
                            }
                            else
                            {
                                bgGraphics.DrawString("-", wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), bestrectangle2, strright);
                            };
                        };
                        if (wsplit.currentDispMode != DisplayMode.Detailed)
                        {
                            bgGraphics.DrawString("Goal: " + wsplit.split.RunGoal, wsplit.displayFont, new SolidBrush(ColorSettings.Profile.StatusFore), goalTextRectangle, format4);
                        }
                    }

                    //
                    // Wide or detailed modes
                    //
                    if ((wsplit.currentDispMode == DisplayMode.Wide) || (wsplit.currentDispMode == DisplayMode.Detailed))
                    {
                        Rectangle rectangle8;   // Yet another unnamed rectangle
                        int num16 = wsplit.clockRect.Right + 2;
                        int y = 0;

                        if (((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle) && ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal))
                        {
                            y += 32;
                        }
                        else if ((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle)
                            y += 18;

                        else if ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal)
                        {
                            y += 18;
                        }

                        if (wsplit.currentDispMode == DisplayMode.Wide)
                        {
                            rectangle8 = new Rectangle(num16, 0, (wsplit.Width - wsplit.clockRect.Width) - 122, wsplit.Height);
                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBack2), wsplit.clockRect.Right, 0, 2, wsplit.Height);
                        }

                        else
                            rectangle8 = new Rectangle(0, y, wsplit.Width, wsplit.clockRect.Bottom - 18);

                        if (!Settings.Profile.BackgroundBlack)
                        {
                            if (Settings.Profile.BackgroundPlain)
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.SegBackPlain), rectangle8);
                            else
                                bgGraphics.FillRectangle(new LinearGradientBrush(rectangle8, ColorSettings.Profile.SegBack, ColorSettings.Profile.SegBack2, angle), rectangle8);
                        }

                        // Flag2 = Show last
                        bool flag2 = false;
                        if (((num5 > 3) && (((num13 + num5) - 1) < wsplit.split.LastIndex)) && (((wsplit.currentDispMode == DisplayMode.Detailed) && Settings.Profile.ShowLastDetailed) || ((wsplit.currentDispMode == DisplayMode.Wide) && Settings.Profile.ShowLastWide)))
                            flag2 = true;

                        if (wsplit.currentDispMode == DisplayMode.Wide)
                        {
                            if (flag2)
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBack2), (wsplit.Width - 0x7a) - wsplit.wideSegWidth, 0, 2, wsplit.Height);
                            else
                                bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBack2), wsplit.Width - 0x7a, 0, 2, wsplit.Height);
                        }
                        else if (flag2)
                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBackPlain), 0, (wsplit.clockRect.Y - 3) - wsplit.segHeight, wsplit.Width, 3);
                        else if (Settings.Profile.BackgroundPlain || Settings.Profile.BackgroundBlack)
                            bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.StatusBackPlain), 0, wsplit.clockRect.Y - 3, wsplit.Width, 3);
                        else
                            bgGraphics.FillRectangle(new LinearGradientBrush(rectangle8, ColorSettings.Profile.StatusBack, ColorSettings.Profile.StatusBack2, 0f), 0, wsplit.clockRect.Y - 3, wsplit.Width, 3);

                        StringFormat format6 = new StringFormat
                        {
                            Trimming = StringTrimming.EllipsisCharacter,
                            LineAlignment = StringAlignment.Center
                        };

                        StringFormat format7 = new StringFormat
                        {
                            LineAlignment = StringAlignment.Center
                        };

                        if (wsplit.currentDispMode != DisplayMode.Wide)
                        {
                            if (wsplit.segHeight > 24)
                                format6.Alignment = StringAlignment.Near;

                            format7.Alignment = StringAlignment.Far;
                        }

                        Rectangle rect = new Rectangle(0, 0, 0, 1);

                        int num18 = 0;
                        for (int i = num13; (num18 < num5) && (i <= wsplit.split.LastIndex); i++)
                        {
                            int segTimeWidth;
                            Rectangle rectangle10;
                            Rectangle rectangle11;
                            Rectangle rectangle12;
                            Rectangle rectangle13;

                            Image grayIcon;
                            ImageAttributes attributes;

                            if (((num18 + 1) >= num5) && flag2)
                            {
                                i = wsplit.split.LastIndex;
                                y += 3;
                                num16 += 2;
                            }

                            Brush brush3 = new SolidBrush(ColorSettings.Profile.FutureSegName);
                            string str9 = wsplit.split.segments[i].TimeString;
                            // thing //
                            string splittime = "";
                            if ((i < wsplit.split.LiveIndex) && (wsplit.split.segments[i].LiveTime > 0.0))
                            {
                                splittime = wsplit.timeFormatter(wsplit.split.segments[i].LiveTime, TimeFormat.Short);
                            }
                            else
                            {
                                splittime = "-";
                            };
                            // idk //
                            string name = wsplit.split.segments[i].Name;

                            if ((i == wsplit.split.LiveIndex) && this.runLosingTime)
                                segTimeWidth = this.segTimeWidth;
                            else
                                segTimeWidth = wsplit.split.segments[i].TimeWidth;

                            ColorMatrix newColorMatrix = new ColorMatrix
                            {
                                Matrix33 = 0.65f
                            };

                            if (wsplit.currentDispMode == DisplayMode.Wide)
                            {
                                rectangle10 = new Rectangle(num16, 0, wsplit.wideSegWidth, wsplit.Height);
                                rectangle11 = new Rectangle(num16 + 2, (wsplit.Height / 4) - 4, (wsplit.wideSegWidth - x) - 2, 12);
                                rectangle12 = new Rectangle(rectangle11.Left, wsplit.Height / 2, rectangle11.Width, wsplit.Height / 2);
                                rectangle13 = new Rectangle(rectangle11.Left + Settings.Profile.Width + 8, wsplit.Height / 2, rectangle11.Width, wsplit.Height / 2);
                            }

                            else
                            /* create rectangles here */
                            {
                                rectangle10 = new Rectangle(0, y, wsplit.Width, wsplit.segHeight);         //icon
                                rectangle11 = new Rectangle(x, y + 2, wsplit.Width - x, wsplit.segHeight); //name
                                rectangle12 = new Rectangle(x, y + 1, wsplit.Width - x, wsplit.segHeight); //delta
                                rectangle13 = new Rectangle(x - Settings.Profile.Width - 8, y + 1, wsplit.Width - x, wsplit.segHeight); //test

                                if (wsplit.segHeight <= 24)
                                {
                                    rectangle11.Width -= segTimeWidth + 2;
                                    rectangle11.Y = (y + (wsplit.segHeight / 2)) - 5;
                                    rectangle11.Height = 13;
                                }
                                else
                                {
                                    rectangle11.Y = y + 2;
                                    rectangle11.Height /= 2;
                                    rectangle12.Y = rectangle11.Bottom - 2;
                                    rectangle12.Height /= 2;
                                    rectangle13.Y = rectangle11.Bottom - 2;
                                    rectangle13.Height /= 2;
                                }
                            }
                            if ((i < wsplit.split.LiveIndex) && (wsplit.timer.ElapsedTicks > 0L))
                            {
                                brush3 = new SolidBrush(ColorSettings.Profile.PastSeg);
                                if (wsplit.split.segments[i].TimeColor == ColorSettings.Profile.SegRainbow && Settings.Profile.RainbowSplits)
                                {
                                    brush3 = new SolidBrush(ColorSettings.Profile.SegRainbow);
                                };
                            }
                            else if (i == wsplit.split.LiveIndex)
                            {
                                brush3 = new SolidBrush(ColorSettings.Profile.LiveSeg);
                                rect = rectangle10;
                                if (Settings.Profile.BackgroundPlain || Settings.Profile.BackgroundBlack)
                                {
                                    bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.SegHighlightPlain), rectangle10);
                                }
                                else
                                {
                                    bgGraphics.FillRectangle(new LinearGradientBrush(rectangle10, ColorSettings.Profile.SegHighlight, ColorSettings.Profile.SegHighlight2, angle), rectangle10);
                                }
                                newColorMatrix.Matrix33 = 1f;
                            }
                            if (x == 0)
                            {
                                goto Label_1F67;
                            }
                            if ((i < wsplit.split.LiveIndex) && (wsplit.timer.ElapsedTicks > 0L))
                            {
                                newColorMatrix.Matrix33 = 0.85f;
                                switch (x)
                                {
                                    case 0x10:
                                        grayIcon = wsplit.split.segments[i].GrayIcon16;
                                        goto Label_1EE9;

                                    case 0x18:
                                        grayIcon = wsplit.split.segments[i].GrayIcon24;
                                        goto Label_1EE9;

                                    case 0x20:
                                        grayIcon = wsplit.split.segments[i].GrayIcon32;
                                        goto Label_1EE9;
                                }
                                grayIcon = wsplit.split.segments[i].GrayIcon;
                            }
                            else
                            {
                                switch (x)
                                {
                                    case 0x10:
                                        grayIcon = wsplit.split.segments[i].Icon16;
                                        goto Label_1EE9;

                                    case 0x18:
                                        grayIcon = wsplit.split.segments[i].Icon24;
                                        goto Label_1EE9;

                                    case 0x20:
                                        grayIcon = wsplit.split.segments[i].Icon32;
                                        goto Label_1EE9;
                                }
                                grayIcon = wsplit.split.segments[i].Icon;
                            }
                        Label_1EE9:
                            attributes = new ImageAttributes();
                            attributes.SetColorMatrix(newColorMatrix);
                            Rectangle destRect = new Rectangle(rectangle10.X, rectangle10.Y, x, x);
                            if (wsplit.currentDispMode == DisplayMode.Wide)
                            {
                                destRect.X += wsplit.wideSegWidth - x;
                                destRect.Y += wsplit.Height - x;
                            }
                            bgGraphics.DrawImage(grayIcon, destRect, 0, 0, grayIcon.Width, grayIcon.Height, GraphicsUnit.Pixel, attributes);
                        Label_1F67:
                            bgGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                            //test
                            if (Settings.Profile.SplitTimes && (i < wsplit.split.LiveIndex) && (x < 32) && wsplit.currentDispMode == DisplayMode.Detailed)
                            {
                                rectangle11.Width = rectangle13.Right - MeasureDisplayStringWidth(str9, wsplit.timeFont) - x - 4;
                            };
                            bgGraphics.DrawString(name, wsplit.displayFont, brush3, rectangle11, format6);
                            /* draw labels here */
                            if (i != wsplit.split.LiveIndex)
                            {
                                if (i < wsplit.split.LiveIndex && Settings.Profile.SplitTimes && (Settings.Profile.last != "-") && wsplit.timer.ElapsedTicks > 0L)
                                {
                                    bgGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                                    if (wsplit.split.segments[i].TimeColor == ColorSettings.Profile.SegRainbow && Settings.Profile.RainbowSplits)
                                    {
                                        bgGraphics.DrawString(splittime, wsplit.timeFont, new SolidBrush(ColorSettings.Profile.SegRainbow), rectangle12, format7);
                                    }
                                    else
                                    {
                                        bgGraphics.DrawString(splittime, wsplit.timeFont, new SolidBrush(ColorSettings.Profile.SegPastTime), rectangle12, format7);
                                    };
                                    bgGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                                    if (wsplit.split.CompTime(i) == 0.0) { str9 = "-"; };
                                    bgGraphics.DrawString(str9, wsplit.timeFont, new SolidBrush(wsplit.split.segments[i].TimeColor), rectangle13, format7);
                                }
                                else
                                {
                                    bgGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                                    bgGraphics.DrawString(str9, wsplit.timeFont, new SolidBrush(wsplit.split.segments[i].TimeColor), rectangle12, format7);
                                };
                            }
                            num16 += wsplit.wideSegWidth;
                            y += wsplit.segHeight;
                            num18++;
                        }

                        if (wsplit.split.LiveRun && !wsplit.split.Done)
                        {
                            Pen pen = new Pen(new SolidBrush(ColorSettings.Profile.SegHighlightBorder));
                            if (wsplit.currentDispMode == DisplayMode.Wide)
                            {
                                rect.Height--;
                                bgGraphics.DrawRectangle(pen, rect);
                            }
                            else
                            {
                                bgGraphics.DrawLine(pen, rect.Left, rect.Top, rect.Right, rect.Top);
                                bgGraphics.DrawLine(pen, rect.Left, rect.Bottom, rect.Right, rect.Bottom);
                            }
                        }
                    }

                    // Code for drawing clock back has been moved to another function. Current method's signature is temporary
                    this.DrawClockBack(angle, num8, bgGraphics);

                    if (((x > 0) && (wsplit.currentDispMode == DisplayMode.Compact)) && (wsplit.split.LiveRun && !wsplit.split.Done))
                    {
                        Image icon;
                        switch (x)
                        {
                            case 0x10:
                                icon = wsplit.split.CurrentSegment.Icon16;
                                break;

                            case 0x18:
                                icon = wsplit.split.CurrentSegment.Icon24;
                                break;

                            case 0x20:
                                icon = wsplit.split.CurrentSegment.Icon32;
                                break;

                            default:
                                icon = wsplit.split.CurrentSegment.Icon;
                                break;
                        }
                        Rectangle rectangle14 = new Rectangle(3, 3, x, x);
                        bgGraphics.DrawImage(icon, rectangle14, 0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel);
                        bgGraphics.DrawRectangle(new Pen(new SolidBrush(wsplit.DarkenColor(this.clockColor, 0.7))), 3, 3, icon.Width, icon.Height);
                    }
                }

                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.DrawImage(this.background, 0, 0);
                graphics.CompositingMode = CompositingMode.SourceOver;
            }
Beispiel #9
0
            public void PaintAll(Graphics graphics)
            {
                TimeSpan span2;
                ColorSettings settings = ColorSettings.Profile;
                bool flag = false;
                double totalMilliseconds = wsplit.timer.Elapsed.TotalMilliseconds;

                if (((Settings.Profile.FallbackPreference == 1) || (Settings.Profile.FallbackPreference == 2)) && (totalMilliseconds > 0.0))
                {
                    double num2 = Math.Abs(wsplit.timer.driftMilliseconds);

                    if ((num2 > 500.0) && ((num2 / totalMilliseconds) > 5.5555555555555558E-05))
                    {
                        if (Settings.Profile.FallbackPreference == 2)
                            wsplit.timer.useFallback = true;

                        else
                            flag = true;
                    }

                    else if (Settings.Profile.FallbackPreference == 2)
                    {
                        wsplit.timer.useFallback = false;
                    }
                }

                TimeSpan elapsed = wsplit.timer.Elapsed;
                double num3 = wsplit.split.SegDelta(elapsed.TotalSeconds, wsplit.split.LiveIndex);
                double secs = wsplit.split.RunDelta(elapsed.TotalSeconds, wsplit.split.LiveIndex);
                int num5 = 0;
                float angle;
                if (Settings.Profile.HGrad)
                {
                    angle = 0f;
                }
                else
                {
                    angle = 270f;
                };

                if (wsplit.currentDispMode == DisplayMode.Wide)
                {
                    num5 = wsplit.displaySegsWide();
                    //angle = 90f;
                }
                else
                    num5 = wsplit.detailSegCount();

                if ((wsplit.split.StartDelay != 0) && (wsplit.timer.ElapsedTicks == 0L))
                {
                    span2 = TimeSpan.FromMilliseconds((double)wsplit.split.StartDelay);
                    if (wsplit.startDelay != null)
                    {
                        span2 -= DateTime.UtcNow - wsplit.offsetStartTime;
                    }
                }
                else if (wsplit.split.Done)
                    span2 = TimeSpan.FromSeconds(wsplit.split.LastSegment.LiveTime);
                else
                    span2 = elapsed;

                if (span2.TotalHours >= 100.0)
                {
                    clockTimeAbsSize = MeasureTimeStringMax("888:88:88", (Settings.Profile.DigitalClock) ? wsplit.digitLarge : wsplit.clockLarge, graphics);
                    this.timeStringAbsPart = string.Format("{0:000}:{1:00}:{2:00}", Math.Floor(span2.TotalHours) % 1000.0, span2.Minutes, span2.Seconds);
                }
                else
                {
                    clockTimeAbsSize = MeasureTimeStringMax("88:88:88", (Settings.Profile.DigitalClock) ? wsplit.digitLarge : wsplit.clockLarge, graphics);
                    if (span2.TotalHours >= 1.0)
                        this.timeStringAbsPart = string.Format("{0:0}:{1:00}:{2:00}", Math.Floor(span2.TotalHours), span2.Minutes, span2.Seconds);
                    else if (span2.TotalMinutes >= 1.0)
                        this.timeStringAbsPart = string.Format("{0}:{1:00}", span2.Minutes, span2.Seconds);
                    else
                        this.timeStringAbsPart = string.Format("{0}", span2.Seconds);
                }

                if (Settings.Profile.DigitalClock)
                {
                    // If the refresh interval is greater than 42, only 1 digit is shown after the decimal
                    /*if (wsplit.stopwatch.Interval > 42)
                        this.timeStringAbsPart = this.timeStringAbsPart.PadLeft(9, ' ');*/

                    this.timeStringAbsPart = this.timeStringAbsPart.PadLeft(8, ' ');
                    if (((wsplit.split.StartDelay != 0) && (wsplit.timer.ElapsedTicks == 0L)) && (this.timeStringAbsPart.Substring(0, 1) == " "))
                    {
                        this.timeStringAbsPart = "-" + this.timeStringAbsPart.Substring(1, this.timeStringAbsPart.Length - 1);
                    }
                }
                else if (((wsplit.split.StartDelay != 0) && (wsplit.timer.ElapsedTicks == 0L)) && ((span2.TotalHours < 10.0) || ((span2.TotalHours < 100.0) && (wsplit.stopwatch.Interval > 42))))
                    this.timeStringAbsPart = "-" + this.timeStringAbsPart;

                // If the number of hours is greater or equal to 100 or the refresh interval is greater than 42, show only 1 digit after the decimal
                if ((span2.TotalHours >= 100.0) || (wsplit.stopwatch.Interval > 42))
                {
                    this.clockTimeDecSize = MeasureTimeStringMax("8", (Settings.Profile.DigitalClock) ? wsplit.digitMed : wsplit.clockMed, graphics);
                    this.timeStringDecPart = string.Format("{0:0}", Math.Floor((double)(((double)span2.Milliseconds) / 100.0)));
                }
                else
                {
                    this.clockTimeDecSize = MeasureTimeStringMax("88", (Settings.Profile.DigitalClock) ? wsplit.digitMed : wsplit.clockMed, graphics);
                    this.timeStringDecPart = string.Format("{0:00}", Math.Floor((double)(((double)span2.Milliseconds) / 10.0)));
                }

                clockTimeTotalSize = new SizeF(clockTimeAbsSize.Width + clockTimeDecSize.Width,
                    Math.Max(clockTimeAbsSize.Height, clockTimeDecSize.Height));

                int x = 0;

                if (Settings.Profile.SegmentIcons >= 1)
                    x = (Settings.Profile.SegmentIcons + 1) * 8;

                int num8 = 0;

                if (((x > 16) && (wsplit.currentDispMode == DisplayMode.Compact)) && (wsplit.split.LiveRun && !wsplit.split.Done))
                    num8 = x + 6;

                //clockScale = Math.Min((float)(((float)(wsplit.clockRect.Width - num8)) / 124f), (float)(((float)wsplit.clockRect.Height) / 26f));
                clockScale = Math.Min((wsplit.clockRect.Width - num8) / clockTimeTotalSize.Width, wsplit.clockRect.Height / clockTimeTotalSize.Height);

                Color clockColor = this.clockColor;
                Color dViewClockColor = new Color();
                if (wsplit.timer.IsRunning)
                {
                    if (wsplit.split.LiveRun)
                    {
                        if (wsplit.split.Done)
                        {
                            if ((wsplit.split.LastSegment.LiveTime < wsplit.split.CompTime(wsplit.split.LastIndex)) || (wsplit.split.CompTime(wsplit.split.LastIndex) == 0.0))
                            {
                                clockColor = ColorSettings.Profile.RecordFore;
                                this.clockGrColor = ColorSettings.Profile.RecordBack;
                                this.clockGrColor2 = ColorSettings.Profile.RecordBack2;
                                this.clockPlainColor = ColorSettings.Profile.RecordBackPlain;

                                dViewClockColor = ColorSettings.Profile.UsedDViewRecord;
                            }
                            else
                            {
                                clockColor = ColorSettings.Profile.FinishedFore;
                                this.clockGrColor = ColorSettings.Profile.FinishedBack;
                                this.clockGrColor2 = ColorSettings.Profile.FinishedBack2;
                                this.clockPlainColor = ColorSettings.Profile.FinishedBackPlain;

                                dViewClockColor = ColorSettings.Profile.UsedDViewFinished;
                            }
                        }
                        else if (wsplit.flashDelay != null)
                        {
                            clockColor = ColorSettings.Profile.Flash;
                            dViewClockColor = ColorSettings.Profile.DViewFlash;
                        }
                        else if (wsplit.split.CompTime() == 0.0)
                        {
                            clockColor = ColorSettings.Profile.AheadFore;
                            this.clockGrColor = ColorSettings.Profile.AheadBack;
                            this.clockGrColor2 = ColorSettings.Profile.AheadBack2;
                            this.clockPlainColor = ColorSettings.Profile.AheadBackPlain;

                            dViewClockColor = ColorSettings.Profile.UsedDViewAhead;
                        }
                        else if (elapsed.TotalSeconds < wsplit.split.CompTime())
                        {
                            if (num3 < 0.0)
                            {
                                clockColor = ColorSettings.Profile.AheadFore;
                                this.clockGrColor = ColorSettings.Profile.AheadBack;
                                this.clockGrColor2 = ColorSettings.Profile.AheadBack2;
                                this.clockPlainColor = ColorSettings.Profile.AheadBackPlain;

                                dViewClockColor = ColorSettings.Profile.UsedDViewAhead;
                            }
                            else
                            {
                                clockColor = ColorSettings.Profile.AheadLosingFore;
                                this.clockGrColor = ColorSettings.Profile.AheadLosingBack;
                                this.clockGrColor2 = ColorSettings.Profile.AheadLosingBack2;
                                this.clockPlainColor = ColorSettings.Profile.AheadLosingBackPlain;

                                dViewClockColor = ColorSettings.Profile.UsedDViewAheadLosing;
                            }
                        }
                        else if (num3 < 0.0)
                        {
                            clockColor = ColorSettings.Profile.BehindFore;
                            this.clockGrColor = ColorSettings.Profile.BehindBack;
                            this.clockGrColor2 = ColorSettings.Profile.BehindBack2;
                            this.clockPlainColor = ColorSettings.Profile.BehindBackPlain;

                            dViewClockColor = ColorSettings.Profile.UsedDViewBehind;
                        }
                        else
                        {
                            clockColor = ColorSettings.Profile.BehindLosingFore;
                            this.clockGrColor = ColorSettings.Profile.BehindLosingBack;
                            this.clockGrColor2 = ColorSettings.Profile.BehindLosingBack2;
                            this.clockPlainColor = ColorSettings.Profile.BehindLosingBackPlain;

                            dViewClockColor = ColorSettings.Profile.UsedDViewBehindLosing;
                        }
                    }
                    else
                    {
                        clockColor = ColorSettings.Profile.WatchFore;
                        this.clockGrColor = ColorSettings.Profile.WatchBack;
                        this.clockGrColor2 = ColorSettings.Profile.WatchBack2;
                        this.clockPlainColor = ColorSettings.Profile.WatchBackPlain;
                    }
                }
                else if (wsplit.timer.ElapsedTicks > 0L)
                {
                    clockColor = ColorSettings.Profile.Paused;
                    dViewClockColor = ColorSettings.Profile.UsedDViewPaused;
                }
                else if (wsplit.split.StartDelay != 0)
                {
                    clockColor = ColorSettings.Profile.DelayFore;
                    this.clockGrColor = ColorSettings.Profile.DelayBack;
                    this.clockGrColor2 = ColorSettings.Profile.DelayBack2;
                    this.clockPlainColor = ColorSettings.Profile.DelayBackPlain;

                    dViewClockColor = ColorSettings.Profile.UsedDViewDelay;
                }
                else if (wsplit.split.LiveRun)
                {
                    clockColor = ColorSettings.Profile.AheadFore;
                    this.clockGrColor = ColorSettings.Profile.AheadBack;
                    this.clockGrColor2 = ColorSettings.Profile.AheadBack2;
                    this.clockPlainColor = ColorSettings.Profile.AheadBackPlain;

                    dViewClockColor = ColorSettings.Profile.UsedDViewAhead;
                }
                else
                {
                    clockColor = ColorSettings.Profile.WatchFore;
                    this.clockGrColor = ColorSettings.Profile.WatchBack;
                    this.clockGrColor2 = ColorSettings.Profile.WatchBack2;
                    this.clockPlainColor = ColorSettings.Profile.WatchBackPlain;

                    dViewClockColor = ColorSettings.Profile.UsedDViewAhead;
                }

                if (clockColor != this.clockColor)
                {
                    this.RequestBackgroundRedraw();
                    this.clockColor = clockColor;
                }

                Brush brush = new SolidBrush(this.clockColor);
                wsplit.dview.clockColor = new SolidBrush(dViewClockColor);

                if (span2.TotalHours >= 100.0)
                    wsplit.dview.clockText = string.Format("{0:000}:{1:00}:{2:00.00}", Math.Floor((double)(span2.TotalHours % 1000.0)), span2.Minutes, span2.Seconds + (Math.Floor((double)(((float)span2.Milliseconds) / 10f)) / 100.0));
                else if (span2.TotalHours >= 1.0)
                    wsplit.dview.clockText = string.Format("{0:0}:{1:00}:{2:00.00}", Math.Floor((double)(span2.TotalHours % 1000.0)), span2.Minutes, span2.Seconds + (Math.Floor((double)(((float)span2.Milliseconds) / 10f)) / 100.0));
                else
                    wsplit.dview.clockText = string.Format("{0:00}:{1:00.00}", span2.Minutes, span2.Seconds + (Math.Floor((double)(((float)span2.Milliseconds) / 10f)) / 100.0));

                wsplit.dview.Invalidate();

                Rectangle layoutRectangle = new Rectangle();
                Rectangle rectangle2 = new Rectangle();
                StringFormat format = new StringFormat();
                StringFormat format2 = new StringFormat();

                string text = "";
                string str4 = "";

                double num10 = 0.0;
                Brush white = Brushes.White;

                if (wsplit.currentDispMode != DisplayMode.Timer)
                {
                    if (wsplit.currentDispMode == DisplayMode.Wide)
                    {
                        layoutRectangle = new Rectangle(wsplit.Width - 119, 2, 119, wsplit.Height / 2);
                        rectangle2 = new Rectangle(wsplit.Width - 119, layoutRectangle.Bottom - 2, 119, wsplit.Height / 2);
                    }
                    else if (wsplit.currentDispMode == DisplayMode.Detailed)
                    {
                        layoutRectangle = new Rectangle(0, 0, 0, 0);
                        rectangle2 = new Rectangle(1, wsplit.clockRect.Bottom + 2, wsplit.Width - 1, 16);
                    }
                    else
                    {
                        rectangle2 = new Rectangle(1, 2, wsplit.Width - 1, 13);
                        layoutRectangle = new Rectangle(1, wsplit.clockRect.Bottom + 2, wsplit.Width - 1, 14);
                        if ((Settings.Profile.SegmentIcons > 0) && !wsplit.split.Done)
                        {
                            rectangle2.Width -= 2 + x;
                            rectangle2.X += 2 + x;
                        }
                    }

                    format.LineAlignment = StringAlignment.Center;
                    format.Trimming = StringTrimming.EllipsisCharacter;
                    format.Alignment = StringAlignment.Far;
                    format2 = (StringFormat)format.Clone();

                    if (wsplit.currentDispMode == DisplayMode.Compact)
                        format2.Alignment = StringAlignment.Near;

                    if (num3 <= 0.0)
                        this.segLosingTime = false;

                    if (wsplit.timer.ElapsedTicks != 0L)
                    {
                        if (wsplit.split.Done)
                        {
                            if (wsplit.split.CompTime(wsplit.split.LastIndex) != 0.0)
                            {
                                num10 = wsplit.split.SegDelta(wsplit.split.LastSegment.LiveTime, wsplit.split.LastIndex);
                                text = wsplit.timeFormatter(num10, TimeFormat.DeltaShort);
                            }
                        }
                        // If we are losing time on the current segment...
                        else if (num3 > 0.0)
                        {
                            num10 = num3;   // The number to be written becomes the current segment delta
                            text = wsplit.timeFormatter(num10, TimeFormat.DeltaShort);

                            // If we just started losing time, we indicate we are and we ask for a redraw of the timer background since color has changed
                            if (!this.segLosingTime)
                            {
                                this.segLosingTime = true;
                                this.RequestBackgroundRedraw();
                            }
                        }

                        // If we aren't losing time on the current segment and if the current segment isn't the first segment...
                        else if (wsplit.split.LiveIndex > 0)
                        {
                            // The number to be written becomes the previous segment delta:
                            num10 = wsplit.split.SegDelta(wsplit.split.segments[wsplit.split.LiveIndex - 1].LiveTime, wsplit.split.LiveIndex - 1);

                            // Though, if the previous split was skipped or if the previous split had no time, we don't write anything...
                            // wsplit will probably change.
                            if ((wsplit.split.segments[wsplit.split.LiveIndex - 1].LiveTime > 0.0) && (wsplit.split.CompTime(wsplit.split.LiveIndex - 1) != 0.0))
                            {
                                text = wsplit.timeFormatter(num10, TimeFormat.DeltaShort);
                            }
                        }
                    }

                    // If we're not in the Detailed display mode
                    if (wsplit.currentDispMode != DisplayMode.Detailed)
                    {
                        // If splits are done
                        if (wsplit.split.Done)
                        {
                            if (wsplit.split.CompTime(wsplit.split.LastIndex) != 0.0)
                            {
                                double num11 = wsplit.split.RunDeltaAt(wsplit.split.LastIndex);
                                str4 = wsplit.timeFormatter(num11, TimeFormat.Delta);
                                if (num11 < 0.0)
                                {
                                    white = new SolidBrush(ColorSettings.Profile.RecordFore);
                                }
                                else
                                {
                                    white = new SolidBrush(ColorSettings.Profile.FinishedFore);
                                }
                            }
                        }

                        // If we are losing time on the current segment...
                        else if (num3 > 0.0)
                        {
                            // Format the run delta in str4
                            str4 = wsplit.timeFormatter(secs, TimeFormat.Delta);

                            if (secs < 0.0) // If ahead overall | Is wsplit part of the code even useful?
                            {
                                white = new SolidBrush(ColorSettings.Profile.SegAheadGain);
                            }
                            else            // If behind overall
                            {
                                white = new SolidBrush(ColorSettings.Profile.SegBehindLoss);
                            }
                        }

                        // If there is a previous split time and there is a time to compare it to...
                        else if (((wsplit.split.LiveIndex > 0) && (wsplit.split.segments[wsplit.split.LiveIndex - 1].LiveTime > 0.0)) && (wsplit.split.CompTime(wsplit.split.LiveIndex - 1) != 0.0))
                        {
                            // Stores the run delta at the previous split in num12
                            double num12 = wsplit.split.RunDeltaAt(wsplit.split.LiveIndex - 1);
                            str4 = wsplit.timeFormatter(num12, TimeFormat.Delta);
                            if (num12 < 0.0)
                            {
                                white = new SolidBrush(ColorSettings.Profile.SegAheadLoss);
                            }
                            else
                            {
                                white = new SolidBrush(ColorSettings.Profile.SegBehindGain);
                            }
                        }
                    }

                    if (text.Length != this.segDelLength)
                    {
                        this.segDelLength = text.Length;
                        this.segDeltaWidth = MeasureDisplayStringWidth(text, wsplit.timeFont);
                        this.RequestBackgroundRedraw();
                    }

                    if (str4.Length != this.runDelLength)
                    {
                        this.runDelLength = str4.Length;
                        this.runDeltaWidth = MeasureDisplayStringWidth(str4, wsplit.timeFont);
                        this.RequestBackgroundRedraw();
                    }
                }

                int num13 = 0;
                int num14 = (wsplit.split.LiveIndex - num5) + 2;
                int liveIndex = wsplit.split.LiveIndex;
                if (num5 >= 2)
                {
                    liveIndex--;
                }
                if (((wsplit.currentDispMode == DisplayMode.Detailed) && Settings.Profile.ShowLastDetailed) || ((wsplit.currentDispMode == DisplayMode.Wide) && Settings.Profile.ShowLastWide))
                {
                    num14++;
                }
                num13 = Math.Max(0, Math.Min(liveIndex, Math.Min((wsplit.split.LastIndex - num5) + 1, num14)));
                Rectangle rectangle3 = new Rectangle();
                Color timeColor = wsplit.split.CurrentSegment.TimeColor;
                string timeString = wsplit.split.CurrentSegment.TimeString;

                // If in wide or detailed desplay mode and if not done...
                if (((wsplit.currentDispMode == DisplayMode.Wide) || (wsplit.currentDispMode == DisplayMode.Detailed)) && !wsplit.split.Done)
                {
                    this.runLosingTime = false; // Not losing time... ?

                    // If there is a time to compare to and one current segment delta or run delta is greater than 0.0
                    if ((wsplit.split.CompTime() > 0.0) && ((num3 > 0.0) || (secs > 0.0)))
                    {
                        this.runLosingTime = true;  // Losing time...
                        // Formats run delta in timeString:
                        //timeString = wsplit.timeFormatter(secs, TimeFormat.Delta);
                    }
                    // If losing time and in detailed display mode, and if Segment height (so Icon size) is smaller or equal to 24 pixels and length has changed...
                    if ((this.runLosingTime && (wsplit.currentDispMode == DisplayMode.Detailed)) && ((wsplit.segHeight <= 0x18) && (timeString.Length != this.segTimeLength)))
                    {
                        this.segTimeLength = timeString.Length;
                        this.segTimeWidth = MeasureDisplayStringWidth(timeString, wsplit.timeFont);
                        this.RequestBackgroundRedraw();
                    }

                    // If in the Wide display mode...
                    if (wsplit.currentDispMode == DisplayMode.Wide)
                        rectangle3 = new Rectangle((wsplit.clockRect.Right + (wsplit.wideSegWidth * (wsplit.split.LiveIndex - num13))) + 4, wsplit.Height / 2, (wsplit.wideSegWidth - x) - 2, wsplit.Height / 2);
                    // Otherwise...
                    else
                    {
                        // Builds a rectangle for the live segment time
                        rectangle3 = new Rectangle(x, wsplit.segHeight * (wsplit.split.LiveIndex - num13), wsplit.Width - x, wsplit.segHeight);
                        // Moves the rectangle down if we have to show the run title

                        if (((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle) && ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal))
                        {
                            rectangle3.Y += 0x20;
                        }
                        else if ((wsplit.split.RunTitle != "") && Settings.Profile.ShowTitle)
                        {
                            rectangle3.Y += 0x12;
                        }
                        else if ((wsplit.split.RunGoal != "") && Settings.Profile.ShowGoal)
                        {
                            rectangle3.Y += 0x12;
                        }
                        // If greater than 24 pixels icons
                        if (wsplit.segHeight > 0x18)
                        {
                            // Goes to the second half of the rectangle
                            rectangle3.Height /= 2;
                            rectangle3.Y += rectangle3.Height;
                        }
                        // Otherwise, moves down 1 pixel.
                        else
                        {
                            rectangle3.Y++;
                        }
                    }
                }

                // Temporary signature of the method
                this.DrawBackground(graphics, angle, num5, num8, num13, x);

                // Code for drawing clock fore has been moved to another function. Current method's signature is temporary
                this.DrawClockFore(graphics, timeStringAbsPart, ref timeStringDecPart, flag, num8, ref brush);

                if (wsplit.currentDispMode != DisplayMode.Timer)
                {
                    graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                    //graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                    // At this point...
                    // num3 -> Current segment delta
                    // num10 -> What has to be written in the status bar

                    // If the time to write in the status bar is a new best segment...
                    /* apparently this always runs m8 */
                    if (Settings.Profile.ShowPrevSeg)
                    {
                        if (!this.segLosingTime && wsplit.split.LiveIndex > 0 &&
                            wsplit.split.LiveSegment(wsplit.split.LiveIndex - 1) != 0.0 && (wsplit.split.segments[wsplit.split.LiveIndex - 1].BestSegment == 0.0 ||
                            wsplit.split.LiveSegment(wsplit.split.LiveIndex - 1) < wsplit.split.segments[wsplit.split.LiveIndex - 1].BestSegment))
                        {
                            if (Settings.Profile.RainbowSplits)
                            {
                                graphics.DrawString(text, wsplit.timeFont, new SolidBrush(ColorSettings.Profile.SegRainbow), rectangle2, format);
                            }
                            else
                            {
                                graphics.DrawString(text, wsplit.timeFont, new SolidBrush(ColorSettings.Profile.SegBestSegment), rectangle2, format);
                            };
                        }
                        // Else, if The time to write in the status bar is a time loss...
                        else if (num10 > 0.0)
                        {
                            graphics.DrawString(text, wsplit.timeFont, new SolidBrush(ColorSettings.Profile.SegBehindLoss), rectangle2, format);
                        }
                        // Otherwise (the time is a time gain but not a best segment), or there is not time to write...
                        else
                        {
                            graphics.DrawString(text, wsplit.timeFont, new SolidBrush(ColorSettings.Profile.SegAheadGain), rectangle2, format);
                        }
                    };
                    if (wsplit.currentDispMode != DisplayMode.Detailed)
                    {
                        graphics.DrawString(str4, wsplit.timeFont, white, layoutRectangle, format2);
                    }
                }
                if (((wsplit.currentDispMode == DisplayMode.Wide) || (wsplit.currentDispMode == DisplayMode.Detailed)) && !wsplit.split.Done)
                {
                    StringFormat format9 = new StringFormat
                    {
                        LineAlignment = StringAlignment.Center
                    };

                    if (wsplit.currentDispMode == DisplayMode.Wide)
                        format9.Alignment = StringAlignment.Near;
                    else
                        format9.Alignment = StringAlignment.Far;

                    graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                    //graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                    graphics.DrawString(timeString, wsplit.timeFont, new SolidBrush(timeColor), rectangle3, format9);
                }
            }
Beispiel #10
0
        void DrawString(Graphics g, Brush brush, ref Rectangle rect, out Size used,
                                StringFormat format, string text, Font font)
        {
            using (StringFormat copy = (StringFormat)format.Clone())
            {
                copy.SetMeasurableCharacterRanges(new CharacterRange[]
                    {
                        new CharacterRange(0, text.Length)
                    });
                Region[] regions = g.MeasureCharacterRanges(text, font, rect, copy);

                g.DrawString(text, font, brush, rect, format);

                int height = (int)(regions[0].GetBounds(g).Height);
                int width = (int)(regions[0].GetBounds(g).Width);

                // First just one line...
                used = new Size(width, height);

                rect.X += width;
                rect.Width -= width;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Draws label string in oriented way.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="labelCaption"></param>
        /// <param name="labelFont"></param>
        /// <param name="labelBrush"></param>
        /// <param name="yOffset">Y Offset value (in pixel)</param>
        /// <param name="xyLocation"></param>
        /// <param name="_stringFormat"></param>
        /// <param name="orientationAngle">-90 to +90 degrees</param>
        private void DrawString(Graphics g, string labelCaption, bool ShowLabelAboveChart, Font labelFont, Brush labelBrush, PointF xyLocation, int yOffset, StringFormat _stringFormat, int orientationAngle)
        {
            try
            {
                //-- Apply Y Offset Settings
                xyLocation.Y += (-1) * yOffset;

                //- Get Label's measurement
                SizeF labelSize = g.MeasureString(labelCaption, labelFont);

                if (orientationAngle != 0)
                {
                    orientationAngle = orientationAngle * -1;

                    //-- To draw orientated text label,
                    // draw string in new graphics object with Rotation applied,
                    // convert that into image object and then add image object into original graphics object

                    StringFormat NewStringFormat = (StringFormat)(_stringFormat.Clone());
                    NewStringFormat.Alignment = StringAlignment.Near;

                    //-- Get image rectangular Area considering Label's orientationAngle too (height should accomodate orientation)
                    Bitmap stringImg = new Bitmap((int)labelSize.Width + 10, (int)(labelSize.Width) + 10);

                    Graphics gbitmap = Graphics.FromImage(stringImg);

                    gbitmap.SmoothingMode = SmoothingMode.AntiAlias;
                    gbitmap.Clear(Color.Transparent);

                    PointF xyPos = new PointF();
                    xyPos.X = 0 - labelSize.Width / 2;
                    xyPos.Y = 0 - labelSize.Height / 2;

                    int TextOffsetX = (int)(labelSize.Height / 2);

                    //-- Calculate transformed distance caused due to rotation
                    float XTransformed = TextOffsetX + labelSize.Width / 2;
                    float YTransformed = TextOffsetX + labelSize.Width / 2;

                    gbitmap.TranslateTransform(XTransformed, YTransformed);
                    gbitmap.RotateTransform(orientationAngle);

                    gbitmap.DrawString(labelCaption, labelFont, labelBrush, xyPos, NewStringFormat);

                    //add image object into original graphics object
                    if (ShowLabelAboveChart)
                    {
                        //-- Show label above Chart (i.e Case of DataValue Label)
                        g.DrawImage(stringImg, xyLocation.X - (labelSize.Width / 2), xyLocation.Y - (labelSize.Width * 0.75F) - (labelSize.Width * 0.56F) * (float)(Math.Sin(Math.Abs(orientationAngle) * Math.PI / 180)));
                    }
                    else
                    {
                        //-- Show label below Chart (i.e Case of TimePeriod Label)
                        g.DrawImage(stringImg, xyLocation.X + 2 - (labelSize.Width / 2) - TextOffsetX / 2, xyLocation.Y - (labelSize.Height / 2) - TextOffsetX);
                    }

                    //dispose your bitmap and graphics objects at the end of onpaint
                    gbitmap.Dispose();
                    stringImg.Dispose();
                }
                else
                {
                    if (ShowLabelAboveChart)
                    {
                        xyLocation.Y = xyLocation.Y - (labelSize.Height * 0.5F);
                    }
                    g.DrawString(labelCaption, labelFont, labelBrush, xyLocation, _stringFormat);
                }
            }
            catch
            {
            }
        }
Beispiel #12
0
		public void Clone_Complex ()
		{
			using (StringFormat sf = new StringFormat ()) {
				CharacterRange[] ranges = new CharacterRange [2];
				ranges[0].First = 1;
				ranges[0].Length = 2;
				ranges[1].First = 3;
				ranges[1].Length = 4;
				sf.SetMeasurableCharacterRanges (ranges);

				float[] stops = new float [2];
				stops [0] = 6.0f;
				stops [1] = 7.0f;
				sf.SetTabStops (5.0f, stops);

				using (StringFormat clone = (StringFormat) sf.Clone ()) {
					CheckDefaults (clone);

					float first;
					float[] cloned_stops = clone.GetTabStops (out first);
					Assert.AreEqual (5.0f, first, "first");
					Assert.AreEqual (6.0f, cloned_stops[0], "cloned_stops[0]");
					Assert.AreEqual (7.0f, cloned_stops[1], "cloned_stops[1]");
				}
			}
		}
Beispiel #13
0
		public void Clone() 
		{
			using (StringFormat sf = new StringFormat ()) {
				using (StringFormat clone = (StringFormat) sf.Clone ()) {
					CheckDefaults (clone);
				}
			}
		}
    public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, Font font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
    {
      

      MeasuredLabelItem[] litems = new MeasuredLabelItem[items.Length];

      Font localfont1 = (Font)font.Clone();
      Font localfont2 = new Font(font.FontFamily, font.Size * 2 / 3, font.Style, GraphicsUnit.World);
     
      StringFormat localstrfmt = (StringFormat)strfmt.Clone();

      string[] firstp = new string[items.Length];
      string[] expos = new string[items.Length];

      float maxexposize=0;
      for (int i = 0; i < items.Length; ++i)
      {
        string firstpart, exponent;
        if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble))
        {
          SplitInFirstPartAndExponent((double)items[i], out firstpart, out exponent);
        }
        else
        {
          firstpart = items[i].ToString(); exponent = string.Empty;
        }
        firstp[i] = firstpart;
        expos[i] = exponent;
        maxexposize = Math.Max(maxexposize,g.MeasureString(exponent,localfont2,new PointF(0,0),strfmt).Width);
      }


      for (int i = 0; i < items.Length; ++i)
      {
        litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, localstrfmt, firstp[i],expos[i],maxexposize);
      }

      return litems;
      
    }
		public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
		{
			MeasuredLabelItem[] litems = new MeasuredLabelItem[items.Length];

			FontX localfont1 = font;
			FontX localfont2 = font.WithSize(font.Size * 2 / 3);

			StringFormat localstrfmt = (StringFormat)strfmt.Clone();

			string[] firstp = new string[items.Length];
			string[] middel = new string[items.Length];
			string[] expos = new string[items.Length];
			double[] mants = new double[items.Length];

			float maxexposize = 0;
			int firstpartmin = int.MaxValue;
			int firstpartmax = int.MinValue;
			for (int i = 0; i < items.Length; ++i)
			{
				string firstpart, exponent;
				if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble))
				{
					SplitInFirstPartAndExponent((double)items[i], out firstpart, out mants[i], out middel[i], out exponent);
					if (exponent.Length > 0)
					{
						firstpartmin = Math.Min(firstpartmin, firstpart.Length);
						firstpartmax = Math.Max(firstpartmax, firstpart.Length);
					}
				}
				else
				{
					firstpart = items[i].ToString(); middel[i] = string.Empty; exponent = string.Empty;
				}
				firstp[i] = firstpart;
				expos[i] = exponent;
				maxexposize = Math.Max(maxexposize, g.MeasureString(exponent, GdiFontManager.ToGdi(localfont2), new PointF(0, 0), strfmt).Width);
			}

			if (firstpartmax > 0 && firstpartmax > firstpartmin) // then we must use special measures to equilibrate the mantissa
			{
				firstp = NumericLabelFormattingAuto.FormatItems(mants);
			}

			for (int i = 0; i < items.Length; ++i)
			{
				string mid = string.Empty;
				if (!string.IsNullOrEmpty(expos[i]))
				{
					if (string.IsNullOrEmpty(firstp[i]))
						mid = "10";
					else
						mid = "\u00D710";
				}
				litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, localstrfmt, _prefix + firstp[i] + mid, expos[i], _suffix, maxexposize);
			}

			return litems;
		}