gbrainy r410 - trunk/src
- From: jmas svn gnome org
- To: svn-commits-list gnome org
- Subject: gbrainy r410 - trunk/src
- Date: Sun, 3 Aug 2008 14:56:49 +0000 (UTC)
Author: jmas
Date: Sun Aug 3 14:56:49 2008
New Revision: 410
URL: http://svn.gnome.org/viewvc/gbrainy?rev=410&view=rev
Log:
RTL support
Modified:
trunk/src/CairoContextEx.cs
trunk/src/ChangeLog
trunk/src/GameDrawingArea.cs
Modified: trunk/src/CairoContextEx.cs
==============================================================================
--- trunk/src/CairoContextEx.cs (original)
+++ trunk/src/CairoContextEx.cs Sun Aug 3 14:56:49 2008
@@ -31,6 +31,7 @@
static SVGImage image = null;
const double line_space = 0.018;
+ const double width_margin = 0.04;
public CairoContextEx (IntPtr state, Gtk.Widget widget) : base (state)
{
@@ -75,6 +76,8 @@
and Pango paints on the top-left of the coordinate
*/
+
+ // Shows a text from the current position. No Width defined then no RTL positioning
public void ShowPangoText (string str)
{
Cairo.Matrix old = Matrix;
@@ -83,20 +86,29 @@
Matrix = new Cairo.Matrix ();
layout.SetText (str);
layout.SingleParagraphMode = true;
- layout.Width = -1;
Pango.CairoHelper.UpdateLayout (this, layout);
Pango.CairoHelper.ShowLayout (this, layout);
Matrix = old;
}
- public void ShowPangoText (string str, bool bold)
+ // Shows a text from the current position. Defines all the line as text drawing box
+ public void ShowPangoText (string str, bool bold, double width)
{
+ Pango.Alignment align = layout.Alignment;
+
if (bold) {
layout.FontDescription.Weight = Pango.Weight.Bold;
}
+ if (width == -1) { // Calculates maximum width in the user space
+ layout.Width = (int) (((1 - width_margin) * Matrix.Xx - (CurrentPoint.X * Matrix.Xx)) * Pango.Scale.PangoScale);
+ } else
+ layout.Width = (int) (width * Matrix.Xx * Pango.Scale.PangoScale);
+
ShowPangoText (str);
layout.FontDescription.Weight = Pango.Weight.Normal;
+ layout.Width = -1;
+ layout.Alignment = align;
}
public void SetPangoNormalFontSize ()
@@ -118,6 +130,7 @@
Draw text functions
*/
+ // Used for fractions that right align is needed
public void DrawTextAlignedRight (double x, double y, string str)
{
int w, h;
@@ -157,6 +170,11 @@
public double DrawStringWithWrapping (double x, double y, string str)
{
+ return DrawStringWithWrapping (x, y, str, -1);
+ }
+
+ public double DrawStringWithWrapping (double x, double y, string str, double width)
+ {
int w, h;
Cairo.Matrix old = Matrix;
@@ -164,7 +182,11 @@
UpdateFontSize ();
Matrix = new Cairo.Matrix ();
- layout.Width = (int) ((1.0 - x - 0.02) * old.Xx * Pango.Scale.PangoScale);
+ if (width == -1)
+ layout.Width = (int) ((1.0 - x - width_margin) * old.Xx * Pango.Scale.PangoScale);
+ else
+ layout.Width = (int) (width * old.Xx * Pango.Scale.PangoScale);
+
layout.Spacing = (int) (line_space * (old.Xx * Pango.Scale.PangoScale));
layout.SingleParagraphMode = false;
layout.SetText (str);
@@ -233,5 +255,3 @@
}
-
-
Modified: trunk/src/GameDrawingArea.cs
==============================================================================
--- trunk/src/GameDrawingArea.cs (original)
+++ trunk/src/GameDrawingArea.cs Sun Aug 3 14:56:49 2008
@@ -43,6 +43,7 @@
private const int tips_count = 10;
private const int tips_shown = 4;
private CountDown countdown;
+ private bool rtl;
public GameDrawingArea ()
{
@@ -50,6 +51,7 @@
puzzle = null;
session = null;
countdown = null;
+ rtl = Direction == Gtk.TextDirection.Rtl;
}
public GameSession GameSession {
@@ -95,7 +97,7 @@
gr.Color = new Cairo.Color (0, 0, 0, 1);
gr.MoveTo (0.05, y);
- gr.ShowPangoText (String.Format (Catalog.GetString ("Welcome to gbrainy {0}"), Defines.VERSION), true);
+ gr.ShowPangoText (String.Format (Catalog.GetString ("Welcome to gbrainy {0}"), Defines.VERSION), true, -1);
gr.Stroke ();
gr.DrawStringWithWrapping (0.05, y + 0.07, Catalog.GetString ("gbrainy is a brain teaser game and trainer to have fun and to keep your brain trained. It includes:"));
@@ -104,41 +106,46 @@
image = new ImageSurface (Defines.DATA_DIR + "logic-games-80.png");
if (image.Width > 0) {
gr.Save ();
- gr.Translate (0.05, y);
+ gr.Translate (rtl ? 0.75 : 0.05, y);
gr.Scale (0.8 / area_width, 0.8 / area_height);
gr.SetSourceSurface (image, 0, 0);
gr.Paint ();
gr.Restore ();
image.Destroy ();
}
- gr.DrawStringWithWrapping (0.23, y + 0.01, Catalog.GetString ("Logic puzzles. Designed to challenge your reasoning and thinking skills."));
+ gr.DrawStringWithWrapping (rtl ? 0.05 : 0.23, y + 0.01,
+ Catalog.GetString ("Logic puzzles. Designed to challenge your reasoning and thinking skills."),
+ rtl ? 0.65 : -1);
y += space;
image = new ImageSurface (Defines.DATA_DIR + "math-games-80.png");
if (image.Width > 0) {
gr.Save ();
- gr.Translate (0.05, y);
+ gr.Translate (rtl ? 0.75 : 0.05, y);
gr.Scale (0.8 / area_width, 0.8 / area_height);
gr.SetSourceSurface (image, 0, 0);
gr.Paint ();
gr.Restore ();
image.Destroy ();
}
- gr.DrawStringWithWrapping (0.23, y + 0.01, Catalog.GetString ("Mental calculation. Based on arithmetical operations that test your mental calculation abilities."));
+ gr.DrawStringWithWrapping (rtl ? 0.05 : 0.23, y + 0.01,
+ Catalog.GetString ("Mental calculation. Based on arithmetical operations that test your mental calculation abilities."),
+ rtl ? 0.65 : -1);
y += space;
image = new ImageSurface (Defines.DATA_DIR + "memory-games-80.png");
if (image.Width > 0) {
gr.Save ();
- gr.Translate (0.05, y);
+ gr.Translate (rtl ? 0.75 : 0.05, y);
gr.Scale (0.8 / area_width, 0.8 / area_height);
gr.SetSourceSurface (image, 0, 0);
gr.Paint ();
gr.Restore ();
image.Destroy ();
}
- gr.DrawStringWithWrapping (0.23, y + 0.01, Catalog.GetString ("Memory trainers. To prove and enhance your short term memory."));
- gr.Stroke ();
+ gr.DrawStringWithWrapping (rtl ? 0.05 : 0.23, y + 0.01,
+ Catalog.GetString ("Memory trainers. To prove and enhance your short term memory."),
+ rtl ? 0.65 : -1);
gr.DrawStringWithWrapping (0.05, y + 0.2, Catalog.GetString ("Use the Settings to adjust the difficulty level of the game."));
gr.Stroke ();
@@ -207,7 +214,7 @@
gr.Color = new Cairo.Color (0, 0, 0, 1);
gr.MoveTo (x, y);
- gr.ShowPangoText (Catalog.GetString ("Score"));
+ gr.ShowPangoText (Catalog.GetString ("Score"), false, -1);
DrawBand (gr, 0.03, y - 0.01);
y += 0.08;
@@ -241,7 +248,7 @@
y += 0.4;
gr.MoveTo (x, y);
- gr.ShowPangoText (Catalog.GetString ("Tips for your next games"));
+ gr.ShowPangoText (Catalog.GetString ("Tips for your next games"), false, -1);
DrawBand (gr, 0.03, y - 0.01);
y += 0.08;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]