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 (); }
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, records[i].PreviousScore); break; case GameTypes.Memory: s = String.Format (Translations. GetString ("By scoring {0} in memory games you have established a new personal record. Your previous record was {1}."), records[i].NewScore, records[i].PreviousScore); break; case GameTypes.VerbalAnalogy: s = String.Format (Translations. GetString ("By scoring {0} in verbal analogies you have established a new personal record. Your previous record was {1}."), records[i].NewScore, records[i].PreviousScore); break; default: break; } tip = "- " + s; 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; } } gr.Stroke (); }
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 (); }