示例#1
0
        public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
        {
            double x = X, y = Y;

            this.rtl = rtl;

            #if DESIGN_MODE
            gr.Save ();
            gr.Color = new Cairo.Color (0, 0, 1);
            gr.Rectangle (X, Y, Width, Height);
            gr.Stroke ();
            gr.Restore ();

            ValidateDimensions ();
            #endif

            //
            // Coordinates are stored right to left
            //
            if (rtl == false) {
                for (int i = 0; i < children.Count; i++)
                {
                    gr.Save ();
                    gr.Translate (x, y);

                    children[i].Draw (gr, area_width, area_height, rtl);
                    gr.Restore ();
                    x += children[i].Width;
                }
            } else {
                x += Width;
                for (int i = 0; i < children.Count; i++)
                {
                    x -= children[i].Width;
                    gr.Save ();
                    gr.Translate (x, y);
                    children[i].Draw (gr, area_width, area_height, rtl);
                    gr.Restore ();
                }
            }
        }
        public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
        {
            double x = X, y = Y;

            this.rtl = rtl;

            #if DESIGN_MODE
            gr.Save ();
            gr.Color = new Cairo.Color (0, 0, 1);
            gr.Rectangle (X, Y, Width, Height);
            gr.Stroke ();
            gr.Restore ();

            double width = 0;

            foreach (Widget child in children)
            {
                width += child.Width;

                if (Height < child.Height)
                    throw new InvalidOperationException (String.Format ("Container height too small {0} < {1}", Height, child.Height));
            }

            if (Width < width)
                throw new InvalidOperationException (String.Format ("Container witdh too small {0} < {1}", Width, width));
            #endif
            //
            // Coordinates are stored right to left
            //
            if (rtl == false) {
                for (int i = 0; i < children.Count; i++)
                {
                    gr.Save ();
                    gr.Translate (x, y);

                    children[i].Draw (gr, area_width, area_height, rtl);
                    gr.Restore ();
                    x += children[i].Width;
                }
            } else {
                x += Width;
                for (int i = 0; i < children.Count; i++)
                {
                    x -= children[i].Width;
                    gr.Save ();
                    gr.Translate (x, y);
                    children[i].Draw (gr, area_width, area_height, rtl);
                    gr.Restore ();
                }
            }
        }
示例#3
0
        public virtual void Draw(CairoContextEx gr, int width, int height, bool rtl)
        {
            InitDraw(gr, width, height, rtl);

            foreach (Toolkit.Container container in containers)
            {
                container.Draw(gr, width, height, rtl);
            }

#if DESIGN_MODE
            gr.Save();
            gr.Color = new Cairo.Color(0, 1, 0);
            gr.Rectangle(0, 0, 1, 1);
            gr.Stroke();
            gr.Restore();
#endif
        }
示例#4
0
        public void DrawTimeBar(CairoContextEx gr, double x, double y, double percentage)
        {
            double       width = 0.04, height = 0.6;
            const double w = 0.003, h = 0.003;

            gr.DrawTextCentered(x + (width / 2), y + height + 0.05, ServiceLocator.Instance.GetService <ITranslations> ().GetString("Time left"));
            gr.Stroke();

            gr.Save();
            gr.Color = new Color(0, 0, 0);
            gr.MoveTo(x, y);
            gr.LineTo(x, y + height);
            gr.LineTo(x + width, y + height);
            gr.LineTo(x + width, y);
            gr.LineTo(x, y);
            gr.Stroke();

            x      += w;
            y      += h;
            width  -= w * 2;
            height -= h * 2;
            y      += height * (100 - percentage) / 100;
            height *= percentage / 100;

            if (gradient == null)
            {
                gradient = new LinearGradient(x, y, x + width, y + height);
                gradient.AddColorStop(0, new Color(1, 0, 0, 1));
                gradient.AddColorStop(1, new Color(0.2, 0, 0, 1));
            }

            gr.Source = gradient;
            gr.MoveTo(x, y);
            gr.LineTo(x, y + height);
            gr.LineTo(x + width, y + height);
            gr.LineTo(x + width, y);
            gr.LineTo(x, y);
            gr.FillPreserve();
            gr.Stroke();
            gr.Restore();
        }
示例#5
0
文件: Memory.cs 项目: GNOME/gbrainy
        public void DrawTimeBar(CairoContextEx gr, double x, double y, double percentage)
        {
            double width = 0.04, height = 0.6;
            const double w = 0.003, h = 0.003;

            gr.DrawTextCentered (x + (width / 2), y + height + 0.05, Translations.GetString ("Time left"));
            gr.Stroke ();

            gr.Save ();
            gr.Color = new Color (0, 0, 0);
            gr.MoveTo (x, y);
            gr.LineTo (x, y + height);
            gr.LineTo (x + width, y + height);
            gr.LineTo (x + width, y);
            gr.LineTo (x, y);
            gr.Stroke ();

            x+= w;
            y+= h;
            width -= w * 2;
            height -= h * 2;
            y += height * (100 - percentage) / 100;
            height *= percentage / 100;

            if (gradient == null) {
                gradient = new LinearGradient (x, y, x + width, y + height);
                gradient.AddColorStop (0, new Color (1, 0, 0, 1));
                gradient.AddColorStop (1, new Color (0.2, 0, 0, 1));
            }

            gr.Source = gradient;
            gr.MoveTo (x, y);
            gr.LineTo (x, y + height);
            gr.LineTo (x + width, y + height);
            gr.LineTo (x + width, y);
            gr.LineTo (x, y);
            gr.FillPreserve ();
            gr.Stroke ();
            gr.Restore ();
        }
示例#6
0
 static void DrawBand(CairoContextEx gr, double x, double y)
 {
     gr.Save ();
     gr.Rectangle (x, y, 1 - 0.06, 0.06);
     gr.Color = new Cairo.Color (0, 0, 0.2, 0.2);
     gr.Fill ();
     gr.Restore ();
 }
示例#7
0
        void DrawAnswer(CairoContextEx gr, double x, double y)
        {
            ColorPalette palette = new ColorPalette (Translations);
            gr.Save ();

            // A full sized square of paper
            gr.Color = palette.Cairo (ColorPalette.Id.Yellow);
            gr.Rectangle (x, y, width, height);
            gr.Fill ();
            gr.Stroke ();

            // 3/4 of the whole size square of paper in the bottom right corner
            gr.Color = palette.Cairo (ColorPalette.Id.Blue);
            double w = 3d/4d * width;
            double h = 3d/4d * height;
            gr.Rectangle (x + (width - w), y + (height - h), w, h);
            gr.Fill ();
            gr.Stroke ();

            // 3/4 square of paper in the top left corner
            gr.Color = palette.Cairo (ColorPalette.Id.Green);
            gr.Rectangle (x, y, 3d/4d * width, 3d/4d * height);
            gr.Fill ();
            gr.Stroke ();

            // 1/4 square of paper in the top left corner
            gr.Color = palette.Cairo (ColorPalette.Id.Red);
            gr.Rectangle (x, y, 1d/4d * width, 1d/4d * height);
            gr.Fill ();
            gr.Stroke ();

            gr.Restore ();
        }
示例#8
0
        private void DrawSquare(CairoContextEx gr, double x, double y, SquareColor []colours, int index)
        {
            gr.Save ();
            for (int column = 0; column < columns; column++) {
                for (int row = 0; row < rows; row++) {

                    // if you want 2 schemes (primary or secundary colors)
                    Color c = palette.Cairo(ColorPalette.Id.First+ color_sheme*3 + (int)colours[index+(columns * row) + column]);
                    gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
                    gr.FillGradient (x + row * rect_w, y + column * rect_h, rect_w, rect_h, c);
                }
            }
            gr.Restore ();
            for (int column = 0; column < columns; column++) {
                for (int row = 0; row < rows; row++) {
                    gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
                    gr.Stroke ();
                }
            }
        }
        void DrawGrid(CairoContextEx cr, double x, double y)
        {
            // Draw Axis
            cr.MoveTo (x, y);
            cr.LineTo (x, y + grid_height);
            cr.LineTo (x + grid_width, y + grid_height);
            cr.Stroke ();

            cr.Save ();
            cr.Color = axis_color;
            cr.LineWidth = 0.001;

            for (double line_y = y; line_y < grid_height + y; line_y += grid_height / 10) {
                cr.MoveTo (x, line_y);
                cr.LineTo (x + grid_width, line_y);
                cr.Stroke ();
            }

            cr.Restore ();

            // Draw score scale
            int pos = 100;
            for (double line_y = y; line_y < grid_height + y; line_y += grid_height / 10) {
                cr.DrawTextAlignedRight (x- 0.01, line_y, String.Format ("{0}", pos));
                pos -= 10;
            }
        }
示例#10
0
        public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
        {
            int element;
            double x = DrawAreaX;
            double y = 0.05, pos_y;

            base.Draw (gr, area_width, area_height, rtl);

            for (int i = 0; i < (Answer.Draw ? question_columns : question_columns - 1); i++)
            {
                element = question_indices [i];
                pos_y = y;
                for (int n = 0; n < figures_column; n++)
                {
                    DrawFigure (gr, x, pos_y, figures [(n * question_columns) + element]);
                    pos_y+= figure_size + space_height;
                }
                x+= figure_size + space_width;
            }

            if (Answer.Draw == false) {
                gr.Save ();
                gr.SetPangoFontSize (figure_size);
                for (int n = 0; n < figures_column; n++) {
                    gr.MoveTo (x, y - 0.02);
                    gr.ShowPangoText ("?");
                    gr.Stroke ();
                    y+= figure_size + space_height;
                }
                gr.SetPangoNormalFontSize ();
                gr.Restore ();
            }

            gr.MoveTo (0.08, 0.45);
            gr.ShowPangoText (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Choose one of the following:"));
            gr.Stroke ();
        }
示例#11
0
        public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
        {
            #if DESIGN_MODE
            gr.Save ();
            gr.Color = new Cairo.Color (1, 0, 0);
            gr.Rectangle (0, 0, Width, Height);
            gr.Stroke ();
            gr.Restore ();
            #endif

            if (hoover == true)
              			{
                double lw = gr.LineWidth;
                double [] dashes = {0.01,  /* ink */
                           0.01,  /* skip */ };

                gr.Save ();

                gr.Color = new Cairo.Color (0.5, 0.5, 0.5, 1);
                gr.SetDash (dashes, 0);

                if (SelectedArea.Width == 0 && SelectedArea.Height == 0)
                    gr.Rectangle (-lw, -lw, Width + lw * 2, Height + lw * 2);
                else
                    gr.Rectangle (SelectedArea.X -lw, SelectedArea.Y -lw, SelectedArea.Width + lw * 2, SelectedArea.Height + lw * 2);

                gr.Stroke ();
                gr.Restore ();
            }

            if (DrawEventHandler == null)
                return;

            DrawEventHandler (this, new DrawEventArgs (gr, Width, Height, rtl, Data));
        }
        static void DrawCircle(CairoContextEx gr, double x, double y, Color[] colors, int color_indice)
        {
            double dg;
            gr.Arc (x, y, radius, 0, 2 * Math.PI);
            gr.Stroke ();

            gr.Save ();
            for (int slice = 0; slice < total_slices; slice++)
            {
                dg = slice * (360 / total_slices);
                DrawSlice (gr, x, y, dg, colors [color_indice]);

                color_indice++;
                if (color_indice >= colors.Length)
                    color_indice = 0;

            }
            gr.Restore ();
        }
示例#13
0
        private void DrawSection(CairoContextEx gr, double x, double y)
        {
            double w =  width / 2, h = height / 2;
            double pos_x = x, pos_y = y;
            for (int i = 0; i < 5; i++) {
                gr.MoveTo (pos_x, pos_y + h / 5);
                gr.LineTo (pos_x + w, pos_y + h / 5);
                gr.Stroke ();
                pos_y += h / 5;
            }

            gr.MoveTo (x + w / 2, y);
            gr.LineTo (x + w / 2, y + h);
            gr.Stroke ();

            gr.Save ();
            gr.Color = new Cairo.Color (0.90, 0.90, 0.90);
            for (int i = 0; i < partial_zones; i++) {
                Fill (gr, x + line_width, line_width + y,
                    (w / 2) - (line_width * 2) , (h / 5) - (line_width * 2));
                Fill (gr, x + (w / 2) + line_width * 2, line_width + y,
                    (w / 2) - (line_width * 4) , (h / 5) - (line_width * 2));
                y += h / 5;
            }
            gr.Restore ();
        }
示例#14
0
 public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
 {
     #if DESIGN_MODE
     gr.Save ();
     gr.Color = new Cairo.Color (0, 0, 1);
     gr.Rectangle (X, Y, Width, Height);
     gr.Stroke ();
     gr.Restore ();
     #endif
     foreach (Widget child in children)
     {
         gr.Save ();
         gr.Translate (child.X, child.Y);
         child.Draw (gr, area_width, area_height, rtl);
         gr.Restore ();
     }
 }
示例#15
0
        void GenerateQuestions(CairoContextEx cr, Game [] games, int columns, int rows)
        {
            int    x, y, page;
            Game   puzzle;
            string str;

            x = y = page = 0;
            for (int i = 0; i < games.Length; i++)
            {
                puzzle = games [i];
                puzzle.Begin();
                page++;

                cr.Save();
                cr.Translate(x, y);
                cr.Rectangle(0, 0, width, height + question_height);
                cr.Clip();

                // Translators: {0} is the game number and {1} the game question or answer
                // The number is used as reference when looking for the game solution in the PDF
                str = String.Format(Translations.GetString("Game #{0}. {1}"), i + 1, puzzle.Question);

                // Draw question
                cr.SetPangoFontSize(12);
                cr.UseMarkup = true;
                cr.DrawStringWithWrapping(margin, 10, str, width - margin);
                cr.Stroke();
                cr.UseMarkup = false;

                // Draw from question_height up height since from 0 to question_height is the question
                // Translate adds always to previous matrix's transformation
                cr.Translate(0, question_height);
                puzzle.DrawPreview(cr, width, height, false);
                if (i == 0)
                {
                    cr.Save();
                    cr.SetPangoFontSize(0.02);
                    cr.MoveTo(0.05, 0.95);
                    cr.ShowPangoText(String.Format(Translations.GetString("Created by gbrainy {0}"), Defines.VERSION));
                    cr.Stroke();
                    cr.Restore();
                }

                x += width + margin;
                if (x > width + margin)
                {
                    x  = 0;
                    y += height + margin + question_height;
                }
                cr.Restore();
                cr.Stroke();

                if (page >= columns * rows)
                {
                    cr.ShowPage();
                    page = x = y = 0;
                }
            }

            if (y > 0)
            {
                cr.ShowPage();
            }
        }
示例#16
0
        void DrawSolution(CairoContextEx cr, int height, double max_width)
        {
            if (UseSolutionArea == false || String.IsNullOrEmpty (Solution) == true)
                return;

            double width_str, height_str, x_text, icon_x, icon_w, icon_h, box_height_scaled;

            cr.Save ();
            cr.LineWidth = 0.001;

            icon_w = icon_size * (cr.Matrix.Xx > cr.Matrix.Yy ? cr.Matrix.Yy / cr.Matrix.Xx : 1);
            icon_h = icon_size * (cr.Matrix.Yy > cr.Matrix.Xx ? cr.Matrix.Xx / cr.Matrix.Yy : 1);

            cr.MeasureString (Solution, max_width - icon_w, true, out width_str, out height_str);

            // In case that the string to show is longer than the space reserved (long translations for example)
            // allow the box to grow taking part of the lower part of the graphic
            box_height_scaled = Math.Max (height_str, (double) solution_high / (double) height);

            // Draw black box
            cr.Color = new Color (0.1, 0.1, 0.1);

            cr.Rectangle (text_margin,
                1 - box_height_scaled - text_margin,
                max_width,
                box_height_scaled);
            cr.Fill ();
            cr.Stroke ();

            // Draw text and icon
            cr.Color = new Color (1, 1, 1);

            if (Direction == Gtk.TextDirection.Rtl)
            {
                x_text = 0;
                icon_x = max_width - icon_w;
            }
            else
            {
                x_text =  icon_w + text_margin;
                icon_x = 0;
            }

            cr.DrawStringWithWrapping (x_text,
                (1 - box_height_scaled - text_margin) + ((box_height_scaled - height_str) / 2),
                Solution, max_width - icon_w);
            cr.Stroke ();

            DrawSolutionIcon (cr, icon_x,
                (1 - box_height_scaled - text_margin) + ((box_height_scaled - icon_h) / 2),
                icon_w, icon_h);
            cr.Restore ();
        }
示例#17
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            if (!IsRealized)
                return false;

            int w, h, total_w, total_h;

            Cairo.Context cc = Gdk.CairoHelper.Create (args.Window);
            CairoContextEx cr = new CairoContextEx (cc.Handle, this);

            args.Window.GetSize (out total_w, out total_h);

            h = total_h - question_high;
            if (UseSolutionArea)
                h -= solution_high;

            w = total_w;

            // We want a square drawing area for the puzzles then the figures are shown as designed.
            // For example, squares are squares. This also makes sure that proportions are kept when resizing
            DrawingSquare = Math.Min (w, h);

            if (DrawingSquare < w)
                OffsetX = (w - DrawingSquare) / 2d;
            else
                OffsetX = 0;

            if (DrawingSquare < h)
                OffsetY = (h - DrawingSquare) / 2d;
            else
                OffsetY = 0;

            OffsetY += question_high;

            // Draw a background taking all the window area
            cr.Save ();
            cr.Scale (total_w, total_h);
            cr.DrawBackground ();

            if (Paused == false) {
                DrawQuestionAndAnswer (cr, total_h);
            } else {
                cr.SetPangoFontSize (0.08);
                cr.DrawTextCentered (0.5, 0.5, Catalog.GetString ("Paused"));
                cr.Stroke ();
            }
            cr.Restore ();

            if (Paused == false) {
                // Draw the game area
                cr.Translate (OffsetX, OffsetY);
                cr.SetPangoNormalFontSize ();
                cr.Color = new Color (1, 1, 1, 0.5);
                Drawable.Draw (cr, DrawingSquare, DrawingSquare, Direction == Gtk.TextDirection.Rtl);
                cr.Stroke ();
            }

            ((IDisposable)cc).Dispose();
            ((IDisposable)cr).Dispose();
            return true;
        }
示例#18
0
        static void DrawBar(CairoContextEx gr, double x, double y, double w, double h, double percentage)
        {
            double per = percentage / 100;

            gr.Rectangle (x, y - h * per, w, h * per);
            gr.FillGradient (x, y - h * per, w, h * per, new Cairo.Color (0, 0, 1));
            gr.DrawTextCentered (x + w / 2, (y - 0.03) - h * per, String.Format ("{0}", percentage));

            gr.Save ();
            gr.Color = new Cairo.Color (0, 0, 0);
            gr.MoveTo (x, y);
            gr.LineTo (x, y - h * per);
            gr.LineTo (x + w, y - h * per);
            gr.LineTo (x + w, y);
            gr.LineTo (x, y);
            gr.Stroke ();
            gr.Restore ();
        }
 void DrawAxisDescription(CairoContextEx cr, double x, double y, string description)
 {
     cr.Save ();
     cr.Color = desc_color;
     cr.MoveTo (x, y);
     cr.ShowPangoText (description);
     cr.Stroke ();
     cr.Restore ();
 }
示例#20
0
        static void GenerateQuestions(CairoContextEx cr, Game [] games, int columns, int rows)
        {
            int x, y, page;
            Game puzzle;
            string str;

            x = y = page = 0;
            for (int i = 0; i < games.Length; i++)
            {
                puzzle = games [i];
                puzzle.Begin ();
                page++;

                cr.Save ();
                cr.Translate (x, y);
                cr.Rectangle (0, 0, width, height + question_height);
                cr.Clip ();

                // Translators: {0} is the game number and {1} the game question or answer
                // The number is used as reference when looking for the game solution in the PDF
                str = String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Game #{0}. {1}"), i + 1, puzzle.Question);

                // Draw question
                cr.SetPangoFontSize (12);
                cr.UseMarkup = true;
                cr.DrawStringWithWrapping (margin, 10, str, width - margin);
                cr.Stroke ();
                cr.UseMarkup = false;

                // Draw from question_height up height since from 0 to question_height is the question
                // Translate adds always to previous matrix's transformation
                cr.Translate (0, question_height);
                puzzle.DrawPreview (cr, width, height, false);
                if (i == 0) {
                    cr.Save ();
                    cr.SetPangoFontSize (0.02);
                    cr.MoveTo (0.05, 0.95);
                    cr.ShowPangoText (String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Created by gbrainy {0}"), Defines.VERSION));
                    cr.Stroke ();
                    cr.Restore ();
                }

                x += width + margin;
                if (x > width + margin) {
                    x = 0;
                    y += height + margin + question_height;
                }
                cr.Restore ();
                cr.Stroke ();

                if (page >= columns * rows) {
                    cr.ShowPage ();
                    page = x = y = 0;
                }
            }

            if (y > 0)
                cr.ShowPage ();
        }
示例#21
0
        private static void DrawAndConnectPoints(CairoContextEx gr, double x, double y, Circle[] circles, bool connect)
        {
            const double point_size = 0.01;
            for (int i = 0; i < circles.Length; i++) {
                gr.Arc (x + point_size + circles[i].x, y + point_size + circles[i].y, point_size, 0, 2 * Math.PI);
                gr.Fill ();
                gr.Stroke ();
            }

            if (connect == false)
                return;

            gr.Save ();
            gr.LineWidth = 0.003;
            double offset = point_size;
            for (int from = 0; from < circles.Length; from++) {
                for (int to = 0; to < circles.Length; to++) {
                    gr.MoveTo (x + circles[from].x+ offset, y + circles[from].y + offset);
                    gr.LineTo (x + circles[to].x + offset, y + circles[to].y + offset);
                    gr.Stroke ();
                }
            }
            gr.Restore ();
        }