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

public GetSource ( ) : Pattern
Результат Pattern
Пример #1
0
        protected void DrawBackground(Cairo.Context cr)
        {
            var totalRect = GetTotalBounds();

            cr.SetSourceColor(BackgroundColor);
            cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height);
            cr.Fill();

            cr.Save();
            cr.Translate(XOffset, YOffset);
            cr.Scale(Scale, Scale);

            if (Surface != null)
            {
                cr.SetSource(Surface, 0, 0);

                using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                    pattern.Filter = Filter.Nearest;
                }

                cr.Paint();
            }
            else if (Image != null)
            {
                using (Surface source = new BitmapSurface(Image)) {
                    cr.SetSource(source, 0, 0);

                    using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                        pattern.Filter = Filter.Nearest;
                    }

                    cr.Paint();
                }
            }
            else
            {
                Cairo.Rectangle extents = cr.ClipExtents();
                for (int i = 0; i < Width * Height; i++)
                {
                    int             tileX = i % Width;
                    int             tileY = i / Width;
                    Cairo.Rectangle rect  = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false);

                    if (!CairoHelper.RectsOverlap(extents, rect))
                    {
                        continue;
                    }

                    cr.Save();
                    cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY);
                    cr.Rectangle(0, 0, TileWidth, TileHeight);
                    cr.Clip();
                    TileDrawer(i, cr);
                    cr.Restore();
                }
            }

            cr.Restore(); // Undo scale, offset
        }
Пример #2
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();
            }
        }
Пример #3
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 ();*/
        }
Пример #4
0
        private void RenderBarSegments (Context cr, int w, int h, int r)
        {
            LinearGradient grad = new LinearGradient (0, 0, w, 0);
            double last = 0.0;

            foreach (Segment segment in segments) {
                if (segment.Percent > 0) {
                    grad.AddColorStop (last, segment.Color);
                    grad.AddColorStop (last += segment.Percent, segment.Color);
                }
            }

            CairoExtensions.RoundedRectangle (cr, 0, 0, w, h, r);
	    cr.SetSource (grad);
            cr.FillPreserve ();
	    cr.GetSource ().Dispose ();

            grad = new LinearGradient (0, 0, 0, h);
            grad.AddColorStop (0.0, new Color (1, 1, 1, 0.125));
            grad.AddColorStop (0.35, new Color (1, 1, 1, 0.255));
            grad.AddColorStop (1, new Color (0, 0, 0, 0.4));

	    cr.SetSource (grad);
            cr.Fill ();
	    cr.GetSource ().Dispose ();
        }