InitScale() public method

public InitScale ( double sx, double sy ) : void
sx double
sy double
return void
Exemplo n.º 1
0
	static void draw (Cairo.Context gr, int width, int height)
	{
		int w, h;
		ImageSurface image;
		Matrix matrix;
		SurfacePattern pattern;
		
		gr.Scale (width, height);
		gr.LineWidth = 0.04;

		image = new ImageSurface ("data/e.png");
		w = image.Width;
		h = image.Height;
		
		pattern = new SurfacePattern (image);
		pattern.Extend = Cairo.Extend.Repeat;
		
		gr.Translate (0.5, 0.5);
		gr.Rotate (M_PI / 4);
		gr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
		gr.Translate (- 0.5, - 0.5);
		
		matrix = new Matrix ();
		matrix.InitScale (w * 5.0, h * 5.0);
		
		pattern.Matrix = matrix;
		
		gr.Pattern = pattern;
		
		gr.Rectangle ( new PointD (0, 0),
			       1.0, 1.0);
		gr.Fill ();
		
		pattern.Destroy ();
		image.Destroy();
	}
Exemplo n.º 2
0
        private Surface CreateScene (Cairo.Context window_cr, ImageSurface image, int reflect)
        {
            Surface surface = window_cr.Target.CreateSimilar (window_cr.Target.Content,
                image.Width, image.Height + reflect);
            Cairo.Context cr = new Context (surface);

            cr.Save ();

            cr.SetSource (image);
            cr.Paint ();

            cr.Rectangle (0, image.Height, image.Width, reflect);
            cr.Clip ();

            Matrix matrix = new Matrix ();
            matrix.InitScale (1, -1);
            matrix.Translate (0, -(2 * image.Height) + 1);
            cr.Transform (matrix);

            cr.SetSource (image);
            cr.Paint ();

            cr.Restore ();

            Color bg_transparent = BackgroundColor;
            bg_transparent.A = 0.65;

            LinearGradient mask = new LinearGradient (0, image.Height, 0, image.Height + reflect);
            mask.AddColorStop (0, bg_transparent);
            mask.AddColorStop (1, BackgroundColor);

            cr.Rectangle (0, image.Height, image.Width, reflect);
            cr.Pattern = mask;
            cr.Fill ();

            ((IDisposable)cr).Dispose ();
            return surface;
        }
Exemplo n.º 3
0
        private void imagepatternToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lastSelected = "imagepattern";
            OnPaintAction = cr =>
            {
                int w, h;
                ImageSurface image;

                Pattern pattern;
                Matrix matrix = new Matrix();

                image = new ImageSurface(romedalenPngData);
                w = image.Width;
                h = image.Height;

                pattern = new SurfacePattern(image);
                pattern.Extend = Extend.Repeat;

                cr.Translate(128.0, 128.0);
                cr.Rotate(Math.PI / 4);
                cr.Scale(1 / Math.Sqrt(2), 1 / Math.Sqrt(2));
                cr.Translate(-128.0, -128.0);

                matrix.InitScale(w/256.0*5.0, h/256.0*5.0);
                pattern.Matrix = matrix;

                cr.SetSource(pattern);

                cr.Rectangle(0, 0, 256.0, 256.0);
                cr.Fill();

                pattern.Dispose();
                image.Dispose();
            };

            Invalidate();
        }
Exemplo n.º 4
0
		public void imagepattern(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			
			ImageSurface image = new ImageSurface ("data/romedalen.png");
			int w = image.Width;
			int h = image.Height;

			SurfacePattern pattern = new SurfacePattern (image);
			pattern.Extend = Extend.Repeat;

			cr.Translate (0.5, 0.5);
			cr.Rotate (Math.PI / 4);
			cr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
			cr.Translate (- 0.5, - 0.5);

			Matrix matrix = new Matrix ();
			matrix.InitScale (w * 5.0, h * 5.0);
			pattern.Matrix = matrix;

			cr.Source = pattern;

			cr.Rectangle (0, 0, 1.0, 1.0);
			cr.Fill ();

			pattern.Destroy ();
			image.Destroy ();
		}
Exemplo n.º 5
0
        private Surface CreateScene(Cairo.Context window_cr, ImageSurface image, int reflect)
        {
            var target = window_cr.GetTarget ();
            Surface surface = target.CreateSimilar (target.Content,
                image.Width, image.Height + reflect);
            using (var cr = new Context (surface)) {

                cr.Save ();

                cr.SetSource (image);
                cr.Paint ();

                cr.Rectangle (0, image.Height, image.Width, reflect);
                cr.Clip ();

                Matrix matrix = new Matrix ();
                matrix.InitScale (1, -1);
                matrix.Translate (0, -(2 * image.Height) + 1);
                cr.Transform (matrix);

                cr.SetSource (image);
                cr.Paint ();

                cr.Restore ();

                Color bg_transparent = BackgroundColor;
                bg_transparent.A = 0.65;

                using (var mask = new LinearGradient (0, image.Height, 0, image.Height + reflect)) {
                    mask.AddColorStop (0, bg_transparent);
                    mask.AddColorStop (1, BackgroundColor);

                    cr.Rectangle (0, image.Height, image.Width, reflect);
                    cr.SetSource (mask);
                    cr.Fill ();
                }

            }
            return surface;
        }
Exemplo n.º 6
0
        protected override bool OnExposeEvent (Gdk.EventExpose evnt)
        {
            if (evnt.Window != GdkWindow) {
                return base.OnExposeEvent (evnt);
            }

            Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window);

            if (reflect) {
                CairoExtensions.PushGroup (cr);
            }

            cr.Operator = Operator.Over;
            cr.Translate (Allocation.X + h_padding, Allocation.Y);
            cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height,
                bar_height + bar_label_spacing + layout_height));
            cr.Clip ();

            Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height);

            cr.Save ();
	    cr.SetSource (bar);
            cr.Paint ();
            cr.Restore ();

            if (reflect) {
                cr.Save ();

                cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height);
                cr.Clip ();

                Matrix matrix = new Matrix ();
                matrix.InitScale (1, -1);
                matrix.Translate (0, -(2 * bar_height) + 1);
                cr.Transform (matrix);

		cr.SetSource (bar);

                LinearGradient mask = new LinearGradient (0, 0, 0, bar_height);

                mask.AddColorStop (0.25, new Color (0, 0, 0, 0));
                mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125));
                mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4));
                mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7));

                cr.Mask (mask);
		mask.Dispose ();

                cr.Restore ();

                CairoExtensions.PopGroupToSource (cr);
                cr.Paint ();
            }

            if (show_labels) {
                cr.Translate ((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2,
                     (reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing);

                RenderLabels (cr);
            }

	    bar.Dispose ();
            CairoExtensions.DisposeContext (cr);

            return true;
        }
Exemplo n.º 7
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (!CairoHelper.ShouldDrawWindow (cr, Window)) {
                return base.OnDrawn (cr);
            }

            if (reflect) {
                CairoExtensions.PushGroup (cr);
            }

            cr.Operator = Operator.Over;
            cr.Translate (h_padding, 0);
            cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height,
                bar_height + bar_label_spacing + layout_height));
            cr.Clip ();

            Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height);

            cr.Save ();
            cr.Source = bar;
            cr.Paint ();
            cr.Restore ();

            if (reflect) {
                cr.Save ();

                cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height);
                cr.Clip ();

                Matrix matrix = new Matrix ();
                matrix.InitScale (1, -1);
                matrix.Translate (0, -(2 * bar_height) + 1);
                cr.Transform (matrix);

                cr.Pattern = bar;

                LinearGradient mask = new LinearGradient (0, 0, 0, bar_height);

                mask.AddColorStop (0.25, new Color (0, 0, 0, 0));
                mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125));
                mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4));
                mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7));

                cr.Mask (mask);
                mask.Destroy ();

                cr.Restore ();

                CairoExtensions.PopGroupToSource (cr);
                cr.Paint ();
            }

            if (show_labels) {
                cr.Translate ((reflect ? 0 : -h_padding) + (Allocation.Width - layout_width) / 2,
                     bar_height + bar_label_spacing);
                RenderLabels (cr);
            }

            bar.Destroy ();

            return true;
        }