当前位置: 首页>>代码示例>>C#>>正文


C# CairoContextEx.MeasureString方法代码示例

本文整理汇总了C#中gbrainy.Core.Main.CairoContextEx.MeasureString方法的典型用法代码示例。如果您正苦于以下问题:C# CairoContextEx.MeasureString方法的具体用法?C# CairoContextEx.MeasureString怎么用?C# CairoContextEx.MeasureString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gbrainy.Core.Main.CairoContextEx的用法示例。


在下文中一共展示了CairoContextEx.MeasureString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawSolution

        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 ();
        }
开发者ID:syoubin,项目名称:gbrainy_android,代码行数:53,代码来源:GameDrawingArea.cs

示例2: Draw

        public void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
        {
            double y = 0.04, x = 0.05;
            const double space_small = 0.02;
            List <PlayerPersonalRecord> records;
            string s, tip, played;
            double width, height;

            gr.Scale (area_width, area_height);
            gr.Color = new Cairo.Color (0, 0, 0, 1);

            gr.MoveTo (x, y);
            gr.ShowPangoText (Translations.GetString ("Score"), false, -1, 0);
            DrawBand (gr, 0.03, y - 0.01);

            y += 0.08;
            gr.MoveTo (x, y);

            s = session.History.GetResult (Translations);

            // Translator: This will be part of the sentence "Games won: 10 (6 played)"
            played = String.Format (Translations.GetPluralString ("{0} played", "{0} played", session.History.GamesPlayed),
                session.History.GamesPlayed);

            if (s == string.Empty) {
                gr.ShowPangoText (String.Format (Translations.GetPluralString ("Games won: {0} ({1})",
                    "Games won: {0} ({1})", session.History.GamesWon), session.History.GamesWon, played));
            }
            else {
                gr.ShowPangoText (String.Format (Translations.GetPluralString ("{0}. Games won: {1} ({2})",
                    "{0}. Games won: {1} ({2})", session.History.GamesWon),	s, session.History.GamesWon, played));
            }

            y += 0.06;
            gr.MoveTo (x, y);
            gr.ShowPangoText (String.Format (Translations.GetString ("Time played {0} (average per game {1})"), session.GameTime, session.TimePerGame));

            y += 0.09;
            DrawColumnBarGraphic (gr, x, y);

            y += 0.36;
            gr.MoveTo (x, y);
            gr.SetPangoFontSize (smaller_font);
            // Translators: translated string should not be longer that the English original (space restriction on the UI)
            gr.ShowPangoText (Translations.GetString ("For details on how gbrainy's scoring works refer to the help."));

            y += 0.07;
            gr.SetPangoNormalFontSize ();
            records	= session.PlayerHistory.GetLastGameRecords ();
            gr.MoveTo (x, y);

            if (records.Count == 0) {
                bool caching = cached_sessionid != session.ID;

                gr.ShowPangoText (Translations.GetString ("Tips for your next games"), false, -1, 0);
                DrawBand (gr, 0.03, y - 0.01);

                y += 0.08;

                if (caching)
                    tips.Clear ();

                for (int i = 0; i < tips_shown; i++)
                {
                    if (caching)
                        tips.Add (game_tips.Tip);

                    tip = "- " + tips [i];

                    gr.MeasureString (tip, 1.0 - x, true, out width, out height);

                    if (y + height > 0.98)
                        break;

                    gr.DrawStringWithWrapping (x, y, tip , 1.0 - x);
                    y += height + space_small;
                }

                if (caching)
                    cached_sessionid = session.ID;
            }
            else  {
                gr.ShowPangoText (Translations.GetString ("Congratulations! New personal record"), false, -1, 0);
                DrawBand (gr, 0.03, y - 0.01);

                y += 0.08;

                for (int i = 0; i < records.Count; i++)
                {
                    switch (records[i].GameType) {
                    case GameTypes.LogicPuzzle:
                        s = String.Format (Translations.
                            GetString ("By scoring {0} in logic puzzle games you have established a new personal record. Your previous record was {1}."),
                            records[i].NewScore,
                            records[i].PreviousScore);
                        break;
                    case GameTypes.Calculation:
                        s = String.Format (Translations.
                            GetString ("By scoring {0} in calculation games you have established a new personal record. Your previous record was {1}."),
                            records[i].NewScore,
//.........这里部分代码省略.........
开发者ID:GNOME,项目名称:gbrainy,代码行数:101,代码来源:FinishView.cs

示例3: DrawQuestion

        void DrawQuestion(CairoContextEx cr, int height, double max_width)
        {
            if (String.IsNullOrEmpty (Question) == true)
                return;

            cr.DrawStringWithWrapping (text_margin, text_margin, Question, max_width);
            cr.Stroke ();

            double w, h, question_high_scaled;
            cr.MeasureString (Question, max_width, true, out w, out h);

            // We use a minimum hight, but if the text is longer (L10 versions) move the line as needed
            question_high_scaled = Math.Max (question_high / (double) height, h);
            cr.LineWidth = 0.002;
            cr.MoveTo (0.01, question_high_scaled + 0.01);
            cr.LineTo (0.99, question_high_scaled + 0.01);
            cr.Stroke ();
        }
开发者ID:syoubin,项目名称:gbrainy_android,代码行数:18,代码来源:GameDrawingArea.cs


注:本文中的gbrainy.Core.Main.CairoContextEx.MeasureString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。