gbrainy r418 - in branches/RTL/src: . PuzzleGames
- From: jmas svn gnome org
- To: svn-commits-list gnome org
- Subject: gbrainy r418 - in branches/RTL/src: . PuzzleGames
- Date: Sat, 9 Aug 2008 13:38:50 +0000 (UTC)
Author: jmas
Date: Sat Aug 9 13:38:49 2008
New Revision: 418
URL: http://svn.gnome.org/viewvc/gbrainy?rev=418&view=rev
Log:
First RTL support
Modified:
branches/RTL/src/CairoContextEx.cs
branches/RTL/src/Game.cs
branches/RTL/src/PuzzleGames/PuzzleClocks.cs
branches/RTL/src/PuzzleGames/PuzzleFigures.cs
Modified: branches/RTL/src/CairoContextEx.cs
==============================================================================
--- branches/RTL/src/CairoContextEx.cs (original)
+++ branches/RTL/src/CairoContextEx.cs Sat Aug 9 13:38:49 2008
@@ -23,20 +23,74 @@
using System.Text;
using System.Runtime.InteropServices;
using Pango;
+using System.Collections.Generic;
+
+public class WidgetMatrix
+{
+ public struct PointD
+ {
+ public double X, Y;
+ }
+
+ List <PointD> points;
+ int cols, rows;
+ bool rtl;
+
+ public PointD GetPoint (int pos)
+ {
+ if (rtl == false)
+ return points[pos];
+
+ int row, col;
+
+ row = (pos / cols);
+ col = pos - (row * cols);
+
+ return points[((row * cols) + cols - col) -1];
+ }
+
+ public PointD GetPoint (int row, int column)
+ {
+ return GetPoint (row * column);
+ }
+
+ public WidgetMatrix (CairoContextEx cr, int rows, int cols)
+ {
+ this.cols = cols;
+ this.rows = rows;
+ points = new List <PointD> (cols * rows);
+ for (int i = 0; i < cols * rows; i++)
+ points.Add (new PointD ());
+
+ rtl = cr.rtl;
+ }
+
+ public void Add (int index, double x, double y)
+ {
+ PointD p = new PointD ();
+
+ p.X = x;
+ p.Y = y;
+ points[index] = p;
+ }
+}
public class CairoContextEx : Cairo.Context
{
Pango.Layout layout;
double font_size;
static SVGImage image = null;
-
const double line_space = 0.018;
const double width_margin = 0.04;
+ public bool rtl;
+
public CairoContextEx (IntPtr state, Gtk.Widget widget) : base (state)
{
double resolution = widget.Screen.Resolution;
CommonConstructor ();
+
+ rtl = widget.Direction == Gtk.TextDirection.Rtl;
if (resolution != -1)
CairoHelper.ContextSetResolution (layout.Context, resolution);
Modified: branches/RTL/src/Game.cs
==============================================================================
--- branches/RTL/src/Game.cs (original)
+++ branches/RTL/src/Game.cs Sat Aug 9 13:38:49 2008
@@ -224,11 +224,34 @@
return (int) score;
}
}
-
public abstract void Initialize ();
public virtual void Finish () {}
+ public string GetPossibleAnswer (int answer)
+ {
+ switch (answer) {
+ case 0: // First possible answer for a serie (e.g.: Figure A)
+ return Catalog.GetString ("A");
+ case 1: // Second possible answer for a serie
+ return Catalog.GetString ("B");
+ case 2: // Third possible answer for a serie
+ return Catalog.GetString ("C");
+ case 3: // Fourth possible answer for a serie
+ return Catalog.GetString ("D");
+ case 4: // Fifth possible answer for a serie
+ return Catalog.GetString ("E");
+ case 5: // Sixth possible answer for a serie
+ return Catalog.GetString ("F");
+ default:
+ return string.Empty;
+ }
+ }
+
+ public string GetPossibleFigureAnswer (int answer)
+ {
+ return String.Format (Catalog.GetString ("Figure {0}"), GetPossibleAnswer (answer));
+ }
public virtual void Draw (CairoContextEx gr, int width, int height)
{
Modified: branches/RTL/src/PuzzleGames/PuzzleClocks.cs
==============================================================================
--- branches/RTL/src/PuzzleGames/PuzzleClocks.cs (original)
+++ branches/RTL/src/PuzzleGames/PuzzleClocks.cs Sat Aug 9 13:38:49 2008
@@ -35,7 +35,8 @@
}
public override string Question {
- get {return Catalog.GetString ("To what number should the large handle of the last clock point? Answer A, B, C or D.");}
+ get {return String.Format (Catalog.GetString ("To what number should the large handle of the '{0}' clock point? Answer {1}, {2}, {3} or {4}."),
+ GetPossibleFigureAnswer (3), GetPossibleAnswer (0), GetPossibleAnswer (1), GetPossibleAnswer (2), GetPossibleAnswer (3));}
}
public override string Answer {
@@ -143,32 +144,30 @@
gr.Stroke ();
}
+ private void DrawElement (CairoContextEx gr, double x, double y, string str, int h1, int h2, bool draw_handle)
+ {
+ DrawClock (gr, x, y, handles[h1], handles[h2], draw_handle);
+ gr.MoveTo (x - 0.07, y + 0.19);
+ gr.ShowPangoText (str);
+ gr.Stroke ();
+ }
+
public override void Draw (CairoContextEx gr, int area_width, int area_height)
{
double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
+ WidgetMatrix wm = new WidgetMatrix (gr, 2, 2);
base.Draw (gr, area_width, area_height);
- DrawClock (gr, x + 0.1, y + 0.1, handles[0], handles[1], true);
- gr.MoveTo (x + 0.03, y + 0.29);
- gr.ShowPangoText (String.Format (Catalog.GetString ("Figure {0}"), 'A'));
- gr.Stroke ();
-
- DrawClock (gr, x + 0.5, y + 0.1, handles[2], handles[3], true);
- gr.MoveTo (x + 0.43, y + 0.29);
- gr.ShowPangoText (String.Format (Catalog.GetString ("Figure {0}"), 'B'));
- gr.Stroke ();
-
- DrawClock (gr, x + 0.1, y + 0.52, handles[4], handles[5], true);
- gr.MoveTo (x + 0.03, y + 0.71);
- gr.ShowPangoText (String.Format (Catalog.GetString ("Figure {0}"), 'C'));
- gr.Stroke ();
-
- DrawClock (gr, x + 0.5, y + 0.52, handles[6], handles[7], DrawAnswer == true);
- gr.MoveTo (x + 0.43, y + 0.71);
- gr.ShowPangoText (String.Format (Catalog.GetString ("Figure {0}"), 'D'));
- gr.Stroke ();
-
+ wm.Add (0, x + 0.1, y + 0.1);
+ wm.Add (1, x + 0.5, y + 0.1);
+ wm.Add (2, x + 0.1, y + 0.52);
+ wm.Add (3, x + 0.5, y + 0.52);
+
+ DrawElement (gr, wm.GetPoint(0).X, wm.GetPoint(0).Y, GetPossibleFigureAnswer (0), 0, 1, true);
+ DrawElement (gr, wm.GetPoint(1).X, wm.GetPoint(1).Y, GetPossibleFigureAnswer (1), 2, 3, true);
+ DrawElement (gr, wm.GetPoint(2).X, wm.GetPoint(2).Y, GetPossibleFigureAnswer (2), 4, 5, true);
+ DrawElement (gr, wm.GetPoint(3).X, wm.GetPoint(3).Y, GetPossibleFigureAnswer (3), 6, 7, DrawAnswer);
}
}
Modified: branches/RTL/src/PuzzleGames/PuzzleFigures.cs
==============================================================================
--- branches/RTL/src/PuzzleGames/PuzzleFigures.cs (original)
+++ branches/RTL/src/PuzzleGames/PuzzleFigures.cs Sat Aug 9 13:38:49 2008
@@ -60,9 +60,9 @@
StringBuilder sb = new StringBuilder (3);
- sb.Append ((char) (65 + figures[random_indices [5]]));
- sb.Append ((char) (65 + figures[6 + random_indices [5]]));
- sb.Append ((char) (65 + figures[(2 * 6) + random_indices [5]]));
+ sb.Append (GetPossibleAnswer (figures[random_indices [5]]));
+ sb.Append (GetPossibleAnswer (figures[6 + random_indices [5]]));
+ sb.Append (GetPossibleAnswer (figures[(2 * 6) + random_indices [5]]));
right_answer = sb.ToString ();
}
@@ -70,36 +70,42 @@
private void AnswerCoding (CairoContextEx gr, double x, double y)
{
double pos_x = x;
+ WidgetMatrix wm = new WidgetMatrix (gr, 1, 6);
gr.MoveTo (pos_x, y - 0.01);
y += 0.05;
gr.ShowPangoText (Catalog.GetString ("Convention when giving the answer is:"));
- gr.MoveTo (pos_x, y + 0.05);
- gr.ShowPangoText ("A ->");
- gr.Stroke ();
- gr.DrawDiamond (x + 0.1, y, 0.1);
+ wm.Add (0, pos_x, y);
+ wm.Add (1, pos_x + 0.1, y);
+
+ wm.Add (2, pos_x + 0.3, y);
+ wm.Add (3, pos_x + 0.3 + 0.1, y);
+
+ wm.Add (4, pos_x + 0.6, y);
+ wm.Add (5, pos_x + 0.6 + 0.1, y);
+
+ gr.MoveTo (wm.GetPoint(0).X, wm.GetPoint(0).Y + 0.05);
+ gr.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (0)));
+ gr.DrawDiamond (wm.GetPoint(1).X, wm.GetPoint(1).Y, 0.1);
gr.Stroke ();
- pos_x += 0.3;
- gr.MoveTo (pos_x, y + 0.05);
- gr.ShowPangoText ("B ->");
+ gr.MoveTo (wm.GetPoint(2).X, wm.GetPoint(2).Y + 0.05);
+ gr.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (1)));
gr.Stroke ();
- pos_x += 0.1;
- gr.Arc (pos_x + 0.05, y + 0.05, 0.05, 0, 2 * Math.PI);
+ gr.Arc (wm.GetPoint(3).X + 0.05, wm.GetPoint(3).Y + 0.05, 0.05, 0, 2 * Math.PI);
gr.Stroke ();
- pos_x += 0.2;
- gr.MoveTo (pos_x, y + 0.05);
- gr.ShowPangoText ("C ->");
+ gr.MoveTo (wm.GetPoint(4).X, wm.GetPoint(4).Y + 0.05);
+ gr.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (2)));
gr.Stroke ();
- pos_x += 0.1;
- gr.DrawEquilateralTriangle (pos_x, y, 0.1);
+ gr.DrawEquilateralTriangle (wm.GetPoint(5).X, wm.GetPoint(5).Y, 0.1);
gr.Stroke ();
y += 0.16;
gr.MoveTo (x, y);
- gr.ShowPangoText (Catalog.GetString ("E.g: ACB (diamond, triangle, circle)"));
+ gr.ShowPangoText (String.Format (Catalog.GetString ("E.g: {0}{1}{2} (diamond, triangle, circle)"),
+ GetPossibleFigureAnswer (0), GetPossibleFigureAnswer (1), GetPossibleFigureAnswer (2)));
}
public override void Draw (CairoContextEx gr, int area_width, int area_height)
@@ -107,13 +113,22 @@
int element;
double figure_width = 0.1, figure_height = 0.1, space_width = 0.05, space_height = 0.1;
double x = DrawAreaX, y = DrawAreaY;
+ WidgetMatrix wm = new WidgetMatrix (gr, 1, 6); // We paint every row as a single entity
base.Draw (gr, area_width, area_height);
+ for (int i = 0; i < 6; i++)
+ {
+ wm.Add (i, x, y);
+ x+= figure_width + space_width;
+ }
+
for (int i = 0; i < (DrawAnswer ? 6 : 5) ; i++)
{
element = random_indices [i];
- y = DrawAreaY;
+ x = wm.GetPoint(i).X;
+ y = wm.GetPoint(i).Y;
+
for (int n = 0; n < 3; n++)
{
switch ((int) figures[(n * 6) + element])
@@ -137,11 +152,11 @@
}
if (DrawAnswer == false) {
- y = DrawAreaY;
+ y = wm.GetPoint(5).Y - 0.02;
gr.Save ();
gr.SetPangoFontSize (0.1);
for (int n = 0; n < 3; n++) {
- gr.MoveTo (x, y - 0.02);
+ gr.MoveTo (wm.GetPoint(5).X, y);
gr.ShowPangoText ("?");
gr.Stroke ();
y+= figure_height + space_height;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]