RelLineTo() public method

public RelLineTo ( Distance d ) : void
d Distance
return void
Beispiel #1
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        gr.MoveTo(new PointD(0.5, 0.1));
        gr.LineTo(new PointD(0.9, 0.9));
        gr.RelLineTo(new Distance(-0.4, 0.0));
        gr.CurveTo(new PointD(0.2, 0.9),
                   new PointD(0.2, 0.5),
                   new PointD(0.5, 0.5)
                   );
        gr.ClosePath();

        gr.MoveTo(new PointD(0.25, 0.1));
        gr.RelLineTo(new Distance(0.2, 0.2));
        gr.RelLineTo(new Distance(-0.2, 0.2));
        gr.RelLineTo(new Distance(-0.2, -0.2));
        gr.ClosePath();

        gr.Color = new Color(0, 0, 1, 1);
        gr.FillPreserve();
        gr.Color = new Color(0, 0, 0, 1);
        gr.Stroke();
    }
Beispiel #2
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            using (Cairo.Context ctx = CairoHelper.Create(evnt.Window)) {
                int dx = (int)((double)Allocation.Width * dividerPosition);
                ctx.LineWidth = 1;
                ctx.Rectangle(0, 0, dx, Allocation.Height);
                ctx.SetSourceColor(LabelBackgroundColor);
                ctx.Fill();
                ctx.Rectangle(dx, 0, Allocation.Width - dx, Allocation.Height);
                ctx.SetSourceRGB(1, 1, 1);
                ctx.Fill();

                if (PropertyContentRightPadding > 0)
                {
                    ctx.Rectangle(Allocation.Width - PropertyContentRightPadding, 0, PropertyContentRightPadding, Allocation.Height);
                    ctx.SetSourceColor(LabelBackgroundColor);
                    ctx.Fill();

                    ctx.MoveTo(Allocation.Width - PropertyContentRightPadding + 0.5, 0);
                    ctx.RelLineTo(0, Allocation.Height);
                    ctx.SetSourceColor(DividerColor);
                    ctx.Stroke();
                }

                ctx.MoveTo(dx + 0.5, 0);
                ctx.RelLineTo(0, Allocation.Height);
                ctx.SetSourceColor(DividerColor);
                ctx.Stroke();

                int y = 0;
                Draw(ctx, rows, dx, PropertyLeftPadding, ref y);
            }
            return(base.OnExposeEvent(evnt));
        }
Beispiel #3
0
        private void DrawOutputndicator(Cairo.Context context)
        {
            context.Save();
            RelativeLocator locator = new RelativeLocator(-0.04, 1.2);
            PointD          point   = locator.Locate(this);

            context.MoveTo(point);
            context.LineCap = LineCap.Round;
            context.Color   = s_ioIndicatorColor;

            double l = 4;   //arm lenght of indicator icon
            double s = 0.4; //spacing between arms in the indicator icon

            //draw <<
            //up
            context.RelLineTo(new Distance(-s, -l));
            context.RelMoveTo(new Distance(s, l));   //back

            //right
            context.RelLineTo(new Distance(l, s));
            context.RelMoveTo(new Distance(-l, -s));   //back

            context.RelMoveTo(new Distance(3, -3));

            //repeat above for second arrow
            context.RelLineTo(new Distance(-s, -l));
            context.RelMoveTo(new Distance(s, l));   //back
            context.RelLineTo(new Distance(l, s));
            context.RelMoveTo(new Distance(-l, -s)); //back

            context.Stroke();

            context.Restore();
        }
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (this.isDirty)
            {
                this.Rebuild();
            }

            bool baseDrawnResult = base.OnDrawn(cr);

            cr.SetFontSize(FONT_HEIGHT);
            cr.SelectFontFace("Mono", FontSlant.Normal, FontWeight.Normal);

            cr.Rectangle(0.0, 0.0, this.allocRect.Width, this.allocRect.Height);
            cr.SetSourceRGB(1, 1, 1);
            cr.Fill();

            var gradient = new LinearGradient(0.0, 0.0, 0.0, this.allocRect.Height);

            gradient.AddColorStopRgb(0.0, new Color(0.4, 0.4, 0.4));
            gradient.AddColorStopRgb(0.1, new Color(1.0, 1.0, 1.0));
            gradient.AddColorStopRgb(0.2, new Color(0.6, 0.6, 0.6));
            gradient.AddColorStopRgb(1.0, new Color(0.1, 0.1, 0.1));

            cr.LineWidth = 1;

            foreach (var box in this.boxen)
            {
                this.RoundedRect(cr, box.Rect, 4.0);
                cr.SetSource(gradient);
                cr.FillPreserve();
                cr.SetSourceRGB(0, 0, 0);
                cr.Stroke();


                int x = (int)(box.Rect.X + TAGBOX_PADDING * 2 + TAGBOX_XSIZE);
                int y = (int)(box.Rect.Y + box.Rect.Height / 2 + cr.FontExtents.Height / 2 - cr.FontExtents.Descent / 2);
                cr.MoveTo(x, y);
                cr.TextPath(box.Tag);
                cr.SetSourceRGB(1.0, 1.0, 1.0);
                cr.Fill();

                cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XOFFSET);
                cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, TAGBOX_XSIZE - TAGBOX_XOFFSET * 2);
                cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XSIZE - TAGBOX_XOFFSET);
                cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, -TAGBOX_XSIZE + TAGBOX_XOFFSET * 2);
                cr.Stroke();
            }

            return(baseDrawnResult);
        }
Beispiel #5
0
 void DrawMarker(Cairo.Context cr, ref Cairo.Color color, int sampleIndex)
 {
     SetColor(cr, ref color);
     cr.MoveTo(WorldToPhysicalX(sampleIndex), 0);
     cr.RelLineTo(0, height);
     cr.Stroke();
 }
Beispiel #6
0
        void DrawButtonTabs(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            int topPadding = 2;

            if (Active || HoverPosition.X >= 0)
            {
                cr.NewPath();
                cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding);
                cr.ClosePath();
                if (Active)
                {
                    cr.Color = (HslColor)parent.Style.Background(StateType.Prelight);
                }
                else if (HoverPosition.X >= 0)
                {
                    double rx = rectangle.X + HoverPosition.X;
                    double ry = rectangle.Y + HoverPosition.Y;
                    Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5,
                                                                             rx, ry, 2);
                    var color = (HslColor)parent.Style.Dark(StateType.Normal);
                    color.L *= 1.1;
                    gradient.AddColorStop(0, color);
                    color.L *= 1.1;
                    gradient.AddColorStop(1, color);
                    cr.Pattern = gradient;
                }
                if (!Active)
                {
                    cr.Fill();
                }
                else
                {
                    cr.FillPreserve();
                    cr.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
            }

            cr.Save();
            cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding);
            cr.Color = (HslColor)parent.Style.Text(StateType.Normal);

            cr.ShowLayout(layout);

            cr.Restore();
        }
Beispiel #7
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        gr.AddColorStop(0, Tabstrip.ActiveGradientStart);
                        gr.AddColorStop(1, Tabstrip.ActiveGradientEnd);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                    cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1);
                    cr.SetSourceRGBA(1, 1, 1, 0.05);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        var c1 = Tabstrip.ActiveGradientStart;
                        var c2 = Tabstrip.ActiveGradientEnd;
                        c1.A = 0.2;
                        c2.A = 0.2;
                        gr.AddColorStop(0, c1);
                        gr.AddColorStop(1, c2);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceRGB(1, 1, 1);
            }
            else
            {
                cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor());
            }

            cr.MoveTo(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }
Beispiel #8
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(Styles.SubTabBarSeparatorColor.ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    cr.SetSourceColor(Styles.SubTabBarActiveBackgroundColor.ToCairoColor());
                    cr.Fill();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    cr.SetSourceColor(Styles.SubTabBarHoverBackgroundColor.ToCairoColor());
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceColor(Styles.SubTabBarActiveTextColor.ToCairoColor());
                layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11, Pango.Weight.Bold);
            }
            else
            {
                cr.SetSourceColor(Styles.SubTabBarTextColor.ToCairoColor());
                layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11);
            }

            layout.Width = (int)rectangle.Width;

            cr.MoveTo(rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 - 1);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            using (Cairo.Context ctx = CairoHelper.Create(evnt.Window)) {
                int dx = (int)((double)Allocation.Width * dividerPosition);
                ctx.LineWidth = 1;
                ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                ctx.SetSourceColor(Styles.PropertyPadLabelBackgroundColor.ToCairoColor());
                ctx.Fill();
                ctx.MoveTo(dx + 0.5, 0);
                ctx.RelLineTo(0, Allocation.Height);
                ctx.SetSourceColor(Styles.PropertyPadDividerColor.ToCairoColor());
                ctx.Stroke();

                int y = 0;
                Draw(ctx, rows, dx, PropertyLeftPadding, ref y);
            }
            return(base.OnExposeEvent(evnt));
        }
Beispiel #10
0
 void DrawMarkedPositions(Cairo.Context cr)
 {
     if (MarkedPositionsToDisplay)
     {
         SetColor(cr, ref ColorMarkedPos);
         if (markedPositions.Length == PosSize)
         {
             // all positions are marked
             Rectangle(cr, ref totalRect);
             cr.Fill();
         }
         else
         {
             foreach (int i in markedPositions)
             {
                 cr.MoveTo(WorldToPhysicalX(i), 0);
                 cr.RelLineTo(0, height);
             }
             // single call is much faster
             cr.Stroke();
         }
     }
 }
Beispiel #11
0
		public void set_line_join(Context cr, int width, int height)
		{
			Normalize(cr, width, height);
			cr.LineWidth = 0.16;
			cr.MoveTo(0.3, 0.33);
			cr.RelLineTo(0.2, -0.2);
			cr.RelLineTo(0.2, 0.2);
			cr.LineJoin = LineJoin.Miter; // default
			cr.Stroke();

			cr.MoveTo(0.3, 0.63);
			cr.RelLineTo(0.2, -0.2);
			cr.RelLineTo(0.2, 0.2);
			cr.LineJoin = LineJoin.Bevel;
			cr.Stroke();

			cr.MoveTo(0.3, 0.93);
			cr.RelLineTo(0.2, -0.2);
			cr.RelLineTo(0.2, 0.2);
			cr.LineJoin = LineJoin.Round;
			cr.Stroke();
		}
Beispiel #12
0
 public static void DrawText(Context cr, string family, double fontSize, string text, Pango.Alignment alignment)
 {
     //   return;
       lock (FontCache) {
     //   LogError("DrawText {0}", text);
     Profiler p = new Profiler ("DrawText");
     double w,h;
     Pango.Layout layout = GetLayout (cr, family, QuantizeFontSize(fontSize));
     layout.SetText (text);
     layout.Alignment = alignment;
     layout.GetExtents(out pe, out le);
     p.Time ("GetExtents {0}", pe);
     w = (double)le.Width / (double)Pango.Scale.PangoScale;
     h = (double)le.Height / (double)Pango.Scale.PangoScale;
     if (alignment == Pango.Alignment.Right) {
       cr.RelMoveTo (-w, 0);
     } else if (alignment == Pango.Alignment.Center) {
       cr.RelMoveTo (-w/2, 0);
     }
     Pango.CairoHelper.ShowLayout (cr, layout);
     p.Time ("ShowLayout");
     if (ShowTextExtents) {
       cr.Save ();
     PointD pt = cr.CurrentPoint;
     cr.MoveTo (pt.X, pt.Y);
     cr.RelLineTo(w, 0);
     cr.RelLineTo(0, h);
     cr.Operator = Operator.Over;
     cr.Color = new Color (1,0.5,1,0.5);
     cr.LineWidth = 0.5;
     cr.Stroke ();
     cr.MoveTo (pt.X, pt.Y);
       cr.Restore ();
     }
     cr.RelMoveTo (w, 0);
       }
 }
 protected override void PaintWidget(Context ctx, int w, int h)
 {
     ctx.Rectangle (0.0d, 0.0d, w, h);
     ctx.SetFill (BlueprintStyle.BluePrint);
     double wb = w - Offset - xb - 4.0d;
     double xbt = wb * (current - min) / (max - min) - 4.0d;
     ctx.Fill ();
     switch (this.mode) {
     case MediaMode.Play:
         ctx.Rectangle (Offset + 2, 1.0d, 8.0d, 32.0d);
         ctx.Rectangle (Offset + 18, 1.0d, 8.0d, 32.0d);
         ctx.ClosePath ();
         break;
     default:
         ctx.MoveTo (Offset, 1.0d);
         ctx.RelLineTo (32.0d, 16.0d);
         ctx.RelLineTo (-32.0d, 16.0d);
         ctx.ClosePath ();
         break;
     }
     double xf = xb + xbt;
     double xt = xf + 8.0d;
     ctx.Rectangle (xf, 1.0d, 8.0d, 32.0d);
     this.xtickS = xf;
     this.xtickE = xt;
     ctx.SetFill (BlueprintStyle.FillPattern);
     ctx.FillPreserve ();
     ctx.SetFill (BlueprintStyle.HardWhite);
     if (xbt > 0.0d) {
         ctx.MoveTo (xb, 16.0d);
         ctx.LineTo (xf, 16.0d);
     }
     if (xf < w - Offset - 4.0d) {
         ctx.MoveTo (xt, 16.0d);
         ctx.LineTo (w - Offset - 4.0d, 16.0d);
     }
     foreach (double t in this.Chapters) {
         double x = this.TtoX (t);
         if (x < xf || x >= xt) {
             ctx.MoveTo (x, 0.0d);
             ctx.LineTo (x, 33.0d);
         }
     }
     ctx.Stroke ();
 }
Beispiel #14
0
 public virtual void Paint(Context ctx)
 {
     PointD size = this.MeasureSize (ctx);
     PaintContour (ctx,size);
     KnownColors.SetFontFacePieceName(ctx);
     TextExtents te = ctx.TextExtents(this.Name), ten;
     double y0 = 0.5d*(size.Y-te.Width);
     ctx.MoveTo(0.5d*Margin,y0);
     ctx.Save();
     ctx.Rotate(0.5d*Math.PI);
     ctx.ShowText(this.Name);
     ctx.Restore();
     double x0 = Margin+te.Height;
     KnownColors.SetFontFaceNormal(ctx);
     te = ctx.TextExtents(OptionalString);
     y0 = 2.0d*Margin;
     int index = 0x00;
     PointD siz;
     foreach(IPuzzlePiece ipp in this.arguments) {
         ctx.Save();
         ctx.Translate(x0,Margin);
         if(ipp == null) {
             siz = new PointD(MinimumWidth,size.Y-4.0d*Margin);
             ctx.Rectangle(Margin,Margin,siz.X,siz.Y);
             ctx.Pattern = KnownColors.ConstructionPattern;
             ctx.FillPreserve();
         }
         else {
             siz = ipp.MeasureSize(ctx);
         }
         ctx.Rectangle(0.0d,0.0d,siz.X+2.0d*Margin,siz.Y+2.0d*Margin);
         ctx.Color = KnownColors.Black;
         ctx.StrokePreserve();
         if(ipp == null) {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Translate(Margin,Margin);
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(MinimumWidth,0.0d);
             ctx.RelLineTo(0.0d,5.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowDownPattern;
             ctx.Fill();
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(0.0d,siz.Y);
             ctx.RelLineTo(5.0d,0.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowRightPattern;
             ctx.Fill();
         }
         else {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Color = KnownColors.Black;
             ctx.Translate(Margin,Margin);
             ipp.Paint(ctx);
         }
         ctx.Restore();
         subpieces[index] = new Rectangle(x0+Margin,2.0d*Margin,siz.X,siz.Y);
         x0 += siz.X+3.0d*Margin;
         if(index >= NumberOfArguments-NumberOfOptionalArguments) {
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+te.Width),siz.Y+3.0d*Margin-2.0d);
             ctx.ShowText(OptionalString);
         }
         if(this.ArgumentNames != null && index < arguments.Length) {
             ten = ctx.TextExtents(this.ArgumentNames[index]);
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+ten.Width),-te.YBearing+Margin+2.0d);
             ctx.ShowText(this.ArgumentNames[index]);
         }
         index++;
     }
 }
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            var baseResult = base.OnExposeEvent(evnt);

            if (TrackerCore.Instance.TaskManager is EmptyTaskManager)
            {
                return(baseResult);
            }

            Source = TrackerCore.Instance.TaskManager.AssigmentSource;

            var v1        = Source.Tables["DataRange"].Rows[0]["MinDate"];
            var firstDate = v1 as DateTime? ?? DateTime.Now;
            var v2        = Source.Tables["DataRange"].Rows[0]["MaxDate"];
            var lastDate  = v2 as DateTime? ?? DateTime.Now;
            var deltaSpan = lastDate.Subtract(firstDate);

            // Insert drawing code here.
            if (grw == null)
            {
                grw = Gdk.CairoHelper.Create(GdkWindow);
            }

            int fX, fY, fWidth, fHeight, fDepth;

            GdkWindow.GetGeometry(out fX, out fY, out fWidth, out fHeight, out fDepth);

            fWidth  -= 3;
            fHeight -= 3;

            var delta = (deltaSpan.Days > 0) ?
                        (fWidth - 2 * FBorderMarginH) / deltaSpan.Days :
                        (fWidth - 2 * FBorderMarginH);

            GdkWindow.ClearArea(fX, fY, fWidth, fHeight);
            Show();

            //DrawBorder
            grw.SetSourceRGB(0xff, 0, 0);

            grw.MoveTo(FBorderMarginH, FBorderMarginV);
            grw.LineTo(fWidth - FBorderMarginH, FBorderMarginV);
            grw.LineTo(fWidth - FBorderMarginH, fHeight - FBorderMarginV);
            grw.LineTo(FBorderMarginH, fHeight - FBorderMarginV);
            grw.LineTo(FBorderMarginH, FBorderMarginV);
            grw.Stroke();

            //DrawTasks
            var deltaActor = (Source.Tables["Actor"].Rows.Count > 0) ?
                             (fHeight - 2 * FBorderMarginV) / Source.Tables["Actor"].Rows.Count :
                             fHeight - 2 * FBorderMarginV;

            deltaActor -= FTaskHeight;

            var maxTaskCout = (from DataRow row in Source.Tables["AssigmentSource"].Rows select(int) row["TaskCount"]).Concat(new[] { 0 }).Max();

            var actorIndex       = 0;
            var foregroundColor3 = new Gdk.Color(0xff, 0xff, 0xff);
            var taskLabelGc      = new Gdk.GC(GdkWindow);
            var colormap         = Colormap.System;

            colormap.AllocColor(ref foregroundColor3, true, true);
            taskLabelGc.Foreground = foregroundColor3;

            //draw proportion line.
            var states1 = new Dictionary <int, int>();

            foreach (DataRow row in Source.Tables["StateRange"].Rows)
            {
                v1 = row["StateID"];
                var id = v1 as int? ?? -1;
                if (states1.ContainsKey(id))
                {
                    states1[id] += 1;
                }
                else
                {
                    states1.Add(id, 0);
                }
            }

            var sum = states1.Keys.Sum(id => states1[id]);

            var states2 = states1.Keys.ToList();

            foreach (var id in states2.OrderBy(s => s))
            {
                states1[id] = (int)(((double)fHeight / sum) * states1[id]);
            }

            var proportionOffset = 0;

            foreach (var id in states1.Keys)
            {
                var state  = Source.Tables["StateRange"].Select("StateID = " + id)[0];
                var taskGc = new Gdk.GC(GdkWindow);
                try
                {
                    var colorRed   = Convert.ToByte(state["ColorRed"]);
                    var colorGreen = Convert.ToByte(state["ColorGreen"]);
                    var colorBlue  = Convert.ToByte(state["ColorBlue"]);

                    var foregroundColor2 = new Gdk.Color(colorRed, colorGreen, colorBlue);
                    colormap.AllocColor(ref foregroundColor2, true, true);
                    taskGc.Foreground = foregroundColor2;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }

                GdkWindow.DrawRectangle(taskGc, true, fWidth - 10, proportionOffset, 10, states1[id]);
                proportionOffset += states1[id];
            }

            foreach (DataRow row in Source.Tables["Actor"].Rows)
            {
                var labelDate = firstDate;
                var offset    = FBorderMarginH;
                for (var i = 0; i < deltaSpan.Days; i++)
                {
                    var taskCount    = 0;
                    var assignmentId = -1;
                    var assignment   = Source.Tables["AssigmentSource"]
                                       .Select("ActorID = " + row["ID"] + "and Date = '" + labelDate.ToShortDateString() + "'");
                    if (assignment.Length > 0)
                    {
                        v1           = assignment[0]["TaskCount"];
                        taskCount    = v1 as int? ?? -1;
                        v2           = assignment[0]["ID"];
                        assignmentId = v2 as int? ?? -1;
                    }

                    if (taskCount > 0)
                    {
                        var states  = Source.Tables["StateRange"].Select("AssigmentID = " + assignmentId, "StateID");                                //order by stateid
                        var taskSum = 0;
                        foreach (var state in states)
                        {
                            var taskGc = new Gdk.GC(GdkWindow);
                            try
                            {
                                var colorRed         = Convert.ToByte(state["ColorRed"]);
                                var colorGreen       = Convert.ToByte(state["ColorGreen"]);
                                var colorBlue        = Convert.ToByte(state["ColorBlue"]);
                                var foregroundColor2 = new Gdk.Color(colorRed, colorGreen, colorBlue);
                                colormap.AllocColor(ref foregroundColor2, true, true);
                                taskGc.Foreground = foregroundColor2;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }

                            var currentCount = (int)state["TaskCount"];

                            GdkWindow.DrawRectangle(
                                taskGc,
                                true,
                                offset,
                                FBorderMarginV + (int)(deltaActor * (1 - (double)(taskSum + currentCount) / maxTaskCout))
                                + deltaActor * actorIndex
                                , delta
                                , (int)(deltaActor * ((double)currentCount / maxTaskCout)));

                            taskSum += currentCount;
                            var layout = new Layout(PangoContext)
                            {
                                Wrap            = WrapMode.Word,
                                FontDescription = FontDescription.FromString("Tahoma 10")
                            };
                            layout.SetMarkup(taskCount.ToString());

                            GdkWindow.DrawLayout(taskLabelGc,
                                                 offset,
                                                 (int)(deltaActor * (1 - (double)taskCount / maxTaskCout)) + deltaActor * actorIndex, layout);
                        }
                    }

                    offset   += delta;
                    labelDate = labelDate.AddDays(1);
                }

                actorIndex++;
            }

            taskLabelGc.Dispose();

            //DrawActorAxis
            var offsetActor      = FBorderMarginV;
            var foregroundColor  = new Gdk.Color(0xff, 0, 0);
            var foregroundColor1 = new Gdk.Color(0, 0, 0xff);
            var actorLabelGc     = new Gdk.GC(GdkWindow);
            var axisGc           = new Gdk.GC(GdkWindow);

            colormap.AllocColor(ref foregroundColor, true, true);
            taskLabelGc.Foreground = foregroundColor;
            axisGc.Foreground      = foregroundColor1;

            foreach (DataRow row in Source.Tables["Actor"].Rows)
            {
                var layout = new Layout(PangoContext)
                {
                    Wrap            = WrapMode.Word,
                    FontDescription = FontDescription.FromString("Tahoma 10")
                };
                layout.SetMarkup((string)row["Name"]);

                GdkWindow.DrawLayout(actorLabelGc,
                                     FBorderMarginH,
                                     offsetActor - FBorderMarginV, layout);
                GdkWindow.DrawLine(axisGc,
                                   FBorderMarginH,
                                   offsetActor,
                                   fWidth - FBorderMarginH, offsetActor);
                offsetActor += deltaActor;
            }

            axisGc.Dispose();

            //DrawDateAxis
            var labelDate1 = firstDate;
            var offset1    = FBorderMarginH;

            for (var i = 0; i < deltaSpan.Days; i++)
            {
                var layout = new Layout(PangoContext)
                {
                    Wrap            = WrapMode.Word,
                    FontDescription = FontDescription.FromString("Tahoma 10")
                };
                layout.SetMarkup(labelDate1.ToString("dd/MM"));

                GdkWindow.DrawLayout(actorLabelGc,
                                     offset1 + FBorderMarginH,
                                     fHeight - 2 * FBorderMarginV - FTaskHeight,
                                     layout);

                GdkWindow.DrawLine(axisGc,
                                   offset1,
                                   FBorderMarginV,
                                   offset1,
                                   fHeight - FBorderMarginV);
                offset1   += delta;
                labelDate1 = labelDate1.AddDays(1);
            }

            actorLabelGc.Dispose();

            //DrawDateNow
            var nowSpan = DateTime.Now.Subtract(firstDate);

            var offsetDate = FBorderMarginH + (int)(delta * (double)nowSpan.Ticks / TimeSpan.TicksPerDay);

            grw.SetSourceRGB(0, 0, 0);
            grw.MoveTo(offsetDate,
                       FBorderMarginV);
            grw.LineTo(offsetDate,
                       fHeight - FBorderMarginV);
            grw.RelLineTo(new Distance {
                Dx = -3, Dy = 0
            });
            grw.RelLineTo(new Distance {
                Dx = 3, Dy = -3
            });
            grw.RelLineTo(new Distance {
                Dx = 3, Dy = 3
            });
            grw.RelLineTo(new Distance {
                Dx = -3, Dy = 0
            });
            grw.Stroke();


            return(true);
        }
Beispiel #16
0
		public void xxx_dash(Context cr, int width, int height)
		{
			double[] dashes = new double[] {
				0.20,  // ink
				0.05,  // skip
				0.05,  // ink
				0.05   // skip 
			};
			double offset = -0.2; 

			Normalize(cr, width, height);

			cr.SetDash(dashes, offset);

			cr.MoveTo(0.5, 0.1);
			cr.LineTo(0.9, 0.9);
			cr.RelLineTo(-0.4, 0.0);
			cr.CurveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
			cr.Stroke();
		}
Beispiel #17
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            var baseResult = base.OnExposeEvent(evnt);

            if (Source == null && TrackerCore.Instance.TaskManager is EmptyTaskManager)
            {
                return(baseResult);
            }

            Source = ((IGanttSource)this).StaticSource ?? TrackerCore.Instance.TaskManager.GanttSource;

            //ReadGepmetry
            int fX, fY, fWidth, fHeight, fDepth;

            GdkWindow.GetGeometry(out fX, out fY, out fWidth, out fHeight, out fDepth);
            fWidth  -= 3;
            fHeight -= 3;

            // Insert drawing code here.

            if (grw == null)
            {
                grw = Gdk.CairoHelper.Create(GdkWindow);
            }
            //DrawBorder
            grw.SetSourceRGB(0xff, 0, 0);

            grw.MoveTo(FBorderMarginH, FBorderMarginV);
            grw.LineTo(fWidth - FBorderMarginH, FBorderMarginV);
            grw.LineTo(fWidth - FBorderMarginH, fHeight - FBorderMarginV);
            grw.LineTo(FBorderMarginH, fHeight - FBorderMarginV);
            grw.LineTo(FBorderMarginH, FBorderMarginV);
            grw.Stroke();

            //DrawTasks
            var deltaActor = (Source.Tables["Actor"].Rows.Count > 0) ?
                             (fHeight - 2 * FBorderMarginV) / Source.Tables["Actor"].Rows.Count :
                             fHeight - 2 * FBorderMarginV;

            var v1        = Source.Tables["DataRange"].Rows[0]["MinDate"];
            var v2        = Source.Tables["DataRange"].Rows[0]["MaxDate"];
            var firstDate = v1 as DateTime? ?? DateTime.Now;
            var lastDate  = v2 as DateTime? ?? DateTime.Now;
            var deltaSpan = lastDate.Date.Subtract(firstDate.Date);

            var deltaTask = fWidth;

            if (deltaSpan.Days > 1)
            {
                deltaTask = fWidth / deltaSpan.Days;
            }

            var columns     = (lastDate - firstDate).Days + 1;
            var filled      = new bool[columns, 100];
            var passedState = ConfigurationManager.AppSettings["passed_state"];

            var stateColors   = new Dictionary <int, Gdk.Color>();
            var statePresence = new Dictionary <int, Dictionary <int, int> >();

            foreach (DataRow row in Source.Tables["Task"].Rows)
            {
                v1 = row["ActorID"];
                if ((v1 as int? ?? -1) < 0)
                {
                    continue;
                }
                var actorIndex = Source.Tables["Actor"].Rows.Cast <DataRow>().TakeWhile(actorRow => (int)actorRow["ID"] != (int)row["ActorID"]).Count();

                v1 = row["StartTime"];
                v2 = row["EndTime"];
                var startTime = v1 as DateTime? ?? DateTime.Now;
                var endTime   = v2 as DateTime? ?? DateTime.Now;
                var startSpan = startTime.Subtract(firstDate);
                var endSpan   = endTime.Subtract(firstDate);

                // fill availability matrix


                if (taskGc == null)
                {
                    taskGc = new Gdk.GC(GdkWindow);
                }

                int stateId = (int)row["StateID"];
                if (Source.Tables["TaskState"].Select("ID = " + stateId).Length == 0)
                {
                    throw new KeyNotFoundException <object>(row["StateID"]);
                }

                var list = Source.Tables["TaskState"].Select("ID = " + row["StateID"]);
                if (list.Length > 0)
                {
                    var stateRow = list[0];

                    var stateName = (string)stateRow["Name"];
                    if (passedState.Split(';').Select(s => s.ToLower()).Contains(stateName.ToLower()))
                    {
                        continue;
                    }

                    try
                    {
                        var colorRed   = Convert.ToByte(stateRow["ColorRed"]);
                        var colorGreen = Convert.ToByte(stateRow["ColorGreen"]);
                        var colorBlue  = Convert.ToByte(stateRow["ColorBlue"]);

                        if (!stateColors.ContainsKey(stateId))
                        {
                            var foregroundColor = new Gdk.Color(colorRed, colorGreen, colorBlue);
                            stateColors.Add(stateId, foregroundColor);
                        }
                    }

                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }

                int offset;
                if (lastDate.Date > endTime.Date)
                {
                    offset = startSpan.Days * deltaTask + FBorderMarginH;
                }
                else if (startTime.Date < lastDate.Date)
                {
                    offset = startSpan.Days * deltaTask + FBorderMarginH;
                }
                else
                {
                    offset = (startSpan.Days - 1) * deltaTask + FBorderMarginH;
                }

                if (!statePresence.ContainsKey(offset))
                {
                    statePresence.Add(offset, new Dictionary <int, int>());
                }
                if (!statePresence[offset].ContainsKey(stateId))
                {
                    statePresence[offset].Add(stateId, 1);
                }
                else
                {
                    statePresence[offset][stateId]++;
                }
            }

            //TODO: for now the diagram was disabled because it not represent any gantt presentation itself
            //draw tasks
            foreach (DataRow row in Source.Tables["Task"].Rows)
            {
                v1 = row["ActorID"];
                if ((v1 as int? ?? -1) < 0)
                {
                    continue;
                }
                var actorIndex = Source.Tables["Actor"].Rows.Cast <DataRow>().TakeWhile(actorRow => (int)actorRow["ID"] != (int)row["ActorID"]).Count();

                v1 = row["StartTime"];
                v2 = row["EndTime"];
                var startTime = v1 as DateTime? ?? DateTime.Now;
                var endTime   = v2 as DateTime? ?? DateTime.Now;
                var startSpan = startTime.Subtract(firstDate);
                var endSpan   = endTime.Subtract(firstDate);

                if (taskGc == null)
                {
                    taskGc = new Gdk.GC(GdkWindow);
                }

                int stateId         = (int)row["StateID"];
                var foregroundColor = stateColors[stateId];
                var colormap        = Colormap.System;
                colormap.AllocColor(ref foregroundColor, true, true);
                taskGc.Foreground = foregroundColor;
                colormap.Dispose();

                int offset;
                if (lastDate.Date > endTime.Date)
                {
                    offset = startSpan.Days * deltaTask + FBorderMarginH;
                    if (statePresence.ContainsKey(offset) && statePresence[offset].ContainsKey(stateId) && statePresence[offset][stateId] > 0)
                    {
                        int  sum   = 0;
                        int  start = 0;
                        bool found = false;
                        foreach (var s in statePresence[offset].Keys)
                        {
                            sum += Math.Abs(statePresence[offset][s]);
                        }

                        foreach (var s in statePresence[offset].Keys)
                        {
                            found = s == stateId;
                            if (!found)
                            {
                                start += deltaActor * (Math.Abs(statePresence[offset][stateId]) - 1) / sum;
                            }
                            else
                            {
                                break;
                            }
                        }

                        GdkWindow.DrawRectangle(
                            taskGc,
                            true,
                            startSpan.Days * deltaTask + FBorderMarginH,
                            actorIndex * deltaActor + start,
                            deltaTask,
                            deltaActor * (statePresence[offset][stateId]) / sum);
                    }
                }
                else if (startTime.Date < lastDate.Date)
                {
                    offset = startSpan.Days * deltaTask + FBorderMarginH;


                    if (statePresence.ContainsKey(offset) && statePresence[offset].ContainsKey(stateId) && statePresence[offset][stateId] > 0)
                    {
                        int  sum   = 0;
                        int  start = 0;
                        bool found = false;
                        foreach (var s in statePresence[offset].Keys)
                        {
                            sum += Math.Abs(statePresence[offset][s]);
                        }

                        foreach (var s in statePresence[offset].Keys)
                        {
                            found = s == stateId;
                            if (!found)
                            {
                                start += deltaActor * (Math.Abs(statePresence[offset][stateId]) - 1) / sum;
                            }
                            else
                            {
                                break;
                            }
                        }

                        GdkWindow.DrawRectangle(
                            taskGc,
                            true,
                            startSpan.Days * deltaTask + FBorderMarginH,
                            actorIndex * deltaActor + FBorderMarginV + start,
                            deltaTask + FBorderMarginH,
                            deltaActor * (statePresence[offset][stateId]) / sum);
                    }
                }
                else
                {
                    offset = (startSpan.Days - 1) * deltaTask + FBorderMarginH;
                    if (statePresence.ContainsKey(offset) && statePresence[offset].ContainsKey(stateId) && statePresence[offset][stateId] > 0)
                    {
                        int  sum   = 0;
                        int  start = 0;
                        bool found = false;
                        foreach (var s in statePresence[offset].Keys)
                        {
                            sum += Math.Abs(statePresence[offset][s]);
                        }

                        foreach (var s in statePresence[offset].Keys)
                        {
                            found = s == stateId;
                            if (!found)
                            {
                                start += deltaActor * (Math.Abs(statePresence[offset][stateId]) - 1) / sum;
                            }
                            else
                            {
                                break;
                            }
                        }

                        GdkWindow.DrawRectangle(
                            taskGc,
                            true, (startSpan.Days - 1) * deltaTask + FBorderMarginH,
                            actorIndex * deltaActor + FBorderMarginV + start,
                            deltaTask + FBorderMarginH,
                            deltaActor * (statePresence[offset][stateId]) / sum);
                    }
                }
                statePresence[offset][stateId] = -Math.Abs(statePresence[offset][stateId]);
                GdkPalette.DestroyColor();
            }


            //DrawActorAxis

            //TODO: reuse gc
            var taskLabelGc = new Gdk.GC(GdkWindow);

            if (!((IGanttSource)this).DateNowVisible)
            {
                return(true);
            }

            //DrawActorAxis
            var offsetActor      = FBorderMarginV;
            var foregroundColor2 = new Gdk.Color(0xff, 0, 0);
            var foregroundColor1 = new Gdk.Color(0, 0, 0xff);
            //TODO: reuse gc
            var actorLabelGc = new Gdk.GC(GdkWindow);
            //TODO: reuse gc
            var axisGc = new Gdk.GC(GdkWindow);

            Colormap.System.AllocColor(ref foregroundColor2, true, true);
            taskLabelGc.Foreground = foregroundColor2;
            axisGc.Foreground      = foregroundColor1;

            foreach (DataRow row in Source.Tables["Actor"].Rows)
            {
                var layout = new Layout(PangoContext)
                {
                    Wrap            = WrapMode.Word,
                    FontDescription = FontDescription.FromString("Tahoma 10")
                };
                v1 = row["Name"];
                layout.SetMarkup(v1?.ToString() ?? "<unknown>");

                GdkWindow.DrawLayout(actorLabelGc,
                                     FBorderMarginH,
                                     offsetActor - FBorderMarginV, layout);
                GdkWindow.DrawLine(axisGc,
                                   FBorderMarginH,
                                   offsetActor,
                                   fWidth - FBorderMarginH, offsetActor);
                offsetActor += deltaActor;
            }

            axisGc.Dispose();

            actorLabelGc.Dispose();

            //DrawDateNow
            var nowSpan = DateTime.Now.Subtract(firstDate);

            var offsetDate = FBorderMarginH + (int)(deltaTask * (double)nowSpan.Ticks / TimeSpan.TicksPerDay);

            grw.SetSourceRGB(0, 0, 0);
            grw.MoveTo(offsetDate,
                       FBorderMarginV);
            grw.LineTo(offsetDate,
                       fHeight - FBorderMarginV);
            grw.RelLineTo(new Distance {
                Dx = -3, Dy = 0
            });
            grw.RelLineTo(new Distance {
                Dx = 3, Dy = -3
            });
            grw.RelLineTo(new Distance {
                Dx = 3, Dy = 3
            });
            grw.RelLineTo(new Distance {
                Dx = -3, Dy = 0
            });
            grw.Stroke();


            return(true);
        }
 private void paintBackground(Context ctx, int w, int h)
 {
     ctx.Color = BlueprintStyle.BluePrint;
     ctx.Rectangle(0.0d, 0.0d, w, h);
     ctx.Fill();
     ctx.Color = BlueprintStyle.SoftWhite;
     ctx.Rectangle(Offset, Offset, w-2*Offset, h-2*Offset);
     ctx.ClosePath();
     ctx.Rectangle(Offset2, Offset2, w-2*Offset2, h-2*Offset2);
     ctx.ClosePath();
     ctx.Fill();
     double W = w-2*Offset2;
     int n = (int)Math.Round((double)W/LineDelta);
     double dx = (double)W/n;
     ctx.LineWidth = 0.5d;
     for(int i = 1; i < n; i++) {
         ctx.MoveTo(dx*i+Offset2, Offset2);
         ctx.RelLineTo(0.0d, h-2*Offset2);
         ctx.Stroke();
     }
     double H = h-2*Offset2;
     n = (int)Math.Round((double)H/LineDelta);
     double dy = (double)H/n;
     for(int i = 1; i < n; i++) {
         ctx.MoveTo(Offset2, dy*i+Offset2);
         ctx.RelLineTo(w-2.0d*Offset2, 0.0d);
         ctx.Stroke();
     }
 }
Beispiel #19
0
		public void fill_and_stroke2(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.MoveTo(0.5, 0.1);
			cr.LineTo(0.9, 0.9);
			cr.RelLineTo(-0.4, 0.0);
			cr.CurveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
			cr.ClosePath();

			cr.MoveTo(0.25, 0.1);
			cr.RelLineTo(0.2, 0.2);
			cr.RelLineTo(-0.2, 0.2);
			cr.RelLineTo(-0.2, -0.2);
			cr.ClosePath();

			cr.Color = new Color (0, 0, 1);
			cr.FillPreserve();
			cr.Color = new Color (0, 0, 0);

			cr.Stroke();
		}
Beispiel #20
0
		public void path(Context cr, int width, int height)
		{
			Normalize(cr, width, height);
			cr.MoveTo(0.5, 0.1);
			cr.LineTo(0.9, 0.9);
			cr.RelLineTo(-0.4, 0.0);
			cr.CurveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);

			cr.Stroke();
		}
Beispiel #21
0
		public void text_align_center(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
			cr.SetFontSize(0.2);
			TextExtents extents = cr.TextExtents("cairo");
			double x = 0.5 -((extents.Width/2.0) + extents.XBearing);
			double y = 0.5 -((extents.Height/2.0) + extents.YBearing);

			cr.MoveTo(x, y);
			cr.ShowText("cairo");

			// draw helping lines
			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.Arc(x, y, 0.05, 0, 2*Math.PI);
			cr.Fill();
			cr.MoveTo(0.5, 0);
			cr.RelLineTo(0, 1);
			cr.MoveTo(0, 0.5);
			cr.RelLineTo(1, 0);
			cr.Stroke();
		}
Beispiel #22
0
		public void text_extents(Context cr, int width, int height)
		{
			double x=0.1;
			double y=0.6;
			string utf8 = "cairo";
			Normalize (cr, width, height);

			cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);

			cr.SetFontSize(0.4);
			TextExtents extents = cr.TextExtents(utf8);

			cr.MoveTo(x,y);
			cr.ShowText(utf8);

			// draw helping lines
			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.Arc(x, y, 0.05, 0, 2*Math.PI);
			cr.Fill();
			cr.MoveTo(x,y);
			cr.RelLineTo(0, -extents.Height);
			cr.RelLineTo(extents.Width, 0);
			cr.RelLineTo(extents.XBearing, -extents.YBearing);
			cr.Stroke();
		}
Beispiel #23
0
			void DrawTriangle (Context ctx)
			{
				var halfSide = arrowPadding;
				var verticalModifier = arrowPosition == Xwt.Popover.Position.Top ? -1 : 1;
				// Move to the left
				ctx.RelMoveTo (-halfSide, 0);
				ctx.RelLineTo (halfSide, verticalModifier * arrowPadding);
				ctx.RelLineTo (halfSide, verticalModifier * -arrowPadding);
			}
Beispiel #24
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        gr.AddColorStop(0, Tabstrip.ActiveGradientStart);
                        gr.AddColorStop(1, Tabstrip.ActiveGradientEnd);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                    cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1);
                    cr.SetSourceRGBA(1, 1, 1, 0.05);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        var c1 = Tabstrip.ActiveGradientStart;
                        var c2 = Tabstrip.ActiveGradientEnd;
                        c1.A = 0.2;
                        c2.A = 0.2;
                        gr.AddColorStop(0, c1);
                        gr.AddColorStop(1, c2);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceRGB(1, 1, 1);
            }
            else
            {
                cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor());
            }

            if (layout.Width != (int)rectangle.Width)
            {
                layout.Width = (int)rectangle.Width;
            }

                        #if MAC
            /* On Cocoa, Pango doesn't render text correctly using layout width/height computation.
             * For instance here we need to balance some kind of internal padding by two pixels which
             * only happens on Mac.
             */
            const int verticalOffset = -2;
                        #else
            const int verticalOffset = 0;
                        #endif

            cr.MoveTo(rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 + verticalOffset);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }