SetSourceRGBA() публичный Метод

public SetSourceRGBA ( double r, double g, double b, double a ) : void
r double
g double
b double
a double
Результат void
Пример #1
0
        void ExposeTitle(Cairo.Context c)
        {
            // The primary title background
            c.SetSourceRGBA(0, 0, 0, 0.3);
            c.Rectangle(0, m_titleOffset, this.Allocation.Width, m_titleHeight);
            c.Fill();

            // The title shadow (lip)
            c.SetSourceRGBA(0, 0, 0, 0.1);
            c.Rectangle(0, m_titleOffset + m_titleHeight, this.Allocation.Width, m_titleLip);
            c.Fill();

            // Paint the title text
            using (var p = Pango.CairoHelper.CreateLayout(c))
            {
                int w = 0, h = 0, pad = 0;

                p.SetText(m_Title);
                p.GetPixelSize(out w, out h);
                pad = (m_titleHeight - h) / 2;
                c.MoveTo(pad, m_titleOffset + pad);
                c.SetSourceRGB(1.0, 1.0, 1.0);
                Pango.CairoHelper.ShowLayout(c, p);
            }
        }
Пример #2
0
 private void dibujar_grilla(DrawingArea area, Cairo.Context cr)
 {
     for (int x = 0; x < Constantes.nro_casillas; x++)
     {
         int x0 = Logica.grilla.get_casillero(x, 0).inicioX;
         cr.Save();
         cr.LineWidth = 0.5;
         cr.SetSourceRGBA(0, 0, 0, 0.5);
         cr.MoveTo(x0, 0);
         cr.LineTo(x0, Constantes.limites.Height);
         cr.Stroke();
         cr.Restore();
     }
     for (int y = 0; y < Constantes.nro_casillas; y++)
     {
         int y0 = Logica.grilla.get_casillero(0, y).inicioY;
         cr.Save();
         cr.LineWidth = 0.5;
         cr.SetSourceRGBA(0, 0, 0, 0.5);
         cr.MoveTo(0, y0);
         cr.LineTo(Constantes.limites.Width, y0);
         cr.Stroke();
         cr.Restore();
     }
 }
        protected void DrawSmallCovers(Cairo.Context context, float width, float height, double lwidth)
        {
            context.Save();

            double hlwidth = lwidth * 0.5;

            context.MoveTo(hlwidth, height - hlwidth);
            context.LineTo(hlwidth, 0.3 * (height - lwidth));
            context.LineTo((width - lwidth) * 0.65, hlwidth);
            context.LineTo((width - lwidth) * 0.65, 0.7 * (height - lwidth));
            context.ClosePath();
            context.LineWidth = lwidth;
            context.SetSourceRGBA(0.1, 0.1, 0.1, 1.0);
            context.FillPreserve();
            context.SetSourceRGBA(1.0, 1.0, 1.0, 0.7);
            context.Stroke();
            context.Translate((4 + hlwidth), 0);
            context.MoveTo(hlwidth, height - hlwidth);
            context.LineTo(hlwidth, 0.3 * (height - lwidth));
            context.LineTo((width - lwidth) * 0.65, hlwidth);
            context.LineTo((width - lwidth) * 0.65, 0.7 * (height - lwidth));
            context.ClosePath();
            context.SetSourceRGBA(0.1, 0.1, 0.1, 1.0);
            context.FillPreserve();
            context.SetSourceRGBA(1.0, 1.0, 1.0, 0.7);
            context.Stroke();
            context.Translate(-(4 + hlwidth), 0);

            context.Restore();
        }
Пример #4
0
        /// <summary>
        /// Draw the specified surface.
        /// </summary>
        /// <param name="surface">Surface.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;


            RetrieveData();
            FindSmallestValue(_graphData);
            FindMaxValue(_graphData);

            x_scale_ratio = DrawAssembly.ContentWidth / _totalDataPoints;
            y_scale_ratio = DrawAssembly.FrameAreaHeight / (_maxValue - _minValue);



            surface.LineWidth = GraphLineWidth;
            surface.SetSourceRGBA(R, G, B, Alpha);


            //Console.WriteLine ("the smallest value is " + smallestValue);

            for (int i = 0; i < _totalDataPoints - 1; i++)
            {
                int k = i + 1;


                _p1 = new PointD(X - DrawAssembly.FrameAreaMarginLEFT + (i * (x_scale_ratio * 0.5)), Y + DrawAssembly.FrameAreaMarginTOP - (_graphData [i] - _minValue) * (y_scale_ratio * 0.5));
                _p2 = new PointD(X - DrawAssembly.FrameAreaMarginLEFT + (k * (x_scale_ratio * 0.5)), Y + DrawAssembly.FrameAreaMarginTOP - (_graphData [k] - _minValue) * (y_scale_ratio * 0.5));


                surface.MoveTo(_p1);
                surface.LineTo(_p2);

                p1Xcoordinates [i] = _p1.X;
                p1Ycoordinates [i] = _p1.Y;
            }

            DrawGraphDots(surface);
            DrawYScale(surface);

            surface.Stroke();

            string widgetText = DataStreamId;

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(R, G, B, Alpha);
            surface.MoveTo(DrawAssembly.FrameAreaMarginLEFT, Y + (text.Height * Id));

            surface.ShowText(widgetText);

            /*
             * surface.SetSourceRGBA (1, 1, 1, 0.5);
             * surface.Rectangle (DrawAssembly.FrameAreaMarginLEFT, 0, DrawAssembly.FrameAreaWidth, DrawAssembly.FrameAreaHeight);
             * surface.Stroke ();
             */
        }
Пример #5
0
        public override void RealRenderCairo(Cairo.Context context)
        {
            //if (Camera.IsRendererOutOfScreen (this))
            //	return;
            context.MoveTo(Camera.WorldToScreenPosition(gameObject.transform.LocalToWorldPoint(points[len - 1])).ToPointD());
            for (int i = 0; i < len; i++)
            {
                context.LineTo(Camera.WorldToScreenPosition(gameObject.transform.LocalToWorldPoint(points [i])).ToPointD());
            }
            context.ClosePath();
            if (surf == null)
            {
                context.SetSourceRGBA(ColorR, ColorG, ColorB, ColorA);
                context.Fill();
            }
            else
            {
                int     w = surf.Width;
                int     h = surf.Height;
                Vector2 screenMinBound = Camera.WorldToScreenPosition(gameObject.transform.LocalToWorldPoint(minBound));
                Vector2 screenMaxBound = Camera.WorldToScreenPosition(gameObject.transform.LocalToWorldPoint(maxBound));

                int myH = (int)(screenMinBound.y - screenMaxBound.y);


                int posY = (int)screenMaxBound.y;
                while (myH > 0)
                {
                    int posX = (int)screenMinBound.x;
                    int myW  = (int)(screenMaxBound.x - screenMinBound.x);
                    while (myW > 0)
                    {
                        if (Camera.IsPointOutOfScreen(new Vector2(posX, posY)) &&
                            Camera.IsPointOutOfScreen(new Vector2(posX, posY + h)) &&
                            Camera.IsPointOutOfScreen(new Vector2(posX + w, posY)) &&
                            Camera.IsPointOutOfScreen(new Vector2(posX + w, posY + h)))
                        {
                            myW  -= w;
                            posX += w;
                            continue;
                        }

                        context.SetSourceSurface(surf, posX, posY);
                        context.FillPreserve();
                        myW  -= w;
                        posX += w;
                    }
                    myH  -= h;
                    posY += h;
                }
                context.SetSourceRGBA(ColorR, ColorG, ColorB, ColorA);
                context.Stroke();
                //context.NewPath();
                context.GetSource().Dispose();
            }
        }
Пример #6
0
        void RenderShadowedText(Cairo.Context context, Gdk.Point position, double opacity, Pango.Layout layout)
        {
            context.MoveTo(position.X, position.Y + 2);
            context.SetSourceRGBA(0, 0, 0, 0.3 * opacity);
            Pango.CairoHelper.ShowLayout(context, layout);

            context.MoveTo(position.X, position.Y);
            context.SetSourceRGBA(1, 1, 1, opacity);
            Pango.CairoHelper.ShowLayout(context, layout);
        }
		protected override void DrawBackground (Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region);
			context.Clip ();

			context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF"));
			context.Paint ();

			context.Save ();
			context.Translate (region.X + region.Width / 2.0, region.Y + region.Height);

			using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				var color = CairoExtensions.ParseColor ("E5F0FF");
				rg.AddColorStop (0, color);
				color.A = 0;
				rg.AddColorStop (1, color);

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.SetSource (rg);
				context.Paint ();
			}

			context.Restore ();

			LayoutRoundedRectangle (context, region, -3, -3, 2);
			context.SetSourceRGBA (1, 1, 1, 0.4);
			context.LineWidth = 1;
			context.StrokePreserve ();

			context.Clip ();

			int boxSize = 11;
			int x = region.Left + (region.Width % boxSize) / 2;
			for (; x < region.Right; x += boxSize) {
				context.MoveTo (x + 0.5, region.Top);
				context.LineTo (x + 0.5, region.Bottom);
			}

			int y = region.Top + (region.Height % boxSize) / 2;
			y += boxSize / 2;
			for (; y < region.Bottom; y += boxSize) {
				context.MoveTo (region.Left, y + 0.5);
				context.LineTo (region.Right, y + 0.5);
			}

			context.SetSourceRGBA (1, 1, 1, 0.2);
			context.Stroke ();

			context.ResetClip ();
		}
        protected override void CreatePassiveTexture(Clutter.CairoTexture texture, int with_state)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            //Draw outline rectangles:
            DrawSmallCovers(context, texture.Width, texture.Height, lwidth);

            //Draw play icon:
            context.MoveTo((texture.Width - lwidth) * 0.5, 0.3 * (texture.Height - lwidth));
            context.LineTo((texture.Width - lwidth) * 0.5, texture.Height - hlwidth);
            context.LineTo(texture.Width - hlwidth, 0.65 * (texture.Height - lwidth));
            context.ClosePath();
            context.LineWidth = lwidth;
            double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));

            context.SetSourceRGBA(sat, sat, sat, 1.0);
            context.FillPreserve();
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.Stroke();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Пример #9
0
	void Draw3Circles (Context cr, int xc, int yc, double radius, double alpha)
	{
		double subradius = radius * (2 / 3.0 - 0.1);

		cr.SetSourceRGBA (1.0, 0.0, 0.0, alpha);
		OvalPath (cr, xc + radius / 3.0 * Math.Cos (Math.PI * 0.5), yc - radius / 3.0 * Math.Sin (Math.PI * 0.5), subradius, subradius);
		cr.Fill ();

		cr.SetSourceRGBA (0.0, 1.0, 0.0, alpha);
		OvalPath (cr, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 2 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 2 / 0.3)), subradius, subradius);
		cr.Fill ();

		cr.SetSourceRGBA (0.0, 0.0, 1.0, alpha);
		OvalPath (cr, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 4 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 4 / 0.3)), subradius, subradius);
		cr.Fill ();
	}
Пример #10
0
 //Original function which draws a straight line from start to end
 void DrawLine(Cairo.Context ctx, PointD start, PointD end)
 {
     ctx.SetSourceRGBA(R, G, B, A);
     ctx.MoveTo(start);
     ctx.LineTo(end);
     ctx.Stroke();
 }
        protected override void CreateActiveTexture(Clutter.CairoTexture texture, int with_state)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            //Draw outline rectangles:
            DrawSmallCovers(context, texture.Width, texture.Height, lwidth);

            //Draw stop icon:
            double dim = Math.Min(texture.Width * 0.6 - hlwidth, texture.Height * 0.6 - hlwidth);

            context.Rectangle(texture.Width * 0.4, texture.Height * 0.4, dim, dim);
            context.LineWidth = lwidth;
            double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));

            context.SetSourceRGBA(sat, sat, sat, 1.0);
            context.FillPreserve();
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.Stroke();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Пример #12
0
        void OnExpose(object sender, EventArgs args)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(this.Window);

            cr.LineWidth = 3;
            cr.LineCap   = LineCap.Round;

            int width, height;

            width  = Allocation.Width;
            height = Allocation.Height;

            cr.Translate(width / 2, height / 2);

            for (int i = 0; i < 8; i++)
            {
                cr.SetSourceRGBA(0, 0, 0, trs[count % 8, i]);
                cr.MoveTo(0.0, -10.0);
                cr.LineTo(0.0, -40.0);
                cr.Rotate(Math.PI / 4);
                cr.Stroke();
            }

            cr.GetTarget().Dispose();
            cr.Dispose();
        }
Пример #13
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);
        }
Пример #14
0
 protected void OnRender(Context cr, int width, int height)
 {
     cr.Save();
     cr.SetSourceRGBA(1, 0, 0, mTick*0.1);
     cr.Rectangle(0, 0, width, height);
     cr.Fill();
     cr.Restore();
 }
Пример #15
0
        private void scene_design(DrawingArea area, Cairo.Context cr)
        {
            area.AddEvents((int)Gdk.EventMask.ButtonPressMask);
            area.ButtonPressEvent += delegate(object o, ButtonPressEventArgs arg) {
                area.GetPointer(out xo, out yo);
                pressed = true;
            };

            area.AddEvents((int)Gdk.EventMask.ButtonReleaseMask);
            area.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) {
                pressed = false;
                UpdateViewSurface();
            };


            if (pressed)
            {
                area.GetPointer(out xt, out yt);
                if (ventana.circulo.Active)
                {
                    cr.LineWidth = 2;
                    cr.SetSourceRGBA(0, 0, 1, 0.5);
                    cr.Arc(xo, yo, Constantes.distancia(xt, xo), 0, Math.PI * 2);
                    cr.Stroke();
                }
                else if (ventana.linea.Active)
                {
                    cr.LineWidth = 2;
                    cr.SetSourceRGBA(0, 1, 0, 0.5);
                    cr.MoveTo(xo, yo);
                    cr.LineTo(xt, yt);
                    cr.Stroke();
                }
                else if (ventana.rectangulo.Active)
                {
                    cr.LineWidth = 2;
                    cr.SetSourceRGBA(1, 0, 0, 0.5);
                    cr.Rectangle(xo, yo, xt - xo, yt - yo);
                    cr.Stroke();
                }
            }

            cr.SetSourceSurface(Constantes.viewSurface, 0, 0);
            cr.Paint();
        }
Пример #16
0
        private void triangulo(Cairo.Context cr, Boid b, double rot)
        {
            reset(cr);

            cr.Save();

            r.Rotate(rot);
            t.Translate(b.Location.X, Logica.mapeo(b.Location.Y));

            r.TransformPoint(ref Ax, ref Ay);
            t.TransformPoint(ref Ax, ref Ay);

            r.TransformPoint(ref Bx, ref By);
            t.TransformPoint(ref Bx, ref By);

            r.TransformPoint(ref Cx, ref Cy);
            t.TransformPoint(ref Cx, ref Cy);

            //			System.Diagnostics.Debug.WriteLine (Ax+", "+Ay);

            cr.MoveTo(Ax, Ay);
            cr.LineTo(Bx, By);
            cr.LineTo(Cx, Cy);

            cr.LineWidth = 2;

            if (b.criterio == 0)
            {
                cr.SetSourceRGBA(0.5, 0, 0, 0.5);                  //cercano
            }
            else if (b.criterio == 1)
            {
                cr.SetSourceRGBA(0, 0.5, 0, 0.5);                  //menos concurrido
            }
            else
            {
                cr.SetSourceRGBA(0, 0, 0.5, 0.5);                  //random
            }
            cr.ClosePath();
            cr.FillPreserve();
            cr.Stroke();

            cr.Restore();
        }
Пример #17
0
 private void FillCell(CellNumber cell, Cairo.Color color)
 {
     using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow))
     {
         g.SetSourceRGBA(color.R, color.G, color.B, color.A);
         g.MoveTo(GetCellCoordinates(cell.Y, cell.X));
         g.Rectangle(GetCellCoordinates(cell.Y, cell.X), cellWidth, cellHeight);
         g.Fill();
         g.GetTarget().Dispose();
     }
 }
Пример #18
0
 private void FillCell(PointD coord, Cairo.Color color)
 {
     using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow))
     {
         g.SetSourceRGBA(color.R, color.G, color.B, color.A);
         g.MoveTo(coord);
         g.Rectangle(coord, cellWidth, cellHeight);
         g.Fill();
         g.GetTarget().Dispose();
     }
 }
Пример #19
0
 /// <summary>
 /// Draws the lines.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="xStart">X start.</param>
 /// <param name="yStart">Y start.</param>
 /// <param name="xEnd">X end.</param>
 /// <param name="yEnd">Y end.</param>
 /// <param name="color">Color.</param>
 private static void DrawLines(Cairo.Context context, int xStart, int yStart, int xEnd, int yEnd, Cairo.Color color)
 {
     context.Save();
     context.SetSourceRGBA(color.R, color.G, color.B, color.A);
     context.MoveTo(xStart, yStart);
     context.LineTo(xEnd, yEnd);
     context.ClosePath();
     context.Restore();
     context.LineWidth = 1;
     context.Stroke();
 }
Пример #20
0
 public static void PaintFocus(Cairo.Context cr, Style style, StateType state)
 {
     cr.SetSourceRGBA(GetCairoColorWithAlpha(style.Foreground(state), 0.7f).R, GetCairoColorWithAlpha(style.Foreground(state), 0.7f).G, GetCairoColorWithAlpha(style.Foreground(state), 0.7f).B, GetCairoColorWithAlpha(style.Foreground(state), 0.7f).A);
     //cr.Color = GetCairoColorWithAlpha (style.Foreground (state), 0.7f);
     cr.LineCap  = LineCap.Butt;
     cr.LineJoin = LineJoin.Miter;
     cr.SetDash(FocusDash, 1.5f);
     cr.Antialias = Antialias.None;
     cr.LineWidth = 1.0f;
     cr.Stroke();
 }
Пример #21
0
        public override void RealRenderCairo(Cairo.Context context)
        {
            if (Camera.IsRendererOutOfScreen(this))
            {
                return;
            }
            Vector2 screenPos = Camera.WorldToScreenPosition(gameObject.transform.position);
            float   realRad   = gameObject.transform.LocalToWorldLength(radius);
            double  screenRad = (double)realRad * Camera.instance.zoom;

            context.Arc((double)screenPos.x,
                        (double)screenPos.y,
                        screenRad,
                        0, 2 * Math.PI);


            if (surf == null)
            {
                if (useShadow)
                {
                    LinearGradient g = new LinearGradient(screenPos.x - screenRad, screenPos.y + screenRad, screenPos.x + screenRad, screenPos.y - screenRad);

                    //g.AddColorStopRgb (0.75, new Cairo.Color (ColorR, ColorG, ColorB, ColorA));
                    g.AddColorStop(0, new Cairo.Color(ColorR * 0.5, ColorG * 0.5, ColorB * 0.5, ColorA * 0.5));
                    g.AddColorStop(1, new Cairo.Color(ColorR, ColorG, ColorB, ColorA));

                    context.SetSource(g);
                    context.Fill();
                    g.Dispose();
                }
                else
                {
                    context.SetSourceRGBA(ColorR, ColorG, ColorB, ColorA);
                    context.Fill();
                }
            }
            else
            {
                context.SetSourceSurface(surf, (int)(screenPos.x - screenRad), (int)(screenPos.y - screenRad));

                context.Fill();
                context.GetSource().Dispose();
                //surf.Dispose ();
            }

            /*context.SetSourceRGBA (1,1,1,1);
             * context.Arc ((double)screenPos.x,
             *      (double)screenPos.y,
             *      (double)realRad * Camera.instance.zoom,
             *      MyMath.FixAngleRad(-Math.PI/4 - gameObject.transform.rotation), MyMath.FixAngleRad(Math.PI /4 - gameObject.transform.rotation));
             *
             * context.Fill ();*/
        }
Пример #22
0
        private void triangulo_contorno(Cairo.Context cr, Vector location, double rot)
        {
            reset(cr);

            cr.Save();

            r.Rotate(rot);
            t.Translate(location.X, Logica.mapeo(location.Y));

            r.TransformPoint(ref Ax, ref Ay);
            t.TransformPoint(ref Ax, ref Ay);

            r.TransformPoint(ref Bx, ref By);
            t.TransformPoint(ref Bx, ref By);

            r.TransformPoint(ref Cx, ref Cy);
            t.TransformPoint(ref Cx, ref Cy);

//			System.Diagnostics.Debug.WriteLine (Ax+", "+Ay);

            cr.MoveTo(Ax, Ay);
            cr.LineTo(Bx, By);
            cr.LineTo(Cx, Cy);

            cr.LineWidth = 2;
            cr.SetSourceRGBA(0, 0, 0, 0.5);

            cr.ClosePath();
            cr.FillPreserve();
            cr.Stroke();

            cr.Restore();

            cr.Save();
            cr.Arc(Ax, Ay, Logica.radioSep, 0, 2 * Math.PI);
            cr.SetSourceRGBA(1, 0, 0, 0.2);
            cr.Stroke();
            cr.Restore();
        }
Пример #23
0
        void RenderButton(Cairo.Context context, Gdk.Point corner, double opacity, bool hovered)
        {
            Gdk.Rectangle region = new Gdk.Rectangle(corner.X,
                                                     corner.Y,
                                                     ButtonSize.Width, ButtonSize.Height);



            context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 3);
            using (var lg = new LinearGradient(0, region.Top, 0, region.Bottom)) {
                if (hovered)
                {
                    lg.AddColorStop(0, new Cairo.Color(.15, .76, .09, opacity));
                    lg.AddColorStop(1, new Cairo.Color(.41, .91, .46, opacity));
                }
                else
                {
                    lg.AddColorStop(0, new Cairo.Color(.41, .91, .46, opacity));
                    lg.AddColorStop(1, new Cairo.Color(.15, .76, .09, opacity));
                }

                context.SetSource(lg);
                context.FillPreserve();
            }

            context.SetSourceRGBA(.29, .79, .28, opacity);
            context.LineWidth = 1;
            context.Stroke();

            region.Inflate(-1, -1);
            context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 2);

            using (var lg = new LinearGradient(0, region.Top, 0, region.Bottom)) {
                lg.AddColorStop(0, new Cairo.Color(1, 1, 1, .74 * opacity));
                lg.AddColorStop(0.1, new Cairo.Color(1, 1, 1, 0));
                lg.AddColorStop(0.9, new Cairo.Color(0, 0, 0, 0));
                lg.AddColorStop(1, new Cairo.Color(0, 0, 0, .34 * opacity));

                context.SetSource(lg);
                context.Stroke();
            }

            using (var layout = ButtonLayout(PangoContext)) {
                int w, h;
                layout.GetPixelSize(out w, out h);

                RenderShadowedText(context, new Gdk.Point(corner.X + ButtonSize.Width / 2 - w / 2, corner.Y + ButtonSize.Height / 2 - h / 2 - 1), opacity, layout);
            }
        }
Пример #24
0
 //Draws the dots on the screen, end is a moot parameter
 public void DrawDot(Cairo.Context ctx, PointD start, PointD end)
 {
     if (!start.Equals(prevDot))
     {
         ctx.SetSourceRGBA(R, G, B, A);
         ctx.Arc(start.X, start.Y, 1, 0, 2 * Math.PI);
         ctx.StrokePreserve();
         ctx.Fill();
         if (startRecordPoints)
         {
             currentDrawnPoints.Add(start);
         }
         prevDot = start;
     }
 }
Пример #25
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.SetSourceRGBA(LabelBackgroundColor.R, LabelBackgroundColor.G, LabelBackgroundColor.B,
                                  LabelBackgroundColor.A);

                ctx.Fill();
                ctx.Rectangle(dx, 0, Allocation.Width - dx, Allocation.Height);
                ctx.SetSourceRGB(1, 1, 1);
                ctx.Fill();
                ctx.MoveTo(dx + 0.5, 0);
                ctx.RelLineTo(0, Allocation.Height);
                ctx.SetSourceRGBA(DividerColor.R, DividerColor.G, DividerColor.B, DividerColor.A);

                ctx.Stroke();

                int y = 0;
                Draw(ctx, rows, dx, InspectorLeftPadding, ref y);
            }
            return(base.OnExposeEvent(evnt));
        }
Пример #26
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;

            Y = y;

            double StartAngle = (1 / 8) * Math.PI;
            double EndAngle   = 2 * Math.PI - ((1 / 8) * Math.PI);

            lightValue = CurrentData.GetCurrentValueByIdFloat("LIGHT");


            //LIGHTBULB ALL THE WAY BABY

            surface.MoveTo(X - 100 * scaleFactor, Y + 200 * scaleFactor);
            surface.LineTo(X - 100 * scaleFactor, Y - 100 * scaleFactor);
            surface.Arc(X, Y - 100 * scaleFactor, 200 * scaleFactor, StartAngle, EndAngle);
            surface.MoveTo(X + 100 * scaleFactor, Y - 100 * scaleFactor);
            surface.LineTo(X + 100 * scaleFactor, Y + 200 * scaleFactor);
            surface.LineTo(X - 100 * scaleFactor, Y + 200 * scaleFactor);

            surface.SetSourceRGBA(1, 1, 0, 0.20 + normalizingLightValue());
            surface.Fill();

            if (_showText == true)
            {
                widgetText = lightValue + "";
                surface.SetFontSize(13);
                text = surface.TextExtents(widgetText);

                surface.SetSourceRGBA(0.98f, 0.5f, 0.4f, Alpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2) + 15);

                surface.ShowText(widgetText);
            }
        }
Пример #27
0
        public override void RealRenderCairo(Cairo.Context context)
        {
            if (Camera.IsRendererOutOfScreen(this))
            {
                return;
            }
            Vector2 screenPos = Camera.WorldToScreenPosition(gameObject.transform.position);
            double  realSize  = (double)gameObject.transform.LocalToWorldLength(size);

            context.MoveTo(screenPos.ToPointD());
            context.SetSourceRGBA(ColorR, ColorG, ColorB, ColorA);
            context.SetFontSize(realSize);
            context.TextPath(text);
            context.Fill();
        }
Пример #28
0
        private void FillHalf(PointD coord, Cairo.Color color, Half half)
        {
            if (half == Half.Bottom)
            {
                coord.Y += cellHeight / 2;
            }

            using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow))
            {
                g.SetSourceRGBA(color.R, color.G, color.B, color.A);
                g.MoveTo(coord);
                g.Rectangle(coord, cellWidth, cellHeight / 2);
                g.Fill();
                g.GetTarget().Dispose();
            }
        }
Пример #29
0
        //        public override TextExtents GetExtents(Cairo.Context cr)
        //        {
        //            TextExtents extents = new TextExtents();
        //            extents.Height = _pageSettings.PageHeight;
        //            extents.Width = _pageSettings.PageWidth;
        //            return extents;
        //        }

        public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer)
        {
            if (layer == PrintLayer.DisplayBackground)
            {
                // Create the shadow effect
                cr.SetSourceRGBA(0.5, 0.5, 0.5, 0.5);
                cr.Rectangle(xPos + Constants.SHADOW_WIDTH
                             , yPos + Constants.SHADOW_WIDTH
                             , _pageSettings.PaperWidth
                             , _pageSettings.PaperHeight);
                cr.Fill();



                cr.SetSourceRGB(1, 1, 1);
                cr.Rectangle(xPos
                             , yPos
                             , _pageSettings.PaperWidth
                             , _pageSettings.PaperHeight);
                cr.Fill();
            }

            double pageTop = yPos;

            yPos += _pageSettings.TopMargin;
            xPos += _pageSettings.LeftMargin;

            if (_header != null)
            {
                yPos += _header.GetExtents(cr).Height;
                _header.Draw(cr, xPos, yPos, layer);
            }

            // Move the cursor to the bottom of the page elements.
            TextExtents extents = GetExtents(cr);

            yPos += extents.Height + extents.YAdvance;

            // Draw the page elements in reverse order.
            base.Draw(cr, xPos, yPos, layer);

            if (_footer != null)
            {
                yPos = pageTop + _pageSettings.PageHeight;
                _footer.Draw(cr, xPos, yPos, layer);
            }
        }
Пример #30
0
        protected override void CreateTexture(Clutter.CairoTexture texture, int with_state)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            context.Translate(texture.Width * 0.5, texture.Height * 0.5);
            context.Arc(0, 0, (texture.Height - 1) * 0.5, 0, 2 * Math.PI);
            context.ClosePath();
            context.SetSourceRGBA(1.0, 1.0, 1.0, with_state == 0 ? 0.3 : (with_state == 1 ? 0.5 : 0.7));
            context.FillPreserve();
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.LineWidth = 1;
            context.Stroke();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Пример #31
0
        void DrawBackground(Cairo.Context context, Gdk.Rectangle region, int radius, StateType state)
        {
            double rad     = radius - 0.5;
            int    centerX = region.X + region.Width / 2;
            int    centerY = region.Y + region.Height / 2;

            context.MoveTo(centerX + rad, centerY);
            context.Arc(centerX, centerY, rad, 0, Math.PI * 2);

            double high;
            double low;

            switch (state)
            {
            case StateType.Selected:
                high = 0.85;
                low  = 1.0;
                break;

            case StateType.Prelight:
                high = 1.0;
                low  = 0.9;
                break;

            case StateType.Insensitive:
                high = 0.95;
                low  = 0.83;
                break;

            default:
                high = 1.0;
                low  = 0.85;
                break;
            }
            using (var lg = new LinearGradient(0, centerY - rad, 0, centerY + rad)) {
                lg.AddColorStop(0, new Cairo.Color(high, high, high));
                lg.AddColorStop(1, new Cairo.Color(low, low, low));
                context.SetSource(lg);
                context.FillPreserve();
            }

            context.SetSourceRGBA(0, 0, 0, 0.4);
            context.LineWidth = 1;
            context.Stroke();
        }
Пример #32
0
        private void FillHalf(HalfCell cell, Cairo.Color color)
        {
            PointD coord = GetCellCoordinates(cell.CellNumber.Y, cell.CellNumber.X);

            if (cell.half == Half.Bottom)
            {
                coord.Y += cellHeight / 2;
            }

            using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow))
            {
                g.SetSourceRGBA(color.R, color.G, color.B, color.A);
                g.MoveTo(coord);
                g.Rectangle(coord, cellWidth, cellHeight / 2);
                g.Fill();
                g.GetTarget().Dispose();
            }
        }
Пример #33
0
        /// <summary>
        /// Draws the label.
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="bordertype">Bordertype.</param>
        /// <param name="pin">Pin.</param>
        /// <param name="xpos">Xpos.</param>
        /// <param name="ypos">Ypos.</param>
        private static void DrawLabel(Cairo.Context context, BorderType bordertype, IPin pin, int xpos = 0, int ypos = 0)
        {
            const int widht    = 100;
            const int height   = BoldHeight;
            const int fontsize = 12;

            //Rect
            context.Rectangle(xpos, ypos, widht, 26);
            context.SetSourceRGBA(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
            context.Fill();

            string displaytext = pin.Name;

            if (displaytext.Length > 12)
            {
                displaytext  = displaytext.Substring(0, 12);
                displaytext += "...";
            }

            if (bordertype == BorderType.Line)
            {
                //Border
                context.SetSourceRGB(0, 0, 0);
                context.LineWidth = .5;
                context.Rectangle(xpos, ypos, widht, height);
                context.Stroke();
            }

            //ColorFlag
            context.Rectangle(xpos, ypos, 5, height);
            context.SetSourceRGB(pin.PlotColor.Red, pin.PlotColor.Green, pin.PlotColor.Blue);
            context.Fill();

            //Number
            context.SetSourceRGB(0, 0, 0);
            context.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Bold);
            context.SetFontSize(fontsize);
            context.MoveTo(xpos + 5, ypos + fontsize);
            context.ShowText(pin.DisplayNumberShort);

            context.MoveTo(xpos + 5, ypos + fontsize * 2);
            context.ShowText(displaytext);
        }
Пример #34
0
		public static void Draw(Context grw, RectangleElement rect)
		{
			if (rect.Foregraund != null) {
				grw.SetSourceRGBA (
					rect.Foregraund.Red, 
					rect.Foregraund.Green, 
					rect.Foregraund.Blue, 
					rect.Alpha);
			}

			grw.Rectangle (
				new Rectangle (
					rect.LeftBottom.GeometryX, 
					rect.LeftBottom.GeometryY, 
					rect.GeometryWidth, 
					rect.GeometryHeight));

			grw.StrokePreserve();
			grw.Fill();
		}
Пример #35
0
        private Moodbar(string mood_file_path)
        {
            this.mood_file_path = mood_file_path;
            //            mood_file_path = GetMoodFilePath(audio_file_path);
            var file = new FileStream (mood_file_path, FileMode.Open);
            moodbar_data = new byte[file.Length / 3, 3];

            for (int i = 0; i < file.Length; i += 3) {
                moodbar_data[i / 3, 0] = (byte)file.ReadByte ();
                moodbar_data[i / 3, 1] = (byte)file.ReadByte ();
                moodbar_data[i / 3, 2] = (byte)file.ReadByte ();
            }
            file.Close ();

            mood_surface = new Cairo.ImageSurface (Cairo.Format.RGB24, 1000, 1);
            using (Cairo.Context cr = new Cairo.Context (mood_surface)) {
                for (int i = 0; i < moodbar_data.GetLength (0); i++) {
                    cr.SetSourceRGBA (moodbar_data[i, 0] / 255.0, moodbar_data[i, 1] / 255.0, moodbar_data[i, 2] / 255.0, 1);
                    cr.Rectangle (i, 0, 1, 1);
                    cr.Fill ();
                }
            }
        }
Пример #36
0
		static void DrawCloseButton (Context context, Gdk.Point center, bool hovered, double opacity, double animationProgress)
		{
			if (hovered) {
				const double radius = 6;
				context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
				context.SetSourceRGBA (.6, .6, .6, opacity);
				context.Fill ();

				context.SetSourceRGBA (0.95, 0.95, 0.95, opacity);
				context.LineWidth = 2;

				context.MoveTo (center.X - 3, center.Y - 3);
				context.LineTo (center.X + 3, center.Y + 3);
				context.MoveTo (center.X - 3, center.Y + 3);
				context.LineTo (center.X + 3, center.Y - 3);
				context.Stroke ();
			} else {
				double lineColor = .63 - .1 * animationProgress;
				const double fillColor = .74;

				double heightMod = Math.Max (0, 1.0 - animationProgress * 2);
				context.MoveTo (center.X - 3, center.Y - 3 * heightMod);
				context.LineTo (center.X + 3, center.Y + 3 * heightMod);
				context.MoveTo (center.X - 3, center.Y + 3 * heightMod);
				context.LineTo (center.X + 3, center.Y - 3 * heightMod);

				context.LineWidth = 2;
				context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
				context.Stroke ();

				if (animationProgress > 0.5) {
					double partialProg = (animationProgress - 0.5) * 2;
					context.MoveTo (center.X - 3, center.Y);
					context.LineTo (center.X + 3, center.Y);

					context.LineWidth = 2 - partialProg;
					context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
					context.Stroke ();

					double radius = partialProg * 3.5;

					// Background
					context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
					context.SetSourceRGBA (fillColor, fillColor, fillColor, opacity);
					context.Fill ();

					// Inset shadow
					using (var lg = new LinearGradient (0, center.Y - 5, 0, center.Y)) {
						context.Arc (center.X, center.Y + 1, radius, 0, Math.PI * 2);
						lg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.2 * opacity));
						lg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0));
						context.SetSource (lg);
						context.Stroke ();
					}

					// Outline
					context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
					context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
					context.Stroke ();

				}
			}
		}
Пример #37
0
        private Pixbuf PixbufText(string text, int size, bool transparent)
        {
            int x=0, y=36;

            surface = new Cairo.ImageSurface(Cairo.Format.Argb32,  800, 600);
            cr = new Cairo.Context(surface);

            if (!transparent) {
                cr.SetSourceRGBA (0.0, 0.0, 0.0, 1.0);
                cr.Rectangle (new Cairo.Rectangle (0, 0, 800, 600));
                cr.Fill ();
            }

            //cr.MoveTo(x, y);
            string font = "sans";
            if (Util.IsWindows ()) {
                font = "MS Gothic";
            }
            if (Util.IsLinux ()) {
                font = "TakaoGothic";
            }
            if (Util.IsMac ()) {
                font = "Hiragino Kaku Gothic ProN";
            }

            cr.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Bold);
            cr.SetFontSize(size);

            Cairo.TextExtents extents = cr.TextExtents(text);
            string[] lines = text.Split ('\n');
            int min = size;
            for (int i = 0; i < lines.Length; i++) {
                string line = lines[i];
                for (int j = size; j > 8; j-=4) {
                    extents = cr.TextExtents(line);
                    if(extents.Width+extents.XBearing<800){
                        if(j<min) min = j;
                        break;
                    }
                    cr.SetFontSize(j);
                }
            }
            cr.SetFontSize(min);

            //string[] lines = text.Split ('\n');
            for (int i = 0; i < lines.Length; i++) {
                DrawText (cr, lines[i], x, y);
                y += (int)extents.Height;
                if (i > 5)
                    break;
            }

            Pixbuf buf = new Gdk.Pixbuf (surface.Data, true, 8, surface.Width, surface.Height, surface.Stride);
            return buf;

            //buf.Save ("aaa.png", "png");
            //surface.WriteToPng (file);
        }
Пример #38
0
        private void DrawText(Context cr, string text, int x, int y)
        {
            cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.1);
            int dx = 3, dy = 4;
            cr.MoveTo(x-1+dx, y-1+dy);
            cr.ShowText(text);
            cr.MoveTo(x+1+dx, y+1+dy);
            cr.ShowText(text);
            cr.MoveTo(x-1+dx, y+1+dy);
            cr.ShowText(text);
            cr.MoveTo(x+1+dx, y-1+dy);
            cr.ShowText(text);

            Gdk.Color c = textcolor;
            double b = (double)c.Blue / ushort.MaxValue;
            double g = (double)c.Green / ushort.MaxValue;
            double r = (double)c.Red / ushort.MaxValue;
            if(b>1) b = 1;
            if(g>1) g = 1;
            if(r>1) r = 1;
            cr.SetSourceRGBA(b,g,r, 1);
            cr.MoveTo(x, y);
            cr.Antialias = Antialias.Default;
            cr.ShowText(text);
        }
Пример #39
0
        private void DrawSpline(Context g)
        {
            var infos = GetDrawingInfos ();

            foreach (var controlPoints in ControlPoints) {

                int points = controlPoints.Count;
                SplineInterpolator interpolator = new SplineInterpolator ();
                IList<int> xa = controlPoints.Keys;
                IList<int> ya = controlPoints.Values;
                PointD[] line = new PointD [size];

                for (int i = 0; i < points; i++) {
                    interpolator.Add (xa [i], ya [i]);
                }

                for (int i = 0; i < line.Length; i++) {
                   			line[i].X = (float)i;
                            line[i].Y = (float)(Utility.Clamp(size - 1 - interpolator.Interpolate (i), 0, size - 1));

                        }

                g.LineWidth = 2;
                g.LineJoin = LineJoin.Round;

                g.MoveTo (line [0]);
                for (int i = 1; i < line.Length; i++)
                    g.LineTo (line [i]);

                infos.MoveNext ();
                var info = infos.Current;

                g.SetSourceRGBA(info.Color);
                g.LineWidth = info.IsActive ? 2 : 1;
                g.Stroke ();
            }
        }
Пример #40
0
        private void Draw(DrawingArea drawingarea1, Color tool_color, Cairo.PointD point, bool first_pixel)
        {
            int x = (int)point.X;
            int y = (int) point.Y;

            if (last_point.Equals (point_empty)) {
                last_point = new Point (x, y);

                if (!first_pixel)
                    return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = doc.CurrentUserLayer.Surface;

            if (first_pixel) {
                // Does Cairo really not support a single-pixel-long single-pixel-wide line?
                surf.Flush ();
                int shiftedX = (int)point.X;
                int shiftedY = (int)point.Y;
                ColorBgra source = surf.GetColorBgra (shiftedX, shiftedY);
                source = UserBlendOps.NormalBlendOp.ApplyStatic (source, tool_color.ToColorBgra ());
                surf.SetColorBgra (source, shiftedX, shiftedY);
                surf.MarkDirty ();
            } else {
                using (Context g = new Context (surf)) {
                    g.AppendPath (doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Clip ();

                    g.Antialias = Antialias.None;

                    // Adding 0.5 forces cairo into the correct square:
                    // See https://bugs.launchpad.net/bugs/672232
                    g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5);
                    g.LineTo (x + 0.5, y + 0.5);

                    g.SetSourceRGBA (tool_color);
                    g.LineWidth = 1;
                    g.LineCap = LineCap.Square;

                    g.Stroke ();
                }
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            if (doc.Workspace.IsPartiallyOffscreen (r)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (r));
            }

            last_point = new Point (x, y);
        }
Пример #41
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button <= 0) {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty))
                last_point = new Point (x, y);

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = doc.CurrentUserLayer.Surface;

            using (Context g = new Context (surf)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                // Adding 0.5 forces cairo into the correct square:
                // See https://bugs.launchpad.net/bugs/672232
                g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5);
                g.LineTo (x + 0.5, y + 0.5);

                // Right-click is erase to background color, left-click is transparent
                if (mouse_button == 3)
                    g.SetSourceRGBA(PintaCore.Palette.SecondaryColor);
                else
                    g.Operator = Operator.Clear;

                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            if (doc.Workspace.IsPartiallyOffscreen (r)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (r));
            }

            last_point = new Point (x, y);
        }
Пример #42
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if ((args.Event.State & Gdk.ModifierType.Button1Mask) == Gdk.ModifierType.Button1Mask) {
                outline_color = PintaCore.Palette.PrimaryColor;
                fill_color = PintaCore.Palette.SecondaryColor;
            } else if ((args.Event.State & Gdk.ModifierType.Button3Mask) == Gdk.ModifierType.Button3Mask) {
                outline_color = PintaCore.Palette.SecondaryColor;
                fill_color = PintaCore.Palette.PrimaryColor;
            } else {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty)) {
                last_point = new Point (x, y);
                return;
            }

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            doc.ToolLayer.Clear ();
            ImageSurface surf = doc.ToolLayer.Surface;

            using (Context g = new Context (surf)) {
                doc.Selection.Clip(g);

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                if (path != null) {
                    g.AppendPath (path);
                    (path as IDisposable).Dispose ();
                }

                g.LineTo (x, y);

                path = g.CopyPath ();

                g.ClosePath ();
                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;
                g.FillRule = FillRule.EvenOdd;

                if (FillShape && StrokeShape) {
                    g.SetSourceRGBA (fill_color);
                    g.FillPreserve ();
                    g.SetSourceRGBA (outline_color);
                    g.Stroke ();
                } else if (FillShape) {
                    g.SetSourceRGBA (outline_color);
                    g.Fill ();
                } else {
                    g.SetSourceRGBA (outline_color);
                    g.Stroke ();
                }
            }

            doc.Workspace.Invalidate ();

            last_point = new Point (x, y);
        }
Пример #43
0
 void paintDisabled(Context gr, Rectangle rb)
 {
     gr.Operator = Operator.Xor;
     gr.SetSourceRGBA (0.6, 0.6, 0.6, 0.3);
     gr.Rectangle (rb);
     gr.Fill ();
     gr.Operator = Operator.Over;
 }
Пример #44
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            doc.ToolLayer.Hidden = true;

            if (surface_modified)
                PintaCore.History.PushNewItem (new SimpleHistoryItem (Icon, Name, undo_surface, doc.CurrentUserLayerIndex));
            else if (undo_surface != null)
                (undo_surface as IDisposable).Dispose ();

            surface_modified = false;
            ImageSurface surf = doc.CurrentUserLayer.Surface;

            using (Context g = new Context (surf)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                if (path != null) {
                    g.AppendPath (path);
                    (path as IDisposable).Dispose ();
                    path = null;
                }

                g.ClosePath ();
                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;
                g.FillRule = FillRule.EvenOdd;

                if (FillShape && StrokeShape) {
                    g.SetSourceRGBA (fill_color);
                    g.FillPreserve ();
                    g.SetSourceRGBA (outline_color);
                    g.Stroke ();
                } else if (FillShape) {
                    g.SetSourceRGBA (outline_color);
                    g.Fill ();
                } else {
                    g.SetSourceRGBA (outline_color);
                    g.Stroke ();
                }
            }

            doc.Workspace.Invalidate ();
        }
Пример #45
0
 protected void DrawLineInfo(Context g, HChartLine line, int index)
 {
     g.MoveTo (NumberSpacingXLeft+15, NumberSpacingYUp+15 + index * 15);
     g.LineTo (NumberSpacingXLeft+25, NumberSpacingYUp+15 + index * 15);
     line.UseColor (g);
     g.LineWidth = 11;
     g.Stroke ();
     g.MoveTo (NumberSpacingXLeft+26, NumberSpacingYUp+20 + index * 15);
     g.SetSourceRGBA (0, 0, 0, 0.5f);
     g.ShowText (line.GetName ());
 }
Пример #46
0
 static void DrawCircle(Context cr, double xc, double yc, double radius, Color color)
 {
     cr.SetSourceRGBA (color.R, color.G, color.B, color.A);
     OvalPath (cr, xc, yc, radius, radius);
     cr.Fill ();
 }
Пример #47
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button == 1) {
                StrokeColor = PintaCore.Palette.PrimaryColor;
                FillColor = PintaCore.Palette.SecondaryColor;
            } else if (mouse_button == 3) {
                StrokeColor = PintaCore.Palette.SecondaryColor;
                FillColor = PintaCore.Palette.PrimaryColor;
            } else {
                LastPoint = point_empty;
                return;
            }

            // TODO: also multiply by pressure
            StrokeColor = new Color (StrokeColor.R, StrokeColor.G, StrokeColor.B,
                StrokeColor.A * active_brush.StrokeAlphaMultiplier);

            int x = (int)point.X;
            int y = (int)point.Y;

            if (LastPoint.Equals (point_empty))
                LastPoint = new Point (x, y);

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            var surf = doc.CurrentUserLayer.Surface;
            var invalidate_rect = Gdk.Rectangle.Zero;
            var brush_width = BrushWidth;

            Surface = surf;

            using (Drawable = new Context (surf)) {
                Drawable.AppendPath (doc.Selection.SelectionPath);
                Drawable.FillRule = FillRule.EvenOdd;
                Drawable.Clip ();

                Drawable.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;
                Drawable.LineWidth = brush_width;
                Drawable.LineJoin = LineJoin.Round;
                Drawable.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round;
                Drawable.SetSourceRGBA (StrokeColor);

                active_brush.Tool = this;
                invalidate_rect = active_brush.DoMouseMove (x, y, LastPoint.X, LastPoint.Y);
                active_brush.Tool = null;
            }

            Surface = null;
            Drawable = null;

            // If we draw partially offscreen, Cairo gives us a bogus
            // dirty rectangle, so redraw everything.
            if (doc.Workspace.IsPartiallyOffscreen (invalidate_rect)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (invalidate_rect));
            }

            LastPoint = new Point (x, y);
        }
Пример #48
0
 protected void DrawTitle(Context g, String name)
 {
     g.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold); //Draw the title and line names/colors.
     g.SetFontSize (14);
     g.SetSourceRGBA (0, 0, 0, 0.5f);
     g.MoveTo (NumberSpacingXLeft+15, NumberSpacingYUp+7);
     g.ShowText (name);
 }
Пример #49
0
 /* Drawing */
 void DrawFrame(Context cr)
 {
     var fp = new Profiler ("DrawFrame");
     int w, h;
     GdkWindow.GetSize (out w, out h);
     fp.Time ("Window.GetSize");
     double x = dragX, y = dragY;
     bool sizeChanged = false;
     fp.Time ("GetPointer");
     if (InteractionProfiler.Watch.IsRunning)
       InteractionProfiler.Time ("From UI action to expose");
     if (Width != (uint)w || Height != (uint)h || CachedSurface == null) {
       if (CachedSurface != null) CachedSurface.Destroy ();
       CachedSurface = new ImageSurface(Format.ARGB32, w, h);
       sizeChanged = true;
       Width = (uint) w;
       Height = (uint) h;
       UpdateLayout ();
       fp.Time ("Recreate CachedSurface");
     }
     if (Cancelled) {
       ThrowFrames.Clear ();
       ThrowVelocity = 0;
     }
     if (ThrowVelocity != 0) {
       using ( Context ecr = new Context (EtcSurface) )
     PanBy (ecr, Width, Height, 0, ThrowVelocity);
       ThrowVelocity *= 0.98;
       if (Math.Abs(ThrowVelocity) < 1)
     ThrowVelocity = 0;
     }
     if (ZoomVelocity != 1) {
       using ( Context ecr = new Context (EtcSurface) )
     ZoomBy (ecr, Width, Height, x, y, ZoomVelocity);
       ZoomVelocity = Math.Pow(ZoomVelocity, 0.8);
       if (Math.Abs(1 - ZoomVelocity) < 0.001)
     ZoomVelocity = 1;
     }
     if (NeedZoomCheck)
       using ( Context ecr = new Context (EtcSurface) )
     CheckZoomNavigation(ecr, Width, Height);
     fp.Time ("Throw and zoom");
     if (sizeChanged || (!EffectInProgress && FSNeedRedraw)) {
       FSNeedRedraw = false;
       using (Context scr = new Context (CachedSurface)) {
     scr.Save ();
       scr.Operator = Operator.Source;
       scr.SetSourceRGBA (0,0,0,0);
       scr.Paint ();
     scr.Restore ();
     DrawMainView (scr, Width, Height);
     if (scr.Status != Status.Success)
       Helpers.LogError("Cairo error: {0}", scr.Status);
       }
       fp.Time ("FS Draw");
     }
     cr.Operator = Operator.Over;
     DrawBackground (cr, Width, Height);
     fp.Time ("DrawBackground");
     if (ControlLineVisible && panning) {
       cr.Save ();
     cr.Color = Renderer.DirectoryFGColor;
     cr.Rectangle (0, dragY, Width, 1);
     cr.Fill ();
       cr.Restore ();
     }
     using (SurfacePattern p = new SurfacePattern (CachedSurface)) {
       cr.Source = p;
       cr.Paint ();
       cr.Operator = Operator.Over;
       fp.Time ("Composite");
       if (DrawEffects (cr, Width, Height)) {
     LimitedRedraw = true;
     fp.Time ("Effects");
       }
     }
     if (InteractionProfiler.Watch.IsRunning) {
       InteractionProfiler.Total ("Interaction latency");
       InteractionProfiler.Stop ();
       InteractionProfiler.Reset ();
       InteractionProfiler.TotalElapsed = 0;
     }
     //     fp.Total ("Frame");
 }
Пример #50
0
			protected override bool OnDrawn (Context cr)
			{
				int w, h;
				this.GdkWindow.GetSize (out w, out h);
				var bounds = new Xwt.Rectangle (0.5, 0.5, w - 1, h - 1);
				var black = Xwt.Drawing.Color.FromBytes (0xee, 0xee, 0xee);
				
				// We clear the surface with a transparent color if possible
				if (supportAlpha)
					cr.SetSourceRGBA (1.0, 1.0, 1.0, 0.0);
				else
					cr.SetSourceRGB (1.0, 1.0, 1.0);
				cr.Operator = Operator.Source;
				cr.Paint ();
				
				var calibratedRect = RecalibrateChildRectangle (bounds);
				// Fill it with one round rectangle
				RoundRectangle (cr, calibratedRect, radius);
				cr.LineWidth = 1;
				
				// Triangle
				// We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
				var arrowX = bounds.Center.X + arrowDelta;
				var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + cr.LineWidth : calibratedRect.Bottom;
				cr.MoveTo (arrowX, arrowY);
				// We draw the rectangle path
				DrawTriangle (cr);

				// We use it
				cr.SetSourceRGBA (black.Red, black.Green, black.Blue, black.Alpha);
				cr.StrokePreserve ();
				cr.SetSourceRGBA (BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
				cr.Fill ();

				return base.OnDrawn (cr);
			}
Пример #51
0
        private void HandlePintaCoreActionsEditFillSelectionActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit ();

            Cairo.ImageSurface old = doc.CurrentUserLayer.Surface.Clone ();

            using (var g = new Cairo.Context (doc.CurrentUserLayer.Surface)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;

                g.SetSourceRGBA(PintaCore.Palette.PrimaryColor);
                g.Fill ();
            }

            doc.Workspace.Invalidate ();
            doc.History.PushNewItem (new SimpleHistoryItem ("Menu.Edit.FillSelection.png", Catalog.GetString ("Fill Selection"), old, doc.CurrentUserLayerIndex));
        }