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

public ShowText ( byte utf8 ) : void
utf8 byte
Результат void
Пример #1
0
        public static void PrintMonthHeader(Cairo.Context cr, int year, int month, bool outputMonthHeaderRect = false)
        {
            if (outputMonthHeaderRect)
            {
                var MonthHeaderRect = new Rectangle(
                    MarginLeft, MarginUp,
                    ContentWidth,
                    MonthHeader);
                cr.Rectangle(MonthHeaderRect);
            }

            var Month = MonthNames[month];

            cr.SetFontSize(MonthHeader * 0.8);
            var te = cr.TextExtents(Month);

            cr.MoveTo(MarginLeft - te.XBearing,
                      MarginUp + MonthHeader - ((MonthHeader - te.Height) / 2) - (te.Height + te.YBearing));
            cr.ShowText(Month);

            te = cr.TextExtents(year.ToString());
            cr.MoveTo(width - MarginRight - te.Width - te.XBearing,
                      MarginUp + MonthHeader - ((MonthHeader - te.Height) / 2) - (te.Height + te.YBearing));
            cr.ShowText(year.ToString());
        }
Пример #2
0
        private void CairoDraw(EventExpose evnt, int height, int width)
        {
            Time time = new Time();

            width = Math.Min(width, this.Allocation.Width);
            using (Cairo.Context g = Gdk.CairoHelper.Create(evnt.Window)) {
                Cairo.Color color = new Cairo.Color(0, 0, 0);
                /* Drawing position triangle */
                CairoUtils.DrawTriangle(g, CurrentFrame / pixelRatio - Scroll, height, 10, 15, color);
                /* Draw '0' */
                CairoUtils.DrawLine(g, 0 - Scroll, height, width, height, 2, color);
                g.MoveTo(new PointD(0 - Scroll, height - 20));
                g.ShowText("0");

                for (int i = 10 * FrameRate; i <= frames / pixelRatio;)
                {
                    CairoUtils.DrawLine(g, i - Scroll, height, i - Scroll,
                                        height - 10, 2, color);
                    g.MoveTo(new PointD(i - Scroll - 13, height - 20));
                    time.Seconds = (int)(i / FrameRate * pixelRatio);
                    g.ShowText(time.ToSecondsString());
                    i = i + 10 * FrameRate;
                }
                for (int i = 0; i <= frames / pixelRatio;)
                {
                    CairoUtils.DrawLine(g, i - Scroll, height, i - Scroll,
                                        height - 5, 1, color);
                    i = i + FrameRate;
                }
            }
        }
Пример #3
0
        protected override void DrawContents(Gdk.Drawable d)
        {
            Gdk.GC        gc = new Gdk.GC(d);
            Cairo.Context g  = Gdk.CairoHelper.Create(d);

            g.SelectFontFace("Lucida Console", FontSlant.Normal, FontWeight.Bold);
            g.SetFontSize(24);


            TextExtents te;

            string lvl, hp, hpm, mp, mpm;


            #region Character Status

            d.DrawPixbuf(gc, Graphics.GetProfile(Selected.Name), 0, 0,
                         X + xpic, Y + ypic,
                         Graphics.PROFILE_WIDTH, Graphics.PROFILE_HEIGHT,
                         Gdk.RgbDither.None, 0, 0);

            g.Color = new Color(.3, .8, .8);
            g.MoveTo(X + x3, Y + ya);
            g.ShowText("LV");
            g.MoveTo(X + x3, Y + yb);
            g.ShowText("HP");
            g.MoveTo(X + x3, Y + yc);
            g.ShowText("MP");
            g.Color = new Color(1, 1, 1);

            Graphics.ShadowedText(g, Selected.Name, X + x3, Y + y);

            lvl = Selected.Level.ToString();
            hp  = Selected.HP.ToString() + "/";
            hpm = Selected.MaxHP.ToString();
            mp  = Selected.MP.ToString() + "/";
            mpm = Selected.MaxMP.ToString();

            te = g.TextExtents(lvl);
            Graphics.ShadowedText(g, lvl, X + x4 - te.Width, Y + ya);

            te = g.TextExtents(hp);
            Graphics.ShadowedText(g, hp, X + x5 - te.Width, Y + yb);

            te = g.TextExtents(hpm);
            Graphics.ShadowedText(g, hpm, X + x6 - te.Width, Y + yb);

            te = g.TextExtents(mp);
            Graphics.ShadowedText(g, mp, X + x5 - te.Width, Y + yc);

            te = g.TextExtents(mpm);
            Graphics.ShadowedText(g, mpm, X + x6 - te.Width, Y + yc);

            #endregion Status



            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Пример #4
0
    protected void DrawingPlace(object sender, ExposeEventArgs args)
    {
        DrawingArea area = (DrawingArea)sender;

        Cairo.Context cc = Gdk.CairoHelper.Create(area.GdkWindow);

        cc.SelectFontFace("Sans", Cairo.FontSlant.Italic, Cairo.FontWeight.Bold);
        cc.SetFontSize(25);
        cc.MoveTo(15, 20);
        cc.ShowText("Диаграмма");
        cc.MoveTo(330, 40);
        cc.SetFontSize(15);
        cc.SelectFontFace("Sans", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
        cc.ShowText("Выручка");

        cc.SetSourceRGB(0.2, 0.23, 0.9);
        cc.LineWidth = 1;

        int s      = 50;
        int s_next = 40;
        int w;
        int i = 0;
        int h = 65;

        foreach (var item in global_1)
        {
            w = Convert.ToInt32(item);
            cc.SetFontSize(15);
            cc.MoveTo(0, h);
            cc.SetSourceRGB(0, 0, 0);
            cc.SelectFontFace("Sans", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
            cc.ShowText(Convert.ToString(i + 1));
            i = i + 1;
            cc.SetSourceRGB(0.2, 0.23, 0.9);
            cc.Rectangle(10, s, w, 30);
            h = h + 40;
            s = s + s_next;
        }

        cc.LineTo(10, 50);
        cc.LineTo(10, 390);
        cc.StrokePreserve();
        cc.Fill();

        cc.LineTo(10, 50);
        cc.LineTo(390, 50);
        cc.StrokePreserve();
        cc.Fill();

        cc.MoveTo(0, 390);
        cc.SetSourceRGB(0, 0, 0);
        cc.SetFontSize(15);
        cc.SelectFontFace("Sans", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
        cc.ShowText("Период");

        ((IDisposable)cc).Dispose();
    }
Пример #5
0
        public static void ShadowedText(Cairo.Context g, Cairo.Color c, string text, double x, double y)
        {
            g.Save();

            g.MoveTo(x + SHADOW_SPACING, y + SHADOW_SPACING);
            g.Color = Colors.BLACK;
            g.ShowText(text);

            g.MoveTo(x, y);
            g.Color = c;
            g.ShowText(text);

            g.Restore();
        }
Пример #6
0
        protected override void DrawContents(Gdk.Drawable d, Cairo.Context g, int width, int height, bool screenChanged)
        {
            g.SelectFontFace(Text.MONOSPACE_FONT, FontSlant.Normal, FontWeight.Bold);
            g.SetFontSize(24);



            #region Slots

            MateriaSlots.Render(g, MenuState.Party.Selected.Weapon, X + x_slots, Y + y_slots_weapon);
            MateriaSlots.Render(g, MenuState.Party.Selected.Armor, X + x_slots, Y + y_slots_armor);

            #endregion

            #region Character Status

            Images.RenderProfile(d, X + xpic, Y + ypic, MenuState.Party.Selected);

            Graphics.Stats.RenderCharacterStatus(d, g, MenuState.Party.Selected, X + x_status, Y + y_status, false);

            #endregion Status

            #region Equipment

            g.Color = Colors.TEXT_TEAL;
            g.MoveTo(X + x_labels, Y + y_weapon);
            g.ShowText("Wpn.");
            g.MoveTo(X + x_labels, Y + y_armor);
            g.ShowText("Arm.");
            g.Color = Colors.WHITE;

            Text.ShadowedText(g, "Check", X + x_labels, Y + y_check);
            Text.ShadowedText(g, "Arr.", X + x_labels, Y + y_arrange);

            string weapon, armor;
            weapon = MenuState.Party.Selected.Weapon.Name;
            armor  = MenuState.Party.Selected.Armor.Name;

            Text.ShadowedText(g, MenuState.Party.Selected.Weapon.Name, X + x_names, Y + y_weapon);
            Text.ShadowedText(g, MenuState.Party.Selected.Armor.Name, X + x_names, Y + y_armor);

            #endregion


            if (IsControl)
            {
                Shapes.RenderCursor(g, X + cx, Y + cy);
            }
        }
Пример #7
0
    void draw_grid(Cairo.Context gr, int w, int h)
    {
        double y_interval, y_spacing;
        double pixels    = 80;
        double num_ticks = h / pixels;
        double interval  = max_y / num_ticks;
        double min_size  = 1;

        while (true)
        {
            double new_size = min_size * 10;
            if (new_size < interval)
            {
                min_size = new_size;
                continue;
            }
            break;
        }
        y_spacing  = pixels * min_size / interval;
        y_interval = min_size;

        gr.Color     = new Color(0.4, 0.4, 0.4, 1);
        gr.LineWidth = .5;
        double y_label = 0;

        for (double i = h; i >= 0; i -= y_spacing)
        {
            gr.MoveTo(0, i);
            gr.LineTo(w, i);
            gr.Stroke();
            gr.LineTo(5, i);
            gr.ShowText(GetLabel(y_label));
            y_label += y_interval;
        }
    }
Пример #8
0
        /*
         * Paints text to the surface with Cairo's Toy text API.  Toy
         * text API.  This is solely useful when trying to draw
         * text without the assistance of Pango.CairoHelper.
         */
        public static void PaintToyText(Cairo.Context cr, int size,
                                        string text, int x, int y,
                                        bool centered, int hint_width)
        {
            if (text == null)
            {
                return;
            }

            cr.SetFontSize(size);

            // Do manual text layout since Cairo's toy text api is
            // just that, a toy.
            string[] lines = text.Split('\n');
            foreach (string line in lines)
            {
                // Cairo's text origin is at the bottom left
                // corner of the text rect
                Cairo.TextExtents te = cr.TextExtents(line);

                int line_x = centered
                                        ? (int)(x + (hint_width / 2) - ((te.Width + te.XBearing) / 2))
                                        : x;

                // Center the text
                cr.MoveTo(line_x, y - (te.Height + te.YBearing) + te.Height);
                cr.ShowText(line);

                y += (int)te.Height + LEADING;
            }
        }
Пример #9
0
        //intro top Welcome
        public void IntroTop(Cairo.Context g, Int32 width)
        {
            PointD p1, p2, p3, p4, s1, s2, s3, s4;

            p1 = new PointD(10, 10); p2 = new PointD(width, 10); s1 = new PointD(width + 2, 12); s2 = new PointD(width + 2, 38);
            p3 = new PointD(width, 40); p4 = new PointD(10, 40); s3 = new PointD(8, 38); s4 = new PointD(8, 12);

            g.Color = new Color(0.3, 0.4, 0.6, 1);
            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath(); g.LineWidth = 1; g.Stroke();

            g.MoveTo(p1); g.LineTo(p2);  g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath();

            Cairo.Gradient pat = new Cairo.LinearGradient(80, 10, 80, 80);
            pat.AddColorStop(0, new Cairo.Color(0.3, 0.4, 0.6, 0.6));
            pat.AddColorStop(1, new Cairo.Color(0, 0, 0, 1));
            g.Pattern = pat; g.FillPreserve();

            g.SetFontSize(22);
            g.SelectFontFace("", FontSlant.Italic, FontWeight.Bold);
            g.MoveTo(new PointD(22, 33));
            g.Color = new Color(1, 1, 1, 1);
            g.ShowText("Welcome to");

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Пример #10
0
        private void DrawText(Cairo.Context cr, string text, double lineSpacing)
        {
            string [] lines        = text.Split('\n');
            double [] cuml_heights = new double[lines.Length];
            double    y_start      = 0.0;

            for (int i = 0; i < lines.Length; i++)
            {
                TextExtents extents = cr.TextExtents(lines[i]);
                double      height  = extents.Height + (i > 0 ? lineSpacing : 0);
                cuml_heights[i] = i > 0 ? cuml_heights[i - 1] + height : height;
            }

            y_start = (Allocation.Height / 2) - (cuml_heights[cuml_heights.Length - 1] / 2);

            for (int i = 0; i < lines.Length; i++)
            {
                TextExtents extents = cr.TextExtents(lines[i]);

                double x = (Allocation.Width / 2) - (extents.Width / 2);
                double y = y_start + cuml_heights[i];

                cr.MoveTo(x, y);
                cr.ShowText(lines[i]);
            }
        }
Пример #11
0
 private void Image_Loaded(object sender, RoutedEventArgs e)
 {
     Image image = (Image)sender;
     using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height))
     {
         using (Context context = new Context(surface))
         {
             PointD p = new PointD(10.0, 10.0);
             PointD p2 = new PointD(100.0, 10.0);
             PointD p3 = new PointD(100.0, 100.0);
             PointD p4 = new PointD(10.0, 100.0);
             context.MoveTo(p);
             context.LineTo(p2);
             context.LineTo(p3);
             context.LineTo(p4);
             context.LineTo(p);
             context.ClosePath();
             context.Fill();
             context.MoveTo(140.0, 110.0);
             context.SetFontSize(32.0);
             context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0));
             context.ShowText("Hello Cairo!");
             surface.Flush();
             RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width);
             image.Source = source;
         }
     }
 }
Пример #12
0
        public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer)
        {
            if (layer == PrintLayer.Text)
            {
                cr.SetFont(_fontInfo);

                yPos -= _extents.YAdvance;

                if (_fontInfo.Underline == true)
                {
                    TextExtents extents = GetExtents(cr);

                    cr.Rectangle(xPos
                                 , yPos - _fontInfo.UnderlineHeight
                                 , extents.Width
                                 , _fontInfo.UnderlineHeight);

                    cr.Fill();

                    yPos -= _fontInfo.UnderlineHeight + 2.0;
                }

                cr.MoveTo(xPos, yPos);
                cr.ShowText(_text);
            }
        }
Пример #13
0
        //system top
        public void SystemTop(Cairo.Context g, Int32 width)
        {
            PointD p1, p2, p3, p4, s1, s2, s3, s4;

            p1 = new PointD(5, 5); p2 = new PointD(width, 5); s1 = new PointD(width + 2, 7); s2 = new PointD(width + 2, 28);
            p3 = new PointD(width, 30); p4 = new PointD(5, 30); s3 = new PointD(3, 28); s4 = new PointD(3, 7);

            g.Color = new Color(0.3, 0.4, 0.6, 1);
            g.MoveTo(p1); g.LineTo(p2);  g.LineTo(s1);  g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath(); g.LineWidth = 1; g.Stroke();

            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath();

            Cairo.Gradient pat = new Cairo.LinearGradient(80, 10, 80, 60);
            pat.AddColorStop(0, new Cairo.Color(0.3, 0.4, 0.6, 0.6));
            pat.AddColorStop(1, new Cairo.Color(0, 0, 0, 1));
            g.Pattern = pat;
            g.FillPreserve();

            g.SetFontSize(17);
            g.SelectFontFace("", FontSlant.Normal, FontWeight.Bold);
            g.MoveTo(new PointD(12, 23));
            g.Color = new Color(1, 1, 1, 1);
            g.ShowText("General system information");

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Пример #14
0
    public void DrawGraph(Context gr)
    {
        int mag = Magnification;
        double xoffset =  (Allocation.Width/2) ;
        double yoffset =  (Allocation.Height/2) ;

        if (ForceGraph != null) {
            this.GdkWindow.Clear ();
            gr.Antialias = Antialias.Subpixel;
            foreach (var p in ForceGraph.Springs){
                gr.LineWidth = 1.5;

                if ( p.Data != null ){
                    var data = p.Data as NodeData;
                    if ( data != null )
                        gr.Color = data.Stroke;
                } else {
                    gr.Color = new Color( 0,0,0,1);
                }
                gr.MoveTo( xoffset + ( p.NodeA.Location.X * mag ), yoffset + ( p.NodeA.Location.Y * mag ) );
                gr.LineTo( xoffset + ( p.NodeB.Location.X * mag ), yoffset + ( p.NodeB.Location.Y * mag ) );
                gr.Stroke();

            }

            foreach (var n in ForceGraph.Nodes) {
                var stroke = new Color( 0.1, 0.1, 0.1, 0.8 );
                var fill   = new Color( 0.2, 0.7, 0.7, 0.8 );
                var size = 5.5;

                NodeData nd = n.Data as NodeData;
                if ( nd != null ){
                    stroke = nd.Stroke;
                    fill = nd.Fill;
                    size = nd.Size;

                }

                DrawFilledCircle (gr,
                    xoffset + (mag * n.Location.X),
                    yoffset + (mag * n.Location.Y),
                    size,
                    stroke,
                    fill
                    );

                if ( nd != null ) {
                    if ( nd.Label != null ){
                        gr.Color = new Color(0,0,0,0.7);
                        gr.SetFontSize(24);
                        gr.MoveTo( 25 + xoffset + (mag * n.Location.X), 25 + yoffset + (mag * n.Location.Y));
                        gr.ShowText( nd.Label );
                    }
                }

            }

        }
    }
Пример #15
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 ();
             */
        }
Пример #16
0
        public static void ShadowedText(Cairo.Context g, Cairo.Color c, string text, double x, double y, string font, int point)
        {
            g.Save();

            g.SelectFontFace(font, FontSlant.Normal, FontWeight.Normal);
            g.SetFontSize(point);


            g.MoveTo(x + SHADOW_SPACING, y + SHADOW_SPACING);
            g.Color = Colors.BLACK;
            g.ShowText(text);

            g.MoveTo(x, y);
            g.Color = c;
            g.ShowText(text);

            g.Restore();
        }
Пример #17
0
        private void DrawText(Cairo.Context g, string text, int top, int left)
        {
            g.SetSourceRGB(0, 0, 0);
            g.SetFontSize(cellHeight / 1.5);
            FontExtents fe = g.FontExtents;
            TextExtents te = g.TextExtents(text);

            g.MoveTo(left * cellWidth + (cellWidth - te.Width) / 2, top * cellHeight + (cellHeight + te.YBearing + fe.Height) / 2);
            g.ShowText(text);
        }
Пример #18
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);
        }
Пример #19
0
        protected override void DrawContents(Gdk.Drawable d, Cairo.Context g, int width, int height, bool screenChanged)
        {
            g.SelectFontFace(Text.MONOSPACE_FONT, FontSlant.Normal, FontWeight.Bold);
            g.SetFontSize(24);

            string weapon, armor, acc;


            #region Character Status

            Images.RenderProfile(d, X + xpic, Y + ypic, MenuState.Party.Selected);

            Graphics.Stats.RenderCharacterStatus(d, g, MenuState.Party.Selected, X + x_status, Y + y_status, false);

            #endregion Status

            #region Equipment

            g.Color = Colors.TEXT_TEAL;
            g.MoveTo(X + x7, Y + yi);
            g.ShowText("Wpn.");
            g.MoveTo(X + x7, Y + yj);
            g.ShowText("Arm.");
            g.MoveTo(X + x7, Y + yk);
            g.ShowText("Acc.");
            g.Color = Colors.WHITE;

            weapon = MenuState.Party.Selected.Weapon.Name;
            armor  = MenuState.Party.Selected.Armor.Name;
            acc    = MenuState.Party.Selected.Accessory == null ? String.Empty : MenuState.Party.Selected.Accessory.Name;

            Text.ShadowedText(g, weapon, X + x8, Y + yi);
            Text.ShadowedText(g, armor, X + x8, Y + yj);
            Text.ShadowedText(g, acc, X + x8, Y + yk);

            #endregion Equipment


            if (IsControl)
            {
                Shapes.RenderCursor(g, X + cx, Y + cy - 10);
            }
        }
Пример #20
0
    public void CreatePng()
    {
        const int Width     = 480;
        const int Height    = 160;
        const int CheckSize = 10;
        const int Spacing   = 2;

        // Create an Image-based surface with data stored in ARGB32 format and a context,
        // "using" is used here to ensure that they are Disposed once we are done
        using (ImageSurface surface = new ImageSurface(Format.ARGB32, Width, Height))
            using (Context cr = new Cairo.Context(surface))
            {
                // Start drawing a checkerboard
                int i, j, xcount, ycount;
                xcount = 0;
                i      = Spacing;
                while (i < Width)
                {
                    j      = Spacing;
                    ycount = xcount % 2;             // start with even/odd depending on row
                    while (j < Height)
                    {
                        if (ycount % 2 != 0)
                        {
                            cr.SetSourceRGB(1, 0, 0);
                        }
                        else
                        {
                            cr.SetSourceRGB(1, 1, 1);
                        }
                        // If we're outside the clip, this will do nothing.
                        cr.Rectangle(i, j, CheckSize, CheckSize);
                        cr.Fill();

                        j += CheckSize + Spacing;
                        ++ycount;
                    }
                    i += CheckSize + Spacing;
                    ++xcount;
                }

                // Select a font to draw with
                cr.SelectFontFace("serif", FontSlant.Normal, FontWeight.Bold);
                cr.SetFontSize(64.0);

                // Select a color (blue)
                cr.SetSourceRGB(0, 0, 1);

                // Draw
                cr.MoveTo(20, 100);
                cr.ShowText("Hello, World");

                surface.WriteToPng("test.png");
            }
    }
Пример #21
0
        //intro bottom tips
        public void IntroBottom(Cairo.Context g)
        {
            PointD p1, p2, p3, p4, s1, s2, s3, s4;

            p1 = new PointD(30, 10); p2 = new PointD(420, 10); s1 = new PointD(422, 12); s2 = new PointD(422, 88);
            p3 = new PointD(420, 90); p4 = new PointD(30, 90); s3 = new PointD(28, 88); s4 = new PointD(28, 12);

            g.Color = new Color(0.3, 0.4, 0.6, 0.8);
            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath(); g.LineWidth = 1; g.Stroke();

            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath();

            Cairo.Gradient pat = new Cairo.LinearGradient(80, 20, 80, 80);
            pat.AddColorStop(0, new Cairo.Color(0.3, 0.4, 0.6, 0));
            pat.AddColorStop(1, new Cairo.Color(0.3, 0.4, 0.6, 0.3));
            g.Pattern = pat;
            g.FillPreserve();


            g.Color = new Color(0, 0, 0, 0.8);
            g.SelectFontFace("", FontSlant.Italic, FontWeight.Bold);
            g.SetFontSize(18);
            g.MoveTo(new PointD(88, 28));
            g.ShowText(".");
            g.MoveTo(new PointD(88, 58));
            g.ShowText(".");
            g.SelectFontFace("", FontSlant.Italic, FontWeight.Normal);
            g.SetFontSize(10);
            g.MoveTo(new PointD(98, 30));
            g.ShowText("Use the navigation on the left to choose different categories");
            g.MoveTo(new PointD(98, 42));
            g.ShowText("of your computer and system information to display.");
            g.MoveTo(new PointD(98, 60));
            g.ShowText("When you click on a category in the navigation, the dynamic");
            g.MoveTo(new PointD(98, 72));
            g.ShowText("information is automatically refreshed.");

            g.MoveTo(new PointD(38, 35));
            g.Color = new Color(0.3, 0.4, 0.6, 1);
            g.SelectFontFace("", FontSlant.Normal, FontWeight.Bold);
            g.SetFontSize(18);
            g.ShowText("Tips");

            g.NewPath();

            /*
             * g.Color = new Color (0.3, 0.4, 0.6, 0.8);
             * g.Scale (34, 34);
             * g.LineWidth = 0.06;
             * g.Arc (1.0, 1.0, 0.6, 0, 360);
             * g.Stroke ();*/

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Пример #22
0
    private static void printText(int x, int y, int height, int textHeight, string text, Cairo.Context g, bool centered)
    {
        int moveToLeft = 0;

        if (centered)
        {
            Cairo.TextExtents te;
            te         = g.TextExtents(text);
            moveToLeft = Convert.ToInt32(te.Width / 2);
        }
        g.MoveTo(x - moveToLeft, ((y + y + height) / 2) + textHeight / 2);
        g.ShowText(text);
    }
Пример #23
0
        private void DrawText(string text, int top, int left)
        {
            using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow))
            {
                g.SetSourceRGB(0, 0, 0);
                g.SetFontSize(cellHeight / 1.5);
                FontExtents fe = g.FontExtents;
                TextExtents te = g.TextExtents(text);
                g.MoveTo(left * cellWidth + (cellWidth - te.Width) / 2, top * cellHeight + (cellHeight + te.YBearing + fe.Height) / 2);
                g.ShowText(text);

                g.GetTarget().Dispose();
            }
        }
Пример #24
0
	public void CreatePng ()
	{
		const int Width = 480;
		const int Height = 160;
		const int CheckSize = 10;
		const int Spacing = 2;

		// Create an Image-based surface with data stored in ARGB32 format and a context,
		// "using" is used here to ensure that they are Disposed once we are done
		using (ImageSurface surface = new ImageSurface (Format.ARGB32, Width, Height))
		using (Context cr = new Cairo.Context (surface))
		{
			// Start drawing a checkerboard
			int i, j, xcount, ycount;
			xcount = 0;
			i = Spacing;
			while (i < Width) {
				j = Spacing;
				ycount = xcount % 2; // start with even/odd depending on row
				while (j < Height) {
					if (ycount % 2 != 0)
						cr.SetSourceRGB (1, 0, 0);
					else
						cr.SetSourceRGB (1, 1, 1);
					// If we're outside the clip, this will do nothing.
					cr.Rectangle (i, j, CheckSize, CheckSize);
					cr.Fill ();

					j += CheckSize + Spacing;
					++ycount;
				}
				i += CheckSize + Spacing;
				++xcount;
			}

			// Select a font to draw with
			cr.SelectFontFace ("serif", FontSlant.Normal, FontWeight.Bold);
			cr.SetFontSize (64.0);

			// Select a color (blue)
			cr.SetSourceRGB (0, 0, 1);

			// Draw
			cr.MoveTo (20, 100);
			cr.ShowText ("Hello, World");

			surface.WriteToPng ("test.png");
		}
	}
Пример #25
0
        protected override bool OnDrawn(Context cr)
        {
            cr.Rectangle(0, 0, AllocatedWidth, AllocatedHeight);
            cr.SetSourceColor(BackgroundColor);
            cr.Fill();

            cr.SelectFontFace(FontFamily, FontStyle, Cairo.FontWeight.Normal);
            cr.SetFontSize(FontSize);
            cr.SetSourceColor(Color);

            var te           = cr.TextExtents(Text);
            var charsPerLine = AllocatedWidth / te.Height;
            var lineCount    = Text.Length * charsPerLine;
            var totalHeight  = te.Height * lineCount + PaddingBottom + PaddingTop;

            if (totalHeight < AllocatedHeight)
            {
//        SetSizeRequest();
            }
            if (te.Width > AllocatedWidth)
            {
            }

            cr.MoveTo(PaddingLeft, PaddingTop + FontSize);
            cr.ShowText(Text);
//      var g = new Glyph();

//      Pango.CairoHelper.ShowGlyphString();
            Console.WriteLine(cr.TextExtents(Text).Width);
            Console.WriteLine(cr.TextExtents(Text).Height);

            var fontWidth  = cr.GetScaledFont().FontExtents.MaxXAdvance;
            var fontHeight = cr.GetScaledFont().FontExtents.Height;

//      7.201171875
//      13.5

//      cr.ShowGlyphs();
//      cr.ShowGlyphs();

//      for (var i = 0; i < lineCount; i++)
//      {
//        cr.ShowText(Text.Substring(
//          i * charsPerLine,
//          (i + 1) * charsPerLine));
//      }

            return(true);
        }
Пример #26
0
    public static void Numbers(object sender)
    {
        DrawingArea area = (DrawingArea)sender;

        Cairo.Context cc = Gdk.CairoHelper.Create(area.GdkWindow);

        cc.SetSourceRGB(0, 0, 0);
        cc.LineWidth = 1;
        cc.SetFontSize(15);
        cc.SelectFontFace("Sans", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
        cc.MoveTo(20, 100);
        cc.ShowText(DateTime.Now.ToString());
        cc.StrokePreserve();
        cc.Fill();
    }
Пример #27
0
        private void referencia_mapa(Cairo.Context cr)
        {
            cr.Save();
            cr.SetSourceRGB(0, 0, 0);
            cr.LineWidth = 1;
            cr.Rectangle(2, 2, 250, 100);
            cr.StrokePreserve();
            cr.SetSourceRGB(1, 1, 1);
            cr.Fill();
            cr.Restore();

            double[] color;
            for (int i = 27; i < 227; i++)
            {
                color = calcular_mapa_calor(i, 27, 227);
                cr.Save();
                cr.SetSourceRGBA(color[0], color[1], color[2], 1);
                cr.Rectangle(i, 27, 1, 50);
                cr.Fill();
                cr.Restore();
            }

            cr.Save();
            cr.SetSourceRGB(0, 0, 0);
            cr.SelectFontFace("Arial", FontSlant.Normal, FontWeight.Normal);
            cr.SetFontSize(10);
            cr.MoveTo(7, 92);
            cr.ShowText("Menos visitado");
            cr.MoveTo(192, 92);
            cr.ShowText("Mas visitado");
            cr.MoveTo(12, 12);
            cr.ShowText("Nro. de visitas acumuladas de boids por casillero ");
            cr.MoveTo(12, 24);
            cr.ShowText("por unidad de tiempo");
            cr.Restore();
        }
Пример #28
0
		protected override void onDraw (Cairo.Context gr)
		{
			base.onDraw (gr);

			if (lines == null)
				return;

			gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
			gr.SetFontSize (Font.Size);

			Rectangle r = ClientRectangle;

			Foreground.SetAsSource (gr);

			double y = ClientRectangle.Y;
			double x = ClientRectangle.X;
			Fill errorFill = new SolidColor (Color.Carmine);
			for (int i = 0; i < visibleLines; i++) {
				if (i + Scroll >= Lines.Count)
					break;
				if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) {
					errorFill.SetAsSource (gr);
					gr.Rectangle (x, y, (double)r.Width, fe.Height);
					gr.Fill ();
					Foreground.SetAsSource (gr);
				}
				gr.MoveTo (x, y + fe.Ascent);
				gr.ShowText (lines[i+Scroll] as string);
				y += fe.Height;
				gr.Fill ();
			}

			if (Lines.Count <= visibleLines)
				return;
			Rectangle scrBar = ClientRectangle;
			scrBar.X += ClientRectangle.Width - scrBarWidth;
			scrBar.Width = scrBarWidth;

			new SolidColor (Color.LightGray.AdjustAlpha(0.5)).SetAsSource (gr);
			CairoHelpers.CairoRectangle(gr, scrBar, 2.0);
			gr.Fill ();
			new SolidColor (Color.BlueCrayola.AdjustAlpha(0.7)).SetAsSource (gr);
			scrBar.Y += (int)((double)scrBar.Height * (double)Scroll / (double)Lines.Count);
			scrBar.Height = (int)((double)scrBar.Height * (double)visibleLines / (double)Lines.Count);
			CairoHelpers.CairoRectangle(gr, scrBar, 2.0);
			gr.Fill ();
		}
Пример #29
0
        void HandleHeaderDrawn(object o, DrawnArgs args)
        {
            Cairo.Context cr = args.Cr;
            cr.Save();

            int wd = Allocation.Width - 48;

            Cairo.Color c1 = new Gdk.Color(65, 65, 65).ToCairoColor();
            Cairo.Color c2 = new Gdk.Color(255, 255, 255).ToCairoColor();

            Cairo.Gradient linpat = new LinearGradient(0, 0, wd, Allocation.Height);
            linpat.AddColorStop(0.00, c1);
            linpat.AddColorStop(1.00, c2);

            cr.Rectangle(0, 0, wd, Allocation.Height);
            cr.Source = linpat;
            //cr.PaintWithAlpha(0.5);
            cr.Fill();

            cr.Color = new Color(1, 1, 1);
            cr.SelectFontFace("Arial", FontSlant.Normal, FontWeight.Bold);
            cr.SetFontSize(15.2);

            String txt = String.Empty;

            if (CurrentWidget != null)
            {
                if (CurrentWidget is  DockableWidget)
                {
                    txt = (CurrentWidget as DockableWidget).Title;
                }
            }

            //TextExtents te = cr.TextExtents(txt);


            cr.MoveTo(4, 20);
            cr.ShowText(txt);

            cr.Restore();

            cr = null;
        }
Пример #30
0
    // print Txt Function
    void printtxt(string theResultmessge, object sender)
    {
        DrawingArea area = (DrawingArea)sender;

        Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);


        cr.MoveTo(messegepoint);

        // give a color to line (red in this case)
        cr.Color = new Color(0, 0, 0);
        // this is line type

        cr.ShowText(theResultmessge);

        messegepoint.Y += 15;

        cr.Stroke();
        ((IDisposable)cr).Dispose();
    }
Пример #31
0
        PointD drawButton(Cairo.Context cr, double x, double y, String text, Boolean selected)
        {
            cr.SetSourceRGB(0, 0, 0);
            cr.SelectFontFace("Georgia", FontSlant.Normal, FontWeight.Bold);
            int grow = selected ? 3 : 0;

            cr.SetFontSize(11 + grow);
            TextExtents te = cr.TextExtents(text);

            int spacing = 5;

            DrawRoundedRectangle(cr,
                                 x - grow,
                                 y - grow,
                                 te.Width + grow * 2 + spacing * 2,
                                 TileSize + grow * 2,
                                 3);
            cr.SetSourceRGB(1, 1, 1);
            cr.FillPreserve();
            cr.SetSourceRGB(0, 0, 0);
            cr.LineWidth = 1.2;
            cr.Stroke();

            cr.MoveTo(
                x + spacing - te.XBearing,
                y - te.YBearing + (TileSize - te.Height) / 2);
            cr.ShowText(text);

            if (allOffPosition.X == 0)
            {
                allOffPosition.X      = (int)x;
                allOffPosition.Y      = (int)y;
                allOffPosition.Width  = (int)(te.Width + spacing * 2);
                allOffPosition.Height = TileSize;
            }

            return(new PointD(x + te.Width + spacing * 2 + TileSpacing, 0));
        }
Пример #32
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        gr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Bold);
        gr.SetFontSize(0.35);

        gr.MoveTo(new PointD(0.04, 0.53));
        gr.ShowText("Hello");

        gr.MoveTo(new PointD(0.27, 0.65));
        gr.TextPath("void");
        gr.ColorRgb = new Color(0.5, 0.5, 1, 0);
        gr.FillPreserve();
        gr.ColorRgb  = new Color(0, 0, 0, 0);
        gr.LineWidth = 0.01;
        gr.Stroke();

        gr.Color = new Color(1, 0.2, 0.2, 0.6);
        gr.Arc(0.04, 0.53, 0.02, 0, 2 * M_PI);
        gr.Arc(0.27, 0.65, 0.02, 0, 2 * M_PI);
        gr.Fill();
    }
Пример #33
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);
            }
        }
Пример #34
0
 protected void DrawVerticalReferenceLines(Context g, Gdk.Rectangle area, float xSize, float xTranslation)
 {
     for (int i = 0; i <= NumbersX; i++) {
         float actualLoc = i * (area.Width - numberSpacingXTotal) / NumbersX + NumberSpacingXLeft;
         String text = (xTranslation+i*xSize/NumbersX).ToString ("0.0");
         g.MoveTo (actualLoc - g.TextExtents (text).Width / 2, area.Height - 5);
         g.ShowText (text);
         g.MoveTo (actualLoc, area.Height - NumberSpacingYDown);
         g.LineTo (actualLoc, NumberSpacingYUp);
         g.Stroke ();
     }
 }
Пример #35
0
        private ImageSurface CreateImage(string text, double fontsize, Color wordColor = default(Color), double angle = 0)
        {
            if (text == string.Empty)
                return new ImageSurface(Format.Argb32, 0, 0);
            //			Font font1 = new Font(font,(float)size,FontStyle.Bold);

            g.SetFontSize(fontsize);
            TextExtents te = g.TextExtents(text);

            ImageSurface bm;
            if(angle == 90.0) bm = new ImageSurface(Format.Argb32,(int)Math.Ceiling(te.Height),(int)Math.Ceiling(te.Width));
            else bm = new ImageSurface(Format.Argb32,(int)Math.Ceiling(te.Width),(int)Math.Ceiling(te.Height));
            Context g2 = new Context(bm);
            g2.ScaledFont = g.ScaledFont;
            g2.Color = wordColor;
            /*		g2.Color = new Color(1.0,1.0,1.0);
            g2.Paint();*/
            if(angle == 90.0) {
                g2.MoveTo(-1.0*te.YBearing,te.Width+te.XBearing);
                g2.Rotate(-0.5*Math.PI);
            }
            else g2.MoveTo(-1.0*te.XBearing,-1.0*te.YBearing);
            g2.ShowText(text);
            ((IDisposable)g2).Dispose();
               			return bm;
        }
Пример #36
0
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
            gr.SetFontSize (Font.Size);
            gr.FontOptions = Interface.FontRenderingOptions;
            gr.Antialias = Interface.Antialias;

            rText = new Rectangle(new Size(
                measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height)));
            rText.Width -= 2 * Margin;
            rText.Height -= 2 * Margin;

            widthRatio = 1f;
            heightRatio = 1f;

            Rectangle cb = ClientRectangle;

            rText.X = cb.X;
            rText.Y = cb.Y;

            if (horizontalStretch) {
                widthRatio = (float)cb.Width / (float)rText.Width;
                if (!verticalStretch)
                    heightRatio = widthRatio;
            }

            if (verticalStretch) {
                heightRatio = (float)cb.Height / (float)rText.Height;
                if (!horizontalStretch)
                    widthRatio = heightRatio;
            }

            rText.Width = (int)(widthRatio * (float)rText.Width);
            rText.Height = (int)(heightRatio * (float)rText.Height);

            switch (TextAlignment)
            {
            case Alignment.TopLeft:     //ok
                rText.X = cb.X;
                rText.Y = cb.Y;
                break;
            case Alignment.Top:   //ok
                rText.Y = cb.Y;
                rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                break;
            case Alignment.TopRight:    //ok
                rText.Y = cb.Y;
                rText.X = cb.Right - rText.Width;
                break;
            case Alignment.Left://ok
                rText.X = cb.X;
                rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                break;
            case Alignment.Right://ok
                rText.X = cb.X + cb.Width - rText.Width;
                rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                break;
            case Alignment.Bottom://ok
                rText.X = cb.Width / 2 - rText.Width / 2;
                rText.Y = cb.Height - rText.Height;
                break;
            case Alignment.BottomLeft://ok
                rText.X = cb.X;
                rText.Y = cb.Bottom - rText.Height;
                break;
            case Alignment.BottomRight://ok
                rText.Y = cb.Bottom - rText.Height;
                rText.X = cb.Right - rText.Width;
                break;
            case Alignment.Center://ok
                rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                break;
            }

            gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0);
            fe = gr.FontExtents;

            #region draw text cursor
            if (HasFocus && Selectable)
            {
                if (mouseLocalPos >= 0)
                {
                    computeTextCursor(gr);

                    if (SelectionInProgress)
                    {
                        if (SelBegin < 0){
                            SelBegin = new Point(CurrentColumn, CurrentLine);
                            SelStartCursorPos = textCursorPos;
                            SelRelease = -1;
                        }else{
                            SelRelease = new Point(CurrentColumn, CurrentLine);
                            if (SelRelease == SelBegin)
                                SelRelease = -1;
                            else
                                SelEndCursorPos = textCursorPos;
                        }
                    }
                }else
                    computeTextCursorPosition(gr);

                Foreground.SetAsSource (gr);
                gr.LineWidth = 1.0;
                gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height);
                gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height);
                gr.Stroke();
            }
            #endregion

            //****** debug selection *************
            //			if (SelRelease >= 0) {
            //				gr.Color = Color.Green;
            //				Rectangle R = new Rectangle (
            //					             rText.X + (int)SelEndCursorPos - 2,
            //					             rText.Y + (int)(SelRelease.Y * fe.Height),
            //					             4,
            //					             (int)fe.Height);
            //				gr.Rectangle (R);
            //				gr.Fill ();
            //			}
            //			if (SelBegin >= 0) {
            //				gr.Color = Color.UnmellowYellow;
            //				Rectangle R = new Rectangle (
            //					rText.X + (int)SelStartCursorPos - 2,
            //					rText.Y + (int)(SelBegin.Y * fe.Height),
            //					4,
            //					(int)fe.Height);
            //				gr.Rectangle (R);
            //				gr.Fill ();
            //			}
            //*******************

            for (int i = 0; i < lines.Count; i++) {
                string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize));
                int lineLength = (int)gr.TextExtents (l).XAdvance;
                Rectangle lineRect = new Rectangle (
                    rText.X,
                    rText.Y + (int)Math.Ceiling(i * fe.Height),
                    lineLength,
                    (int)Math.Ceiling(fe.Height));

            //				if (TextAlignment == Alignment.Center ||
            //					TextAlignment == Alignment.Top ||
            //					TextAlignment == Alignment.Bottom)
            //					lineRect.X += (rText.Width - lineLength) / 2;
            //				else if (TextAlignment == Alignment.Right ||
            //					TextAlignment == Alignment.TopRight ||
            //					TextAlignment == Alignment.BottomRight)
            //					lineRect.X += (rText.Width - lineLength);
                if (Selectable) {
                    if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) {
                        gr.SetSourceColor (selBackground);

                        Rectangle selRect = lineRect;

                        int cpStart = (int)SelStartCursorPos,
                        cpEnd = (int)SelEndCursorPos;

                        if (SelBegin.Y > SelRelease.Y) {
                            cpStart = cpEnd;
                            cpEnd = (int)SelStartCursorPos;
                        }

                        if (i == selectionStart.Y) {
                            selRect.Width -= cpStart;
                            selRect.Left += cpStart;
                        }
                        if (i == selectionEnd.Y)
                            selRect.Width -= (lineLength - cpEnd);

                        gr.Rectangle (selRect);
                        gr.Fill ();
                    }
                }

                if (string.IsNullOrWhiteSpace (l))
                    continue;

                Foreground.SetAsSource (gr);
                gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i);
                gr.ShowText (l);
                gr.Fill ();
            }
        }
Пример #37
0
        private void DrawOnHandPieces(Context cr, Position pos, bool BlackPlayer)
        {
            cr.Save();
            cr.Rectangle(0, 0, ON_HAND_AREA_WIDTH, 9 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
            cr.Color = BorderColor;
            cr.FillPreserve();
            cr.Color = new Color(0.6, 0.5, 0.55);
            cr.LineWidth = 3;
            cr.Stroke();

            if (BlackPlayer)
            {
                cr.Translate(0, 8 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
            }

            for (int i = 0; i < (int)PieceType.PIECE_TYPES_COUNT; i++)
            {
                int player_nr = BlackPlayer ? 0 : 1;
                if (pos.OnHandPieces[player_nr, i] != 0)
                {
                    //highlight selected piece
                    if (gi != null && gi.localPlayerMoveState != LocalPlayerMoveState.Wait
                        && gi.localPlayerMoveState != LocalPlayerMoveState.PickSource
                        && gi.GetLocalPlayerMove().OnHandPiece != PieceType.NONE
                        && gi.GetLocalPlayerMove().OnHandPiece == (PieceType)i
                        && !((gi.CurPlayer == gi.BlackPlayer) ^ BlackPlayer))
                    {
                        cr.Rectangle(0, 0, FIELD_SIZE, FIELD_SIZE);
                        cr.Color = new Color(0.8, 0.835, 0.4);
                        cr.Fill();
                    }

                    //draw piece
                    cr.Save();
                    if (!BlackPlayer)
                    {
                        cr.Rotate(180 * Math.PI / 180);
                        cr.Translate(-FIELD_SIZE, -FIELD_SIZE);
                    }
                    cr.Scale(FIELD_SIZE / PieceGraphics[i].Dimensions.Width, FIELD_SIZE / PieceGraphics[i].Dimensions.Width);
                    PieceGraphics[i].RenderCairo(cr);
                    cr.Restore();

                    //draw amount
                    cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
                    cr.SetFontSize(FIELD_SIZE / 3 * 0.9);
                    cr.Color = new Color(0, 0, 0);

                    String amount_str = "x " + pos.OnHandPieces[player_nr, i].ToString();
                    TextExtents extents = cr.TextExtents(amount_str);
                    double x = (FIELD_SIZE);
                    // - (extents.Width/2 + extents.XBearing);
                    double y = (FIELD_SIZE / 2) - (extents.Height / 2 + extents.YBearing);

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

                    double offset = BlackPlayer ? -FIELD_SIZE - PADDING : FIELD_SIZE + PADDING;
                    cr.Translate(0, offset);
                }
            }
            cr.Restore();
        }
Пример #38
0
		public bool OnExpose (Context ctx, Gdk.Rectangle allocation)
		{
			if (frames == 0)
				start = DateTime.UtcNow;
			
			frames ++;
			TimeSpan elapsed = DateTime.UtcNow - start;
			double fraction = elapsed.Ticks / (double) duration.Ticks; 
			double opacity = Math.Sin (Math.Min (fraction, 1.0) * Math.PI * 0.5);
			
			ctx.Operator = Operator.Source;
			
			SurfacePattern p = new SurfacePattern (begin_buffer.Surface);
			ctx.Matrix = begin_buffer.Fill (allocation);
			p.Filter = Filter.Fast;
			ctx.Source = p;
			ctx.Paint ();
			
			ctx.Operator = Operator.Over;
			ctx.Matrix = end_buffer.Fill (allocation);
			SurfacePattern sur = new SurfacePattern (end_buffer.Surface);
			Pattern black = new SolidPattern (new Cairo.Color (0.0, 0.0, 0.0, opacity));
			//ctx.Source = black;
			//ctx.Fill ();
			sur.Filter = Filter.Fast;
			ctx.Source = sur;
			ctx.Mask (black);
			//ctx.Paint ();
			
			ctx.Matrix = new Matrix ();
			
			ctx.MoveTo (allocation.Width / 2.0, allocation.Height / 2.0);
			ctx.Source = new SolidPattern (1.0, 0, 0);	
			#if debug
			ctx.ShowText (String.Format ("{0} {1} {2} {3} {4} {5} {6} {7}", 
						     frames,
						     sur.Status,
						     p.Status,
						     opacity, fraction, elapsed, start, DateTime.UtcNow));
			#endif
			sur.Destroy ();
			p.Destroy ();
			return fraction < 1.0;
		}
 private ImageSurface GenerateStub()
 {
     ImageSurface stub = new ImageSurface (Format.ARGB32, 600, 300);
     Context cairo  = new Context(stub);
     cairo.IdentityMatrix ();
     cairo.Scale (600,300);
     cairo.Rectangle (0, 0, 1, 1);
     cairo.SetSourceRGB (1,1,1);
     cairo.Fill ();
     cairo.MoveTo (0.14, 0.5);
     cairo.SetFontSize (0.08);
     cairo.SetSourceRGB (0, 0, 0);
     cairo.ShowText ("Загрузите подложку");
     cairo.Dispose ();
     return stub;
 }
        static BitmapContent CreateBitmapContent(
			double bitmapWidth, 
			double bitmapHeight, 
			string fontName, 
			FontSlant fontSlant, 
			FontWeight fontWeight, 
			double fontSize, 
			List<CharacterData> cds, 
			ParsedPath pngFile)
        {
            using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)bitmapWidth, (int)bitmapHeight))
            {
                using (Context g = new Context(surface))
                {
                    SetupContext(g, fontName, fontSlant, fontWeight, fontSize);
                    double x = 0;

                    for (int i = 0; i < cds.Count; i++)
                    {
                        CharacterData cd = cds[i];

                        if (cd.Location.Width == 0)
                            continue;

                        g.MoveTo(x + cd.Bearing.X, cd.Bearing.Y);
                        g.ShowText(cd.Character);
            #if DEBUG
                        g.Save();
                        g.Color = new Color(1.0, 0, 0, 0.5);
                        g.Antialias = Antialias.None;
                        g.LineWidth = 1;
                        g.MoveTo(x + 0.5, 0.5);
                        g.LineTo(x + cd.Location.Width - 0.5, 0);
                        g.LineTo(x + cd.Location.Width - 0.5, cd.Location.Height - 0.5);
                        g.LineTo(x + 0.5, cd.Location.Height - 0.5);
                        g.LineTo(x + 0.5, 0.5);
                        g.Stroke();
                        g.Restore();
            #endif
                        x += cd.Location.Width;
                    }

                    g.Restore();
                }

                if (pngFile != null)
                    surface.WriteToPng(pngFile);

                return new BitmapContent(SurfaceFormat.Color, surface.Width, surface.Height, surface.Data);
            }
        }
Пример #41
0
 protected override bool OnExposed(Context cr, Rectangle area)
 {
     cr.Save();
     if(!base.OnExposed(cr, area))
     {
         cr.Color = new Color(1.0, 0.0, 1.0);
         cr.Rectangle(new Rectangle(2.0, 2.0, Allocation.Width - 4.0, Allocation.Height - 4.0));
         cr.LineWidth = 4.0;
         cr.LineJoin = LineJoin.Round;
         cr.Stroke();
         cr.SetFontSize(20.0);
         cr.SelectFontFace("Librarian", FontSlant.Normal, FontWeight.Bold);
         cr.Translate(0.0, Allocation.Height / 2);
         cr.ShowText(type.ToString());
         cr.Restore();
         return true;
     }
     cr.Restore();
     return true;
 }
Пример #42
0
 public virtual void Paint(Context ctx)
 {
     PointD size = this.MeasureSize (ctx);
     PaintContour (ctx,size);
     KnownColors.SetFontFacePieceName(ctx);
     TextExtents te = ctx.TextExtents(this.Name), ten;
     double y0 = 0.5d*(size.Y-te.Width);
     ctx.MoveTo(0.5d*Margin,y0);
     ctx.Save();
     ctx.Rotate(0.5d*Math.PI);
     ctx.ShowText(this.Name);
     ctx.Restore();
     double x0 = Margin+te.Height;
     KnownColors.SetFontFaceNormal(ctx);
     te = ctx.TextExtents(OptionalString);
     y0 = 2.0d*Margin;
     int index = 0x00;
     PointD siz;
     foreach(IPuzzlePiece ipp in this.arguments) {
         ctx.Save();
         ctx.Translate(x0,Margin);
         if(ipp == null) {
             siz = new PointD(MinimumWidth,size.Y-4.0d*Margin);
             ctx.Rectangle(Margin,Margin,siz.X,siz.Y);
             ctx.Pattern = KnownColors.ConstructionPattern;
             ctx.FillPreserve();
         }
         else {
             siz = ipp.MeasureSize(ctx);
         }
         ctx.Rectangle(0.0d,0.0d,siz.X+2.0d*Margin,siz.Y+2.0d*Margin);
         ctx.Color = KnownColors.Black;
         ctx.StrokePreserve();
         if(ipp == null) {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Translate(Margin,Margin);
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(MinimumWidth,0.0d);
             ctx.RelLineTo(0.0d,5.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowDownPattern;
             ctx.Fill();
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(0.0d,siz.Y);
             ctx.RelLineTo(5.0d,0.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowRightPattern;
             ctx.Fill();
         }
         else {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Color = KnownColors.Black;
             ctx.Translate(Margin,Margin);
             ipp.Paint(ctx);
         }
         ctx.Restore();
         subpieces[index] = new Rectangle(x0+Margin,2.0d*Margin,siz.X,siz.Y);
         x0 += siz.X+3.0d*Margin;
         if(index >= NumberOfArguments-NumberOfOptionalArguments) {
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+te.Width),siz.Y+3.0d*Margin-2.0d);
             ctx.ShowText(OptionalString);
         }
         if(this.ArgumentNames != null && index < arguments.Length) {
             ten = ctx.TextExtents(this.ArgumentNames[index]);
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+ten.Width),-te.YBearing+Margin+2.0d);
             ctx.ShowText(this.ArgumentNames[index]);
         }
         index++;
     }
 }
 private void paintNodes(Context ctx, int w, int h, IEnumerable<Node> nodes)
 {
     ctx.LineWidth = 2.0d;
     foreach(Node node in nodes) {
         PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
         ctx.Arc(abs.X, abs.Y, AlgorithmRadius, 0.0d, 2.0d*Math.PI);
         ctx.ClosePath();
         ctx.NewSubPath();
         ctx.Arc(abs.X, abs.Y, AlgorithmRadius-BlueprintStyle.Thickness, 0.0d, 2.0d*Math.PI);
         ctx.ClosePath();
         ctx.NewSubPath();
     }
     ctx.Pattern = BlueprintStyle.FillPattern;
     ctx.FillPreserve();
     ctx.Color = BlueprintStyle.HardWhite;
     ctx.Stroke();
     double r_2, dx, dy;
     this.nodeCenters.Clear();
     foreach(Node node in nodes) {
         PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
         this.nodeCenters.Add(abs);
         TextExtents te = ctx.TextExtents(node.Item1);
         r_2 = (AlgorithmRadius-BlueprintStyle.Thickness)/Math.Sqrt(te.Width*te.Width+te.Height*te.Height);
         ctx.Save();
         ctx.MoveTo(abs.X-r_2*te.Width, abs.Y+r_2*te.Height);
         ctx.Scale(2.0d*r_2, 2.0d*r_2);
         ctx.ShowText(node.Item1);
         ctx.Restore();
     }
 }
 private void PaintEdges(Context ctx, int w, int h, IEnumerable<NotatedEdge> edges)
 {
     PointD pc, pd;
     foreach(NotatedEdge edge in edges) {
         PointD pa = new PointD(w*edge.Item1.X, h*edge.Item1.Y);
         PointD pb = new PointD(w*edge.Item2.X, h*edge.Item2.Y);
         Utils.CutTowardsCenter(pa, pb, AlgorithmRadius, out pc, out pd);
         double dxr = pc.X-pd.X;
         double dyr = pc.Y-pd.Y;
         double r = Math.Sqrt(dxr*dxr+dyr*dyr);
         ctx.MoveTo(pc);
         ctx.LineTo(pd);
         ctx.Stroke();
         ctx.Save();
         ctx.Translate(pc.X, pc.Y);
         ctx.Rotate(Math.Atan2(pb.Y-pa.Y, pb.X-pa.X));
         double v = 0.0d;//double v = tm/e.Delay;
         foreach(EdgeNotation msg in edge.Item3) {
             TextExtents te = ctx.TextExtents(msg.Item2);
             ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
             ctx.ShowText(msg.Item2);
         }
         ctx.Restore();
         ctx.Save();
         ctx.Translate(pd.X, pd.Y);
         ctx.Rotate(Math.Atan2(pa.Y-pb.Y, pa.X-pb.X));
         foreach(EdgeNotation msg in edge.Item4) {
             TextExtents te = ctx.TextExtents(msg.Item2);
             ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
             ctx.ShowText(msg.Item2);
         }
         ctx.Restore();
     }
 }
Пример #45
0
 public void Text(Context context,  string txt, HorizontalTextAlignment horizontal = HorizontalTextAlignment.Center, VerticalTextAlignment vertical = VerticalTextAlignment.Middle)
 {
     context.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Normal);
     //context.SetFontSize (_surface.Height / 10);
     context.SetFontSize (14);
     var extends = context.TextExtents (txt);
     double x, y;
     x = -(((double)horizontal) / 2 * extends.Width + extends.XBearing);
     y = -(((double)vertical) / 2 * extends.Height + extends.YBearing);
     context.RelMoveTo (x, y);
     context.ShowText (txt);
 }
Пример #46
0
 protected override bool OnExposed(Context cr, Rectangle area)
 {
     cr.Save();
     if(!base.OnExposed(cr, area))
     {
         cr.Color = new Color(1.0, 0.0, 0.0);
         cr.SetFontSize(100.0);
         cr.SelectFontFace("Librarian", FontSlant.Normal, FontWeight.Bold);
         cr.ShowText(role.ToString());
         cr.Restore();
         return true;
     }
     cr.Restore();
     return true;
 }
Пример #47
0
    private void DrawGraphGrid()
    {
        using (Context GridGraphCtx = new Context(ScaleGraph))
        {
            GridGraphCtx.Antialias = Antialias.Subpixel;
            GridGraphCtx.Color = new Cairo.Color(0, 0, 0);
            GridGraphCtx.LineWidth = 0.6;
            GridGraphCtx.SelectFontFace("Purisa", FontSlant.Normal, FontWeight.Normal);
            GridGraphCtx.SetFontSize(10);

            ClearGraph(GridGraphCtx);

            GCurves.GCurve tmp;
            AllCurves.Curves.TryGetValue(CurveSelectBox.ActiveText, out tmp);

            if (tmp != null)
            {
                double min = tmp.min;
                double max = tmp.max;
                int width = GraphArea.Allocation.Width;
                int height = GraphArea.Allocation.Height;

                if (AllFiles.Count > 1)
                {
                    double Xp = GetGraphXY(new PointF(AllFiles.Count - 1, 0)).X;
                    double Xm = GetGraphXY(new PointF(0, 0)).X;

                    //drawing the X scale lines
                    double f = (Xp - Xm) / 10;

                    for (int i = 0; i <= 10; i++)
                    {
                        GridGraphCtx.MoveTo((int)(GrBorLeft + (f * i)) + 0.5, (int)(height - GrBor + 8) + 0.5);
                        GridGraphCtx.LineTo((int)(GrBorLeft + (f * i)) + 0.5, GrBor + 0.5);
                    }

                    //X-axis label
                    GridGraphCtx.MoveTo(GrBor + 12, height - 5);
                    GridGraphCtx.ShowText("1");
                    if (AllFiles.Count >= 10) { GridGraphCtx.MoveTo(Xp - 10, height - 5); }
                    else if (AllFiles.Count >= 100) { GridGraphCtx.MoveTo(Xp - 25, height - 5); }
                    else if (AllFiles.Count >= 1000) { GridGraphCtx.MoveTo(Xp - 40, height - 5); }
                    else if (AllFiles.Count >= 10000) { GridGraphCtx.MoveTo(Xp - 55, height - 5); }
                    else { GridGraphCtx.MoveTo(Xp - 5, height - 5); }
                    GridGraphCtx.ShowText(AllFiles.Count.ToString());

                    //drawing the Y scale lines
                    for (int i = 0; i <= 10; i++)
                    {
                        GridGraphCtx.MoveTo((int)(GrBorLeft - 8) + 0.5, (int)(height - GrBor - (((height - (2 * GrBor)) / 10) * i)) + 0.5);
                        GridGraphCtx.LineTo((int)Xp + 0.5, (int)(height - GrBor - (((height - (2 * GrBor)) / 10) * i)) + 0.5);
                    }

                    //Y-axis label
                    GridGraphCtx.MoveTo(3, height - GrBor);
                    GridGraphCtx.ShowText(min.ToString("N2"));
                    GridGraphCtx.MoveTo(3, GrBor);
                    GridGraphCtx.ShowText(max.ToString("N2"));
                    GridGraphCtx.Stroke();
                }
            }
        }
    }
Пример #48
0
        private void DrawBoard(Context cr, Position pos)
        {
            Console.WriteLine("ShogibanSVG.DrawBoard");
            #region board border
            //Top
            cr.Rectangle(0, 0, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
            //Left
            cr.Rectangle(0, 0, FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE);
            //Bottom
            cr.Rectangle(0, Game.BOARD_SIZE * FIELD_SIZE + FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
            //Right
            cr.Rectangle(9*FIELD_SIZE + FIELD_NAMING_SIZE, 0, FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE);
            cr.Color = BorderColor;
            cr.Fill();
            #endregion

            #region field namings
            cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
            cr.SetFontSize(FIELD_NAMING_SIZE * 0.9);
            cr.Color = new Color(0, 0, 0);

            for (int i = 0; i < VerticalNamings.Length; i++)
            {
                TextExtents extents = cr.TextExtents(VerticalNamings[i].ToString());
                double x = (FIELD_NAMING_SIZE/2) - (extents.Width/2 + extents.XBearing);
                double y = (FIELD_NAMING_SIZE + i*FIELD_SIZE + FIELD_SIZE/2) - (extents.Height/2 + extents.YBearing);

                cr.MoveTo(x, y);
                cr.ShowText(VerticalNamings[i].ToString());
                cr.MoveTo(x + 9*FIELD_SIZE + FIELD_NAMING_SIZE, y);
                cr.ShowText(VerticalNamings[i].ToString());
            }
            for (int i = 0; i < HorizontalNamings.Length; i++)
            {
                TextExtents extents = cr.TextExtents(HorizontalNamings[i].ToString());
                double x = (FIELD_NAMING_SIZE + i*FIELD_SIZE + FIELD_SIZE/2) - (extents.Width/2 + extents.XBearing);
                double y = (FIELD_NAMING_SIZE/2) - (extents.Height/2 + extents.YBearing);

                cr.MoveTo(x, y);
                cr.ShowText(HorizontalNamings[Game.BOARD_SIZE-i-1].ToString());
                cr.MoveTo(x, y + 9*FIELD_SIZE + FIELD_NAMING_SIZE);
                cr.ShowText(HorizontalNamings[Game.BOARD_SIZE-i-1].ToString());
            }
            #endregion

            #region board playfield
            //background
            cr.Translate(FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
            cr.Rectangle(0, 0, Game.BOARD_SIZE * FIELD_SIZE, Game.BOARD_SIZE * FIELD_SIZE);
            cr.Color = BoardColor;
            cr.Fill();

            if (gi != null)
            {
                //highlight selected piece field
                if (gi.localPlayerMoveState != LocalPlayerMoveState.Wait
                    && gi.localPlayerMoveState != LocalPlayerMoveState.PickSource
                    && CurMoveNr < 0)
                {
                    if (gi.GetLocalPlayerMove().OnHandPiece == PieceType.NONE)
                    {
                        cr.Rectangle((Game.BOARD_SIZE - gi.GetLocalPlayerMove().From.x - 1) * FIELD_SIZE, gi.GetLocalPlayerMove().From.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                        cr.Color = SelectedFieldColor;
                        cr.Fill();
                    }
                }

                //highlight last move
                if (gi.Moves.Count > 0 && CurMoveNr != 0)
                {
                    Move move;
                    if (CurMoveNr < 0)
                        move = gi.Moves[gi.Moves.Count-1].move;
                    else
                        move = gi.Moves[CurMoveNr - 1].move;

                    if (move.OnHandPiece == PieceType.NONE)
                    {
                        cr.Rectangle((Game.BOARD_SIZE - move.From.x - 1) * FIELD_SIZE, move.From.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                    }
                    cr.Rectangle((Game.BOARD_SIZE - move.To.x - 1) * FIELD_SIZE, move.To.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                    cr.Color = LastMoveFieldColor;
                    cr.Fill();
                }

                //highlight possible moves
                if (gi.localPlayerMoveState == LocalPlayerMoveState.PickDestination && CurMoveNr < 0)
                {
                    ValidMoves Moves;
                    Move LocalPlayerMove = gi.GetLocalPlayerMove();
                    if (LocalPlayerMove.OnHandPiece == PieceType.NONE)
                    {
                        Moves = pos.GetValidBoardMoves(LocalPlayerMove.From);
                    }
                    else
                    {
                        Moves = pos.GetValidOnHandMoves(LocalPlayerMove.OnHandPiece, gi.CurPlayer == gi.BlackPlayer);
                    }

                    foreach (BoardField Field in Moves)
                    {
                        cr.Rectangle((Game.BOARD_SIZE - Field.x - 1) * FIELD_SIZE, Field.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                        cr.Color = PossibleMoveColor;
                        cr.Fill();
                    }
                }
            }

            //dividing lines
            for (int i = 0; i <= Game.BOARD_SIZE; i++)
            {
                cr.MoveTo(0, i * FIELD_SIZE);
                cr.LineTo(Game.BOARD_SIZE * FIELD_SIZE, i * FIELD_SIZE);
            }
            for (int i = 0; i <= Game.BOARD_SIZE; i++)
            {
                cr.MoveTo(i * FIELD_SIZE, 0);
                cr.LineTo(i * FIELD_SIZE, Game.BOARD_SIZE * FIELD_SIZE);
            }
            cr.Color = new Color(0, 0, 0);
            cr.LineWidth = 2.5;
            cr.LineCap = LineCap.Round;
            cr.Stroke();
            #endregion

            DrawPieces(cr, pos);

            //draw promotion choice area
            if (gi != null && gi.localPlayerMoveState == LocalPlayerMoveState.PickPromotion && CurMoveNr < 0)
            {
                double PromotionChoiceAreaStartX = (Game.BOARD_SIZE - gi.GetLocalPlayerMove().To.x - 1) * FIELD_SIZE - FIELD_SIZE / 2;
                double PromotionChoiceAreaStartY = gi.GetLocalPlayerMove().To.y * FIELD_SIZE;

                cr.Save();
                //draw boarder
                cr.Translate(PromotionChoiceAreaStartX - PADDING,
                    PromotionChoiceAreaStartY - PADDING);
                cr.Rectangle(0, 0, 2 * FIELD_SIZE + 2 * PADDING, FIELD_SIZE + 2 * PADDING);
                cr.Color = new Color(0, 0, 0);
                cr.Fill();

                cr.Translate(PADDING, PADDING);
                cr.Rectangle(0, 0, 2 * FIELD_SIZE, FIELD_SIZE);
                cr.Color = BoardColor;
                cr.Fill();

                Move LocalPlayerMove = gi.GetLocalPlayerMove();
                FieldInfo From = pos.Board[LocalPlayerMove.From.x, LocalPlayerMove.From.y];
                DrawPiece(cr, From.Piece, From.Direction, 0, 0);
                DrawPiece(cr, From.Piece.GetPromotedPiece(), From.Direction, FIELD_SIZE, 0);

                cr.Restore();
            }
        }
Пример #49
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);
 }
Пример #50
0
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
            gr.SetFontSize (Font.Size);
            gr.FontOptions = Interface.FontRenderingOptions;
            gr.Antialias = Interface.Antialias;

            rText = new Rectangle (new Size (
                measureRawSize (LayoutingType.Width), measureRawSize (LayoutingType.Height)));
            rText.Width -= 2 * Margin;
            rText.Height -= 2 * Margin;

            widthRatio = 1f;
            heightRatio = 1f;

            Rectangle cb = ClientRectangle;

            //ignore text alignment if size to content = true
            //or if text size is larger than client bounds
            if (Width < 0 || Height < 0 || rText.Width > cb.Width) {
                rText.X = cb.X;
                rText.Y = cb.Y;
            } else {
                if (horizontalStretch) {
                    widthRatio = (float)cb.Width / rText.Width;
                    if (!verticalStretch)
                        heightRatio = widthRatio;
                }
                if (verticalStretch) {
                    heightRatio = (float)cb.Height / rText.Height;
                    if (!horizontalStretch)
                        widthRatio = heightRatio;
                }

                rText.Width = (int)(widthRatio * cb.Width);
                rText.Height = (int)(heightRatio * cb.Height);

                switch (TextAlignment) {
                case Alignment.TopLeft:     //ok
                    rText.X = cb.X;
                    rText.Y = cb.Y;
                    break;
                case Alignment.Top:   //ok
                    rText.Y = cb.Y;
                    rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                    break;
                case Alignment.TopRight:    //ok
                    rText.Y = cb.Y;
                    rText.X = cb.Right - rText.Width;
                    break;
                case Alignment.Left://ok
                    rText.X = cb.X;
                    rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                    break;
                case Alignment.Right://ok
                    rText.X = cb.X + cb.Width - rText.Width;
                    rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                    break;
                case Alignment.Bottom://ok
                    rText.X = cb.Width / 2 - rText.Width / 2;
                    rText.Y = cb.Height - rText.Height;
                    break;
                case Alignment.BottomLeft://ok
                    rText.X = cb.X;
                    rText.Y = cb.Bottom - rText.Height;
                    break;
                case Alignment.BottomRight://ok
                    rText.Y = cb.Bottom - rText.Height;
                    rText.X = cb.Right - rText.Width;
                    break;
                case Alignment.Center://ok
                    rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                    rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                    break;
                }
            }

            gr.FontMatrix = new Matrix (widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0);

            int curLineCount = 0;
            for (int i = 0; i < lines.Count; i++) {
                string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize));
                List<string> wl = new List<string> ();
                int lineLength = (int)gr.TextExtents (l).XAdvance;

                if (wordWrap && lineLength > cb.Width) {
                    string tmpLine = "";
                    int curChar = 0;
                    while (curChar < l.Length) {
                        tmpLine += l [curChar];
                        if ((int)gr.TextExtents (tmpLine).XAdvance > cb.Width) {
                            tmpLine = tmpLine.Remove (tmpLine.Length - 1);
                            wl.Add (tmpLine);
                            tmpLine = "";
                            continue;
                        }
                        curChar++;
                    }
                    wl.Add (tmpLine);
                } else
                    wl.Add (l);

                foreach (string ll in wl) {
                    lineLength = (int)gr.TextExtents (ll).XAdvance;

                    if (string.IsNullOrWhiteSpace (ll)) {
                        curLineCount++;
                        continue;
                    }

                    Foreground.SetAsSource (gr);
                    gr.MoveTo (rText.X, rText.Y + fe.Ascent + fe.Height * curLineCount);

                    gr.ShowText (ll);
                    gr.Fill ();

                    curLineCount++;
                }
            }
        }
Пример #51
0
 protected void DrawRightsideHorisontalNumbers(Context g, Gdk.Rectangle area, float ySize)
 {
     for (int i = 0; i <= NumbersY; i++) {
         float actualLoc = (1 - i/NumbersY) * (area.Height - numberSpacingYTotal) + NumberSpacingYUp;
         String text = (i*ySize/NumbersY).ToString ("0.0");
         TextExtents size = g.TextExtents (text);
         g.MoveTo (area.Width-NumberSpacingXRight, actualLoc + size.Height / 2);
         g.ShowText (text);
     }
 }
Пример #52
0
		public void text(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Bold);
			cr.SetFontSize(0.35);

			cr.MoveTo(0.04, 0.53);
			cr.ShowText("Hello");

			cr.MoveTo(0.27, 0.65);
			cr.TextPath("void");
			cr.Save();
			cr.Color = new Color (0.5,0.5,1);
			cr.Fill();
			cr.Restore();
			cr.LineWidth = 0.01;
			cr.Stroke();

			// draw helping lines
			cr.Color = new Color (1.0, 0.2, 0.2, 0.6);
			cr.Arc(0.04, 0.53, 0.02, 0, 2*Math.PI);
			cr.Arc(0.27, 0.65, 0.02, 0, 2*Math.PI);
			cr.Fill();
		}
Пример #53
0
        protected override bool OnExposed(Context cr, Rectangle area)
        {
            cr.Save();
            if(!base.OnExposed(cr, area))
            {
                cr.Color = new Color(1.0, 0.0, 0.0);
                cr.SetFontSize(100.0);
                cr.SelectFontFace("Librarian", FontSlant.Normal, FontWeight.Bold);
                cr.ShowText(type.ToString());
                cr.Restore();
                return true;
            }
            cr.Restore();

            if(type != CardType.Unknown)
            {
                ApplyConstriction(cr);
                double ratio = Allocation.Height / Card.DefaultHeight;
                cr.Scale(ratio, ratio);
                cr.Translate(RankOffsetX, RankOffsetY);
                Pango.CairoHelper.ShowLayout(cr, layout);
                cr.LineWidth = 2.0;
                cr.Color = new Color(1, 1, 1);
                cr.LineCap = LineCap.Butt;
                cr.LineJoin = LineJoin.Round;
                Pango.CairoHelper.LayoutPath(cr, layout);
                cr.Stroke();
            }
            return true;
        }
Пример #54
0
		public void text_align_center(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

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

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

			// draw helping lines
			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.Arc(x, y, 0.05, 0, 2*Math.PI);
			cr.Fill();
			cr.MoveTo(0.5, 0);
			cr.RelLineTo(0, 1);
			cr.MoveTo(0, 0.5);
			cr.RelLineTo(1, 0);
			cr.Stroke();
		}
Пример #55
0
		public static void Draw (Context grw, TextElement text)
		{
			double dY = 0;

			if (text.Foregraund != null) {
				grw.SetSourceRGB (
					text.Foregraund.Red, 
					text.Foregraund.Green, 
					text.Foregraund.Blue);
			}

			grw.SelectFontFace (
				text.FontFamily, 
				FontSlant.Normal, 
				(FontWeight)text.Weight);

			grw.SetFontSize (text.ScaledFontSize);
			var te = grw.TextExtents (text.Text);

			double dX = 0;
			if (text.Align != null) {
				switch (text.Align.ToLowerInvariant()) {
				case AlignType.Center:
					dX = 0.5 * te.Width;

					break;
				case AlignType.Right:
					dX = te.Width;

					break;
				case AlignType.Left:
					dX = 0;
					break;
				default:					
					return;
				}
			}

			if (text.VAlign != null) {
				switch (text.VAlign.ToLowerInvariant ()) {
				case VAlignType.Top:
					dY = te.YBearing;
					break;
				case VAlignType.Center:
					dY = 0.5 * te.YBearing;
					break;
				case VAlignType.Bottom:
					dY = 0;
					break;
				default:					
					return;
				}
			}

			grw.MoveTo (
				text.Start.GeometryX - dX, 
				text.Start.GeometryY - dY);

			grw.ShowText (text.FormattedText);

			grw.Stroke ();
		}
Пример #56
0
		public void text_extents(Context cr, int width, int height)
		{
			double x=0.1;
			double y=0.6;
			string utf8 = "cairo";
			Normalize (cr, width, height);

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

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

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

			// draw helping lines
			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.Arc(x, y, 0.05, 0, 2*Math.PI);
			cr.Fill();
			cr.MoveTo(x,y);
			cr.RelLineTo(0, -extents.Height);
			cr.RelLineTo(extents.Width, 0);
			cr.RelLineTo(extents.XBearing, -extents.YBearing);
			cr.Stroke();
		}
Пример #57
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);
        }
Пример #58
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 ());
 }
Пример #59
0
        protected TextExtents RenderText(Context context, string text, double x, double y, Color colour)
        {
            TextExtents extents = context.TextExtents(text);

            context.Save();

            context.Color = colour;

            context.MoveTo(x, y + extents.Height); // we add the height as it seems to be top left, not bottom left
            context.ShowText(text);

            context.Restore();

            return extents;
        }
Пример #60
0
 protected void DrawHorizontalReferenceLines(Context g, Gdk.Rectangle area, float ySize)
 {
     for (int i = 0; i <= NumbersY; i++) {
         float actualLoc = (1 - i/NumbersY) * (area.Height - numberSpacingYTotal) + NumberSpacingYUp;
         String text = (i*ySize/NumbersY).ToString ("0.0");
         TextExtents size = g.TextExtents (text);
         g.MoveTo (Math.Max(NumberSpacingXLeft-size.Width, 0), actualLoc + size.Height / 2);
         g.ShowText (text);
         g.MoveTo (NumberSpacingXLeft, actualLoc);
         g.LineTo (area.Width-NumberSpacingXRight, actualLoc);
         g.Stroke ();
     }
 }