コード例 #1
0
ファイル: CairoContext.cs プロジェクト: nated099/gbrainy
        public void DrawStringWithWrapping(double x, double y, string str, double max_width)
        {
            int w, h, spacing;

            Cairo.Matrix old = Matrix;

            if (max_width < 0)
            {
                throw new ArgumentOutOfRangeException("Invalid maximum width value");
            }

            MoveTo(x, y);
            UpdateFontSize();
            Matrix = new Cairo.Matrix();

            spacing        = layout.Spacing;
            layout.Width   = (int)(max_width * old.Xx * Pango.Scale.PangoScale);
            layout.Spacing = (int)(FontLineSpace * (old.Yy * Pango.Scale.PangoScale));

            layout.SingleParagraphMode = false;
            SetText(str);
            Pango.CairoHelper.ShowLayout(this, layout);
            layout.GetPixelSize(out w, out h);

            layout.Spacing = spacing;
            Matrix         = old;
        }
コード例 #2
0
ファイル: CairoContext.cs プロジェクト: nated099/gbrainy
        public void MeasureString(string str, double max_width, bool wrapping, out double width, out double height)
        {
            int w, h, spacing;

            Cairo.Matrix old = Matrix;

            if (max_width < 0 || max_width > 1)
            {
                throw new ArgumentOutOfRangeException("Invalid maximum width value");
            }

            UpdateFontSize();
            Matrix = new Cairo.Matrix();

            spacing        = layout.Spacing;
            layout.Width   = (int)(max_width * old.Xx * Pango.Scale.PangoScale);
            layout.Spacing = (int)(FontLineSpace * (old.Xx * Pango.Scale.PangoScale));

            layout.SingleParagraphMode = !wrapping;
            SetText(str);
            layout.GetPixelSize(out w, out h);
            Matrix         = old;
            layout.Spacing = spacing;

            height = h / old.Yy;
            width  = w / old.Xx;
        }
コード例 #3
0
        /// <summary>
        /// Creates a new GdiRenderObject instance.
        /// </summary>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">The font to use to render the text.</param>
        /// <param name="bounds">The location and size to draw the text.</param>
        /// <param name="fill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="outline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        public CairoRenderObject(String text, FontFace font, Rectangle bounds,
                                 StyleBrush fill, StyleBrush highlightFill, StyleBrush selectFill,
                                 StylePen outline, StylePen highlightOutline, StylePen selectOutline)
        {
            _state = RenderState.Normal;
            Path   = null;

            Image           = null;
            Bounds          = new Rectangle();
            AffineTransform = null;
            ColorTransform  = null;

            Text             = text;
            Font             = font;
            Bounds           = bounds;
            Fill             = fill;
            HighlightFill    = highlightFill;
            SelectFill       = selectFill;
            Outline          = outline;
            HighlightOutline = highlightOutline;
            SelectOutline    = selectOutline;
            Line             = null;
            HighlightLine    = null;
            SelectLine       = null;
        }
コード例 #4
0
                public Cairo.Status Copy (out Cairo.Matrix other)
                {
                        IntPtr p = IntPtr.Zero;
                        
                        Cairo.Status status = CairoAPI.cairo_matrix_copy (matrix, out p);

                        other = new Cairo.Matrix (p);

                        return status;
                }
コード例 #5
0
ファイル: CairoContext.cs プロジェクト: nated099/gbrainy
        // Shows a text from the current position. No Width defined then no RTL positioning
        public void ShowPangoText(string str)
        {
            Cairo.Matrix old = Matrix;

            UpdateFontSize();
            Matrix = new Cairo.Matrix();
            SetText(str);
            layout.SingleParagraphMode = true;
            layout.Width = -1;
            Pango.CairoHelper.ShowLayout(this, layout);
            Matrix = old;
        }
コード例 #6
0
ファイル: ZoomableCairoArea.cs プロジェクト: tabrath/meshwork
 public void DeviceToUser(ref double x, ref double y)
 {
     Cairo.Matrix inv = (Cairo.Matrix) this.transformMatrix.Clone();
     Cairo.Status cs  = inv.Invert();
     if (cs == Cairo.Status.Success)
     {
         inv.TransformPoint(ref x, ref y);
     }
     else
     {
         throw new Exception("Unable to transform device coordinates to user coordinates because the matrix was uninvertible (" + cs.ToString() + ").");
     }
 }
コード例 #7
0
ファイル: CairoContext.cs プロジェクト: nated099/gbrainy
        // From a giving point centers the text into it
        public void DrawTextCentered(double x, double y, string str)
        {
            int w, h;

            Cairo.Matrix old = Matrix;

            UpdateFontSize();
            Matrix = new Cairo.Matrix();

            SetText(str);
            layout.SingleParagraphMode = true;
            layout.Width = -1;
            layout.GetPixelSize(out w, out h);
            MoveTo((old.X0 + x * old.Xx) - w / 2d, old.Y0 + (y * old.Yy) - h / 2d);
            Pango.CairoHelper.ShowLayout(this, layout);
            Matrix = old;
        }
コード例 #8
0
        /// <summary>
        /// Creates a new GdiRenderObject instance.
        /// </summary>
        /// <param name="image">The symbol to draw.</param>
        /// <param name="imageBounds">The location and size to draw the symbol.</param>
        /// <param name="transform">The affine transform applied to the symbol before drawing.</param>
        /// <param name="colorTransform">The color transform applied to the symbol before drawing.</param>
        public CairoRenderObject(Surface image, Rectangle imageBounds, CairoMatrix transform, CairoMatrix colorTransform)
        {
            _state          = RenderState.Normal;
            Image           = image;
            Bounds          = imageBounds;
            AffineTransform = transform;
            ColorTransform  = colorTransform;

            Path             = null;
            Fill             = null;
            HighlightFill    = null;
            SelectFill       = null;
            Line             = null;
            HighlightLine    = null;
            SelectLine       = null;
            Outline          = null;
            HighlightOutline = null;
            SelectOutline    = null;

            Text = null;
            Font = null;
        }
コード例 #9
0
ファイル: CairoContext.cs プロジェクト: nated099/gbrainy
        // Shows a text from the current position. Defines all the line as text drawing box
        public void ShowPangoText(string str, bool bold, double width, double rotation)
        {
            Pango.Alignment align = layout.Alignment;

            if (bold)
            {
                layout.FontDescription.Weight = Pango.Weight.Bold;
            }

            if (width == -1)               // Calculates maximum width in the user space
            {
                layout.Width = (int)(((1 - width_margin) * Matrix.Xx - (CurrentPoint.X * Matrix.Xx)) * Pango.Scale.PangoScale);
            }
            else
            {
                layout.Width = (int)(width * Matrix.Xx * Pango.Scale.PangoScale);
            }

            if (rotation != 0)
            {
                Cairo.Matrix old = Matrix;

                UpdateFontSize();
                Matrix = new Cairo.Matrix();
                Rotate(rotation);
                SetText(str);
                layout.SingleParagraphMode = true;

                Pango.CairoHelper.ShowLayout(this, layout);
                Matrix = old;
            }
            else
            {
                ShowPangoText(str);
            }

            layout.FontDescription.Weight = Pango.Weight.Normal;
            layout.Alignment = align;
        }
コード例 #10
0
        /// <summary>
        /// Creates a new CairoRenderObject instance.
        /// </summary>
        /// <param name="path">The path to draw.</param>
        /// <param name="fill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="line">
        /// The pen used to draw a line when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightLine">
        /// The pen used to draw a line when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectLine">
        /// The pen used to draw a line when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="outline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        public CairoRenderObject(Path2D path, StyleBrush fill, StyleBrush highlightFill, StyleBrush selectFill,
                                 StylePen line, StylePen highlightLine, StylePen selectLine,
                                 StylePen outline, StylePen highlightOutline, StylePen selectOutline)
        {
            _state           = RenderState.Normal;
            Path             = path;
            Fill             = fill;
            HighlightFill    = highlightFill;
            SelectFill       = selectFill;
            Line             = line;
            HighlightLine    = highlightLine;
            SelectLine       = selectLine;
            Outline          = outline;
            HighlightOutline = highlightOutline;
            SelectOutline    = selectOutline;

            Image           = null;
            Bounds          = new Rectangle();
            AffineTransform = new CairoMatrix();
            ColorTransform  = null;

            Text = null;
            Font = null;
        }
コード例 #11
0
ファイル: ZoomableCairoArea.cs プロジェクト: tabrath/meshwork
        public ZoomableCairoArea()
        {
            this.mousePressedX      = -1;
            this.mousePressedY      = -1;
            this.currentMouseX      = -1;
            this.currentMouseY      = -1;
            this.lastMouseX         = -1;
            this.lastMouseY         = -1;
            this.mousePressedUserX  = -1;
            this.mousePressedUserY  = -1;
            this.firstPressedButton = 0;
            this.scrollUnits        = 0.1;

            this.maxScale = 1.0;
            this.minScale = 0.1;

            this.transformMatrix = new Matrix();
            this.background      = new Cairo.Color(0.3, 0.3, 0.3, 1.0);

            this.mouseInWidget        = false;
            this.pressedButtons       = new bool[] { false, false, false };
            this.isScaling            = false;
            this.isTranslating        = false;
            this.isScrollWheelScaling = false;
            this.drawZoomScale        = true;

            this.Events = this.Events |
                          Gdk.EventMask.ButtonPressMask |
                          Gdk.EventMask.ButtonReleaseMask |
                          Gdk.EventMask.PointerMotionMask |
                          Gdk.EventMask.EnterNotifyMask |
                          Gdk.EventMask.LeaveNotifyMask |
                          Gdk.EventMask.ScrollMask;

            this.CanFocus = true;
        }
コード例 #12
0
        // Shows a text from the current position. No Width defined then no RTL positioning
        public void ShowPangoText(string str)
        {
            Cairo.Matrix old = Matrix;

            UpdateFontSize ();
            Matrix = new Cairo.Matrix ();
            SetText (str);
            layout.SingleParagraphMode = true;
            layout.Width = -1;
            Pango.CairoHelper.ShowLayout (this, layout);
            Matrix = old;
        }
コード例 #13
0
        // Shows a text from the current position. Defines all the line as text drawing box
        public void ShowPangoText(string str, bool bold, double width, double rotation)
        {
            Pango.Alignment align = layout.Alignment;

            if (bold) {
                layout.FontDescription.Weight = Pango.Weight.Bold;
            }

            if (width == -1) { // Calculates maximum width in the user space
                layout.Width = (int) (((1 - width_margin) * Matrix.Xx - (CurrentPoint.X * Matrix.Xx)) * Pango.Scale.PangoScale);
            } else
                layout.Width = (int) (width * Matrix.Xx * Pango.Scale.PangoScale);

            if (rotation != 0) {

                Cairo.Matrix old = Matrix;

                UpdateFontSize ();
                Matrix = new Cairo.Matrix ();
                Rotate (rotation);
                SetText (str);
                layout.SingleParagraphMode = true;

                Pango.CairoHelper.ShowLayout (this, layout);
                Matrix = old;
            }
            else
                ShowPangoText (str);

            layout.FontDescription.Weight = Pango.Weight.Normal;
            layout.Alignment = align;
        }
コード例 #14
0
        // From a giving point centers the text into it
        public void DrawTextCentered(double x, double y, string str)
        {
            int w, h;
            Cairo.Matrix old = Matrix;

            UpdateFontSize ();
            Matrix = new Cairo.Matrix ();

            SetText (str);
            layout.SingleParagraphMode = true;
            layout.Width = -1;
            layout.GetPixelSize (out w, out h);
            MoveTo ((old.X0 + x * old.Xx) - w / 2d, old.Y0 + (y * old.Yy) - h / 2d);
            Pango.CairoHelper.ShowLayout (this, layout);
            Matrix = old;
        }
コード例 #15
0
        public void MeasureString(string str, double max_width, bool wrapping, out double width, out double height)
        {
            int w, h, spacing;
            Cairo.Matrix old = Matrix;

            if (max_width < 0 || max_width > 1)
                throw new ArgumentOutOfRangeException ("Invalid maximum width value");

            UpdateFontSize ();
            Matrix = new Cairo.Matrix ();

            spacing = layout.Spacing;
            layout.Width = (int) (max_width * old.Xx * Pango.Scale.PangoScale);
            layout.Spacing = (int) (FontLineSpace * (old.Xx * Pango.Scale.PangoScale));

            layout.SingleParagraphMode = !wrapping;
            SetText (str);
            layout.GetPixelSize (out w, out h);
            Matrix = old;
            layout.Spacing = spacing;

            height = h / old.Yy;
            width = w / old.Xx;
        }
コード例 #16
0
        public void DrawStringWithWrapping(double x, double y, string str, double max_width)
        {
            int w, h, spacing;
            Cairo.Matrix old = Matrix;

            if (max_width < 0)
                throw new ArgumentOutOfRangeException ("Invalid maximum width value");

            MoveTo (x, y);
            UpdateFontSize ();
            Matrix = new Cairo.Matrix ();

            spacing = layout.Spacing;
            layout.Width = (int) (max_width * old.Xx * Pango.Scale.PangoScale);
            layout.Spacing = (int) (FontLineSpace * (old.Yy * Pango.Scale.PangoScale));

            layout.SingleParagraphMode = false;
            SetText (str);
            Pango.CairoHelper.ShowLayout (this, layout);
            layout.GetPixelSize (out w, out h);

            layout.Spacing = spacing;
            Matrix = old;
        }
コード例 #17
0
ファイル: Point3.cs プロジェクト: KULeuven-KRR/IdpGie
 /// <summary>
 /// Transform this point with the given <see cref="Matrix"/>.
 /// </summary>
 /// <param name='m'>
 /// The given transformation matrix.
 /// </param>
 public void Transform(Matrix m)
 {
     double newx = this.x * m.Xx + this.y * m.Xy + m.X0;
     double newy = this.x * m.Yx + this.y * m.Yy + m.Y0;
     this.x = newx;
     this.y = newy;
 }
コード例 #18
0
        /// <summary>
        /// Creates a new GdiRenderObject instance.
        /// </summary>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">The font to use to render the text.</param>
        /// <param name="bounds">The location and size to draw the text.</param>
        /// <param name="fill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="outline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        public CairoRenderObject(String text, FontFace font, Rectangle bounds,
                                 StyleBrush fill, StyleBrush highlightFill, StyleBrush selectFill,
                                 StylePen outline, StylePen highlightOutline, StylePen selectOutline)
        {
            _state = RenderState.Normal;
            Path = null;

            Image = null;
            Bounds = new Rectangle();
            AffineTransform = null;
            ColorTransform = null;

            Text = text;
            Font = font;
            Bounds = bounds;
            Fill = fill;
            HighlightFill = highlightFill;
            SelectFill = selectFill;
            Outline = outline;
            HighlightOutline = highlightOutline;
            SelectOutline = selectOutline;
            Line = null;
            HighlightLine = null;
            SelectLine = null;
        }
コード例 #19
0
        /// <summary>
        /// Creates a new GdiRenderObject instance.
        /// </summary>
        /// <param name="image">The symbol to draw.</param>
        /// <param name="imageBounds">The location and size to draw the symbol.</param>
        /// <param name="transform">The affine transform applied to the symbol before drawing.</param>
        /// <param name="colorTransform">The color transform applied to the symbol before drawing.</param>
        public CairoRenderObject(Surface image, Rectangle imageBounds, CairoMatrix transform, CairoMatrix colorTransform)
        {
            _state = RenderState.Normal;
            Image = image;
            Bounds = imageBounds;
            AffineTransform = transform;
            ColorTransform = colorTransform;

            Path = null;
            Fill = null;
            HighlightFill = null;
            SelectFill = null;
            Line = null;
            HighlightLine = null;
            SelectLine = null;
            Outline = null;
            HighlightOutline = null;
            SelectOutline = null;

            Text = null;
            Font = null;
        }
コード例 #20
0
        public ZoomableCairoArea()
        {
            this.mousePressedX = -1;
            this.mousePressedY = -1;
            this.currentMouseX = -1;
            this.currentMouseY = -1;
            this.lastMouseX = -1;
            this.lastMouseY = -1;
            this.mousePressedUserX = -1;
            this.mousePressedUserY = -1;
            this.firstPressedButton = 0;
            this.scrollUnits = 0.1;

            this.maxScale = 1.0;
            this.minScale = 0.1;

            this.transformMatrix = new Matrix ();
            this.background = new Cairo.Color (0.3, 0.3, 0.3, 1.0);

            this.mouseInWidget = false;
            this.pressedButtons = new bool[] {false, false, false};
            this.isScaling = false;
            this.isTranslating = false;
            this.isScrollWheelScaling = false;
            this.drawZoomScale = true;

            this.Events = this.Events |
                Gdk.EventMask.ButtonPressMask |
                Gdk.EventMask.ButtonReleaseMask |
                Gdk.EventMask.PointerMotionMask |
                Gdk.EventMask.EnterNotifyMask |
                Gdk.EventMask.LeaveNotifyMask |
                Gdk.EventMask.ScrollMask;

            this.CanFocus = true;
        }
コード例 #21
0
        /// <summary>
        /// Creates a new CairoRenderObject instance.
        /// </summary>
        /// <param name="path">The path to draw.</param>
        /// <param name="fill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="line">
        /// The pen used to draw a line when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightLine">
        /// The pen used to draw a line when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectLine">
        /// The pen used to draw a line when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="outline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        public CairoRenderObject(Path2D path, StyleBrush fill, StyleBrush highlightFill, StyleBrush selectFill,
                                 StylePen line, StylePen highlightLine, StylePen selectLine,
                                 StylePen outline, StylePen highlightOutline, StylePen selectOutline)
        {
            _state = RenderState.Normal;
            Path = path;
            Fill = fill;
            HighlightFill = highlightFill;
            SelectFill = selectFill;
            Line = line;
            HighlightLine = highlightLine;
            SelectLine = selectLine;
            Outline = outline;
            HighlightOutline = highlightOutline;
            SelectOutline = selectOutline;

            Image = null;
            Bounds = new Rectangle();
            AffineTransform = new CairoMatrix();
            ColorTransform = null;

            Text = null;
            Font = null;
        }
コード例 #22
0
                public static Cairo.Status Multiply (
                        out Cairo.Matrix result, Cairo.Matrix a, Cairo.Matrix b)
                {
                        IntPtr p = IntPtr.Zero;
                        
                        Cairo.Status status = CairoAPI.cairo_matrix_multiply (
                                out p, a.Pointer, b.Pointer);

                        result = new Cairo.Matrix (p);

                        return status;
                }